]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.4.3-201206192225.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.4.3-201206192225.patch
CommitLineData
82e63073
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index b4a898f..a0e01d0 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@@ -80,6 +86,7 @@ aic7*seq.h*
46 aicasm
47 aicdb.h*
48 altivec*.c
49+ashldi3.S
50 asm-offsets.h
51 asm_offsets.h
52 autoconf.h*
53@@ -92,19 +99,24 @@ bounds.h
54 bsetup
55 btfixupprep
56 build
57+builtin-policy.h
58 bvmlinux
59 bzImage*
60 capability_names.h
61 capflags.c
62 classlist.h*
63+clut_vga16.c
64+common-cmds.h
65 comp*.log
66 compile.h*
67 conf
68 config
69 config-*
70 config_data.h*
71+config.c
72 config.mak
73 config.mak.autogen
74+config.tmp
75 conmakehash
76 consolemap_deftbl.c*
77 cpustr.h
78@@ -115,9 +127,11 @@ devlist.h*
79 dnotify_test
80 docproc
81 dslm
82+dtc-lexer.lex.c
83 elf2ecoff
84 elfconfig.h*
85 evergreen_reg_safe.h
86+exception_policy.conf
87 fixdep
88 flask.h
89 fore200e_mkfirm
90@@ -125,12 +139,15 @@ fore200e_pca_fw.c*
91 gconf
92 gconf.glade.h
93 gen-devlist
94+gen-kdb_cmds.c
95 gen_crc32table
96 gen_init_cpio
97 generated
98 genheaders
99 genksyms
100 *_gray256.c
101+hash
102+hid-example
103 hpet_example
104 hugepage-mmap
105 hugepage-shm
106@@ -145,7 +162,7 @@ int32.c
107 int4.c
108 int8.c
109 kallsyms
110-kconfig
111+kern_constants.h
112 keywords.c
113 ksym.c*
114 ksym.h*
115@@ -153,7 +170,7 @@ kxgettext
116 lkc_defs.h
117 lex.c
118 lex.*.c
119-linux
120+lib1funcs.S
121 logo_*.c
122 logo_*_clut224.c
123 logo_*_mono.c
124@@ -164,14 +181,15 @@ machtypes.h
125 map
126 map_hugetlb
127 maui_boot.h
128-media
129 mconf
130+mdp
131 miboot*
132 mk_elfconfig
133 mkboot
134 mkbugboot
135 mkcpustr
136 mkdep
137+mkpiggy
138 mkprep
139 mkregtable
140 mktables
141@@ -188,6 +206,7 @@ oui.c*
142 page-types
143 parse.c
144 parse.h
145+parse-events*
146 patches*
147 pca200e.bin
148 pca200e_ecd.bin2
149@@ -197,6 +216,7 @@ perf-archive
150 piggyback
151 piggy.gzip
152 piggy.S
153+pmu-*
154 pnmtologo
155 ppc_defs.h*
156 pss_boot.h
157@@ -207,6 +227,7 @@ r300_reg_safe.h
158 r420_reg_safe.h
159 r600_reg_safe.h
160 recordmcount
161+regdb.c
162 relocs
163 rlim_names.h
164 rn50_reg_safe.h
165@@ -216,7 +237,9 @@ series
166 setup
167 setup.bin
168 setup.elf
169+size_overflow_hash.h
170 sImage
171+slabinfo
172 sm_tbl*
173 split-include
174 syscalltab.h
175@@ -227,6 +250,7 @@ tftpboot.img
176 timeconst.h
177 times.h*
178 trix_boot.h
179+user_constants.h
180 utsrelease.h*
181 vdso-syms.lds
182 vdso.lds
183@@ -238,13 +262,17 @@ vdso32.lds
184 vdso32.so.dbg
185 vdso64.lds
186 vdso64.so.dbg
187+vdsox32.lds
188+vdsox32-syms.lds
189 version.h*
190 vmImage
191 vmlinux
192 vmlinux-*
193 vmlinux.aout
194 vmlinux.bin.all
195+vmlinux.bin.bz2
196 vmlinux.lds
197+vmlinux.relocs
198 vmlinuz
199 voffset.h
200 vsyscall.lds
201@@ -252,9 +280,11 @@ vsyscall_32.lds
202 wanxlfw.inc
203 uImage
204 unifdef
205+utsrelease.h
206 wakeup.bin
207 wakeup.elf
208 wakeup.lds
209 zImage*
210 zconf.hash.c
211+zconf.lex.c
212 zoffset.h
213diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
214index c1601e5..08557ce 100644
215--- a/Documentation/kernel-parameters.txt
216+++ b/Documentation/kernel-parameters.txt
217@@ -2021,6 +2021,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
218 the specified number of seconds. This is to be used if
219 your oopses keep scrolling off the screen.
220
221+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
222+ virtualization environments that don't cope well with the
223+ expand down segment used by UDEREF on X86-32 or the frequent
224+ page table updates on X86-64.
225+
226+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
227+
228 pcbit= [HW,ISDN]
229
230 pcd. [PARIDE]
231diff --git a/Makefile b/Makefile
232index a0804c6..f487027 100644
233--- a/Makefile
234+++ b/Makefile
235@@ -245,8 +245,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
236
237 HOSTCC = gcc
238 HOSTCXX = g++
239-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
240-HOSTCXXFLAGS = -O2
241+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
242+HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
243+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
244
245 # Decide whether to build built-in, modular, or both.
246 # Normally, just do built-in.
247@@ -407,8 +408,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exc
248 # Rules shared between *config targets and build targets
249
250 # Basic helpers built in scripts/
251-PHONY += scripts_basic
252-scripts_basic:
253+PHONY += scripts_basic gcc-plugins
254+scripts_basic: gcc-plugins
255 $(Q)$(MAKE) $(build)=scripts/basic
256 $(Q)rm -f .tmp_quiet_recordmcount
257
258@@ -564,6 +565,56 @@ else
259 KBUILD_CFLAGS += -O2
260 endif
261
262+ifndef DISABLE_PAX_PLUGINS
263+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
264+ifneq ($(PLUGINCC),)
265+ifndef DISABLE_PAX_CONSTIFY_PLUGIN
266+ifndef CONFIG_UML
267+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
268+endif
269+endif
270+ifdef CONFIG_PAX_MEMORY_STACKLEAK
271+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
272+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
273+endif
274+ifdef CONFIG_KALLOCSTAT_PLUGIN
275+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
276+endif
277+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
278+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
279+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
280+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
281+endif
282+ifdef CONFIG_CHECKER_PLUGIN
283+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
284+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
285+endif
286+endif
287+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
288+ifdef CONFIG_PAX_SIZE_OVERFLOW
289+SIZE_OVERFLOW_PLUGIN := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
290+endif
291+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
292+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS) $(SIZE_OVERFLOW_PLUGIN)
293+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
294+export PLUGINCC CONSTIFY_PLUGIN STACKLEAK_PLUGIN KERNEXEC_PLUGIN CHECKER_PLUGIN SIZE_OVERFLOW_PLUGIN
295+ifeq ($(KBUILD_EXTMOD),)
296+gcc-plugins:
297+ $(Q)$(MAKE) $(build)=tools/gcc
298+else
299+gcc-plugins: ;
300+endif
301+else
302+gcc-plugins:
303+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
304+ $(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.))
305+else
306+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
307+endif
308+ $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
309+endif
310+endif
311+
312 include $(srctree)/arch/$(SRCARCH)/Makefile
313
314 ifneq ($(CONFIG_FRAME_WARN),0)
315@@ -708,7 +759,7 @@ export mod_strip_cmd
316
317
318 ifeq ($(KBUILD_EXTMOD),)
319-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
320+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
321
322 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
323 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
324@@ -932,6 +983,8 @@ vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
325
326 # The actual objects are generated when descending,
327 # make sure no implicit rule kicks in
328+$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
329+$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
330 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
331
332 # Handle descending into subdirectories listed in $(vmlinux-dirs)
333@@ -941,7 +994,7 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
334 # Error messages still appears in the original language
335
336 PHONY += $(vmlinux-dirs)
337-$(vmlinux-dirs): prepare scripts
338+$(vmlinux-dirs): gcc-plugins prepare scripts
339 $(Q)$(MAKE) $(build)=$@
340
341 # Store (new) KERNELRELASE string in include/config/kernel.release
342@@ -985,6 +1038,7 @@ prepare0: archprepare FORCE
343 $(Q)$(MAKE) $(build)=.
344
345 # All the preparing..
346+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
347 prepare: prepare0
348
349 # Generate some files
350@@ -1092,6 +1146,8 @@ all: modules
351 # using awk while concatenating to the final file.
352
353 PHONY += modules
354+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
355+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
356 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
357 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
358 @$(kecho) ' Building modules, stage 2.';
359@@ -1107,7 +1163,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
360
361 # Target to prepare building external modules
362 PHONY += modules_prepare
363-modules_prepare: prepare scripts
364+modules_prepare: gcc-plugins prepare scripts
365
366 # Target to install modules
367 PHONY += modules_install
368@@ -1204,6 +1260,7 @@ distclean: mrproper
369 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
370 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
371 -o -name '.*.rej' \
372+ -o -name '.*.rej' -o -name '*.so' \
373 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
374 -type f -print | xargs rm -f
375
376@@ -1364,6 +1421,8 @@ PHONY += $(module-dirs) modules
377 $(module-dirs): crmodverdir $(objtree)/Module.symvers
378 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
379
380+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
381+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
382 modules: $(module-dirs)
383 @$(kecho) ' Building modules, stage 2.';
384 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
385@@ -1490,17 +1549,21 @@ else
386 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
387 endif
388
389-%.s: %.c prepare scripts FORCE
390+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
391+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
392+%.s: %.c gcc-plugins prepare scripts FORCE
393 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
394 %.i: %.c prepare scripts FORCE
395 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
396-%.o: %.c prepare scripts FORCE
397+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
398+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
399+%.o: %.c gcc-plugins prepare scripts FORCE
400 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
401 %.lst: %.c prepare scripts FORCE
402 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
403-%.s: %.S prepare scripts FORCE
404+%.s: %.S gcc-plugins prepare scripts FORCE
405 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
406-%.o: %.S prepare scripts FORCE
407+%.o: %.S gcc-plugins prepare scripts FORCE
408 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
409 %.symtypes: %.c prepare scripts FORCE
410 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
411@@ -1510,11 +1573,15 @@ endif
412 $(cmd_crmodverdir)
413 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
414 $(build)=$(build-dir)
415-%/: prepare scripts FORCE
416+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
417+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
418+%/: gcc-plugins prepare scripts FORCE
419 $(cmd_crmodverdir)
420 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
421 $(build)=$(build-dir)
422-%.ko: prepare scripts FORCE
423+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
424+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
425+%.ko: gcc-plugins prepare scripts FORCE
426 $(cmd_crmodverdir)
427 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
428 $(build)=$(build-dir) $(@:.ko=.o)
429diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
430index 3bb7ffe..347a54c 100644
431--- a/arch/alpha/include/asm/atomic.h
432+++ b/arch/alpha/include/asm/atomic.h
433@@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
434 #define atomic_dec(v) atomic_sub(1,(v))
435 #define atomic64_dec(v) atomic64_sub(1,(v))
436
437+#define atomic64_read_unchecked(v) atomic64_read(v)
438+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
439+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
440+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
441+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
442+#define atomic64_inc_unchecked(v) atomic64_inc(v)
443+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
444+#define atomic64_dec_unchecked(v) atomic64_dec(v)
445+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
446+
447 #define smp_mb__before_atomic_dec() smp_mb()
448 #define smp_mb__after_atomic_dec() smp_mb()
449 #define smp_mb__before_atomic_inc() smp_mb()
450diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
451index ad368a9..fbe0f25 100644
452--- a/arch/alpha/include/asm/cache.h
453+++ b/arch/alpha/include/asm/cache.h
454@@ -4,19 +4,19 @@
455 #ifndef __ARCH_ALPHA_CACHE_H
456 #define __ARCH_ALPHA_CACHE_H
457
458+#include <linux/const.h>
459
460 /* Bytes per L1 (data) cache line. */
461 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
462-# define L1_CACHE_BYTES 64
463 # define L1_CACHE_SHIFT 6
464 #else
465 /* Both EV4 and EV5 are write-through, read-allocate,
466 direct-mapped, physical.
467 */
468-# define L1_CACHE_BYTES 32
469 # define L1_CACHE_SHIFT 5
470 #endif
471
472+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
473 #define SMP_CACHE_BYTES L1_CACHE_BYTES
474
475 #endif
476diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
477index 968d999..d36b2df 100644
478--- a/arch/alpha/include/asm/elf.h
479+++ b/arch/alpha/include/asm/elf.h
480@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
481
482 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
483
484+#ifdef CONFIG_PAX_ASLR
485+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
486+
487+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
488+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
489+#endif
490+
491 /* $0 is set by ld.so to a pointer to a function which might be
492 registered using atexit. This provides a mean for the dynamic
493 linker to call DT_FINI functions for shared libraries that have
494diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
495index bc2a0da..8ad11ee 100644
496--- a/arch/alpha/include/asm/pgalloc.h
497+++ b/arch/alpha/include/asm/pgalloc.h
498@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
499 pgd_set(pgd, pmd);
500 }
501
502+static inline void
503+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
504+{
505+ pgd_populate(mm, pgd, pmd);
506+}
507+
508 extern pgd_t *pgd_alloc(struct mm_struct *mm);
509
510 static inline void
511diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
512index 81a4342..348b927 100644
513--- a/arch/alpha/include/asm/pgtable.h
514+++ b/arch/alpha/include/asm/pgtable.h
515@@ -102,6 +102,17 @@ struct vm_area_struct;
516 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
517 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
518 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
519+
520+#ifdef CONFIG_PAX_PAGEEXEC
521+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
522+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
523+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
524+#else
525+# define PAGE_SHARED_NOEXEC PAGE_SHARED
526+# define PAGE_COPY_NOEXEC PAGE_COPY
527+# define PAGE_READONLY_NOEXEC PAGE_READONLY
528+#endif
529+
530 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
531
532 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
533diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
534index 2fd00b7..cfd5069 100644
535--- a/arch/alpha/kernel/module.c
536+++ b/arch/alpha/kernel/module.c
537@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
538
539 /* The small sections were sorted to the end of the segment.
540 The following should definitely cover them. */
541- gp = (u64)me->module_core + me->core_size - 0x8000;
542+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
543 got = sechdrs[me->arch.gotsecindex].sh_addr;
544
545 for (i = 0; i < n; i++) {
546diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
547index 49ee319..9ee7d14 100644
548--- a/arch/alpha/kernel/osf_sys.c
549+++ b/arch/alpha/kernel/osf_sys.c
550@@ -1146,7 +1146,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
551 /* At this point: (!vma || addr < vma->vm_end). */
552 if (limit - len < addr)
553 return -ENOMEM;
554- if (!vma || addr + len <= vma->vm_start)
555+ if (check_heap_stack_gap(vma, addr, len))
556 return addr;
557 addr = vma->vm_end;
558 vma = vma->vm_next;
559@@ -1182,6 +1182,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
560 merely specific addresses, but regions of memory -- perhaps
561 this feature should be incorporated into all ports? */
562
563+#ifdef CONFIG_PAX_RANDMMAP
564+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
565+#endif
566+
567 if (addr) {
568 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
569 if (addr != (unsigned long) -ENOMEM)
570@@ -1189,8 +1193,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
571 }
572
573 /* Next, try allocating at TASK_UNMAPPED_BASE. */
574- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
575- len, limit);
576+ addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
577+
578 if (addr != (unsigned long) -ENOMEM)
579 return addr;
580
581diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
582index 5eecab1..609abc0 100644
583--- a/arch/alpha/mm/fault.c
584+++ b/arch/alpha/mm/fault.c
585@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
586 __reload_thread(pcb);
587 }
588
589+#ifdef CONFIG_PAX_PAGEEXEC
590+/*
591+ * PaX: decide what to do with offenders (regs->pc = fault address)
592+ *
593+ * returns 1 when task should be killed
594+ * 2 when patched PLT trampoline was detected
595+ * 3 when unpatched PLT trampoline was detected
596+ */
597+static int pax_handle_fetch_fault(struct pt_regs *regs)
598+{
599+
600+#ifdef CONFIG_PAX_EMUPLT
601+ int err;
602+
603+ do { /* PaX: patched PLT emulation #1 */
604+ unsigned int ldah, ldq, jmp;
605+
606+ err = get_user(ldah, (unsigned int *)regs->pc);
607+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
608+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
609+
610+ if (err)
611+ break;
612+
613+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
614+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
615+ jmp == 0x6BFB0000U)
616+ {
617+ unsigned long r27, addr;
618+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
619+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
620+
621+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
622+ err = get_user(r27, (unsigned long *)addr);
623+ if (err)
624+ break;
625+
626+ regs->r27 = r27;
627+ regs->pc = r27;
628+ return 2;
629+ }
630+ } while (0);
631+
632+ do { /* PaX: patched PLT emulation #2 */
633+ unsigned int ldah, lda, br;
634+
635+ err = get_user(ldah, (unsigned int *)regs->pc);
636+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
637+ err |= get_user(br, (unsigned int *)(regs->pc+8));
638+
639+ if (err)
640+ break;
641+
642+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
643+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
644+ (br & 0xFFE00000U) == 0xC3E00000U)
645+ {
646+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
647+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
648+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
649+
650+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
651+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
652+ return 2;
653+ }
654+ } while (0);
655+
656+ do { /* PaX: unpatched PLT emulation */
657+ unsigned int br;
658+
659+ err = get_user(br, (unsigned int *)regs->pc);
660+
661+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
662+ unsigned int br2, ldq, nop, jmp;
663+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
664+
665+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
666+ err = get_user(br2, (unsigned int *)addr);
667+ err |= get_user(ldq, (unsigned int *)(addr+4));
668+ err |= get_user(nop, (unsigned int *)(addr+8));
669+ err |= get_user(jmp, (unsigned int *)(addr+12));
670+ err |= get_user(resolver, (unsigned long *)(addr+16));
671+
672+ if (err)
673+ break;
674+
675+ if (br2 == 0xC3600000U &&
676+ ldq == 0xA77B000CU &&
677+ nop == 0x47FF041FU &&
678+ jmp == 0x6B7B0000U)
679+ {
680+ regs->r28 = regs->pc+4;
681+ regs->r27 = addr+16;
682+ regs->pc = resolver;
683+ return 3;
684+ }
685+ }
686+ } while (0);
687+#endif
688+
689+ return 1;
690+}
691+
692+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
693+{
694+ unsigned long i;
695+
696+ printk(KERN_ERR "PAX: bytes at PC: ");
697+ for (i = 0; i < 5; i++) {
698+ unsigned int c;
699+ if (get_user(c, (unsigned int *)pc+i))
700+ printk(KERN_CONT "???????? ");
701+ else
702+ printk(KERN_CONT "%08x ", c);
703+ }
704+ printk("\n");
705+}
706+#endif
707
708 /*
709 * This routine handles page faults. It determines the address,
710@@ -130,8 +248,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
711 good_area:
712 si_code = SEGV_ACCERR;
713 if (cause < 0) {
714- if (!(vma->vm_flags & VM_EXEC))
715+ if (!(vma->vm_flags & VM_EXEC)) {
716+
717+#ifdef CONFIG_PAX_PAGEEXEC
718+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
719+ goto bad_area;
720+
721+ up_read(&mm->mmap_sem);
722+ switch (pax_handle_fetch_fault(regs)) {
723+
724+#ifdef CONFIG_PAX_EMUPLT
725+ case 2:
726+ case 3:
727+ return;
728+#endif
729+
730+ }
731+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
732+ do_group_exit(SIGKILL);
733+#else
734 goto bad_area;
735+#endif
736+
737+ }
738 } else if (!cause) {
739 /* Allow reads even for write-only mappings */
740 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
741diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
742index 68374ba..cff7196 100644
743--- a/arch/arm/include/asm/atomic.h
744+++ b/arch/arm/include/asm/atomic.h
745@@ -17,17 +17,35 @@
746 #include <asm/barrier.h>
747 #include <asm/cmpxchg.h>
748
749+#ifdef CONFIG_GENERIC_ATOMIC64
750+#include <asm-generic/atomic64.h>
751+#endif
752+
753 #define ATOMIC_INIT(i) { (i) }
754
755 #ifdef __KERNEL__
756
757+#define _ASM_EXTABLE(from, to) \
758+" .pushsection __ex_table,\"a\"\n"\
759+" .align 3\n" \
760+" .long " #from ", " #to"\n" \
761+" .popsection"
762+
763 /*
764 * On ARM, ordinary assignment (str instruction) doesn't clear the local
765 * strex/ldrex monitor on some implementations. The reason we can use it for
766 * atomic_set() is the clrex or dummy strex done on every exception return.
767 */
768 #define atomic_read(v) (*(volatile int *)&(v)->counter)
769+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
770+{
771+ return v->counter;
772+}
773 #define atomic_set(v,i) (((v)->counter) = (i))
774+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
775+{
776+ v->counter = i;
777+}
778
779 #if __LINUX_ARM_ARCH__ >= 6
780
781@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
782 int result;
783
784 __asm__ __volatile__("@ atomic_add\n"
785+"1: ldrex %1, [%3]\n"
786+" adds %0, %1, %4\n"
787+
788+#ifdef CONFIG_PAX_REFCOUNT
789+" bvc 3f\n"
790+"2: bkpt 0xf103\n"
791+"3:\n"
792+#endif
793+
794+" strex %1, %0, [%3]\n"
795+" teq %1, #0\n"
796+" bne 1b"
797+
798+#ifdef CONFIG_PAX_REFCOUNT
799+"\n4:\n"
800+ _ASM_EXTABLE(2b, 4b)
801+#endif
802+
803+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
804+ : "r" (&v->counter), "Ir" (i)
805+ : "cc");
806+}
807+
808+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
809+{
810+ unsigned long tmp;
811+ int result;
812+
813+ __asm__ __volatile__("@ atomic_add_unchecked\n"
814 "1: ldrex %0, [%3]\n"
815 " add %0, %0, %4\n"
816 " strex %1, %0, [%3]\n"
817@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
818 smp_mb();
819
820 __asm__ __volatile__("@ atomic_add_return\n"
821+"1: ldrex %1, [%3]\n"
822+" adds %0, %1, %4\n"
823+
824+#ifdef CONFIG_PAX_REFCOUNT
825+" bvc 3f\n"
826+" mov %0, %1\n"
827+"2: bkpt 0xf103\n"
828+"3:\n"
829+#endif
830+
831+" strex %1, %0, [%3]\n"
832+" teq %1, #0\n"
833+" bne 1b"
834+
835+#ifdef CONFIG_PAX_REFCOUNT
836+"\n4:\n"
837+ _ASM_EXTABLE(2b, 4b)
838+#endif
839+
840+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
841+ : "r" (&v->counter), "Ir" (i)
842+ : "cc");
843+
844+ smp_mb();
845+
846+ return result;
847+}
848+
849+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
850+{
851+ unsigned long tmp;
852+ int result;
853+
854+ smp_mb();
855+
856+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
857 "1: ldrex %0, [%3]\n"
858 " add %0, %0, %4\n"
859 " strex %1, %0, [%3]\n"
860@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
861 int result;
862
863 __asm__ __volatile__("@ atomic_sub\n"
864+"1: ldrex %1, [%3]\n"
865+" subs %0, %1, %4\n"
866+
867+#ifdef CONFIG_PAX_REFCOUNT
868+" bvc 3f\n"
869+"2: bkpt 0xf103\n"
870+"3:\n"
871+#endif
872+
873+" strex %1, %0, [%3]\n"
874+" teq %1, #0\n"
875+" bne 1b"
876+
877+#ifdef CONFIG_PAX_REFCOUNT
878+"\n4:\n"
879+ _ASM_EXTABLE(2b, 4b)
880+#endif
881+
882+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
883+ : "r" (&v->counter), "Ir" (i)
884+ : "cc");
885+}
886+
887+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
888+{
889+ unsigned long tmp;
890+ int result;
891+
892+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
893 "1: ldrex %0, [%3]\n"
894 " sub %0, %0, %4\n"
895 " strex %1, %0, [%3]\n"
896@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
897 smp_mb();
898
899 __asm__ __volatile__("@ atomic_sub_return\n"
900-"1: ldrex %0, [%3]\n"
901-" sub %0, %0, %4\n"
902+"1: ldrex %1, [%3]\n"
903+" sub %0, %1, %4\n"
904+
905+#ifdef CONFIG_PAX_REFCOUNT
906+" bvc 3f\n"
907+" mov %0, %1\n"
908+"2: bkpt 0xf103\n"
909+"3:\n"
910+#endif
911+
912 " strex %1, %0, [%3]\n"
913 " teq %1, #0\n"
914 " bne 1b"
915+
916+#ifdef CONFIG_PAX_REFCOUNT
917+"\n4:\n"
918+ _ASM_EXTABLE(2b, 4b)
919+#endif
920+
921 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
922 : "r" (&v->counter), "Ir" (i)
923 : "cc");
924@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
925 return oldval;
926 }
927
928+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
929+{
930+ unsigned long oldval, res;
931+
932+ smp_mb();
933+
934+ do {
935+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
936+ "ldrex %1, [%3]\n"
937+ "mov %0, #0\n"
938+ "teq %1, %4\n"
939+ "strexeq %0, %5, [%3]\n"
940+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
941+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
942+ : "cc");
943+ } while (res);
944+
945+ smp_mb();
946+
947+ return oldval;
948+}
949+
950 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
951 {
952 unsigned long tmp, tmp2;
953@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
954
955 return val;
956 }
957+
958+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
959+{
960+ return atomic_add_return(i, v);
961+}
962+
963 #define atomic_add(i, v) (void) atomic_add_return(i, v)
964+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
965+{
966+ (void) atomic_add_return(i, v);
967+}
968
969 static inline int atomic_sub_return(int i, atomic_t *v)
970 {
971@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
972 return val;
973 }
974 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
975+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
976+{
977+ (void) atomic_sub_return(i, v);
978+}
979
980 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
981 {
982@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
983 return ret;
984 }
985
986+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
987+{
988+ return atomic_cmpxchg(v, old, new);
989+}
990+
991 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
992 {
993 unsigned long flags;
994@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
995 #endif /* __LINUX_ARM_ARCH__ */
996
997 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
998+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
999+{
1000+ return xchg(&v->counter, new);
1001+}
1002
1003 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1004 {
1005@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1006 }
1007
1008 #define atomic_inc(v) atomic_add(1, v)
1009+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1010+{
1011+ atomic_add_unchecked(1, v);
1012+}
1013 #define atomic_dec(v) atomic_sub(1, v)
1014+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1015+{
1016+ atomic_sub_unchecked(1, v);
1017+}
1018
1019 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1020+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1021+{
1022+ return atomic_add_return_unchecked(1, v) == 0;
1023+}
1024 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1025 #define atomic_inc_return(v) (atomic_add_return(1, v))
1026+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1027+{
1028+ return atomic_add_return_unchecked(1, v);
1029+}
1030 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1031 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1032
1033@@ -241,6 +428,14 @@ typedef struct {
1034 u64 __aligned(8) counter;
1035 } atomic64_t;
1036
1037+#ifdef CONFIG_PAX_REFCOUNT
1038+typedef struct {
1039+ u64 __aligned(8) counter;
1040+} atomic64_unchecked_t;
1041+#else
1042+typedef atomic64_t atomic64_unchecked_t;
1043+#endif
1044+
1045 #define ATOMIC64_INIT(i) { (i) }
1046
1047 static inline u64 atomic64_read(atomic64_t *v)
1048@@ -256,6 +451,19 @@ static inline u64 atomic64_read(atomic64_t *v)
1049 return result;
1050 }
1051
1052+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1053+{
1054+ u64 result;
1055+
1056+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1057+" ldrexd %0, %H0, [%1]"
1058+ : "=&r" (result)
1059+ : "r" (&v->counter), "Qo" (v->counter)
1060+ );
1061+
1062+ return result;
1063+}
1064+
1065 static inline void atomic64_set(atomic64_t *v, u64 i)
1066 {
1067 u64 tmp;
1068@@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1069 : "cc");
1070 }
1071
1072+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1073+{
1074+ u64 tmp;
1075+
1076+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1077+"1: ldrexd %0, %H0, [%2]\n"
1078+" strexd %0, %3, %H3, [%2]\n"
1079+" teq %0, #0\n"
1080+" bne 1b"
1081+ : "=&r" (tmp), "=Qo" (v->counter)
1082+ : "r" (&v->counter), "r" (i)
1083+ : "cc");
1084+}
1085+
1086 static inline void atomic64_add(u64 i, atomic64_t *v)
1087 {
1088 u64 result;
1089@@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1090 __asm__ __volatile__("@ atomic64_add\n"
1091 "1: ldrexd %0, %H0, [%3]\n"
1092 " adds %0, %0, %4\n"
1093+" adcs %H0, %H0, %H4\n"
1094+
1095+#ifdef CONFIG_PAX_REFCOUNT
1096+" bvc 3f\n"
1097+"2: bkpt 0xf103\n"
1098+"3:\n"
1099+#endif
1100+
1101+" strexd %1, %0, %H0, [%3]\n"
1102+" teq %1, #0\n"
1103+" bne 1b"
1104+
1105+#ifdef CONFIG_PAX_REFCOUNT
1106+"\n4:\n"
1107+ _ASM_EXTABLE(2b, 4b)
1108+#endif
1109+
1110+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1111+ : "r" (&v->counter), "r" (i)
1112+ : "cc");
1113+}
1114+
1115+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1116+{
1117+ u64 result;
1118+ unsigned long tmp;
1119+
1120+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1121+"1: ldrexd %0, %H0, [%3]\n"
1122+" adds %0, %0, %4\n"
1123 " adc %H0, %H0, %H4\n"
1124 " strexd %1, %0, %H0, [%3]\n"
1125 " teq %1, #0\n"
1126@@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1127
1128 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1129 {
1130- u64 result;
1131- unsigned long tmp;
1132+ u64 result, tmp;
1133
1134 smp_mb();
1135
1136 __asm__ __volatile__("@ atomic64_add_return\n"
1137+"1: ldrexd %1, %H1, [%3]\n"
1138+" adds %0, %1, %4\n"
1139+" adcs %H0, %H1, %H4\n"
1140+
1141+#ifdef CONFIG_PAX_REFCOUNT
1142+" bvc 3f\n"
1143+" mov %0, %1\n"
1144+" mov %H0, %H1\n"
1145+"2: bkpt 0xf103\n"
1146+"3:\n"
1147+#endif
1148+
1149+" strexd %1, %0, %H0, [%3]\n"
1150+" teq %1, #0\n"
1151+" bne 1b"
1152+
1153+#ifdef CONFIG_PAX_REFCOUNT
1154+"\n4:\n"
1155+ _ASM_EXTABLE(2b, 4b)
1156+#endif
1157+
1158+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1159+ : "r" (&v->counter), "r" (i)
1160+ : "cc");
1161+
1162+ smp_mb();
1163+
1164+ return result;
1165+}
1166+
1167+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1168+{
1169+ u64 result;
1170+ unsigned long tmp;
1171+
1172+ smp_mb();
1173+
1174+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1175 "1: ldrexd %0, %H0, [%3]\n"
1176 " adds %0, %0, %4\n"
1177 " adc %H0, %H0, %H4\n"
1178@@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1179 __asm__ __volatile__("@ atomic64_sub\n"
1180 "1: ldrexd %0, %H0, [%3]\n"
1181 " subs %0, %0, %4\n"
1182+" sbcs %H0, %H0, %H4\n"
1183+
1184+#ifdef CONFIG_PAX_REFCOUNT
1185+" bvc 3f\n"
1186+"2: bkpt 0xf103\n"
1187+"3:\n"
1188+#endif
1189+
1190+" strexd %1, %0, %H0, [%3]\n"
1191+" teq %1, #0\n"
1192+" bne 1b"
1193+
1194+#ifdef CONFIG_PAX_REFCOUNT
1195+"\n4:\n"
1196+ _ASM_EXTABLE(2b, 4b)
1197+#endif
1198+
1199+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1200+ : "r" (&v->counter), "r" (i)
1201+ : "cc");
1202+}
1203+
1204+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1205+{
1206+ u64 result;
1207+ unsigned long tmp;
1208+
1209+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1210+"1: ldrexd %0, %H0, [%3]\n"
1211+" subs %0, %0, %4\n"
1212 " sbc %H0, %H0, %H4\n"
1213 " strexd %1, %0, %H0, [%3]\n"
1214 " teq %1, #0\n"
1215@@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1216
1217 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1218 {
1219- u64 result;
1220- unsigned long tmp;
1221+ u64 result, tmp;
1222
1223 smp_mb();
1224
1225 __asm__ __volatile__("@ atomic64_sub_return\n"
1226-"1: ldrexd %0, %H0, [%3]\n"
1227-" subs %0, %0, %4\n"
1228-" sbc %H0, %H0, %H4\n"
1229+"1: ldrexd %1, %H1, [%3]\n"
1230+" subs %0, %1, %4\n"
1231+" sbc %H0, %H1, %H4\n"
1232+
1233+#ifdef CONFIG_PAX_REFCOUNT
1234+" bvc 3f\n"
1235+" mov %0, %1\n"
1236+" mov %H0, %H1\n"
1237+"2: bkpt 0xf103\n"
1238+"3:\n"
1239+#endif
1240+
1241 " strexd %1, %0, %H0, [%3]\n"
1242 " teq %1, #0\n"
1243 " bne 1b"
1244+
1245+#ifdef CONFIG_PAX_REFCOUNT
1246+"\n4:\n"
1247+ _ASM_EXTABLE(2b, 4b)
1248+#endif
1249+
1250 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1251 : "r" (&v->counter), "r" (i)
1252 : "cc");
1253@@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1254 return oldval;
1255 }
1256
1257+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1258+{
1259+ u64 oldval;
1260+ unsigned long res;
1261+
1262+ smp_mb();
1263+
1264+ do {
1265+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1266+ "ldrexd %1, %H1, [%3]\n"
1267+ "mov %0, #0\n"
1268+ "teq %1, %4\n"
1269+ "teqeq %H1, %H4\n"
1270+ "strexdeq %0, %5, %H5, [%3]"
1271+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1272+ : "r" (&ptr->counter), "r" (old), "r" (new)
1273+ : "cc");
1274+ } while (res);
1275+
1276+ smp_mb();
1277+
1278+ return oldval;
1279+}
1280+
1281 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1282 {
1283 u64 result;
1284@@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1285
1286 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1287 {
1288- u64 result;
1289- unsigned long tmp;
1290+ u64 result, tmp;
1291
1292 smp_mb();
1293
1294 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1295-"1: ldrexd %0, %H0, [%3]\n"
1296-" subs %0, %0, #1\n"
1297-" sbc %H0, %H0, #0\n"
1298+"1: ldrexd %1, %H1, [%3]\n"
1299+" subs %0, %1, #1\n"
1300+" sbc %H0, %H1, #0\n"
1301+
1302+#ifdef CONFIG_PAX_REFCOUNT
1303+" bvc 3f\n"
1304+" mov %0, %1\n"
1305+" mov %H0, %H1\n"
1306+"2: bkpt 0xf103\n"
1307+"3:\n"
1308+#endif
1309+
1310 " teq %H0, #0\n"
1311-" bmi 2f\n"
1312+" bmi 4f\n"
1313 " strexd %1, %0, %H0, [%3]\n"
1314 " teq %1, #0\n"
1315 " bne 1b\n"
1316-"2:"
1317+"4:\n"
1318+
1319+#ifdef CONFIG_PAX_REFCOUNT
1320+ _ASM_EXTABLE(2b, 4b)
1321+#endif
1322+
1323 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1324 : "r" (&v->counter)
1325 : "cc");
1326@@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1327 " teq %0, %5\n"
1328 " teqeq %H0, %H5\n"
1329 " moveq %1, #0\n"
1330-" beq 2f\n"
1331+" beq 4f\n"
1332 " adds %0, %0, %6\n"
1333 " adc %H0, %H0, %H6\n"
1334+
1335+#ifdef CONFIG_PAX_REFCOUNT
1336+" bvc 3f\n"
1337+"2: bkpt 0xf103\n"
1338+"3:\n"
1339+#endif
1340+
1341 " strexd %2, %0, %H0, [%4]\n"
1342 " teq %2, #0\n"
1343 " bne 1b\n"
1344-"2:"
1345+"4:\n"
1346+
1347+#ifdef CONFIG_PAX_REFCOUNT
1348+ _ASM_EXTABLE(2b, 4b)
1349+#endif
1350+
1351 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1352 : "r" (&v->counter), "r" (u), "r" (a)
1353 : "cc");
1354@@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1355
1356 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1357 #define atomic64_inc(v) atomic64_add(1LL, (v))
1358+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1359 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1360+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1361 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1362 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1363 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1364+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1365 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1366 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1367 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1368diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1369index 75fe66b..2255c86 100644
1370--- a/arch/arm/include/asm/cache.h
1371+++ b/arch/arm/include/asm/cache.h
1372@@ -4,8 +4,10 @@
1373 #ifndef __ASMARM_CACHE_H
1374 #define __ASMARM_CACHE_H
1375
1376+#include <linux/const.h>
1377+
1378 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1379-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1380+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1381
1382 /*
1383 * Memory returned by kmalloc() may be used for DMA, so we must make
1384diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1385index 1252a26..9dc17b5 100644
1386--- a/arch/arm/include/asm/cacheflush.h
1387+++ b/arch/arm/include/asm/cacheflush.h
1388@@ -108,7 +108,7 @@ struct cpu_cache_fns {
1389 void (*dma_unmap_area)(const void *, size_t, int);
1390
1391 void (*dma_flush_range)(const void *, const void *);
1392-};
1393+} __no_const;
1394
1395 /*
1396 * Select the calling method
1397diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1398index d41d7cb..9bea5e0 100644
1399--- a/arch/arm/include/asm/cmpxchg.h
1400+++ b/arch/arm/include/asm/cmpxchg.h
1401@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1402
1403 #define xchg(ptr,x) \
1404 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1405+#define xchg_unchecked(ptr,x) \
1406+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1407
1408 #include <asm-generic/cmpxchg-local.h>
1409
1410diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1411index 38050b1..9d90e8b 100644
1412--- a/arch/arm/include/asm/elf.h
1413+++ b/arch/arm/include/asm/elf.h
1414@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1415 the loader. We need to make sure that it is out of the way of the program
1416 that it will "exec", and that there is sufficient room for the brk. */
1417
1418-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1419+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1420+
1421+#ifdef CONFIG_PAX_ASLR
1422+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1423+
1424+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1425+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1426+#endif
1427
1428 /* When the program starts, a1 contains a pointer to a function to be
1429 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1430@@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1431 extern void elf_set_personality(const struct elf32_hdr *);
1432 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1433
1434-struct mm_struct;
1435-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1436-#define arch_randomize_brk arch_randomize_brk
1437-
1438 #endif
1439diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1440index e51b1e8..32a3113 100644
1441--- a/arch/arm/include/asm/kmap_types.h
1442+++ b/arch/arm/include/asm/kmap_types.h
1443@@ -21,6 +21,7 @@ enum km_type {
1444 KM_L1_CACHE,
1445 KM_L2_CACHE,
1446 KM_KDB,
1447+ KM_CLEARPAGE,
1448 KM_TYPE_NR
1449 };
1450
1451diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1452index 53426c6..c7baff3 100644
1453--- a/arch/arm/include/asm/outercache.h
1454+++ b/arch/arm/include/asm/outercache.h
1455@@ -35,7 +35,7 @@ struct outer_cache_fns {
1456 #endif
1457 void (*set_debug)(unsigned long);
1458 void (*resume)(void);
1459-};
1460+} __no_const;
1461
1462 #ifdef CONFIG_OUTER_CACHE
1463
1464diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1465index 5838361..da6e813 100644
1466--- a/arch/arm/include/asm/page.h
1467+++ b/arch/arm/include/asm/page.h
1468@@ -123,7 +123,7 @@ struct cpu_user_fns {
1469 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1470 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1471 unsigned long vaddr, struct vm_area_struct *vma);
1472-};
1473+} __no_const;
1474
1475 #ifdef MULTI_USER
1476 extern struct cpu_user_fns cpu_user;
1477diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1478index 943504f..bf8d667 100644
1479--- a/arch/arm/include/asm/pgalloc.h
1480+++ b/arch/arm/include/asm/pgalloc.h
1481@@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1482 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1483 }
1484
1485+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1486+{
1487+ pud_populate(mm, pud, pmd);
1488+}
1489+
1490 #else /* !CONFIG_ARM_LPAE */
1491
1492 /*
1493@@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1494 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1495 #define pmd_free(mm, pmd) do { } while (0)
1496 #define pud_populate(mm,pmd,pte) BUG()
1497+#define pud_populate_kernel(mm,pmd,pte) BUG()
1498
1499 #endif /* CONFIG_ARM_LPAE */
1500
1501diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1502index 0f04d84..2be5648 100644
1503--- a/arch/arm/include/asm/thread_info.h
1504+++ b/arch/arm/include/asm/thread_info.h
1505@@ -148,6 +148,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1506 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1507 #define TIF_SYSCALL_TRACE 8
1508 #define TIF_SYSCALL_AUDIT 9
1509+
1510+/* within 8 bits of TIF_SYSCALL_TRACE
1511+ to meet flexible second operand requirements
1512+*/
1513+#define TIF_GRSEC_SETXID 10
1514+
1515 #define TIF_POLLING_NRFLAG 16
1516 #define TIF_USING_IWMMXT 17
1517 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1518@@ -163,9 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1519 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1520 #define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
1521 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1522+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1523
1524 /* Checks for any syscall work in entry-common.S */
1525-#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
1526+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1527+ _TIF_GRSEC_SETXID)
1528
1529 /*
1530 * Change these and you break ASM code in entry-common.S
1531diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1532index 71f6536..602f279 100644
1533--- a/arch/arm/include/asm/uaccess.h
1534+++ b/arch/arm/include/asm/uaccess.h
1535@@ -22,6 +22,8 @@
1536 #define VERIFY_READ 0
1537 #define VERIFY_WRITE 1
1538
1539+extern void check_object_size(const void *ptr, unsigned long n, bool to);
1540+
1541 /*
1542 * The exception table consists of pairs of addresses: the first is the
1543 * address of an instruction that is allowed to fault, and the second is
1544@@ -387,8 +389,23 @@ do { \
1545
1546
1547 #ifdef CONFIG_MMU
1548-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1549-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1550+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1551+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1552+
1553+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1554+{
1555+ if (!__builtin_constant_p(n))
1556+ check_object_size(to, n, false);
1557+ return ___copy_from_user(to, from, n);
1558+}
1559+
1560+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1561+{
1562+ if (!__builtin_constant_p(n))
1563+ check_object_size(from, n, true);
1564+ return ___copy_to_user(to, from, n);
1565+}
1566+
1567 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1568 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1569 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1570@@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1571
1572 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1573 {
1574+ if ((long)n < 0)
1575+ return n;
1576+
1577 if (access_ok(VERIFY_READ, from, n))
1578 n = __copy_from_user(to, from, n);
1579 else /* security hole - plug it */
1580@@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1581
1582 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1583 {
1584+ if ((long)n < 0)
1585+ return n;
1586+
1587 if (access_ok(VERIFY_WRITE, to, n))
1588 n = __copy_to_user(to, from, n);
1589 return n;
1590diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1591index b57c75e..ed2d6b2 100644
1592--- a/arch/arm/kernel/armksyms.c
1593+++ b/arch/arm/kernel/armksyms.c
1594@@ -94,8 +94,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1595 #ifdef CONFIG_MMU
1596 EXPORT_SYMBOL(copy_page);
1597
1598-EXPORT_SYMBOL(__copy_from_user);
1599-EXPORT_SYMBOL(__copy_to_user);
1600+EXPORT_SYMBOL(___copy_from_user);
1601+EXPORT_SYMBOL(___copy_to_user);
1602 EXPORT_SYMBOL(__clear_user);
1603
1604 EXPORT_SYMBOL(__get_user_1);
1605diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1606index 2b7b017..c380fa2 100644
1607--- a/arch/arm/kernel/process.c
1608+++ b/arch/arm/kernel/process.c
1609@@ -28,7 +28,6 @@
1610 #include <linux/tick.h>
1611 #include <linux/utsname.h>
1612 #include <linux/uaccess.h>
1613-#include <linux/random.h>
1614 #include <linux/hw_breakpoint.h>
1615 #include <linux/cpuidle.h>
1616
1617@@ -275,9 +274,10 @@ void machine_power_off(void)
1618 machine_shutdown();
1619 if (pm_power_off)
1620 pm_power_off();
1621+ BUG();
1622 }
1623
1624-void machine_restart(char *cmd)
1625+__noreturn void machine_restart(char *cmd)
1626 {
1627 machine_shutdown();
1628
1629@@ -519,12 +519,6 @@ unsigned long get_wchan(struct task_struct *p)
1630 return 0;
1631 }
1632
1633-unsigned long arch_randomize_brk(struct mm_struct *mm)
1634-{
1635- unsigned long range_end = mm->brk + 0x02000000;
1636- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1637-}
1638-
1639 #ifdef CONFIG_MMU
1640 /*
1641 * The vectors page is always readable from user space for the
1642diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1643index 9650c14..ae30cdd 100644
1644--- a/arch/arm/kernel/ptrace.c
1645+++ b/arch/arm/kernel/ptrace.c
1646@@ -906,10 +906,19 @@ long arch_ptrace(struct task_struct *child, long request,
1647 return ret;
1648 }
1649
1650+#ifdef CONFIG_GRKERNSEC_SETXID
1651+extern void gr_delayed_cred_worker(void);
1652+#endif
1653+
1654 asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
1655 {
1656 unsigned long ip;
1657
1658+#ifdef CONFIG_GRKERNSEC_SETXID
1659+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1660+ gr_delayed_cred_worker();
1661+#endif
1662+
1663 if (why)
1664 audit_syscall_exit(regs);
1665 else
1666diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1667index ebfac78..cbea9c0 100644
1668--- a/arch/arm/kernel/setup.c
1669+++ b/arch/arm/kernel/setup.c
1670@@ -111,13 +111,13 @@ struct processor processor __read_mostly;
1671 struct cpu_tlb_fns cpu_tlb __read_mostly;
1672 #endif
1673 #ifdef MULTI_USER
1674-struct cpu_user_fns cpu_user __read_mostly;
1675+struct cpu_user_fns cpu_user __read_only;
1676 #endif
1677 #ifdef MULTI_CACHE
1678-struct cpu_cache_fns cpu_cache __read_mostly;
1679+struct cpu_cache_fns cpu_cache __read_only;
1680 #endif
1681 #ifdef CONFIG_OUTER_CACHE
1682-struct outer_cache_fns outer_cache __read_mostly;
1683+struct outer_cache_fns outer_cache __read_only;
1684 EXPORT_SYMBOL(outer_cache);
1685 #endif
1686
1687diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1688index 63d402f..db1d714 100644
1689--- a/arch/arm/kernel/traps.c
1690+++ b/arch/arm/kernel/traps.c
1691@@ -264,6 +264,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1692
1693 static DEFINE_RAW_SPINLOCK(die_lock);
1694
1695+extern void gr_handle_kernel_exploit(void);
1696+
1697 /*
1698 * This function is protected against re-entrancy.
1699 */
1700@@ -296,6 +298,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1701 panic("Fatal exception in interrupt");
1702 if (panic_on_oops)
1703 panic("Fatal exception");
1704+
1705+ gr_handle_kernel_exploit();
1706+
1707 if (ret != NOTIFY_STOP)
1708 do_exit(SIGSEGV);
1709 }
1710diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1711index 66a477a..bee61d3 100644
1712--- a/arch/arm/lib/copy_from_user.S
1713+++ b/arch/arm/lib/copy_from_user.S
1714@@ -16,7 +16,7 @@
1715 /*
1716 * Prototype:
1717 *
1718- * size_t __copy_from_user(void *to, const void *from, size_t n)
1719+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
1720 *
1721 * Purpose:
1722 *
1723@@ -84,11 +84,11 @@
1724
1725 .text
1726
1727-ENTRY(__copy_from_user)
1728+ENTRY(___copy_from_user)
1729
1730 #include "copy_template.S"
1731
1732-ENDPROC(__copy_from_user)
1733+ENDPROC(___copy_from_user)
1734
1735 .pushsection .fixup,"ax"
1736 .align 0
1737diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1738index 6ee2f67..d1cce76 100644
1739--- a/arch/arm/lib/copy_page.S
1740+++ b/arch/arm/lib/copy_page.S
1741@@ -10,6 +10,7 @@
1742 * ASM optimised string functions
1743 */
1744 #include <linux/linkage.h>
1745+#include <linux/const.h>
1746 #include <asm/assembler.h>
1747 #include <asm/asm-offsets.h>
1748 #include <asm/cache.h>
1749diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1750index d066df6..df28194 100644
1751--- a/arch/arm/lib/copy_to_user.S
1752+++ b/arch/arm/lib/copy_to_user.S
1753@@ -16,7 +16,7 @@
1754 /*
1755 * Prototype:
1756 *
1757- * size_t __copy_to_user(void *to, const void *from, size_t n)
1758+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
1759 *
1760 * Purpose:
1761 *
1762@@ -88,11 +88,11 @@
1763 .text
1764
1765 ENTRY(__copy_to_user_std)
1766-WEAK(__copy_to_user)
1767+WEAK(___copy_to_user)
1768
1769 #include "copy_template.S"
1770
1771-ENDPROC(__copy_to_user)
1772+ENDPROC(___copy_to_user)
1773 ENDPROC(__copy_to_user_std)
1774
1775 .pushsection .fixup,"ax"
1776diff --git a/arch/arm/lib/uaccess.S b/arch/arm/lib/uaccess.S
1777index 5c908b1..e712687 100644
1778--- a/arch/arm/lib/uaccess.S
1779+++ b/arch/arm/lib/uaccess.S
1780@@ -20,7 +20,7 @@
1781
1782 #define PAGE_SHIFT 12
1783
1784-/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
1785+/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
1786 * Purpose : copy a block to user memory from kernel memory
1787 * Params : to - user memory
1788 * : from - kernel memory
1789@@ -40,7 +40,7 @@ USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1790 sub r2, r2, ip
1791 b .Lc2u_dest_aligned
1792
1793-ENTRY(__copy_to_user)
1794+ENTRY(___copy_to_user)
1795 stmfd sp!, {r2, r4 - r7, lr}
1796 cmp r2, #4
1797 blt .Lc2u_not_enough
1798@@ -278,14 +278,14 @@ USER( TUSER( strgeb) r3, [r0], #1) @ May fault
1799 ldrgtb r3, [r1], #0
1800 USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1801 b .Lc2u_finished
1802-ENDPROC(__copy_to_user)
1803+ENDPROC(___copy_to_user)
1804
1805 .pushsection .fixup,"ax"
1806 .align 0
1807 9001: ldmfd sp!, {r0, r4 - r7, pc}
1808 .popsection
1809
1810-/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
1811+/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
1812 * Purpose : copy a block from user memory to kernel memory
1813 * Params : to - kernel memory
1814 * : from - user memory
1815@@ -304,7 +304,7 @@ USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1816 sub r2, r2, ip
1817 b .Lcfu_dest_aligned
1818
1819-ENTRY(__copy_from_user)
1820+ENTRY(___copy_from_user)
1821 stmfd sp!, {r0, r2, r4 - r7, lr}
1822 cmp r2, #4
1823 blt .Lcfu_not_enough
1824@@ -544,7 +544,7 @@ USER( TUSER( ldrgeb) r3, [r1], #1) @ May fault
1825 USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1826 strgtb r3, [r0], #1
1827 b .Lcfu_finished
1828-ENDPROC(__copy_from_user)
1829+ENDPROC(___copy_from_user)
1830
1831 .pushsection .fixup,"ax"
1832 .align 0
1833diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1834index 025f742..8432b08 100644
1835--- a/arch/arm/lib/uaccess_with_memcpy.c
1836+++ b/arch/arm/lib/uaccess_with_memcpy.c
1837@@ -104,7 +104,7 @@ out:
1838 }
1839
1840 unsigned long
1841-__copy_to_user(void __user *to, const void *from, unsigned long n)
1842+___copy_to_user(void __user *to, const void *from, unsigned long n)
1843 {
1844 /*
1845 * This test is stubbed out of the main function above to keep
1846diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1847index 518091c..eae9a76 100644
1848--- a/arch/arm/mach-omap2/board-n8x0.c
1849+++ b/arch/arm/mach-omap2/board-n8x0.c
1850@@ -596,7 +596,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1851 }
1852 #endif
1853
1854-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1855+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1856 .late_init = n8x0_menelaus_late_init,
1857 };
1858
1859diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1860index 5bb4835..4760f68 100644
1861--- a/arch/arm/mm/fault.c
1862+++ b/arch/arm/mm/fault.c
1863@@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1864 }
1865 #endif
1866
1867+#ifdef CONFIG_PAX_PAGEEXEC
1868+ if (fsr & FSR_LNX_PF) {
1869+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1870+ do_group_exit(SIGKILL);
1871+ }
1872+#endif
1873+
1874 tsk->thread.address = addr;
1875 tsk->thread.error_code = fsr;
1876 tsk->thread.trap_no = 14;
1877@@ -397,6 +404,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1878 }
1879 #endif /* CONFIG_MMU */
1880
1881+#ifdef CONFIG_PAX_PAGEEXEC
1882+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1883+{
1884+ long i;
1885+
1886+ printk(KERN_ERR "PAX: bytes at PC: ");
1887+ for (i = 0; i < 20; i++) {
1888+ unsigned char c;
1889+ if (get_user(c, (__force unsigned char __user *)pc+i))
1890+ printk(KERN_CONT "?? ");
1891+ else
1892+ printk(KERN_CONT "%02x ", c);
1893+ }
1894+ printk("\n");
1895+
1896+ printk(KERN_ERR "PAX: bytes at SP-4: ");
1897+ for (i = -1; i < 20; i++) {
1898+ unsigned long c;
1899+ if (get_user(c, (__force unsigned long __user *)sp+i))
1900+ printk(KERN_CONT "???????? ");
1901+ else
1902+ printk(KERN_CONT "%08lx ", c);
1903+ }
1904+ printk("\n");
1905+}
1906+#endif
1907+
1908 /*
1909 * First Level Translation Fault Handler
1910 *
1911@@ -577,6 +611,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1912 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1913 struct siginfo info;
1914
1915+#ifdef CONFIG_PAX_REFCOUNT
1916+ if (fsr_fs(ifsr) == 2) {
1917+ unsigned int bkpt;
1918+
1919+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1920+ current->thread.error_code = ifsr;
1921+ current->thread.trap_no = 0;
1922+ pax_report_refcount_overflow(regs);
1923+ fixup_exception(regs);
1924+ return;
1925+ }
1926+ }
1927+#endif
1928+
1929 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1930 return;
1931
1932diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1933index ce8cb19..3ec539d 100644
1934--- a/arch/arm/mm/mmap.c
1935+++ b/arch/arm/mm/mmap.c
1936@@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1937 if (len > TASK_SIZE)
1938 return -ENOMEM;
1939
1940+#ifdef CONFIG_PAX_RANDMMAP
1941+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1942+#endif
1943+
1944 if (addr) {
1945 if (do_align)
1946 addr = COLOUR_ALIGN(addr, pgoff);
1947@@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1948 addr = PAGE_ALIGN(addr);
1949
1950 vma = find_vma(mm, addr);
1951- if (TASK_SIZE - len >= addr &&
1952- (!vma || addr + len <= vma->vm_start))
1953+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1954 return addr;
1955 }
1956 if (len > mm->cached_hole_size) {
1957- start_addr = addr = mm->free_area_cache;
1958+ start_addr = addr = mm->free_area_cache;
1959 } else {
1960- start_addr = addr = mm->mmap_base;
1961- mm->cached_hole_size = 0;
1962+ start_addr = addr = mm->mmap_base;
1963+ mm->cached_hole_size = 0;
1964 }
1965
1966 full_search:
1967@@ -124,14 +127,14 @@ full_search:
1968 * Start a new search - just in case we missed
1969 * some holes.
1970 */
1971- if (start_addr != TASK_UNMAPPED_BASE) {
1972- start_addr = addr = TASK_UNMAPPED_BASE;
1973+ if (start_addr != mm->mmap_base) {
1974+ start_addr = addr = mm->mmap_base;
1975 mm->cached_hole_size = 0;
1976 goto full_search;
1977 }
1978 return -ENOMEM;
1979 }
1980- if (!vma || addr + len <= vma->vm_start) {
1981+ if (check_heap_stack_gap(vma, addr, len)) {
1982 /*
1983 * Remember the place where we stopped the search:
1984 */
1985@@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1986
1987 if (mmap_is_legacy()) {
1988 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
1989+
1990+#ifdef CONFIG_PAX_RANDMMAP
1991+ if (mm->pax_flags & MF_PAX_RANDMMAP)
1992+ mm->mmap_base += mm->delta_mmap;
1993+#endif
1994+
1995 mm->get_unmapped_area = arch_get_unmapped_area;
1996 mm->unmap_area = arch_unmap_area;
1997 } else {
1998 mm->mmap_base = mmap_base(random_factor);
1999+
2000+#ifdef CONFIG_PAX_RANDMMAP
2001+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2002+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2003+#endif
2004+
2005 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2006 mm->unmap_area = arch_unmap_area_topdown;
2007 }
2008diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2009index fd556f7..af2e7d2 100644
2010--- a/arch/arm/plat-orion/include/plat/addr-map.h
2011+++ b/arch/arm/plat-orion/include/plat/addr-map.h
2012@@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2013 value in bridge_virt_base */
2014 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2015 const int win);
2016-};
2017+} __no_const;
2018
2019 /*
2020 * Information needed to setup one address mapping.
2021diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2022index 71a6827..e7fbc23 100644
2023--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2024+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2025@@ -43,7 +43,7 @@ struct samsung_dma_ops {
2026 int (*started)(unsigned ch);
2027 int (*flush)(unsigned ch);
2028 int (*stop)(unsigned ch);
2029-};
2030+} __no_const;
2031
2032 extern void *samsung_dmadev_get_ops(void);
2033 extern void *s3c_dma_get_ops(void);
2034diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
2035index 5f28cae..3d23723 100644
2036--- a/arch/arm/plat-samsung/include/plat/ehci.h
2037+++ b/arch/arm/plat-samsung/include/plat/ehci.h
2038@@ -14,7 +14,7 @@
2039 struct s5p_ehci_platdata {
2040 int (*phy_init)(struct platform_device *pdev, int type);
2041 int (*phy_exit)(struct platform_device *pdev, int type);
2042-};
2043+} __no_const;
2044
2045 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2046
2047diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2048index c3a58a1..78fbf54 100644
2049--- a/arch/avr32/include/asm/cache.h
2050+++ b/arch/avr32/include/asm/cache.h
2051@@ -1,8 +1,10 @@
2052 #ifndef __ASM_AVR32_CACHE_H
2053 #define __ASM_AVR32_CACHE_H
2054
2055+#include <linux/const.h>
2056+
2057 #define L1_CACHE_SHIFT 5
2058-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2059+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2060
2061 /*
2062 * Memory returned by kmalloc() may be used for DMA, so we must make
2063diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2064index 3b3159b..425ea94 100644
2065--- a/arch/avr32/include/asm/elf.h
2066+++ b/arch/avr32/include/asm/elf.h
2067@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2068 the loader. We need to make sure that it is out of the way of the program
2069 that it will "exec", and that there is sufficient room for the brk. */
2070
2071-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2072+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2073
2074+#ifdef CONFIG_PAX_ASLR
2075+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2076+
2077+#define PAX_DELTA_MMAP_LEN 15
2078+#define PAX_DELTA_STACK_LEN 15
2079+#endif
2080
2081 /* This yields a mask that user programs can use to figure out what
2082 instruction set this CPU supports. This could be done in user space,
2083diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2084index b7f5c68..556135c 100644
2085--- a/arch/avr32/include/asm/kmap_types.h
2086+++ b/arch/avr32/include/asm/kmap_types.h
2087@@ -22,7 +22,8 @@ D(10) KM_IRQ0,
2088 D(11) KM_IRQ1,
2089 D(12) KM_SOFTIRQ0,
2090 D(13) KM_SOFTIRQ1,
2091-D(14) KM_TYPE_NR
2092+D(14) KM_CLEARPAGE,
2093+D(15) KM_TYPE_NR
2094 };
2095
2096 #undef D
2097diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2098index f7040a1..db9f300 100644
2099--- a/arch/avr32/mm/fault.c
2100+++ b/arch/avr32/mm/fault.c
2101@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2102
2103 int exception_trace = 1;
2104
2105+#ifdef CONFIG_PAX_PAGEEXEC
2106+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2107+{
2108+ unsigned long i;
2109+
2110+ printk(KERN_ERR "PAX: bytes at PC: ");
2111+ for (i = 0; i < 20; i++) {
2112+ unsigned char c;
2113+ if (get_user(c, (unsigned char *)pc+i))
2114+ printk(KERN_CONT "???????? ");
2115+ else
2116+ printk(KERN_CONT "%02x ", c);
2117+ }
2118+ printk("\n");
2119+}
2120+#endif
2121+
2122 /*
2123 * This routine handles page faults. It determines the address and the
2124 * problem, and then passes it off to one of the appropriate routines.
2125@@ -156,6 +173,16 @@ bad_area:
2126 up_read(&mm->mmap_sem);
2127
2128 if (user_mode(regs)) {
2129+
2130+#ifdef CONFIG_PAX_PAGEEXEC
2131+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2132+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2133+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2134+ do_group_exit(SIGKILL);
2135+ }
2136+ }
2137+#endif
2138+
2139 if (exception_trace && printk_ratelimit())
2140 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2141 "sp %08lx ecr %lu\n",
2142diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2143index 568885a..f8008df 100644
2144--- a/arch/blackfin/include/asm/cache.h
2145+++ b/arch/blackfin/include/asm/cache.h
2146@@ -7,6 +7,7 @@
2147 #ifndef __ARCH_BLACKFIN_CACHE_H
2148 #define __ARCH_BLACKFIN_CACHE_H
2149
2150+#include <linux/const.h>
2151 #include <linux/linkage.h> /* for asmlinkage */
2152
2153 /*
2154@@ -14,7 +15,7 @@
2155 * Blackfin loads 32 bytes for cache
2156 */
2157 #define L1_CACHE_SHIFT 5
2158-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2159+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2160 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2161
2162 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2163diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2164index aea2718..3639a60 100644
2165--- a/arch/cris/include/arch-v10/arch/cache.h
2166+++ b/arch/cris/include/arch-v10/arch/cache.h
2167@@ -1,8 +1,9 @@
2168 #ifndef _ASM_ARCH_CACHE_H
2169 #define _ASM_ARCH_CACHE_H
2170
2171+#include <linux/const.h>
2172 /* Etrax 100LX have 32-byte cache-lines. */
2173-#define L1_CACHE_BYTES 32
2174 #define L1_CACHE_SHIFT 5
2175+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2176
2177 #endif /* _ASM_ARCH_CACHE_H */
2178diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2179index 1de779f..336fad3 100644
2180--- a/arch/cris/include/arch-v32/arch/cache.h
2181+++ b/arch/cris/include/arch-v32/arch/cache.h
2182@@ -1,11 +1,12 @@
2183 #ifndef _ASM_CRIS_ARCH_CACHE_H
2184 #define _ASM_CRIS_ARCH_CACHE_H
2185
2186+#include <linux/const.h>
2187 #include <arch/hwregs/dma.h>
2188
2189 /* A cache-line is 32 bytes. */
2190-#define L1_CACHE_BYTES 32
2191 #define L1_CACHE_SHIFT 5
2192+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2193
2194 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
2195
2196diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2197index b86329d..6709906 100644
2198--- a/arch/frv/include/asm/atomic.h
2199+++ b/arch/frv/include/asm/atomic.h
2200@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2201 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2202 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2203
2204+#define atomic64_read_unchecked(v) atomic64_read(v)
2205+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2206+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2207+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2208+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2209+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2210+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2211+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2212+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2213+
2214 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2215 {
2216 int c, old;
2217diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2218index 2797163..c2a401d 100644
2219--- a/arch/frv/include/asm/cache.h
2220+++ b/arch/frv/include/asm/cache.h
2221@@ -12,10 +12,11 @@
2222 #ifndef __ASM_CACHE_H
2223 #define __ASM_CACHE_H
2224
2225+#include <linux/const.h>
2226
2227 /* bytes per L1 cache line */
2228 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2229-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2230+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2231
2232 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2233 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2234diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2235index f8e16b2..c73ff79 100644
2236--- a/arch/frv/include/asm/kmap_types.h
2237+++ b/arch/frv/include/asm/kmap_types.h
2238@@ -23,6 +23,7 @@ enum km_type {
2239 KM_IRQ1,
2240 KM_SOFTIRQ0,
2241 KM_SOFTIRQ1,
2242+ KM_CLEARPAGE,
2243 KM_TYPE_NR
2244 };
2245
2246diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2247index 385fd30..6c3d97e 100644
2248--- a/arch/frv/mm/elf-fdpic.c
2249+++ b/arch/frv/mm/elf-fdpic.c
2250@@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2251 if (addr) {
2252 addr = PAGE_ALIGN(addr);
2253 vma = find_vma(current->mm, addr);
2254- if (TASK_SIZE - len >= addr &&
2255- (!vma || addr + len <= vma->vm_start))
2256+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2257 goto success;
2258 }
2259
2260@@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2261 for (; vma; vma = vma->vm_next) {
2262 if (addr > limit)
2263 break;
2264- if (addr + len <= vma->vm_start)
2265+ if (check_heap_stack_gap(vma, addr, len))
2266 goto success;
2267 addr = vma->vm_end;
2268 }
2269@@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2270 for (; vma; vma = vma->vm_next) {
2271 if (addr > limit)
2272 break;
2273- if (addr + len <= vma->vm_start)
2274+ if (check_heap_stack_gap(vma, addr, len))
2275 goto success;
2276 addr = vma->vm_end;
2277 }
2278diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2279index c635028..6d9445a 100644
2280--- a/arch/h8300/include/asm/cache.h
2281+++ b/arch/h8300/include/asm/cache.h
2282@@ -1,8 +1,10 @@
2283 #ifndef __ARCH_H8300_CACHE_H
2284 #define __ARCH_H8300_CACHE_H
2285
2286+#include <linux/const.h>
2287+
2288 /* bytes per L1 cache line */
2289-#define L1_CACHE_BYTES 4
2290+#define L1_CACHE_BYTES _AC(4,UL)
2291
2292 /* m68k-elf-gcc 2.95.2 doesn't like these */
2293
2294diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2295index 0f01de2..d37d309 100644
2296--- a/arch/hexagon/include/asm/cache.h
2297+++ b/arch/hexagon/include/asm/cache.h
2298@@ -21,9 +21,11 @@
2299 #ifndef __ASM_CACHE_H
2300 #define __ASM_CACHE_H
2301
2302+#include <linux/const.h>
2303+
2304 /* Bytes per L1 cache line */
2305-#define L1_CACHE_SHIFT (5)
2306-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2307+#define L1_CACHE_SHIFT 5
2308+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2309
2310 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2311 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2312diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2313index 7d91166..88ab87e 100644
2314--- a/arch/ia64/include/asm/atomic.h
2315+++ b/arch/ia64/include/asm/atomic.h
2316@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2317 #define atomic64_inc(v) atomic64_add(1, (v))
2318 #define atomic64_dec(v) atomic64_sub(1, (v))
2319
2320+#define atomic64_read_unchecked(v) atomic64_read(v)
2321+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2322+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2323+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2324+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2325+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2326+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2327+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2328+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2329+
2330 /* Atomic operations are already serializing */
2331 #define smp_mb__before_atomic_dec() barrier()
2332 #define smp_mb__after_atomic_dec() barrier()
2333diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2334index 988254a..e1ee885 100644
2335--- a/arch/ia64/include/asm/cache.h
2336+++ b/arch/ia64/include/asm/cache.h
2337@@ -1,6 +1,7 @@
2338 #ifndef _ASM_IA64_CACHE_H
2339 #define _ASM_IA64_CACHE_H
2340
2341+#include <linux/const.h>
2342
2343 /*
2344 * Copyright (C) 1998-2000 Hewlett-Packard Co
2345@@ -9,7 +10,7 @@
2346
2347 /* Bytes per L1 (data) cache line. */
2348 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2349-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2350+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2351
2352 #ifdef CONFIG_SMP
2353 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2354diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2355index b5298eb..67c6e62 100644
2356--- a/arch/ia64/include/asm/elf.h
2357+++ b/arch/ia64/include/asm/elf.h
2358@@ -42,6 +42,13 @@
2359 */
2360 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2361
2362+#ifdef CONFIG_PAX_ASLR
2363+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2364+
2365+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2366+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2367+#endif
2368+
2369 #define PT_IA_64_UNWIND 0x70000001
2370
2371 /* IA-64 relocations: */
2372diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2373index 96a8d92..617a1cf 100644
2374--- a/arch/ia64/include/asm/pgalloc.h
2375+++ b/arch/ia64/include/asm/pgalloc.h
2376@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2377 pgd_val(*pgd_entry) = __pa(pud);
2378 }
2379
2380+static inline void
2381+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2382+{
2383+ pgd_populate(mm, pgd_entry, pud);
2384+}
2385+
2386 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2387 {
2388 return quicklist_alloc(0, GFP_KERNEL, NULL);
2389@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2390 pud_val(*pud_entry) = __pa(pmd);
2391 }
2392
2393+static inline void
2394+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2395+{
2396+ pud_populate(mm, pud_entry, pmd);
2397+}
2398+
2399 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2400 {
2401 return quicklist_alloc(0, GFP_KERNEL, NULL);
2402diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2403index 815810c..d60bd4c 100644
2404--- a/arch/ia64/include/asm/pgtable.h
2405+++ b/arch/ia64/include/asm/pgtable.h
2406@@ -12,7 +12,7 @@
2407 * David Mosberger-Tang <davidm@hpl.hp.com>
2408 */
2409
2410-
2411+#include <linux/const.h>
2412 #include <asm/mman.h>
2413 #include <asm/page.h>
2414 #include <asm/processor.h>
2415@@ -142,6 +142,17 @@
2416 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2417 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2418 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2419+
2420+#ifdef CONFIG_PAX_PAGEEXEC
2421+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2422+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2423+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2424+#else
2425+# define PAGE_SHARED_NOEXEC PAGE_SHARED
2426+# define PAGE_READONLY_NOEXEC PAGE_READONLY
2427+# define PAGE_COPY_NOEXEC PAGE_COPY
2428+#endif
2429+
2430 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2431 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2432 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2433diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2434index 54ff557..70c88b7 100644
2435--- a/arch/ia64/include/asm/spinlock.h
2436+++ b/arch/ia64/include/asm/spinlock.h
2437@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2438 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2439
2440 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2441- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2442+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2443 }
2444
2445 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2446diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2447index 449c8c0..432a3d2 100644
2448--- a/arch/ia64/include/asm/uaccess.h
2449+++ b/arch/ia64/include/asm/uaccess.h
2450@@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2451 const void *__cu_from = (from); \
2452 long __cu_len = (n); \
2453 \
2454- if (__access_ok(__cu_to, __cu_len, get_fs())) \
2455+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2456 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2457 __cu_len; \
2458 })
2459@@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2460 long __cu_len = (n); \
2461 \
2462 __chk_user_ptr(__cu_from); \
2463- if (__access_ok(__cu_from, __cu_len, get_fs())) \
2464+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2465 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2466 __cu_len; \
2467 })
2468diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2469index 24603be..948052d 100644
2470--- a/arch/ia64/kernel/module.c
2471+++ b/arch/ia64/kernel/module.c
2472@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2473 void
2474 module_free (struct module *mod, void *module_region)
2475 {
2476- if (mod && mod->arch.init_unw_table &&
2477- module_region == mod->module_init) {
2478+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2479 unw_remove_unwind_table(mod->arch.init_unw_table);
2480 mod->arch.init_unw_table = NULL;
2481 }
2482@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2483 }
2484
2485 static inline int
2486+in_init_rx (const struct module *mod, uint64_t addr)
2487+{
2488+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2489+}
2490+
2491+static inline int
2492+in_init_rw (const struct module *mod, uint64_t addr)
2493+{
2494+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2495+}
2496+
2497+static inline int
2498 in_init (const struct module *mod, uint64_t addr)
2499 {
2500- return addr - (uint64_t) mod->module_init < mod->init_size;
2501+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2502+}
2503+
2504+static inline int
2505+in_core_rx (const struct module *mod, uint64_t addr)
2506+{
2507+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2508+}
2509+
2510+static inline int
2511+in_core_rw (const struct module *mod, uint64_t addr)
2512+{
2513+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2514 }
2515
2516 static inline int
2517 in_core (const struct module *mod, uint64_t addr)
2518 {
2519- return addr - (uint64_t) mod->module_core < mod->core_size;
2520+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2521 }
2522
2523 static inline int
2524@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2525 break;
2526
2527 case RV_BDREL:
2528- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2529+ if (in_init_rx(mod, val))
2530+ val -= (uint64_t) mod->module_init_rx;
2531+ else if (in_init_rw(mod, val))
2532+ val -= (uint64_t) mod->module_init_rw;
2533+ else if (in_core_rx(mod, val))
2534+ val -= (uint64_t) mod->module_core_rx;
2535+ else if (in_core_rw(mod, val))
2536+ val -= (uint64_t) mod->module_core_rw;
2537 break;
2538
2539 case RV_LTV:
2540@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2541 * addresses have been selected...
2542 */
2543 uint64_t gp;
2544- if (mod->core_size > MAX_LTOFF)
2545+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2546 /*
2547 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2548 * at the end of the module.
2549 */
2550- gp = mod->core_size - MAX_LTOFF / 2;
2551+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2552 else
2553- gp = mod->core_size / 2;
2554- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2555+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2556+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2557 mod->arch.gp = gp;
2558 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2559 }
2560diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2561index 609d500..7dde2a8 100644
2562--- a/arch/ia64/kernel/sys_ia64.c
2563+++ b/arch/ia64/kernel/sys_ia64.c
2564@@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2565 if (REGION_NUMBER(addr) == RGN_HPAGE)
2566 addr = 0;
2567 #endif
2568+
2569+#ifdef CONFIG_PAX_RANDMMAP
2570+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2571+ addr = mm->free_area_cache;
2572+ else
2573+#endif
2574+
2575 if (!addr)
2576 addr = mm->free_area_cache;
2577
2578@@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2579 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2580 /* At this point: (!vma || addr < vma->vm_end). */
2581 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2582- if (start_addr != TASK_UNMAPPED_BASE) {
2583+ if (start_addr != mm->mmap_base) {
2584 /* Start a new search --- just in case we missed some holes. */
2585- addr = TASK_UNMAPPED_BASE;
2586+ addr = mm->mmap_base;
2587 goto full_search;
2588 }
2589 return -ENOMEM;
2590 }
2591- if (!vma || addr + len <= vma->vm_start) {
2592+ if (check_heap_stack_gap(vma, addr, len)) {
2593 /* Remember the address where we stopped this search: */
2594 mm->free_area_cache = addr + len;
2595 return addr;
2596diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2597index 0ccb28f..8992469 100644
2598--- a/arch/ia64/kernel/vmlinux.lds.S
2599+++ b/arch/ia64/kernel/vmlinux.lds.S
2600@@ -198,7 +198,7 @@ SECTIONS {
2601 /* Per-cpu data: */
2602 . = ALIGN(PERCPU_PAGE_SIZE);
2603 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2604- __phys_per_cpu_start = __per_cpu_load;
2605+ __phys_per_cpu_start = per_cpu_load;
2606 /*
2607 * ensure percpu data fits
2608 * into percpu page size
2609diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2610index 02d29c2..ea893df 100644
2611--- a/arch/ia64/mm/fault.c
2612+++ b/arch/ia64/mm/fault.c
2613@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2614 return pte_present(pte);
2615 }
2616
2617+#ifdef CONFIG_PAX_PAGEEXEC
2618+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2619+{
2620+ unsigned long i;
2621+
2622+ printk(KERN_ERR "PAX: bytes at PC: ");
2623+ for (i = 0; i < 8; i++) {
2624+ unsigned int c;
2625+ if (get_user(c, (unsigned int *)pc+i))
2626+ printk(KERN_CONT "???????? ");
2627+ else
2628+ printk(KERN_CONT "%08x ", c);
2629+ }
2630+ printk("\n");
2631+}
2632+#endif
2633+
2634 void __kprobes
2635 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2636 {
2637@@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2638 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2639 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2640
2641- if ((vma->vm_flags & mask) != mask)
2642+ if ((vma->vm_flags & mask) != mask) {
2643+
2644+#ifdef CONFIG_PAX_PAGEEXEC
2645+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2646+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2647+ goto bad_area;
2648+
2649+ up_read(&mm->mmap_sem);
2650+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2651+ do_group_exit(SIGKILL);
2652+ }
2653+#endif
2654+
2655 goto bad_area;
2656
2657+ }
2658+
2659 /*
2660 * If for any reason at all we couldn't handle the fault, make
2661 * sure we exit gracefully rather than endlessly redo the
2662diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2663index 5ca674b..e0e1b70 100644
2664--- a/arch/ia64/mm/hugetlbpage.c
2665+++ b/arch/ia64/mm/hugetlbpage.c
2666@@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2667 /* At this point: (!vmm || addr < vmm->vm_end). */
2668 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2669 return -ENOMEM;
2670- if (!vmm || (addr + len) <= vmm->vm_start)
2671+ if (check_heap_stack_gap(vmm, addr, len))
2672 return addr;
2673 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2674 }
2675diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2676index 0eab454..bd794f2 100644
2677--- a/arch/ia64/mm/init.c
2678+++ b/arch/ia64/mm/init.c
2679@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2680 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2681 vma->vm_end = vma->vm_start + PAGE_SIZE;
2682 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2683+
2684+#ifdef CONFIG_PAX_PAGEEXEC
2685+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2686+ vma->vm_flags &= ~VM_EXEC;
2687+
2688+#ifdef CONFIG_PAX_MPROTECT
2689+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
2690+ vma->vm_flags &= ~VM_MAYEXEC;
2691+#endif
2692+
2693+ }
2694+#endif
2695+
2696 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2697 down_write(&current->mm->mmap_sem);
2698 if (insert_vm_struct(current->mm, vma)) {
2699diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2700index 40b3ee9..8c2c112 100644
2701--- a/arch/m32r/include/asm/cache.h
2702+++ b/arch/m32r/include/asm/cache.h
2703@@ -1,8 +1,10 @@
2704 #ifndef _ASM_M32R_CACHE_H
2705 #define _ASM_M32R_CACHE_H
2706
2707+#include <linux/const.h>
2708+
2709 /* L1 cache line size */
2710 #define L1_CACHE_SHIFT 4
2711-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2712+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2713
2714 #endif /* _ASM_M32R_CACHE_H */
2715diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2716index 82abd15..d95ae5d 100644
2717--- a/arch/m32r/lib/usercopy.c
2718+++ b/arch/m32r/lib/usercopy.c
2719@@ -14,6 +14,9 @@
2720 unsigned long
2721 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2722 {
2723+ if ((long)n < 0)
2724+ return n;
2725+
2726 prefetch(from);
2727 if (access_ok(VERIFY_WRITE, to, n))
2728 __copy_user(to,from,n);
2729@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2730 unsigned long
2731 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2732 {
2733+ if ((long)n < 0)
2734+ return n;
2735+
2736 prefetchw(to);
2737 if (access_ok(VERIFY_READ, from, n))
2738 __copy_user_zeroing(to,from,n);
2739diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2740index 0395c51..5f26031 100644
2741--- a/arch/m68k/include/asm/cache.h
2742+++ b/arch/m68k/include/asm/cache.h
2743@@ -4,9 +4,11 @@
2744 #ifndef __ARCH_M68K_CACHE_H
2745 #define __ARCH_M68K_CACHE_H
2746
2747+#include <linux/const.h>
2748+
2749 /* bytes per L1 cache line */
2750 #define L1_CACHE_SHIFT 4
2751-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2752+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2753
2754 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2755
2756diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2757index 4efe96a..60e8699 100644
2758--- a/arch/microblaze/include/asm/cache.h
2759+++ b/arch/microblaze/include/asm/cache.h
2760@@ -13,11 +13,12 @@
2761 #ifndef _ASM_MICROBLAZE_CACHE_H
2762 #define _ASM_MICROBLAZE_CACHE_H
2763
2764+#include <linux/const.h>
2765 #include <asm/registers.h>
2766
2767 #define L1_CACHE_SHIFT 5
2768 /* word-granular cache in microblaze */
2769-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2770+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2771
2772 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2773
2774diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2775index 3f4c5cb..3439c6e 100644
2776--- a/arch/mips/include/asm/atomic.h
2777+++ b/arch/mips/include/asm/atomic.h
2778@@ -21,6 +21,10 @@
2779 #include <asm/cmpxchg.h>
2780 #include <asm/war.h>
2781
2782+#ifdef CONFIG_GENERIC_ATOMIC64
2783+#include <asm-generic/atomic64.h>
2784+#endif
2785+
2786 #define ATOMIC_INIT(i) { (i) }
2787
2788 /*
2789@@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2790 */
2791 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2792
2793+#define atomic64_read_unchecked(v) atomic64_read(v)
2794+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2795+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2796+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2797+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2798+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2799+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2800+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2801+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2802+
2803 #endif /* CONFIG_64BIT */
2804
2805 /*
2806diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2807index b4db69f..8f3b093 100644
2808--- a/arch/mips/include/asm/cache.h
2809+++ b/arch/mips/include/asm/cache.h
2810@@ -9,10 +9,11 @@
2811 #ifndef _ASM_CACHE_H
2812 #define _ASM_CACHE_H
2813
2814+#include <linux/const.h>
2815 #include <kmalloc.h>
2816
2817 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2818-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2819+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2820
2821 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2822 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2823diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2824index 455c0ac..ad65fbe 100644
2825--- a/arch/mips/include/asm/elf.h
2826+++ b/arch/mips/include/asm/elf.h
2827@@ -372,13 +372,16 @@ extern const char *__elf_platform;
2828 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2829 #endif
2830
2831+#ifdef CONFIG_PAX_ASLR
2832+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2833+
2834+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2835+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2836+#endif
2837+
2838 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2839 struct linux_binprm;
2840 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2841 int uses_interp);
2842
2843-struct mm_struct;
2844-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2845-#define arch_randomize_brk arch_randomize_brk
2846-
2847 #endif /* _ASM_ELF_H */
2848diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2849index c1f6afa..38cc6e9 100644
2850--- a/arch/mips/include/asm/exec.h
2851+++ b/arch/mips/include/asm/exec.h
2852@@ -12,6 +12,6 @@
2853 #ifndef _ASM_EXEC_H
2854 #define _ASM_EXEC_H
2855
2856-extern unsigned long arch_align_stack(unsigned long sp);
2857+#define arch_align_stack(x) ((x) & ~0xfUL)
2858
2859 #endif /* _ASM_EXEC_H */
2860diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2861index da9bd7d..91aa7ab 100644
2862--- a/arch/mips/include/asm/page.h
2863+++ b/arch/mips/include/asm/page.h
2864@@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2865 #ifdef CONFIG_CPU_MIPS32
2866 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2867 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2868- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2869+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2870 #else
2871 typedef struct { unsigned long long pte; } pte_t;
2872 #define pte_val(x) ((x).pte)
2873diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2874index 881d18b..cea38bc 100644
2875--- a/arch/mips/include/asm/pgalloc.h
2876+++ b/arch/mips/include/asm/pgalloc.h
2877@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2878 {
2879 set_pud(pud, __pud((unsigned long)pmd));
2880 }
2881+
2882+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2883+{
2884+ pud_populate(mm, pud, pmd);
2885+}
2886 #endif
2887
2888 /*
2889diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2890index 0d85d8e..ec71487 100644
2891--- a/arch/mips/include/asm/thread_info.h
2892+++ b/arch/mips/include/asm/thread_info.h
2893@@ -123,6 +123,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2894 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2895 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2896 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2897+/* li takes a 32bit immediate */
2898+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2899 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2900
2901 #ifdef CONFIG_MIPS32_O32
2902@@ -146,15 +148,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2903 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2904 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2905 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2906+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2907+
2908+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2909
2910 /* work to do in syscall_trace_leave() */
2911-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2912+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2913
2914 /* work to do on interrupt/exception return */
2915 #define _TIF_WORK_MASK (0x0000ffef & \
2916 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2917 /* work to do on any return to u-space */
2918-#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2919+#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2920
2921 #endif /* __KERNEL__ */
2922
2923diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2924index 9fdd8bc..4bd7f1a 100644
2925--- a/arch/mips/kernel/binfmt_elfn32.c
2926+++ b/arch/mips/kernel/binfmt_elfn32.c
2927@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2928 #undef ELF_ET_DYN_BASE
2929 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2930
2931+#ifdef CONFIG_PAX_ASLR
2932+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2933+
2934+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2935+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2936+#endif
2937+
2938 #include <asm/processor.h>
2939 #include <linux/module.h>
2940 #include <linux/elfcore.h>
2941diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2942index ff44823..97f8906 100644
2943--- a/arch/mips/kernel/binfmt_elfo32.c
2944+++ b/arch/mips/kernel/binfmt_elfo32.c
2945@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2946 #undef ELF_ET_DYN_BASE
2947 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2948
2949+#ifdef CONFIG_PAX_ASLR
2950+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2951+
2952+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2953+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2954+#endif
2955+
2956 #include <asm/processor.h>
2957
2958 /*
2959diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2960index e9a5fd7..378809a 100644
2961--- a/arch/mips/kernel/process.c
2962+++ b/arch/mips/kernel/process.c
2963@@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
2964 out:
2965 return pc;
2966 }
2967-
2968-/*
2969- * Don't forget that the stack pointer must be aligned on a 8 bytes
2970- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2971- */
2972-unsigned long arch_align_stack(unsigned long sp)
2973-{
2974- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2975- sp -= get_random_int() & ~PAGE_MASK;
2976-
2977- return sp & ALMASK;
2978-}
2979diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2980index 7c24c29..e2f1981 100644
2981--- a/arch/mips/kernel/ptrace.c
2982+++ b/arch/mips/kernel/ptrace.c
2983@@ -528,6 +528,10 @@ static inline int audit_arch(void)
2984 return arch;
2985 }
2986
2987+#ifdef CONFIG_GRKERNSEC_SETXID
2988+extern void gr_delayed_cred_worker(void);
2989+#endif
2990+
2991 /*
2992 * Notification of system call entry/exit
2993 * - triggered by current->work.syscall_trace
2994@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
2995 /* do the secure computing check first */
2996 secure_computing(regs->regs[2]);
2997
2998+#ifdef CONFIG_GRKERNSEC_SETXID
2999+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3000+ gr_delayed_cred_worker();
3001+#endif
3002+
3003 if (!(current->ptrace & PT_PTRACED))
3004 goto out;
3005
3006diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3007index a632bc1..0b77c7c 100644
3008--- a/arch/mips/kernel/scall32-o32.S
3009+++ b/arch/mips/kernel/scall32-o32.S
3010@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3011
3012 stack_done:
3013 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3014- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3015+ li t1, _TIF_SYSCALL_WORK
3016 and t0, t1
3017 bnez t0, syscall_trace_entry # -> yes
3018
3019diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3020index 3b5a5e9..e1ee86d 100644
3021--- a/arch/mips/kernel/scall64-64.S
3022+++ b/arch/mips/kernel/scall64-64.S
3023@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3024
3025 sd a3, PT_R26(sp) # save a3 for syscall restarting
3026
3027- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3028+ li t1, _TIF_SYSCALL_WORK
3029 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3030 and t0, t1, t0
3031 bnez t0, syscall_trace_entry
3032diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3033index 6be6f70..1859577 100644
3034--- a/arch/mips/kernel/scall64-n32.S
3035+++ b/arch/mips/kernel/scall64-n32.S
3036@@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3037
3038 sd a3, PT_R26(sp) # save a3 for syscall restarting
3039
3040- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3041+ li t1, _TIF_SYSCALL_WORK
3042 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3043 and t0, t1, t0
3044 bnez t0, n32_syscall_trace_entry
3045diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3046index 5422855..74e63a3 100644
3047--- a/arch/mips/kernel/scall64-o32.S
3048+++ b/arch/mips/kernel/scall64-o32.S
3049@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3050 PTR 4b, bad_stack
3051 .previous
3052
3053- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3054+ li t1, _TIF_SYSCALL_WORK
3055 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3056 and t0, t1, t0
3057 bnez t0, trace_a_syscall
3058diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3059index c14f6df..537e729 100644
3060--- a/arch/mips/mm/fault.c
3061+++ b/arch/mips/mm/fault.c
3062@@ -27,6 +27,23 @@
3063 #include <asm/highmem.h> /* For VMALLOC_END */
3064 #include <linux/kdebug.h>
3065
3066+#ifdef CONFIG_PAX_PAGEEXEC
3067+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3068+{
3069+ unsigned long i;
3070+
3071+ printk(KERN_ERR "PAX: bytes at PC: ");
3072+ for (i = 0; i < 5; i++) {
3073+ unsigned int c;
3074+ if (get_user(c, (unsigned int *)pc+i))
3075+ printk(KERN_CONT "???????? ");
3076+ else
3077+ printk(KERN_CONT "%08x ", c);
3078+ }
3079+ printk("\n");
3080+}
3081+#endif
3082+
3083 /*
3084 * This routine handles page faults. It determines the address,
3085 * and the problem, and then passes it off to one of the appropriate
3086diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3087index 302d779..7d35bf8 100644
3088--- a/arch/mips/mm/mmap.c
3089+++ b/arch/mips/mm/mmap.c
3090@@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3091 do_color_align = 1;
3092
3093 /* requesting a specific address */
3094+
3095+#ifdef CONFIG_PAX_RANDMMAP
3096+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3097+#endif
3098+
3099 if (addr) {
3100 if (do_color_align)
3101 addr = COLOUR_ALIGN(addr, pgoff);
3102@@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3103 addr = PAGE_ALIGN(addr);
3104
3105 vma = find_vma(mm, addr);
3106- if (TASK_SIZE - len >= addr &&
3107- (!vma || addr + len <= vma->vm_start))
3108+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3109 return addr;
3110 }
3111
3112@@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3113 /* At this point: (!vma || addr < vma->vm_end). */
3114 if (TASK_SIZE - len < addr)
3115 return -ENOMEM;
3116- if (!vma || addr + len <= vma->vm_start)
3117+ if (check_heap_stack_gap(vmm, addr, len))
3118 return addr;
3119 addr = vma->vm_end;
3120 if (do_color_align)
3121@@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3122 /* make sure it can fit in the remaining address space */
3123 if (likely(addr > len)) {
3124 vma = find_vma(mm, addr - len);
3125- if (!vma || addr <= vma->vm_start) {
3126+ if (check_heap_stack_gap(vmm, addr - len, len))
3127 /* cache the address as a hint for next time */
3128 return mm->free_area_cache = addr - len;
3129 }
3130@@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3131 * return with success:
3132 */
3133 vma = find_vma(mm, addr);
3134- if (likely(!vma || addr + len <= vma->vm_start)) {
3135+ if (check_heap_stack_gap(vmm, addr, len)) {
3136 /* cache the address as a hint for next time */
3137 return mm->free_area_cache = addr;
3138 }
3139@@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3140 mm->unmap_area = arch_unmap_area_topdown;
3141 }
3142 }
3143-
3144-static inline unsigned long brk_rnd(void)
3145-{
3146- unsigned long rnd = get_random_int();
3147-
3148- rnd = rnd << PAGE_SHIFT;
3149- /* 8MB for 32bit, 256MB for 64bit */
3150- if (TASK_IS_32BIT_ADDR)
3151- rnd = rnd & 0x7ffffful;
3152- else
3153- rnd = rnd & 0xffffffful;
3154-
3155- return rnd;
3156-}
3157-
3158-unsigned long arch_randomize_brk(struct mm_struct *mm)
3159-{
3160- unsigned long base = mm->brk;
3161- unsigned long ret;
3162-
3163- ret = PAGE_ALIGN(base + brk_rnd());
3164-
3165- if (ret < mm->brk)
3166- return mm->brk;
3167-
3168- return ret;
3169-}
3170diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3171index 967d144..db12197 100644
3172--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3173+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3174@@ -11,12 +11,14 @@
3175 #ifndef _ASM_PROC_CACHE_H
3176 #define _ASM_PROC_CACHE_H
3177
3178+#include <linux/const.h>
3179+
3180 /* L1 cache */
3181
3182 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3183 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3184-#define L1_CACHE_BYTES 16 /* bytes per entry */
3185 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3186+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3187 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3188
3189 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3190diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3191index bcb5df2..84fabd2 100644
3192--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3193+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3194@@ -16,13 +16,15 @@
3195 #ifndef _ASM_PROC_CACHE_H
3196 #define _ASM_PROC_CACHE_H
3197
3198+#include <linux/const.h>
3199+
3200 /*
3201 * L1 cache
3202 */
3203 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3204 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3205-#define L1_CACHE_BYTES 32 /* bytes per entry */
3206 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3207+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3208 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3209
3210 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3211diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3212index 4ce7a01..449202a 100644
3213--- a/arch/openrisc/include/asm/cache.h
3214+++ b/arch/openrisc/include/asm/cache.h
3215@@ -19,11 +19,13 @@
3216 #ifndef __ASM_OPENRISC_CACHE_H
3217 #define __ASM_OPENRISC_CACHE_H
3218
3219+#include <linux/const.h>
3220+
3221 /* FIXME: How can we replace these with values from the CPU...
3222 * they shouldn't be hard-coded!
3223 */
3224
3225-#define L1_CACHE_BYTES 16
3226 #define L1_CACHE_SHIFT 4
3227+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3228
3229 #endif /* __ASM_OPENRISC_CACHE_H */
3230diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3231index 6c6defc..d30653d 100644
3232--- a/arch/parisc/include/asm/atomic.h
3233+++ b/arch/parisc/include/asm/atomic.h
3234@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3235
3236 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3237
3238+#define atomic64_read_unchecked(v) atomic64_read(v)
3239+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3240+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3241+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3242+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3243+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3244+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3245+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3246+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3247+
3248 #endif /* !CONFIG_64BIT */
3249
3250
3251diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3252index 47f11c7..3420df2 100644
3253--- a/arch/parisc/include/asm/cache.h
3254+++ b/arch/parisc/include/asm/cache.h
3255@@ -5,6 +5,7 @@
3256 #ifndef __ARCH_PARISC_CACHE_H
3257 #define __ARCH_PARISC_CACHE_H
3258
3259+#include <linux/const.h>
3260
3261 /*
3262 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3263@@ -15,13 +16,13 @@
3264 * just ruin performance.
3265 */
3266 #ifdef CONFIG_PA20
3267-#define L1_CACHE_BYTES 64
3268 #define L1_CACHE_SHIFT 6
3269 #else
3270-#define L1_CACHE_BYTES 32
3271 #define L1_CACHE_SHIFT 5
3272 #endif
3273
3274+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3275+
3276 #ifndef __ASSEMBLY__
3277
3278 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3279diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3280index 19f6cb1..6c78cf2 100644
3281--- a/arch/parisc/include/asm/elf.h
3282+++ b/arch/parisc/include/asm/elf.h
3283@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3284
3285 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3286
3287+#ifdef CONFIG_PAX_ASLR
3288+#define PAX_ELF_ET_DYN_BASE 0x10000UL
3289+
3290+#define PAX_DELTA_MMAP_LEN 16
3291+#define PAX_DELTA_STACK_LEN 16
3292+#endif
3293+
3294 /* This yields a mask that user programs can use to figure out what
3295 instruction set this CPU supports. This could be done in user space,
3296 but it's not easy, and we've already done it here. */
3297diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3298index fc987a1..6e068ef 100644
3299--- a/arch/parisc/include/asm/pgalloc.h
3300+++ b/arch/parisc/include/asm/pgalloc.h
3301@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3302 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3303 }
3304
3305+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3306+{
3307+ pgd_populate(mm, pgd, pmd);
3308+}
3309+
3310 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3311 {
3312 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3313@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3314 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3315 #define pmd_free(mm, x) do { } while (0)
3316 #define pgd_populate(mm, pmd, pte) BUG()
3317+#define pgd_populate_kernel(mm, pmd, pte) BUG()
3318
3319 #endif
3320
3321diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3322index ee99f23..802b0a1 100644
3323--- a/arch/parisc/include/asm/pgtable.h
3324+++ b/arch/parisc/include/asm/pgtable.h
3325@@ -212,6 +212,17 @@ struct vm_area_struct;
3326 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3327 #define PAGE_COPY PAGE_EXECREAD
3328 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3329+
3330+#ifdef CONFIG_PAX_PAGEEXEC
3331+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3332+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3333+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3334+#else
3335+# define PAGE_SHARED_NOEXEC PAGE_SHARED
3336+# define PAGE_COPY_NOEXEC PAGE_COPY
3337+# define PAGE_READONLY_NOEXEC PAGE_READONLY
3338+#endif
3339+
3340 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3341 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3342 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3343diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3344index 9ac0660..6ed15c4 100644
3345--- a/arch/parisc/include/asm/uaccess.h
3346+++ b/arch/parisc/include/asm/uaccess.h
3347@@ -252,10 +252,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3348 const void __user *from,
3349 unsigned long n)
3350 {
3351- int sz = __compiletime_object_size(to);
3352+ size_t sz = __compiletime_object_size(to);
3353 int ret = -EFAULT;
3354
3355- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3356+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3357 ret = __copy_from_user(to, from, n);
3358 else
3359 copy_from_user_overflow();
3360diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3361index 5e34ccf..672bc9c 100644
3362--- a/arch/parisc/kernel/module.c
3363+++ b/arch/parisc/kernel/module.c
3364@@ -98,16 +98,38 @@
3365
3366 /* three functions to determine where in the module core
3367 * or init pieces the location is */
3368+static inline int in_init_rx(struct module *me, void *loc)
3369+{
3370+ return (loc >= me->module_init_rx &&
3371+ loc < (me->module_init_rx + me->init_size_rx));
3372+}
3373+
3374+static inline int in_init_rw(struct module *me, void *loc)
3375+{
3376+ return (loc >= me->module_init_rw &&
3377+ loc < (me->module_init_rw + me->init_size_rw));
3378+}
3379+
3380 static inline int in_init(struct module *me, void *loc)
3381 {
3382- return (loc >= me->module_init &&
3383- loc <= (me->module_init + me->init_size));
3384+ return in_init_rx(me, loc) || in_init_rw(me, loc);
3385+}
3386+
3387+static inline int in_core_rx(struct module *me, void *loc)
3388+{
3389+ return (loc >= me->module_core_rx &&
3390+ loc < (me->module_core_rx + me->core_size_rx));
3391+}
3392+
3393+static inline int in_core_rw(struct module *me, void *loc)
3394+{
3395+ return (loc >= me->module_core_rw &&
3396+ loc < (me->module_core_rw + me->core_size_rw));
3397 }
3398
3399 static inline int in_core(struct module *me, void *loc)
3400 {
3401- return (loc >= me->module_core &&
3402- loc <= (me->module_core + me->core_size));
3403+ return in_core_rx(me, loc) || in_core_rw(me, loc);
3404 }
3405
3406 static inline int in_local(struct module *me, void *loc)
3407@@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3408 }
3409
3410 /* align things a bit */
3411- me->core_size = ALIGN(me->core_size, 16);
3412- me->arch.got_offset = me->core_size;
3413- me->core_size += gots * sizeof(struct got_entry);
3414+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
3415+ me->arch.got_offset = me->core_size_rw;
3416+ me->core_size_rw += gots * sizeof(struct got_entry);
3417
3418- me->core_size = ALIGN(me->core_size, 16);
3419- me->arch.fdesc_offset = me->core_size;
3420- me->core_size += fdescs * sizeof(Elf_Fdesc);
3421+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
3422+ me->arch.fdesc_offset = me->core_size_rw;
3423+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3424
3425 me->arch.got_max = gots;
3426 me->arch.fdesc_max = fdescs;
3427@@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3428
3429 BUG_ON(value == 0);
3430
3431- got = me->module_core + me->arch.got_offset;
3432+ got = me->module_core_rw + me->arch.got_offset;
3433 for (i = 0; got[i].addr; i++)
3434 if (got[i].addr == value)
3435 goto out;
3436@@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3437 #ifdef CONFIG_64BIT
3438 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3439 {
3440- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3441+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3442
3443 if (!value) {
3444 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3445@@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3446
3447 /* Create new one */
3448 fdesc->addr = value;
3449- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3450+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3451 return (Elf_Addr)fdesc;
3452 }
3453 #endif /* CONFIG_64BIT */
3454@@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3455
3456 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3457 end = table + sechdrs[me->arch.unwind_section].sh_size;
3458- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3459+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3460
3461 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3462 me->arch.unwind_section, table, end, gp);
3463diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3464index c9b9322..02d8940 100644
3465--- a/arch/parisc/kernel/sys_parisc.c
3466+++ b/arch/parisc/kernel/sys_parisc.c
3467@@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3468 /* At this point: (!vma || addr < vma->vm_end). */
3469 if (TASK_SIZE - len < addr)
3470 return -ENOMEM;
3471- if (!vma || addr + len <= vma->vm_start)
3472+ if (check_heap_stack_gap(vma, addr, len))
3473 return addr;
3474 addr = vma->vm_end;
3475 }
3476@@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3477 /* At this point: (!vma || addr < vma->vm_end). */
3478 if (TASK_SIZE - len < addr)
3479 return -ENOMEM;
3480- if (!vma || addr + len <= vma->vm_start)
3481+ if (check_heap_stack_gap(vma, addr, len))
3482 return addr;
3483 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3484 if (addr < vma->vm_end) /* handle wraparound */
3485@@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3486 if (flags & MAP_FIXED)
3487 return addr;
3488 if (!addr)
3489- addr = TASK_UNMAPPED_BASE;
3490+ addr = current->mm->mmap_base;
3491
3492 if (filp) {
3493 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3494diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3495index 45ba99f..8e22c33 100644
3496--- a/arch/parisc/kernel/traps.c
3497+++ b/arch/parisc/kernel/traps.c
3498@@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3499
3500 down_read(&current->mm->mmap_sem);
3501 vma = find_vma(current->mm,regs->iaoq[0]);
3502- if (vma && (regs->iaoq[0] >= vma->vm_start)
3503- && (vma->vm_flags & VM_EXEC)) {
3504-
3505+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3506 fault_address = regs->iaoq[0];
3507 fault_space = regs->iasq[0];
3508
3509diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3510index 18162ce..94de376 100644
3511--- a/arch/parisc/mm/fault.c
3512+++ b/arch/parisc/mm/fault.c
3513@@ -15,6 +15,7 @@
3514 #include <linux/sched.h>
3515 #include <linux/interrupt.h>
3516 #include <linux/module.h>
3517+#include <linux/unistd.h>
3518
3519 #include <asm/uaccess.h>
3520 #include <asm/traps.h>
3521@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3522 static unsigned long
3523 parisc_acctyp(unsigned long code, unsigned int inst)
3524 {
3525- if (code == 6 || code == 16)
3526+ if (code == 6 || code == 7 || code == 16)
3527 return VM_EXEC;
3528
3529 switch (inst & 0xf0000000) {
3530@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3531 }
3532 #endif
3533
3534+#ifdef CONFIG_PAX_PAGEEXEC
3535+/*
3536+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3537+ *
3538+ * returns 1 when task should be killed
3539+ * 2 when rt_sigreturn trampoline was detected
3540+ * 3 when unpatched PLT trampoline was detected
3541+ */
3542+static int pax_handle_fetch_fault(struct pt_regs *regs)
3543+{
3544+
3545+#ifdef CONFIG_PAX_EMUPLT
3546+ int err;
3547+
3548+ do { /* PaX: unpatched PLT emulation */
3549+ unsigned int bl, depwi;
3550+
3551+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3552+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3553+
3554+ if (err)
3555+ break;
3556+
3557+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3558+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3559+
3560+ err = get_user(ldw, (unsigned int *)addr);
3561+ err |= get_user(bv, (unsigned int *)(addr+4));
3562+ err |= get_user(ldw2, (unsigned int *)(addr+8));
3563+
3564+ if (err)
3565+ break;
3566+
3567+ if (ldw == 0x0E801096U &&
3568+ bv == 0xEAC0C000U &&
3569+ ldw2 == 0x0E881095U)
3570+ {
3571+ unsigned int resolver, map;
3572+
3573+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3574+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3575+ if (err)
3576+ break;
3577+
3578+ regs->gr[20] = instruction_pointer(regs)+8;
3579+ regs->gr[21] = map;
3580+ regs->gr[22] = resolver;
3581+ regs->iaoq[0] = resolver | 3UL;
3582+ regs->iaoq[1] = regs->iaoq[0] + 4;
3583+ return 3;
3584+ }
3585+ }
3586+ } while (0);
3587+#endif
3588+
3589+#ifdef CONFIG_PAX_EMUTRAMP
3590+
3591+#ifndef CONFIG_PAX_EMUSIGRT
3592+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3593+ return 1;
3594+#endif
3595+
3596+ do { /* PaX: rt_sigreturn emulation */
3597+ unsigned int ldi1, ldi2, bel, nop;
3598+
3599+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3600+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3601+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3602+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3603+
3604+ if (err)
3605+ break;
3606+
3607+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3608+ ldi2 == 0x3414015AU &&
3609+ bel == 0xE4008200U &&
3610+ nop == 0x08000240U)
3611+ {
3612+ regs->gr[25] = (ldi1 & 2) >> 1;
3613+ regs->gr[20] = __NR_rt_sigreturn;
3614+ regs->gr[31] = regs->iaoq[1] + 16;
3615+ regs->sr[0] = regs->iasq[1];
3616+ regs->iaoq[0] = 0x100UL;
3617+ regs->iaoq[1] = regs->iaoq[0] + 4;
3618+ regs->iasq[0] = regs->sr[2];
3619+ regs->iasq[1] = regs->sr[2];
3620+ return 2;
3621+ }
3622+ } while (0);
3623+#endif
3624+
3625+ return 1;
3626+}
3627+
3628+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3629+{
3630+ unsigned long i;
3631+
3632+ printk(KERN_ERR "PAX: bytes at PC: ");
3633+ for (i = 0; i < 5; i++) {
3634+ unsigned int c;
3635+ if (get_user(c, (unsigned int *)pc+i))
3636+ printk(KERN_CONT "???????? ");
3637+ else
3638+ printk(KERN_CONT "%08x ", c);
3639+ }
3640+ printk("\n");
3641+}
3642+#endif
3643+
3644 int fixup_exception(struct pt_regs *regs)
3645 {
3646 const struct exception_table_entry *fix;
3647@@ -192,8 +303,33 @@ good_area:
3648
3649 acc_type = parisc_acctyp(code,regs->iir);
3650
3651- if ((vma->vm_flags & acc_type) != acc_type)
3652+ if ((vma->vm_flags & acc_type) != acc_type) {
3653+
3654+#ifdef CONFIG_PAX_PAGEEXEC
3655+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3656+ (address & ~3UL) == instruction_pointer(regs))
3657+ {
3658+ up_read(&mm->mmap_sem);
3659+ switch (pax_handle_fetch_fault(regs)) {
3660+
3661+#ifdef CONFIG_PAX_EMUPLT
3662+ case 3:
3663+ return;
3664+#endif
3665+
3666+#ifdef CONFIG_PAX_EMUTRAMP
3667+ case 2:
3668+ return;
3669+#endif
3670+
3671+ }
3672+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3673+ do_group_exit(SIGKILL);
3674+ }
3675+#endif
3676+
3677 goto bad_area;
3678+ }
3679
3680 /*
3681 * If for any reason at all we couldn't handle the fault, make
3682diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3683index da29032..f76c24c 100644
3684--- a/arch/powerpc/include/asm/atomic.h
3685+++ b/arch/powerpc/include/asm/atomic.h
3686@@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3687 return t1;
3688 }
3689
3690+#define atomic64_read_unchecked(v) atomic64_read(v)
3691+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3692+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3693+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3694+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3695+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3696+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3697+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3698+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3699+
3700 #endif /* __powerpc64__ */
3701
3702 #endif /* __KERNEL__ */
3703diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3704index 9e495c9..b6878e5 100644
3705--- a/arch/powerpc/include/asm/cache.h
3706+++ b/arch/powerpc/include/asm/cache.h
3707@@ -3,6 +3,7 @@
3708
3709 #ifdef __KERNEL__
3710
3711+#include <linux/const.h>
3712
3713 /* bytes per L1 cache line */
3714 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3715@@ -22,7 +23,7 @@
3716 #define L1_CACHE_SHIFT 7
3717 #endif
3718
3719-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3720+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3721
3722 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3723
3724diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3725index 3bf9cca..e7457d0 100644
3726--- a/arch/powerpc/include/asm/elf.h
3727+++ b/arch/powerpc/include/asm/elf.h
3728@@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3729 the loader. We need to make sure that it is out of the way of the program
3730 that it will "exec", and that there is sufficient room for the brk. */
3731
3732-extern unsigned long randomize_et_dyn(unsigned long base);
3733-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3734+#define ELF_ET_DYN_BASE (0x20000000)
3735+
3736+#ifdef CONFIG_PAX_ASLR
3737+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3738+
3739+#ifdef __powerpc64__
3740+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3741+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3742+#else
3743+#define PAX_DELTA_MMAP_LEN 15
3744+#define PAX_DELTA_STACK_LEN 15
3745+#endif
3746+#endif
3747
3748 /*
3749 * Our registers are always unsigned longs, whether we're a 32 bit
3750@@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3751 (0x7ff >> (PAGE_SHIFT - 12)) : \
3752 (0x3ffff >> (PAGE_SHIFT - 12)))
3753
3754-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3755-#define arch_randomize_brk arch_randomize_brk
3756-
3757 #endif /* __KERNEL__ */
3758
3759 /*
3760diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3761index 8196e9c..d83a9f3 100644
3762--- a/arch/powerpc/include/asm/exec.h
3763+++ b/arch/powerpc/include/asm/exec.h
3764@@ -4,6 +4,6 @@
3765 #ifndef _ASM_POWERPC_EXEC_H
3766 #define _ASM_POWERPC_EXEC_H
3767
3768-extern unsigned long arch_align_stack(unsigned long sp);
3769+#define arch_align_stack(x) ((x) & ~0xfUL)
3770
3771 #endif /* _ASM_POWERPC_EXEC_H */
3772diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3773index bca8fdc..61e9580 100644
3774--- a/arch/powerpc/include/asm/kmap_types.h
3775+++ b/arch/powerpc/include/asm/kmap_types.h
3776@@ -27,6 +27,7 @@ enum km_type {
3777 KM_PPC_SYNC_PAGE,
3778 KM_PPC_SYNC_ICACHE,
3779 KM_KDB,
3780+ KM_CLEARPAGE,
3781 KM_TYPE_NR
3782 };
3783
3784diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3785index d4a7f64..451de1c 100644
3786--- a/arch/powerpc/include/asm/mman.h
3787+++ b/arch/powerpc/include/asm/mman.h
3788@@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3789 }
3790 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3791
3792-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3793+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3794 {
3795 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3796 }
3797diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3798index f072e97..b436dee 100644
3799--- a/arch/powerpc/include/asm/page.h
3800+++ b/arch/powerpc/include/asm/page.h
3801@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3802 * and needs to be executable. This means the whole heap ends
3803 * up being executable.
3804 */
3805-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3806- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3807+#define VM_DATA_DEFAULT_FLAGS32 \
3808+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3809+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3810
3811 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3812 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3813@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3814 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3815 #endif
3816
3817+#define ktla_ktva(addr) (addr)
3818+#define ktva_ktla(addr) (addr)
3819+
3820 /*
3821 * Use the top bit of the higher-level page table entries to indicate whether
3822 * the entries we point to contain hugepages. This works because we know that
3823diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3824index fed85e6..da5c71b 100644
3825--- a/arch/powerpc/include/asm/page_64.h
3826+++ b/arch/powerpc/include/asm/page_64.h
3827@@ -146,15 +146,18 @@ do { \
3828 * stack by default, so in the absence of a PT_GNU_STACK program header
3829 * we turn execute permission off.
3830 */
3831-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3832- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3833+#define VM_STACK_DEFAULT_FLAGS32 \
3834+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3835+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3836
3837 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3838 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3839
3840+#ifndef CONFIG_PAX_PAGEEXEC
3841 #define VM_STACK_DEFAULT_FLAGS \
3842 (is_32bit_task() ? \
3843 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3844+#endif
3845
3846 #include <asm-generic/getorder.h>
3847
3848diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3849index 292725c..f87ae14 100644
3850--- a/arch/powerpc/include/asm/pgalloc-64.h
3851+++ b/arch/powerpc/include/asm/pgalloc-64.h
3852@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3853 #ifndef CONFIG_PPC_64K_PAGES
3854
3855 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3856+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3857
3858 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3859 {
3860@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3861 pud_set(pud, (unsigned long)pmd);
3862 }
3863
3864+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3865+{
3866+ pud_populate(mm, pud, pmd);
3867+}
3868+
3869 #define pmd_populate(mm, pmd, pte_page) \
3870 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3871 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3872@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3873 #else /* CONFIG_PPC_64K_PAGES */
3874
3875 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3876+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3877
3878 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3879 pte_t *pte)
3880diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3881index 2e0e411..7899c68 100644
3882--- a/arch/powerpc/include/asm/pgtable.h
3883+++ b/arch/powerpc/include/asm/pgtable.h
3884@@ -2,6 +2,7 @@
3885 #define _ASM_POWERPC_PGTABLE_H
3886 #ifdef __KERNEL__
3887
3888+#include <linux/const.h>
3889 #ifndef __ASSEMBLY__
3890 #include <asm/processor.h> /* For TASK_SIZE */
3891 #include <asm/mmu.h>
3892diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3893index 4aad413..85d86bf 100644
3894--- a/arch/powerpc/include/asm/pte-hash32.h
3895+++ b/arch/powerpc/include/asm/pte-hash32.h
3896@@ -21,6 +21,7 @@
3897 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3898 #define _PAGE_USER 0x004 /* usermode access allowed */
3899 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3900+#define _PAGE_EXEC _PAGE_GUARDED
3901 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3902 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3903 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3904diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3905index 9d7f0fb..a28fe69 100644
3906--- a/arch/powerpc/include/asm/reg.h
3907+++ b/arch/powerpc/include/asm/reg.h
3908@@ -212,6 +212,7 @@
3909 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3910 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3911 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3912+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3913 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3914 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3915 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3916diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3917index 4a741c7..c8162227b 100644
3918--- a/arch/powerpc/include/asm/thread_info.h
3919+++ b/arch/powerpc/include/asm/thread_info.h
3920@@ -104,12 +104,14 @@ static inline struct thread_info *current_thread_info(void)
3921 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3922 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3923 #define TIF_SINGLESTEP 8 /* singlestepping active */
3924-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3925 #define TIF_SECCOMP 10 /* secure computing */
3926 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3927 #define TIF_NOERROR 12 /* Force successful syscall return */
3928 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3929 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3930+#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3931+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3932+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3933
3934 /* as above, but as bit values */
3935 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3936@@ -127,8 +129,11 @@ static inline struct thread_info *current_thread_info(void)
3937 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3938 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3939 #define _TIF_RUNLATCH (1<<TIF_RUNLATCH)
3940+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3941+
3942 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3943- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3944+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT \
3945+ _TIF_GRSEC_SETXID)
3946
3947 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3948 _TIF_NOTIFY_RESUME)
3949diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3950index bd0fb84..a42a14b 100644
3951--- a/arch/powerpc/include/asm/uaccess.h
3952+++ b/arch/powerpc/include/asm/uaccess.h
3953@@ -13,6 +13,8 @@
3954 #define VERIFY_READ 0
3955 #define VERIFY_WRITE 1
3956
3957+extern void check_object_size(const void *ptr, unsigned long n, bool to);
3958+
3959 /*
3960 * The fs value determines whether argument validity checking should be
3961 * performed or not. If get_fs() == USER_DS, checking is performed, with
3962@@ -327,52 +329,6 @@ do { \
3963 extern unsigned long __copy_tofrom_user(void __user *to,
3964 const void __user *from, unsigned long size);
3965
3966-#ifndef __powerpc64__
3967-
3968-static inline unsigned long copy_from_user(void *to,
3969- const void __user *from, unsigned long n)
3970-{
3971- unsigned long over;
3972-
3973- if (access_ok(VERIFY_READ, from, n))
3974- return __copy_tofrom_user((__force void __user *)to, from, n);
3975- if ((unsigned long)from < TASK_SIZE) {
3976- over = (unsigned long)from + n - TASK_SIZE;
3977- return __copy_tofrom_user((__force void __user *)to, from,
3978- n - over) + over;
3979- }
3980- return n;
3981-}
3982-
3983-static inline unsigned long copy_to_user(void __user *to,
3984- const void *from, unsigned long n)
3985-{
3986- unsigned long over;
3987-
3988- if (access_ok(VERIFY_WRITE, to, n))
3989- return __copy_tofrom_user(to, (__force void __user *)from, n);
3990- if ((unsigned long)to < TASK_SIZE) {
3991- over = (unsigned long)to + n - TASK_SIZE;
3992- return __copy_tofrom_user(to, (__force void __user *)from,
3993- n - over) + over;
3994- }
3995- return n;
3996-}
3997-
3998-#else /* __powerpc64__ */
3999-
4000-#define __copy_in_user(to, from, size) \
4001- __copy_tofrom_user((to), (from), (size))
4002-
4003-extern unsigned long copy_from_user(void *to, const void __user *from,
4004- unsigned long n);
4005-extern unsigned long copy_to_user(void __user *to, const void *from,
4006- unsigned long n);
4007-extern unsigned long copy_in_user(void __user *to, const void __user *from,
4008- unsigned long n);
4009-
4010-#endif /* __powerpc64__ */
4011-
4012 static inline unsigned long __copy_from_user_inatomic(void *to,
4013 const void __user *from, unsigned long n)
4014 {
4015@@ -396,6 +352,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4016 if (ret == 0)
4017 return 0;
4018 }
4019+
4020+ if (!__builtin_constant_p(n))
4021+ check_object_size(to, n, false);
4022+
4023 return __copy_tofrom_user((__force void __user *)to, from, n);
4024 }
4025
4026@@ -422,6 +382,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4027 if (ret == 0)
4028 return 0;
4029 }
4030+
4031+ if (!__builtin_constant_p(n))
4032+ check_object_size(from, n, true);
4033+
4034 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4035 }
4036
4037@@ -439,6 +403,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4038 return __copy_to_user_inatomic(to, from, size);
4039 }
4040
4041+#ifndef __powerpc64__
4042+
4043+static inline unsigned long __must_check copy_from_user(void *to,
4044+ const void __user *from, unsigned long n)
4045+{
4046+ unsigned long over;
4047+
4048+ if ((long)n < 0)
4049+ return n;
4050+
4051+ if (access_ok(VERIFY_READ, from, n)) {
4052+ if (!__builtin_constant_p(n))
4053+ check_object_size(to, n, false);
4054+ return __copy_tofrom_user((__force void __user *)to, from, n);
4055+ }
4056+ if ((unsigned long)from < TASK_SIZE) {
4057+ over = (unsigned long)from + n - TASK_SIZE;
4058+ if (!__builtin_constant_p(n - over))
4059+ check_object_size(to, n - over, false);
4060+ return __copy_tofrom_user((__force void __user *)to, from,
4061+ n - over) + over;
4062+ }
4063+ return n;
4064+}
4065+
4066+static inline unsigned long __must_check copy_to_user(void __user *to,
4067+ const void *from, unsigned long n)
4068+{
4069+ unsigned long over;
4070+
4071+ if ((long)n < 0)
4072+ return n;
4073+
4074+ if (access_ok(VERIFY_WRITE, to, n)) {
4075+ if (!__builtin_constant_p(n))
4076+ check_object_size(from, n, true);
4077+ return __copy_tofrom_user(to, (__force void __user *)from, n);
4078+ }
4079+ if ((unsigned long)to < TASK_SIZE) {
4080+ over = (unsigned long)to + n - TASK_SIZE;
4081+ if (!__builtin_constant_p(n))
4082+ check_object_size(from, n - over, true);
4083+ return __copy_tofrom_user(to, (__force void __user *)from,
4084+ n - over) + over;
4085+ }
4086+ return n;
4087+}
4088+
4089+#else /* __powerpc64__ */
4090+
4091+#define __copy_in_user(to, from, size) \
4092+ __copy_tofrom_user((to), (from), (size))
4093+
4094+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4095+{
4096+ if ((long)n < 0 || n > INT_MAX)
4097+ return n;
4098+
4099+ if (!__builtin_constant_p(n))
4100+ check_object_size(to, n, false);
4101+
4102+ if (likely(access_ok(VERIFY_READ, from, n)))
4103+ n = __copy_from_user(to, from, n);
4104+ else
4105+ memset(to, 0, n);
4106+ return n;
4107+}
4108+
4109+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4110+{
4111+ if ((long)n < 0 || n > INT_MAX)
4112+ return n;
4113+
4114+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
4115+ if (!__builtin_constant_p(n))
4116+ check_object_size(from, n, true);
4117+ n = __copy_to_user(to, from, n);
4118+ }
4119+ return n;
4120+}
4121+
4122+extern unsigned long copy_in_user(void __user *to, const void __user *from,
4123+ unsigned long n);
4124+
4125+#endif /* __powerpc64__ */
4126+
4127 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4128
4129 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4130diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4131index 7215cc2..a9730c1 100644
4132--- a/arch/powerpc/kernel/exceptions-64e.S
4133+++ b/arch/powerpc/kernel/exceptions-64e.S
4134@@ -661,6 +661,7 @@ storage_fault_common:
4135 std r14,_DAR(r1)
4136 std r15,_DSISR(r1)
4137 addi r3,r1,STACK_FRAME_OVERHEAD
4138+ bl .save_nvgprs
4139 mr r4,r14
4140 mr r5,r15
4141 ld r14,PACA_EXGEN+EX_R14(r13)
4142@@ -669,8 +670,7 @@ storage_fault_common:
4143 cmpdi r3,0
4144 bne- 1f
4145 b .ret_from_except_lite
4146-1: bl .save_nvgprs
4147- mr r5,r3
4148+1: mr r5,r3
4149 addi r3,r1,STACK_FRAME_OVERHEAD
4150 ld r4,_DAR(r1)
4151 bl .bad_page_fault
4152diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4153index 8f880bc..c5bd2f3 100644
4154--- a/arch/powerpc/kernel/exceptions-64s.S
4155+++ b/arch/powerpc/kernel/exceptions-64s.S
4156@@ -890,10 +890,10 @@ handle_page_fault:
4157 11: ld r4,_DAR(r1)
4158 ld r5,_DSISR(r1)
4159 addi r3,r1,STACK_FRAME_OVERHEAD
4160+ bl .save_nvgprs
4161 bl .do_page_fault
4162 cmpdi r3,0
4163 beq+ 12f
4164- bl .save_nvgprs
4165 mr r5,r3
4166 addi r3,r1,STACK_FRAME_OVERHEAD
4167 lwz r4,_DAR(r1)
4168diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4169index 2e3200c..72095ce 100644
4170--- a/arch/powerpc/kernel/module_32.c
4171+++ b/arch/powerpc/kernel/module_32.c
4172@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4173 me->arch.core_plt_section = i;
4174 }
4175 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4176- printk("Module doesn't contain .plt or .init.plt sections.\n");
4177+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4178 return -ENOEXEC;
4179 }
4180
4181@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4182
4183 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4184 /* Init, or core PLT? */
4185- if (location >= mod->module_core
4186- && location < mod->module_core + mod->core_size)
4187+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4188+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4189 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4190- else
4191+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4192+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4193 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4194+ else {
4195+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4196+ return ~0UL;
4197+ }
4198
4199 /* Find this entry, or if that fails, the next avail. entry */
4200 while (entry->jump[0]) {
4201diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4202index 4937c96..70714b7 100644
4203--- a/arch/powerpc/kernel/process.c
4204+++ b/arch/powerpc/kernel/process.c
4205@@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4206 * Lookup NIP late so we have the best change of getting the
4207 * above info out without failing
4208 */
4209- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4210- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4211+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4212+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4213 #endif
4214 show_stack(current, (unsigned long *) regs->gpr[1]);
4215 if (!user_mode(regs))
4216@@ -1186,10 +1186,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4217 newsp = stack[0];
4218 ip = stack[STACK_FRAME_LR_SAVE];
4219 if (!firstframe || ip != lr) {
4220- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4221+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4222 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4223 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4224- printk(" (%pS)",
4225+ printk(" (%pA)",
4226 (void *)current->ret_stack[curr_frame].ret);
4227 curr_frame--;
4228 }
4229@@ -1209,7 +1209,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4230 struct pt_regs *regs = (struct pt_regs *)
4231 (sp + STACK_FRAME_OVERHEAD);
4232 lr = regs->link;
4233- printk("--- Exception: %lx at %pS\n LR = %pS\n",
4234+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
4235 regs->trap, (void *)regs->nip, (void *)lr);
4236 firstframe = 1;
4237 }
4238@@ -1282,58 +1282,3 @@ void thread_info_cache_init(void)
4239 }
4240
4241 #endif /* THREAD_SHIFT < PAGE_SHIFT */
4242-
4243-unsigned long arch_align_stack(unsigned long sp)
4244-{
4245- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4246- sp -= get_random_int() & ~PAGE_MASK;
4247- return sp & ~0xf;
4248-}
4249-
4250-static inline unsigned long brk_rnd(void)
4251-{
4252- unsigned long rnd = 0;
4253-
4254- /* 8MB for 32bit, 1GB for 64bit */
4255- if (is_32bit_task())
4256- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4257- else
4258- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4259-
4260- return rnd << PAGE_SHIFT;
4261-}
4262-
4263-unsigned long arch_randomize_brk(struct mm_struct *mm)
4264-{
4265- unsigned long base = mm->brk;
4266- unsigned long ret;
4267-
4268-#ifdef CONFIG_PPC_STD_MMU_64
4269- /*
4270- * If we are using 1TB segments and we are allowed to randomise
4271- * the heap, we can put it above 1TB so it is backed by a 1TB
4272- * segment. Otherwise the heap will be in the bottom 1TB
4273- * which always uses 256MB segments and this may result in a
4274- * performance penalty.
4275- */
4276- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4277- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4278-#endif
4279-
4280- ret = PAGE_ALIGN(base + brk_rnd());
4281-
4282- if (ret < mm->brk)
4283- return mm->brk;
4284-
4285- return ret;
4286-}
4287-
4288-unsigned long randomize_et_dyn(unsigned long base)
4289-{
4290- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4291-
4292- if (ret < base)
4293- return base;
4294-
4295- return ret;
4296-}
4297diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4298index 8d8e028..c2aeb50 100644
4299--- a/arch/powerpc/kernel/ptrace.c
4300+++ b/arch/powerpc/kernel/ptrace.c
4301@@ -1702,6 +1702,10 @@ long arch_ptrace(struct task_struct *child, long request,
4302 return ret;
4303 }
4304
4305+#ifdef CONFIG_GRKERNSEC_SETXID
4306+extern void gr_delayed_cred_worker(void);
4307+#endif
4308+
4309 /*
4310 * We must return the syscall number to actually look up in the table.
4311 * This can be -1L to skip running any syscall at all.
4312@@ -1712,6 +1716,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4313
4314 secure_computing(regs->gpr[0]);
4315
4316+#ifdef CONFIG_GRKERNSEC_SETXID
4317+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4318+ gr_delayed_cred_worker();
4319+#endif
4320+
4321 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4322 tracehook_report_syscall_entry(regs))
4323 /*
4324@@ -1746,6 +1755,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4325 {
4326 int step;
4327
4328+#ifdef CONFIG_GRKERNSEC_SETXID
4329+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4330+ gr_delayed_cred_worker();
4331+#endif
4332+
4333 audit_syscall_exit(regs);
4334
4335 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4336diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4337index 45eb998..0cb36bc 100644
4338--- a/arch/powerpc/kernel/signal_32.c
4339+++ b/arch/powerpc/kernel/signal_32.c
4340@@ -861,7 +861,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4341 /* Save user registers on the stack */
4342 frame = &rt_sf->uc.uc_mcontext;
4343 addr = frame;
4344- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4345+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4346 if (save_user_regs(regs, frame, 0, 1))
4347 goto badframe;
4348 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4349diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4350index 2692efd..6673d2e 100644
4351--- a/arch/powerpc/kernel/signal_64.c
4352+++ b/arch/powerpc/kernel/signal_64.c
4353@@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4354 current->thread.fpscr.val = 0;
4355
4356 /* Set up to return from userspace. */
4357- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4358+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4359 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4360 } else {
4361 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4362diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4363index 1589723..cefe690 100644
4364--- a/arch/powerpc/kernel/traps.c
4365+++ b/arch/powerpc/kernel/traps.c
4366@@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4367 return flags;
4368 }
4369
4370+extern void gr_handle_kernel_exploit(void);
4371+
4372 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4373 int signr)
4374 {
4375@@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4376 panic("Fatal exception in interrupt");
4377 if (panic_on_oops)
4378 panic("Fatal exception");
4379+
4380+ gr_handle_kernel_exploit();
4381+
4382 do_exit(signr);
4383 }
4384
4385diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4386index 9eb5b9b..e45498a 100644
4387--- a/arch/powerpc/kernel/vdso.c
4388+++ b/arch/powerpc/kernel/vdso.c
4389@@ -34,6 +34,7 @@
4390 #include <asm/firmware.h>
4391 #include <asm/vdso.h>
4392 #include <asm/vdso_datapage.h>
4393+#include <asm/mman.h>
4394
4395 #include "setup.h"
4396
4397@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4398 vdso_base = VDSO32_MBASE;
4399 #endif
4400
4401- current->mm->context.vdso_base = 0;
4402+ current->mm->context.vdso_base = ~0UL;
4403
4404 /* vDSO has a problem and was disabled, just don't "enable" it for the
4405 * process
4406@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4407 vdso_base = get_unmapped_area(NULL, vdso_base,
4408 (vdso_pages << PAGE_SHIFT) +
4409 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4410- 0, 0);
4411+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
4412 if (IS_ERR_VALUE(vdso_base)) {
4413 rc = vdso_base;
4414 goto fail_mmapsem;
4415diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4416index 5eea6f3..5d10396 100644
4417--- a/arch/powerpc/lib/usercopy_64.c
4418+++ b/arch/powerpc/lib/usercopy_64.c
4419@@ -9,22 +9,6 @@
4420 #include <linux/module.h>
4421 #include <asm/uaccess.h>
4422
4423-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4424-{
4425- if (likely(access_ok(VERIFY_READ, from, n)))
4426- n = __copy_from_user(to, from, n);
4427- else
4428- memset(to, 0, n);
4429- return n;
4430-}
4431-
4432-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4433-{
4434- if (likely(access_ok(VERIFY_WRITE, to, n)))
4435- n = __copy_to_user(to, from, n);
4436- return n;
4437-}
4438-
4439 unsigned long copy_in_user(void __user *to, const void __user *from,
4440 unsigned long n)
4441 {
4442@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4443 return n;
4444 }
4445
4446-EXPORT_SYMBOL(copy_from_user);
4447-EXPORT_SYMBOL(copy_to_user);
4448 EXPORT_SYMBOL(copy_in_user);
4449
4450diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4451index 08ffcf5..a0ab912 100644
4452--- a/arch/powerpc/mm/fault.c
4453+++ b/arch/powerpc/mm/fault.c
4454@@ -32,6 +32,10 @@
4455 #include <linux/perf_event.h>
4456 #include <linux/magic.h>
4457 #include <linux/ratelimit.h>
4458+#include <linux/slab.h>
4459+#include <linux/pagemap.h>
4460+#include <linux/compiler.h>
4461+#include <linux/unistd.h>
4462
4463 #include <asm/firmware.h>
4464 #include <asm/page.h>
4465@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4466 }
4467 #endif
4468
4469+#ifdef CONFIG_PAX_PAGEEXEC
4470+/*
4471+ * PaX: decide what to do with offenders (regs->nip = fault address)
4472+ *
4473+ * returns 1 when task should be killed
4474+ */
4475+static int pax_handle_fetch_fault(struct pt_regs *regs)
4476+{
4477+ return 1;
4478+}
4479+
4480+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4481+{
4482+ unsigned long i;
4483+
4484+ printk(KERN_ERR "PAX: bytes at PC: ");
4485+ for (i = 0; i < 5; i++) {
4486+ unsigned int c;
4487+ if (get_user(c, (unsigned int __user *)pc+i))
4488+ printk(KERN_CONT "???????? ");
4489+ else
4490+ printk(KERN_CONT "%08x ", c);
4491+ }
4492+ printk("\n");
4493+}
4494+#endif
4495+
4496 /*
4497 * Check whether the instruction at regs->nip is a store using
4498 * an update addressing form which will update r1.
4499@@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4500 * indicate errors in DSISR but can validly be set in SRR1.
4501 */
4502 if (trap == 0x400)
4503- error_code &= 0x48200000;
4504+ error_code &= 0x58200000;
4505 else
4506 is_write = error_code & DSISR_ISSTORE;
4507 #else
4508@@ -366,7 +397,7 @@ good_area:
4509 * "undefined". Of those that can be set, this is the only
4510 * one which seems bad.
4511 */
4512- if (error_code & 0x10000000)
4513+ if (error_code & DSISR_GUARDED)
4514 /* Guarded storage error. */
4515 goto bad_area;
4516 #endif /* CONFIG_8xx */
4517@@ -381,7 +412,7 @@ good_area:
4518 * processors use the same I/D cache coherency mechanism
4519 * as embedded.
4520 */
4521- if (error_code & DSISR_PROTFAULT)
4522+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4523 goto bad_area;
4524 #endif /* CONFIG_PPC_STD_MMU */
4525
4526@@ -463,6 +494,23 @@ bad_area:
4527 bad_area_nosemaphore:
4528 /* User mode accesses cause a SIGSEGV */
4529 if (user_mode(regs)) {
4530+
4531+#ifdef CONFIG_PAX_PAGEEXEC
4532+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4533+#ifdef CONFIG_PPC_STD_MMU
4534+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4535+#else
4536+ if (is_exec && regs->nip == address) {
4537+#endif
4538+ switch (pax_handle_fetch_fault(regs)) {
4539+ }
4540+
4541+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4542+ do_group_exit(SIGKILL);
4543+ }
4544+ }
4545+#endif
4546+
4547 _exception(SIGSEGV, regs, code, address);
4548 return 0;
4549 }
4550diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4551index 67a42ed..1c7210c 100644
4552--- a/arch/powerpc/mm/mmap_64.c
4553+++ b/arch/powerpc/mm/mmap_64.c
4554@@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4555 */
4556 if (mmap_is_legacy()) {
4557 mm->mmap_base = TASK_UNMAPPED_BASE;
4558+
4559+#ifdef CONFIG_PAX_RANDMMAP
4560+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4561+ mm->mmap_base += mm->delta_mmap;
4562+#endif
4563+
4564 mm->get_unmapped_area = arch_get_unmapped_area;
4565 mm->unmap_area = arch_unmap_area;
4566 } else {
4567 mm->mmap_base = mmap_base();
4568+
4569+#ifdef CONFIG_PAX_RANDMMAP
4570+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4571+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4572+#endif
4573+
4574 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4575 mm->unmap_area = arch_unmap_area_topdown;
4576 }
4577diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4578index 73709f7..6b90313 100644
4579--- a/arch/powerpc/mm/slice.c
4580+++ b/arch/powerpc/mm/slice.c
4581@@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4582 if ((mm->task_size - len) < addr)
4583 return 0;
4584 vma = find_vma(mm, addr);
4585- return (!vma || (addr + len) <= vma->vm_start);
4586+ return check_heap_stack_gap(vma, addr, len);
4587 }
4588
4589 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4590@@ -256,7 +256,7 @@ full_search:
4591 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4592 continue;
4593 }
4594- if (!vma || addr + len <= vma->vm_start) {
4595+ if (check_heap_stack_gap(vma, addr, len)) {
4596 /*
4597 * Remember the place where we stopped the search:
4598 */
4599@@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4600 }
4601 }
4602
4603- addr = mm->mmap_base;
4604- while (addr > len) {
4605+ if (mm->mmap_base < len)
4606+ addr = -ENOMEM;
4607+ else
4608+ addr = mm->mmap_base - len;
4609+
4610+ while (!IS_ERR_VALUE(addr)) {
4611 /* Go down by chunk size */
4612- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4613+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
4614
4615 /* Check for hit with different page size */
4616 mask = slice_range_to_mask(addr, len);
4617@@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4618 * return with success:
4619 */
4620 vma = find_vma(mm, addr);
4621- if (!vma || (addr + len) <= vma->vm_start) {
4622+ if (check_heap_stack_gap(vma, addr, len)) {
4623 /* remember the address as a hint for next time */
4624 if (use_cache)
4625 mm->free_area_cache = addr;
4626@@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4627 mm->cached_hole_size = vma->vm_start - addr;
4628
4629 /* try just below the current vma->vm_start */
4630- addr = vma->vm_start;
4631+ addr = skip_heap_stack_gap(vma, len);
4632 }
4633
4634 /*
4635@@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4636 if (fixed && addr > (mm->task_size - len))
4637 return -EINVAL;
4638
4639+#ifdef CONFIG_PAX_RANDMMAP
4640+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4641+ addr = 0;
4642+#endif
4643+
4644 /* If hint, make sure it matches our alignment restrictions */
4645 if (!fixed && addr) {
4646 addr = _ALIGN_UP(addr, 1ul << pshift);
4647diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4648index 748347b..81bc6c7 100644
4649--- a/arch/s390/include/asm/atomic.h
4650+++ b/arch/s390/include/asm/atomic.h
4651@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4652 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4653 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4654
4655+#define atomic64_read_unchecked(v) atomic64_read(v)
4656+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4657+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4658+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4659+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4660+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4661+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4662+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4663+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4664+
4665 #define smp_mb__before_atomic_dec() smp_mb()
4666 #define smp_mb__after_atomic_dec() smp_mb()
4667 #define smp_mb__before_atomic_inc() smp_mb()
4668diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4669index 2a30d5a..5e5586f 100644
4670--- a/arch/s390/include/asm/cache.h
4671+++ b/arch/s390/include/asm/cache.h
4672@@ -11,8 +11,10 @@
4673 #ifndef __ARCH_S390_CACHE_H
4674 #define __ARCH_S390_CACHE_H
4675
4676-#define L1_CACHE_BYTES 256
4677+#include <linux/const.h>
4678+
4679 #define L1_CACHE_SHIFT 8
4680+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4681 #define NET_SKB_PAD 32
4682
4683 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4684diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4685index c4ee39f..352881b 100644
4686--- a/arch/s390/include/asm/elf.h
4687+++ b/arch/s390/include/asm/elf.h
4688@@ -161,8 +161,14 @@ extern unsigned int vdso_enabled;
4689 the loader. We need to make sure that it is out of the way of the program
4690 that it will "exec", and that there is sufficient room for the brk. */
4691
4692-extern unsigned long randomize_et_dyn(unsigned long base);
4693-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4694+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4695+
4696+#ifdef CONFIG_PAX_ASLR
4697+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4698+
4699+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4700+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4701+#endif
4702
4703 /* This yields a mask that user programs can use to figure out what
4704 instruction set this CPU supports. */
4705@@ -210,7 +216,4 @@ struct linux_binprm;
4706 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4707 int arch_setup_additional_pages(struct linux_binprm *, int);
4708
4709-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4710-#define arch_randomize_brk arch_randomize_brk
4711-
4712 #endif
4713diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4714index c4a93d6..4d2a9b4 100644
4715--- a/arch/s390/include/asm/exec.h
4716+++ b/arch/s390/include/asm/exec.h
4717@@ -7,6 +7,6 @@
4718 #ifndef __ASM_EXEC_H
4719 #define __ASM_EXEC_H
4720
4721-extern unsigned long arch_align_stack(unsigned long sp);
4722+#define arch_align_stack(x) ((x) & ~0xfUL)
4723
4724 #endif /* __ASM_EXEC_H */
4725diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4726index 8f2cada..43072c1 100644
4727--- a/arch/s390/include/asm/uaccess.h
4728+++ b/arch/s390/include/asm/uaccess.h
4729@@ -236,6 +236,10 @@ static inline unsigned long __must_check
4730 copy_to_user(void __user *to, const void *from, unsigned long n)
4731 {
4732 might_fault();
4733+
4734+ if ((long)n < 0)
4735+ return n;
4736+
4737 if (access_ok(VERIFY_WRITE, to, n))
4738 n = __copy_to_user(to, from, n);
4739 return n;
4740@@ -261,6 +265,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4741 static inline unsigned long __must_check
4742 __copy_from_user(void *to, const void __user *from, unsigned long n)
4743 {
4744+ if ((long)n < 0)
4745+ return n;
4746+
4747 if (__builtin_constant_p(n) && (n <= 256))
4748 return uaccess.copy_from_user_small(n, from, to);
4749 else
4750@@ -292,10 +299,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4751 static inline unsigned long __must_check
4752 copy_from_user(void *to, const void __user *from, unsigned long n)
4753 {
4754- unsigned int sz = __compiletime_object_size(to);
4755+ size_t sz = __compiletime_object_size(to);
4756
4757 might_fault();
4758- if (unlikely(sz != -1 && sz < n)) {
4759+
4760+ if ((long)n < 0)
4761+ return n;
4762+
4763+ if (unlikely(sz != (size_t)-1 && sz < n)) {
4764 copy_from_user_overflow();
4765 return n;
4766 }
4767diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4768index dfcb343..eda788a 100644
4769--- a/arch/s390/kernel/module.c
4770+++ b/arch/s390/kernel/module.c
4771@@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4772
4773 /* Increase core size by size of got & plt and set start
4774 offsets for got and plt. */
4775- me->core_size = ALIGN(me->core_size, 4);
4776- me->arch.got_offset = me->core_size;
4777- me->core_size += me->arch.got_size;
4778- me->arch.plt_offset = me->core_size;
4779- me->core_size += me->arch.plt_size;
4780+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
4781+ me->arch.got_offset = me->core_size_rw;
4782+ me->core_size_rw += me->arch.got_size;
4783+ me->arch.plt_offset = me->core_size_rx;
4784+ me->core_size_rx += me->arch.plt_size;
4785 return 0;
4786 }
4787
4788@@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4789 if (info->got_initialized == 0) {
4790 Elf_Addr *gotent;
4791
4792- gotent = me->module_core + me->arch.got_offset +
4793+ gotent = me->module_core_rw + me->arch.got_offset +
4794 info->got_offset;
4795 *gotent = val;
4796 info->got_initialized = 1;
4797@@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4798 else if (r_type == R_390_GOTENT ||
4799 r_type == R_390_GOTPLTENT)
4800 *(unsigned int *) loc =
4801- (val + (Elf_Addr) me->module_core - loc) >> 1;
4802+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4803 else if (r_type == R_390_GOT64 ||
4804 r_type == R_390_GOTPLT64)
4805 *(unsigned long *) loc = val;
4806@@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4807 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4808 if (info->plt_initialized == 0) {
4809 unsigned int *ip;
4810- ip = me->module_core + me->arch.plt_offset +
4811+ ip = me->module_core_rx + me->arch.plt_offset +
4812 info->plt_offset;
4813 #ifndef CONFIG_64BIT
4814 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4815@@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4816 val - loc + 0xffffUL < 0x1ffffeUL) ||
4817 (r_type == R_390_PLT32DBL &&
4818 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4819- val = (Elf_Addr) me->module_core +
4820+ val = (Elf_Addr) me->module_core_rx +
4821 me->arch.plt_offset +
4822 info->plt_offset;
4823 val += rela->r_addend - loc;
4824@@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4825 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4826 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4827 val = val + rela->r_addend -
4828- ((Elf_Addr) me->module_core + me->arch.got_offset);
4829+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4830 if (r_type == R_390_GOTOFF16)
4831 *(unsigned short *) loc = val;
4832 else if (r_type == R_390_GOTOFF32)
4833@@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4834 break;
4835 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4836 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4837- val = (Elf_Addr) me->module_core + me->arch.got_offset +
4838+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4839 rela->r_addend - loc;
4840 if (r_type == R_390_GOTPC)
4841 *(unsigned int *) loc = val;
4842diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4843index 60055ce..ee4b252 100644
4844--- a/arch/s390/kernel/process.c
4845+++ b/arch/s390/kernel/process.c
4846@@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4847 }
4848 return 0;
4849 }
4850-
4851-unsigned long arch_align_stack(unsigned long sp)
4852-{
4853- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4854- sp -= get_random_int() & ~PAGE_MASK;
4855- return sp & ~0xf;
4856-}
4857-
4858-static inline unsigned long brk_rnd(void)
4859-{
4860- /* 8MB for 32bit, 1GB for 64bit */
4861- if (is_32bit_task())
4862- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4863- else
4864- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4865-}
4866-
4867-unsigned long arch_randomize_brk(struct mm_struct *mm)
4868-{
4869- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4870-
4871- if (ret < mm->brk)
4872- return mm->brk;
4873- return ret;
4874-}
4875-
4876-unsigned long randomize_et_dyn(unsigned long base)
4877-{
4878- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4879-
4880- if (!(current->flags & PF_RANDOMIZE))
4881- return base;
4882- if (ret < base)
4883- return base;
4884- return ret;
4885-}
4886diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4887index 2857c48..d047481 100644
4888--- a/arch/s390/mm/mmap.c
4889+++ b/arch/s390/mm/mmap.c
4890@@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4891 */
4892 if (mmap_is_legacy()) {
4893 mm->mmap_base = TASK_UNMAPPED_BASE;
4894+
4895+#ifdef CONFIG_PAX_RANDMMAP
4896+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4897+ mm->mmap_base += mm->delta_mmap;
4898+#endif
4899+
4900 mm->get_unmapped_area = arch_get_unmapped_area;
4901 mm->unmap_area = arch_unmap_area;
4902 } else {
4903 mm->mmap_base = mmap_base();
4904+
4905+#ifdef CONFIG_PAX_RANDMMAP
4906+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4907+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4908+#endif
4909+
4910 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4911 mm->unmap_area = arch_unmap_area_topdown;
4912 }
4913@@ -166,10 +178,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4914 */
4915 if (mmap_is_legacy()) {
4916 mm->mmap_base = TASK_UNMAPPED_BASE;
4917+
4918+#ifdef CONFIG_PAX_RANDMMAP
4919+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4920+ mm->mmap_base += mm->delta_mmap;
4921+#endif
4922+
4923 mm->get_unmapped_area = s390_get_unmapped_area;
4924 mm->unmap_area = arch_unmap_area;
4925 } else {
4926 mm->mmap_base = mmap_base();
4927+
4928+#ifdef CONFIG_PAX_RANDMMAP
4929+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4930+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4931+#endif
4932+
4933 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4934 mm->unmap_area = arch_unmap_area_topdown;
4935 }
4936diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4937index ae3d59f..f65f075 100644
4938--- a/arch/score/include/asm/cache.h
4939+++ b/arch/score/include/asm/cache.h
4940@@ -1,7 +1,9 @@
4941 #ifndef _ASM_SCORE_CACHE_H
4942 #define _ASM_SCORE_CACHE_H
4943
4944+#include <linux/const.h>
4945+
4946 #define L1_CACHE_SHIFT 4
4947-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4948+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4949
4950 #endif /* _ASM_SCORE_CACHE_H */
4951diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4952index f9f3cd5..58ff438 100644
4953--- a/arch/score/include/asm/exec.h
4954+++ b/arch/score/include/asm/exec.h
4955@@ -1,6 +1,6 @@
4956 #ifndef _ASM_SCORE_EXEC_H
4957 #define _ASM_SCORE_EXEC_H
4958
4959-extern unsigned long arch_align_stack(unsigned long sp);
4960+#define arch_align_stack(x) (x)
4961
4962 #endif /* _ASM_SCORE_EXEC_H */
4963diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4964index 2707023..1c2a3b7 100644
4965--- a/arch/score/kernel/process.c
4966+++ b/arch/score/kernel/process.c
4967@@ -159,8 +159,3 @@ unsigned long get_wchan(struct task_struct *task)
4968
4969 return task_pt_regs(task)->cp0_epc;
4970 }
4971-
4972-unsigned long arch_align_stack(unsigned long sp)
4973-{
4974- return sp;
4975-}
4976diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4977index ef9e555..331bd29 100644
4978--- a/arch/sh/include/asm/cache.h
4979+++ b/arch/sh/include/asm/cache.h
4980@@ -9,10 +9,11 @@
4981 #define __ASM_SH_CACHE_H
4982 #ifdef __KERNEL__
4983
4984+#include <linux/const.h>
4985 #include <linux/init.h>
4986 #include <cpu/cache.h>
4987
4988-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4989+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4990
4991 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4992
4993diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
4994index afeb710..d1d1289 100644
4995--- a/arch/sh/mm/mmap.c
4996+++ b/arch/sh/mm/mmap.c
4997@@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4998 addr = PAGE_ALIGN(addr);
4999
5000 vma = find_vma(mm, addr);
5001- if (TASK_SIZE - len >= addr &&
5002- (!vma || addr + len <= vma->vm_start))
5003+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5004 return addr;
5005 }
5006
5007@@ -106,7 +105,7 @@ full_search:
5008 }
5009 return -ENOMEM;
5010 }
5011- if (likely(!vma || addr + len <= vma->vm_start)) {
5012+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5013 /*
5014 * Remember the place where we stopped the search:
5015 */
5016@@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5017 addr = PAGE_ALIGN(addr);
5018
5019 vma = find_vma(mm, addr);
5020- if (TASK_SIZE - len >= addr &&
5021- (!vma || addr + len <= vma->vm_start))
5022+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5023 return addr;
5024 }
5025
5026@@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5027 /* make sure it can fit in the remaining address space */
5028 if (likely(addr > len)) {
5029 vma = find_vma(mm, addr-len);
5030- if (!vma || addr <= vma->vm_start) {
5031+ if (check_heap_stack_gap(vma, addr - len, len)) {
5032 /* remember the address as a hint for next time */
5033 return (mm->free_area_cache = addr-len);
5034 }
5035@@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5036 if (unlikely(mm->mmap_base < len))
5037 goto bottomup;
5038
5039- addr = mm->mmap_base-len;
5040- if (do_colour_align)
5041- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5042+ addr = mm->mmap_base - len;
5043
5044 do {
5045+ if (do_colour_align)
5046+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5047 /*
5048 * Lookup failure means no vma is above this address,
5049 * else if new region fits below vma->vm_start,
5050 * return with success:
5051 */
5052 vma = find_vma(mm, addr);
5053- if (likely(!vma || addr+len <= vma->vm_start)) {
5054+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5055 /* remember the address as a hint for next time */
5056 return (mm->free_area_cache = addr);
5057 }
5058@@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5059 mm->cached_hole_size = vma->vm_start - addr;
5060
5061 /* try just below the current vma->vm_start */
5062- addr = vma->vm_start-len;
5063- if (do_colour_align)
5064- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5065- } while (likely(len < vma->vm_start));
5066+ addr = skip_heap_stack_gap(vma, len);
5067+ } while (!IS_ERR_VALUE(addr));
5068
5069 bottomup:
5070 /*
5071diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
5072index eddcfb3..b117d90 100644
5073--- a/arch/sparc/Makefile
5074+++ b/arch/sparc/Makefile
5075@@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc/oprofile/
5076 # Export what is needed by arch/sparc/boot/Makefile
5077 export VMLINUX_INIT VMLINUX_MAIN
5078 VMLINUX_INIT := $(head-y) $(init-y)
5079-VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
5080+VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
5081 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
5082 VMLINUX_MAIN += $(drivers-y) $(net-y)
5083
5084diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5085index ce35a1c..2e7b8f9 100644
5086--- a/arch/sparc/include/asm/atomic_64.h
5087+++ b/arch/sparc/include/asm/atomic_64.h
5088@@ -14,18 +14,40 @@
5089 #define ATOMIC64_INIT(i) { (i) }
5090
5091 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5092+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5093+{
5094+ return v->counter;
5095+}
5096 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5097+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5098+{
5099+ return v->counter;
5100+}
5101
5102 #define atomic_set(v, i) (((v)->counter) = i)
5103+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5104+{
5105+ v->counter = i;
5106+}
5107 #define atomic64_set(v, i) (((v)->counter) = i)
5108+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5109+{
5110+ v->counter = i;
5111+}
5112
5113 extern void atomic_add(int, atomic_t *);
5114+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5115 extern void atomic64_add(long, atomic64_t *);
5116+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5117 extern void atomic_sub(int, atomic_t *);
5118+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5119 extern void atomic64_sub(long, atomic64_t *);
5120+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5121
5122 extern int atomic_add_ret(int, atomic_t *);
5123+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5124 extern long atomic64_add_ret(long, atomic64_t *);
5125+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5126 extern int atomic_sub_ret(int, atomic_t *);
5127 extern long atomic64_sub_ret(long, atomic64_t *);
5128
5129@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5130 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5131
5132 #define atomic_inc_return(v) atomic_add_ret(1, v)
5133+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5134+{
5135+ return atomic_add_ret_unchecked(1, v);
5136+}
5137 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5138+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5139+{
5140+ return atomic64_add_ret_unchecked(1, v);
5141+}
5142
5143 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5144 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5145
5146 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5147+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5148+{
5149+ return atomic_add_ret_unchecked(i, v);
5150+}
5151 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5152+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5153+{
5154+ return atomic64_add_ret_unchecked(i, v);
5155+}
5156
5157 /*
5158 * atomic_inc_and_test - increment and test
5159@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5160 * other cases.
5161 */
5162 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5163+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5164+{
5165+ return atomic_inc_return_unchecked(v) == 0;
5166+}
5167 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5168
5169 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5170@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5171 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5172
5173 #define atomic_inc(v) atomic_add(1, v)
5174+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5175+{
5176+ atomic_add_unchecked(1, v);
5177+}
5178 #define atomic64_inc(v) atomic64_add(1, v)
5179+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5180+{
5181+ atomic64_add_unchecked(1, v);
5182+}
5183
5184 #define atomic_dec(v) atomic_sub(1, v)
5185+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5186+{
5187+ atomic_sub_unchecked(1, v);
5188+}
5189 #define atomic64_dec(v) atomic64_sub(1, v)
5190+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5191+{
5192+ atomic64_sub_unchecked(1, v);
5193+}
5194
5195 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5196 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5197
5198 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5199+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5200+{
5201+ return cmpxchg(&v->counter, old, new);
5202+}
5203 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5204+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5205+{
5206+ return xchg(&v->counter, new);
5207+}
5208
5209 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5210 {
5211- int c, old;
5212+ int c, old, new;
5213 c = atomic_read(v);
5214 for (;;) {
5215- if (unlikely(c == (u)))
5216+ if (unlikely(c == u))
5217 break;
5218- old = atomic_cmpxchg((v), c, c + (a));
5219+
5220+ asm volatile("addcc %2, %0, %0\n"
5221+
5222+#ifdef CONFIG_PAX_REFCOUNT
5223+ "tvs %%icc, 6\n"
5224+#endif
5225+
5226+ : "=r" (new)
5227+ : "0" (c), "ir" (a)
5228+ : "cc");
5229+
5230+ old = atomic_cmpxchg(v, c, new);
5231 if (likely(old == c))
5232 break;
5233 c = old;
5234@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5235 #define atomic64_cmpxchg(v, o, n) \
5236 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5237 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5238+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5239+{
5240+ return xchg(&v->counter, new);
5241+}
5242
5243 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5244 {
5245- long c, old;
5246+ long c, old, new;
5247 c = atomic64_read(v);
5248 for (;;) {
5249- if (unlikely(c == (u)))
5250+ if (unlikely(c == u))
5251 break;
5252- old = atomic64_cmpxchg((v), c, c + (a));
5253+
5254+ asm volatile("addcc %2, %0, %0\n"
5255+
5256+#ifdef CONFIG_PAX_REFCOUNT
5257+ "tvs %%xcc, 6\n"
5258+#endif
5259+
5260+ : "=r" (new)
5261+ : "0" (c), "ir" (a)
5262+ : "cc");
5263+
5264+ old = atomic64_cmpxchg(v, c, new);
5265 if (likely(old == c))
5266 break;
5267 c = old;
5268 }
5269- return c != (u);
5270+ return c != u;
5271 }
5272
5273 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5274diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5275index 69358b5..9d0d492 100644
5276--- a/arch/sparc/include/asm/cache.h
5277+++ b/arch/sparc/include/asm/cache.h
5278@@ -7,10 +7,12 @@
5279 #ifndef _SPARC_CACHE_H
5280 #define _SPARC_CACHE_H
5281
5282+#include <linux/const.h>
5283+
5284 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5285
5286 #define L1_CACHE_SHIFT 5
5287-#define L1_CACHE_BYTES 32
5288+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5289
5290 #ifdef CONFIG_SPARC32
5291 #define SMP_CACHE_BYTES_SHIFT 5
5292diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5293index 4269ca6..e3da77f 100644
5294--- a/arch/sparc/include/asm/elf_32.h
5295+++ b/arch/sparc/include/asm/elf_32.h
5296@@ -114,6 +114,13 @@ typedef struct {
5297
5298 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5299
5300+#ifdef CONFIG_PAX_ASLR
5301+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5302+
5303+#define PAX_DELTA_MMAP_LEN 16
5304+#define PAX_DELTA_STACK_LEN 16
5305+#endif
5306+
5307 /* This yields a mask that user programs can use to figure out what
5308 instruction set this cpu supports. This can NOT be done in userspace
5309 on Sparc. */
5310diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5311index 7df8b7f..4946269 100644
5312--- a/arch/sparc/include/asm/elf_64.h
5313+++ b/arch/sparc/include/asm/elf_64.h
5314@@ -180,6 +180,13 @@ typedef struct {
5315 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5316 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5317
5318+#ifdef CONFIG_PAX_ASLR
5319+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5320+
5321+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5322+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5323+#endif
5324+
5325 extern unsigned long sparc64_elf_hwcap;
5326 #define ELF_HWCAP sparc64_elf_hwcap
5327
5328diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5329index ca2b344..c6084f89 100644
5330--- a/arch/sparc/include/asm/pgalloc_32.h
5331+++ b/arch/sparc/include/asm/pgalloc_32.h
5332@@ -37,6 +37,7 @@ BTFIXUPDEF_CALL(void, free_pgd_fast, pgd_t *)
5333 BTFIXUPDEF_CALL(void, pgd_set, pgd_t *, pmd_t *)
5334 #define pgd_set(pgdp,pmdp) BTFIXUP_CALL(pgd_set)(pgdp,pmdp)
5335 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5336+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5337
5338 BTFIXUPDEF_CALL(pmd_t *, pmd_alloc_one, struct mm_struct *, unsigned long)
5339 #define pmd_alloc_one(mm, address) BTFIXUP_CALL(pmd_alloc_one)(mm, address)
5340diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5341index 40b2d7a..22a665b 100644
5342--- a/arch/sparc/include/asm/pgalloc_64.h
5343+++ b/arch/sparc/include/asm/pgalloc_64.h
5344@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5345 }
5346
5347 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5348+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5349
5350 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5351 {
5352diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5353index 3d71018..48a11c5 100644
5354--- a/arch/sparc/include/asm/pgtable_32.h
5355+++ b/arch/sparc/include/asm/pgtable_32.h
5356@@ -45,6 +45,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
5357 BTFIXUPDEF_INT(page_none)
5358 BTFIXUPDEF_INT(page_copy)
5359 BTFIXUPDEF_INT(page_readonly)
5360+
5361+#ifdef CONFIG_PAX_PAGEEXEC
5362+BTFIXUPDEF_INT(page_shared_noexec)
5363+BTFIXUPDEF_INT(page_copy_noexec)
5364+BTFIXUPDEF_INT(page_readonly_noexec)
5365+#endif
5366+
5367 BTFIXUPDEF_INT(page_kernel)
5368
5369 #define PMD_SHIFT SUN4C_PMD_SHIFT
5370@@ -66,6 +73,16 @@ extern pgprot_t PAGE_SHARED;
5371 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
5372 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
5373
5374+#ifdef CONFIG_PAX_PAGEEXEC
5375+extern pgprot_t PAGE_SHARED_NOEXEC;
5376+# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
5377+# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
5378+#else
5379+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5380+# define PAGE_COPY_NOEXEC PAGE_COPY
5381+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5382+#endif
5383+
5384 extern unsigned long page_kernel;
5385
5386 #ifdef MODULE
5387diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5388index f6ae2b2..b03ffc7 100644
5389--- a/arch/sparc/include/asm/pgtsrmmu.h
5390+++ b/arch/sparc/include/asm/pgtsrmmu.h
5391@@ -115,6 +115,13 @@
5392 SRMMU_EXEC | SRMMU_REF)
5393 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5394 SRMMU_EXEC | SRMMU_REF)
5395+
5396+#ifdef CONFIG_PAX_PAGEEXEC
5397+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5398+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5399+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5400+#endif
5401+
5402 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5403 SRMMU_DIRTY | SRMMU_REF)
5404
5405diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5406index 9689176..63c18ea 100644
5407--- a/arch/sparc/include/asm/spinlock_64.h
5408+++ b/arch/sparc/include/asm/spinlock_64.h
5409@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5410
5411 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5412
5413-static void inline arch_read_lock(arch_rwlock_t *lock)
5414+static inline void arch_read_lock(arch_rwlock_t *lock)
5415 {
5416 unsigned long tmp1, tmp2;
5417
5418 __asm__ __volatile__ (
5419 "1: ldsw [%2], %0\n"
5420 " brlz,pn %0, 2f\n"
5421-"4: add %0, 1, %1\n"
5422+"4: addcc %0, 1, %1\n"
5423+
5424+#ifdef CONFIG_PAX_REFCOUNT
5425+" tvs %%icc, 6\n"
5426+#endif
5427+
5428 " cas [%2], %0, %1\n"
5429 " cmp %0, %1\n"
5430 " bne,pn %%icc, 1b\n"
5431@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5432 " .previous"
5433 : "=&r" (tmp1), "=&r" (tmp2)
5434 : "r" (lock)
5435- : "memory");
5436+ : "memory", "cc");
5437 }
5438
5439-static int inline arch_read_trylock(arch_rwlock_t *lock)
5440+static inline int arch_read_trylock(arch_rwlock_t *lock)
5441 {
5442 int tmp1, tmp2;
5443
5444@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5445 "1: ldsw [%2], %0\n"
5446 " brlz,a,pn %0, 2f\n"
5447 " mov 0, %0\n"
5448-" add %0, 1, %1\n"
5449+" addcc %0, 1, %1\n"
5450+
5451+#ifdef CONFIG_PAX_REFCOUNT
5452+" tvs %%icc, 6\n"
5453+#endif
5454+
5455 " cas [%2], %0, %1\n"
5456 " cmp %0, %1\n"
5457 " bne,pn %%icc, 1b\n"
5458@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5459 return tmp1;
5460 }
5461
5462-static void inline arch_read_unlock(arch_rwlock_t *lock)
5463+static inline void arch_read_unlock(arch_rwlock_t *lock)
5464 {
5465 unsigned long tmp1, tmp2;
5466
5467 __asm__ __volatile__(
5468 "1: lduw [%2], %0\n"
5469-" sub %0, 1, %1\n"
5470+" subcc %0, 1, %1\n"
5471+
5472+#ifdef CONFIG_PAX_REFCOUNT
5473+" tvs %%icc, 6\n"
5474+#endif
5475+
5476 " cas [%2], %0, %1\n"
5477 " cmp %0, %1\n"
5478 " bne,pn %%xcc, 1b\n"
5479@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5480 : "memory");
5481 }
5482
5483-static void inline arch_write_lock(arch_rwlock_t *lock)
5484+static inline void arch_write_lock(arch_rwlock_t *lock)
5485 {
5486 unsigned long mask, tmp1, tmp2;
5487
5488@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5489 : "memory");
5490 }
5491
5492-static void inline arch_write_unlock(arch_rwlock_t *lock)
5493+static inline void arch_write_unlock(arch_rwlock_t *lock)
5494 {
5495 __asm__ __volatile__(
5496 " stw %%g0, [%0]"
5497@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5498 : "memory");
5499 }
5500
5501-static int inline arch_write_trylock(arch_rwlock_t *lock)
5502+static inline int arch_write_trylock(arch_rwlock_t *lock)
5503 {
5504 unsigned long mask, tmp1, tmp2, result;
5505
5506diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5507index c2a1080..21ed218 100644
5508--- a/arch/sparc/include/asm/thread_info_32.h
5509+++ b/arch/sparc/include/asm/thread_info_32.h
5510@@ -50,6 +50,8 @@ struct thread_info {
5511 unsigned long w_saved;
5512
5513 struct restart_block restart_block;
5514+
5515+ unsigned long lowest_stack;
5516 };
5517
5518 /*
5519diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5520index 01d057f..13a7d2f 100644
5521--- a/arch/sparc/include/asm/thread_info_64.h
5522+++ b/arch/sparc/include/asm/thread_info_64.h
5523@@ -63,6 +63,8 @@ struct thread_info {
5524 struct pt_regs *kern_una_regs;
5525 unsigned int kern_una_insn;
5526
5527+ unsigned long lowest_stack;
5528+
5529 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5530 };
5531
5532@@ -214,10 +216,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5533 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5534 /* flag bit 6 is available */
5535 #define TIF_32BIT 7 /* 32-bit binary */
5536-/* flag bit 8 is available */
5537+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5538 #define TIF_SECCOMP 9 /* secure computing */
5539 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5540 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5541+
5542 /* NOTE: Thread flags >= 12 should be ones we have no interest
5543 * in using in assembly, else we can't use the mask as
5544 * an immediate value in instructions such as andcc.
5545@@ -236,12 +239,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5546 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5547 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5548 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5549+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5550
5551 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5552 _TIF_DO_NOTIFY_RESUME_MASK | \
5553 _TIF_NEED_RESCHED)
5554 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5555
5556+#define _TIF_WORK_SYSCALL \
5557+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5558+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5559+
5560+
5561 /*
5562 * Thread-synchronous status.
5563 *
5564diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5565index e88fbe5..96b0ce5 100644
5566--- a/arch/sparc/include/asm/uaccess.h
5567+++ b/arch/sparc/include/asm/uaccess.h
5568@@ -1,5 +1,13 @@
5569 #ifndef ___ASM_SPARC_UACCESS_H
5570 #define ___ASM_SPARC_UACCESS_H
5571+
5572+#ifdef __KERNEL__
5573+#ifndef __ASSEMBLY__
5574+#include <linux/types.h>
5575+extern void check_object_size(const void *ptr, unsigned long n, bool to);
5576+#endif
5577+#endif
5578+
5579 #if defined(__sparc__) && defined(__arch64__)
5580 #include <asm/uaccess_64.h>
5581 #else
5582diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5583index 8303ac4..07f333d 100644
5584--- a/arch/sparc/include/asm/uaccess_32.h
5585+++ b/arch/sparc/include/asm/uaccess_32.h
5586@@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5587
5588 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5589 {
5590- if (n && __access_ok((unsigned long) to, n))
5591+ if ((long)n < 0)
5592+ return n;
5593+
5594+ if (n && __access_ok((unsigned long) to, n)) {
5595+ if (!__builtin_constant_p(n))
5596+ check_object_size(from, n, true);
5597 return __copy_user(to, (__force void __user *) from, n);
5598- else
5599+ } else
5600 return n;
5601 }
5602
5603 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5604 {
5605+ if ((long)n < 0)
5606+ return n;
5607+
5608+ if (!__builtin_constant_p(n))
5609+ check_object_size(from, n, true);
5610+
5611 return __copy_user(to, (__force void __user *) from, n);
5612 }
5613
5614 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5615 {
5616- if (n && __access_ok((unsigned long) from, n))
5617+ if ((long)n < 0)
5618+ return n;
5619+
5620+ if (n && __access_ok((unsigned long) from, n)) {
5621+ if (!__builtin_constant_p(n))
5622+ check_object_size(to, n, false);
5623 return __copy_user((__force void __user *) to, from, n);
5624- else
5625+ } else
5626 return n;
5627 }
5628
5629 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5630 {
5631+ if ((long)n < 0)
5632+ return n;
5633+
5634 return __copy_user((__force void __user *) to, from, n);
5635 }
5636
5637diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5638index a1091afb..380228e 100644
5639--- a/arch/sparc/include/asm/uaccess_64.h
5640+++ b/arch/sparc/include/asm/uaccess_64.h
5641@@ -10,6 +10,7 @@
5642 #include <linux/compiler.h>
5643 #include <linux/string.h>
5644 #include <linux/thread_info.h>
5645+#include <linux/kernel.h>
5646 #include <asm/asi.h>
5647 #include <asm/spitfire.h>
5648 #include <asm-generic/uaccess-unaligned.h>
5649@@ -212,8 +213,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5650 static inline unsigned long __must_check
5651 copy_from_user(void *to, const void __user *from, unsigned long size)
5652 {
5653- unsigned long ret = ___copy_from_user(to, from, size);
5654+ unsigned long ret;
5655
5656+ if ((long)size < 0 || size > INT_MAX)
5657+ return size;
5658+
5659+ if (!__builtin_constant_p(size))
5660+ check_object_size(to, size, false);
5661+
5662+ ret = ___copy_from_user(to, from, size);
5663 if (unlikely(ret))
5664 ret = copy_from_user_fixup(to, from, size);
5665
5666@@ -229,8 +237,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5667 static inline unsigned long __must_check
5668 copy_to_user(void __user *to, const void *from, unsigned long size)
5669 {
5670- unsigned long ret = ___copy_to_user(to, from, size);
5671+ unsigned long ret;
5672
5673+ if ((long)size < 0 || size > INT_MAX)
5674+ return size;
5675+
5676+ if (!__builtin_constant_p(size))
5677+ check_object_size(from, size, true);
5678+
5679+ ret = ___copy_to_user(to, from, size);
5680 if (unlikely(ret))
5681 ret = copy_to_user_fixup(to, from, size);
5682 return ret;
5683diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5684index cb85458..e063f17 100644
5685--- a/arch/sparc/kernel/Makefile
5686+++ b/arch/sparc/kernel/Makefile
5687@@ -3,7 +3,7 @@
5688 #
5689
5690 asflags-y := -ansi
5691-ccflags-y := -Werror
5692+#ccflags-y := -Werror
5693
5694 extra-y := head_$(BITS).o
5695 extra-y += init_task.o
5696diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5697index efa0754..74b03fe 100644
5698--- a/arch/sparc/kernel/process_32.c
5699+++ b/arch/sparc/kernel/process_32.c
5700@@ -200,7 +200,7 @@ void __show_backtrace(unsigned long fp)
5701 rw->ins[4], rw->ins[5],
5702 rw->ins[6],
5703 rw->ins[7]);
5704- printk("%pS\n", (void *) rw->ins[7]);
5705+ printk("%pA\n", (void *) rw->ins[7]);
5706 rw = (struct reg_window32 *) rw->ins[6];
5707 }
5708 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
5709@@ -267,14 +267,14 @@ void show_regs(struct pt_regs *r)
5710
5711 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5712 r->psr, r->pc, r->npc, r->y, print_tainted());
5713- printk("PC: <%pS>\n", (void *) r->pc);
5714+ printk("PC: <%pA>\n", (void *) r->pc);
5715 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5716 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5717 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5718 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5719 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5720 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5721- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5722+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5723
5724 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5725 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5726@@ -309,7 +309,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5727 rw = (struct reg_window32 *) fp;
5728 pc = rw->ins[7];
5729 printk("[%08lx : ", pc);
5730- printk("%pS ] ", (void *) pc);
5731+ printk("%pA ] ", (void *) pc);
5732 fp = rw->ins[6];
5733 } while (++count < 16);
5734 printk("\n");
5735diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5736index aff0c72..9067b39 100644
5737--- a/arch/sparc/kernel/process_64.c
5738+++ b/arch/sparc/kernel/process_64.c
5739@@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5740 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5741 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5742 if (regs->tstate & TSTATE_PRIV)
5743- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5744+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5745 }
5746
5747 void show_regs(struct pt_regs *regs)
5748 {
5749 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5750 regs->tpc, regs->tnpc, regs->y, print_tainted());
5751- printk("TPC: <%pS>\n", (void *) regs->tpc);
5752+ printk("TPC: <%pA>\n", (void *) regs->tpc);
5753 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5754 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5755 regs->u_regs[3]);
5756@@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5757 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5758 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5759 regs->u_regs[15]);
5760- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5761+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5762 show_regwindow(regs);
5763 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5764 }
5765@@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5766 ((tp && tp->task) ? tp->task->pid : -1));
5767
5768 if (gp->tstate & TSTATE_PRIV) {
5769- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5770+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5771 (void *) gp->tpc,
5772 (void *) gp->o7,
5773 (void *) gp->i7,
5774diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5775index 6f97c07..b1300ec 100644
5776--- a/arch/sparc/kernel/ptrace_64.c
5777+++ b/arch/sparc/kernel/ptrace_64.c
5778@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5779 return ret;
5780 }
5781
5782+#ifdef CONFIG_GRKERNSEC_SETXID
5783+extern void gr_delayed_cred_worker(void);
5784+#endif
5785+
5786 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5787 {
5788 int ret = 0;
5789@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5790 /* do the secure computing check first */
5791 secure_computing(regs->u_regs[UREG_G1]);
5792
5793+#ifdef CONFIG_GRKERNSEC_SETXID
5794+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5795+ gr_delayed_cred_worker();
5796+#endif
5797+
5798 if (test_thread_flag(TIF_SYSCALL_TRACE))
5799 ret = tracehook_report_syscall_entry(regs);
5800
5801@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5802
5803 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5804 {
5805+#ifdef CONFIG_GRKERNSEC_SETXID
5806+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5807+ gr_delayed_cred_worker();
5808+#endif
5809+
5810 audit_syscall_exit(regs);
5811
5812 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5813diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5814index 42b282f..28ce9f2 100644
5815--- a/arch/sparc/kernel/sys_sparc_32.c
5816+++ b/arch/sparc/kernel/sys_sparc_32.c
5817@@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5818 if (ARCH_SUN4C && len > 0x20000000)
5819 return -ENOMEM;
5820 if (!addr)
5821- addr = TASK_UNMAPPED_BASE;
5822+ addr = current->mm->mmap_base;
5823
5824 if (flags & MAP_SHARED)
5825 addr = COLOUR_ALIGN(addr);
5826@@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5827 }
5828 if (TASK_SIZE - PAGE_SIZE - len < addr)
5829 return -ENOMEM;
5830- if (!vmm || addr + len <= vmm->vm_start)
5831+ if (check_heap_stack_gap(vmm, addr, len))
5832 return addr;
5833 addr = vmm->vm_end;
5834 if (flags & MAP_SHARED)
5835diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5836index 3ee51f1..2ba4913 100644
5837--- a/arch/sparc/kernel/sys_sparc_64.c
5838+++ b/arch/sparc/kernel/sys_sparc_64.c
5839@@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5840 /* We do not accept a shared mapping if it would violate
5841 * cache aliasing constraints.
5842 */
5843- if ((flags & MAP_SHARED) &&
5844+ if ((filp || (flags & MAP_SHARED)) &&
5845 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5846 return -EINVAL;
5847 return addr;
5848@@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5849 if (filp || (flags & MAP_SHARED))
5850 do_color_align = 1;
5851
5852+#ifdef CONFIG_PAX_RANDMMAP
5853+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5854+#endif
5855+
5856 if (addr) {
5857 if (do_color_align)
5858 addr = COLOUR_ALIGN(addr, pgoff);
5859@@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5860 addr = PAGE_ALIGN(addr);
5861
5862 vma = find_vma(mm, addr);
5863- if (task_size - len >= addr &&
5864- (!vma || addr + len <= vma->vm_start))
5865+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5866 return addr;
5867 }
5868
5869 if (len > mm->cached_hole_size) {
5870- start_addr = addr = mm->free_area_cache;
5871+ start_addr = addr = mm->free_area_cache;
5872 } else {
5873- start_addr = addr = TASK_UNMAPPED_BASE;
5874+ start_addr = addr = mm->mmap_base;
5875 mm->cached_hole_size = 0;
5876 }
5877
5878@@ -174,14 +177,14 @@ full_search:
5879 vma = find_vma(mm, VA_EXCLUDE_END);
5880 }
5881 if (unlikely(task_size < addr)) {
5882- if (start_addr != TASK_UNMAPPED_BASE) {
5883- start_addr = addr = TASK_UNMAPPED_BASE;
5884+ if (start_addr != mm->mmap_base) {
5885+ start_addr = addr = mm->mmap_base;
5886 mm->cached_hole_size = 0;
5887 goto full_search;
5888 }
5889 return -ENOMEM;
5890 }
5891- if (likely(!vma || addr + len <= vma->vm_start)) {
5892+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5893 /*
5894 * Remember the place where we stopped the search:
5895 */
5896@@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5897 /* We do not accept a shared mapping if it would violate
5898 * cache aliasing constraints.
5899 */
5900- if ((flags & MAP_SHARED) &&
5901+ if ((filp || (flags & MAP_SHARED)) &&
5902 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5903 return -EINVAL;
5904 return addr;
5905@@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5906 addr = PAGE_ALIGN(addr);
5907
5908 vma = find_vma(mm, addr);
5909- if (task_size - len >= addr &&
5910- (!vma || addr + len <= vma->vm_start))
5911+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5912 return addr;
5913 }
5914
5915@@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5916 /* make sure it can fit in the remaining address space */
5917 if (likely(addr > len)) {
5918 vma = find_vma(mm, addr-len);
5919- if (!vma || addr <= vma->vm_start) {
5920+ if (check_heap_stack_gap(vma, addr - len, len)) {
5921 /* remember the address as a hint for next time */
5922 return (mm->free_area_cache = addr-len);
5923 }
5924@@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5925 if (unlikely(mm->mmap_base < len))
5926 goto bottomup;
5927
5928- addr = mm->mmap_base-len;
5929- if (do_color_align)
5930- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5931+ addr = mm->mmap_base - len;
5932
5933 do {
5934+ if (do_color_align)
5935+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5936 /*
5937 * Lookup failure means no vma is above this address,
5938 * else if new region fits below vma->vm_start,
5939 * return with success:
5940 */
5941 vma = find_vma(mm, addr);
5942- if (likely(!vma || addr+len <= vma->vm_start)) {
5943+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5944 /* remember the address as a hint for next time */
5945 return (mm->free_area_cache = addr);
5946 }
5947@@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5948 mm->cached_hole_size = vma->vm_start - addr;
5949
5950 /* try just below the current vma->vm_start */
5951- addr = vma->vm_start-len;
5952- if (do_color_align)
5953- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5954- } while (likely(len < vma->vm_start));
5955+ addr = skip_heap_stack_gap(vma, len);
5956+ } while (!IS_ERR_VALUE(addr));
5957
5958 bottomup:
5959 /*
5960@@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5961 gap == RLIM_INFINITY ||
5962 sysctl_legacy_va_layout) {
5963 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5964+
5965+#ifdef CONFIG_PAX_RANDMMAP
5966+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5967+ mm->mmap_base += mm->delta_mmap;
5968+#endif
5969+
5970 mm->get_unmapped_area = arch_get_unmapped_area;
5971 mm->unmap_area = arch_unmap_area;
5972 } else {
5973@@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5974 gap = (task_size / 6 * 5);
5975
5976 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5977+
5978+#ifdef CONFIG_PAX_RANDMMAP
5979+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5980+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5981+#endif
5982+
5983 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5984 mm->unmap_area = arch_unmap_area_topdown;
5985 }
5986diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
5987index 1d7e274..b39c527 100644
5988--- a/arch/sparc/kernel/syscalls.S
5989+++ b/arch/sparc/kernel/syscalls.S
5990@@ -62,7 +62,7 @@ sys32_rt_sigreturn:
5991 #endif
5992 .align 32
5993 1: ldx [%g6 + TI_FLAGS], %l5
5994- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5995+ andcc %l5, _TIF_WORK_SYSCALL, %g0
5996 be,pt %icc, rtrap
5997 nop
5998 call syscall_trace_leave
5999@@ -179,7 +179,7 @@ linux_sparc_syscall32:
6000
6001 srl %i5, 0, %o5 ! IEU1
6002 srl %i2, 0, %o2 ! IEU0 Group
6003- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6004+ andcc %l0, _TIF_WORK_SYSCALL, %g0
6005 bne,pn %icc, linux_syscall_trace32 ! CTI
6006 mov %i0, %l5 ! IEU1
6007 call %l7 ! CTI Group brk forced
6008@@ -202,7 +202,7 @@ linux_sparc_syscall:
6009
6010 mov %i3, %o3 ! IEU1
6011 mov %i4, %o4 ! IEU0 Group
6012- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6013+ andcc %l0, _TIF_WORK_SYSCALL, %g0
6014 bne,pn %icc, linux_syscall_trace ! CTI Group
6015 mov %i0, %l5 ! IEU0
6016 2: call %l7 ! CTI Group brk forced
6017@@ -226,7 +226,7 @@ ret_sys_call:
6018
6019 cmp %o0, -ERESTART_RESTARTBLOCK
6020 bgeu,pn %xcc, 1f
6021- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6022+ andcc %l0, _TIF_WORK_SYSCALL, %l6
6023 80:
6024 /* System call success, clear Carry condition code. */
6025 andn %g3, %g2, %g3
6026@@ -241,7 +241,7 @@ ret_sys_call:
6027 /* System call failure, set Carry condition code.
6028 * Also, get abs(errno) to return to the process.
6029 */
6030- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6031+ andcc %l0, _TIF_WORK_SYSCALL, %l6
6032 sub %g0, %o0, %o0
6033 or %g3, %g2, %g3
6034 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
6035diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6036index d2de213..6b22bc3 100644
6037--- a/arch/sparc/kernel/traps_32.c
6038+++ b/arch/sparc/kernel/traps_32.c
6039@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6040 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6041 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6042
6043+extern void gr_handle_kernel_exploit(void);
6044+
6045 void die_if_kernel(char *str, struct pt_regs *regs)
6046 {
6047 static int die_counter;
6048@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6049 count++ < 30 &&
6050 (((unsigned long) rw) >= PAGE_OFFSET) &&
6051 !(((unsigned long) rw) & 0x7)) {
6052- printk("Caller[%08lx]: %pS\n", rw->ins[7],
6053+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
6054 (void *) rw->ins[7]);
6055 rw = (struct reg_window32 *)rw->ins[6];
6056 }
6057 }
6058 printk("Instruction DUMP:");
6059 instruction_dump ((unsigned long *) regs->pc);
6060- if(regs->psr & PSR_PS)
6061+ if(regs->psr & PSR_PS) {
6062+ gr_handle_kernel_exploit();
6063 do_exit(SIGKILL);
6064+ }
6065 do_exit(SIGSEGV);
6066 }
6067
6068diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6069index c72fdf5..743a344 100644
6070--- a/arch/sparc/kernel/traps_64.c
6071+++ b/arch/sparc/kernel/traps_64.c
6072@@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6073 i + 1,
6074 p->trapstack[i].tstate, p->trapstack[i].tpc,
6075 p->trapstack[i].tnpc, p->trapstack[i].tt);
6076- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6077+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6078 }
6079 }
6080
6081@@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6082
6083 lvl -= 0x100;
6084 if (regs->tstate & TSTATE_PRIV) {
6085+
6086+#ifdef CONFIG_PAX_REFCOUNT
6087+ if (lvl == 6)
6088+ pax_report_refcount_overflow(regs);
6089+#endif
6090+
6091 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6092 die_if_kernel(buffer, regs);
6093 }
6094@@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6095 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6096 {
6097 char buffer[32];
6098-
6099+
6100 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6101 0, lvl, SIGTRAP) == NOTIFY_STOP)
6102 return;
6103
6104+#ifdef CONFIG_PAX_REFCOUNT
6105+ if (lvl == 6)
6106+ pax_report_refcount_overflow(regs);
6107+#endif
6108+
6109 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6110
6111 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6112@@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6113 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6114 printk("%s" "ERROR(%d): ",
6115 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6116- printk("TPC<%pS>\n", (void *) regs->tpc);
6117+ printk("TPC<%pA>\n", (void *) regs->tpc);
6118 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6119 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6120 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6121@@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6122 smp_processor_id(),
6123 (type & 0x1) ? 'I' : 'D',
6124 regs->tpc);
6125- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6126+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6127 panic("Irrecoverable Cheetah+ parity error.");
6128 }
6129
6130@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6131 smp_processor_id(),
6132 (type & 0x1) ? 'I' : 'D',
6133 regs->tpc);
6134- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6135+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6136 }
6137
6138 struct sun4v_error_entry {
6139@@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6140
6141 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6142 regs->tpc, tl);
6143- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6144+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6145 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6146- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6147+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6148 (void *) regs->u_regs[UREG_I7]);
6149 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6150 "pte[%lx] error[%lx]\n",
6151@@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6152
6153 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6154 regs->tpc, tl);
6155- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6156+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6157 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6158- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6159+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6160 (void *) regs->u_regs[UREG_I7]);
6161 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6162 "pte[%lx] error[%lx]\n",
6163@@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6164 fp = (unsigned long)sf->fp + STACK_BIAS;
6165 }
6166
6167- printk(" [%016lx] %pS\n", pc, (void *) pc);
6168+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6169 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6170 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6171 int index = tsk->curr_ret_stack;
6172 if (tsk->ret_stack && index >= graph) {
6173 pc = tsk->ret_stack[index - graph].ret;
6174- printk(" [%016lx] %pS\n", pc, (void *) pc);
6175+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6176 graph++;
6177 }
6178 }
6179@@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6180 return (struct reg_window *) (fp + STACK_BIAS);
6181 }
6182
6183+extern void gr_handle_kernel_exploit(void);
6184+
6185 void die_if_kernel(char *str, struct pt_regs *regs)
6186 {
6187 static int die_counter;
6188@@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6189 while (rw &&
6190 count++ < 30 &&
6191 kstack_valid(tp, (unsigned long) rw)) {
6192- printk("Caller[%016lx]: %pS\n", rw->ins[7],
6193+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
6194 (void *) rw->ins[7]);
6195
6196 rw = kernel_stack_up(rw);
6197@@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6198 }
6199 user_instruction_dump ((unsigned int __user *) regs->tpc);
6200 }
6201- if (regs->tstate & TSTATE_PRIV)
6202+ if (regs->tstate & TSTATE_PRIV) {
6203+ gr_handle_kernel_exploit();
6204 do_exit(SIGKILL);
6205+ }
6206 do_exit(SIGSEGV);
6207 }
6208 EXPORT_SYMBOL(die_if_kernel);
6209diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6210index dae85bc..af1e19d 100644
6211--- a/arch/sparc/kernel/unaligned_64.c
6212+++ b/arch/sparc/kernel/unaligned_64.c
6213@@ -279,7 +279,7 @@ static void log_unaligned(struct pt_regs *regs)
6214 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6215
6216 if (__ratelimit(&ratelimit)) {
6217- printk("Kernel unaligned access at TPC[%lx] %pS\n",
6218+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
6219 regs->tpc, (void *) regs->tpc);
6220 }
6221 }
6222diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6223index a3fc437..fea9957 100644
6224--- a/arch/sparc/lib/Makefile
6225+++ b/arch/sparc/lib/Makefile
6226@@ -2,7 +2,7 @@
6227 #
6228
6229 asflags-y := -ansi -DST_DIV0=0x02
6230-ccflags-y := -Werror
6231+#ccflags-y := -Werror
6232
6233 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
6234 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6235diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6236index 59186e0..f747d7a 100644
6237--- a/arch/sparc/lib/atomic_64.S
6238+++ b/arch/sparc/lib/atomic_64.S
6239@@ -18,7 +18,12 @@
6240 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
6241 BACKOFF_SETUP(%o2)
6242 1: lduw [%o1], %g1
6243- add %g1, %o0, %g7
6244+ addcc %g1, %o0, %g7
6245+
6246+#ifdef CONFIG_PAX_REFCOUNT
6247+ tvs %icc, 6
6248+#endif
6249+
6250 cas [%o1], %g1, %g7
6251 cmp %g1, %g7
6252 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6253@@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
6254 2: BACKOFF_SPIN(%o2, %o3, 1b)
6255 .size atomic_add, .-atomic_add
6256
6257+ .globl atomic_add_unchecked
6258+ .type atomic_add_unchecked,#function
6259+atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6260+ BACKOFF_SETUP(%o2)
6261+1: lduw [%o1], %g1
6262+ add %g1, %o0, %g7
6263+ cas [%o1], %g1, %g7
6264+ cmp %g1, %g7
6265+ bne,pn %icc, 2f
6266+ nop
6267+ retl
6268+ nop
6269+2: BACKOFF_SPIN(%o2, %o3, 1b)
6270+ .size atomic_add_unchecked, .-atomic_add_unchecked
6271+
6272 .globl atomic_sub
6273 .type atomic_sub,#function
6274 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6275 BACKOFF_SETUP(%o2)
6276 1: lduw [%o1], %g1
6277- sub %g1, %o0, %g7
6278+ subcc %g1, %o0, %g7
6279+
6280+#ifdef CONFIG_PAX_REFCOUNT
6281+ tvs %icc, 6
6282+#endif
6283+
6284 cas [%o1], %g1, %g7
6285 cmp %g1, %g7
6286 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6287@@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6288 2: BACKOFF_SPIN(%o2, %o3, 1b)
6289 .size atomic_sub, .-atomic_sub
6290
6291+ .globl atomic_sub_unchecked
6292+ .type atomic_sub_unchecked,#function
6293+atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6294+ BACKOFF_SETUP(%o2)
6295+1: lduw [%o1], %g1
6296+ sub %g1, %o0, %g7
6297+ cas [%o1], %g1, %g7
6298+ cmp %g1, %g7
6299+ bne,pn %icc, 2f
6300+ nop
6301+ retl
6302+ nop
6303+2: BACKOFF_SPIN(%o2, %o3, 1b)
6304+ .size atomic_sub_unchecked, .-atomic_sub_unchecked
6305+
6306 .globl atomic_add_ret
6307 .type atomic_add_ret,#function
6308 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6309 BACKOFF_SETUP(%o2)
6310 1: lduw [%o1], %g1
6311- add %g1, %o0, %g7
6312+ addcc %g1, %o0, %g7
6313+
6314+#ifdef CONFIG_PAX_REFCOUNT
6315+ tvs %icc, 6
6316+#endif
6317+
6318 cas [%o1], %g1, %g7
6319 cmp %g1, %g7
6320 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6321@@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6322 2: BACKOFF_SPIN(%o2, %o3, 1b)
6323 .size atomic_add_ret, .-atomic_add_ret
6324
6325+ .globl atomic_add_ret_unchecked
6326+ .type atomic_add_ret_unchecked,#function
6327+atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6328+ BACKOFF_SETUP(%o2)
6329+1: lduw [%o1], %g1
6330+ addcc %g1, %o0, %g7
6331+ cas [%o1], %g1, %g7
6332+ cmp %g1, %g7
6333+ bne,pn %icc, 2f
6334+ add %g7, %o0, %g7
6335+ sra %g7, 0, %o0
6336+ retl
6337+ nop
6338+2: BACKOFF_SPIN(%o2, %o3, 1b)
6339+ .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
6340+
6341 .globl atomic_sub_ret
6342 .type atomic_sub_ret,#function
6343 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6344 BACKOFF_SETUP(%o2)
6345 1: lduw [%o1], %g1
6346- sub %g1, %o0, %g7
6347+ subcc %g1, %o0, %g7
6348+
6349+#ifdef CONFIG_PAX_REFCOUNT
6350+ tvs %icc, 6
6351+#endif
6352+
6353 cas [%o1], %g1, %g7
6354 cmp %g1, %g7
6355 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6356@@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6357 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
6358 BACKOFF_SETUP(%o2)
6359 1: ldx [%o1], %g1
6360- add %g1, %o0, %g7
6361+ addcc %g1, %o0, %g7
6362+
6363+#ifdef CONFIG_PAX_REFCOUNT
6364+ tvs %xcc, 6
6365+#endif
6366+
6367 casx [%o1], %g1, %g7
6368 cmp %g1, %g7
6369 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6370@@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
6371 2: BACKOFF_SPIN(%o2, %o3, 1b)
6372 .size atomic64_add, .-atomic64_add
6373
6374+ .globl atomic64_add_unchecked
6375+ .type atomic64_add_unchecked,#function
6376+atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6377+ BACKOFF_SETUP(%o2)
6378+1: ldx [%o1], %g1
6379+ addcc %g1, %o0, %g7
6380+ casx [%o1], %g1, %g7
6381+ cmp %g1, %g7
6382+ bne,pn %xcc, 2f
6383+ nop
6384+ retl
6385+ nop
6386+2: BACKOFF_SPIN(%o2, %o3, 1b)
6387+ .size atomic64_add_unchecked, .-atomic64_add_unchecked
6388+
6389 .globl atomic64_sub
6390 .type atomic64_sub,#function
6391 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6392 BACKOFF_SETUP(%o2)
6393 1: ldx [%o1], %g1
6394- sub %g1, %o0, %g7
6395+ subcc %g1, %o0, %g7
6396+
6397+#ifdef CONFIG_PAX_REFCOUNT
6398+ tvs %xcc, 6
6399+#endif
6400+
6401 casx [%o1], %g1, %g7
6402 cmp %g1, %g7
6403 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6404@@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6405 2: BACKOFF_SPIN(%o2, %o3, 1b)
6406 .size atomic64_sub, .-atomic64_sub
6407
6408+ .globl atomic64_sub_unchecked
6409+ .type atomic64_sub_unchecked,#function
6410+atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6411+ BACKOFF_SETUP(%o2)
6412+1: ldx [%o1], %g1
6413+ subcc %g1, %o0, %g7
6414+ casx [%o1], %g1, %g7
6415+ cmp %g1, %g7
6416+ bne,pn %xcc, 2f
6417+ nop
6418+ retl
6419+ nop
6420+2: BACKOFF_SPIN(%o2, %o3, 1b)
6421+ .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
6422+
6423 .globl atomic64_add_ret
6424 .type atomic64_add_ret,#function
6425 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6426 BACKOFF_SETUP(%o2)
6427 1: ldx [%o1], %g1
6428- add %g1, %o0, %g7
6429+ addcc %g1, %o0, %g7
6430+
6431+#ifdef CONFIG_PAX_REFCOUNT
6432+ tvs %xcc, 6
6433+#endif
6434+
6435 casx [%o1], %g1, %g7
6436 cmp %g1, %g7
6437 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6438@@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6439 2: BACKOFF_SPIN(%o2, %o3, 1b)
6440 .size atomic64_add_ret, .-atomic64_add_ret
6441
6442+ .globl atomic64_add_ret_unchecked
6443+ .type atomic64_add_ret_unchecked,#function
6444+atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6445+ BACKOFF_SETUP(%o2)
6446+1: ldx [%o1], %g1
6447+ addcc %g1, %o0, %g7
6448+ casx [%o1], %g1, %g7
6449+ cmp %g1, %g7
6450+ bne,pn %xcc, 2f
6451+ add %g7, %o0, %g7
6452+ mov %g7, %o0
6453+ retl
6454+ nop
6455+2: BACKOFF_SPIN(%o2, %o3, 1b)
6456+ .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
6457+
6458 .globl atomic64_sub_ret
6459 .type atomic64_sub_ret,#function
6460 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6461 BACKOFF_SETUP(%o2)
6462 1: ldx [%o1], %g1
6463- sub %g1, %o0, %g7
6464+ subcc %g1, %o0, %g7
6465+
6466+#ifdef CONFIG_PAX_REFCOUNT
6467+ tvs %xcc, 6
6468+#endif
6469+
6470 casx [%o1], %g1, %g7
6471 cmp %g1, %g7
6472 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6473diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6474index f73c224..662af10 100644
6475--- a/arch/sparc/lib/ksyms.c
6476+++ b/arch/sparc/lib/ksyms.c
6477@@ -136,12 +136,18 @@ EXPORT_SYMBOL(__downgrade_write);
6478
6479 /* Atomic counter implementation. */
6480 EXPORT_SYMBOL(atomic_add);
6481+EXPORT_SYMBOL(atomic_add_unchecked);
6482 EXPORT_SYMBOL(atomic_add_ret);
6483+EXPORT_SYMBOL(atomic_add_ret_unchecked);
6484 EXPORT_SYMBOL(atomic_sub);
6485+EXPORT_SYMBOL(atomic_sub_unchecked);
6486 EXPORT_SYMBOL(atomic_sub_ret);
6487 EXPORT_SYMBOL(atomic64_add);
6488+EXPORT_SYMBOL(atomic64_add_unchecked);
6489 EXPORT_SYMBOL(atomic64_add_ret);
6490+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6491 EXPORT_SYMBOL(atomic64_sub);
6492+EXPORT_SYMBOL(atomic64_sub_unchecked);
6493 EXPORT_SYMBOL(atomic64_sub_ret);
6494
6495 /* Atomic bit operations. */
6496diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6497index 301421c..e2535d1 100644
6498--- a/arch/sparc/mm/Makefile
6499+++ b/arch/sparc/mm/Makefile
6500@@ -2,7 +2,7 @@
6501 #
6502
6503 asflags-y := -ansi
6504-ccflags-y := -Werror
6505+#ccflags-y := -Werror
6506
6507 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6508 obj-y += fault_$(BITS).o
6509diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6510index df3155a..eb708b8 100644
6511--- a/arch/sparc/mm/fault_32.c
6512+++ b/arch/sparc/mm/fault_32.c
6513@@ -21,6 +21,9 @@
6514 #include <linux/perf_event.h>
6515 #include <linux/interrupt.h>
6516 #include <linux/kdebug.h>
6517+#include <linux/slab.h>
6518+#include <linux/pagemap.h>
6519+#include <linux/compiler.h>
6520
6521 #include <asm/page.h>
6522 #include <asm/pgtable.h>
6523@@ -207,6 +210,268 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6524 return safe_compute_effective_address(regs, insn);
6525 }
6526
6527+#ifdef CONFIG_PAX_PAGEEXEC
6528+#ifdef CONFIG_PAX_DLRESOLVE
6529+static void pax_emuplt_close(struct vm_area_struct *vma)
6530+{
6531+ vma->vm_mm->call_dl_resolve = 0UL;
6532+}
6533+
6534+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6535+{
6536+ unsigned int *kaddr;
6537+
6538+ vmf->page = alloc_page(GFP_HIGHUSER);
6539+ if (!vmf->page)
6540+ return VM_FAULT_OOM;
6541+
6542+ kaddr = kmap(vmf->page);
6543+ memset(kaddr, 0, PAGE_SIZE);
6544+ kaddr[0] = 0x9DE3BFA8U; /* save */
6545+ flush_dcache_page(vmf->page);
6546+ kunmap(vmf->page);
6547+ return VM_FAULT_MAJOR;
6548+}
6549+
6550+static const struct vm_operations_struct pax_vm_ops = {
6551+ .close = pax_emuplt_close,
6552+ .fault = pax_emuplt_fault
6553+};
6554+
6555+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6556+{
6557+ int ret;
6558+
6559+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6560+ vma->vm_mm = current->mm;
6561+ vma->vm_start = addr;
6562+ vma->vm_end = addr + PAGE_SIZE;
6563+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6564+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6565+ vma->vm_ops = &pax_vm_ops;
6566+
6567+ ret = insert_vm_struct(current->mm, vma);
6568+ if (ret)
6569+ return ret;
6570+
6571+ ++current->mm->total_vm;
6572+ return 0;
6573+}
6574+#endif
6575+
6576+/*
6577+ * PaX: decide what to do with offenders (regs->pc = fault address)
6578+ *
6579+ * returns 1 when task should be killed
6580+ * 2 when patched PLT trampoline was detected
6581+ * 3 when unpatched PLT trampoline was detected
6582+ */
6583+static int pax_handle_fetch_fault(struct pt_regs *regs)
6584+{
6585+
6586+#ifdef CONFIG_PAX_EMUPLT
6587+ int err;
6588+
6589+ do { /* PaX: patched PLT emulation #1 */
6590+ unsigned int sethi1, sethi2, jmpl;
6591+
6592+ err = get_user(sethi1, (unsigned int *)regs->pc);
6593+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6594+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6595+
6596+ if (err)
6597+ break;
6598+
6599+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6600+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6601+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6602+ {
6603+ unsigned int addr;
6604+
6605+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6606+ addr = regs->u_regs[UREG_G1];
6607+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6608+ regs->pc = addr;
6609+ regs->npc = addr+4;
6610+ return 2;
6611+ }
6612+ } while (0);
6613+
6614+ { /* PaX: patched PLT emulation #2 */
6615+ unsigned int ba;
6616+
6617+ err = get_user(ba, (unsigned int *)regs->pc);
6618+
6619+ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6620+ unsigned int addr;
6621+
6622+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6623+ regs->pc = addr;
6624+ regs->npc = addr+4;
6625+ return 2;
6626+ }
6627+ }
6628+
6629+ do { /* PaX: patched PLT emulation #3 */
6630+ unsigned int sethi, jmpl, nop;
6631+
6632+ err = get_user(sethi, (unsigned int *)regs->pc);
6633+ err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
6634+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6635+
6636+ if (err)
6637+ break;
6638+
6639+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6640+ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6641+ nop == 0x01000000U)
6642+ {
6643+ unsigned int addr;
6644+
6645+ addr = (sethi & 0x003FFFFFU) << 10;
6646+ regs->u_regs[UREG_G1] = addr;
6647+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6648+ regs->pc = addr;
6649+ regs->npc = addr+4;
6650+ return 2;
6651+ }
6652+ } while (0);
6653+
6654+ do { /* PaX: unpatched PLT emulation step 1 */
6655+ unsigned int sethi, ba, nop;
6656+
6657+ err = get_user(sethi, (unsigned int *)regs->pc);
6658+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
6659+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6660+
6661+ if (err)
6662+ break;
6663+
6664+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6665+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6666+ nop == 0x01000000U)
6667+ {
6668+ unsigned int addr, save, call;
6669+
6670+ if ((ba & 0xFFC00000U) == 0x30800000U)
6671+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6672+ else
6673+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6674+
6675+ err = get_user(save, (unsigned int *)addr);
6676+ err |= get_user(call, (unsigned int *)(addr+4));
6677+ err |= get_user(nop, (unsigned int *)(addr+8));
6678+ if (err)
6679+ break;
6680+
6681+#ifdef CONFIG_PAX_DLRESOLVE
6682+ if (save == 0x9DE3BFA8U &&
6683+ (call & 0xC0000000U) == 0x40000000U &&
6684+ nop == 0x01000000U)
6685+ {
6686+ struct vm_area_struct *vma;
6687+ unsigned long call_dl_resolve;
6688+
6689+ down_read(&current->mm->mmap_sem);
6690+ call_dl_resolve = current->mm->call_dl_resolve;
6691+ up_read(&current->mm->mmap_sem);
6692+ if (likely(call_dl_resolve))
6693+ goto emulate;
6694+
6695+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6696+
6697+ down_write(&current->mm->mmap_sem);
6698+ if (current->mm->call_dl_resolve) {
6699+ call_dl_resolve = current->mm->call_dl_resolve;
6700+ up_write(&current->mm->mmap_sem);
6701+ if (vma)
6702+ kmem_cache_free(vm_area_cachep, vma);
6703+ goto emulate;
6704+ }
6705+
6706+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6707+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6708+ up_write(&current->mm->mmap_sem);
6709+ if (vma)
6710+ kmem_cache_free(vm_area_cachep, vma);
6711+ return 1;
6712+ }
6713+
6714+ if (pax_insert_vma(vma, call_dl_resolve)) {
6715+ up_write(&current->mm->mmap_sem);
6716+ kmem_cache_free(vm_area_cachep, vma);
6717+ return 1;
6718+ }
6719+
6720+ current->mm->call_dl_resolve = call_dl_resolve;
6721+ up_write(&current->mm->mmap_sem);
6722+
6723+emulate:
6724+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6725+ regs->pc = call_dl_resolve;
6726+ regs->npc = addr+4;
6727+ return 3;
6728+ }
6729+#endif
6730+
6731+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6732+ if ((save & 0xFFC00000U) == 0x05000000U &&
6733+ (call & 0xFFFFE000U) == 0x85C0A000U &&
6734+ nop == 0x01000000U)
6735+ {
6736+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6737+ regs->u_regs[UREG_G2] = addr + 4;
6738+ addr = (save & 0x003FFFFFU) << 10;
6739+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6740+ regs->pc = addr;
6741+ regs->npc = addr+4;
6742+ return 3;
6743+ }
6744+ }
6745+ } while (0);
6746+
6747+ do { /* PaX: unpatched PLT emulation step 2 */
6748+ unsigned int save, call, nop;
6749+
6750+ err = get_user(save, (unsigned int *)(regs->pc-4));
6751+ err |= get_user(call, (unsigned int *)regs->pc);
6752+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
6753+ if (err)
6754+ break;
6755+
6756+ if (save == 0x9DE3BFA8U &&
6757+ (call & 0xC0000000U) == 0x40000000U &&
6758+ nop == 0x01000000U)
6759+ {
6760+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6761+
6762+ regs->u_regs[UREG_RETPC] = regs->pc;
6763+ regs->pc = dl_resolve;
6764+ regs->npc = dl_resolve+4;
6765+ return 3;
6766+ }
6767+ } while (0);
6768+#endif
6769+
6770+ return 1;
6771+}
6772+
6773+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6774+{
6775+ unsigned long i;
6776+
6777+ printk(KERN_ERR "PAX: bytes at PC: ");
6778+ for (i = 0; i < 8; i++) {
6779+ unsigned int c;
6780+ if (get_user(c, (unsigned int *)pc+i))
6781+ printk(KERN_CONT "???????? ");
6782+ else
6783+ printk(KERN_CONT "%08x ", c);
6784+ }
6785+ printk("\n");
6786+}
6787+#endif
6788+
6789 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6790 int text_fault)
6791 {
6792@@ -282,6 +547,24 @@ good_area:
6793 if(!(vma->vm_flags & VM_WRITE))
6794 goto bad_area;
6795 } else {
6796+
6797+#ifdef CONFIG_PAX_PAGEEXEC
6798+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6799+ up_read(&mm->mmap_sem);
6800+ switch (pax_handle_fetch_fault(regs)) {
6801+
6802+#ifdef CONFIG_PAX_EMUPLT
6803+ case 2:
6804+ case 3:
6805+ return;
6806+#endif
6807+
6808+ }
6809+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6810+ do_group_exit(SIGKILL);
6811+ }
6812+#endif
6813+
6814 /* Allow reads even for write-only mappings */
6815 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
6816 goto bad_area;
6817diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6818index 1fe0429..aee2e87 100644
6819--- a/arch/sparc/mm/fault_64.c
6820+++ b/arch/sparc/mm/fault_64.c
6821@@ -21,6 +21,9 @@
6822 #include <linux/kprobes.h>
6823 #include <linux/kdebug.h>
6824 #include <linux/percpu.h>
6825+#include <linux/slab.h>
6826+#include <linux/pagemap.h>
6827+#include <linux/compiler.h>
6828
6829 #include <asm/page.h>
6830 #include <asm/pgtable.h>
6831@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6832 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6833 regs->tpc);
6834 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6835- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6836+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6837 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6838 dump_stack();
6839 unhandled_fault(regs->tpc, current, regs);
6840@@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6841 show_regs(regs);
6842 }
6843
6844+#ifdef CONFIG_PAX_PAGEEXEC
6845+#ifdef CONFIG_PAX_DLRESOLVE
6846+static void pax_emuplt_close(struct vm_area_struct *vma)
6847+{
6848+ vma->vm_mm->call_dl_resolve = 0UL;
6849+}
6850+
6851+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6852+{
6853+ unsigned int *kaddr;
6854+
6855+ vmf->page = alloc_page(GFP_HIGHUSER);
6856+ if (!vmf->page)
6857+ return VM_FAULT_OOM;
6858+
6859+ kaddr = kmap(vmf->page);
6860+ memset(kaddr, 0, PAGE_SIZE);
6861+ kaddr[0] = 0x9DE3BFA8U; /* save */
6862+ flush_dcache_page(vmf->page);
6863+ kunmap(vmf->page);
6864+ return VM_FAULT_MAJOR;
6865+}
6866+
6867+static const struct vm_operations_struct pax_vm_ops = {
6868+ .close = pax_emuplt_close,
6869+ .fault = pax_emuplt_fault
6870+};
6871+
6872+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6873+{
6874+ int ret;
6875+
6876+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6877+ vma->vm_mm = current->mm;
6878+ vma->vm_start = addr;
6879+ vma->vm_end = addr + PAGE_SIZE;
6880+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6881+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6882+ vma->vm_ops = &pax_vm_ops;
6883+
6884+ ret = insert_vm_struct(current->mm, vma);
6885+ if (ret)
6886+ return ret;
6887+
6888+ ++current->mm->total_vm;
6889+ return 0;
6890+}
6891+#endif
6892+
6893+/*
6894+ * PaX: decide what to do with offenders (regs->tpc = fault address)
6895+ *
6896+ * returns 1 when task should be killed
6897+ * 2 when patched PLT trampoline was detected
6898+ * 3 when unpatched PLT trampoline was detected
6899+ */
6900+static int pax_handle_fetch_fault(struct pt_regs *regs)
6901+{
6902+
6903+#ifdef CONFIG_PAX_EMUPLT
6904+ int err;
6905+
6906+ do { /* PaX: patched PLT emulation #1 */
6907+ unsigned int sethi1, sethi2, jmpl;
6908+
6909+ err = get_user(sethi1, (unsigned int *)regs->tpc);
6910+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6911+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6912+
6913+ if (err)
6914+ break;
6915+
6916+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6917+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6918+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6919+ {
6920+ unsigned long addr;
6921+
6922+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6923+ addr = regs->u_regs[UREG_G1];
6924+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6925+
6926+ if (test_thread_flag(TIF_32BIT))
6927+ addr &= 0xFFFFFFFFUL;
6928+
6929+ regs->tpc = addr;
6930+ regs->tnpc = addr+4;
6931+ return 2;
6932+ }
6933+ } while (0);
6934+
6935+ { /* PaX: patched PLT emulation #2 */
6936+ unsigned int ba;
6937+
6938+ err = get_user(ba, (unsigned int *)regs->tpc);
6939+
6940+ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6941+ unsigned long addr;
6942+
6943+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6944+
6945+ if (test_thread_flag(TIF_32BIT))
6946+ addr &= 0xFFFFFFFFUL;
6947+
6948+ regs->tpc = addr;
6949+ regs->tnpc = addr+4;
6950+ return 2;
6951+ }
6952+ }
6953+
6954+ do { /* PaX: patched PLT emulation #3 */
6955+ unsigned int sethi, jmpl, nop;
6956+
6957+ err = get_user(sethi, (unsigned int *)regs->tpc);
6958+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
6959+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6960+
6961+ if (err)
6962+ break;
6963+
6964+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6965+ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6966+ nop == 0x01000000U)
6967+ {
6968+ unsigned long addr;
6969+
6970+ addr = (sethi & 0x003FFFFFU) << 10;
6971+ regs->u_regs[UREG_G1] = addr;
6972+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6973+
6974+ if (test_thread_flag(TIF_32BIT))
6975+ addr &= 0xFFFFFFFFUL;
6976+
6977+ regs->tpc = addr;
6978+ regs->tnpc = addr+4;
6979+ return 2;
6980+ }
6981+ } while (0);
6982+
6983+ do { /* PaX: patched PLT emulation #4 */
6984+ unsigned int sethi, mov1, call, mov2;
6985+
6986+ err = get_user(sethi, (unsigned int *)regs->tpc);
6987+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6988+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
6989+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6990+
6991+ if (err)
6992+ break;
6993+
6994+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6995+ mov1 == 0x8210000FU &&
6996+ (call & 0xC0000000U) == 0x40000000U &&
6997+ mov2 == 0x9E100001U)
6998+ {
6999+ unsigned long addr;
7000+
7001+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
7002+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7003+
7004+ if (test_thread_flag(TIF_32BIT))
7005+ addr &= 0xFFFFFFFFUL;
7006+
7007+ regs->tpc = addr;
7008+ regs->tnpc = addr+4;
7009+ return 2;
7010+ }
7011+ } while (0);
7012+
7013+ do { /* PaX: patched PLT emulation #5 */
7014+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7015+
7016+ err = get_user(sethi, (unsigned int *)regs->tpc);
7017+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7018+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7019+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7020+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7021+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7022+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7023+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7024+
7025+ if (err)
7026+ break;
7027+
7028+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7029+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7030+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7031+ (or1 & 0xFFFFE000U) == 0x82106000U &&
7032+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7033+ sllx == 0x83287020U &&
7034+ jmpl == 0x81C04005U &&
7035+ nop == 0x01000000U)
7036+ {
7037+ unsigned long addr;
7038+
7039+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7040+ regs->u_regs[UREG_G1] <<= 32;
7041+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7042+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7043+ regs->tpc = addr;
7044+ regs->tnpc = addr+4;
7045+ return 2;
7046+ }
7047+ } while (0);
7048+
7049+ do { /* PaX: patched PLT emulation #6 */
7050+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7051+
7052+ err = get_user(sethi, (unsigned int *)regs->tpc);
7053+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7054+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7055+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7056+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
7057+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7058+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7059+
7060+ if (err)
7061+ break;
7062+
7063+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7064+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7065+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7066+ sllx == 0x83287020U &&
7067+ (or & 0xFFFFE000U) == 0x8A116000U &&
7068+ jmpl == 0x81C04005U &&
7069+ nop == 0x01000000U)
7070+ {
7071+ unsigned long addr;
7072+
7073+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7074+ regs->u_regs[UREG_G1] <<= 32;
7075+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7076+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7077+ regs->tpc = addr;
7078+ regs->tnpc = addr+4;
7079+ return 2;
7080+ }
7081+ } while (0);
7082+
7083+ do { /* PaX: unpatched PLT emulation step 1 */
7084+ unsigned int sethi, ba, nop;
7085+
7086+ err = get_user(sethi, (unsigned int *)regs->tpc);
7087+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7088+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7089+
7090+ if (err)
7091+ break;
7092+
7093+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7094+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7095+ nop == 0x01000000U)
7096+ {
7097+ unsigned long addr;
7098+ unsigned int save, call;
7099+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7100+
7101+ if ((ba & 0xFFC00000U) == 0x30800000U)
7102+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7103+ else
7104+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7105+
7106+ if (test_thread_flag(TIF_32BIT))
7107+ addr &= 0xFFFFFFFFUL;
7108+
7109+ err = get_user(save, (unsigned int *)addr);
7110+ err |= get_user(call, (unsigned int *)(addr+4));
7111+ err |= get_user(nop, (unsigned int *)(addr+8));
7112+ if (err)
7113+ break;
7114+
7115+#ifdef CONFIG_PAX_DLRESOLVE
7116+ if (save == 0x9DE3BFA8U &&
7117+ (call & 0xC0000000U) == 0x40000000U &&
7118+ nop == 0x01000000U)
7119+ {
7120+ struct vm_area_struct *vma;
7121+ unsigned long call_dl_resolve;
7122+
7123+ down_read(&current->mm->mmap_sem);
7124+ call_dl_resolve = current->mm->call_dl_resolve;
7125+ up_read(&current->mm->mmap_sem);
7126+ if (likely(call_dl_resolve))
7127+ goto emulate;
7128+
7129+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7130+
7131+ down_write(&current->mm->mmap_sem);
7132+ if (current->mm->call_dl_resolve) {
7133+ call_dl_resolve = current->mm->call_dl_resolve;
7134+ up_write(&current->mm->mmap_sem);
7135+ if (vma)
7136+ kmem_cache_free(vm_area_cachep, vma);
7137+ goto emulate;
7138+ }
7139+
7140+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7141+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7142+ up_write(&current->mm->mmap_sem);
7143+ if (vma)
7144+ kmem_cache_free(vm_area_cachep, vma);
7145+ return 1;
7146+ }
7147+
7148+ if (pax_insert_vma(vma, call_dl_resolve)) {
7149+ up_write(&current->mm->mmap_sem);
7150+ kmem_cache_free(vm_area_cachep, vma);
7151+ return 1;
7152+ }
7153+
7154+ current->mm->call_dl_resolve = call_dl_resolve;
7155+ up_write(&current->mm->mmap_sem);
7156+
7157+emulate:
7158+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7159+ regs->tpc = call_dl_resolve;
7160+ regs->tnpc = addr+4;
7161+ return 3;
7162+ }
7163+#endif
7164+
7165+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7166+ if ((save & 0xFFC00000U) == 0x05000000U &&
7167+ (call & 0xFFFFE000U) == 0x85C0A000U &&
7168+ nop == 0x01000000U)
7169+ {
7170+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7171+ regs->u_regs[UREG_G2] = addr + 4;
7172+ addr = (save & 0x003FFFFFU) << 10;
7173+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7174+
7175+ if (test_thread_flag(TIF_32BIT))
7176+ addr &= 0xFFFFFFFFUL;
7177+
7178+ regs->tpc = addr;
7179+ regs->tnpc = addr+4;
7180+ return 3;
7181+ }
7182+
7183+ /* PaX: 64-bit PLT stub */
7184+ err = get_user(sethi1, (unsigned int *)addr);
7185+ err |= get_user(sethi2, (unsigned int *)(addr+4));
7186+ err |= get_user(or1, (unsigned int *)(addr+8));
7187+ err |= get_user(or2, (unsigned int *)(addr+12));
7188+ err |= get_user(sllx, (unsigned int *)(addr+16));
7189+ err |= get_user(add, (unsigned int *)(addr+20));
7190+ err |= get_user(jmpl, (unsigned int *)(addr+24));
7191+ err |= get_user(nop, (unsigned int *)(addr+28));
7192+ if (err)
7193+ break;
7194+
7195+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7196+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7197+ (or1 & 0xFFFFE000U) == 0x88112000U &&
7198+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7199+ sllx == 0x89293020U &&
7200+ add == 0x8A010005U &&
7201+ jmpl == 0x89C14000U &&
7202+ nop == 0x01000000U)
7203+ {
7204+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7205+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7206+ regs->u_regs[UREG_G4] <<= 32;
7207+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7208+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7209+ regs->u_regs[UREG_G4] = addr + 24;
7210+ addr = regs->u_regs[UREG_G5];
7211+ regs->tpc = addr;
7212+ regs->tnpc = addr+4;
7213+ return 3;
7214+ }
7215+ }
7216+ } while (0);
7217+
7218+#ifdef CONFIG_PAX_DLRESOLVE
7219+ do { /* PaX: unpatched PLT emulation step 2 */
7220+ unsigned int save, call, nop;
7221+
7222+ err = get_user(save, (unsigned int *)(regs->tpc-4));
7223+ err |= get_user(call, (unsigned int *)regs->tpc);
7224+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7225+ if (err)
7226+ break;
7227+
7228+ if (save == 0x9DE3BFA8U &&
7229+ (call & 0xC0000000U) == 0x40000000U &&
7230+ nop == 0x01000000U)
7231+ {
7232+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7233+
7234+ if (test_thread_flag(TIF_32BIT))
7235+ dl_resolve &= 0xFFFFFFFFUL;
7236+
7237+ regs->u_regs[UREG_RETPC] = regs->tpc;
7238+ regs->tpc = dl_resolve;
7239+ regs->tnpc = dl_resolve+4;
7240+ return 3;
7241+ }
7242+ } while (0);
7243+#endif
7244+
7245+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7246+ unsigned int sethi, ba, nop;
7247+
7248+ err = get_user(sethi, (unsigned int *)regs->tpc);
7249+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7250+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7251+
7252+ if (err)
7253+ break;
7254+
7255+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7256+ (ba & 0xFFF00000U) == 0x30600000U &&
7257+ nop == 0x01000000U)
7258+ {
7259+ unsigned long addr;
7260+
7261+ addr = (sethi & 0x003FFFFFU) << 10;
7262+ regs->u_regs[UREG_G1] = addr;
7263+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7264+
7265+ if (test_thread_flag(TIF_32BIT))
7266+ addr &= 0xFFFFFFFFUL;
7267+
7268+ regs->tpc = addr;
7269+ regs->tnpc = addr+4;
7270+ return 2;
7271+ }
7272+ } while (0);
7273+
7274+#endif
7275+
7276+ return 1;
7277+}
7278+
7279+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7280+{
7281+ unsigned long i;
7282+
7283+ printk(KERN_ERR "PAX: bytes at PC: ");
7284+ for (i = 0; i < 8; i++) {
7285+ unsigned int c;
7286+ if (get_user(c, (unsigned int *)pc+i))
7287+ printk(KERN_CONT "???????? ");
7288+ else
7289+ printk(KERN_CONT "%08x ", c);
7290+ }
7291+ printk("\n");
7292+}
7293+#endif
7294+
7295 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7296 {
7297 struct mm_struct *mm = current->mm;
7298@@ -343,6 +797,29 @@ retry:
7299 if (!vma)
7300 goto bad_area;
7301
7302+#ifdef CONFIG_PAX_PAGEEXEC
7303+ /* PaX: detect ITLB misses on non-exec pages */
7304+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7305+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7306+ {
7307+ if (address != regs->tpc)
7308+ goto good_area;
7309+
7310+ up_read(&mm->mmap_sem);
7311+ switch (pax_handle_fetch_fault(regs)) {
7312+
7313+#ifdef CONFIG_PAX_EMUPLT
7314+ case 2:
7315+ case 3:
7316+ return;
7317+#endif
7318+
7319+ }
7320+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7321+ do_group_exit(SIGKILL);
7322+ }
7323+#endif
7324+
7325 /* Pure DTLB misses do not tell us whether the fault causing
7326 * load/store/atomic was a write or not, it only says that there
7327 * was no match. So in such a case we (carefully) read the
7328diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7329index 07e1453..0a7d9e9 100644
7330--- a/arch/sparc/mm/hugetlbpage.c
7331+++ b/arch/sparc/mm/hugetlbpage.c
7332@@ -67,7 +67,7 @@ full_search:
7333 }
7334 return -ENOMEM;
7335 }
7336- if (likely(!vma || addr + len <= vma->vm_start)) {
7337+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7338 /*
7339 * Remember the place where we stopped the search:
7340 */
7341@@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7342 /* make sure it can fit in the remaining address space */
7343 if (likely(addr > len)) {
7344 vma = find_vma(mm, addr-len);
7345- if (!vma || addr <= vma->vm_start) {
7346+ if (check_heap_stack_gap(vma, addr - len, len)) {
7347 /* remember the address as a hint for next time */
7348 return (mm->free_area_cache = addr-len);
7349 }
7350@@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7351 if (unlikely(mm->mmap_base < len))
7352 goto bottomup;
7353
7354- addr = (mm->mmap_base-len) & HPAGE_MASK;
7355+ addr = mm->mmap_base - len;
7356
7357 do {
7358+ addr &= HPAGE_MASK;
7359 /*
7360 * Lookup failure means no vma is above this address,
7361 * else if new region fits below vma->vm_start,
7362 * return with success:
7363 */
7364 vma = find_vma(mm, addr);
7365- if (likely(!vma || addr+len <= vma->vm_start)) {
7366+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7367 /* remember the address as a hint for next time */
7368 return (mm->free_area_cache = addr);
7369 }
7370@@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7371 mm->cached_hole_size = vma->vm_start - addr;
7372
7373 /* try just below the current vma->vm_start */
7374- addr = (vma->vm_start-len) & HPAGE_MASK;
7375- } while (likely(len < vma->vm_start));
7376+ addr = skip_heap_stack_gap(vma, len);
7377+ } while (!IS_ERR_VALUE(addr));
7378
7379 bottomup:
7380 /*
7381@@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7382 if (addr) {
7383 addr = ALIGN(addr, HPAGE_SIZE);
7384 vma = find_vma(mm, addr);
7385- if (task_size - len >= addr &&
7386- (!vma || addr + len <= vma->vm_start))
7387+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7388 return addr;
7389 }
7390 if (mm->get_unmapped_area == arch_get_unmapped_area)
7391diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
7392index c5f9021..7591bae 100644
7393--- a/arch/sparc/mm/init_32.c
7394+++ b/arch/sparc/mm/init_32.c
7395@@ -315,6 +315,9 @@ extern void device_scan(void);
7396 pgprot_t PAGE_SHARED __read_mostly;
7397 EXPORT_SYMBOL(PAGE_SHARED);
7398
7399+pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
7400+EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
7401+
7402 void __init paging_init(void)
7403 {
7404 switch(sparc_cpu_model) {
7405@@ -343,17 +346,17 @@ void __init paging_init(void)
7406
7407 /* Initialize the protection map with non-constant, MMU dependent values. */
7408 protection_map[0] = PAGE_NONE;
7409- protection_map[1] = PAGE_READONLY;
7410- protection_map[2] = PAGE_COPY;
7411- protection_map[3] = PAGE_COPY;
7412+ protection_map[1] = PAGE_READONLY_NOEXEC;
7413+ protection_map[2] = PAGE_COPY_NOEXEC;
7414+ protection_map[3] = PAGE_COPY_NOEXEC;
7415 protection_map[4] = PAGE_READONLY;
7416 protection_map[5] = PAGE_READONLY;
7417 protection_map[6] = PAGE_COPY;
7418 protection_map[7] = PAGE_COPY;
7419 protection_map[8] = PAGE_NONE;
7420- protection_map[9] = PAGE_READONLY;
7421- protection_map[10] = PAGE_SHARED;
7422- protection_map[11] = PAGE_SHARED;
7423+ protection_map[9] = PAGE_READONLY_NOEXEC;
7424+ protection_map[10] = PAGE_SHARED_NOEXEC;
7425+ protection_map[11] = PAGE_SHARED_NOEXEC;
7426 protection_map[12] = PAGE_READONLY;
7427 protection_map[13] = PAGE_READONLY;
7428 protection_map[14] = PAGE_SHARED;
7429diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
7430index cbef74e..c38fead 100644
7431--- a/arch/sparc/mm/srmmu.c
7432+++ b/arch/sparc/mm/srmmu.c
7433@@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
7434 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
7435 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
7436 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
7437+
7438+#ifdef CONFIG_PAX_PAGEEXEC
7439+ PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
7440+ BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
7441+ BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
7442+#endif
7443+
7444 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
7445 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
7446
7447diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7448index f4500c6..889656c 100644
7449--- a/arch/tile/include/asm/atomic_64.h
7450+++ b/arch/tile/include/asm/atomic_64.h
7451@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7452
7453 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7454
7455+#define atomic64_read_unchecked(v) atomic64_read(v)
7456+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7457+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7458+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7459+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7460+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7461+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7462+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7463+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7464+
7465 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7466 #define smp_mb__before_atomic_dec() smp_mb()
7467 #define smp_mb__after_atomic_dec() smp_mb()
7468diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7469index 392e533..536b092 100644
7470--- a/arch/tile/include/asm/cache.h
7471+++ b/arch/tile/include/asm/cache.h
7472@@ -15,11 +15,12 @@
7473 #ifndef _ASM_TILE_CACHE_H
7474 #define _ASM_TILE_CACHE_H
7475
7476+#include <linux/const.h>
7477 #include <arch/chip.h>
7478
7479 /* bytes per L1 data cache line */
7480 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7481-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7482+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7483
7484 /* bytes per L2 cache line */
7485 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7486diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7487index ef34d2c..d6ce60c 100644
7488--- a/arch/tile/include/asm/uaccess.h
7489+++ b/arch/tile/include/asm/uaccess.h
7490@@ -361,9 +361,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7491 const void __user *from,
7492 unsigned long n)
7493 {
7494- int sz = __compiletime_object_size(to);
7495+ size_t sz = __compiletime_object_size(to);
7496
7497- if (likely(sz == -1 || sz >= n))
7498+ if (likely(sz == (size_t)-1 || sz >= n))
7499 n = _copy_from_user(to, from, n);
7500 else
7501 copy_from_user_overflow();
7502diff --git a/arch/um/Makefile b/arch/um/Makefile
7503index 55c0661..86ad413 100644
7504--- a/arch/um/Makefile
7505+++ b/arch/um/Makefile
7506@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7507 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7508 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7509
7510+ifdef CONSTIFY_PLUGIN
7511+USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7512+endif
7513+
7514 #This will adjust *FLAGS accordingly to the platform.
7515 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7516
7517diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7518index 19e1bdd..3665b77 100644
7519--- a/arch/um/include/asm/cache.h
7520+++ b/arch/um/include/asm/cache.h
7521@@ -1,6 +1,7 @@
7522 #ifndef __UM_CACHE_H
7523 #define __UM_CACHE_H
7524
7525+#include <linux/const.h>
7526
7527 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7528 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7529@@ -12,6 +13,6 @@
7530 # define L1_CACHE_SHIFT 5
7531 #endif
7532
7533-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7534+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7535
7536 #endif
7537diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7538index 6c03acd..a5e0215 100644
7539--- a/arch/um/include/asm/kmap_types.h
7540+++ b/arch/um/include/asm/kmap_types.h
7541@@ -23,6 +23,7 @@ enum km_type {
7542 KM_IRQ1,
7543 KM_SOFTIRQ0,
7544 KM_SOFTIRQ1,
7545+ KM_CLEARPAGE,
7546 KM_TYPE_NR
7547 };
7548
7549diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7550index 7cfc3ce..cbd1a58 100644
7551--- a/arch/um/include/asm/page.h
7552+++ b/arch/um/include/asm/page.h
7553@@ -14,6 +14,9 @@
7554 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7555 #define PAGE_MASK (~(PAGE_SIZE-1))
7556
7557+#define ktla_ktva(addr) (addr)
7558+#define ktva_ktla(addr) (addr)
7559+
7560 #ifndef __ASSEMBLY__
7561
7562 struct page;
7563diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7564index 0032f92..cd151e0 100644
7565--- a/arch/um/include/asm/pgtable-3level.h
7566+++ b/arch/um/include/asm/pgtable-3level.h
7567@@ -58,6 +58,7 @@
7568 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7569 #define pud_populate(mm, pud, pmd) \
7570 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7571+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7572
7573 #ifdef CONFIG_64BIT
7574 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7575diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7576index 2b73ded..804f540 100644
7577--- a/arch/um/kernel/process.c
7578+++ b/arch/um/kernel/process.c
7579@@ -404,22 +404,6 @@ int singlestepping(void * t)
7580 return 2;
7581 }
7582
7583-/*
7584- * Only x86 and x86_64 have an arch_align_stack().
7585- * All other arches have "#define arch_align_stack(x) (x)"
7586- * in their asm/system.h
7587- * As this is included in UML from asm-um/system-generic.h,
7588- * we can use it to behave as the subarch does.
7589- */
7590-#ifndef arch_align_stack
7591-unsigned long arch_align_stack(unsigned long sp)
7592-{
7593- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7594- sp -= get_random_int() % 8192;
7595- return sp & ~0xf;
7596-}
7597-#endif
7598-
7599 unsigned long get_wchan(struct task_struct *p)
7600 {
7601 unsigned long stack_page, sp, ip;
7602diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7603index ad8f795..2c7eec6 100644
7604--- a/arch/unicore32/include/asm/cache.h
7605+++ b/arch/unicore32/include/asm/cache.h
7606@@ -12,8 +12,10 @@
7607 #ifndef __UNICORE_CACHE_H__
7608 #define __UNICORE_CACHE_H__
7609
7610-#define L1_CACHE_SHIFT (5)
7611-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7612+#include <linux/const.h>
7613+
7614+#define L1_CACHE_SHIFT 5
7615+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7616
7617 /*
7618 * Memory returned by kmalloc() may be used for DMA, so we must make
7619diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7620index c9866b0..fe53aef 100644
7621--- a/arch/x86/Kconfig
7622+++ b/arch/x86/Kconfig
7623@@ -229,7 +229,7 @@ config X86_HT
7624
7625 config X86_32_LAZY_GS
7626 def_bool y
7627- depends on X86_32 && !CC_STACKPROTECTOR
7628+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7629
7630 config ARCH_HWEIGHT_CFLAGS
7631 string
7632@@ -1042,7 +1042,7 @@ choice
7633
7634 config NOHIGHMEM
7635 bool "off"
7636- depends on !X86_NUMAQ
7637+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7638 ---help---
7639 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7640 However, the address space of 32-bit x86 processors is only 4
7641@@ -1079,7 +1079,7 @@ config NOHIGHMEM
7642
7643 config HIGHMEM4G
7644 bool "4GB"
7645- depends on !X86_NUMAQ
7646+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7647 ---help---
7648 Select this if you have a 32-bit processor and between 1 and 4
7649 gigabytes of physical RAM.
7650@@ -1133,7 +1133,7 @@ config PAGE_OFFSET
7651 hex
7652 default 0xB0000000 if VMSPLIT_3G_OPT
7653 default 0x80000000 if VMSPLIT_2G
7654- default 0x78000000 if VMSPLIT_2G_OPT
7655+ default 0x70000000 if VMSPLIT_2G_OPT
7656 default 0x40000000 if VMSPLIT_1G
7657 default 0xC0000000
7658 depends on X86_32
7659@@ -1523,6 +1523,7 @@ config SECCOMP
7660
7661 config CC_STACKPROTECTOR
7662 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7663+ depends on X86_64 || !PAX_MEMORY_UDEREF
7664 ---help---
7665 This option turns on the -fstack-protector GCC feature. This
7666 feature puts, at the beginning of functions, a canary value on
7667@@ -1580,6 +1581,7 @@ config KEXEC_JUMP
7668 config PHYSICAL_START
7669 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7670 default "0x1000000"
7671+ range 0x400000 0x40000000
7672 ---help---
7673 This gives the physical address where the kernel is loaded.
7674
7675@@ -1643,6 +1645,7 @@ config X86_NEED_RELOCS
7676 config PHYSICAL_ALIGN
7677 hex "Alignment value to which kernel should be aligned" if X86_32
7678 default "0x1000000"
7679+ range 0x400000 0x1000000 if PAX_KERNEXEC
7680 range 0x2000 0x1000000
7681 ---help---
7682 This value puts the alignment restrictions on physical address
7683@@ -1674,9 +1677,10 @@ config HOTPLUG_CPU
7684 Say N if you want to disable CPU hotplug.
7685
7686 config COMPAT_VDSO
7687- def_bool y
7688+ def_bool n
7689 prompt "Compat VDSO support"
7690 depends on X86_32 || IA32_EMULATION
7691+ depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7692 ---help---
7693 Map the 32-bit VDSO to the predictable old-style address too.
7694
7695diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7696index 706e12e..62e4feb 100644
7697--- a/arch/x86/Kconfig.cpu
7698+++ b/arch/x86/Kconfig.cpu
7699@@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7700
7701 config X86_F00F_BUG
7702 def_bool y
7703- depends on M586MMX || M586TSC || M586 || M486 || M386
7704+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7705
7706 config X86_INVD_BUG
7707 def_bool y
7708@@ -358,7 +358,7 @@ config X86_POPAD_OK
7709
7710 config X86_ALIGNMENT_16
7711 def_bool y
7712- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7713+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7714
7715 config X86_INTEL_USERCOPY
7716 def_bool y
7717@@ -404,7 +404,7 @@ config X86_CMPXCHG64
7718 # generates cmov.
7719 config X86_CMOV
7720 def_bool y
7721- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7722+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7723
7724 config X86_MINIMUM_CPU_FAMILY
7725 int
7726diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7727index e46c214..7c72b55 100644
7728--- a/arch/x86/Kconfig.debug
7729+++ b/arch/x86/Kconfig.debug
7730@@ -84,7 +84,7 @@ config X86_PTDUMP
7731 config DEBUG_RODATA
7732 bool "Write protect kernel read-only data structures"
7733 default y
7734- depends on DEBUG_KERNEL
7735+ depends on DEBUG_KERNEL && BROKEN
7736 ---help---
7737 Mark the kernel read-only data as write-protected in the pagetables,
7738 in order to catch accidental (and incorrect) writes to such const
7739@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7740
7741 config DEBUG_SET_MODULE_RONX
7742 bool "Set loadable kernel module data as NX and text as RO"
7743- depends on MODULES
7744+ depends on MODULES && BROKEN
7745 ---help---
7746 This option helps catch unintended modifications to loadable
7747 kernel module's text and read-only data. It also prevents execution
7748diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7749index b1c611e..2c1a823 100644
7750--- a/arch/x86/Makefile
7751+++ b/arch/x86/Makefile
7752@@ -46,6 +46,7 @@ else
7753 UTS_MACHINE := x86_64
7754 CHECKFLAGS += -D__x86_64__ -m64
7755
7756+ biarch := $(call cc-option,-m64)
7757 KBUILD_AFLAGS += -m64
7758 KBUILD_CFLAGS += -m64
7759
7760@@ -222,3 +223,12 @@ define archhelp
7761 echo ' FDARGS="..." arguments for the booted kernel'
7762 echo ' FDINITRD=file initrd for the booted kernel'
7763 endef
7764+
7765+define OLD_LD
7766+
7767+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7768+*** Please upgrade your binutils to 2.18 or newer
7769+endef
7770+
7771+archprepare:
7772+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7773diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7774index 5a747dd..ff7b12c 100644
7775--- a/arch/x86/boot/Makefile
7776+++ b/arch/x86/boot/Makefile
7777@@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7778 $(call cc-option, -fno-stack-protector) \
7779 $(call cc-option, -mpreferred-stack-boundary=2)
7780 KBUILD_CFLAGS += $(call cc-option, -m32)
7781+ifdef CONSTIFY_PLUGIN
7782+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7783+endif
7784 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7785 GCOV_PROFILE := n
7786
7787diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7788index 878e4b9..20537ab 100644
7789--- a/arch/x86/boot/bitops.h
7790+++ b/arch/x86/boot/bitops.h
7791@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7792 u8 v;
7793 const u32 *p = (const u32 *)addr;
7794
7795- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7796+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7797 return v;
7798 }
7799
7800@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7801
7802 static inline void set_bit(int nr, void *addr)
7803 {
7804- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7805+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7806 }
7807
7808 #endif /* BOOT_BITOPS_H */
7809diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7810index 18997e5..83d9c67 100644
7811--- a/arch/x86/boot/boot.h
7812+++ b/arch/x86/boot/boot.h
7813@@ -85,7 +85,7 @@ static inline void io_delay(void)
7814 static inline u16 ds(void)
7815 {
7816 u16 seg;
7817- asm("movw %%ds,%0" : "=rm" (seg));
7818+ asm volatile("movw %%ds,%0" : "=rm" (seg));
7819 return seg;
7820 }
7821
7822@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7823 static inline int memcmp(const void *s1, const void *s2, size_t len)
7824 {
7825 u8 diff;
7826- asm("repe; cmpsb; setnz %0"
7827+ asm volatile("repe; cmpsb; setnz %0"
7828 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7829 return diff;
7830 }
7831diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7832index e398bb5..3a382ca 100644
7833--- a/arch/x86/boot/compressed/Makefile
7834+++ b/arch/x86/boot/compressed/Makefile
7835@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7836 KBUILD_CFLAGS += $(cflags-y)
7837 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7838 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7839+ifdef CONSTIFY_PLUGIN
7840+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7841+endif
7842
7843 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7844 GCOV_PROFILE := n
7845diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7846index 0cdfc0d..6e79437 100644
7847--- a/arch/x86/boot/compressed/eboot.c
7848+++ b/arch/x86/boot/compressed/eboot.c
7849@@ -122,7 +122,6 @@ again:
7850 *addr = max_addr;
7851 }
7852
7853-free_pool:
7854 efi_call_phys1(sys_table->boottime->free_pool, map);
7855
7856 fail:
7857@@ -186,7 +185,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7858 if (i == map_size / desc_size)
7859 status = EFI_NOT_FOUND;
7860
7861-free_pool:
7862 efi_call_phys1(sys_table->boottime->free_pool, map);
7863 fail:
7864 return status;
7865diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7866index c85e3ac..6f5aa80 100644
7867--- a/arch/x86/boot/compressed/head_32.S
7868+++ b/arch/x86/boot/compressed/head_32.S
7869@@ -106,7 +106,7 @@ preferred_addr:
7870 notl %eax
7871 andl %eax, %ebx
7872 #else
7873- movl $LOAD_PHYSICAL_ADDR, %ebx
7874+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7875 #endif
7876
7877 /* Target address to relocate to for decompression */
7878@@ -192,7 +192,7 @@ relocated:
7879 * and where it was actually loaded.
7880 */
7881 movl %ebp, %ebx
7882- subl $LOAD_PHYSICAL_ADDR, %ebx
7883+ subl $____LOAD_PHYSICAL_ADDR, %ebx
7884 jz 2f /* Nothing to be done if loaded at compiled addr. */
7885 /*
7886 * Process relocations.
7887@@ -200,8 +200,7 @@ relocated:
7888
7889 1: subl $4, %edi
7890 movl (%edi), %ecx
7891- testl %ecx, %ecx
7892- jz 2f
7893+ jecxz 2f
7894 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7895 jmp 1b
7896 2:
7897diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7898index 87e03a1..0d94c76 100644
7899--- a/arch/x86/boot/compressed/head_64.S
7900+++ b/arch/x86/boot/compressed/head_64.S
7901@@ -91,7 +91,7 @@ ENTRY(startup_32)
7902 notl %eax
7903 andl %eax, %ebx
7904 #else
7905- movl $LOAD_PHYSICAL_ADDR, %ebx
7906+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7907 #endif
7908
7909 /* Target address to relocate to for decompression */
7910@@ -263,7 +263,7 @@ preferred_addr:
7911 notq %rax
7912 andq %rax, %rbp
7913 #else
7914- movq $LOAD_PHYSICAL_ADDR, %rbp
7915+ movq $____LOAD_PHYSICAL_ADDR, %rbp
7916 #endif
7917
7918 /* Target address to relocate to for decompression */
7919diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7920index 7116dcb..d9ae1d7 100644
7921--- a/arch/x86/boot/compressed/misc.c
7922+++ b/arch/x86/boot/compressed/misc.c
7923@@ -310,7 +310,7 @@ static void parse_elf(void *output)
7924 case PT_LOAD:
7925 #ifdef CONFIG_RELOCATABLE
7926 dest = output;
7927- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7928+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7929 #else
7930 dest = (void *)(phdr->p_paddr);
7931 #endif
7932@@ -365,7 +365,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7933 error("Destination address too large");
7934 #endif
7935 #ifndef CONFIG_RELOCATABLE
7936- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7937+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7938 error("Wrong destination address");
7939 #endif
7940
7941diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7942index 4d3ff03..e4972ff 100644
7943--- a/arch/x86/boot/cpucheck.c
7944+++ b/arch/x86/boot/cpucheck.c
7945@@ -74,7 +74,7 @@ static int has_fpu(void)
7946 u16 fcw = -1, fsw = -1;
7947 u32 cr0;
7948
7949- asm("movl %%cr0,%0" : "=r" (cr0));
7950+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
7951 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7952 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7953 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7954@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7955 {
7956 u32 f0, f1;
7957
7958- asm("pushfl ; "
7959+ asm volatile("pushfl ; "
7960 "pushfl ; "
7961 "popl %0 ; "
7962 "movl %0,%1 ; "
7963@@ -115,7 +115,7 @@ static void get_flags(void)
7964 set_bit(X86_FEATURE_FPU, cpu.flags);
7965
7966 if (has_eflag(X86_EFLAGS_ID)) {
7967- asm("cpuid"
7968+ asm volatile("cpuid"
7969 : "=a" (max_intel_level),
7970 "=b" (cpu_vendor[0]),
7971 "=d" (cpu_vendor[1]),
7972@@ -124,7 +124,7 @@ static void get_flags(void)
7973
7974 if (max_intel_level >= 0x00000001 &&
7975 max_intel_level <= 0x0000ffff) {
7976- asm("cpuid"
7977+ asm volatile("cpuid"
7978 : "=a" (tfms),
7979 "=c" (cpu.flags[4]),
7980 "=d" (cpu.flags[0])
7981@@ -136,7 +136,7 @@ static void get_flags(void)
7982 cpu.model += ((tfms >> 16) & 0xf) << 4;
7983 }
7984
7985- asm("cpuid"
7986+ asm volatile("cpuid"
7987 : "=a" (max_amd_level)
7988 : "a" (0x80000000)
7989 : "ebx", "ecx", "edx");
7990@@ -144,7 +144,7 @@ static void get_flags(void)
7991 if (max_amd_level >= 0x80000001 &&
7992 max_amd_level <= 0x8000ffff) {
7993 u32 eax = 0x80000001;
7994- asm("cpuid"
7995+ asm volatile("cpuid"
7996 : "+a" (eax),
7997 "=c" (cpu.flags[6]),
7998 "=d" (cpu.flags[1])
7999@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8000 u32 ecx = MSR_K7_HWCR;
8001 u32 eax, edx;
8002
8003- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8004+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8005 eax &= ~(1 << 15);
8006- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8007+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8008
8009 get_flags(); /* Make sure it really did something */
8010 err = check_flags();
8011@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8012 u32 ecx = MSR_VIA_FCR;
8013 u32 eax, edx;
8014
8015- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8016+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8017 eax |= (1<<1)|(1<<7);
8018- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8019+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8020
8021 set_bit(X86_FEATURE_CX8, cpu.flags);
8022 err = check_flags();
8023@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8024 u32 eax, edx;
8025 u32 level = 1;
8026
8027- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8028- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8029- asm("cpuid"
8030+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8031+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8032+ asm volatile("cpuid"
8033 : "+a" (level), "=d" (cpu.flags[0])
8034 : : "ecx", "ebx");
8035- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8036+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8037
8038 err = check_flags();
8039 }
8040diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
8041index f1bbeeb..aff09cb 100644
8042--- a/arch/x86/boot/header.S
8043+++ b/arch/x86/boot/header.S
8044@@ -372,7 +372,7 @@ setup_data: .quad 0 # 64-bit physical pointer to
8045 # single linked list of
8046 # struct setup_data
8047
8048-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
8049+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
8050
8051 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8052 #define VO_INIT_SIZE (VO__end - VO__text)
8053diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8054index db75d07..8e6d0af 100644
8055--- a/arch/x86/boot/memory.c
8056+++ b/arch/x86/boot/memory.c
8057@@ -19,7 +19,7 @@
8058
8059 static int detect_memory_e820(void)
8060 {
8061- int count = 0;
8062+ unsigned int count = 0;
8063 struct biosregs ireg, oreg;
8064 struct e820entry *desc = boot_params.e820_map;
8065 static struct e820entry buf; /* static so it is zeroed */
8066diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8067index 11e8c6e..fdbb1ed 100644
8068--- a/arch/x86/boot/video-vesa.c
8069+++ b/arch/x86/boot/video-vesa.c
8070@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8071
8072 boot_params.screen_info.vesapm_seg = oreg.es;
8073 boot_params.screen_info.vesapm_off = oreg.di;
8074+ boot_params.screen_info.vesapm_size = oreg.cx;
8075 }
8076
8077 /*
8078diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8079index 43eda28..5ab5fdb 100644
8080--- a/arch/x86/boot/video.c
8081+++ b/arch/x86/boot/video.c
8082@@ -96,7 +96,7 @@ static void store_mode_params(void)
8083 static unsigned int get_entry(void)
8084 {
8085 char entry_buf[4];
8086- int i, len = 0;
8087+ unsigned int i, len = 0;
8088 int key;
8089 unsigned int v;
8090
8091diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8092index 5b577d5..3c1fed4 100644
8093--- a/arch/x86/crypto/aes-x86_64-asm_64.S
8094+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8095@@ -8,6 +8,8 @@
8096 * including this sentence is retained in full.
8097 */
8098
8099+#include <asm/alternative-asm.h>
8100+
8101 .extern crypto_ft_tab
8102 .extern crypto_it_tab
8103 .extern crypto_fl_tab
8104@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8105 je B192; \
8106 leaq 32(r9),r9;
8107
8108+#define ret pax_force_retaddr 0, 1; ret
8109+
8110 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8111 movq r1,r2; \
8112 movq r3,r4; \
8113diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8114index 3470624..201259d 100644
8115--- a/arch/x86/crypto/aesni-intel_asm.S
8116+++ b/arch/x86/crypto/aesni-intel_asm.S
8117@@ -31,6 +31,7 @@
8118
8119 #include <linux/linkage.h>
8120 #include <asm/inst.h>
8121+#include <asm/alternative-asm.h>
8122
8123 #ifdef __x86_64__
8124 .data
8125@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8126 pop %r14
8127 pop %r13
8128 pop %r12
8129+ pax_force_retaddr 0, 1
8130 ret
8131+ENDPROC(aesni_gcm_dec)
8132
8133
8134 /*****************************************************************************
8135@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8136 pop %r14
8137 pop %r13
8138 pop %r12
8139+ pax_force_retaddr 0, 1
8140 ret
8141+ENDPROC(aesni_gcm_enc)
8142
8143 #endif
8144
8145@@ -1714,6 +1719,7 @@ _key_expansion_256a:
8146 pxor %xmm1, %xmm0
8147 movaps %xmm0, (TKEYP)
8148 add $0x10, TKEYP
8149+ pax_force_retaddr_bts
8150 ret
8151
8152 .align 4
8153@@ -1738,6 +1744,7 @@ _key_expansion_192a:
8154 shufps $0b01001110, %xmm2, %xmm1
8155 movaps %xmm1, 0x10(TKEYP)
8156 add $0x20, TKEYP
8157+ pax_force_retaddr_bts
8158 ret
8159
8160 .align 4
8161@@ -1757,6 +1764,7 @@ _key_expansion_192b:
8162
8163 movaps %xmm0, (TKEYP)
8164 add $0x10, TKEYP
8165+ pax_force_retaddr_bts
8166 ret
8167
8168 .align 4
8169@@ -1769,6 +1777,7 @@ _key_expansion_256b:
8170 pxor %xmm1, %xmm2
8171 movaps %xmm2, (TKEYP)
8172 add $0x10, TKEYP
8173+ pax_force_retaddr_bts
8174 ret
8175
8176 /*
8177@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8178 #ifndef __x86_64__
8179 popl KEYP
8180 #endif
8181+ pax_force_retaddr 0, 1
8182 ret
8183+ENDPROC(aesni_set_key)
8184
8185 /*
8186 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8187@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8188 popl KLEN
8189 popl KEYP
8190 #endif
8191+ pax_force_retaddr 0, 1
8192 ret
8193+ENDPROC(aesni_enc)
8194
8195 /*
8196 * _aesni_enc1: internal ABI
8197@@ -1959,6 +1972,7 @@ _aesni_enc1:
8198 AESENC KEY STATE
8199 movaps 0x70(TKEYP), KEY
8200 AESENCLAST KEY STATE
8201+ pax_force_retaddr_bts
8202 ret
8203
8204 /*
8205@@ -2067,6 +2081,7 @@ _aesni_enc4:
8206 AESENCLAST KEY STATE2
8207 AESENCLAST KEY STATE3
8208 AESENCLAST KEY STATE4
8209+ pax_force_retaddr_bts
8210 ret
8211
8212 /*
8213@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8214 popl KLEN
8215 popl KEYP
8216 #endif
8217+ pax_force_retaddr 0, 1
8218 ret
8219+ENDPROC(aesni_dec)
8220
8221 /*
8222 * _aesni_dec1: internal ABI
8223@@ -2146,6 +2163,7 @@ _aesni_dec1:
8224 AESDEC KEY STATE
8225 movaps 0x70(TKEYP), KEY
8226 AESDECLAST KEY STATE
8227+ pax_force_retaddr_bts
8228 ret
8229
8230 /*
8231@@ -2254,6 +2272,7 @@ _aesni_dec4:
8232 AESDECLAST KEY STATE2
8233 AESDECLAST KEY STATE3
8234 AESDECLAST KEY STATE4
8235+ pax_force_retaddr_bts
8236 ret
8237
8238 /*
8239@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8240 popl KEYP
8241 popl LEN
8242 #endif
8243+ pax_force_retaddr 0, 1
8244 ret
8245+ENDPROC(aesni_ecb_enc)
8246
8247 /*
8248 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8249@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8250 popl KEYP
8251 popl LEN
8252 #endif
8253+ pax_force_retaddr 0, 1
8254 ret
8255+ENDPROC(aesni_ecb_dec)
8256
8257 /*
8258 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8259@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8260 popl LEN
8261 popl IVP
8262 #endif
8263+ pax_force_retaddr 0, 1
8264 ret
8265+ENDPROC(aesni_cbc_enc)
8266
8267 /*
8268 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8269@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8270 popl LEN
8271 popl IVP
8272 #endif
8273+ pax_force_retaddr 0, 1
8274 ret
8275+ENDPROC(aesni_cbc_dec)
8276
8277 #ifdef __x86_64__
8278 .align 16
8279@@ -2526,6 +2553,7 @@ _aesni_inc_init:
8280 mov $1, TCTR_LOW
8281 MOVQ_R64_XMM TCTR_LOW INC
8282 MOVQ_R64_XMM CTR TCTR_LOW
8283+ pax_force_retaddr_bts
8284 ret
8285
8286 /*
8287@@ -2554,6 +2582,7 @@ _aesni_inc:
8288 .Linc_low:
8289 movaps CTR, IV
8290 PSHUFB_XMM BSWAP_MASK IV
8291+ pax_force_retaddr_bts
8292 ret
8293
8294 /*
8295@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8296 .Lctr_enc_ret:
8297 movups IV, (IVP)
8298 .Lctr_enc_just_ret:
8299+ pax_force_retaddr 0, 1
8300 ret
8301+ENDPROC(aesni_ctr_enc)
8302 #endif
8303diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8304index 391d245..67f35c2 100644
8305--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8306+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8307@@ -20,6 +20,8 @@
8308 *
8309 */
8310
8311+#include <asm/alternative-asm.h>
8312+
8313 .file "blowfish-x86_64-asm.S"
8314 .text
8315
8316@@ -151,9 +153,11 @@ __blowfish_enc_blk:
8317 jnz __enc_xor;
8318
8319 write_block();
8320+ pax_force_retaddr 0, 1
8321 ret;
8322 __enc_xor:
8323 xor_block();
8324+ pax_force_retaddr 0, 1
8325 ret;
8326
8327 .align 8
8328@@ -188,6 +192,7 @@ blowfish_dec_blk:
8329
8330 movq %r11, %rbp;
8331
8332+ pax_force_retaddr 0, 1
8333 ret;
8334
8335 /**********************************************************************
8336@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8337
8338 popq %rbx;
8339 popq %rbp;
8340+ pax_force_retaddr 0, 1
8341 ret;
8342
8343 __enc_xor4:
8344@@ -349,6 +355,7 @@ __enc_xor4:
8345
8346 popq %rbx;
8347 popq %rbp;
8348+ pax_force_retaddr 0, 1
8349 ret;
8350
8351 .align 8
8352@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8353 popq %rbx;
8354 popq %rbp;
8355
8356+ pax_force_retaddr 0, 1
8357 ret;
8358
8359diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8360index 0b33743..7a56206 100644
8361--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8362+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8363@@ -20,6 +20,8 @@
8364 *
8365 */
8366
8367+#include <asm/alternative-asm.h>
8368+
8369 .file "camellia-x86_64-asm_64.S"
8370 .text
8371
8372@@ -229,12 +231,14 @@ __enc_done:
8373 enc_outunpack(mov, RT1);
8374
8375 movq RRBP, %rbp;
8376+ pax_force_retaddr 0, 1
8377 ret;
8378
8379 __enc_xor:
8380 enc_outunpack(xor, RT1);
8381
8382 movq RRBP, %rbp;
8383+ pax_force_retaddr 0, 1
8384 ret;
8385
8386 .global camellia_dec_blk;
8387@@ -275,6 +279,7 @@ __dec_rounds16:
8388 dec_outunpack();
8389
8390 movq RRBP, %rbp;
8391+ pax_force_retaddr 0, 1
8392 ret;
8393
8394 /**********************************************************************
8395@@ -468,6 +473,7 @@ __enc2_done:
8396
8397 movq RRBP, %rbp;
8398 popq %rbx;
8399+ pax_force_retaddr 0, 1
8400 ret;
8401
8402 __enc2_xor:
8403@@ -475,6 +481,7 @@ __enc2_xor:
8404
8405 movq RRBP, %rbp;
8406 popq %rbx;
8407+ pax_force_retaddr 0, 1
8408 ret;
8409
8410 .global camellia_dec_blk_2way;
8411@@ -517,4 +524,5 @@ __dec2_rounds16:
8412
8413 movq RRBP, %rbp;
8414 movq RXOR, %rbx;
8415+ pax_force_retaddr 0, 1
8416 ret;
8417diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8418index 6214a9b..1f4fc9a 100644
8419--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8420+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8421@@ -1,3 +1,5 @@
8422+#include <asm/alternative-asm.h>
8423+
8424 # enter ECRYPT_encrypt_bytes
8425 .text
8426 .p2align 5
8427@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8428 add %r11,%rsp
8429 mov %rdi,%rax
8430 mov %rsi,%rdx
8431+ pax_force_retaddr 0, 1
8432 ret
8433 # bytesatleast65:
8434 ._bytesatleast65:
8435@@ -891,6 +894,7 @@ ECRYPT_keysetup:
8436 add %r11,%rsp
8437 mov %rdi,%rax
8438 mov %rsi,%rdx
8439+ pax_force_retaddr
8440 ret
8441 # enter ECRYPT_ivsetup
8442 .text
8443@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8444 add %r11,%rsp
8445 mov %rdi,%rax
8446 mov %rsi,%rdx
8447+ pax_force_retaddr
8448 ret
8449diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8450index 3ee1ff0..cbc568b 100644
8451--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8452+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8453@@ -24,6 +24,8 @@
8454 *
8455 */
8456
8457+#include <asm/alternative-asm.h>
8458+
8459 .file "serpent-sse2-x86_64-asm_64.S"
8460 .text
8461
8462@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8463 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8464 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8465
8466+ pax_force_retaddr
8467 ret;
8468
8469 __enc_xor8:
8470 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8471 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8472
8473+ pax_force_retaddr
8474 ret;
8475
8476 .align 8
8477@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8478 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8479 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8480
8481+ pax_force_retaddr
8482 ret;
8483diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8484index b2c2f57..8470cab 100644
8485--- a/arch/x86/crypto/sha1_ssse3_asm.S
8486+++ b/arch/x86/crypto/sha1_ssse3_asm.S
8487@@ -28,6 +28,8 @@
8488 * (at your option) any later version.
8489 */
8490
8491+#include <asm/alternative-asm.h>
8492+
8493 #define CTX %rdi // arg1
8494 #define BUF %rsi // arg2
8495 #define CNT %rdx // arg3
8496@@ -104,6 +106,7 @@
8497 pop %r12
8498 pop %rbp
8499 pop %rbx
8500+ pax_force_retaddr 0, 1
8501 ret
8502
8503 .size \name, .-\name
8504diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8505index 5b012a2..36d5364 100644
8506--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8507+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8508@@ -20,6 +20,8 @@
8509 *
8510 */
8511
8512+#include <asm/alternative-asm.h>
8513+
8514 .file "twofish-x86_64-asm-3way.S"
8515 .text
8516
8517@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8518 popq %r13;
8519 popq %r14;
8520 popq %r15;
8521+ pax_force_retaddr 0, 1
8522 ret;
8523
8524 __enc_xor3:
8525@@ -271,6 +274,7 @@ __enc_xor3:
8526 popq %r13;
8527 popq %r14;
8528 popq %r15;
8529+ pax_force_retaddr 0, 1
8530 ret;
8531
8532 .global twofish_dec_blk_3way
8533@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8534 popq %r13;
8535 popq %r14;
8536 popq %r15;
8537+ pax_force_retaddr 0, 1
8538 ret;
8539
8540diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8541index 7bcf3fc..f53832f 100644
8542--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8543+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8544@@ -21,6 +21,7 @@
8545 .text
8546
8547 #include <asm/asm-offsets.h>
8548+#include <asm/alternative-asm.h>
8549
8550 #define a_offset 0
8551 #define b_offset 4
8552@@ -268,6 +269,7 @@ twofish_enc_blk:
8553
8554 popq R1
8555 movq $1,%rax
8556+ pax_force_retaddr 0, 1
8557 ret
8558
8559 twofish_dec_blk:
8560@@ -319,4 +321,5 @@ twofish_dec_blk:
8561
8562 popq R1
8563 movq $1,%rax
8564+ pax_force_retaddr 0, 1
8565 ret
8566diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8567index 07b3a68..bd2a388 100644
8568--- a/arch/x86/ia32/ia32_aout.c
8569+++ b/arch/x86/ia32/ia32_aout.c
8570@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8571 unsigned long dump_start, dump_size;
8572 struct user32 dump;
8573
8574+ memset(&dump, 0, sizeof(dump));
8575+
8576 fs = get_fs();
8577 set_fs(KERNEL_DS);
8578 has_dumped = 1;
8579diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8580index a69245b..6d145f4 100644
8581--- a/arch/x86/ia32/ia32_signal.c
8582+++ b/arch/x86/ia32/ia32_signal.c
8583@@ -168,7 +168,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8584 }
8585 seg = get_fs();
8586 set_fs(KERNEL_DS);
8587- ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8588+ ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8589 set_fs(seg);
8590 if (ret >= 0 && uoss_ptr) {
8591 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8592@@ -369,7 +369,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8593 */
8594 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8595 size_t frame_size,
8596- void **fpstate)
8597+ void __user **fpstate)
8598 {
8599 unsigned long sp;
8600
8601@@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8602
8603 if (used_math()) {
8604 sp = sp - sig_xstate_ia32_size;
8605- *fpstate = (struct _fpstate_ia32 *) sp;
8606+ *fpstate = (struct _fpstate_ia32 __user *) sp;
8607 if (save_i387_xstate_ia32(*fpstate) < 0)
8608 return (void __user *) -1L;
8609 }
8610@@ -398,7 +398,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8611 sp -= frame_size;
8612 /* Align the stack pointer according to the i386 ABI,
8613 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8614- sp = ((sp + 4) & -16ul) - 4;
8615+ sp = ((sp - 12) & -16ul) - 4;
8616 return (void __user *) sp;
8617 }
8618
8619@@ -456,7 +456,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8620 * These are actually not used anymore, but left because some
8621 * gdb versions depend on them as a marker.
8622 */
8623- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8624+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8625 } put_user_catch(err);
8626
8627 if (err)
8628@@ -498,7 +498,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8629 0xb8,
8630 __NR_ia32_rt_sigreturn,
8631 0x80cd,
8632- 0,
8633+ 0
8634 };
8635
8636 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8637@@ -528,16 +528,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8638
8639 if (ka->sa.sa_flags & SA_RESTORER)
8640 restorer = ka->sa.sa_restorer;
8641+ else if (current->mm->context.vdso)
8642+ /* Return stub is in 32bit vsyscall page */
8643+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8644 else
8645- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8646- rt_sigreturn);
8647+ restorer = &frame->retcode;
8648 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8649
8650 /*
8651 * Not actually used anymore, but left because some gdb
8652 * versions need it.
8653 */
8654- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8655+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8656 } put_user_catch(err);
8657
8658 if (err)
8659diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8660index e3e7340..05ed805 100644
8661--- a/arch/x86/ia32/ia32entry.S
8662+++ b/arch/x86/ia32/ia32entry.S
8663@@ -13,8 +13,10 @@
8664 #include <asm/thread_info.h>
8665 #include <asm/segment.h>
8666 #include <asm/irqflags.h>
8667+#include <asm/pgtable.h>
8668 #include <linux/linkage.h>
8669 #include <linux/err.h>
8670+#include <asm/alternative-asm.h>
8671
8672 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8673 #include <linux/elf-em.h>
8674@@ -94,6 +96,32 @@ ENTRY(native_irq_enable_sysexit)
8675 ENDPROC(native_irq_enable_sysexit)
8676 #endif
8677
8678+ .macro pax_enter_kernel_user
8679+ pax_set_fptr_mask
8680+#ifdef CONFIG_PAX_MEMORY_UDEREF
8681+ call pax_enter_kernel_user
8682+#endif
8683+ .endm
8684+
8685+ .macro pax_exit_kernel_user
8686+#ifdef CONFIG_PAX_MEMORY_UDEREF
8687+ call pax_exit_kernel_user
8688+#endif
8689+#ifdef CONFIG_PAX_RANDKSTACK
8690+ pushq %rax
8691+ pushq %r11
8692+ call pax_randomize_kstack
8693+ popq %r11
8694+ popq %rax
8695+#endif
8696+ .endm
8697+
8698+.macro pax_erase_kstack
8699+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8700+ call pax_erase_kstack
8701+#endif
8702+.endm
8703+
8704 /*
8705 * 32bit SYSENTER instruction entry.
8706 *
8707@@ -120,12 +148,6 @@ ENTRY(ia32_sysenter_target)
8708 CFI_REGISTER rsp,rbp
8709 SWAPGS_UNSAFE_STACK
8710 movq PER_CPU_VAR(kernel_stack), %rsp
8711- addq $(KERNEL_STACK_OFFSET),%rsp
8712- /*
8713- * No need to follow this irqs on/off section: the syscall
8714- * disabled irqs, here we enable it straight after entry:
8715- */
8716- ENABLE_INTERRUPTS(CLBR_NONE)
8717 movl %ebp,%ebp /* zero extension */
8718 pushq_cfi $__USER32_DS
8719 /*CFI_REL_OFFSET ss,0*/
8720@@ -133,24 +155,39 @@ ENTRY(ia32_sysenter_target)
8721 CFI_REL_OFFSET rsp,0
8722 pushfq_cfi
8723 /*CFI_REL_OFFSET rflags,0*/
8724- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8725- CFI_REGISTER rip,r10
8726+ orl $X86_EFLAGS_IF,(%rsp)
8727+ GET_THREAD_INFO(%r11)
8728+ movl TI_sysenter_return(%r11), %r11d
8729+ CFI_REGISTER rip,r11
8730 pushq_cfi $__USER32_CS
8731 /*CFI_REL_OFFSET cs,0*/
8732 movl %eax, %eax
8733- pushq_cfi %r10
8734+ pushq_cfi %r11
8735 CFI_REL_OFFSET rip,0
8736 pushq_cfi %rax
8737 cld
8738 SAVE_ARGS 0,1,0
8739+ pax_enter_kernel_user
8740+ /*
8741+ * No need to follow this irqs on/off section: the syscall
8742+ * disabled irqs, here we enable it straight after entry:
8743+ */
8744+ ENABLE_INTERRUPTS(CLBR_NONE)
8745 /* no need to do an access_ok check here because rbp has been
8746 32bit zero extended */
8747+
8748+#ifdef CONFIG_PAX_MEMORY_UDEREF
8749+ mov $PAX_USER_SHADOW_BASE,%r11
8750+ add %r11,%rbp
8751+#endif
8752+
8753 1: movl (%rbp),%ebp
8754 .section __ex_table,"a"
8755 .quad 1b,ia32_badarg
8756 .previous
8757- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8758- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8759+ GET_THREAD_INFO(%r11)
8760+ orl $TS_COMPAT,TI_status(%r11)
8761+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8762 CFI_REMEMBER_STATE
8763 jnz sysenter_tracesys
8764 cmpq $(IA32_NR_syscalls-1),%rax
8765@@ -160,12 +197,15 @@ sysenter_do_call:
8766 sysenter_dispatch:
8767 call *ia32_sys_call_table(,%rax,8)
8768 movq %rax,RAX-ARGOFFSET(%rsp)
8769+ GET_THREAD_INFO(%r11)
8770 DISABLE_INTERRUPTS(CLBR_NONE)
8771 TRACE_IRQS_OFF
8772- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8773+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8774 jnz sysexit_audit
8775 sysexit_from_sys_call:
8776- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8777+ pax_exit_kernel_user
8778+ pax_erase_kstack
8779+ andl $~TS_COMPAT,TI_status(%r11)
8780 /* clear IF, that popfq doesn't enable interrupts early */
8781 andl $~0x200,EFLAGS-R11(%rsp)
8782 movl RIP-R11(%rsp),%edx /* User %eip */
8783@@ -191,6 +231,9 @@ sysexit_from_sys_call:
8784 movl %eax,%esi /* 2nd arg: syscall number */
8785 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8786 call __audit_syscall_entry
8787+
8788+ pax_erase_kstack
8789+
8790 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8791 cmpq $(IA32_NR_syscalls-1),%rax
8792 ja ia32_badsys
8793@@ -202,7 +245,7 @@ sysexit_from_sys_call:
8794 .endm
8795
8796 .macro auditsys_exit exit
8797- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8798+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8799 jnz ia32_ret_from_sys_call
8800 TRACE_IRQS_ON
8801 sti
8802@@ -213,11 +256,12 @@ sysexit_from_sys_call:
8803 1: setbe %al /* 1 if error, 0 if not */
8804 movzbl %al,%edi /* zero-extend that into %edi */
8805 call __audit_syscall_exit
8806+ GET_THREAD_INFO(%r11)
8807 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8808 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8809 cli
8810 TRACE_IRQS_OFF
8811- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8812+ testl %edi,TI_flags(%r11)
8813 jz \exit
8814 CLEAR_RREGS -ARGOFFSET
8815 jmp int_with_check
8816@@ -235,7 +279,7 @@ sysexit_audit:
8817
8818 sysenter_tracesys:
8819 #ifdef CONFIG_AUDITSYSCALL
8820- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8821+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8822 jz sysenter_auditsys
8823 #endif
8824 SAVE_REST
8825@@ -243,6 +287,9 @@ sysenter_tracesys:
8826 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8827 movq %rsp,%rdi /* &pt_regs -> arg1 */
8828 call syscall_trace_enter
8829+
8830+ pax_erase_kstack
8831+
8832 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8833 RESTORE_REST
8834 cmpq $(IA32_NR_syscalls-1),%rax
8835@@ -274,19 +321,20 @@ ENDPROC(ia32_sysenter_target)
8836 ENTRY(ia32_cstar_target)
8837 CFI_STARTPROC32 simple
8838 CFI_SIGNAL_FRAME
8839- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8840+ CFI_DEF_CFA rsp,0
8841 CFI_REGISTER rip,rcx
8842 /*CFI_REGISTER rflags,r11*/
8843 SWAPGS_UNSAFE_STACK
8844 movl %esp,%r8d
8845 CFI_REGISTER rsp,r8
8846 movq PER_CPU_VAR(kernel_stack),%rsp
8847+ SAVE_ARGS 8*6,0,0
8848+ pax_enter_kernel_user
8849 /*
8850 * No need to follow this irqs on/off section: the syscall
8851 * disabled irqs and here we enable it straight after entry:
8852 */
8853 ENABLE_INTERRUPTS(CLBR_NONE)
8854- SAVE_ARGS 8,0,0
8855 movl %eax,%eax /* zero extension */
8856 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8857 movq %rcx,RIP-ARGOFFSET(%rsp)
8858@@ -302,12 +350,19 @@ ENTRY(ia32_cstar_target)
8859 /* no need to do an access_ok check here because r8 has been
8860 32bit zero extended */
8861 /* hardware stack frame is complete now */
8862+
8863+#ifdef CONFIG_PAX_MEMORY_UDEREF
8864+ mov $PAX_USER_SHADOW_BASE,%r11
8865+ add %r11,%r8
8866+#endif
8867+
8868 1: movl (%r8),%r9d
8869 .section __ex_table,"a"
8870 .quad 1b,ia32_badarg
8871 .previous
8872- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8873- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8874+ GET_THREAD_INFO(%r11)
8875+ orl $TS_COMPAT,TI_status(%r11)
8876+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8877 CFI_REMEMBER_STATE
8878 jnz cstar_tracesys
8879 cmpq $IA32_NR_syscalls-1,%rax
8880@@ -317,12 +372,15 @@ cstar_do_call:
8881 cstar_dispatch:
8882 call *ia32_sys_call_table(,%rax,8)
8883 movq %rax,RAX-ARGOFFSET(%rsp)
8884+ GET_THREAD_INFO(%r11)
8885 DISABLE_INTERRUPTS(CLBR_NONE)
8886 TRACE_IRQS_OFF
8887- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8888+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8889 jnz sysretl_audit
8890 sysretl_from_sys_call:
8891- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8892+ pax_exit_kernel_user
8893+ pax_erase_kstack
8894+ andl $~TS_COMPAT,TI_status(%r11)
8895 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8896 movl RIP-ARGOFFSET(%rsp),%ecx
8897 CFI_REGISTER rip,rcx
8898@@ -350,7 +408,7 @@ sysretl_audit:
8899
8900 cstar_tracesys:
8901 #ifdef CONFIG_AUDITSYSCALL
8902- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8903+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8904 jz cstar_auditsys
8905 #endif
8906 xchgl %r9d,%ebp
8907@@ -359,6 +417,9 @@ cstar_tracesys:
8908 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8909 movq %rsp,%rdi /* &pt_regs -> arg1 */
8910 call syscall_trace_enter
8911+
8912+ pax_erase_kstack
8913+
8914 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8915 RESTORE_REST
8916 xchgl %ebp,%r9d
8917@@ -404,19 +465,21 @@ ENTRY(ia32_syscall)
8918 CFI_REL_OFFSET rip,RIP-RIP
8919 PARAVIRT_ADJUST_EXCEPTION_FRAME
8920 SWAPGS
8921- /*
8922- * No need to follow this irqs on/off section: the syscall
8923- * disabled irqs and here we enable it straight after entry:
8924- */
8925- ENABLE_INTERRUPTS(CLBR_NONE)
8926 movl %eax,%eax
8927 pushq_cfi %rax
8928 cld
8929 /* note the registers are not zero extended to the sf.
8930 this could be a problem. */
8931 SAVE_ARGS 0,1,0
8932- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8933- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8934+ pax_enter_kernel_user
8935+ /*
8936+ * No need to follow this irqs on/off section: the syscall
8937+ * disabled irqs and here we enable it straight after entry:
8938+ */
8939+ ENABLE_INTERRUPTS(CLBR_NONE)
8940+ GET_THREAD_INFO(%r11)
8941+ orl $TS_COMPAT,TI_status(%r11)
8942+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8943 jnz ia32_tracesys
8944 cmpq $(IA32_NR_syscalls-1),%rax
8945 ja ia32_badsys
8946@@ -435,6 +498,9 @@ ia32_tracesys:
8947 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8948 movq %rsp,%rdi /* &pt_regs -> arg1 */
8949 call syscall_trace_enter
8950+
8951+ pax_erase_kstack
8952+
8953 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8954 RESTORE_REST
8955 cmpq $(IA32_NR_syscalls-1),%rax
8956diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8957index aec2202..f76174e 100644
8958--- a/arch/x86/ia32/sys_ia32.c
8959+++ b/arch/x86/ia32/sys_ia32.c
8960@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8961 */
8962 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8963 {
8964- typeof(ubuf->st_uid) uid = 0;
8965- typeof(ubuf->st_gid) gid = 0;
8966+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
8967+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
8968 SET_UID(uid, stat->uid);
8969 SET_GID(gid, stat->gid);
8970 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8971@@ -292,7 +292,7 @@ asmlinkage long sys32_alarm(unsigned int seconds)
8972 return alarm_setitimer(seconds);
8973 }
8974
8975-asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8976+asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8977 int options)
8978 {
8979 return compat_sys_wait4(pid, stat_addr, options, NULL);
8980@@ -313,7 +313,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8981 mm_segment_t old_fs = get_fs();
8982
8983 set_fs(KERNEL_DS);
8984- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8985+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8986 set_fs(old_fs);
8987 if (put_compat_timespec(&t, interval))
8988 return -EFAULT;
8989@@ -329,7 +329,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8990 mm_segment_t old_fs = get_fs();
8991
8992 set_fs(KERNEL_DS);
8993- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8994+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8995 set_fs(old_fs);
8996 if (!ret) {
8997 switch (_NSIG_WORDS) {
8998@@ -354,7 +354,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8999 if (copy_siginfo_from_user32(&info, uinfo))
9000 return -EFAULT;
9001 set_fs(KERNEL_DS);
9002- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9003+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9004 set_fs(old_fs);
9005 return ret;
9006 }
9007@@ -399,7 +399,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9008 return -EFAULT;
9009
9010 set_fs(KERNEL_DS);
9011- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9012+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9013 count);
9014 set_fs(old_fs);
9015
9016diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9017index 952bd01..7692c6f 100644
9018--- a/arch/x86/include/asm/alternative-asm.h
9019+++ b/arch/x86/include/asm/alternative-asm.h
9020@@ -15,6 +15,45 @@
9021 .endm
9022 #endif
9023
9024+#ifdef KERNEXEC_PLUGIN
9025+ .macro pax_force_retaddr_bts rip=0
9026+ btsq $63,\rip(%rsp)
9027+ .endm
9028+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9029+ .macro pax_force_retaddr rip=0, reload=0
9030+ btsq $63,\rip(%rsp)
9031+ .endm
9032+ .macro pax_force_fptr ptr
9033+ btsq $63,\ptr
9034+ .endm
9035+ .macro pax_set_fptr_mask
9036+ .endm
9037+#endif
9038+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9039+ .macro pax_force_retaddr rip=0, reload=0
9040+ .if \reload
9041+ pax_set_fptr_mask
9042+ .endif
9043+ orq %r10,\rip(%rsp)
9044+ .endm
9045+ .macro pax_force_fptr ptr
9046+ orq %r10,\ptr
9047+ .endm
9048+ .macro pax_set_fptr_mask
9049+ movabs $0x8000000000000000,%r10
9050+ .endm
9051+#endif
9052+#else
9053+ .macro pax_force_retaddr rip=0, reload=0
9054+ .endm
9055+ .macro pax_force_fptr ptr
9056+ .endm
9057+ .macro pax_force_retaddr_bts rip=0
9058+ .endm
9059+ .macro pax_set_fptr_mask
9060+ .endm
9061+#endif
9062+
9063 .macro altinstruction_entry orig alt feature orig_len alt_len
9064 .long \orig - .
9065 .long \alt - .
9066diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9067index 49331be..9706065 100644
9068--- a/arch/x86/include/asm/alternative.h
9069+++ b/arch/x86/include/asm/alternative.h
9070@@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9071 ".section .discard,\"aw\",@progbits\n" \
9072 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
9073 ".previous\n" \
9074- ".section .altinstr_replacement, \"ax\"\n" \
9075+ ".section .altinstr_replacement, \"a\"\n" \
9076 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
9077 ".previous"
9078
9079diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9080index d854101..f6ea947 100644
9081--- a/arch/x86/include/asm/apic.h
9082+++ b/arch/x86/include/asm/apic.h
9083@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9084
9085 #ifdef CONFIG_X86_LOCAL_APIC
9086
9087-extern unsigned int apic_verbosity;
9088+extern int apic_verbosity;
9089 extern int local_apic_timer_c2_ok;
9090
9091 extern int disable_apic;
9092diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9093index 20370c6..a2eb9b0 100644
9094--- a/arch/x86/include/asm/apm.h
9095+++ b/arch/x86/include/asm/apm.h
9096@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9097 __asm__ __volatile__(APM_DO_ZERO_SEGS
9098 "pushl %%edi\n\t"
9099 "pushl %%ebp\n\t"
9100- "lcall *%%cs:apm_bios_entry\n\t"
9101+ "lcall *%%ss:apm_bios_entry\n\t"
9102 "setc %%al\n\t"
9103 "popl %%ebp\n\t"
9104 "popl %%edi\n\t"
9105@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9106 __asm__ __volatile__(APM_DO_ZERO_SEGS
9107 "pushl %%edi\n\t"
9108 "pushl %%ebp\n\t"
9109- "lcall *%%cs:apm_bios_entry\n\t"
9110+ "lcall *%%ss:apm_bios_entry\n\t"
9111 "setc %%bl\n\t"
9112 "popl %%ebp\n\t"
9113 "popl %%edi\n\t"
9114diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9115index 58cb6d4..ca9010d 100644
9116--- a/arch/x86/include/asm/atomic.h
9117+++ b/arch/x86/include/asm/atomic.h
9118@@ -22,7 +22,18 @@
9119 */
9120 static inline int atomic_read(const atomic_t *v)
9121 {
9122- return (*(volatile int *)&(v)->counter);
9123+ return (*(volatile const int *)&(v)->counter);
9124+}
9125+
9126+/**
9127+ * atomic_read_unchecked - read atomic variable
9128+ * @v: pointer of type atomic_unchecked_t
9129+ *
9130+ * Atomically reads the value of @v.
9131+ */
9132+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9133+{
9134+ return (*(volatile const int *)&(v)->counter);
9135 }
9136
9137 /**
9138@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9139 }
9140
9141 /**
9142+ * atomic_set_unchecked - set atomic variable
9143+ * @v: pointer of type atomic_unchecked_t
9144+ * @i: required value
9145+ *
9146+ * Atomically sets the value of @v to @i.
9147+ */
9148+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9149+{
9150+ v->counter = i;
9151+}
9152+
9153+/**
9154 * atomic_add - add integer to atomic variable
9155 * @i: integer value to add
9156 * @v: pointer of type atomic_t
9157@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9158 */
9159 static inline void atomic_add(int i, atomic_t *v)
9160 {
9161- asm volatile(LOCK_PREFIX "addl %1,%0"
9162+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9163+
9164+#ifdef CONFIG_PAX_REFCOUNT
9165+ "jno 0f\n"
9166+ LOCK_PREFIX "subl %1,%0\n"
9167+ "int $4\n0:\n"
9168+ _ASM_EXTABLE(0b, 0b)
9169+#endif
9170+
9171+ : "+m" (v->counter)
9172+ : "ir" (i));
9173+}
9174+
9175+/**
9176+ * atomic_add_unchecked - add integer to atomic variable
9177+ * @i: integer value to add
9178+ * @v: pointer of type atomic_unchecked_t
9179+ *
9180+ * Atomically adds @i to @v.
9181+ */
9182+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9183+{
9184+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9185 : "+m" (v->counter)
9186 : "ir" (i));
9187 }
9188@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9189 */
9190 static inline void atomic_sub(int i, atomic_t *v)
9191 {
9192- asm volatile(LOCK_PREFIX "subl %1,%0"
9193+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9194+
9195+#ifdef CONFIG_PAX_REFCOUNT
9196+ "jno 0f\n"
9197+ LOCK_PREFIX "addl %1,%0\n"
9198+ "int $4\n0:\n"
9199+ _ASM_EXTABLE(0b, 0b)
9200+#endif
9201+
9202+ : "+m" (v->counter)
9203+ : "ir" (i));
9204+}
9205+
9206+/**
9207+ * atomic_sub_unchecked - subtract integer from atomic variable
9208+ * @i: integer value to subtract
9209+ * @v: pointer of type atomic_unchecked_t
9210+ *
9211+ * Atomically subtracts @i from @v.
9212+ */
9213+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9214+{
9215+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9216 : "+m" (v->counter)
9217 : "ir" (i));
9218 }
9219@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9220 {
9221 unsigned char c;
9222
9223- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9224+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
9225+
9226+#ifdef CONFIG_PAX_REFCOUNT
9227+ "jno 0f\n"
9228+ LOCK_PREFIX "addl %2,%0\n"
9229+ "int $4\n0:\n"
9230+ _ASM_EXTABLE(0b, 0b)
9231+#endif
9232+
9233+ "sete %1\n"
9234 : "+m" (v->counter), "=qm" (c)
9235 : "ir" (i) : "memory");
9236 return c;
9237@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9238 */
9239 static inline void atomic_inc(atomic_t *v)
9240 {
9241- asm volatile(LOCK_PREFIX "incl %0"
9242+ asm volatile(LOCK_PREFIX "incl %0\n"
9243+
9244+#ifdef CONFIG_PAX_REFCOUNT
9245+ "jno 0f\n"
9246+ LOCK_PREFIX "decl %0\n"
9247+ "int $4\n0:\n"
9248+ _ASM_EXTABLE(0b, 0b)
9249+#endif
9250+
9251+ : "+m" (v->counter));
9252+}
9253+
9254+/**
9255+ * atomic_inc_unchecked - increment atomic variable
9256+ * @v: pointer of type atomic_unchecked_t
9257+ *
9258+ * Atomically increments @v by 1.
9259+ */
9260+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9261+{
9262+ asm volatile(LOCK_PREFIX "incl %0\n"
9263 : "+m" (v->counter));
9264 }
9265
9266@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9267 */
9268 static inline void atomic_dec(atomic_t *v)
9269 {
9270- asm volatile(LOCK_PREFIX "decl %0"
9271+ asm volatile(LOCK_PREFIX "decl %0\n"
9272+
9273+#ifdef CONFIG_PAX_REFCOUNT
9274+ "jno 0f\n"
9275+ LOCK_PREFIX "incl %0\n"
9276+ "int $4\n0:\n"
9277+ _ASM_EXTABLE(0b, 0b)
9278+#endif
9279+
9280+ : "+m" (v->counter));
9281+}
9282+
9283+/**
9284+ * atomic_dec_unchecked - decrement atomic variable
9285+ * @v: pointer of type atomic_unchecked_t
9286+ *
9287+ * Atomically decrements @v by 1.
9288+ */
9289+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9290+{
9291+ asm volatile(LOCK_PREFIX "decl %0\n"
9292 : "+m" (v->counter));
9293 }
9294
9295@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9296 {
9297 unsigned char c;
9298
9299- asm volatile(LOCK_PREFIX "decl %0; sete %1"
9300+ asm volatile(LOCK_PREFIX "decl %0\n"
9301+
9302+#ifdef CONFIG_PAX_REFCOUNT
9303+ "jno 0f\n"
9304+ LOCK_PREFIX "incl %0\n"
9305+ "int $4\n0:\n"
9306+ _ASM_EXTABLE(0b, 0b)
9307+#endif
9308+
9309+ "sete %1\n"
9310 : "+m" (v->counter), "=qm" (c)
9311 : : "memory");
9312 return c != 0;
9313@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9314 {
9315 unsigned char c;
9316
9317- asm volatile(LOCK_PREFIX "incl %0; sete %1"
9318+ asm volatile(LOCK_PREFIX "incl %0\n"
9319+
9320+#ifdef CONFIG_PAX_REFCOUNT
9321+ "jno 0f\n"
9322+ LOCK_PREFIX "decl %0\n"
9323+ "int $4\n0:\n"
9324+ _ASM_EXTABLE(0b, 0b)
9325+#endif
9326+
9327+ "sete %1\n"
9328+ : "+m" (v->counter), "=qm" (c)
9329+ : : "memory");
9330+ return c != 0;
9331+}
9332+
9333+/**
9334+ * atomic_inc_and_test_unchecked - increment and test
9335+ * @v: pointer of type atomic_unchecked_t
9336+ *
9337+ * Atomically increments @v by 1
9338+ * and returns true if the result is zero, or false for all
9339+ * other cases.
9340+ */
9341+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9342+{
9343+ unsigned char c;
9344+
9345+ asm volatile(LOCK_PREFIX "incl %0\n"
9346+ "sete %1\n"
9347 : "+m" (v->counter), "=qm" (c)
9348 : : "memory");
9349 return c != 0;
9350@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9351 {
9352 unsigned char c;
9353
9354- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9355+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
9356+
9357+#ifdef CONFIG_PAX_REFCOUNT
9358+ "jno 0f\n"
9359+ LOCK_PREFIX "subl %2,%0\n"
9360+ "int $4\n0:\n"
9361+ _ASM_EXTABLE(0b, 0b)
9362+#endif
9363+
9364+ "sets %1\n"
9365 : "+m" (v->counter), "=qm" (c)
9366 : "ir" (i) : "memory");
9367 return c;
9368@@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9369 goto no_xadd;
9370 #endif
9371 /* Modern 486+ processor */
9372- return i + xadd(&v->counter, i);
9373+ return i + xadd_check_overflow(&v->counter, i);
9374
9375 #ifdef CONFIG_M386
9376 no_xadd: /* Legacy 386 processor */
9377@@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9378 }
9379
9380 /**
9381+ * atomic_add_return_unchecked - add integer and return
9382+ * @i: integer value to add
9383+ * @v: pointer of type atomic_unchecked_t
9384+ *
9385+ * Atomically adds @i to @v and returns @i + @v
9386+ */
9387+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9388+{
9389+#ifdef CONFIG_M386
9390+ int __i;
9391+ unsigned long flags;
9392+ if (unlikely(boot_cpu_data.x86 <= 3))
9393+ goto no_xadd;
9394+#endif
9395+ /* Modern 486+ processor */
9396+ return i + xadd(&v->counter, i);
9397+
9398+#ifdef CONFIG_M386
9399+no_xadd: /* Legacy 386 processor */
9400+ raw_local_irq_save(flags);
9401+ __i = atomic_read_unchecked(v);
9402+ atomic_set_unchecked(v, i + __i);
9403+ raw_local_irq_restore(flags);
9404+ return i + __i;
9405+#endif
9406+}
9407+
9408+/**
9409 * atomic_sub_return - subtract integer and return
9410 * @v: pointer of type atomic_t
9411 * @i: integer value to subtract
9412@@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9413 }
9414
9415 #define atomic_inc_return(v) (atomic_add_return(1, v))
9416+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9417+{
9418+ return atomic_add_return_unchecked(1, v);
9419+}
9420 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9421
9422 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9423@@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9424 return cmpxchg(&v->counter, old, new);
9425 }
9426
9427+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9428+{
9429+ return cmpxchg(&v->counter, old, new);
9430+}
9431+
9432 static inline int atomic_xchg(atomic_t *v, int new)
9433 {
9434 return xchg(&v->counter, new);
9435 }
9436
9437+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9438+{
9439+ return xchg(&v->counter, new);
9440+}
9441+
9442 /**
9443 * __atomic_add_unless - add unless the number is already a given value
9444 * @v: pointer of type atomic_t
9445@@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9446 */
9447 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9448 {
9449- int c, old;
9450+ int c, old, new;
9451 c = atomic_read(v);
9452 for (;;) {
9453- if (unlikely(c == (u)))
9454+ if (unlikely(c == u))
9455 break;
9456- old = atomic_cmpxchg((v), c, c + (a));
9457+
9458+ asm volatile("addl %2,%0\n"
9459+
9460+#ifdef CONFIG_PAX_REFCOUNT
9461+ "jno 0f\n"
9462+ "subl %2,%0\n"
9463+ "int $4\n0:\n"
9464+ _ASM_EXTABLE(0b, 0b)
9465+#endif
9466+
9467+ : "=r" (new)
9468+ : "0" (c), "ir" (a));
9469+
9470+ old = atomic_cmpxchg(v, c, new);
9471 if (likely(old == c))
9472 break;
9473 c = old;
9474@@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9475 return c;
9476 }
9477
9478+/**
9479+ * atomic_inc_not_zero_hint - increment if not null
9480+ * @v: pointer of type atomic_t
9481+ * @hint: probable value of the atomic before the increment
9482+ *
9483+ * This version of atomic_inc_not_zero() gives a hint of probable
9484+ * value of the atomic. This helps processor to not read the memory
9485+ * before doing the atomic read/modify/write cycle, lowering
9486+ * number of bus transactions on some arches.
9487+ *
9488+ * Returns: 0 if increment was not done, 1 otherwise.
9489+ */
9490+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9491+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9492+{
9493+ int val, c = hint, new;
9494+
9495+ /* sanity test, should be removed by compiler if hint is a constant */
9496+ if (!hint)
9497+ return __atomic_add_unless(v, 1, 0);
9498+
9499+ do {
9500+ asm volatile("incl %0\n"
9501+
9502+#ifdef CONFIG_PAX_REFCOUNT
9503+ "jno 0f\n"
9504+ "decl %0\n"
9505+ "int $4\n0:\n"
9506+ _ASM_EXTABLE(0b, 0b)
9507+#endif
9508+
9509+ : "=r" (new)
9510+ : "0" (c));
9511+
9512+ val = atomic_cmpxchg(v, c, new);
9513+ if (val == c)
9514+ return 1;
9515+ c = val;
9516+ } while (c);
9517+
9518+ return 0;
9519+}
9520
9521 /*
9522 * atomic_dec_if_positive - decrement by 1 if old value positive
9523diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9524index 1981199..36b9dfb 100644
9525--- a/arch/x86/include/asm/atomic64_32.h
9526+++ b/arch/x86/include/asm/atomic64_32.h
9527@@ -12,6 +12,14 @@ typedef struct {
9528 u64 __aligned(8) counter;
9529 } atomic64_t;
9530
9531+#ifdef CONFIG_PAX_REFCOUNT
9532+typedef struct {
9533+ u64 __aligned(8) counter;
9534+} atomic64_unchecked_t;
9535+#else
9536+typedef atomic64_t atomic64_unchecked_t;
9537+#endif
9538+
9539 #define ATOMIC64_INIT(val) { (val) }
9540
9541 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9542@@ -37,21 +45,31 @@ typedef struct {
9543 ATOMIC64_DECL_ONE(sym##_386)
9544
9545 ATOMIC64_DECL_ONE(add_386);
9546+ATOMIC64_DECL_ONE(add_unchecked_386);
9547 ATOMIC64_DECL_ONE(sub_386);
9548+ATOMIC64_DECL_ONE(sub_unchecked_386);
9549 ATOMIC64_DECL_ONE(inc_386);
9550+ATOMIC64_DECL_ONE(inc_unchecked_386);
9551 ATOMIC64_DECL_ONE(dec_386);
9552+ATOMIC64_DECL_ONE(dec_unchecked_386);
9553 #endif
9554
9555 #define alternative_atomic64(f, out, in...) \
9556 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9557
9558 ATOMIC64_DECL(read);
9559+ATOMIC64_DECL(read_unchecked);
9560 ATOMIC64_DECL(set);
9561+ATOMIC64_DECL(set_unchecked);
9562 ATOMIC64_DECL(xchg);
9563 ATOMIC64_DECL(add_return);
9564+ATOMIC64_DECL(add_return_unchecked);
9565 ATOMIC64_DECL(sub_return);
9566+ATOMIC64_DECL(sub_return_unchecked);
9567 ATOMIC64_DECL(inc_return);
9568+ATOMIC64_DECL(inc_return_unchecked);
9569 ATOMIC64_DECL(dec_return);
9570+ATOMIC64_DECL(dec_return_unchecked);
9571 ATOMIC64_DECL(dec_if_positive);
9572 ATOMIC64_DECL(inc_not_zero);
9573 ATOMIC64_DECL(add_unless);
9574@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9575 }
9576
9577 /**
9578+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9579+ * @p: pointer to type atomic64_unchecked_t
9580+ * @o: expected value
9581+ * @n: new value
9582+ *
9583+ * Atomically sets @v to @n if it was equal to @o and returns
9584+ * the old value.
9585+ */
9586+
9587+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9588+{
9589+ return cmpxchg64(&v->counter, o, n);
9590+}
9591+
9592+/**
9593 * atomic64_xchg - xchg atomic64 variable
9594 * @v: pointer to type atomic64_t
9595 * @n: value to assign
9596@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9597 }
9598
9599 /**
9600+ * atomic64_set_unchecked - set atomic64 variable
9601+ * @v: pointer to type atomic64_unchecked_t
9602+ * @n: value to assign
9603+ *
9604+ * Atomically sets the value of @v to @n.
9605+ */
9606+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9607+{
9608+ unsigned high = (unsigned)(i >> 32);
9609+ unsigned low = (unsigned)i;
9610+ alternative_atomic64(set, /* no output */,
9611+ "S" (v), "b" (low), "c" (high)
9612+ : "eax", "edx", "memory");
9613+}
9614+
9615+/**
9616 * atomic64_read - read atomic64 variable
9617 * @v: pointer to type atomic64_t
9618 *
9619@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9620 }
9621
9622 /**
9623+ * atomic64_read_unchecked - read atomic64 variable
9624+ * @v: pointer to type atomic64_unchecked_t
9625+ *
9626+ * Atomically reads the value of @v and returns it.
9627+ */
9628+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9629+{
9630+ long long r;
9631+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9632+ return r;
9633+ }
9634+
9635+/**
9636 * atomic64_add_return - add and return
9637 * @i: integer value to add
9638 * @v: pointer to type atomic64_t
9639@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9640 return i;
9641 }
9642
9643+/**
9644+ * atomic64_add_return_unchecked - add and return
9645+ * @i: integer value to add
9646+ * @v: pointer to type atomic64_unchecked_t
9647+ *
9648+ * Atomically adds @i to @v and returns @i + *@v
9649+ */
9650+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9651+{
9652+ alternative_atomic64(add_return_unchecked,
9653+ ASM_OUTPUT2("+A" (i), "+c" (v)),
9654+ ASM_NO_INPUT_CLOBBER("memory"));
9655+ return i;
9656+}
9657+
9658 /*
9659 * Other variants with different arithmetic operators:
9660 */
9661@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9662 return a;
9663 }
9664
9665+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9666+{
9667+ long long a;
9668+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
9669+ "S" (v) : "memory", "ecx");
9670+ return a;
9671+}
9672+
9673 static inline long long atomic64_dec_return(atomic64_t *v)
9674 {
9675 long long a;
9676@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9677 }
9678
9679 /**
9680+ * atomic64_add_unchecked - add integer to atomic64 variable
9681+ * @i: integer value to add
9682+ * @v: pointer to type atomic64_unchecked_t
9683+ *
9684+ * Atomically adds @i to @v.
9685+ */
9686+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9687+{
9688+ __alternative_atomic64(add_unchecked, add_return_unchecked,
9689+ ASM_OUTPUT2("+A" (i), "+c" (v)),
9690+ ASM_NO_INPUT_CLOBBER("memory"));
9691+ return i;
9692+}
9693+
9694+/**
9695 * atomic64_sub - subtract the atomic64 variable
9696 * @i: integer value to subtract
9697 * @v: pointer to type atomic64_t
9698diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9699index 0e1cbfc..5623683 100644
9700--- a/arch/x86/include/asm/atomic64_64.h
9701+++ b/arch/x86/include/asm/atomic64_64.h
9702@@ -18,7 +18,19 @@
9703 */
9704 static inline long atomic64_read(const atomic64_t *v)
9705 {
9706- return (*(volatile long *)&(v)->counter);
9707+ return (*(volatile const long *)&(v)->counter);
9708+}
9709+
9710+/**
9711+ * atomic64_read_unchecked - read atomic64 variable
9712+ * @v: pointer of type atomic64_unchecked_t
9713+ *
9714+ * Atomically reads the value of @v.
9715+ * Doesn't imply a read memory barrier.
9716+ */
9717+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9718+{
9719+ return (*(volatile const long *)&(v)->counter);
9720 }
9721
9722 /**
9723@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9724 }
9725
9726 /**
9727+ * atomic64_set_unchecked - set atomic64 variable
9728+ * @v: pointer to type atomic64_unchecked_t
9729+ * @i: required value
9730+ *
9731+ * Atomically sets the value of @v to @i.
9732+ */
9733+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9734+{
9735+ v->counter = i;
9736+}
9737+
9738+/**
9739 * atomic64_add - add integer to atomic64 variable
9740 * @i: integer value to add
9741 * @v: pointer to type atomic64_t
9742@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9743 */
9744 static inline void atomic64_add(long i, atomic64_t *v)
9745 {
9746+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
9747+
9748+#ifdef CONFIG_PAX_REFCOUNT
9749+ "jno 0f\n"
9750+ LOCK_PREFIX "subq %1,%0\n"
9751+ "int $4\n0:\n"
9752+ _ASM_EXTABLE(0b, 0b)
9753+#endif
9754+
9755+ : "=m" (v->counter)
9756+ : "er" (i), "m" (v->counter));
9757+}
9758+
9759+/**
9760+ * atomic64_add_unchecked - add integer to atomic64 variable
9761+ * @i: integer value to add
9762+ * @v: pointer to type atomic64_unchecked_t
9763+ *
9764+ * Atomically adds @i to @v.
9765+ */
9766+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9767+{
9768 asm volatile(LOCK_PREFIX "addq %1,%0"
9769 : "=m" (v->counter)
9770 : "er" (i), "m" (v->counter));
9771@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9772 */
9773 static inline void atomic64_sub(long i, atomic64_t *v)
9774 {
9775- asm volatile(LOCK_PREFIX "subq %1,%0"
9776+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9777+
9778+#ifdef CONFIG_PAX_REFCOUNT
9779+ "jno 0f\n"
9780+ LOCK_PREFIX "addq %1,%0\n"
9781+ "int $4\n0:\n"
9782+ _ASM_EXTABLE(0b, 0b)
9783+#endif
9784+
9785+ : "=m" (v->counter)
9786+ : "er" (i), "m" (v->counter));
9787+}
9788+
9789+/**
9790+ * atomic64_sub_unchecked - subtract the atomic64 variable
9791+ * @i: integer value to subtract
9792+ * @v: pointer to type atomic64_unchecked_t
9793+ *
9794+ * Atomically subtracts @i from @v.
9795+ */
9796+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9797+{
9798+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9799 : "=m" (v->counter)
9800 : "er" (i), "m" (v->counter));
9801 }
9802@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9803 {
9804 unsigned char c;
9805
9806- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9807+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
9808+
9809+#ifdef CONFIG_PAX_REFCOUNT
9810+ "jno 0f\n"
9811+ LOCK_PREFIX "addq %2,%0\n"
9812+ "int $4\n0:\n"
9813+ _ASM_EXTABLE(0b, 0b)
9814+#endif
9815+
9816+ "sete %1\n"
9817 : "=m" (v->counter), "=qm" (c)
9818 : "er" (i), "m" (v->counter) : "memory");
9819 return c;
9820@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9821 */
9822 static inline void atomic64_inc(atomic64_t *v)
9823 {
9824+ asm volatile(LOCK_PREFIX "incq %0\n"
9825+
9826+#ifdef CONFIG_PAX_REFCOUNT
9827+ "jno 0f\n"
9828+ LOCK_PREFIX "decq %0\n"
9829+ "int $4\n0:\n"
9830+ _ASM_EXTABLE(0b, 0b)
9831+#endif
9832+
9833+ : "=m" (v->counter)
9834+ : "m" (v->counter));
9835+}
9836+
9837+/**
9838+ * atomic64_inc_unchecked - increment atomic64 variable
9839+ * @v: pointer to type atomic64_unchecked_t
9840+ *
9841+ * Atomically increments @v by 1.
9842+ */
9843+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9844+{
9845 asm volatile(LOCK_PREFIX "incq %0"
9846 : "=m" (v->counter)
9847 : "m" (v->counter));
9848@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9849 */
9850 static inline void atomic64_dec(atomic64_t *v)
9851 {
9852- asm volatile(LOCK_PREFIX "decq %0"
9853+ asm volatile(LOCK_PREFIX "decq %0\n"
9854+
9855+#ifdef CONFIG_PAX_REFCOUNT
9856+ "jno 0f\n"
9857+ LOCK_PREFIX "incq %0\n"
9858+ "int $4\n0:\n"
9859+ _ASM_EXTABLE(0b, 0b)
9860+#endif
9861+
9862+ : "=m" (v->counter)
9863+ : "m" (v->counter));
9864+}
9865+
9866+/**
9867+ * atomic64_dec_unchecked - decrement atomic64 variable
9868+ * @v: pointer to type atomic64_t
9869+ *
9870+ * Atomically decrements @v by 1.
9871+ */
9872+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9873+{
9874+ asm volatile(LOCK_PREFIX "decq %0\n"
9875 : "=m" (v->counter)
9876 : "m" (v->counter));
9877 }
9878@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9879 {
9880 unsigned char c;
9881
9882- asm volatile(LOCK_PREFIX "decq %0; sete %1"
9883+ asm volatile(LOCK_PREFIX "decq %0\n"
9884+
9885+#ifdef CONFIG_PAX_REFCOUNT
9886+ "jno 0f\n"
9887+ LOCK_PREFIX "incq %0\n"
9888+ "int $4\n0:\n"
9889+ _ASM_EXTABLE(0b, 0b)
9890+#endif
9891+
9892+ "sete %1\n"
9893 : "=m" (v->counter), "=qm" (c)
9894 : "m" (v->counter) : "memory");
9895 return c != 0;
9896@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9897 {
9898 unsigned char c;
9899
9900- asm volatile(LOCK_PREFIX "incq %0; sete %1"
9901+ asm volatile(LOCK_PREFIX "incq %0\n"
9902+
9903+#ifdef CONFIG_PAX_REFCOUNT
9904+ "jno 0f\n"
9905+ LOCK_PREFIX "decq %0\n"
9906+ "int $4\n0:\n"
9907+ _ASM_EXTABLE(0b, 0b)
9908+#endif
9909+
9910+ "sete %1\n"
9911 : "=m" (v->counter), "=qm" (c)
9912 : "m" (v->counter) : "memory");
9913 return c != 0;
9914@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9915 {
9916 unsigned char c;
9917
9918- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9919+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
9920+
9921+#ifdef CONFIG_PAX_REFCOUNT
9922+ "jno 0f\n"
9923+ LOCK_PREFIX "subq %2,%0\n"
9924+ "int $4\n0:\n"
9925+ _ASM_EXTABLE(0b, 0b)
9926+#endif
9927+
9928+ "sets %1\n"
9929 : "=m" (v->counter), "=qm" (c)
9930 : "er" (i), "m" (v->counter) : "memory");
9931 return c;
9932@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9933 */
9934 static inline long atomic64_add_return(long i, atomic64_t *v)
9935 {
9936+ return i + xadd_check_overflow(&v->counter, i);
9937+}
9938+
9939+/**
9940+ * atomic64_add_return_unchecked - add and return
9941+ * @i: integer value to add
9942+ * @v: pointer to type atomic64_unchecked_t
9943+ *
9944+ * Atomically adds @i to @v and returns @i + @v
9945+ */
9946+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9947+{
9948 return i + xadd(&v->counter, i);
9949 }
9950
9951@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9952 }
9953
9954 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9955+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9956+{
9957+ return atomic64_add_return_unchecked(1, v);
9958+}
9959 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9960
9961 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9962@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9963 return cmpxchg(&v->counter, old, new);
9964 }
9965
9966+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
9967+{
9968+ return cmpxchg(&v->counter, old, new);
9969+}
9970+
9971 static inline long atomic64_xchg(atomic64_t *v, long new)
9972 {
9973 return xchg(&v->counter, new);
9974@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
9975 */
9976 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
9977 {
9978- long c, old;
9979+ long c, old, new;
9980 c = atomic64_read(v);
9981 for (;;) {
9982- if (unlikely(c == (u)))
9983+ if (unlikely(c == u))
9984 break;
9985- old = atomic64_cmpxchg((v), c, c + (a));
9986+
9987+ asm volatile("add %2,%0\n"
9988+
9989+#ifdef CONFIG_PAX_REFCOUNT
9990+ "jno 0f\n"
9991+ "sub %2,%0\n"
9992+ "int $4\n0:\n"
9993+ _ASM_EXTABLE(0b, 0b)
9994+#endif
9995+
9996+ : "=r" (new)
9997+ : "0" (c), "ir" (a));
9998+
9999+ old = atomic64_cmpxchg(v, c, new);
10000 if (likely(old == c))
10001 break;
10002 c = old;
10003 }
10004- return c != (u);
10005+ return c != u;
10006 }
10007
10008 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10009diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10010index b97596e..9bd48b06 100644
10011--- a/arch/x86/include/asm/bitops.h
10012+++ b/arch/x86/include/asm/bitops.h
10013@@ -38,7 +38,7 @@
10014 * a mask operation on a byte.
10015 */
10016 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10017-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10018+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10019 #define CONST_MASK(nr) (1 << ((nr) & 7))
10020
10021 /**
10022diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10023index 5e1a2ee..c9f9533 100644
10024--- a/arch/x86/include/asm/boot.h
10025+++ b/arch/x86/include/asm/boot.h
10026@@ -11,10 +11,15 @@
10027 #include <asm/pgtable_types.h>
10028
10029 /* Physical address where kernel should be loaded. */
10030-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10031+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10032 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10033 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10034
10035+#ifndef __ASSEMBLY__
10036+extern unsigned char __LOAD_PHYSICAL_ADDR[];
10037+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10038+#endif
10039+
10040 /* Minimum kernel alignment, as a power of two */
10041 #ifdef CONFIG_X86_64
10042 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10043diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10044index 48f99f1..d78ebf9 100644
10045--- a/arch/x86/include/asm/cache.h
10046+++ b/arch/x86/include/asm/cache.h
10047@@ -5,12 +5,13 @@
10048
10049 /* L1 cache line size */
10050 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10051-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10052+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10053
10054 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10055+#define __read_only __attribute__((__section__(".data..read_only")))
10056
10057 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10058-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10059+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10060
10061 #ifdef CONFIG_X86_VSMP
10062 #ifdef CONFIG_SMP
10063diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10064index 9863ee3..4a1f8e1 100644
10065--- a/arch/x86/include/asm/cacheflush.h
10066+++ b/arch/x86/include/asm/cacheflush.h
10067@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10068 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10069
10070 if (pg_flags == _PGMT_DEFAULT)
10071- return -1;
10072+ return ~0UL;
10073 else if (pg_flags == _PGMT_WC)
10074 return _PAGE_CACHE_WC;
10075 else if (pg_flags == _PGMT_UC_MINUS)
10076diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10077index 46fc474..b02b0f9 100644
10078--- a/arch/x86/include/asm/checksum_32.h
10079+++ b/arch/x86/include/asm/checksum_32.h
10080@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10081 int len, __wsum sum,
10082 int *src_err_ptr, int *dst_err_ptr);
10083
10084+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10085+ int len, __wsum sum,
10086+ int *src_err_ptr, int *dst_err_ptr);
10087+
10088+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10089+ int len, __wsum sum,
10090+ int *src_err_ptr, int *dst_err_ptr);
10091+
10092 /*
10093 * Note: when you get a NULL pointer exception here this means someone
10094 * passed in an incorrect kernel address to one of these functions.
10095@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10096 int *err_ptr)
10097 {
10098 might_sleep();
10099- return csum_partial_copy_generic((__force void *)src, dst,
10100+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
10101 len, sum, err_ptr, NULL);
10102 }
10103
10104@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10105 {
10106 might_sleep();
10107 if (access_ok(VERIFY_WRITE, dst, len))
10108- return csum_partial_copy_generic(src, (__force void *)dst,
10109+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10110 len, sum, NULL, err_ptr);
10111
10112 if (len)
10113diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10114index 99480e5..d81165b 100644
10115--- a/arch/x86/include/asm/cmpxchg.h
10116+++ b/arch/x86/include/asm/cmpxchg.h
10117@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10118 __compiletime_error("Bad argument size for cmpxchg");
10119 extern void __xadd_wrong_size(void)
10120 __compiletime_error("Bad argument size for xadd");
10121+extern void __xadd_check_overflow_wrong_size(void)
10122+ __compiletime_error("Bad argument size for xadd_check_overflow");
10123 extern void __add_wrong_size(void)
10124 __compiletime_error("Bad argument size for add");
10125+extern void __add_check_overflow_wrong_size(void)
10126+ __compiletime_error("Bad argument size for add_check_overflow");
10127
10128 /*
10129 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10130@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10131 __ret; \
10132 })
10133
10134+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10135+ ({ \
10136+ __typeof__ (*(ptr)) __ret = (arg); \
10137+ switch (sizeof(*(ptr))) { \
10138+ case __X86_CASE_L: \
10139+ asm volatile (lock #op "l %0, %1\n" \
10140+ "jno 0f\n" \
10141+ "mov %0,%1\n" \
10142+ "int $4\n0:\n" \
10143+ _ASM_EXTABLE(0b, 0b) \
10144+ : "+r" (__ret), "+m" (*(ptr)) \
10145+ : : "memory", "cc"); \
10146+ break; \
10147+ case __X86_CASE_Q: \
10148+ asm volatile (lock #op "q %q0, %1\n" \
10149+ "jno 0f\n" \
10150+ "mov %0,%1\n" \
10151+ "int $4\n0:\n" \
10152+ _ASM_EXTABLE(0b, 0b) \
10153+ : "+r" (__ret), "+m" (*(ptr)) \
10154+ : : "memory", "cc"); \
10155+ break; \
10156+ default: \
10157+ __ ## op ## _check_overflow_wrong_size(); \
10158+ } \
10159+ __ret; \
10160+ })
10161+
10162 /*
10163 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10164 * Since this is generally used to protect other memory information, we
10165@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10166 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10167 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10168
10169+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10170+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10171+
10172 #define __add(ptr, inc, lock) \
10173 ({ \
10174 __typeof__ (*(ptr)) __ret = (inc); \
10175diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10176index 340ee49..4238ced 100644
10177--- a/arch/x86/include/asm/cpufeature.h
10178+++ b/arch/x86/include/asm/cpufeature.h
10179@@ -371,7 +371,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10180 ".section .discard,\"aw\",@progbits\n"
10181 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10182 ".previous\n"
10183- ".section .altinstr_replacement,\"ax\"\n"
10184+ ".section .altinstr_replacement,\"a\"\n"
10185 "3: movb $1,%0\n"
10186 "4:\n"
10187 ".previous\n"
10188diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10189index e95822d..a90010e 100644
10190--- a/arch/x86/include/asm/desc.h
10191+++ b/arch/x86/include/asm/desc.h
10192@@ -4,6 +4,7 @@
10193 #include <asm/desc_defs.h>
10194 #include <asm/ldt.h>
10195 #include <asm/mmu.h>
10196+#include <asm/pgtable.h>
10197
10198 #include <linux/smp.h>
10199
10200@@ -16,6 +17,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10201
10202 desc->type = (info->read_exec_only ^ 1) << 1;
10203 desc->type |= info->contents << 2;
10204+ desc->type |= info->seg_not_present ^ 1;
10205
10206 desc->s = 1;
10207 desc->dpl = 0x3;
10208@@ -34,19 +36,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10209 }
10210
10211 extern struct desc_ptr idt_descr;
10212-extern gate_desc idt_table[];
10213 extern struct desc_ptr nmi_idt_descr;
10214-extern gate_desc nmi_idt_table[];
10215-
10216-struct gdt_page {
10217- struct desc_struct gdt[GDT_ENTRIES];
10218-} __attribute__((aligned(PAGE_SIZE)));
10219-
10220-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10221+extern gate_desc idt_table[256];
10222+extern gate_desc nmi_idt_table[256];
10223
10224+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10225 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10226 {
10227- return per_cpu(gdt_page, cpu).gdt;
10228+ return cpu_gdt_table[cpu];
10229 }
10230
10231 #ifdef CONFIG_X86_64
10232@@ -71,8 +68,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10233 unsigned long base, unsigned dpl, unsigned flags,
10234 unsigned short seg)
10235 {
10236- gate->a = (seg << 16) | (base & 0xffff);
10237- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10238+ gate->gate.offset_low = base;
10239+ gate->gate.seg = seg;
10240+ gate->gate.reserved = 0;
10241+ gate->gate.type = type;
10242+ gate->gate.s = 0;
10243+ gate->gate.dpl = dpl;
10244+ gate->gate.p = 1;
10245+ gate->gate.offset_high = base >> 16;
10246 }
10247
10248 #endif
10249@@ -117,12 +120,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10250
10251 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10252 {
10253+ pax_open_kernel();
10254 memcpy(&idt[entry], gate, sizeof(*gate));
10255+ pax_close_kernel();
10256 }
10257
10258 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10259 {
10260+ pax_open_kernel();
10261 memcpy(&ldt[entry], desc, 8);
10262+ pax_close_kernel();
10263 }
10264
10265 static inline void
10266@@ -136,7 +143,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10267 default: size = sizeof(*gdt); break;
10268 }
10269
10270+ pax_open_kernel();
10271 memcpy(&gdt[entry], desc, size);
10272+ pax_close_kernel();
10273 }
10274
10275 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10276@@ -209,7 +218,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10277
10278 static inline void native_load_tr_desc(void)
10279 {
10280+ pax_open_kernel();
10281 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10282+ pax_close_kernel();
10283 }
10284
10285 static inline void native_load_gdt(const struct desc_ptr *dtr)
10286@@ -246,8 +257,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10287 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10288 unsigned int i;
10289
10290+ pax_open_kernel();
10291 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10292 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10293+ pax_close_kernel();
10294 }
10295
10296 #define _LDT_empty(info) \
10297@@ -310,7 +323,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10298 }
10299
10300 #ifdef CONFIG_X86_64
10301-static inline void set_nmi_gate(int gate, void *addr)
10302+static inline void set_nmi_gate(int gate, const void *addr)
10303 {
10304 gate_desc s;
10305
10306@@ -319,7 +332,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10307 }
10308 #endif
10309
10310-static inline void _set_gate(int gate, unsigned type, void *addr,
10311+static inline void _set_gate(int gate, unsigned type, const void *addr,
10312 unsigned dpl, unsigned ist, unsigned seg)
10313 {
10314 gate_desc s;
10315@@ -338,7 +351,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10316 * Pentium F0 0F bugfix can have resulted in the mapped
10317 * IDT being write-protected.
10318 */
10319-static inline void set_intr_gate(unsigned int n, void *addr)
10320+static inline void set_intr_gate(unsigned int n, const void *addr)
10321 {
10322 BUG_ON((unsigned)n > 0xFF);
10323 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10324@@ -368,19 +381,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10325 /*
10326 * This routine sets up an interrupt gate at directory privilege level 3.
10327 */
10328-static inline void set_system_intr_gate(unsigned int n, void *addr)
10329+static inline void set_system_intr_gate(unsigned int n, const void *addr)
10330 {
10331 BUG_ON((unsigned)n > 0xFF);
10332 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10333 }
10334
10335-static inline void set_system_trap_gate(unsigned int n, void *addr)
10336+static inline void set_system_trap_gate(unsigned int n, const void *addr)
10337 {
10338 BUG_ON((unsigned)n > 0xFF);
10339 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10340 }
10341
10342-static inline void set_trap_gate(unsigned int n, void *addr)
10343+static inline void set_trap_gate(unsigned int n, const void *addr)
10344 {
10345 BUG_ON((unsigned)n > 0xFF);
10346 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10347@@ -389,19 +402,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10348 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10349 {
10350 BUG_ON((unsigned)n > 0xFF);
10351- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10352+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10353 }
10354
10355-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10356+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10357 {
10358 BUG_ON((unsigned)n > 0xFF);
10359 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10360 }
10361
10362-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10363+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10364 {
10365 BUG_ON((unsigned)n > 0xFF);
10366 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10367 }
10368
10369+#ifdef CONFIG_X86_32
10370+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10371+{
10372+ struct desc_struct d;
10373+
10374+ if (likely(limit))
10375+ limit = (limit - 1UL) >> PAGE_SHIFT;
10376+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
10377+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10378+}
10379+#endif
10380+
10381 #endif /* _ASM_X86_DESC_H */
10382diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10383index 278441f..b95a174 100644
10384--- a/arch/x86/include/asm/desc_defs.h
10385+++ b/arch/x86/include/asm/desc_defs.h
10386@@ -31,6 +31,12 @@ struct desc_struct {
10387 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10388 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10389 };
10390+ struct {
10391+ u16 offset_low;
10392+ u16 seg;
10393+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10394+ unsigned offset_high: 16;
10395+ } gate;
10396 };
10397 } __attribute__((packed));
10398
10399diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10400index 3778256..c5d4fce 100644
10401--- a/arch/x86/include/asm/e820.h
10402+++ b/arch/x86/include/asm/e820.h
10403@@ -69,7 +69,7 @@ struct e820map {
10404 #define ISA_START_ADDRESS 0xa0000
10405 #define ISA_END_ADDRESS 0x100000
10406
10407-#define BIOS_BEGIN 0x000a0000
10408+#define BIOS_BEGIN 0x000c0000
10409 #define BIOS_END 0x00100000
10410
10411 #define BIOS_ROM_BASE 0xffe00000
10412diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10413index 5939f44..f8845f6 100644
10414--- a/arch/x86/include/asm/elf.h
10415+++ b/arch/x86/include/asm/elf.h
10416@@ -243,7 +243,25 @@ extern int force_personality32;
10417 the loader. We need to make sure that it is out of the way of the program
10418 that it will "exec", and that there is sufficient room for the brk. */
10419
10420+#ifdef CONFIG_PAX_SEGMEXEC
10421+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10422+#else
10423 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10424+#endif
10425+
10426+#ifdef CONFIG_PAX_ASLR
10427+#ifdef CONFIG_X86_32
10428+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10429+
10430+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10431+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10432+#else
10433+#define PAX_ELF_ET_DYN_BASE 0x400000UL
10434+
10435+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10436+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10437+#endif
10438+#endif
10439
10440 /* This yields a mask that user programs can use to figure out what
10441 instruction set this CPU supports. This could be done in user space,
10442@@ -296,16 +314,12 @@ do { \
10443
10444 #define ARCH_DLINFO \
10445 do { \
10446- if (vdso_enabled) \
10447- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10448- (unsigned long)current->mm->context.vdso); \
10449+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10450 } while (0)
10451
10452 #define ARCH_DLINFO_X32 \
10453 do { \
10454- if (vdso_enabled) \
10455- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10456- (unsigned long)current->mm->context.vdso); \
10457+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10458 } while (0)
10459
10460 #define AT_SYSINFO 32
10461@@ -320,7 +334,7 @@ else \
10462
10463 #endif /* !CONFIG_X86_32 */
10464
10465-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10466+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10467
10468 #define VDSO_ENTRY \
10469 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10470@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10471 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10472 #define compat_arch_setup_additional_pages syscall32_setup_pages
10473
10474-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10475-#define arch_randomize_brk arch_randomize_brk
10476-
10477 /*
10478 * True on X86_32 or when emulating IA32 on X86_64
10479 */
10480diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10481index cc70c1c..d96d011 100644
10482--- a/arch/x86/include/asm/emergency-restart.h
10483+++ b/arch/x86/include/asm/emergency-restart.h
10484@@ -15,6 +15,6 @@ enum reboot_type {
10485
10486 extern enum reboot_type reboot_type;
10487
10488-extern void machine_emergency_restart(void);
10489+extern void machine_emergency_restart(void) __noreturn;
10490
10491 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10492diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10493index 4fa8815..71b121a 100644
10494--- a/arch/x86/include/asm/fpu-internal.h
10495+++ b/arch/x86/include/asm/fpu-internal.h
10496@@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10497 {
10498 int err;
10499
10500+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10501+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10502+ fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10503+#endif
10504+
10505 /* See comment in fxsave() below. */
10506 #ifdef CONFIG_AS_FXSAVEQ
10507 asm volatile("1: fxrstorq %[fx]\n\t"
10508@@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10509 {
10510 int err;
10511
10512+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10513+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10514+ fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10515+#endif
10516+
10517 /*
10518 * Clear the bytes not touched by the fxsave and reserved
10519 * for the SW usage.
10520@@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10521 "emms\n\t" /* clear stack tags */
10522 "fildl %P[addr]", /* set F?P to defined value */
10523 X86_FEATURE_FXSAVE_LEAK,
10524- [addr] "m" (tsk->thread.fpu.has_fpu));
10525+ [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10526
10527 return fpu_restore_checking(&tsk->thread.fpu);
10528 }
10529diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10530index 71ecbcb..bac10b7 100644
10531--- a/arch/x86/include/asm/futex.h
10532+++ b/arch/x86/include/asm/futex.h
10533@@ -11,16 +11,18 @@
10534 #include <asm/processor.h>
10535
10536 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10537+ typecheck(u32 __user *, uaddr); \
10538 asm volatile("1:\t" insn "\n" \
10539 "2:\t.section .fixup,\"ax\"\n" \
10540 "3:\tmov\t%3, %1\n" \
10541 "\tjmp\t2b\n" \
10542 "\t.previous\n" \
10543 _ASM_EXTABLE(1b, 3b) \
10544- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10545+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10546 : "i" (-EFAULT), "0" (oparg), "1" (0))
10547
10548 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10549+ typecheck(u32 __user *, uaddr); \
10550 asm volatile("1:\tmovl %2, %0\n" \
10551 "\tmovl\t%0, %3\n" \
10552 "\t" insn "\n" \
10553@@ -33,7 +35,7 @@
10554 _ASM_EXTABLE(1b, 4b) \
10555 _ASM_EXTABLE(2b, 4b) \
10556 : "=&a" (oldval), "=&r" (ret), \
10557- "+m" (*uaddr), "=&r" (tem) \
10558+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10559 : "r" (oparg), "i" (-EFAULT), "1" (0))
10560
10561 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10562@@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10563
10564 switch (op) {
10565 case FUTEX_OP_SET:
10566- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10567+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10568 break;
10569 case FUTEX_OP_ADD:
10570- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10571+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10572 uaddr, oparg);
10573 break;
10574 case FUTEX_OP_OR:
10575@@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10576 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10577 return -EFAULT;
10578
10579- asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10580+ asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10581 "2:\t.section .fixup, \"ax\"\n"
10582 "3:\tmov %3, %0\n"
10583 "\tjmp 2b\n"
10584 "\t.previous\n"
10585 _ASM_EXTABLE(1b, 3b)
10586- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10587+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10588 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10589 : "memory"
10590 );
10591diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10592index eb92a6e..b98b2f4 100644
10593--- a/arch/x86/include/asm/hw_irq.h
10594+++ b/arch/x86/include/asm/hw_irq.h
10595@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10596 extern void enable_IO_APIC(void);
10597
10598 /* Statistics */
10599-extern atomic_t irq_err_count;
10600-extern atomic_t irq_mis_count;
10601+extern atomic_unchecked_t irq_err_count;
10602+extern atomic_unchecked_t irq_mis_count;
10603
10604 /* EISA */
10605 extern void eisa_set_level_irq(unsigned int irq);
10606diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10607index d8e8eef..99f81ae 100644
10608--- a/arch/x86/include/asm/io.h
10609+++ b/arch/x86/include/asm/io.h
10610@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10611
10612 #include <linux/vmalloc.h>
10613
10614+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10615+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10616+{
10617+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10618+}
10619+
10620+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10621+{
10622+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10623+}
10624+
10625 /*
10626 * Convert a virtual cached pointer to an uncached pointer
10627 */
10628diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10629index bba3cf8..06bc8da 100644
10630--- a/arch/x86/include/asm/irqflags.h
10631+++ b/arch/x86/include/asm/irqflags.h
10632@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10633 sti; \
10634 sysexit
10635
10636+#define GET_CR0_INTO_RDI mov %cr0, %rdi
10637+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10638+#define GET_CR3_INTO_RDI mov %cr3, %rdi
10639+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10640+
10641 #else
10642 #define INTERRUPT_RETURN iret
10643 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10644diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10645index 5478825..839e88c 100644
10646--- a/arch/x86/include/asm/kprobes.h
10647+++ b/arch/x86/include/asm/kprobes.h
10648@@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10649 #define RELATIVEJUMP_SIZE 5
10650 #define RELATIVECALL_OPCODE 0xe8
10651 #define RELATIVE_ADDR_SIZE 4
10652-#define MAX_STACK_SIZE 64
10653-#define MIN_STACK_SIZE(ADDR) \
10654- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10655- THREAD_SIZE - (unsigned long)(ADDR))) \
10656- ? (MAX_STACK_SIZE) \
10657- : (((unsigned long)current_thread_info()) + \
10658- THREAD_SIZE - (unsigned long)(ADDR)))
10659+#define MAX_STACK_SIZE 64UL
10660+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10661
10662 #define flush_insn_slot(p) do { } while (0)
10663
10664diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10665index e216ba0..453f6ec 100644
10666--- a/arch/x86/include/asm/kvm_host.h
10667+++ b/arch/x86/include/asm/kvm_host.h
10668@@ -679,7 +679,7 @@ struct kvm_x86_ops {
10669 int (*check_intercept)(struct kvm_vcpu *vcpu,
10670 struct x86_instruction_info *info,
10671 enum x86_intercept_stage stage);
10672-};
10673+} __do_const;
10674
10675 struct kvm_arch_async_pf {
10676 u32 token;
10677diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10678index c8bed0d..e5721fa 100644
10679--- a/arch/x86/include/asm/local.h
10680+++ b/arch/x86/include/asm/local.h
10681@@ -17,26 +17,58 @@ typedef struct {
10682
10683 static inline void local_inc(local_t *l)
10684 {
10685- asm volatile(_ASM_INC "%0"
10686+ asm volatile(_ASM_INC "%0\n"
10687+
10688+#ifdef CONFIG_PAX_REFCOUNT
10689+ "jno 0f\n"
10690+ _ASM_DEC "%0\n"
10691+ "int $4\n0:\n"
10692+ _ASM_EXTABLE(0b, 0b)
10693+#endif
10694+
10695 : "+m" (l->a.counter));
10696 }
10697
10698 static inline void local_dec(local_t *l)
10699 {
10700- asm volatile(_ASM_DEC "%0"
10701+ asm volatile(_ASM_DEC "%0\n"
10702+
10703+#ifdef CONFIG_PAX_REFCOUNT
10704+ "jno 0f\n"
10705+ _ASM_INC "%0\n"
10706+ "int $4\n0:\n"
10707+ _ASM_EXTABLE(0b, 0b)
10708+#endif
10709+
10710 : "+m" (l->a.counter));
10711 }
10712
10713 static inline void local_add(long i, local_t *l)
10714 {
10715- asm volatile(_ASM_ADD "%1,%0"
10716+ asm volatile(_ASM_ADD "%1,%0\n"
10717+
10718+#ifdef CONFIG_PAX_REFCOUNT
10719+ "jno 0f\n"
10720+ _ASM_SUB "%1,%0\n"
10721+ "int $4\n0:\n"
10722+ _ASM_EXTABLE(0b, 0b)
10723+#endif
10724+
10725 : "+m" (l->a.counter)
10726 : "ir" (i));
10727 }
10728
10729 static inline void local_sub(long i, local_t *l)
10730 {
10731- asm volatile(_ASM_SUB "%1,%0"
10732+ asm volatile(_ASM_SUB "%1,%0\n"
10733+
10734+#ifdef CONFIG_PAX_REFCOUNT
10735+ "jno 0f\n"
10736+ _ASM_ADD "%1,%0\n"
10737+ "int $4\n0:\n"
10738+ _ASM_EXTABLE(0b, 0b)
10739+#endif
10740+
10741 : "+m" (l->a.counter)
10742 : "ir" (i));
10743 }
10744@@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10745 {
10746 unsigned char c;
10747
10748- asm volatile(_ASM_SUB "%2,%0; sete %1"
10749+ asm volatile(_ASM_SUB "%2,%0\n"
10750+
10751+#ifdef CONFIG_PAX_REFCOUNT
10752+ "jno 0f\n"
10753+ _ASM_ADD "%2,%0\n"
10754+ "int $4\n0:\n"
10755+ _ASM_EXTABLE(0b, 0b)
10756+#endif
10757+
10758+ "sete %1\n"
10759 : "+m" (l->a.counter), "=qm" (c)
10760 : "ir" (i) : "memory");
10761 return c;
10762@@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10763 {
10764 unsigned char c;
10765
10766- asm volatile(_ASM_DEC "%0; sete %1"
10767+ asm volatile(_ASM_DEC "%0\n"
10768+
10769+#ifdef CONFIG_PAX_REFCOUNT
10770+ "jno 0f\n"
10771+ _ASM_INC "%0\n"
10772+ "int $4\n0:\n"
10773+ _ASM_EXTABLE(0b, 0b)
10774+#endif
10775+
10776+ "sete %1\n"
10777 : "+m" (l->a.counter), "=qm" (c)
10778 : : "memory");
10779 return c != 0;
10780@@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10781 {
10782 unsigned char c;
10783
10784- asm volatile(_ASM_INC "%0; sete %1"
10785+ asm volatile(_ASM_INC "%0\n"
10786+
10787+#ifdef CONFIG_PAX_REFCOUNT
10788+ "jno 0f\n"
10789+ _ASM_DEC "%0\n"
10790+ "int $4\n0:\n"
10791+ _ASM_EXTABLE(0b, 0b)
10792+#endif
10793+
10794+ "sete %1\n"
10795 : "+m" (l->a.counter), "=qm" (c)
10796 : : "memory");
10797 return c != 0;
10798@@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10799 {
10800 unsigned char c;
10801
10802- asm volatile(_ASM_ADD "%2,%0; sets %1"
10803+ asm volatile(_ASM_ADD "%2,%0\n"
10804+
10805+#ifdef CONFIG_PAX_REFCOUNT
10806+ "jno 0f\n"
10807+ _ASM_SUB "%2,%0\n"
10808+ "int $4\n0:\n"
10809+ _ASM_EXTABLE(0b, 0b)
10810+#endif
10811+
10812+ "sets %1\n"
10813 : "+m" (l->a.counter), "=qm" (c)
10814 : "ir" (i) : "memory");
10815 return c;
10816@@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10817 #endif
10818 /* Modern 486+ processor */
10819 __i = i;
10820- asm volatile(_ASM_XADD "%0, %1;"
10821+ asm volatile(_ASM_XADD "%0, %1\n"
10822+
10823+#ifdef CONFIG_PAX_REFCOUNT
10824+ "jno 0f\n"
10825+ _ASM_MOV "%0,%1\n"
10826+ "int $4\n0:\n"
10827+ _ASM_EXTABLE(0b, 0b)
10828+#endif
10829+
10830 : "+r" (i), "+m" (l->a.counter)
10831 : : "memory");
10832 return i + __i;
10833diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10834index 593e51d..fa69c9a 100644
10835--- a/arch/x86/include/asm/mman.h
10836+++ b/arch/x86/include/asm/mman.h
10837@@ -5,4 +5,14 @@
10838
10839 #include <asm-generic/mman.h>
10840
10841+#ifdef __KERNEL__
10842+#ifndef __ASSEMBLY__
10843+#ifdef CONFIG_X86_32
10844+#define arch_mmap_check i386_mmap_check
10845+int i386_mmap_check(unsigned long addr, unsigned long len,
10846+ unsigned long flags);
10847+#endif
10848+#endif
10849+#endif
10850+
10851 #endif /* _ASM_X86_MMAN_H */
10852diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10853index 5f55e69..e20bfb1 100644
10854--- a/arch/x86/include/asm/mmu.h
10855+++ b/arch/x86/include/asm/mmu.h
10856@@ -9,7 +9,7 @@
10857 * we put the segment information here.
10858 */
10859 typedef struct {
10860- void *ldt;
10861+ struct desc_struct *ldt;
10862 int size;
10863
10864 #ifdef CONFIG_X86_64
10865@@ -18,7 +18,19 @@ typedef struct {
10866 #endif
10867
10868 struct mutex lock;
10869- void *vdso;
10870+ unsigned long vdso;
10871+
10872+#ifdef CONFIG_X86_32
10873+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10874+ unsigned long user_cs_base;
10875+ unsigned long user_cs_limit;
10876+
10877+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10878+ cpumask_t cpu_user_cs_mask;
10879+#endif
10880+
10881+#endif
10882+#endif
10883 } mm_context_t;
10884
10885 #ifdef CONFIG_SMP
10886diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10887index 6902152..da4283a 100644
10888--- a/arch/x86/include/asm/mmu_context.h
10889+++ b/arch/x86/include/asm/mmu_context.h
10890@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10891
10892 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10893 {
10894+
10895+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10896+ unsigned int i;
10897+ pgd_t *pgd;
10898+
10899+ pax_open_kernel();
10900+ pgd = get_cpu_pgd(smp_processor_id());
10901+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10902+ set_pgd_batched(pgd+i, native_make_pgd(0));
10903+ pax_close_kernel();
10904+#endif
10905+
10906 #ifdef CONFIG_SMP
10907 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10908 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10909@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10910 struct task_struct *tsk)
10911 {
10912 unsigned cpu = smp_processor_id();
10913+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10914+ int tlbstate = TLBSTATE_OK;
10915+#endif
10916
10917 if (likely(prev != next)) {
10918 #ifdef CONFIG_SMP
10919+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10920+ tlbstate = percpu_read(cpu_tlbstate.state);
10921+#endif
10922 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10923 percpu_write(cpu_tlbstate.active_mm, next);
10924 #endif
10925 cpumask_set_cpu(cpu, mm_cpumask(next));
10926
10927 /* Re-load page tables */
10928+#ifdef CONFIG_PAX_PER_CPU_PGD
10929+ pax_open_kernel();
10930+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10931+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10932+ pax_close_kernel();
10933+ load_cr3(get_cpu_pgd(cpu));
10934+#else
10935 load_cr3(next->pgd);
10936+#endif
10937
10938 /* stop flush ipis for the previous mm */
10939 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10940@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10941 */
10942 if (unlikely(prev->context.ldt != next->context.ldt))
10943 load_LDT_nolock(&next->context);
10944- }
10945+
10946+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10947+ if (!(__supported_pte_mask & _PAGE_NX)) {
10948+ smp_mb__before_clear_bit();
10949+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10950+ smp_mb__after_clear_bit();
10951+ cpu_set(cpu, next->context.cpu_user_cs_mask);
10952+ }
10953+#endif
10954+
10955+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10956+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10957+ prev->context.user_cs_limit != next->context.user_cs_limit))
10958+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10959 #ifdef CONFIG_SMP
10960+ else if (unlikely(tlbstate != TLBSTATE_OK))
10961+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10962+#endif
10963+#endif
10964+
10965+ }
10966 else {
10967+
10968+#ifdef CONFIG_PAX_PER_CPU_PGD
10969+ pax_open_kernel();
10970+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10971+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10972+ pax_close_kernel();
10973+ load_cr3(get_cpu_pgd(cpu));
10974+#endif
10975+
10976+#ifdef CONFIG_SMP
10977 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10978 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
10979
10980@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10981 * tlb flush IPI delivery. We must reload CR3
10982 * to make sure to use no freed page tables.
10983 */
10984+
10985+#ifndef CONFIG_PAX_PER_CPU_PGD
10986 load_cr3(next->pgd);
10987+#endif
10988+
10989 load_LDT_nolock(&next->context);
10990+
10991+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10992+ if (!(__supported_pte_mask & _PAGE_NX))
10993+ cpu_set(cpu, next->context.cpu_user_cs_mask);
10994+#endif
10995+
10996+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10997+#ifdef CONFIG_PAX_PAGEEXEC
10998+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
10999+#endif
11000+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11001+#endif
11002+
11003 }
11004+#endif
11005 }
11006-#endif
11007 }
11008
11009 #define activate_mm(prev, next) \
11010diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11011index 9eae775..c914fea 100644
11012--- a/arch/x86/include/asm/module.h
11013+++ b/arch/x86/include/asm/module.h
11014@@ -5,6 +5,7 @@
11015
11016 #ifdef CONFIG_X86_64
11017 /* X86_64 does not define MODULE_PROC_FAMILY */
11018+#define MODULE_PROC_FAMILY ""
11019 #elif defined CONFIG_M386
11020 #define MODULE_PROC_FAMILY "386 "
11021 #elif defined CONFIG_M486
11022@@ -59,8 +60,20 @@
11023 #error unknown processor family
11024 #endif
11025
11026-#ifdef CONFIG_X86_32
11027-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11028+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11029+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11030+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11031+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11032+#else
11033+#define MODULE_PAX_KERNEXEC ""
11034 #endif
11035
11036+#ifdef CONFIG_PAX_MEMORY_UDEREF
11037+#define MODULE_PAX_UDEREF "UDEREF "
11038+#else
11039+#define MODULE_PAX_UDEREF ""
11040+#endif
11041+
11042+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11043+
11044 #endif /* _ASM_X86_MODULE_H */
11045diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11046index 7639dbf..e08a58c 100644
11047--- a/arch/x86/include/asm/page_64_types.h
11048+++ b/arch/x86/include/asm/page_64_types.h
11049@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11050
11051 /* duplicated to the one in bootmem.h */
11052 extern unsigned long max_pfn;
11053-extern unsigned long phys_base;
11054+extern const unsigned long phys_base;
11055
11056 extern unsigned long __phys_addr(unsigned long);
11057 #define __phys_reloc_hide(x) (x)
11058diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11059index aa0f913..0c5bc6a 100644
11060--- a/arch/x86/include/asm/paravirt.h
11061+++ b/arch/x86/include/asm/paravirt.h
11062@@ -668,6 +668,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11063 val);
11064 }
11065
11066+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11067+{
11068+ pgdval_t val = native_pgd_val(pgd);
11069+
11070+ if (sizeof(pgdval_t) > sizeof(long))
11071+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11072+ val, (u64)val >> 32);
11073+ else
11074+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11075+ val);
11076+}
11077+
11078 static inline void pgd_clear(pgd_t *pgdp)
11079 {
11080 set_pgd(pgdp, __pgd(0));
11081@@ -749,6 +761,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11082 pv_mmu_ops.set_fixmap(idx, phys, flags);
11083 }
11084
11085+#ifdef CONFIG_PAX_KERNEXEC
11086+static inline unsigned long pax_open_kernel(void)
11087+{
11088+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11089+}
11090+
11091+static inline unsigned long pax_close_kernel(void)
11092+{
11093+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11094+}
11095+#else
11096+static inline unsigned long pax_open_kernel(void) { return 0; }
11097+static inline unsigned long pax_close_kernel(void) { return 0; }
11098+#endif
11099+
11100 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11101
11102 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11103@@ -965,7 +992,7 @@ extern void default_banner(void);
11104
11105 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11106 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11107-#define PARA_INDIRECT(addr) *%cs:addr
11108+#define PARA_INDIRECT(addr) *%ss:addr
11109 #endif
11110
11111 #define INTERRUPT_RETURN \
11112@@ -1042,6 +1069,21 @@ extern void default_banner(void);
11113 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11114 CLBR_NONE, \
11115 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11116+
11117+#define GET_CR0_INTO_RDI \
11118+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11119+ mov %rax,%rdi
11120+
11121+#define SET_RDI_INTO_CR0 \
11122+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11123+
11124+#define GET_CR3_INTO_RDI \
11125+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11126+ mov %rax,%rdi
11127+
11128+#define SET_RDI_INTO_CR3 \
11129+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11130+
11131 #endif /* CONFIG_X86_32 */
11132
11133 #endif /* __ASSEMBLY__ */
11134diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11135index 8e8b9a4..f07d725 100644
11136--- a/arch/x86/include/asm/paravirt_types.h
11137+++ b/arch/x86/include/asm/paravirt_types.h
11138@@ -84,20 +84,20 @@ struct pv_init_ops {
11139 */
11140 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11141 unsigned long addr, unsigned len);
11142-};
11143+} __no_const;
11144
11145
11146 struct pv_lazy_ops {
11147 /* Set deferred update mode, used for batching operations. */
11148 void (*enter)(void);
11149 void (*leave)(void);
11150-};
11151+} __no_const;
11152
11153 struct pv_time_ops {
11154 unsigned long long (*sched_clock)(void);
11155 unsigned long long (*steal_clock)(int cpu);
11156 unsigned long (*get_tsc_khz)(void);
11157-};
11158+} __no_const;
11159
11160 struct pv_cpu_ops {
11161 /* hooks for various privileged instructions */
11162@@ -193,7 +193,7 @@ struct pv_cpu_ops {
11163
11164 void (*start_context_switch)(struct task_struct *prev);
11165 void (*end_context_switch)(struct task_struct *next);
11166-};
11167+} __no_const;
11168
11169 struct pv_irq_ops {
11170 /*
11171@@ -224,7 +224,7 @@ struct pv_apic_ops {
11172 unsigned long start_eip,
11173 unsigned long start_esp);
11174 #endif
11175-};
11176+} __no_const;
11177
11178 struct pv_mmu_ops {
11179 unsigned long (*read_cr2)(void);
11180@@ -313,6 +313,7 @@ struct pv_mmu_ops {
11181 struct paravirt_callee_save make_pud;
11182
11183 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11184+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11185 #endif /* PAGETABLE_LEVELS == 4 */
11186 #endif /* PAGETABLE_LEVELS >= 3 */
11187
11188@@ -324,6 +325,12 @@ struct pv_mmu_ops {
11189 an mfn. We can tell which is which from the index. */
11190 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11191 phys_addr_t phys, pgprot_t flags);
11192+
11193+#ifdef CONFIG_PAX_KERNEXEC
11194+ unsigned long (*pax_open_kernel)(void);
11195+ unsigned long (*pax_close_kernel)(void);
11196+#endif
11197+
11198 };
11199
11200 struct arch_spinlock;
11201@@ -334,7 +341,7 @@ struct pv_lock_ops {
11202 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11203 int (*spin_trylock)(struct arch_spinlock *lock);
11204 void (*spin_unlock)(struct arch_spinlock *lock);
11205-};
11206+} __no_const;
11207
11208 /* This contains all the paravirt structures: we get a convenient
11209 * number for each function using the offset which we use to indicate
11210diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11211index b4389a4..7024269 100644
11212--- a/arch/x86/include/asm/pgalloc.h
11213+++ b/arch/x86/include/asm/pgalloc.h
11214@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11215 pmd_t *pmd, pte_t *pte)
11216 {
11217 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11218+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11219+}
11220+
11221+static inline void pmd_populate_user(struct mm_struct *mm,
11222+ pmd_t *pmd, pte_t *pte)
11223+{
11224+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11225 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11226 }
11227
11228@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11229
11230 #ifdef CONFIG_X86_PAE
11231 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11232+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11233+{
11234+ pud_populate(mm, pudp, pmd);
11235+}
11236 #else /* !CONFIG_X86_PAE */
11237 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11238 {
11239 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11240 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11241 }
11242+
11243+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11244+{
11245+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11246+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11247+}
11248 #endif /* CONFIG_X86_PAE */
11249
11250 #if PAGETABLE_LEVELS > 3
11251@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11252 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11253 }
11254
11255+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11256+{
11257+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11258+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11259+}
11260+
11261 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11262 {
11263 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11264diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11265index 98391db..8f6984e 100644
11266--- a/arch/x86/include/asm/pgtable-2level.h
11267+++ b/arch/x86/include/asm/pgtable-2level.h
11268@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11269
11270 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11271 {
11272+ pax_open_kernel();
11273 *pmdp = pmd;
11274+ pax_close_kernel();
11275 }
11276
11277 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11278diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11279index effff47..bbb8295 100644
11280--- a/arch/x86/include/asm/pgtable-3level.h
11281+++ b/arch/x86/include/asm/pgtable-3level.h
11282@@ -31,6 +31,56 @@ static inline void native_set_pte(pte_t *ptep, pte_t pte)
11283 ptep->pte_low = pte.pte_low;
11284 }
11285
11286+#define __HAVE_ARCH_READ_PMD_ATOMIC
11287+/*
11288+ * pte_offset_map_lock on 32bit PAE kernels was reading the pmd_t with
11289+ * a "*pmdp" dereference done by gcc. Problem is, in certain places
11290+ * where pte_offset_map_lock is called, concurrent page faults are
11291+ * allowed, if the mmap_sem is hold for reading. An example is mincore
11292+ * vs page faults vs MADV_DONTNEED. On the page fault side
11293+ * pmd_populate rightfully does a set_64bit, but if we're reading the
11294+ * pmd_t with a "*pmdp" on the mincore side, a SMP race can happen
11295+ * because gcc will not read the 64bit of the pmd atomically. To fix
11296+ * this all places running pmd_offset_map_lock() while holding the
11297+ * mmap_sem in read mode, shall read the pmdp pointer using this
11298+ * function to know if the pmd is null nor not, and in turn to know if
11299+ * they can run pmd_offset_map_lock or pmd_trans_huge or other pmd
11300+ * operations.
11301+ *
11302+ * Without THP if the mmap_sem is hold for reading, the
11303+ * pmd can only transition from null to not null while read_pmd_atomic runs.
11304+ * So there's no need of literally reading it atomically.
11305+ *
11306+ * With THP if the mmap_sem is hold for reading, the pmd can become
11307+ * THP or null or point to a pte (and in turn become "stable") at any
11308+ * time under read_pmd_atomic, so it's mandatory to read it atomically
11309+ * with cmpxchg8b.
11310+ */
11311+#ifndef CONFIG_TRANSPARENT_HUGEPAGE
11312+static inline pmd_t read_pmd_atomic(pmd_t *pmdp)
11313+{
11314+ pmdval_t ret;
11315+ u32 *tmp = (u32 *)pmdp;
11316+
11317+ ret = (pmdval_t) (*tmp);
11318+ if (ret) {
11319+ /*
11320+ * If the low part is null, we must not read the high part
11321+ * or we can end up with a partial pmd.
11322+ */
11323+ smp_rmb();
11324+ ret |= ((pmdval_t)*(tmp + 1)) << 32;
11325+ }
11326+
11327+ return __pmd(ret);
11328+}
11329+#else /* CONFIG_TRANSPARENT_HUGEPAGE */
11330+static inline pmd_t read_pmd_atomic(pmd_t *pmdp)
11331+{
11332+ return __pmd(atomic64_read((atomic64_t *)pmdp));
11333+}
11334+#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
11335+
11336 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11337 {
11338 set_64bit((unsigned long long *)(ptep), native_pte_val(pte));
11339@@ -38,12 +88,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11340
11341 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11342 {
11343+ pax_open_kernel();
11344 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11345+ pax_close_kernel();
11346 }
11347
11348 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11349 {
11350+ pax_open_kernel();
11351 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11352+ pax_close_kernel();
11353 }
11354
11355 /*
11356diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11357index 49afb3f..91a8c63 100644
11358--- a/arch/x86/include/asm/pgtable.h
11359+++ b/arch/x86/include/asm/pgtable.h
11360@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11361
11362 #ifndef __PAGETABLE_PUD_FOLDED
11363 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11364+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11365 #define pgd_clear(pgd) native_pgd_clear(pgd)
11366 #endif
11367
11368@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11369
11370 #define arch_end_context_switch(prev) do {} while(0)
11371
11372+#define pax_open_kernel() native_pax_open_kernel()
11373+#define pax_close_kernel() native_pax_close_kernel()
11374 #endif /* CONFIG_PARAVIRT */
11375
11376+#define __HAVE_ARCH_PAX_OPEN_KERNEL
11377+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11378+
11379+#ifdef CONFIG_PAX_KERNEXEC
11380+static inline unsigned long native_pax_open_kernel(void)
11381+{
11382+ unsigned long cr0;
11383+
11384+ preempt_disable();
11385+ barrier();
11386+ cr0 = read_cr0() ^ X86_CR0_WP;
11387+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
11388+ write_cr0(cr0);
11389+ return cr0 ^ X86_CR0_WP;
11390+}
11391+
11392+static inline unsigned long native_pax_close_kernel(void)
11393+{
11394+ unsigned long cr0;
11395+
11396+ cr0 = read_cr0() ^ X86_CR0_WP;
11397+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11398+ write_cr0(cr0);
11399+ barrier();
11400+ preempt_enable_no_resched();
11401+ return cr0 ^ X86_CR0_WP;
11402+}
11403+#else
11404+static inline unsigned long native_pax_open_kernel(void) { return 0; }
11405+static inline unsigned long native_pax_close_kernel(void) { return 0; }
11406+#endif
11407+
11408 /*
11409 * The following only work if pte_present() is true.
11410 * Undefined behaviour if not..
11411 */
11412+static inline int pte_user(pte_t pte)
11413+{
11414+ return pte_val(pte) & _PAGE_USER;
11415+}
11416+
11417 static inline int pte_dirty(pte_t pte)
11418 {
11419 return pte_flags(pte) & _PAGE_DIRTY;
11420@@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11421 return pte_clear_flags(pte, _PAGE_RW);
11422 }
11423
11424+static inline pte_t pte_mkread(pte_t pte)
11425+{
11426+ return __pte(pte_val(pte) | _PAGE_USER);
11427+}
11428+
11429 static inline pte_t pte_mkexec(pte_t pte)
11430 {
11431- return pte_clear_flags(pte, _PAGE_NX);
11432+#ifdef CONFIG_X86_PAE
11433+ if (__supported_pte_mask & _PAGE_NX)
11434+ return pte_clear_flags(pte, _PAGE_NX);
11435+ else
11436+#endif
11437+ return pte_set_flags(pte, _PAGE_USER);
11438+}
11439+
11440+static inline pte_t pte_exprotect(pte_t pte)
11441+{
11442+#ifdef CONFIG_X86_PAE
11443+ if (__supported_pte_mask & _PAGE_NX)
11444+ return pte_set_flags(pte, _PAGE_NX);
11445+ else
11446+#endif
11447+ return pte_clear_flags(pte, _PAGE_USER);
11448 }
11449
11450 static inline pte_t pte_mkdirty(pte_t pte)
11451@@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11452 #endif
11453
11454 #ifndef __ASSEMBLY__
11455+
11456+#ifdef CONFIG_PAX_PER_CPU_PGD
11457+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11458+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11459+{
11460+ return cpu_pgd[cpu];
11461+}
11462+#endif
11463+
11464 #include <linux/mm_types.h>
11465
11466 static inline int pte_none(pte_t pte)
11467@@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11468
11469 static inline int pgd_bad(pgd_t pgd)
11470 {
11471- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11472+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11473 }
11474
11475 static inline int pgd_none(pgd_t pgd)
11476@@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
11477 * pgd_offset() returns a (pgd_t *)
11478 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11479 */
11480-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11481+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11482+
11483+#ifdef CONFIG_PAX_PER_CPU_PGD
11484+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11485+#endif
11486+
11487 /*
11488 * a shortcut which implies the use of the kernel's pgd, instead
11489 * of a process's
11490@@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
11491 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11492 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11493
11494+#ifdef CONFIG_X86_32
11495+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11496+#else
11497+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11498+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11499+
11500+#ifdef CONFIG_PAX_MEMORY_UDEREF
11501+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11502+#else
11503+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11504+#endif
11505+
11506+#endif
11507+
11508 #ifndef __ASSEMBLY__
11509
11510 extern int direct_gbpages;
11511@@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11512 * dst and src can be on the same page, but the range must not overlap,
11513 * and must not cross a page boundary.
11514 */
11515-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11516+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11517 {
11518- memcpy(dst, src, count * sizeof(pgd_t));
11519+ pax_open_kernel();
11520+ while (count--)
11521+ *dst++ = *src++;
11522+ pax_close_kernel();
11523 }
11524
11525+#ifdef CONFIG_PAX_PER_CPU_PGD
11526+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11527+#endif
11528+
11529+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11530+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11531+#else
11532+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11533+#endif
11534
11535 #include <asm-generic/pgtable.h>
11536 #endif /* __ASSEMBLY__ */
11537diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11538index 0c92113..34a77c6 100644
11539--- a/arch/x86/include/asm/pgtable_32.h
11540+++ b/arch/x86/include/asm/pgtable_32.h
11541@@ -25,9 +25,6 @@
11542 struct mm_struct;
11543 struct vm_area_struct;
11544
11545-extern pgd_t swapper_pg_dir[1024];
11546-extern pgd_t initial_page_table[1024];
11547-
11548 static inline void pgtable_cache_init(void) { }
11549 static inline void check_pgt_cache(void) { }
11550 void paging_init(void);
11551@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11552 # include <asm/pgtable-2level.h>
11553 #endif
11554
11555+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11556+extern pgd_t initial_page_table[PTRS_PER_PGD];
11557+#ifdef CONFIG_X86_PAE
11558+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11559+#endif
11560+
11561 #if defined(CONFIG_HIGHPTE)
11562 #define pte_offset_map(dir, address) \
11563 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11564@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11565 /* Clear a kernel PTE and flush it from the TLB */
11566 #define kpte_clear_flush(ptep, vaddr) \
11567 do { \
11568+ pax_open_kernel(); \
11569 pte_clear(&init_mm, (vaddr), (ptep)); \
11570+ pax_close_kernel(); \
11571 __flush_tlb_one((vaddr)); \
11572 } while (0)
11573
11574@@ -74,6 +79,9 @@ do { \
11575
11576 #endif /* !__ASSEMBLY__ */
11577
11578+#define HAVE_ARCH_UNMAPPED_AREA
11579+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11580+
11581 /*
11582 * kern_addr_valid() is (1) for FLATMEM and (0) for
11583 * SPARSEMEM and DISCONTIGMEM
11584diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11585index ed5903b..c7fe163 100644
11586--- a/arch/x86/include/asm/pgtable_32_types.h
11587+++ b/arch/x86/include/asm/pgtable_32_types.h
11588@@ -8,7 +8,7 @@
11589 */
11590 #ifdef CONFIG_X86_PAE
11591 # include <asm/pgtable-3level_types.h>
11592-# define PMD_SIZE (1UL << PMD_SHIFT)
11593+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11594 # define PMD_MASK (~(PMD_SIZE - 1))
11595 #else
11596 # include <asm/pgtable-2level_types.h>
11597@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11598 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11599 #endif
11600
11601+#ifdef CONFIG_PAX_KERNEXEC
11602+#ifndef __ASSEMBLY__
11603+extern unsigned char MODULES_EXEC_VADDR[];
11604+extern unsigned char MODULES_EXEC_END[];
11605+#endif
11606+#include <asm/boot.h>
11607+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11608+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11609+#else
11610+#define ktla_ktva(addr) (addr)
11611+#define ktva_ktla(addr) (addr)
11612+#endif
11613+
11614 #define MODULES_VADDR VMALLOC_START
11615 #define MODULES_END VMALLOC_END
11616 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11617diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11618index 975f709..9f779c9 100644
11619--- a/arch/x86/include/asm/pgtable_64.h
11620+++ b/arch/x86/include/asm/pgtable_64.h
11621@@ -16,10 +16,14 @@
11622
11623 extern pud_t level3_kernel_pgt[512];
11624 extern pud_t level3_ident_pgt[512];
11625+extern pud_t level3_vmalloc_start_pgt[512];
11626+extern pud_t level3_vmalloc_end_pgt[512];
11627+extern pud_t level3_vmemmap_pgt[512];
11628+extern pud_t level2_vmemmap_pgt[512];
11629 extern pmd_t level2_kernel_pgt[512];
11630 extern pmd_t level2_fixmap_pgt[512];
11631-extern pmd_t level2_ident_pgt[512];
11632-extern pgd_t init_level4_pgt[];
11633+extern pmd_t level2_ident_pgt[512*2];
11634+extern pgd_t init_level4_pgt[512];
11635
11636 #define swapper_pg_dir init_level4_pgt
11637
11638@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11639
11640 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11641 {
11642+ pax_open_kernel();
11643 *pmdp = pmd;
11644+ pax_close_kernel();
11645 }
11646
11647 static inline void native_pmd_clear(pmd_t *pmd)
11648@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11649
11650 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11651 {
11652+ pax_open_kernel();
11653 *pudp = pud;
11654+ pax_close_kernel();
11655 }
11656
11657 static inline void native_pud_clear(pud_t *pud)
11658@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11659
11660 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11661 {
11662+ pax_open_kernel();
11663+ *pgdp = pgd;
11664+ pax_close_kernel();
11665+}
11666+
11667+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11668+{
11669 *pgdp = pgd;
11670 }
11671
11672diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11673index 766ea16..5b96cb3 100644
11674--- a/arch/x86/include/asm/pgtable_64_types.h
11675+++ b/arch/x86/include/asm/pgtable_64_types.h
11676@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11677 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11678 #define MODULES_END _AC(0xffffffffff000000, UL)
11679 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11680+#define MODULES_EXEC_VADDR MODULES_VADDR
11681+#define MODULES_EXEC_END MODULES_END
11682+
11683+#define ktla_ktva(addr) (addr)
11684+#define ktva_ktla(addr) (addr)
11685
11686 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11687diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11688index 013286a..8b42f4f 100644
11689--- a/arch/x86/include/asm/pgtable_types.h
11690+++ b/arch/x86/include/asm/pgtable_types.h
11691@@ -16,13 +16,12 @@
11692 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11693 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11694 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11695-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11696+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11697 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11698 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11699 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11700-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11701-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11702-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11703+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11704+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11705 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11706
11707 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11708@@ -40,7 +39,6 @@
11709 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11710 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11711 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11712-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11713 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11714 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11715 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11716@@ -57,8 +55,10 @@
11717
11718 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11719 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11720-#else
11721+#elif defined(CONFIG_KMEMCHECK)
11722 #define _PAGE_NX (_AT(pteval_t, 0))
11723+#else
11724+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11725 #endif
11726
11727 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11728@@ -96,6 +96,9 @@
11729 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11730 _PAGE_ACCESSED)
11731
11732+#define PAGE_READONLY_NOEXEC PAGE_READONLY
11733+#define PAGE_SHARED_NOEXEC PAGE_SHARED
11734+
11735 #define __PAGE_KERNEL_EXEC \
11736 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11737 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11738@@ -106,7 +109,7 @@
11739 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11740 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11741 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11742-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11743+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11744 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11745 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11746 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11747@@ -168,8 +171,8 @@
11748 * bits are combined, this will alow user to access the high address mapped
11749 * VDSO in the presence of CONFIG_COMPAT_VDSO
11750 */
11751-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11752-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11753+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11754+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11755 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11756 #endif
11757
11758@@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11759 {
11760 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11761 }
11762+#endif
11763
11764+#if PAGETABLE_LEVELS == 3
11765+#include <asm-generic/pgtable-nopud.h>
11766+#endif
11767+
11768+#if PAGETABLE_LEVELS == 2
11769+#include <asm-generic/pgtable-nopmd.h>
11770+#endif
11771+
11772+#ifndef __ASSEMBLY__
11773 #if PAGETABLE_LEVELS > 3
11774 typedef struct { pudval_t pud; } pud_t;
11775
11776@@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11777 return pud.pud;
11778 }
11779 #else
11780-#include <asm-generic/pgtable-nopud.h>
11781-
11782 static inline pudval_t native_pud_val(pud_t pud)
11783 {
11784 return native_pgd_val(pud.pgd);
11785@@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11786 return pmd.pmd;
11787 }
11788 #else
11789-#include <asm-generic/pgtable-nopmd.h>
11790-
11791 static inline pmdval_t native_pmd_val(pmd_t pmd)
11792 {
11793 return native_pgd_val(pmd.pud.pgd);
11794@@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11795
11796 extern pteval_t __supported_pte_mask;
11797 extern void set_nx(void);
11798-extern int nx_enabled;
11799
11800 #define pgprot_writecombine pgprot_writecombine
11801 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11802diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11803index 4fa7dcc..764e33a 100644
11804--- a/arch/x86/include/asm/processor.h
11805+++ b/arch/x86/include/asm/processor.h
11806@@ -276,7 +276,7 @@ struct tss_struct {
11807
11808 } ____cacheline_aligned;
11809
11810-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11811+extern struct tss_struct init_tss[NR_CPUS];
11812
11813 /*
11814 * Save the original ist values for checking stack pointers during debugging
11815@@ -807,11 +807,18 @@ static inline void spin_lock_prefetch(const void *x)
11816 */
11817 #define TASK_SIZE PAGE_OFFSET
11818 #define TASK_SIZE_MAX TASK_SIZE
11819+
11820+#ifdef CONFIG_PAX_SEGMEXEC
11821+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11822+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11823+#else
11824 #define STACK_TOP TASK_SIZE
11825-#define STACK_TOP_MAX STACK_TOP
11826+#endif
11827+
11828+#define STACK_TOP_MAX TASK_SIZE
11829
11830 #define INIT_THREAD { \
11831- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11832+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11833 .vm86_info = NULL, \
11834 .sysenter_cs = __KERNEL_CS, \
11835 .io_bitmap_ptr = NULL, \
11836@@ -825,7 +832,7 @@ static inline void spin_lock_prefetch(const void *x)
11837 */
11838 #define INIT_TSS { \
11839 .x86_tss = { \
11840- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11841+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11842 .ss0 = __KERNEL_DS, \
11843 .ss1 = __KERNEL_CS, \
11844 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11845@@ -836,11 +843,7 @@ static inline void spin_lock_prefetch(const void *x)
11846 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11847
11848 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11849-#define KSTK_TOP(info) \
11850-({ \
11851- unsigned long *__ptr = (unsigned long *)(info); \
11852- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11853-})
11854+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11855
11856 /*
11857 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11858@@ -855,7 +858,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11859 #define task_pt_regs(task) \
11860 ({ \
11861 struct pt_regs *__regs__; \
11862- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11863+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11864 __regs__ - 1; \
11865 })
11866
11867@@ -865,13 +868,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11868 /*
11869 * User space process size. 47bits minus one guard page.
11870 */
11871-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11872+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11873
11874 /* This decides where the kernel will search for a free chunk of vm
11875 * space during mmap's.
11876 */
11877 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11878- 0xc0000000 : 0xFFFFe000)
11879+ 0xc0000000 : 0xFFFFf000)
11880
11881 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11882 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11883@@ -882,11 +885,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11884 #define STACK_TOP_MAX TASK_SIZE_MAX
11885
11886 #define INIT_THREAD { \
11887- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11888+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11889 }
11890
11891 #define INIT_TSS { \
11892- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11893+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11894 }
11895
11896 /*
11897@@ -914,6 +917,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11898 */
11899 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11900
11901+#ifdef CONFIG_PAX_SEGMEXEC
11902+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11903+#endif
11904+
11905 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11906
11907 /* Get/set a process' ability to use the timestamp counter instruction */
11908@@ -976,12 +983,12 @@ extern bool cpu_has_amd_erratum(const int *);
11909
11910 void cpu_idle_wait(void);
11911
11912-extern unsigned long arch_align_stack(unsigned long sp);
11913+#define arch_align_stack(x) ((x) & ~0xfUL)
11914 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11915
11916 void default_idle(void);
11917 bool set_pm_idle_to_default(void);
11918
11919-void stop_this_cpu(void *dummy);
11920+void stop_this_cpu(void *dummy) __noreturn;
11921
11922 #endif /* _ASM_X86_PROCESSOR_H */
11923diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11924index dcfde52..dbfea06 100644
11925--- a/arch/x86/include/asm/ptrace.h
11926+++ b/arch/x86/include/asm/ptrace.h
11927@@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11928 }
11929
11930 /*
11931- * user_mode_vm(regs) determines whether a register set came from user mode.
11932+ * user_mode(regs) determines whether a register set came from user mode.
11933 * This is true if V8086 mode was enabled OR if the register set was from
11934 * protected mode with RPL-3 CS value. This tricky test checks that with
11935 * one comparison. Many places in the kernel can bypass this full check
11936- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11937+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11938+ * be used.
11939 */
11940-static inline int user_mode(struct pt_regs *regs)
11941+static inline int user_mode_novm(struct pt_regs *regs)
11942 {
11943 #ifdef CONFIG_X86_32
11944 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11945 #else
11946- return !!(regs->cs & 3);
11947+ return !!(regs->cs & SEGMENT_RPL_MASK);
11948 #endif
11949 }
11950
11951-static inline int user_mode_vm(struct pt_regs *regs)
11952+static inline int user_mode(struct pt_regs *regs)
11953 {
11954 #ifdef CONFIG_X86_32
11955 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11956 USER_RPL;
11957 #else
11958- return user_mode(regs);
11959+ return user_mode_novm(regs);
11960 #endif
11961 }
11962
11963@@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11964 #ifdef CONFIG_X86_64
11965 static inline bool user_64bit_mode(struct pt_regs *regs)
11966 {
11967+ unsigned long cs = regs->cs & 0xffff;
11968 #ifndef CONFIG_PARAVIRT
11969 /*
11970 * On non-paravirt systems, this is the only long mode CPL 3
11971 * selector. We do not allow long mode selectors in the LDT.
11972 */
11973- return regs->cs == __USER_CS;
11974+ return cs == __USER_CS;
11975 #else
11976 /* Headers are too twisted for this to go in paravirt.h. */
11977- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11978+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11979 #endif
11980 }
11981 #endif
11982diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11983index 92f29706..a79cbbb 100644
11984--- a/arch/x86/include/asm/reboot.h
11985+++ b/arch/x86/include/asm/reboot.h
11986@@ -6,19 +6,19 @@
11987 struct pt_regs;
11988
11989 struct machine_ops {
11990- void (*restart)(char *cmd);
11991- void (*halt)(void);
11992- void (*power_off)(void);
11993+ void (* __noreturn restart)(char *cmd);
11994+ void (* __noreturn halt)(void);
11995+ void (* __noreturn power_off)(void);
11996 void (*shutdown)(void);
11997 void (*crash_shutdown)(struct pt_regs *);
11998- void (*emergency_restart)(void);
11999-};
12000+ void (* __noreturn emergency_restart)(void);
12001+} __no_const;
12002
12003 extern struct machine_ops machine_ops;
12004
12005 void native_machine_crash_shutdown(struct pt_regs *regs);
12006 void native_machine_shutdown(void);
12007-void machine_real_restart(unsigned int type);
12008+void machine_real_restart(unsigned int type) __noreturn;
12009 /* These must match dispatch_table in reboot_32.S */
12010 #define MRR_BIOS 0
12011 #define MRR_APM 1
12012diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12013index 2dbe4a7..ce1db00 100644
12014--- a/arch/x86/include/asm/rwsem.h
12015+++ b/arch/x86/include/asm/rwsem.h
12016@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12017 {
12018 asm volatile("# beginning down_read\n\t"
12019 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12020+
12021+#ifdef CONFIG_PAX_REFCOUNT
12022+ "jno 0f\n"
12023+ LOCK_PREFIX _ASM_DEC "(%1)\n"
12024+ "int $4\n0:\n"
12025+ _ASM_EXTABLE(0b, 0b)
12026+#endif
12027+
12028 /* adds 0x00000001 */
12029 " jns 1f\n"
12030 " call call_rwsem_down_read_failed\n"
12031@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12032 "1:\n\t"
12033 " mov %1,%2\n\t"
12034 " add %3,%2\n\t"
12035+
12036+#ifdef CONFIG_PAX_REFCOUNT
12037+ "jno 0f\n"
12038+ "sub %3,%2\n"
12039+ "int $4\n0:\n"
12040+ _ASM_EXTABLE(0b, 0b)
12041+#endif
12042+
12043 " jle 2f\n\t"
12044 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12045 " jnz 1b\n\t"
12046@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12047 long tmp;
12048 asm volatile("# beginning down_write\n\t"
12049 LOCK_PREFIX " xadd %1,(%2)\n\t"
12050+
12051+#ifdef CONFIG_PAX_REFCOUNT
12052+ "jno 0f\n"
12053+ "mov %1,(%2)\n"
12054+ "int $4\n0:\n"
12055+ _ASM_EXTABLE(0b, 0b)
12056+#endif
12057+
12058 /* adds 0xffff0001, returns the old value */
12059 " test %1,%1\n\t"
12060 /* was the count 0 before? */
12061@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12062 long tmp;
12063 asm volatile("# beginning __up_read\n\t"
12064 LOCK_PREFIX " xadd %1,(%2)\n\t"
12065+
12066+#ifdef CONFIG_PAX_REFCOUNT
12067+ "jno 0f\n"
12068+ "mov %1,(%2)\n"
12069+ "int $4\n0:\n"
12070+ _ASM_EXTABLE(0b, 0b)
12071+#endif
12072+
12073 /* subtracts 1, returns the old value */
12074 " jns 1f\n\t"
12075 " call call_rwsem_wake\n" /* expects old value in %edx */
12076@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12077 long tmp;
12078 asm volatile("# beginning __up_write\n\t"
12079 LOCK_PREFIX " xadd %1,(%2)\n\t"
12080+
12081+#ifdef CONFIG_PAX_REFCOUNT
12082+ "jno 0f\n"
12083+ "mov %1,(%2)\n"
12084+ "int $4\n0:\n"
12085+ _ASM_EXTABLE(0b, 0b)
12086+#endif
12087+
12088 /* subtracts 0xffff0001, returns the old value */
12089 " jns 1f\n\t"
12090 " call call_rwsem_wake\n" /* expects old value in %edx */
12091@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12092 {
12093 asm volatile("# beginning __downgrade_write\n\t"
12094 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12095+
12096+#ifdef CONFIG_PAX_REFCOUNT
12097+ "jno 0f\n"
12098+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12099+ "int $4\n0:\n"
12100+ _ASM_EXTABLE(0b, 0b)
12101+#endif
12102+
12103 /*
12104 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12105 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12106@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12107 */
12108 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12109 {
12110- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12111+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12112+
12113+#ifdef CONFIG_PAX_REFCOUNT
12114+ "jno 0f\n"
12115+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
12116+ "int $4\n0:\n"
12117+ _ASM_EXTABLE(0b, 0b)
12118+#endif
12119+
12120 : "+m" (sem->count)
12121 : "er" (delta));
12122 }
12123@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12124 */
12125 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12126 {
12127- return delta + xadd(&sem->count, delta);
12128+ return delta + xadd_check_overflow(&sem->count, delta);
12129 }
12130
12131 #endif /* __KERNEL__ */
12132diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12133index 1654662..5af4157 100644
12134--- a/arch/x86/include/asm/segment.h
12135+++ b/arch/x86/include/asm/segment.h
12136@@ -64,10 +64,15 @@
12137 * 26 - ESPFIX small SS
12138 * 27 - per-cpu [ offset to per-cpu data area ]
12139 * 28 - stack_canary-20 [ for stack protector ]
12140- * 29 - unused
12141- * 30 - unused
12142+ * 29 - PCI BIOS CS
12143+ * 30 - PCI BIOS DS
12144 * 31 - TSS for double fault handler
12145 */
12146+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12147+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12148+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12149+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12150+
12151 #define GDT_ENTRY_TLS_MIN 6
12152 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12153
12154@@ -79,6 +84,8 @@
12155
12156 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12157
12158+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12159+
12160 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12161
12162 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12163@@ -104,6 +111,12 @@
12164 #define __KERNEL_STACK_CANARY 0
12165 #endif
12166
12167+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12168+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12169+
12170+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12171+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12172+
12173 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12174
12175 /*
12176@@ -141,7 +154,7 @@
12177 */
12178
12179 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12180-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12181+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12182
12183
12184 #else
12185@@ -165,6 +178,8 @@
12186 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12187 #define __USER32_DS __USER_DS
12188
12189+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12190+
12191 #define GDT_ENTRY_TSS 8 /* needs two entries */
12192 #define GDT_ENTRY_LDT 10 /* needs two entries */
12193 #define GDT_ENTRY_TLS_MIN 12
12194@@ -185,6 +200,7 @@
12195 #endif
12196
12197 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12198+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12199 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12200 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12201 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12202@@ -263,7 +279,7 @@ static inline unsigned long get_limit(unsigned long segment)
12203 {
12204 unsigned long __limit;
12205 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12206- return __limit + 1;
12207+ return __limit;
12208 }
12209
12210 #endif /* !__ASSEMBLY__ */
12211diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12212index 0434c40..1714bf0 100644
12213--- a/arch/x86/include/asm/smp.h
12214+++ b/arch/x86/include/asm/smp.h
12215@@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
12216 /* cpus sharing the last level cache: */
12217 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
12218 DECLARE_PER_CPU(u16, cpu_llc_id);
12219-DECLARE_PER_CPU(int, cpu_number);
12220+DECLARE_PER_CPU(unsigned int, cpu_number);
12221
12222 static inline struct cpumask *cpu_sibling_mask(int cpu)
12223 {
12224@@ -77,7 +77,7 @@ struct smp_ops {
12225
12226 void (*send_call_func_ipi)(const struct cpumask *mask);
12227 void (*send_call_func_single_ipi)(int cpu);
12228-};
12229+} __no_const;
12230
12231 /* Globals due to paravirt */
12232 extern void set_cpu_sibling_map(int cpu);
12233@@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12234 extern int safe_smp_processor_id(void);
12235
12236 #elif defined(CONFIG_X86_64_SMP)
12237-#define raw_smp_processor_id() (percpu_read(cpu_number))
12238-
12239-#define stack_smp_processor_id() \
12240-({ \
12241- struct thread_info *ti; \
12242- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12243- ti->cpu; \
12244-})
12245+#define raw_smp_processor_id() (percpu_read(cpu_number))
12246+#define stack_smp_processor_id() raw_smp_processor_id()
12247 #define safe_smp_processor_id() smp_processor_id()
12248
12249 #endif
12250diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12251index 76bfa2c..12d3fe7 100644
12252--- a/arch/x86/include/asm/spinlock.h
12253+++ b/arch/x86/include/asm/spinlock.h
12254@@ -175,6 +175,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12255 static inline void arch_read_lock(arch_rwlock_t *rw)
12256 {
12257 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12258+
12259+#ifdef CONFIG_PAX_REFCOUNT
12260+ "jno 0f\n"
12261+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12262+ "int $4\n0:\n"
12263+ _ASM_EXTABLE(0b, 0b)
12264+#endif
12265+
12266 "jns 1f\n"
12267 "call __read_lock_failed\n\t"
12268 "1:\n"
12269@@ -184,6 +192,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12270 static inline void arch_write_lock(arch_rwlock_t *rw)
12271 {
12272 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12273+
12274+#ifdef CONFIG_PAX_REFCOUNT
12275+ "jno 0f\n"
12276+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12277+ "int $4\n0:\n"
12278+ _ASM_EXTABLE(0b, 0b)
12279+#endif
12280+
12281 "jz 1f\n"
12282 "call __write_lock_failed\n\t"
12283 "1:\n"
12284@@ -213,13 +229,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12285
12286 static inline void arch_read_unlock(arch_rwlock_t *rw)
12287 {
12288- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12289+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12290+
12291+#ifdef CONFIG_PAX_REFCOUNT
12292+ "jno 0f\n"
12293+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12294+ "int $4\n0:\n"
12295+ _ASM_EXTABLE(0b, 0b)
12296+#endif
12297+
12298 :"+m" (rw->lock) : : "memory");
12299 }
12300
12301 static inline void arch_write_unlock(arch_rwlock_t *rw)
12302 {
12303- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12304+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12305+
12306+#ifdef CONFIG_PAX_REFCOUNT
12307+ "jno 0f\n"
12308+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12309+ "int $4\n0:\n"
12310+ _ASM_EXTABLE(0b, 0b)
12311+#endif
12312+
12313 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12314 }
12315
12316diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12317index b5d9533..41655fa 100644
12318--- a/arch/x86/include/asm/stackprotector.h
12319+++ b/arch/x86/include/asm/stackprotector.h
12320@@ -47,7 +47,7 @@
12321 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12322 */
12323 #define GDT_STACK_CANARY_INIT \
12324- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12325+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12326
12327 /*
12328 * Initialize the stackprotector canary value.
12329@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12330
12331 static inline void load_stack_canary_segment(void)
12332 {
12333-#ifdef CONFIG_X86_32
12334+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12335 asm volatile ("mov %0, %%gs" : : "r" (0));
12336 #endif
12337 }
12338diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12339index 70bbe39..4ae2bd4 100644
12340--- a/arch/x86/include/asm/stacktrace.h
12341+++ b/arch/x86/include/asm/stacktrace.h
12342@@ -11,28 +11,20 @@
12343
12344 extern int kstack_depth_to_print;
12345
12346-struct thread_info;
12347+struct task_struct;
12348 struct stacktrace_ops;
12349
12350-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12351- unsigned long *stack,
12352- unsigned long bp,
12353- const struct stacktrace_ops *ops,
12354- void *data,
12355- unsigned long *end,
12356- int *graph);
12357+typedef unsigned long walk_stack_t(struct task_struct *task,
12358+ void *stack_start,
12359+ unsigned long *stack,
12360+ unsigned long bp,
12361+ const struct stacktrace_ops *ops,
12362+ void *data,
12363+ unsigned long *end,
12364+ int *graph);
12365
12366-extern unsigned long
12367-print_context_stack(struct thread_info *tinfo,
12368- unsigned long *stack, unsigned long bp,
12369- const struct stacktrace_ops *ops, void *data,
12370- unsigned long *end, int *graph);
12371-
12372-extern unsigned long
12373-print_context_stack_bp(struct thread_info *tinfo,
12374- unsigned long *stack, unsigned long bp,
12375- const struct stacktrace_ops *ops, void *data,
12376- unsigned long *end, int *graph);
12377+extern walk_stack_t print_context_stack;
12378+extern walk_stack_t print_context_stack_bp;
12379
12380 /* Generic stack tracer with callbacks */
12381
12382@@ -40,7 +32,7 @@ struct stacktrace_ops {
12383 void (*address)(void *data, unsigned long address, int reliable);
12384 /* On negative return stop dumping */
12385 int (*stack)(void *data, char *name);
12386- walk_stack_t walk_stack;
12387+ walk_stack_t *walk_stack;
12388 };
12389
12390 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12391diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12392index 4ec45b3..a4f0a8a 100644
12393--- a/arch/x86/include/asm/switch_to.h
12394+++ b/arch/x86/include/asm/switch_to.h
12395@@ -108,7 +108,7 @@ do { \
12396 "call __switch_to\n\t" \
12397 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12398 __switch_canary \
12399- "movq %P[thread_info](%%rsi),%%r8\n\t" \
12400+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12401 "movq %%rax,%%rdi\n\t" \
12402 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12403 "jnz ret_from_fork\n\t" \
12404@@ -119,7 +119,7 @@ do { \
12405 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12406 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12407 [_tif_fork] "i" (_TIF_FORK), \
12408- [thread_info] "i" (offsetof(struct task_struct, stack)), \
12409+ [thread_info] "m" (current_tinfo), \
12410 [current_task] "m" (current_task) \
12411 __switch_canary_iparam \
12412 : "memory", "cc" __EXTRA_CLOBBER)
12413diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12414index 3fda9db4..4ca1c61 100644
12415--- a/arch/x86/include/asm/sys_ia32.h
12416+++ b/arch/x86/include/asm/sys_ia32.h
12417@@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12418 struct old_sigaction32 __user *);
12419 asmlinkage long sys32_alarm(unsigned int);
12420
12421-asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12422+asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12423 asmlinkage long sys32_sysfs(int, u32, u32);
12424
12425 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12426diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12427index ad6df8c..5e0cf6e 100644
12428--- a/arch/x86/include/asm/thread_info.h
12429+++ b/arch/x86/include/asm/thread_info.h
12430@@ -10,6 +10,7 @@
12431 #include <linux/compiler.h>
12432 #include <asm/page.h>
12433 #include <asm/types.h>
12434+#include <asm/percpu.h>
12435
12436 /*
12437 * low level task data that entry.S needs immediate access to
12438@@ -24,7 +25,6 @@ struct exec_domain;
12439 #include <linux/atomic.h>
12440
12441 struct thread_info {
12442- struct task_struct *task; /* main task structure */
12443 struct exec_domain *exec_domain; /* execution domain */
12444 __u32 flags; /* low level flags */
12445 __u32 status; /* thread synchronous flags */
12446@@ -34,19 +34,13 @@ struct thread_info {
12447 mm_segment_t addr_limit;
12448 struct restart_block restart_block;
12449 void __user *sysenter_return;
12450-#ifdef CONFIG_X86_32
12451- unsigned long previous_esp; /* ESP of the previous stack in
12452- case of nested (IRQ) stacks
12453- */
12454- __u8 supervisor_stack[0];
12455-#endif
12456+ unsigned long lowest_stack;
12457 unsigned int sig_on_uaccess_error:1;
12458 unsigned int uaccess_err:1; /* uaccess failed */
12459 };
12460
12461-#define INIT_THREAD_INFO(tsk) \
12462+#define INIT_THREAD_INFO \
12463 { \
12464- .task = &tsk, \
12465 .exec_domain = &default_exec_domain, \
12466 .flags = 0, \
12467 .cpu = 0, \
12468@@ -57,7 +51,7 @@ struct thread_info {
12469 }, \
12470 }
12471
12472-#define init_thread_info (init_thread_union.thread_info)
12473+#define init_thread_info (init_thread_union.stack)
12474 #define init_stack (init_thread_union.stack)
12475
12476 #else /* !__ASSEMBLY__ */
12477@@ -97,6 +91,7 @@ struct thread_info {
12478 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12479 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12480 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12481+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12482
12483 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12484 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12485@@ -120,16 +115,18 @@ struct thread_info {
12486 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12487 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12488 #define _TIF_X32 (1 << TIF_X32)
12489+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12490
12491 /* work to do in syscall_trace_enter() */
12492 #define _TIF_WORK_SYSCALL_ENTRY \
12493 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12494- _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12495+ _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12496+ _TIF_GRSEC_SETXID)
12497
12498 /* work to do in syscall_trace_leave() */
12499 #define _TIF_WORK_SYSCALL_EXIT \
12500 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12501- _TIF_SYSCALL_TRACEPOINT)
12502+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12503
12504 /* work to do on interrupt/exception return */
12505 #define _TIF_WORK_MASK \
12506@@ -139,7 +136,8 @@ struct thread_info {
12507
12508 /* work to do on any return to user space */
12509 #define _TIF_ALLWORK_MASK \
12510- ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12511+ ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12512+ _TIF_GRSEC_SETXID)
12513
12514 /* Only used for 64 bit */
12515 #define _TIF_DO_NOTIFY_MASK \
12516@@ -173,45 +171,40 @@ struct thread_info {
12517 ret; \
12518 })
12519
12520-#ifdef CONFIG_X86_32
12521-
12522-#define STACK_WARN (THREAD_SIZE/8)
12523-/*
12524- * macros/functions for gaining access to the thread information structure
12525- *
12526- * preempt_count needs to be 1 initially, until the scheduler is functional.
12527- */
12528-#ifndef __ASSEMBLY__
12529-
12530-
12531-/* how to get the current stack pointer from C */
12532-register unsigned long current_stack_pointer asm("esp") __used;
12533-
12534-/* how to get the thread information struct from C */
12535-static inline struct thread_info *current_thread_info(void)
12536-{
12537- return (struct thread_info *)
12538- (current_stack_pointer & ~(THREAD_SIZE - 1));
12539-}
12540-
12541-#else /* !__ASSEMBLY__ */
12542-
12543+#ifdef __ASSEMBLY__
12544 /* how to get the thread information struct from ASM */
12545 #define GET_THREAD_INFO(reg) \
12546- movl $-THREAD_SIZE, reg; \
12547- andl %esp, reg
12548+ mov PER_CPU_VAR(current_tinfo), reg
12549
12550 /* use this one if reg already contains %esp */
12551-#define GET_THREAD_INFO_WITH_ESP(reg) \
12552- andl $-THREAD_SIZE, reg
12553+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12554+#else
12555+/* how to get the thread information struct from C */
12556+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12557+
12558+static __always_inline struct thread_info *current_thread_info(void)
12559+{
12560+ return percpu_read_stable(current_tinfo);
12561+}
12562+#endif
12563+
12564+#ifdef CONFIG_X86_32
12565+
12566+#define STACK_WARN (THREAD_SIZE/8)
12567+/*
12568+ * macros/functions for gaining access to the thread information structure
12569+ *
12570+ * preempt_count needs to be 1 initially, until the scheduler is functional.
12571+ */
12572+#ifndef __ASSEMBLY__
12573+
12574+/* how to get the current stack pointer from C */
12575+register unsigned long current_stack_pointer asm("esp") __used;
12576
12577 #endif
12578
12579 #else /* X86_32 */
12580
12581-#include <asm/percpu.h>
12582-#define KERNEL_STACK_OFFSET (5*8)
12583-
12584 /*
12585 * macros/functions for gaining access to the thread information structure
12586 * preempt_count needs to be 1 initially, until the scheduler is functional.
12587@@ -219,27 +212,8 @@ static inline struct thread_info *current_thread_info(void)
12588 #ifndef __ASSEMBLY__
12589 DECLARE_PER_CPU(unsigned long, kernel_stack);
12590
12591-static inline struct thread_info *current_thread_info(void)
12592-{
12593- struct thread_info *ti;
12594- ti = (void *)(percpu_read_stable(kernel_stack) +
12595- KERNEL_STACK_OFFSET - THREAD_SIZE);
12596- return ti;
12597-}
12598-
12599-#else /* !__ASSEMBLY__ */
12600-
12601-/* how to get the thread information struct from ASM */
12602-#define GET_THREAD_INFO(reg) \
12603- movq PER_CPU_VAR(kernel_stack),reg ; \
12604- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12605-
12606-/*
12607- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12608- * a certain register (to be used in assembler memory operands).
12609- */
12610-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12611-
12612+/* how to get the current stack pointer from C */
12613+register unsigned long current_stack_pointer asm("rsp") __used;
12614 #endif
12615
12616 #endif /* !X86_32 */
12617@@ -285,5 +259,16 @@ extern void arch_task_cache_init(void);
12618 extern void free_thread_info(struct thread_info *ti);
12619 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12620 #define arch_task_cache_init arch_task_cache_init
12621+
12622+#define __HAVE_THREAD_FUNCTIONS
12623+#define task_thread_info(task) (&(task)->tinfo)
12624+#define task_stack_page(task) ((task)->stack)
12625+#define setup_thread_stack(p, org) do {} while (0)
12626+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12627+
12628+#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
12629+extern struct task_struct *alloc_task_struct_node(int node);
12630+extern void free_task_struct(struct task_struct *);
12631+
12632 #endif
12633 #endif /* _ASM_X86_THREAD_INFO_H */
12634diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12635index e054459..14bc8a7 100644
12636--- a/arch/x86/include/asm/uaccess.h
12637+++ b/arch/x86/include/asm/uaccess.h
12638@@ -7,12 +7,15 @@
12639 #include <linux/compiler.h>
12640 #include <linux/thread_info.h>
12641 #include <linux/string.h>
12642+#include <linux/sched.h>
12643 #include <asm/asm.h>
12644 #include <asm/page.h>
12645
12646 #define VERIFY_READ 0
12647 #define VERIFY_WRITE 1
12648
12649+extern void check_object_size(const void *ptr, unsigned long n, bool to);
12650+
12651 /*
12652 * The fs value determines whether argument validity checking should be
12653 * performed or not. If get_fs() == USER_DS, checking is performed, with
12654@@ -28,7 +31,12 @@
12655
12656 #define get_ds() (KERNEL_DS)
12657 #define get_fs() (current_thread_info()->addr_limit)
12658+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12659+void __set_fs(mm_segment_t x);
12660+void set_fs(mm_segment_t x);
12661+#else
12662 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12663+#endif
12664
12665 #define segment_eq(a, b) ((a).seg == (b).seg)
12666
12667@@ -76,7 +84,33 @@
12668 * checks that the pointer is in the user space range - after calling
12669 * this function, memory access functions may still return -EFAULT.
12670 */
12671-#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12672+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12673+#define access_ok(type, addr, size) \
12674+({ \
12675+ long __size = size; \
12676+ unsigned long __addr = (unsigned long)addr; \
12677+ unsigned long __addr_ao = __addr & PAGE_MASK; \
12678+ unsigned long __end_ao = __addr + __size - 1; \
12679+ bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12680+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12681+ while(__addr_ao <= __end_ao) { \
12682+ char __c_ao; \
12683+ __addr_ao += PAGE_SIZE; \
12684+ if (__size > PAGE_SIZE) \
12685+ cond_resched(); \
12686+ if (__get_user(__c_ao, (char __user *)__addr)) \
12687+ break; \
12688+ if (type != VERIFY_WRITE) { \
12689+ __addr = __addr_ao; \
12690+ continue; \
12691+ } \
12692+ if (__put_user(__c_ao, (char __user *)__addr)) \
12693+ break; \
12694+ __addr = __addr_ao; \
12695+ } \
12696+ } \
12697+ __ret_ao; \
12698+})
12699
12700 /*
12701 * The exception table consists of pairs of addresses: the first is the
12702@@ -182,12 +216,20 @@ extern int __get_user_bad(void);
12703 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12704 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12705
12706-
12707+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12708+#define __copyuser_seg "gs;"
12709+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12710+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12711+#else
12712+#define __copyuser_seg
12713+#define __COPYUSER_SET_ES
12714+#define __COPYUSER_RESTORE_ES
12715+#endif
12716
12717 #ifdef CONFIG_X86_32
12718 #define __put_user_asm_u64(x, addr, err, errret) \
12719- asm volatile("1: movl %%eax,0(%2)\n" \
12720- "2: movl %%edx,4(%2)\n" \
12721+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12722+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12723 "3:\n" \
12724 ".section .fixup,\"ax\"\n" \
12725 "4: movl %3,%0\n" \
12726@@ -199,8 +241,8 @@ extern int __get_user_bad(void);
12727 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12728
12729 #define __put_user_asm_ex_u64(x, addr) \
12730- asm volatile("1: movl %%eax,0(%1)\n" \
12731- "2: movl %%edx,4(%1)\n" \
12732+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12733+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12734 "3:\n" \
12735 _ASM_EXTABLE(1b, 2b - 1b) \
12736 _ASM_EXTABLE(2b, 3b - 2b) \
12737@@ -252,7 +294,7 @@ extern void __put_user_8(void);
12738 __typeof__(*(ptr)) __pu_val; \
12739 __chk_user_ptr(ptr); \
12740 might_fault(); \
12741- __pu_val = x; \
12742+ __pu_val = (x); \
12743 switch (sizeof(*(ptr))) { \
12744 case 1: \
12745 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12746@@ -373,7 +415,7 @@ do { \
12747 } while (0)
12748
12749 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12750- asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12751+ asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12752 "2:\n" \
12753 ".section .fixup,\"ax\"\n" \
12754 "3: mov %3,%0\n" \
12755@@ -381,7 +423,7 @@ do { \
12756 " jmp 2b\n" \
12757 ".previous\n" \
12758 _ASM_EXTABLE(1b, 3b) \
12759- : "=r" (err), ltype(x) \
12760+ : "=r" (err), ltype (x) \
12761 : "m" (__m(addr)), "i" (errret), "0" (err))
12762
12763 #define __get_user_size_ex(x, ptr, size) \
12764@@ -406,7 +448,7 @@ do { \
12765 } while (0)
12766
12767 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12768- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12769+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12770 "2:\n" \
12771 _ASM_EXTABLE(1b, 2b - 1b) \
12772 : ltype(x) : "m" (__m(addr)))
12773@@ -423,13 +465,24 @@ do { \
12774 int __gu_err; \
12775 unsigned long __gu_val; \
12776 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12777- (x) = (__force __typeof__(*(ptr)))__gu_val; \
12778+ (x) = (__typeof__(*(ptr)))__gu_val; \
12779 __gu_err; \
12780 })
12781
12782 /* FIXME: this hack is definitely wrong -AK */
12783 struct __large_struct { unsigned long buf[100]; };
12784-#define __m(x) (*(struct __large_struct __user *)(x))
12785+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12786+#define ____m(x) \
12787+({ \
12788+ unsigned long ____x = (unsigned long)(x); \
12789+ if (____x < PAX_USER_SHADOW_BASE) \
12790+ ____x += PAX_USER_SHADOW_BASE; \
12791+ (void __user *)____x; \
12792+})
12793+#else
12794+#define ____m(x) (x)
12795+#endif
12796+#define __m(x) (*(struct __large_struct __user *)____m(x))
12797
12798 /*
12799 * Tell gcc we read from memory instead of writing: this is because
12800@@ -437,7 +490,7 @@ struct __large_struct { unsigned long buf[100]; };
12801 * aliasing issues.
12802 */
12803 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12804- asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12805+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12806 "2:\n" \
12807 ".section .fixup,\"ax\"\n" \
12808 "3: mov %3,%0\n" \
12809@@ -445,10 +498,10 @@ struct __large_struct { unsigned long buf[100]; };
12810 ".previous\n" \
12811 _ASM_EXTABLE(1b, 3b) \
12812 : "=r"(err) \
12813- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12814+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12815
12816 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12817- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12818+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12819 "2:\n" \
12820 _ASM_EXTABLE(1b, 2b - 1b) \
12821 : : ltype(x), "m" (__m(addr)))
12822@@ -487,8 +540,12 @@ struct __large_struct { unsigned long buf[100]; };
12823 * On error, the variable @x is set to zero.
12824 */
12825
12826+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12827+#define __get_user(x, ptr) get_user((x), (ptr))
12828+#else
12829 #define __get_user(x, ptr) \
12830 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12831+#endif
12832
12833 /**
12834 * __put_user: - Write a simple value into user space, with less checking.
12835@@ -510,8 +567,12 @@ struct __large_struct { unsigned long buf[100]; };
12836 * Returns zero on success, or -EFAULT on error.
12837 */
12838
12839+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12840+#define __put_user(x, ptr) put_user((x), (ptr))
12841+#else
12842 #define __put_user(x, ptr) \
12843 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12844+#endif
12845
12846 #define __get_user_unaligned __get_user
12847 #define __put_user_unaligned __put_user
12848@@ -529,7 +590,7 @@ struct __large_struct { unsigned long buf[100]; };
12849 #define get_user_ex(x, ptr) do { \
12850 unsigned long __gue_val; \
12851 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12852- (x) = (__force __typeof__(*(ptr)))__gue_val; \
12853+ (x) = (__typeof__(*(ptr)))__gue_val; \
12854 } while (0)
12855
12856 #ifdef CONFIG_X86_WP_WORKS_OK
12857diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12858index 8084bc7..3d6ec37 100644
12859--- a/arch/x86/include/asm/uaccess_32.h
12860+++ b/arch/x86/include/asm/uaccess_32.h
12861@@ -11,15 +11,15 @@
12862 #include <asm/page.h>
12863
12864 unsigned long __must_check __copy_to_user_ll
12865- (void __user *to, const void *from, unsigned long n);
12866+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12867 unsigned long __must_check __copy_from_user_ll
12868- (void *to, const void __user *from, unsigned long n);
12869+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12870 unsigned long __must_check __copy_from_user_ll_nozero
12871- (void *to, const void __user *from, unsigned long n);
12872+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12873 unsigned long __must_check __copy_from_user_ll_nocache
12874- (void *to, const void __user *from, unsigned long n);
12875+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12876 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12877- (void *to, const void __user *from, unsigned long n);
12878+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12879
12880 /**
12881 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12882@@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12883 static __always_inline unsigned long __must_check
12884 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12885 {
12886+ if ((long)n < 0)
12887+ return n;
12888+
12889 if (__builtin_constant_p(n)) {
12890 unsigned long ret;
12891
12892@@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12893 return ret;
12894 }
12895 }
12896+ if (!__builtin_constant_p(n))
12897+ check_object_size(from, n, true);
12898 return __copy_to_user_ll(to, from, n);
12899 }
12900
12901@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12902 __copy_to_user(void __user *to, const void *from, unsigned long n)
12903 {
12904 might_fault();
12905+
12906 return __copy_to_user_inatomic(to, from, n);
12907 }
12908
12909 static __always_inline unsigned long
12910 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12911 {
12912+ if ((long)n < 0)
12913+ return n;
12914+
12915 /* Avoid zeroing the tail if the copy fails..
12916 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12917 * but as the zeroing behaviour is only significant when n is not
12918@@ -137,6 +146,10 @@ static __always_inline unsigned long
12919 __copy_from_user(void *to, const void __user *from, unsigned long n)
12920 {
12921 might_fault();
12922+
12923+ if ((long)n < 0)
12924+ return n;
12925+
12926 if (__builtin_constant_p(n)) {
12927 unsigned long ret;
12928
12929@@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12930 return ret;
12931 }
12932 }
12933+ if (!__builtin_constant_p(n))
12934+ check_object_size(to, n, false);
12935 return __copy_from_user_ll(to, from, n);
12936 }
12937
12938@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12939 const void __user *from, unsigned long n)
12940 {
12941 might_fault();
12942+
12943+ if ((long)n < 0)
12944+ return n;
12945+
12946 if (__builtin_constant_p(n)) {
12947 unsigned long ret;
12948
12949@@ -181,15 +200,19 @@ static __always_inline unsigned long
12950 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12951 unsigned long n)
12952 {
12953- return __copy_from_user_ll_nocache_nozero(to, from, n);
12954+ if ((long)n < 0)
12955+ return n;
12956+
12957+ return __copy_from_user_ll_nocache_nozero(to, from, n);
12958 }
12959
12960-unsigned long __must_check copy_to_user(void __user *to,
12961- const void *from, unsigned long n);
12962-unsigned long __must_check _copy_from_user(void *to,
12963- const void __user *from,
12964- unsigned long n);
12965-
12966+extern void copy_to_user_overflow(void)
12967+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12968+ __compiletime_error("copy_to_user() buffer size is not provably correct")
12969+#else
12970+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
12971+#endif
12972+;
12973
12974 extern void copy_from_user_overflow(void)
12975 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12976@@ -199,17 +222,61 @@ extern void copy_from_user_overflow(void)
12977 #endif
12978 ;
12979
12980-static inline unsigned long __must_check copy_from_user(void *to,
12981- const void __user *from,
12982- unsigned long n)
12983+/**
12984+ * copy_to_user: - Copy a block of data into user space.
12985+ * @to: Destination address, in user space.
12986+ * @from: Source address, in kernel space.
12987+ * @n: Number of bytes to copy.
12988+ *
12989+ * Context: User context only. This function may sleep.
12990+ *
12991+ * Copy data from kernel space to user space.
12992+ *
12993+ * Returns number of bytes that could not be copied.
12994+ * On success, this will be zero.
12995+ */
12996+static inline unsigned long __must_check
12997+copy_to_user(void __user *to, const void *from, unsigned long n)
12998 {
12999- int sz = __compiletime_object_size(to);
13000+ size_t sz = __compiletime_object_size(from);
13001
13002- if (likely(sz == -1 || sz >= n))
13003- n = _copy_from_user(to, from, n);
13004- else
13005+ if (unlikely(sz != (size_t)-1 && sz < n))
13006+ copy_to_user_overflow();
13007+ else if (access_ok(VERIFY_WRITE, to, n))
13008+ n = __copy_to_user(to, from, n);
13009+ return n;
13010+}
13011+
13012+/**
13013+ * copy_from_user: - Copy a block of data from user space.
13014+ * @to: Destination address, in kernel space.
13015+ * @from: Source address, in user space.
13016+ * @n: Number of bytes to copy.
13017+ *
13018+ * Context: User context only. This function may sleep.
13019+ *
13020+ * Copy data from user space to kernel space.
13021+ *
13022+ * Returns number of bytes that could not be copied.
13023+ * On success, this will be zero.
13024+ *
13025+ * If some data could not be copied, this function will pad the copied
13026+ * data to the requested size using zero bytes.
13027+ */
13028+static inline unsigned long __must_check
13029+copy_from_user(void *to, const void __user *from, unsigned long n)
13030+{
13031+ size_t sz = __compiletime_object_size(to);
13032+
13033+ if (unlikely(sz != (size_t)-1 && sz < n))
13034 copy_from_user_overflow();
13035-
13036+ else if (access_ok(VERIFY_READ, from, n))
13037+ n = __copy_from_user(to, from, n);
13038+ else if ((long)n > 0) {
13039+ if (!__builtin_constant_p(n))
13040+ check_object_size(to, n, false);
13041+ memset(to, 0, n);
13042+ }
13043 return n;
13044 }
13045
13046@@ -230,7 +297,7 @@ static inline unsigned long __must_check copy_from_user(void *to,
13047 #define strlen_user(str) strnlen_user(str, LONG_MAX)
13048
13049 long strnlen_user(const char __user *str, long n);
13050-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13051-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13052+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13053+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13054
13055 #endif /* _ASM_X86_UACCESS_32_H */
13056diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13057index fcd4b6f..ef04f8f 100644
13058--- a/arch/x86/include/asm/uaccess_64.h
13059+++ b/arch/x86/include/asm/uaccess_64.h
13060@@ -10,6 +10,9 @@
13061 #include <asm/alternative.h>
13062 #include <asm/cpufeature.h>
13063 #include <asm/page.h>
13064+#include <asm/pgtable.h>
13065+
13066+#define set_fs(x) (current_thread_info()->addr_limit = (x))
13067
13068 /*
13069 * Copy To/From Userspace
13070@@ -17,12 +20,14 @@
13071
13072 /* Handles exceptions in both to and from, but doesn't do access_ok */
13073 __must_check unsigned long
13074-copy_user_generic_string(void *to, const void *from, unsigned len);
13075+copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
13076 __must_check unsigned long
13077-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13078+copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
13079
13080 static __always_inline __must_check unsigned long
13081-copy_user_generic(void *to, const void *from, unsigned len)
13082+copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
13083+static __always_inline __must_check unsigned long
13084+copy_user_generic(void *to, const void *from, unsigned long len)
13085 {
13086 unsigned ret;
13087
13088@@ -32,142 +37,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13089 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13090 "=d" (len)),
13091 "1" (to), "2" (from), "3" (len)
13092- : "memory", "rcx", "r8", "r9", "r10", "r11");
13093+ : "memory", "rcx", "r8", "r9", "r11");
13094 return ret;
13095 }
13096
13097+static __always_inline __must_check unsigned long
13098+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13099+static __always_inline __must_check unsigned long
13100+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13101 __must_check unsigned long
13102-_copy_to_user(void __user *to, const void *from, unsigned len);
13103-__must_check unsigned long
13104-_copy_from_user(void *to, const void __user *from, unsigned len);
13105-__must_check unsigned long
13106-copy_in_user(void __user *to, const void __user *from, unsigned len);
13107+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13108+
13109+extern void copy_to_user_overflow(void)
13110+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13111+ __compiletime_error("copy_to_user() buffer size is not provably correct")
13112+#else
13113+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
13114+#endif
13115+;
13116+
13117+extern void copy_from_user_overflow(void)
13118+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13119+ __compiletime_error("copy_from_user() buffer size is not provably correct")
13120+#else
13121+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
13122+#endif
13123+;
13124
13125 static inline unsigned long __must_check copy_from_user(void *to,
13126 const void __user *from,
13127 unsigned long n)
13128 {
13129- int sz = __compiletime_object_size(to);
13130-
13131 might_fault();
13132- if (likely(sz == -1 || sz >= n))
13133- n = _copy_from_user(to, from, n);
13134-#ifdef CONFIG_DEBUG_VM
13135- else
13136- WARN(1, "Buffer overflow detected!\n");
13137-#endif
13138+
13139+ if (access_ok(VERIFY_READ, from, n))
13140+ n = __copy_from_user(to, from, n);
13141+ else if (n < INT_MAX) {
13142+ if (!__builtin_constant_p(n))
13143+ check_object_size(to, n, false);
13144+ memset(to, 0, n);
13145+ }
13146 return n;
13147 }
13148
13149 static __always_inline __must_check
13150-int copy_to_user(void __user *dst, const void *src, unsigned size)
13151+int copy_to_user(void __user *dst, const void *src, unsigned long size)
13152 {
13153 might_fault();
13154
13155- return _copy_to_user(dst, src, size);
13156+ if (access_ok(VERIFY_WRITE, dst, size))
13157+ size = __copy_to_user(dst, src, size);
13158+ return size;
13159 }
13160
13161 static __always_inline __must_check
13162-int __copy_from_user(void *dst, const void __user *src, unsigned size)
13163+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13164 {
13165- int ret = 0;
13166+ size_t sz = __compiletime_object_size(dst);
13167+ unsigned ret = 0;
13168
13169 might_fault();
13170- if (!__builtin_constant_p(size))
13171- return copy_user_generic(dst, (__force void *)src, size);
13172+
13173+ if (size > INT_MAX)
13174+ return size;
13175+
13176+#ifdef CONFIG_PAX_MEMORY_UDEREF
13177+ if (!__access_ok(VERIFY_READ, src, size))
13178+ return size;
13179+#endif
13180+
13181+ if (unlikely(sz != (size_t)-1 && sz < size)) {
13182+ copy_from_user_overflow();
13183+ return size;
13184+ }
13185+
13186+ if (!__builtin_constant_p(size)) {
13187+ check_object_size(dst, size, false);
13188+
13189+#ifdef CONFIG_PAX_MEMORY_UDEREF
13190+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13191+ src += PAX_USER_SHADOW_BASE;
13192+#endif
13193+
13194+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13195+ }
13196 switch (size) {
13197- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13198+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13199 ret, "b", "b", "=q", 1);
13200 return ret;
13201- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13202+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13203 ret, "w", "w", "=r", 2);
13204 return ret;
13205- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13206+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13207 ret, "l", "k", "=r", 4);
13208 return ret;
13209- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13210+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13211 ret, "q", "", "=r", 8);
13212 return ret;
13213 case 10:
13214- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13215+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13216 ret, "q", "", "=r", 10);
13217 if (unlikely(ret))
13218 return ret;
13219 __get_user_asm(*(u16 *)(8 + (char *)dst),
13220- (u16 __user *)(8 + (char __user *)src),
13221+ (const u16 __user *)(8 + (const char __user *)src),
13222 ret, "w", "w", "=r", 2);
13223 return ret;
13224 case 16:
13225- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13226+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13227 ret, "q", "", "=r", 16);
13228 if (unlikely(ret))
13229 return ret;
13230 __get_user_asm(*(u64 *)(8 + (char *)dst),
13231- (u64 __user *)(8 + (char __user *)src),
13232+ (const u64 __user *)(8 + (const char __user *)src),
13233 ret, "q", "", "=r", 8);
13234 return ret;
13235 default:
13236- return copy_user_generic(dst, (__force void *)src, size);
13237+
13238+#ifdef CONFIG_PAX_MEMORY_UDEREF
13239+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13240+ src += PAX_USER_SHADOW_BASE;
13241+#endif
13242+
13243+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13244 }
13245 }
13246
13247 static __always_inline __must_check
13248-int __copy_to_user(void __user *dst, const void *src, unsigned size)
13249+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13250 {
13251- int ret = 0;
13252+ size_t sz = __compiletime_object_size(src);
13253+ unsigned ret = 0;
13254
13255 might_fault();
13256- if (!__builtin_constant_p(size))
13257- return copy_user_generic((__force void *)dst, src, size);
13258+
13259+ if (size > INT_MAX)
13260+ return size;
13261+
13262+#ifdef CONFIG_PAX_MEMORY_UDEREF
13263+ if (!__access_ok(VERIFY_WRITE, dst, size))
13264+ return size;
13265+#endif
13266+
13267+ if (unlikely(sz != (size_t)-1 && sz < size)) {
13268+ copy_to_user_overflow();
13269+ return size;
13270+ }
13271+
13272+ if (!__builtin_constant_p(size)) {
13273+ check_object_size(src, size, true);
13274+
13275+#ifdef CONFIG_PAX_MEMORY_UDEREF
13276+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13277+ dst += PAX_USER_SHADOW_BASE;
13278+#endif
13279+
13280+ return copy_user_generic((__force_kernel void *)dst, src, size);
13281+ }
13282 switch (size) {
13283- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13284+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13285 ret, "b", "b", "iq", 1);
13286 return ret;
13287- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13288+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13289 ret, "w", "w", "ir", 2);
13290 return ret;
13291- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13292+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13293 ret, "l", "k", "ir", 4);
13294 return ret;
13295- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13296+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13297 ret, "q", "", "er", 8);
13298 return ret;
13299 case 10:
13300- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13301+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13302 ret, "q", "", "er", 10);
13303 if (unlikely(ret))
13304 return ret;
13305 asm("":::"memory");
13306- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13307+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13308 ret, "w", "w", "ir", 2);
13309 return ret;
13310 case 16:
13311- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13312+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13313 ret, "q", "", "er", 16);
13314 if (unlikely(ret))
13315 return ret;
13316 asm("":::"memory");
13317- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13318+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13319 ret, "q", "", "er", 8);
13320 return ret;
13321 default:
13322- return copy_user_generic((__force void *)dst, src, size);
13323+
13324+#ifdef CONFIG_PAX_MEMORY_UDEREF
13325+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13326+ dst += PAX_USER_SHADOW_BASE;
13327+#endif
13328+
13329+ return copy_user_generic((__force_kernel void *)dst, src, size);
13330 }
13331 }
13332
13333 static __always_inline __must_check
13334-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13335+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13336 {
13337- int ret = 0;
13338+ unsigned ret = 0;
13339
13340 might_fault();
13341- if (!__builtin_constant_p(size))
13342- return copy_user_generic((__force void *)dst,
13343- (__force void *)src, size);
13344+
13345+ if (size > INT_MAX)
13346+ return size;
13347+
13348+#ifdef CONFIG_PAX_MEMORY_UDEREF
13349+ if (!__access_ok(VERIFY_READ, src, size))
13350+ return size;
13351+ if (!__access_ok(VERIFY_WRITE, dst, size))
13352+ return size;
13353+#endif
13354+
13355+ if (!__builtin_constant_p(size)) {
13356+
13357+#ifdef CONFIG_PAX_MEMORY_UDEREF
13358+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13359+ src += PAX_USER_SHADOW_BASE;
13360+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13361+ dst += PAX_USER_SHADOW_BASE;
13362+#endif
13363+
13364+ return copy_user_generic((__force_kernel void *)dst,
13365+ (__force_kernel const void *)src, size);
13366+ }
13367 switch (size) {
13368 case 1: {
13369 u8 tmp;
13370- __get_user_asm(tmp, (u8 __user *)src,
13371+ __get_user_asm(tmp, (const u8 __user *)src,
13372 ret, "b", "b", "=q", 1);
13373 if (likely(!ret))
13374 __put_user_asm(tmp, (u8 __user *)dst,
13375@@ -176,7 +277,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13376 }
13377 case 2: {
13378 u16 tmp;
13379- __get_user_asm(tmp, (u16 __user *)src,
13380+ __get_user_asm(tmp, (const u16 __user *)src,
13381 ret, "w", "w", "=r", 2);
13382 if (likely(!ret))
13383 __put_user_asm(tmp, (u16 __user *)dst,
13384@@ -186,7 +287,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13385
13386 case 4: {
13387 u32 tmp;
13388- __get_user_asm(tmp, (u32 __user *)src,
13389+ __get_user_asm(tmp, (const u32 __user *)src,
13390 ret, "l", "k", "=r", 4);
13391 if (likely(!ret))
13392 __put_user_asm(tmp, (u32 __user *)dst,
13393@@ -195,7 +296,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13394 }
13395 case 8: {
13396 u64 tmp;
13397- __get_user_asm(tmp, (u64 __user *)src,
13398+ __get_user_asm(tmp, (const u64 __user *)src,
13399 ret, "q", "", "=r", 8);
13400 if (likely(!ret))
13401 __put_user_asm(tmp, (u64 __user *)dst,
13402@@ -203,47 +304,92 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13403 return ret;
13404 }
13405 default:
13406- return copy_user_generic((__force void *)dst,
13407- (__force void *)src, size);
13408+
13409+#ifdef CONFIG_PAX_MEMORY_UDEREF
13410+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13411+ src += PAX_USER_SHADOW_BASE;
13412+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13413+ dst += PAX_USER_SHADOW_BASE;
13414+#endif
13415+
13416+ return copy_user_generic((__force_kernel void *)dst,
13417+ (__force_kernel const void *)src, size);
13418 }
13419 }
13420
13421 __must_check long strnlen_user(const char __user *str, long n);
13422 __must_check long __strnlen_user(const char __user *str, long n);
13423 __must_check long strlen_user(const char __user *str);
13424-__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13425-__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13426+__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13427+__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13428
13429 static __must_check __always_inline int
13430-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13431+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13432 {
13433- return copy_user_generic(dst, (__force const void *)src, size);
13434+ if (size > INT_MAX)
13435+ return size;
13436+
13437+#ifdef CONFIG_PAX_MEMORY_UDEREF
13438+ if (!__access_ok(VERIFY_READ, src, size))
13439+ return size;
13440+
13441+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13442+ src += PAX_USER_SHADOW_BASE;
13443+#endif
13444+
13445+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13446 }
13447
13448-static __must_check __always_inline int
13449-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13450+static __must_check __always_inline unsigned long
13451+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13452 {
13453- return copy_user_generic((__force void *)dst, src, size);
13454+ if (size > INT_MAX)
13455+ return size;
13456+
13457+#ifdef CONFIG_PAX_MEMORY_UDEREF
13458+ if (!__access_ok(VERIFY_WRITE, dst, size))
13459+ return size;
13460+
13461+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13462+ dst += PAX_USER_SHADOW_BASE;
13463+#endif
13464+
13465+ return copy_user_generic((__force_kernel void *)dst, src, size);
13466 }
13467
13468-extern long __copy_user_nocache(void *dst, const void __user *src,
13469- unsigned size, int zerorest);
13470+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13471+ unsigned long size, int zerorest) __size_overflow(3);
13472
13473-static inline int
13474-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13475+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13476 {
13477 might_sleep();
13478+
13479+ if (size > INT_MAX)
13480+ return size;
13481+
13482+#ifdef CONFIG_PAX_MEMORY_UDEREF
13483+ if (!__access_ok(VERIFY_READ, src, size))
13484+ return size;
13485+#endif
13486+
13487 return __copy_user_nocache(dst, src, size, 1);
13488 }
13489
13490-static inline int
13491-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13492- unsigned size)
13493+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13494+ unsigned long size)
13495 {
13496+ if (size > INT_MAX)
13497+ return size;
13498+
13499+#ifdef CONFIG_PAX_MEMORY_UDEREF
13500+ if (!__access_ok(VERIFY_READ, src, size))
13501+ return size;
13502+#endif
13503+
13504 return __copy_user_nocache(dst, src, size, 0);
13505 }
13506
13507-unsigned long
13508-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13509+extern unsigned long
13510+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13511
13512 #endif /* _ASM_X86_UACCESS_64_H */
13513diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13514index bb05228..d763d5b 100644
13515--- a/arch/x86/include/asm/vdso.h
13516+++ b/arch/x86/include/asm/vdso.h
13517@@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13518 #define VDSO32_SYMBOL(base, name) \
13519 ({ \
13520 extern const char VDSO32_##name[]; \
13521- (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13522+ (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13523 })
13524 #endif
13525
13526diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13527index 764b66a..ad3cfc8 100644
13528--- a/arch/x86/include/asm/x86_init.h
13529+++ b/arch/x86/include/asm/x86_init.h
13530@@ -29,7 +29,7 @@ struct x86_init_mpparse {
13531 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13532 void (*find_smp_config)(void);
13533 void (*get_smp_config)(unsigned int early);
13534-};
13535+} __no_const;
13536
13537 /**
13538 * struct x86_init_resources - platform specific resource related ops
13539@@ -43,7 +43,7 @@ struct x86_init_resources {
13540 void (*probe_roms)(void);
13541 void (*reserve_resources)(void);
13542 char *(*memory_setup)(void);
13543-};
13544+} __no_const;
13545
13546 /**
13547 * struct x86_init_irqs - platform specific interrupt setup
13548@@ -56,7 +56,7 @@ struct x86_init_irqs {
13549 void (*pre_vector_init)(void);
13550 void (*intr_init)(void);
13551 void (*trap_init)(void);
13552-};
13553+} __no_const;
13554
13555 /**
13556 * struct x86_init_oem - oem platform specific customizing functions
13557@@ -66,7 +66,7 @@ struct x86_init_irqs {
13558 struct x86_init_oem {
13559 void (*arch_setup)(void);
13560 void (*banner)(void);
13561-};
13562+} __no_const;
13563
13564 /**
13565 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13566@@ -77,7 +77,7 @@ struct x86_init_oem {
13567 */
13568 struct x86_init_mapping {
13569 void (*pagetable_reserve)(u64 start, u64 end);
13570-};
13571+} __no_const;
13572
13573 /**
13574 * struct x86_init_paging - platform specific paging functions
13575@@ -87,7 +87,7 @@ struct x86_init_mapping {
13576 struct x86_init_paging {
13577 void (*pagetable_setup_start)(pgd_t *base);
13578 void (*pagetable_setup_done)(pgd_t *base);
13579-};
13580+} __no_const;
13581
13582 /**
13583 * struct x86_init_timers - platform specific timer setup
13584@@ -102,7 +102,7 @@ struct x86_init_timers {
13585 void (*tsc_pre_init)(void);
13586 void (*timer_init)(void);
13587 void (*wallclock_init)(void);
13588-};
13589+} __no_const;
13590
13591 /**
13592 * struct x86_init_iommu - platform specific iommu setup
13593@@ -110,7 +110,7 @@ struct x86_init_timers {
13594 */
13595 struct x86_init_iommu {
13596 int (*iommu_init)(void);
13597-};
13598+} __no_const;
13599
13600 /**
13601 * struct x86_init_pci - platform specific pci init functions
13602@@ -124,7 +124,7 @@ struct x86_init_pci {
13603 int (*init)(void);
13604 void (*init_irq)(void);
13605 void (*fixup_irqs)(void);
13606-};
13607+} __no_const;
13608
13609 /**
13610 * struct x86_init_ops - functions for platform specific setup
13611@@ -140,7 +140,7 @@ struct x86_init_ops {
13612 struct x86_init_timers timers;
13613 struct x86_init_iommu iommu;
13614 struct x86_init_pci pci;
13615-};
13616+} __no_const;
13617
13618 /**
13619 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13620@@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13621 void (*setup_percpu_clockev)(void);
13622 void (*early_percpu_clock_init)(void);
13623 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13624-};
13625+} __no_const;
13626
13627 /**
13628 * struct x86_platform_ops - platform specific runtime functions
13629@@ -177,7 +177,7 @@ struct x86_platform_ops {
13630 int (*i8042_detect)(void);
13631 void (*save_sched_clock_state)(void);
13632 void (*restore_sched_clock_state)(void);
13633-};
13634+} __no_const;
13635
13636 struct pci_dev;
13637
13638@@ -186,7 +186,7 @@ struct x86_msi_ops {
13639 void (*teardown_msi_irq)(unsigned int irq);
13640 void (*teardown_msi_irqs)(struct pci_dev *dev);
13641 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13642-};
13643+} __no_const;
13644
13645 extern struct x86_init_ops x86_init;
13646 extern struct x86_cpuinit_ops x86_cpuinit;
13647diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13648index c6ce245..ffbdab7 100644
13649--- a/arch/x86/include/asm/xsave.h
13650+++ b/arch/x86/include/asm/xsave.h
13651@@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13652 {
13653 int err;
13654
13655+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13656+ if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13657+ buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13658+#endif
13659+
13660 /*
13661 * Clear the xsave header first, so that reserved fields are
13662 * initialized to zero.
13663@@ -96,10 +101,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13664 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13665 {
13666 int err;
13667- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13668+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13669 u32 lmask = mask;
13670 u32 hmask = mask >> 32;
13671
13672+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13673+ if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13674+ xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13675+#endif
13676+
13677 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13678 "2:\n"
13679 ".section .fixup,\"ax\"\n"
13680diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
13681index 6a564ac..9b1340c 100644
13682--- a/arch/x86/kernel/acpi/realmode/Makefile
13683+++ b/arch/x86/kernel/acpi/realmode/Makefile
13684@@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
13685 $(call cc-option, -fno-stack-protector) \
13686 $(call cc-option, -mpreferred-stack-boundary=2)
13687 KBUILD_CFLAGS += $(call cc-option, -m32)
13688+ifdef CONSTIFY_PLUGIN
13689+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
13690+endif
13691 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13692 GCOV_PROFILE := n
13693
13694diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
13695index b4fd836..4358fe3 100644
13696--- a/arch/x86/kernel/acpi/realmode/wakeup.S
13697+++ b/arch/x86/kernel/acpi/realmode/wakeup.S
13698@@ -108,6 +108,9 @@ wakeup_code:
13699 /* Do any other stuff... */
13700
13701 #ifndef CONFIG_64BIT
13702+ /* Recheck NX bit overrides (64bit path does this in trampoline */
13703+ call verify_cpu
13704+
13705 /* This could also be done in C code... */
13706 movl pmode_cr3, %eax
13707 movl %eax, %cr3
13708@@ -131,6 +134,7 @@ wakeup_code:
13709 movl pmode_cr0, %eax
13710 movl %eax, %cr0
13711 jmp pmode_return
13712+# include "../../verify_cpu.S"
13713 #else
13714 pushw $0
13715 pushw trampoline_segment
13716diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13717index 146a49c..1b5338b 100644
13718--- a/arch/x86/kernel/acpi/sleep.c
13719+++ b/arch/x86/kernel/acpi/sleep.c
13720@@ -98,8 +98,12 @@ int acpi_suspend_lowlevel(void)
13721 header->trampoline_segment = trampoline_address() >> 4;
13722 #ifdef CONFIG_SMP
13723 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13724+
13725+ pax_open_kernel();
13726 early_gdt_descr.address =
13727 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13728+ pax_close_kernel();
13729+
13730 initial_gs = per_cpu_offset(smp_processor_id());
13731 #endif
13732 initial_code = (unsigned long)wakeup_long64;
13733diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13734index 7261083..5c12053 100644
13735--- a/arch/x86/kernel/acpi/wakeup_32.S
13736+++ b/arch/x86/kernel/acpi/wakeup_32.S
13737@@ -30,13 +30,11 @@ wakeup_pmode_return:
13738 # and restore the stack ... but you need gdt for this to work
13739 movl saved_context_esp, %esp
13740
13741- movl %cs:saved_magic, %eax
13742- cmpl $0x12345678, %eax
13743+ cmpl $0x12345678, saved_magic
13744 jne bogus_magic
13745
13746 # jump to place where we left off
13747- movl saved_eip, %eax
13748- jmp *%eax
13749+ jmp *(saved_eip)
13750
13751 bogus_magic:
13752 jmp bogus_magic
13753diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13754index 1f84794..e23f862 100644
13755--- a/arch/x86/kernel/alternative.c
13756+++ b/arch/x86/kernel/alternative.c
13757@@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13758 */
13759 for (a = start; a < end; a++) {
13760 instr = (u8 *)&a->instr_offset + a->instr_offset;
13761+
13762+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13763+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13764+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13765+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13766+#endif
13767+
13768 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13769 BUG_ON(a->replacementlen > a->instrlen);
13770 BUG_ON(a->instrlen > sizeof(insnbuf));
13771@@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13772 for (poff = start; poff < end; poff++) {
13773 u8 *ptr = (u8 *)poff + *poff;
13774
13775+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13776+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13777+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13778+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13779+#endif
13780+
13781 if (!*poff || ptr < text || ptr >= text_end)
13782 continue;
13783 /* turn DS segment override prefix into lock prefix */
13784- if (*ptr == 0x3e)
13785+ if (*ktla_ktva(ptr) == 0x3e)
13786 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13787 };
13788 mutex_unlock(&text_mutex);
13789@@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13790 for (poff = start; poff < end; poff++) {
13791 u8 *ptr = (u8 *)poff + *poff;
13792
13793+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13794+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13795+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13796+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13797+#endif
13798+
13799 if (!*poff || ptr < text || ptr >= text_end)
13800 continue;
13801 /* turn lock prefix into DS segment override prefix */
13802- if (*ptr == 0xf0)
13803+ if (*ktla_ktva(ptr) == 0xf0)
13804 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13805 };
13806 mutex_unlock(&text_mutex);
13807@@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13808
13809 BUG_ON(p->len > MAX_PATCH_LEN);
13810 /* prep the buffer with the original instructions */
13811- memcpy(insnbuf, p->instr, p->len);
13812+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13813 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13814 (unsigned long)p->instr, p->len);
13815
13816@@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13817 if (smp_alt_once)
13818 free_init_pages("SMP alternatives",
13819 (unsigned long)__smp_locks,
13820- (unsigned long)__smp_locks_end);
13821+ PAGE_ALIGN((unsigned long)__smp_locks_end));
13822
13823 restart_nmi();
13824 }
13825@@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13826 * instructions. And on the local CPU you need to be protected again NMI or MCE
13827 * handlers seeing an inconsistent instruction while you patch.
13828 */
13829-void *__init_or_module text_poke_early(void *addr, const void *opcode,
13830+void *__kprobes text_poke_early(void *addr, const void *opcode,
13831 size_t len)
13832 {
13833 unsigned long flags;
13834 local_irq_save(flags);
13835- memcpy(addr, opcode, len);
13836+
13837+ pax_open_kernel();
13838+ memcpy(ktla_ktva(addr), opcode, len);
13839 sync_core();
13840+ pax_close_kernel();
13841+
13842 local_irq_restore(flags);
13843 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13844 that causes hangs on some VIA CPUs. */
13845@@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13846 */
13847 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13848 {
13849- unsigned long flags;
13850- char *vaddr;
13851+ unsigned char *vaddr = ktla_ktva(addr);
13852 struct page *pages[2];
13853- int i;
13854+ size_t i;
13855
13856 if (!core_kernel_text((unsigned long)addr)) {
13857- pages[0] = vmalloc_to_page(addr);
13858- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13859+ pages[0] = vmalloc_to_page(vaddr);
13860+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13861 } else {
13862- pages[0] = virt_to_page(addr);
13863+ pages[0] = virt_to_page(vaddr);
13864 WARN_ON(!PageReserved(pages[0]));
13865- pages[1] = virt_to_page(addr + PAGE_SIZE);
13866+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13867 }
13868 BUG_ON(!pages[0]);
13869- local_irq_save(flags);
13870- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13871- if (pages[1])
13872- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13873- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13874- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13875- clear_fixmap(FIX_TEXT_POKE0);
13876- if (pages[1])
13877- clear_fixmap(FIX_TEXT_POKE1);
13878- local_flush_tlb();
13879- sync_core();
13880- /* Could also do a CLFLUSH here to speed up CPU recovery; but
13881- that causes hangs on some VIA CPUs. */
13882+ text_poke_early(addr, opcode, len);
13883 for (i = 0; i < len; i++)
13884- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13885- local_irq_restore(flags);
13886+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13887 return addr;
13888 }
13889
13890diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13891index edc2448..553e7c5 100644
13892--- a/arch/x86/kernel/apic/apic.c
13893+++ b/arch/x86/kernel/apic/apic.c
13894@@ -184,7 +184,7 @@ int first_system_vector = 0xfe;
13895 /*
13896 * Debug level, exported for io_apic.c
13897 */
13898-unsigned int apic_verbosity;
13899+int apic_verbosity;
13900
13901 int pic_mode;
13902
13903@@ -1917,7 +1917,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13904 apic_write(APIC_ESR, 0);
13905 v1 = apic_read(APIC_ESR);
13906 ack_APIC_irq();
13907- atomic_inc(&irq_err_count);
13908+ atomic_inc_unchecked(&irq_err_count);
13909
13910 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13911 smp_processor_id(), v0 , v1);
13912diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13913index e88300d..cd5a87a 100644
13914--- a/arch/x86/kernel/apic/io_apic.c
13915+++ b/arch/x86/kernel/apic/io_apic.c
13916@@ -83,7 +83,9 @@ static struct io_apic_ops io_apic_ops = {
13917
13918 void __init set_io_apic_ops(const struct io_apic_ops *ops)
13919 {
13920- io_apic_ops = *ops;
13921+ pax_open_kernel();
13922+ memcpy((void*)&io_apic_ops, ops, sizeof io_apic_ops);
13923+ pax_close_kernel();
13924 }
13925
13926 /*
13927@@ -1135,7 +1137,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13928 }
13929 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13930
13931-void lock_vector_lock(void)
13932+void lock_vector_lock(void) __acquires(vector_lock)
13933 {
13934 /* Used to the online set of cpus does not change
13935 * during assign_irq_vector.
13936@@ -1143,7 +1145,7 @@ void lock_vector_lock(void)
13937 raw_spin_lock(&vector_lock);
13938 }
13939
13940-void unlock_vector_lock(void)
13941+void unlock_vector_lock(void) __releases(vector_lock)
13942 {
13943 raw_spin_unlock(&vector_lock);
13944 }
13945@@ -2549,7 +2551,7 @@ static void ack_apic_edge(struct irq_data *data)
13946 ack_APIC_irq();
13947 }
13948
13949-atomic_t irq_mis_count;
13950+atomic_unchecked_t irq_mis_count;
13951
13952 #ifdef CONFIG_GENERIC_PENDING_IRQ
13953 static inline bool ioapic_irqd_mask(struct irq_data *data, struct irq_cfg *cfg)
13954@@ -2667,7 +2669,7 @@ static void ack_apic_level(struct irq_data *data)
13955 * at the cpu.
13956 */
13957 if (!(v & (1 << (i & 0x1f)))) {
13958- atomic_inc(&irq_mis_count);
13959+ atomic_inc_unchecked(&irq_mis_count);
13960
13961 eoi_ioapic_irq(irq, cfg);
13962 }
13963diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13964index 459e78c..f037006 100644
13965--- a/arch/x86/kernel/apm_32.c
13966+++ b/arch/x86/kernel/apm_32.c
13967@@ -410,7 +410,7 @@ static DEFINE_MUTEX(apm_mutex);
13968 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13969 * even though they are called in protected mode.
13970 */
13971-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13972+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13973 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13974
13975 static const char driver_version[] = "1.16ac"; /* no spaces */
13976@@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
13977 BUG_ON(cpu != 0);
13978 gdt = get_cpu_gdt_table(cpu);
13979 save_desc_40 = gdt[0x40 / 8];
13980+
13981+ pax_open_kernel();
13982 gdt[0x40 / 8] = bad_bios_desc;
13983+ pax_close_kernel();
13984
13985 apm_irq_save(flags);
13986 APM_DO_SAVE_SEGS;
13987@@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
13988 &call->esi);
13989 APM_DO_RESTORE_SEGS;
13990 apm_irq_restore(flags);
13991+
13992+ pax_open_kernel();
13993 gdt[0x40 / 8] = save_desc_40;
13994+ pax_close_kernel();
13995+
13996 put_cpu();
13997
13998 return call->eax & 0xff;
13999@@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void *_call)
14000 BUG_ON(cpu != 0);
14001 gdt = get_cpu_gdt_table(cpu);
14002 save_desc_40 = gdt[0x40 / 8];
14003+
14004+ pax_open_kernel();
14005 gdt[0x40 / 8] = bad_bios_desc;
14006+ pax_close_kernel();
14007
14008 apm_irq_save(flags);
14009 APM_DO_SAVE_SEGS;
14010@@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void *_call)
14011 &call->eax);
14012 APM_DO_RESTORE_SEGS;
14013 apm_irq_restore(flags);
14014+
14015+ pax_open_kernel();
14016 gdt[0x40 / 8] = save_desc_40;
14017+ pax_close_kernel();
14018+
14019 put_cpu();
14020 return error;
14021 }
14022@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
14023 * code to that CPU.
14024 */
14025 gdt = get_cpu_gdt_table(0);
14026+
14027+ pax_open_kernel();
14028 set_desc_base(&gdt[APM_CS >> 3],
14029 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14030 set_desc_base(&gdt[APM_CS_16 >> 3],
14031 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14032 set_desc_base(&gdt[APM_DS >> 3],
14033 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14034+ pax_close_kernel();
14035
14036 proc_create("apm", 0, NULL, &apm_file_ops);
14037
14038diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14039index 68de2dc..1f3c720 100644
14040--- a/arch/x86/kernel/asm-offsets.c
14041+++ b/arch/x86/kernel/asm-offsets.c
14042@@ -33,6 +33,8 @@ void common(void) {
14043 OFFSET(TI_status, thread_info, status);
14044 OFFSET(TI_addr_limit, thread_info, addr_limit);
14045 OFFSET(TI_preempt_count, thread_info, preempt_count);
14046+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14047+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14048
14049 BLANK();
14050 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14051@@ -53,8 +55,26 @@ void common(void) {
14052 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14053 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14054 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14055+
14056+#ifdef CONFIG_PAX_KERNEXEC
14057+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14058 #endif
14059
14060+#ifdef CONFIG_PAX_MEMORY_UDEREF
14061+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14062+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14063+#ifdef CONFIG_X86_64
14064+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14065+#endif
14066+#endif
14067+
14068+#endif
14069+
14070+ BLANK();
14071+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14072+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14073+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14074+
14075 #ifdef CONFIG_XEN
14076 BLANK();
14077 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14078diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14079index 1b4754f..fbb4227 100644
14080--- a/arch/x86/kernel/asm-offsets_64.c
14081+++ b/arch/x86/kernel/asm-offsets_64.c
14082@@ -76,6 +76,7 @@ int main(void)
14083 BLANK();
14084 #undef ENTRY
14085
14086+ DEFINE(TSS_size, sizeof(struct tss_struct));
14087 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14088 BLANK();
14089
14090diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14091index 6ab6aa2..8f71507 100644
14092--- a/arch/x86/kernel/cpu/Makefile
14093+++ b/arch/x86/kernel/cpu/Makefile
14094@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14095 CFLAGS_REMOVE_perf_event.o = -pg
14096 endif
14097
14098-# Make sure load_percpu_segment has no stackprotector
14099-nostackp := $(call cc-option, -fno-stack-protector)
14100-CFLAGS_common.o := $(nostackp)
14101-
14102 obj-y := intel_cacheinfo.o scattered.o topology.o
14103 obj-y += proc.o capflags.o powerflags.o common.o
14104 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
14105diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14106index 146bb62..ac9c74a 100644
14107--- a/arch/x86/kernel/cpu/amd.c
14108+++ b/arch/x86/kernel/cpu/amd.c
14109@@ -691,7 +691,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14110 unsigned int size)
14111 {
14112 /* AMD errata T13 (order #21922) */
14113- if ((c->x86 == 6)) {
14114+ if (c->x86 == 6) {
14115 /* Duron Rev A0 */
14116 if (c->x86_model == 3 && c->x86_mask == 0)
14117 size = 64;
14118diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14119index cf79302..b1b28ae 100644
14120--- a/arch/x86/kernel/cpu/common.c
14121+++ b/arch/x86/kernel/cpu/common.c
14122@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14123
14124 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14125
14126-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14127-#ifdef CONFIG_X86_64
14128- /*
14129- * We need valid kernel segments for data and code in long mode too
14130- * IRET will check the segment types kkeil 2000/10/28
14131- * Also sysret mandates a special GDT layout
14132- *
14133- * TLS descriptors are currently at a different place compared to i386.
14134- * Hopefully nobody expects them at a fixed place (Wine?)
14135- */
14136- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14137- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14138- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14139- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14140- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14141- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14142-#else
14143- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14144- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14145- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14146- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14147- /*
14148- * Segments used for calling PnP BIOS have byte granularity.
14149- * They code segments and data segments have fixed 64k limits,
14150- * the transfer segment sizes are set at run time.
14151- */
14152- /* 32-bit code */
14153- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14154- /* 16-bit code */
14155- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14156- /* 16-bit data */
14157- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14158- /* 16-bit data */
14159- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14160- /* 16-bit data */
14161- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14162- /*
14163- * The APM segments have byte granularity and their bases
14164- * are set at run time. All have 64k limits.
14165- */
14166- /* 32-bit code */
14167- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14168- /* 16-bit code */
14169- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14170- /* data */
14171- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14172-
14173- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14174- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14175- GDT_STACK_CANARY_INIT
14176-#endif
14177-} };
14178-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14179-
14180 static int __init x86_xsave_setup(char *s)
14181 {
14182 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14183@@ -374,7 +320,7 @@ void switch_to_new_gdt(int cpu)
14184 {
14185 struct desc_ptr gdt_descr;
14186
14187- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14188+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14189 gdt_descr.size = GDT_SIZE - 1;
14190 load_gdt(&gdt_descr);
14191 /* Reload the per-cpu base */
14192@@ -841,6 +787,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14193 /* Filter out anything that depends on CPUID levels we don't have */
14194 filter_cpuid_features(c, true);
14195
14196+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14197+ setup_clear_cpu_cap(X86_FEATURE_SEP);
14198+#endif
14199+
14200 /* If the model name is still unset, do table lookup. */
14201 if (!c->x86_model_id[0]) {
14202 const char *p;
14203@@ -1021,10 +971,12 @@ static __init int setup_disablecpuid(char *arg)
14204 }
14205 __setup("clearcpuid=", setup_disablecpuid);
14206
14207+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14208+EXPORT_PER_CPU_SYMBOL(current_tinfo);
14209+
14210 #ifdef CONFIG_X86_64
14211 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14212-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14213- (unsigned long) nmi_idt_table };
14214+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14215
14216 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14217 irq_stack_union) __aligned(PAGE_SIZE);
14218@@ -1038,7 +990,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14219 EXPORT_PER_CPU_SYMBOL(current_task);
14220
14221 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14222- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14223+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14224 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14225
14226 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14227@@ -1126,7 +1078,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14228 {
14229 memset(regs, 0, sizeof(struct pt_regs));
14230 regs->fs = __KERNEL_PERCPU;
14231- regs->gs = __KERNEL_STACK_CANARY;
14232+ savesegment(gs, regs->gs);
14233
14234 return regs;
14235 }
14236@@ -1181,7 +1133,7 @@ void __cpuinit cpu_init(void)
14237 int i;
14238
14239 cpu = stack_smp_processor_id();
14240- t = &per_cpu(init_tss, cpu);
14241+ t = init_tss + cpu;
14242 oist = &per_cpu(orig_ist, cpu);
14243
14244 #ifdef CONFIG_NUMA
14245@@ -1207,7 +1159,7 @@ void __cpuinit cpu_init(void)
14246 switch_to_new_gdt(cpu);
14247 loadsegment(fs, 0);
14248
14249- load_idt((const struct desc_ptr *)&idt_descr);
14250+ load_idt(&idt_descr);
14251
14252 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14253 syscall_init();
14254@@ -1216,7 +1168,6 @@ void __cpuinit cpu_init(void)
14255 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14256 barrier();
14257
14258- x86_configure_nx();
14259 if (cpu != 0)
14260 enable_x2apic();
14261
14262@@ -1272,7 +1223,7 @@ void __cpuinit cpu_init(void)
14263 {
14264 int cpu = smp_processor_id();
14265 struct task_struct *curr = current;
14266- struct tss_struct *t = &per_cpu(init_tss, cpu);
14267+ struct tss_struct *t = init_tss + cpu;
14268 struct thread_struct *thread = &curr->thread;
14269
14270 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14271diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14272index 3e6ff6c..54b4992 100644
14273--- a/arch/x86/kernel/cpu/intel.c
14274+++ b/arch/x86/kernel/cpu/intel.c
14275@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14276 * Update the IDT descriptor and reload the IDT so that
14277 * it uses the read-only mapped virtual address.
14278 */
14279- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14280+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14281 load_idt(&idt_descr);
14282 }
14283 #endif
14284diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14285index 61604ae..98250a5 100644
14286--- a/arch/x86/kernel/cpu/mcheck/mce.c
14287+++ b/arch/x86/kernel/cpu/mcheck/mce.c
14288@@ -42,6 +42,7 @@
14289 #include <asm/processor.h>
14290 #include <asm/mce.h>
14291 #include <asm/msr.h>
14292+#include <asm/local.h>
14293
14294 #include "mce-internal.h"
14295
14296@@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
14297 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14298 m->cs, m->ip);
14299
14300- if (m->cs == __KERNEL_CS)
14301+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14302 print_symbol("{%s}", m->ip);
14303 pr_cont("\n");
14304 }
14305@@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
14306
14307 #define PANIC_TIMEOUT 5 /* 5 seconds */
14308
14309-static atomic_t mce_paniced;
14310+static atomic_unchecked_t mce_paniced;
14311
14312 static int fake_panic;
14313-static atomic_t mce_fake_paniced;
14314+static atomic_unchecked_t mce_fake_paniced;
14315
14316 /* Panic in progress. Enable interrupts and wait for final IPI */
14317 static void wait_for_panic(void)
14318@@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14319 /*
14320 * Make sure only one CPU runs in machine check panic
14321 */
14322- if (atomic_inc_return(&mce_paniced) > 1)
14323+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14324 wait_for_panic();
14325 barrier();
14326
14327@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14328 console_verbose();
14329 } else {
14330 /* Don't log too much for fake panic */
14331- if (atomic_inc_return(&mce_fake_paniced) > 1)
14332+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14333 return;
14334 }
14335 /* First print corrected ones that are still unlogged */
14336@@ -684,7 +685,7 @@ static int mce_timed_out(u64 *t)
14337 * might have been modified by someone else.
14338 */
14339 rmb();
14340- if (atomic_read(&mce_paniced))
14341+ if (atomic_read_unchecked(&mce_paniced))
14342 wait_for_panic();
14343 if (!monarch_timeout)
14344 goto out;
14345@@ -1535,7 +1536,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14346 }
14347
14348 /* Call the installed machine check handler for this CPU setup. */
14349-void (*machine_check_vector)(struct pt_regs *, long error_code) =
14350+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14351 unexpected_machine_check;
14352
14353 /*
14354@@ -1558,7 +1559,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14355 return;
14356 }
14357
14358+ pax_open_kernel();
14359 machine_check_vector = do_machine_check;
14360+ pax_close_kernel();
14361
14362 __mcheck_cpu_init_generic();
14363 __mcheck_cpu_init_vendor(c);
14364@@ -1572,7 +1575,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14365 */
14366
14367 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14368-static int mce_chrdev_open_count; /* #times opened */
14369+static local_t mce_chrdev_open_count; /* #times opened */
14370 static int mce_chrdev_open_exclu; /* already open exclusive? */
14371
14372 static int mce_chrdev_open(struct inode *inode, struct file *file)
14373@@ -1580,7 +1583,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14374 spin_lock(&mce_chrdev_state_lock);
14375
14376 if (mce_chrdev_open_exclu ||
14377- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14378+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14379 spin_unlock(&mce_chrdev_state_lock);
14380
14381 return -EBUSY;
14382@@ -1588,7 +1591,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14383
14384 if (file->f_flags & O_EXCL)
14385 mce_chrdev_open_exclu = 1;
14386- mce_chrdev_open_count++;
14387+ local_inc(&mce_chrdev_open_count);
14388
14389 spin_unlock(&mce_chrdev_state_lock);
14390
14391@@ -1599,7 +1602,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14392 {
14393 spin_lock(&mce_chrdev_state_lock);
14394
14395- mce_chrdev_open_count--;
14396+ local_dec(&mce_chrdev_open_count);
14397 mce_chrdev_open_exclu = 0;
14398
14399 spin_unlock(&mce_chrdev_state_lock);
14400@@ -2324,7 +2327,7 @@ struct dentry *mce_get_debugfs_dir(void)
14401 static void mce_reset(void)
14402 {
14403 cpu_missing = 0;
14404- atomic_set(&mce_fake_paniced, 0);
14405+ atomic_set_unchecked(&mce_fake_paniced, 0);
14406 atomic_set(&mce_executing, 0);
14407 atomic_set(&mce_callin, 0);
14408 atomic_set(&global_nwo, 0);
14409diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14410index 2d5454c..51987eb 100644
14411--- a/arch/x86/kernel/cpu/mcheck/p5.c
14412+++ b/arch/x86/kernel/cpu/mcheck/p5.c
14413@@ -11,6 +11,7 @@
14414 #include <asm/processor.h>
14415 #include <asm/mce.h>
14416 #include <asm/msr.h>
14417+#include <asm/pgtable.h>
14418
14419 /* By default disabled */
14420 int mce_p5_enabled __read_mostly;
14421@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14422 if (!cpu_has(c, X86_FEATURE_MCE))
14423 return;
14424
14425+ pax_open_kernel();
14426 machine_check_vector = pentium_machine_check;
14427+ pax_close_kernel();
14428 /* Make sure the vector pointer is visible before we enable MCEs: */
14429 wmb();
14430
14431diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14432index 2d7998f..17c9de1 100644
14433--- a/arch/x86/kernel/cpu/mcheck/winchip.c
14434+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14435@@ -10,6 +10,7 @@
14436 #include <asm/processor.h>
14437 #include <asm/mce.h>
14438 #include <asm/msr.h>
14439+#include <asm/pgtable.h>
14440
14441 /* Machine check handler for WinChip C6: */
14442 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14443@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14444 {
14445 u32 lo, hi;
14446
14447+ pax_open_kernel();
14448 machine_check_vector = winchip_machine_check;
14449+ pax_close_kernel();
14450 /* Make sure the vector pointer is visible before we enable MCEs: */
14451 wmb();
14452
14453diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14454index 6b96110..0da73eb 100644
14455--- a/arch/x86/kernel/cpu/mtrr/main.c
14456+++ b/arch/x86/kernel/cpu/mtrr/main.c
14457@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14458 u64 size_or_mask, size_and_mask;
14459 static bool mtrr_aps_delayed_init;
14460
14461-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14462+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14463
14464 const struct mtrr_ops *mtrr_if;
14465
14466diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14467index df5e41f..816c719 100644
14468--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14469+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14470@@ -25,7 +25,7 @@ struct mtrr_ops {
14471 int (*validate_add_page)(unsigned long base, unsigned long size,
14472 unsigned int type);
14473 int (*have_wrcomb)(void);
14474-};
14475+} __do_const;
14476
14477 extern int generic_get_free_region(unsigned long base, unsigned long size,
14478 int replace_reg);
14479diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14480index bb8e034..fb9020b 100644
14481--- a/arch/x86/kernel/cpu/perf_event.c
14482+++ b/arch/x86/kernel/cpu/perf_event.c
14483@@ -1835,7 +1835,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14484 break;
14485
14486 perf_callchain_store(entry, frame.return_address);
14487- fp = frame.next_frame;
14488+ fp = (const void __force_user *)frame.next_frame;
14489 }
14490 }
14491
14492diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14493index 13ad899..f642b9a 100644
14494--- a/arch/x86/kernel/crash.c
14495+++ b/arch/x86/kernel/crash.c
14496@@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14497 {
14498 #ifdef CONFIG_X86_32
14499 struct pt_regs fixed_regs;
14500-#endif
14501
14502-#ifdef CONFIG_X86_32
14503- if (!user_mode_vm(regs)) {
14504+ if (!user_mode(regs)) {
14505 crash_fixup_ss_esp(&fixed_regs, regs);
14506 regs = &fixed_regs;
14507 }
14508diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14509index 37250fe..bf2ec74 100644
14510--- a/arch/x86/kernel/doublefault_32.c
14511+++ b/arch/x86/kernel/doublefault_32.c
14512@@ -11,7 +11,7 @@
14513
14514 #define DOUBLEFAULT_STACKSIZE (1024)
14515 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14516-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14517+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14518
14519 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14520
14521@@ -21,7 +21,7 @@ static void doublefault_fn(void)
14522 unsigned long gdt, tss;
14523
14524 store_gdt(&gdt_desc);
14525- gdt = gdt_desc.address;
14526+ gdt = (unsigned long)gdt_desc.address;
14527
14528 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14529
14530@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14531 /* 0x2 bit is always set */
14532 .flags = X86_EFLAGS_SF | 0x2,
14533 .sp = STACK_START,
14534- .es = __USER_DS,
14535+ .es = __KERNEL_DS,
14536 .cs = __KERNEL_CS,
14537 .ss = __KERNEL_DS,
14538- .ds = __USER_DS,
14539+ .ds = __KERNEL_DS,
14540 .fs = __KERNEL_PERCPU,
14541
14542 .__cr3 = __pa_nodebug(swapper_pg_dir),
14543diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14544index 1b81839..0b4e7b0 100644
14545--- a/arch/x86/kernel/dumpstack.c
14546+++ b/arch/x86/kernel/dumpstack.c
14547@@ -2,6 +2,9 @@
14548 * Copyright (C) 1991, 1992 Linus Torvalds
14549 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14550 */
14551+#ifdef CONFIG_GRKERNSEC_HIDESYM
14552+#define __INCLUDED_BY_HIDESYM 1
14553+#endif
14554 #include <linux/kallsyms.h>
14555 #include <linux/kprobes.h>
14556 #include <linux/uaccess.h>
14557@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14558 static void
14559 print_ftrace_graph_addr(unsigned long addr, void *data,
14560 const struct stacktrace_ops *ops,
14561- struct thread_info *tinfo, int *graph)
14562+ struct task_struct *task, int *graph)
14563 {
14564- struct task_struct *task;
14565 unsigned long ret_addr;
14566 int index;
14567
14568 if (addr != (unsigned long)return_to_handler)
14569 return;
14570
14571- task = tinfo->task;
14572 index = task->curr_ret_stack;
14573
14574 if (!task->ret_stack || index < *graph)
14575@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14576 static inline void
14577 print_ftrace_graph_addr(unsigned long addr, void *data,
14578 const struct stacktrace_ops *ops,
14579- struct thread_info *tinfo, int *graph)
14580+ struct task_struct *task, int *graph)
14581 { }
14582 #endif
14583
14584@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14585 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14586 */
14587
14588-static inline int valid_stack_ptr(struct thread_info *tinfo,
14589- void *p, unsigned int size, void *end)
14590+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14591 {
14592- void *t = tinfo;
14593 if (end) {
14594 if (p < end && p >= (end-THREAD_SIZE))
14595 return 1;
14596@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14597 }
14598
14599 unsigned long
14600-print_context_stack(struct thread_info *tinfo,
14601+print_context_stack(struct task_struct *task, void *stack_start,
14602 unsigned long *stack, unsigned long bp,
14603 const struct stacktrace_ops *ops, void *data,
14604 unsigned long *end, int *graph)
14605 {
14606 struct stack_frame *frame = (struct stack_frame *)bp;
14607
14608- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14609+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14610 unsigned long addr;
14611
14612 addr = *stack;
14613@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14614 } else {
14615 ops->address(data, addr, 0);
14616 }
14617- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14618+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14619 }
14620 stack++;
14621 }
14622@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14623 EXPORT_SYMBOL_GPL(print_context_stack);
14624
14625 unsigned long
14626-print_context_stack_bp(struct thread_info *tinfo,
14627+print_context_stack_bp(struct task_struct *task, void *stack_start,
14628 unsigned long *stack, unsigned long bp,
14629 const struct stacktrace_ops *ops, void *data,
14630 unsigned long *end, int *graph)
14631@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14632 struct stack_frame *frame = (struct stack_frame *)bp;
14633 unsigned long *ret_addr = &frame->return_address;
14634
14635- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14636+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14637 unsigned long addr = *ret_addr;
14638
14639 if (!__kernel_text_address(addr))
14640@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14641 ops->address(data, addr, 1);
14642 frame = frame->next_frame;
14643 ret_addr = &frame->return_address;
14644- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14645+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14646 }
14647
14648 return (unsigned long)frame;
14649@@ -189,7 +188,7 @@ void dump_stack(void)
14650
14651 bp = stack_frame(current, NULL);
14652 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14653- current->pid, current->comm, print_tainted(),
14654+ task_pid_nr(current), current->comm, print_tainted(),
14655 init_utsname()->release,
14656 (int)strcspn(init_utsname()->version, " "),
14657 init_utsname()->version);
14658@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14659 }
14660 EXPORT_SYMBOL_GPL(oops_begin);
14661
14662+extern void gr_handle_kernel_exploit(void);
14663+
14664 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14665 {
14666 if (regs && kexec_should_crash(current))
14667@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14668 panic("Fatal exception in interrupt");
14669 if (panic_on_oops)
14670 panic("Fatal exception");
14671- do_exit(signr);
14672+
14673+ gr_handle_kernel_exploit();
14674+
14675+ do_group_exit(signr);
14676 }
14677
14678 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14679@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14680
14681 show_registers(regs);
14682 #ifdef CONFIG_X86_32
14683- if (user_mode_vm(regs)) {
14684+ if (user_mode(regs)) {
14685 sp = regs->sp;
14686 ss = regs->ss & 0xffff;
14687 } else {
14688@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14689 unsigned long flags = oops_begin();
14690 int sig = SIGSEGV;
14691
14692- if (!user_mode_vm(regs))
14693+ if (!user_mode(regs))
14694 report_bug(regs->ip, regs);
14695
14696 if (__die(str, regs, err))
14697diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14698index 88ec912..e95e935 100644
14699--- a/arch/x86/kernel/dumpstack_32.c
14700+++ b/arch/x86/kernel/dumpstack_32.c
14701@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14702 bp = stack_frame(task, regs);
14703
14704 for (;;) {
14705- struct thread_info *context;
14706+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14707
14708- context = (struct thread_info *)
14709- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14710- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14711+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14712
14713- stack = (unsigned long *)context->previous_esp;
14714- if (!stack)
14715+ if (stack_start == task_stack_page(task))
14716 break;
14717+ stack = *(unsigned long **)stack_start;
14718 if (ops->stack(data, "IRQ") < 0)
14719 break;
14720 touch_nmi_watchdog();
14721@@ -87,7 +85,7 @@ void show_registers(struct pt_regs *regs)
14722 int i;
14723
14724 print_modules();
14725- __show_regs(regs, !user_mode_vm(regs));
14726+ __show_regs(regs, !user_mode(regs));
14727
14728 printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14729 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14730@@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
14731 * When in-kernel, we also print out the stack and code at the
14732 * time of the fault..
14733 */
14734- if (!user_mode_vm(regs)) {
14735+ if (!user_mode(regs)) {
14736 unsigned int code_prologue = code_bytes * 43 / 64;
14737 unsigned int code_len = code_bytes;
14738 unsigned char c;
14739 u8 *ip;
14740+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14741
14742 printk(KERN_EMERG "Stack:\n");
14743 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14744
14745 printk(KERN_EMERG "Code: ");
14746
14747- ip = (u8 *)regs->ip - code_prologue;
14748+ ip = (u8 *)regs->ip - code_prologue + cs_base;
14749 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14750 /* try starting at IP */
14751- ip = (u8 *)regs->ip;
14752+ ip = (u8 *)regs->ip + cs_base;
14753 code_len = code_len - code_prologue + 1;
14754 }
14755 for (i = 0; i < code_len; i++, ip++) {
14756@@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
14757 printk(KERN_CONT " Bad EIP value.");
14758 break;
14759 }
14760- if (ip == (u8 *)regs->ip)
14761+ if (ip == (u8 *)regs->ip + cs_base)
14762 printk(KERN_CONT "<%02x> ", c);
14763 else
14764 printk(KERN_CONT "%02x ", c);
14765@@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14766 {
14767 unsigned short ud2;
14768
14769+ ip = ktla_ktva(ip);
14770 if (ip < PAGE_OFFSET)
14771 return 0;
14772 if (probe_kernel_address((unsigned short *)ip, ud2))
14773@@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14774
14775 return ud2 == 0x0b0f;
14776 }
14777+
14778+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14779+void pax_check_alloca(unsigned long size)
14780+{
14781+ unsigned long sp = (unsigned long)&sp, stack_left;
14782+
14783+ /* all kernel stacks are of the same size */
14784+ stack_left = sp & (THREAD_SIZE - 1);
14785+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14786+}
14787+EXPORT_SYMBOL(pax_check_alloca);
14788+#endif
14789diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14790index 17107bd..9623722 100644
14791--- a/arch/x86/kernel/dumpstack_64.c
14792+++ b/arch/x86/kernel/dumpstack_64.c
14793@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14794 unsigned long *irq_stack_end =
14795 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14796 unsigned used = 0;
14797- struct thread_info *tinfo;
14798 int graph = 0;
14799 unsigned long dummy;
14800+ void *stack_start;
14801
14802 if (!task)
14803 task = current;
14804@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14805 * current stack address. If the stacks consist of nested
14806 * exceptions
14807 */
14808- tinfo = task_thread_info(task);
14809 for (;;) {
14810 char *id;
14811 unsigned long *estack_end;
14812+
14813 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14814 &used, &id);
14815
14816@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14817 if (ops->stack(data, id) < 0)
14818 break;
14819
14820- bp = ops->walk_stack(tinfo, stack, bp, ops,
14821+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14822 data, estack_end, &graph);
14823 ops->stack(data, "<EOE>");
14824 /*
14825@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14826 * second-to-last pointer (index -2 to end) in the
14827 * exception stack:
14828 */
14829+ if ((u16)estack_end[-1] != __KERNEL_DS)
14830+ goto out;
14831 stack = (unsigned long *) estack_end[-2];
14832 continue;
14833 }
14834@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14835 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14836 if (ops->stack(data, "IRQ") < 0)
14837 break;
14838- bp = ops->walk_stack(tinfo, stack, bp,
14839+ bp = ops->walk_stack(task, irq_stack, stack, bp,
14840 ops, data, irq_stack_end, &graph);
14841 /*
14842 * We link to the next stack (which would be
14843@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14844 /*
14845 * This handles the process stack:
14846 */
14847- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14848+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14849+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14850+out:
14851 put_cpu();
14852 }
14853 EXPORT_SYMBOL(dump_trace);
14854@@ -305,3 +309,50 @@ int is_valid_bugaddr(unsigned long ip)
14855
14856 return ud2 == 0x0b0f;
14857 }
14858+
14859+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14860+void pax_check_alloca(unsigned long size)
14861+{
14862+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14863+ unsigned cpu, used;
14864+ char *id;
14865+
14866+ /* check the process stack first */
14867+ stack_start = (unsigned long)task_stack_page(current);
14868+ stack_end = stack_start + THREAD_SIZE;
14869+ if (likely(stack_start <= sp && sp < stack_end)) {
14870+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
14871+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14872+ return;
14873+ }
14874+
14875+ cpu = get_cpu();
14876+
14877+ /* check the irq stacks */
14878+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14879+ stack_start = stack_end - IRQ_STACK_SIZE;
14880+ if (stack_start <= sp && sp < stack_end) {
14881+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14882+ put_cpu();
14883+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14884+ return;
14885+ }
14886+
14887+ /* check the exception stacks */
14888+ used = 0;
14889+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14890+ stack_start = stack_end - EXCEPTION_STKSZ;
14891+ if (stack_end && stack_start <= sp && sp < stack_end) {
14892+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14893+ put_cpu();
14894+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14895+ return;
14896+ }
14897+
14898+ put_cpu();
14899+
14900+ /* unknown stack */
14901+ BUG();
14902+}
14903+EXPORT_SYMBOL(pax_check_alloca);
14904+#endif
14905diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14906index 9b9f18b..9fcaa04 100644
14907--- a/arch/x86/kernel/early_printk.c
14908+++ b/arch/x86/kernel/early_printk.c
14909@@ -7,6 +7,7 @@
14910 #include <linux/pci_regs.h>
14911 #include <linux/pci_ids.h>
14912 #include <linux/errno.h>
14913+#include <linux/sched.h>
14914 #include <asm/io.h>
14915 #include <asm/processor.h>
14916 #include <asm/fcntl.h>
14917diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14918index 7b784f4..db6b628 100644
14919--- a/arch/x86/kernel/entry_32.S
14920+++ b/arch/x86/kernel/entry_32.S
14921@@ -179,13 +179,146 @@
14922 /*CFI_REL_OFFSET gs, PT_GS*/
14923 .endm
14924 .macro SET_KERNEL_GS reg
14925+
14926+#ifdef CONFIG_CC_STACKPROTECTOR
14927 movl $(__KERNEL_STACK_CANARY), \reg
14928+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14929+ movl $(__USER_DS), \reg
14930+#else
14931+ xorl \reg, \reg
14932+#endif
14933+
14934 movl \reg, %gs
14935 .endm
14936
14937 #endif /* CONFIG_X86_32_LAZY_GS */
14938
14939-.macro SAVE_ALL
14940+.macro pax_enter_kernel
14941+#ifdef CONFIG_PAX_KERNEXEC
14942+ call pax_enter_kernel
14943+#endif
14944+.endm
14945+
14946+.macro pax_exit_kernel
14947+#ifdef CONFIG_PAX_KERNEXEC
14948+ call pax_exit_kernel
14949+#endif
14950+.endm
14951+
14952+#ifdef CONFIG_PAX_KERNEXEC
14953+ENTRY(pax_enter_kernel)
14954+#ifdef CONFIG_PARAVIRT
14955+ pushl %eax
14956+ pushl %ecx
14957+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14958+ mov %eax, %esi
14959+#else
14960+ mov %cr0, %esi
14961+#endif
14962+ bts $16, %esi
14963+ jnc 1f
14964+ mov %cs, %esi
14965+ cmp $__KERNEL_CS, %esi
14966+ jz 3f
14967+ ljmp $__KERNEL_CS, $3f
14968+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14969+2:
14970+#ifdef CONFIG_PARAVIRT
14971+ mov %esi, %eax
14972+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14973+#else
14974+ mov %esi, %cr0
14975+#endif
14976+3:
14977+#ifdef CONFIG_PARAVIRT
14978+ popl %ecx
14979+ popl %eax
14980+#endif
14981+ ret
14982+ENDPROC(pax_enter_kernel)
14983+
14984+ENTRY(pax_exit_kernel)
14985+#ifdef CONFIG_PARAVIRT
14986+ pushl %eax
14987+ pushl %ecx
14988+#endif
14989+ mov %cs, %esi
14990+ cmp $__KERNEXEC_KERNEL_CS, %esi
14991+ jnz 2f
14992+#ifdef CONFIG_PARAVIRT
14993+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14994+ mov %eax, %esi
14995+#else
14996+ mov %cr0, %esi
14997+#endif
14998+ btr $16, %esi
14999+ ljmp $__KERNEL_CS, $1f
15000+1:
15001+#ifdef CONFIG_PARAVIRT
15002+ mov %esi, %eax
15003+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15004+#else
15005+ mov %esi, %cr0
15006+#endif
15007+2:
15008+#ifdef CONFIG_PARAVIRT
15009+ popl %ecx
15010+ popl %eax
15011+#endif
15012+ ret
15013+ENDPROC(pax_exit_kernel)
15014+#endif
15015+
15016+.macro pax_erase_kstack
15017+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15018+ call pax_erase_kstack
15019+#endif
15020+.endm
15021+
15022+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15023+/*
15024+ * ebp: thread_info
15025+ * ecx, edx: can be clobbered
15026+ */
15027+ENTRY(pax_erase_kstack)
15028+ pushl %edi
15029+ pushl %eax
15030+
15031+ mov TI_lowest_stack(%ebp), %edi
15032+ mov $-0xBEEF, %eax
15033+ std
15034+
15035+1: mov %edi, %ecx
15036+ and $THREAD_SIZE_asm - 1, %ecx
15037+ shr $2, %ecx
15038+ repne scasl
15039+ jecxz 2f
15040+
15041+ cmp $2*16, %ecx
15042+ jc 2f
15043+
15044+ mov $2*16, %ecx
15045+ repe scasl
15046+ jecxz 2f
15047+ jne 1b
15048+
15049+2: cld
15050+ mov %esp, %ecx
15051+ sub %edi, %ecx
15052+ shr $2, %ecx
15053+ rep stosl
15054+
15055+ mov TI_task_thread_sp0(%ebp), %edi
15056+ sub $128, %edi
15057+ mov %edi, TI_lowest_stack(%ebp)
15058+
15059+ popl %eax
15060+ popl %edi
15061+ ret
15062+ENDPROC(pax_erase_kstack)
15063+#endif
15064+
15065+.macro __SAVE_ALL _DS
15066 cld
15067 PUSH_GS
15068 pushl_cfi %fs
15069@@ -208,7 +341,7 @@
15070 CFI_REL_OFFSET ecx, 0
15071 pushl_cfi %ebx
15072 CFI_REL_OFFSET ebx, 0
15073- movl $(__USER_DS), %edx
15074+ movl $\_DS, %edx
15075 movl %edx, %ds
15076 movl %edx, %es
15077 movl $(__KERNEL_PERCPU), %edx
15078@@ -216,6 +349,15 @@
15079 SET_KERNEL_GS %edx
15080 .endm
15081
15082+.macro SAVE_ALL
15083+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15084+ __SAVE_ALL __KERNEL_DS
15085+ pax_enter_kernel
15086+#else
15087+ __SAVE_ALL __USER_DS
15088+#endif
15089+.endm
15090+
15091 .macro RESTORE_INT_REGS
15092 popl_cfi %ebx
15093 CFI_RESTORE ebx
15094@@ -301,7 +443,7 @@ ENTRY(ret_from_fork)
15095 popfl_cfi
15096 jmp syscall_exit
15097 CFI_ENDPROC
15098-END(ret_from_fork)
15099+ENDPROC(ret_from_fork)
15100
15101 /*
15102 * Interrupt exit functions should be protected against kprobes
15103@@ -335,7 +477,15 @@ resume_userspace_sig:
15104 andl $SEGMENT_RPL_MASK, %eax
15105 #endif
15106 cmpl $USER_RPL, %eax
15107+
15108+#ifdef CONFIG_PAX_KERNEXEC
15109+ jae resume_userspace
15110+
15111+ pax_exit_kernel
15112+ jmp resume_kernel
15113+#else
15114 jb resume_kernel # not returning to v8086 or userspace
15115+#endif
15116
15117 ENTRY(resume_userspace)
15118 LOCKDEP_SYS_EXIT
15119@@ -347,8 +497,8 @@ ENTRY(resume_userspace)
15120 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15121 # int/exception return?
15122 jne work_pending
15123- jmp restore_all
15124-END(ret_from_exception)
15125+ jmp restore_all_pax
15126+ENDPROC(ret_from_exception)
15127
15128 #ifdef CONFIG_PREEMPT
15129 ENTRY(resume_kernel)
15130@@ -363,7 +513,7 @@ need_resched:
15131 jz restore_all
15132 call preempt_schedule_irq
15133 jmp need_resched
15134-END(resume_kernel)
15135+ENDPROC(resume_kernel)
15136 #endif
15137 CFI_ENDPROC
15138 /*
15139@@ -397,23 +547,34 @@ sysenter_past_esp:
15140 /*CFI_REL_OFFSET cs, 0*/
15141 /*
15142 * Push current_thread_info()->sysenter_return to the stack.
15143- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15144- * pushed above; +8 corresponds to copy_thread's esp0 setting.
15145 */
15146- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15147+ pushl_cfi $0
15148 CFI_REL_OFFSET eip, 0
15149
15150 pushl_cfi %eax
15151 SAVE_ALL
15152+ GET_THREAD_INFO(%ebp)
15153+ movl TI_sysenter_return(%ebp),%ebp
15154+ movl %ebp,PT_EIP(%esp)
15155 ENABLE_INTERRUPTS(CLBR_NONE)
15156
15157 /*
15158 * Load the potential sixth argument from user stack.
15159 * Careful about security.
15160 */
15161+ movl PT_OLDESP(%esp),%ebp
15162+
15163+#ifdef CONFIG_PAX_MEMORY_UDEREF
15164+ mov PT_OLDSS(%esp),%ds
15165+1: movl %ds:(%ebp),%ebp
15166+ push %ss
15167+ pop %ds
15168+#else
15169 cmpl $__PAGE_OFFSET-3,%ebp
15170 jae syscall_fault
15171 1: movl (%ebp),%ebp
15172+#endif
15173+
15174 movl %ebp,PT_EBP(%esp)
15175 .section __ex_table,"a"
15176 .align 4
15177@@ -436,12 +597,24 @@ sysenter_do_call:
15178 testl $_TIF_ALLWORK_MASK, %ecx
15179 jne sysexit_audit
15180 sysenter_exit:
15181+
15182+#ifdef CONFIG_PAX_RANDKSTACK
15183+ pushl_cfi %eax
15184+ movl %esp, %eax
15185+ call pax_randomize_kstack
15186+ popl_cfi %eax
15187+#endif
15188+
15189+ pax_erase_kstack
15190+
15191 /* if something modifies registers it must also disable sysexit */
15192 movl PT_EIP(%esp), %edx
15193 movl PT_OLDESP(%esp), %ecx
15194 xorl %ebp,%ebp
15195 TRACE_IRQS_ON
15196 1: mov PT_FS(%esp), %fs
15197+2: mov PT_DS(%esp), %ds
15198+3: mov PT_ES(%esp), %es
15199 PTGS_TO_GS
15200 ENABLE_INTERRUPTS_SYSEXIT
15201
15202@@ -458,6 +631,9 @@ sysenter_audit:
15203 movl %eax,%edx /* 2nd arg: syscall number */
15204 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15205 call __audit_syscall_entry
15206+
15207+ pax_erase_kstack
15208+
15209 pushl_cfi %ebx
15210 movl PT_EAX(%esp),%eax /* reload syscall number */
15211 jmp sysenter_do_call
15212@@ -483,11 +659,17 @@ sysexit_audit:
15213
15214 CFI_ENDPROC
15215 .pushsection .fixup,"ax"
15216-2: movl $0,PT_FS(%esp)
15217+4: movl $0,PT_FS(%esp)
15218+ jmp 1b
15219+5: movl $0,PT_DS(%esp)
15220+ jmp 1b
15221+6: movl $0,PT_ES(%esp)
15222 jmp 1b
15223 .section __ex_table,"a"
15224 .align 4
15225- .long 1b,2b
15226+ .long 1b,4b
15227+ .long 2b,5b
15228+ .long 3b,6b
15229 .popsection
15230 PTGS_TO_GS_EX
15231 ENDPROC(ia32_sysenter_target)
15232@@ -520,6 +702,15 @@ syscall_exit:
15233 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15234 jne syscall_exit_work
15235
15236+restore_all_pax:
15237+
15238+#ifdef CONFIG_PAX_RANDKSTACK
15239+ movl %esp, %eax
15240+ call pax_randomize_kstack
15241+#endif
15242+
15243+ pax_erase_kstack
15244+
15245 restore_all:
15246 TRACE_IRQS_IRET
15247 restore_all_notrace:
15248@@ -579,14 +770,34 @@ ldt_ss:
15249 * compensating for the offset by changing to the ESPFIX segment with
15250 * a base address that matches for the difference.
15251 */
15252-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15253+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15254 mov %esp, %edx /* load kernel esp */
15255 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15256 mov %dx, %ax /* eax: new kernel esp */
15257 sub %eax, %edx /* offset (low word is 0) */
15258+#ifdef CONFIG_SMP
15259+ movl PER_CPU_VAR(cpu_number), %ebx
15260+ shll $PAGE_SHIFT_asm, %ebx
15261+ addl $cpu_gdt_table, %ebx
15262+#else
15263+ movl $cpu_gdt_table, %ebx
15264+#endif
15265 shr $16, %edx
15266- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15267- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15268+
15269+#ifdef CONFIG_PAX_KERNEXEC
15270+ mov %cr0, %esi
15271+ btr $16, %esi
15272+ mov %esi, %cr0
15273+#endif
15274+
15275+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15276+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15277+
15278+#ifdef CONFIG_PAX_KERNEXEC
15279+ bts $16, %esi
15280+ mov %esi, %cr0
15281+#endif
15282+
15283 pushl_cfi $__ESPFIX_SS
15284 pushl_cfi %eax /* new kernel esp */
15285 /* Disable interrupts, but do not irqtrace this section: we
15286@@ -615,38 +826,30 @@ work_resched:
15287 movl TI_flags(%ebp), %ecx
15288 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15289 # than syscall tracing?
15290- jz restore_all
15291+ jz restore_all_pax
15292 testb $_TIF_NEED_RESCHED, %cl
15293 jnz work_resched
15294
15295 work_notifysig: # deal with pending signals and
15296 # notify-resume requests
15297+ movl %esp, %eax
15298 #ifdef CONFIG_VM86
15299 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15300- movl %esp, %eax
15301- jne work_notifysig_v86 # returning to kernel-space or
15302+ jz 1f # returning to kernel-space or
15303 # vm86-space
15304- TRACE_IRQS_ON
15305- ENABLE_INTERRUPTS(CLBR_NONE)
15306- xorl %edx, %edx
15307- call do_notify_resume
15308- jmp resume_userspace_sig
15309
15310- ALIGN
15311-work_notifysig_v86:
15312 pushl_cfi %ecx # save ti_flags for do_notify_resume
15313 call save_v86_state # %eax contains pt_regs pointer
15314 popl_cfi %ecx
15315 movl %eax, %esp
15316-#else
15317- movl %esp, %eax
15318+1:
15319 #endif
15320 TRACE_IRQS_ON
15321 ENABLE_INTERRUPTS(CLBR_NONE)
15322 xorl %edx, %edx
15323 call do_notify_resume
15324 jmp resume_userspace_sig
15325-END(work_pending)
15326+ENDPROC(work_pending)
15327
15328 # perform syscall exit tracing
15329 ALIGN
15330@@ -654,11 +857,14 @@ syscall_trace_entry:
15331 movl $-ENOSYS,PT_EAX(%esp)
15332 movl %esp, %eax
15333 call syscall_trace_enter
15334+
15335+ pax_erase_kstack
15336+
15337 /* What it returned is what we'll actually use. */
15338 cmpl $(NR_syscalls), %eax
15339 jnae syscall_call
15340 jmp syscall_exit
15341-END(syscall_trace_entry)
15342+ENDPROC(syscall_trace_entry)
15343
15344 # perform syscall exit tracing
15345 ALIGN
15346@@ -671,20 +877,24 @@ syscall_exit_work:
15347 movl %esp, %eax
15348 call syscall_trace_leave
15349 jmp resume_userspace
15350-END(syscall_exit_work)
15351+ENDPROC(syscall_exit_work)
15352 CFI_ENDPROC
15353
15354 RING0_INT_FRAME # can't unwind into user space anyway
15355 syscall_fault:
15356+#ifdef CONFIG_PAX_MEMORY_UDEREF
15357+ push %ss
15358+ pop %ds
15359+#endif
15360 GET_THREAD_INFO(%ebp)
15361 movl $-EFAULT,PT_EAX(%esp)
15362 jmp resume_userspace
15363-END(syscall_fault)
15364+ENDPROC(syscall_fault)
15365
15366 syscall_badsys:
15367 movl $-ENOSYS,PT_EAX(%esp)
15368 jmp resume_userspace
15369-END(syscall_badsys)
15370+ENDPROC(syscall_badsys)
15371 CFI_ENDPROC
15372 /*
15373 * End of kprobes section
15374@@ -756,6 +966,36 @@ ENTRY(ptregs_clone)
15375 CFI_ENDPROC
15376 ENDPROC(ptregs_clone)
15377
15378+ ALIGN;
15379+ENTRY(kernel_execve)
15380+ CFI_STARTPROC
15381+ pushl_cfi %ebp
15382+ sub $PT_OLDSS+4,%esp
15383+ pushl_cfi %edi
15384+ pushl_cfi %ecx
15385+ pushl_cfi %eax
15386+ lea 3*4(%esp),%edi
15387+ mov $PT_OLDSS/4+1,%ecx
15388+ xorl %eax,%eax
15389+ rep stosl
15390+ popl_cfi %eax
15391+ popl_cfi %ecx
15392+ popl_cfi %edi
15393+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15394+ pushl_cfi %esp
15395+ call sys_execve
15396+ add $4,%esp
15397+ CFI_ADJUST_CFA_OFFSET -4
15398+ GET_THREAD_INFO(%ebp)
15399+ test %eax,%eax
15400+ jz syscall_exit
15401+ add $PT_OLDSS+4,%esp
15402+ CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15403+ popl_cfi %ebp
15404+ ret
15405+ CFI_ENDPROC
15406+ENDPROC(kernel_execve)
15407+
15408 .macro FIXUP_ESPFIX_STACK
15409 /*
15410 * Switch back for ESPFIX stack to the normal zerobased stack
15411@@ -765,8 +1005,15 @@ ENDPROC(ptregs_clone)
15412 * normal stack and adjusts ESP with the matching offset.
15413 */
15414 /* fixup the stack */
15415- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15416- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15417+#ifdef CONFIG_SMP
15418+ movl PER_CPU_VAR(cpu_number), %ebx
15419+ shll $PAGE_SHIFT_asm, %ebx
15420+ addl $cpu_gdt_table, %ebx
15421+#else
15422+ movl $cpu_gdt_table, %ebx
15423+#endif
15424+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15425+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15426 shl $16, %eax
15427 addl %esp, %eax /* the adjusted stack pointer */
15428 pushl_cfi $__KERNEL_DS
15429@@ -819,7 +1066,7 @@ vector=vector+1
15430 .endr
15431 2: jmp common_interrupt
15432 .endr
15433-END(irq_entries_start)
15434+ENDPROC(irq_entries_start)
15435
15436 .previous
15437 END(interrupt)
15438@@ -867,7 +1114,7 @@ ENTRY(coprocessor_error)
15439 pushl_cfi $do_coprocessor_error
15440 jmp error_code
15441 CFI_ENDPROC
15442-END(coprocessor_error)
15443+ENDPROC(coprocessor_error)
15444
15445 ENTRY(simd_coprocessor_error)
15446 RING0_INT_FRAME
15447@@ -888,7 +1135,7 @@ ENTRY(simd_coprocessor_error)
15448 #endif
15449 jmp error_code
15450 CFI_ENDPROC
15451-END(simd_coprocessor_error)
15452+ENDPROC(simd_coprocessor_error)
15453
15454 ENTRY(device_not_available)
15455 RING0_INT_FRAME
15456@@ -896,7 +1143,7 @@ ENTRY(device_not_available)
15457 pushl_cfi $do_device_not_available
15458 jmp error_code
15459 CFI_ENDPROC
15460-END(device_not_available)
15461+ENDPROC(device_not_available)
15462
15463 #ifdef CONFIG_PARAVIRT
15464 ENTRY(native_iret)
15465@@ -905,12 +1152,12 @@ ENTRY(native_iret)
15466 .align 4
15467 .long native_iret, iret_exc
15468 .previous
15469-END(native_iret)
15470+ENDPROC(native_iret)
15471
15472 ENTRY(native_irq_enable_sysexit)
15473 sti
15474 sysexit
15475-END(native_irq_enable_sysexit)
15476+ENDPROC(native_irq_enable_sysexit)
15477 #endif
15478
15479 ENTRY(overflow)
15480@@ -919,7 +1166,7 @@ ENTRY(overflow)
15481 pushl_cfi $do_overflow
15482 jmp error_code
15483 CFI_ENDPROC
15484-END(overflow)
15485+ENDPROC(overflow)
15486
15487 ENTRY(bounds)
15488 RING0_INT_FRAME
15489@@ -927,7 +1174,7 @@ ENTRY(bounds)
15490 pushl_cfi $do_bounds
15491 jmp error_code
15492 CFI_ENDPROC
15493-END(bounds)
15494+ENDPROC(bounds)
15495
15496 ENTRY(invalid_op)
15497 RING0_INT_FRAME
15498@@ -935,7 +1182,7 @@ ENTRY(invalid_op)
15499 pushl_cfi $do_invalid_op
15500 jmp error_code
15501 CFI_ENDPROC
15502-END(invalid_op)
15503+ENDPROC(invalid_op)
15504
15505 ENTRY(coprocessor_segment_overrun)
15506 RING0_INT_FRAME
15507@@ -943,35 +1190,35 @@ ENTRY(coprocessor_segment_overrun)
15508 pushl_cfi $do_coprocessor_segment_overrun
15509 jmp error_code
15510 CFI_ENDPROC
15511-END(coprocessor_segment_overrun)
15512+ENDPROC(coprocessor_segment_overrun)
15513
15514 ENTRY(invalid_TSS)
15515 RING0_EC_FRAME
15516 pushl_cfi $do_invalid_TSS
15517 jmp error_code
15518 CFI_ENDPROC
15519-END(invalid_TSS)
15520+ENDPROC(invalid_TSS)
15521
15522 ENTRY(segment_not_present)
15523 RING0_EC_FRAME
15524 pushl_cfi $do_segment_not_present
15525 jmp error_code
15526 CFI_ENDPROC
15527-END(segment_not_present)
15528+ENDPROC(segment_not_present)
15529
15530 ENTRY(stack_segment)
15531 RING0_EC_FRAME
15532 pushl_cfi $do_stack_segment
15533 jmp error_code
15534 CFI_ENDPROC
15535-END(stack_segment)
15536+ENDPROC(stack_segment)
15537
15538 ENTRY(alignment_check)
15539 RING0_EC_FRAME
15540 pushl_cfi $do_alignment_check
15541 jmp error_code
15542 CFI_ENDPROC
15543-END(alignment_check)
15544+ENDPROC(alignment_check)
15545
15546 ENTRY(divide_error)
15547 RING0_INT_FRAME
15548@@ -979,7 +1226,7 @@ ENTRY(divide_error)
15549 pushl_cfi $do_divide_error
15550 jmp error_code
15551 CFI_ENDPROC
15552-END(divide_error)
15553+ENDPROC(divide_error)
15554
15555 #ifdef CONFIG_X86_MCE
15556 ENTRY(machine_check)
15557@@ -988,7 +1235,7 @@ ENTRY(machine_check)
15558 pushl_cfi machine_check_vector
15559 jmp error_code
15560 CFI_ENDPROC
15561-END(machine_check)
15562+ENDPROC(machine_check)
15563 #endif
15564
15565 ENTRY(spurious_interrupt_bug)
15566@@ -997,7 +1244,7 @@ ENTRY(spurious_interrupt_bug)
15567 pushl_cfi $do_spurious_interrupt_bug
15568 jmp error_code
15569 CFI_ENDPROC
15570-END(spurious_interrupt_bug)
15571+ENDPROC(spurious_interrupt_bug)
15572 /*
15573 * End of kprobes section
15574 */
15575@@ -1112,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15576
15577 ENTRY(mcount)
15578 ret
15579-END(mcount)
15580+ENDPROC(mcount)
15581
15582 ENTRY(ftrace_caller)
15583 cmpl $0, function_trace_stop
15584@@ -1141,7 +1388,7 @@ ftrace_graph_call:
15585 .globl ftrace_stub
15586 ftrace_stub:
15587 ret
15588-END(ftrace_caller)
15589+ENDPROC(ftrace_caller)
15590
15591 #else /* ! CONFIG_DYNAMIC_FTRACE */
15592
15593@@ -1177,7 +1424,7 @@ trace:
15594 popl %ecx
15595 popl %eax
15596 jmp ftrace_stub
15597-END(mcount)
15598+ENDPROC(mcount)
15599 #endif /* CONFIG_DYNAMIC_FTRACE */
15600 #endif /* CONFIG_FUNCTION_TRACER */
15601
15602@@ -1198,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15603 popl %ecx
15604 popl %eax
15605 ret
15606-END(ftrace_graph_caller)
15607+ENDPROC(ftrace_graph_caller)
15608
15609 .globl return_to_handler
15610 return_to_handler:
15611@@ -1253,15 +1500,18 @@ error_code:
15612 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15613 REG_TO_PTGS %ecx
15614 SET_KERNEL_GS %ecx
15615- movl $(__USER_DS), %ecx
15616+ movl $(__KERNEL_DS), %ecx
15617 movl %ecx, %ds
15618 movl %ecx, %es
15619+
15620+ pax_enter_kernel
15621+
15622 TRACE_IRQS_OFF
15623 movl %esp,%eax # pt_regs pointer
15624 call *%edi
15625 jmp ret_from_exception
15626 CFI_ENDPROC
15627-END(page_fault)
15628+ENDPROC(page_fault)
15629
15630 /*
15631 * Debug traps and NMI can happen at the one SYSENTER instruction
15632@@ -1303,7 +1553,7 @@ debug_stack_correct:
15633 call do_debug
15634 jmp ret_from_exception
15635 CFI_ENDPROC
15636-END(debug)
15637+ENDPROC(debug)
15638
15639 /*
15640 * NMI is doubly nasty. It can happen _while_ we're handling
15641@@ -1340,6 +1590,9 @@ nmi_stack_correct:
15642 xorl %edx,%edx # zero error code
15643 movl %esp,%eax # pt_regs pointer
15644 call do_nmi
15645+
15646+ pax_exit_kernel
15647+
15648 jmp restore_all_notrace
15649 CFI_ENDPROC
15650
15651@@ -1376,12 +1629,15 @@ nmi_espfix_stack:
15652 FIXUP_ESPFIX_STACK # %eax == %esp
15653 xorl %edx,%edx # zero error code
15654 call do_nmi
15655+
15656+ pax_exit_kernel
15657+
15658 RESTORE_REGS
15659 lss 12+4(%esp), %esp # back to espfix stack
15660 CFI_ADJUST_CFA_OFFSET -24
15661 jmp irq_return
15662 CFI_ENDPROC
15663-END(nmi)
15664+ENDPROC(nmi)
15665
15666 ENTRY(int3)
15667 RING0_INT_FRAME
15668@@ -1393,14 +1649,14 @@ ENTRY(int3)
15669 call do_int3
15670 jmp ret_from_exception
15671 CFI_ENDPROC
15672-END(int3)
15673+ENDPROC(int3)
15674
15675 ENTRY(general_protection)
15676 RING0_EC_FRAME
15677 pushl_cfi $do_general_protection
15678 jmp error_code
15679 CFI_ENDPROC
15680-END(general_protection)
15681+ENDPROC(general_protection)
15682
15683 #ifdef CONFIG_KVM_GUEST
15684 ENTRY(async_page_fault)
15685@@ -1408,7 +1664,7 @@ ENTRY(async_page_fault)
15686 pushl_cfi $do_async_page_fault
15687 jmp error_code
15688 CFI_ENDPROC
15689-END(async_page_fault)
15690+ENDPROC(async_page_fault)
15691 #endif
15692
15693 /*
15694diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15695index cdc79b5..4710a75 100644
15696--- a/arch/x86/kernel/entry_64.S
15697+++ b/arch/x86/kernel/entry_64.S
15698@@ -56,6 +56,8 @@
15699 #include <asm/ftrace.h>
15700 #include <asm/percpu.h>
15701 #include <linux/err.h>
15702+#include <asm/pgtable.h>
15703+#include <asm/alternative-asm.h>
15704
15705 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15706 #include <linux/elf-em.h>
15707@@ -69,8 +71,9 @@
15708 #ifdef CONFIG_FUNCTION_TRACER
15709 #ifdef CONFIG_DYNAMIC_FTRACE
15710 ENTRY(mcount)
15711+ pax_force_retaddr
15712 retq
15713-END(mcount)
15714+ENDPROC(mcount)
15715
15716 ENTRY(ftrace_caller)
15717 cmpl $0, function_trace_stop
15718@@ -93,8 +96,9 @@ GLOBAL(ftrace_graph_call)
15719 #endif
15720
15721 GLOBAL(ftrace_stub)
15722+ pax_force_retaddr
15723 retq
15724-END(ftrace_caller)
15725+ENDPROC(ftrace_caller)
15726
15727 #else /* ! CONFIG_DYNAMIC_FTRACE */
15728 ENTRY(mcount)
15729@@ -113,6 +117,7 @@ ENTRY(mcount)
15730 #endif
15731
15732 GLOBAL(ftrace_stub)
15733+ pax_force_retaddr
15734 retq
15735
15736 trace:
15737@@ -122,12 +127,13 @@ trace:
15738 movq 8(%rbp), %rsi
15739 subq $MCOUNT_INSN_SIZE, %rdi
15740
15741+ pax_force_fptr ftrace_trace_function
15742 call *ftrace_trace_function
15743
15744 MCOUNT_RESTORE_FRAME
15745
15746 jmp ftrace_stub
15747-END(mcount)
15748+ENDPROC(mcount)
15749 #endif /* CONFIG_DYNAMIC_FTRACE */
15750 #endif /* CONFIG_FUNCTION_TRACER */
15751
15752@@ -147,8 +153,9 @@ ENTRY(ftrace_graph_caller)
15753
15754 MCOUNT_RESTORE_FRAME
15755
15756+ pax_force_retaddr
15757 retq
15758-END(ftrace_graph_caller)
15759+ENDPROC(ftrace_graph_caller)
15760
15761 GLOBAL(return_to_handler)
15762 subq $24, %rsp
15763@@ -164,6 +171,7 @@ GLOBAL(return_to_handler)
15764 movq 8(%rsp), %rdx
15765 movq (%rsp), %rax
15766 addq $24, %rsp
15767+ pax_force_fptr %rdi
15768 jmp *%rdi
15769 #endif
15770
15771@@ -179,6 +187,282 @@ ENTRY(native_usergs_sysret64)
15772 ENDPROC(native_usergs_sysret64)
15773 #endif /* CONFIG_PARAVIRT */
15774
15775+ .macro ljmpq sel, off
15776+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15777+ .byte 0x48; ljmp *1234f(%rip)
15778+ .pushsection .rodata
15779+ .align 16
15780+ 1234: .quad \off; .word \sel
15781+ .popsection
15782+#else
15783+ pushq $\sel
15784+ pushq $\off
15785+ lretq
15786+#endif
15787+ .endm
15788+
15789+ .macro pax_enter_kernel
15790+ pax_set_fptr_mask
15791+#ifdef CONFIG_PAX_KERNEXEC
15792+ call pax_enter_kernel
15793+#endif
15794+ .endm
15795+
15796+ .macro pax_exit_kernel
15797+#ifdef CONFIG_PAX_KERNEXEC
15798+ call pax_exit_kernel
15799+#endif
15800+ .endm
15801+
15802+#ifdef CONFIG_PAX_KERNEXEC
15803+ENTRY(pax_enter_kernel)
15804+ pushq %rdi
15805+
15806+#ifdef CONFIG_PARAVIRT
15807+ PV_SAVE_REGS(CLBR_RDI)
15808+#endif
15809+
15810+ GET_CR0_INTO_RDI
15811+ bts $16,%rdi
15812+ jnc 3f
15813+ mov %cs,%edi
15814+ cmp $__KERNEL_CS,%edi
15815+ jnz 2f
15816+1:
15817+
15818+#ifdef CONFIG_PARAVIRT
15819+ PV_RESTORE_REGS(CLBR_RDI)
15820+#endif
15821+
15822+ popq %rdi
15823+ pax_force_retaddr
15824+ retq
15825+
15826+2: ljmpq __KERNEL_CS,1f
15827+3: ljmpq __KERNEXEC_KERNEL_CS,4f
15828+4: SET_RDI_INTO_CR0
15829+ jmp 1b
15830+ENDPROC(pax_enter_kernel)
15831+
15832+ENTRY(pax_exit_kernel)
15833+ pushq %rdi
15834+
15835+#ifdef CONFIG_PARAVIRT
15836+ PV_SAVE_REGS(CLBR_RDI)
15837+#endif
15838+
15839+ mov %cs,%rdi
15840+ cmp $__KERNEXEC_KERNEL_CS,%edi
15841+ jz 2f
15842+1:
15843+
15844+#ifdef CONFIG_PARAVIRT
15845+ PV_RESTORE_REGS(CLBR_RDI);
15846+#endif
15847+
15848+ popq %rdi
15849+ pax_force_retaddr
15850+ retq
15851+
15852+2: GET_CR0_INTO_RDI
15853+ btr $16,%rdi
15854+ ljmpq __KERNEL_CS,3f
15855+3: SET_RDI_INTO_CR0
15856+ jmp 1b
15857+#ifdef CONFIG_PARAVIRT
15858+ PV_RESTORE_REGS(CLBR_RDI);
15859+#endif
15860+
15861+ popq %rdi
15862+ pax_force_retaddr
15863+ retq
15864+ENDPROC(pax_exit_kernel)
15865+#endif
15866+
15867+ .macro pax_enter_kernel_user
15868+ pax_set_fptr_mask
15869+#ifdef CONFIG_PAX_MEMORY_UDEREF
15870+ call pax_enter_kernel_user
15871+#endif
15872+ .endm
15873+
15874+ .macro pax_exit_kernel_user
15875+#ifdef CONFIG_PAX_MEMORY_UDEREF
15876+ call pax_exit_kernel_user
15877+#endif
15878+#ifdef CONFIG_PAX_RANDKSTACK
15879+ pushq %rax
15880+ call pax_randomize_kstack
15881+ popq %rax
15882+#endif
15883+ .endm
15884+
15885+#ifdef CONFIG_PAX_MEMORY_UDEREF
15886+ENTRY(pax_enter_kernel_user)
15887+ pushq %rdi
15888+ pushq %rbx
15889+
15890+#ifdef CONFIG_PARAVIRT
15891+ PV_SAVE_REGS(CLBR_RDI)
15892+#endif
15893+
15894+ GET_CR3_INTO_RDI
15895+ mov %rdi,%rbx
15896+ add $__START_KERNEL_map,%rbx
15897+ sub phys_base(%rip),%rbx
15898+
15899+#ifdef CONFIG_PARAVIRT
15900+ pushq %rdi
15901+ cmpl $0, pv_info+PARAVIRT_enabled
15902+ jz 1f
15903+ i = 0
15904+ .rept USER_PGD_PTRS
15905+ mov i*8(%rbx),%rsi
15906+ mov $0,%sil
15907+ lea i*8(%rbx),%rdi
15908+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15909+ i = i + 1
15910+ .endr
15911+ jmp 2f
15912+1:
15913+#endif
15914+
15915+ i = 0
15916+ .rept USER_PGD_PTRS
15917+ movb $0,i*8(%rbx)
15918+ i = i + 1
15919+ .endr
15920+
15921+#ifdef CONFIG_PARAVIRT
15922+2: popq %rdi
15923+#endif
15924+ SET_RDI_INTO_CR3
15925+
15926+#ifdef CONFIG_PAX_KERNEXEC
15927+ GET_CR0_INTO_RDI
15928+ bts $16,%rdi
15929+ SET_RDI_INTO_CR0
15930+#endif
15931+
15932+#ifdef CONFIG_PARAVIRT
15933+ PV_RESTORE_REGS(CLBR_RDI)
15934+#endif
15935+
15936+ popq %rbx
15937+ popq %rdi
15938+ pax_force_retaddr
15939+ retq
15940+ENDPROC(pax_enter_kernel_user)
15941+
15942+ENTRY(pax_exit_kernel_user)
15943+ push %rdi
15944+
15945+#ifdef CONFIG_PARAVIRT
15946+ pushq %rbx
15947+ PV_SAVE_REGS(CLBR_RDI)
15948+#endif
15949+
15950+#ifdef CONFIG_PAX_KERNEXEC
15951+ GET_CR0_INTO_RDI
15952+ btr $16,%rdi
15953+ SET_RDI_INTO_CR0
15954+#endif
15955+
15956+ GET_CR3_INTO_RDI
15957+ add $__START_KERNEL_map,%rdi
15958+ sub phys_base(%rip),%rdi
15959+
15960+#ifdef CONFIG_PARAVIRT
15961+ cmpl $0, pv_info+PARAVIRT_enabled
15962+ jz 1f
15963+ mov %rdi,%rbx
15964+ i = 0
15965+ .rept USER_PGD_PTRS
15966+ mov i*8(%rbx),%rsi
15967+ mov $0x67,%sil
15968+ lea i*8(%rbx),%rdi
15969+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15970+ i = i + 1
15971+ .endr
15972+ jmp 2f
15973+1:
15974+#endif
15975+
15976+ i = 0
15977+ .rept USER_PGD_PTRS
15978+ movb $0x67,i*8(%rdi)
15979+ i = i + 1
15980+ .endr
15981+
15982+#ifdef CONFIG_PARAVIRT
15983+2: PV_RESTORE_REGS(CLBR_RDI)
15984+ popq %rbx
15985+#endif
15986+
15987+ popq %rdi
15988+ pax_force_retaddr
15989+ retq
15990+ENDPROC(pax_exit_kernel_user)
15991+#endif
15992+
15993+.macro pax_erase_kstack
15994+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15995+ call pax_erase_kstack
15996+#endif
15997+.endm
15998+
15999+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16000+/*
16001+ * r11: thread_info
16002+ * rcx, rdx: can be clobbered
16003+ */
16004+ENTRY(pax_erase_kstack)
16005+ pushq %rdi
16006+ pushq %rax
16007+ pushq %r11
16008+
16009+ GET_THREAD_INFO(%r11)
16010+ mov TI_lowest_stack(%r11), %rdi
16011+ mov $-0xBEEF, %rax
16012+ std
16013+
16014+1: mov %edi, %ecx
16015+ and $THREAD_SIZE_asm - 1, %ecx
16016+ shr $3, %ecx
16017+ repne scasq
16018+ jecxz 2f
16019+
16020+ cmp $2*8, %ecx
16021+ jc 2f
16022+
16023+ mov $2*8, %ecx
16024+ repe scasq
16025+ jecxz 2f
16026+ jne 1b
16027+
16028+2: cld
16029+ mov %esp, %ecx
16030+ sub %edi, %ecx
16031+
16032+ cmp $THREAD_SIZE_asm, %rcx
16033+ jb 3f
16034+ ud2
16035+3:
16036+
16037+ shr $3, %ecx
16038+ rep stosq
16039+
16040+ mov TI_task_thread_sp0(%r11), %rdi
16041+ sub $256, %rdi
16042+ mov %rdi, TI_lowest_stack(%r11)
16043+
16044+ popq %r11
16045+ popq %rax
16046+ popq %rdi
16047+ pax_force_retaddr
16048+ ret
16049+ENDPROC(pax_erase_kstack)
16050+#endif
16051
16052 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16053 #ifdef CONFIG_TRACE_IRQFLAGS
16054@@ -232,8 +516,8 @@ ENDPROC(native_usergs_sysret64)
16055 .endm
16056
16057 .macro UNFAKE_STACK_FRAME
16058- addq $8*6, %rsp
16059- CFI_ADJUST_CFA_OFFSET -(6*8)
16060+ addq $8*6 + ARG_SKIP, %rsp
16061+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16062 .endm
16063
16064 /*
16065@@ -320,7 +604,7 @@ ENDPROC(native_usergs_sysret64)
16066 movq %rsp, %rsi
16067
16068 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16069- testl $3, CS-RBP(%rsi)
16070+ testb $3, CS-RBP(%rsi)
16071 je 1f
16072 SWAPGS
16073 /*
16074@@ -355,9 +639,10 @@ ENTRY(save_rest)
16075 movq_cfi r15, R15+16
16076 movq %r11, 8(%rsp) /* return address */
16077 FIXUP_TOP_OF_STACK %r11, 16
16078+ pax_force_retaddr
16079 ret
16080 CFI_ENDPROC
16081-END(save_rest)
16082+ENDPROC(save_rest)
16083
16084 /* save complete stack frame */
16085 .pushsection .kprobes.text, "ax"
16086@@ -386,9 +671,10 @@ ENTRY(save_paranoid)
16087 js 1f /* negative -> in kernel */
16088 SWAPGS
16089 xorl %ebx,%ebx
16090-1: ret
16091+1: pax_force_retaddr_bts
16092+ ret
16093 CFI_ENDPROC
16094-END(save_paranoid)
16095+ENDPROC(save_paranoid)
16096 .popsection
16097
16098 /*
16099@@ -410,7 +696,7 @@ ENTRY(ret_from_fork)
16100
16101 RESTORE_REST
16102
16103- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16104+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16105 jz retint_restore_args
16106
16107 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16108@@ -420,7 +706,7 @@ ENTRY(ret_from_fork)
16109 jmp ret_from_sys_call # go to the SYSRET fastpath
16110
16111 CFI_ENDPROC
16112-END(ret_from_fork)
16113+ENDPROC(ret_from_fork)
16114
16115 /*
16116 * System call entry. Up to 6 arguments in registers are supported.
16117@@ -456,7 +742,7 @@ END(ret_from_fork)
16118 ENTRY(system_call)
16119 CFI_STARTPROC simple
16120 CFI_SIGNAL_FRAME
16121- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16122+ CFI_DEF_CFA rsp,0
16123 CFI_REGISTER rip,rcx
16124 /*CFI_REGISTER rflags,r11*/
16125 SWAPGS_UNSAFE_STACK
16126@@ -469,16 +755,18 @@ GLOBAL(system_call_after_swapgs)
16127
16128 movq %rsp,PER_CPU_VAR(old_rsp)
16129 movq PER_CPU_VAR(kernel_stack),%rsp
16130+ SAVE_ARGS 8*6,0
16131+ pax_enter_kernel_user
16132 /*
16133 * No need to follow this irqs off/on section - it's straight
16134 * and short:
16135 */
16136 ENABLE_INTERRUPTS(CLBR_NONE)
16137- SAVE_ARGS 8,0
16138 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16139 movq %rcx,RIP-ARGOFFSET(%rsp)
16140 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16141- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16142+ GET_THREAD_INFO(%rcx)
16143+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16144 jnz tracesys
16145 system_call_fastpath:
16146 #if __SYSCALL_MASK == ~0
16147@@ -488,7 +776,7 @@ system_call_fastpath:
16148 cmpl $__NR_syscall_max,%eax
16149 #endif
16150 ja badsys
16151- movq %r10,%rcx
16152+ movq R10-ARGOFFSET(%rsp),%rcx
16153 call *sys_call_table(,%rax,8) # XXX: rip relative
16154 movq %rax,RAX-ARGOFFSET(%rsp)
16155 /*
16156@@ -502,10 +790,13 @@ sysret_check:
16157 LOCKDEP_SYS_EXIT
16158 DISABLE_INTERRUPTS(CLBR_NONE)
16159 TRACE_IRQS_OFF
16160- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16161+ GET_THREAD_INFO(%rcx)
16162+ movl TI_flags(%rcx),%edx
16163 andl %edi,%edx
16164 jnz sysret_careful
16165 CFI_REMEMBER_STATE
16166+ pax_exit_kernel_user
16167+ pax_erase_kstack
16168 /*
16169 * sysretq will re-enable interrupts:
16170 */
16171@@ -557,14 +848,18 @@ badsys:
16172 * jump back to the normal fast path.
16173 */
16174 auditsys:
16175- movq %r10,%r9 /* 6th arg: 4th syscall arg */
16176+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16177 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16178 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16179 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16180 movq %rax,%rsi /* 2nd arg: syscall number */
16181 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16182 call __audit_syscall_entry
16183+
16184+ pax_erase_kstack
16185+
16186 LOAD_ARGS 0 /* reload call-clobbered registers */
16187+ pax_set_fptr_mask
16188 jmp system_call_fastpath
16189
16190 /*
16191@@ -585,7 +880,7 @@ sysret_audit:
16192 /* Do syscall tracing */
16193 tracesys:
16194 #ifdef CONFIG_AUDITSYSCALL
16195- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16196+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16197 jz auditsys
16198 #endif
16199 SAVE_REST
16200@@ -593,12 +888,16 @@ tracesys:
16201 FIXUP_TOP_OF_STACK %rdi
16202 movq %rsp,%rdi
16203 call syscall_trace_enter
16204+
16205+ pax_erase_kstack
16206+
16207 /*
16208 * Reload arg registers from stack in case ptrace changed them.
16209 * We don't reload %rax because syscall_trace_enter() returned
16210 * the value it wants us to use in the table lookup.
16211 */
16212 LOAD_ARGS ARGOFFSET, 1
16213+ pax_set_fptr_mask
16214 RESTORE_REST
16215 #if __SYSCALL_MASK == ~0
16216 cmpq $__NR_syscall_max,%rax
16217@@ -607,7 +906,7 @@ tracesys:
16218 cmpl $__NR_syscall_max,%eax
16219 #endif
16220 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16221- movq %r10,%rcx /* fixup for C */
16222+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16223 call *sys_call_table(,%rax,8)
16224 movq %rax,RAX-ARGOFFSET(%rsp)
16225 /* Use IRET because user could have changed frame */
16226@@ -628,6 +927,7 @@ GLOBAL(int_with_check)
16227 andl %edi,%edx
16228 jnz int_careful
16229 andl $~TS_COMPAT,TI_status(%rcx)
16230+ pax_erase_kstack
16231 jmp retint_swapgs
16232
16233 /* Either reschedule or signal or syscall exit tracking needed. */
16234@@ -674,7 +974,7 @@ int_restore_rest:
16235 TRACE_IRQS_OFF
16236 jmp int_with_check
16237 CFI_ENDPROC
16238-END(system_call)
16239+ENDPROC(system_call)
16240
16241 /*
16242 * Certain special system calls that need to save a complete full stack frame.
16243@@ -690,7 +990,7 @@ ENTRY(\label)
16244 call \func
16245 jmp ptregscall_common
16246 CFI_ENDPROC
16247-END(\label)
16248+ENDPROC(\label)
16249 .endm
16250
16251 PTREGSCALL stub_clone, sys_clone, %r8
16252@@ -708,9 +1008,10 @@ ENTRY(ptregscall_common)
16253 movq_cfi_restore R12+8, r12
16254 movq_cfi_restore RBP+8, rbp
16255 movq_cfi_restore RBX+8, rbx
16256+ pax_force_retaddr
16257 ret $REST_SKIP /* pop extended registers */
16258 CFI_ENDPROC
16259-END(ptregscall_common)
16260+ENDPROC(ptregscall_common)
16261
16262 ENTRY(stub_execve)
16263 CFI_STARTPROC
16264@@ -725,7 +1026,7 @@ ENTRY(stub_execve)
16265 RESTORE_REST
16266 jmp int_ret_from_sys_call
16267 CFI_ENDPROC
16268-END(stub_execve)
16269+ENDPROC(stub_execve)
16270
16271 /*
16272 * sigreturn is special because it needs to restore all registers on return.
16273@@ -743,7 +1044,7 @@ ENTRY(stub_rt_sigreturn)
16274 RESTORE_REST
16275 jmp int_ret_from_sys_call
16276 CFI_ENDPROC
16277-END(stub_rt_sigreturn)
16278+ENDPROC(stub_rt_sigreturn)
16279
16280 #ifdef CONFIG_X86_X32_ABI
16281 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16282@@ -812,7 +1113,7 @@ vector=vector+1
16283 2: jmp common_interrupt
16284 .endr
16285 CFI_ENDPROC
16286-END(irq_entries_start)
16287+ENDPROC(irq_entries_start)
16288
16289 .previous
16290 END(interrupt)
16291@@ -832,6 +1133,16 @@ END(interrupt)
16292 subq $ORIG_RAX-RBP, %rsp
16293 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16294 SAVE_ARGS_IRQ
16295+#ifdef CONFIG_PAX_MEMORY_UDEREF
16296+ testb $3, CS(%rdi)
16297+ jnz 1f
16298+ pax_enter_kernel
16299+ jmp 2f
16300+1: pax_enter_kernel_user
16301+2:
16302+#else
16303+ pax_enter_kernel
16304+#endif
16305 call \func
16306 .endm
16307
16308@@ -863,7 +1174,7 @@ ret_from_intr:
16309
16310 exit_intr:
16311 GET_THREAD_INFO(%rcx)
16312- testl $3,CS-ARGOFFSET(%rsp)
16313+ testb $3,CS-ARGOFFSET(%rsp)
16314 je retint_kernel
16315
16316 /* Interrupt came from user space */
16317@@ -885,12 +1196,15 @@ retint_swapgs: /* return to user-space */
16318 * The iretq could re-enable interrupts:
16319 */
16320 DISABLE_INTERRUPTS(CLBR_ANY)
16321+ pax_exit_kernel_user
16322 TRACE_IRQS_IRETQ
16323 SWAPGS
16324 jmp restore_args
16325
16326 retint_restore_args: /* return to kernel space */
16327 DISABLE_INTERRUPTS(CLBR_ANY)
16328+ pax_exit_kernel
16329+ pax_force_retaddr RIP-ARGOFFSET
16330 /*
16331 * The iretq could re-enable interrupts:
16332 */
16333@@ -979,7 +1293,7 @@ ENTRY(retint_kernel)
16334 #endif
16335
16336 CFI_ENDPROC
16337-END(common_interrupt)
16338+ENDPROC(common_interrupt)
16339 /*
16340 * End of kprobes section
16341 */
16342@@ -996,7 +1310,7 @@ ENTRY(\sym)
16343 interrupt \do_sym
16344 jmp ret_from_intr
16345 CFI_ENDPROC
16346-END(\sym)
16347+ENDPROC(\sym)
16348 .endm
16349
16350 #ifdef CONFIG_SMP
16351@@ -1069,12 +1383,22 @@ ENTRY(\sym)
16352 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16353 call error_entry
16354 DEFAULT_FRAME 0
16355+#ifdef CONFIG_PAX_MEMORY_UDEREF
16356+ testb $3, CS(%rsp)
16357+ jnz 1f
16358+ pax_enter_kernel
16359+ jmp 2f
16360+1: pax_enter_kernel_user
16361+2:
16362+#else
16363+ pax_enter_kernel
16364+#endif
16365 movq %rsp,%rdi /* pt_regs pointer */
16366 xorl %esi,%esi /* no error code */
16367 call \do_sym
16368 jmp error_exit /* %ebx: no swapgs flag */
16369 CFI_ENDPROC
16370-END(\sym)
16371+ENDPROC(\sym)
16372 .endm
16373
16374 .macro paranoidzeroentry sym do_sym
16375@@ -1086,15 +1410,25 @@ ENTRY(\sym)
16376 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16377 call save_paranoid
16378 TRACE_IRQS_OFF
16379+#ifdef CONFIG_PAX_MEMORY_UDEREF
16380+ testb $3, CS(%rsp)
16381+ jnz 1f
16382+ pax_enter_kernel
16383+ jmp 2f
16384+1: pax_enter_kernel_user
16385+2:
16386+#else
16387+ pax_enter_kernel
16388+#endif
16389 movq %rsp,%rdi /* pt_regs pointer */
16390 xorl %esi,%esi /* no error code */
16391 call \do_sym
16392 jmp paranoid_exit /* %ebx: no swapgs flag */
16393 CFI_ENDPROC
16394-END(\sym)
16395+ENDPROC(\sym)
16396 .endm
16397
16398-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16399+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16400 .macro paranoidzeroentry_ist sym do_sym ist
16401 ENTRY(\sym)
16402 INTR_FRAME
16403@@ -1104,14 +1438,30 @@ ENTRY(\sym)
16404 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16405 call save_paranoid
16406 TRACE_IRQS_OFF
16407+#ifdef CONFIG_PAX_MEMORY_UDEREF
16408+ testb $3, CS(%rsp)
16409+ jnz 1f
16410+ pax_enter_kernel
16411+ jmp 2f
16412+1: pax_enter_kernel_user
16413+2:
16414+#else
16415+ pax_enter_kernel
16416+#endif
16417 movq %rsp,%rdi /* pt_regs pointer */
16418 xorl %esi,%esi /* no error code */
16419+#ifdef CONFIG_SMP
16420+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16421+ lea init_tss(%r12), %r12
16422+#else
16423+ lea init_tss(%rip), %r12
16424+#endif
16425 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16426 call \do_sym
16427 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16428 jmp paranoid_exit /* %ebx: no swapgs flag */
16429 CFI_ENDPROC
16430-END(\sym)
16431+ENDPROC(\sym)
16432 .endm
16433
16434 .macro errorentry sym do_sym
16435@@ -1122,13 +1472,23 @@ ENTRY(\sym)
16436 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16437 call error_entry
16438 DEFAULT_FRAME 0
16439+#ifdef CONFIG_PAX_MEMORY_UDEREF
16440+ testb $3, CS(%rsp)
16441+ jnz 1f
16442+ pax_enter_kernel
16443+ jmp 2f
16444+1: pax_enter_kernel_user
16445+2:
16446+#else
16447+ pax_enter_kernel
16448+#endif
16449 movq %rsp,%rdi /* pt_regs pointer */
16450 movq ORIG_RAX(%rsp),%rsi /* get error code */
16451 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16452 call \do_sym
16453 jmp error_exit /* %ebx: no swapgs flag */
16454 CFI_ENDPROC
16455-END(\sym)
16456+ENDPROC(\sym)
16457 .endm
16458
16459 /* error code is on the stack already */
16460@@ -1141,13 +1501,23 @@ ENTRY(\sym)
16461 call save_paranoid
16462 DEFAULT_FRAME 0
16463 TRACE_IRQS_OFF
16464+#ifdef CONFIG_PAX_MEMORY_UDEREF
16465+ testb $3, CS(%rsp)
16466+ jnz 1f
16467+ pax_enter_kernel
16468+ jmp 2f
16469+1: pax_enter_kernel_user
16470+2:
16471+#else
16472+ pax_enter_kernel
16473+#endif
16474 movq %rsp,%rdi /* pt_regs pointer */
16475 movq ORIG_RAX(%rsp),%rsi /* get error code */
16476 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16477 call \do_sym
16478 jmp paranoid_exit /* %ebx: no swapgs flag */
16479 CFI_ENDPROC
16480-END(\sym)
16481+ENDPROC(\sym)
16482 .endm
16483
16484 zeroentry divide_error do_divide_error
16485@@ -1177,9 +1547,10 @@ gs_change:
16486 2: mfence /* workaround */
16487 SWAPGS
16488 popfq_cfi
16489+ pax_force_retaddr
16490 ret
16491 CFI_ENDPROC
16492-END(native_load_gs_index)
16493+ENDPROC(native_load_gs_index)
16494
16495 .section __ex_table,"a"
16496 .align 8
16497@@ -1201,13 +1572,14 @@ ENTRY(kernel_thread_helper)
16498 * Here we are in the child and the registers are set as they were
16499 * at kernel_thread() invocation in the parent.
16500 */
16501+ pax_force_fptr %rsi
16502 call *%rsi
16503 # exit
16504 mov %eax, %edi
16505 call do_exit
16506 ud2 # padding for call trace
16507 CFI_ENDPROC
16508-END(kernel_thread_helper)
16509+ENDPROC(kernel_thread_helper)
16510
16511 /*
16512 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16513@@ -1234,11 +1606,11 @@ ENTRY(kernel_execve)
16514 RESTORE_REST
16515 testq %rax,%rax
16516 je int_ret_from_sys_call
16517- RESTORE_ARGS
16518 UNFAKE_STACK_FRAME
16519+ pax_force_retaddr
16520 ret
16521 CFI_ENDPROC
16522-END(kernel_execve)
16523+ENDPROC(kernel_execve)
16524
16525 /* Call softirq on interrupt stack. Interrupts are off. */
16526 ENTRY(call_softirq)
16527@@ -1256,9 +1628,10 @@ ENTRY(call_softirq)
16528 CFI_DEF_CFA_REGISTER rsp
16529 CFI_ADJUST_CFA_OFFSET -8
16530 decl PER_CPU_VAR(irq_count)
16531+ pax_force_retaddr
16532 ret
16533 CFI_ENDPROC
16534-END(call_softirq)
16535+ENDPROC(call_softirq)
16536
16537 #ifdef CONFIG_XEN
16538 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16539@@ -1296,7 +1669,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16540 decl PER_CPU_VAR(irq_count)
16541 jmp error_exit
16542 CFI_ENDPROC
16543-END(xen_do_hypervisor_callback)
16544+ENDPROC(xen_do_hypervisor_callback)
16545
16546 /*
16547 * Hypervisor uses this for application faults while it executes.
16548@@ -1355,7 +1728,7 @@ ENTRY(xen_failsafe_callback)
16549 SAVE_ALL
16550 jmp error_exit
16551 CFI_ENDPROC
16552-END(xen_failsafe_callback)
16553+ENDPROC(xen_failsafe_callback)
16554
16555 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16556 xen_hvm_callback_vector xen_evtchn_do_upcall
16557@@ -1404,16 +1777,31 @@ ENTRY(paranoid_exit)
16558 TRACE_IRQS_OFF
16559 testl %ebx,%ebx /* swapgs needed? */
16560 jnz paranoid_restore
16561- testl $3,CS(%rsp)
16562+ testb $3,CS(%rsp)
16563 jnz paranoid_userspace
16564+#ifdef CONFIG_PAX_MEMORY_UDEREF
16565+ pax_exit_kernel
16566+ TRACE_IRQS_IRETQ 0
16567+ SWAPGS_UNSAFE_STACK
16568+ RESTORE_ALL 8
16569+ pax_force_retaddr_bts
16570+ jmp irq_return
16571+#endif
16572 paranoid_swapgs:
16573+#ifdef CONFIG_PAX_MEMORY_UDEREF
16574+ pax_exit_kernel_user
16575+#else
16576+ pax_exit_kernel
16577+#endif
16578 TRACE_IRQS_IRETQ 0
16579 SWAPGS_UNSAFE_STACK
16580 RESTORE_ALL 8
16581 jmp irq_return
16582 paranoid_restore:
16583+ pax_exit_kernel
16584 TRACE_IRQS_IRETQ 0
16585 RESTORE_ALL 8
16586+ pax_force_retaddr_bts
16587 jmp irq_return
16588 paranoid_userspace:
16589 GET_THREAD_INFO(%rcx)
16590@@ -1442,7 +1830,7 @@ paranoid_schedule:
16591 TRACE_IRQS_OFF
16592 jmp paranoid_userspace
16593 CFI_ENDPROC
16594-END(paranoid_exit)
16595+ENDPROC(paranoid_exit)
16596
16597 /*
16598 * Exception entry point. This expects an error code/orig_rax on the stack.
16599@@ -1469,12 +1857,13 @@ ENTRY(error_entry)
16600 movq_cfi r14, R14+8
16601 movq_cfi r15, R15+8
16602 xorl %ebx,%ebx
16603- testl $3,CS+8(%rsp)
16604+ testb $3,CS+8(%rsp)
16605 je error_kernelspace
16606 error_swapgs:
16607 SWAPGS
16608 error_sti:
16609 TRACE_IRQS_OFF
16610+ pax_force_retaddr_bts
16611 ret
16612
16613 /*
16614@@ -1501,7 +1890,7 @@ bstep_iret:
16615 movq %rcx,RIP+8(%rsp)
16616 jmp error_swapgs
16617 CFI_ENDPROC
16618-END(error_entry)
16619+ENDPROC(error_entry)
16620
16621
16622 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16623@@ -1521,7 +1910,7 @@ ENTRY(error_exit)
16624 jnz retint_careful
16625 jmp retint_swapgs
16626 CFI_ENDPROC
16627-END(error_exit)
16628+ENDPROC(error_exit)
16629
16630 /*
16631 * Test if a given stack is an NMI stack or not.
16632@@ -1579,9 +1968,11 @@ ENTRY(nmi)
16633 * If %cs was not the kernel segment, then the NMI triggered in user
16634 * space, which means it is definitely not nested.
16635 */
16636+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16637+ je 1f
16638 cmpl $__KERNEL_CS, 16(%rsp)
16639 jne first_nmi
16640-
16641+1:
16642 /*
16643 * Check the special variable on the stack to see if NMIs are
16644 * executing.
16645@@ -1728,6 +2119,16 @@ end_repeat_nmi:
16646 */
16647 call save_paranoid
16648 DEFAULT_FRAME 0
16649+#ifdef CONFIG_PAX_MEMORY_UDEREF
16650+ testb $3, CS(%rsp)
16651+ jnz 1f
16652+ pax_enter_kernel
16653+ jmp 2f
16654+1: pax_enter_kernel_user
16655+2:
16656+#else
16657+ pax_enter_kernel
16658+#endif
16659 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16660 movq %rsp,%rdi
16661 movq $-1,%rsi
16662@@ -1735,21 +2136,32 @@ end_repeat_nmi:
16663 testl %ebx,%ebx /* swapgs needed? */
16664 jnz nmi_restore
16665 nmi_swapgs:
16666+#ifdef CONFIG_PAX_MEMORY_UDEREF
16667+ pax_exit_kernel_user
16668+#else
16669+ pax_exit_kernel
16670+#endif
16671 SWAPGS_UNSAFE_STACK
16672+ RESTORE_ALL 8
16673+ /* Clear the NMI executing stack variable */
16674+ movq $0, 10*8(%rsp)
16675+ jmp irq_return
16676 nmi_restore:
16677+ pax_exit_kernel
16678 RESTORE_ALL 8
16679+ pax_force_retaddr_bts
16680 /* Clear the NMI executing stack variable */
16681 movq $0, 10*8(%rsp)
16682 jmp irq_return
16683 CFI_ENDPROC
16684-END(nmi)
16685+ENDPROC(nmi)
16686
16687 ENTRY(ignore_sysret)
16688 CFI_STARTPROC
16689 mov $-ENOSYS,%eax
16690 sysret
16691 CFI_ENDPROC
16692-END(ignore_sysret)
16693+ENDPROC(ignore_sysret)
16694
16695 /*
16696 * End of kprobes section
16697diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16698index c9a281f..ce2f317 100644
16699--- a/arch/x86/kernel/ftrace.c
16700+++ b/arch/x86/kernel/ftrace.c
16701@@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
16702 static const void *mod_code_newcode; /* holds the text to write to the IP */
16703
16704 static unsigned nmi_wait_count;
16705-static atomic_t nmi_update_count = ATOMIC_INIT(0);
16706+static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
16707
16708 int ftrace_arch_read_dyn_info(char *buf, int size)
16709 {
16710@@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
16711
16712 r = snprintf(buf, size, "%u %u",
16713 nmi_wait_count,
16714- atomic_read(&nmi_update_count));
16715+ atomic_read_unchecked(&nmi_update_count));
16716 return r;
16717 }
16718
16719@@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
16720
16721 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
16722 smp_rmb();
16723+ pax_open_kernel();
16724 ftrace_mod_code();
16725- atomic_inc(&nmi_update_count);
16726+ pax_close_kernel();
16727+ atomic_inc_unchecked(&nmi_update_count);
16728 }
16729 /* Must have previous changes seen before executions */
16730 smp_mb();
16731@@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
16732 {
16733 unsigned char replaced[MCOUNT_INSN_SIZE];
16734
16735+ ip = ktla_ktva(ip);
16736+
16737 /*
16738 * Note: Due to modules and __init, code can
16739 * disappear and change, we need to protect against faulting
16740@@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16741 unsigned char old[MCOUNT_INSN_SIZE], *new;
16742 int ret;
16743
16744- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16745+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16746 new = ftrace_call_replace(ip, (unsigned long)func);
16747 ret = ftrace_modify_code(ip, old, new);
16748
16749@@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16750 {
16751 unsigned char code[MCOUNT_INSN_SIZE];
16752
16753+ ip = ktla_ktva(ip);
16754+
16755 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16756 return -EFAULT;
16757
16758diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16759index 51ff186..9e77418 100644
16760--- a/arch/x86/kernel/head32.c
16761+++ b/arch/x86/kernel/head32.c
16762@@ -19,6 +19,7 @@
16763 #include <asm/io_apic.h>
16764 #include <asm/bios_ebda.h>
16765 #include <asm/tlbflush.h>
16766+#include <asm/boot.h>
16767
16768 static void __init i386_default_early_setup(void)
16769 {
16770@@ -31,8 +32,7 @@ static void __init i386_default_early_setup(void)
16771
16772 void __init i386_start_kernel(void)
16773 {
16774- memblock_reserve(__pa_symbol(&_text),
16775- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16776+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16777
16778 #ifdef CONFIG_BLK_DEV_INITRD
16779 /* Reserve INITRD */
16780diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16781index ce0be7c..c41476e 100644
16782--- a/arch/x86/kernel/head_32.S
16783+++ b/arch/x86/kernel/head_32.S
16784@@ -25,6 +25,12 @@
16785 /* Physical address */
16786 #define pa(X) ((X) - __PAGE_OFFSET)
16787
16788+#ifdef CONFIG_PAX_KERNEXEC
16789+#define ta(X) (X)
16790+#else
16791+#define ta(X) ((X) - __PAGE_OFFSET)
16792+#endif
16793+
16794 /*
16795 * References to members of the new_cpu_data structure.
16796 */
16797@@ -54,11 +60,7 @@
16798 * and small than max_low_pfn, otherwise will waste some page table entries
16799 */
16800
16801-#if PTRS_PER_PMD > 1
16802-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16803-#else
16804-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16805-#endif
16806+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16807
16808 /* Number of possible pages in the lowmem region */
16809 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16810@@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16811 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16812
16813 /*
16814+ * Real beginning of normal "text" segment
16815+ */
16816+ENTRY(stext)
16817+ENTRY(_stext)
16818+
16819+/*
16820 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16821 * %esi points to the real-mode code as a 32-bit pointer.
16822 * CS and DS must be 4 GB flat segments, but we don't depend on
16823@@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16824 * can.
16825 */
16826 __HEAD
16827+
16828+#ifdef CONFIG_PAX_KERNEXEC
16829+ jmp startup_32
16830+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16831+.fill PAGE_SIZE-5,1,0xcc
16832+#endif
16833+
16834 ENTRY(startup_32)
16835 movl pa(stack_start),%ecx
16836
16837@@ -105,6 +120,57 @@ ENTRY(startup_32)
16838 2:
16839 leal -__PAGE_OFFSET(%ecx),%esp
16840
16841+#ifdef CONFIG_SMP
16842+ movl $pa(cpu_gdt_table),%edi
16843+ movl $__per_cpu_load,%eax
16844+ movw %ax,__KERNEL_PERCPU + 2(%edi)
16845+ rorl $16,%eax
16846+ movb %al,__KERNEL_PERCPU + 4(%edi)
16847+ movb %ah,__KERNEL_PERCPU + 7(%edi)
16848+ movl $__per_cpu_end - 1,%eax
16849+ subl $__per_cpu_start,%eax
16850+ movw %ax,__KERNEL_PERCPU + 0(%edi)
16851+#endif
16852+
16853+#ifdef CONFIG_PAX_MEMORY_UDEREF
16854+ movl $NR_CPUS,%ecx
16855+ movl $pa(cpu_gdt_table),%edi
16856+1:
16857+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16858+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16859+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16860+ addl $PAGE_SIZE_asm,%edi
16861+ loop 1b
16862+#endif
16863+
16864+#ifdef CONFIG_PAX_KERNEXEC
16865+ movl $pa(boot_gdt),%edi
16866+ movl $__LOAD_PHYSICAL_ADDR,%eax
16867+ movw %ax,__BOOT_CS + 2(%edi)
16868+ rorl $16,%eax
16869+ movb %al,__BOOT_CS + 4(%edi)
16870+ movb %ah,__BOOT_CS + 7(%edi)
16871+ rorl $16,%eax
16872+
16873+ ljmp $(__BOOT_CS),$1f
16874+1:
16875+
16876+ movl $NR_CPUS,%ecx
16877+ movl $pa(cpu_gdt_table),%edi
16878+ addl $__PAGE_OFFSET,%eax
16879+1:
16880+ movw %ax,__KERNEL_CS + 2(%edi)
16881+ movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16882+ rorl $16,%eax
16883+ movb %al,__KERNEL_CS + 4(%edi)
16884+ movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16885+ movb %ah,__KERNEL_CS + 7(%edi)
16886+ movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16887+ rorl $16,%eax
16888+ addl $PAGE_SIZE_asm,%edi
16889+ loop 1b
16890+#endif
16891+
16892 /*
16893 * Clear BSS first so that there are no surprises...
16894 */
16895@@ -195,8 +261,11 @@ ENTRY(startup_32)
16896 movl %eax, pa(max_pfn_mapped)
16897
16898 /* Do early initialization of the fixmap area */
16899- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16900- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16901+#ifdef CONFIG_COMPAT_VDSO
16902+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16903+#else
16904+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16905+#endif
16906 #else /* Not PAE */
16907
16908 page_pde_offset = (__PAGE_OFFSET >> 20);
16909@@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16910 movl %eax, pa(max_pfn_mapped)
16911
16912 /* Do early initialization of the fixmap area */
16913- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16914- movl %eax,pa(initial_page_table+0xffc)
16915+#ifdef CONFIG_COMPAT_VDSO
16916+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16917+#else
16918+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16919+#endif
16920 #endif
16921
16922 #ifdef CONFIG_PARAVIRT
16923@@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16924 cmpl $num_subarch_entries, %eax
16925 jae bad_subarch
16926
16927- movl pa(subarch_entries)(,%eax,4), %eax
16928- subl $__PAGE_OFFSET, %eax
16929- jmp *%eax
16930+ jmp *pa(subarch_entries)(,%eax,4)
16931
16932 bad_subarch:
16933 WEAK(lguest_entry)
16934@@ -255,10 +325,10 @@ WEAK(xen_entry)
16935 __INITDATA
16936
16937 subarch_entries:
16938- .long default_entry /* normal x86/PC */
16939- .long lguest_entry /* lguest hypervisor */
16940- .long xen_entry /* Xen hypervisor */
16941- .long default_entry /* Moorestown MID */
16942+ .long ta(default_entry) /* normal x86/PC */
16943+ .long ta(lguest_entry) /* lguest hypervisor */
16944+ .long ta(xen_entry) /* Xen hypervisor */
16945+ .long ta(default_entry) /* Moorestown MID */
16946 num_subarch_entries = (. - subarch_entries) / 4
16947 .previous
16948 #else
16949@@ -312,6 +382,7 @@ default_entry:
16950 orl %edx,%eax
16951 movl %eax,%cr4
16952
16953+#ifdef CONFIG_X86_PAE
16954 testb $X86_CR4_PAE, %al # check if PAE is enabled
16955 jz 6f
16956
16957@@ -340,6 +411,9 @@ default_entry:
16958 /* Make changes effective */
16959 wrmsr
16960
16961+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16962+#endif
16963+
16964 6:
16965
16966 /*
16967@@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
16968 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16969 movl %eax,%ss # after changing gdt.
16970
16971- movl $(__USER_DS),%eax # DS/ES contains default USER segment
16972+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16973 movl %eax,%ds
16974 movl %eax,%es
16975
16976@@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
16977 */
16978 cmpb $0,ready
16979 jne 1f
16980- movl $gdt_page,%eax
16981+ movl $cpu_gdt_table,%eax
16982 movl $stack_canary,%ecx
16983+#ifdef CONFIG_SMP
16984+ addl $__per_cpu_load,%ecx
16985+#endif
16986 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16987 shrl $16, %ecx
16988 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16989 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
16990 1:
16991-#endif
16992 movl $(__KERNEL_STACK_CANARY),%eax
16993+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16994+ movl $(__USER_DS),%eax
16995+#else
16996+ xorl %eax,%eax
16997+#endif
16998 movl %eax,%gs
16999
17000 xorl %eax,%eax # Clear LDT
17001@@ -558,22 +639,22 @@ early_page_fault:
17002 jmp early_fault
17003
17004 early_fault:
17005- cld
17006 #ifdef CONFIG_PRINTK
17007+ cmpl $1,%ss:early_recursion_flag
17008+ je hlt_loop
17009+ incl %ss:early_recursion_flag
17010+ cld
17011 pusha
17012 movl $(__KERNEL_DS),%eax
17013 movl %eax,%ds
17014 movl %eax,%es
17015- cmpl $2,early_recursion_flag
17016- je hlt_loop
17017- incl early_recursion_flag
17018 movl %cr2,%eax
17019 pushl %eax
17020 pushl %edx /* trapno */
17021 pushl $fault_msg
17022 call printk
17023+; call dump_stack
17024 #endif
17025- call dump_stack
17026 hlt_loop:
17027 hlt
17028 jmp hlt_loop
17029@@ -581,8 +662,11 @@ hlt_loop:
17030 /* This is the default interrupt "handler" :-) */
17031 ALIGN
17032 ignore_int:
17033- cld
17034 #ifdef CONFIG_PRINTK
17035+ cmpl $2,%ss:early_recursion_flag
17036+ je hlt_loop
17037+ incl %ss:early_recursion_flag
17038+ cld
17039 pushl %eax
17040 pushl %ecx
17041 pushl %edx
17042@@ -591,9 +675,6 @@ ignore_int:
17043 movl $(__KERNEL_DS),%eax
17044 movl %eax,%ds
17045 movl %eax,%es
17046- cmpl $2,early_recursion_flag
17047- je hlt_loop
17048- incl early_recursion_flag
17049 pushl 16(%esp)
17050 pushl 24(%esp)
17051 pushl 32(%esp)
17052@@ -622,29 +703,43 @@ ENTRY(initial_code)
17053 /*
17054 * BSS section
17055 */
17056-__PAGE_ALIGNED_BSS
17057- .align PAGE_SIZE
17058 #ifdef CONFIG_X86_PAE
17059+.section .initial_pg_pmd,"a",@progbits
17060 initial_pg_pmd:
17061 .fill 1024*KPMDS,4,0
17062 #else
17063+.section .initial_page_table,"a",@progbits
17064 ENTRY(initial_page_table)
17065 .fill 1024,4,0
17066 #endif
17067+.section .initial_pg_fixmap,"a",@progbits
17068 initial_pg_fixmap:
17069 .fill 1024,4,0
17070+.section .empty_zero_page,"a",@progbits
17071 ENTRY(empty_zero_page)
17072 .fill 4096,1,0
17073+.section .swapper_pg_dir,"a",@progbits
17074 ENTRY(swapper_pg_dir)
17075+#ifdef CONFIG_X86_PAE
17076+ .fill 4,8,0
17077+#else
17078 .fill 1024,4,0
17079+#endif
17080+
17081+/*
17082+ * The IDT has to be page-aligned to simplify the Pentium
17083+ * F0 0F bug workaround.. We have a special link segment
17084+ * for this.
17085+ */
17086+.section .idt,"a",@progbits
17087+ENTRY(idt_table)
17088+ .fill 256,8,0
17089
17090 /*
17091 * This starts the data section.
17092 */
17093 #ifdef CONFIG_X86_PAE
17094-__PAGE_ALIGNED_DATA
17095- /* Page-aligned for the benefit of paravirt? */
17096- .align PAGE_SIZE
17097+.section .initial_page_table,"a",@progbits
17098 ENTRY(initial_page_table)
17099 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17100 # if KPMDS == 3
17101@@ -663,18 +758,27 @@ ENTRY(initial_page_table)
17102 # error "Kernel PMDs should be 1, 2 or 3"
17103 # endif
17104 .align PAGE_SIZE /* needs to be page-sized too */
17105+
17106+#ifdef CONFIG_PAX_PER_CPU_PGD
17107+ENTRY(cpu_pgd)
17108+ .rept NR_CPUS
17109+ .fill 4,8,0
17110+ .endr
17111+#endif
17112+
17113 #endif
17114
17115 .data
17116 .balign 4
17117 ENTRY(stack_start)
17118- .long init_thread_union+THREAD_SIZE
17119+ .long init_thread_union+THREAD_SIZE-8
17120
17121+ready: .byte 0
17122+
17123+.section .rodata,"a",@progbits
17124 early_recursion_flag:
17125 .long 0
17126
17127-ready: .byte 0
17128-
17129 int_msg:
17130 .asciz "Unknown interrupt or fault at: %p %p %p\n"
17131
17132@@ -707,7 +811,7 @@ fault_msg:
17133 .word 0 # 32 bit align gdt_desc.address
17134 boot_gdt_descr:
17135 .word __BOOT_DS+7
17136- .long boot_gdt - __PAGE_OFFSET
17137+ .long pa(boot_gdt)
17138
17139 .word 0 # 32-bit align idt_desc.address
17140 idt_descr:
17141@@ -718,7 +822,7 @@ idt_descr:
17142 .word 0 # 32 bit align gdt_desc.address
17143 ENTRY(early_gdt_descr)
17144 .word GDT_ENTRIES*8-1
17145- .long gdt_page /* Overwritten for secondary CPUs */
17146+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
17147
17148 /*
17149 * The boot_gdt must mirror the equivalent in setup.S and is
17150@@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
17151 .align L1_CACHE_BYTES
17152 ENTRY(boot_gdt)
17153 .fill GDT_ENTRY_BOOT_CS,8,0
17154- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17155- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17156+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17157+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17158+
17159+ .align PAGE_SIZE_asm
17160+ENTRY(cpu_gdt_table)
17161+ .rept NR_CPUS
17162+ .quad 0x0000000000000000 /* NULL descriptor */
17163+ .quad 0x0000000000000000 /* 0x0b reserved */
17164+ .quad 0x0000000000000000 /* 0x13 reserved */
17165+ .quad 0x0000000000000000 /* 0x1b reserved */
17166+
17167+#ifdef CONFIG_PAX_KERNEXEC
17168+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17169+#else
17170+ .quad 0x0000000000000000 /* 0x20 unused */
17171+#endif
17172+
17173+ .quad 0x0000000000000000 /* 0x28 unused */
17174+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17175+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17176+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17177+ .quad 0x0000000000000000 /* 0x4b reserved */
17178+ .quad 0x0000000000000000 /* 0x53 reserved */
17179+ .quad 0x0000000000000000 /* 0x5b reserved */
17180+
17181+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17182+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17183+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17184+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17185+
17186+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17187+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17188+
17189+ /*
17190+ * Segments used for calling PnP BIOS have byte granularity.
17191+ * The code segments and data segments have fixed 64k limits,
17192+ * the transfer segment sizes are set at run time.
17193+ */
17194+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
17195+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
17196+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
17197+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
17198+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
17199+
17200+ /*
17201+ * The APM segments have byte granularity and their bases
17202+ * are set at run time. All have 64k limits.
17203+ */
17204+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17205+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17206+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
17207+
17208+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17209+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17210+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17211+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17212+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17213+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17214+
17215+ /* Be sure this is zeroed to avoid false validations in Xen */
17216+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17217+ .endr
17218diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17219index 40f4eb3..6d24d9d 100644
17220--- a/arch/x86/kernel/head_64.S
17221+++ b/arch/x86/kernel/head_64.S
17222@@ -19,6 +19,8 @@
17223 #include <asm/cache.h>
17224 #include <asm/processor-flags.h>
17225 #include <asm/percpu.h>
17226+#include <asm/cpufeature.h>
17227+#include <asm/alternative-asm.h>
17228
17229 #ifdef CONFIG_PARAVIRT
17230 #include <asm/asm-offsets.h>
17231@@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17232 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17233 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17234 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17235+L4_VMALLOC_START = pgd_index(VMALLOC_START)
17236+L3_VMALLOC_START = pud_index(VMALLOC_START)
17237+L4_VMALLOC_END = pgd_index(VMALLOC_END)
17238+L3_VMALLOC_END = pud_index(VMALLOC_END)
17239+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17240+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17241
17242 .text
17243 __HEAD
17244@@ -85,35 +93,23 @@ startup_64:
17245 */
17246 addq %rbp, init_level4_pgt + 0(%rip)
17247 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17248+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17249+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17250+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17251 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17252
17253 addq %rbp, level3_ident_pgt + 0(%rip)
17254+#ifndef CONFIG_XEN
17255+ addq %rbp, level3_ident_pgt + 8(%rip)
17256+#endif
17257
17258- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17259- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17260+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17261+
17262+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17263+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17264
17265 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17266-
17267- /* Add an Identity mapping if I am above 1G */
17268- leaq _text(%rip), %rdi
17269- andq $PMD_PAGE_MASK, %rdi
17270-
17271- movq %rdi, %rax
17272- shrq $PUD_SHIFT, %rax
17273- andq $(PTRS_PER_PUD - 1), %rax
17274- jz ident_complete
17275-
17276- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17277- leaq level3_ident_pgt(%rip), %rbx
17278- movq %rdx, 0(%rbx, %rax, 8)
17279-
17280- movq %rdi, %rax
17281- shrq $PMD_SHIFT, %rax
17282- andq $(PTRS_PER_PMD - 1), %rax
17283- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17284- leaq level2_spare_pgt(%rip), %rbx
17285- movq %rdx, 0(%rbx, %rax, 8)
17286-ident_complete:
17287+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17288
17289 /*
17290 * Fixup the kernel text+data virtual addresses. Note that
17291@@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
17292 * after the boot processor executes this code.
17293 */
17294
17295- /* Enable PAE mode and PGE */
17296- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17297+ /* Enable PAE mode and PSE/PGE */
17298+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17299 movq %rax, %cr4
17300
17301 /* Setup early boot stage 4 level pagetables. */
17302@@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
17303 movl $MSR_EFER, %ecx
17304 rdmsr
17305 btsl $_EFER_SCE, %eax /* Enable System Call */
17306- btl $20,%edi /* No Execute supported? */
17307+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17308 jnc 1f
17309 btsl $_EFER_NX, %eax
17310+ leaq init_level4_pgt(%rip), %rdi
17311+#ifndef CONFIG_EFI
17312+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17313+#endif
17314+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17315+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17316+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17317+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17318 1: wrmsr /* Make changes effective */
17319
17320 /* Setup cr0 */
17321@@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
17322 * jump. In addition we need to ensure %cs is set so we make this
17323 * a far return.
17324 */
17325+ pax_set_fptr_mask
17326 movq initial_code(%rip),%rax
17327 pushq $0 # fake return address to stop unwinder
17328 pushq $__KERNEL_CS # set correct cs
17329@@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
17330 bad_address:
17331 jmp bad_address
17332
17333- .section ".init.text","ax"
17334+ __INIT
17335 #ifdef CONFIG_EARLY_PRINTK
17336 .globl early_idt_handlers
17337 early_idt_handlers:
17338@@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
17339 #endif /* EARLY_PRINTK */
17340 1: hlt
17341 jmp 1b
17342+ .previous
17343
17344 #ifdef CONFIG_EARLY_PRINTK
17345+ __INITDATA
17346 early_recursion_flag:
17347 .long 0
17348+ .previous
17349
17350+ .section .rodata,"a",@progbits
17351 early_idt_msg:
17352 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17353 early_idt_ripmsg:
17354 .asciz "RIP %s\n"
17355+ .previous
17356 #endif /* CONFIG_EARLY_PRINTK */
17357- .previous
17358
17359+ .section .rodata,"a",@progbits
17360 #define NEXT_PAGE(name) \
17361 .balign PAGE_SIZE; \
17362 ENTRY(name)
17363@@ -338,7 +348,6 @@ ENTRY(name)
17364 i = i + 1 ; \
17365 .endr
17366
17367- .data
17368 /*
17369 * This default setting generates an ident mapping at address 0x100000
17370 * and a mapping for the kernel that precisely maps virtual address
17371@@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
17372 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17373 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17374 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17375+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
17376+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17377+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
17378+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17379+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17380+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17381 .org init_level4_pgt + L4_START_KERNEL*8, 0
17382 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17383 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17384
17385+#ifdef CONFIG_PAX_PER_CPU_PGD
17386+NEXT_PAGE(cpu_pgd)
17387+ .rept NR_CPUS
17388+ .fill 512,8,0
17389+ .endr
17390+#endif
17391+
17392 NEXT_PAGE(level3_ident_pgt)
17393 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17394+#ifdef CONFIG_XEN
17395 .fill 511,8,0
17396+#else
17397+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17398+ .fill 510,8,0
17399+#endif
17400+
17401+NEXT_PAGE(level3_vmalloc_start_pgt)
17402+ .fill 512,8,0
17403+
17404+NEXT_PAGE(level3_vmalloc_end_pgt)
17405+ .fill 512,8,0
17406+
17407+NEXT_PAGE(level3_vmemmap_pgt)
17408+ .fill L3_VMEMMAP_START,8,0
17409+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17410
17411 NEXT_PAGE(level3_kernel_pgt)
17412 .fill L3_START_KERNEL,8,0
17413@@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
17414 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17415 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17416
17417+NEXT_PAGE(level2_vmemmap_pgt)
17418+ .fill 512,8,0
17419+
17420 NEXT_PAGE(level2_fixmap_pgt)
17421- .fill 506,8,0
17422- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17423- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17424- .fill 5,8,0
17425+ .fill 507,8,0
17426+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17427+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17428+ .fill 4,8,0
17429
17430-NEXT_PAGE(level1_fixmap_pgt)
17431+NEXT_PAGE(level1_vsyscall_pgt)
17432 .fill 512,8,0
17433
17434-NEXT_PAGE(level2_ident_pgt)
17435- /* Since I easily can, map the first 1G.
17436+ /* Since I easily can, map the first 2G.
17437 * Don't set NX because code runs from these pages.
17438 */
17439- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17440+NEXT_PAGE(level2_ident_pgt)
17441+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17442
17443 NEXT_PAGE(level2_kernel_pgt)
17444 /*
17445@@ -389,37 +429,59 @@ NEXT_PAGE(level2_kernel_pgt)
17446 * If you want to increase this then increase MODULES_VADDR
17447 * too.)
17448 */
17449- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17450- KERNEL_IMAGE_SIZE/PMD_SIZE)
17451-
17452-NEXT_PAGE(level2_spare_pgt)
17453- .fill 512, 8, 0
17454+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17455
17456 #undef PMDS
17457 #undef NEXT_PAGE
17458
17459- .data
17460+ .align PAGE_SIZE
17461+ENTRY(cpu_gdt_table)
17462+ .rept NR_CPUS
17463+ .quad 0x0000000000000000 /* NULL descriptor */
17464+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17465+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
17466+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
17467+ .quad 0x00cffb000000ffff /* __USER32_CS */
17468+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17469+ .quad 0x00affb000000ffff /* __USER_CS */
17470+
17471+#ifdef CONFIG_PAX_KERNEXEC
17472+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17473+#else
17474+ .quad 0x0 /* unused */
17475+#endif
17476+
17477+ .quad 0,0 /* TSS */
17478+ .quad 0,0 /* LDT */
17479+ .quad 0,0,0 /* three TLS descriptors */
17480+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
17481+ /* asm/segment.h:GDT_ENTRIES must match this */
17482+
17483+ /* zero the remaining page */
17484+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17485+ .endr
17486+
17487 .align 16
17488 .globl early_gdt_descr
17489 early_gdt_descr:
17490 .word GDT_ENTRIES*8-1
17491 early_gdt_descr_base:
17492- .quad INIT_PER_CPU_VAR(gdt_page)
17493+ .quad cpu_gdt_table
17494
17495 ENTRY(phys_base)
17496 /* This must match the first entry in level2_kernel_pgt */
17497 .quad 0x0000000000000000
17498
17499 #include "../../x86/xen/xen-head.S"
17500-
17501- .section .bss, "aw", @nobits
17502+
17503+ .section .rodata,"a",@progbits
17504 .align L1_CACHE_BYTES
17505 ENTRY(idt_table)
17506- .skip IDT_ENTRIES * 16
17507+ .fill 512,8,0
17508
17509 .align L1_CACHE_BYTES
17510 ENTRY(nmi_idt_table)
17511- .skip IDT_ENTRIES * 16
17512+ .fill 512,8,0
17513
17514 __PAGE_ALIGNED_BSS
17515 .align PAGE_SIZE
17516diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17517index 9c3bd4a..e1d9b35 100644
17518--- a/arch/x86/kernel/i386_ksyms_32.c
17519+++ b/arch/x86/kernel/i386_ksyms_32.c
17520@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17521 EXPORT_SYMBOL(cmpxchg8b_emu);
17522 #endif
17523
17524+EXPORT_SYMBOL_GPL(cpu_gdt_table);
17525+
17526 /* Networking helper routines. */
17527 EXPORT_SYMBOL(csum_partial_copy_generic);
17528+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17529+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17530
17531 EXPORT_SYMBOL(__get_user_1);
17532 EXPORT_SYMBOL(__get_user_2);
17533@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17534
17535 EXPORT_SYMBOL(csum_partial);
17536 EXPORT_SYMBOL(empty_zero_page);
17537+
17538+#ifdef CONFIG_PAX_KERNEXEC
17539+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17540+#endif
17541diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17542index 2d6e649..df6e1af 100644
17543--- a/arch/x86/kernel/i387.c
17544+++ b/arch/x86/kernel/i387.c
17545@@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17546 static inline bool interrupted_user_mode(void)
17547 {
17548 struct pt_regs *regs = get_irq_regs();
17549- return regs && user_mode_vm(regs);
17550+ return regs && user_mode(regs);
17551 }
17552
17553 /*
17554diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17555index 36d1853..bf25736 100644
17556--- a/arch/x86/kernel/i8259.c
17557+++ b/arch/x86/kernel/i8259.c
17558@@ -209,7 +209,7 @@ spurious_8259A_irq:
17559 "spurious 8259A interrupt: IRQ%d.\n", irq);
17560 spurious_irq_mask |= irqmask;
17561 }
17562- atomic_inc(&irq_err_count);
17563+ atomic_inc_unchecked(&irq_err_count);
17564 /*
17565 * Theoretically we do not have to handle this IRQ,
17566 * but in Linux this does not cause problems and is
17567diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
17568index 43e9ccf..44ccf6f 100644
17569--- a/arch/x86/kernel/init_task.c
17570+++ b/arch/x86/kernel/init_task.c
17571@@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
17572 * way process stacks are handled. This is done by having a special
17573 * "init_task" linker map entry..
17574 */
17575-union thread_union init_thread_union __init_task_data =
17576- { INIT_THREAD_INFO(init_task) };
17577+union thread_union init_thread_union __init_task_data;
17578
17579 /*
17580 * Initial task structure.
17581@@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
17582 * section. Since TSS's are completely CPU-local, we want them
17583 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
17584 */
17585-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
17586-
17587+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
17588+EXPORT_SYMBOL(init_tss);
17589diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17590index 8c96897..be66bfa 100644
17591--- a/arch/x86/kernel/ioport.c
17592+++ b/arch/x86/kernel/ioport.c
17593@@ -6,6 +6,7 @@
17594 #include <linux/sched.h>
17595 #include <linux/kernel.h>
17596 #include <linux/capability.h>
17597+#include <linux/security.h>
17598 #include <linux/errno.h>
17599 #include <linux/types.h>
17600 #include <linux/ioport.h>
17601@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17602
17603 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17604 return -EINVAL;
17605+#ifdef CONFIG_GRKERNSEC_IO
17606+ if (turn_on && grsec_disable_privio) {
17607+ gr_handle_ioperm();
17608+ return -EPERM;
17609+ }
17610+#endif
17611 if (turn_on && !capable(CAP_SYS_RAWIO))
17612 return -EPERM;
17613
17614@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17615 * because the ->io_bitmap_max value must match the bitmap
17616 * contents:
17617 */
17618- tss = &per_cpu(init_tss, get_cpu());
17619+ tss = init_tss + get_cpu();
17620
17621 if (turn_on)
17622 bitmap_clear(t->io_bitmap_ptr, from, num);
17623@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17624 return -EINVAL;
17625 /* Trying to gain more privileges? */
17626 if (level > old) {
17627+#ifdef CONFIG_GRKERNSEC_IO
17628+ if (grsec_disable_privio) {
17629+ gr_handle_iopl();
17630+ return -EPERM;
17631+ }
17632+#endif
17633 if (!capable(CAP_SYS_RAWIO))
17634 return -EPERM;
17635 }
17636diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17637index 3dafc60..aa8e9c4 100644
17638--- a/arch/x86/kernel/irq.c
17639+++ b/arch/x86/kernel/irq.c
17640@@ -18,7 +18,7 @@
17641 #include <asm/mce.h>
17642 #include <asm/hw_irq.h>
17643
17644-atomic_t irq_err_count;
17645+atomic_unchecked_t irq_err_count;
17646
17647 /* Function pointer for generic interrupt vector handling */
17648 void (*x86_platform_ipi_callback)(void) = NULL;
17649@@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17650 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17651 seq_printf(p, " Machine check polls\n");
17652 #endif
17653- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17654+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17655 #if defined(CONFIG_X86_IO_APIC)
17656- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17657+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17658 #endif
17659 return 0;
17660 }
17661@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17662
17663 u64 arch_irq_stat(void)
17664 {
17665- u64 sum = atomic_read(&irq_err_count);
17666+ u64 sum = atomic_read_unchecked(&irq_err_count);
17667
17668 #ifdef CONFIG_X86_IO_APIC
17669- sum += atomic_read(&irq_mis_count);
17670+ sum += atomic_read_unchecked(&irq_mis_count);
17671 #endif
17672 return sum;
17673 }
17674diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17675index 58b7f27..e112d08 100644
17676--- a/arch/x86/kernel/irq_32.c
17677+++ b/arch/x86/kernel/irq_32.c
17678@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17679 __asm__ __volatile__("andl %%esp,%0" :
17680 "=r" (sp) : "0" (THREAD_SIZE - 1));
17681
17682- return sp < (sizeof(struct thread_info) + STACK_WARN);
17683+ return sp < STACK_WARN;
17684 }
17685
17686 static void print_stack_overflow(void)
17687@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17688 * per-CPU IRQ handling contexts (thread information and stack)
17689 */
17690 union irq_ctx {
17691- struct thread_info tinfo;
17692- u32 stack[THREAD_SIZE/sizeof(u32)];
17693+ unsigned long previous_esp;
17694+ u32 stack[THREAD_SIZE/sizeof(u32)];
17695 } __attribute__((aligned(THREAD_SIZE)));
17696
17697 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17698@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17699 static inline int
17700 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17701 {
17702- union irq_ctx *curctx, *irqctx;
17703+ union irq_ctx *irqctx;
17704 u32 *isp, arg1, arg2;
17705
17706- curctx = (union irq_ctx *) current_thread_info();
17707 irqctx = __this_cpu_read(hardirq_ctx);
17708
17709 /*
17710@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17711 * handler) we can't do that and just have to keep using the
17712 * current stack (which is the irq stack already after all)
17713 */
17714- if (unlikely(curctx == irqctx))
17715+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17716 return 0;
17717
17718 /* build the stack frame on the IRQ stack */
17719- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17720- irqctx->tinfo.task = curctx->tinfo.task;
17721- irqctx->tinfo.previous_esp = current_stack_pointer;
17722+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17723+ irqctx->previous_esp = current_stack_pointer;
17724
17725- /* Copy the preempt_count so that the [soft]irq checks work. */
17726- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17727+#ifdef CONFIG_PAX_MEMORY_UDEREF
17728+ __set_fs(MAKE_MM_SEG(0));
17729+#endif
17730
17731 if (unlikely(overflow))
17732 call_on_stack(print_stack_overflow, isp);
17733@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17734 : "0" (irq), "1" (desc), "2" (isp),
17735 "D" (desc->handle_irq)
17736 : "memory", "cc", "ecx");
17737+
17738+#ifdef CONFIG_PAX_MEMORY_UDEREF
17739+ __set_fs(current_thread_info()->addr_limit);
17740+#endif
17741+
17742 return 1;
17743 }
17744
17745@@ -121,29 +125,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17746 */
17747 void __cpuinit irq_ctx_init(int cpu)
17748 {
17749- union irq_ctx *irqctx;
17750-
17751 if (per_cpu(hardirq_ctx, cpu))
17752 return;
17753
17754- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17755- THREAD_FLAGS,
17756- THREAD_ORDER));
17757- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17758- irqctx->tinfo.cpu = cpu;
17759- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17760- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17761-
17762- per_cpu(hardirq_ctx, cpu) = irqctx;
17763-
17764- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17765- THREAD_FLAGS,
17766- THREAD_ORDER));
17767- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17768- irqctx->tinfo.cpu = cpu;
17769- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17770-
17771- per_cpu(softirq_ctx, cpu) = irqctx;
17772+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17773+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17774
17775 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17776 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17777@@ -152,7 +138,6 @@ void __cpuinit irq_ctx_init(int cpu)
17778 asmlinkage void do_softirq(void)
17779 {
17780 unsigned long flags;
17781- struct thread_info *curctx;
17782 union irq_ctx *irqctx;
17783 u32 *isp;
17784
17785@@ -162,15 +147,22 @@ asmlinkage void do_softirq(void)
17786 local_irq_save(flags);
17787
17788 if (local_softirq_pending()) {
17789- curctx = current_thread_info();
17790 irqctx = __this_cpu_read(softirq_ctx);
17791- irqctx->tinfo.task = curctx->task;
17792- irqctx->tinfo.previous_esp = current_stack_pointer;
17793+ irqctx->previous_esp = current_stack_pointer;
17794
17795 /* build the stack frame on the softirq stack */
17796- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17797+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17798+
17799+#ifdef CONFIG_PAX_MEMORY_UDEREF
17800+ __set_fs(MAKE_MM_SEG(0));
17801+#endif
17802
17803 call_on_stack(__do_softirq, isp);
17804+
17805+#ifdef CONFIG_PAX_MEMORY_UDEREF
17806+ __set_fs(current_thread_info()->addr_limit);
17807+#endif
17808+
17809 /*
17810 * Shouldn't happen, we returned above if in_interrupt():
17811 */
17812@@ -191,7 +183,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17813 if (unlikely(!desc))
17814 return false;
17815
17816- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17817+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17818 if (unlikely(overflow))
17819 print_stack_overflow();
17820 desc->handle_irq(irq, desc);
17821diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17822index d04d3ec..ea4b374 100644
17823--- a/arch/x86/kernel/irq_64.c
17824+++ b/arch/x86/kernel/irq_64.c
17825@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17826 u64 estack_top, estack_bottom;
17827 u64 curbase = (u64)task_stack_page(current);
17828
17829- if (user_mode_vm(regs))
17830+ if (user_mode(regs))
17831 return;
17832
17833 if (regs->sp >= curbase + sizeof(struct thread_info) +
17834diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17835index 1d5d31e..ab846ed 100644
17836--- a/arch/x86/kernel/kdebugfs.c
17837+++ b/arch/x86/kernel/kdebugfs.c
17838@@ -28,6 +28,8 @@ struct setup_data_node {
17839 };
17840
17841 static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17842+ size_t count, loff_t *ppos) __size_overflow(3);
17843+static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17844 size_t count, loff_t *ppos)
17845 {
17846 struct setup_data_node *node = file->private_data;
17847diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17848index 8bfb614..2b3b35f 100644
17849--- a/arch/x86/kernel/kgdb.c
17850+++ b/arch/x86/kernel/kgdb.c
17851@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17852 #ifdef CONFIG_X86_32
17853 switch (regno) {
17854 case GDB_SS:
17855- if (!user_mode_vm(regs))
17856+ if (!user_mode(regs))
17857 *(unsigned long *)mem = __KERNEL_DS;
17858 break;
17859 case GDB_SP:
17860- if (!user_mode_vm(regs))
17861+ if (!user_mode(regs))
17862 *(unsigned long *)mem = kernel_stack_pointer(regs);
17863 break;
17864 case GDB_GS:
17865@@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17866 case 'k':
17867 /* clear the trace bit */
17868 linux_regs->flags &= ~X86_EFLAGS_TF;
17869- atomic_set(&kgdb_cpu_doing_single_step, -1);
17870+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17871
17872 /* set the trace bit if we're stepping */
17873 if (remcomInBuffer[0] == 's') {
17874 linux_regs->flags |= X86_EFLAGS_TF;
17875- atomic_set(&kgdb_cpu_doing_single_step,
17876+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17877 raw_smp_processor_id());
17878 }
17879
17880@@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17881
17882 switch (cmd) {
17883 case DIE_DEBUG:
17884- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17885+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17886 if (user_mode(regs))
17887 return single_step_cont(regs, args);
17888 break;
17889diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17890index c5e410e..da6aaf9 100644
17891--- a/arch/x86/kernel/kprobes-opt.c
17892+++ b/arch/x86/kernel/kprobes-opt.c
17893@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17894 * Verify if the address gap is in 2GB range, because this uses
17895 * a relative jump.
17896 */
17897- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17898+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17899 if (abs(rel) > 0x7fffffff)
17900 return -ERANGE;
17901
17902@@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17903 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17904
17905 /* Set probe function call */
17906- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17907+ synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17908
17909 /* Set returning jmp instruction at the tail of out-of-line buffer */
17910 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17911- (u8 *)op->kp.addr + op->optinsn.size);
17912+ (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17913
17914 flush_icache_range((unsigned long) buf,
17915 (unsigned long) buf + TMPL_END_IDX +
17916@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17917 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17918
17919 /* Backup instructions which will be replaced by jump address */
17920- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17921+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17922 RELATIVE_ADDR_SIZE);
17923
17924 insn_buf[0] = RELATIVEJUMP_OPCODE;
17925diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17926index e213fc8..d783ba4 100644
17927--- a/arch/x86/kernel/kprobes.c
17928+++ b/arch/x86/kernel/kprobes.c
17929@@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17930 } __attribute__((packed)) *insn;
17931
17932 insn = (struct __arch_relative_insn *)from;
17933+
17934+ pax_open_kernel();
17935 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17936 insn->op = op;
17937+ pax_close_kernel();
17938 }
17939
17940 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17941@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17942 kprobe_opcode_t opcode;
17943 kprobe_opcode_t *orig_opcodes = opcodes;
17944
17945- if (search_exception_tables((unsigned long)opcodes))
17946+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17947 return 0; /* Page fault may occur on this address. */
17948
17949 retry:
17950@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17951 /* Another subsystem puts a breakpoint, failed to recover */
17952 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
17953 return 0;
17954+ pax_open_kernel();
17955 memcpy(dest, insn.kaddr, insn.length);
17956+ pax_close_kernel();
17957
17958 #ifdef CONFIG_X86_64
17959 if (insn_rip_relative(&insn)) {
17960@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17961 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
17962 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17963 disp = (u8 *) dest + insn_offset_displacement(&insn);
17964+ pax_open_kernel();
17965 *(s32 *) disp = (s32) newdisp;
17966+ pax_close_kernel();
17967 }
17968 #endif
17969 return insn.length;
17970@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17971 * nor set current_kprobe, because it doesn't use single
17972 * stepping.
17973 */
17974- regs->ip = (unsigned long)p->ainsn.insn;
17975+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17976 preempt_enable_no_resched();
17977 return;
17978 }
17979@@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17980 if (p->opcode == BREAKPOINT_INSTRUCTION)
17981 regs->ip = (unsigned long)p->addr;
17982 else
17983- regs->ip = (unsigned long)p->ainsn.insn;
17984+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17985 }
17986
17987 /*
17988@@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17989 setup_singlestep(p, regs, kcb, 0);
17990 return 1;
17991 }
17992- } else if (*addr != BREAKPOINT_INSTRUCTION) {
17993+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17994 /*
17995 * The breakpoint instruction was removed right
17996 * after we hit it. Another cpu has removed
17997@@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17998 " movq %rax, 152(%rsp)\n"
17999 RESTORE_REGS_STRING
18000 " popfq\n"
18001+#ifdef KERNEXEC_PLUGIN
18002+ " btsq $63,(%rsp)\n"
18003+#endif
18004 #else
18005 " pushf\n"
18006 SAVE_REGS_STRING
18007@@ -765,7 +775,7 @@ static void __kprobes
18008 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18009 {
18010 unsigned long *tos = stack_addr(regs);
18011- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18012+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18013 unsigned long orig_ip = (unsigned long)p->addr;
18014 kprobe_opcode_t *insn = p->ainsn.insn;
18015
18016@@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
18017 struct die_args *args = data;
18018 int ret = NOTIFY_DONE;
18019
18020- if (args->regs && user_mode_vm(args->regs))
18021+ if (args->regs && user_mode(args->regs))
18022 return ret;
18023
18024 switch (val) {
18025diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18026index ebc9873..1b9724b 100644
18027--- a/arch/x86/kernel/ldt.c
18028+++ b/arch/x86/kernel/ldt.c
18029@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18030 if (reload) {
18031 #ifdef CONFIG_SMP
18032 preempt_disable();
18033- load_LDT(pc);
18034+ load_LDT_nolock(pc);
18035 if (!cpumask_equal(mm_cpumask(current->mm),
18036 cpumask_of(smp_processor_id())))
18037 smp_call_function(flush_ldt, current->mm, 1);
18038 preempt_enable();
18039 #else
18040- load_LDT(pc);
18041+ load_LDT_nolock(pc);
18042 #endif
18043 }
18044 if (oldsize) {
18045@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18046 return err;
18047
18048 for (i = 0; i < old->size; i++)
18049- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18050+ write_ldt_entry(new->ldt, i, old->ldt + i);
18051 return 0;
18052 }
18053
18054@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18055 retval = copy_ldt(&mm->context, &old_mm->context);
18056 mutex_unlock(&old_mm->context.lock);
18057 }
18058+
18059+ if (tsk == current) {
18060+ mm->context.vdso = 0;
18061+
18062+#ifdef CONFIG_X86_32
18063+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18064+ mm->context.user_cs_base = 0UL;
18065+ mm->context.user_cs_limit = ~0UL;
18066+
18067+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18068+ cpus_clear(mm->context.cpu_user_cs_mask);
18069+#endif
18070+
18071+#endif
18072+#endif
18073+
18074+ }
18075+
18076 return retval;
18077 }
18078
18079@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18080 }
18081 }
18082
18083+#ifdef CONFIG_PAX_SEGMEXEC
18084+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18085+ error = -EINVAL;
18086+ goto out_unlock;
18087+ }
18088+#endif
18089+
18090 fill_ldt(&ldt, &ldt_info);
18091 if (oldmode)
18092 ldt.avl = 0;
18093diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18094index 5b19e4d..6476a76 100644
18095--- a/arch/x86/kernel/machine_kexec_32.c
18096+++ b/arch/x86/kernel/machine_kexec_32.c
18097@@ -26,7 +26,7 @@
18098 #include <asm/cacheflush.h>
18099 #include <asm/debugreg.h>
18100
18101-static void set_idt(void *newidt, __u16 limit)
18102+static void set_idt(struct desc_struct *newidt, __u16 limit)
18103 {
18104 struct desc_ptr curidt;
18105
18106@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18107 }
18108
18109
18110-static void set_gdt(void *newgdt, __u16 limit)
18111+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18112 {
18113 struct desc_ptr curgdt;
18114
18115@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18116 }
18117
18118 control_page = page_address(image->control_code_page);
18119- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18120+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18121
18122 relocate_kernel_ptr = control_page;
18123 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18124diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18125index 0327e2b..e43737b 100644
18126--- a/arch/x86/kernel/microcode_intel.c
18127+++ b/arch/x86/kernel/microcode_intel.c
18128@@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18129
18130 static int get_ucode_user(void *to, const void *from, size_t n)
18131 {
18132- return copy_from_user(to, from, n);
18133+ return copy_from_user(to, (const void __force_user *)from, n);
18134 }
18135
18136 static enum ucode_state
18137 request_microcode_user(int cpu, const void __user *buf, size_t size)
18138 {
18139- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18140+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18141 }
18142
18143 static void microcode_fini_cpu(int cpu)
18144diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18145index f21fd94..61565cd 100644
18146--- a/arch/x86/kernel/module.c
18147+++ b/arch/x86/kernel/module.c
18148@@ -35,15 +35,60 @@
18149 #define DEBUGP(fmt...)
18150 #endif
18151
18152-void *module_alloc(unsigned long size)
18153+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18154 {
18155- if (PAGE_ALIGN(size) > MODULES_LEN)
18156+ if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18157 return NULL;
18158 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18159- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18160+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18161 -1, __builtin_return_address(0));
18162 }
18163
18164+void *module_alloc(unsigned long size)
18165+{
18166+
18167+#ifdef CONFIG_PAX_KERNEXEC
18168+ return __module_alloc(size, PAGE_KERNEL);
18169+#else
18170+ return __module_alloc(size, PAGE_KERNEL_EXEC);
18171+#endif
18172+
18173+}
18174+
18175+#ifdef CONFIG_PAX_KERNEXEC
18176+#ifdef CONFIG_X86_32
18177+void *module_alloc_exec(unsigned long size)
18178+{
18179+ struct vm_struct *area;
18180+
18181+ if (size == 0)
18182+ return NULL;
18183+
18184+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18185+ return area ? area->addr : NULL;
18186+}
18187+EXPORT_SYMBOL(module_alloc_exec);
18188+
18189+void module_free_exec(struct module *mod, void *module_region)
18190+{
18191+ vunmap(module_region);
18192+}
18193+EXPORT_SYMBOL(module_free_exec);
18194+#else
18195+void module_free_exec(struct module *mod, void *module_region)
18196+{
18197+ module_free(mod, module_region);
18198+}
18199+EXPORT_SYMBOL(module_free_exec);
18200+
18201+void *module_alloc_exec(unsigned long size)
18202+{
18203+ return __module_alloc(size, PAGE_KERNEL_RX);
18204+}
18205+EXPORT_SYMBOL(module_alloc_exec);
18206+#endif
18207+#endif
18208+
18209 #ifdef CONFIG_X86_32
18210 int apply_relocate(Elf32_Shdr *sechdrs,
18211 const char *strtab,
18212@@ -54,14 +99,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18213 unsigned int i;
18214 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18215 Elf32_Sym *sym;
18216- uint32_t *location;
18217+ uint32_t *plocation, location;
18218
18219 DEBUGP("Applying relocate section %u to %u\n", relsec,
18220 sechdrs[relsec].sh_info);
18221 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18222 /* This is where to make the change */
18223- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18224- + rel[i].r_offset;
18225+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18226+ location = (uint32_t)plocation;
18227+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18228+ plocation = ktla_ktva((void *)plocation);
18229 /* This is the symbol it is referring to. Note that all
18230 undefined symbols have been resolved. */
18231 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18232@@ -70,11 +117,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18233 switch (ELF32_R_TYPE(rel[i].r_info)) {
18234 case R_386_32:
18235 /* We add the value into the location given */
18236- *location += sym->st_value;
18237+ pax_open_kernel();
18238+ *plocation += sym->st_value;
18239+ pax_close_kernel();
18240 break;
18241 case R_386_PC32:
18242 /* Add the value, subtract its postition */
18243- *location += sym->st_value - (uint32_t)location;
18244+ pax_open_kernel();
18245+ *plocation += sym->st_value - location;
18246+ pax_close_kernel();
18247 break;
18248 default:
18249 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18250@@ -119,21 +170,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18251 case R_X86_64_NONE:
18252 break;
18253 case R_X86_64_64:
18254+ pax_open_kernel();
18255 *(u64 *)loc = val;
18256+ pax_close_kernel();
18257 break;
18258 case R_X86_64_32:
18259+ pax_open_kernel();
18260 *(u32 *)loc = val;
18261+ pax_close_kernel();
18262 if (val != *(u32 *)loc)
18263 goto overflow;
18264 break;
18265 case R_X86_64_32S:
18266+ pax_open_kernel();
18267 *(s32 *)loc = val;
18268+ pax_close_kernel();
18269 if ((s64)val != *(s32 *)loc)
18270 goto overflow;
18271 break;
18272 case R_X86_64_PC32:
18273 val -= (u64)loc;
18274+ pax_open_kernel();
18275 *(u32 *)loc = val;
18276+ pax_close_kernel();
18277+
18278 #if 0
18279 if ((s64)val != *(s32 *)loc)
18280 goto overflow;
18281diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18282index 32856fa..ce95eaa 100644
18283--- a/arch/x86/kernel/nmi.c
18284+++ b/arch/x86/kernel/nmi.c
18285@@ -507,6 +507,17 @@ static inline void nmi_nesting_postprocess(void)
18286 dotraplinkage notrace __kprobes void
18287 do_nmi(struct pt_regs *regs, long error_code)
18288 {
18289+
18290+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18291+ if (!user_mode(regs)) {
18292+ unsigned long cs = regs->cs & 0xFFFF;
18293+ unsigned long ip = ktva_ktla(regs->ip);
18294+
18295+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18296+ regs->ip = ip;
18297+ }
18298+#endif
18299+
18300 nmi_nesting_preprocess(regs);
18301
18302 nmi_enter();
18303diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18304index 676b8c7..870ba04 100644
18305--- a/arch/x86/kernel/paravirt-spinlocks.c
18306+++ b/arch/x86/kernel/paravirt-spinlocks.c
18307@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18308 arch_spin_lock(lock);
18309 }
18310
18311-struct pv_lock_ops pv_lock_ops = {
18312+struct pv_lock_ops pv_lock_ops __read_only = {
18313 #ifdef CONFIG_SMP
18314 .spin_is_locked = __ticket_spin_is_locked,
18315 .spin_is_contended = __ticket_spin_is_contended,
18316diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18317index ab13760..01218e0 100644
18318--- a/arch/x86/kernel/paravirt.c
18319+++ b/arch/x86/kernel/paravirt.c
18320@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18321 {
18322 return x;
18323 }
18324+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18325+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18326+#endif
18327
18328 void __init default_banner(void)
18329 {
18330@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18331 if (opfunc == NULL)
18332 /* If there's no function, patch it with a ud2a (BUG) */
18333 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18334- else if (opfunc == _paravirt_nop)
18335+ else if (opfunc == (void *)_paravirt_nop)
18336 /* If the operation is a nop, then nop the callsite */
18337 ret = paravirt_patch_nop();
18338
18339 /* identity functions just return their single argument */
18340- else if (opfunc == _paravirt_ident_32)
18341+ else if (opfunc == (void *)_paravirt_ident_32)
18342 ret = paravirt_patch_ident_32(insnbuf, len);
18343- else if (opfunc == _paravirt_ident_64)
18344+ else if (opfunc == (void *)_paravirt_ident_64)
18345 ret = paravirt_patch_ident_64(insnbuf, len);
18346+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18347+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18348+ ret = paravirt_patch_ident_64(insnbuf, len);
18349+#endif
18350
18351 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18352 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18353@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18354 if (insn_len > len || start == NULL)
18355 insn_len = len;
18356 else
18357- memcpy(insnbuf, start, insn_len);
18358+ memcpy(insnbuf, ktla_ktva(start), insn_len);
18359
18360 return insn_len;
18361 }
18362@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18363 preempt_enable();
18364 }
18365
18366-struct pv_info pv_info = {
18367+struct pv_info pv_info __read_only = {
18368 .name = "bare hardware",
18369 .paravirt_enabled = 0,
18370 .kernel_rpl = 0,
18371@@ -315,16 +322,16 @@ struct pv_info pv_info = {
18372 #endif
18373 };
18374
18375-struct pv_init_ops pv_init_ops = {
18376+struct pv_init_ops pv_init_ops __read_only = {
18377 .patch = native_patch,
18378 };
18379
18380-struct pv_time_ops pv_time_ops = {
18381+struct pv_time_ops pv_time_ops __read_only = {
18382 .sched_clock = native_sched_clock,
18383 .steal_clock = native_steal_clock,
18384 };
18385
18386-struct pv_irq_ops pv_irq_ops = {
18387+struct pv_irq_ops pv_irq_ops __read_only = {
18388 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18389 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18390 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18391@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18392 #endif
18393 };
18394
18395-struct pv_cpu_ops pv_cpu_ops = {
18396+struct pv_cpu_ops pv_cpu_ops __read_only = {
18397 .cpuid = native_cpuid,
18398 .get_debugreg = native_get_debugreg,
18399 .set_debugreg = native_set_debugreg,
18400@@ -397,21 +404,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18401 .end_context_switch = paravirt_nop,
18402 };
18403
18404-struct pv_apic_ops pv_apic_ops = {
18405+struct pv_apic_ops pv_apic_ops __read_only = {
18406 #ifdef CONFIG_X86_LOCAL_APIC
18407 .startup_ipi_hook = paravirt_nop,
18408 #endif
18409 };
18410
18411-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18412+#ifdef CONFIG_X86_32
18413+#ifdef CONFIG_X86_PAE
18414+/* 64-bit pagetable entries */
18415+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18416+#else
18417 /* 32-bit pagetable entries */
18418 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18419+#endif
18420 #else
18421 /* 64-bit pagetable entries */
18422 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18423 #endif
18424
18425-struct pv_mmu_ops pv_mmu_ops = {
18426+struct pv_mmu_ops pv_mmu_ops __read_only = {
18427
18428 .read_cr2 = native_read_cr2,
18429 .write_cr2 = native_write_cr2,
18430@@ -461,6 +473,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18431 .make_pud = PTE_IDENT,
18432
18433 .set_pgd = native_set_pgd,
18434+ .set_pgd_batched = native_set_pgd_batched,
18435 #endif
18436 #endif /* PAGETABLE_LEVELS >= 3 */
18437
18438@@ -480,6 +493,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18439 },
18440
18441 .set_fixmap = native_set_fixmap,
18442+
18443+#ifdef CONFIG_PAX_KERNEXEC
18444+ .pax_open_kernel = native_pax_open_kernel,
18445+ .pax_close_kernel = native_pax_close_kernel,
18446+#endif
18447+
18448 };
18449
18450 EXPORT_SYMBOL_GPL(pv_time_ops);
18451diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18452index 35ccf75..7a15747 100644
18453--- a/arch/x86/kernel/pci-iommu_table.c
18454+++ b/arch/x86/kernel/pci-iommu_table.c
18455@@ -2,7 +2,7 @@
18456 #include <asm/iommu_table.h>
18457 #include <linux/string.h>
18458 #include <linux/kallsyms.h>
18459-
18460+#include <linux/sched.h>
18461
18462 #define DEBUG 1
18463
18464diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18465index 1d92a5a..7bc8c29 100644
18466--- a/arch/x86/kernel/process.c
18467+++ b/arch/x86/kernel/process.c
18468@@ -69,16 +69,33 @@ void free_thread_xstate(struct task_struct *tsk)
18469
18470 void free_thread_info(struct thread_info *ti)
18471 {
18472- free_thread_xstate(ti->task);
18473 free_pages((unsigned long)ti, THREAD_ORDER);
18474 }
18475
18476+static struct kmem_cache *task_struct_cachep;
18477+
18478 void arch_task_cache_init(void)
18479 {
18480- task_xstate_cachep =
18481- kmem_cache_create("task_xstate", xstate_size,
18482+ /* create a slab on which task_structs can be allocated */
18483+ task_struct_cachep =
18484+ kmem_cache_create("task_struct", sizeof(struct task_struct),
18485+ ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
18486+
18487+ task_xstate_cachep =
18488+ kmem_cache_create("task_xstate", xstate_size,
18489 __alignof__(union thread_xstate),
18490- SLAB_PANIC | SLAB_NOTRACK, NULL);
18491+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18492+}
18493+
18494+struct task_struct *alloc_task_struct_node(int node)
18495+{
18496+ return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
18497+}
18498+
18499+void free_task_struct(struct task_struct *task)
18500+{
18501+ free_thread_xstate(task);
18502+ kmem_cache_free(task_struct_cachep, task);
18503 }
18504
18505 /*
18506@@ -91,7 +108,7 @@ void exit_thread(void)
18507 unsigned long *bp = t->io_bitmap_ptr;
18508
18509 if (bp) {
18510- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18511+ struct tss_struct *tss = init_tss + get_cpu();
18512
18513 t->io_bitmap_ptr = NULL;
18514 clear_thread_flag(TIF_IO_BITMAP);
18515@@ -127,7 +144,7 @@ void show_regs_common(void)
18516
18517 printk(KERN_CONT "\n");
18518 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18519- current->pid, current->comm, print_tainted(),
18520+ task_pid_nr(current), current->comm, print_tainted(),
18521 init_utsname()->release,
18522 (int)strcspn(init_utsname()->version, " "),
18523 init_utsname()->version);
18524@@ -141,6 +158,9 @@ void flush_thread(void)
18525 {
18526 struct task_struct *tsk = current;
18527
18528+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18529+ loadsegment(gs, 0);
18530+#endif
18531 flush_ptrace_hw_breakpoint(tsk);
18532 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18533 /*
18534@@ -303,10 +323,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18535 regs.di = (unsigned long) arg;
18536
18537 #ifdef CONFIG_X86_32
18538- regs.ds = __USER_DS;
18539- regs.es = __USER_DS;
18540+ regs.ds = __KERNEL_DS;
18541+ regs.es = __KERNEL_DS;
18542 regs.fs = __KERNEL_PERCPU;
18543- regs.gs = __KERNEL_STACK_CANARY;
18544+ savesegment(gs, regs.gs);
18545 #else
18546 regs.ss = __KERNEL_DS;
18547 #endif
18548@@ -392,7 +412,7 @@ static void __exit_idle(void)
18549 void exit_idle(void)
18550 {
18551 /* idle loop has pid 0 */
18552- if (current->pid)
18553+ if (task_pid_nr(current))
18554 return;
18555 __exit_idle();
18556 }
18557@@ -501,7 +521,7 @@ bool set_pm_idle_to_default(void)
18558
18559 return ret;
18560 }
18561-void stop_this_cpu(void *dummy)
18562+__noreturn void stop_this_cpu(void *dummy)
18563 {
18564 local_irq_disable();
18565 /*
18566@@ -743,16 +763,37 @@ static int __init idle_setup(char *str)
18567 }
18568 early_param("idle", idle_setup);
18569
18570-unsigned long arch_align_stack(unsigned long sp)
18571+#ifdef CONFIG_PAX_RANDKSTACK
18572+void pax_randomize_kstack(struct pt_regs *regs)
18573 {
18574- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18575- sp -= get_random_int() % 8192;
18576- return sp & ~0xf;
18577-}
18578+ struct thread_struct *thread = &current->thread;
18579+ unsigned long time;
18580
18581-unsigned long arch_randomize_brk(struct mm_struct *mm)
18582-{
18583- unsigned long range_end = mm->brk + 0x02000000;
18584- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18585-}
18586+ if (!randomize_va_space)
18587+ return;
18588+
18589+ if (v8086_mode(regs))
18590+ return;
18591
18592+ rdtscl(time);
18593+
18594+ /* P4 seems to return a 0 LSB, ignore it */
18595+#ifdef CONFIG_MPENTIUM4
18596+ time &= 0x3EUL;
18597+ time <<= 2;
18598+#elif defined(CONFIG_X86_64)
18599+ time &= 0xFUL;
18600+ time <<= 4;
18601+#else
18602+ time &= 0x1FUL;
18603+ time <<= 3;
18604+#endif
18605+
18606+ thread->sp0 ^= time;
18607+ load_sp0(init_tss + smp_processor_id(), thread);
18608+
18609+#ifdef CONFIG_X86_64
18610+ percpu_write(kernel_stack, thread->sp0);
18611+#endif
18612+}
18613+#endif
18614diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18615index ae68473..7b0bb71 100644
18616--- a/arch/x86/kernel/process_32.c
18617+++ b/arch/x86/kernel/process_32.c
18618@@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18619 unsigned long thread_saved_pc(struct task_struct *tsk)
18620 {
18621 return ((unsigned long *)tsk->thread.sp)[3];
18622+//XXX return tsk->thread.eip;
18623 }
18624
18625 void __show_regs(struct pt_regs *regs, int all)
18626@@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18627 unsigned long sp;
18628 unsigned short ss, gs;
18629
18630- if (user_mode_vm(regs)) {
18631+ if (user_mode(regs)) {
18632 sp = regs->sp;
18633 ss = regs->ss & 0xffff;
18634- gs = get_user_gs(regs);
18635 } else {
18636 sp = kernel_stack_pointer(regs);
18637 savesegment(ss, ss);
18638- savesegment(gs, gs);
18639 }
18640+ gs = get_user_gs(regs);
18641
18642 show_regs_common();
18643
18644@@ -143,13 +143,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18645 struct task_struct *tsk;
18646 int err;
18647
18648- childregs = task_pt_regs(p);
18649+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18650 *childregs = *regs;
18651 childregs->ax = 0;
18652 childregs->sp = sp;
18653
18654 p->thread.sp = (unsigned long) childregs;
18655 p->thread.sp0 = (unsigned long) (childregs+1);
18656+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18657
18658 p->thread.ip = (unsigned long) ret_from_fork;
18659
18660@@ -240,7 +241,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18661 struct thread_struct *prev = &prev_p->thread,
18662 *next = &next_p->thread;
18663 int cpu = smp_processor_id();
18664- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18665+ struct tss_struct *tss = init_tss + cpu;
18666 fpu_switch_t fpu;
18667
18668 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18669@@ -264,6 +265,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18670 */
18671 lazy_save_gs(prev->gs);
18672
18673+#ifdef CONFIG_PAX_MEMORY_UDEREF
18674+ __set_fs(task_thread_info(next_p)->addr_limit);
18675+#endif
18676+
18677 /*
18678 * Load the per-thread Thread-Local Storage descriptor.
18679 */
18680@@ -294,6 +299,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18681 */
18682 arch_end_context_switch(next_p);
18683
18684+ percpu_write(current_task, next_p);
18685+ percpu_write(current_tinfo, &next_p->tinfo);
18686+
18687 /*
18688 * Restore %gs if needed (which is common)
18689 */
18690@@ -302,8 +310,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18691
18692 switch_fpu_finish(next_p, fpu);
18693
18694- percpu_write(current_task, next_p);
18695-
18696 return prev_p;
18697 }
18698
18699@@ -333,4 +339,3 @@ unsigned long get_wchan(struct task_struct *p)
18700 } while (count++ < 16);
18701 return 0;
18702 }
18703-
18704diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18705index 43d8b48..c45d566 100644
18706--- a/arch/x86/kernel/process_64.c
18707+++ b/arch/x86/kernel/process_64.c
18708@@ -162,8 +162,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18709 struct pt_regs *childregs;
18710 struct task_struct *me = current;
18711
18712- childregs = ((struct pt_regs *)
18713- (THREAD_SIZE + task_stack_page(p))) - 1;
18714+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18715 *childregs = *regs;
18716
18717 childregs->ax = 0;
18718@@ -175,6 +174,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18719 p->thread.sp = (unsigned long) childregs;
18720 p->thread.sp0 = (unsigned long) (childregs+1);
18721 p->thread.usersp = me->thread.usersp;
18722+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18723
18724 set_tsk_thread_flag(p, TIF_FORK);
18725
18726@@ -280,7 +280,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18727 struct thread_struct *prev = &prev_p->thread;
18728 struct thread_struct *next = &next_p->thread;
18729 int cpu = smp_processor_id();
18730- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18731+ struct tss_struct *tss = init_tss + cpu;
18732 unsigned fsindex, gsindex;
18733 fpu_switch_t fpu;
18734
18735@@ -362,10 +362,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18736 prev->usersp = percpu_read(old_rsp);
18737 percpu_write(old_rsp, next->usersp);
18738 percpu_write(current_task, next_p);
18739+ percpu_write(current_tinfo, &next_p->tinfo);
18740
18741- percpu_write(kernel_stack,
18742- (unsigned long)task_stack_page(next_p) +
18743- THREAD_SIZE - KERNEL_STACK_OFFSET);
18744+ percpu_write(kernel_stack, next->sp0);
18745
18746 /*
18747 * Now maybe reload the debug registers and handle I/O bitmaps
18748@@ -434,12 +433,11 @@ unsigned long get_wchan(struct task_struct *p)
18749 if (!p || p == current || p->state == TASK_RUNNING)
18750 return 0;
18751 stack = (unsigned long)task_stack_page(p);
18752- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18753+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18754 return 0;
18755 fp = *(u64 *)(p->thread.sp);
18756 do {
18757- if (fp < (unsigned long)stack ||
18758- fp >= (unsigned long)stack+THREAD_SIZE)
18759+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18760 return 0;
18761 ip = *(u64 *)(fp+8);
18762 if (!in_sched_functions(ip))
18763diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18764index cf11783..e7ce551 100644
18765--- a/arch/x86/kernel/ptrace.c
18766+++ b/arch/x86/kernel/ptrace.c
18767@@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18768 unsigned long addr, unsigned long data)
18769 {
18770 int ret;
18771- unsigned long __user *datap = (unsigned long __user *)data;
18772+ unsigned long __user *datap = (__force unsigned long __user *)data;
18773
18774 switch (request) {
18775 /* read the word at location addr in the USER area. */
18776@@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18777 if ((int) addr < 0)
18778 return -EIO;
18779 ret = do_get_thread_area(child, addr,
18780- (struct user_desc __user *)data);
18781+ (__force struct user_desc __user *) data);
18782 break;
18783
18784 case PTRACE_SET_THREAD_AREA:
18785 if ((int) addr < 0)
18786 return -EIO;
18787 ret = do_set_thread_area(child, addr,
18788- (struct user_desc __user *)data, 0);
18789+ (__force struct user_desc __user *) data, 0);
18790 break;
18791 #endif
18792
18793@@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18794 memset(info, 0, sizeof(*info));
18795 info->si_signo = SIGTRAP;
18796 info->si_code = si_code;
18797- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18798+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18799 }
18800
18801 void user_single_step_siginfo(struct task_struct *tsk,
18802@@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18803 # define IS_IA32 0
18804 #endif
18805
18806+#ifdef CONFIG_GRKERNSEC_SETXID
18807+extern void gr_delayed_cred_worker(void);
18808+#endif
18809+
18810 /*
18811 * We must return the syscall number to actually look up in the table.
18812 * This can be -1L to skip running any syscall at all.
18813@@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18814 {
18815 long ret = 0;
18816
18817+#ifdef CONFIG_GRKERNSEC_SETXID
18818+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18819+ gr_delayed_cred_worker();
18820+#endif
18821+
18822 /*
18823 * If we stepped into a sysenter/syscall insn, it trapped in
18824 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18825@@ -1506,6 +1515,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18826 {
18827 bool step;
18828
18829+#ifdef CONFIG_GRKERNSEC_SETXID
18830+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18831+ gr_delayed_cred_worker();
18832+#endif
18833+
18834 audit_syscall_exit(regs);
18835
18836 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18837diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18838index 42eb330..139955c 100644
18839--- a/arch/x86/kernel/pvclock.c
18840+++ b/arch/x86/kernel/pvclock.c
18841@@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18842 return pv_tsc_khz;
18843 }
18844
18845-static atomic64_t last_value = ATOMIC64_INIT(0);
18846+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18847
18848 void pvclock_resume(void)
18849 {
18850- atomic64_set(&last_value, 0);
18851+ atomic64_set_unchecked(&last_value, 0);
18852 }
18853
18854 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18855@@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18856 * updating at the same time, and one of them could be slightly behind,
18857 * making the assumption that last_value always go forward fail to hold.
18858 */
18859- last = atomic64_read(&last_value);
18860+ last = atomic64_read_unchecked(&last_value);
18861 do {
18862 if (ret < last)
18863 return last;
18864- last = atomic64_cmpxchg(&last_value, last, ret);
18865+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18866 } while (unlikely(last != ret));
18867
18868 return ret;
18869diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18870index d840e69..98e9581 100644
18871--- a/arch/x86/kernel/reboot.c
18872+++ b/arch/x86/kernel/reboot.c
18873@@ -35,7 +35,7 @@ void (*pm_power_off)(void);
18874 EXPORT_SYMBOL(pm_power_off);
18875
18876 static const struct desc_ptr no_idt = {};
18877-static int reboot_mode;
18878+static unsigned short reboot_mode;
18879 enum reboot_type reboot_type = BOOT_ACPI;
18880 int reboot_force;
18881
18882@@ -335,13 +335,17 @@ core_initcall(reboot_init);
18883 extern const unsigned char machine_real_restart_asm[];
18884 extern const u64 machine_real_restart_gdt[3];
18885
18886-void machine_real_restart(unsigned int type)
18887+__noreturn void machine_real_restart(unsigned int type)
18888 {
18889 void *restart_va;
18890 unsigned long restart_pa;
18891- void (*restart_lowmem)(unsigned int);
18892+ void (* __noreturn restart_lowmem)(unsigned int);
18893 u64 *lowmem_gdt;
18894
18895+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18896+ struct desc_struct *gdt;
18897+#endif
18898+
18899 local_irq_disable();
18900
18901 /* Write zero to CMOS register number 0x0f, which the BIOS POST
18902@@ -367,14 +371,14 @@ void machine_real_restart(unsigned int type)
18903 boot)". This seems like a fairly standard thing that gets set by
18904 REBOOT.COM programs, and the previous reset routine did this
18905 too. */
18906- *((unsigned short *)0x472) = reboot_mode;
18907+ *(unsigned short *)(__va(0x472)) = reboot_mode;
18908
18909 /* Patch the GDT in the low memory trampoline */
18910 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
18911
18912 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
18913 restart_pa = virt_to_phys(restart_va);
18914- restart_lowmem = (void (*)(unsigned int))restart_pa;
18915+ restart_lowmem = (void *)restart_pa;
18916
18917 /* GDT[0]: GDT self-pointer */
18918 lowmem_gdt[0] =
18919@@ -385,7 +389,33 @@ void machine_real_restart(unsigned int type)
18920 GDT_ENTRY(0x009b, restart_pa, 0xffff);
18921
18922 /* Jump to the identity-mapped low memory code */
18923+
18924+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18925+ gdt = get_cpu_gdt_table(smp_processor_id());
18926+ pax_open_kernel();
18927+#ifdef CONFIG_PAX_MEMORY_UDEREF
18928+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18929+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18930+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18931+#endif
18932+#ifdef CONFIG_PAX_KERNEXEC
18933+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18934+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18935+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18936+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18937+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18938+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18939+#endif
18940+ pax_close_kernel();
18941+#endif
18942+
18943+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18944+ asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18945+ unreachable();
18946+#else
18947 restart_lowmem(type);
18948+#endif
18949+
18950 }
18951 #ifdef CONFIG_APM_MODULE
18952 EXPORT_SYMBOL(machine_real_restart);
18953@@ -556,7 +586,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18954 * try to force a triple fault and then cycle between hitting the keyboard
18955 * controller and doing that
18956 */
18957-static void native_machine_emergency_restart(void)
18958+__noreturn static void native_machine_emergency_restart(void)
18959 {
18960 int i;
18961 int attempt = 0;
18962@@ -680,13 +710,13 @@ void native_machine_shutdown(void)
18963 #endif
18964 }
18965
18966-static void __machine_emergency_restart(int emergency)
18967+static __noreturn void __machine_emergency_restart(int emergency)
18968 {
18969 reboot_emergency = emergency;
18970 machine_ops.emergency_restart();
18971 }
18972
18973-static void native_machine_restart(char *__unused)
18974+static __noreturn void native_machine_restart(char *__unused)
18975 {
18976 printk("machine restart\n");
18977
18978@@ -695,7 +725,7 @@ static void native_machine_restart(char *__unused)
18979 __machine_emergency_restart(0);
18980 }
18981
18982-static void native_machine_halt(void)
18983+static __noreturn void native_machine_halt(void)
18984 {
18985 /* stop other cpus and apics */
18986 machine_shutdown();
18987@@ -706,7 +736,7 @@ static void native_machine_halt(void)
18988 stop_this_cpu(NULL);
18989 }
18990
18991-static void native_machine_power_off(void)
18992+__noreturn static void native_machine_power_off(void)
18993 {
18994 if (pm_power_off) {
18995 if (!reboot_force)
18996@@ -715,6 +745,7 @@ static void native_machine_power_off(void)
18997 }
18998 /* a fallback in case there is no PM info available */
18999 tboot_shutdown(TB_SHUTDOWN_HALT);
19000+ unreachable();
19001 }
19002
19003 struct machine_ops machine_ops = {
19004diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
19005index 7a6f3b3..bed145d7 100644
19006--- a/arch/x86/kernel/relocate_kernel_64.S
19007+++ b/arch/x86/kernel/relocate_kernel_64.S
19008@@ -11,6 +11,7 @@
19009 #include <asm/kexec.h>
19010 #include <asm/processor-flags.h>
19011 #include <asm/pgtable_types.h>
19012+#include <asm/alternative-asm.h>
19013
19014 /*
19015 * Must be relocatable PIC code callable as a C function
19016@@ -160,13 +161,14 @@ identity_mapped:
19017 xorq %rbp, %rbp
19018 xorq %r8, %r8
19019 xorq %r9, %r9
19020- xorq %r10, %r9
19021+ xorq %r10, %r10
19022 xorq %r11, %r11
19023 xorq %r12, %r12
19024 xorq %r13, %r13
19025 xorq %r14, %r14
19026 xorq %r15, %r15
19027
19028+ pax_force_retaddr 0, 1
19029 ret
19030
19031 1:
19032diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19033index 1a29015..712f324 100644
19034--- a/arch/x86/kernel/setup.c
19035+++ b/arch/x86/kernel/setup.c
19036@@ -447,7 +447,7 @@ static void __init parse_setup_data(void)
19037
19038 switch (data->type) {
19039 case SETUP_E820_EXT:
19040- parse_e820_ext(data);
19041+ parse_e820_ext((struct setup_data __force_kernel *)data);
19042 break;
19043 case SETUP_DTB:
19044 add_dtb(pa_data);
19045@@ -639,7 +639,7 @@ static void __init trim_bios_range(void)
19046 * area (640->1Mb) as ram even though it is not.
19047 * take them out.
19048 */
19049- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19050+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19051 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19052 }
19053
19054@@ -763,14 +763,14 @@ void __init setup_arch(char **cmdline_p)
19055
19056 if (!boot_params.hdr.root_flags)
19057 root_mountflags &= ~MS_RDONLY;
19058- init_mm.start_code = (unsigned long) _text;
19059- init_mm.end_code = (unsigned long) _etext;
19060+ init_mm.start_code = ktla_ktva((unsigned long) _text);
19061+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
19062 init_mm.end_data = (unsigned long) _edata;
19063 init_mm.brk = _brk_end;
19064
19065- code_resource.start = virt_to_phys(_text);
19066- code_resource.end = virt_to_phys(_etext)-1;
19067- data_resource.start = virt_to_phys(_etext);
19068+ code_resource.start = virt_to_phys(ktla_ktva(_text));
19069+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19070+ data_resource.start = virt_to_phys(_sdata);
19071 data_resource.end = virt_to_phys(_edata)-1;
19072 bss_resource.start = virt_to_phys(&__bss_start);
19073 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19074diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19075index 5a98aa2..2f9288d 100644
19076--- a/arch/x86/kernel/setup_percpu.c
19077+++ b/arch/x86/kernel/setup_percpu.c
19078@@ -21,19 +21,17 @@
19079 #include <asm/cpu.h>
19080 #include <asm/stackprotector.h>
19081
19082-DEFINE_PER_CPU(int, cpu_number);
19083+#ifdef CONFIG_SMP
19084+DEFINE_PER_CPU(unsigned int, cpu_number);
19085 EXPORT_PER_CPU_SYMBOL(cpu_number);
19086+#endif
19087
19088-#ifdef CONFIG_X86_64
19089 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19090-#else
19091-#define BOOT_PERCPU_OFFSET 0
19092-#endif
19093
19094 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19095 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19096
19097-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19098+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19099 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19100 };
19101 EXPORT_SYMBOL(__per_cpu_offset);
19102@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19103 {
19104 #ifdef CONFIG_X86_32
19105 struct desc_struct gdt;
19106+ unsigned long base = per_cpu_offset(cpu);
19107
19108- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19109- 0x2 | DESCTYPE_S, 0x8);
19110- gdt.s = 1;
19111+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19112+ 0x83 | DESCTYPE_S, 0xC);
19113 write_gdt_entry(get_cpu_gdt_table(cpu),
19114 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19115 #endif
19116@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19117 /* alrighty, percpu areas up and running */
19118 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19119 for_each_possible_cpu(cpu) {
19120+#ifdef CONFIG_CC_STACKPROTECTOR
19121+#ifdef CONFIG_X86_32
19122+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
19123+#endif
19124+#endif
19125 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19126 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19127 per_cpu(cpu_number, cpu) = cpu;
19128@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19129 */
19130 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19131 #endif
19132+#ifdef CONFIG_CC_STACKPROTECTOR
19133+#ifdef CONFIG_X86_32
19134+ if (!cpu)
19135+ per_cpu(stack_canary.canary, cpu) = canary;
19136+#endif
19137+#endif
19138 /*
19139 * Up to this point, the boot CPU has been using .init.data
19140 * area. Reload any changed state for the boot CPU.
19141diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19142index 115eac4..c0591d5 100644
19143--- a/arch/x86/kernel/signal.c
19144+++ b/arch/x86/kernel/signal.c
19145@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
19146 * Align the stack pointer according to the i386 ABI,
19147 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19148 */
19149- sp = ((sp + 4) & -16ul) - 4;
19150+ sp = ((sp - 12) & -16ul) - 4;
19151 #else /* !CONFIG_X86_32 */
19152 sp = round_down(sp, 16) - 8;
19153 #endif
19154@@ -241,11 +241,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19155 * Return an always-bogus address instead so we will die with SIGSEGV.
19156 */
19157 if (onsigstack && !likely(on_sig_stack(sp)))
19158- return (void __user *)-1L;
19159+ return (__force void __user *)-1L;
19160
19161 /* save i387 state */
19162 if (used_math() && save_i387_xstate(*fpstate) < 0)
19163- return (void __user *)-1L;
19164+ return (__force void __user *)-1L;
19165
19166 return (void __user *)sp;
19167 }
19168@@ -300,9 +300,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19169 }
19170
19171 if (current->mm->context.vdso)
19172- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19173+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19174 else
19175- restorer = &frame->retcode;
19176+ restorer = (void __user *)&frame->retcode;
19177 if (ka->sa.sa_flags & SA_RESTORER)
19178 restorer = ka->sa.sa_restorer;
19179
19180@@ -316,7 +316,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19181 * reasons and because gdb uses it as a signature to notice
19182 * signal handler stack frames.
19183 */
19184- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19185+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19186
19187 if (err)
19188 return -EFAULT;
19189@@ -370,7 +370,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19190 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19191
19192 /* Set up to return from userspace. */
19193- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19194+ if (current->mm->context.vdso)
19195+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19196+ else
19197+ restorer = (void __user *)&frame->retcode;
19198 if (ka->sa.sa_flags & SA_RESTORER)
19199 restorer = ka->sa.sa_restorer;
19200 put_user_ex(restorer, &frame->pretcode);
19201@@ -382,7 +385,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19202 * reasons and because gdb uses it as a signature to notice
19203 * signal handler stack frames.
19204 */
19205- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19206+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19207 } put_user_catch(err);
19208
19209 if (err)
19210@@ -773,7 +776,7 @@ static void do_signal(struct pt_regs *regs)
19211 * X86_32: vm86 regs switched out by assembly code before reaching
19212 * here, so testing against kernel CS suffices.
19213 */
19214- if (!user_mode(regs))
19215+ if (!user_mode_novm(regs))
19216 return;
19217
19218 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
19219diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19220index 6e1e406..edfb7cb 100644
19221--- a/arch/x86/kernel/smpboot.c
19222+++ b/arch/x86/kernel/smpboot.c
19223@@ -699,17 +699,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
19224 set_idle_for_cpu(cpu, c_idle.idle);
19225 do_rest:
19226 per_cpu(current_task, cpu) = c_idle.idle;
19227+ per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
19228 #ifdef CONFIG_X86_32
19229 /* Stack for startup_32 can be just as for start_secondary onwards */
19230 irq_ctx_init(cpu);
19231 #else
19232 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
19233 initial_gs = per_cpu_offset(cpu);
19234- per_cpu(kernel_stack, cpu) =
19235- (unsigned long)task_stack_page(c_idle.idle) -
19236- KERNEL_STACK_OFFSET + THREAD_SIZE;
19237+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
19238 #endif
19239+
19240+ pax_open_kernel();
19241 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19242+ pax_close_kernel();
19243+
19244 initial_code = (unsigned long)start_secondary;
19245 stack_start = c_idle.idle->thread.sp;
19246
19247@@ -851,6 +854,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
19248
19249 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19250
19251+#ifdef CONFIG_PAX_PER_CPU_PGD
19252+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19253+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19254+ KERNEL_PGD_PTRS);
19255+#endif
19256+
19257 err = do_boot_cpu(apicid, cpu);
19258 if (err) {
19259 pr_debug("do_boot_cpu failed %d\n", err);
19260diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19261index c346d11..d43b163 100644
19262--- a/arch/x86/kernel/step.c
19263+++ b/arch/x86/kernel/step.c
19264@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19265 struct desc_struct *desc;
19266 unsigned long base;
19267
19268- seg &= ~7UL;
19269+ seg >>= 3;
19270
19271 mutex_lock(&child->mm->context.lock);
19272- if (unlikely((seg >> 3) >= child->mm->context.size))
19273+ if (unlikely(seg >= child->mm->context.size))
19274 addr = -1L; /* bogus selector, access would fault */
19275 else {
19276 desc = child->mm->context.ldt + seg;
19277@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19278 addr += base;
19279 }
19280 mutex_unlock(&child->mm->context.lock);
19281- }
19282+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19283+ addr = ktla_ktva(addr);
19284
19285 return addr;
19286 }
19287@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19288 unsigned char opcode[15];
19289 unsigned long addr = convert_ip_to_linear(child, regs);
19290
19291+ if (addr == -EINVAL)
19292+ return 0;
19293+
19294 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19295 for (i = 0; i < copied; i++) {
19296 switch (opcode[i]) {
19297diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19298index 0b0cb5f..db6b9ed 100644
19299--- a/arch/x86/kernel/sys_i386_32.c
19300+++ b/arch/x86/kernel/sys_i386_32.c
19301@@ -24,17 +24,224 @@
19302
19303 #include <asm/syscalls.h>
19304
19305-/*
19306- * Do a system call from kernel instead of calling sys_execve so we
19307- * end up with proper pt_regs.
19308- */
19309-int kernel_execve(const char *filename,
19310- const char *const argv[],
19311- const char *const envp[])
19312+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19313 {
19314- long __res;
19315- asm volatile ("int $0x80"
19316- : "=a" (__res)
19317- : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19318- return __res;
19319+ unsigned long pax_task_size = TASK_SIZE;
19320+
19321+#ifdef CONFIG_PAX_SEGMEXEC
19322+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19323+ pax_task_size = SEGMEXEC_TASK_SIZE;
19324+#endif
19325+
19326+ if (len > pax_task_size || addr > pax_task_size - len)
19327+ return -EINVAL;
19328+
19329+ return 0;
19330+}
19331+
19332+unsigned long
19333+arch_get_unmapped_area(struct file *filp, unsigned long addr,
19334+ unsigned long len, unsigned long pgoff, unsigned long flags)
19335+{
19336+ struct mm_struct *mm = current->mm;
19337+ struct vm_area_struct *vma;
19338+ unsigned long start_addr, pax_task_size = TASK_SIZE;
19339+
19340+#ifdef CONFIG_PAX_SEGMEXEC
19341+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19342+ pax_task_size = SEGMEXEC_TASK_SIZE;
19343+#endif
19344+
19345+ pax_task_size -= PAGE_SIZE;
19346+
19347+ if (len > pax_task_size)
19348+ return -ENOMEM;
19349+
19350+ if (flags & MAP_FIXED)
19351+ return addr;
19352+
19353+#ifdef CONFIG_PAX_RANDMMAP
19354+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19355+#endif
19356+
19357+ if (addr) {
19358+ addr = PAGE_ALIGN(addr);
19359+ if (pax_task_size - len >= addr) {
19360+ vma = find_vma(mm, addr);
19361+ if (check_heap_stack_gap(vma, addr, len))
19362+ return addr;
19363+ }
19364+ }
19365+ if (len > mm->cached_hole_size) {
19366+ start_addr = addr = mm->free_area_cache;
19367+ } else {
19368+ start_addr = addr = mm->mmap_base;
19369+ mm->cached_hole_size = 0;
19370+ }
19371+
19372+#ifdef CONFIG_PAX_PAGEEXEC
19373+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19374+ start_addr = 0x00110000UL;
19375+
19376+#ifdef CONFIG_PAX_RANDMMAP
19377+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19378+ start_addr += mm->delta_mmap & 0x03FFF000UL;
19379+#endif
19380+
19381+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19382+ start_addr = addr = mm->mmap_base;
19383+ else
19384+ addr = start_addr;
19385+ }
19386+#endif
19387+
19388+full_search:
19389+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19390+ /* At this point: (!vma || addr < vma->vm_end). */
19391+ if (pax_task_size - len < addr) {
19392+ /*
19393+ * Start a new search - just in case we missed
19394+ * some holes.
19395+ */
19396+ if (start_addr != mm->mmap_base) {
19397+ start_addr = addr = mm->mmap_base;
19398+ mm->cached_hole_size = 0;
19399+ goto full_search;
19400+ }
19401+ return -ENOMEM;
19402+ }
19403+ if (check_heap_stack_gap(vma, addr, len))
19404+ break;
19405+ if (addr + mm->cached_hole_size < vma->vm_start)
19406+ mm->cached_hole_size = vma->vm_start - addr;
19407+ addr = vma->vm_end;
19408+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
19409+ start_addr = addr = mm->mmap_base;
19410+ mm->cached_hole_size = 0;
19411+ goto full_search;
19412+ }
19413+ }
19414+
19415+ /*
19416+ * Remember the place where we stopped the search:
19417+ */
19418+ mm->free_area_cache = addr + len;
19419+ return addr;
19420+}
19421+
19422+unsigned long
19423+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19424+ const unsigned long len, const unsigned long pgoff,
19425+ const unsigned long flags)
19426+{
19427+ struct vm_area_struct *vma;
19428+ struct mm_struct *mm = current->mm;
19429+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19430+
19431+#ifdef CONFIG_PAX_SEGMEXEC
19432+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19433+ pax_task_size = SEGMEXEC_TASK_SIZE;
19434+#endif
19435+
19436+ pax_task_size -= PAGE_SIZE;
19437+
19438+ /* requested length too big for entire address space */
19439+ if (len > pax_task_size)
19440+ return -ENOMEM;
19441+
19442+ if (flags & MAP_FIXED)
19443+ return addr;
19444+
19445+#ifdef CONFIG_PAX_PAGEEXEC
19446+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19447+ goto bottomup;
19448+#endif
19449+
19450+#ifdef CONFIG_PAX_RANDMMAP
19451+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19452+#endif
19453+
19454+ /* requesting a specific address */
19455+ if (addr) {
19456+ addr = PAGE_ALIGN(addr);
19457+ if (pax_task_size - len >= addr) {
19458+ vma = find_vma(mm, addr);
19459+ if (check_heap_stack_gap(vma, addr, len))
19460+ return addr;
19461+ }
19462+ }
19463+
19464+ /* check if free_area_cache is useful for us */
19465+ if (len <= mm->cached_hole_size) {
19466+ mm->cached_hole_size = 0;
19467+ mm->free_area_cache = mm->mmap_base;
19468+ }
19469+
19470+ /* either no address requested or can't fit in requested address hole */
19471+ addr = mm->free_area_cache;
19472+
19473+ /* make sure it can fit in the remaining address space */
19474+ if (addr > len) {
19475+ vma = find_vma(mm, addr-len);
19476+ if (check_heap_stack_gap(vma, addr - len, len))
19477+ /* remember the address as a hint for next time */
19478+ return (mm->free_area_cache = addr-len);
19479+ }
19480+
19481+ if (mm->mmap_base < len)
19482+ goto bottomup;
19483+
19484+ addr = mm->mmap_base-len;
19485+
19486+ do {
19487+ /*
19488+ * Lookup failure means no vma is above this address,
19489+ * else if new region fits below vma->vm_start,
19490+ * return with success:
19491+ */
19492+ vma = find_vma(mm, addr);
19493+ if (check_heap_stack_gap(vma, addr, len))
19494+ /* remember the address as a hint for next time */
19495+ return (mm->free_area_cache = addr);
19496+
19497+ /* remember the largest hole we saw so far */
19498+ if (addr + mm->cached_hole_size < vma->vm_start)
19499+ mm->cached_hole_size = vma->vm_start - addr;
19500+
19501+ /* try just below the current vma->vm_start */
19502+ addr = skip_heap_stack_gap(vma, len);
19503+ } while (!IS_ERR_VALUE(addr));
19504+
19505+bottomup:
19506+ /*
19507+ * A failed mmap() very likely causes application failure,
19508+ * so fall back to the bottom-up function here. This scenario
19509+ * can happen with large stack limits and large mmap()
19510+ * allocations.
19511+ */
19512+
19513+#ifdef CONFIG_PAX_SEGMEXEC
19514+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19515+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19516+ else
19517+#endif
19518+
19519+ mm->mmap_base = TASK_UNMAPPED_BASE;
19520+
19521+#ifdef CONFIG_PAX_RANDMMAP
19522+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19523+ mm->mmap_base += mm->delta_mmap;
19524+#endif
19525+
19526+ mm->free_area_cache = mm->mmap_base;
19527+ mm->cached_hole_size = ~0UL;
19528+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19529+ /*
19530+ * Restore the topdown base:
19531+ */
19532+ mm->mmap_base = base;
19533+ mm->free_area_cache = base;
19534+ mm->cached_hole_size = ~0UL;
19535+
19536+ return addr;
19537 }
19538diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19539index b4d3c39..82bb73b 100644
19540--- a/arch/x86/kernel/sys_x86_64.c
19541+++ b/arch/x86/kernel/sys_x86_64.c
19542@@ -95,8 +95,8 @@ out:
19543 return error;
19544 }
19545
19546-static void find_start_end(unsigned long flags, unsigned long *begin,
19547- unsigned long *end)
19548+static void find_start_end(struct mm_struct *mm, unsigned long flags,
19549+ unsigned long *begin, unsigned long *end)
19550 {
19551 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19552 unsigned long new_begin;
19553@@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19554 *begin = new_begin;
19555 }
19556 } else {
19557- *begin = TASK_UNMAPPED_BASE;
19558+ *begin = mm->mmap_base;
19559 *end = TASK_SIZE;
19560 }
19561 }
19562@@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19563 if (flags & MAP_FIXED)
19564 return addr;
19565
19566- find_start_end(flags, &begin, &end);
19567+ find_start_end(mm, flags, &begin, &end);
19568
19569 if (len > end)
19570 return -ENOMEM;
19571
19572+#ifdef CONFIG_PAX_RANDMMAP
19573+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19574+#endif
19575+
19576 if (addr) {
19577 addr = PAGE_ALIGN(addr);
19578 vma = find_vma(mm, addr);
19579- if (end - len >= addr &&
19580- (!vma || addr + len <= vma->vm_start))
19581+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19582 return addr;
19583 }
19584 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19585@@ -172,7 +175,7 @@ full_search:
19586 }
19587 return -ENOMEM;
19588 }
19589- if (!vma || addr + len <= vma->vm_start) {
19590+ if (check_heap_stack_gap(vma, addr, len)) {
19591 /*
19592 * Remember the place where we stopped the search:
19593 */
19594@@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19595 {
19596 struct vm_area_struct *vma;
19597 struct mm_struct *mm = current->mm;
19598- unsigned long addr = addr0, start_addr;
19599+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19600
19601 /* requested length too big for entire address space */
19602 if (len > TASK_SIZE)
19603@@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19604 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19605 goto bottomup;
19606
19607+#ifdef CONFIG_PAX_RANDMMAP
19608+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19609+#endif
19610+
19611 /* requesting a specific address */
19612 if (addr) {
19613 addr = PAGE_ALIGN(addr);
19614- vma = find_vma(mm, addr);
19615- if (TASK_SIZE - len >= addr &&
19616- (!vma || addr + len <= vma->vm_start))
19617- return addr;
19618+ if (TASK_SIZE - len >= addr) {
19619+ vma = find_vma(mm, addr);
19620+ if (check_heap_stack_gap(vma, addr, len))
19621+ return addr;
19622+ }
19623 }
19624
19625 /* check if free_area_cache is useful for us */
19626@@ -240,7 +248,7 @@ try_again:
19627 * return with success:
19628 */
19629 vma = find_vma(mm, addr);
19630- if (!vma || addr+len <= vma->vm_start)
19631+ if (check_heap_stack_gap(vma, addr, len))
19632 /* remember the address as a hint for next time */
19633 return mm->free_area_cache = addr;
19634
19635@@ -249,8 +257,8 @@ try_again:
19636 mm->cached_hole_size = vma->vm_start - addr;
19637
19638 /* try just below the current vma->vm_start */
19639- addr = vma->vm_start-len;
19640- } while (len < vma->vm_start);
19641+ addr = skip_heap_stack_gap(vma, len);
19642+ } while (!IS_ERR_VALUE(addr));
19643
19644 fail:
19645 /*
19646@@ -270,13 +278,21 @@ bottomup:
19647 * can happen with large stack limits and large mmap()
19648 * allocations.
19649 */
19650+ mm->mmap_base = TASK_UNMAPPED_BASE;
19651+
19652+#ifdef CONFIG_PAX_RANDMMAP
19653+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19654+ mm->mmap_base += mm->delta_mmap;
19655+#endif
19656+
19657+ mm->free_area_cache = mm->mmap_base;
19658 mm->cached_hole_size = ~0UL;
19659- mm->free_area_cache = TASK_UNMAPPED_BASE;
19660 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19661 /*
19662 * Restore the topdown base:
19663 */
19664- mm->free_area_cache = mm->mmap_base;
19665+ mm->mmap_base = base;
19666+ mm->free_area_cache = base;
19667 mm->cached_hole_size = ~0UL;
19668
19669 return addr;
19670diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19671index 6410744..79758f0 100644
19672--- a/arch/x86/kernel/tboot.c
19673+++ b/arch/x86/kernel/tboot.c
19674@@ -219,7 +219,7 @@ static int tboot_setup_sleep(void)
19675
19676 void tboot_shutdown(u32 shutdown_type)
19677 {
19678- void (*shutdown)(void);
19679+ void (* __noreturn shutdown)(void);
19680
19681 if (!tboot_enabled())
19682 return;
19683@@ -241,7 +241,7 @@ void tboot_shutdown(u32 shutdown_type)
19684
19685 switch_to_tboot_pt();
19686
19687- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19688+ shutdown = (void *)tboot->shutdown_entry;
19689 shutdown();
19690
19691 /* should not reach here */
19692@@ -299,7 +299,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19693 return 0;
19694 }
19695
19696-static atomic_t ap_wfs_count;
19697+static atomic_unchecked_t ap_wfs_count;
19698
19699 static int tboot_wait_for_aps(int num_aps)
19700 {
19701@@ -323,9 +323,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19702 {
19703 switch (action) {
19704 case CPU_DYING:
19705- atomic_inc(&ap_wfs_count);
19706+ atomic_inc_unchecked(&ap_wfs_count);
19707 if (num_online_cpus() == 1)
19708- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19709+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19710 return NOTIFY_BAD;
19711 break;
19712 }
19713@@ -344,7 +344,7 @@ static __init int tboot_late_init(void)
19714
19715 tboot_create_trampoline();
19716
19717- atomic_set(&ap_wfs_count, 0);
19718+ atomic_set_unchecked(&ap_wfs_count, 0);
19719 register_hotcpu_notifier(&tboot_cpu_notifier);
19720
19721 acpi_os_set_prepare_sleep(&tboot_sleep);
19722diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19723index c6eba2b..3303326 100644
19724--- a/arch/x86/kernel/time.c
19725+++ b/arch/x86/kernel/time.c
19726@@ -31,9 +31,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19727 {
19728 unsigned long pc = instruction_pointer(regs);
19729
19730- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19731+ if (!user_mode(regs) && in_lock_functions(pc)) {
19732 #ifdef CONFIG_FRAME_POINTER
19733- return *(unsigned long *)(regs->bp + sizeof(long));
19734+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19735 #else
19736 unsigned long *sp =
19737 (unsigned long *)kernel_stack_pointer(regs);
19738@@ -42,11 +42,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19739 * or above a saved flags. Eflags has bits 22-31 zero,
19740 * kernel addresses don't.
19741 */
19742+
19743+#ifdef CONFIG_PAX_KERNEXEC
19744+ return ktla_ktva(sp[0]);
19745+#else
19746 if (sp[0] >> 22)
19747 return sp[0];
19748 if (sp[1] >> 22)
19749 return sp[1];
19750 #endif
19751+
19752+#endif
19753 }
19754 return pc;
19755 }
19756diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19757index 9d9d2f9..ed344e4 100644
19758--- a/arch/x86/kernel/tls.c
19759+++ b/arch/x86/kernel/tls.c
19760@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19761 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19762 return -EINVAL;
19763
19764+#ifdef CONFIG_PAX_SEGMEXEC
19765+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19766+ return -EINVAL;
19767+#endif
19768+
19769 set_tls_desc(p, idx, &info, 1);
19770
19771 return 0;
19772diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
19773index 451c0a7..e57f551 100644
19774--- a/arch/x86/kernel/trampoline_32.S
19775+++ b/arch/x86/kernel/trampoline_32.S
19776@@ -32,6 +32,12 @@
19777 #include <asm/segment.h>
19778 #include <asm/page_types.h>
19779
19780+#ifdef CONFIG_PAX_KERNEXEC
19781+#define ta(X) (X)
19782+#else
19783+#define ta(X) ((X) - __PAGE_OFFSET)
19784+#endif
19785+
19786 #ifdef CONFIG_SMP
19787
19788 .section ".x86_trampoline","a"
19789@@ -62,7 +68,7 @@ r_base = .
19790 inc %ax # protected mode (PE) bit
19791 lmsw %ax # into protected mode
19792 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
19793- ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
19794+ ljmpl $__BOOT_CS, $ta(startup_32_smp)
19795
19796 # These need to be in the same 64K segment as the above;
19797 # hence we don't use the boot_gdt_descr defined in head.S
19798diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
19799index 09ff517..df19fbff 100644
19800--- a/arch/x86/kernel/trampoline_64.S
19801+++ b/arch/x86/kernel/trampoline_64.S
19802@@ -90,7 +90,7 @@ startup_32:
19803 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
19804 movl %eax, %ds
19805
19806- movl $X86_CR4_PAE, %eax
19807+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19808 movl %eax, %cr4 # Enable PAE mode
19809
19810 # Setup trampoline 4 level pagetables
19811@@ -138,7 +138,7 @@ tidt:
19812 # so the kernel can live anywhere
19813 .balign 4
19814 tgdt:
19815- .short tgdt_end - tgdt # gdt limit
19816+ .short tgdt_end - tgdt - 1 # gdt limit
19817 .long tgdt - r_base
19818 .short 0
19819 .quad 0x00cf9b000000ffff # __KERNEL32_CS
19820diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19821index ff9281f1..30cb4ac 100644
19822--- a/arch/x86/kernel/traps.c
19823+++ b/arch/x86/kernel/traps.c
19824@@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19825
19826 /* Do we ignore FPU interrupts ? */
19827 char ignore_fpu_irq;
19828-
19829-/*
19830- * The IDT has to be page-aligned to simplify the Pentium
19831- * F0 0F bug workaround.
19832- */
19833-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19834 #endif
19835
19836 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19837@@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19838 }
19839
19840 static void __kprobes
19841-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19842+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19843 long error_code, siginfo_t *info)
19844 {
19845 struct task_struct *tsk = current;
19846
19847 #ifdef CONFIG_X86_32
19848- if (regs->flags & X86_VM_MASK) {
19849+ if (v8086_mode(regs)) {
19850 /*
19851 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19852 * On nmi (interrupt 2), do_trap should not be called.
19853@@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19854 }
19855 #endif
19856
19857- if (!user_mode(regs))
19858+ if (!user_mode_novm(regs))
19859 goto kernel_trap;
19860
19861 #ifdef CONFIG_X86_32
19862@@ -148,7 +142,7 @@ trap_signal:
19863 printk_ratelimit()) {
19864 printk(KERN_INFO
19865 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19866- tsk->comm, tsk->pid, str,
19867+ tsk->comm, task_pid_nr(tsk), str,
19868 regs->ip, regs->sp, error_code);
19869 print_vma_addr(" in ", regs->ip);
19870 printk("\n");
19871@@ -165,8 +159,20 @@ kernel_trap:
19872 if (!fixup_exception(regs)) {
19873 tsk->thread.error_code = error_code;
19874 tsk->thread.trap_nr = trapnr;
19875+
19876+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19877+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19878+ str = "PAX: suspicious stack segment fault";
19879+#endif
19880+
19881 die(str, regs, error_code);
19882 }
19883+
19884+#ifdef CONFIG_PAX_REFCOUNT
19885+ if (trapnr == 4)
19886+ pax_report_refcount_overflow(regs);
19887+#endif
19888+
19889 return;
19890
19891 #ifdef CONFIG_X86_32
19892@@ -259,14 +265,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19893 conditional_sti(regs);
19894
19895 #ifdef CONFIG_X86_32
19896- if (regs->flags & X86_VM_MASK)
19897+ if (v8086_mode(regs))
19898 goto gp_in_vm86;
19899 #endif
19900
19901 tsk = current;
19902- if (!user_mode(regs))
19903+ if (!user_mode_novm(regs))
19904 goto gp_in_kernel;
19905
19906+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19907+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19908+ struct mm_struct *mm = tsk->mm;
19909+ unsigned long limit;
19910+
19911+ down_write(&mm->mmap_sem);
19912+ limit = mm->context.user_cs_limit;
19913+ if (limit < TASK_SIZE) {
19914+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19915+ up_write(&mm->mmap_sem);
19916+ return;
19917+ }
19918+ up_write(&mm->mmap_sem);
19919+ }
19920+#endif
19921+
19922 tsk->thread.error_code = error_code;
19923 tsk->thread.trap_nr = X86_TRAP_GP;
19924
19925@@ -299,6 +321,13 @@ gp_in_kernel:
19926 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19927 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19928 return;
19929+
19930+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19931+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19932+ die("PAX: suspicious general protection fault", regs, error_code);
19933+ else
19934+#endif
19935+
19936 die("general protection fault", regs, error_code);
19937 }
19938
19939@@ -425,7 +454,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19940 /* It's safe to allow irq's after DR6 has been saved */
19941 preempt_conditional_sti(regs);
19942
19943- if (regs->flags & X86_VM_MASK) {
19944+ if (v8086_mode(regs)) {
19945 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19946 X86_TRAP_DB);
19947 preempt_conditional_cli(regs);
19948@@ -440,7 +469,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19949 * We already checked v86 mode above, so we can check for kernel mode
19950 * by just checking the CPL of CS.
19951 */
19952- if ((dr6 & DR_STEP) && !user_mode(regs)) {
19953+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19954 tsk->thread.debugreg6 &= ~DR_STEP;
19955 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19956 regs->flags &= ~X86_EFLAGS_TF;
19957@@ -471,7 +500,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19958 return;
19959 conditional_sti(regs);
19960
19961- if (!user_mode_vm(regs))
19962+ if (!user_mode(regs))
19963 {
19964 if (!fixup_exception(regs)) {
19965 task->thread.error_code = error_code;
19966diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19967index b9242ba..50c5edd 100644
19968--- a/arch/x86/kernel/verify_cpu.S
19969+++ b/arch/x86/kernel/verify_cpu.S
19970@@ -20,6 +20,7 @@
19971 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19972 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19973 * arch/x86/kernel/head_32.S: processor startup
19974+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19975 *
19976 * verify_cpu, returns the status of longmode and SSE in register %eax.
19977 * 0: Success 1: Failure
19978diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19979index 255f58a..5e91150 100644
19980--- a/arch/x86/kernel/vm86_32.c
19981+++ b/arch/x86/kernel/vm86_32.c
19982@@ -41,6 +41,7 @@
19983 #include <linux/ptrace.h>
19984 #include <linux/audit.h>
19985 #include <linux/stddef.h>
19986+#include <linux/grsecurity.h>
19987
19988 #include <asm/uaccess.h>
19989 #include <asm/io.h>
19990@@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19991 do_exit(SIGSEGV);
19992 }
19993
19994- tss = &per_cpu(init_tss, get_cpu());
19995+ tss = init_tss + get_cpu();
19996 current->thread.sp0 = current->thread.saved_sp0;
19997 current->thread.sysenter_cs = __KERNEL_CS;
19998 load_sp0(tss, &current->thread);
19999@@ -210,6 +211,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
20000 struct task_struct *tsk;
20001 int tmp, ret = -EPERM;
20002
20003+#ifdef CONFIG_GRKERNSEC_VM86
20004+ if (!capable(CAP_SYS_RAWIO)) {
20005+ gr_handle_vm86();
20006+ goto out;
20007+ }
20008+#endif
20009+
20010 tsk = current;
20011 if (tsk->thread.saved_sp0)
20012 goto out;
20013@@ -240,6 +248,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
20014 int tmp, ret;
20015 struct vm86plus_struct __user *v86;
20016
20017+#ifdef CONFIG_GRKERNSEC_VM86
20018+ if (!capable(CAP_SYS_RAWIO)) {
20019+ gr_handle_vm86();
20020+ ret = -EPERM;
20021+ goto out;
20022+ }
20023+#endif
20024+
20025 tsk = current;
20026 switch (cmd) {
20027 case VM86_REQUEST_IRQ:
20028@@ -326,7 +342,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
20029 tsk->thread.saved_fs = info->regs32->fs;
20030 tsk->thread.saved_gs = get_user_gs(info->regs32);
20031
20032- tss = &per_cpu(init_tss, get_cpu());
20033+ tss = init_tss + get_cpu();
20034 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
20035 if (cpu_has_sep)
20036 tsk->thread.sysenter_cs = 0;
20037@@ -533,7 +549,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
20038 goto cannot_handle;
20039 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
20040 goto cannot_handle;
20041- intr_ptr = (unsigned long __user *) (i << 2);
20042+ intr_ptr = (__force unsigned long __user *) (i << 2);
20043 if (get_user(segoffs, intr_ptr))
20044 goto cannot_handle;
20045 if ((segoffs >> 16) == BIOSSEG)
20046diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20047index 0f703f1..9e15f64 100644
20048--- a/arch/x86/kernel/vmlinux.lds.S
20049+++ b/arch/x86/kernel/vmlinux.lds.S
20050@@ -26,6 +26,13 @@
20051 #include <asm/page_types.h>
20052 #include <asm/cache.h>
20053 #include <asm/boot.h>
20054+#include <asm/segment.h>
20055+
20056+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20057+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20058+#else
20059+#define __KERNEL_TEXT_OFFSET 0
20060+#endif
20061
20062 #undef i386 /* in case the preprocessor is a 32bit one */
20063
20064@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20065
20066 PHDRS {
20067 text PT_LOAD FLAGS(5); /* R_E */
20068+#ifdef CONFIG_X86_32
20069+ module PT_LOAD FLAGS(5); /* R_E */
20070+#endif
20071+#ifdef CONFIG_XEN
20072+ rodata PT_LOAD FLAGS(5); /* R_E */
20073+#else
20074+ rodata PT_LOAD FLAGS(4); /* R__ */
20075+#endif
20076 data PT_LOAD FLAGS(6); /* RW_ */
20077-#ifdef CONFIG_X86_64
20078+ init.begin PT_LOAD FLAGS(6); /* RW_ */
20079 #ifdef CONFIG_SMP
20080 percpu PT_LOAD FLAGS(6); /* RW_ */
20081 #endif
20082+ text.init PT_LOAD FLAGS(5); /* R_E */
20083+ text.exit PT_LOAD FLAGS(5); /* R_E */
20084 init PT_LOAD FLAGS(7); /* RWE */
20085-#endif
20086 note PT_NOTE FLAGS(0); /* ___ */
20087 }
20088
20089 SECTIONS
20090 {
20091 #ifdef CONFIG_X86_32
20092- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20093- phys_startup_32 = startup_32 - LOAD_OFFSET;
20094+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20095 #else
20096- . = __START_KERNEL;
20097- phys_startup_64 = startup_64 - LOAD_OFFSET;
20098+ . = __START_KERNEL;
20099 #endif
20100
20101 /* Text and read-only data */
20102- .text : AT(ADDR(.text) - LOAD_OFFSET) {
20103- _text = .;
20104+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20105 /* bootstrapping code */
20106+#ifdef CONFIG_X86_32
20107+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20108+#else
20109+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20110+#endif
20111+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20112+ _text = .;
20113 HEAD_TEXT
20114 #ifdef CONFIG_X86_32
20115 . = ALIGN(PAGE_SIZE);
20116@@ -108,13 +128,47 @@ SECTIONS
20117 IRQENTRY_TEXT
20118 *(.fixup)
20119 *(.gnu.warning)
20120- /* End of text section */
20121- _etext = .;
20122 } :text = 0x9090
20123
20124- NOTES :text :note
20125+ . += __KERNEL_TEXT_OFFSET;
20126
20127- EXCEPTION_TABLE(16) :text = 0x9090
20128+#ifdef CONFIG_X86_32
20129+ . = ALIGN(PAGE_SIZE);
20130+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20131+
20132+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20133+ MODULES_EXEC_VADDR = .;
20134+ BYTE(0)
20135+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20136+ . = ALIGN(HPAGE_SIZE);
20137+ MODULES_EXEC_END = . - 1;
20138+#endif
20139+
20140+ } :module
20141+#endif
20142+
20143+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20144+ /* End of text section */
20145+ _etext = . - __KERNEL_TEXT_OFFSET;
20146+ }
20147+
20148+#ifdef CONFIG_X86_32
20149+ . = ALIGN(PAGE_SIZE);
20150+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20151+ *(.idt)
20152+ . = ALIGN(PAGE_SIZE);
20153+ *(.empty_zero_page)
20154+ *(.initial_pg_fixmap)
20155+ *(.initial_pg_pmd)
20156+ *(.initial_page_table)
20157+ *(.swapper_pg_dir)
20158+ } :rodata
20159+#endif
20160+
20161+ . = ALIGN(PAGE_SIZE);
20162+ NOTES :rodata :note
20163+
20164+ EXCEPTION_TABLE(16) :rodata
20165
20166 #if defined(CONFIG_DEBUG_RODATA)
20167 /* .text should occupy whole number of pages */
20168@@ -126,16 +180,20 @@ SECTIONS
20169
20170 /* Data */
20171 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20172+
20173+#ifdef CONFIG_PAX_KERNEXEC
20174+ . = ALIGN(HPAGE_SIZE);
20175+#else
20176+ . = ALIGN(PAGE_SIZE);
20177+#endif
20178+
20179 /* Start of data section */
20180 _sdata = .;
20181
20182 /* init_task */
20183 INIT_TASK_DATA(THREAD_SIZE)
20184
20185-#ifdef CONFIG_X86_32
20186- /* 32 bit has nosave before _edata */
20187 NOSAVE_DATA
20188-#endif
20189
20190 PAGE_ALIGNED_DATA(PAGE_SIZE)
20191
20192@@ -176,12 +234,19 @@ SECTIONS
20193 #endif /* CONFIG_X86_64 */
20194
20195 /* Init code and data - will be freed after init */
20196- . = ALIGN(PAGE_SIZE);
20197 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20198+ BYTE(0)
20199+
20200+#ifdef CONFIG_PAX_KERNEXEC
20201+ . = ALIGN(HPAGE_SIZE);
20202+#else
20203+ . = ALIGN(PAGE_SIZE);
20204+#endif
20205+
20206 __init_begin = .; /* paired with __init_end */
20207- }
20208+ } :init.begin
20209
20210-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20211+#ifdef CONFIG_SMP
20212 /*
20213 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20214 * output PHDR, so the next output section - .init.text - should
20215@@ -190,12 +255,27 @@ SECTIONS
20216 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20217 #endif
20218
20219- INIT_TEXT_SECTION(PAGE_SIZE)
20220-#ifdef CONFIG_X86_64
20221- :init
20222-#endif
20223+ . = ALIGN(PAGE_SIZE);
20224+ init_begin = .;
20225+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20226+ VMLINUX_SYMBOL(_sinittext) = .;
20227+ INIT_TEXT
20228+ VMLINUX_SYMBOL(_einittext) = .;
20229+ . = ALIGN(PAGE_SIZE);
20230+ } :text.init
20231
20232- INIT_DATA_SECTION(16)
20233+ /*
20234+ * .exit.text is discard at runtime, not link time, to deal with
20235+ * references from .altinstructions and .eh_frame
20236+ */
20237+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20238+ EXIT_TEXT
20239+ . = ALIGN(16);
20240+ } :text.exit
20241+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20242+
20243+ . = ALIGN(PAGE_SIZE);
20244+ INIT_DATA_SECTION(16) :init
20245
20246 /*
20247 * Code and data for a variety of lowlevel trampolines, to be
20248@@ -269,19 +349,12 @@ SECTIONS
20249 }
20250
20251 . = ALIGN(8);
20252- /*
20253- * .exit.text is discard at runtime, not link time, to deal with
20254- * references from .altinstructions and .eh_frame
20255- */
20256- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20257- EXIT_TEXT
20258- }
20259
20260 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20261 EXIT_DATA
20262 }
20263
20264-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20265+#ifndef CONFIG_SMP
20266 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20267 #endif
20268
20269@@ -300,16 +373,10 @@ SECTIONS
20270 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20271 __smp_locks = .;
20272 *(.smp_locks)
20273- . = ALIGN(PAGE_SIZE);
20274 __smp_locks_end = .;
20275+ . = ALIGN(PAGE_SIZE);
20276 }
20277
20278-#ifdef CONFIG_X86_64
20279- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20280- NOSAVE_DATA
20281- }
20282-#endif
20283-
20284 /* BSS */
20285 . = ALIGN(PAGE_SIZE);
20286 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20287@@ -325,6 +392,7 @@ SECTIONS
20288 __brk_base = .;
20289 . += 64 * 1024; /* 64k alignment slop space */
20290 *(.brk_reservation) /* areas brk users have reserved */
20291+ . = ALIGN(HPAGE_SIZE);
20292 __brk_limit = .;
20293 }
20294
20295@@ -351,13 +419,12 @@ SECTIONS
20296 * for the boot processor.
20297 */
20298 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20299-INIT_PER_CPU(gdt_page);
20300 INIT_PER_CPU(irq_stack_union);
20301
20302 /*
20303 * Build-time check on the image size:
20304 */
20305-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20306+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20307 "kernel image bigger than KERNEL_IMAGE_SIZE");
20308
20309 #ifdef CONFIG_SMP
20310diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20311index 7515cf0..331a1a0 100644
20312--- a/arch/x86/kernel/vsyscall_64.c
20313+++ b/arch/x86/kernel/vsyscall_64.c
20314@@ -54,15 +54,13 @@
20315 DEFINE_VVAR(int, vgetcpu_mode);
20316 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20317
20318-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20319+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20320
20321 static int __init vsyscall_setup(char *str)
20322 {
20323 if (str) {
20324 if (!strcmp("emulate", str))
20325 vsyscall_mode = EMULATE;
20326- else if (!strcmp("native", str))
20327- vsyscall_mode = NATIVE;
20328 else if (!strcmp("none", str))
20329 vsyscall_mode = NONE;
20330 else
20331@@ -206,7 +204,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
20332
20333 tsk = current;
20334 if (seccomp_mode(&tsk->seccomp))
20335- do_exit(SIGKILL);
20336+ do_group_exit(SIGKILL);
20337
20338 /*
20339 * With a real vsyscall, page faults cause SIGSEGV. We want to
20340@@ -278,8 +276,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
20341 return true;
20342
20343 sigsegv:
20344- force_sig(SIGSEGV, current);
20345- return true;
20346+ do_group_exit(SIGKILL);
20347 }
20348
20349 /*
20350@@ -332,10 +329,7 @@ void __init map_vsyscall(void)
20351 extern char __vvar_page;
20352 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20353
20354- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20355- vsyscall_mode == NATIVE
20356- ? PAGE_KERNEL_VSYSCALL
20357- : PAGE_KERNEL_VVAR);
20358+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20359 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20360 (unsigned long)VSYSCALL_START);
20361
20362diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20363index 9796c2f..f686fbf 100644
20364--- a/arch/x86/kernel/x8664_ksyms_64.c
20365+++ b/arch/x86/kernel/x8664_ksyms_64.c
20366@@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
20367 EXPORT_SYMBOL(copy_user_generic_string);
20368 EXPORT_SYMBOL(copy_user_generic_unrolled);
20369 EXPORT_SYMBOL(__copy_user_nocache);
20370-EXPORT_SYMBOL(_copy_from_user);
20371-EXPORT_SYMBOL(_copy_to_user);
20372
20373 EXPORT_SYMBOL(copy_page);
20374 EXPORT_SYMBOL(clear_page);
20375diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20376index e62728e..5fc3a07 100644
20377--- a/arch/x86/kernel/xsave.c
20378+++ b/arch/x86/kernel/xsave.c
20379@@ -131,7 +131,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20380 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20381 return -EINVAL;
20382
20383- err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20384+ err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20385 fx_sw_user->extended_size -
20386 FP_XSTATE_MAGIC2_SIZE));
20387 if (err)
20388@@ -267,7 +267,7 @@ fx_only:
20389 * the other extended state.
20390 */
20391 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20392- return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20393+ return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20394 }
20395
20396 /*
20397@@ -296,7 +296,7 @@ int restore_i387_xstate(void __user *buf)
20398 if (use_xsave())
20399 err = restore_user_xstate(buf);
20400 else
20401- err = fxrstor_checking((__force struct i387_fxsave_struct *)
20402+ err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20403 buf);
20404 if (unlikely(err)) {
20405 /*
20406diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20407index 9fed5be..18fd595 100644
20408--- a/arch/x86/kvm/cpuid.c
20409+++ b/arch/x86/kvm/cpuid.c
20410@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20411 struct kvm_cpuid2 *cpuid,
20412 struct kvm_cpuid_entry2 __user *entries)
20413 {
20414- int r;
20415+ int r, i;
20416
20417 r = -E2BIG;
20418 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20419 goto out;
20420 r = -EFAULT;
20421- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20422- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20423+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20424 goto out;
20425+ for (i = 0; i < cpuid->nent; ++i) {
20426+ struct kvm_cpuid_entry2 cpuid_entry;
20427+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20428+ goto out;
20429+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
20430+ }
20431 vcpu->arch.cpuid_nent = cpuid->nent;
20432 kvm_apic_set_version(vcpu);
20433 kvm_x86_ops->cpuid_update(vcpu);
20434@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20435 struct kvm_cpuid2 *cpuid,
20436 struct kvm_cpuid_entry2 __user *entries)
20437 {
20438- int r;
20439+ int r, i;
20440
20441 r = -E2BIG;
20442 if (cpuid->nent < vcpu->arch.cpuid_nent)
20443 goto out;
20444 r = -EFAULT;
20445- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20446- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20447+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20448 goto out;
20449+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20450+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20451+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20452+ goto out;
20453+ }
20454 return 0;
20455
20456 out:
20457diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20458index 8375622..b7bca1a 100644
20459--- a/arch/x86/kvm/emulate.c
20460+++ b/arch/x86/kvm/emulate.c
20461@@ -252,6 +252,7 @@ struct gprefix {
20462
20463 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20464 do { \
20465+ unsigned long _tmp; \
20466 __asm__ __volatile__ ( \
20467 _PRE_EFLAGS("0", "4", "2") \
20468 _op _suffix " %"_x"3,%1; " \
20469@@ -266,8 +267,6 @@ struct gprefix {
20470 /* Raw emulation: instruction has two explicit operands. */
20471 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20472 do { \
20473- unsigned long _tmp; \
20474- \
20475 switch ((ctxt)->dst.bytes) { \
20476 case 2: \
20477 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20478@@ -283,7 +282,6 @@ struct gprefix {
20479
20480 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20481 do { \
20482- unsigned long _tmp; \
20483 switch ((ctxt)->dst.bytes) { \
20484 case 1: \
20485 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20486diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20487index 8584322..17d5955 100644
20488--- a/arch/x86/kvm/lapic.c
20489+++ b/arch/x86/kvm/lapic.c
20490@@ -54,7 +54,7 @@
20491 #define APIC_BUS_CYCLE_NS 1
20492
20493 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20494-#define apic_debug(fmt, arg...)
20495+#define apic_debug(fmt, arg...) do {} while (0)
20496
20497 #define APIC_LVT_NUM 6
20498 /* 14 is the version for Xeon and Pentium 8.4.8*/
20499diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20500index df5a703..63748a7 100644
20501--- a/arch/x86/kvm/paging_tmpl.h
20502+++ b/arch/x86/kvm/paging_tmpl.h
20503@@ -197,7 +197,7 @@ retry_walk:
20504 if (unlikely(kvm_is_error_hva(host_addr)))
20505 goto error;
20506
20507- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20508+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20509 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20510 goto error;
20511
20512diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20513index e334389..6839087 100644
20514--- a/arch/x86/kvm/svm.c
20515+++ b/arch/x86/kvm/svm.c
20516@@ -3509,7 +3509,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20517 int cpu = raw_smp_processor_id();
20518
20519 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20520+
20521+ pax_open_kernel();
20522 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20523+ pax_close_kernel();
20524+
20525 load_TR_desc();
20526 }
20527
20528@@ -3887,6 +3891,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20529 #endif
20530 #endif
20531
20532+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20533+ __set_fs(current_thread_info()->addr_limit);
20534+#endif
20535+
20536 reload_tss(vcpu);
20537
20538 local_irq_disable();
20539diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20540index 4ff0ab9..2ff68d3 100644
20541--- a/arch/x86/kvm/vmx.c
20542+++ b/arch/x86/kvm/vmx.c
20543@@ -1303,7 +1303,11 @@ static void reload_tss(void)
20544 struct desc_struct *descs;
20545
20546 descs = (void *)gdt->address;
20547+
20548+ pax_open_kernel();
20549 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20550+ pax_close_kernel();
20551+
20552 load_TR_desc();
20553 }
20554
20555@@ -2625,8 +2629,11 @@ static __init int hardware_setup(void)
20556 if (!cpu_has_vmx_flexpriority())
20557 flexpriority_enabled = 0;
20558
20559- if (!cpu_has_vmx_tpr_shadow())
20560- kvm_x86_ops->update_cr8_intercept = NULL;
20561+ if (!cpu_has_vmx_tpr_shadow()) {
20562+ pax_open_kernel();
20563+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20564+ pax_close_kernel();
20565+ }
20566
20567 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20568 kvm_disable_largepages();
20569@@ -3642,7 +3649,7 @@ static void vmx_set_constant_host_state(void)
20570 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20571
20572 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20573- vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20574+ vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20575
20576 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20577 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20578@@ -6180,6 +6187,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20579 "jmp .Lkvm_vmx_return \n\t"
20580 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20581 ".Lkvm_vmx_return: "
20582+
20583+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20584+ "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20585+ ".Lkvm_vmx_return2: "
20586+#endif
20587+
20588 /* Save guest registers, load host registers, keep flags */
20589 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20590 "pop %0 \n\t"
20591@@ -6228,6 +6241,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20592 #endif
20593 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20594 [wordsize]"i"(sizeof(ulong))
20595+
20596+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20597+ ,[cs]"i"(__KERNEL_CS)
20598+#endif
20599+
20600 : "cc", "memory"
20601 , R"ax", R"bx", R"di", R"si"
20602 #ifdef CONFIG_X86_64
20603@@ -6256,7 +6274,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20604 }
20605 }
20606
20607- asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
20608+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
20609+
20610+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20611+ loadsegment(fs, __KERNEL_PERCPU);
20612+#endif
20613+
20614+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20615+ __set_fs(current_thread_info()->addr_limit);
20616+#endif
20617+
20618 vmx->loaded_vmcs->launched = 1;
20619
20620 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
20621diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20622index 185a2b8..866d2a6 100644
20623--- a/arch/x86/kvm/x86.c
20624+++ b/arch/x86/kvm/x86.c
20625@@ -1357,8 +1357,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20626 {
20627 struct kvm *kvm = vcpu->kvm;
20628 int lm = is_long_mode(vcpu);
20629- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20630- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20631+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20632+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20633 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20634 : kvm->arch.xen_hvm_config.blob_size_32;
20635 u32 page_num = data & ~PAGE_MASK;
20636@@ -2213,6 +2213,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20637 if (n < msr_list.nmsrs)
20638 goto out;
20639 r = -EFAULT;
20640+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20641+ goto out;
20642 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20643 num_msrs_to_save * sizeof(u32)))
20644 goto out;
20645@@ -2338,7 +2340,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20646 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20647 struct kvm_interrupt *irq)
20648 {
20649- if (irq->irq < 0 || irq->irq >= 256)
20650+ if (irq->irq >= 256)
20651 return -EINVAL;
20652 if (irqchip_in_kernel(vcpu->kvm))
20653 return -ENXIO;
20654@@ -4860,7 +4862,7 @@ static void kvm_set_mmio_spte_mask(void)
20655 kvm_mmu_set_mmio_spte_mask(mask);
20656 }
20657
20658-int kvm_arch_init(void *opaque)
20659+int kvm_arch_init(const void *opaque)
20660 {
20661 int r;
20662 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20663diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20664index 642d880..44e0f3f 100644
20665--- a/arch/x86/lguest/boot.c
20666+++ b/arch/x86/lguest/boot.c
20667@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20668 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20669 * Launcher to reboot us.
20670 */
20671-static void lguest_restart(char *reason)
20672+static __noreturn void lguest_restart(char *reason)
20673 {
20674 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20675+ BUG();
20676 }
20677
20678 /*G:050
20679diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20680index 00933d5..3a64af9 100644
20681--- a/arch/x86/lib/atomic64_386_32.S
20682+++ b/arch/x86/lib/atomic64_386_32.S
20683@@ -48,6 +48,10 @@ BEGIN(read)
20684 movl (v), %eax
20685 movl 4(v), %edx
20686 RET_ENDP
20687+BEGIN(read_unchecked)
20688+ movl (v), %eax
20689+ movl 4(v), %edx
20690+RET_ENDP
20691 #undef v
20692
20693 #define v %esi
20694@@ -55,6 +59,10 @@ BEGIN(set)
20695 movl %ebx, (v)
20696 movl %ecx, 4(v)
20697 RET_ENDP
20698+BEGIN(set_unchecked)
20699+ movl %ebx, (v)
20700+ movl %ecx, 4(v)
20701+RET_ENDP
20702 #undef v
20703
20704 #define v %esi
20705@@ -70,6 +78,20 @@ RET_ENDP
20706 BEGIN(add)
20707 addl %eax, (v)
20708 adcl %edx, 4(v)
20709+
20710+#ifdef CONFIG_PAX_REFCOUNT
20711+ jno 0f
20712+ subl %eax, (v)
20713+ sbbl %edx, 4(v)
20714+ int $4
20715+0:
20716+ _ASM_EXTABLE(0b, 0b)
20717+#endif
20718+
20719+RET_ENDP
20720+BEGIN(add_unchecked)
20721+ addl %eax, (v)
20722+ adcl %edx, 4(v)
20723 RET_ENDP
20724 #undef v
20725
20726@@ -77,6 +99,24 @@ RET_ENDP
20727 BEGIN(add_return)
20728 addl (v), %eax
20729 adcl 4(v), %edx
20730+
20731+#ifdef CONFIG_PAX_REFCOUNT
20732+ into
20733+1234:
20734+ _ASM_EXTABLE(1234b, 2f)
20735+#endif
20736+
20737+ movl %eax, (v)
20738+ movl %edx, 4(v)
20739+
20740+#ifdef CONFIG_PAX_REFCOUNT
20741+2:
20742+#endif
20743+
20744+RET_ENDP
20745+BEGIN(add_return_unchecked)
20746+ addl (v), %eax
20747+ adcl 4(v), %edx
20748 movl %eax, (v)
20749 movl %edx, 4(v)
20750 RET_ENDP
20751@@ -86,6 +126,20 @@ RET_ENDP
20752 BEGIN(sub)
20753 subl %eax, (v)
20754 sbbl %edx, 4(v)
20755+
20756+#ifdef CONFIG_PAX_REFCOUNT
20757+ jno 0f
20758+ addl %eax, (v)
20759+ adcl %edx, 4(v)
20760+ int $4
20761+0:
20762+ _ASM_EXTABLE(0b, 0b)
20763+#endif
20764+
20765+RET_ENDP
20766+BEGIN(sub_unchecked)
20767+ subl %eax, (v)
20768+ sbbl %edx, 4(v)
20769 RET_ENDP
20770 #undef v
20771
20772@@ -96,6 +150,27 @@ BEGIN(sub_return)
20773 sbbl $0, %edx
20774 addl (v), %eax
20775 adcl 4(v), %edx
20776+
20777+#ifdef CONFIG_PAX_REFCOUNT
20778+ into
20779+1234:
20780+ _ASM_EXTABLE(1234b, 2f)
20781+#endif
20782+
20783+ movl %eax, (v)
20784+ movl %edx, 4(v)
20785+
20786+#ifdef CONFIG_PAX_REFCOUNT
20787+2:
20788+#endif
20789+
20790+RET_ENDP
20791+BEGIN(sub_return_unchecked)
20792+ negl %edx
20793+ negl %eax
20794+ sbbl $0, %edx
20795+ addl (v), %eax
20796+ adcl 4(v), %edx
20797 movl %eax, (v)
20798 movl %edx, 4(v)
20799 RET_ENDP
20800@@ -105,6 +180,20 @@ RET_ENDP
20801 BEGIN(inc)
20802 addl $1, (v)
20803 adcl $0, 4(v)
20804+
20805+#ifdef CONFIG_PAX_REFCOUNT
20806+ jno 0f
20807+ subl $1, (v)
20808+ sbbl $0, 4(v)
20809+ int $4
20810+0:
20811+ _ASM_EXTABLE(0b, 0b)
20812+#endif
20813+
20814+RET_ENDP
20815+BEGIN(inc_unchecked)
20816+ addl $1, (v)
20817+ adcl $0, 4(v)
20818 RET_ENDP
20819 #undef v
20820
20821@@ -114,6 +203,26 @@ BEGIN(inc_return)
20822 movl 4(v), %edx
20823 addl $1, %eax
20824 adcl $0, %edx
20825+
20826+#ifdef CONFIG_PAX_REFCOUNT
20827+ into
20828+1234:
20829+ _ASM_EXTABLE(1234b, 2f)
20830+#endif
20831+
20832+ movl %eax, (v)
20833+ movl %edx, 4(v)
20834+
20835+#ifdef CONFIG_PAX_REFCOUNT
20836+2:
20837+#endif
20838+
20839+RET_ENDP
20840+BEGIN(inc_return_unchecked)
20841+ movl (v), %eax
20842+ movl 4(v), %edx
20843+ addl $1, %eax
20844+ adcl $0, %edx
20845 movl %eax, (v)
20846 movl %edx, 4(v)
20847 RET_ENDP
20848@@ -123,6 +232,20 @@ RET_ENDP
20849 BEGIN(dec)
20850 subl $1, (v)
20851 sbbl $0, 4(v)
20852+
20853+#ifdef CONFIG_PAX_REFCOUNT
20854+ jno 0f
20855+ addl $1, (v)
20856+ adcl $0, 4(v)
20857+ int $4
20858+0:
20859+ _ASM_EXTABLE(0b, 0b)
20860+#endif
20861+
20862+RET_ENDP
20863+BEGIN(dec_unchecked)
20864+ subl $1, (v)
20865+ sbbl $0, 4(v)
20866 RET_ENDP
20867 #undef v
20868
20869@@ -132,6 +255,26 @@ BEGIN(dec_return)
20870 movl 4(v), %edx
20871 subl $1, %eax
20872 sbbl $0, %edx
20873+
20874+#ifdef CONFIG_PAX_REFCOUNT
20875+ into
20876+1234:
20877+ _ASM_EXTABLE(1234b, 2f)
20878+#endif
20879+
20880+ movl %eax, (v)
20881+ movl %edx, 4(v)
20882+
20883+#ifdef CONFIG_PAX_REFCOUNT
20884+2:
20885+#endif
20886+
20887+RET_ENDP
20888+BEGIN(dec_return_unchecked)
20889+ movl (v), %eax
20890+ movl 4(v), %edx
20891+ subl $1, %eax
20892+ sbbl $0, %edx
20893 movl %eax, (v)
20894 movl %edx, 4(v)
20895 RET_ENDP
20896@@ -143,6 +286,13 @@ BEGIN(add_unless)
20897 adcl %edx, %edi
20898 addl (v), %eax
20899 adcl 4(v), %edx
20900+
20901+#ifdef CONFIG_PAX_REFCOUNT
20902+ into
20903+1234:
20904+ _ASM_EXTABLE(1234b, 2f)
20905+#endif
20906+
20907 cmpl %eax, %ecx
20908 je 3f
20909 1:
20910@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20911 1:
20912 addl $1, %eax
20913 adcl $0, %edx
20914+
20915+#ifdef CONFIG_PAX_REFCOUNT
20916+ into
20917+1234:
20918+ _ASM_EXTABLE(1234b, 2f)
20919+#endif
20920+
20921 movl %eax, (v)
20922 movl %edx, 4(v)
20923 movl $1, %eax
20924@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20925 movl 4(v), %edx
20926 subl $1, %eax
20927 sbbl $0, %edx
20928+
20929+#ifdef CONFIG_PAX_REFCOUNT
20930+ into
20931+1234:
20932+ _ASM_EXTABLE(1234b, 1f)
20933+#endif
20934+
20935 js 1f
20936 movl %eax, (v)
20937 movl %edx, 4(v)
20938diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20939index f5cc9eb..51fa319 100644
20940--- a/arch/x86/lib/atomic64_cx8_32.S
20941+++ b/arch/x86/lib/atomic64_cx8_32.S
20942@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20943 CFI_STARTPROC
20944
20945 read64 %ecx
20946+ pax_force_retaddr
20947 ret
20948 CFI_ENDPROC
20949 ENDPROC(atomic64_read_cx8)
20950
20951+ENTRY(atomic64_read_unchecked_cx8)
20952+ CFI_STARTPROC
20953+
20954+ read64 %ecx
20955+ pax_force_retaddr
20956+ ret
20957+ CFI_ENDPROC
20958+ENDPROC(atomic64_read_unchecked_cx8)
20959+
20960 ENTRY(atomic64_set_cx8)
20961 CFI_STARTPROC
20962
20963@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20964 cmpxchg8b (%esi)
20965 jne 1b
20966
20967+ pax_force_retaddr
20968 ret
20969 CFI_ENDPROC
20970 ENDPROC(atomic64_set_cx8)
20971
20972+ENTRY(atomic64_set_unchecked_cx8)
20973+ CFI_STARTPROC
20974+
20975+1:
20976+/* we don't need LOCK_PREFIX since aligned 64-bit writes
20977+ * are atomic on 586 and newer */
20978+ cmpxchg8b (%esi)
20979+ jne 1b
20980+
20981+ pax_force_retaddr
20982+ ret
20983+ CFI_ENDPROC
20984+ENDPROC(atomic64_set_unchecked_cx8)
20985+
20986 ENTRY(atomic64_xchg_cx8)
20987 CFI_STARTPROC
20988
20989@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
20990 cmpxchg8b (%esi)
20991 jne 1b
20992
20993+ pax_force_retaddr
20994 ret
20995 CFI_ENDPROC
20996 ENDPROC(atomic64_xchg_cx8)
20997
20998-.macro addsub_return func ins insc
20999-ENTRY(atomic64_\func\()_return_cx8)
21000+.macro addsub_return func ins insc unchecked=""
21001+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21002 CFI_STARTPROC
21003 SAVE ebp
21004 SAVE ebx
21005@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21006 movl %edx, %ecx
21007 \ins\()l %esi, %ebx
21008 \insc\()l %edi, %ecx
21009+
21010+.ifb \unchecked
21011+#ifdef CONFIG_PAX_REFCOUNT
21012+ into
21013+2:
21014+ _ASM_EXTABLE(2b, 3f)
21015+#endif
21016+.endif
21017+
21018 LOCK_PREFIX
21019 cmpxchg8b (%ebp)
21020 jne 1b
21021-
21022-10:
21023 movl %ebx, %eax
21024 movl %ecx, %edx
21025+
21026+.ifb \unchecked
21027+#ifdef CONFIG_PAX_REFCOUNT
21028+3:
21029+#endif
21030+.endif
21031+
21032 RESTORE edi
21033 RESTORE esi
21034 RESTORE ebx
21035 RESTORE ebp
21036+ pax_force_retaddr
21037 ret
21038 CFI_ENDPROC
21039-ENDPROC(atomic64_\func\()_return_cx8)
21040+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21041 .endm
21042
21043 addsub_return add add adc
21044 addsub_return sub sub sbb
21045+addsub_return add add adc _unchecked
21046+addsub_return sub sub sbb _unchecked
21047
21048-.macro incdec_return func ins insc
21049-ENTRY(atomic64_\func\()_return_cx8)
21050+.macro incdec_return func ins insc unchecked=""
21051+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21052 CFI_STARTPROC
21053 SAVE ebx
21054
21055@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21056 movl %edx, %ecx
21057 \ins\()l $1, %ebx
21058 \insc\()l $0, %ecx
21059+
21060+.ifb \unchecked
21061+#ifdef CONFIG_PAX_REFCOUNT
21062+ into
21063+2:
21064+ _ASM_EXTABLE(2b, 3f)
21065+#endif
21066+.endif
21067+
21068 LOCK_PREFIX
21069 cmpxchg8b (%esi)
21070 jne 1b
21071
21072-10:
21073 movl %ebx, %eax
21074 movl %ecx, %edx
21075+
21076+.ifb \unchecked
21077+#ifdef CONFIG_PAX_REFCOUNT
21078+3:
21079+#endif
21080+.endif
21081+
21082 RESTORE ebx
21083+ pax_force_retaddr
21084 ret
21085 CFI_ENDPROC
21086-ENDPROC(atomic64_\func\()_return_cx8)
21087+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21088 .endm
21089
21090 incdec_return inc add adc
21091 incdec_return dec sub sbb
21092+incdec_return inc add adc _unchecked
21093+incdec_return dec sub sbb _unchecked
21094
21095 ENTRY(atomic64_dec_if_positive_cx8)
21096 CFI_STARTPROC
21097@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21098 movl %edx, %ecx
21099 subl $1, %ebx
21100 sbb $0, %ecx
21101+
21102+#ifdef CONFIG_PAX_REFCOUNT
21103+ into
21104+1234:
21105+ _ASM_EXTABLE(1234b, 2f)
21106+#endif
21107+
21108 js 2f
21109 LOCK_PREFIX
21110 cmpxchg8b (%esi)
21111@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21112 movl %ebx, %eax
21113 movl %ecx, %edx
21114 RESTORE ebx
21115+ pax_force_retaddr
21116 ret
21117 CFI_ENDPROC
21118 ENDPROC(atomic64_dec_if_positive_cx8)
21119@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21120 movl %edx, %ecx
21121 addl %ebp, %ebx
21122 adcl %edi, %ecx
21123+
21124+#ifdef CONFIG_PAX_REFCOUNT
21125+ into
21126+1234:
21127+ _ASM_EXTABLE(1234b, 3f)
21128+#endif
21129+
21130 LOCK_PREFIX
21131 cmpxchg8b (%esi)
21132 jne 1b
21133@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21134 CFI_ADJUST_CFA_OFFSET -8
21135 RESTORE ebx
21136 RESTORE ebp
21137+ pax_force_retaddr
21138 ret
21139 4:
21140 cmpl %edx, 4(%esp)
21141@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21142 xorl %ecx, %ecx
21143 addl $1, %ebx
21144 adcl %edx, %ecx
21145+
21146+#ifdef CONFIG_PAX_REFCOUNT
21147+ into
21148+1234:
21149+ _ASM_EXTABLE(1234b, 3f)
21150+#endif
21151+
21152 LOCK_PREFIX
21153 cmpxchg8b (%esi)
21154 jne 1b
21155@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21156 movl $1, %eax
21157 3:
21158 RESTORE ebx
21159+ pax_force_retaddr
21160 ret
21161 CFI_ENDPROC
21162 ENDPROC(atomic64_inc_not_zero_cx8)
21163diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21164index 78d16a5..fbcf666 100644
21165--- a/arch/x86/lib/checksum_32.S
21166+++ b/arch/x86/lib/checksum_32.S
21167@@ -28,7 +28,8 @@
21168 #include <linux/linkage.h>
21169 #include <asm/dwarf2.h>
21170 #include <asm/errno.h>
21171-
21172+#include <asm/segment.h>
21173+
21174 /*
21175 * computes a partial checksum, e.g. for TCP/UDP fragments
21176 */
21177@@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21178
21179 #define ARGBASE 16
21180 #define FP 12
21181-
21182-ENTRY(csum_partial_copy_generic)
21183+
21184+ENTRY(csum_partial_copy_generic_to_user)
21185 CFI_STARTPROC
21186+
21187+#ifdef CONFIG_PAX_MEMORY_UDEREF
21188+ pushl_cfi %gs
21189+ popl_cfi %es
21190+ jmp csum_partial_copy_generic
21191+#endif
21192+
21193+ENTRY(csum_partial_copy_generic_from_user)
21194+
21195+#ifdef CONFIG_PAX_MEMORY_UDEREF
21196+ pushl_cfi %gs
21197+ popl_cfi %ds
21198+#endif
21199+
21200+ENTRY(csum_partial_copy_generic)
21201 subl $4,%esp
21202 CFI_ADJUST_CFA_OFFSET 4
21203 pushl_cfi %edi
21204@@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
21205 jmp 4f
21206 SRC(1: movw (%esi), %bx )
21207 addl $2, %esi
21208-DST( movw %bx, (%edi) )
21209+DST( movw %bx, %es:(%edi) )
21210 addl $2, %edi
21211 addw %bx, %ax
21212 adcl $0, %eax
21213@@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
21214 SRC(1: movl (%esi), %ebx )
21215 SRC( movl 4(%esi), %edx )
21216 adcl %ebx, %eax
21217-DST( movl %ebx, (%edi) )
21218+DST( movl %ebx, %es:(%edi) )
21219 adcl %edx, %eax
21220-DST( movl %edx, 4(%edi) )
21221+DST( movl %edx, %es:4(%edi) )
21222
21223 SRC( movl 8(%esi), %ebx )
21224 SRC( movl 12(%esi), %edx )
21225 adcl %ebx, %eax
21226-DST( movl %ebx, 8(%edi) )
21227+DST( movl %ebx, %es:8(%edi) )
21228 adcl %edx, %eax
21229-DST( movl %edx, 12(%edi) )
21230+DST( movl %edx, %es:12(%edi) )
21231
21232 SRC( movl 16(%esi), %ebx )
21233 SRC( movl 20(%esi), %edx )
21234 adcl %ebx, %eax
21235-DST( movl %ebx, 16(%edi) )
21236+DST( movl %ebx, %es:16(%edi) )
21237 adcl %edx, %eax
21238-DST( movl %edx, 20(%edi) )
21239+DST( movl %edx, %es:20(%edi) )
21240
21241 SRC( movl 24(%esi), %ebx )
21242 SRC( movl 28(%esi), %edx )
21243 adcl %ebx, %eax
21244-DST( movl %ebx, 24(%edi) )
21245+DST( movl %ebx, %es:24(%edi) )
21246 adcl %edx, %eax
21247-DST( movl %edx, 28(%edi) )
21248+DST( movl %edx, %es:28(%edi) )
21249
21250 lea 32(%esi), %esi
21251 lea 32(%edi), %edi
21252@@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
21253 shrl $2, %edx # This clears CF
21254 SRC(3: movl (%esi), %ebx )
21255 adcl %ebx, %eax
21256-DST( movl %ebx, (%edi) )
21257+DST( movl %ebx, %es:(%edi) )
21258 lea 4(%esi), %esi
21259 lea 4(%edi), %edi
21260 dec %edx
21261@@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
21262 jb 5f
21263 SRC( movw (%esi), %cx )
21264 leal 2(%esi), %esi
21265-DST( movw %cx, (%edi) )
21266+DST( movw %cx, %es:(%edi) )
21267 leal 2(%edi), %edi
21268 je 6f
21269 shll $16,%ecx
21270 SRC(5: movb (%esi), %cl )
21271-DST( movb %cl, (%edi) )
21272+DST( movb %cl, %es:(%edi) )
21273 6: addl %ecx, %eax
21274 adcl $0, %eax
21275 7:
21276@@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
21277
21278 6001:
21279 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21280- movl $-EFAULT, (%ebx)
21281+ movl $-EFAULT, %ss:(%ebx)
21282
21283 # zero the complete destination - computing the rest
21284 # is too much work
21285@@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
21286
21287 6002:
21288 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21289- movl $-EFAULT,(%ebx)
21290+ movl $-EFAULT,%ss:(%ebx)
21291 jmp 5000b
21292
21293 .previous
21294
21295+ pushl_cfi %ss
21296+ popl_cfi %ds
21297+ pushl_cfi %ss
21298+ popl_cfi %es
21299 popl_cfi %ebx
21300 CFI_RESTORE ebx
21301 popl_cfi %esi
21302@@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
21303 popl_cfi %ecx # equivalent to addl $4,%esp
21304 ret
21305 CFI_ENDPROC
21306-ENDPROC(csum_partial_copy_generic)
21307+ENDPROC(csum_partial_copy_generic_to_user)
21308
21309 #else
21310
21311 /* Version for PentiumII/PPro */
21312
21313 #define ROUND1(x) \
21314+ nop; nop; nop; \
21315 SRC(movl x(%esi), %ebx ) ; \
21316 addl %ebx, %eax ; \
21317- DST(movl %ebx, x(%edi) ) ;
21318+ DST(movl %ebx, %es:x(%edi)) ;
21319
21320 #define ROUND(x) \
21321+ nop; nop; nop; \
21322 SRC(movl x(%esi), %ebx ) ; \
21323 adcl %ebx, %eax ; \
21324- DST(movl %ebx, x(%edi) ) ;
21325+ DST(movl %ebx, %es:x(%edi)) ;
21326
21327 #define ARGBASE 12
21328-
21329-ENTRY(csum_partial_copy_generic)
21330+
21331+ENTRY(csum_partial_copy_generic_to_user)
21332 CFI_STARTPROC
21333+
21334+#ifdef CONFIG_PAX_MEMORY_UDEREF
21335+ pushl_cfi %gs
21336+ popl_cfi %es
21337+ jmp csum_partial_copy_generic
21338+#endif
21339+
21340+ENTRY(csum_partial_copy_generic_from_user)
21341+
21342+#ifdef CONFIG_PAX_MEMORY_UDEREF
21343+ pushl_cfi %gs
21344+ popl_cfi %ds
21345+#endif
21346+
21347+ENTRY(csum_partial_copy_generic)
21348 pushl_cfi %ebx
21349 CFI_REL_OFFSET ebx, 0
21350 pushl_cfi %edi
21351@@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
21352 subl %ebx, %edi
21353 lea -1(%esi),%edx
21354 andl $-32,%edx
21355- lea 3f(%ebx,%ebx), %ebx
21356+ lea 3f(%ebx,%ebx,2), %ebx
21357 testl %esi, %esi
21358 jmp *%ebx
21359 1: addl $64,%esi
21360@@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
21361 jb 5f
21362 SRC( movw (%esi), %dx )
21363 leal 2(%esi), %esi
21364-DST( movw %dx, (%edi) )
21365+DST( movw %dx, %es:(%edi) )
21366 leal 2(%edi), %edi
21367 je 6f
21368 shll $16,%edx
21369 5:
21370 SRC( movb (%esi), %dl )
21371-DST( movb %dl, (%edi) )
21372+DST( movb %dl, %es:(%edi) )
21373 6: addl %edx, %eax
21374 adcl $0, %eax
21375 7:
21376 .section .fixup, "ax"
21377 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21378- movl $-EFAULT, (%ebx)
21379+ movl $-EFAULT, %ss:(%ebx)
21380 # zero the complete destination (computing the rest is too much work)
21381 movl ARGBASE+8(%esp),%edi # dst
21382 movl ARGBASE+12(%esp),%ecx # len
21383@@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
21384 rep; stosb
21385 jmp 7b
21386 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21387- movl $-EFAULT, (%ebx)
21388+ movl $-EFAULT, %ss:(%ebx)
21389 jmp 7b
21390 .previous
21391
21392+#ifdef CONFIG_PAX_MEMORY_UDEREF
21393+ pushl_cfi %ss
21394+ popl_cfi %ds
21395+ pushl_cfi %ss
21396+ popl_cfi %es
21397+#endif
21398+
21399 popl_cfi %esi
21400 CFI_RESTORE esi
21401 popl_cfi %edi
21402@@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
21403 CFI_RESTORE ebx
21404 ret
21405 CFI_ENDPROC
21406-ENDPROC(csum_partial_copy_generic)
21407+ENDPROC(csum_partial_copy_generic_to_user)
21408
21409 #undef ROUND
21410 #undef ROUND1
21411diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21412index f2145cf..cea889d 100644
21413--- a/arch/x86/lib/clear_page_64.S
21414+++ b/arch/x86/lib/clear_page_64.S
21415@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21416 movl $4096/8,%ecx
21417 xorl %eax,%eax
21418 rep stosq
21419+ pax_force_retaddr
21420 ret
21421 CFI_ENDPROC
21422 ENDPROC(clear_page_c)
21423@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21424 movl $4096,%ecx
21425 xorl %eax,%eax
21426 rep stosb
21427+ pax_force_retaddr
21428 ret
21429 CFI_ENDPROC
21430 ENDPROC(clear_page_c_e)
21431@@ -43,6 +45,7 @@ ENTRY(clear_page)
21432 leaq 64(%rdi),%rdi
21433 jnz .Lloop
21434 nop
21435+ pax_force_retaddr
21436 ret
21437 CFI_ENDPROC
21438 .Lclear_page_end:
21439@@ -58,7 +61,7 @@ ENDPROC(clear_page)
21440
21441 #include <asm/cpufeature.h>
21442
21443- .section .altinstr_replacement,"ax"
21444+ .section .altinstr_replacement,"a"
21445 1: .byte 0xeb /* jmp <disp8> */
21446 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21447 2: .byte 0xeb /* jmp <disp8> */
21448diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21449index 1e572c5..2a162cd 100644
21450--- a/arch/x86/lib/cmpxchg16b_emu.S
21451+++ b/arch/x86/lib/cmpxchg16b_emu.S
21452@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21453
21454 popf
21455 mov $1, %al
21456+ pax_force_retaddr
21457 ret
21458
21459 not_same:
21460 popf
21461 xor %al,%al
21462+ pax_force_retaddr
21463 ret
21464
21465 CFI_ENDPROC
21466diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21467index 6b34d04..dccb07f 100644
21468--- a/arch/x86/lib/copy_page_64.S
21469+++ b/arch/x86/lib/copy_page_64.S
21470@@ -9,6 +9,7 @@ copy_page_c:
21471 CFI_STARTPROC
21472 movl $4096/8,%ecx
21473 rep movsq
21474+ pax_force_retaddr
21475 ret
21476 CFI_ENDPROC
21477 ENDPROC(copy_page_c)
21478@@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21479
21480 ENTRY(copy_page)
21481 CFI_STARTPROC
21482- subq $2*8,%rsp
21483- CFI_ADJUST_CFA_OFFSET 2*8
21484+ subq $3*8,%rsp
21485+ CFI_ADJUST_CFA_OFFSET 3*8
21486 movq %rbx,(%rsp)
21487 CFI_REL_OFFSET rbx, 0
21488 movq %r12,1*8(%rsp)
21489 CFI_REL_OFFSET r12, 1*8
21490+ movq %r13,2*8(%rsp)
21491+ CFI_REL_OFFSET r13, 2*8
21492
21493 movl $(4096/64)-5,%ecx
21494 .p2align 4
21495@@ -37,7 +40,7 @@ ENTRY(copy_page)
21496 movq 16 (%rsi), %rdx
21497 movq 24 (%rsi), %r8
21498 movq 32 (%rsi), %r9
21499- movq 40 (%rsi), %r10
21500+ movq 40 (%rsi), %r13
21501 movq 48 (%rsi), %r11
21502 movq 56 (%rsi), %r12
21503
21504@@ -48,7 +51,7 @@ ENTRY(copy_page)
21505 movq %rdx, 16 (%rdi)
21506 movq %r8, 24 (%rdi)
21507 movq %r9, 32 (%rdi)
21508- movq %r10, 40 (%rdi)
21509+ movq %r13, 40 (%rdi)
21510 movq %r11, 48 (%rdi)
21511 movq %r12, 56 (%rdi)
21512
21513@@ -67,7 +70,7 @@ ENTRY(copy_page)
21514 movq 16 (%rsi), %rdx
21515 movq 24 (%rsi), %r8
21516 movq 32 (%rsi), %r9
21517- movq 40 (%rsi), %r10
21518+ movq 40 (%rsi), %r13
21519 movq 48 (%rsi), %r11
21520 movq 56 (%rsi), %r12
21521
21522@@ -76,7 +79,7 @@ ENTRY(copy_page)
21523 movq %rdx, 16 (%rdi)
21524 movq %r8, 24 (%rdi)
21525 movq %r9, 32 (%rdi)
21526- movq %r10, 40 (%rdi)
21527+ movq %r13, 40 (%rdi)
21528 movq %r11, 48 (%rdi)
21529 movq %r12, 56 (%rdi)
21530
21531@@ -89,8 +92,11 @@ ENTRY(copy_page)
21532 CFI_RESTORE rbx
21533 movq 1*8(%rsp),%r12
21534 CFI_RESTORE r12
21535- addq $2*8,%rsp
21536- CFI_ADJUST_CFA_OFFSET -2*8
21537+ movq 2*8(%rsp),%r13
21538+ CFI_RESTORE r13
21539+ addq $3*8,%rsp
21540+ CFI_ADJUST_CFA_OFFSET -3*8
21541+ pax_force_retaddr
21542 ret
21543 .Lcopy_page_end:
21544 CFI_ENDPROC
21545@@ -101,7 +107,7 @@ ENDPROC(copy_page)
21546
21547 #include <asm/cpufeature.h>
21548
21549- .section .altinstr_replacement,"ax"
21550+ .section .altinstr_replacement,"a"
21551 1: .byte 0xeb /* jmp <disp8> */
21552 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21553 2:
21554diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21555index 0248402..821c786 100644
21556--- a/arch/x86/lib/copy_user_64.S
21557+++ b/arch/x86/lib/copy_user_64.S
21558@@ -16,6 +16,7 @@
21559 #include <asm/thread_info.h>
21560 #include <asm/cpufeature.h>
21561 #include <asm/alternative-asm.h>
21562+#include <asm/pgtable.h>
21563
21564 /*
21565 * By placing feature2 after feature1 in altinstructions section, we logically
21566@@ -29,7 +30,7 @@
21567 .byte 0xe9 /* 32bit jump */
21568 .long \orig-1f /* by default jump to orig */
21569 1:
21570- .section .altinstr_replacement,"ax"
21571+ .section .altinstr_replacement,"a"
21572 2: .byte 0xe9 /* near jump with 32bit immediate */
21573 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21574 3: .byte 0xe9 /* near jump with 32bit immediate */
21575@@ -71,47 +72,20 @@
21576 #endif
21577 .endm
21578
21579-/* Standard copy_to_user with segment limit checking */
21580-ENTRY(_copy_to_user)
21581- CFI_STARTPROC
21582- GET_THREAD_INFO(%rax)
21583- movq %rdi,%rcx
21584- addq %rdx,%rcx
21585- jc bad_to_user
21586- cmpq TI_addr_limit(%rax),%rcx
21587- ja bad_to_user
21588- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21589- copy_user_generic_unrolled,copy_user_generic_string, \
21590- copy_user_enhanced_fast_string
21591- CFI_ENDPROC
21592-ENDPROC(_copy_to_user)
21593-
21594-/* Standard copy_from_user with segment limit checking */
21595-ENTRY(_copy_from_user)
21596- CFI_STARTPROC
21597- GET_THREAD_INFO(%rax)
21598- movq %rsi,%rcx
21599- addq %rdx,%rcx
21600- jc bad_from_user
21601- cmpq TI_addr_limit(%rax),%rcx
21602- ja bad_from_user
21603- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21604- copy_user_generic_unrolled,copy_user_generic_string, \
21605- copy_user_enhanced_fast_string
21606- CFI_ENDPROC
21607-ENDPROC(_copy_from_user)
21608-
21609 .section .fixup,"ax"
21610 /* must zero dest */
21611 ENTRY(bad_from_user)
21612 bad_from_user:
21613 CFI_STARTPROC
21614+ testl %edx,%edx
21615+ js bad_to_user
21616 movl %edx,%ecx
21617 xorl %eax,%eax
21618 rep
21619 stosb
21620 bad_to_user:
21621 movl %edx,%eax
21622+ pax_force_retaddr
21623 ret
21624 CFI_ENDPROC
21625 ENDPROC(bad_from_user)
21626@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
21627 jz 17f
21628 1: movq (%rsi),%r8
21629 2: movq 1*8(%rsi),%r9
21630-3: movq 2*8(%rsi),%r10
21631+3: movq 2*8(%rsi),%rax
21632 4: movq 3*8(%rsi),%r11
21633 5: movq %r8,(%rdi)
21634 6: movq %r9,1*8(%rdi)
21635-7: movq %r10,2*8(%rdi)
21636+7: movq %rax,2*8(%rdi)
21637 8: movq %r11,3*8(%rdi)
21638 9: movq 4*8(%rsi),%r8
21639 10: movq 5*8(%rsi),%r9
21640-11: movq 6*8(%rsi),%r10
21641+11: movq 6*8(%rsi),%rax
21642 12: movq 7*8(%rsi),%r11
21643 13: movq %r8,4*8(%rdi)
21644 14: movq %r9,5*8(%rdi)
21645-15: movq %r10,6*8(%rdi)
21646+15: movq %rax,6*8(%rdi)
21647 16: movq %r11,7*8(%rdi)
21648 leaq 64(%rsi),%rsi
21649 leaq 64(%rdi),%rdi
21650@@ -179,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
21651 decl %ecx
21652 jnz 21b
21653 23: xor %eax,%eax
21654+ pax_force_retaddr
21655 ret
21656
21657 .section .fixup,"ax"
21658@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
21659 3: rep
21660 movsb
21661 4: xorl %eax,%eax
21662+ pax_force_retaddr
21663 ret
21664
21665 .section .fixup,"ax"
21666@@ -287,6 +263,7 @@ ENTRY(copy_user_enhanced_fast_string)
21667 1: rep
21668 movsb
21669 2: xorl %eax,%eax
21670+ pax_force_retaddr
21671 ret
21672
21673 .section .fixup,"ax"
21674diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21675index cb0c112..e3a6895 100644
21676--- a/arch/x86/lib/copy_user_nocache_64.S
21677+++ b/arch/x86/lib/copy_user_nocache_64.S
21678@@ -8,12 +8,14 @@
21679
21680 #include <linux/linkage.h>
21681 #include <asm/dwarf2.h>
21682+#include <asm/alternative-asm.h>
21683
21684 #define FIX_ALIGNMENT 1
21685
21686 #include <asm/current.h>
21687 #include <asm/asm-offsets.h>
21688 #include <asm/thread_info.h>
21689+#include <asm/pgtable.h>
21690
21691 .macro ALIGN_DESTINATION
21692 #ifdef FIX_ALIGNMENT
21693@@ -50,6 +52,15 @@
21694 */
21695 ENTRY(__copy_user_nocache)
21696 CFI_STARTPROC
21697+
21698+#ifdef CONFIG_PAX_MEMORY_UDEREF
21699+ mov $PAX_USER_SHADOW_BASE,%rcx
21700+ cmp %rcx,%rsi
21701+ jae 1f
21702+ add %rcx,%rsi
21703+1:
21704+#endif
21705+
21706 cmpl $8,%edx
21707 jb 20f /* less then 8 bytes, go to byte copy loop */
21708 ALIGN_DESTINATION
21709@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
21710 jz 17f
21711 1: movq (%rsi),%r8
21712 2: movq 1*8(%rsi),%r9
21713-3: movq 2*8(%rsi),%r10
21714+3: movq 2*8(%rsi),%rax
21715 4: movq 3*8(%rsi),%r11
21716 5: movnti %r8,(%rdi)
21717 6: movnti %r9,1*8(%rdi)
21718-7: movnti %r10,2*8(%rdi)
21719+7: movnti %rax,2*8(%rdi)
21720 8: movnti %r11,3*8(%rdi)
21721 9: movq 4*8(%rsi),%r8
21722 10: movq 5*8(%rsi),%r9
21723-11: movq 6*8(%rsi),%r10
21724+11: movq 6*8(%rsi),%rax
21725 12: movq 7*8(%rsi),%r11
21726 13: movnti %r8,4*8(%rdi)
21727 14: movnti %r9,5*8(%rdi)
21728-15: movnti %r10,6*8(%rdi)
21729+15: movnti %rax,6*8(%rdi)
21730 16: movnti %r11,7*8(%rdi)
21731 leaq 64(%rsi),%rsi
21732 leaq 64(%rdi),%rdi
21733@@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
21734 jnz 21b
21735 23: xorl %eax,%eax
21736 sfence
21737+ pax_force_retaddr
21738 ret
21739
21740 .section .fixup,"ax"
21741diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21742index fb903b7..c92b7f7 100644
21743--- a/arch/x86/lib/csum-copy_64.S
21744+++ b/arch/x86/lib/csum-copy_64.S
21745@@ -8,6 +8,7 @@
21746 #include <linux/linkage.h>
21747 #include <asm/dwarf2.h>
21748 #include <asm/errno.h>
21749+#include <asm/alternative-asm.h>
21750
21751 /*
21752 * Checksum copy with exception handling.
21753@@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
21754 CFI_RESTORE rbp
21755 addq $7*8, %rsp
21756 CFI_ADJUST_CFA_OFFSET -7*8
21757+ pax_force_retaddr 0, 1
21758 ret
21759 CFI_RESTORE_STATE
21760
21761diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21762index 459b58a..9570bc7 100644
21763--- a/arch/x86/lib/csum-wrappers_64.c
21764+++ b/arch/x86/lib/csum-wrappers_64.c
21765@@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21766 len -= 2;
21767 }
21768 }
21769- isum = csum_partial_copy_generic((__force const void *)src,
21770+
21771+#ifdef CONFIG_PAX_MEMORY_UDEREF
21772+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21773+ src += PAX_USER_SHADOW_BASE;
21774+#endif
21775+
21776+ isum = csum_partial_copy_generic((const void __force_kernel *)src,
21777 dst, len, isum, errp, NULL);
21778 if (unlikely(*errp))
21779 goto out_err;
21780@@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21781 }
21782
21783 *errp = 0;
21784- return csum_partial_copy_generic(src, (void __force *)dst,
21785+
21786+#ifdef CONFIG_PAX_MEMORY_UDEREF
21787+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21788+ dst += PAX_USER_SHADOW_BASE;
21789+#endif
21790+
21791+ return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21792 len, isum, NULL, errp);
21793 }
21794 EXPORT_SYMBOL(csum_partial_copy_to_user);
21795diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21796index 51f1504..ddac4c1 100644
21797--- a/arch/x86/lib/getuser.S
21798+++ b/arch/x86/lib/getuser.S
21799@@ -33,15 +33,38 @@
21800 #include <asm/asm-offsets.h>
21801 #include <asm/thread_info.h>
21802 #include <asm/asm.h>
21803+#include <asm/segment.h>
21804+#include <asm/pgtable.h>
21805+#include <asm/alternative-asm.h>
21806+
21807+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21808+#define __copyuser_seg gs;
21809+#else
21810+#define __copyuser_seg
21811+#endif
21812
21813 .text
21814 ENTRY(__get_user_1)
21815 CFI_STARTPROC
21816+
21817+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21818 GET_THREAD_INFO(%_ASM_DX)
21819 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21820 jae bad_get_user
21821-1: movzb (%_ASM_AX),%edx
21822+
21823+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21824+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21825+ cmp %_ASM_DX,%_ASM_AX
21826+ jae 1234f
21827+ add %_ASM_DX,%_ASM_AX
21828+1234:
21829+#endif
21830+
21831+#endif
21832+
21833+1: __copyuser_seg movzb (%_ASM_AX),%edx
21834 xor %eax,%eax
21835+ pax_force_retaddr
21836 ret
21837 CFI_ENDPROC
21838 ENDPROC(__get_user_1)
21839@@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21840 ENTRY(__get_user_2)
21841 CFI_STARTPROC
21842 add $1,%_ASM_AX
21843+
21844+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21845 jc bad_get_user
21846 GET_THREAD_INFO(%_ASM_DX)
21847 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21848 jae bad_get_user
21849-2: movzwl -1(%_ASM_AX),%edx
21850+
21851+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21852+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21853+ cmp %_ASM_DX,%_ASM_AX
21854+ jae 1234f
21855+ add %_ASM_DX,%_ASM_AX
21856+1234:
21857+#endif
21858+
21859+#endif
21860+
21861+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21862 xor %eax,%eax
21863+ pax_force_retaddr
21864 ret
21865 CFI_ENDPROC
21866 ENDPROC(__get_user_2)
21867@@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21868 ENTRY(__get_user_4)
21869 CFI_STARTPROC
21870 add $3,%_ASM_AX
21871+
21872+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21873 jc bad_get_user
21874 GET_THREAD_INFO(%_ASM_DX)
21875 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21876 jae bad_get_user
21877-3: mov -3(%_ASM_AX),%edx
21878+
21879+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21880+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21881+ cmp %_ASM_DX,%_ASM_AX
21882+ jae 1234f
21883+ add %_ASM_DX,%_ASM_AX
21884+1234:
21885+#endif
21886+
21887+#endif
21888+
21889+3: __copyuser_seg mov -3(%_ASM_AX),%edx
21890 xor %eax,%eax
21891+ pax_force_retaddr
21892 ret
21893 CFI_ENDPROC
21894 ENDPROC(__get_user_4)
21895@@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21896 GET_THREAD_INFO(%_ASM_DX)
21897 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21898 jae bad_get_user
21899+
21900+#ifdef CONFIG_PAX_MEMORY_UDEREF
21901+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21902+ cmp %_ASM_DX,%_ASM_AX
21903+ jae 1234f
21904+ add %_ASM_DX,%_ASM_AX
21905+1234:
21906+#endif
21907+
21908 4: movq -7(%_ASM_AX),%_ASM_DX
21909 xor %eax,%eax
21910+ pax_force_retaddr
21911 ret
21912 CFI_ENDPROC
21913 ENDPROC(__get_user_8)
21914@@ -91,6 +152,7 @@ bad_get_user:
21915 CFI_STARTPROC
21916 xor %edx,%edx
21917 mov $(-EFAULT),%_ASM_AX
21918+ pax_force_retaddr
21919 ret
21920 CFI_ENDPROC
21921 END(bad_get_user)
21922diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21923index b1e6c4b..21ae8fc 100644
21924--- a/arch/x86/lib/insn.c
21925+++ b/arch/x86/lib/insn.c
21926@@ -21,6 +21,11 @@
21927 #include <linux/string.h>
21928 #include <asm/inat.h>
21929 #include <asm/insn.h>
21930+#ifdef __KERNEL__
21931+#include <asm/pgtable_types.h>
21932+#else
21933+#define ktla_ktva(addr) addr
21934+#endif
21935
21936 /* Verify next sizeof(t) bytes can be on the same instruction */
21937 #define validate_next(t, insn, n) \
21938@@ -49,8 +54,8 @@
21939 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21940 {
21941 memset(insn, 0, sizeof(*insn));
21942- insn->kaddr = kaddr;
21943- insn->next_byte = kaddr;
21944+ insn->kaddr = ktla_ktva(kaddr);
21945+ insn->next_byte = ktla_ktva(kaddr);
21946 insn->x86_64 = x86_64 ? 1 : 0;
21947 insn->opnd_bytes = 4;
21948 if (x86_64)
21949diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21950index 05a95e7..326f2fa 100644
21951--- a/arch/x86/lib/iomap_copy_64.S
21952+++ b/arch/x86/lib/iomap_copy_64.S
21953@@ -17,6 +17,7 @@
21954
21955 #include <linux/linkage.h>
21956 #include <asm/dwarf2.h>
21957+#include <asm/alternative-asm.h>
21958
21959 /*
21960 * override generic version in lib/iomap_copy.c
21961@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21962 CFI_STARTPROC
21963 movl %edx,%ecx
21964 rep movsd
21965+ pax_force_retaddr
21966 ret
21967 CFI_ENDPROC
21968 ENDPROC(__iowrite32_copy)
21969diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21970index 1c273be..da9cc0e 100644
21971--- a/arch/x86/lib/memcpy_64.S
21972+++ b/arch/x86/lib/memcpy_64.S
21973@@ -33,6 +33,7 @@
21974 rep movsq
21975 movl %edx, %ecx
21976 rep movsb
21977+ pax_force_retaddr
21978 ret
21979 .Lmemcpy_e:
21980 .previous
21981@@ -49,6 +50,7 @@
21982 movq %rdi, %rax
21983 movq %rdx, %rcx
21984 rep movsb
21985+ pax_force_retaddr
21986 ret
21987 .Lmemcpy_e_e:
21988 .previous
21989@@ -76,13 +78,13 @@ ENTRY(memcpy)
21990 */
21991 movq 0*8(%rsi), %r8
21992 movq 1*8(%rsi), %r9
21993- movq 2*8(%rsi), %r10
21994+ movq 2*8(%rsi), %rcx
21995 movq 3*8(%rsi), %r11
21996 leaq 4*8(%rsi), %rsi
21997
21998 movq %r8, 0*8(%rdi)
21999 movq %r9, 1*8(%rdi)
22000- movq %r10, 2*8(%rdi)
22001+ movq %rcx, 2*8(%rdi)
22002 movq %r11, 3*8(%rdi)
22003 leaq 4*8(%rdi), %rdi
22004 jae .Lcopy_forward_loop
22005@@ -105,12 +107,12 @@ ENTRY(memcpy)
22006 subq $0x20, %rdx
22007 movq -1*8(%rsi), %r8
22008 movq -2*8(%rsi), %r9
22009- movq -3*8(%rsi), %r10
22010+ movq -3*8(%rsi), %rcx
22011 movq -4*8(%rsi), %r11
22012 leaq -4*8(%rsi), %rsi
22013 movq %r8, -1*8(%rdi)
22014 movq %r9, -2*8(%rdi)
22015- movq %r10, -3*8(%rdi)
22016+ movq %rcx, -3*8(%rdi)
22017 movq %r11, -4*8(%rdi)
22018 leaq -4*8(%rdi), %rdi
22019 jae .Lcopy_backward_loop
22020@@ -130,12 +132,13 @@ ENTRY(memcpy)
22021 */
22022 movq 0*8(%rsi), %r8
22023 movq 1*8(%rsi), %r9
22024- movq -2*8(%rsi, %rdx), %r10
22025+ movq -2*8(%rsi, %rdx), %rcx
22026 movq -1*8(%rsi, %rdx), %r11
22027 movq %r8, 0*8(%rdi)
22028 movq %r9, 1*8(%rdi)
22029- movq %r10, -2*8(%rdi, %rdx)
22030+ movq %rcx, -2*8(%rdi, %rdx)
22031 movq %r11, -1*8(%rdi, %rdx)
22032+ pax_force_retaddr
22033 retq
22034 .p2align 4
22035 .Lless_16bytes:
22036@@ -148,6 +151,7 @@ ENTRY(memcpy)
22037 movq -1*8(%rsi, %rdx), %r9
22038 movq %r8, 0*8(%rdi)
22039 movq %r9, -1*8(%rdi, %rdx)
22040+ pax_force_retaddr
22041 retq
22042 .p2align 4
22043 .Lless_8bytes:
22044@@ -161,6 +165,7 @@ ENTRY(memcpy)
22045 movl -4(%rsi, %rdx), %r8d
22046 movl %ecx, (%rdi)
22047 movl %r8d, -4(%rdi, %rdx)
22048+ pax_force_retaddr
22049 retq
22050 .p2align 4
22051 .Lless_3bytes:
22052@@ -179,6 +184,7 @@ ENTRY(memcpy)
22053 movb %cl, (%rdi)
22054
22055 .Lend:
22056+ pax_force_retaddr
22057 retq
22058 CFI_ENDPROC
22059 ENDPROC(memcpy)
22060diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22061index ee16461..c39c199 100644
22062--- a/arch/x86/lib/memmove_64.S
22063+++ b/arch/x86/lib/memmove_64.S
22064@@ -61,13 +61,13 @@ ENTRY(memmove)
22065 5:
22066 sub $0x20, %rdx
22067 movq 0*8(%rsi), %r11
22068- movq 1*8(%rsi), %r10
22069+ movq 1*8(%rsi), %rcx
22070 movq 2*8(%rsi), %r9
22071 movq 3*8(%rsi), %r8
22072 leaq 4*8(%rsi), %rsi
22073
22074 movq %r11, 0*8(%rdi)
22075- movq %r10, 1*8(%rdi)
22076+ movq %rcx, 1*8(%rdi)
22077 movq %r9, 2*8(%rdi)
22078 movq %r8, 3*8(%rdi)
22079 leaq 4*8(%rdi), %rdi
22080@@ -81,10 +81,10 @@ ENTRY(memmove)
22081 4:
22082 movq %rdx, %rcx
22083 movq -8(%rsi, %rdx), %r11
22084- lea -8(%rdi, %rdx), %r10
22085+ lea -8(%rdi, %rdx), %r9
22086 shrq $3, %rcx
22087 rep movsq
22088- movq %r11, (%r10)
22089+ movq %r11, (%r9)
22090 jmp 13f
22091 .Lmemmove_end_forward:
22092
22093@@ -95,14 +95,14 @@ ENTRY(memmove)
22094 7:
22095 movq %rdx, %rcx
22096 movq (%rsi), %r11
22097- movq %rdi, %r10
22098+ movq %rdi, %r9
22099 leaq -8(%rsi, %rdx), %rsi
22100 leaq -8(%rdi, %rdx), %rdi
22101 shrq $3, %rcx
22102 std
22103 rep movsq
22104 cld
22105- movq %r11, (%r10)
22106+ movq %r11, (%r9)
22107 jmp 13f
22108
22109 /*
22110@@ -127,13 +127,13 @@ ENTRY(memmove)
22111 8:
22112 subq $0x20, %rdx
22113 movq -1*8(%rsi), %r11
22114- movq -2*8(%rsi), %r10
22115+ movq -2*8(%rsi), %rcx
22116 movq -3*8(%rsi), %r9
22117 movq -4*8(%rsi), %r8
22118 leaq -4*8(%rsi), %rsi
22119
22120 movq %r11, -1*8(%rdi)
22121- movq %r10, -2*8(%rdi)
22122+ movq %rcx, -2*8(%rdi)
22123 movq %r9, -3*8(%rdi)
22124 movq %r8, -4*8(%rdi)
22125 leaq -4*8(%rdi), %rdi
22126@@ -151,11 +151,11 @@ ENTRY(memmove)
22127 * Move data from 16 bytes to 31 bytes.
22128 */
22129 movq 0*8(%rsi), %r11
22130- movq 1*8(%rsi), %r10
22131+ movq 1*8(%rsi), %rcx
22132 movq -2*8(%rsi, %rdx), %r9
22133 movq -1*8(%rsi, %rdx), %r8
22134 movq %r11, 0*8(%rdi)
22135- movq %r10, 1*8(%rdi)
22136+ movq %rcx, 1*8(%rdi)
22137 movq %r9, -2*8(%rdi, %rdx)
22138 movq %r8, -1*8(%rdi, %rdx)
22139 jmp 13f
22140@@ -167,9 +167,9 @@ ENTRY(memmove)
22141 * Move data from 8 bytes to 15 bytes.
22142 */
22143 movq 0*8(%rsi), %r11
22144- movq -1*8(%rsi, %rdx), %r10
22145+ movq -1*8(%rsi, %rdx), %r9
22146 movq %r11, 0*8(%rdi)
22147- movq %r10, -1*8(%rdi, %rdx)
22148+ movq %r9, -1*8(%rdi, %rdx)
22149 jmp 13f
22150 10:
22151 cmpq $4, %rdx
22152@@ -178,9 +178,9 @@ ENTRY(memmove)
22153 * Move data from 4 bytes to 7 bytes.
22154 */
22155 movl (%rsi), %r11d
22156- movl -4(%rsi, %rdx), %r10d
22157+ movl -4(%rsi, %rdx), %r9d
22158 movl %r11d, (%rdi)
22159- movl %r10d, -4(%rdi, %rdx)
22160+ movl %r9d, -4(%rdi, %rdx)
22161 jmp 13f
22162 11:
22163 cmp $2, %rdx
22164@@ -189,9 +189,9 @@ ENTRY(memmove)
22165 * Move data from 2 bytes to 3 bytes.
22166 */
22167 movw (%rsi), %r11w
22168- movw -2(%rsi, %rdx), %r10w
22169+ movw -2(%rsi, %rdx), %r9w
22170 movw %r11w, (%rdi)
22171- movw %r10w, -2(%rdi, %rdx)
22172+ movw %r9w, -2(%rdi, %rdx)
22173 jmp 13f
22174 12:
22175 cmp $1, %rdx
22176@@ -202,6 +202,7 @@ ENTRY(memmove)
22177 movb (%rsi), %r11b
22178 movb %r11b, (%rdi)
22179 13:
22180+ pax_force_retaddr
22181 retq
22182 CFI_ENDPROC
22183
22184@@ -210,6 +211,7 @@ ENTRY(memmove)
22185 /* Forward moving data. */
22186 movq %rdx, %rcx
22187 rep movsb
22188+ pax_force_retaddr
22189 retq
22190 .Lmemmove_end_forward_efs:
22191 .previous
22192diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22193index 2dcb380..963660a 100644
22194--- a/arch/x86/lib/memset_64.S
22195+++ b/arch/x86/lib/memset_64.S
22196@@ -30,6 +30,7 @@
22197 movl %edx,%ecx
22198 rep stosb
22199 movq %r9,%rax
22200+ pax_force_retaddr
22201 ret
22202 .Lmemset_e:
22203 .previous
22204@@ -52,6 +53,7 @@
22205 movq %rdx,%rcx
22206 rep stosb
22207 movq %r9,%rax
22208+ pax_force_retaddr
22209 ret
22210 .Lmemset_e_e:
22211 .previous
22212@@ -59,7 +61,7 @@
22213 ENTRY(memset)
22214 ENTRY(__memset)
22215 CFI_STARTPROC
22216- movq %rdi,%r10
22217+ movq %rdi,%r11
22218
22219 /* expand byte value */
22220 movzbl %sil,%ecx
22221@@ -117,7 +119,8 @@ ENTRY(__memset)
22222 jnz .Lloop_1
22223
22224 .Lende:
22225- movq %r10,%rax
22226+ movq %r11,%rax
22227+ pax_force_retaddr
22228 ret
22229
22230 CFI_RESTORE_STATE
22231diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22232index c9f2d9b..e7fd2c0 100644
22233--- a/arch/x86/lib/mmx_32.c
22234+++ b/arch/x86/lib/mmx_32.c
22235@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22236 {
22237 void *p;
22238 int i;
22239+ unsigned long cr0;
22240
22241 if (unlikely(in_interrupt()))
22242 return __memcpy(to, from, len);
22243@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22244 kernel_fpu_begin();
22245
22246 __asm__ __volatile__ (
22247- "1: prefetch (%0)\n" /* This set is 28 bytes */
22248- " prefetch 64(%0)\n"
22249- " prefetch 128(%0)\n"
22250- " prefetch 192(%0)\n"
22251- " prefetch 256(%0)\n"
22252+ "1: prefetch (%1)\n" /* This set is 28 bytes */
22253+ " prefetch 64(%1)\n"
22254+ " prefetch 128(%1)\n"
22255+ " prefetch 192(%1)\n"
22256+ " prefetch 256(%1)\n"
22257 "2: \n"
22258 ".section .fixup, \"ax\"\n"
22259- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22260+ "3: \n"
22261+
22262+#ifdef CONFIG_PAX_KERNEXEC
22263+ " movl %%cr0, %0\n"
22264+ " movl %0, %%eax\n"
22265+ " andl $0xFFFEFFFF, %%eax\n"
22266+ " movl %%eax, %%cr0\n"
22267+#endif
22268+
22269+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22270+
22271+#ifdef CONFIG_PAX_KERNEXEC
22272+ " movl %0, %%cr0\n"
22273+#endif
22274+
22275 " jmp 2b\n"
22276 ".previous\n"
22277 _ASM_EXTABLE(1b, 3b)
22278- : : "r" (from));
22279+ : "=&r" (cr0) : "r" (from) : "ax");
22280
22281 for ( ; i > 5; i--) {
22282 __asm__ __volatile__ (
22283- "1: prefetch 320(%0)\n"
22284- "2: movq (%0), %%mm0\n"
22285- " movq 8(%0), %%mm1\n"
22286- " movq 16(%0), %%mm2\n"
22287- " movq 24(%0), %%mm3\n"
22288- " movq %%mm0, (%1)\n"
22289- " movq %%mm1, 8(%1)\n"
22290- " movq %%mm2, 16(%1)\n"
22291- " movq %%mm3, 24(%1)\n"
22292- " movq 32(%0), %%mm0\n"
22293- " movq 40(%0), %%mm1\n"
22294- " movq 48(%0), %%mm2\n"
22295- " movq 56(%0), %%mm3\n"
22296- " movq %%mm0, 32(%1)\n"
22297- " movq %%mm1, 40(%1)\n"
22298- " movq %%mm2, 48(%1)\n"
22299- " movq %%mm3, 56(%1)\n"
22300+ "1: prefetch 320(%1)\n"
22301+ "2: movq (%1), %%mm0\n"
22302+ " movq 8(%1), %%mm1\n"
22303+ " movq 16(%1), %%mm2\n"
22304+ " movq 24(%1), %%mm3\n"
22305+ " movq %%mm0, (%2)\n"
22306+ " movq %%mm1, 8(%2)\n"
22307+ " movq %%mm2, 16(%2)\n"
22308+ " movq %%mm3, 24(%2)\n"
22309+ " movq 32(%1), %%mm0\n"
22310+ " movq 40(%1), %%mm1\n"
22311+ " movq 48(%1), %%mm2\n"
22312+ " movq 56(%1), %%mm3\n"
22313+ " movq %%mm0, 32(%2)\n"
22314+ " movq %%mm1, 40(%2)\n"
22315+ " movq %%mm2, 48(%2)\n"
22316+ " movq %%mm3, 56(%2)\n"
22317 ".section .fixup, \"ax\"\n"
22318- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22319+ "3:\n"
22320+
22321+#ifdef CONFIG_PAX_KERNEXEC
22322+ " movl %%cr0, %0\n"
22323+ " movl %0, %%eax\n"
22324+ " andl $0xFFFEFFFF, %%eax\n"
22325+ " movl %%eax, %%cr0\n"
22326+#endif
22327+
22328+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22329+
22330+#ifdef CONFIG_PAX_KERNEXEC
22331+ " movl %0, %%cr0\n"
22332+#endif
22333+
22334 " jmp 2b\n"
22335 ".previous\n"
22336 _ASM_EXTABLE(1b, 3b)
22337- : : "r" (from), "r" (to) : "memory");
22338+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22339
22340 from += 64;
22341 to += 64;
22342@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22343 static void fast_copy_page(void *to, void *from)
22344 {
22345 int i;
22346+ unsigned long cr0;
22347
22348 kernel_fpu_begin();
22349
22350@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22351 * but that is for later. -AV
22352 */
22353 __asm__ __volatile__(
22354- "1: prefetch (%0)\n"
22355- " prefetch 64(%0)\n"
22356- " prefetch 128(%0)\n"
22357- " prefetch 192(%0)\n"
22358- " prefetch 256(%0)\n"
22359+ "1: prefetch (%1)\n"
22360+ " prefetch 64(%1)\n"
22361+ " prefetch 128(%1)\n"
22362+ " prefetch 192(%1)\n"
22363+ " prefetch 256(%1)\n"
22364 "2: \n"
22365 ".section .fixup, \"ax\"\n"
22366- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22367+ "3: \n"
22368+
22369+#ifdef CONFIG_PAX_KERNEXEC
22370+ " movl %%cr0, %0\n"
22371+ " movl %0, %%eax\n"
22372+ " andl $0xFFFEFFFF, %%eax\n"
22373+ " movl %%eax, %%cr0\n"
22374+#endif
22375+
22376+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22377+
22378+#ifdef CONFIG_PAX_KERNEXEC
22379+ " movl %0, %%cr0\n"
22380+#endif
22381+
22382 " jmp 2b\n"
22383 ".previous\n"
22384- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22385+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22386
22387 for (i = 0; i < (4096-320)/64; i++) {
22388 __asm__ __volatile__ (
22389- "1: prefetch 320(%0)\n"
22390- "2: movq (%0), %%mm0\n"
22391- " movntq %%mm0, (%1)\n"
22392- " movq 8(%0), %%mm1\n"
22393- " movntq %%mm1, 8(%1)\n"
22394- " movq 16(%0), %%mm2\n"
22395- " movntq %%mm2, 16(%1)\n"
22396- " movq 24(%0), %%mm3\n"
22397- " movntq %%mm3, 24(%1)\n"
22398- " movq 32(%0), %%mm4\n"
22399- " movntq %%mm4, 32(%1)\n"
22400- " movq 40(%0), %%mm5\n"
22401- " movntq %%mm5, 40(%1)\n"
22402- " movq 48(%0), %%mm6\n"
22403- " movntq %%mm6, 48(%1)\n"
22404- " movq 56(%0), %%mm7\n"
22405- " movntq %%mm7, 56(%1)\n"
22406+ "1: prefetch 320(%1)\n"
22407+ "2: movq (%1), %%mm0\n"
22408+ " movntq %%mm0, (%2)\n"
22409+ " movq 8(%1), %%mm1\n"
22410+ " movntq %%mm1, 8(%2)\n"
22411+ " movq 16(%1), %%mm2\n"
22412+ " movntq %%mm2, 16(%2)\n"
22413+ " movq 24(%1), %%mm3\n"
22414+ " movntq %%mm3, 24(%2)\n"
22415+ " movq 32(%1), %%mm4\n"
22416+ " movntq %%mm4, 32(%2)\n"
22417+ " movq 40(%1), %%mm5\n"
22418+ " movntq %%mm5, 40(%2)\n"
22419+ " movq 48(%1), %%mm6\n"
22420+ " movntq %%mm6, 48(%2)\n"
22421+ " movq 56(%1), %%mm7\n"
22422+ " movntq %%mm7, 56(%2)\n"
22423 ".section .fixup, \"ax\"\n"
22424- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22425+ "3:\n"
22426+
22427+#ifdef CONFIG_PAX_KERNEXEC
22428+ " movl %%cr0, %0\n"
22429+ " movl %0, %%eax\n"
22430+ " andl $0xFFFEFFFF, %%eax\n"
22431+ " movl %%eax, %%cr0\n"
22432+#endif
22433+
22434+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22435+
22436+#ifdef CONFIG_PAX_KERNEXEC
22437+ " movl %0, %%cr0\n"
22438+#endif
22439+
22440 " jmp 2b\n"
22441 ".previous\n"
22442- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22443+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22444
22445 from += 64;
22446 to += 64;
22447@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22448 static void fast_copy_page(void *to, void *from)
22449 {
22450 int i;
22451+ unsigned long cr0;
22452
22453 kernel_fpu_begin();
22454
22455 __asm__ __volatile__ (
22456- "1: prefetch (%0)\n"
22457- " prefetch 64(%0)\n"
22458- " prefetch 128(%0)\n"
22459- " prefetch 192(%0)\n"
22460- " prefetch 256(%0)\n"
22461+ "1: prefetch (%1)\n"
22462+ " prefetch 64(%1)\n"
22463+ " prefetch 128(%1)\n"
22464+ " prefetch 192(%1)\n"
22465+ " prefetch 256(%1)\n"
22466 "2: \n"
22467 ".section .fixup, \"ax\"\n"
22468- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22469+ "3: \n"
22470+
22471+#ifdef CONFIG_PAX_KERNEXEC
22472+ " movl %%cr0, %0\n"
22473+ " movl %0, %%eax\n"
22474+ " andl $0xFFFEFFFF, %%eax\n"
22475+ " movl %%eax, %%cr0\n"
22476+#endif
22477+
22478+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22479+
22480+#ifdef CONFIG_PAX_KERNEXEC
22481+ " movl %0, %%cr0\n"
22482+#endif
22483+
22484 " jmp 2b\n"
22485 ".previous\n"
22486- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22487+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22488
22489 for (i = 0; i < 4096/64; i++) {
22490 __asm__ __volatile__ (
22491- "1: prefetch 320(%0)\n"
22492- "2: movq (%0), %%mm0\n"
22493- " movq 8(%0), %%mm1\n"
22494- " movq 16(%0), %%mm2\n"
22495- " movq 24(%0), %%mm3\n"
22496- " movq %%mm0, (%1)\n"
22497- " movq %%mm1, 8(%1)\n"
22498- " movq %%mm2, 16(%1)\n"
22499- " movq %%mm3, 24(%1)\n"
22500- " movq 32(%0), %%mm0\n"
22501- " movq 40(%0), %%mm1\n"
22502- " movq 48(%0), %%mm2\n"
22503- " movq 56(%0), %%mm3\n"
22504- " movq %%mm0, 32(%1)\n"
22505- " movq %%mm1, 40(%1)\n"
22506- " movq %%mm2, 48(%1)\n"
22507- " movq %%mm3, 56(%1)\n"
22508+ "1: prefetch 320(%1)\n"
22509+ "2: movq (%1), %%mm0\n"
22510+ " movq 8(%1), %%mm1\n"
22511+ " movq 16(%1), %%mm2\n"
22512+ " movq 24(%1), %%mm3\n"
22513+ " movq %%mm0, (%2)\n"
22514+ " movq %%mm1, 8(%2)\n"
22515+ " movq %%mm2, 16(%2)\n"
22516+ " movq %%mm3, 24(%2)\n"
22517+ " movq 32(%1), %%mm0\n"
22518+ " movq 40(%1), %%mm1\n"
22519+ " movq 48(%1), %%mm2\n"
22520+ " movq 56(%1), %%mm3\n"
22521+ " movq %%mm0, 32(%2)\n"
22522+ " movq %%mm1, 40(%2)\n"
22523+ " movq %%mm2, 48(%2)\n"
22524+ " movq %%mm3, 56(%2)\n"
22525 ".section .fixup, \"ax\"\n"
22526- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22527+ "3:\n"
22528+
22529+#ifdef CONFIG_PAX_KERNEXEC
22530+ " movl %%cr0, %0\n"
22531+ " movl %0, %%eax\n"
22532+ " andl $0xFFFEFFFF, %%eax\n"
22533+ " movl %%eax, %%cr0\n"
22534+#endif
22535+
22536+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22537+
22538+#ifdef CONFIG_PAX_KERNEXEC
22539+ " movl %0, %%cr0\n"
22540+#endif
22541+
22542 " jmp 2b\n"
22543 ".previous\n"
22544 _ASM_EXTABLE(1b, 3b)
22545- : : "r" (from), "r" (to) : "memory");
22546+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22547
22548 from += 64;
22549 to += 64;
22550diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22551index 69fa106..adda88b 100644
22552--- a/arch/x86/lib/msr-reg.S
22553+++ b/arch/x86/lib/msr-reg.S
22554@@ -3,6 +3,7 @@
22555 #include <asm/dwarf2.h>
22556 #include <asm/asm.h>
22557 #include <asm/msr.h>
22558+#include <asm/alternative-asm.h>
22559
22560 #ifdef CONFIG_X86_64
22561 /*
22562@@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22563 CFI_STARTPROC
22564 pushq_cfi %rbx
22565 pushq_cfi %rbp
22566- movq %rdi, %r10 /* Save pointer */
22567+ movq %rdi, %r9 /* Save pointer */
22568 xorl %r11d, %r11d /* Return value */
22569 movl (%rdi), %eax
22570 movl 4(%rdi), %ecx
22571@@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22572 movl 28(%rdi), %edi
22573 CFI_REMEMBER_STATE
22574 1: \op
22575-2: movl %eax, (%r10)
22576+2: movl %eax, (%r9)
22577 movl %r11d, %eax /* Return value */
22578- movl %ecx, 4(%r10)
22579- movl %edx, 8(%r10)
22580- movl %ebx, 12(%r10)
22581- movl %ebp, 20(%r10)
22582- movl %esi, 24(%r10)
22583- movl %edi, 28(%r10)
22584+ movl %ecx, 4(%r9)
22585+ movl %edx, 8(%r9)
22586+ movl %ebx, 12(%r9)
22587+ movl %ebp, 20(%r9)
22588+ movl %esi, 24(%r9)
22589+ movl %edi, 28(%r9)
22590 popq_cfi %rbp
22591 popq_cfi %rbx
22592+ pax_force_retaddr
22593 ret
22594 3:
22595 CFI_RESTORE_STATE
22596diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22597index 36b0d15..d381858 100644
22598--- a/arch/x86/lib/putuser.S
22599+++ b/arch/x86/lib/putuser.S
22600@@ -15,7 +15,9 @@
22601 #include <asm/thread_info.h>
22602 #include <asm/errno.h>
22603 #include <asm/asm.h>
22604-
22605+#include <asm/segment.h>
22606+#include <asm/pgtable.h>
22607+#include <asm/alternative-asm.h>
22608
22609 /*
22610 * __put_user_X
22611@@ -29,52 +31,119 @@
22612 * as they get called from within inline assembly.
22613 */
22614
22615-#define ENTER CFI_STARTPROC ; \
22616- GET_THREAD_INFO(%_ASM_BX)
22617-#define EXIT ret ; \
22618+#define ENTER CFI_STARTPROC
22619+#define EXIT pax_force_retaddr; ret ; \
22620 CFI_ENDPROC
22621
22622+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22623+#define _DEST %_ASM_CX,%_ASM_BX
22624+#else
22625+#define _DEST %_ASM_CX
22626+#endif
22627+
22628+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22629+#define __copyuser_seg gs;
22630+#else
22631+#define __copyuser_seg
22632+#endif
22633+
22634 .text
22635 ENTRY(__put_user_1)
22636 ENTER
22637+
22638+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22639+ GET_THREAD_INFO(%_ASM_BX)
22640 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22641 jae bad_put_user
22642-1: movb %al,(%_ASM_CX)
22643+
22644+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22645+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22646+ cmp %_ASM_BX,%_ASM_CX
22647+ jb 1234f
22648+ xor %ebx,%ebx
22649+1234:
22650+#endif
22651+
22652+#endif
22653+
22654+1: __copyuser_seg movb %al,(_DEST)
22655 xor %eax,%eax
22656 EXIT
22657 ENDPROC(__put_user_1)
22658
22659 ENTRY(__put_user_2)
22660 ENTER
22661+
22662+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22663+ GET_THREAD_INFO(%_ASM_BX)
22664 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22665 sub $1,%_ASM_BX
22666 cmp %_ASM_BX,%_ASM_CX
22667 jae bad_put_user
22668-2: movw %ax,(%_ASM_CX)
22669+
22670+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22671+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22672+ cmp %_ASM_BX,%_ASM_CX
22673+ jb 1234f
22674+ xor %ebx,%ebx
22675+1234:
22676+#endif
22677+
22678+#endif
22679+
22680+2: __copyuser_seg movw %ax,(_DEST)
22681 xor %eax,%eax
22682 EXIT
22683 ENDPROC(__put_user_2)
22684
22685 ENTRY(__put_user_4)
22686 ENTER
22687+
22688+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22689+ GET_THREAD_INFO(%_ASM_BX)
22690 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22691 sub $3,%_ASM_BX
22692 cmp %_ASM_BX,%_ASM_CX
22693 jae bad_put_user
22694-3: movl %eax,(%_ASM_CX)
22695+
22696+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22697+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22698+ cmp %_ASM_BX,%_ASM_CX
22699+ jb 1234f
22700+ xor %ebx,%ebx
22701+1234:
22702+#endif
22703+
22704+#endif
22705+
22706+3: __copyuser_seg movl %eax,(_DEST)
22707 xor %eax,%eax
22708 EXIT
22709 ENDPROC(__put_user_4)
22710
22711 ENTRY(__put_user_8)
22712 ENTER
22713+
22714+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22715+ GET_THREAD_INFO(%_ASM_BX)
22716 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22717 sub $7,%_ASM_BX
22718 cmp %_ASM_BX,%_ASM_CX
22719 jae bad_put_user
22720-4: mov %_ASM_AX,(%_ASM_CX)
22721+
22722+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22723+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22724+ cmp %_ASM_BX,%_ASM_CX
22725+ jb 1234f
22726+ xor %ebx,%ebx
22727+1234:
22728+#endif
22729+
22730+#endif
22731+
22732+4: __copyuser_seg mov %_ASM_AX,(_DEST)
22733 #ifdef CONFIG_X86_32
22734-5: movl %edx,4(%_ASM_CX)
22735+5: __copyuser_seg movl %edx,4(_DEST)
22736 #endif
22737 xor %eax,%eax
22738 EXIT
22739diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22740index 1cad221..de671ee 100644
22741--- a/arch/x86/lib/rwlock.S
22742+++ b/arch/x86/lib/rwlock.S
22743@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22744 FRAME
22745 0: LOCK_PREFIX
22746 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22747+
22748+#ifdef CONFIG_PAX_REFCOUNT
22749+ jno 1234f
22750+ LOCK_PREFIX
22751+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22752+ int $4
22753+1234:
22754+ _ASM_EXTABLE(1234b, 1234b)
22755+#endif
22756+
22757 1: rep; nop
22758 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22759 jne 1b
22760 LOCK_PREFIX
22761 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22762+
22763+#ifdef CONFIG_PAX_REFCOUNT
22764+ jno 1234f
22765+ LOCK_PREFIX
22766+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22767+ int $4
22768+1234:
22769+ _ASM_EXTABLE(1234b, 1234b)
22770+#endif
22771+
22772 jnz 0b
22773 ENDFRAME
22774+ pax_force_retaddr
22775 ret
22776 CFI_ENDPROC
22777 END(__write_lock_failed)
22778@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22779 FRAME
22780 0: LOCK_PREFIX
22781 READ_LOCK_SIZE(inc) (%__lock_ptr)
22782+
22783+#ifdef CONFIG_PAX_REFCOUNT
22784+ jno 1234f
22785+ LOCK_PREFIX
22786+ READ_LOCK_SIZE(dec) (%__lock_ptr)
22787+ int $4
22788+1234:
22789+ _ASM_EXTABLE(1234b, 1234b)
22790+#endif
22791+
22792 1: rep; nop
22793 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22794 js 1b
22795 LOCK_PREFIX
22796 READ_LOCK_SIZE(dec) (%__lock_ptr)
22797+
22798+#ifdef CONFIG_PAX_REFCOUNT
22799+ jno 1234f
22800+ LOCK_PREFIX
22801+ READ_LOCK_SIZE(inc) (%__lock_ptr)
22802+ int $4
22803+1234:
22804+ _ASM_EXTABLE(1234b, 1234b)
22805+#endif
22806+
22807 js 0b
22808 ENDFRAME
22809+ pax_force_retaddr
22810 ret
22811 CFI_ENDPROC
22812 END(__read_lock_failed)
22813diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22814index 5dff5f0..cadebf4 100644
22815--- a/arch/x86/lib/rwsem.S
22816+++ b/arch/x86/lib/rwsem.S
22817@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22818 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22819 CFI_RESTORE __ASM_REG(dx)
22820 restore_common_regs
22821+ pax_force_retaddr
22822 ret
22823 CFI_ENDPROC
22824 ENDPROC(call_rwsem_down_read_failed)
22825@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22826 movq %rax,%rdi
22827 call rwsem_down_write_failed
22828 restore_common_regs
22829+ pax_force_retaddr
22830 ret
22831 CFI_ENDPROC
22832 ENDPROC(call_rwsem_down_write_failed)
22833@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22834 movq %rax,%rdi
22835 call rwsem_wake
22836 restore_common_regs
22837-1: ret
22838+1: pax_force_retaddr
22839+ ret
22840 CFI_ENDPROC
22841 ENDPROC(call_rwsem_wake)
22842
22843@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22844 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22845 CFI_RESTORE __ASM_REG(dx)
22846 restore_common_regs
22847+ pax_force_retaddr
22848 ret
22849 CFI_ENDPROC
22850 ENDPROC(call_rwsem_downgrade_wake)
22851diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22852index a63efd6..ccecad8 100644
22853--- a/arch/x86/lib/thunk_64.S
22854+++ b/arch/x86/lib/thunk_64.S
22855@@ -8,6 +8,7 @@
22856 #include <linux/linkage.h>
22857 #include <asm/dwarf2.h>
22858 #include <asm/calling.h>
22859+#include <asm/alternative-asm.h>
22860
22861 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22862 .macro THUNK name, func, put_ret_addr_in_rdi=0
22863@@ -41,5 +42,6 @@
22864 SAVE_ARGS
22865 restore:
22866 RESTORE_ARGS
22867+ pax_force_retaddr
22868 ret
22869 CFI_ENDPROC
22870diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22871index ef2a6a5..3b28862 100644
22872--- a/arch/x86/lib/usercopy_32.c
22873+++ b/arch/x86/lib/usercopy_32.c
22874@@ -41,10 +41,12 @@ do { \
22875 int __d0; \
22876 might_fault(); \
22877 __asm__ __volatile__( \
22878+ __COPYUSER_SET_ES \
22879 "0: rep; stosl\n" \
22880 " movl %2,%0\n" \
22881 "1: rep; stosb\n" \
22882 "2:\n" \
22883+ __COPYUSER_RESTORE_ES \
22884 ".section .fixup,\"ax\"\n" \
22885 "3: lea 0(%2,%0,4),%0\n" \
22886 " jmp 2b\n" \
22887@@ -113,6 +115,7 @@ long strnlen_user(const char __user *s, long n)
22888 might_fault();
22889
22890 __asm__ __volatile__(
22891+ __COPYUSER_SET_ES
22892 " testl %0, %0\n"
22893 " jz 3f\n"
22894 " andl %0,%%ecx\n"
22895@@ -121,6 +124,7 @@ long strnlen_user(const char __user *s, long n)
22896 " subl %%ecx,%0\n"
22897 " addl %0,%%eax\n"
22898 "1:\n"
22899+ __COPYUSER_RESTORE_ES
22900 ".section .fixup,\"ax\"\n"
22901 "2: xorl %%eax,%%eax\n"
22902 " jmp 1b\n"
22903@@ -140,7 +144,7 @@ EXPORT_SYMBOL(strnlen_user);
22904
22905 #ifdef CONFIG_X86_INTEL_USERCOPY
22906 static unsigned long
22907-__copy_user_intel(void __user *to, const void *from, unsigned long size)
22908+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22909 {
22910 int d0, d1;
22911 __asm__ __volatile__(
22912@@ -152,36 +156,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22913 " .align 2,0x90\n"
22914 "3: movl 0(%4), %%eax\n"
22915 "4: movl 4(%4), %%edx\n"
22916- "5: movl %%eax, 0(%3)\n"
22917- "6: movl %%edx, 4(%3)\n"
22918+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22919+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22920 "7: movl 8(%4), %%eax\n"
22921 "8: movl 12(%4),%%edx\n"
22922- "9: movl %%eax, 8(%3)\n"
22923- "10: movl %%edx, 12(%3)\n"
22924+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22925+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22926 "11: movl 16(%4), %%eax\n"
22927 "12: movl 20(%4), %%edx\n"
22928- "13: movl %%eax, 16(%3)\n"
22929- "14: movl %%edx, 20(%3)\n"
22930+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22931+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22932 "15: movl 24(%4), %%eax\n"
22933 "16: movl 28(%4), %%edx\n"
22934- "17: movl %%eax, 24(%3)\n"
22935- "18: movl %%edx, 28(%3)\n"
22936+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22937+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22938 "19: movl 32(%4), %%eax\n"
22939 "20: movl 36(%4), %%edx\n"
22940- "21: movl %%eax, 32(%3)\n"
22941- "22: movl %%edx, 36(%3)\n"
22942+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22943+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22944 "23: movl 40(%4), %%eax\n"
22945 "24: movl 44(%4), %%edx\n"
22946- "25: movl %%eax, 40(%3)\n"
22947- "26: movl %%edx, 44(%3)\n"
22948+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22949+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22950 "27: movl 48(%4), %%eax\n"
22951 "28: movl 52(%4), %%edx\n"
22952- "29: movl %%eax, 48(%3)\n"
22953- "30: movl %%edx, 52(%3)\n"
22954+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22955+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22956 "31: movl 56(%4), %%eax\n"
22957 "32: movl 60(%4), %%edx\n"
22958- "33: movl %%eax, 56(%3)\n"
22959- "34: movl %%edx, 60(%3)\n"
22960+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22961+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22962 " addl $-64, %0\n"
22963 " addl $64, %4\n"
22964 " addl $64, %3\n"
22965@@ -191,10 +195,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22966 " shrl $2, %0\n"
22967 " andl $3, %%eax\n"
22968 " cld\n"
22969+ __COPYUSER_SET_ES
22970 "99: rep; movsl\n"
22971 "36: movl %%eax, %0\n"
22972 "37: rep; movsb\n"
22973 "100:\n"
22974+ __COPYUSER_RESTORE_ES
22975 ".section .fixup,\"ax\"\n"
22976 "101: lea 0(%%eax,%0,4),%0\n"
22977 " jmp 100b\n"
22978@@ -247,46 +253,155 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22979 }
22980
22981 static unsigned long
22982+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22983+{
22984+ int d0, d1;
22985+ __asm__ __volatile__(
22986+ " .align 2,0x90\n"
22987+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22988+ " cmpl $67, %0\n"
22989+ " jbe 3f\n"
22990+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22991+ " .align 2,0x90\n"
22992+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22993+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22994+ "5: movl %%eax, 0(%3)\n"
22995+ "6: movl %%edx, 4(%3)\n"
22996+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22997+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22998+ "9: movl %%eax, 8(%3)\n"
22999+ "10: movl %%edx, 12(%3)\n"
23000+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23001+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23002+ "13: movl %%eax, 16(%3)\n"
23003+ "14: movl %%edx, 20(%3)\n"
23004+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23005+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23006+ "17: movl %%eax, 24(%3)\n"
23007+ "18: movl %%edx, 28(%3)\n"
23008+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23009+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23010+ "21: movl %%eax, 32(%3)\n"
23011+ "22: movl %%edx, 36(%3)\n"
23012+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23013+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23014+ "25: movl %%eax, 40(%3)\n"
23015+ "26: movl %%edx, 44(%3)\n"
23016+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23017+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23018+ "29: movl %%eax, 48(%3)\n"
23019+ "30: movl %%edx, 52(%3)\n"
23020+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23021+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23022+ "33: movl %%eax, 56(%3)\n"
23023+ "34: movl %%edx, 60(%3)\n"
23024+ " addl $-64, %0\n"
23025+ " addl $64, %4\n"
23026+ " addl $64, %3\n"
23027+ " cmpl $63, %0\n"
23028+ " ja 1b\n"
23029+ "35: movl %0, %%eax\n"
23030+ " shrl $2, %0\n"
23031+ " andl $3, %%eax\n"
23032+ " cld\n"
23033+ "99: rep; "__copyuser_seg" movsl\n"
23034+ "36: movl %%eax, %0\n"
23035+ "37: rep; "__copyuser_seg" movsb\n"
23036+ "100:\n"
23037+ ".section .fixup,\"ax\"\n"
23038+ "101: lea 0(%%eax,%0,4),%0\n"
23039+ " jmp 100b\n"
23040+ ".previous\n"
23041+ ".section __ex_table,\"a\"\n"
23042+ " .align 4\n"
23043+ " .long 1b,100b\n"
23044+ " .long 2b,100b\n"
23045+ " .long 3b,100b\n"
23046+ " .long 4b,100b\n"
23047+ " .long 5b,100b\n"
23048+ " .long 6b,100b\n"
23049+ " .long 7b,100b\n"
23050+ " .long 8b,100b\n"
23051+ " .long 9b,100b\n"
23052+ " .long 10b,100b\n"
23053+ " .long 11b,100b\n"
23054+ " .long 12b,100b\n"
23055+ " .long 13b,100b\n"
23056+ " .long 14b,100b\n"
23057+ " .long 15b,100b\n"
23058+ " .long 16b,100b\n"
23059+ " .long 17b,100b\n"
23060+ " .long 18b,100b\n"
23061+ " .long 19b,100b\n"
23062+ " .long 20b,100b\n"
23063+ " .long 21b,100b\n"
23064+ " .long 22b,100b\n"
23065+ " .long 23b,100b\n"
23066+ " .long 24b,100b\n"
23067+ " .long 25b,100b\n"
23068+ " .long 26b,100b\n"
23069+ " .long 27b,100b\n"
23070+ " .long 28b,100b\n"
23071+ " .long 29b,100b\n"
23072+ " .long 30b,100b\n"
23073+ " .long 31b,100b\n"
23074+ " .long 32b,100b\n"
23075+ " .long 33b,100b\n"
23076+ " .long 34b,100b\n"
23077+ " .long 35b,100b\n"
23078+ " .long 36b,100b\n"
23079+ " .long 37b,100b\n"
23080+ " .long 99b,101b\n"
23081+ ".previous"
23082+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
23083+ : "1"(to), "2"(from), "0"(size)
23084+ : "eax", "edx", "memory");
23085+ return size;
23086+}
23087+
23088+static unsigned long
23089+__copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size) __size_overflow(3);
23090+static unsigned long
23091 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23092 {
23093 int d0, d1;
23094 __asm__ __volatile__(
23095 " .align 2,0x90\n"
23096- "0: movl 32(%4), %%eax\n"
23097+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23098 " cmpl $67, %0\n"
23099 " jbe 2f\n"
23100- "1: movl 64(%4), %%eax\n"
23101+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23102 " .align 2,0x90\n"
23103- "2: movl 0(%4), %%eax\n"
23104- "21: movl 4(%4), %%edx\n"
23105+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23106+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23107 " movl %%eax, 0(%3)\n"
23108 " movl %%edx, 4(%3)\n"
23109- "3: movl 8(%4), %%eax\n"
23110- "31: movl 12(%4),%%edx\n"
23111+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23112+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23113 " movl %%eax, 8(%3)\n"
23114 " movl %%edx, 12(%3)\n"
23115- "4: movl 16(%4), %%eax\n"
23116- "41: movl 20(%4), %%edx\n"
23117+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23118+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23119 " movl %%eax, 16(%3)\n"
23120 " movl %%edx, 20(%3)\n"
23121- "10: movl 24(%4), %%eax\n"
23122- "51: movl 28(%4), %%edx\n"
23123+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23124+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23125 " movl %%eax, 24(%3)\n"
23126 " movl %%edx, 28(%3)\n"
23127- "11: movl 32(%4), %%eax\n"
23128- "61: movl 36(%4), %%edx\n"
23129+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23130+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23131 " movl %%eax, 32(%3)\n"
23132 " movl %%edx, 36(%3)\n"
23133- "12: movl 40(%4), %%eax\n"
23134- "71: movl 44(%4), %%edx\n"
23135+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23136+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23137 " movl %%eax, 40(%3)\n"
23138 " movl %%edx, 44(%3)\n"
23139- "13: movl 48(%4), %%eax\n"
23140- "81: movl 52(%4), %%edx\n"
23141+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23142+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23143 " movl %%eax, 48(%3)\n"
23144 " movl %%edx, 52(%3)\n"
23145- "14: movl 56(%4), %%eax\n"
23146- "91: movl 60(%4), %%edx\n"
23147+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23148+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23149 " movl %%eax, 56(%3)\n"
23150 " movl %%edx, 60(%3)\n"
23151 " addl $-64, %0\n"
23152@@ -298,9 +413,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23153 " shrl $2, %0\n"
23154 " andl $3, %%eax\n"
23155 " cld\n"
23156- "6: rep; movsl\n"
23157+ "6: rep; "__copyuser_seg" movsl\n"
23158 " movl %%eax,%0\n"
23159- "7: rep; movsb\n"
23160+ "7: rep; "__copyuser_seg" movsb\n"
23161 "8:\n"
23162 ".section .fixup,\"ax\"\n"
23163 "9: lea 0(%%eax,%0,4),%0\n"
23164@@ -347,47 +462,49 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23165 */
23166
23167 static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23168+ const void __user *from, unsigned long size) __size_overflow(3);
23169+static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23170 const void __user *from, unsigned long size)
23171 {
23172 int d0, d1;
23173
23174 __asm__ __volatile__(
23175 " .align 2,0x90\n"
23176- "0: movl 32(%4), %%eax\n"
23177+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23178 " cmpl $67, %0\n"
23179 " jbe 2f\n"
23180- "1: movl 64(%4), %%eax\n"
23181+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23182 " .align 2,0x90\n"
23183- "2: movl 0(%4), %%eax\n"
23184- "21: movl 4(%4), %%edx\n"
23185+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23186+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23187 " movnti %%eax, 0(%3)\n"
23188 " movnti %%edx, 4(%3)\n"
23189- "3: movl 8(%4), %%eax\n"
23190- "31: movl 12(%4),%%edx\n"
23191+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23192+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23193 " movnti %%eax, 8(%3)\n"
23194 " movnti %%edx, 12(%3)\n"
23195- "4: movl 16(%4), %%eax\n"
23196- "41: movl 20(%4), %%edx\n"
23197+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23198+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23199 " movnti %%eax, 16(%3)\n"
23200 " movnti %%edx, 20(%3)\n"
23201- "10: movl 24(%4), %%eax\n"
23202- "51: movl 28(%4), %%edx\n"
23203+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23204+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23205 " movnti %%eax, 24(%3)\n"
23206 " movnti %%edx, 28(%3)\n"
23207- "11: movl 32(%4), %%eax\n"
23208- "61: movl 36(%4), %%edx\n"
23209+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23210+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23211 " movnti %%eax, 32(%3)\n"
23212 " movnti %%edx, 36(%3)\n"
23213- "12: movl 40(%4), %%eax\n"
23214- "71: movl 44(%4), %%edx\n"
23215+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23216+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23217 " movnti %%eax, 40(%3)\n"
23218 " movnti %%edx, 44(%3)\n"
23219- "13: movl 48(%4), %%eax\n"
23220- "81: movl 52(%4), %%edx\n"
23221+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23222+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23223 " movnti %%eax, 48(%3)\n"
23224 " movnti %%edx, 52(%3)\n"
23225- "14: movl 56(%4), %%eax\n"
23226- "91: movl 60(%4), %%edx\n"
23227+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23228+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23229 " movnti %%eax, 56(%3)\n"
23230 " movnti %%edx, 60(%3)\n"
23231 " addl $-64, %0\n"
23232@@ -400,9 +517,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23233 " shrl $2, %0\n"
23234 " andl $3, %%eax\n"
23235 " cld\n"
23236- "6: rep; movsl\n"
23237+ "6: rep; "__copyuser_seg" movsl\n"
23238 " movl %%eax,%0\n"
23239- "7: rep; movsb\n"
23240+ "7: rep; "__copyuser_seg" movsb\n"
23241 "8:\n"
23242 ".section .fixup,\"ax\"\n"
23243 "9: lea 0(%%eax,%0,4),%0\n"
23244@@ -444,47 +561,49 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23245 }
23246
23247 static unsigned long __copy_user_intel_nocache(void *to,
23248+ const void __user *from, unsigned long size) __size_overflow(3);
23249+static unsigned long __copy_user_intel_nocache(void *to,
23250 const void __user *from, unsigned long size)
23251 {
23252 int d0, d1;
23253
23254 __asm__ __volatile__(
23255 " .align 2,0x90\n"
23256- "0: movl 32(%4), %%eax\n"
23257+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23258 " cmpl $67, %0\n"
23259 " jbe 2f\n"
23260- "1: movl 64(%4), %%eax\n"
23261+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23262 " .align 2,0x90\n"
23263- "2: movl 0(%4), %%eax\n"
23264- "21: movl 4(%4), %%edx\n"
23265+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23266+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23267 " movnti %%eax, 0(%3)\n"
23268 " movnti %%edx, 4(%3)\n"
23269- "3: movl 8(%4), %%eax\n"
23270- "31: movl 12(%4),%%edx\n"
23271+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23272+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23273 " movnti %%eax, 8(%3)\n"
23274 " movnti %%edx, 12(%3)\n"
23275- "4: movl 16(%4), %%eax\n"
23276- "41: movl 20(%4), %%edx\n"
23277+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23278+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23279 " movnti %%eax, 16(%3)\n"
23280 " movnti %%edx, 20(%3)\n"
23281- "10: movl 24(%4), %%eax\n"
23282- "51: movl 28(%4), %%edx\n"
23283+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23284+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23285 " movnti %%eax, 24(%3)\n"
23286 " movnti %%edx, 28(%3)\n"
23287- "11: movl 32(%4), %%eax\n"
23288- "61: movl 36(%4), %%edx\n"
23289+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23290+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23291 " movnti %%eax, 32(%3)\n"
23292 " movnti %%edx, 36(%3)\n"
23293- "12: movl 40(%4), %%eax\n"
23294- "71: movl 44(%4), %%edx\n"
23295+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23296+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23297 " movnti %%eax, 40(%3)\n"
23298 " movnti %%edx, 44(%3)\n"
23299- "13: movl 48(%4), %%eax\n"
23300- "81: movl 52(%4), %%edx\n"
23301+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23302+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23303 " movnti %%eax, 48(%3)\n"
23304 " movnti %%edx, 52(%3)\n"
23305- "14: movl 56(%4), %%eax\n"
23306- "91: movl 60(%4), %%edx\n"
23307+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23308+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23309 " movnti %%eax, 56(%3)\n"
23310 " movnti %%edx, 60(%3)\n"
23311 " addl $-64, %0\n"
23312@@ -497,9 +616,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23313 " shrl $2, %0\n"
23314 " andl $3, %%eax\n"
23315 " cld\n"
23316- "6: rep; movsl\n"
23317+ "6: rep; "__copyuser_seg" movsl\n"
23318 " movl %%eax,%0\n"
23319- "7: rep; movsb\n"
23320+ "7: rep; "__copyuser_seg" movsb\n"
23321 "8:\n"
23322 ".section .fixup,\"ax\"\n"
23323 "9: lea 0(%%eax,%0,4),%0\n"
23324@@ -542,32 +661,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23325 */
23326 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23327 unsigned long size);
23328-unsigned long __copy_user_intel(void __user *to, const void *from,
23329+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23330+ unsigned long size);
23331+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23332 unsigned long size);
23333 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23334 const void __user *from, unsigned long size);
23335 #endif /* CONFIG_X86_INTEL_USERCOPY */
23336
23337 /* Generic arbitrary sized copy. */
23338-#define __copy_user(to, from, size) \
23339+#define __copy_user(to, from, size, prefix, set, restore) \
23340 do { \
23341 int __d0, __d1, __d2; \
23342 __asm__ __volatile__( \
23343+ set \
23344 " cmp $7,%0\n" \
23345 " jbe 1f\n" \
23346 " movl %1,%0\n" \
23347 " negl %0\n" \
23348 " andl $7,%0\n" \
23349 " subl %0,%3\n" \
23350- "4: rep; movsb\n" \
23351+ "4: rep; "prefix"movsb\n" \
23352 " movl %3,%0\n" \
23353 " shrl $2,%0\n" \
23354 " andl $3,%3\n" \
23355 " .align 2,0x90\n" \
23356- "0: rep; movsl\n" \
23357+ "0: rep; "prefix"movsl\n" \
23358 " movl %3,%0\n" \
23359- "1: rep; movsb\n" \
23360+ "1: rep; "prefix"movsb\n" \
23361 "2:\n" \
23362+ restore \
23363 ".section .fixup,\"ax\"\n" \
23364 "5: addl %3,%0\n" \
23365 " jmp 2b\n" \
23366@@ -595,14 +718,14 @@ do { \
23367 " negl %0\n" \
23368 " andl $7,%0\n" \
23369 " subl %0,%3\n" \
23370- "4: rep; movsb\n" \
23371+ "4: rep; "__copyuser_seg"movsb\n" \
23372 " movl %3,%0\n" \
23373 " shrl $2,%0\n" \
23374 " andl $3,%3\n" \
23375 " .align 2,0x90\n" \
23376- "0: rep; movsl\n" \
23377+ "0: rep; "__copyuser_seg"movsl\n" \
23378 " movl %3,%0\n" \
23379- "1: rep; movsb\n" \
23380+ "1: rep; "__copyuser_seg"movsb\n" \
23381 "2:\n" \
23382 ".section .fixup,\"ax\"\n" \
23383 "5: addl %3,%0\n" \
23384@@ -688,9 +811,9 @@ survive:
23385 }
23386 #endif
23387 if (movsl_is_ok(to, from, n))
23388- __copy_user(to, from, n);
23389+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23390 else
23391- n = __copy_user_intel(to, from, n);
23392+ n = __generic_copy_to_user_intel(to, from, n);
23393 return n;
23394 }
23395 EXPORT_SYMBOL(__copy_to_user_ll);
23396@@ -710,10 +833,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23397 unsigned long n)
23398 {
23399 if (movsl_is_ok(to, from, n))
23400- __copy_user(to, from, n);
23401+ __copy_user(to, from, n, __copyuser_seg, "", "");
23402 else
23403- n = __copy_user_intel((void __user *)to,
23404- (const void *)from, n);
23405+ n = __generic_copy_from_user_intel(to, from, n);
23406 return n;
23407 }
23408 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23409@@ -740,65 +862,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23410 if (n > 64 && cpu_has_xmm2)
23411 n = __copy_user_intel_nocache(to, from, n);
23412 else
23413- __copy_user(to, from, n);
23414+ __copy_user(to, from, n, __copyuser_seg, "", "");
23415 #else
23416- __copy_user(to, from, n);
23417+ __copy_user(to, from, n, __copyuser_seg, "", "");
23418 #endif
23419 return n;
23420 }
23421 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23422
23423-/**
23424- * copy_to_user: - Copy a block of data into user space.
23425- * @to: Destination address, in user space.
23426- * @from: Source address, in kernel space.
23427- * @n: Number of bytes to copy.
23428- *
23429- * Context: User context only. This function may sleep.
23430- *
23431- * Copy data from kernel space to user space.
23432- *
23433- * Returns number of bytes that could not be copied.
23434- * On success, this will be zero.
23435- */
23436-unsigned long
23437-copy_to_user(void __user *to, const void *from, unsigned long n)
23438-{
23439- if (access_ok(VERIFY_WRITE, to, n))
23440- n = __copy_to_user(to, from, n);
23441- return n;
23442-}
23443-EXPORT_SYMBOL(copy_to_user);
23444-
23445-/**
23446- * copy_from_user: - Copy a block of data from user space.
23447- * @to: Destination address, in kernel space.
23448- * @from: Source address, in user space.
23449- * @n: Number of bytes to copy.
23450- *
23451- * Context: User context only. This function may sleep.
23452- *
23453- * Copy data from user space to kernel space.
23454- *
23455- * Returns number of bytes that could not be copied.
23456- * On success, this will be zero.
23457- *
23458- * If some data could not be copied, this function will pad the copied
23459- * data to the requested size using zero bytes.
23460- */
23461-unsigned long
23462-_copy_from_user(void *to, const void __user *from, unsigned long n)
23463-{
23464- if (access_ok(VERIFY_READ, from, n))
23465- n = __copy_from_user(to, from, n);
23466- else
23467- memset(to, 0, n);
23468- return n;
23469-}
23470-EXPORT_SYMBOL(_copy_from_user);
23471-
23472 void copy_from_user_overflow(void)
23473 {
23474 WARN(1, "Buffer overflow detected!\n");
23475 }
23476 EXPORT_SYMBOL(copy_from_user_overflow);
23477+
23478+void copy_to_user_overflow(void)
23479+{
23480+ WARN(1, "Buffer overflow detected!\n");
23481+}
23482+EXPORT_SYMBOL(copy_to_user_overflow);
23483+
23484+#ifdef CONFIG_PAX_MEMORY_UDEREF
23485+void __set_fs(mm_segment_t x)
23486+{
23487+ switch (x.seg) {
23488+ case 0:
23489+ loadsegment(gs, 0);
23490+ break;
23491+ case TASK_SIZE_MAX:
23492+ loadsegment(gs, __USER_DS);
23493+ break;
23494+ case -1UL:
23495+ loadsegment(gs, __KERNEL_DS);
23496+ break;
23497+ default:
23498+ BUG();
23499+ }
23500+ return;
23501+}
23502+EXPORT_SYMBOL(__set_fs);
23503+
23504+void set_fs(mm_segment_t x)
23505+{
23506+ current_thread_info()->addr_limit = x;
23507+ __set_fs(x);
23508+}
23509+EXPORT_SYMBOL(set_fs);
23510+#endif
23511diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23512index 0d0326f..6a6155b 100644
23513--- a/arch/x86/lib/usercopy_64.c
23514+++ b/arch/x86/lib/usercopy_64.c
23515@@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23516 {
23517 long __d0;
23518 might_fault();
23519+
23520+#ifdef CONFIG_PAX_MEMORY_UDEREF
23521+ if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23522+ addr += PAX_USER_SHADOW_BASE;
23523+#endif
23524+
23525 /* no memory constraint because it doesn't change any memory gcc knows
23526 about */
23527 asm volatile(
23528@@ -100,12 +106,20 @@ long strlen_user(const char __user *s)
23529 }
23530 EXPORT_SYMBOL(strlen_user);
23531
23532-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23533+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23534 {
23535- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23536- return copy_user_generic((__force void *)to, (__force void *)from, len);
23537- }
23538- return len;
23539+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23540+
23541+#ifdef CONFIG_PAX_MEMORY_UDEREF
23542+ if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23543+ to += PAX_USER_SHADOW_BASE;
23544+ if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23545+ from += PAX_USER_SHADOW_BASE;
23546+#endif
23547+
23548+ return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23549+ }
23550+ return len;
23551 }
23552 EXPORT_SYMBOL(copy_in_user);
23553
23554@@ -115,7 +129,7 @@ EXPORT_SYMBOL(copy_in_user);
23555 * it is not necessary to optimize tail handling.
23556 */
23557 unsigned long
23558-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23559+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23560 {
23561 char c;
23562 unsigned zero_len;
23563@@ -132,3 +146,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23564 break;
23565 return len;
23566 }
23567+
23568+void copy_from_user_overflow(void)
23569+{
23570+ WARN(1, "Buffer overflow detected!\n");
23571+}
23572+EXPORT_SYMBOL(copy_from_user_overflow);
23573+
23574+void copy_to_user_overflow(void)
23575+{
23576+ WARN(1, "Buffer overflow detected!\n");
23577+}
23578+EXPORT_SYMBOL(copy_to_user_overflow);
23579diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23580index 1fb85db..8b3540b 100644
23581--- a/arch/x86/mm/extable.c
23582+++ b/arch/x86/mm/extable.c
23583@@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs)
23584 const struct exception_table_entry *fixup;
23585
23586 #ifdef CONFIG_PNPBIOS
23587- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23588+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23589 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23590 extern u32 pnp_bios_is_utter_crap;
23591 pnp_bios_is_utter_crap = 1;
23592diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23593index 3ecfd1a..304d554 100644
23594--- a/arch/x86/mm/fault.c
23595+++ b/arch/x86/mm/fault.c
23596@@ -13,11 +13,18 @@
23597 #include <linux/perf_event.h> /* perf_sw_event */
23598 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23599 #include <linux/prefetch.h> /* prefetchw */
23600+#include <linux/unistd.h>
23601+#include <linux/compiler.h>
23602
23603 #include <asm/traps.h> /* dotraplinkage, ... */
23604 #include <asm/pgalloc.h> /* pgd_*(), ... */
23605 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23606 #include <asm/fixmap.h> /* VSYSCALL_START */
23607+#include <asm/tlbflush.h>
23608+
23609+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23610+#include <asm/stacktrace.h>
23611+#endif
23612
23613 /*
23614 * Page fault error code bits:
23615@@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23616 int ret = 0;
23617
23618 /* kprobe_running() needs smp_processor_id() */
23619- if (kprobes_built_in() && !user_mode_vm(regs)) {
23620+ if (kprobes_built_in() && !user_mode(regs)) {
23621 preempt_disable();
23622 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23623 ret = 1;
23624@@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23625 return !instr_lo || (instr_lo>>1) == 1;
23626 case 0x00:
23627 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23628- if (probe_kernel_address(instr, opcode))
23629+ if (user_mode(regs)) {
23630+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23631+ return 0;
23632+ } else if (probe_kernel_address(instr, opcode))
23633 return 0;
23634
23635 *prefetch = (instr_lo == 0xF) &&
23636@@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23637 while (instr < max_instr) {
23638 unsigned char opcode;
23639
23640- if (probe_kernel_address(instr, opcode))
23641+ if (user_mode(regs)) {
23642+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23643+ break;
23644+ } else if (probe_kernel_address(instr, opcode))
23645 break;
23646
23647 instr++;
23648@@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23649 force_sig_info(si_signo, &info, tsk);
23650 }
23651
23652+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23653+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23654+#endif
23655+
23656+#ifdef CONFIG_PAX_EMUTRAMP
23657+static int pax_handle_fetch_fault(struct pt_regs *regs);
23658+#endif
23659+
23660+#ifdef CONFIG_PAX_PAGEEXEC
23661+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23662+{
23663+ pgd_t *pgd;
23664+ pud_t *pud;
23665+ pmd_t *pmd;
23666+
23667+ pgd = pgd_offset(mm, address);
23668+ if (!pgd_present(*pgd))
23669+ return NULL;
23670+ pud = pud_offset(pgd, address);
23671+ if (!pud_present(*pud))
23672+ return NULL;
23673+ pmd = pmd_offset(pud, address);
23674+ if (!pmd_present(*pmd))
23675+ return NULL;
23676+ return pmd;
23677+}
23678+#endif
23679+
23680 DEFINE_SPINLOCK(pgd_lock);
23681 LIST_HEAD(pgd_list);
23682
23683@@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23684 for (address = VMALLOC_START & PMD_MASK;
23685 address >= TASK_SIZE && address < FIXADDR_TOP;
23686 address += PMD_SIZE) {
23687+
23688+#ifdef CONFIG_PAX_PER_CPU_PGD
23689+ unsigned long cpu;
23690+#else
23691 struct page *page;
23692+#endif
23693
23694 spin_lock(&pgd_lock);
23695+
23696+#ifdef CONFIG_PAX_PER_CPU_PGD
23697+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23698+ pgd_t *pgd = get_cpu_pgd(cpu);
23699+ pmd_t *ret;
23700+#else
23701 list_for_each_entry(page, &pgd_list, lru) {
23702+ pgd_t *pgd = page_address(page);
23703 spinlock_t *pgt_lock;
23704 pmd_t *ret;
23705
23706@@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23707 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23708
23709 spin_lock(pgt_lock);
23710- ret = vmalloc_sync_one(page_address(page), address);
23711+#endif
23712+
23713+ ret = vmalloc_sync_one(pgd, address);
23714+
23715+#ifndef CONFIG_PAX_PER_CPU_PGD
23716 spin_unlock(pgt_lock);
23717+#endif
23718
23719 if (!ret)
23720 break;
23721@@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23722 * an interrupt in the middle of a task switch..
23723 */
23724 pgd_paddr = read_cr3();
23725+
23726+#ifdef CONFIG_PAX_PER_CPU_PGD
23727+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23728+#endif
23729+
23730 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23731 if (!pmd_k)
23732 return -1;
23733@@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23734 * happen within a race in page table update. In the later
23735 * case just flush:
23736 */
23737+
23738+#ifdef CONFIG_PAX_PER_CPU_PGD
23739+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23740+ pgd = pgd_offset_cpu(smp_processor_id(), address);
23741+#else
23742 pgd = pgd_offset(current->active_mm, address);
23743+#endif
23744+
23745 pgd_ref = pgd_offset_k(address);
23746 if (pgd_none(*pgd_ref))
23747 return -1;
23748@@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23749 static int is_errata100(struct pt_regs *regs, unsigned long address)
23750 {
23751 #ifdef CONFIG_X86_64
23752- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23753+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23754 return 1;
23755 #endif
23756 return 0;
23757@@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23758 }
23759
23760 static const char nx_warning[] = KERN_CRIT
23761-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23762+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23763
23764 static void
23765 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23766@@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23767 if (!oops_may_print())
23768 return;
23769
23770- if (error_code & PF_INSTR) {
23771+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23772 unsigned int level;
23773
23774 pte_t *pte = lookup_address(address, &level);
23775
23776 if (pte && pte_present(*pte) && !pte_exec(*pte))
23777- printk(nx_warning, current_uid());
23778+ printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
23779 }
23780
23781+#ifdef CONFIG_PAX_KERNEXEC
23782+ if (init_mm.start_code <= address && address < init_mm.end_code) {
23783+ if (current->signal->curr_ip)
23784+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23785+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23786+ else
23787+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23788+ current->comm, task_pid_nr(current), current_uid(), current_euid());
23789+ }
23790+#endif
23791+
23792 printk(KERN_ALERT "BUG: unable to handle kernel ");
23793 if (address < PAGE_SIZE)
23794 printk(KERN_CONT "NULL pointer dereference");
23795@@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23796 }
23797 #endif
23798
23799+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23800+ if (pax_is_fetch_fault(regs, error_code, address)) {
23801+
23802+#ifdef CONFIG_PAX_EMUTRAMP
23803+ switch (pax_handle_fetch_fault(regs)) {
23804+ case 2:
23805+ return;
23806+ }
23807+#endif
23808+
23809+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23810+ do_group_exit(SIGKILL);
23811+ }
23812+#endif
23813+
23814 if (unlikely(show_unhandled_signals))
23815 show_signal_msg(regs, error_code, address, tsk);
23816
23817@@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23818 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23819 printk(KERN_ERR
23820 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23821- tsk->comm, tsk->pid, address);
23822+ tsk->comm, task_pid_nr(tsk), address);
23823 code = BUS_MCEERR_AR;
23824 }
23825 #endif
23826@@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23827 return 1;
23828 }
23829
23830+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23831+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23832+{
23833+ pte_t *pte;
23834+ pmd_t *pmd;
23835+ spinlock_t *ptl;
23836+ unsigned char pte_mask;
23837+
23838+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23839+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
23840+ return 0;
23841+
23842+ /* PaX: it's our fault, let's handle it if we can */
23843+
23844+ /* PaX: take a look at read faults before acquiring any locks */
23845+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23846+ /* instruction fetch attempt from a protected page in user mode */
23847+ up_read(&mm->mmap_sem);
23848+
23849+#ifdef CONFIG_PAX_EMUTRAMP
23850+ switch (pax_handle_fetch_fault(regs)) {
23851+ case 2:
23852+ return 1;
23853+ }
23854+#endif
23855+
23856+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23857+ do_group_exit(SIGKILL);
23858+ }
23859+
23860+ pmd = pax_get_pmd(mm, address);
23861+ if (unlikely(!pmd))
23862+ return 0;
23863+
23864+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23865+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23866+ pte_unmap_unlock(pte, ptl);
23867+ return 0;
23868+ }
23869+
23870+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23871+ /* write attempt to a protected page in user mode */
23872+ pte_unmap_unlock(pte, ptl);
23873+ return 0;
23874+ }
23875+
23876+#ifdef CONFIG_SMP
23877+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23878+#else
23879+ if (likely(address > get_limit(regs->cs)))
23880+#endif
23881+ {
23882+ set_pte(pte, pte_mkread(*pte));
23883+ __flush_tlb_one(address);
23884+ pte_unmap_unlock(pte, ptl);
23885+ up_read(&mm->mmap_sem);
23886+ return 1;
23887+ }
23888+
23889+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23890+
23891+ /*
23892+ * PaX: fill DTLB with user rights and retry
23893+ */
23894+ __asm__ __volatile__ (
23895+ "orb %2,(%1)\n"
23896+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23897+/*
23898+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23899+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23900+ * page fault when examined during a TLB load attempt. this is true not only
23901+ * for PTEs holding a non-present entry but also present entries that will
23902+ * raise a page fault (such as those set up by PaX, or the copy-on-write
23903+ * mechanism). in effect it means that we do *not* need to flush the TLBs
23904+ * for our target pages since their PTEs are simply not in the TLBs at all.
23905+
23906+ * the best thing in omitting it is that we gain around 15-20% speed in the
23907+ * fast path of the page fault handler and can get rid of tracing since we
23908+ * can no longer flush unintended entries.
23909+ */
23910+ "invlpg (%0)\n"
23911+#endif
23912+ __copyuser_seg"testb $0,(%0)\n"
23913+ "xorb %3,(%1)\n"
23914+ :
23915+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23916+ : "memory", "cc");
23917+ pte_unmap_unlock(pte, ptl);
23918+ up_read(&mm->mmap_sem);
23919+ return 1;
23920+}
23921+#endif
23922+
23923 /*
23924 * Handle a spurious fault caused by a stale TLB entry.
23925 *
23926@@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23927 static inline int
23928 access_error(unsigned long error_code, struct vm_area_struct *vma)
23929 {
23930+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23931+ return 1;
23932+
23933 if (error_code & PF_WRITE) {
23934 /* write, present and write, not present: */
23935 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23936@@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23937 {
23938 struct vm_area_struct *vma;
23939 struct task_struct *tsk;
23940- unsigned long address;
23941 struct mm_struct *mm;
23942 int fault;
23943 int write = error_code & PF_WRITE;
23944 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23945 (write ? FAULT_FLAG_WRITE : 0);
23946
23947- tsk = current;
23948- mm = tsk->mm;
23949-
23950 /* Get the faulting address: */
23951- address = read_cr2();
23952+ unsigned long address = read_cr2();
23953+
23954+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23955+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23956+ if (!search_exception_tables(regs->ip)) {
23957+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23958+ bad_area_nosemaphore(regs, error_code, address);
23959+ return;
23960+ }
23961+ if (address < PAX_USER_SHADOW_BASE) {
23962+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23963+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23964+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23965+ } else
23966+ address -= PAX_USER_SHADOW_BASE;
23967+ }
23968+#endif
23969+
23970+ tsk = current;
23971+ mm = tsk->mm;
23972
23973 /*
23974 * Detect and handle instructions that would cause a page fault for
23975@@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23976 * User-mode registers count as a user access even for any
23977 * potential system fault or CPU buglet:
23978 */
23979- if (user_mode_vm(regs)) {
23980+ if (user_mode(regs)) {
23981 local_irq_enable();
23982 error_code |= PF_USER;
23983 } else {
23984@@ -1132,6 +1339,11 @@ retry:
23985 might_sleep();
23986 }
23987
23988+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23989+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23990+ return;
23991+#endif
23992+
23993 vma = find_vma(mm, address);
23994 if (unlikely(!vma)) {
23995 bad_area(regs, error_code, address);
23996@@ -1143,18 +1355,24 @@ retry:
23997 bad_area(regs, error_code, address);
23998 return;
23999 }
24000- if (error_code & PF_USER) {
24001- /*
24002- * Accessing the stack below %sp is always a bug.
24003- * The large cushion allows instructions like enter
24004- * and pusha to work. ("enter $65535, $31" pushes
24005- * 32 pointers and then decrements %sp by 65535.)
24006- */
24007- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24008- bad_area(regs, error_code, address);
24009- return;
24010- }
24011+ /*
24012+ * Accessing the stack below %sp is always a bug.
24013+ * The large cushion allows instructions like enter
24014+ * and pusha to work. ("enter $65535, $31" pushes
24015+ * 32 pointers and then decrements %sp by 65535.)
24016+ */
24017+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24018+ bad_area(regs, error_code, address);
24019+ return;
24020 }
24021+
24022+#ifdef CONFIG_PAX_SEGMEXEC
24023+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24024+ bad_area(regs, error_code, address);
24025+ return;
24026+ }
24027+#endif
24028+
24029 if (unlikely(expand_stack(vma, address))) {
24030 bad_area(regs, error_code, address);
24031 return;
24032@@ -1209,3 +1427,292 @@ good_area:
24033
24034 up_read(&mm->mmap_sem);
24035 }
24036+
24037+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24038+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24039+{
24040+ struct mm_struct *mm = current->mm;
24041+ unsigned long ip = regs->ip;
24042+
24043+ if (v8086_mode(regs))
24044+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24045+
24046+#ifdef CONFIG_PAX_PAGEEXEC
24047+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24048+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24049+ return true;
24050+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24051+ return true;
24052+ return false;
24053+ }
24054+#endif
24055+
24056+#ifdef CONFIG_PAX_SEGMEXEC
24057+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24058+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24059+ return true;
24060+ return false;
24061+ }
24062+#endif
24063+
24064+ return false;
24065+}
24066+#endif
24067+
24068+#ifdef CONFIG_PAX_EMUTRAMP
24069+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24070+{
24071+ int err;
24072+
24073+ do { /* PaX: libffi trampoline emulation */
24074+ unsigned char mov, jmp;
24075+ unsigned int addr1, addr2;
24076+
24077+#ifdef CONFIG_X86_64
24078+ if ((regs->ip + 9) >> 32)
24079+ break;
24080+#endif
24081+
24082+ err = get_user(mov, (unsigned char __user *)regs->ip);
24083+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24084+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24085+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24086+
24087+ if (err)
24088+ break;
24089+
24090+ if (mov == 0xB8 && jmp == 0xE9) {
24091+ regs->ax = addr1;
24092+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24093+ return 2;
24094+ }
24095+ } while (0);
24096+
24097+ do { /* PaX: gcc trampoline emulation #1 */
24098+ unsigned char mov1, mov2;
24099+ unsigned short jmp;
24100+ unsigned int addr1, addr2;
24101+
24102+#ifdef CONFIG_X86_64
24103+ if ((regs->ip + 11) >> 32)
24104+ break;
24105+#endif
24106+
24107+ err = get_user(mov1, (unsigned char __user *)regs->ip);
24108+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24109+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24110+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24111+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24112+
24113+ if (err)
24114+ break;
24115+
24116+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24117+ regs->cx = addr1;
24118+ regs->ax = addr2;
24119+ regs->ip = addr2;
24120+ return 2;
24121+ }
24122+ } while (0);
24123+
24124+ do { /* PaX: gcc trampoline emulation #2 */
24125+ unsigned char mov, jmp;
24126+ unsigned int addr1, addr2;
24127+
24128+#ifdef CONFIG_X86_64
24129+ if ((regs->ip + 9) >> 32)
24130+ break;
24131+#endif
24132+
24133+ err = get_user(mov, (unsigned char __user *)regs->ip);
24134+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24135+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24136+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24137+
24138+ if (err)
24139+ break;
24140+
24141+ if (mov == 0xB9 && jmp == 0xE9) {
24142+ regs->cx = addr1;
24143+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24144+ return 2;
24145+ }
24146+ } while (0);
24147+
24148+ return 1; /* PaX in action */
24149+}
24150+
24151+#ifdef CONFIG_X86_64
24152+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24153+{
24154+ int err;
24155+
24156+ do { /* PaX: libffi trampoline emulation */
24157+ unsigned short mov1, mov2, jmp1;
24158+ unsigned char stcclc, jmp2;
24159+ unsigned long addr1, addr2;
24160+
24161+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24162+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24163+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24164+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24165+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24166+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24167+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24168+
24169+ if (err)
24170+ break;
24171+
24172+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24173+ regs->r11 = addr1;
24174+ regs->r10 = addr2;
24175+ if (stcclc == 0xF8)
24176+ regs->flags &= ~X86_EFLAGS_CF;
24177+ else
24178+ regs->flags |= X86_EFLAGS_CF;
24179+ regs->ip = addr1;
24180+ return 2;
24181+ }
24182+ } while (0);
24183+
24184+ do { /* PaX: gcc trampoline emulation #1 */
24185+ unsigned short mov1, mov2, jmp1;
24186+ unsigned char jmp2;
24187+ unsigned int addr1;
24188+ unsigned long addr2;
24189+
24190+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24191+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24192+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24193+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24194+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24195+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24196+
24197+ if (err)
24198+ break;
24199+
24200+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24201+ regs->r11 = addr1;
24202+ regs->r10 = addr2;
24203+ regs->ip = addr1;
24204+ return 2;
24205+ }
24206+ } while (0);
24207+
24208+ do { /* PaX: gcc trampoline emulation #2 */
24209+ unsigned short mov1, mov2, jmp1;
24210+ unsigned char jmp2;
24211+ unsigned long addr1, addr2;
24212+
24213+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24214+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24215+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24216+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24217+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24218+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24219+
24220+ if (err)
24221+ break;
24222+
24223+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24224+ regs->r11 = addr1;
24225+ regs->r10 = addr2;
24226+ regs->ip = addr1;
24227+ return 2;
24228+ }
24229+ } while (0);
24230+
24231+ return 1; /* PaX in action */
24232+}
24233+#endif
24234+
24235+/*
24236+ * PaX: decide what to do with offenders (regs->ip = fault address)
24237+ *
24238+ * returns 1 when task should be killed
24239+ * 2 when gcc trampoline was detected
24240+ */
24241+static int pax_handle_fetch_fault(struct pt_regs *regs)
24242+{
24243+ if (v8086_mode(regs))
24244+ return 1;
24245+
24246+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24247+ return 1;
24248+
24249+#ifdef CONFIG_X86_32
24250+ return pax_handle_fetch_fault_32(regs);
24251+#else
24252+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24253+ return pax_handle_fetch_fault_32(regs);
24254+ else
24255+ return pax_handle_fetch_fault_64(regs);
24256+#endif
24257+}
24258+#endif
24259+
24260+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24261+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24262+{
24263+ long i;
24264+
24265+ printk(KERN_ERR "PAX: bytes at PC: ");
24266+ for (i = 0; i < 20; i++) {
24267+ unsigned char c;
24268+ if (get_user(c, (unsigned char __force_user *)pc+i))
24269+ printk(KERN_CONT "?? ");
24270+ else
24271+ printk(KERN_CONT "%02x ", c);
24272+ }
24273+ printk("\n");
24274+
24275+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24276+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
24277+ unsigned long c;
24278+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
24279+#ifdef CONFIG_X86_32
24280+ printk(KERN_CONT "???????? ");
24281+#else
24282+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24283+ printk(KERN_CONT "???????? ???????? ");
24284+ else
24285+ printk(KERN_CONT "???????????????? ");
24286+#endif
24287+ } else {
24288+#ifdef CONFIG_X86_64
24289+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24290+ printk(KERN_CONT "%08x ", (unsigned int)c);
24291+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24292+ } else
24293+#endif
24294+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24295+ }
24296+ }
24297+ printk("\n");
24298+}
24299+#endif
24300+
24301+/**
24302+ * probe_kernel_write(): safely attempt to write to a location
24303+ * @dst: address to write to
24304+ * @src: pointer to the data that shall be written
24305+ * @size: size of the data chunk
24306+ *
24307+ * Safely write to address @dst from the buffer at @src. If a kernel fault
24308+ * happens, handle that and return -EFAULT.
24309+ */
24310+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24311+{
24312+ long ret;
24313+ mm_segment_t old_fs = get_fs();
24314+
24315+ set_fs(KERNEL_DS);
24316+ pagefault_disable();
24317+ pax_open_kernel();
24318+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24319+ pax_close_kernel();
24320+ pagefault_enable();
24321+ set_fs(old_fs);
24322+
24323+ return ret ? -EFAULT : 0;
24324+}
24325diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24326index dd74e46..7d26398 100644
24327--- a/arch/x86/mm/gup.c
24328+++ b/arch/x86/mm/gup.c
24329@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24330 addr = start;
24331 len = (unsigned long) nr_pages << PAGE_SHIFT;
24332 end = start + len;
24333- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24334+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24335 (void __user *)start, len)))
24336 return 0;
24337
24338diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24339index 6f31ee5..8ee4164 100644
24340--- a/arch/x86/mm/highmem_32.c
24341+++ b/arch/x86/mm/highmem_32.c
24342@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24343 idx = type + KM_TYPE_NR*smp_processor_id();
24344 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24345 BUG_ON(!pte_none(*(kmap_pte-idx)));
24346+
24347+ pax_open_kernel();
24348 set_pte(kmap_pte-idx, mk_pte(page, prot));
24349+ pax_close_kernel();
24350+
24351 arch_flush_lazy_mmu_mode();
24352
24353 return (void *)vaddr;
24354diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24355index f6679a7..8f795a3 100644
24356--- a/arch/x86/mm/hugetlbpage.c
24357+++ b/arch/x86/mm/hugetlbpage.c
24358@@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24359 struct hstate *h = hstate_file(file);
24360 struct mm_struct *mm = current->mm;
24361 struct vm_area_struct *vma;
24362- unsigned long start_addr;
24363+ unsigned long start_addr, pax_task_size = TASK_SIZE;
24364+
24365+#ifdef CONFIG_PAX_SEGMEXEC
24366+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24367+ pax_task_size = SEGMEXEC_TASK_SIZE;
24368+#endif
24369+
24370+ pax_task_size -= PAGE_SIZE;
24371
24372 if (len > mm->cached_hole_size) {
24373- start_addr = mm->free_area_cache;
24374+ start_addr = mm->free_area_cache;
24375 } else {
24376- start_addr = TASK_UNMAPPED_BASE;
24377- mm->cached_hole_size = 0;
24378+ start_addr = mm->mmap_base;
24379+ mm->cached_hole_size = 0;
24380 }
24381
24382 full_search:
24383@@ -280,26 +287,27 @@ full_search:
24384
24385 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24386 /* At this point: (!vma || addr < vma->vm_end). */
24387- if (TASK_SIZE - len < addr) {
24388+ if (pax_task_size - len < addr) {
24389 /*
24390 * Start a new search - just in case we missed
24391 * some holes.
24392 */
24393- if (start_addr != TASK_UNMAPPED_BASE) {
24394- start_addr = TASK_UNMAPPED_BASE;
24395+ if (start_addr != mm->mmap_base) {
24396+ start_addr = mm->mmap_base;
24397 mm->cached_hole_size = 0;
24398 goto full_search;
24399 }
24400 return -ENOMEM;
24401 }
24402- if (!vma || addr + len <= vma->vm_start) {
24403- mm->free_area_cache = addr + len;
24404- return addr;
24405- }
24406+ if (check_heap_stack_gap(vma, addr, len))
24407+ break;
24408 if (addr + mm->cached_hole_size < vma->vm_start)
24409 mm->cached_hole_size = vma->vm_start - addr;
24410 addr = ALIGN(vma->vm_end, huge_page_size(h));
24411 }
24412+
24413+ mm->free_area_cache = addr + len;
24414+ return addr;
24415 }
24416
24417 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24418@@ -310,9 +318,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24419 struct mm_struct *mm = current->mm;
24420 struct vm_area_struct *vma;
24421 unsigned long base = mm->mmap_base;
24422- unsigned long addr = addr0;
24423+ unsigned long addr;
24424 unsigned long largest_hole = mm->cached_hole_size;
24425- unsigned long start_addr;
24426
24427 /* don't allow allocations above current base */
24428 if (mm->free_area_cache > base)
24429@@ -322,16 +329,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24430 largest_hole = 0;
24431 mm->free_area_cache = base;
24432 }
24433-try_again:
24434- start_addr = mm->free_area_cache;
24435
24436 /* make sure it can fit in the remaining address space */
24437 if (mm->free_area_cache < len)
24438 goto fail;
24439
24440 /* either no address requested or can't fit in requested address hole */
24441- addr = (mm->free_area_cache - len) & huge_page_mask(h);
24442+ addr = mm->free_area_cache - len;
24443 do {
24444+ addr &= huge_page_mask(h);
24445 /*
24446 * Lookup failure means no vma is above this address,
24447 * i.e. return with success:
24448@@ -340,10 +346,10 @@ try_again:
24449 if (!vma)
24450 return addr;
24451
24452- if (addr + len <= vma->vm_start) {
24453+ if (check_heap_stack_gap(vma, addr, len)) {
24454 /* remember the address as a hint for next time */
24455- mm->cached_hole_size = largest_hole;
24456- return (mm->free_area_cache = addr);
24457+ mm->cached_hole_size = largest_hole;
24458+ return (mm->free_area_cache = addr);
24459 } else if (mm->free_area_cache == vma->vm_end) {
24460 /* pull free_area_cache down to the first hole */
24461 mm->free_area_cache = vma->vm_start;
24462@@ -352,29 +358,34 @@ try_again:
24463
24464 /* remember the largest hole we saw so far */
24465 if (addr + largest_hole < vma->vm_start)
24466- largest_hole = vma->vm_start - addr;
24467+ largest_hole = vma->vm_start - addr;
24468
24469 /* try just below the current vma->vm_start */
24470- addr = (vma->vm_start - len) & huge_page_mask(h);
24471- } while (len <= vma->vm_start);
24472+ addr = skip_heap_stack_gap(vma, len);
24473+ } while (!IS_ERR_VALUE(addr));
24474
24475 fail:
24476 /*
24477- * if hint left us with no space for the requested
24478- * mapping then try again:
24479- */
24480- if (start_addr != base) {
24481- mm->free_area_cache = base;
24482- largest_hole = 0;
24483- goto try_again;
24484- }
24485- /*
24486 * A failed mmap() very likely causes application failure,
24487 * so fall back to the bottom-up function here. This scenario
24488 * can happen with large stack limits and large mmap()
24489 * allocations.
24490 */
24491- mm->free_area_cache = TASK_UNMAPPED_BASE;
24492+
24493+#ifdef CONFIG_PAX_SEGMEXEC
24494+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24495+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24496+ else
24497+#endif
24498+
24499+ mm->mmap_base = TASK_UNMAPPED_BASE;
24500+
24501+#ifdef CONFIG_PAX_RANDMMAP
24502+ if (mm->pax_flags & MF_PAX_RANDMMAP)
24503+ mm->mmap_base += mm->delta_mmap;
24504+#endif
24505+
24506+ mm->free_area_cache = mm->mmap_base;
24507 mm->cached_hole_size = ~0UL;
24508 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24509 len, pgoff, flags);
24510@@ -382,6 +393,7 @@ fail:
24511 /*
24512 * Restore the topdown base:
24513 */
24514+ mm->mmap_base = base;
24515 mm->free_area_cache = base;
24516 mm->cached_hole_size = ~0UL;
24517
24518@@ -395,10 +407,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24519 struct hstate *h = hstate_file(file);
24520 struct mm_struct *mm = current->mm;
24521 struct vm_area_struct *vma;
24522+ unsigned long pax_task_size = TASK_SIZE;
24523
24524 if (len & ~huge_page_mask(h))
24525 return -EINVAL;
24526- if (len > TASK_SIZE)
24527+
24528+#ifdef CONFIG_PAX_SEGMEXEC
24529+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24530+ pax_task_size = SEGMEXEC_TASK_SIZE;
24531+#endif
24532+
24533+ pax_task_size -= PAGE_SIZE;
24534+
24535+ if (len > pax_task_size)
24536 return -ENOMEM;
24537
24538 if (flags & MAP_FIXED) {
24539@@ -410,8 +431,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24540 if (addr) {
24541 addr = ALIGN(addr, huge_page_size(h));
24542 vma = find_vma(mm, addr);
24543- if (TASK_SIZE - len >= addr &&
24544- (!vma || addr + len <= vma->vm_start))
24545+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24546 return addr;
24547 }
24548 if (mm->get_unmapped_area == arch_get_unmapped_area)
24549diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24550index 4f0cec7..00976ce 100644
24551--- a/arch/x86/mm/init.c
24552+++ b/arch/x86/mm/init.c
24553@@ -16,6 +16,8 @@
24554 #include <asm/tlb.h>
24555 #include <asm/proto.h>
24556 #include <asm/dma.h> /* for MAX_DMA_PFN */
24557+#include <asm/desc.h>
24558+#include <asm/bios_ebda.h>
24559
24560 unsigned long __initdata pgt_buf_start;
24561 unsigned long __meminitdata pgt_buf_end;
24562@@ -32,7 +34,7 @@ int direct_gbpages
24563 static void __init find_early_table_space(unsigned long end, int use_pse,
24564 int use_gbpages)
24565 {
24566- unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24567+ unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24568 phys_addr_t base;
24569
24570 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24571@@ -311,10 +313,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24572 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24573 * mmio resources as well as potential bios/acpi data regions.
24574 */
24575+
24576+#ifdef CONFIG_GRKERNSEC_KMEM
24577+static unsigned int ebda_start __read_only;
24578+static unsigned int ebda_end __read_only;
24579+#endif
24580+
24581 int devmem_is_allowed(unsigned long pagenr)
24582 {
24583+#ifdef CONFIG_GRKERNSEC_KMEM
24584+ /* allow BDA */
24585+ if (!pagenr)
24586+ return 1;
24587+ /* allow EBDA */
24588+ if (pagenr >= ebda_start && pagenr < ebda_end)
24589+ return 1;
24590+#else
24591+ if (!pagenr)
24592+ return 1;
24593+#ifdef CONFIG_VM86
24594+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24595+ return 1;
24596+#endif
24597+#endif
24598+
24599+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24600+ return 1;
24601+#ifdef CONFIG_GRKERNSEC_KMEM
24602+ /* throw out everything else below 1MB */
24603 if (pagenr <= 256)
24604- return 1;
24605+ return 0;
24606+#endif
24607 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24608 return 0;
24609 if (!page_is_ram(pagenr))
24610@@ -371,8 +400,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24611 #endif
24612 }
24613
24614+#ifdef CONFIG_GRKERNSEC_KMEM
24615+static inline void gr_init_ebda(void)
24616+{
24617+ unsigned int ebda_addr;
24618+ unsigned int ebda_size = 0;
24619+
24620+ ebda_addr = get_bios_ebda();
24621+ if (ebda_addr) {
24622+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24623+ ebda_size <<= 10;
24624+ }
24625+ if (ebda_addr && ebda_size) {
24626+ ebda_start = ebda_addr >> PAGE_SHIFT;
24627+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24628+ } else {
24629+ ebda_start = 0x9f000 >> PAGE_SHIFT;
24630+ ebda_end = 0xa0000 >> PAGE_SHIFT;
24631+ }
24632+}
24633+#else
24634+static inline void gr_init_ebda(void) { }
24635+#endif
24636+
24637 void free_initmem(void)
24638 {
24639+#ifdef CONFIG_PAX_KERNEXEC
24640+#ifdef CONFIG_X86_32
24641+ /* PaX: limit KERNEL_CS to actual size */
24642+ unsigned long addr, limit;
24643+ struct desc_struct d;
24644+ int cpu;
24645+#else
24646+ pgd_t *pgd;
24647+ pud_t *pud;
24648+ pmd_t *pmd;
24649+ unsigned long addr, end;
24650+#endif
24651+#endif
24652+
24653+ gr_init_ebda();
24654+
24655+#ifdef CONFIG_PAX_KERNEXEC
24656+#ifdef CONFIG_X86_32
24657+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24658+ limit = (limit - 1UL) >> PAGE_SHIFT;
24659+
24660+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24661+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24662+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24663+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24664+ }
24665+
24666+ /* PaX: make KERNEL_CS read-only */
24667+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24668+ if (!paravirt_enabled())
24669+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24670+/*
24671+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24672+ pgd = pgd_offset_k(addr);
24673+ pud = pud_offset(pgd, addr);
24674+ pmd = pmd_offset(pud, addr);
24675+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24676+ }
24677+*/
24678+#ifdef CONFIG_X86_PAE
24679+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24680+/*
24681+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24682+ pgd = pgd_offset_k(addr);
24683+ pud = pud_offset(pgd, addr);
24684+ pmd = pmd_offset(pud, addr);
24685+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24686+ }
24687+*/
24688+#endif
24689+
24690+#ifdef CONFIG_MODULES
24691+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24692+#endif
24693+
24694+#else
24695+ /* PaX: make kernel code/rodata read-only, rest non-executable */
24696+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24697+ pgd = pgd_offset_k(addr);
24698+ pud = pud_offset(pgd, addr);
24699+ pmd = pmd_offset(pud, addr);
24700+ if (!pmd_present(*pmd))
24701+ continue;
24702+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24703+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24704+ else
24705+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24706+ }
24707+
24708+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24709+ end = addr + KERNEL_IMAGE_SIZE;
24710+ for (; addr < end; addr += PMD_SIZE) {
24711+ pgd = pgd_offset_k(addr);
24712+ pud = pud_offset(pgd, addr);
24713+ pmd = pmd_offset(pud, addr);
24714+ if (!pmd_present(*pmd))
24715+ continue;
24716+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24717+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24718+ }
24719+#endif
24720+
24721+ flush_tlb_all();
24722+#endif
24723+
24724 free_init_pages("unused kernel memory",
24725 (unsigned long)(&__init_begin),
24726 (unsigned long)(&__init_end));
24727diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24728index 575d86f..4987469 100644
24729--- a/arch/x86/mm/init_32.c
24730+++ b/arch/x86/mm/init_32.c
24731@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24732 }
24733
24734 /*
24735- * Creates a middle page table and puts a pointer to it in the
24736- * given global directory entry. This only returns the gd entry
24737- * in non-PAE compilation mode, since the middle layer is folded.
24738- */
24739-static pmd_t * __init one_md_table_init(pgd_t *pgd)
24740-{
24741- pud_t *pud;
24742- pmd_t *pmd_table;
24743-
24744-#ifdef CONFIG_X86_PAE
24745- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24746- if (after_bootmem)
24747- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24748- else
24749- pmd_table = (pmd_t *)alloc_low_page();
24750- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24751- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24752- pud = pud_offset(pgd, 0);
24753- BUG_ON(pmd_table != pmd_offset(pud, 0));
24754-
24755- return pmd_table;
24756- }
24757-#endif
24758- pud = pud_offset(pgd, 0);
24759- pmd_table = pmd_offset(pud, 0);
24760-
24761- return pmd_table;
24762-}
24763-
24764-/*
24765 * Create a page table and place a pointer to it in a middle page
24766 * directory entry:
24767 */
24768@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24769 page_table = (pte_t *)alloc_low_page();
24770
24771 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24772+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24773+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24774+#else
24775 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24776+#endif
24777 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24778 }
24779
24780 return pte_offset_kernel(pmd, 0);
24781 }
24782
24783+static pmd_t * __init one_md_table_init(pgd_t *pgd)
24784+{
24785+ pud_t *pud;
24786+ pmd_t *pmd_table;
24787+
24788+ pud = pud_offset(pgd, 0);
24789+ pmd_table = pmd_offset(pud, 0);
24790+
24791+ return pmd_table;
24792+}
24793+
24794 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24795 {
24796 int pgd_idx = pgd_index(vaddr);
24797@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24798 int pgd_idx, pmd_idx;
24799 unsigned long vaddr;
24800 pgd_t *pgd;
24801+ pud_t *pud;
24802 pmd_t *pmd;
24803 pte_t *pte = NULL;
24804
24805@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24806 pgd = pgd_base + pgd_idx;
24807
24808 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24809- pmd = one_md_table_init(pgd);
24810- pmd = pmd + pmd_index(vaddr);
24811+ pud = pud_offset(pgd, vaddr);
24812+ pmd = pmd_offset(pud, vaddr);
24813+
24814+#ifdef CONFIG_X86_PAE
24815+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24816+#endif
24817+
24818 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24819 pmd++, pmd_idx++) {
24820 pte = page_table_kmap_check(one_page_table_init(pmd),
24821@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24822 }
24823 }
24824
24825-static inline int is_kernel_text(unsigned long addr)
24826+static inline int is_kernel_text(unsigned long start, unsigned long end)
24827 {
24828- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24829- return 1;
24830- return 0;
24831+ if ((start > ktla_ktva((unsigned long)_etext) ||
24832+ end <= ktla_ktva((unsigned long)_stext)) &&
24833+ (start > ktla_ktva((unsigned long)_einittext) ||
24834+ end <= ktla_ktva((unsigned long)_sinittext)) &&
24835+
24836+#ifdef CONFIG_ACPI_SLEEP
24837+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24838+#endif
24839+
24840+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24841+ return 0;
24842+ return 1;
24843 }
24844
24845 /*
24846@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24847 unsigned long last_map_addr = end;
24848 unsigned long start_pfn, end_pfn;
24849 pgd_t *pgd_base = swapper_pg_dir;
24850- int pgd_idx, pmd_idx, pte_ofs;
24851+ unsigned int pgd_idx, pmd_idx, pte_ofs;
24852 unsigned long pfn;
24853 pgd_t *pgd;
24854+ pud_t *pud;
24855 pmd_t *pmd;
24856 pte_t *pte;
24857 unsigned pages_2m, pages_4k;
24858@@ -280,8 +281,13 @@ repeat:
24859 pfn = start_pfn;
24860 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24861 pgd = pgd_base + pgd_idx;
24862- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24863- pmd = one_md_table_init(pgd);
24864+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24865+ pud = pud_offset(pgd, 0);
24866+ pmd = pmd_offset(pud, 0);
24867+
24868+#ifdef CONFIG_X86_PAE
24869+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24870+#endif
24871
24872 if (pfn >= end_pfn)
24873 continue;
24874@@ -293,14 +299,13 @@ repeat:
24875 #endif
24876 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24877 pmd++, pmd_idx++) {
24878- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24879+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24880
24881 /*
24882 * Map with big pages if possible, otherwise
24883 * create normal page tables:
24884 */
24885 if (use_pse) {
24886- unsigned int addr2;
24887 pgprot_t prot = PAGE_KERNEL_LARGE;
24888 /*
24889 * first pass will use the same initial
24890@@ -310,11 +315,7 @@ repeat:
24891 __pgprot(PTE_IDENT_ATTR |
24892 _PAGE_PSE);
24893
24894- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24895- PAGE_OFFSET + PAGE_SIZE-1;
24896-
24897- if (is_kernel_text(addr) ||
24898- is_kernel_text(addr2))
24899+ if (is_kernel_text(address, address + PMD_SIZE))
24900 prot = PAGE_KERNEL_LARGE_EXEC;
24901
24902 pages_2m++;
24903@@ -331,7 +332,7 @@ repeat:
24904 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24905 pte += pte_ofs;
24906 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24907- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24908+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24909 pgprot_t prot = PAGE_KERNEL;
24910 /*
24911 * first pass will use the same initial
24912@@ -339,7 +340,7 @@ repeat:
24913 */
24914 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24915
24916- if (is_kernel_text(addr))
24917+ if (is_kernel_text(address, address + PAGE_SIZE))
24918 prot = PAGE_KERNEL_EXEC;
24919
24920 pages_4k++;
24921@@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24922
24923 pud = pud_offset(pgd, va);
24924 pmd = pmd_offset(pud, va);
24925- if (!pmd_present(*pmd))
24926+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
24927 break;
24928
24929 pte = pte_offset_kernel(pmd, va);
24930@@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24931
24932 static void __init pagetable_init(void)
24933 {
24934- pgd_t *pgd_base = swapper_pg_dir;
24935-
24936- permanent_kmaps_init(pgd_base);
24937+ permanent_kmaps_init(swapper_pg_dir);
24938 }
24939
24940-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24941+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24942 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24943
24944 /* user-defined highmem size */
24945@@ -734,6 +733,12 @@ void __init mem_init(void)
24946
24947 pci_iommu_alloc();
24948
24949+#ifdef CONFIG_PAX_PER_CPU_PGD
24950+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24951+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24952+ KERNEL_PGD_PTRS);
24953+#endif
24954+
24955 #ifdef CONFIG_FLATMEM
24956 BUG_ON(!mem_map);
24957 #endif
24958@@ -760,7 +765,7 @@ void __init mem_init(void)
24959 reservedpages++;
24960
24961 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24962- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24963+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24964 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24965
24966 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24967@@ -801,10 +806,10 @@ void __init mem_init(void)
24968 ((unsigned long)&__init_end -
24969 (unsigned long)&__init_begin) >> 10,
24970
24971- (unsigned long)&_etext, (unsigned long)&_edata,
24972- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24973+ (unsigned long)&_sdata, (unsigned long)&_edata,
24974+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24975
24976- (unsigned long)&_text, (unsigned long)&_etext,
24977+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24978 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24979
24980 /*
24981@@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
24982 if (!kernel_set_to_readonly)
24983 return;
24984
24985+ start = ktla_ktva(start);
24986 pr_debug("Set kernel text: %lx - %lx for read write\n",
24987 start, start+size);
24988
24989@@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
24990 if (!kernel_set_to_readonly)
24991 return;
24992
24993+ start = ktla_ktva(start);
24994 pr_debug("Set kernel text: %lx - %lx for read only\n",
24995 start, start+size);
24996
24997@@ -924,6 +931,7 @@ void mark_rodata_ro(void)
24998 unsigned long start = PFN_ALIGN(_text);
24999 unsigned long size = PFN_ALIGN(_etext) - start;
25000
25001+ start = ktla_ktva(start);
25002 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25003 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25004 size >> 10);
25005diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25006index fc18be0..e539653 100644
25007--- a/arch/x86/mm/init_64.c
25008+++ b/arch/x86/mm/init_64.c
25009@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25010 * around without checking the pgd every time.
25011 */
25012
25013-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25014+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25015 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25016
25017 int force_personality32;
25018@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25019
25020 for (address = start; address <= end; address += PGDIR_SIZE) {
25021 const pgd_t *pgd_ref = pgd_offset_k(address);
25022+
25023+#ifdef CONFIG_PAX_PER_CPU_PGD
25024+ unsigned long cpu;
25025+#else
25026 struct page *page;
25027+#endif
25028
25029 if (pgd_none(*pgd_ref))
25030 continue;
25031
25032 spin_lock(&pgd_lock);
25033+
25034+#ifdef CONFIG_PAX_PER_CPU_PGD
25035+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25036+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
25037+#else
25038 list_for_each_entry(page, &pgd_list, lru) {
25039 pgd_t *pgd;
25040 spinlock_t *pgt_lock;
25041@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25042 /* the pgt_lock only for Xen */
25043 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25044 spin_lock(pgt_lock);
25045+#endif
25046
25047 if (pgd_none(*pgd))
25048 set_pgd(pgd, *pgd_ref);
25049@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25050 BUG_ON(pgd_page_vaddr(*pgd)
25051 != pgd_page_vaddr(*pgd_ref));
25052
25053+#ifndef CONFIG_PAX_PER_CPU_PGD
25054 spin_unlock(pgt_lock);
25055+#endif
25056+
25057 }
25058 spin_unlock(&pgd_lock);
25059 }
25060@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25061 {
25062 if (pgd_none(*pgd)) {
25063 pud_t *pud = (pud_t *)spp_getpage();
25064- pgd_populate(&init_mm, pgd, pud);
25065+ pgd_populate_kernel(&init_mm, pgd, pud);
25066 if (pud != pud_offset(pgd, 0))
25067 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25068 pud, pud_offset(pgd, 0));
25069@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25070 {
25071 if (pud_none(*pud)) {
25072 pmd_t *pmd = (pmd_t *) spp_getpage();
25073- pud_populate(&init_mm, pud, pmd);
25074+ pud_populate_kernel(&init_mm, pud, pmd);
25075 if (pmd != pmd_offset(pud, 0))
25076 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25077 pmd, pmd_offset(pud, 0));
25078@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25079 pmd = fill_pmd(pud, vaddr);
25080 pte = fill_pte(pmd, vaddr);
25081
25082+ pax_open_kernel();
25083 set_pte(pte, new_pte);
25084+ pax_close_kernel();
25085
25086 /*
25087 * It's enough to flush this one mapping.
25088@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25089 pgd = pgd_offset_k((unsigned long)__va(phys));
25090 if (pgd_none(*pgd)) {
25091 pud = (pud_t *) spp_getpage();
25092- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25093- _PAGE_USER));
25094+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25095 }
25096 pud = pud_offset(pgd, (unsigned long)__va(phys));
25097 if (pud_none(*pud)) {
25098 pmd = (pmd_t *) spp_getpage();
25099- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25100- _PAGE_USER));
25101+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25102 }
25103 pmd = pmd_offset(pud, phys);
25104 BUG_ON(!pmd_none(*pmd));
25105@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25106 if (pfn >= pgt_buf_top)
25107 panic("alloc_low_page: ran out of memory");
25108
25109- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25110+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25111 clear_page(adr);
25112 *phys = pfn * PAGE_SIZE;
25113 return adr;
25114@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25115
25116 phys = __pa(virt);
25117 left = phys & (PAGE_SIZE - 1);
25118- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25119+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25120 adr = (void *)(((unsigned long)adr) | left);
25121
25122 return adr;
25123@@ -545,7 +559,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25124 unmap_low_page(pmd);
25125
25126 spin_lock(&init_mm.page_table_lock);
25127- pud_populate(&init_mm, pud, __va(pmd_phys));
25128+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25129 spin_unlock(&init_mm.page_table_lock);
25130 }
25131 __flush_tlb_all();
25132@@ -591,7 +605,7 @@ kernel_physical_mapping_init(unsigned long start,
25133 unmap_low_page(pud);
25134
25135 spin_lock(&init_mm.page_table_lock);
25136- pgd_populate(&init_mm, pgd, __va(pud_phys));
25137+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25138 spin_unlock(&init_mm.page_table_lock);
25139 pgd_changed = true;
25140 }
25141@@ -683,6 +697,12 @@ void __init mem_init(void)
25142
25143 pci_iommu_alloc();
25144
25145+#ifdef CONFIG_PAX_PER_CPU_PGD
25146+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25147+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25148+ KERNEL_PGD_PTRS);
25149+#endif
25150+
25151 /* clear_bss() already clear the empty_zero_page */
25152
25153 reservedpages = 0;
25154@@ -843,8 +863,8 @@ int kern_addr_valid(unsigned long addr)
25155 static struct vm_area_struct gate_vma = {
25156 .vm_start = VSYSCALL_START,
25157 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25158- .vm_page_prot = PAGE_READONLY_EXEC,
25159- .vm_flags = VM_READ | VM_EXEC
25160+ .vm_page_prot = PAGE_READONLY,
25161+ .vm_flags = VM_READ
25162 };
25163
25164 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25165@@ -878,7 +898,7 @@ int in_gate_area_no_mm(unsigned long addr)
25166
25167 const char *arch_vma_name(struct vm_area_struct *vma)
25168 {
25169- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25170+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25171 return "[vdso]";
25172 if (vma == &gate_vma)
25173 return "[vsyscall]";
25174diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25175index 7b179b4..6bd1777 100644
25176--- a/arch/x86/mm/iomap_32.c
25177+++ b/arch/x86/mm/iomap_32.c
25178@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25179 type = kmap_atomic_idx_push();
25180 idx = type + KM_TYPE_NR * smp_processor_id();
25181 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25182+
25183+ pax_open_kernel();
25184 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25185+ pax_close_kernel();
25186+
25187 arch_flush_lazy_mmu_mode();
25188
25189 return (void *)vaddr;
25190diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25191index be1ef57..55f0160 100644
25192--- a/arch/x86/mm/ioremap.c
25193+++ b/arch/x86/mm/ioremap.c
25194@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25195 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25196 int is_ram = page_is_ram(pfn);
25197
25198- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25199+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25200 return NULL;
25201 WARN_ON_ONCE(is_ram);
25202 }
25203@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25204
25205 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25206 if (page_is_ram(start >> PAGE_SHIFT))
25207+#ifdef CONFIG_HIGHMEM
25208+ if ((start >> PAGE_SHIFT) < max_low_pfn)
25209+#endif
25210 return __va(phys);
25211
25212 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25213@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25214 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25215
25216 static __initdata int after_paging_init;
25217-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25218+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25219
25220 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25221 {
25222@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25223 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25224
25225 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25226- memset(bm_pte, 0, sizeof(bm_pte));
25227- pmd_populate_kernel(&init_mm, pmd, bm_pte);
25228+ pmd_populate_user(&init_mm, pmd, bm_pte);
25229
25230 /*
25231 * The boot-ioremap range spans multiple pmds, for which
25232diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25233index d87dd6d..bf3fa66 100644
25234--- a/arch/x86/mm/kmemcheck/kmemcheck.c
25235+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25236@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25237 * memory (e.g. tracked pages)? For now, we need this to avoid
25238 * invoking kmemcheck for PnP BIOS calls.
25239 */
25240- if (regs->flags & X86_VM_MASK)
25241+ if (v8086_mode(regs))
25242 return false;
25243- if (regs->cs != __KERNEL_CS)
25244+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25245 return false;
25246
25247 pte = kmemcheck_pte_lookup(address);
25248diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25249index 845df68..1d8d29f 100644
25250--- a/arch/x86/mm/mmap.c
25251+++ b/arch/x86/mm/mmap.c
25252@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25253 * Leave an at least ~128 MB hole with possible stack randomization.
25254 */
25255 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25256-#define MAX_GAP (TASK_SIZE/6*5)
25257+#define MAX_GAP (pax_task_size/6*5)
25258
25259 static int mmap_is_legacy(void)
25260 {
25261@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25262 return rnd << PAGE_SHIFT;
25263 }
25264
25265-static unsigned long mmap_base(void)
25266+static unsigned long mmap_base(struct mm_struct *mm)
25267 {
25268 unsigned long gap = rlimit(RLIMIT_STACK);
25269+ unsigned long pax_task_size = TASK_SIZE;
25270+
25271+#ifdef CONFIG_PAX_SEGMEXEC
25272+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25273+ pax_task_size = SEGMEXEC_TASK_SIZE;
25274+#endif
25275
25276 if (gap < MIN_GAP)
25277 gap = MIN_GAP;
25278 else if (gap > MAX_GAP)
25279 gap = MAX_GAP;
25280
25281- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25282+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25283 }
25284
25285 /*
25286 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25287 * does, but not when emulating X86_32
25288 */
25289-static unsigned long mmap_legacy_base(void)
25290+static unsigned long mmap_legacy_base(struct mm_struct *mm)
25291 {
25292- if (mmap_is_ia32())
25293+ if (mmap_is_ia32()) {
25294+
25295+#ifdef CONFIG_PAX_SEGMEXEC
25296+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25297+ return SEGMEXEC_TASK_UNMAPPED_BASE;
25298+ else
25299+#endif
25300+
25301 return TASK_UNMAPPED_BASE;
25302- else
25303+ } else
25304 return TASK_UNMAPPED_BASE + mmap_rnd();
25305 }
25306
25307@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25308 void arch_pick_mmap_layout(struct mm_struct *mm)
25309 {
25310 if (mmap_is_legacy()) {
25311- mm->mmap_base = mmap_legacy_base();
25312+ mm->mmap_base = mmap_legacy_base(mm);
25313+
25314+#ifdef CONFIG_PAX_RANDMMAP
25315+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25316+ mm->mmap_base += mm->delta_mmap;
25317+#endif
25318+
25319 mm->get_unmapped_area = arch_get_unmapped_area;
25320 mm->unmap_area = arch_unmap_area;
25321 } else {
25322- mm->mmap_base = mmap_base();
25323+ mm->mmap_base = mmap_base(mm);
25324+
25325+#ifdef CONFIG_PAX_RANDMMAP
25326+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25327+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25328+#endif
25329+
25330 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25331 mm->unmap_area = arch_unmap_area_topdown;
25332 }
25333diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25334index dc0b727..dc9d71a 100644
25335--- a/arch/x86/mm/mmio-mod.c
25336+++ b/arch/x86/mm/mmio-mod.c
25337@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25338 break;
25339 default:
25340 {
25341- unsigned char *ip = (unsigned char *)instptr;
25342+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25343 my_trace->opcode = MMIO_UNKNOWN_OP;
25344 my_trace->width = 0;
25345 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25346@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25347 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25348 void __iomem *addr)
25349 {
25350- static atomic_t next_id;
25351+ static atomic_unchecked_t next_id;
25352 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25353 /* These are page-unaligned. */
25354 struct mmiotrace_map map = {
25355@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25356 .private = trace
25357 },
25358 .phys = offset,
25359- .id = atomic_inc_return(&next_id)
25360+ .id = atomic_inc_return_unchecked(&next_id)
25361 };
25362 map.map_id = trace->id;
25363
25364diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25365index b008656..773eac2 100644
25366--- a/arch/x86/mm/pageattr-test.c
25367+++ b/arch/x86/mm/pageattr-test.c
25368@@ -36,7 +36,7 @@ enum {
25369
25370 static int pte_testbit(pte_t pte)
25371 {
25372- return pte_flags(pte) & _PAGE_UNUSED1;
25373+ return pte_flags(pte) & _PAGE_CPA_TEST;
25374 }
25375
25376 struct split_state {
25377diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25378index e1ebde3..b1e1db38 100644
25379--- a/arch/x86/mm/pageattr.c
25380+++ b/arch/x86/mm/pageattr.c
25381@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25382 */
25383 #ifdef CONFIG_PCI_BIOS
25384 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25385- pgprot_val(forbidden) |= _PAGE_NX;
25386+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25387 #endif
25388
25389 /*
25390@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25391 * Does not cover __inittext since that is gone later on. On
25392 * 64bit we do not enforce !NX on the low mapping
25393 */
25394- if (within(address, (unsigned long)_text, (unsigned long)_etext))
25395- pgprot_val(forbidden) |= _PAGE_NX;
25396+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25397+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25398
25399+#ifdef CONFIG_DEBUG_RODATA
25400 /*
25401 * The .rodata section needs to be read-only. Using the pfn
25402 * catches all aliases.
25403@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25404 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25405 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25406 pgprot_val(forbidden) |= _PAGE_RW;
25407+#endif
25408
25409 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25410 /*
25411@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25412 }
25413 #endif
25414
25415+#ifdef CONFIG_PAX_KERNEXEC
25416+ if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25417+ pgprot_val(forbidden) |= _PAGE_RW;
25418+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25419+ }
25420+#endif
25421+
25422 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25423
25424 return prot;
25425@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25426 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25427 {
25428 /* change init_mm */
25429+ pax_open_kernel();
25430 set_pte_atomic(kpte, pte);
25431+
25432 #ifdef CONFIG_X86_32
25433 if (!SHARED_KERNEL_PMD) {
25434+
25435+#ifdef CONFIG_PAX_PER_CPU_PGD
25436+ unsigned long cpu;
25437+#else
25438 struct page *page;
25439+#endif
25440
25441+#ifdef CONFIG_PAX_PER_CPU_PGD
25442+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25443+ pgd_t *pgd = get_cpu_pgd(cpu);
25444+#else
25445 list_for_each_entry(page, &pgd_list, lru) {
25446- pgd_t *pgd;
25447+ pgd_t *pgd = (pgd_t *)page_address(page);
25448+#endif
25449+
25450 pud_t *pud;
25451 pmd_t *pmd;
25452
25453- pgd = (pgd_t *)page_address(page) + pgd_index(address);
25454+ pgd += pgd_index(address);
25455 pud = pud_offset(pgd, address);
25456 pmd = pmd_offset(pud, address);
25457 set_pte_atomic((pte_t *)pmd, pte);
25458 }
25459 }
25460 #endif
25461+ pax_close_kernel();
25462 }
25463
25464 static int
25465diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25466index f6ff57b..481690f 100644
25467--- a/arch/x86/mm/pat.c
25468+++ b/arch/x86/mm/pat.c
25469@@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
25470
25471 if (!entry) {
25472 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
25473- current->comm, current->pid, start, end);
25474+ current->comm, task_pid_nr(current), start, end);
25475 return -EINVAL;
25476 }
25477
25478@@ -492,8 +492,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25479 while (cursor < to) {
25480 if (!devmem_is_allowed(pfn)) {
25481 printk(KERN_INFO
25482- "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
25483- current->comm, from, to);
25484+ "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
25485+ current->comm, from, to, cursor);
25486 return 0;
25487 }
25488 cursor += PAGE_SIZE;
25489@@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25490 printk(KERN_INFO
25491 "%s:%d ioremap_change_attr failed %s "
25492 "for %Lx-%Lx\n",
25493- current->comm, current->pid,
25494+ current->comm, task_pid_nr(current),
25495 cattr_name(flags),
25496 base, (unsigned long long)(base + size));
25497 return -EINVAL;
25498@@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25499 if (want_flags != flags) {
25500 printk(KERN_WARNING
25501 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
25502- current->comm, current->pid,
25503+ current->comm, task_pid_nr(current),
25504 cattr_name(want_flags),
25505 (unsigned long long)paddr,
25506 (unsigned long long)(paddr + size),
25507@@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25508 free_memtype(paddr, paddr + size);
25509 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25510 " for %Lx-%Lx, got %s\n",
25511- current->comm, current->pid,
25512+ current->comm, task_pid_nr(current),
25513 cattr_name(want_flags),
25514 (unsigned long long)paddr,
25515 (unsigned long long)(paddr + size),
25516diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25517index 9f0614d..92ae64a 100644
25518--- a/arch/x86/mm/pf_in.c
25519+++ b/arch/x86/mm/pf_in.c
25520@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25521 int i;
25522 enum reason_type rv = OTHERS;
25523
25524- p = (unsigned char *)ins_addr;
25525+ p = (unsigned char *)ktla_ktva(ins_addr);
25526 p += skip_prefix(p, &prf);
25527 p += get_opcode(p, &opcode);
25528
25529@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25530 struct prefix_bits prf;
25531 int i;
25532
25533- p = (unsigned char *)ins_addr;
25534+ p = (unsigned char *)ktla_ktva(ins_addr);
25535 p += skip_prefix(p, &prf);
25536 p += get_opcode(p, &opcode);
25537
25538@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25539 struct prefix_bits prf;
25540 int i;
25541
25542- p = (unsigned char *)ins_addr;
25543+ p = (unsigned char *)ktla_ktva(ins_addr);
25544 p += skip_prefix(p, &prf);
25545 p += get_opcode(p, &opcode);
25546
25547@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25548 struct prefix_bits prf;
25549 int i;
25550
25551- p = (unsigned char *)ins_addr;
25552+ p = (unsigned char *)ktla_ktva(ins_addr);
25553 p += skip_prefix(p, &prf);
25554 p += get_opcode(p, &opcode);
25555 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25556@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25557 struct prefix_bits prf;
25558 int i;
25559
25560- p = (unsigned char *)ins_addr;
25561+ p = (unsigned char *)ktla_ktva(ins_addr);
25562 p += skip_prefix(p, &prf);
25563 p += get_opcode(p, &opcode);
25564 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25565diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25566index 8573b83..4f3ed7e 100644
25567--- a/arch/x86/mm/pgtable.c
25568+++ b/arch/x86/mm/pgtable.c
25569@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25570 list_del(&page->lru);
25571 }
25572
25573-#define UNSHARED_PTRS_PER_PGD \
25574- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25575+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25576+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25577
25578+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25579+{
25580+ unsigned int count = USER_PGD_PTRS;
25581
25582+ while (count--)
25583+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25584+}
25585+#endif
25586+
25587+#ifdef CONFIG_PAX_PER_CPU_PGD
25588+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25589+{
25590+ unsigned int count = USER_PGD_PTRS;
25591+
25592+ while (count--) {
25593+ pgd_t pgd;
25594+
25595+#ifdef CONFIG_X86_64
25596+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25597+#else
25598+ pgd = *src++;
25599+#endif
25600+
25601+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25602+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25603+#endif
25604+
25605+ *dst++ = pgd;
25606+ }
25607+
25608+}
25609+#endif
25610+
25611+#ifdef CONFIG_X86_64
25612+#define pxd_t pud_t
25613+#define pyd_t pgd_t
25614+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25615+#define pxd_free(mm, pud) pud_free((mm), (pud))
25616+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25617+#define pyd_offset(mm, address) pgd_offset((mm), (address))
25618+#define PYD_SIZE PGDIR_SIZE
25619+#else
25620+#define pxd_t pmd_t
25621+#define pyd_t pud_t
25622+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25623+#define pxd_free(mm, pud) pmd_free((mm), (pud))
25624+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25625+#define pyd_offset(mm, address) pud_offset((mm), (address))
25626+#define PYD_SIZE PUD_SIZE
25627+#endif
25628+
25629+#ifdef CONFIG_PAX_PER_CPU_PGD
25630+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25631+static inline void pgd_dtor(pgd_t *pgd) {}
25632+#else
25633 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25634 {
25635 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25636@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25637 pgd_list_del(pgd);
25638 spin_unlock(&pgd_lock);
25639 }
25640+#endif
25641
25642 /*
25643 * List of all pgd's needed for non-PAE so it can invalidate entries
25644@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25645 * -- wli
25646 */
25647
25648-#ifdef CONFIG_X86_PAE
25649+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25650 /*
25651 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25652 * updating the top-level pagetable entries to guarantee the
25653@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25654 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25655 * and initialize the kernel pmds here.
25656 */
25657-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25658+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25659
25660 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25661 {
25662@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25663 */
25664 flush_tlb_mm(mm);
25665 }
25666+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25667+#define PREALLOCATED_PXDS USER_PGD_PTRS
25668 #else /* !CONFIG_X86_PAE */
25669
25670 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25671-#define PREALLOCATED_PMDS 0
25672+#define PREALLOCATED_PXDS 0
25673
25674 #endif /* CONFIG_X86_PAE */
25675
25676-static void free_pmds(pmd_t *pmds[])
25677+static void free_pxds(pxd_t *pxds[])
25678 {
25679 int i;
25680
25681- for(i = 0; i < PREALLOCATED_PMDS; i++)
25682- if (pmds[i])
25683- free_page((unsigned long)pmds[i]);
25684+ for(i = 0; i < PREALLOCATED_PXDS; i++)
25685+ if (pxds[i])
25686+ free_page((unsigned long)pxds[i]);
25687 }
25688
25689-static int preallocate_pmds(pmd_t *pmds[])
25690+static int preallocate_pxds(pxd_t *pxds[])
25691 {
25692 int i;
25693 bool failed = false;
25694
25695- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25696- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25697- if (pmd == NULL)
25698+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25699+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25700+ if (pxd == NULL)
25701 failed = true;
25702- pmds[i] = pmd;
25703+ pxds[i] = pxd;
25704 }
25705
25706 if (failed) {
25707- free_pmds(pmds);
25708+ free_pxds(pxds);
25709 return -ENOMEM;
25710 }
25711
25712@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25713 * preallocate which never got a corresponding vma will need to be
25714 * freed manually.
25715 */
25716-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25717+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25718 {
25719 int i;
25720
25721- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25722+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25723 pgd_t pgd = pgdp[i];
25724
25725 if (pgd_val(pgd) != 0) {
25726- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25727+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25728
25729- pgdp[i] = native_make_pgd(0);
25730+ set_pgd(pgdp + i, native_make_pgd(0));
25731
25732- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25733- pmd_free(mm, pmd);
25734+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25735+ pxd_free(mm, pxd);
25736 }
25737 }
25738 }
25739
25740-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25741+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25742 {
25743- pud_t *pud;
25744+ pyd_t *pyd;
25745 unsigned long addr;
25746 int i;
25747
25748- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25749+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25750 return;
25751
25752- pud = pud_offset(pgd, 0);
25753+#ifdef CONFIG_X86_64
25754+ pyd = pyd_offset(mm, 0L);
25755+#else
25756+ pyd = pyd_offset(pgd, 0L);
25757+#endif
25758
25759- for (addr = i = 0; i < PREALLOCATED_PMDS;
25760- i++, pud++, addr += PUD_SIZE) {
25761- pmd_t *pmd = pmds[i];
25762+ for (addr = i = 0; i < PREALLOCATED_PXDS;
25763+ i++, pyd++, addr += PYD_SIZE) {
25764+ pxd_t *pxd = pxds[i];
25765
25766 if (i >= KERNEL_PGD_BOUNDARY)
25767- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25768- sizeof(pmd_t) * PTRS_PER_PMD);
25769+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25770+ sizeof(pxd_t) * PTRS_PER_PMD);
25771
25772- pud_populate(mm, pud, pmd);
25773+ pyd_populate(mm, pyd, pxd);
25774 }
25775 }
25776
25777 pgd_t *pgd_alloc(struct mm_struct *mm)
25778 {
25779 pgd_t *pgd;
25780- pmd_t *pmds[PREALLOCATED_PMDS];
25781+ pxd_t *pxds[PREALLOCATED_PXDS];
25782
25783 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25784
25785@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25786
25787 mm->pgd = pgd;
25788
25789- if (preallocate_pmds(pmds) != 0)
25790+ if (preallocate_pxds(pxds) != 0)
25791 goto out_free_pgd;
25792
25793 if (paravirt_pgd_alloc(mm) != 0)
25794- goto out_free_pmds;
25795+ goto out_free_pxds;
25796
25797 /*
25798 * Make sure that pre-populating the pmds is atomic with
25799@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25800 spin_lock(&pgd_lock);
25801
25802 pgd_ctor(mm, pgd);
25803- pgd_prepopulate_pmd(mm, pgd, pmds);
25804+ pgd_prepopulate_pxd(mm, pgd, pxds);
25805
25806 spin_unlock(&pgd_lock);
25807
25808 return pgd;
25809
25810-out_free_pmds:
25811- free_pmds(pmds);
25812+out_free_pxds:
25813+ free_pxds(pxds);
25814 out_free_pgd:
25815 free_page((unsigned long)pgd);
25816 out:
25817@@ -295,7 +356,7 @@ out:
25818
25819 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25820 {
25821- pgd_mop_up_pmds(mm, pgd);
25822+ pgd_mop_up_pxds(mm, pgd);
25823 pgd_dtor(pgd);
25824 paravirt_pgd_free(mm, pgd);
25825 free_page((unsigned long)pgd);
25826diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25827index a69bcb8..19068ab 100644
25828--- a/arch/x86/mm/pgtable_32.c
25829+++ b/arch/x86/mm/pgtable_32.c
25830@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25831 return;
25832 }
25833 pte = pte_offset_kernel(pmd, vaddr);
25834+
25835+ pax_open_kernel();
25836 if (pte_val(pteval))
25837 set_pte_at(&init_mm, vaddr, pte, pteval);
25838 else
25839 pte_clear(&init_mm, vaddr, pte);
25840+ pax_close_kernel();
25841
25842 /*
25843 * It's enough to flush this one mapping.
25844diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25845index 410531d..0f16030 100644
25846--- a/arch/x86/mm/setup_nx.c
25847+++ b/arch/x86/mm/setup_nx.c
25848@@ -5,8 +5,10 @@
25849 #include <asm/pgtable.h>
25850 #include <asm/proto.h>
25851
25852+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25853 static int disable_nx __cpuinitdata;
25854
25855+#ifndef CONFIG_PAX_PAGEEXEC
25856 /*
25857 * noexec = on|off
25858 *
25859@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25860 return 0;
25861 }
25862 early_param("noexec", noexec_setup);
25863+#endif
25864+
25865+#endif
25866
25867 void __cpuinit x86_configure_nx(void)
25868 {
25869+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25870 if (cpu_has_nx && !disable_nx)
25871 __supported_pte_mask |= _PAGE_NX;
25872 else
25873+#endif
25874 __supported_pte_mask &= ~_PAGE_NX;
25875 }
25876
25877diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25878index d6c0418..06a0ad5 100644
25879--- a/arch/x86/mm/tlb.c
25880+++ b/arch/x86/mm/tlb.c
25881@@ -65,7 +65,11 @@ void leave_mm(int cpu)
25882 BUG();
25883 cpumask_clear_cpu(cpu,
25884 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
25885+
25886+#ifndef CONFIG_PAX_PER_CPU_PGD
25887 load_cr3(swapper_pg_dir);
25888+#endif
25889+
25890 }
25891 EXPORT_SYMBOL_GPL(leave_mm);
25892
25893diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25894index 877b9a1..a8ecf42 100644
25895--- a/arch/x86/net/bpf_jit.S
25896+++ b/arch/x86/net/bpf_jit.S
25897@@ -9,6 +9,7 @@
25898 */
25899 #include <linux/linkage.h>
25900 #include <asm/dwarf2.h>
25901+#include <asm/alternative-asm.h>
25902
25903 /*
25904 * Calling convention :
25905@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25906 jle bpf_slow_path_word
25907 mov (SKBDATA,%rsi),%eax
25908 bswap %eax /* ntohl() */
25909+ pax_force_retaddr
25910 ret
25911
25912 sk_load_half:
25913@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25914 jle bpf_slow_path_half
25915 movzwl (SKBDATA,%rsi),%eax
25916 rol $8,%ax # ntohs()
25917+ pax_force_retaddr
25918 ret
25919
25920 sk_load_byte:
25921@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25922 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25923 jle bpf_slow_path_byte
25924 movzbl (SKBDATA,%rsi),%eax
25925+ pax_force_retaddr
25926 ret
25927
25928 /**
25929@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25930 movzbl (SKBDATA,%rsi),%ebx
25931 and $15,%bl
25932 shl $2,%bl
25933+ pax_force_retaddr
25934 ret
25935
25936 /* rsi contains offset and can be scratched */
25937@@ -109,6 +114,7 @@ bpf_slow_path_word:
25938 js bpf_error
25939 mov -12(%rbp),%eax
25940 bswap %eax
25941+ pax_force_retaddr
25942 ret
25943
25944 bpf_slow_path_half:
25945@@ -117,12 +123,14 @@ bpf_slow_path_half:
25946 mov -12(%rbp),%ax
25947 rol $8,%ax
25948 movzwl %ax,%eax
25949+ pax_force_retaddr
25950 ret
25951
25952 bpf_slow_path_byte:
25953 bpf_slow_path_common(1)
25954 js bpf_error
25955 movzbl -12(%rbp),%eax
25956+ pax_force_retaddr
25957 ret
25958
25959 bpf_slow_path_byte_msh:
25960@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
25961 and $15,%al
25962 shl $2,%al
25963 xchg %eax,%ebx
25964+ pax_force_retaddr
25965 ret
25966
25967 #define sk_negative_common(SIZE) \
25968@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
25969 sk_negative_common(4)
25970 mov (%rax), %eax
25971 bswap %eax
25972+ pax_force_retaddr
25973 ret
25974
25975 bpf_slow_path_half_neg:
25976@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
25977 mov (%rax),%ax
25978 rol $8,%ax
25979 movzwl %ax,%eax
25980+ pax_force_retaddr
25981 ret
25982
25983 bpf_slow_path_byte_neg:
25984@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
25985 .globl sk_load_byte_negative_offset
25986 sk_negative_common(1)
25987 movzbl (%rax), %eax
25988+ pax_force_retaddr
25989 ret
25990
25991 bpf_slow_path_byte_msh_neg:
25992@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
25993 and $15,%al
25994 shl $2,%al
25995 xchg %eax,%ebx
25996+ pax_force_retaddr
25997 ret
25998
25999 bpf_error:
26000@@ -197,4 +210,5 @@ bpf_error:
26001 xor %eax,%eax
26002 mov -8(%rbp),%rbx
26003 leaveq
26004+ pax_force_retaddr
26005 ret
26006diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26007index 0597f95..a12c36e 100644
26008--- a/arch/x86/net/bpf_jit_comp.c
26009+++ b/arch/x86/net/bpf_jit_comp.c
26010@@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
26011 set_fs(old_fs);
26012 }
26013
26014+struct bpf_jit_work {
26015+ struct work_struct work;
26016+ void *image;
26017+};
26018+
26019 #define CHOOSE_LOAD_FUNC(K, func) \
26020 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26021
26022@@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
26023 if (addrs == NULL)
26024 return;
26025
26026+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26027+ if (!fp->work)
26028+ goto out;
26029+
26030 /* Before first pass, make a rough estimation of addrs[]
26031 * each bpf instruction is translated to less than 64 bytes
26032 */
26033@@ -589,17 +598,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26034 break;
26035 default:
26036 /* hmm, too complex filter, give up with jit compiler */
26037- goto out;
26038+ goto error;
26039 }
26040 ilen = prog - temp;
26041 if (image) {
26042 if (unlikely(proglen + ilen > oldproglen)) {
26043 pr_err("bpb_jit_compile fatal error\n");
26044- kfree(addrs);
26045- module_free(NULL, image);
26046- return;
26047+ module_free_exec(NULL, image);
26048+ goto error;
26049 }
26050+ pax_open_kernel();
26051 memcpy(image + proglen, temp, ilen);
26052+ pax_close_kernel();
26053 }
26054 proglen += ilen;
26055 addrs[i] = proglen;
26056@@ -620,11 +630,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26057 break;
26058 }
26059 if (proglen == oldproglen) {
26060- image = module_alloc(max_t(unsigned int,
26061- proglen,
26062- sizeof(struct work_struct)));
26063+ image = module_alloc_exec(proglen);
26064 if (!image)
26065- goto out;
26066+ goto error;
26067 }
26068 oldproglen = proglen;
26069 }
26070@@ -640,7 +648,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26071 bpf_flush_icache(image, image + proglen);
26072
26073 fp->bpf_func = (void *)image;
26074- }
26075+ } else
26076+error:
26077+ kfree(fp->work);
26078+
26079 out:
26080 kfree(addrs);
26081 return;
26082@@ -648,18 +659,20 @@ out:
26083
26084 static void jit_free_defer(struct work_struct *arg)
26085 {
26086- module_free(NULL, arg);
26087+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26088+ kfree(arg);
26089 }
26090
26091 /* run from softirq, we must use a work_struct to call
26092- * module_free() from process context
26093+ * module_free_exec() from process context
26094 */
26095 void bpf_jit_free(struct sk_filter *fp)
26096 {
26097 if (fp->bpf_func != sk_run_filter) {
26098- struct work_struct *work = (struct work_struct *)fp->bpf_func;
26099+ struct work_struct *work = &fp->work->work;
26100
26101 INIT_WORK(work, jit_free_defer);
26102+ fp->work->image = fp->bpf_func;
26103 schedule_work(work);
26104 }
26105 }
26106diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26107index d6aa6e8..266395a 100644
26108--- a/arch/x86/oprofile/backtrace.c
26109+++ b/arch/x86/oprofile/backtrace.c
26110@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26111 struct stack_frame_ia32 *fp;
26112 unsigned long bytes;
26113
26114- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26115+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26116 if (bytes != sizeof(bufhead))
26117 return NULL;
26118
26119- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26120+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26121
26122 oprofile_add_trace(bufhead[0].return_address);
26123
26124@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26125 struct stack_frame bufhead[2];
26126 unsigned long bytes;
26127
26128- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26129+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26130 if (bytes != sizeof(bufhead))
26131 return NULL;
26132
26133@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26134 {
26135 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26136
26137- if (!user_mode_vm(regs)) {
26138+ if (!user_mode(regs)) {
26139 unsigned long stack = kernel_stack_pointer(regs);
26140 if (depth)
26141 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26142diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26143index 140942f..8a5cc55 100644
26144--- a/arch/x86/pci/mrst.c
26145+++ b/arch/x86/pci/mrst.c
26146@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26147 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26148 pci_mmcfg_late_init();
26149 pcibios_enable_irq = mrst_pci_irq_enable;
26150- pci_root_ops = pci_mrst_ops;
26151+ pax_open_kernel();
26152+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26153+ pax_close_kernel();
26154 pci_soc_mode = 1;
26155 /* Continue with standard init */
26156 return 1;
26157diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26158index da8fe05..7ee6704 100644
26159--- a/arch/x86/pci/pcbios.c
26160+++ b/arch/x86/pci/pcbios.c
26161@@ -79,50 +79,93 @@ union bios32 {
26162 static struct {
26163 unsigned long address;
26164 unsigned short segment;
26165-} bios32_indirect = { 0, __KERNEL_CS };
26166+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26167
26168 /*
26169 * Returns the entry point for the given service, NULL on error
26170 */
26171
26172-static unsigned long bios32_service(unsigned long service)
26173+static unsigned long __devinit bios32_service(unsigned long service)
26174 {
26175 unsigned char return_code; /* %al */
26176 unsigned long address; /* %ebx */
26177 unsigned long length; /* %ecx */
26178 unsigned long entry; /* %edx */
26179 unsigned long flags;
26180+ struct desc_struct d, *gdt;
26181
26182 local_irq_save(flags);
26183- __asm__("lcall *(%%edi); cld"
26184+
26185+ gdt = get_cpu_gdt_table(smp_processor_id());
26186+
26187+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26188+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26189+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26190+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26191+
26192+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26193 : "=a" (return_code),
26194 "=b" (address),
26195 "=c" (length),
26196 "=d" (entry)
26197 : "0" (service),
26198 "1" (0),
26199- "D" (&bios32_indirect));
26200+ "D" (&bios32_indirect),
26201+ "r"(__PCIBIOS_DS)
26202+ : "memory");
26203+
26204+ pax_open_kernel();
26205+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26206+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26207+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26208+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26209+ pax_close_kernel();
26210+
26211 local_irq_restore(flags);
26212
26213 switch (return_code) {
26214- case 0:
26215- return address + entry;
26216- case 0x80: /* Not present */
26217- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26218- return 0;
26219- default: /* Shouldn't happen */
26220- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26221- service, return_code);
26222+ case 0: {
26223+ int cpu;
26224+ unsigned char flags;
26225+
26226+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26227+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26228+ printk(KERN_WARNING "bios32_service: not valid\n");
26229 return 0;
26230+ }
26231+ address = address + PAGE_OFFSET;
26232+ length += 16UL; /* some BIOSs underreport this... */
26233+ flags = 4;
26234+ if (length >= 64*1024*1024) {
26235+ length >>= PAGE_SHIFT;
26236+ flags |= 8;
26237+ }
26238+
26239+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26240+ gdt = get_cpu_gdt_table(cpu);
26241+ pack_descriptor(&d, address, length, 0x9b, flags);
26242+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26243+ pack_descriptor(&d, address, length, 0x93, flags);
26244+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26245+ }
26246+ return entry;
26247+ }
26248+ case 0x80: /* Not present */
26249+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26250+ return 0;
26251+ default: /* Shouldn't happen */
26252+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26253+ service, return_code);
26254+ return 0;
26255 }
26256 }
26257
26258 static struct {
26259 unsigned long address;
26260 unsigned short segment;
26261-} pci_indirect = { 0, __KERNEL_CS };
26262+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26263
26264-static int pci_bios_present;
26265+static int pci_bios_present __read_only;
26266
26267 static int __devinit check_pcibios(void)
26268 {
26269@@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26270 unsigned long flags, pcibios_entry;
26271
26272 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26273- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26274+ pci_indirect.address = pcibios_entry;
26275
26276 local_irq_save(flags);
26277- __asm__(
26278- "lcall *(%%edi); cld\n\t"
26279+ __asm__("movw %w6, %%ds\n\t"
26280+ "lcall *%%ss:(%%edi); cld\n\t"
26281+ "push %%ss\n\t"
26282+ "pop %%ds\n\t"
26283 "jc 1f\n\t"
26284 "xor %%ah, %%ah\n"
26285 "1:"
26286@@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26287 "=b" (ebx),
26288 "=c" (ecx)
26289 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26290- "D" (&pci_indirect)
26291+ "D" (&pci_indirect),
26292+ "r" (__PCIBIOS_DS)
26293 : "memory");
26294 local_irq_restore(flags);
26295
26296@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26297
26298 switch (len) {
26299 case 1:
26300- __asm__("lcall *(%%esi); cld\n\t"
26301+ __asm__("movw %w6, %%ds\n\t"
26302+ "lcall *%%ss:(%%esi); cld\n\t"
26303+ "push %%ss\n\t"
26304+ "pop %%ds\n\t"
26305 "jc 1f\n\t"
26306 "xor %%ah, %%ah\n"
26307 "1:"
26308@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26309 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26310 "b" (bx),
26311 "D" ((long)reg),
26312- "S" (&pci_indirect));
26313+ "S" (&pci_indirect),
26314+ "r" (__PCIBIOS_DS));
26315 /*
26316 * Zero-extend the result beyond 8 bits, do not trust the
26317 * BIOS having done it:
26318@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26319 *value &= 0xff;
26320 break;
26321 case 2:
26322- __asm__("lcall *(%%esi); cld\n\t"
26323+ __asm__("movw %w6, %%ds\n\t"
26324+ "lcall *%%ss:(%%esi); cld\n\t"
26325+ "push %%ss\n\t"
26326+ "pop %%ds\n\t"
26327 "jc 1f\n\t"
26328 "xor %%ah, %%ah\n"
26329 "1:"
26330@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26331 : "1" (PCIBIOS_READ_CONFIG_WORD),
26332 "b" (bx),
26333 "D" ((long)reg),
26334- "S" (&pci_indirect));
26335+ "S" (&pci_indirect),
26336+ "r" (__PCIBIOS_DS));
26337 /*
26338 * Zero-extend the result beyond 16 bits, do not trust the
26339 * BIOS having done it:
26340@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26341 *value &= 0xffff;
26342 break;
26343 case 4:
26344- __asm__("lcall *(%%esi); cld\n\t"
26345+ __asm__("movw %w6, %%ds\n\t"
26346+ "lcall *%%ss:(%%esi); cld\n\t"
26347+ "push %%ss\n\t"
26348+ "pop %%ds\n\t"
26349 "jc 1f\n\t"
26350 "xor %%ah, %%ah\n"
26351 "1:"
26352@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26353 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26354 "b" (bx),
26355 "D" ((long)reg),
26356- "S" (&pci_indirect));
26357+ "S" (&pci_indirect),
26358+ "r" (__PCIBIOS_DS));
26359 break;
26360 }
26361
26362@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26363
26364 switch (len) {
26365 case 1:
26366- __asm__("lcall *(%%esi); cld\n\t"
26367+ __asm__("movw %w6, %%ds\n\t"
26368+ "lcall *%%ss:(%%esi); cld\n\t"
26369+ "push %%ss\n\t"
26370+ "pop %%ds\n\t"
26371 "jc 1f\n\t"
26372 "xor %%ah, %%ah\n"
26373 "1:"
26374@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26375 "c" (value),
26376 "b" (bx),
26377 "D" ((long)reg),
26378- "S" (&pci_indirect));
26379+ "S" (&pci_indirect),
26380+ "r" (__PCIBIOS_DS));
26381 break;
26382 case 2:
26383- __asm__("lcall *(%%esi); cld\n\t"
26384+ __asm__("movw %w6, %%ds\n\t"
26385+ "lcall *%%ss:(%%esi); cld\n\t"
26386+ "push %%ss\n\t"
26387+ "pop %%ds\n\t"
26388 "jc 1f\n\t"
26389 "xor %%ah, %%ah\n"
26390 "1:"
26391@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26392 "c" (value),
26393 "b" (bx),
26394 "D" ((long)reg),
26395- "S" (&pci_indirect));
26396+ "S" (&pci_indirect),
26397+ "r" (__PCIBIOS_DS));
26398 break;
26399 case 4:
26400- __asm__("lcall *(%%esi); cld\n\t"
26401+ __asm__("movw %w6, %%ds\n\t"
26402+ "lcall *%%ss:(%%esi); cld\n\t"
26403+ "push %%ss\n\t"
26404+ "pop %%ds\n\t"
26405 "jc 1f\n\t"
26406 "xor %%ah, %%ah\n"
26407 "1:"
26408@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26409 "c" (value),
26410 "b" (bx),
26411 "D" ((long)reg),
26412- "S" (&pci_indirect));
26413+ "S" (&pci_indirect),
26414+ "r" (__PCIBIOS_DS));
26415 break;
26416 }
26417
26418@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26419
26420 DBG("PCI: Fetching IRQ routing table... ");
26421 __asm__("push %%es\n\t"
26422+ "movw %w8, %%ds\n\t"
26423 "push %%ds\n\t"
26424 "pop %%es\n\t"
26425- "lcall *(%%esi); cld\n\t"
26426+ "lcall *%%ss:(%%esi); cld\n\t"
26427 "pop %%es\n\t"
26428+ "push %%ss\n\t"
26429+ "pop %%ds\n"
26430 "jc 1f\n\t"
26431 "xor %%ah, %%ah\n"
26432 "1:"
26433@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26434 "1" (0),
26435 "D" ((long) &opt),
26436 "S" (&pci_indirect),
26437- "m" (opt)
26438+ "m" (opt),
26439+ "r" (__PCIBIOS_DS)
26440 : "memory");
26441 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26442 if (ret & 0xff00)
26443@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26444 {
26445 int ret;
26446
26447- __asm__("lcall *(%%esi); cld\n\t"
26448+ __asm__("movw %w5, %%ds\n\t"
26449+ "lcall *%%ss:(%%esi); cld\n\t"
26450+ "push %%ss\n\t"
26451+ "pop %%ds\n"
26452 "jc 1f\n\t"
26453 "xor %%ah, %%ah\n"
26454 "1:"
26455@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26456 : "0" (PCIBIOS_SET_PCI_HW_INT),
26457 "b" ((dev->bus->number << 8) | dev->devfn),
26458 "c" ((irq << 8) | (pin + 10)),
26459- "S" (&pci_indirect));
26460+ "S" (&pci_indirect),
26461+ "r" (__PCIBIOS_DS));
26462 return !(ret & 0xff00);
26463 }
26464 EXPORT_SYMBOL(pcibios_set_irq_routing);
26465diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26466index 40e4469..1ab536e 100644
26467--- a/arch/x86/platform/efi/efi_32.c
26468+++ b/arch/x86/platform/efi/efi_32.c
26469@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26470 {
26471 struct desc_ptr gdt_descr;
26472
26473+#ifdef CONFIG_PAX_KERNEXEC
26474+ struct desc_struct d;
26475+#endif
26476+
26477 local_irq_save(efi_rt_eflags);
26478
26479 load_cr3(initial_page_table);
26480 __flush_tlb_all();
26481
26482+#ifdef CONFIG_PAX_KERNEXEC
26483+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26484+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26485+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26486+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26487+#endif
26488+
26489 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26490 gdt_descr.size = GDT_SIZE - 1;
26491 load_gdt(&gdt_descr);
26492@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26493 {
26494 struct desc_ptr gdt_descr;
26495
26496+#ifdef CONFIG_PAX_KERNEXEC
26497+ struct desc_struct d;
26498+
26499+ memset(&d, 0, sizeof d);
26500+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26501+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26502+#endif
26503+
26504 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26505 gdt_descr.size = GDT_SIZE - 1;
26506 load_gdt(&gdt_descr);
26507diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26508index fbe66e6..c5c0dd2 100644
26509--- a/arch/x86/platform/efi/efi_stub_32.S
26510+++ b/arch/x86/platform/efi/efi_stub_32.S
26511@@ -6,7 +6,9 @@
26512 */
26513
26514 #include <linux/linkage.h>
26515+#include <linux/init.h>
26516 #include <asm/page_types.h>
26517+#include <asm/segment.h>
26518
26519 /*
26520 * efi_call_phys(void *, ...) is a function with variable parameters.
26521@@ -20,7 +22,7 @@
26522 * service functions will comply with gcc calling convention, too.
26523 */
26524
26525-.text
26526+__INIT
26527 ENTRY(efi_call_phys)
26528 /*
26529 * 0. The function can only be called in Linux kernel. So CS has been
26530@@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
26531 * The mapping of lower virtual memory has been created in prelog and
26532 * epilog.
26533 */
26534- movl $1f, %edx
26535- subl $__PAGE_OFFSET, %edx
26536- jmp *%edx
26537+ movl $(__KERNEXEC_EFI_DS), %edx
26538+ mov %edx, %ds
26539+ mov %edx, %es
26540+ mov %edx, %ss
26541+ ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
26542 1:
26543
26544 /*
26545@@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
26546 * parameter 2, ..., param n. To make things easy, we save the return
26547 * address of efi_call_phys in a global variable.
26548 */
26549- popl %edx
26550- movl %edx, saved_return_addr
26551- /* get the function pointer into ECX*/
26552- popl %ecx
26553- movl %ecx, efi_rt_function_ptr
26554- movl $2f, %edx
26555- subl $__PAGE_OFFSET, %edx
26556- pushl %edx
26557+ popl (saved_return_addr)
26558+ popl (efi_rt_function_ptr)
26559
26560 /*
26561 * 3. Clear PG bit in %CR0.
26562@@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
26563 /*
26564 * 5. Call the physical function.
26565 */
26566- jmp *%ecx
26567+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
26568
26569-2:
26570 /*
26571 * 6. After EFI runtime service returns, control will return to
26572 * following instruction. We'd better readjust stack pointer first.
26573@@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
26574 movl %cr0, %edx
26575 orl $0x80000000, %edx
26576 movl %edx, %cr0
26577- jmp 1f
26578-1:
26579+
26580 /*
26581 * 8. Now restore the virtual mode from flat mode by
26582 * adding EIP with PAGE_OFFSET.
26583 */
26584- movl $1f, %edx
26585- jmp *%edx
26586+ ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
26587 1:
26588+ movl $(__KERNEL_DS), %edx
26589+ mov %edx, %ds
26590+ mov %edx, %es
26591+ mov %edx, %ss
26592
26593 /*
26594 * 9. Balance the stack. And because EAX contain the return value,
26595 * we'd better not clobber it.
26596 */
26597- leal efi_rt_function_ptr, %edx
26598- movl (%edx), %ecx
26599- pushl %ecx
26600+ pushl (efi_rt_function_ptr)
26601
26602 /*
26603- * 10. Push the saved return address onto the stack and return.
26604+ * 10. Return to the saved return address.
26605 */
26606- leal saved_return_addr, %edx
26607- movl (%edx), %ecx
26608- pushl %ecx
26609- ret
26610+ jmpl *(saved_return_addr)
26611 ENDPROC(efi_call_phys)
26612 .previous
26613
26614-.data
26615+__INITDATA
26616 saved_return_addr:
26617 .long 0
26618 efi_rt_function_ptr:
26619diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26620index 4c07cca..2c8427d 100644
26621--- a/arch/x86/platform/efi/efi_stub_64.S
26622+++ b/arch/x86/platform/efi/efi_stub_64.S
26623@@ -7,6 +7,7 @@
26624 */
26625
26626 #include <linux/linkage.h>
26627+#include <asm/alternative-asm.h>
26628
26629 #define SAVE_XMM \
26630 mov %rsp, %rax; \
26631@@ -40,6 +41,7 @@ ENTRY(efi_call0)
26632 call *%rdi
26633 addq $32, %rsp
26634 RESTORE_XMM
26635+ pax_force_retaddr 0, 1
26636 ret
26637 ENDPROC(efi_call0)
26638
26639@@ -50,6 +52,7 @@ ENTRY(efi_call1)
26640 call *%rdi
26641 addq $32, %rsp
26642 RESTORE_XMM
26643+ pax_force_retaddr 0, 1
26644 ret
26645 ENDPROC(efi_call1)
26646
26647@@ -60,6 +63,7 @@ ENTRY(efi_call2)
26648 call *%rdi
26649 addq $32, %rsp
26650 RESTORE_XMM
26651+ pax_force_retaddr 0, 1
26652 ret
26653 ENDPROC(efi_call2)
26654
26655@@ -71,6 +75,7 @@ ENTRY(efi_call3)
26656 call *%rdi
26657 addq $32, %rsp
26658 RESTORE_XMM
26659+ pax_force_retaddr 0, 1
26660 ret
26661 ENDPROC(efi_call3)
26662
26663@@ -83,6 +88,7 @@ ENTRY(efi_call4)
26664 call *%rdi
26665 addq $32, %rsp
26666 RESTORE_XMM
26667+ pax_force_retaddr 0, 1
26668 ret
26669 ENDPROC(efi_call4)
26670
26671@@ -96,6 +102,7 @@ ENTRY(efi_call5)
26672 call *%rdi
26673 addq $48, %rsp
26674 RESTORE_XMM
26675+ pax_force_retaddr 0, 1
26676 ret
26677 ENDPROC(efi_call5)
26678
26679@@ -112,5 +119,6 @@ ENTRY(efi_call6)
26680 call *%rdi
26681 addq $48, %rsp
26682 RESTORE_XMM
26683+ pax_force_retaddr 0, 1
26684 ret
26685 ENDPROC(efi_call6)
26686diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26687index e31bcd8..f12dc46 100644
26688--- a/arch/x86/platform/mrst/mrst.c
26689+++ b/arch/x86/platform/mrst/mrst.c
26690@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26691 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26692 int sfi_mrtc_num;
26693
26694-static void mrst_power_off(void)
26695+static __noreturn void mrst_power_off(void)
26696 {
26697+ BUG();
26698 }
26699
26700-static void mrst_reboot(void)
26701+static __noreturn void mrst_reboot(void)
26702 {
26703 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26704+ BUG();
26705 }
26706
26707 /* parse all the mtimer info to a static mtimer array */
26708diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26709index 218cdb1..fd55c08 100644
26710--- a/arch/x86/power/cpu.c
26711+++ b/arch/x86/power/cpu.c
26712@@ -132,7 +132,7 @@ static void do_fpu_end(void)
26713 static void fix_processor_context(void)
26714 {
26715 int cpu = smp_processor_id();
26716- struct tss_struct *t = &per_cpu(init_tss, cpu);
26717+ struct tss_struct *t = init_tss + cpu;
26718
26719 set_tss_desc(cpu, t); /*
26720 * This just modifies memory; should not be
26721@@ -142,7 +142,9 @@ static void fix_processor_context(void)
26722 */
26723
26724 #ifdef CONFIG_X86_64
26725+ pax_open_kernel();
26726 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26727+ pax_close_kernel();
26728
26729 syscall_init(); /* This sets MSR_*STAR and related */
26730 #endif
26731diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26732index b685296..e00eb65 100644
26733--- a/arch/x86/tools/relocs.c
26734+++ b/arch/x86/tools/relocs.c
26735@@ -12,10 +12,13 @@
26736 #include <regex.h>
26737 #include <tools/le_byteshift.h>
26738
26739+#include "../../../include/generated/autoconf.h"
26740+
26741 static void die(char *fmt, ...);
26742
26743 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26744 static Elf32_Ehdr ehdr;
26745+static Elf32_Phdr *phdr;
26746 static unsigned long reloc_count, reloc_idx;
26747 static unsigned long *relocs;
26748 static unsigned long reloc16_count, reloc16_idx;
26749@@ -323,9 +326,39 @@ static void read_ehdr(FILE *fp)
26750 }
26751 }
26752
26753+static void read_phdrs(FILE *fp)
26754+{
26755+ unsigned int i;
26756+
26757+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26758+ if (!phdr) {
26759+ die("Unable to allocate %d program headers\n",
26760+ ehdr.e_phnum);
26761+ }
26762+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26763+ die("Seek to %d failed: %s\n",
26764+ ehdr.e_phoff, strerror(errno));
26765+ }
26766+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26767+ die("Cannot read ELF program headers: %s\n",
26768+ strerror(errno));
26769+ }
26770+ for(i = 0; i < ehdr.e_phnum; i++) {
26771+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26772+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26773+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26774+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26775+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26776+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26777+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26778+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26779+ }
26780+
26781+}
26782+
26783 static void read_shdrs(FILE *fp)
26784 {
26785- int i;
26786+ unsigned int i;
26787 Elf32_Shdr shdr;
26788
26789 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26790@@ -360,7 +393,7 @@ static void read_shdrs(FILE *fp)
26791
26792 static void read_strtabs(FILE *fp)
26793 {
26794- int i;
26795+ unsigned int i;
26796 for (i = 0; i < ehdr.e_shnum; i++) {
26797 struct section *sec = &secs[i];
26798 if (sec->shdr.sh_type != SHT_STRTAB) {
26799@@ -385,7 +418,7 @@ static void read_strtabs(FILE *fp)
26800
26801 static void read_symtabs(FILE *fp)
26802 {
26803- int i,j;
26804+ unsigned int i,j;
26805 for (i = 0; i < ehdr.e_shnum; i++) {
26806 struct section *sec = &secs[i];
26807 if (sec->shdr.sh_type != SHT_SYMTAB) {
26808@@ -418,7 +451,9 @@ static void read_symtabs(FILE *fp)
26809
26810 static void read_relocs(FILE *fp)
26811 {
26812- int i,j;
26813+ unsigned int i,j;
26814+ uint32_t base;
26815+
26816 for (i = 0; i < ehdr.e_shnum; i++) {
26817 struct section *sec = &secs[i];
26818 if (sec->shdr.sh_type != SHT_REL) {
26819@@ -438,9 +473,22 @@ static void read_relocs(FILE *fp)
26820 die("Cannot read symbol table: %s\n",
26821 strerror(errno));
26822 }
26823+ base = 0;
26824+
26825+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
26826+ for (j = 0; j < ehdr.e_phnum; j++) {
26827+ if (phdr[j].p_type != PT_LOAD )
26828+ continue;
26829+ 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)
26830+ continue;
26831+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26832+ break;
26833+ }
26834+#endif
26835+
26836 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26837 Elf32_Rel *rel = &sec->reltab[j];
26838- rel->r_offset = elf32_to_cpu(rel->r_offset);
26839+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
26840 rel->r_info = elf32_to_cpu(rel->r_info);
26841 }
26842 }
26843@@ -449,13 +497,13 @@ static void read_relocs(FILE *fp)
26844
26845 static void print_absolute_symbols(void)
26846 {
26847- int i;
26848+ unsigned int i;
26849 printf("Absolute symbols\n");
26850 printf(" Num: Value Size Type Bind Visibility Name\n");
26851 for (i = 0; i < ehdr.e_shnum; i++) {
26852 struct section *sec = &secs[i];
26853 char *sym_strtab;
26854- int j;
26855+ unsigned int j;
26856
26857 if (sec->shdr.sh_type != SHT_SYMTAB) {
26858 continue;
26859@@ -482,14 +530,14 @@ static void print_absolute_symbols(void)
26860
26861 static void print_absolute_relocs(void)
26862 {
26863- int i, printed = 0;
26864+ unsigned int i, printed = 0;
26865
26866 for (i = 0; i < ehdr.e_shnum; i++) {
26867 struct section *sec = &secs[i];
26868 struct section *sec_applies, *sec_symtab;
26869 char *sym_strtab;
26870 Elf32_Sym *sh_symtab;
26871- int j;
26872+ unsigned int j;
26873 if (sec->shdr.sh_type != SHT_REL) {
26874 continue;
26875 }
26876@@ -551,13 +599,13 @@ static void print_absolute_relocs(void)
26877 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26878 int use_real_mode)
26879 {
26880- int i;
26881+ unsigned int i;
26882 /* Walk through the relocations */
26883 for (i = 0; i < ehdr.e_shnum; i++) {
26884 char *sym_strtab;
26885 Elf32_Sym *sh_symtab;
26886 struct section *sec_applies, *sec_symtab;
26887- int j;
26888+ unsigned int j;
26889 struct section *sec = &secs[i];
26890
26891 if (sec->shdr.sh_type != SHT_REL) {
26892@@ -581,6 +629,22 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26893 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
26894 r_type = ELF32_R_TYPE(rel->r_info);
26895
26896+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
26897+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
26898+ continue;
26899+
26900+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
26901+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
26902+ if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
26903+ continue;
26904+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
26905+ continue;
26906+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
26907+ continue;
26908+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
26909+ continue;
26910+#endif
26911+
26912 shn_abs = sym->st_shndx == SHN_ABS;
26913
26914 switch (r_type) {
26915@@ -674,7 +738,7 @@ static int write32(unsigned int v, FILE *f)
26916
26917 static void emit_relocs(int as_text, int use_real_mode)
26918 {
26919- int i;
26920+ unsigned int i;
26921 /* Count how many relocations I have and allocate space for them. */
26922 reloc_count = 0;
26923 walk_relocs(count_reloc, use_real_mode);
26924@@ -801,6 +865,7 @@ int main(int argc, char **argv)
26925 fname, strerror(errno));
26926 }
26927 read_ehdr(fp);
26928+ read_phdrs(fp);
26929 read_shdrs(fp);
26930 read_strtabs(fp);
26931 read_symtabs(fp);
26932diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26933index fd14be1..e3c79c0 100644
26934--- a/arch/x86/vdso/Makefile
26935+++ b/arch/x86/vdso/Makefile
26936@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
26937 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
26938 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
26939
26940-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26941+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26942 GCOV_PROFILE := n
26943
26944 #
26945diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26946index 66e6d93..587f435 100644
26947--- a/arch/x86/vdso/vdso32-setup.c
26948+++ b/arch/x86/vdso/vdso32-setup.c
26949@@ -25,6 +25,7 @@
26950 #include <asm/tlbflush.h>
26951 #include <asm/vdso.h>
26952 #include <asm/proto.h>
26953+#include <asm/mman.h>
26954
26955 enum {
26956 VDSO_DISABLED = 0,
26957@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26958 void enable_sep_cpu(void)
26959 {
26960 int cpu = get_cpu();
26961- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26962+ struct tss_struct *tss = init_tss + cpu;
26963
26964 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26965 put_cpu();
26966@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26967 gate_vma.vm_start = FIXADDR_USER_START;
26968 gate_vma.vm_end = FIXADDR_USER_END;
26969 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26970- gate_vma.vm_page_prot = __P101;
26971+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26972
26973 return 0;
26974 }
26975@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26976 if (compat)
26977 addr = VDSO_HIGH_BASE;
26978 else {
26979- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26980+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26981 if (IS_ERR_VALUE(addr)) {
26982 ret = addr;
26983 goto up_fail;
26984 }
26985 }
26986
26987- current->mm->context.vdso = (void *)addr;
26988+ current->mm->context.vdso = addr;
26989
26990 if (compat_uses_vma || !compat) {
26991 /*
26992@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26993 }
26994
26995 current_thread_info()->sysenter_return =
26996- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26997+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26998
26999 up_fail:
27000 if (ret)
27001- current->mm->context.vdso = NULL;
27002+ current->mm->context.vdso = 0;
27003
27004 up_write(&mm->mmap_sem);
27005
27006@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27007
27008 const char *arch_vma_name(struct vm_area_struct *vma)
27009 {
27010- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27011+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27012 return "[vdso]";
27013+
27014+#ifdef CONFIG_PAX_SEGMEXEC
27015+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27016+ return "[vdso]";
27017+#endif
27018+
27019 return NULL;
27020 }
27021
27022@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27023 * Check to see if the corresponding task was created in compat vdso
27024 * mode.
27025 */
27026- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27027+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27028 return &gate_vma;
27029 return NULL;
27030 }
27031diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27032index 00aaf04..4a26505 100644
27033--- a/arch/x86/vdso/vma.c
27034+++ b/arch/x86/vdso/vma.c
27035@@ -16,8 +16,6 @@
27036 #include <asm/vdso.h>
27037 #include <asm/page.h>
27038
27039-unsigned int __read_mostly vdso_enabled = 1;
27040-
27041 extern char vdso_start[], vdso_end[];
27042 extern unsigned short vdso_sync_cpuid;
27043
27044@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27045 * unaligned here as a result of stack start randomization.
27046 */
27047 addr = PAGE_ALIGN(addr);
27048- addr = align_addr(addr, NULL, ALIGN_VDSO);
27049
27050 return addr;
27051 }
27052@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27053 unsigned size)
27054 {
27055 struct mm_struct *mm = current->mm;
27056- unsigned long addr;
27057+ unsigned long addr = 0;
27058 int ret;
27059
27060- if (!vdso_enabled)
27061- return 0;
27062-
27063 down_write(&mm->mmap_sem);
27064+
27065+#ifdef CONFIG_PAX_RANDMMAP
27066+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27067+#endif
27068+
27069 addr = vdso_addr(mm->start_stack, size);
27070+ addr = align_addr(addr, NULL, ALIGN_VDSO);
27071 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27072 if (IS_ERR_VALUE(addr)) {
27073 ret = addr;
27074 goto up_fail;
27075 }
27076
27077- current->mm->context.vdso = (void *)addr;
27078+ mm->context.vdso = addr;
27079
27080 ret = install_special_mapping(mm, addr, size,
27081 VM_READ|VM_EXEC|
27082 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27083 pages);
27084- if (ret) {
27085- current->mm->context.vdso = NULL;
27086- goto up_fail;
27087- }
27088+ if (ret)
27089+ mm->context.vdso = 0;
27090
27091 up_fail:
27092 up_write(&mm->mmap_sem);
27093@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27094 vdsox32_size);
27095 }
27096 #endif
27097-
27098-static __init int vdso_setup(char *s)
27099-{
27100- vdso_enabled = simple_strtoul(s, NULL, 0);
27101- return 0;
27102-}
27103-__setup("vdso=", vdso_setup);
27104diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27105index 6c7f1e8..de96944 100644
27106--- a/arch/x86/xen/enlighten.c
27107+++ b/arch/x86/xen/enlighten.c
27108@@ -95,8 +95,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27109
27110 struct shared_info xen_dummy_shared_info;
27111
27112-void *xen_initial_gdt;
27113-
27114 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27115 __read_mostly int xen_have_vector_callback;
27116 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27117@@ -1157,30 +1155,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27118 #endif
27119 };
27120
27121-static void xen_reboot(int reason)
27122+static __noreturn void xen_reboot(int reason)
27123 {
27124 struct sched_shutdown r = { .reason = reason };
27125
27126- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27127- BUG();
27128+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27129+ BUG();
27130 }
27131
27132-static void xen_restart(char *msg)
27133+static __noreturn void xen_restart(char *msg)
27134 {
27135 xen_reboot(SHUTDOWN_reboot);
27136 }
27137
27138-static void xen_emergency_restart(void)
27139+static __noreturn void xen_emergency_restart(void)
27140 {
27141 xen_reboot(SHUTDOWN_reboot);
27142 }
27143
27144-static void xen_machine_halt(void)
27145+static __noreturn void xen_machine_halt(void)
27146 {
27147 xen_reboot(SHUTDOWN_poweroff);
27148 }
27149
27150-static void xen_machine_power_off(void)
27151+static __noreturn void xen_machine_power_off(void)
27152 {
27153 if (pm_power_off)
27154 pm_power_off();
27155@@ -1283,7 +1281,17 @@ asmlinkage void __init xen_start_kernel(void)
27156 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27157
27158 /* Work out if we support NX */
27159- x86_configure_nx();
27160+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27161+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27162+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27163+ unsigned l, h;
27164+
27165+ __supported_pte_mask |= _PAGE_NX;
27166+ rdmsr(MSR_EFER, l, h);
27167+ l |= EFER_NX;
27168+ wrmsr(MSR_EFER, l, h);
27169+ }
27170+#endif
27171
27172 xen_setup_features();
27173
27174@@ -1314,13 +1322,6 @@ asmlinkage void __init xen_start_kernel(void)
27175
27176 machine_ops = xen_machine_ops;
27177
27178- /*
27179- * The only reliable way to retain the initial address of the
27180- * percpu gdt_page is to remember it here, so we can go and
27181- * mark it RW later, when the initial percpu area is freed.
27182- */
27183- xen_initial_gdt = &per_cpu(gdt_page, 0);
27184-
27185 xen_smp_init();
27186
27187 #ifdef CONFIG_ACPI_NUMA
27188diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27189index 69f5857..0699dc5 100644
27190--- a/arch/x86/xen/mmu.c
27191+++ b/arch/x86/xen/mmu.c
27192@@ -1738,6 +1738,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27193 convert_pfn_mfn(init_level4_pgt);
27194 convert_pfn_mfn(level3_ident_pgt);
27195 convert_pfn_mfn(level3_kernel_pgt);
27196+ convert_pfn_mfn(level3_vmalloc_start_pgt);
27197+ convert_pfn_mfn(level3_vmalloc_end_pgt);
27198+ convert_pfn_mfn(level3_vmemmap_pgt);
27199
27200 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27201 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27202@@ -1756,7 +1759,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27203 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27204 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27205 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27206+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27207+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27208+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27209 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27210+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27211 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27212 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27213
27214@@ -1964,6 +1971,7 @@ static void __init xen_post_allocator_init(void)
27215 pv_mmu_ops.set_pud = xen_set_pud;
27216 #if PAGETABLE_LEVELS == 4
27217 pv_mmu_ops.set_pgd = xen_set_pgd;
27218+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27219 #endif
27220
27221 /* This will work as long as patching hasn't happened yet
27222@@ -2045,6 +2053,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27223 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27224 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27225 .set_pgd = xen_set_pgd_hyper,
27226+ .set_pgd_batched = xen_set_pgd_hyper,
27227
27228 .alloc_pud = xen_alloc_pmd_init,
27229 .release_pud = xen_release_pmd_init,
27230diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27231index 0503c0c..ceb2d16 100644
27232--- a/arch/x86/xen/smp.c
27233+++ b/arch/x86/xen/smp.c
27234@@ -215,11 +215,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27235 {
27236 BUG_ON(smp_processor_id() != 0);
27237 native_smp_prepare_boot_cpu();
27238-
27239- /* We've switched to the "real" per-cpu gdt, so make sure the
27240- old memory can be recycled */
27241- make_lowmem_page_readwrite(xen_initial_gdt);
27242-
27243 xen_filter_cpu_maps();
27244 xen_setup_vcpu_info_placement();
27245 }
27246@@ -296,12 +291,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27247 gdt = get_cpu_gdt_table(cpu);
27248
27249 ctxt->flags = VGCF_IN_KERNEL;
27250- ctxt->user_regs.ds = __USER_DS;
27251- ctxt->user_regs.es = __USER_DS;
27252+ ctxt->user_regs.ds = __KERNEL_DS;
27253+ ctxt->user_regs.es = __KERNEL_DS;
27254 ctxt->user_regs.ss = __KERNEL_DS;
27255 #ifdef CONFIG_X86_32
27256 ctxt->user_regs.fs = __KERNEL_PERCPU;
27257- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27258+ savesegment(gs, ctxt->user_regs.gs);
27259 #else
27260 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27261 #endif
27262@@ -352,13 +347,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
27263 int rc;
27264
27265 per_cpu(current_task, cpu) = idle;
27266+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27267 #ifdef CONFIG_X86_32
27268 irq_ctx_init(cpu);
27269 #else
27270 clear_tsk_thread_flag(idle, TIF_FORK);
27271- per_cpu(kernel_stack, cpu) =
27272- (unsigned long)task_stack_page(idle) -
27273- KERNEL_STACK_OFFSET + THREAD_SIZE;
27274+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27275 #endif
27276 xen_setup_runstate_info(cpu);
27277 xen_setup_timer(cpu);
27278diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27279index b040b0e..8cc4fe0 100644
27280--- a/arch/x86/xen/xen-asm_32.S
27281+++ b/arch/x86/xen/xen-asm_32.S
27282@@ -83,14 +83,14 @@ ENTRY(xen_iret)
27283 ESP_OFFSET=4 # bytes pushed onto stack
27284
27285 /*
27286- * Store vcpu_info pointer for easy access. Do it this way to
27287- * avoid having to reload %fs
27288+ * Store vcpu_info pointer for easy access.
27289 */
27290 #ifdef CONFIG_SMP
27291- GET_THREAD_INFO(%eax)
27292- movl TI_cpu(%eax), %eax
27293- movl __per_cpu_offset(,%eax,4), %eax
27294- mov xen_vcpu(%eax), %eax
27295+ push %fs
27296+ mov $(__KERNEL_PERCPU), %eax
27297+ mov %eax, %fs
27298+ mov PER_CPU_VAR(xen_vcpu), %eax
27299+ pop %fs
27300 #else
27301 movl xen_vcpu, %eax
27302 #endif
27303diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27304index aaa7291..3f77960 100644
27305--- a/arch/x86/xen/xen-head.S
27306+++ b/arch/x86/xen/xen-head.S
27307@@ -19,6 +19,17 @@ ENTRY(startup_xen)
27308 #ifdef CONFIG_X86_32
27309 mov %esi,xen_start_info
27310 mov $init_thread_union+THREAD_SIZE,%esp
27311+#ifdef CONFIG_SMP
27312+ movl $cpu_gdt_table,%edi
27313+ movl $__per_cpu_load,%eax
27314+ movw %ax,__KERNEL_PERCPU + 2(%edi)
27315+ rorl $16,%eax
27316+ movb %al,__KERNEL_PERCPU + 4(%edi)
27317+ movb %ah,__KERNEL_PERCPU + 7(%edi)
27318+ movl $__per_cpu_end - 1,%eax
27319+ subl $__per_cpu_start,%eax
27320+ movw %ax,__KERNEL_PERCPU + 0(%edi)
27321+#endif
27322 #else
27323 mov %rsi,xen_start_info
27324 mov $init_thread_union+THREAD_SIZE,%rsp
27325diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27326index b095739..8c17bcd 100644
27327--- a/arch/x86/xen/xen-ops.h
27328+++ b/arch/x86/xen/xen-ops.h
27329@@ -10,8 +10,6 @@
27330 extern const char xen_hypervisor_callback[];
27331 extern const char xen_failsafe_callback[];
27332
27333-extern void *xen_initial_gdt;
27334-
27335 struct trap_info;
27336 void xen_copy_trap_info(struct trap_info *traps);
27337
27338diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27339index 525bd3d..ef888b1 100644
27340--- a/arch/xtensa/variants/dc232b/include/variant/core.h
27341+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27342@@ -119,9 +119,9 @@
27343 ----------------------------------------------------------------------*/
27344
27345 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27346-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27347 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27348 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27349+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27350
27351 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27352 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27353diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27354index 2f33760..835e50a 100644
27355--- a/arch/xtensa/variants/fsf/include/variant/core.h
27356+++ b/arch/xtensa/variants/fsf/include/variant/core.h
27357@@ -11,6 +11,7 @@
27358 #ifndef _XTENSA_CORE_H
27359 #define _XTENSA_CORE_H
27360
27361+#include <linux/const.h>
27362
27363 /****************************************************************************
27364 Parameters Useful for Any Code, USER or PRIVILEGED
27365@@ -112,9 +113,9 @@
27366 ----------------------------------------------------------------------*/
27367
27368 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27369-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27370 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27371 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27372+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27373
27374 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27375 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27376diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27377index af00795..2bb8105 100644
27378--- a/arch/xtensa/variants/s6000/include/variant/core.h
27379+++ b/arch/xtensa/variants/s6000/include/variant/core.h
27380@@ -11,6 +11,7 @@
27381 #ifndef _XTENSA_CORE_CONFIGURATION_H
27382 #define _XTENSA_CORE_CONFIGURATION_H
27383
27384+#include <linux/const.h>
27385
27386 /****************************************************************************
27387 Parameters Useful for Any Code, USER or PRIVILEGED
27388@@ -118,9 +119,9 @@
27389 ----------------------------------------------------------------------*/
27390
27391 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27392-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27393 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27394 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27395+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27396
27397 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27398 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27399diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27400index 58916af..9cb880b 100644
27401--- a/block/blk-iopoll.c
27402+++ b/block/blk-iopoll.c
27403@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27404 }
27405 EXPORT_SYMBOL(blk_iopoll_complete);
27406
27407-static void blk_iopoll_softirq(struct softirq_action *h)
27408+static void blk_iopoll_softirq(void)
27409 {
27410 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27411 int rearm = 0, budget = blk_iopoll_budget;
27412diff --git a/block/blk-map.c b/block/blk-map.c
27413index 623e1cd..ca1e109 100644
27414--- a/block/blk-map.c
27415+++ b/block/blk-map.c
27416@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27417 if (!len || !kbuf)
27418 return -EINVAL;
27419
27420- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27421+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27422 if (do_copy)
27423 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27424 else
27425diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27426index 467c8de..4bddc6d 100644
27427--- a/block/blk-softirq.c
27428+++ b/block/blk-softirq.c
27429@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27430 * Softirq action handler - move entries to local list and loop over them
27431 * while passing them to the queue registered handler.
27432 */
27433-static void blk_done_softirq(struct softirq_action *h)
27434+static void blk_done_softirq(void)
27435 {
27436 struct list_head *cpu_list, local_list;
27437
27438diff --git a/block/bsg.c b/block/bsg.c
27439index ff64ae3..593560c 100644
27440--- a/block/bsg.c
27441+++ b/block/bsg.c
27442@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27443 struct sg_io_v4 *hdr, struct bsg_device *bd,
27444 fmode_t has_write_perm)
27445 {
27446+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27447+ unsigned char *cmdptr;
27448+
27449 if (hdr->request_len > BLK_MAX_CDB) {
27450 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27451 if (!rq->cmd)
27452 return -ENOMEM;
27453- }
27454+ cmdptr = rq->cmd;
27455+ } else
27456+ cmdptr = tmpcmd;
27457
27458- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27459+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27460 hdr->request_len))
27461 return -EFAULT;
27462
27463+ if (cmdptr != rq->cmd)
27464+ memcpy(rq->cmd, cmdptr, hdr->request_len);
27465+
27466 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27467 if (blk_verify_command(rq->cmd, has_write_perm))
27468 return -EPERM;
27469diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27470index 7c668c8..db3521c 100644
27471--- a/block/compat_ioctl.c
27472+++ b/block/compat_ioctl.c
27473@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27474 err |= __get_user(f->spec1, &uf->spec1);
27475 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27476 err |= __get_user(name, &uf->name);
27477- f->name = compat_ptr(name);
27478+ f->name = (void __force_kernel *)compat_ptr(name);
27479 if (err) {
27480 err = -EFAULT;
27481 goto out;
27482diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27483index 6296b40..417c00f 100644
27484--- a/block/partitions/efi.c
27485+++ b/block/partitions/efi.c
27486@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27487 if (!gpt)
27488 return NULL;
27489
27490+ if (!le32_to_cpu(gpt->num_partition_entries))
27491+ return NULL;
27492+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27493+ if (!pte)
27494+ return NULL;
27495+
27496 count = le32_to_cpu(gpt->num_partition_entries) *
27497 le32_to_cpu(gpt->sizeof_partition_entry);
27498- if (!count)
27499- return NULL;
27500- pte = kzalloc(count, GFP_KERNEL);
27501- if (!pte)
27502- return NULL;
27503-
27504 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27505 (u8 *) pte,
27506 count) < count) {
27507diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27508index 260fa80..e8f3caf 100644
27509--- a/block/scsi_ioctl.c
27510+++ b/block/scsi_ioctl.c
27511@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27512 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27513 struct sg_io_hdr *hdr, fmode_t mode)
27514 {
27515- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27516+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27517+ unsigned char *cmdptr;
27518+
27519+ if (rq->cmd != rq->__cmd)
27520+ cmdptr = rq->cmd;
27521+ else
27522+ cmdptr = tmpcmd;
27523+
27524+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27525 return -EFAULT;
27526+
27527+ if (cmdptr != rq->cmd)
27528+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27529+
27530 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27531 return -EPERM;
27532
27533@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27534 int err;
27535 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27536 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27537+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27538+ unsigned char *cmdptr;
27539
27540 if (!sic)
27541 return -EINVAL;
27542@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27543 */
27544 err = -EFAULT;
27545 rq->cmd_len = cmdlen;
27546- if (copy_from_user(rq->cmd, sic->data, cmdlen))
27547+
27548+ if (rq->cmd != rq->__cmd)
27549+ cmdptr = rq->cmd;
27550+ else
27551+ cmdptr = tmpcmd;
27552+
27553+ if (copy_from_user(cmdptr, sic->data, cmdlen))
27554 goto error;
27555
27556+ if (rq->cmd != cmdptr)
27557+ memcpy(rq->cmd, cmdptr, cmdlen);
27558+
27559 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27560 goto error;
27561
27562diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27563index 671d4d6..5f24030 100644
27564--- a/crypto/cryptd.c
27565+++ b/crypto/cryptd.c
27566@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27567
27568 struct cryptd_blkcipher_request_ctx {
27569 crypto_completion_t complete;
27570-};
27571+} __no_const;
27572
27573 struct cryptd_hash_ctx {
27574 struct crypto_shash *child;
27575@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27576
27577 struct cryptd_aead_request_ctx {
27578 crypto_completion_t complete;
27579-};
27580+} __no_const;
27581
27582 static void cryptd_queue_worker(struct work_struct *work);
27583
27584diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27585index e6defd8..c26a225 100644
27586--- a/drivers/acpi/apei/cper.c
27587+++ b/drivers/acpi/apei/cper.c
27588@@ -38,12 +38,12 @@
27589 */
27590 u64 cper_next_record_id(void)
27591 {
27592- static atomic64_t seq;
27593+ static atomic64_unchecked_t seq;
27594
27595- if (!atomic64_read(&seq))
27596- atomic64_set(&seq, ((u64)get_seconds()) << 32);
27597+ if (!atomic64_read_unchecked(&seq))
27598+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27599
27600- return atomic64_inc_return(&seq);
27601+ return atomic64_inc_return_unchecked(&seq);
27602 }
27603 EXPORT_SYMBOL_GPL(cper_next_record_id);
27604
27605diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27606index 7586544..636a2f0 100644
27607--- a/drivers/acpi/ec_sys.c
27608+++ b/drivers/acpi/ec_sys.c
27609@@ -12,6 +12,7 @@
27610 #include <linux/acpi.h>
27611 #include <linux/debugfs.h>
27612 #include <linux/module.h>
27613+#include <linux/uaccess.h>
27614 #include "internal.h"
27615
27616 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27617@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27618 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27619 */
27620 unsigned int size = EC_SPACE_SIZE;
27621- u8 *data = (u8 *) buf;
27622+ u8 data;
27623 loff_t init_off = *off;
27624 int err = 0;
27625
27626@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27627 size = count;
27628
27629 while (size) {
27630- err = ec_read(*off, &data[*off - init_off]);
27631+ err = ec_read(*off, &data);
27632 if (err)
27633 return err;
27634+ if (put_user(data, &buf[*off - init_off]))
27635+ return -EFAULT;
27636 *off += 1;
27637 size--;
27638 }
27639@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27640
27641 unsigned int size = count;
27642 loff_t init_off = *off;
27643- u8 *data = (u8 *) buf;
27644 int err = 0;
27645
27646 if (*off >= EC_SPACE_SIZE)
27647@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27648 }
27649
27650 while (size) {
27651- u8 byte_write = data[*off - init_off];
27652+ u8 byte_write;
27653+ if (get_user(byte_write, &buf[*off - init_off]))
27654+ return -EFAULT;
27655 err = ec_write(*off, byte_write);
27656 if (err)
27657 return err;
27658diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27659index 251c7b62..000462d 100644
27660--- a/drivers/acpi/proc.c
27661+++ b/drivers/acpi/proc.c
27662@@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27663 size_t count, loff_t * ppos)
27664 {
27665 struct list_head *node, *next;
27666- char strbuf[5];
27667- char str[5] = "";
27668- unsigned int len = count;
27669+ char strbuf[5] = {0};
27670
27671- if (len > 4)
27672- len = 4;
27673- if (len < 0)
27674+ if (count > 4)
27675+ count = 4;
27676+ if (copy_from_user(strbuf, buffer, count))
27677 return -EFAULT;
27678-
27679- if (copy_from_user(strbuf, buffer, len))
27680- return -EFAULT;
27681- strbuf[len] = '\0';
27682- sscanf(strbuf, "%s", str);
27683+ strbuf[count] = '\0';
27684
27685 mutex_lock(&acpi_device_lock);
27686 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27687@@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27688 if (!dev->wakeup.flags.valid)
27689 continue;
27690
27691- if (!strncmp(dev->pnp.bus_id, str, 4)) {
27692+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27693 if (device_can_wakeup(&dev->dev)) {
27694 bool enable = !device_may_wakeup(&dev->dev);
27695 device_set_wakeup_enable(&dev->dev, enable);
27696diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27697index 0734086..3ad3e4c 100644
27698--- a/drivers/acpi/processor_driver.c
27699+++ b/drivers/acpi/processor_driver.c
27700@@ -556,7 +556,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27701 return 0;
27702 #endif
27703
27704- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27705+ BUG_ON(pr->id >= nr_cpu_ids);
27706
27707 /*
27708 * Buggy BIOS check
27709diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27710index d31ee55..8363a8b 100644
27711--- a/drivers/ata/libata-core.c
27712+++ b/drivers/ata/libata-core.c
27713@@ -4742,7 +4742,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27714 struct ata_port *ap;
27715 unsigned int tag;
27716
27717- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27718+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27719 ap = qc->ap;
27720
27721 qc->flags = 0;
27722@@ -4758,7 +4758,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27723 struct ata_port *ap;
27724 struct ata_link *link;
27725
27726- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27727+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27728 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27729 ap = qc->ap;
27730 link = qc->dev->link;
27731@@ -5822,6 +5822,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27732 return;
27733
27734 spin_lock(&lock);
27735+ pax_open_kernel();
27736
27737 for (cur = ops->inherits; cur; cur = cur->inherits) {
27738 void **inherit = (void **)cur;
27739@@ -5835,8 +5836,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27740 if (IS_ERR(*pp))
27741 *pp = NULL;
27742
27743- ops->inherits = NULL;
27744+ *(struct ata_port_operations **)&ops->inherits = NULL;
27745
27746+ pax_close_kernel();
27747 spin_unlock(&lock);
27748 }
27749
27750diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27751index 3239517..343b5f6 100644
27752--- a/drivers/ata/pata_arasan_cf.c
27753+++ b/drivers/ata/pata_arasan_cf.c
27754@@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27755 /* Handle platform specific quirks */
27756 if (pdata->quirk) {
27757 if (pdata->quirk & CF_BROKEN_PIO) {
27758- ap->ops->set_piomode = NULL;
27759+ pax_open_kernel();
27760+ *(void **)&ap->ops->set_piomode = NULL;
27761+ pax_close_kernel();
27762 ap->pio_mask = 0;
27763 }
27764 if (pdata->quirk & CF_BROKEN_MWDMA)
27765diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27766index f9b983a..887b9d8 100644
27767--- a/drivers/atm/adummy.c
27768+++ b/drivers/atm/adummy.c
27769@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27770 vcc->pop(vcc, skb);
27771 else
27772 dev_kfree_skb_any(skb);
27773- atomic_inc(&vcc->stats->tx);
27774+ atomic_inc_unchecked(&vcc->stats->tx);
27775
27776 return 0;
27777 }
27778diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27779index f8f41e0..1f987dd 100644
27780--- a/drivers/atm/ambassador.c
27781+++ b/drivers/atm/ambassador.c
27782@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27783 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27784
27785 // VC layer stats
27786- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27787+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27788
27789 // free the descriptor
27790 kfree (tx_descr);
27791@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27792 dump_skb ("<<<", vc, skb);
27793
27794 // VC layer stats
27795- atomic_inc(&atm_vcc->stats->rx);
27796+ atomic_inc_unchecked(&atm_vcc->stats->rx);
27797 __net_timestamp(skb);
27798 // end of our responsibility
27799 atm_vcc->push (atm_vcc, skb);
27800@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27801 } else {
27802 PRINTK (KERN_INFO, "dropped over-size frame");
27803 // should we count this?
27804- atomic_inc(&atm_vcc->stats->rx_drop);
27805+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27806 }
27807
27808 } else {
27809@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27810 }
27811
27812 if (check_area (skb->data, skb->len)) {
27813- atomic_inc(&atm_vcc->stats->tx_err);
27814+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27815 return -ENOMEM; // ?
27816 }
27817
27818diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27819index b22d71c..d6e1049 100644
27820--- a/drivers/atm/atmtcp.c
27821+++ b/drivers/atm/atmtcp.c
27822@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27823 if (vcc->pop) vcc->pop(vcc,skb);
27824 else dev_kfree_skb(skb);
27825 if (dev_data) return 0;
27826- atomic_inc(&vcc->stats->tx_err);
27827+ atomic_inc_unchecked(&vcc->stats->tx_err);
27828 return -ENOLINK;
27829 }
27830 size = skb->len+sizeof(struct atmtcp_hdr);
27831@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27832 if (!new_skb) {
27833 if (vcc->pop) vcc->pop(vcc,skb);
27834 else dev_kfree_skb(skb);
27835- atomic_inc(&vcc->stats->tx_err);
27836+ atomic_inc_unchecked(&vcc->stats->tx_err);
27837 return -ENOBUFS;
27838 }
27839 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27840@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27841 if (vcc->pop) vcc->pop(vcc,skb);
27842 else dev_kfree_skb(skb);
27843 out_vcc->push(out_vcc,new_skb);
27844- atomic_inc(&vcc->stats->tx);
27845- atomic_inc(&out_vcc->stats->rx);
27846+ atomic_inc_unchecked(&vcc->stats->tx);
27847+ atomic_inc_unchecked(&out_vcc->stats->rx);
27848 return 0;
27849 }
27850
27851@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27852 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27853 read_unlock(&vcc_sklist_lock);
27854 if (!out_vcc) {
27855- atomic_inc(&vcc->stats->tx_err);
27856+ atomic_inc_unchecked(&vcc->stats->tx_err);
27857 goto done;
27858 }
27859 skb_pull(skb,sizeof(struct atmtcp_hdr));
27860@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27861 __net_timestamp(new_skb);
27862 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27863 out_vcc->push(out_vcc,new_skb);
27864- atomic_inc(&vcc->stats->tx);
27865- atomic_inc(&out_vcc->stats->rx);
27866+ atomic_inc_unchecked(&vcc->stats->tx);
27867+ atomic_inc_unchecked(&out_vcc->stats->rx);
27868 done:
27869 if (vcc->pop) vcc->pop(vcc,skb);
27870 else dev_kfree_skb(skb);
27871diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
27872index 2059ee4..faf51c7 100644
27873--- a/drivers/atm/eni.c
27874+++ b/drivers/atm/eni.c
27875@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27876 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27877 vcc->dev->number);
27878 length = 0;
27879- atomic_inc(&vcc->stats->rx_err);
27880+ atomic_inc_unchecked(&vcc->stats->rx_err);
27881 }
27882 else {
27883 length = ATM_CELL_SIZE-1; /* no HEC */
27884@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27885 size);
27886 }
27887 eff = length = 0;
27888- atomic_inc(&vcc->stats->rx_err);
27889+ atomic_inc_unchecked(&vcc->stats->rx_err);
27890 }
27891 else {
27892 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27893@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27894 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27895 vcc->dev->number,vcc->vci,length,size << 2,descr);
27896 length = eff = 0;
27897- atomic_inc(&vcc->stats->rx_err);
27898+ atomic_inc_unchecked(&vcc->stats->rx_err);
27899 }
27900 }
27901 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27902@@ -767,7 +767,7 @@ rx_dequeued++;
27903 vcc->push(vcc,skb);
27904 pushed++;
27905 }
27906- atomic_inc(&vcc->stats->rx);
27907+ atomic_inc_unchecked(&vcc->stats->rx);
27908 }
27909 wake_up(&eni_dev->rx_wait);
27910 }
27911@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
27912 PCI_DMA_TODEVICE);
27913 if (vcc->pop) vcc->pop(vcc,skb);
27914 else dev_kfree_skb_irq(skb);
27915- atomic_inc(&vcc->stats->tx);
27916+ atomic_inc_unchecked(&vcc->stats->tx);
27917 wake_up(&eni_dev->tx_wait);
27918 dma_complete++;
27919 }
27920@@ -1567,7 +1567,7 @@ tx_complete++;
27921 /*--------------------------------- entries ---------------------------------*/
27922
27923
27924-static const char *media_name[] __devinitdata = {
27925+static const char *media_name[] __devinitconst = {
27926 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
27927 "UTP", "05?", "06?", "07?", /* 4- 7 */
27928 "TAXI","09?", "10?", "11?", /* 8-11 */
27929diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
27930index 86fed1b..6dc4721 100644
27931--- a/drivers/atm/firestream.c
27932+++ b/drivers/atm/firestream.c
27933@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
27934 }
27935 }
27936
27937- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27938+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27939
27940 fs_dprintk (FS_DEBUG_TXMEM, "i");
27941 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
27942@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27943 #endif
27944 skb_put (skb, qe->p1 & 0xffff);
27945 ATM_SKB(skb)->vcc = atm_vcc;
27946- atomic_inc(&atm_vcc->stats->rx);
27947+ atomic_inc_unchecked(&atm_vcc->stats->rx);
27948 __net_timestamp(skb);
27949 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
27950 atm_vcc->push (atm_vcc, skb);
27951@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27952 kfree (pe);
27953 }
27954 if (atm_vcc)
27955- atomic_inc(&atm_vcc->stats->rx_drop);
27956+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27957 break;
27958 case 0x1f: /* Reassembly abort: no buffers. */
27959 /* Silently increment error counter. */
27960 if (atm_vcc)
27961- atomic_inc(&atm_vcc->stats->rx_drop);
27962+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27963 break;
27964 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
27965 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
27966diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
27967index 361f5ae..7fc552d 100644
27968--- a/drivers/atm/fore200e.c
27969+++ b/drivers/atm/fore200e.c
27970@@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
27971 #endif
27972 /* check error condition */
27973 if (*entry->status & STATUS_ERROR)
27974- atomic_inc(&vcc->stats->tx_err);
27975+ atomic_inc_unchecked(&vcc->stats->tx_err);
27976 else
27977- atomic_inc(&vcc->stats->tx);
27978+ atomic_inc_unchecked(&vcc->stats->tx);
27979 }
27980 }
27981
27982@@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27983 if (skb == NULL) {
27984 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
27985
27986- atomic_inc(&vcc->stats->rx_drop);
27987+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27988 return -ENOMEM;
27989 }
27990
27991@@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27992
27993 dev_kfree_skb_any(skb);
27994
27995- atomic_inc(&vcc->stats->rx_drop);
27996+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27997 return -ENOMEM;
27998 }
27999
28000 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28001
28002 vcc->push(vcc, skb);
28003- atomic_inc(&vcc->stats->rx);
28004+ atomic_inc_unchecked(&vcc->stats->rx);
28005
28006 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28007
28008@@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28009 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28010 fore200e->atm_dev->number,
28011 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28012- atomic_inc(&vcc->stats->rx_err);
28013+ atomic_inc_unchecked(&vcc->stats->rx_err);
28014 }
28015 }
28016
28017@@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28018 goto retry_here;
28019 }
28020
28021- atomic_inc(&vcc->stats->tx_err);
28022+ atomic_inc_unchecked(&vcc->stats->tx_err);
28023
28024 fore200e->tx_sat++;
28025 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28026diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28027index b182c2f..1c6fa8a 100644
28028--- a/drivers/atm/he.c
28029+++ b/drivers/atm/he.c
28030@@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28031
28032 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28033 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28034- atomic_inc(&vcc->stats->rx_drop);
28035+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28036 goto return_host_buffers;
28037 }
28038
28039@@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28040 RBRQ_LEN_ERR(he_dev->rbrq_head)
28041 ? "LEN_ERR" : "",
28042 vcc->vpi, vcc->vci);
28043- atomic_inc(&vcc->stats->rx_err);
28044+ atomic_inc_unchecked(&vcc->stats->rx_err);
28045 goto return_host_buffers;
28046 }
28047
28048@@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28049 vcc->push(vcc, skb);
28050 spin_lock(&he_dev->global_lock);
28051
28052- atomic_inc(&vcc->stats->rx);
28053+ atomic_inc_unchecked(&vcc->stats->rx);
28054
28055 return_host_buffers:
28056 ++pdus_assembled;
28057@@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28058 tpd->vcc->pop(tpd->vcc, tpd->skb);
28059 else
28060 dev_kfree_skb_any(tpd->skb);
28061- atomic_inc(&tpd->vcc->stats->tx_err);
28062+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28063 }
28064 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28065 return;
28066@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28067 vcc->pop(vcc, skb);
28068 else
28069 dev_kfree_skb_any(skb);
28070- atomic_inc(&vcc->stats->tx_err);
28071+ atomic_inc_unchecked(&vcc->stats->tx_err);
28072 return -EINVAL;
28073 }
28074
28075@@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28076 vcc->pop(vcc, skb);
28077 else
28078 dev_kfree_skb_any(skb);
28079- atomic_inc(&vcc->stats->tx_err);
28080+ atomic_inc_unchecked(&vcc->stats->tx_err);
28081 return -EINVAL;
28082 }
28083 #endif
28084@@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28085 vcc->pop(vcc, skb);
28086 else
28087 dev_kfree_skb_any(skb);
28088- atomic_inc(&vcc->stats->tx_err);
28089+ atomic_inc_unchecked(&vcc->stats->tx_err);
28090 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28091 return -ENOMEM;
28092 }
28093@@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28094 vcc->pop(vcc, skb);
28095 else
28096 dev_kfree_skb_any(skb);
28097- atomic_inc(&vcc->stats->tx_err);
28098+ atomic_inc_unchecked(&vcc->stats->tx_err);
28099 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28100 return -ENOMEM;
28101 }
28102@@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28103 __enqueue_tpd(he_dev, tpd, cid);
28104 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28105
28106- atomic_inc(&vcc->stats->tx);
28107+ atomic_inc_unchecked(&vcc->stats->tx);
28108
28109 return 0;
28110 }
28111diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28112index 75fd691..2d20b14 100644
28113--- a/drivers/atm/horizon.c
28114+++ b/drivers/atm/horizon.c
28115@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28116 {
28117 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28118 // VC layer stats
28119- atomic_inc(&vcc->stats->rx);
28120+ atomic_inc_unchecked(&vcc->stats->rx);
28121 __net_timestamp(skb);
28122 // end of our responsibility
28123 vcc->push (vcc, skb);
28124@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28125 dev->tx_iovec = NULL;
28126
28127 // VC layer stats
28128- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28129+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28130
28131 // free the skb
28132 hrz_kfree_skb (skb);
28133diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28134index 1c05212..c28e200 100644
28135--- a/drivers/atm/idt77252.c
28136+++ b/drivers/atm/idt77252.c
28137@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28138 else
28139 dev_kfree_skb(skb);
28140
28141- atomic_inc(&vcc->stats->tx);
28142+ atomic_inc_unchecked(&vcc->stats->tx);
28143 }
28144
28145 atomic_dec(&scq->used);
28146@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28147 if ((sb = dev_alloc_skb(64)) == NULL) {
28148 printk("%s: Can't allocate buffers for aal0.\n",
28149 card->name);
28150- atomic_add(i, &vcc->stats->rx_drop);
28151+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28152 break;
28153 }
28154 if (!atm_charge(vcc, sb->truesize)) {
28155 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28156 card->name);
28157- atomic_add(i - 1, &vcc->stats->rx_drop);
28158+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28159 dev_kfree_skb(sb);
28160 break;
28161 }
28162@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28163 ATM_SKB(sb)->vcc = vcc;
28164 __net_timestamp(sb);
28165 vcc->push(vcc, sb);
28166- atomic_inc(&vcc->stats->rx);
28167+ atomic_inc_unchecked(&vcc->stats->rx);
28168
28169 cell += ATM_CELL_PAYLOAD;
28170 }
28171@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28172 "(CDC: %08x)\n",
28173 card->name, len, rpp->len, readl(SAR_REG_CDC));
28174 recycle_rx_pool_skb(card, rpp);
28175- atomic_inc(&vcc->stats->rx_err);
28176+ atomic_inc_unchecked(&vcc->stats->rx_err);
28177 return;
28178 }
28179 if (stat & SAR_RSQE_CRC) {
28180 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28181 recycle_rx_pool_skb(card, rpp);
28182- atomic_inc(&vcc->stats->rx_err);
28183+ atomic_inc_unchecked(&vcc->stats->rx_err);
28184 return;
28185 }
28186 if (skb_queue_len(&rpp->queue) > 1) {
28187@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28188 RXPRINTK("%s: Can't alloc RX skb.\n",
28189 card->name);
28190 recycle_rx_pool_skb(card, rpp);
28191- atomic_inc(&vcc->stats->rx_err);
28192+ atomic_inc_unchecked(&vcc->stats->rx_err);
28193 return;
28194 }
28195 if (!atm_charge(vcc, skb->truesize)) {
28196@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28197 __net_timestamp(skb);
28198
28199 vcc->push(vcc, skb);
28200- atomic_inc(&vcc->stats->rx);
28201+ atomic_inc_unchecked(&vcc->stats->rx);
28202
28203 return;
28204 }
28205@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28206 __net_timestamp(skb);
28207
28208 vcc->push(vcc, skb);
28209- atomic_inc(&vcc->stats->rx);
28210+ atomic_inc_unchecked(&vcc->stats->rx);
28211
28212 if (skb->truesize > SAR_FB_SIZE_3)
28213 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28214@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28215 if (vcc->qos.aal != ATM_AAL0) {
28216 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28217 card->name, vpi, vci);
28218- atomic_inc(&vcc->stats->rx_drop);
28219+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28220 goto drop;
28221 }
28222
28223 if ((sb = dev_alloc_skb(64)) == NULL) {
28224 printk("%s: Can't allocate buffers for AAL0.\n",
28225 card->name);
28226- atomic_inc(&vcc->stats->rx_err);
28227+ atomic_inc_unchecked(&vcc->stats->rx_err);
28228 goto drop;
28229 }
28230
28231@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28232 ATM_SKB(sb)->vcc = vcc;
28233 __net_timestamp(sb);
28234 vcc->push(vcc, sb);
28235- atomic_inc(&vcc->stats->rx);
28236+ atomic_inc_unchecked(&vcc->stats->rx);
28237
28238 drop:
28239 skb_pull(queue, 64);
28240@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28241
28242 if (vc == NULL) {
28243 printk("%s: NULL connection in send().\n", card->name);
28244- atomic_inc(&vcc->stats->tx_err);
28245+ atomic_inc_unchecked(&vcc->stats->tx_err);
28246 dev_kfree_skb(skb);
28247 return -EINVAL;
28248 }
28249 if (!test_bit(VCF_TX, &vc->flags)) {
28250 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28251- atomic_inc(&vcc->stats->tx_err);
28252+ atomic_inc_unchecked(&vcc->stats->tx_err);
28253 dev_kfree_skb(skb);
28254 return -EINVAL;
28255 }
28256@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28257 break;
28258 default:
28259 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28260- atomic_inc(&vcc->stats->tx_err);
28261+ atomic_inc_unchecked(&vcc->stats->tx_err);
28262 dev_kfree_skb(skb);
28263 return -EINVAL;
28264 }
28265
28266 if (skb_shinfo(skb)->nr_frags != 0) {
28267 printk("%s: No scatter-gather yet.\n", card->name);
28268- atomic_inc(&vcc->stats->tx_err);
28269+ atomic_inc_unchecked(&vcc->stats->tx_err);
28270 dev_kfree_skb(skb);
28271 return -EINVAL;
28272 }
28273@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28274
28275 err = queue_skb(card, vc, skb, oam);
28276 if (err) {
28277- atomic_inc(&vcc->stats->tx_err);
28278+ atomic_inc_unchecked(&vcc->stats->tx_err);
28279 dev_kfree_skb(skb);
28280 return err;
28281 }
28282@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28283 skb = dev_alloc_skb(64);
28284 if (!skb) {
28285 printk("%s: Out of memory in send_oam().\n", card->name);
28286- atomic_inc(&vcc->stats->tx_err);
28287+ atomic_inc_unchecked(&vcc->stats->tx_err);
28288 return -ENOMEM;
28289 }
28290 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28291diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28292index d438601..8b98495 100644
28293--- a/drivers/atm/iphase.c
28294+++ b/drivers/atm/iphase.c
28295@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28296 status = (u_short) (buf_desc_ptr->desc_mode);
28297 if (status & (RX_CER | RX_PTE | RX_OFL))
28298 {
28299- atomic_inc(&vcc->stats->rx_err);
28300+ atomic_inc_unchecked(&vcc->stats->rx_err);
28301 IF_ERR(printk("IA: bad packet, dropping it");)
28302 if (status & RX_CER) {
28303 IF_ERR(printk(" cause: packet CRC error\n");)
28304@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28305 len = dma_addr - buf_addr;
28306 if (len > iadev->rx_buf_sz) {
28307 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28308- atomic_inc(&vcc->stats->rx_err);
28309+ atomic_inc_unchecked(&vcc->stats->rx_err);
28310 goto out_free_desc;
28311 }
28312
28313@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28314 ia_vcc = INPH_IA_VCC(vcc);
28315 if (ia_vcc == NULL)
28316 {
28317- atomic_inc(&vcc->stats->rx_err);
28318+ atomic_inc_unchecked(&vcc->stats->rx_err);
28319 atm_return(vcc, skb->truesize);
28320 dev_kfree_skb_any(skb);
28321 goto INCR_DLE;
28322@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28323 if ((length > iadev->rx_buf_sz) || (length >
28324 (skb->len - sizeof(struct cpcs_trailer))))
28325 {
28326- atomic_inc(&vcc->stats->rx_err);
28327+ atomic_inc_unchecked(&vcc->stats->rx_err);
28328 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28329 length, skb->len);)
28330 atm_return(vcc, skb->truesize);
28331@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28332
28333 IF_RX(printk("rx_dle_intr: skb push");)
28334 vcc->push(vcc,skb);
28335- atomic_inc(&vcc->stats->rx);
28336+ atomic_inc_unchecked(&vcc->stats->rx);
28337 iadev->rx_pkt_cnt++;
28338 }
28339 INCR_DLE:
28340@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28341 {
28342 struct k_sonet_stats *stats;
28343 stats = &PRIV(_ia_dev[board])->sonet_stats;
28344- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28345- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28346- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28347- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28348- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28349- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28350- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28351- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28352- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28353+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28354+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28355+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28356+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28357+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28358+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28359+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28360+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28361+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28362 }
28363 ia_cmds.status = 0;
28364 break;
28365@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28366 if ((desc == 0) || (desc > iadev->num_tx_desc))
28367 {
28368 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28369- atomic_inc(&vcc->stats->tx);
28370+ atomic_inc_unchecked(&vcc->stats->tx);
28371 if (vcc->pop)
28372 vcc->pop(vcc, skb);
28373 else
28374@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28375 ATM_DESC(skb) = vcc->vci;
28376 skb_queue_tail(&iadev->tx_dma_q, skb);
28377
28378- atomic_inc(&vcc->stats->tx);
28379+ atomic_inc_unchecked(&vcc->stats->tx);
28380 iadev->tx_pkt_cnt++;
28381 /* Increment transaction counter */
28382 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28383
28384 #if 0
28385 /* add flow control logic */
28386- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28387+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28388 if (iavcc->vc_desc_cnt > 10) {
28389 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28390 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28391diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28392index 68c7588..7036683 100644
28393--- a/drivers/atm/lanai.c
28394+++ b/drivers/atm/lanai.c
28395@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28396 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28397 lanai_endtx(lanai, lvcc);
28398 lanai_free_skb(lvcc->tx.atmvcc, skb);
28399- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28400+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28401 }
28402
28403 /* Try to fill the buffer - don't call unless there is backlog */
28404@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28405 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28406 __net_timestamp(skb);
28407 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28408- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28409+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28410 out:
28411 lvcc->rx.buf.ptr = end;
28412 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28413@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28414 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28415 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28416 lanai->stats.service_rxnotaal5++;
28417- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28418+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28419 return 0;
28420 }
28421 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28422@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28423 int bytes;
28424 read_unlock(&vcc_sklist_lock);
28425 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28426- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28427+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28428 lvcc->stats.x.aal5.service_trash++;
28429 bytes = (SERVICE_GET_END(s) * 16) -
28430 (((unsigned long) lvcc->rx.buf.ptr) -
28431@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28432 }
28433 if (s & SERVICE_STREAM) {
28434 read_unlock(&vcc_sklist_lock);
28435- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28436+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28437 lvcc->stats.x.aal5.service_stream++;
28438 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28439 "PDU on VCI %d!\n", lanai->number, vci);
28440@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28441 return 0;
28442 }
28443 DPRINTK("got rx crc error on vci %d\n", vci);
28444- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28445+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28446 lvcc->stats.x.aal5.service_rxcrc++;
28447 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28448 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28449diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28450index 1c70c45..300718d 100644
28451--- a/drivers/atm/nicstar.c
28452+++ b/drivers/atm/nicstar.c
28453@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28454 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28455 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28456 card->index);
28457- atomic_inc(&vcc->stats->tx_err);
28458+ atomic_inc_unchecked(&vcc->stats->tx_err);
28459 dev_kfree_skb_any(skb);
28460 return -EINVAL;
28461 }
28462@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28463 if (!vc->tx) {
28464 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28465 card->index);
28466- atomic_inc(&vcc->stats->tx_err);
28467+ atomic_inc_unchecked(&vcc->stats->tx_err);
28468 dev_kfree_skb_any(skb);
28469 return -EINVAL;
28470 }
28471@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28472 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28473 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28474 card->index);
28475- atomic_inc(&vcc->stats->tx_err);
28476+ atomic_inc_unchecked(&vcc->stats->tx_err);
28477 dev_kfree_skb_any(skb);
28478 return -EINVAL;
28479 }
28480
28481 if (skb_shinfo(skb)->nr_frags != 0) {
28482 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28483- atomic_inc(&vcc->stats->tx_err);
28484+ atomic_inc_unchecked(&vcc->stats->tx_err);
28485 dev_kfree_skb_any(skb);
28486 return -EINVAL;
28487 }
28488@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28489 }
28490
28491 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28492- atomic_inc(&vcc->stats->tx_err);
28493+ atomic_inc_unchecked(&vcc->stats->tx_err);
28494 dev_kfree_skb_any(skb);
28495 return -EIO;
28496 }
28497- atomic_inc(&vcc->stats->tx);
28498+ atomic_inc_unchecked(&vcc->stats->tx);
28499
28500 return 0;
28501 }
28502@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28503 printk
28504 ("nicstar%d: Can't allocate buffers for aal0.\n",
28505 card->index);
28506- atomic_add(i, &vcc->stats->rx_drop);
28507+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28508 break;
28509 }
28510 if (!atm_charge(vcc, sb->truesize)) {
28511 RXPRINTK
28512 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28513 card->index);
28514- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28515+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28516 dev_kfree_skb_any(sb);
28517 break;
28518 }
28519@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28520 ATM_SKB(sb)->vcc = vcc;
28521 __net_timestamp(sb);
28522 vcc->push(vcc, sb);
28523- atomic_inc(&vcc->stats->rx);
28524+ atomic_inc_unchecked(&vcc->stats->rx);
28525 cell += ATM_CELL_PAYLOAD;
28526 }
28527
28528@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28529 if (iovb == NULL) {
28530 printk("nicstar%d: Out of iovec buffers.\n",
28531 card->index);
28532- atomic_inc(&vcc->stats->rx_drop);
28533+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28534 recycle_rx_buf(card, skb);
28535 return;
28536 }
28537@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28538 small or large buffer itself. */
28539 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28540 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28541- atomic_inc(&vcc->stats->rx_err);
28542+ atomic_inc_unchecked(&vcc->stats->rx_err);
28543 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28544 NS_MAX_IOVECS);
28545 NS_PRV_IOVCNT(iovb) = 0;
28546@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28547 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28548 card->index);
28549 which_list(card, skb);
28550- atomic_inc(&vcc->stats->rx_err);
28551+ atomic_inc_unchecked(&vcc->stats->rx_err);
28552 recycle_rx_buf(card, skb);
28553 vc->rx_iov = NULL;
28554 recycle_iov_buf(card, iovb);
28555@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28556 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28557 card->index);
28558 which_list(card, skb);
28559- atomic_inc(&vcc->stats->rx_err);
28560+ atomic_inc_unchecked(&vcc->stats->rx_err);
28561 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28562 NS_PRV_IOVCNT(iovb));
28563 vc->rx_iov = NULL;
28564@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28565 printk(" - PDU size mismatch.\n");
28566 else
28567 printk(".\n");
28568- atomic_inc(&vcc->stats->rx_err);
28569+ atomic_inc_unchecked(&vcc->stats->rx_err);
28570 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28571 NS_PRV_IOVCNT(iovb));
28572 vc->rx_iov = NULL;
28573@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28574 /* skb points to a small buffer */
28575 if (!atm_charge(vcc, skb->truesize)) {
28576 push_rxbufs(card, skb);
28577- atomic_inc(&vcc->stats->rx_drop);
28578+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28579 } else {
28580 skb_put(skb, len);
28581 dequeue_sm_buf(card, skb);
28582@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28583 ATM_SKB(skb)->vcc = vcc;
28584 __net_timestamp(skb);
28585 vcc->push(vcc, skb);
28586- atomic_inc(&vcc->stats->rx);
28587+ atomic_inc_unchecked(&vcc->stats->rx);
28588 }
28589 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28590 struct sk_buff *sb;
28591@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28592 if (len <= NS_SMBUFSIZE) {
28593 if (!atm_charge(vcc, sb->truesize)) {
28594 push_rxbufs(card, sb);
28595- atomic_inc(&vcc->stats->rx_drop);
28596+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28597 } else {
28598 skb_put(sb, len);
28599 dequeue_sm_buf(card, sb);
28600@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28601 ATM_SKB(sb)->vcc = vcc;
28602 __net_timestamp(sb);
28603 vcc->push(vcc, sb);
28604- atomic_inc(&vcc->stats->rx);
28605+ atomic_inc_unchecked(&vcc->stats->rx);
28606 }
28607
28608 push_rxbufs(card, skb);
28609@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28610
28611 if (!atm_charge(vcc, skb->truesize)) {
28612 push_rxbufs(card, skb);
28613- atomic_inc(&vcc->stats->rx_drop);
28614+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28615 } else {
28616 dequeue_lg_buf(card, skb);
28617 #ifdef NS_USE_DESTRUCTORS
28618@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28619 ATM_SKB(skb)->vcc = vcc;
28620 __net_timestamp(skb);
28621 vcc->push(vcc, skb);
28622- atomic_inc(&vcc->stats->rx);
28623+ atomic_inc_unchecked(&vcc->stats->rx);
28624 }
28625
28626 push_rxbufs(card, sb);
28627@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28628 printk
28629 ("nicstar%d: Out of huge buffers.\n",
28630 card->index);
28631- atomic_inc(&vcc->stats->rx_drop);
28632+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28633 recycle_iovec_rx_bufs(card,
28634 (struct iovec *)
28635 iovb->data,
28636@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28637 card->hbpool.count++;
28638 } else
28639 dev_kfree_skb_any(hb);
28640- atomic_inc(&vcc->stats->rx_drop);
28641+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28642 } else {
28643 /* Copy the small buffer to the huge buffer */
28644 sb = (struct sk_buff *)iov->iov_base;
28645@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28646 #endif /* NS_USE_DESTRUCTORS */
28647 __net_timestamp(hb);
28648 vcc->push(vcc, hb);
28649- atomic_inc(&vcc->stats->rx);
28650+ atomic_inc_unchecked(&vcc->stats->rx);
28651 }
28652 }
28653
28654diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28655index 9851093..adb2b1e 100644
28656--- a/drivers/atm/solos-pci.c
28657+++ b/drivers/atm/solos-pci.c
28658@@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28659 }
28660 atm_charge(vcc, skb->truesize);
28661 vcc->push(vcc, skb);
28662- atomic_inc(&vcc->stats->rx);
28663+ atomic_inc_unchecked(&vcc->stats->rx);
28664 break;
28665
28666 case PKT_STATUS:
28667@@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28668 vcc = SKB_CB(oldskb)->vcc;
28669
28670 if (vcc) {
28671- atomic_inc(&vcc->stats->tx);
28672+ atomic_inc_unchecked(&vcc->stats->tx);
28673 solos_pop(vcc, oldskb);
28674 } else
28675 dev_kfree_skb_irq(oldskb);
28676diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28677index 0215934..ce9f5b1 100644
28678--- a/drivers/atm/suni.c
28679+++ b/drivers/atm/suni.c
28680@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28681
28682
28683 #define ADD_LIMITED(s,v) \
28684- atomic_add((v),&stats->s); \
28685- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28686+ atomic_add_unchecked((v),&stats->s); \
28687+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28688
28689
28690 static void suni_hz(unsigned long from_timer)
28691diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28692index 5120a96..e2572bd 100644
28693--- a/drivers/atm/uPD98402.c
28694+++ b/drivers/atm/uPD98402.c
28695@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28696 struct sonet_stats tmp;
28697 int error = 0;
28698
28699- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28700+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28701 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28702 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28703 if (zero && !error) {
28704@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28705
28706
28707 #define ADD_LIMITED(s,v) \
28708- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28709- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28710- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28711+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28712+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28713+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28714
28715
28716 static void stat_event(struct atm_dev *dev)
28717@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28718 if (reason & uPD98402_INT_PFM) stat_event(dev);
28719 if (reason & uPD98402_INT_PCO) {
28720 (void) GET(PCOCR); /* clear interrupt cause */
28721- atomic_add(GET(HECCT),
28722+ atomic_add_unchecked(GET(HECCT),
28723 &PRIV(dev)->sonet_stats.uncorr_hcs);
28724 }
28725 if ((reason & uPD98402_INT_RFO) &&
28726@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28727 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28728 uPD98402_INT_LOS),PIMR); /* enable them */
28729 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28730- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28731- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28732- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28733+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28734+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28735+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28736 return 0;
28737 }
28738
28739diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28740index abe4e20..83c4727 100644
28741--- a/drivers/atm/zatm.c
28742+++ b/drivers/atm/zatm.c
28743@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28744 }
28745 if (!size) {
28746 dev_kfree_skb_irq(skb);
28747- if (vcc) atomic_inc(&vcc->stats->rx_err);
28748+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28749 continue;
28750 }
28751 if (!atm_charge(vcc,skb->truesize)) {
28752@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28753 skb->len = size;
28754 ATM_SKB(skb)->vcc = vcc;
28755 vcc->push(vcc,skb);
28756- atomic_inc(&vcc->stats->rx);
28757+ atomic_inc_unchecked(&vcc->stats->rx);
28758 }
28759 zout(pos & 0xffff,MTA(mbx));
28760 #if 0 /* probably a stupid idea */
28761@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28762 skb_queue_head(&zatm_vcc->backlog,skb);
28763 break;
28764 }
28765- atomic_inc(&vcc->stats->tx);
28766+ atomic_inc_unchecked(&vcc->stats->tx);
28767 wake_up(&zatm_vcc->tx_wait);
28768 }
28769
28770diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28771index 8493536..31adee0 100644
28772--- a/drivers/base/devtmpfs.c
28773+++ b/drivers/base/devtmpfs.c
28774@@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28775 if (!thread)
28776 return 0;
28777
28778- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28779+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28780 if (err)
28781 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28782 else
28783diff --git a/drivers/base/node.c b/drivers/base/node.c
28784index 90aa2a1..af1a177 100644
28785--- a/drivers/base/node.c
28786+++ b/drivers/base/node.c
28787@@ -592,11 +592,9 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
28788 {
28789 int n;
28790
28791- n = nodelist_scnprintf(buf, PAGE_SIZE, node_states[state]);
28792- if (n > 0 && PAGE_SIZE > n + 1) {
28793- *(buf + n++) = '\n';
28794- *(buf + n++) = '\0';
28795- }
28796+ n = nodelist_scnprintf(buf, PAGE_SIZE-2, node_states[state]);
28797+ buf[n++] = '\n';
28798+ buf[n] = '\0';
28799 return n;
28800 }
28801
28802diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28803index 2a3e581..3d6a73f 100644
28804--- a/drivers/base/power/wakeup.c
28805+++ b/drivers/base/power/wakeup.c
28806@@ -30,14 +30,14 @@ bool events_check_enabled;
28807 * They need to be modified together atomically, so it's better to use one
28808 * atomic variable to hold them both.
28809 */
28810-static atomic_t combined_event_count = ATOMIC_INIT(0);
28811+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28812
28813 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28814 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28815
28816 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28817 {
28818- unsigned int comb = atomic_read(&combined_event_count);
28819+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
28820
28821 *cnt = (comb >> IN_PROGRESS_BITS);
28822 *inpr = comb & MAX_IN_PROGRESS;
28823@@ -379,7 +379,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28824 ws->last_time = ktime_get();
28825
28826 /* Increment the counter of events in progress. */
28827- atomic_inc(&combined_event_count);
28828+ atomic_inc_unchecked(&combined_event_count);
28829 }
28830
28831 /**
28832@@ -475,7 +475,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28833 * Increment the counter of registered wakeup events and decrement the
28834 * couter of wakeup events in progress simultaneously.
28835 */
28836- atomic_add(MAX_IN_PROGRESS, &combined_event_count);
28837+ atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28838 }
28839
28840 /**
28841diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28842index b0f553b..77b928b 100644
28843--- a/drivers/block/cciss.c
28844+++ b/drivers/block/cciss.c
28845@@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28846 int err;
28847 u32 cp;
28848
28849+ memset(&arg64, 0, sizeof(arg64));
28850+
28851 err = 0;
28852 err |=
28853 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28854@@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28855 while (!list_empty(&h->reqQ)) {
28856 c = list_entry(h->reqQ.next, CommandList_struct, list);
28857 /* can't do anything if fifo is full */
28858- if ((h->access.fifo_full(h))) {
28859+ if ((h->access->fifo_full(h))) {
28860 dev_warn(&h->pdev->dev, "fifo full\n");
28861 break;
28862 }
28863@@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
28864 h->Qdepth--;
28865
28866 /* Tell the controller execute command */
28867- h->access.submit_command(h, c);
28868+ h->access->submit_command(h, c);
28869
28870 /* Put job onto the completed Q */
28871 addQ(&h->cmpQ, c);
28872@@ -3443,17 +3445,17 @@ startio:
28873
28874 static inline unsigned long get_next_completion(ctlr_info_t *h)
28875 {
28876- return h->access.command_completed(h);
28877+ return h->access->command_completed(h);
28878 }
28879
28880 static inline int interrupt_pending(ctlr_info_t *h)
28881 {
28882- return h->access.intr_pending(h);
28883+ return h->access->intr_pending(h);
28884 }
28885
28886 static inline long interrupt_not_for_us(ctlr_info_t *h)
28887 {
28888- return ((h->access.intr_pending(h) == 0) ||
28889+ return ((h->access->intr_pending(h) == 0) ||
28890 (h->interrupts_enabled == 0));
28891 }
28892
28893@@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
28894 u32 a;
28895
28896 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
28897- return h->access.command_completed(h);
28898+ return h->access->command_completed(h);
28899
28900 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
28901 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
28902@@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
28903 trans_support & CFGTBL_Trans_use_short_tags);
28904
28905 /* Change the access methods to the performant access methods */
28906- h->access = SA5_performant_access;
28907+ h->access = &SA5_performant_access;
28908 h->transMethod = CFGTBL_Trans_Performant;
28909
28910 return;
28911@@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
28912 if (prod_index < 0)
28913 return -ENODEV;
28914 h->product_name = products[prod_index].product_name;
28915- h->access = *(products[prod_index].access);
28916+ h->access = products[prod_index].access;
28917
28918 if (cciss_board_disabled(h)) {
28919 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
28920@@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
28921 }
28922
28923 /* make sure the board interrupts are off */
28924- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28925+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28926 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
28927 if (rc)
28928 goto clean2;
28929@@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
28930 * fake ones to scoop up any residual completions.
28931 */
28932 spin_lock_irqsave(&h->lock, flags);
28933- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28934+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28935 spin_unlock_irqrestore(&h->lock, flags);
28936 free_irq(h->intr[h->intr_mode], h);
28937 rc = cciss_request_irq(h, cciss_msix_discard_completions,
28938@@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
28939 dev_info(&h->pdev->dev, "Board READY.\n");
28940 dev_info(&h->pdev->dev,
28941 "Waiting for stale completions to drain.\n");
28942- h->access.set_intr_mask(h, CCISS_INTR_ON);
28943+ h->access->set_intr_mask(h, CCISS_INTR_ON);
28944 msleep(10000);
28945- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28946+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28947
28948 rc = controller_reset_failed(h->cfgtable);
28949 if (rc)
28950@@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
28951 cciss_scsi_setup(h);
28952
28953 /* Turn the interrupts on so we can service requests */
28954- h->access.set_intr_mask(h, CCISS_INTR_ON);
28955+ h->access->set_intr_mask(h, CCISS_INTR_ON);
28956
28957 /* Get the firmware version */
28958 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
28959@@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
28960 kfree(flush_buf);
28961 if (return_code != IO_OK)
28962 dev_warn(&h->pdev->dev, "Error flushing cache\n");
28963- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28964+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28965 free_irq(h->intr[h->intr_mode], h);
28966 }
28967
28968diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
28969index 7fda30e..eb5dfe0 100644
28970--- a/drivers/block/cciss.h
28971+++ b/drivers/block/cciss.h
28972@@ -101,7 +101,7 @@ struct ctlr_info
28973 /* information about each logical volume */
28974 drive_info_struct *drv[CISS_MAX_LUN];
28975
28976- struct access_method access;
28977+ struct access_method *access;
28978
28979 /* queue and queue Info */
28980 struct list_head reqQ;
28981diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
28982index 9125bbe..eede5c8 100644
28983--- a/drivers/block/cpqarray.c
28984+++ b/drivers/block/cpqarray.c
28985@@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28986 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
28987 goto Enomem4;
28988 }
28989- hba[i]->access.set_intr_mask(hba[i], 0);
28990+ hba[i]->access->set_intr_mask(hba[i], 0);
28991 if (request_irq(hba[i]->intr, do_ida_intr,
28992 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
28993 {
28994@@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28995 add_timer(&hba[i]->timer);
28996
28997 /* Enable IRQ now that spinlock and rate limit timer are set up */
28998- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28999+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29000
29001 for(j=0; j<NWD; j++) {
29002 struct gendisk *disk = ida_gendisk[i][j];
29003@@ -694,7 +694,7 @@ DBGINFO(
29004 for(i=0; i<NR_PRODUCTS; i++) {
29005 if (board_id == products[i].board_id) {
29006 c->product_name = products[i].product_name;
29007- c->access = *(products[i].access);
29008+ c->access = products[i].access;
29009 break;
29010 }
29011 }
29012@@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29013 hba[ctlr]->intr = intr;
29014 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29015 hba[ctlr]->product_name = products[j].product_name;
29016- hba[ctlr]->access = *(products[j].access);
29017+ hba[ctlr]->access = products[j].access;
29018 hba[ctlr]->ctlr = ctlr;
29019 hba[ctlr]->board_id = board_id;
29020 hba[ctlr]->pci_dev = NULL; /* not PCI */
29021@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29022
29023 while((c = h->reqQ) != NULL) {
29024 /* Can't do anything if we're busy */
29025- if (h->access.fifo_full(h) == 0)
29026+ if (h->access->fifo_full(h) == 0)
29027 return;
29028
29029 /* Get the first entry from the request Q */
29030@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29031 h->Qdepth--;
29032
29033 /* Tell the controller to do our bidding */
29034- h->access.submit_command(h, c);
29035+ h->access->submit_command(h, c);
29036
29037 /* Get onto the completion Q */
29038 addQ(&h->cmpQ, c);
29039@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29040 unsigned long flags;
29041 __u32 a,a1;
29042
29043- istat = h->access.intr_pending(h);
29044+ istat = h->access->intr_pending(h);
29045 /* Is this interrupt for us? */
29046 if (istat == 0)
29047 return IRQ_NONE;
29048@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29049 */
29050 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29051 if (istat & FIFO_NOT_EMPTY) {
29052- while((a = h->access.command_completed(h))) {
29053+ while((a = h->access->command_completed(h))) {
29054 a1 = a; a &= ~3;
29055 if ((c = h->cmpQ) == NULL)
29056 {
29057@@ -1449,11 +1449,11 @@ static int sendcmd(
29058 /*
29059 * Disable interrupt
29060 */
29061- info_p->access.set_intr_mask(info_p, 0);
29062+ info_p->access->set_intr_mask(info_p, 0);
29063 /* Make sure there is room in the command FIFO */
29064 /* Actually it should be completely empty at this time. */
29065 for (i = 200000; i > 0; i--) {
29066- temp = info_p->access.fifo_full(info_p);
29067+ temp = info_p->access->fifo_full(info_p);
29068 if (temp != 0) {
29069 break;
29070 }
29071@@ -1466,7 +1466,7 @@ DBG(
29072 /*
29073 * Send the cmd
29074 */
29075- info_p->access.submit_command(info_p, c);
29076+ info_p->access->submit_command(info_p, c);
29077 complete = pollcomplete(ctlr);
29078
29079 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29080@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29081 * we check the new geometry. Then turn interrupts back on when
29082 * we're done.
29083 */
29084- host->access.set_intr_mask(host, 0);
29085+ host->access->set_intr_mask(host, 0);
29086 getgeometry(ctlr);
29087- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29088+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29089
29090 for(i=0; i<NWD; i++) {
29091 struct gendisk *disk = ida_gendisk[ctlr][i];
29092@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29093 /* Wait (up to 2 seconds) for a command to complete */
29094
29095 for (i = 200000; i > 0; i--) {
29096- done = hba[ctlr]->access.command_completed(hba[ctlr]);
29097+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
29098 if (done == 0) {
29099 udelay(10); /* a short fixed delay */
29100 } else
29101diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29102index be73e9d..7fbf140 100644
29103--- a/drivers/block/cpqarray.h
29104+++ b/drivers/block/cpqarray.h
29105@@ -99,7 +99,7 @@ struct ctlr_info {
29106 drv_info_t drv[NWD];
29107 struct proc_dir_entry *proc;
29108
29109- struct access_method access;
29110+ struct access_method *access;
29111
29112 cmdlist_t *reqQ;
29113 cmdlist_t *cmpQ;
29114diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29115index 8d68056..e67050f 100644
29116--- a/drivers/block/drbd/drbd_int.h
29117+++ b/drivers/block/drbd/drbd_int.h
29118@@ -736,7 +736,7 @@ struct drbd_request;
29119 struct drbd_epoch {
29120 struct list_head list;
29121 unsigned int barrier_nr;
29122- atomic_t epoch_size; /* increased on every request added. */
29123+ atomic_unchecked_t epoch_size; /* increased on every request added. */
29124 atomic_t active; /* increased on every req. added, and dec on every finished. */
29125 unsigned long flags;
29126 };
29127@@ -1108,7 +1108,7 @@ struct drbd_conf {
29128 void *int_dig_in;
29129 void *int_dig_vv;
29130 wait_queue_head_t seq_wait;
29131- atomic_t packet_seq;
29132+ atomic_unchecked_t packet_seq;
29133 unsigned int peer_seq;
29134 spinlock_t peer_seq_lock;
29135 unsigned int minor;
29136@@ -1617,30 +1617,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29137
29138 static inline void drbd_tcp_cork(struct socket *sock)
29139 {
29140- int __user val = 1;
29141+ int val = 1;
29142 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29143- (char __user *)&val, sizeof(val));
29144+ (char __force_user *)&val, sizeof(val));
29145 }
29146
29147 static inline void drbd_tcp_uncork(struct socket *sock)
29148 {
29149- int __user val = 0;
29150+ int val = 0;
29151 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29152- (char __user *)&val, sizeof(val));
29153+ (char __force_user *)&val, sizeof(val));
29154 }
29155
29156 static inline void drbd_tcp_nodelay(struct socket *sock)
29157 {
29158- int __user val = 1;
29159+ int val = 1;
29160 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29161- (char __user *)&val, sizeof(val));
29162+ (char __force_user *)&val, sizeof(val));
29163 }
29164
29165 static inline void drbd_tcp_quickack(struct socket *sock)
29166 {
29167- int __user val = 2;
29168+ int val = 2;
29169 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29170- (char __user *)&val, sizeof(val));
29171+ (char __force_user *)&val, sizeof(val));
29172 }
29173
29174 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29175diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29176index 211fc44..c5116f1 100644
29177--- a/drivers/block/drbd/drbd_main.c
29178+++ b/drivers/block/drbd/drbd_main.c
29179@@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29180 p.sector = sector;
29181 p.block_id = block_id;
29182 p.blksize = blksize;
29183- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29184+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29185
29186 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29187 return false;
29188@@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29189 p.sector = cpu_to_be64(req->sector);
29190 p.block_id = (unsigned long)req;
29191 p.seq_num = cpu_to_be32(req->seq_num =
29192- atomic_add_return(1, &mdev->packet_seq));
29193+ atomic_add_return_unchecked(1, &mdev->packet_seq));
29194
29195 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29196
29197@@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29198 atomic_set(&mdev->unacked_cnt, 0);
29199 atomic_set(&mdev->local_cnt, 0);
29200 atomic_set(&mdev->net_cnt, 0);
29201- atomic_set(&mdev->packet_seq, 0);
29202+ atomic_set_unchecked(&mdev->packet_seq, 0);
29203 atomic_set(&mdev->pp_in_use, 0);
29204 atomic_set(&mdev->pp_in_use_by_net, 0);
29205 atomic_set(&mdev->rs_sect_in, 0);
29206@@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29207 mdev->receiver.t_state);
29208
29209 /* no need to lock it, I'm the only thread alive */
29210- if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29211- dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29212+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29213+ dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29214 mdev->al_writ_cnt =
29215 mdev->bm_writ_cnt =
29216 mdev->read_cnt =
29217diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29218index 946166e..356b39a 100644
29219--- a/drivers/block/drbd/drbd_nl.c
29220+++ b/drivers/block/drbd/drbd_nl.c
29221@@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29222 module_put(THIS_MODULE);
29223 }
29224
29225-static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29226+static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29227
29228 static unsigned short *
29229 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29230@@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29231 cn_reply->id.idx = CN_IDX_DRBD;
29232 cn_reply->id.val = CN_VAL_DRBD;
29233
29234- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29235+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29236 cn_reply->ack = 0; /* not used here. */
29237 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29238 (int)((char *)tl - (char *)reply->tag_list);
29239@@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29240 cn_reply->id.idx = CN_IDX_DRBD;
29241 cn_reply->id.val = CN_VAL_DRBD;
29242
29243- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29244+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29245 cn_reply->ack = 0; /* not used here. */
29246 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29247 (int)((char *)tl - (char *)reply->tag_list);
29248@@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29249 cn_reply->id.idx = CN_IDX_DRBD;
29250 cn_reply->id.val = CN_VAL_DRBD;
29251
29252- cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29253+ cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29254 cn_reply->ack = 0; // not used here.
29255 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29256 (int)((char*)tl - (char*)reply->tag_list);
29257@@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29258 cn_reply->id.idx = CN_IDX_DRBD;
29259 cn_reply->id.val = CN_VAL_DRBD;
29260
29261- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29262+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29263 cn_reply->ack = 0; /* not used here. */
29264 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29265 (int)((char *)tl - (char *)reply->tag_list);
29266diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29267index 43beaca..4a5b1dd 100644
29268--- a/drivers/block/drbd/drbd_receiver.c
29269+++ b/drivers/block/drbd/drbd_receiver.c
29270@@ -894,7 +894,7 @@ retry:
29271 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29272 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29273
29274- atomic_set(&mdev->packet_seq, 0);
29275+ atomic_set_unchecked(&mdev->packet_seq, 0);
29276 mdev->peer_seq = 0;
29277
29278 drbd_thread_start(&mdev->asender);
29279@@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29280 do {
29281 next_epoch = NULL;
29282
29283- epoch_size = atomic_read(&epoch->epoch_size);
29284+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29285
29286 switch (ev & ~EV_CLEANUP) {
29287 case EV_PUT:
29288@@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29289 rv = FE_DESTROYED;
29290 } else {
29291 epoch->flags = 0;
29292- atomic_set(&epoch->epoch_size, 0);
29293+ atomic_set_unchecked(&epoch->epoch_size, 0);
29294 /* atomic_set(&epoch->active, 0); is already zero */
29295 if (rv == FE_STILL_LIVE)
29296 rv = FE_RECYCLED;
29297@@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29298 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29299 drbd_flush(mdev);
29300
29301- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29302+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29303 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29304 if (epoch)
29305 break;
29306 }
29307
29308 epoch = mdev->current_epoch;
29309- wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29310+ wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29311
29312 D_ASSERT(atomic_read(&epoch->active) == 0);
29313 D_ASSERT(epoch->flags == 0);
29314@@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29315 }
29316
29317 epoch->flags = 0;
29318- atomic_set(&epoch->epoch_size, 0);
29319+ atomic_set_unchecked(&epoch->epoch_size, 0);
29320 atomic_set(&epoch->active, 0);
29321
29322 spin_lock(&mdev->epoch_lock);
29323- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29324+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29325 list_add(&epoch->list, &mdev->current_epoch->list);
29326 mdev->current_epoch = epoch;
29327 mdev->epochs++;
29328@@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29329 spin_unlock(&mdev->peer_seq_lock);
29330
29331 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29332- atomic_inc(&mdev->current_epoch->epoch_size);
29333+ atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29334 return drbd_drain_block(mdev, data_size);
29335 }
29336
29337@@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29338
29339 spin_lock(&mdev->epoch_lock);
29340 e->epoch = mdev->current_epoch;
29341- atomic_inc(&e->epoch->epoch_size);
29342+ atomic_inc_unchecked(&e->epoch->epoch_size);
29343 atomic_inc(&e->epoch->active);
29344 spin_unlock(&mdev->epoch_lock);
29345
29346@@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29347 D_ASSERT(list_empty(&mdev->done_ee));
29348
29349 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29350- atomic_set(&mdev->current_epoch->epoch_size, 0);
29351+ atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29352 D_ASSERT(list_empty(&mdev->current_epoch->list));
29353 }
29354
29355diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29356index bbca966..65e37dd 100644
29357--- a/drivers/block/loop.c
29358+++ b/drivers/block/loop.c
29359@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29360 mm_segment_t old_fs = get_fs();
29361
29362 set_fs(get_ds());
29363- bw = file->f_op->write(file, buf, len, &pos);
29364+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29365 set_fs(old_fs);
29366 if (likely(bw == len))
29367 return 0;
29368diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29369index ee94686..3e09ad3 100644
29370--- a/drivers/char/Kconfig
29371+++ b/drivers/char/Kconfig
29372@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29373
29374 config DEVKMEM
29375 bool "/dev/kmem virtual device support"
29376- default y
29377+ default n
29378+ depends on !GRKERNSEC_KMEM
29379 help
29380 Say Y here if you want to support the /dev/kmem device. The
29381 /dev/kmem device is rarely used, but can be used for certain
29382@@ -581,6 +582,7 @@ config DEVPORT
29383 bool
29384 depends on !M68K
29385 depends on ISA || PCI
29386+ depends on !GRKERNSEC_KMEM
29387 default y
29388
29389 source "drivers/s390/char/Kconfig"
29390diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29391index 2e04433..22afc64 100644
29392--- a/drivers/char/agp/frontend.c
29393+++ b/drivers/char/agp/frontend.c
29394@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29395 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29396 return -EFAULT;
29397
29398- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29399+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29400 return -EFAULT;
29401
29402 client = agp_find_client_by_pid(reserve.pid);
29403diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29404index 21cb980..f15107c 100644
29405--- a/drivers/char/genrtc.c
29406+++ b/drivers/char/genrtc.c
29407@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29408 switch (cmd) {
29409
29410 case RTC_PLL_GET:
29411+ memset(&pll, 0, sizeof(pll));
29412 if (get_rtc_pll(&pll))
29413 return -EINVAL;
29414 else
29415diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29416index dfd7876..c0b0885 100644
29417--- a/drivers/char/hpet.c
29418+++ b/drivers/char/hpet.c
29419@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29420 }
29421
29422 static int
29423-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29424+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29425 struct hpet_info *info)
29426 {
29427 struct hpet_timer __iomem *timer;
29428diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29429index 2c29942..604c5ba 100644
29430--- a/drivers/char/ipmi/ipmi_msghandler.c
29431+++ b/drivers/char/ipmi/ipmi_msghandler.c
29432@@ -420,7 +420,7 @@ struct ipmi_smi {
29433 struct proc_dir_entry *proc_dir;
29434 char proc_dir_name[10];
29435
29436- atomic_t stats[IPMI_NUM_STATS];
29437+ atomic_unchecked_t stats[IPMI_NUM_STATS];
29438
29439 /*
29440 * run_to_completion duplicate of smb_info, smi_info
29441@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29442
29443
29444 #define ipmi_inc_stat(intf, stat) \
29445- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29446+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29447 #define ipmi_get_stat(intf, stat) \
29448- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29449+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29450
29451 static int is_lan_addr(struct ipmi_addr *addr)
29452 {
29453@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29454 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29455 init_waitqueue_head(&intf->waitq);
29456 for (i = 0; i < IPMI_NUM_STATS; i++)
29457- atomic_set(&intf->stats[i], 0);
29458+ atomic_set_unchecked(&intf->stats[i], 0);
29459
29460 intf->proc_dir = NULL;
29461
29462diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29463index 1e638ff..a869ef5 100644
29464--- a/drivers/char/ipmi/ipmi_si_intf.c
29465+++ b/drivers/char/ipmi/ipmi_si_intf.c
29466@@ -275,7 +275,7 @@ struct smi_info {
29467 unsigned char slave_addr;
29468
29469 /* Counters and things for the proc filesystem. */
29470- atomic_t stats[SI_NUM_STATS];
29471+ atomic_unchecked_t stats[SI_NUM_STATS];
29472
29473 struct task_struct *thread;
29474
29475@@ -284,9 +284,9 @@ struct smi_info {
29476 };
29477
29478 #define smi_inc_stat(smi, stat) \
29479- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29480+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29481 #define smi_get_stat(smi, stat) \
29482- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29483+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29484
29485 #define SI_MAX_PARMS 4
29486
29487@@ -3209,7 +3209,7 @@ static int try_smi_init(struct smi_info *new_smi)
29488 atomic_set(&new_smi->req_events, 0);
29489 new_smi->run_to_completion = 0;
29490 for (i = 0; i < SI_NUM_STATS; i++)
29491- atomic_set(&new_smi->stats[i], 0);
29492+ atomic_set_unchecked(&new_smi->stats[i], 0);
29493
29494 new_smi->interrupt_disabled = 1;
29495 atomic_set(&new_smi->stop_operation, 0);
29496diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29497index 47ff7e4..0c7d340 100644
29498--- a/drivers/char/mbcs.c
29499+++ b/drivers/char/mbcs.c
29500@@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29501 return 0;
29502 }
29503
29504-static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29505+static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29506 {
29507 .part_num = MBCS_PART_NUM,
29508 .mfg_num = MBCS_MFG_NUM,
29509diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29510index d6e9d08..4493e89 100644
29511--- a/drivers/char/mem.c
29512+++ b/drivers/char/mem.c
29513@@ -18,6 +18,7 @@
29514 #include <linux/raw.h>
29515 #include <linux/tty.h>
29516 #include <linux/capability.h>
29517+#include <linux/security.h>
29518 #include <linux/ptrace.h>
29519 #include <linux/device.h>
29520 #include <linux/highmem.h>
29521@@ -35,6 +36,10 @@
29522 # include <linux/efi.h>
29523 #endif
29524
29525+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29526+extern const struct file_operations grsec_fops;
29527+#endif
29528+
29529 static inline unsigned long size_inside_page(unsigned long start,
29530 unsigned long size)
29531 {
29532@@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29533
29534 while (cursor < to) {
29535 if (!devmem_is_allowed(pfn)) {
29536+#ifdef CONFIG_GRKERNSEC_KMEM
29537+ gr_handle_mem_readwrite(from, to);
29538+#else
29539 printk(KERN_INFO
29540 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29541 current->comm, from, to);
29542+#endif
29543 return 0;
29544 }
29545 cursor += PAGE_SIZE;
29546@@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29547 }
29548 return 1;
29549 }
29550+#elif defined(CONFIG_GRKERNSEC_KMEM)
29551+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29552+{
29553+ return 0;
29554+}
29555 #else
29556 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29557 {
29558@@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29559
29560 while (count > 0) {
29561 unsigned long remaining;
29562+ char *temp;
29563
29564 sz = size_inside_page(p, count);
29565
29566@@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29567 if (!ptr)
29568 return -EFAULT;
29569
29570- remaining = copy_to_user(buf, ptr, sz);
29571+#ifdef CONFIG_PAX_USERCOPY
29572+ temp = kmalloc(sz, GFP_KERNEL);
29573+ if (!temp) {
29574+ unxlate_dev_mem_ptr(p, ptr);
29575+ return -ENOMEM;
29576+ }
29577+ memcpy(temp, ptr, sz);
29578+#else
29579+ temp = ptr;
29580+#endif
29581+
29582+ remaining = copy_to_user(buf, temp, sz);
29583+
29584+#ifdef CONFIG_PAX_USERCOPY
29585+ kfree(temp);
29586+#endif
29587+
29588 unxlate_dev_mem_ptr(p, ptr);
29589 if (remaining)
29590 return -EFAULT;
29591@@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29592 size_t count, loff_t *ppos)
29593 {
29594 unsigned long p = *ppos;
29595- ssize_t low_count, read, sz;
29596+ ssize_t low_count, read, sz, err = 0;
29597 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29598- int err = 0;
29599
29600 read = 0;
29601 if (p < (unsigned long) high_memory) {
29602@@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29603 }
29604 #endif
29605 while (low_count > 0) {
29606+ char *temp;
29607+
29608 sz = size_inside_page(p, low_count);
29609
29610 /*
29611@@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29612 */
29613 kbuf = xlate_dev_kmem_ptr((char *)p);
29614
29615- if (copy_to_user(buf, kbuf, sz))
29616+#ifdef CONFIG_PAX_USERCOPY
29617+ temp = kmalloc(sz, GFP_KERNEL);
29618+ if (!temp)
29619+ return -ENOMEM;
29620+ memcpy(temp, kbuf, sz);
29621+#else
29622+ temp = kbuf;
29623+#endif
29624+
29625+ err = copy_to_user(buf, temp, sz);
29626+
29627+#ifdef CONFIG_PAX_USERCOPY
29628+ kfree(temp);
29629+#endif
29630+
29631+ if (err)
29632 return -EFAULT;
29633 buf += sz;
29634 p += sz;
29635@@ -867,6 +914,9 @@ static const struct memdev {
29636 #ifdef CONFIG_CRASH_DUMP
29637 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29638 #endif
29639+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29640+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29641+#endif
29642 };
29643
29644 static int memory_open(struct inode *inode, struct file *filp)
29645diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29646index 9df78e2..01ba9ae 100644
29647--- a/drivers/char/nvram.c
29648+++ b/drivers/char/nvram.c
29649@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29650
29651 spin_unlock_irq(&rtc_lock);
29652
29653- if (copy_to_user(buf, contents, tmp - contents))
29654+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29655 return -EFAULT;
29656
29657 *ppos = i;
29658diff --git a/drivers/char/random.c b/drivers/char/random.c
29659index 4ec04a7..4a092ed 100644
29660--- a/drivers/char/random.c
29661+++ b/drivers/char/random.c
29662@@ -261,8 +261,13 @@
29663 /*
29664 * Configuration information
29665 */
29666+#ifdef CONFIG_GRKERNSEC_RANDNET
29667+#define INPUT_POOL_WORDS 512
29668+#define OUTPUT_POOL_WORDS 128
29669+#else
29670 #define INPUT_POOL_WORDS 128
29671 #define OUTPUT_POOL_WORDS 32
29672+#endif
29673 #define SEC_XFER_SIZE 512
29674 #define EXTRACT_SIZE 10
29675
29676@@ -300,10 +305,17 @@ static struct poolinfo {
29677 int poolwords;
29678 int tap1, tap2, tap3, tap4, tap5;
29679 } poolinfo_table[] = {
29680+#ifdef CONFIG_GRKERNSEC_RANDNET
29681+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29682+ { 512, 411, 308, 208, 104, 1 },
29683+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29684+ { 128, 103, 76, 51, 25, 1 },
29685+#else
29686 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29687 { 128, 103, 76, 51, 25, 1 },
29688 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29689 { 32, 26, 20, 14, 7, 1 },
29690+#endif
29691 #if 0
29692 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29693 { 2048, 1638, 1231, 819, 411, 1 },
29694@@ -913,7 +925,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29695
29696 extract_buf(r, tmp);
29697 i = min_t(int, nbytes, EXTRACT_SIZE);
29698- if (copy_to_user(buf, tmp, i)) {
29699+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29700 ret = -EFAULT;
29701 break;
29702 }
29703@@ -1238,7 +1250,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29704 #include <linux/sysctl.h>
29705
29706 static int min_read_thresh = 8, min_write_thresh;
29707-static int max_read_thresh = INPUT_POOL_WORDS * 32;
29708+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29709 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29710 static char sysctl_bootid[16];
29711
29712diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29713index 45713f0..8286d21 100644
29714--- a/drivers/char/sonypi.c
29715+++ b/drivers/char/sonypi.c
29716@@ -54,6 +54,7 @@
29717
29718 #include <asm/uaccess.h>
29719 #include <asm/io.h>
29720+#include <asm/local.h>
29721
29722 #include <linux/sonypi.h>
29723
29724@@ -490,7 +491,7 @@ static struct sonypi_device {
29725 spinlock_t fifo_lock;
29726 wait_queue_head_t fifo_proc_list;
29727 struct fasync_struct *fifo_async;
29728- int open_count;
29729+ local_t open_count;
29730 int model;
29731 struct input_dev *input_jog_dev;
29732 struct input_dev *input_key_dev;
29733@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29734 static int sonypi_misc_release(struct inode *inode, struct file *file)
29735 {
29736 mutex_lock(&sonypi_device.lock);
29737- sonypi_device.open_count--;
29738+ local_dec(&sonypi_device.open_count);
29739 mutex_unlock(&sonypi_device.lock);
29740 return 0;
29741 }
29742@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29743 {
29744 mutex_lock(&sonypi_device.lock);
29745 /* Flush input queue on first open */
29746- if (!sonypi_device.open_count)
29747+ if (!local_read(&sonypi_device.open_count))
29748 kfifo_reset(&sonypi_device.fifo);
29749- sonypi_device.open_count++;
29750+ local_inc(&sonypi_device.open_count);
29751 mutex_unlock(&sonypi_device.lock);
29752
29753 return 0;
29754diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29755index ad7c732..5aa8054 100644
29756--- a/drivers/char/tpm/tpm.c
29757+++ b/drivers/char/tpm/tpm.c
29758@@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29759 chip->vendor.req_complete_val)
29760 goto out_recv;
29761
29762- if ((status == chip->vendor.req_canceled)) {
29763+ if (status == chip->vendor.req_canceled) {
29764 dev_err(chip->dev, "Operation Canceled\n");
29765 rc = -ECANCELED;
29766 goto out;
29767diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29768index 0636520..169c1d0 100644
29769--- a/drivers/char/tpm/tpm_bios.c
29770+++ b/drivers/char/tpm/tpm_bios.c
29771@@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29772 event = addr;
29773
29774 if ((event->event_type == 0 && event->event_size == 0) ||
29775- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29776+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29777 return NULL;
29778
29779 return addr;
29780@@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29781 return NULL;
29782
29783 if ((event->event_type == 0 && event->event_size == 0) ||
29784- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29785+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29786 return NULL;
29787
29788 (*pos)++;
29789@@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29790 int i;
29791
29792 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29793- seq_putc(m, data[i]);
29794+ if (!seq_putc(m, data[i]))
29795+ return -EFAULT;
29796
29797 return 0;
29798 }
29799@@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29800 log->bios_event_log_end = log->bios_event_log + len;
29801
29802 virt = acpi_os_map_memory(start, len);
29803+ if (!virt) {
29804+ kfree(log->bios_event_log);
29805+ log->bios_event_log = NULL;
29806+ return -EFAULT;
29807+ }
29808
29809- memcpy(log->bios_event_log, virt, len);
29810+ memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29811
29812 acpi_os_unmap_memory(virt, len);
29813 return 0;
29814diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29815index cdf2f54..e55c197 100644
29816--- a/drivers/char/virtio_console.c
29817+++ b/drivers/char/virtio_console.c
29818@@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29819 if (to_user) {
29820 ssize_t ret;
29821
29822- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29823+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29824 if (ret)
29825 return -EFAULT;
29826 } else {
29827@@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29828 if (!port_has_data(port) && !port->host_connected)
29829 return 0;
29830
29831- return fill_readbuf(port, ubuf, count, true);
29832+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29833 }
29834
29835 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29836diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29837index 97f5064..202b6e6 100644
29838--- a/drivers/edac/edac_pci_sysfs.c
29839+++ b/drivers/edac/edac_pci_sysfs.c
29840@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29841 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29842 static int edac_pci_poll_msec = 1000; /* one second workq period */
29843
29844-static atomic_t pci_parity_count = ATOMIC_INIT(0);
29845-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29846+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29847+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29848
29849 static struct kobject *edac_pci_top_main_kobj;
29850 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29851@@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29852 edac_printk(KERN_CRIT, EDAC_PCI,
29853 "Signaled System Error on %s\n",
29854 pci_name(dev));
29855- atomic_inc(&pci_nonparity_count);
29856+ atomic_inc_unchecked(&pci_nonparity_count);
29857 }
29858
29859 if (status & (PCI_STATUS_PARITY)) {
29860@@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29861 "Master Data Parity Error on %s\n",
29862 pci_name(dev));
29863
29864- atomic_inc(&pci_parity_count);
29865+ atomic_inc_unchecked(&pci_parity_count);
29866 }
29867
29868 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29869@@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29870 "Detected Parity Error on %s\n",
29871 pci_name(dev));
29872
29873- atomic_inc(&pci_parity_count);
29874+ atomic_inc_unchecked(&pci_parity_count);
29875 }
29876 }
29877
29878@@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29879 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29880 "Signaled System Error on %s\n",
29881 pci_name(dev));
29882- atomic_inc(&pci_nonparity_count);
29883+ atomic_inc_unchecked(&pci_nonparity_count);
29884 }
29885
29886 if (status & (PCI_STATUS_PARITY)) {
29887@@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29888 "Master Data Parity Error on "
29889 "%s\n", pci_name(dev));
29890
29891- atomic_inc(&pci_parity_count);
29892+ atomic_inc_unchecked(&pci_parity_count);
29893 }
29894
29895 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29896@@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29897 "Detected Parity Error on %s\n",
29898 pci_name(dev));
29899
29900- atomic_inc(&pci_parity_count);
29901+ atomic_inc_unchecked(&pci_parity_count);
29902 }
29903 }
29904 }
29905@@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29906 if (!check_pci_errors)
29907 return;
29908
29909- before_count = atomic_read(&pci_parity_count);
29910+ before_count = atomic_read_unchecked(&pci_parity_count);
29911
29912 /* scan all PCI devices looking for a Parity Error on devices and
29913 * bridges.
29914@@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29915 /* Only if operator has selected panic on PCI Error */
29916 if (edac_pci_get_panic_on_pe()) {
29917 /* If the count is different 'after' from 'before' */
29918- if (before_count != atomic_read(&pci_parity_count))
29919+ if (before_count != atomic_read_unchecked(&pci_parity_count))
29920 panic("EDAC: PCI Parity Error");
29921 }
29922 }
29923diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
29924index c6074c5..88a9e2e 100644
29925--- a/drivers/edac/mce_amd.h
29926+++ b/drivers/edac/mce_amd.h
29927@@ -82,7 +82,7 @@ extern const char * const ii_msgs[];
29928 struct amd_decoder_ops {
29929 bool (*dc_mce)(u16, u8);
29930 bool (*ic_mce)(u16, u8);
29931-};
29932+} __no_const;
29933
29934 void amd_report_gart_errors(bool);
29935 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
29936diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
29937index cc595eb..4ec702a 100644
29938--- a/drivers/firewire/core-card.c
29939+++ b/drivers/firewire/core-card.c
29940@@ -679,7 +679,7 @@ void fw_card_release(struct kref *kref)
29941
29942 void fw_core_remove_card(struct fw_card *card)
29943 {
29944- struct fw_card_driver dummy_driver = dummy_driver_template;
29945+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
29946
29947 card->driver->update_phy_reg(card, 4,
29948 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
29949diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
29950index 2e6b245..c3857d9 100644
29951--- a/drivers/firewire/core-cdev.c
29952+++ b/drivers/firewire/core-cdev.c
29953@@ -1341,8 +1341,7 @@ static int init_iso_resource(struct client *client,
29954 int ret;
29955
29956 if ((request->channels == 0 && request->bandwidth == 0) ||
29957- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
29958- request->bandwidth < 0)
29959+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
29960 return -EINVAL;
29961
29962 r = kmalloc(sizeof(*r), GFP_KERNEL);
29963diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
29964index dea2dcc..a4fb978 100644
29965--- a/drivers/firewire/core-transaction.c
29966+++ b/drivers/firewire/core-transaction.c
29967@@ -37,6 +37,7 @@
29968 #include <linux/timer.h>
29969 #include <linux/types.h>
29970 #include <linux/workqueue.h>
29971+#include <linux/sched.h>
29972
29973 #include <asm/byteorder.h>
29974
29975diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
29976index 9047f55..e47c7ff 100644
29977--- a/drivers/firewire/core.h
29978+++ b/drivers/firewire/core.h
29979@@ -110,6 +110,7 @@ struct fw_card_driver {
29980
29981 int (*stop_iso)(struct fw_iso_context *ctx);
29982 };
29983+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
29984
29985 void fw_card_initialize(struct fw_card *card,
29986 const struct fw_card_driver *driver, struct device *device);
29987diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
29988index 153980b..4b4d046 100644
29989--- a/drivers/firmware/dmi_scan.c
29990+++ b/drivers/firmware/dmi_scan.c
29991@@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
29992 }
29993 }
29994 else {
29995- /*
29996- * no iounmap() for that ioremap(); it would be a no-op, but
29997- * it's so early in setup that sucker gets confused into doing
29998- * what it shouldn't if we actually call it.
29999- */
30000 p = dmi_ioremap(0xF0000, 0x10000);
30001 if (p == NULL)
30002 goto error;
30003@@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30004 if (buf == NULL)
30005 return -1;
30006
30007- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30008+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30009
30010 iounmap(buf);
30011 return 0;
30012diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30013index 82d5c20..44a7177 100644
30014--- a/drivers/gpio/gpio-vr41xx.c
30015+++ b/drivers/gpio/gpio-vr41xx.c
30016@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30017 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30018 maskl, pendl, maskh, pendh);
30019
30020- atomic_inc(&irq_err_count);
30021+ atomic_inc_unchecked(&irq_err_count);
30022
30023 return -EINVAL;
30024 }
30025diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30026index 8111889..367b253 100644
30027--- a/drivers/gpu/drm/drm_crtc_helper.c
30028+++ b/drivers/gpu/drm/drm_crtc_helper.c
30029@@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30030 struct drm_crtc *tmp;
30031 int crtc_mask = 1;
30032
30033- WARN(!crtc, "checking null crtc?\n");
30034+ BUG_ON(!crtc);
30035
30036 dev = crtc->dev;
30037
30038diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30039index 6116e3b..c29dd16 100644
30040--- a/drivers/gpu/drm/drm_drv.c
30041+++ b/drivers/gpu/drm/drm_drv.c
30042@@ -316,7 +316,7 @@ module_exit(drm_core_exit);
30043 /**
30044 * Copy and IOCTL return string to user space
30045 */
30046-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30047+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30048 {
30049 int len;
30050
30051@@ -399,7 +399,7 @@ long drm_ioctl(struct file *filp,
30052 return -ENODEV;
30053
30054 atomic_inc(&dev->ioctl_count);
30055- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30056+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30057 ++file_priv->ioctl_count;
30058
30059 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30060diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30061index 123de28..43a0897 100644
30062--- a/drivers/gpu/drm/drm_fops.c
30063+++ b/drivers/gpu/drm/drm_fops.c
30064@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30065 }
30066
30067 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30068- atomic_set(&dev->counts[i], 0);
30069+ atomic_set_unchecked(&dev->counts[i], 0);
30070
30071 dev->sigdata.lock = NULL;
30072
30073@@ -138,8 +138,8 @@ int drm_open(struct inode *inode, struct file *filp)
30074
30075 retcode = drm_open_helper(inode, filp, dev);
30076 if (!retcode) {
30077- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30078- if (!dev->open_count++)
30079+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30080+ if (local_inc_return(&dev->open_count) == 1)
30081 retcode = drm_setup(dev);
30082 }
30083 if (!retcode) {
30084@@ -482,7 +482,7 @@ int drm_release(struct inode *inode, struct file *filp)
30085
30086 mutex_lock(&drm_global_mutex);
30087
30088- DRM_DEBUG("open_count = %d\n", dev->open_count);
30089+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30090
30091 if (dev->driver->preclose)
30092 dev->driver->preclose(dev, file_priv);
30093@@ -491,10 +491,10 @@ int drm_release(struct inode *inode, struct file *filp)
30094 * Begin inline drm_release
30095 */
30096
30097- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30098+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30099 task_pid_nr(current),
30100 (long)old_encode_dev(file_priv->minor->device),
30101- dev->open_count);
30102+ local_read(&dev->open_count));
30103
30104 /* Release any auth tokens that might point to this file_priv,
30105 (do that under the drm_global_mutex) */
30106@@ -584,8 +584,8 @@ int drm_release(struct inode *inode, struct file *filp)
30107 * End inline drm_release
30108 */
30109
30110- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30111- if (!--dev->open_count) {
30112+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30113+ if (local_dec_and_test(&dev->open_count)) {
30114 if (atomic_read(&dev->ioctl_count)) {
30115 DRM_ERROR("Device busy: %d\n",
30116 atomic_read(&dev->ioctl_count));
30117diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30118index c87dc96..326055d 100644
30119--- a/drivers/gpu/drm/drm_global.c
30120+++ b/drivers/gpu/drm/drm_global.c
30121@@ -36,7 +36,7 @@
30122 struct drm_global_item {
30123 struct mutex mutex;
30124 void *object;
30125- int refcount;
30126+ atomic_t refcount;
30127 };
30128
30129 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30130@@ -49,7 +49,7 @@ void drm_global_init(void)
30131 struct drm_global_item *item = &glob[i];
30132 mutex_init(&item->mutex);
30133 item->object = NULL;
30134- item->refcount = 0;
30135+ atomic_set(&item->refcount, 0);
30136 }
30137 }
30138
30139@@ -59,7 +59,7 @@ void drm_global_release(void)
30140 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30141 struct drm_global_item *item = &glob[i];
30142 BUG_ON(item->object != NULL);
30143- BUG_ON(item->refcount != 0);
30144+ BUG_ON(atomic_read(&item->refcount) != 0);
30145 }
30146 }
30147
30148@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30149 void *object;
30150
30151 mutex_lock(&item->mutex);
30152- if (item->refcount == 0) {
30153+ if (atomic_read(&item->refcount) == 0) {
30154 item->object = kzalloc(ref->size, GFP_KERNEL);
30155 if (unlikely(item->object == NULL)) {
30156 ret = -ENOMEM;
30157@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30158 goto out_err;
30159
30160 }
30161- ++item->refcount;
30162+ atomic_inc(&item->refcount);
30163 ref->object = item->object;
30164 object = item->object;
30165 mutex_unlock(&item->mutex);
30166@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30167 struct drm_global_item *item = &glob[ref->global_type];
30168
30169 mutex_lock(&item->mutex);
30170- BUG_ON(item->refcount == 0);
30171+ BUG_ON(atomic_read(&item->refcount) == 0);
30172 BUG_ON(ref->object != item->object);
30173- if (--item->refcount == 0) {
30174+ if (atomic_dec_and_test(&item->refcount)) {
30175 ref->release(ref);
30176 item->object = NULL;
30177 }
30178diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30179index ab1162d..42587b2 100644
30180--- a/drivers/gpu/drm/drm_info.c
30181+++ b/drivers/gpu/drm/drm_info.c
30182@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30183 struct drm_local_map *map;
30184 struct drm_map_list *r_list;
30185
30186- /* Hardcoded from _DRM_FRAME_BUFFER,
30187- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30188- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30189- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30190+ static const char * const types[] = {
30191+ [_DRM_FRAME_BUFFER] = "FB",
30192+ [_DRM_REGISTERS] = "REG",
30193+ [_DRM_SHM] = "SHM",
30194+ [_DRM_AGP] = "AGP",
30195+ [_DRM_SCATTER_GATHER] = "SG",
30196+ [_DRM_CONSISTENT] = "PCI",
30197+ [_DRM_GEM] = "GEM" };
30198 const char *type;
30199 int i;
30200
30201@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30202 map = r_list->map;
30203 if (!map)
30204 continue;
30205- if (map->type < 0 || map->type > 5)
30206+ if (map->type >= ARRAY_SIZE(types))
30207 type = "??";
30208 else
30209 type = types[map->type];
30210@@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30211 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30212 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30213 vma->vm_flags & VM_IO ? 'i' : '-',
30214+#ifdef CONFIG_GRKERNSEC_HIDESYM
30215+ 0);
30216+#else
30217 vma->vm_pgoff);
30218+#endif
30219
30220 #if defined(__i386__)
30221 pgprot = pgprot_val(vma->vm_page_prot);
30222diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30223index 637fcc3..e890b33 100644
30224--- a/drivers/gpu/drm/drm_ioc32.c
30225+++ b/drivers/gpu/drm/drm_ioc32.c
30226@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30227 request = compat_alloc_user_space(nbytes);
30228 if (!access_ok(VERIFY_WRITE, request, nbytes))
30229 return -EFAULT;
30230- list = (struct drm_buf_desc *) (request + 1);
30231+ list = (struct drm_buf_desc __user *) (request + 1);
30232
30233 if (__put_user(count, &request->count)
30234 || __put_user(list, &request->list))
30235@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30236 request = compat_alloc_user_space(nbytes);
30237 if (!access_ok(VERIFY_WRITE, request, nbytes))
30238 return -EFAULT;
30239- list = (struct drm_buf_pub *) (request + 1);
30240+ list = (struct drm_buf_pub __user *) (request + 1);
30241
30242 if (__put_user(count, &request->count)
30243 || __put_user(list, &request->list))
30244diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30245index cf85155..f2665cb 100644
30246--- a/drivers/gpu/drm/drm_ioctl.c
30247+++ b/drivers/gpu/drm/drm_ioctl.c
30248@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30249 stats->data[i].value =
30250 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30251 else
30252- stats->data[i].value = atomic_read(&dev->counts[i]);
30253+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30254 stats->data[i].type = dev->types[i];
30255 }
30256
30257diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30258index c79c713..2048588 100644
30259--- a/drivers/gpu/drm/drm_lock.c
30260+++ b/drivers/gpu/drm/drm_lock.c
30261@@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30262 if (drm_lock_take(&master->lock, lock->context)) {
30263 master->lock.file_priv = file_priv;
30264 master->lock.lock_time = jiffies;
30265- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30266+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30267 break; /* Got lock */
30268 }
30269
30270@@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30271 return -EINVAL;
30272 }
30273
30274- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30275+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30276
30277 if (drm_lock_free(&master->lock, lock->context)) {
30278 /* FIXME: Should really bail out here. */
30279diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30280index aa454f8..6d38580 100644
30281--- a/drivers/gpu/drm/drm_stub.c
30282+++ b/drivers/gpu/drm/drm_stub.c
30283@@ -512,7 +512,7 @@ void drm_unplug_dev(struct drm_device *dev)
30284
30285 drm_device_set_unplugged(dev);
30286
30287- if (dev->open_count == 0) {
30288+ if (local_read(&dev->open_count) == 0) {
30289 drm_put_dev(dev);
30290 }
30291 mutex_unlock(&drm_global_mutex);
30292diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30293index f920fb5..001c52d 100644
30294--- a/drivers/gpu/drm/i810/i810_dma.c
30295+++ b/drivers/gpu/drm/i810/i810_dma.c
30296@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30297 dma->buflist[vertex->idx],
30298 vertex->discard, vertex->used);
30299
30300- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30301- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30302+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30303+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30304 sarea_priv->last_enqueue = dev_priv->counter - 1;
30305 sarea_priv->last_dispatch = (int)hw_status[5];
30306
30307@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30308 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30309 mc->last_render);
30310
30311- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30312- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30313+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30314+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30315 sarea_priv->last_enqueue = dev_priv->counter - 1;
30316 sarea_priv->last_dispatch = (int)hw_status[5];
30317
30318diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30319index c9339f4..f5e1b9d 100644
30320--- a/drivers/gpu/drm/i810/i810_drv.h
30321+++ b/drivers/gpu/drm/i810/i810_drv.h
30322@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30323 int page_flipping;
30324
30325 wait_queue_head_t irq_queue;
30326- atomic_t irq_received;
30327- atomic_t irq_emitted;
30328+ atomic_unchecked_t irq_received;
30329+ atomic_unchecked_t irq_emitted;
30330
30331 int front_offset;
30332 } drm_i810_private_t;
30333diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30334index e6162a1..b2ff486 100644
30335--- a/drivers/gpu/drm/i915/i915_debugfs.c
30336+++ b/drivers/gpu/drm/i915/i915_debugfs.c
30337@@ -500,7 +500,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30338 I915_READ(GTIMR));
30339 }
30340 seq_printf(m, "Interrupts received: %d\n",
30341- atomic_read(&dev_priv->irq_received));
30342+ atomic_read_unchecked(&dev_priv->irq_received));
30343 for (i = 0; i < I915_NUM_RINGS; i++) {
30344 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30345 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30346@@ -1313,7 +1313,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
30347 return ret;
30348
30349 if (opregion->header)
30350- seq_write(m, opregion->header, OPREGION_SIZE);
30351+ seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
30352
30353 mutex_unlock(&dev->struct_mutex);
30354
30355diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30356index ba60f3c..e2dff7f 100644
30357--- a/drivers/gpu/drm/i915/i915_dma.c
30358+++ b/drivers/gpu/drm/i915/i915_dma.c
30359@@ -1178,7 +1178,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30360 bool can_switch;
30361
30362 spin_lock(&dev->count_lock);
30363- can_switch = (dev->open_count == 0);
30364+ can_switch = (local_read(&dev->open_count) == 0);
30365 spin_unlock(&dev->count_lock);
30366 return can_switch;
30367 }
30368diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30369index 5fabc6c..0b08aa1 100644
30370--- a/drivers/gpu/drm/i915/i915_drv.h
30371+++ b/drivers/gpu/drm/i915/i915_drv.h
30372@@ -240,7 +240,7 @@ struct drm_i915_display_funcs {
30373 /* render clock increase/decrease */
30374 /* display clock increase/decrease */
30375 /* pll clock increase/decrease */
30376-};
30377+} __no_const;
30378
30379 struct intel_device_info {
30380 u8 gen;
30381@@ -350,7 +350,7 @@ typedef struct drm_i915_private {
30382 int current_page;
30383 int page_flipping;
30384
30385- atomic_t irq_received;
30386+ atomic_unchecked_t irq_received;
30387
30388 /* protects the irq masks */
30389 spinlock_t irq_lock;
30390@@ -937,7 +937,7 @@ struct drm_i915_gem_object {
30391 * will be page flipped away on the next vblank. When it
30392 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30393 */
30394- atomic_t pending_flip;
30395+ atomic_unchecked_t pending_flip;
30396 };
30397
30398 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30399@@ -1359,7 +1359,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
30400 extern void intel_teardown_gmbus(struct drm_device *dev);
30401 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30402 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30403-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30404+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30405 {
30406 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30407 }
30408diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30409index de43194..a14c4cc 100644
30410--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30411+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30412@@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30413 i915_gem_clflush_object(obj);
30414
30415 if (obj->base.pending_write_domain)
30416- cd->flips |= atomic_read(&obj->pending_flip);
30417+ cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30418
30419 /* The actual obj->write_domain will be updated with
30420 * pending_write_domain after we emit the accumulated flush for all
30421@@ -933,9 +933,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30422
30423 static int
30424 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30425- int count)
30426+ unsigned int count)
30427 {
30428- int i;
30429+ unsigned int i;
30430
30431 for (i = 0; i < count; i++) {
30432 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30433diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30434index f57e5cf..c82f79d 100644
30435--- a/drivers/gpu/drm/i915/i915_irq.c
30436+++ b/drivers/gpu/drm/i915/i915_irq.c
30437@@ -472,7 +472,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30438 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30439 struct drm_i915_master_private *master_priv;
30440
30441- atomic_inc(&dev_priv->irq_received);
30442+ atomic_inc_unchecked(&dev_priv->irq_received);
30443
30444 /* disable master interrupt before clearing iir */
30445 de_ier = I915_READ(DEIER);
30446@@ -563,7 +563,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30447 struct drm_i915_master_private *master_priv;
30448 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
30449
30450- atomic_inc(&dev_priv->irq_received);
30451+ atomic_inc_unchecked(&dev_priv->irq_received);
30452
30453 if (IS_GEN6(dev))
30454 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
30455@@ -1292,7 +1292,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
30456 int ret = IRQ_NONE, pipe;
30457 bool blc_event = false;
30458
30459- atomic_inc(&dev_priv->irq_received);
30460+ atomic_inc_unchecked(&dev_priv->irq_received);
30461
30462 iir = I915_READ(IIR);
30463
30464@@ -1803,7 +1803,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30465 {
30466 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30467
30468- atomic_set(&dev_priv->irq_received, 0);
30469+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30470
30471 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30472 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30473@@ -1980,7 +1980,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
30474 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30475 int pipe;
30476
30477- atomic_set(&dev_priv->irq_received, 0);
30478+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30479
30480 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30481 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30482diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30483index d4d162f..e80037c 100644
30484--- a/drivers/gpu/drm/i915/intel_display.c
30485+++ b/drivers/gpu/drm/i915/intel_display.c
30486@@ -2254,7 +2254,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30487
30488 wait_event(dev_priv->pending_flip_queue,
30489 atomic_read(&dev_priv->mm.wedged) ||
30490- atomic_read(&obj->pending_flip) == 0);
30491+ atomic_read_unchecked(&obj->pending_flip) == 0);
30492
30493 /* Big Hammer, we also need to ensure that any pending
30494 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30495@@ -2919,7 +2919,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
30496 obj = to_intel_framebuffer(crtc->fb)->obj;
30497 dev_priv = crtc->dev->dev_private;
30498 wait_event(dev_priv->pending_flip_queue,
30499- atomic_read(&obj->pending_flip) == 0);
30500+ atomic_read_unchecked(&obj->pending_flip) == 0);
30501 }
30502
30503 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
30504@@ -7286,7 +7286,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30505
30506 atomic_clear_mask(1 << intel_crtc->plane,
30507 &obj->pending_flip.counter);
30508- if (atomic_read(&obj->pending_flip) == 0)
30509+ if (atomic_read_unchecked(&obj->pending_flip) == 0)
30510 wake_up(&dev_priv->pending_flip_queue);
30511
30512 schedule_work(&work->work);
30513@@ -7582,7 +7582,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30514 /* Block clients from rendering to the new back buffer until
30515 * the flip occurs and the object is no longer visible.
30516 */
30517- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30518+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30519
30520 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30521 if (ret)
30522@@ -7596,7 +7596,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30523 return 0;
30524
30525 cleanup_pending:
30526- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30527+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30528 drm_gem_object_unreference(&work->old_fb_obj->base);
30529 drm_gem_object_unreference(&obj->base);
30530 mutex_unlock(&dev->struct_mutex);
30531diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30532index 54558a0..2d97005 100644
30533--- a/drivers/gpu/drm/mga/mga_drv.h
30534+++ b/drivers/gpu/drm/mga/mga_drv.h
30535@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30536 u32 clear_cmd;
30537 u32 maccess;
30538
30539- atomic_t vbl_received; /**< Number of vblanks received. */
30540+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30541 wait_queue_head_t fence_queue;
30542- atomic_t last_fence_retired;
30543+ atomic_unchecked_t last_fence_retired;
30544 u32 next_fence_to_post;
30545
30546 unsigned int fb_cpp;
30547diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30548index 2581202..f230a8d9 100644
30549--- a/drivers/gpu/drm/mga/mga_irq.c
30550+++ b/drivers/gpu/drm/mga/mga_irq.c
30551@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30552 if (crtc != 0)
30553 return 0;
30554
30555- return atomic_read(&dev_priv->vbl_received);
30556+ return atomic_read_unchecked(&dev_priv->vbl_received);
30557 }
30558
30559
30560@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30561 /* VBLANK interrupt */
30562 if (status & MGA_VLINEPEN) {
30563 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30564- atomic_inc(&dev_priv->vbl_received);
30565+ atomic_inc_unchecked(&dev_priv->vbl_received);
30566 drm_handle_vblank(dev, 0);
30567 handled = 1;
30568 }
30569@@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30570 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30571 MGA_WRITE(MGA_PRIMEND, prim_end);
30572
30573- atomic_inc(&dev_priv->last_fence_retired);
30574+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
30575 DRM_WAKEUP(&dev_priv->fence_queue);
30576 handled = 1;
30577 }
30578@@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30579 * using fences.
30580 */
30581 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30582- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30583+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30584 - *sequence) <= (1 << 23)));
30585
30586 *sequence = cur_fence;
30587diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30588index 0be4a81..7464804 100644
30589--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30590+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30591@@ -5329,7 +5329,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30592 struct bit_table {
30593 const char id;
30594 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30595-};
30596+} __no_const;
30597
30598 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30599
30600diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30601index 3aef353..0ad1322 100644
30602--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30603+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30604@@ -240,7 +240,7 @@ struct nouveau_channel {
30605 struct list_head pending;
30606 uint32_t sequence;
30607 uint32_t sequence_ack;
30608- atomic_t last_sequence_irq;
30609+ atomic_unchecked_t last_sequence_irq;
30610 struct nouveau_vma vma;
30611 } fence;
30612
30613@@ -321,7 +321,7 @@ struct nouveau_exec_engine {
30614 u32 handle, u16 class);
30615 void (*set_tile_region)(struct drm_device *dev, int i);
30616 void (*tlb_flush)(struct drm_device *, int engine);
30617-};
30618+} __no_const;
30619
30620 struct nouveau_instmem_engine {
30621 void *priv;
30622@@ -343,13 +343,13 @@ struct nouveau_instmem_engine {
30623 struct nouveau_mc_engine {
30624 int (*init)(struct drm_device *dev);
30625 void (*takedown)(struct drm_device *dev);
30626-};
30627+} __no_const;
30628
30629 struct nouveau_timer_engine {
30630 int (*init)(struct drm_device *dev);
30631 void (*takedown)(struct drm_device *dev);
30632 uint64_t (*read)(struct drm_device *dev);
30633-};
30634+} __no_const;
30635
30636 struct nouveau_fb_engine {
30637 int num_tiles;
30638@@ -590,7 +590,7 @@ struct nouveau_vram_engine {
30639 void (*put)(struct drm_device *, struct nouveau_mem **);
30640
30641 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30642-};
30643+} __no_const;
30644
30645 struct nouveau_engine {
30646 struct nouveau_instmem_engine instmem;
30647@@ -739,7 +739,7 @@ struct drm_nouveau_private {
30648 struct drm_global_reference mem_global_ref;
30649 struct ttm_bo_global_ref bo_global_ref;
30650 struct ttm_bo_device bdev;
30651- atomic_t validate_sequence;
30652+ atomic_unchecked_t validate_sequence;
30653 } ttm;
30654
30655 struct {
30656diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
30657index c1dc20f..4df673c 100644
30658--- a/drivers/gpu/drm/nouveau/nouveau_fence.c
30659+++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
30660@@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
30661 if (USE_REFCNT(dev))
30662 sequence = nvchan_rd32(chan, 0x48);
30663 else
30664- sequence = atomic_read(&chan->fence.last_sequence_irq);
30665+ sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
30666
30667 if (chan->fence.sequence_ack == sequence)
30668 goto out;
30669@@ -538,7 +538,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
30670 return ret;
30671 }
30672
30673- atomic_set(&chan->fence.last_sequence_irq, 0);
30674+ atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
30675 return 0;
30676 }
30677
30678diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30679index ed52a6f..484acdc 100644
30680--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30681+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30682@@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30683 int trycnt = 0;
30684 int ret, i;
30685
30686- sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30687+ sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30688 retry:
30689 if (++trycnt > 100000) {
30690 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30691diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30692index c2a8511..4b996f9 100644
30693--- a/drivers/gpu/drm/nouveau/nouveau_state.c
30694+++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30695@@ -588,7 +588,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30696 bool can_switch;
30697
30698 spin_lock(&dev->count_lock);
30699- can_switch = (dev->open_count == 0);
30700+ can_switch = (local_read(&dev->open_count) == 0);
30701 spin_unlock(&dev->count_lock);
30702 return can_switch;
30703 }
30704diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
30705index dbdea8e..cd6eeeb 100644
30706--- a/drivers/gpu/drm/nouveau/nv04_graph.c
30707+++ b/drivers/gpu/drm/nouveau/nv04_graph.c
30708@@ -554,7 +554,7 @@ static int
30709 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
30710 u32 class, u32 mthd, u32 data)
30711 {
30712- atomic_set(&chan->fence.last_sequence_irq, data);
30713+ atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
30714 return 0;
30715 }
30716
30717diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
30718index 2746402..c8dc4a4 100644
30719--- a/drivers/gpu/drm/nouveau/nv50_sor.c
30720+++ b/drivers/gpu/drm/nouveau/nv50_sor.c
30721@@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
30722 }
30723
30724 if (nv_encoder->dcb->type == OUTPUT_DP) {
30725- struct dp_train_func func = {
30726+ static struct dp_train_func func = {
30727 .link_set = nv50_sor_dp_link_set,
30728 .train_set = nv50_sor_dp_train_set,
30729 .train_adj = nv50_sor_dp_train_adj
30730diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
30731index 0247250..d2f6aaf 100644
30732--- a/drivers/gpu/drm/nouveau/nvd0_display.c
30733+++ b/drivers/gpu/drm/nouveau/nvd0_display.c
30734@@ -1366,7 +1366,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
30735 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
30736
30737 if (nv_encoder->dcb->type == OUTPUT_DP) {
30738- struct dp_train_func func = {
30739+ static struct dp_train_func func = {
30740 .link_set = nvd0_sor_dp_link_set,
30741 .train_set = nvd0_sor_dp_train_set,
30742 .train_adj = nvd0_sor_dp_train_adj
30743diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30744index bcac90b..53bfc76 100644
30745--- a/drivers/gpu/drm/r128/r128_cce.c
30746+++ b/drivers/gpu/drm/r128/r128_cce.c
30747@@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30748
30749 /* GH: Simple idle check.
30750 */
30751- atomic_set(&dev_priv->idle_count, 0);
30752+ atomic_set_unchecked(&dev_priv->idle_count, 0);
30753
30754 /* We don't support anything other than bus-mastering ring mode,
30755 * but the ring can be in either AGP or PCI space for the ring
30756diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30757index 930c71b..499aded 100644
30758--- a/drivers/gpu/drm/r128/r128_drv.h
30759+++ b/drivers/gpu/drm/r128/r128_drv.h
30760@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30761 int is_pci;
30762 unsigned long cce_buffers_offset;
30763
30764- atomic_t idle_count;
30765+ atomic_unchecked_t idle_count;
30766
30767 int page_flipping;
30768 int current_page;
30769 u32 crtc_offset;
30770 u32 crtc_offset_cntl;
30771
30772- atomic_t vbl_received;
30773+ atomic_unchecked_t vbl_received;
30774
30775 u32 color_fmt;
30776 unsigned int front_offset;
30777diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30778index 429d5a0..7e899ed 100644
30779--- a/drivers/gpu/drm/r128/r128_irq.c
30780+++ b/drivers/gpu/drm/r128/r128_irq.c
30781@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30782 if (crtc != 0)
30783 return 0;
30784
30785- return atomic_read(&dev_priv->vbl_received);
30786+ return atomic_read_unchecked(&dev_priv->vbl_received);
30787 }
30788
30789 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30790@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30791 /* VBLANK interrupt */
30792 if (status & R128_CRTC_VBLANK_INT) {
30793 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30794- atomic_inc(&dev_priv->vbl_received);
30795+ atomic_inc_unchecked(&dev_priv->vbl_received);
30796 drm_handle_vblank(dev, 0);
30797 return IRQ_HANDLED;
30798 }
30799diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30800index a9e33ce..09edd4b 100644
30801--- a/drivers/gpu/drm/r128/r128_state.c
30802+++ b/drivers/gpu/drm/r128/r128_state.c
30803@@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30804
30805 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30806 {
30807- if (atomic_read(&dev_priv->idle_count) == 0)
30808+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30809 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30810 else
30811- atomic_set(&dev_priv->idle_count, 0);
30812+ atomic_set_unchecked(&dev_priv->idle_count, 0);
30813 }
30814
30815 #endif
30816diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30817index 5a82b6b..9e69c73 100644
30818--- a/drivers/gpu/drm/radeon/mkregtable.c
30819+++ b/drivers/gpu/drm/radeon/mkregtable.c
30820@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30821 regex_t mask_rex;
30822 regmatch_t match[4];
30823 char buf[1024];
30824- size_t end;
30825+ long end;
30826 int len;
30827 int done = 0;
30828 int r;
30829 unsigned o;
30830 struct offset *offset;
30831 char last_reg_s[10];
30832- int last_reg;
30833+ unsigned long last_reg;
30834
30835 if (regcomp
30836 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30837diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30838index 138b952..d74f9cb 100644
30839--- a/drivers/gpu/drm/radeon/radeon.h
30840+++ b/drivers/gpu/drm/radeon/radeon.h
30841@@ -253,7 +253,7 @@ struct radeon_fence_driver {
30842 uint32_t scratch_reg;
30843 uint64_t gpu_addr;
30844 volatile uint32_t *cpu_addr;
30845- atomic_t seq;
30846+ atomic_unchecked_t seq;
30847 uint32_t last_seq;
30848 unsigned long last_jiffies;
30849 unsigned long last_timeout;
30850@@ -753,7 +753,7 @@ struct r600_blit_cp_primitives {
30851 int x2, int y2);
30852 void (*draw_auto)(struct radeon_device *rdev);
30853 void (*set_default_state)(struct radeon_device *rdev);
30854-};
30855+} __no_const;
30856
30857 struct r600_blit {
30858 struct mutex mutex;
30859@@ -1246,7 +1246,7 @@ struct radeon_asic {
30860 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30861 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30862 } pflip;
30863-};
30864+} __no_const;
30865
30866 /*
30867 * Asic structures
30868diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30869index 5992502..c19c633 100644
30870--- a/drivers/gpu/drm/radeon/radeon_device.c
30871+++ b/drivers/gpu/drm/radeon/radeon_device.c
30872@@ -691,7 +691,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30873 bool can_switch;
30874
30875 spin_lock(&dev->count_lock);
30876- can_switch = (dev->open_count == 0);
30877+ can_switch = (local_read(&dev->open_count) == 0);
30878 spin_unlock(&dev->count_lock);
30879 return can_switch;
30880 }
30881diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30882index a1b59ca..86f2d44 100644
30883--- a/drivers/gpu/drm/radeon/radeon_drv.h
30884+++ b/drivers/gpu/drm/radeon/radeon_drv.h
30885@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
30886
30887 /* SW interrupt */
30888 wait_queue_head_t swi_queue;
30889- atomic_t swi_emitted;
30890+ atomic_unchecked_t swi_emitted;
30891 int vblank_crtc;
30892 uint32_t irq_enable_reg;
30893 uint32_t r500_disp_irq_reg;
30894diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
30895index 4bd36a3..e66fe9c 100644
30896--- a/drivers/gpu/drm/radeon/radeon_fence.c
30897+++ b/drivers/gpu/drm/radeon/radeon_fence.c
30898@@ -70,7 +70,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
30899 write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
30900 return 0;
30901 }
30902- fence->seq = atomic_add_return(1, &rdev->fence_drv[fence->ring].seq);
30903+ fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv[fence->ring].seq);
30904 if (!rdev->ring[fence->ring].ready)
30905 /* FIXME: cp is not running assume everythings is done right
30906 * away
30907@@ -405,7 +405,7 @@ int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring)
30908 }
30909 rdev->fence_drv[ring].cpu_addr = &rdev->wb.wb[index/4];
30910 rdev->fence_drv[ring].gpu_addr = rdev->wb.gpu_addr + index;
30911- radeon_fence_write(rdev, atomic_read(&rdev->fence_drv[ring].seq), ring);
30912+ radeon_fence_write(rdev, atomic_read_unchecked(&rdev->fence_drv[ring].seq), ring);
30913 rdev->fence_drv[ring].initialized = true;
30914 DRM_INFO("fence driver on ring %d use gpu addr 0x%08Lx and cpu addr 0x%p\n",
30915 ring, rdev->fence_drv[ring].gpu_addr, rdev->fence_drv[ring].cpu_addr);
30916@@ -418,7 +418,7 @@ static void radeon_fence_driver_init_ring(struct radeon_device *rdev, int ring)
30917 rdev->fence_drv[ring].scratch_reg = -1;
30918 rdev->fence_drv[ring].cpu_addr = NULL;
30919 rdev->fence_drv[ring].gpu_addr = 0;
30920- atomic_set(&rdev->fence_drv[ring].seq, 0);
30921+ atomic_set_unchecked(&rdev->fence_drv[ring].seq, 0);
30922 INIT_LIST_HEAD(&rdev->fence_drv[ring].created);
30923 INIT_LIST_HEAD(&rdev->fence_drv[ring].emitted);
30924 INIT_LIST_HEAD(&rdev->fence_drv[ring].signaled);
30925diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
30926index 48b7cea..342236f 100644
30927--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
30928+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
30929@@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
30930 request = compat_alloc_user_space(sizeof(*request));
30931 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30932 || __put_user(req32.param, &request->param)
30933- || __put_user((void __user *)(unsigned long)req32.value,
30934+ || __put_user((unsigned long)req32.value,
30935 &request->value))
30936 return -EFAULT;
30937
30938diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
30939index 00da384..32f972d 100644
30940--- a/drivers/gpu/drm/radeon/radeon_irq.c
30941+++ b/drivers/gpu/drm/radeon/radeon_irq.c
30942@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
30943 unsigned int ret;
30944 RING_LOCALS;
30945
30946- atomic_inc(&dev_priv->swi_emitted);
30947- ret = atomic_read(&dev_priv->swi_emitted);
30948+ atomic_inc_unchecked(&dev_priv->swi_emitted);
30949+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30950
30951 BEGIN_RING(4);
30952 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30953@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
30954 drm_radeon_private_t *dev_priv =
30955 (drm_radeon_private_t *) dev->dev_private;
30956
30957- atomic_set(&dev_priv->swi_emitted, 0);
30958+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30959 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30960
30961 dev->max_vblank_count = 0x001fffff;
30962diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
30963index e8422ae..d22d4a8 100644
30964--- a/drivers/gpu/drm/radeon/radeon_state.c
30965+++ b/drivers/gpu/drm/radeon/radeon_state.c
30966@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
30967 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
30968 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
30969
30970- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30971+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30972 sarea_priv->nbox * sizeof(depth_boxes[0])))
30973 return -EFAULT;
30974
30975@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
30976 {
30977 drm_radeon_private_t *dev_priv = dev->dev_private;
30978 drm_radeon_getparam_t *param = data;
30979- int value;
30980+ int value = 0;
30981
30982 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
30983
30984diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
30985index f493c64..524ab6b 100644
30986--- a/drivers/gpu/drm/radeon/radeon_ttm.c
30987+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
30988@@ -843,8 +843,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
30989 }
30990 if (unlikely(ttm_vm_ops == NULL)) {
30991 ttm_vm_ops = vma->vm_ops;
30992- radeon_ttm_vm_ops = *ttm_vm_ops;
30993- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30994+ pax_open_kernel();
30995+ memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
30996+ *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30997+ pax_close_kernel();
30998 }
30999 vma->vm_ops = &radeon_ttm_vm_ops;
31000 return 0;
31001diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31002index f2c3b9d..d5a376b 100644
31003--- a/drivers/gpu/drm/radeon/rs690.c
31004+++ b/drivers/gpu/drm/radeon/rs690.c
31005@@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31006 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31007 rdev->pm.sideport_bandwidth.full)
31008 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31009- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31010+ read_delay_latency.full = dfixed_const(800 * 1000);
31011 read_delay_latency.full = dfixed_div(read_delay_latency,
31012 rdev->pm.igp_sideport_mclk);
31013+ a.full = dfixed_const(370);
31014+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31015 } else {
31016 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31017 rdev->pm.k8_bandwidth.full)
31018diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31019index ebc6fac..a8313ed 100644
31020--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31021+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31022@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31023 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31024 struct shrink_control *sc)
31025 {
31026- static atomic_t start_pool = ATOMIC_INIT(0);
31027+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31028 unsigned i;
31029- unsigned pool_offset = atomic_add_return(1, &start_pool);
31030+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31031 struct ttm_page_pool *pool;
31032 int shrink_pages = sc->nr_to_scan;
31033
31034diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31035index 88edacc..1e5412b 100644
31036--- a/drivers/gpu/drm/via/via_drv.h
31037+++ b/drivers/gpu/drm/via/via_drv.h
31038@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31039 typedef uint32_t maskarray_t[5];
31040
31041 typedef struct drm_via_irq {
31042- atomic_t irq_received;
31043+ atomic_unchecked_t irq_received;
31044 uint32_t pending_mask;
31045 uint32_t enable_mask;
31046 wait_queue_head_t irq_queue;
31047@@ -75,7 +75,7 @@ typedef struct drm_via_private {
31048 struct timeval last_vblank;
31049 int last_vblank_valid;
31050 unsigned usec_per_vblank;
31051- atomic_t vbl_received;
31052+ atomic_unchecked_t vbl_received;
31053 drm_via_state_t hc_state;
31054 char pci_buf[VIA_PCI_BUF_SIZE];
31055 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31056diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31057index d391f48..10c8ca3 100644
31058--- a/drivers/gpu/drm/via/via_irq.c
31059+++ b/drivers/gpu/drm/via/via_irq.c
31060@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31061 if (crtc != 0)
31062 return 0;
31063
31064- return atomic_read(&dev_priv->vbl_received);
31065+ return atomic_read_unchecked(&dev_priv->vbl_received);
31066 }
31067
31068 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31069@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31070
31071 status = VIA_READ(VIA_REG_INTERRUPT);
31072 if (status & VIA_IRQ_VBLANK_PENDING) {
31073- atomic_inc(&dev_priv->vbl_received);
31074- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31075+ atomic_inc_unchecked(&dev_priv->vbl_received);
31076+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31077 do_gettimeofday(&cur_vblank);
31078 if (dev_priv->last_vblank_valid) {
31079 dev_priv->usec_per_vblank =
31080@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31081 dev_priv->last_vblank = cur_vblank;
31082 dev_priv->last_vblank_valid = 1;
31083 }
31084- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31085+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31086 DRM_DEBUG("US per vblank is: %u\n",
31087 dev_priv->usec_per_vblank);
31088 }
31089@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31090
31091 for (i = 0; i < dev_priv->num_irqs; ++i) {
31092 if (status & cur_irq->pending_mask) {
31093- atomic_inc(&cur_irq->irq_received);
31094+ atomic_inc_unchecked(&cur_irq->irq_received);
31095 DRM_WAKEUP(&cur_irq->irq_queue);
31096 handled = 1;
31097 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31098@@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31099 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31100 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31101 masks[irq][4]));
31102- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31103+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31104 } else {
31105 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31106 (((cur_irq_sequence =
31107- atomic_read(&cur_irq->irq_received)) -
31108+ atomic_read_unchecked(&cur_irq->irq_received)) -
31109 *sequence) <= (1 << 23)));
31110 }
31111 *sequence = cur_irq_sequence;
31112@@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31113 }
31114
31115 for (i = 0; i < dev_priv->num_irqs; ++i) {
31116- atomic_set(&cur_irq->irq_received, 0);
31117+ atomic_set_unchecked(&cur_irq->irq_received, 0);
31118 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31119 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31120 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31121@@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31122 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31123 case VIA_IRQ_RELATIVE:
31124 irqwait->request.sequence +=
31125- atomic_read(&cur_irq->irq_received);
31126+ atomic_read_unchecked(&cur_irq->irq_received);
31127 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31128 case VIA_IRQ_ABSOLUTE:
31129 break;
31130diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31131index d0f2c07..9ebd9c3 100644
31132--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31133+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31134@@ -263,7 +263,7 @@ struct vmw_private {
31135 * Fencing and IRQs.
31136 */
31137
31138- atomic_t marker_seq;
31139+ atomic_unchecked_t marker_seq;
31140 wait_queue_head_t fence_queue;
31141 wait_queue_head_t fifo_queue;
31142 int fence_queue_waiters; /* Protected by hw_mutex */
31143diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31144index a0c2f12..68ae6cb 100644
31145--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31146+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31147@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31148 (unsigned int) min,
31149 (unsigned int) fifo->capabilities);
31150
31151- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31152+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31153 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31154 vmw_marker_queue_init(&fifo->marker_queue);
31155 return vmw_fifo_send_fence(dev_priv, &dummy);
31156@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31157 if (reserveable)
31158 iowrite32(bytes, fifo_mem +
31159 SVGA_FIFO_RESERVED);
31160- return fifo_mem + (next_cmd >> 2);
31161+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31162 } else {
31163 need_bounce = true;
31164 }
31165@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31166
31167 fm = vmw_fifo_reserve(dev_priv, bytes);
31168 if (unlikely(fm == NULL)) {
31169- *seqno = atomic_read(&dev_priv->marker_seq);
31170+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31171 ret = -ENOMEM;
31172 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31173 false, 3*HZ);
31174@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31175 }
31176
31177 do {
31178- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31179+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31180 } while (*seqno == 0);
31181
31182 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31183diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31184index cabc95f..14b3d77 100644
31185--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31186+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31187@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31188 * emitted. Then the fence is stale and signaled.
31189 */
31190
31191- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31192+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31193 > VMW_FENCE_WRAP);
31194
31195 return ret;
31196@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31197
31198 if (fifo_idle)
31199 down_read(&fifo_state->rwsem);
31200- signal_seq = atomic_read(&dev_priv->marker_seq);
31201+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31202 ret = 0;
31203
31204 for (;;) {
31205diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31206index 8a8725c..afed796 100644
31207--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31208+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31209@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31210 while (!vmw_lag_lt(queue, us)) {
31211 spin_lock(&queue->lock);
31212 if (list_empty(&queue->head))
31213- seqno = atomic_read(&dev_priv->marker_seq);
31214+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31215 else {
31216 marker = list_first_entry(&queue->head,
31217 struct vmw_marker, head);
31218diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31219index 4da66b4..e948655 100644
31220--- a/drivers/hid/hid-core.c
31221+++ b/drivers/hid/hid-core.c
31222@@ -2063,7 +2063,7 @@ static bool hid_ignore(struct hid_device *hdev)
31223
31224 int hid_add_device(struct hid_device *hdev)
31225 {
31226- static atomic_t id = ATOMIC_INIT(0);
31227+ static atomic_unchecked_t id = ATOMIC_INIT(0);
31228 int ret;
31229
31230 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31231@@ -2078,7 +2078,7 @@ int hid_add_device(struct hid_device *hdev)
31232 /* XXX hack, any other cleaner solution after the driver core
31233 * is converted to allow more than 20 bytes as the device name? */
31234 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31235- hdev->vendor, hdev->product, atomic_inc_return(&id));
31236+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31237
31238 hid_debug_register(hdev, dev_name(&hdev->dev));
31239 ret = device_add(&hdev->dev);
31240diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31241index eec3291..8ed706b 100644
31242--- a/drivers/hid/hid-wiimote-debug.c
31243+++ b/drivers/hid/hid-wiimote-debug.c
31244@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31245 else if (size == 0)
31246 return -EIO;
31247
31248- if (copy_to_user(u, buf, size))
31249+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
31250 return -EFAULT;
31251
31252 *off += size;
31253diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31254index b1ec0e2..c295a61 100644
31255--- a/drivers/hid/usbhid/hiddev.c
31256+++ b/drivers/hid/usbhid/hiddev.c
31257@@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31258 break;
31259
31260 case HIDIOCAPPLICATION:
31261- if (arg < 0 || arg >= hid->maxapplication)
31262+ if (arg >= hid->maxapplication)
31263 break;
31264
31265 for (i = 0; i < hid->maxcollection; i++)
31266diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31267index 4065374..10ed7dc 100644
31268--- a/drivers/hv/channel.c
31269+++ b/drivers/hv/channel.c
31270@@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31271 int ret = 0;
31272 int t;
31273
31274- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31275- atomic_inc(&vmbus_connection.next_gpadl_handle);
31276+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31277+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31278
31279 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31280 if (ret)
31281diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31282index 15956bd..ea34398 100644
31283--- a/drivers/hv/hv.c
31284+++ b/drivers/hv/hv.c
31285@@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31286 u64 output_address = (output) ? virt_to_phys(output) : 0;
31287 u32 output_address_hi = output_address >> 32;
31288 u32 output_address_lo = output_address & 0xFFFFFFFF;
31289- void *hypercall_page = hv_context.hypercall_page;
31290+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31291
31292 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31293 "=a"(hv_status_lo) : "d" (control_hi),
31294diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31295index 699f0d8..f4f19250 100644
31296--- a/drivers/hv/hyperv_vmbus.h
31297+++ b/drivers/hv/hyperv_vmbus.h
31298@@ -555,7 +555,7 @@ enum vmbus_connect_state {
31299 struct vmbus_connection {
31300 enum vmbus_connect_state conn_state;
31301
31302- atomic_t next_gpadl_handle;
31303+ atomic_unchecked_t next_gpadl_handle;
31304
31305 /*
31306 * Represents channel interrupts. Each bit position represents a
31307diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31308index a220e57..428f54d 100644
31309--- a/drivers/hv/vmbus_drv.c
31310+++ b/drivers/hv/vmbus_drv.c
31311@@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31312 {
31313 int ret = 0;
31314
31315- static atomic_t device_num = ATOMIC_INIT(0);
31316+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31317
31318 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31319- atomic_inc_return(&device_num));
31320+ atomic_inc_return_unchecked(&device_num));
31321
31322 child_device_obj->device.bus = &hv_bus;
31323 child_device_obj->device.parent = &hv_acpi_dev->dev;
31324diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31325index 9140236..ceaef4e 100644
31326--- a/drivers/hwmon/acpi_power_meter.c
31327+++ b/drivers/hwmon/acpi_power_meter.c
31328@@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31329 return res;
31330
31331 temp /= 1000;
31332- if (temp < 0)
31333- return -EINVAL;
31334
31335 mutex_lock(&resource->lock);
31336 resource->trip[attr->index - 7] = temp;
31337diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31338index 8b011d0..3de24a1 100644
31339--- a/drivers/hwmon/sht15.c
31340+++ b/drivers/hwmon/sht15.c
31341@@ -166,7 +166,7 @@ struct sht15_data {
31342 int supply_uV;
31343 bool supply_uV_valid;
31344 struct work_struct update_supply_work;
31345- atomic_t interrupt_handled;
31346+ atomic_unchecked_t interrupt_handled;
31347 };
31348
31349 /**
31350@@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31351 return ret;
31352
31353 gpio_direction_input(data->pdata->gpio_data);
31354- atomic_set(&data->interrupt_handled, 0);
31355+ atomic_set_unchecked(&data->interrupt_handled, 0);
31356
31357 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31358 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31359 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31360 /* Only relevant if the interrupt hasn't occurred. */
31361- if (!atomic_read(&data->interrupt_handled))
31362+ if (!atomic_read_unchecked(&data->interrupt_handled))
31363 schedule_work(&data->read_work);
31364 }
31365 ret = wait_event_timeout(data->wait_queue,
31366@@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31367
31368 /* First disable the interrupt */
31369 disable_irq_nosync(irq);
31370- atomic_inc(&data->interrupt_handled);
31371+ atomic_inc_unchecked(&data->interrupt_handled);
31372 /* Then schedule a reading work struct */
31373 if (data->state != SHT15_READING_NOTHING)
31374 schedule_work(&data->read_work);
31375@@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31376 * If not, then start the interrupt again - care here as could
31377 * have gone low in meantime so verify it hasn't!
31378 */
31379- atomic_set(&data->interrupt_handled, 0);
31380+ atomic_set_unchecked(&data->interrupt_handled, 0);
31381 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31382 /* If still not occurred or another handler was scheduled */
31383 if (gpio_get_value(data->pdata->gpio_data)
31384- || atomic_read(&data->interrupt_handled))
31385+ || atomic_read_unchecked(&data->interrupt_handled))
31386 return;
31387 }
31388
31389diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31390index 378fcb5..5e91fa8 100644
31391--- a/drivers/i2c/busses/i2c-amd756-s4882.c
31392+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31393@@ -43,7 +43,7 @@
31394 extern struct i2c_adapter amd756_smbus;
31395
31396 static struct i2c_adapter *s4882_adapter;
31397-static struct i2c_algorithm *s4882_algo;
31398+static i2c_algorithm_no_const *s4882_algo;
31399
31400 /* Wrapper access functions for multiplexed SMBus */
31401 static DEFINE_MUTEX(amd756_lock);
31402diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31403index 29015eb..af2d8e9 100644
31404--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31405+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31406@@ -41,7 +41,7 @@
31407 extern struct i2c_adapter *nforce2_smbus;
31408
31409 static struct i2c_adapter *s4985_adapter;
31410-static struct i2c_algorithm *s4985_algo;
31411+static i2c_algorithm_no_const *s4985_algo;
31412
31413 /* Wrapper access functions for multiplexed SMBus */
31414 static DEFINE_MUTEX(nforce2_lock);
31415diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31416index d7a4833..7fae376 100644
31417--- a/drivers/i2c/i2c-mux.c
31418+++ b/drivers/i2c/i2c-mux.c
31419@@ -28,7 +28,7 @@
31420 /* multiplexer per channel data */
31421 struct i2c_mux_priv {
31422 struct i2c_adapter adap;
31423- struct i2c_algorithm algo;
31424+ i2c_algorithm_no_const algo;
31425
31426 struct i2c_adapter *parent;
31427 void *mux_dev; /* the mux chip/device */
31428diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31429index 57d00ca..0145194 100644
31430--- a/drivers/ide/aec62xx.c
31431+++ b/drivers/ide/aec62xx.c
31432@@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31433 .cable_detect = atp86x_cable_detect,
31434 };
31435
31436-static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31437+static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31438 { /* 0: AEC6210 */
31439 .name = DRV_NAME,
31440 .init_chipset = init_chipset_aec62xx,
31441diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31442index 2c8016a..911a27c 100644
31443--- a/drivers/ide/alim15x3.c
31444+++ b/drivers/ide/alim15x3.c
31445@@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31446 .dma_sff_read_status = ide_dma_sff_read_status,
31447 };
31448
31449-static const struct ide_port_info ali15x3_chipset __devinitdata = {
31450+static const struct ide_port_info ali15x3_chipset __devinitconst = {
31451 .name = DRV_NAME,
31452 .init_chipset = init_chipset_ali15x3,
31453 .init_hwif = init_hwif_ali15x3,
31454diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31455index 3747b25..56fc995 100644
31456--- a/drivers/ide/amd74xx.c
31457+++ b/drivers/ide/amd74xx.c
31458@@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31459 .udma_mask = udma, \
31460 }
31461
31462-static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31463+static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31464 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31465 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31466 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31467diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31468index 15f0ead..cb43480 100644
31469--- a/drivers/ide/atiixp.c
31470+++ b/drivers/ide/atiixp.c
31471@@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31472 .cable_detect = atiixp_cable_detect,
31473 };
31474
31475-static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31476+static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31477 { /* 0: IXP200/300/400/700 */
31478 .name = DRV_NAME,
31479 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31480diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31481index 5f80312..d1fc438 100644
31482--- a/drivers/ide/cmd64x.c
31483+++ b/drivers/ide/cmd64x.c
31484@@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31485 .dma_sff_read_status = ide_dma_sff_read_status,
31486 };
31487
31488-static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31489+static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31490 { /* 0: CMD643 */
31491 .name = DRV_NAME,
31492 .init_chipset = init_chipset_cmd64x,
31493diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31494index 2c1e5f7..1444762 100644
31495--- a/drivers/ide/cs5520.c
31496+++ b/drivers/ide/cs5520.c
31497@@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31498 .set_dma_mode = cs5520_set_dma_mode,
31499 };
31500
31501-static const struct ide_port_info cyrix_chipset __devinitdata = {
31502+static const struct ide_port_info cyrix_chipset __devinitconst = {
31503 .name = DRV_NAME,
31504 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31505 .port_ops = &cs5520_port_ops,
31506diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31507index 4dc4eb9..49b40ad 100644
31508--- a/drivers/ide/cs5530.c
31509+++ b/drivers/ide/cs5530.c
31510@@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31511 .udma_filter = cs5530_udma_filter,
31512 };
31513
31514-static const struct ide_port_info cs5530_chipset __devinitdata = {
31515+static const struct ide_port_info cs5530_chipset __devinitconst = {
31516 .name = DRV_NAME,
31517 .init_chipset = init_chipset_cs5530,
31518 .init_hwif = init_hwif_cs5530,
31519diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31520index 5059faf..18d4c85 100644
31521--- a/drivers/ide/cs5535.c
31522+++ b/drivers/ide/cs5535.c
31523@@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31524 .cable_detect = cs5535_cable_detect,
31525 };
31526
31527-static const struct ide_port_info cs5535_chipset __devinitdata = {
31528+static const struct ide_port_info cs5535_chipset __devinitconst = {
31529 .name = DRV_NAME,
31530 .port_ops = &cs5535_port_ops,
31531 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31532diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31533index 847553f..3ffb49d 100644
31534--- a/drivers/ide/cy82c693.c
31535+++ b/drivers/ide/cy82c693.c
31536@@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31537 .set_dma_mode = cy82c693_set_dma_mode,
31538 };
31539
31540-static const struct ide_port_info cy82c693_chipset __devinitdata = {
31541+static const struct ide_port_info cy82c693_chipset __devinitconst = {
31542 .name = DRV_NAME,
31543 .init_iops = init_iops_cy82c693,
31544 .port_ops = &cy82c693_port_ops,
31545diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31546index 58c51cd..4aec3b8 100644
31547--- a/drivers/ide/hpt366.c
31548+++ b/drivers/ide/hpt366.c
31549@@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31550 }
31551 };
31552
31553-static const struct hpt_info hpt36x __devinitdata = {
31554+static const struct hpt_info hpt36x __devinitconst = {
31555 .chip_name = "HPT36x",
31556 .chip_type = HPT36x,
31557 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31558@@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31559 .timings = &hpt36x_timings
31560 };
31561
31562-static const struct hpt_info hpt370 __devinitdata = {
31563+static const struct hpt_info hpt370 __devinitconst = {
31564 .chip_name = "HPT370",
31565 .chip_type = HPT370,
31566 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31567@@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31568 .timings = &hpt37x_timings
31569 };
31570
31571-static const struct hpt_info hpt370a __devinitdata = {
31572+static const struct hpt_info hpt370a __devinitconst = {
31573 .chip_name = "HPT370A",
31574 .chip_type = HPT370A,
31575 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31576@@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31577 .timings = &hpt37x_timings
31578 };
31579
31580-static const struct hpt_info hpt374 __devinitdata = {
31581+static const struct hpt_info hpt374 __devinitconst = {
31582 .chip_name = "HPT374",
31583 .chip_type = HPT374,
31584 .udma_mask = ATA_UDMA5,
31585@@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31586 .timings = &hpt37x_timings
31587 };
31588
31589-static const struct hpt_info hpt372 __devinitdata = {
31590+static const struct hpt_info hpt372 __devinitconst = {
31591 .chip_name = "HPT372",
31592 .chip_type = HPT372,
31593 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31594@@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31595 .timings = &hpt37x_timings
31596 };
31597
31598-static const struct hpt_info hpt372a __devinitdata = {
31599+static const struct hpt_info hpt372a __devinitconst = {
31600 .chip_name = "HPT372A",
31601 .chip_type = HPT372A,
31602 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31603@@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31604 .timings = &hpt37x_timings
31605 };
31606
31607-static const struct hpt_info hpt302 __devinitdata = {
31608+static const struct hpt_info hpt302 __devinitconst = {
31609 .chip_name = "HPT302",
31610 .chip_type = HPT302,
31611 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31612@@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31613 .timings = &hpt37x_timings
31614 };
31615
31616-static const struct hpt_info hpt371 __devinitdata = {
31617+static const struct hpt_info hpt371 __devinitconst = {
31618 .chip_name = "HPT371",
31619 .chip_type = HPT371,
31620 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31621@@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31622 .timings = &hpt37x_timings
31623 };
31624
31625-static const struct hpt_info hpt372n __devinitdata = {
31626+static const struct hpt_info hpt372n __devinitconst = {
31627 .chip_name = "HPT372N",
31628 .chip_type = HPT372N,
31629 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31630@@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31631 .timings = &hpt37x_timings
31632 };
31633
31634-static const struct hpt_info hpt302n __devinitdata = {
31635+static const struct hpt_info hpt302n __devinitconst = {
31636 .chip_name = "HPT302N",
31637 .chip_type = HPT302N,
31638 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31639@@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31640 .timings = &hpt37x_timings
31641 };
31642
31643-static const struct hpt_info hpt371n __devinitdata = {
31644+static const struct hpt_info hpt371n __devinitconst = {
31645 .chip_name = "HPT371N",
31646 .chip_type = HPT371N,
31647 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31648@@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31649 .dma_sff_read_status = ide_dma_sff_read_status,
31650 };
31651
31652-static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31653+static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31654 { /* 0: HPT36x */
31655 .name = DRV_NAME,
31656 .init_chipset = init_chipset_hpt366,
31657diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31658index 8126824..55a2798 100644
31659--- a/drivers/ide/ide-cd.c
31660+++ b/drivers/ide/ide-cd.c
31661@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31662 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31663 if ((unsigned long)buf & alignment
31664 || blk_rq_bytes(rq) & q->dma_pad_mask
31665- || object_is_on_stack(buf))
31666+ || object_starts_on_stack(buf))
31667 drive->dma = 0;
31668 }
31669 }
31670diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31671index 7f56b73..dab5b67 100644
31672--- a/drivers/ide/ide-pci-generic.c
31673+++ b/drivers/ide/ide-pci-generic.c
31674@@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31675 .udma_mask = ATA_UDMA6, \
31676 }
31677
31678-static const struct ide_port_info generic_chipsets[] __devinitdata = {
31679+static const struct ide_port_info generic_chipsets[] __devinitconst = {
31680 /* 0: Unknown */
31681 DECLARE_GENERIC_PCI_DEV(0),
31682
31683diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31684index 560e66d..d5dd180 100644
31685--- a/drivers/ide/it8172.c
31686+++ b/drivers/ide/it8172.c
31687@@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31688 .set_dma_mode = it8172_set_dma_mode,
31689 };
31690
31691-static const struct ide_port_info it8172_port_info __devinitdata = {
31692+static const struct ide_port_info it8172_port_info __devinitconst = {
31693 .name = DRV_NAME,
31694 .port_ops = &it8172_port_ops,
31695 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31696diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31697index 46816ba..1847aeb 100644
31698--- a/drivers/ide/it8213.c
31699+++ b/drivers/ide/it8213.c
31700@@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31701 .cable_detect = it8213_cable_detect,
31702 };
31703
31704-static const struct ide_port_info it8213_chipset __devinitdata = {
31705+static const struct ide_port_info it8213_chipset __devinitconst = {
31706 .name = DRV_NAME,
31707 .enablebits = { {0x41, 0x80, 0x80} },
31708 .port_ops = &it8213_port_ops,
31709diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31710index 2e3169f..c5611db 100644
31711--- a/drivers/ide/it821x.c
31712+++ b/drivers/ide/it821x.c
31713@@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31714 .cable_detect = it821x_cable_detect,
31715 };
31716
31717-static const struct ide_port_info it821x_chipset __devinitdata = {
31718+static const struct ide_port_info it821x_chipset __devinitconst = {
31719 .name = DRV_NAME,
31720 .init_chipset = init_chipset_it821x,
31721 .init_hwif = init_hwif_it821x,
31722diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31723index 74c2c4a..efddd7d 100644
31724--- a/drivers/ide/jmicron.c
31725+++ b/drivers/ide/jmicron.c
31726@@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31727 .cable_detect = jmicron_cable_detect,
31728 };
31729
31730-static const struct ide_port_info jmicron_chipset __devinitdata = {
31731+static const struct ide_port_info jmicron_chipset __devinitconst = {
31732 .name = DRV_NAME,
31733 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31734 .port_ops = &jmicron_port_ops,
31735diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31736index 95327a2..73f78d8 100644
31737--- a/drivers/ide/ns87415.c
31738+++ b/drivers/ide/ns87415.c
31739@@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31740 .dma_sff_read_status = superio_dma_sff_read_status,
31741 };
31742
31743-static const struct ide_port_info ns87415_chipset __devinitdata = {
31744+static const struct ide_port_info ns87415_chipset __devinitconst = {
31745 .name = DRV_NAME,
31746 .init_hwif = init_hwif_ns87415,
31747 .tp_ops = &ns87415_tp_ops,
31748diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31749index 1a53a4c..39edc66 100644
31750--- a/drivers/ide/opti621.c
31751+++ b/drivers/ide/opti621.c
31752@@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31753 .set_pio_mode = opti621_set_pio_mode,
31754 };
31755
31756-static const struct ide_port_info opti621_chipset __devinitdata = {
31757+static const struct ide_port_info opti621_chipset __devinitconst = {
31758 .name = DRV_NAME,
31759 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31760 .port_ops = &opti621_port_ops,
31761diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31762index 9546fe2..2e5ceb6 100644
31763--- a/drivers/ide/pdc202xx_new.c
31764+++ b/drivers/ide/pdc202xx_new.c
31765@@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31766 .udma_mask = udma, \
31767 }
31768
31769-static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31770+static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31771 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31772 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31773 };
31774diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31775index 3a35ec6..5634510 100644
31776--- a/drivers/ide/pdc202xx_old.c
31777+++ b/drivers/ide/pdc202xx_old.c
31778@@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31779 .max_sectors = sectors, \
31780 }
31781
31782-static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31783+static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31784 { /* 0: PDC20246 */
31785 .name = DRV_NAME,
31786 .init_chipset = init_chipset_pdc202xx,
31787diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31788index 1892e81..fe0fd60 100644
31789--- a/drivers/ide/piix.c
31790+++ b/drivers/ide/piix.c
31791@@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31792 .udma_mask = udma, \
31793 }
31794
31795-static const struct ide_port_info piix_pci_info[] __devinitdata = {
31796+static const struct ide_port_info piix_pci_info[] __devinitconst = {
31797 /* 0: MPIIX */
31798 { /*
31799 * MPIIX actually has only a single IDE channel mapped to
31800diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31801index a6414a8..c04173e 100644
31802--- a/drivers/ide/rz1000.c
31803+++ b/drivers/ide/rz1000.c
31804@@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31805 }
31806 }
31807
31808-static const struct ide_port_info rz1000_chipset __devinitdata = {
31809+static const struct ide_port_info rz1000_chipset __devinitconst = {
31810 .name = DRV_NAME,
31811 .host_flags = IDE_HFLAG_NO_DMA,
31812 };
31813diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31814index 356b9b5..d4758eb 100644
31815--- a/drivers/ide/sc1200.c
31816+++ b/drivers/ide/sc1200.c
31817@@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31818 .dma_sff_read_status = ide_dma_sff_read_status,
31819 };
31820
31821-static const struct ide_port_info sc1200_chipset __devinitdata = {
31822+static const struct ide_port_info sc1200_chipset __devinitconst = {
31823 .name = DRV_NAME,
31824 .port_ops = &sc1200_port_ops,
31825 .dma_ops = &sc1200_dma_ops,
31826diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31827index b7f5b0c..9701038 100644
31828--- a/drivers/ide/scc_pata.c
31829+++ b/drivers/ide/scc_pata.c
31830@@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31831 .dma_sff_read_status = scc_dma_sff_read_status,
31832 };
31833
31834-static const struct ide_port_info scc_chipset __devinitdata = {
31835+static const struct ide_port_info scc_chipset __devinitconst = {
31836 .name = "sccIDE",
31837 .init_iops = init_iops_scc,
31838 .init_dma = scc_init_dma,
31839diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31840index 35fb8da..24d72ef 100644
31841--- a/drivers/ide/serverworks.c
31842+++ b/drivers/ide/serverworks.c
31843@@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31844 .cable_detect = svwks_cable_detect,
31845 };
31846
31847-static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31848+static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31849 { /* 0: OSB4 */
31850 .name = DRV_NAME,
31851 .init_chipset = init_chipset_svwks,
31852diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31853index ddeda44..46f7e30 100644
31854--- a/drivers/ide/siimage.c
31855+++ b/drivers/ide/siimage.c
31856@@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31857 .udma_mask = ATA_UDMA6, \
31858 }
31859
31860-static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31861+static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31862 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31863 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31864 };
31865diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31866index 4a00225..09e61b4 100644
31867--- a/drivers/ide/sis5513.c
31868+++ b/drivers/ide/sis5513.c
31869@@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31870 .cable_detect = sis_cable_detect,
31871 };
31872
31873-static const struct ide_port_info sis5513_chipset __devinitdata = {
31874+static const struct ide_port_info sis5513_chipset __devinitconst = {
31875 .name = DRV_NAME,
31876 .init_chipset = init_chipset_sis5513,
31877 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31878diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31879index f21dc2a..d051cd2 100644
31880--- a/drivers/ide/sl82c105.c
31881+++ b/drivers/ide/sl82c105.c
31882@@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31883 .dma_sff_read_status = ide_dma_sff_read_status,
31884 };
31885
31886-static const struct ide_port_info sl82c105_chipset __devinitdata = {
31887+static const struct ide_port_info sl82c105_chipset __devinitconst = {
31888 .name = DRV_NAME,
31889 .init_chipset = init_chipset_sl82c105,
31890 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31891diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31892index 864ffe0..863a5e9 100644
31893--- a/drivers/ide/slc90e66.c
31894+++ b/drivers/ide/slc90e66.c
31895@@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31896 .cable_detect = slc90e66_cable_detect,
31897 };
31898
31899-static const struct ide_port_info slc90e66_chipset __devinitdata = {
31900+static const struct ide_port_info slc90e66_chipset __devinitconst = {
31901 .name = DRV_NAME,
31902 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
31903 .port_ops = &slc90e66_port_ops,
31904diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
31905index 4799d5c..1794678 100644
31906--- a/drivers/ide/tc86c001.c
31907+++ b/drivers/ide/tc86c001.c
31908@@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
31909 .dma_sff_read_status = ide_dma_sff_read_status,
31910 };
31911
31912-static const struct ide_port_info tc86c001_chipset __devinitdata = {
31913+static const struct ide_port_info tc86c001_chipset __devinitconst = {
31914 .name = DRV_NAME,
31915 .init_hwif = init_hwif_tc86c001,
31916 .port_ops = &tc86c001_port_ops,
31917diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
31918index 281c914..55ce1b8 100644
31919--- a/drivers/ide/triflex.c
31920+++ b/drivers/ide/triflex.c
31921@@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
31922 .set_dma_mode = triflex_set_mode,
31923 };
31924
31925-static const struct ide_port_info triflex_device __devinitdata = {
31926+static const struct ide_port_info triflex_device __devinitconst = {
31927 .name = DRV_NAME,
31928 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
31929 .port_ops = &triflex_port_ops,
31930diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
31931index 4b42ca0..e494a98 100644
31932--- a/drivers/ide/trm290.c
31933+++ b/drivers/ide/trm290.c
31934@@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
31935 .dma_check = trm290_dma_check,
31936 };
31937
31938-static const struct ide_port_info trm290_chipset __devinitdata = {
31939+static const struct ide_port_info trm290_chipset __devinitconst = {
31940 .name = DRV_NAME,
31941 .init_hwif = init_hwif_trm290,
31942 .tp_ops = &trm290_tp_ops,
31943diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
31944index f46f49c..eb77678 100644
31945--- a/drivers/ide/via82cxxx.c
31946+++ b/drivers/ide/via82cxxx.c
31947@@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
31948 .cable_detect = via82cxxx_cable_detect,
31949 };
31950
31951-static const struct ide_port_info via82cxxx_chipset __devinitdata = {
31952+static const struct ide_port_info via82cxxx_chipset __devinitconst = {
31953 .name = DRV_NAME,
31954 .init_chipset = init_chipset_via82cxxx,
31955 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
31956diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
31957index 73d4531..c90cd2d 100644
31958--- a/drivers/ieee802154/fakehard.c
31959+++ b/drivers/ieee802154/fakehard.c
31960@@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
31961 phy->transmit_power = 0xbf;
31962
31963 dev->netdev_ops = &fake_ops;
31964- dev->ml_priv = &fake_mlme;
31965+ dev->ml_priv = (void *)&fake_mlme;
31966
31967 priv = netdev_priv(dev);
31968 priv->phy = phy;
31969diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
31970index c889aae..6cf5aa7 100644
31971--- a/drivers/infiniband/core/cm.c
31972+++ b/drivers/infiniband/core/cm.c
31973@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
31974
31975 struct cm_counter_group {
31976 struct kobject obj;
31977- atomic_long_t counter[CM_ATTR_COUNT];
31978+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
31979 };
31980
31981 struct cm_counter_attribute {
31982@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
31983 struct ib_mad_send_buf *msg = NULL;
31984 int ret;
31985
31986- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31987+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31988 counter[CM_REQ_COUNTER]);
31989
31990 /* Quick state check to discard duplicate REQs. */
31991@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
31992 if (!cm_id_priv)
31993 return;
31994
31995- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31996+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31997 counter[CM_REP_COUNTER]);
31998 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
31999 if (ret)
32000@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32001 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32002 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32003 spin_unlock_irq(&cm_id_priv->lock);
32004- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32005+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32006 counter[CM_RTU_COUNTER]);
32007 goto out;
32008 }
32009@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32010 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32011 dreq_msg->local_comm_id);
32012 if (!cm_id_priv) {
32013- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32014+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32015 counter[CM_DREQ_COUNTER]);
32016 cm_issue_drep(work->port, work->mad_recv_wc);
32017 return -EINVAL;
32018@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32019 case IB_CM_MRA_REP_RCVD:
32020 break;
32021 case IB_CM_TIMEWAIT:
32022- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32023+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32024 counter[CM_DREQ_COUNTER]);
32025 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32026 goto unlock;
32027@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32028 cm_free_msg(msg);
32029 goto deref;
32030 case IB_CM_DREQ_RCVD:
32031- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32032+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32033 counter[CM_DREQ_COUNTER]);
32034 goto unlock;
32035 default:
32036@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32037 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32038 cm_id_priv->msg, timeout)) {
32039 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32040- atomic_long_inc(&work->port->
32041+ atomic_long_inc_unchecked(&work->port->
32042 counter_group[CM_RECV_DUPLICATES].
32043 counter[CM_MRA_COUNTER]);
32044 goto out;
32045@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32046 break;
32047 case IB_CM_MRA_REQ_RCVD:
32048 case IB_CM_MRA_REP_RCVD:
32049- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32050+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32051 counter[CM_MRA_COUNTER]);
32052 /* fall through */
32053 default:
32054@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32055 case IB_CM_LAP_IDLE:
32056 break;
32057 case IB_CM_MRA_LAP_SENT:
32058- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32059+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32060 counter[CM_LAP_COUNTER]);
32061 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32062 goto unlock;
32063@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32064 cm_free_msg(msg);
32065 goto deref;
32066 case IB_CM_LAP_RCVD:
32067- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32068+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32069 counter[CM_LAP_COUNTER]);
32070 goto unlock;
32071 default:
32072@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32073 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32074 if (cur_cm_id_priv) {
32075 spin_unlock_irq(&cm.lock);
32076- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32077+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32078 counter[CM_SIDR_REQ_COUNTER]);
32079 goto out; /* Duplicate message. */
32080 }
32081@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32082 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32083 msg->retries = 1;
32084
32085- atomic_long_add(1 + msg->retries,
32086+ atomic_long_add_unchecked(1 + msg->retries,
32087 &port->counter_group[CM_XMIT].counter[attr_index]);
32088 if (msg->retries)
32089- atomic_long_add(msg->retries,
32090+ atomic_long_add_unchecked(msg->retries,
32091 &port->counter_group[CM_XMIT_RETRIES].
32092 counter[attr_index]);
32093
32094@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32095 }
32096
32097 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32098- atomic_long_inc(&port->counter_group[CM_RECV].
32099+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32100 counter[attr_id - CM_ATTR_ID_OFFSET]);
32101
32102 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32103@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32104 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32105
32106 return sprintf(buf, "%ld\n",
32107- atomic_long_read(&group->counter[cm_attr->index]));
32108+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32109 }
32110
32111 static const struct sysfs_ops cm_counter_ops = {
32112diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32113index 176c8f9..2627b62 100644
32114--- a/drivers/infiniband/core/fmr_pool.c
32115+++ b/drivers/infiniband/core/fmr_pool.c
32116@@ -98,8 +98,8 @@ struct ib_fmr_pool {
32117
32118 struct task_struct *thread;
32119
32120- atomic_t req_ser;
32121- atomic_t flush_ser;
32122+ atomic_unchecked_t req_ser;
32123+ atomic_unchecked_t flush_ser;
32124
32125 wait_queue_head_t force_wait;
32126 };
32127@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32128 struct ib_fmr_pool *pool = pool_ptr;
32129
32130 do {
32131- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32132+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32133 ib_fmr_batch_release(pool);
32134
32135- atomic_inc(&pool->flush_ser);
32136+ atomic_inc_unchecked(&pool->flush_ser);
32137 wake_up_interruptible(&pool->force_wait);
32138
32139 if (pool->flush_function)
32140@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32141 }
32142
32143 set_current_state(TASK_INTERRUPTIBLE);
32144- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32145+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32146 !kthread_should_stop())
32147 schedule();
32148 __set_current_state(TASK_RUNNING);
32149@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32150 pool->dirty_watermark = params->dirty_watermark;
32151 pool->dirty_len = 0;
32152 spin_lock_init(&pool->pool_lock);
32153- atomic_set(&pool->req_ser, 0);
32154- atomic_set(&pool->flush_ser, 0);
32155+ atomic_set_unchecked(&pool->req_ser, 0);
32156+ atomic_set_unchecked(&pool->flush_ser, 0);
32157 init_waitqueue_head(&pool->force_wait);
32158
32159 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32160@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32161 }
32162 spin_unlock_irq(&pool->pool_lock);
32163
32164- serial = atomic_inc_return(&pool->req_ser);
32165+ serial = atomic_inc_return_unchecked(&pool->req_ser);
32166 wake_up_process(pool->thread);
32167
32168 if (wait_event_interruptible(pool->force_wait,
32169- atomic_read(&pool->flush_ser) - serial >= 0))
32170+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32171 return -EINTR;
32172
32173 return 0;
32174@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32175 } else {
32176 list_add_tail(&fmr->list, &pool->dirty_list);
32177 if (++pool->dirty_len >= pool->dirty_watermark) {
32178- atomic_inc(&pool->req_ser);
32179+ atomic_inc_unchecked(&pool->req_ser);
32180 wake_up_process(pool->thread);
32181 }
32182 }
32183diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32184index 40c8353..946b0e4 100644
32185--- a/drivers/infiniband/hw/cxgb4/mem.c
32186+++ b/drivers/infiniband/hw/cxgb4/mem.c
32187@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32188 int err;
32189 struct fw_ri_tpte tpt;
32190 u32 stag_idx;
32191- static atomic_t key;
32192+ static atomic_unchecked_t key;
32193
32194 if (c4iw_fatal_error(rdev))
32195 return -EIO;
32196@@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32197 &rdev->resource.tpt_fifo_lock);
32198 if (!stag_idx)
32199 return -ENOMEM;
32200- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32201+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32202 }
32203 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32204 __func__, stag_state, type, pdid, stag_idx);
32205diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32206index 79b3dbc..96e5fcc 100644
32207--- a/drivers/infiniband/hw/ipath/ipath_rc.c
32208+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32209@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32210 struct ib_atomic_eth *ateth;
32211 struct ipath_ack_entry *e;
32212 u64 vaddr;
32213- atomic64_t *maddr;
32214+ atomic64_unchecked_t *maddr;
32215 u64 sdata;
32216 u32 rkey;
32217 u8 next;
32218@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32219 IB_ACCESS_REMOTE_ATOMIC)))
32220 goto nack_acc_unlck;
32221 /* Perform atomic OP and save result. */
32222- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32223+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32224 sdata = be64_to_cpu(ateth->swap_data);
32225 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32226 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32227- (u64) atomic64_add_return(sdata, maddr) - sdata :
32228+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32229 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32230 be64_to_cpu(ateth->compare_data),
32231 sdata);
32232diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32233index 1f95bba..9530f87 100644
32234--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32235+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32236@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32237 unsigned long flags;
32238 struct ib_wc wc;
32239 u64 sdata;
32240- atomic64_t *maddr;
32241+ atomic64_unchecked_t *maddr;
32242 enum ib_wc_status send_status;
32243
32244 /*
32245@@ -382,11 +382,11 @@ again:
32246 IB_ACCESS_REMOTE_ATOMIC)))
32247 goto acc_err;
32248 /* Perform atomic OP and save result. */
32249- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32250+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32251 sdata = wqe->wr.wr.atomic.compare_add;
32252 *(u64 *) sqp->s_sge.sge.vaddr =
32253 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32254- (u64) atomic64_add_return(sdata, maddr) - sdata :
32255+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32256 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32257 sdata, wqe->wr.wr.atomic.swap);
32258 goto send_comp;
32259diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32260index 7140199..da60063 100644
32261--- a/drivers/infiniband/hw/nes/nes.c
32262+++ b/drivers/infiniband/hw/nes/nes.c
32263@@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32264 LIST_HEAD(nes_adapter_list);
32265 static LIST_HEAD(nes_dev_list);
32266
32267-atomic_t qps_destroyed;
32268+atomic_unchecked_t qps_destroyed;
32269
32270 static unsigned int ee_flsh_adapter;
32271 static unsigned int sysfs_nonidx_addr;
32272@@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32273 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32274 struct nes_adapter *nesadapter = nesdev->nesadapter;
32275
32276- atomic_inc(&qps_destroyed);
32277+ atomic_inc_unchecked(&qps_destroyed);
32278
32279 /* Free the control structures */
32280
32281diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32282index c438e46..ca30356 100644
32283--- a/drivers/infiniband/hw/nes/nes.h
32284+++ b/drivers/infiniband/hw/nes/nes.h
32285@@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32286 extern unsigned int wqm_quanta;
32287 extern struct list_head nes_adapter_list;
32288
32289-extern atomic_t cm_connects;
32290-extern atomic_t cm_accepts;
32291-extern atomic_t cm_disconnects;
32292-extern atomic_t cm_closes;
32293-extern atomic_t cm_connecteds;
32294-extern atomic_t cm_connect_reqs;
32295-extern atomic_t cm_rejects;
32296-extern atomic_t mod_qp_timouts;
32297-extern atomic_t qps_created;
32298-extern atomic_t qps_destroyed;
32299-extern atomic_t sw_qps_destroyed;
32300+extern atomic_unchecked_t cm_connects;
32301+extern atomic_unchecked_t cm_accepts;
32302+extern atomic_unchecked_t cm_disconnects;
32303+extern atomic_unchecked_t cm_closes;
32304+extern atomic_unchecked_t cm_connecteds;
32305+extern atomic_unchecked_t cm_connect_reqs;
32306+extern atomic_unchecked_t cm_rejects;
32307+extern atomic_unchecked_t mod_qp_timouts;
32308+extern atomic_unchecked_t qps_created;
32309+extern atomic_unchecked_t qps_destroyed;
32310+extern atomic_unchecked_t sw_qps_destroyed;
32311 extern u32 mh_detected;
32312 extern u32 mh_pauses_sent;
32313 extern u32 cm_packets_sent;
32314@@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32315 extern u32 cm_packets_received;
32316 extern u32 cm_packets_dropped;
32317 extern u32 cm_packets_retrans;
32318-extern atomic_t cm_listens_created;
32319-extern atomic_t cm_listens_destroyed;
32320+extern atomic_unchecked_t cm_listens_created;
32321+extern atomic_unchecked_t cm_listens_destroyed;
32322 extern u32 cm_backlog_drops;
32323-extern atomic_t cm_loopbacks;
32324-extern atomic_t cm_nodes_created;
32325-extern atomic_t cm_nodes_destroyed;
32326-extern atomic_t cm_accel_dropped_pkts;
32327-extern atomic_t cm_resets_recvd;
32328-extern atomic_t pau_qps_created;
32329-extern atomic_t pau_qps_destroyed;
32330+extern atomic_unchecked_t cm_loopbacks;
32331+extern atomic_unchecked_t cm_nodes_created;
32332+extern atomic_unchecked_t cm_nodes_destroyed;
32333+extern atomic_unchecked_t cm_accel_dropped_pkts;
32334+extern atomic_unchecked_t cm_resets_recvd;
32335+extern atomic_unchecked_t pau_qps_created;
32336+extern atomic_unchecked_t pau_qps_destroyed;
32337
32338 extern u32 int_mod_timer_init;
32339 extern u32 int_mod_cq_depth_256;
32340diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32341index 71edfbb..15b62ae 100644
32342--- a/drivers/infiniband/hw/nes/nes_cm.c
32343+++ b/drivers/infiniband/hw/nes/nes_cm.c
32344@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32345 u32 cm_packets_retrans;
32346 u32 cm_packets_created;
32347 u32 cm_packets_received;
32348-atomic_t cm_listens_created;
32349-atomic_t cm_listens_destroyed;
32350+atomic_unchecked_t cm_listens_created;
32351+atomic_unchecked_t cm_listens_destroyed;
32352 u32 cm_backlog_drops;
32353-atomic_t cm_loopbacks;
32354-atomic_t cm_nodes_created;
32355-atomic_t cm_nodes_destroyed;
32356-atomic_t cm_accel_dropped_pkts;
32357-atomic_t cm_resets_recvd;
32358+atomic_unchecked_t cm_loopbacks;
32359+atomic_unchecked_t cm_nodes_created;
32360+atomic_unchecked_t cm_nodes_destroyed;
32361+atomic_unchecked_t cm_accel_dropped_pkts;
32362+atomic_unchecked_t cm_resets_recvd;
32363
32364 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32365 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32366@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32367
32368 static struct nes_cm_core *g_cm_core;
32369
32370-atomic_t cm_connects;
32371-atomic_t cm_accepts;
32372-atomic_t cm_disconnects;
32373-atomic_t cm_closes;
32374-atomic_t cm_connecteds;
32375-atomic_t cm_connect_reqs;
32376-atomic_t cm_rejects;
32377+atomic_unchecked_t cm_connects;
32378+atomic_unchecked_t cm_accepts;
32379+atomic_unchecked_t cm_disconnects;
32380+atomic_unchecked_t cm_closes;
32381+atomic_unchecked_t cm_connecteds;
32382+atomic_unchecked_t cm_connect_reqs;
32383+atomic_unchecked_t cm_rejects;
32384
32385 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32386 {
32387@@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32388 kfree(listener);
32389 listener = NULL;
32390 ret = 0;
32391- atomic_inc(&cm_listens_destroyed);
32392+ atomic_inc_unchecked(&cm_listens_destroyed);
32393 } else {
32394 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32395 }
32396@@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32397 cm_node->rem_mac);
32398
32399 add_hte_node(cm_core, cm_node);
32400- atomic_inc(&cm_nodes_created);
32401+ atomic_inc_unchecked(&cm_nodes_created);
32402
32403 return cm_node;
32404 }
32405@@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32406 }
32407
32408 atomic_dec(&cm_core->node_cnt);
32409- atomic_inc(&cm_nodes_destroyed);
32410+ atomic_inc_unchecked(&cm_nodes_destroyed);
32411 nesqp = cm_node->nesqp;
32412 if (nesqp) {
32413 nesqp->cm_node = NULL;
32414@@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32415
32416 static void drop_packet(struct sk_buff *skb)
32417 {
32418- atomic_inc(&cm_accel_dropped_pkts);
32419+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32420 dev_kfree_skb_any(skb);
32421 }
32422
32423@@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32424 {
32425
32426 int reset = 0; /* whether to send reset in case of err.. */
32427- atomic_inc(&cm_resets_recvd);
32428+ atomic_inc_unchecked(&cm_resets_recvd);
32429 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32430 " refcnt=%d\n", cm_node, cm_node->state,
32431 atomic_read(&cm_node->ref_count));
32432@@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32433 rem_ref_cm_node(cm_node->cm_core, cm_node);
32434 return NULL;
32435 }
32436- atomic_inc(&cm_loopbacks);
32437+ atomic_inc_unchecked(&cm_loopbacks);
32438 loopbackremotenode->loopbackpartner = cm_node;
32439 loopbackremotenode->tcp_cntxt.rcv_wscale =
32440 NES_CM_DEFAULT_RCV_WND_SCALE;
32441@@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32442 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32443 else {
32444 rem_ref_cm_node(cm_core, cm_node);
32445- atomic_inc(&cm_accel_dropped_pkts);
32446+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32447 dev_kfree_skb_any(skb);
32448 }
32449 break;
32450@@ -2890,7 +2890,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32451
32452 if ((cm_id) && (cm_id->event_handler)) {
32453 if (issue_disconn) {
32454- atomic_inc(&cm_disconnects);
32455+ atomic_inc_unchecked(&cm_disconnects);
32456 cm_event.event = IW_CM_EVENT_DISCONNECT;
32457 cm_event.status = disconn_status;
32458 cm_event.local_addr = cm_id->local_addr;
32459@@ -2912,7 +2912,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32460 }
32461
32462 if (issue_close) {
32463- atomic_inc(&cm_closes);
32464+ atomic_inc_unchecked(&cm_closes);
32465 nes_disconnect(nesqp, 1);
32466
32467 cm_id->provider_data = nesqp;
32468@@ -3048,7 +3048,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32469
32470 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32471 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32472- atomic_inc(&cm_accepts);
32473+ atomic_inc_unchecked(&cm_accepts);
32474
32475 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32476 netdev_refcnt_read(nesvnic->netdev));
32477@@ -3250,7 +3250,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32478 struct nes_cm_core *cm_core;
32479 u8 *start_buff;
32480
32481- atomic_inc(&cm_rejects);
32482+ atomic_inc_unchecked(&cm_rejects);
32483 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32484 loopback = cm_node->loopbackpartner;
32485 cm_core = cm_node->cm_core;
32486@@ -3310,7 +3310,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32487 ntohl(cm_id->local_addr.sin_addr.s_addr),
32488 ntohs(cm_id->local_addr.sin_port));
32489
32490- atomic_inc(&cm_connects);
32491+ atomic_inc_unchecked(&cm_connects);
32492 nesqp->active_conn = 1;
32493
32494 /* cache the cm_id in the qp */
32495@@ -3416,7 +3416,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32496 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32497 return err;
32498 }
32499- atomic_inc(&cm_listens_created);
32500+ atomic_inc_unchecked(&cm_listens_created);
32501 }
32502
32503 cm_id->add_ref(cm_id);
32504@@ -3517,7 +3517,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32505
32506 if (nesqp->destroyed)
32507 return;
32508- atomic_inc(&cm_connecteds);
32509+ atomic_inc_unchecked(&cm_connecteds);
32510 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32511 " local port 0x%04X. jiffies = %lu.\n",
32512 nesqp->hwqp.qp_id,
32513@@ -3704,7 +3704,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32514
32515 cm_id->add_ref(cm_id);
32516 ret = cm_id->event_handler(cm_id, &cm_event);
32517- atomic_inc(&cm_closes);
32518+ atomic_inc_unchecked(&cm_closes);
32519 cm_event.event = IW_CM_EVENT_CLOSE;
32520 cm_event.status = 0;
32521 cm_event.provider_data = cm_id->provider_data;
32522@@ -3740,7 +3740,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32523 return;
32524 cm_id = cm_node->cm_id;
32525
32526- atomic_inc(&cm_connect_reqs);
32527+ atomic_inc_unchecked(&cm_connect_reqs);
32528 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32529 cm_node, cm_id, jiffies);
32530
32531@@ -3780,7 +3780,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32532 return;
32533 cm_id = cm_node->cm_id;
32534
32535- atomic_inc(&cm_connect_reqs);
32536+ atomic_inc_unchecked(&cm_connect_reqs);
32537 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32538 cm_node, cm_id, jiffies);
32539
32540diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32541index 3ba7be3..c81f6ff 100644
32542--- a/drivers/infiniband/hw/nes/nes_mgt.c
32543+++ b/drivers/infiniband/hw/nes/nes_mgt.c
32544@@ -40,8 +40,8 @@
32545 #include "nes.h"
32546 #include "nes_mgt.h"
32547
32548-atomic_t pau_qps_created;
32549-atomic_t pau_qps_destroyed;
32550+atomic_unchecked_t pau_qps_created;
32551+atomic_unchecked_t pau_qps_destroyed;
32552
32553 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32554 {
32555@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32556 {
32557 struct sk_buff *skb;
32558 unsigned long flags;
32559- atomic_inc(&pau_qps_destroyed);
32560+ atomic_inc_unchecked(&pau_qps_destroyed);
32561
32562 /* Free packets that have not yet been forwarded */
32563 /* Lock is acquired by skb_dequeue when removing the skb */
32564@@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32565 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32566 skb_queue_head_init(&nesqp->pau_list);
32567 spin_lock_init(&nesqp->pau_lock);
32568- atomic_inc(&pau_qps_created);
32569+ atomic_inc_unchecked(&pau_qps_created);
32570 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32571 }
32572
32573diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32574index f3a3ecf..57d311d 100644
32575--- a/drivers/infiniband/hw/nes/nes_nic.c
32576+++ b/drivers/infiniband/hw/nes/nes_nic.c
32577@@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32578 target_stat_values[++index] = mh_detected;
32579 target_stat_values[++index] = mh_pauses_sent;
32580 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32581- target_stat_values[++index] = atomic_read(&cm_connects);
32582- target_stat_values[++index] = atomic_read(&cm_accepts);
32583- target_stat_values[++index] = atomic_read(&cm_disconnects);
32584- target_stat_values[++index] = atomic_read(&cm_connecteds);
32585- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32586- target_stat_values[++index] = atomic_read(&cm_rejects);
32587- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32588- target_stat_values[++index] = atomic_read(&qps_created);
32589- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32590- target_stat_values[++index] = atomic_read(&qps_destroyed);
32591- target_stat_values[++index] = atomic_read(&cm_closes);
32592+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32593+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32594+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32595+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32596+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32597+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32598+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32599+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32600+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32601+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32602+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32603 target_stat_values[++index] = cm_packets_sent;
32604 target_stat_values[++index] = cm_packets_bounced;
32605 target_stat_values[++index] = cm_packets_created;
32606 target_stat_values[++index] = cm_packets_received;
32607 target_stat_values[++index] = cm_packets_dropped;
32608 target_stat_values[++index] = cm_packets_retrans;
32609- target_stat_values[++index] = atomic_read(&cm_listens_created);
32610- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32611+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32612+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32613 target_stat_values[++index] = cm_backlog_drops;
32614- target_stat_values[++index] = atomic_read(&cm_loopbacks);
32615- target_stat_values[++index] = atomic_read(&cm_nodes_created);
32616- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32617- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32618- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32619+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32620+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32621+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32622+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32623+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32624 target_stat_values[++index] = nesadapter->free_4kpbl;
32625 target_stat_values[++index] = nesadapter->free_256pbl;
32626 target_stat_values[++index] = int_mod_timer_init;
32627 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32628 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32629 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32630- target_stat_values[++index] = atomic_read(&pau_qps_created);
32631- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32632+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32633+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32634 }
32635
32636 /**
32637diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32638index 8b8812d..a5e1133 100644
32639--- a/drivers/infiniband/hw/nes/nes_verbs.c
32640+++ b/drivers/infiniband/hw/nes/nes_verbs.c
32641@@ -46,9 +46,9 @@
32642
32643 #include <rdma/ib_umem.h>
32644
32645-atomic_t mod_qp_timouts;
32646-atomic_t qps_created;
32647-atomic_t sw_qps_destroyed;
32648+atomic_unchecked_t mod_qp_timouts;
32649+atomic_unchecked_t qps_created;
32650+atomic_unchecked_t sw_qps_destroyed;
32651
32652 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32653
32654@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32655 if (init_attr->create_flags)
32656 return ERR_PTR(-EINVAL);
32657
32658- atomic_inc(&qps_created);
32659+ atomic_inc_unchecked(&qps_created);
32660 switch (init_attr->qp_type) {
32661 case IB_QPT_RC:
32662 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32663@@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32664 struct iw_cm_event cm_event;
32665 int ret = 0;
32666
32667- atomic_inc(&sw_qps_destroyed);
32668+ atomic_inc_unchecked(&sw_qps_destroyed);
32669 nesqp->destroyed = 1;
32670
32671 /* Blow away the connection if it exists. */
32672diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32673index 6b811e3..f8acf88 100644
32674--- a/drivers/infiniband/hw/qib/qib.h
32675+++ b/drivers/infiniband/hw/qib/qib.h
32676@@ -51,6 +51,7 @@
32677 #include <linux/completion.h>
32678 #include <linux/kref.h>
32679 #include <linux/sched.h>
32680+#include <linux/slab.h>
32681
32682 #include "qib_common.h"
32683 #include "qib_verbs.h"
32684diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32685index da739d9..da1c7f4 100644
32686--- a/drivers/input/gameport/gameport.c
32687+++ b/drivers/input/gameport/gameport.c
32688@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32689 */
32690 static void gameport_init_port(struct gameport *gameport)
32691 {
32692- static atomic_t gameport_no = ATOMIC_INIT(0);
32693+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32694
32695 __module_get(THIS_MODULE);
32696
32697 mutex_init(&gameport->drv_mutex);
32698 device_initialize(&gameport->dev);
32699 dev_set_name(&gameport->dev, "gameport%lu",
32700- (unsigned long)atomic_inc_return(&gameport_no) - 1);
32701+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32702 gameport->dev.bus = &gameport_bus;
32703 gameport->dev.release = gameport_release_port;
32704 if (gameport->parent)
32705diff --git a/drivers/input/input.c b/drivers/input/input.c
32706index 8921c61..f5cd63d 100644
32707--- a/drivers/input/input.c
32708+++ b/drivers/input/input.c
32709@@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32710 */
32711 int input_register_device(struct input_dev *dev)
32712 {
32713- static atomic_t input_no = ATOMIC_INIT(0);
32714+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32715 struct input_handler *handler;
32716 const char *path;
32717 int error;
32718@@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32719 dev->setkeycode = input_default_setkeycode;
32720
32721 dev_set_name(&dev->dev, "input%ld",
32722- (unsigned long) atomic_inc_return(&input_no) - 1);
32723+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32724
32725 error = device_add(&dev->dev);
32726 if (error)
32727diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32728index b8d8611..7a4a04b 100644
32729--- a/drivers/input/joystick/sidewinder.c
32730+++ b/drivers/input/joystick/sidewinder.c
32731@@ -30,6 +30,7 @@
32732 #include <linux/kernel.h>
32733 #include <linux/module.h>
32734 #include <linux/slab.h>
32735+#include <linux/sched.h>
32736 #include <linux/init.h>
32737 #include <linux/input.h>
32738 #include <linux/gameport.h>
32739diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32740index fd7a0d5..a4af10c 100644
32741--- a/drivers/input/joystick/xpad.c
32742+++ b/drivers/input/joystick/xpad.c
32743@@ -710,7 +710,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32744
32745 static int xpad_led_probe(struct usb_xpad *xpad)
32746 {
32747- static atomic_t led_seq = ATOMIC_INIT(0);
32748+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32749 long led_no;
32750 struct xpad_led *led;
32751 struct led_classdev *led_cdev;
32752@@ -723,7 +723,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32753 if (!led)
32754 return -ENOMEM;
32755
32756- led_no = (long)atomic_inc_return(&led_seq) - 1;
32757+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32758
32759 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32760 led->xpad = xpad;
32761diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32762index 0110b5a..d3ad144 100644
32763--- a/drivers/input/mousedev.c
32764+++ b/drivers/input/mousedev.c
32765@@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32766
32767 spin_unlock_irq(&client->packet_lock);
32768
32769- if (copy_to_user(buffer, data, count))
32770+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
32771 return -EFAULT;
32772
32773 return count;
32774diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32775index d0f7533..fb8215b 100644
32776--- a/drivers/input/serio/serio.c
32777+++ b/drivers/input/serio/serio.c
32778@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
32779 */
32780 static void serio_init_port(struct serio *serio)
32781 {
32782- static atomic_t serio_no = ATOMIC_INIT(0);
32783+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32784
32785 __module_get(THIS_MODULE);
32786
32787@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
32788 mutex_init(&serio->drv_mutex);
32789 device_initialize(&serio->dev);
32790 dev_set_name(&serio->dev, "serio%ld",
32791- (long)atomic_inc_return(&serio_no) - 1);
32792+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
32793 serio->dev.bus = &serio_bus;
32794 serio->dev.release = serio_release_port;
32795 serio->dev.groups = serio_device_attr_groups;
32796diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32797index b902794..fc7b85b 100644
32798--- a/drivers/isdn/capi/capi.c
32799+++ b/drivers/isdn/capi/capi.c
32800@@ -83,8 +83,8 @@ struct capiminor {
32801
32802 struct capi20_appl *ap;
32803 u32 ncci;
32804- atomic_t datahandle;
32805- atomic_t msgid;
32806+ atomic_unchecked_t datahandle;
32807+ atomic_unchecked_t msgid;
32808
32809 struct tty_port port;
32810 int ttyinstop;
32811@@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32812 capimsg_setu16(s, 2, mp->ap->applid);
32813 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32814 capimsg_setu8 (s, 5, CAPI_RESP);
32815- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32816+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32817 capimsg_setu32(s, 8, mp->ncci);
32818 capimsg_setu16(s, 12, datahandle);
32819 }
32820@@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
32821 mp->outbytes -= len;
32822 spin_unlock_bh(&mp->outlock);
32823
32824- datahandle = atomic_inc_return(&mp->datahandle);
32825+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32826 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32827 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32828 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32829 capimsg_setu16(skb->data, 2, mp->ap->applid);
32830 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32831 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32832- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32833+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32834 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32835 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32836 capimsg_setu16(skb->data, 16, len); /* Data length */
32837diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32838index 821f7ac..28d4030 100644
32839--- a/drivers/isdn/hardware/avm/b1.c
32840+++ b/drivers/isdn/hardware/avm/b1.c
32841@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
32842 }
32843 if (left) {
32844 if (t4file->user) {
32845- if (copy_from_user(buf, dp, left))
32846+ if (left > sizeof buf || copy_from_user(buf, dp, left))
32847 return -EFAULT;
32848 } else {
32849 memcpy(buf, dp, left);
32850@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
32851 }
32852 if (left) {
32853 if (config->user) {
32854- if (copy_from_user(buf, dp, left))
32855+ if (left > sizeof buf || copy_from_user(buf, dp, left))
32856 return -EFAULT;
32857 } else {
32858 memcpy(buf, dp, left);
32859diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32860index dd6b53a..19d9ee6 100644
32861--- a/drivers/isdn/hardware/eicon/divasync.h
32862+++ b/drivers/isdn/hardware/eicon/divasync.h
32863@@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32864 } diva_didd_add_adapter_t;
32865 typedef struct _diva_didd_remove_adapter {
32866 IDI_CALL p_request;
32867-} diva_didd_remove_adapter_t;
32868+} __no_const diva_didd_remove_adapter_t;
32869 typedef struct _diva_didd_read_adapter_array {
32870 void *buffer;
32871 dword length;
32872diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32873index d303e65..28bcb7b 100644
32874--- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32875+++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32876@@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32877 typedef struct _diva_os_idi_adapter_interface {
32878 diva_init_card_proc_t cleanup_adapter_proc;
32879 diva_cmd_card_proc_t cmd_proc;
32880-} diva_os_idi_adapter_interface_t;
32881+} __no_const diva_os_idi_adapter_interface_t;
32882
32883 typedef struct _diva_os_xdi_adapter {
32884 struct list_head link;
32885diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
32886index e74df7c..03a03ba 100644
32887--- a/drivers/isdn/icn/icn.c
32888+++ b/drivers/isdn/icn/icn.c
32889@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
32890 if (count > len)
32891 count = len;
32892 if (user) {
32893- if (copy_from_user(msg, buf, count))
32894+ if (count > sizeof msg || copy_from_user(msg, buf, count))
32895 return -EFAULT;
32896 } else
32897 memcpy(msg, buf, count);
32898diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c
32899index 8bc4915..4cc6a2e 100644
32900--- a/drivers/leds/leds-mc13783.c
32901+++ b/drivers/leds/leds-mc13783.c
32902@@ -280,7 +280,7 @@ static int __devinit mc13783_led_probe(struct platform_device *pdev)
32903 return -EINVAL;
32904 }
32905
32906- led = kzalloc(sizeof(*led) * pdata->num_leds, GFP_KERNEL);
32907+ led = kcalloc(pdata->num_leds, sizeof(*led), GFP_KERNEL);
32908 if (led == NULL) {
32909 dev_err(&pdev->dev, "failed to alloc memory\n");
32910 return -ENOMEM;
32911diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
32912index b5fdcb7..5b6c59f 100644
32913--- a/drivers/lguest/core.c
32914+++ b/drivers/lguest/core.c
32915@@ -92,9 +92,17 @@ static __init int map_switcher(void)
32916 * it's worked so far. The end address needs +1 because __get_vm_area
32917 * allocates an extra guard page, so we need space for that.
32918 */
32919+
32920+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32921+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32922+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
32923+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32924+#else
32925 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32926 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
32927 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32928+#endif
32929+
32930 if (!switcher_vma) {
32931 err = -ENOMEM;
32932 printk("lguest: could not map switcher pages high\n");
32933@@ -119,7 +127,7 @@ static __init int map_switcher(void)
32934 * Now the Switcher is mapped at the right address, we can't fail!
32935 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
32936 */
32937- memcpy(switcher_vma->addr, start_switcher_text,
32938+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
32939 end_switcher_text - start_switcher_text);
32940
32941 printk(KERN_INFO "lguest: mapped switcher at %p\n",
32942diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
32943index 3980903..ce25c5e 100644
32944--- a/drivers/lguest/x86/core.c
32945+++ b/drivers/lguest/x86/core.c
32946@@ -59,7 +59,7 @@ static struct {
32947 /* Offset from where switcher.S was compiled to where we've copied it */
32948 static unsigned long switcher_offset(void)
32949 {
32950- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
32951+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
32952 }
32953
32954 /* This cpu's struct lguest_pages. */
32955@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
32956 * These copies are pretty cheap, so we do them unconditionally: */
32957 /* Save the current Host top-level page directory.
32958 */
32959+
32960+#ifdef CONFIG_PAX_PER_CPU_PGD
32961+ pages->state.host_cr3 = read_cr3();
32962+#else
32963 pages->state.host_cr3 = __pa(current->mm->pgd);
32964+#endif
32965+
32966 /*
32967 * Set up the Guest's page tables to see this CPU's pages (and no
32968 * other CPU's pages).
32969@@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
32970 * compiled-in switcher code and the high-mapped copy we just made.
32971 */
32972 for (i = 0; i < IDT_ENTRIES; i++)
32973- default_idt_entries[i] += switcher_offset();
32974+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
32975
32976 /*
32977 * Set up the Switcher's per-cpu areas.
32978@@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
32979 * it will be undisturbed when we switch. To change %cs and jump we
32980 * need this structure to feed to Intel's "lcall" instruction.
32981 */
32982- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
32983+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
32984 lguest_entry.segment = LGUEST_CS;
32985
32986 /*
32987diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
32988index 40634b0..4f5855e 100644
32989--- a/drivers/lguest/x86/switcher_32.S
32990+++ b/drivers/lguest/x86/switcher_32.S
32991@@ -87,6 +87,7 @@
32992 #include <asm/page.h>
32993 #include <asm/segment.h>
32994 #include <asm/lguest.h>
32995+#include <asm/processor-flags.h>
32996
32997 // We mark the start of the code to copy
32998 // It's placed in .text tho it's never run here
32999@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33000 // Changes type when we load it: damn Intel!
33001 // For after we switch over our page tables
33002 // That entry will be read-only: we'd crash.
33003+
33004+#ifdef CONFIG_PAX_KERNEXEC
33005+ mov %cr0, %edx
33006+ xor $X86_CR0_WP, %edx
33007+ mov %edx, %cr0
33008+#endif
33009+
33010 movl $(GDT_ENTRY_TSS*8), %edx
33011 ltr %dx
33012
33013@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33014 // Let's clear it again for our return.
33015 // The GDT descriptor of the Host
33016 // Points to the table after two "size" bytes
33017- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33018+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33019 // Clear "used" from type field (byte 5, bit 2)
33020- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33021+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33022+
33023+#ifdef CONFIG_PAX_KERNEXEC
33024+ mov %cr0, %eax
33025+ xor $X86_CR0_WP, %eax
33026+ mov %eax, %cr0
33027+#endif
33028
33029 // Once our page table's switched, the Guest is live!
33030 // The Host fades as we run this final step.
33031@@ -295,13 +309,12 @@ deliver_to_host:
33032 // I consulted gcc, and it gave
33033 // These instructions, which I gladly credit:
33034 leal (%edx,%ebx,8), %eax
33035- movzwl (%eax),%edx
33036- movl 4(%eax), %eax
33037- xorw %ax, %ax
33038- orl %eax, %edx
33039+ movl 4(%eax), %edx
33040+ movw (%eax), %dx
33041 // Now the address of the handler's in %edx
33042 // We call it now: its "iret" drops us home.
33043- jmp *%edx
33044+ ljmp $__KERNEL_CS, $1f
33045+1: jmp *%edx
33046
33047 // Every interrupt can come to us here
33048 // But we must truly tell each apart.
33049diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33050index 20e5c2c..9e849a9 100644
33051--- a/drivers/macintosh/macio_asic.c
33052+++ b/drivers/macintosh/macio_asic.c
33053@@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33054 * MacIO is matched against any Apple ID, it's probe() function
33055 * will then decide wether it applies or not
33056 */
33057-static const struct pci_device_id __devinitdata pci_ids [] = { {
33058+static const struct pci_device_id __devinitconst pci_ids [] = { {
33059 .vendor = PCI_VENDOR_ID_APPLE,
33060 .device = PCI_ANY_ID,
33061 .subvendor = PCI_ANY_ID,
33062diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33063index 17e2b47..bcbeec4 100644
33064--- a/drivers/md/bitmap.c
33065+++ b/drivers/md/bitmap.c
33066@@ -1823,7 +1823,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33067 chunk_kb ? "KB" : "B");
33068 if (bitmap->file) {
33069 seq_printf(seq, ", file: ");
33070- seq_path(seq, &bitmap->file->f_path, " \t\n");
33071+ seq_path(seq, &bitmap->file->f_path, " \t\n\\");
33072 }
33073
33074 seq_printf(seq, "\n");
33075diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33076index a1a3e6d..1918bfc 100644
33077--- a/drivers/md/dm-ioctl.c
33078+++ b/drivers/md/dm-ioctl.c
33079@@ -1590,7 +1590,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33080 cmd == DM_LIST_VERSIONS_CMD)
33081 return 0;
33082
33083- if ((cmd == DM_DEV_CREATE_CMD)) {
33084+ if (cmd == DM_DEV_CREATE_CMD) {
33085 if (!*param->name) {
33086 DMWARN("name not supplied when creating device");
33087 return -EINVAL;
33088diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33089index d039de8..0cf5b87 100644
33090--- a/drivers/md/dm-raid1.c
33091+++ b/drivers/md/dm-raid1.c
33092@@ -40,7 +40,7 @@ enum dm_raid1_error {
33093
33094 struct mirror {
33095 struct mirror_set *ms;
33096- atomic_t error_count;
33097+ atomic_unchecked_t error_count;
33098 unsigned long error_type;
33099 struct dm_dev *dev;
33100 sector_t offset;
33101@@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33102 struct mirror *m;
33103
33104 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33105- if (!atomic_read(&m->error_count))
33106+ if (!atomic_read_unchecked(&m->error_count))
33107 return m;
33108
33109 return NULL;
33110@@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33111 * simple way to tell if a device has encountered
33112 * errors.
33113 */
33114- atomic_inc(&m->error_count);
33115+ atomic_inc_unchecked(&m->error_count);
33116
33117 if (test_and_set_bit(error_type, &m->error_type))
33118 return;
33119@@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33120 struct mirror *m = get_default_mirror(ms);
33121
33122 do {
33123- if (likely(!atomic_read(&m->error_count)))
33124+ if (likely(!atomic_read_unchecked(&m->error_count)))
33125 return m;
33126
33127 if (m-- == ms->mirror)
33128@@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33129 {
33130 struct mirror *default_mirror = get_default_mirror(m->ms);
33131
33132- return !atomic_read(&default_mirror->error_count);
33133+ return !atomic_read_unchecked(&default_mirror->error_count);
33134 }
33135
33136 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33137@@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33138 */
33139 if (likely(region_in_sync(ms, region, 1)))
33140 m = choose_mirror(ms, bio->bi_sector);
33141- else if (m && atomic_read(&m->error_count))
33142+ else if (m && atomic_read_unchecked(&m->error_count))
33143 m = NULL;
33144
33145 if (likely(m))
33146@@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33147 }
33148
33149 ms->mirror[mirror].ms = ms;
33150- atomic_set(&(ms->mirror[mirror].error_count), 0);
33151+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33152 ms->mirror[mirror].error_type = 0;
33153 ms->mirror[mirror].offset = offset;
33154
33155@@ -1351,7 +1351,7 @@ static void mirror_resume(struct dm_target *ti)
33156 */
33157 static char device_status_char(struct mirror *m)
33158 {
33159- if (!atomic_read(&(m->error_count)))
33160+ if (!atomic_read_unchecked(&(m->error_count)))
33161 return 'A';
33162
33163 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33164diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33165index 35c94ff..20d4c17 100644
33166--- a/drivers/md/dm-stripe.c
33167+++ b/drivers/md/dm-stripe.c
33168@@ -20,7 +20,7 @@ struct stripe {
33169 struct dm_dev *dev;
33170 sector_t physical_start;
33171
33172- atomic_t error_count;
33173+ atomic_unchecked_t error_count;
33174 };
33175
33176 struct stripe_c {
33177@@ -193,7 +193,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33178 kfree(sc);
33179 return r;
33180 }
33181- atomic_set(&(sc->stripe[i].error_count), 0);
33182+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33183 }
33184
33185 ti->private = sc;
33186@@ -315,7 +315,7 @@ static int stripe_status(struct dm_target *ti,
33187 DMEMIT("%d ", sc->stripes);
33188 for (i = 0; i < sc->stripes; i++) {
33189 DMEMIT("%s ", sc->stripe[i].dev->name);
33190- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33191+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33192 'D' : 'A';
33193 }
33194 buffer[i] = '\0';
33195@@ -362,8 +362,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33196 */
33197 for (i = 0; i < sc->stripes; i++)
33198 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33199- atomic_inc(&(sc->stripe[i].error_count));
33200- if (atomic_read(&(sc->stripe[i].error_count)) <
33201+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
33202+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33203 DM_IO_ERROR_THRESHOLD)
33204 schedule_work(&sc->trigger_event);
33205 }
33206diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33207index 2e227fb..44ead1f 100644
33208--- a/drivers/md/dm-table.c
33209+++ b/drivers/md/dm-table.c
33210@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33211 if (!dev_size)
33212 return 0;
33213
33214- if ((start >= dev_size) || (start + len > dev_size)) {
33215+ if ((start >= dev_size) || (len > dev_size - start)) {
33216 DMWARN("%s: %s too small for target: "
33217 "start=%llu, len=%llu, dev_size=%llu",
33218 dm_device_name(ti->table->md), bdevname(bdev, b),
33219diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33220index 737d388..811ad5a 100644
33221--- a/drivers/md/dm-thin-metadata.c
33222+++ b/drivers/md/dm-thin-metadata.c
33223@@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33224
33225 pmd->info.tm = tm;
33226 pmd->info.levels = 2;
33227- pmd->info.value_type.context = pmd->data_sm;
33228+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33229 pmd->info.value_type.size = sizeof(__le64);
33230 pmd->info.value_type.inc = data_block_inc;
33231 pmd->info.value_type.dec = data_block_dec;
33232@@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33233
33234 pmd->bl_info.tm = tm;
33235 pmd->bl_info.levels = 1;
33236- pmd->bl_info.value_type.context = pmd->data_sm;
33237+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33238 pmd->bl_info.value_type.size = sizeof(__le64);
33239 pmd->bl_info.value_type.inc = data_block_inc;
33240 pmd->bl_info.value_type.dec = data_block_dec;
33241diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33242index e24143c..ce2f21a1 100644
33243--- a/drivers/md/dm.c
33244+++ b/drivers/md/dm.c
33245@@ -176,9 +176,9 @@ struct mapped_device {
33246 /*
33247 * Event handling.
33248 */
33249- atomic_t event_nr;
33250+ atomic_unchecked_t event_nr;
33251 wait_queue_head_t eventq;
33252- atomic_t uevent_seq;
33253+ atomic_unchecked_t uevent_seq;
33254 struct list_head uevent_list;
33255 spinlock_t uevent_lock; /* Protect access to uevent_list */
33256
33257@@ -1845,8 +1845,8 @@ static struct mapped_device *alloc_dev(int minor)
33258 rwlock_init(&md->map_lock);
33259 atomic_set(&md->holders, 1);
33260 atomic_set(&md->open_count, 0);
33261- atomic_set(&md->event_nr, 0);
33262- atomic_set(&md->uevent_seq, 0);
33263+ atomic_set_unchecked(&md->event_nr, 0);
33264+ atomic_set_unchecked(&md->uevent_seq, 0);
33265 INIT_LIST_HEAD(&md->uevent_list);
33266 spin_lock_init(&md->uevent_lock);
33267
33268@@ -1980,7 +1980,7 @@ static void event_callback(void *context)
33269
33270 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33271
33272- atomic_inc(&md->event_nr);
33273+ atomic_inc_unchecked(&md->event_nr);
33274 wake_up(&md->eventq);
33275 }
33276
33277@@ -2622,18 +2622,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33278
33279 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33280 {
33281- return atomic_add_return(1, &md->uevent_seq);
33282+ return atomic_add_return_unchecked(1, &md->uevent_seq);
33283 }
33284
33285 uint32_t dm_get_event_nr(struct mapped_device *md)
33286 {
33287- return atomic_read(&md->event_nr);
33288+ return atomic_read_unchecked(&md->event_nr);
33289 }
33290
33291 int dm_wait_event(struct mapped_device *md, int event_nr)
33292 {
33293 return wait_event_interruptible(md->eventq,
33294- (event_nr != atomic_read(&md->event_nr)));
33295+ (event_nr != atomic_read_unchecked(&md->event_nr)));
33296 }
33297
33298 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33299diff --git a/drivers/md/md.c b/drivers/md/md.c
33300index 2b30ffd..bf789ce 100644
33301--- a/drivers/md/md.c
33302+++ b/drivers/md/md.c
33303@@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33304 * start build, activate spare
33305 */
33306 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33307-static atomic_t md_event_count;
33308+static atomic_unchecked_t md_event_count;
33309 void md_new_event(struct mddev *mddev)
33310 {
33311- atomic_inc(&md_event_count);
33312+ atomic_inc_unchecked(&md_event_count);
33313 wake_up(&md_event_waiters);
33314 }
33315 EXPORT_SYMBOL_GPL(md_new_event);
33316@@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33317 */
33318 static void md_new_event_inintr(struct mddev *mddev)
33319 {
33320- atomic_inc(&md_event_count);
33321+ atomic_inc_unchecked(&md_event_count);
33322 wake_up(&md_event_waiters);
33323 }
33324
33325@@ -1526,7 +1526,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33326
33327 rdev->preferred_minor = 0xffff;
33328 rdev->data_offset = le64_to_cpu(sb->data_offset);
33329- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33330+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33331
33332 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33333 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33334@@ -1745,7 +1745,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33335 else
33336 sb->resync_offset = cpu_to_le64(0);
33337
33338- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33339+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33340
33341 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33342 sb->size = cpu_to_le64(mddev->dev_sectors);
33343@@ -2691,7 +2691,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33344 static ssize_t
33345 errors_show(struct md_rdev *rdev, char *page)
33346 {
33347- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33348+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33349 }
33350
33351 static ssize_t
33352@@ -2700,7 +2700,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33353 char *e;
33354 unsigned long n = simple_strtoul(buf, &e, 10);
33355 if (*buf && (*e == 0 || *e == '\n')) {
33356- atomic_set(&rdev->corrected_errors, n);
33357+ atomic_set_unchecked(&rdev->corrected_errors, n);
33358 return len;
33359 }
33360 return -EINVAL;
33361@@ -3086,8 +3086,8 @@ int md_rdev_init(struct md_rdev *rdev)
33362 rdev->sb_loaded = 0;
33363 rdev->bb_page = NULL;
33364 atomic_set(&rdev->nr_pending, 0);
33365- atomic_set(&rdev->read_errors, 0);
33366- atomic_set(&rdev->corrected_errors, 0);
33367+ atomic_set_unchecked(&rdev->read_errors, 0);
33368+ atomic_set_unchecked(&rdev->corrected_errors, 0);
33369
33370 INIT_LIST_HEAD(&rdev->same_set);
33371 init_waitqueue_head(&rdev->blocked_wait);
33372@@ -6738,7 +6738,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33373
33374 spin_unlock(&pers_lock);
33375 seq_printf(seq, "\n");
33376- seq->poll_event = atomic_read(&md_event_count);
33377+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33378 return 0;
33379 }
33380 if (v == (void*)2) {
33381@@ -6841,7 +6841,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33382 return error;
33383
33384 seq = file->private_data;
33385- seq->poll_event = atomic_read(&md_event_count);
33386+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33387 return error;
33388 }
33389
33390@@ -6855,7 +6855,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33391 /* always allow read */
33392 mask = POLLIN | POLLRDNORM;
33393
33394- if (seq->poll_event != atomic_read(&md_event_count))
33395+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33396 mask |= POLLERR | POLLPRI;
33397 return mask;
33398 }
33399@@ -6899,7 +6899,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33400 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33401 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33402 (int)part_stat_read(&disk->part0, sectors[1]) -
33403- atomic_read(&disk->sync_io);
33404+ atomic_read_unchecked(&disk->sync_io);
33405 /* sync IO will cause sync_io to increase before the disk_stats
33406 * as sync_io is counted when a request starts, and
33407 * disk_stats is counted when it completes.
33408diff --git a/drivers/md/md.h b/drivers/md/md.h
33409index 1c2063c..9639970 100644
33410--- a/drivers/md/md.h
33411+++ b/drivers/md/md.h
33412@@ -93,13 +93,13 @@ struct md_rdev {
33413 * only maintained for arrays that
33414 * support hot removal
33415 */
33416- atomic_t read_errors; /* number of consecutive read errors that
33417+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
33418 * we have tried to ignore.
33419 */
33420 struct timespec last_read_error; /* monotonic time since our
33421 * last read error
33422 */
33423- atomic_t corrected_errors; /* number of corrected read errors,
33424+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33425 * for reporting to userspace and storing
33426 * in superblock.
33427 */
33428@@ -429,7 +429,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33429
33430 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33431 {
33432- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33433+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33434 }
33435
33436 struct md_personality
33437diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33438index 50ed53b..4f29d7d 100644
33439--- a/drivers/md/persistent-data/dm-space-map-checker.c
33440+++ b/drivers/md/persistent-data/dm-space-map-checker.c
33441@@ -159,7 +159,7 @@ static void ca_destroy(struct count_array *ca)
33442 /*----------------------------------------------------------------*/
33443
33444 struct sm_checker {
33445- struct dm_space_map sm;
33446+ dm_space_map_no_const sm;
33447
33448 struct count_array old_counts;
33449 struct count_array counts;
33450diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33451index fc469ba..2d91555 100644
33452--- a/drivers/md/persistent-data/dm-space-map-disk.c
33453+++ b/drivers/md/persistent-data/dm-space-map-disk.c
33454@@ -23,7 +23,7 @@
33455 * Space map interface.
33456 */
33457 struct sm_disk {
33458- struct dm_space_map sm;
33459+ dm_space_map_no_const sm;
33460
33461 struct ll_disk ll;
33462 struct ll_disk old_ll;
33463diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33464index e89ae5e..062e4c2 100644
33465--- a/drivers/md/persistent-data/dm-space-map-metadata.c
33466+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33467@@ -43,7 +43,7 @@ struct block_op {
33468 };
33469
33470 struct sm_metadata {
33471- struct dm_space_map sm;
33472+ dm_space_map_no_const sm;
33473
33474 struct ll_disk ll;
33475 struct ll_disk old_ll;
33476diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33477index 1cbfc6b..56e1dbb 100644
33478--- a/drivers/md/persistent-data/dm-space-map.h
33479+++ b/drivers/md/persistent-data/dm-space-map.h
33480@@ -60,6 +60,7 @@ struct dm_space_map {
33481 int (*root_size)(struct dm_space_map *sm, size_t *result);
33482 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33483 };
33484+typedef struct dm_space_map __no_const dm_space_map_no_const;
33485
33486 /*----------------------------------------------------------------*/
33487
33488diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33489index d7e9577..faa512f2 100644
33490--- a/drivers/md/raid1.c
33491+++ b/drivers/md/raid1.c
33492@@ -1688,7 +1688,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33493 if (r1_sync_page_io(rdev, sect, s,
33494 bio->bi_io_vec[idx].bv_page,
33495 READ) != 0)
33496- atomic_add(s, &rdev->corrected_errors);
33497+ atomic_add_unchecked(s, &rdev->corrected_errors);
33498 }
33499 sectors -= s;
33500 sect += s;
33501@@ -1902,7 +1902,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33502 test_bit(In_sync, &rdev->flags)) {
33503 if (r1_sync_page_io(rdev, sect, s,
33504 conf->tmppage, READ)) {
33505- atomic_add(s, &rdev->corrected_errors);
33506+ atomic_add_unchecked(s, &rdev->corrected_errors);
33507 printk(KERN_INFO
33508 "md/raid1:%s: read error corrected "
33509 "(%d sectors at %llu on %s)\n",
33510diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33511index d037adb..ed17dc9 100644
33512--- a/drivers/md/raid10.c
33513+++ b/drivers/md/raid10.c
33514@@ -1684,7 +1684,7 @@ static void end_sync_read(struct bio *bio, int error)
33515 /* The write handler will notice the lack of
33516 * R10BIO_Uptodate and record any errors etc
33517 */
33518- atomic_add(r10_bio->sectors,
33519+ atomic_add_unchecked(r10_bio->sectors,
33520 &conf->mirrors[d].rdev->corrected_errors);
33521
33522 /* for reconstruct, we always reschedule after a read.
33523@@ -2033,7 +2033,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33524 {
33525 struct timespec cur_time_mon;
33526 unsigned long hours_since_last;
33527- unsigned int read_errors = atomic_read(&rdev->read_errors);
33528+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33529
33530 ktime_get_ts(&cur_time_mon);
33531
33532@@ -2055,9 +2055,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33533 * overflowing the shift of read_errors by hours_since_last.
33534 */
33535 if (hours_since_last >= 8 * sizeof(read_errors))
33536- atomic_set(&rdev->read_errors, 0);
33537+ atomic_set_unchecked(&rdev->read_errors, 0);
33538 else
33539- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33540+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33541 }
33542
33543 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33544@@ -2111,8 +2111,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33545 return;
33546
33547 check_decay_read_errors(mddev, rdev);
33548- atomic_inc(&rdev->read_errors);
33549- if (atomic_read(&rdev->read_errors) > max_read_errors) {
33550+ atomic_inc_unchecked(&rdev->read_errors);
33551+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33552 char b[BDEVNAME_SIZE];
33553 bdevname(rdev->bdev, b);
33554
33555@@ -2120,7 +2120,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33556 "md/raid10:%s: %s: Raid device exceeded "
33557 "read_error threshold [cur %d:max %d]\n",
33558 mdname(mddev), b,
33559- atomic_read(&rdev->read_errors), max_read_errors);
33560+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33561 printk(KERN_NOTICE
33562 "md/raid10:%s: %s: Failing raid device\n",
33563 mdname(mddev), b);
33564@@ -2271,7 +2271,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33565 (unsigned long long)(
33566 sect + rdev->data_offset),
33567 bdevname(rdev->bdev, b));
33568- atomic_add(s, &rdev->corrected_errors);
33569+ atomic_add_unchecked(s, &rdev->corrected_errors);
33570 }
33571
33572 rdev_dec_pending(rdev, mddev);
33573diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33574index f351422..85c01bb 100644
33575--- a/drivers/md/raid5.c
33576+++ b/drivers/md/raid5.c
33577@@ -1686,18 +1686,18 @@ static void raid5_end_read_request(struct bio * bi, int error)
33578 (unsigned long long)(sh->sector
33579 + rdev->data_offset),
33580 bdevname(rdev->bdev, b));
33581- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33582+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33583 clear_bit(R5_ReadError, &sh->dev[i].flags);
33584 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33585 }
33586- if (atomic_read(&rdev->read_errors))
33587- atomic_set(&rdev->read_errors, 0);
33588+ if (atomic_read_unchecked(&rdev->read_errors))
33589+ atomic_set_unchecked(&rdev->read_errors, 0);
33590 } else {
33591 const char *bdn = bdevname(rdev->bdev, b);
33592 int retry = 0;
33593
33594 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33595- atomic_inc(&rdev->read_errors);
33596+ atomic_inc_unchecked(&rdev->read_errors);
33597 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33598 printk_ratelimited(
33599 KERN_WARNING
33600@@ -1726,7 +1726,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33601 (unsigned long long)(sh->sector
33602 + rdev->data_offset),
33603 bdn);
33604- else if (atomic_read(&rdev->read_errors)
33605+ else if (atomic_read_unchecked(&rdev->read_errors)
33606 > conf->max_nr_stripes)
33607 printk(KERN_WARNING
33608 "md/raid:%s: Too many read errors, failing device %s.\n",
33609diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33610index d88c4aa..17c80b1 100644
33611--- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33612+++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33613@@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
33614 .subvendor = _subvend, .subdevice = _subdev, \
33615 .driver_data = (unsigned long)&_driverdata }
33616
33617-static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33618+static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33619 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33620 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33621 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33622diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33623index a7d876f..8c21b61 100644
33624--- a/drivers/media/dvb/dvb-core/dvb_demux.h
33625+++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33626@@ -73,7 +73,7 @@ struct dvb_demux_feed {
33627 union {
33628 dmx_ts_cb ts;
33629 dmx_section_cb sec;
33630- } cb;
33631+ } __no_const cb;
33632
33633 struct dvb_demux *demux;
33634 void *priv;
33635diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33636index 00a6732..70a682e 100644
33637--- a/drivers/media/dvb/dvb-core/dvbdev.c
33638+++ b/drivers/media/dvb/dvb-core/dvbdev.c
33639@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33640 const struct dvb_device *template, void *priv, int type)
33641 {
33642 struct dvb_device *dvbdev;
33643- struct file_operations *dvbdevfops;
33644+ file_operations_no_const *dvbdevfops;
33645 struct device *clsdev;
33646 int minor;
33647 int id;
33648diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33649index 3940bb0..fb3952a 100644
33650--- a/drivers/media/dvb/dvb-usb/cxusb.c
33651+++ b/drivers/media/dvb/dvb-usb/cxusb.c
33652@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33653
33654 struct dib0700_adapter_state {
33655 int (*set_param_save) (struct dvb_frontend *);
33656-};
33657+} __no_const;
33658
33659 static int dib7070_set_param_override(struct dvb_frontend *fe)
33660 {
33661diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33662index 451c5a7..649f711 100644
33663--- a/drivers/media/dvb/dvb-usb/dw2102.c
33664+++ b/drivers/media/dvb/dvb-usb/dw2102.c
33665@@ -95,7 +95,7 @@ struct su3000_state {
33666
33667 struct s6x0_state {
33668 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33669-};
33670+} __no_const;
33671
33672 /* debug */
33673 static int dvb_usb_dw2102_debug;
33674diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33675index 404f63a..4796533 100644
33676--- a/drivers/media/dvb/frontends/dib3000.h
33677+++ b/drivers/media/dvb/frontends/dib3000.h
33678@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33679 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33680 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33681 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33682-};
33683+} __no_const;
33684
33685 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33686 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33687diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33688index 7539a5d..06531a6 100644
33689--- a/drivers/media/dvb/ngene/ngene-cards.c
33690+++ b/drivers/media/dvb/ngene/ngene-cards.c
33691@@ -478,7 +478,7 @@ static struct ngene_info ngene_info_m780 = {
33692
33693 /****************************************************************************/
33694
33695-static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33696+static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33697 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33698 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33699 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33700diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33701index 16a089f..1661b11 100644
33702--- a/drivers/media/radio/radio-cadet.c
33703+++ b/drivers/media/radio/radio-cadet.c
33704@@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33705 unsigned char readbuf[RDS_BUFFER];
33706 int i = 0;
33707
33708+ if (count > RDS_BUFFER)
33709+ return -EFAULT;
33710 mutex_lock(&dev->lock);
33711 if (dev->rdsstat == 0) {
33712 dev->rdsstat = 1;
33713@@ -347,7 +349,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33714 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
33715 mutex_unlock(&dev->lock);
33716
33717- if (copy_to_user(data, readbuf, i))
33718+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
33719 return -EFAULT;
33720 return i;
33721 }
33722diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33723index 9cde353..8c6a1c3 100644
33724--- a/drivers/media/video/au0828/au0828.h
33725+++ b/drivers/media/video/au0828/au0828.h
33726@@ -191,7 +191,7 @@ struct au0828_dev {
33727
33728 /* I2C */
33729 struct i2c_adapter i2c_adap;
33730- struct i2c_algorithm i2c_algo;
33731+ i2c_algorithm_no_const i2c_algo;
33732 struct i2c_client i2c_client;
33733 u32 i2c_rc;
33734
33735diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
33736index 04bf662..e0ac026 100644
33737--- a/drivers/media/video/cx88/cx88-alsa.c
33738+++ b/drivers/media/video/cx88/cx88-alsa.c
33739@@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33740 * Only boards with eeprom and byte 1 at eeprom=1 have it
33741 */
33742
33743-static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
33744+static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
33745 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33746 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33747 {0, }
33748diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
33749index 88cf9d9..bbc4b2c 100644
33750--- a/drivers/media/video/omap/omap_vout.c
33751+++ b/drivers/media/video/omap/omap_vout.c
33752@@ -64,7 +64,6 @@ enum omap_vout_channels {
33753 OMAP_VIDEO2,
33754 };
33755
33756-static struct videobuf_queue_ops video_vbq_ops;
33757 /* Variables configurable through module params*/
33758 static u32 video1_numbuffers = 3;
33759 static u32 video2_numbuffers = 3;
33760@@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
33761 {
33762 struct videobuf_queue *q;
33763 struct omap_vout_device *vout = NULL;
33764+ static struct videobuf_queue_ops video_vbq_ops = {
33765+ .buf_setup = omap_vout_buffer_setup,
33766+ .buf_prepare = omap_vout_buffer_prepare,
33767+ .buf_release = omap_vout_buffer_release,
33768+ .buf_queue = omap_vout_buffer_queue,
33769+ };
33770
33771 vout = video_drvdata(file);
33772 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33773@@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
33774 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33775
33776 q = &vout->vbq;
33777- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33778- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33779- video_vbq_ops.buf_release = omap_vout_buffer_release;
33780- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33781 spin_lock_init(&vout->vbq_lock);
33782
33783 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33784diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33785index 305e6aa..0143317 100644
33786--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33787+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33788@@ -196,7 +196,7 @@ struct pvr2_hdw {
33789
33790 /* I2C stuff */
33791 struct i2c_adapter i2c_adap;
33792- struct i2c_algorithm i2c_algo;
33793+ i2c_algorithm_no_const i2c_algo;
33794 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33795 int i2c_cx25840_hack_state;
33796 int i2c_linked;
33797diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
33798index 02194c0..091733b 100644
33799--- a/drivers/media/video/timblogiw.c
33800+++ b/drivers/media/video/timblogiw.c
33801@@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33802
33803 /* Platform device functions */
33804
33805-static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33806+static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33807 .vidioc_querycap = timblogiw_querycap,
33808 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33809 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33810@@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33811 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33812 };
33813
33814-static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33815+static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33816 .owner = THIS_MODULE,
33817 .open = timblogiw_open,
33818 .release = timblogiw_close,
33819diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33820index a5c591f..db692a3 100644
33821--- a/drivers/message/fusion/mptbase.c
33822+++ b/drivers/message/fusion/mptbase.c
33823@@ -6754,8 +6754,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33824 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33825 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33826
33827+#ifdef CONFIG_GRKERNSEC_HIDESYM
33828+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33829+#else
33830 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33831 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33832+#endif
33833+
33834 /*
33835 * Rounding UP to nearest 4-kB boundary here...
33836 */
33837diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33838index 551262e..7551198 100644
33839--- a/drivers/message/fusion/mptsas.c
33840+++ b/drivers/message/fusion/mptsas.c
33841@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33842 return 0;
33843 }
33844
33845+static inline void
33846+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33847+{
33848+ if (phy_info->port_details) {
33849+ phy_info->port_details->rphy = rphy;
33850+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33851+ ioc->name, rphy));
33852+ }
33853+
33854+ if (rphy) {
33855+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33856+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33857+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33858+ ioc->name, rphy, rphy->dev.release));
33859+ }
33860+}
33861+
33862 /* no mutex */
33863 static void
33864 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33865@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
33866 return NULL;
33867 }
33868
33869-static inline void
33870-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33871-{
33872- if (phy_info->port_details) {
33873- phy_info->port_details->rphy = rphy;
33874- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33875- ioc->name, rphy));
33876- }
33877-
33878- if (rphy) {
33879- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33880- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33881- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33882- ioc->name, rphy, rphy->dev.release));
33883- }
33884-}
33885-
33886 static inline struct sas_port *
33887 mptsas_get_port(struct mptsas_phyinfo *phy_info)
33888 {
33889diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
33890index 0c3ced7..1fe34ec 100644
33891--- a/drivers/message/fusion/mptscsih.c
33892+++ b/drivers/message/fusion/mptscsih.c
33893@@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
33894
33895 h = shost_priv(SChost);
33896
33897- if (h) {
33898- if (h->info_kbuf == NULL)
33899- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33900- return h->info_kbuf;
33901- h->info_kbuf[0] = '\0';
33902+ if (!h)
33903+ return NULL;
33904
33905- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33906- h->info_kbuf[size-1] = '\0';
33907- }
33908+ if (h->info_kbuf == NULL)
33909+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33910+ return h->info_kbuf;
33911+ h->info_kbuf[0] = '\0';
33912+
33913+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33914+ h->info_kbuf[size-1] = '\0';
33915
33916 return h->info_kbuf;
33917 }
33918diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
33919index 6d115c7..58ff7fd 100644
33920--- a/drivers/message/i2o/i2o_proc.c
33921+++ b/drivers/message/i2o/i2o_proc.c
33922@@ -255,13 +255,6 @@ static char *scsi_devices[] = {
33923 "Array Controller Device"
33924 };
33925
33926-static char *chtostr(u8 * chars, int n)
33927-{
33928- char tmp[256];
33929- tmp[0] = 0;
33930- return strncat(tmp, (char *)chars, n);
33931-}
33932-
33933 static int i2o_report_query_status(struct seq_file *seq, int block_status,
33934 char *group)
33935 {
33936@@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
33937
33938 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
33939 seq_printf(seq, "%-#8x", ddm_table.module_id);
33940- seq_printf(seq, "%-29s",
33941- chtostr(ddm_table.module_name_version, 28));
33942+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
33943 seq_printf(seq, "%9d ", ddm_table.data_size);
33944 seq_printf(seq, "%8d", ddm_table.code_size);
33945
33946@@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
33947
33948 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
33949 seq_printf(seq, "%-#8x", dst->module_id);
33950- seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
33951- seq_printf(seq, "%-9s", chtostr(dst->date, 8));
33952+ seq_printf(seq, "%-.28s", dst->module_name_version);
33953+ seq_printf(seq, "%-.8s", dst->date);
33954 seq_printf(seq, "%8d ", dst->module_size);
33955 seq_printf(seq, "%8d ", dst->mpb_size);
33956 seq_printf(seq, "0x%04x", dst->module_flags);
33957@@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
33958 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
33959 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
33960 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
33961- seq_printf(seq, "Vendor info : %s\n",
33962- chtostr((u8 *) (work32 + 2), 16));
33963- seq_printf(seq, "Product info : %s\n",
33964- chtostr((u8 *) (work32 + 6), 16));
33965- seq_printf(seq, "Description : %s\n",
33966- chtostr((u8 *) (work32 + 10), 16));
33967- seq_printf(seq, "Product rev. : %s\n",
33968- chtostr((u8 *) (work32 + 14), 8));
33969+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
33970+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
33971+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
33972+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
33973
33974 seq_printf(seq, "Serial number : ");
33975 print_serial_number(seq, (u8 *) (work32 + 16),
33976@@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
33977 }
33978
33979 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
33980- seq_printf(seq, "Module name : %s\n",
33981- chtostr(result.module_name, 24));
33982- seq_printf(seq, "Module revision : %s\n",
33983- chtostr(result.module_rev, 8));
33984+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
33985+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
33986
33987 seq_printf(seq, "Serial number : ");
33988 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
33989@@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
33990 return 0;
33991 }
33992
33993- seq_printf(seq, "Device name : %s\n",
33994- chtostr(result.device_name, 64));
33995- seq_printf(seq, "Service name : %s\n",
33996- chtostr(result.service_name, 64));
33997- seq_printf(seq, "Physical name : %s\n",
33998- chtostr(result.physical_location, 64));
33999- seq_printf(seq, "Instance number : %s\n",
34000- chtostr(result.instance_number, 4));
34001+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
34002+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
34003+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34004+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34005
34006 return 0;
34007 }
34008diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34009index a8c08f3..155fe3d 100644
34010--- a/drivers/message/i2o/iop.c
34011+++ b/drivers/message/i2o/iop.c
34012@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34013
34014 spin_lock_irqsave(&c->context_list_lock, flags);
34015
34016- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34017- atomic_inc(&c->context_list_counter);
34018+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34019+ atomic_inc_unchecked(&c->context_list_counter);
34020
34021- entry->context = atomic_read(&c->context_list_counter);
34022+ entry->context = atomic_read_unchecked(&c->context_list_counter);
34023
34024 list_add(&entry->list, &c->context_list);
34025
34026@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34027
34028 #if BITS_PER_LONG == 64
34029 spin_lock_init(&c->context_list_lock);
34030- atomic_set(&c->context_list_counter, 0);
34031+ atomic_set_unchecked(&c->context_list_counter, 0);
34032 INIT_LIST_HEAD(&c->context_list);
34033 #endif
34034
34035diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34036index 7ce65f4..e66e9bc 100644
34037--- a/drivers/mfd/abx500-core.c
34038+++ b/drivers/mfd/abx500-core.c
34039@@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34040
34041 struct abx500_device_entry {
34042 struct list_head list;
34043- struct abx500_ops ops;
34044+ abx500_ops_no_const ops;
34045 struct device *dev;
34046 };
34047
34048diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34049index a9223ed..4127b13 100644
34050--- a/drivers/mfd/janz-cmodio.c
34051+++ b/drivers/mfd/janz-cmodio.c
34052@@ -13,6 +13,7 @@
34053
34054 #include <linux/kernel.h>
34055 #include <linux/module.h>
34056+#include <linux/slab.h>
34057 #include <linux/init.h>
34058 #include <linux/pci.h>
34059 #include <linux/interrupt.h>
34060diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34061index a981e2a..5ca0c8b 100644
34062--- a/drivers/misc/lis3lv02d/lis3lv02d.c
34063+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34064@@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34065 * the lid is closed. This leads to interrupts as soon as a little move
34066 * is done.
34067 */
34068- atomic_inc(&lis3->count);
34069+ atomic_inc_unchecked(&lis3->count);
34070
34071 wake_up_interruptible(&lis3->misc_wait);
34072 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34073@@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34074 if (lis3->pm_dev)
34075 pm_runtime_get_sync(lis3->pm_dev);
34076
34077- atomic_set(&lis3->count, 0);
34078+ atomic_set_unchecked(&lis3->count, 0);
34079 return 0;
34080 }
34081
34082@@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34083 add_wait_queue(&lis3->misc_wait, &wait);
34084 while (true) {
34085 set_current_state(TASK_INTERRUPTIBLE);
34086- data = atomic_xchg(&lis3->count, 0);
34087+ data = atomic_xchg_unchecked(&lis3->count, 0);
34088 if (data)
34089 break;
34090
34091@@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34092 struct lis3lv02d, miscdev);
34093
34094 poll_wait(file, &lis3->misc_wait, wait);
34095- if (atomic_read(&lis3->count))
34096+ if (atomic_read_unchecked(&lis3->count))
34097 return POLLIN | POLLRDNORM;
34098 return 0;
34099 }
34100diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34101index 2b1482a..5d33616 100644
34102--- a/drivers/misc/lis3lv02d/lis3lv02d.h
34103+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34104@@ -266,7 +266,7 @@ struct lis3lv02d {
34105 struct input_polled_dev *idev; /* input device */
34106 struct platform_device *pdev; /* platform device */
34107 struct regulator_bulk_data regulators[2];
34108- atomic_t count; /* interrupt count after last read */
34109+ atomic_unchecked_t count; /* interrupt count after last read */
34110 union axis_conversion ac; /* hw -> logical axis */
34111 int mapped_btns[3];
34112
34113diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34114index 2f30bad..c4c13d0 100644
34115--- a/drivers/misc/sgi-gru/gruhandles.c
34116+++ b/drivers/misc/sgi-gru/gruhandles.c
34117@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34118 unsigned long nsec;
34119
34120 nsec = CLKS2NSEC(clks);
34121- atomic_long_inc(&mcs_op_statistics[op].count);
34122- atomic_long_add(nsec, &mcs_op_statistics[op].total);
34123+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34124+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34125 if (mcs_op_statistics[op].max < nsec)
34126 mcs_op_statistics[op].max = nsec;
34127 }
34128diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34129index 950dbe9..eeef0f8 100644
34130--- a/drivers/misc/sgi-gru/gruprocfs.c
34131+++ b/drivers/misc/sgi-gru/gruprocfs.c
34132@@ -32,9 +32,9 @@
34133
34134 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34135
34136-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34137+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34138 {
34139- unsigned long val = atomic_long_read(v);
34140+ unsigned long val = atomic_long_read_unchecked(v);
34141
34142 seq_printf(s, "%16lu %s\n", val, id);
34143 }
34144@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34145
34146 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34147 for (op = 0; op < mcsop_last; op++) {
34148- count = atomic_long_read(&mcs_op_statistics[op].count);
34149- total = atomic_long_read(&mcs_op_statistics[op].total);
34150+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34151+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34152 max = mcs_op_statistics[op].max;
34153 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34154 count ? total / count : 0, max);
34155diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34156index 5c3ce24..4915ccb 100644
34157--- a/drivers/misc/sgi-gru/grutables.h
34158+++ b/drivers/misc/sgi-gru/grutables.h
34159@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34160 * GRU statistics.
34161 */
34162 struct gru_stats_s {
34163- atomic_long_t vdata_alloc;
34164- atomic_long_t vdata_free;
34165- atomic_long_t gts_alloc;
34166- atomic_long_t gts_free;
34167- atomic_long_t gms_alloc;
34168- atomic_long_t gms_free;
34169- atomic_long_t gts_double_allocate;
34170- atomic_long_t assign_context;
34171- atomic_long_t assign_context_failed;
34172- atomic_long_t free_context;
34173- atomic_long_t load_user_context;
34174- atomic_long_t load_kernel_context;
34175- atomic_long_t lock_kernel_context;
34176- atomic_long_t unlock_kernel_context;
34177- atomic_long_t steal_user_context;
34178- atomic_long_t steal_kernel_context;
34179- atomic_long_t steal_context_failed;
34180- atomic_long_t nopfn;
34181- atomic_long_t asid_new;
34182- atomic_long_t asid_next;
34183- atomic_long_t asid_wrap;
34184- atomic_long_t asid_reuse;
34185- atomic_long_t intr;
34186- atomic_long_t intr_cbr;
34187- atomic_long_t intr_tfh;
34188- atomic_long_t intr_spurious;
34189- atomic_long_t intr_mm_lock_failed;
34190- atomic_long_t call_os;
34191- atomic_long_t call_os_wait_queue;
34192- atomic_long_t user_flush_tlb;
34193- atomic_long_t user_unload_context;
34194- atomic_long_t user_exception;
34195- atomic_long_t set_context_option;
34196- atomic_long_t check_context_retarget_intr;
34197- atomic_long_t check_context_unload;
34198- atomic_long_t tlb_dropin;
34199- atomic_long_t tlb_preload_page;
34200- atomic_long_t tlb_dropin_fail_no_asid;
34201- atomic_long_t tlb_dropin_fail_upm;
34202- atomic_long_t tlb_dropin_fail_invalid;
34203- atomic_long_t tlb_dropin_fail_range_active;
34204- atomic_long_t tlb_dropin_fail_idle;
34205- atomic_long_t tlb_dropin_fail_fmm;
34206- atomic_long_t tlb_dropin_fail_no_exception;
34207- atomic_long_t tfh_stale_on_fault;
34208- atomic_long_t mmu_invalidate_range;
34209- atomic_long_t mmu_invalidate_page;
34210- atomic_long_t flush_tlb;
34211- atomic_long_t flush_tlb_gru;
34212- atomic_long_t flush_tlb_gru_tgh;
34213- atomic_long_t flush_tlb_gru_zero_asid;
34214+ atomic_long_unchecked_t vdata_alloc;
34215+ atomic_long_unchecked_t vdata_free;
34216+ atomic_long_unchecked_t gts_alloc;
34217+ atomic_long_unchecked_t gts_free;
34218+ atomic_long_unchecked_t gms_alloc;
34219+ atomic_long_unchecked_t gms_free;
34220+ atomic_long_unchecked_t gts_double_allocate;
34221+ atomic_long_unchecked_t assign_context;
34222+ atomic_long_unchecked_t assign_context_failed;
34223+ atomic_long_unchecked_t free_context;
34224+ atomic_long_unchecked_t load_user_context;
34225+ atomic_long_unchecked_t load_kernel_context;
34226+ atomic_long_unchecked_t lock_kernel_context;
34227+ atomic_long_unchecked_t unlock_kernel_context;
34228+ atomic_long_unchecked_t steal_user_context;
34229+ atomic_long_unchecked_t steal_kernel_context;
34230+ atomic_long_unchecked_t steal_context_failed;
34231+ atomic_long_unchecked_t nopfn;
34232+ atomic_long_unchecked_t asid_new;
34233+ atomic_long_unchecked_t asid_next;
34234+ atomic_long_unchecked_t asid_wrap;
34235+ atomic_long_unchecked_t asid_reuse;
34236+ atomic_long_unchecked_t intr;
34237+ atomic_long_unchecked_t intr_cbr;
34238+ atomic_long_unchecked_t intr_tfh;
34239+ atomic_long_unchecked_t intr_spurious;
34240+ atomic_long_unchecked_t intr_mm_lock_failed;
34241+ atomic_long_unchecked_t call_os;
34242+ atomic_long_unchecked_t call_os_wait_queue;
34243+ atomic_long_unchecked_t user_flush_tlb;
34244+ atomic_long_unchecked_t user_unload_context;
34245+ atomic_long_unchecked_t user_exception;
34246+ atomic_long_unchecked_t set_context_option;
34247+ atomic_long_unchecked_t check_context_retarget_intr;
34248+ atomic_long_unchecked_t check_context_unload;
34249+ atomic_long_unchecked_t tlb_dropin;
34250+ atomic_long_unchecked_t tlb_preload_page;
34251+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34252+ atomic_long_unchecked_t tlb_dropin_fail_upm;
34253+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
34254+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
34255+ atomic_long_unchecked_t tlb_dropin_fail_idle;
34256+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
34257+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34258+ atomic_long_unchecked_t tfh_stale_on_fault;
34259+ atomic_long_unchecked_t mmu_invalidate_range;
34260+ atomic_long_unchecked_t mmu_invalidate_page;
34261+ atomic_long_unchecked_t flush_tlb;
34262+ atomic_long_unchecked_t flush_tlb_gru;
34263+ atomic_long_unchecked_t flush_tlb_gru_tgh;
34264+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34265
34266- atomic_long_t copy_gpa;
34267- atomic_long_t read_gpa;
34268+ atomic_long_unchecked_t copy_gpa;
34269+ atomic_long_unchecked_t read_gpa;
34270
34271- atomic_long_t mesq_receive;
34272- atomic_long_t mesq_receive_none;
34273- atomic_long_t mesq_send;
34274- atomic_long_t mesq_send_failed;
34275- atomic_long_t mesq_noop;
34276- atomic_long_t mesq_send_unexpected_error;
34277- atomic_long_t mesq_send_lb_overflow;
34278- atomic_long_t mesq_send_qlimit_reached;
34279- atomic_long_t mesq_send_amo_nacked;
34280- atomic_long_t mesq_send_put_nacked;
34281- atomic_long_t mesq_page_overflow;
34282- atomic_long_t mesq_qf_locked;
34283- atomic_long_t mesq_qf_noop_not_full;
34284- atomic_long_t mesq_qf_switch_head_failed;
34285- atomic_long_t mesq_qf_unexpected_error;
34286- atomic_long_t mesq_noop_unexpected_error;
34287- atomic_long_t mesq_noop_lb_overflow;
34288- atomic_long_t mesq_noop_qlimit_reached;
34289- atomic_long_t mesq_noop_amo_nacked;
34290- atomic_long_t mesq_noop_put_nacked;
34291- atomic_long_t mesq_noop_page_overflow;
34292+ atomic_long_unchecked_t mesq_receive;
34293+ atomic_long_unchecked_t mesq_receive_none;
34294+ atomic_long_unchecked_t mesq_send;
34295+ atomic_long_unchecked_t mesq_send_failed;
34296+ atomic_long_unchecked_t mesq_noop;
34297+ atomic_long_unchecked_t mesq_send_unexpected_error;
34298+ atomic_long_unchecked_t mesq_send_lb_overflow;
34299+ atomic_long_unchecked_t mesq_send_qlimit_reached;
34300+ atomic_long_unchecked_t mesq_send_amo_nacked;
34301+ atomic_long_unchecked_t mesq_send_put_nacked;
34302+ atomic_long_unchecked_t mesq_page_overflow;
34303+ atomic_long_unchecked_t mesq_qf_locked;
34304+ atomic_long_unchecked_t mesq_qf_noop_not_full;
34305+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
34306+ atomic_long_unchecked_t mesq_qf_unexpected_error;
34307+ atomic_long_unchecked_t mesq_noop_unexpected_error;
34308+ atomic_long_unchecked_t mesq_noop_lb_overflow;
34309+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
34310+ atomic_long_unchecked_t mesq_noop_amo_nacked;
34311+ atomic_long_unchecked_t mesq_noop_put_nacked;
34312+ atomic_long_unchecked_t mesq_noop_page_overflow;
34313
34314 };
34315
34316@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34317 tghop_invalidate, mcsop_last};
34318
34319 struct mcs_op_statistic {
34320- atomic_long_t count;
34321- atomic_long_t total;
34322+ atomic_long_unchecked_t count;
34323+ atomic_long_unchecked_t total;
34324 unsigned long max;
34325 };
34326
34327@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34328
34329 #define STAT(id) do { \
34330 if (gru_options & OPT_STATS) \
34331- atomic_long_inc(&gru_stats.id); \
34332+ atomic_long_inc_unchecked(&gru_stats.id); \
34333 } while (0)
34334
34335 #ifdef CONFIG_SGI_GRU_DEBUG
34336diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34337index c862cd4..0d176fe 100644
34338--- a/drivers/misc/sgi-xp/xp.h
34339+++ b/drivers/misc/sgi-xp/xp.h
34340@@ -288,7 +288,7 @@ struct xpc_interface {
34341 xpc_notify_func, void *);
34342 void (*received) (short, int, void *);
34343 enum xp_retval (*partid_to_nasids) (short, void *);
34344-};
34345+} __no_const;
34346
34347 extern struct xpc_interface xpc_interface;
34348
34349diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34350index b94d5f7..7f494c5 100644
34351--- a/drivers/misc/sgi-xp/xpc.h
34352+++ b/drivers/misc/sgi-xp/xpc.h
34353@@ -835,6 +835,7 @@ struct xpc_arch_operations {
34354 void (*received_payload) (struct xpc_channel *, void *);
34355 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34356 };
34357+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34358
34359 /* struct xpc_partition act_state values (for XPC HB) */
34360
34361@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34362 /* found in xpc_main.c */
34363 extern struct device *xpc_part;
34364 extern struct device *xpc_chan;
34365-extern struct xpc_arch_operations xpc_arch_ops;
34366+extern xpc_arch_operations_no_const xpc_arch_ops;
34367 extern int xpc_disengage_timelimit;
34368 extern int xpc_disengage_timedout;
34369 extern int xpc_activate_IRQ_rcvd;
34370diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34371index 8d082b4..aa749ae 100644
34372--- a/drivers/misc/sgi-xp/xpc_main.c
34373+++ b/drivers/misc/sgi-xp/xpc_main.c
34374@@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34375 .notifier_call = xpc_system_die,
34376 };
34377
34378-struct xpc_arch_operations xpc_arch_ops;
34379+xpc_arch_operations_no_const xpc_arch_ops;
34380
34381 /*
34382 * Timer function to enforce the timelimit on the partition disengage.
34383diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34384index 69ef0be..f3ef91e 100644
34385--- a/drivers/mmc/host/sdhci-pci.c
34386+++ b/drivers/mmc/host/sdhci-pci.c
34387@@ -652,7 +652,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34388 .probe = via_probe,
34389 };
34390
34391-static const struct pci_device_id pci_ids[] __devinitdata = {
34392+static const struct pci_device_id pci_ids[] __devinitconst = {
34393 {
34394 .vendor = PCI_VENDOR_ID_RICOH,
34395 .device = PCI_DEVICE_ID_RICOH_R5C822,
34396diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34397index a4eb8b5..8c0628f 100644
34398--- a/drivers/mtd/devices/doc2000.c
34399+++ b/drivers/mtd/devices/doc2000.c
34400@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34401
34402 /* The ECC will not be calculated correctly if less than 512 is written */
34403 /* DBB-
34404- if (len != 0x200 && eccbuf)
34405+ if (len != 0x200)
34406 printk(KERN_WARNING
34407 "ECC needs a full sector write (adr: %lx size %lx)\n",
34408 (long) to, (long) len);
34409diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34410index a9e57d6..c6d8731 100644
34411--- a/drivers/mtd/nand/denali.c
34412+++ b/drivers/mtd/nand/denali.c
34413@@ -26,6 +26,7 @@
34414 #include <linux/pci.h>
34415 #include <linux/mtd/mtd.h>
34416 #include <linux/module.h>
34417+#include <linux/slab.h>
34418
34419 #include "denali.h"
34420
34421diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34422index 51b9d6a..52af9a7 100644
34423--- a/drivers/mtd/nftlmount.c
34424+++ b/drivers/mtd/nftlmount.c
34425@@ -24,6 +24,7 @@
34426 #include <asm/errno.h>
34427 #include <linux/delay.h>
34428 #include <linux/slab.h>
34429+#include <linux/sched.h>
34430 #include <linux/mtd/mtd.h>
34431 #include <linux/mtd/nand.h>
34432 #include <linux/mtd/nftl.h>
34433diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34434index 6762dc4..9956862 100644
34435--- a/drivers/net/ethernet/atheros/atlx/atl2.c
34436+++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34437@@ -2859,7 +2859,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34438 */
34439
34440 #define ATL2_PARAM(X, desc) \
34441- static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34442+ static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34443 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34444 MODULE_PARM_DESC(X, desc);
34445 #else
34446diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34447index 61a7670..7da6e34 100644
34448--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34449+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34450@@ -483,7 +483,7 @@ struct bnx2x_rx_mode_obj {
34451
34452 int (*wait_comp)(struct bnx2x *bp,
34453 struct bnx2x_rx_mode_ramrod_params *p);
34454-};
34455+} __no_const;
34456
34457 /********************** Set multicast group ***********************************/
34458
34459diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34460index 93865f8..5448741 100644
34461--- a/drivers/net/ethernet/broadcom/tg3.h
34462+++ b/drivers/net/ethernet/broadcom/tg3.h
34463@@ -140,6 +140,7 @@
34464 #define CHIPREV_ID_5750_A0 0x4000
34465 #define CHIPREV_ID_5750_A1 0x4001
34466 #define CHIPREV_ID_5750_A3 0x4003
34467+#define CHIPREV_ID_5750_C1 0x4201
34468 #define CHIPREV_ID_5750_C2 0x4202
34469 #define CHIPREV_ID_5752_A0_HW 0x5000
34470 #define CHIPREV_ID_5752_A0 0x6000
34471diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34472index c4e8643..0979484 100644
34473--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34474+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34475@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34476 */
34477 struct l2t_skb_cb {
34478 arp_failure_handler_func arp_failure_handler;
34479-};
34480+} __no_const;
34481
34482 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34483
34484diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34485index 18b106c..2b38d36 100644
34486--- a/drivers/net/ethernet/dec/tulip/de4x5.c
34487+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34488@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34489 for (i=0; i<ETH_ALEN; i++) {
34490 tmp.addr[i] = dev->dev_addr[i];
34491 }
34492- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34493+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34494 break;
34495
34496 case DE4X5_SET_HWADDR: /* Set the hardware address */
34497@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34498 spin_lock_irqsave(&lp->lock, flags);
34499 memcpy(&statbuf, &lp->pktStats, ioc->len);
34500 spin_unlock_irqrestore(&lp->lock, flags);
34501- if (copy_to_user(ioc->data, &statbuf, ioc->len))
34502+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34503 return -EFAULT;
34504 break;
34505 }
34506diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34507index ed7d1dc..d426748 100644
34508--- a/drivers/net/ethernet/dec/tulip/eeprom.c
34509+++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34510@@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34511 {NULL}};
34512
34513
34514-static const char *block_name[] __devinitdata = {
34515+static const char *block_name[] __devinitconst = {
34516 "21140 non-MII",
34517 "21140 MII PHY",
34518 "21142 Serial PHY",
34519diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34520index 2ac6fff..2d127d0 100644
34521--- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34522+++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34523@@ -236,7 +236,7 @@ struct pci_id_info {
34524 int drv_flags; /* Driver use, intended as capability flags. */
34525 };
34526
34527-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34528+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34529 { /* Sometime a Level-One switch card. */
34530 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34531 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34532diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34533index d783f4f..97fa1b0 100644
34534--- a/drivers/net/ethernet/dlink/sundance.c
34535+++ b/drivers/net/ethernet/dlink/sundance.c
34536@@ -218,7 +218,7 @@ enum {
34537 struct pci_id_info {
34538 const char *name;
34539 };
34540-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34541+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34542 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34543 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34544 {"D-Link DFE-580TX 4 port Server Adapter"},
34545diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34546index 528a886..e6a98a3 100644
34547--- a/drivers/net/ethernet/emulex/benet/be_main.c
34548+++ b/drivers/net/ethernet/emulex/benet/be_main.c
34549@@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34550
34551 if (wrapped)
34552 newacc += 65536;
34553- ACCESS_ONCE(*acc) = newacc;
34554+ ACCESS_ONCE_RW(*acc) = newacc;
34555 }
34556
34557 void be_parse_stats(struct be_adapter *adapter)
34558diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34559index 16b0704..d2c07d7 100644
34560--- a/drivers/net/ethernet/faraday/ftgmac100.c
34561+++ b/drivers/net/ethernet/faraday/ftgmac100.c
34562@@ -31,6 +31,8 @@
34563 #include <linux/netdevice.h>
34564 #include <linux/phy.h>
34565 #include <linux/platform_device.h>
34566+#include <linux/interrupt.h>
34567+#include <linux/irqreturn.h>
34568 #include <net/ip.h>
34569
34570 #include "ftgmac100.h"
34571diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34572index 829b109..4ae5f6a 100644
34573--- a/drivers/net/ethernet/faraday/ftmac100.c
34574+++ b/drivers/net/ethernet/faraday/ftmac100.c
34575@@ -31,6 +31,8 @@
34576 #include <linux/module.h>
34577 #include <linux/netdevice.h>
34578 #include <linux/platform_device.h>
34579+#include <linux/interrupt.h>
34580+#include <linux/irqreturn.h>
34581
34582 #include "ftmac100.h"
34583
34584diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34585index 1637b98..c42f87b 100644
34586--- a/drivers/net/ethernet/fealnx.c
34587+++ b/drivers/net/ethernet/fealnx.c
34588@@ -150,7 +150,7 @@ struct chip_info {
34589 int flags;
34590 };
34591
34592-static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34593+static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34594 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34595 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34596 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34597diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
34598index b83897f..b2d970f 100644
34599--- a/drivers/net/ethernet/intel/e1000e/e1000.h
34600+++ b/drivers/net/ethernet/intel/e1000e/e1000.h
34601@@ -181,7 +181,7 @@ struct e1000_info;
34602 #define E1000_TXDCTL_DMA_BURST_ENABLE \
34603 (E1000_TXDCTL_GRAN | /* set descriptor granularity */ \
34604 E1000_TXDCTL_COUNT_DESC | \
34605- (5 << 16) | /* wthresh must be +1 more than desired */\
34606+ (1 << 16) | /* wthresh must be +1 more than desired */\
34607 (1 << 8) | /* hthresh */ \
34608 0x1f) /* pthresh */
34609
34610diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34611index f82ecf5..7d59ecb 100644
34612--- a/drivers/net/ethernet/intel/e1000e/hw.h
34613+++ b/drivers/net/ethernet/intel/e1000e/hw.h
34614@@ -784,6 +784,7 @@ struct e1000_mac_operations {
34615 void (*config_collision_dist)(struct e1000_hw *);
34616 s32 (*read_mac_addr)(struct e1000_hw *);
34617 };
34618+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34619
34620 /*
34621 * When to use various PHY register access functions:
34622@@ -824,6 +825,7 @@ struct e1000_phy_operations {
34623 void (*power_up)(struct e1000_hw *);
34624 void (*power_down)(struct e1000_hw *);
34625 };
34626+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34627
34628 /* Function pointers for the NVM. */
34629 struct e1000_nvm_operations {
34630@@ -836,9 +838,10 @@ struct e1000_nvm_operations {
34631 s32 (*validate)(struct e1000_hw *);
34632 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34633 };
34634+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34635
34636 struct e1000_mac_info {
34637- struct e1000_mac_operations ops;
34638+ e1000_mac_operations_no_const ops;
34639 u8 addr[ETH_ALEN];
34640 u8 perm_addr[ETH_ALEN];
34641
34642@@ -879,7 +882,7 @@ struct e1000_mac_info {
34643 };
34644
34645 struct e1000_phy_info {
34646- struct e1000_phy_operations ops;
34647+ e1000_phy_operations_no_const ops;
34648
34649 enum e1000_phy_type type;
34650
34651@@ -913,7 +916,7 @@ struct e1000_phy_info {
34652 };
34653
34654 struct e1000_nvm_info {
34655- struct e1000_nvm_operations ops;
34656+ e1000_nvm_operations_no_const ops;
34657
34658 enum e1000_nvm_type type;
34659 enum e1000_nvm_override override;
34660diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34661index f67cbd3..cef9e3d 100644
34662--- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34663+++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34664@@ -314,6 +314,7 @@ struct e1000_mac_operations {
34665 s32 (*read_mac_addr)(struct e1000_hw *);
34666 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
34667 };
34668+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34669
34670 struct e1000_phy_operations {
34671 s32 (*acquire)(struct e1000_hw *);
34672@@ -330,6 +331,7 @@ struct e1000_phy_operations {
34673 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34674 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34675 };
34676+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34677
34678 struct e1000_nvm_operations {
34679 s32 (*acquire)(struct e1000_hw *);
34680@@ -339,6 +341,7 @@ struct e1000_nvm_operations {
34681 s32 (*update)(struct e1000_hw *);
34682 s32 (*validate)(struct e1000_hw *);
34683 };
34684+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34685
34686 struct e1000_info {
34687 s32 (*get_invariants)(struct e1000_hw *);
34688@@ -350,7 +353,7 @@ struct e1000_info {
34689 extern const struct e1000_info e1000_82575_info;
34690
34691 struct e1000_mac_info {
34692- struct e1000_mac_operations ops;
34693+ e1000_mac_operations_no_const ops;
34694
34695 u8 addr[6];
34696 u8 perm_addr[6];
34697@@ -388,7 +391,7 @@ struct e1000_mac_info {
34698 };
34699
34700 struct e1000_phy_info {
34701- struct e1000_phy_operations ops;
34702+ e1000_phy_operations_no_const ops;
34703
34704 enum e1000_phy_type type;
34705
34706@@ -423,7 +426,7 @@ struct e1000_phy_info {
34707 };
34708
34709 struct e1000_nvm_info {
34710- struct e1000_nvm_operations ops;
34711+ e1000_nvm_operations_no_const ops;
34712 enum e1000_nvm_type type;
34713 enum e1000_nvm_override override;
34714
34715@@ -468,6 +471,7 @@ struct e1000_mbx_operations {
34716 s32 (*check_for_ack)(struct e1000_hw *, u16);
34717 s32 (*check_for_rst)(struct e1000_hw *, u16);
34718 };
34719+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34720
34721 struct e1000_mbx_stats {
34722 u32 msgs_tx;
34723@@ -479,7 +483,7 @@ struct e1000_mbx_stats {
34724 };
34725
34726 struct e1000_mbx_info {
34727- struct e1000_mbx_operations ops;
34728+ e1000_mbx_operations_no_const ops;
34729 struct e1000_mbx_stats stats;
34730 u32 timeout;
34731 u32 usec_delay;
34732diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34733index 57db3c6..aa825fc 100644
34734--- a/drivers/net/ethernet/intel/igbvf/vf.h
34735+++ b/drivers/net/ethernet/intel/igbvf/vf.h
34736@@ -189,9 +189,10 @@ struct e1000_mac_operations {
34737 s32 (*read_mac_addr)(struct e1000_hw *);
34738 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34739 };
34740+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34741
34742 struct e1000_mac_info {
34743- struct e1000_mac_operations ops;
34744+ e1000_mac_operations_no_const ops;
34745 u8 addr[6];
34746 u8 perm_addr[6];
34747
34748@@ -213,6 +214,7 @@ struct e1000_mbx_operations {
34749 s32 (*check_for_ack)(struct e1000_hw *);
34750 s32 (*check_for_rst)(struct e1000_hw *);
34751 };
34752+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34753
34754 struct e1000_mbx_stats {
34755 u32 msgs_tx;
34756@@ -224,7 +226,7 @@ struct e1000_mbx_stats {
34757 };
34758
34759 struct e1000_mbx_info {
34760- struct e1000_mbx_operations ops;
34761+ e1000_mbx_operations_no_const ops;
34762 struct e1000_mbx_stats stats;
34763 u32 timeout;
34764 u32 usec_delay;
34765diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34766index 8636e83..ab9bbc3 100644
34767--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34768+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34769@@ -2710,6 +2710,7 @@ struct ixgbe_eeprom_operations {
34770 s32 (*update_checksum)(struct ixgbe_hw *);
34771 u16 (*calc_checksum)(struct ixgbe_hw *);
34772 };
34773+typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
34774
34775 struct ixgbe_mac_operations {
34776 s32 (*init_hw)(struct ixgbe_hw *);
34777@@ -2773,6 +2774,7 @@ struct ixgbe_mac_operations {
34778 /* Manageability interface */
34779 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
34780 };
34781+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34782
34783 struct ixgbe_phy_operations {
34784 s32 (*identify)(struct ixgbe_hw *);
34785@@ -2792,9 +2794,10 @@ struct ixgbe_phy_operations {
34786 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
34787 s32 (*check_overtemp)(struct ixgbe_hw *);
34788 };
34789+typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
34790
34791 struct ixgbe_eeprom_info {
34792- struct ixgbe_eeprom_operations ops;
34793+ ixgbe_eeprom_operations_no_const ops;
34794 enum ixgbe_eeprom_type type;
34795 u32 semaphore_delay;
34796 u16 word_size;
34797@@ -2804,7 +2807,7 @@ struct ixgbe_eeprom_info {
34798
34799 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
34800 struct ixgbe_mac_info {
34801- struct ixgbe_mac_operations ops;
34802+ ixgbe_mac_operations_no_const ops;
34803 enum ixgbe_mac_type type;
34804 u8 addr[ETH_ALEN];
34805 u8 perm_addr[ETH_ALEN];
34806@@ -2832,7 +2835,7 @@ struct ixgbe_mac_info {
34807 };
34808
34809 struct ixgbe_phy_info {
34810- struct ixgbe_phy_operations ops;
34811+ ixgbe_phy_operations_no_const ops;
34812 struct mdio_if_info mdio;
34813 enum ixgbe_phy_type type;
34814 u32 id;
34815@@ -2860,6 +2863,7 @@ struct ixgbe_mbx_operations {
34816 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
34817 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
34818 };
34819+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34820
34821 struct ixgbe_mbx_stats {
34822 u32 msgs_tx;
34823@@ -2871,7 +2875,7 @@ struct ixgbe_mbx_stats {
34824 };
34825
34826 struct ixgbe_mbx_info {
34827- struct ixgbe_mbx_operations ops;
34828+ ixgbe_mbx_operations_no_const ops;
34829 struct ixgbe_mbx_stats stats;
34830 u32 timeout;
34831 u32 usec_delay;
34832diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
34833index 25c951d..cc7cf33 100644
34834--- a/drivers/net/ethernet/intel/ixgbevf/vf.h
34835+++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
34836@@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
34837 s32 (*clear_vfta)(struct ixgbe_hw *);
34838 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
34839 };
34840+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34841
34842 enum ixgbe_mac_type {
34843 ixgbe_mac_unknown = 0,
34844@@ -79,7 +80,7 @@ enum ixgbe_mac_type {
34845 };
34846
34847 struct ixgbe_mac_info {
34848- struct ixgbe_mac_operations ops;
34849+ ixgbe_mac_operations_no_const ops;
34850 u8 addr[6];
34851 u8 perm_addr[6];
34852
34853@@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
34854 s32 (*check_for_ack)(struct ixgbe_hw *);
34855 s32 (*check_for_rst)(struct ixgbe_hw *);
34856 };
34857+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34858
34859 struct ixgbe_mbx_stats {
34860 u32 msgs_tx;
34861@@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
34862 };
34863
34864 struct ixgbe_mbx_info {
34865- struct ixgbe_mbx_operations ops;
34866+ ixgbe_mbx_operations_no_const ops;
34867 struct ixgbe_mbx_stats stats;
34868 u32 timeout;
34869 u32 udelay;
34870diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
34871index 8bb05b4..074796f 100644
34872--- a/drivers/net/ethernet/mellanox/mlx4/main.c
34873+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
34874@@ -41,6 +41,7 @@
34875 #include <linux/slab.h>
34876 #include <linux/io-mapping.h>
34877 #include <linux/delay.h>
34878+#include <linux/sched.h>
34879
34880 #include <linux/mlx4/device.h>
34881 #include <linux/mlx4/doorbell.h>
34882diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34883index 5046a64..71ca936 100644
34884--- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
34885+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34886@@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
34887 void (*link_down)(struct __vxge_hw_device *devh);
34888 void (*crit_err)(struct __vxge_hw_device *devh,
34889 enum vxge_hw_event type, u64 ext_data);
34890-};
34891+} __no_const;
34892
34893 /*
34894 * struct __vxge_hw_blockpool_entry - Block private data structure
34895diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34896index 4a518a3..936b334 100644
34897--- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34898+++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34899@@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
34900 struct vxge_hw_mempool_dma *dma_object,
34901 u32 index,
34902 u32 is_last);
34903-};
34904+} __no_const;
34905
34906 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
34907 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
34908diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
34909index ce6b44d..74f10c2 100644
34910--- a/drivers/net/ethernet/realtek/r8169.c
34911+++ b/drivers/net/ethernet/realtek/r8169.c
34912@@ -708,17 +708,17 @@ struct rtl8169_private {
34913 struct mdio_ops {
34914 void (*write)(void __iomem *, int, int);
34915 int (*read)(void __iomem *, int);
34916- } mdio_ops;
34917+ } __no_const mdio_ops;
34918
34919 struct pll_power_ops {
34920 void (*down)(struct rtl8169_private *);
34921 void (*up)(struct rtl8169_private *);
34922- } pll_power_ops;
34923+ } __no_const pll_power_ops;
34924
34925 struct jumbo_ops {
34926 void (*enable)(struct rtl8169_private *);
34927 void (*disable)(struct rtl8169_private *);
34928- } jumbo_ops;
34929+ } __no_const jumbo_ops;
34930
34931 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
34932 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
34933diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
34934index a9deda8..5507c31 100644
34935--- a/drivers/net/ethernet/sis/sis190.c
34936+++ b/drivers/net/ethernet/sis/sis190.c
34937@@ -1620,7 +1620,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
34938 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
34939 struct net_device *dev)
34940 {
34941- static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
34942+ static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
34943 struct sis190_private *tp = netdev_priv(dev);
34944 struct pci_dev *isa_bridge;
34945 u8 reg, tmp8;
34946diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
34947index c07cfe9..81cbf7e 100644
34948--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
34949+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
34950@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
34951
34952 writel(value, ioaddr + MMC_CNTRL);
34953
34954- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
34955- MMC_CNTRL, value);
34956+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
34957+// MMC_CNTRL, value);
34958 }
34959
34960 /* To mask all all interrupts.*/
34961diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
34962index 48d56da..a27e46c 100644
34963--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
34964+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
34965@@ -1584,7 +1584,7 @@ static const struct file_operations stmmac_rings_status_fops = {
34966 .open = stmmac_sysfs_ring_open,
34967 .read = seq_read,
34968 .llseek = seq_lseek,
34969- .release = seq_release,
34970+ .release = single_release,
34971 };
34972
34973 static int stmmac_sysfs_dma_cap_read(struct seq_file *seq, void *v)
34974@@ -1656,7 +1656,7 @@ static const struct file_operations stmmac_dma_cap_fops = {
34975 .open = stmmac_sysfs_dma_cap_open,
34976 .read = seq_read,
34977 .llseek = seq_lseek,
34978- .release = seq_release,
34979+ .release = single_release,
34980 };
34981
34982 static int stmmac_init_fs(struct net_device *dev)
34983diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
34984index c358245..8c1de63 100644
34985--- a/drivers/net/hyperv/hyperv_net.h
34986+++ b/drivers/net/hyperv/hyperv_net.h
34987@@ -98,7 +98,7 @@ struct rndis_device {
34988
34989 enum rndis_device_state state;
34990 bool link_state;
34991- atomic_t new_req_id;
34992+ atomic_unchecked_t new_req_id;
34993
34994 spinlock_t request_lock;
34995 struct list_head req_list;
34996diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
34997index d6be64b..5d97e3b 100644
34998--- a/drivers/net/hyperv/rndis_filter.c
34999+++ b/drivers/net/hyperv/rndis_filter.c
35000@@ -97,7 +97,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35001 * template
35002 */
35003 set = &rndis_msg->msg.set_req;
35004- set->req_id = atomic_inc_return(&dev->new_req_id);
35005+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35006
35007 /* Add to the request list */
35008 spin_lock_irqsave(&dev->request_lock, flags);
35009@@ -648,7 +648,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35010
35011 /* Setup the rndis set */
35012 halt = &request->request_msg.msg.halt_req;
35013- halt->req_id = atomic_inc_return(&dev->new_req_id);
35014+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35015
35016 /* Ignore return since this msg is optional. */
35017 rndis_filter_send_request(dev, request);
35018diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
35019index cb8fd50..003ec38 100644
35020--- a/drivers/net/macvtap.c
35021+++ b/drivers/net/macvtap.c
35022@@ -528,6 +528,8 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
35023 }
35024 base = (unsigned long)from->iov_base + offset1;
35025 size = ((base & ~PAGE_MASK) + len + ~PAGE_MASK) >> PAGE_SHIFT;
35026+ if (i + size >= MAX_SKB_FRAGS)
35027+ return -EFAULT;
35028 num_pages = get_user_pages_fast(base, size, 0, &page[i]);
35029 if ((num_pages != size) ||
35030 (num_pages > MAX_SKB_FRAGS - skb_shinfo(skb)->nr_frags))
35031diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35032index 21d7151..8034208 100644
35033--- a/drivers/net/ppp/ppp_generic.c
35034+++ b/drivers/net/ppp/ppp_generic.c
35035@@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35036 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35037 struct ppp_stats stats;
35038 struct ppp_comp_stats cstats;
35039- char *vers;
35040
35041 switch (cmd) {
35042 case SIOCGPPPSTATS:
35043@@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35044 break;
35045
35046 case SIOCGPPPVER:
35047- vers = PPP_VERSION;
35048- if (copy_to_user(addr, vers, strlen(vers) + 1))
35049+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35050 break;
35051 err = 0;
35052 break;
35053diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
35054index b715e6b..6d2490f 100644
35055--- a/drivers/net/tokenring/abyss.c
35056+++ b/drivers/net/tokenring/abyss.c
35057@@ -450,10 +450,12 @@ static struct pci_driver abyss_driver = {
35058
35059 static int __init abyss_init (void)
35060 {
35061- abyss_netdev_ops = tms380tr_netdev_ops;
35062+ pax_open_kernel();
35063+ memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35064
35065- abyss_netdev_ops.ndo_open = abyss_open;
35066- abyss_netdev_ops.ndo_stop = abyss_close;
35067+ *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
35068+ *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
35069+ pax_close_kernel();
35070
35071 return pci_register_driver(&abyss_driver);
35072 }
35073diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
35074index 28adcdf..ae82f35 100644
35075--- a/drivers/net/tokenring/madgemc.c
35076+++ b/drivers/net/tokenring/madgemc.c
35077@@ -742,9 +742,11 @@ static struct mca_driver madgemc_driver = {
35078
35079 static int __init madgemc_init (void)
35080 {
35081- madgemc_netdev_ops = tms380tr_netdev_ops;
35082- madgemc_netdev_ops.ndo_open = madgemc_open;
35083- madgemc_netdev_ops.ndo_stop = madgemc_close;
35084+ pax_open_kernel();
35085+ memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35086+ *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
35087+ *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
35088+ pax_close_kernel();
35089
35090 return mca_register_driver (&madgemc_driver);
35091 }
35092diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
35093index 62d90e4..9d84237 100644
35094--- a/drivers/net/tokenring/proteon.c
35095+++ b/drivers/net/tokenring/proteon.c
35096@@ -352,9 +352,11 @@ static int __init proteon_init(void)
35097 struct platform_device *pdev;
35098 int i, num = 0, err = 0;
35099
35100- proteon_netdev_ops = tms380tr_netdev_ops;
35101- proteon_netdev_ops.ndo_open = proteon_open;
35102- proteon_netdev_ops.ndo_stop = tms380tr_close;
35103+ pax_open_kernel();
35104+ memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35105+ *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
35106+ *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
35107+ pax_close_kernel();
35108
35109 err = platform_driver_register(&proteon_driver);
35110 if (err)
35111diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
35112index ee11e93..c8f19c7 100644
35113--- a/drivers/net/tokenring/skisa.c
35114+++ b/drivers/net/tokenring/skisa.c
35115@@ -362,9 +362,11 @@ static int __init sk_isa_init(void)
35116 struct platform_device *pdev;
35117 int i, num = 0, err = 0;
35118
35119- sk_isa_netdev_ops = tms380tr_netdev_ops;
35120- sk_isa_netdev_ops.ndo_open = sk_isa_open;
35121- sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35122+ pax_open_kernel();
35123+ memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35124+ *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
35125+ *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35126+ pax_close_kernel();
35127
35128 err = platform_driver_register(&sk_isa_driver);
35129 if (err)
35130diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35131index 2d2a688..35f2372 100644
35132--- a/drivers/net/usb/hso.c
35133+++ b/drivers/net/usb/hso.c
35134@@ -71,7 +71,7 @@
35135 #include <asm/byteorder.h>
35136 #include <linux/serial_core.h>
35137 #include <linux/serial.h>
35138-
35139+#include <asm/local.h>
35140
35141 #define MOD_AUTHOR "Option Wireless"
35142 #define MOD_DESCRIPTION "USB High Speed Option driver"
35143@@ -257,7 +257,7 @@ struct hso_serial {
35144
35145 /* from usb_serial_port */
35146 struct tty_struct *tty;
35147- int open_count;
35148+ local_t open_count;
35149 spinlock_t serial_lock;
35150
35151 int (*write_data) (struct hso_serial *serial);
35152@@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35153 struct urb *urb;
35154
35155 urb = serial->rx_urb[0];
35156- if (serial->open_count > 0) {
35157+ if (local_read(&serial->open_count) > 0) {
35158 count = put_rxbuf_data(urb, serial);
35159 if (count == -1)
35160 return;
35161@@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35162 DUMP1(urb->transfer_buffer, urb->actual_length);
35163
35164 /* Anyone listening? */
35165- if (serial->open_count == 0)
35166+ if (local_read(&serial->open_count) == 0)
35167 return;
35168
35169 if (status == 0) {
35170@@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35171 spin_unlock_irq(&serial->serial_lock);
35172
35173 /* check for port already opened, if not set the termios */
35174- serial->open_count++;
35175- if (serial->open_count == 1) {
35176+ if (local_inc_return(&serial->open_count) == 1) {
35177 serial->rx_state = RX_IDLE;
35178 /* Force default termio settings */
35179 _hso_serial_set_termios(tty, NULL);
35180@@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35181 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35182 if (result) {
35183 hso_stop_serial_device(serial->parent);
35184- serial->open_count--;
35185+ local_dec(&serial->open_count);
35186 kref_put(&serial->parent->ref, hso_serial_ref_free);
35187 }
35188 } else {
35189@@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35190
35191 /* reset the rts and dtr */
35192 /* do the actual close */
35193- serial->open_count--;
35194+ local_dec(&serial->open_count);
35195
35196- if (serial->open_count <= 0) {
35197- serial->open_count = 0;
35198+ if (local_read(&serial->open_count) <= 0) {
35199+ local_set(&serial->open_count, 0);
35200 spin_lock_irq(&serial->serial_lock);
35201 if (serial->tty == tty) {
35202 serial->tty->driver_data = NULL;
35203@@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35204
35205 /* the actual setup */
35206 spin_lock_irqsave(&serial->serial_lock, flags);
35207- if (serial->open_count)
35208+ if (local_read(&serial->open_count))
35209 _hso_serial_set_termios(tty, old);
35210 else
35211 tty->termios = old;
35212@@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
35213 D1("Pending read interrupt on port %d\n", i);
35214 spin_lock(&serial->serial_lock);
35215 if (serial->rx_state == RX_IDLE &&
35216- serial->open_count > 0) {
35217+ local_read(&serial->open_count) > 0) {
35218 /* Setup and send a ctrl req read on
35219 * port i */
35220 if (!serial->rx_urb_filled[0]) {
35221@@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
35222 /* Start all serial ports */
35223 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35224 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35225- if (dev2ser(serial_table[i])->open_count) {
35226+ if (local_read(&dev2ser(serial_table[i])->open_count)) {
35227 result =
35228 hso_start_serial_device(serial_table[i], GFP_NOIO);
35229 hso_kick_transmit(dev2ser(serial_table[i]));
35230diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35231index c54b7d37..af1f359 100644
35232--- a/drivers/net/wireless/ath/ath.h
35233+++ b/drivers/net/wireless/ath/ath.h
35234@@ -119,6 +119,7 @@ struct ath_ops {
35235 void (*write_flush) (void *);
35236 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35237 };
35238+typedef struct ath_ops __no_const ath_ops_no_const;
35239
35240 struct ath_common;
35241 struct ath_bus_ops;
35242diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35243index aa2abaf..5f5152d 100644
35244--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35245+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35246@@ -183,8 +183,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35247 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35248 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35249
35250- ACCESS_ONCE(ads->ds_link) = i->link;
35251- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35252+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
35253+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35254
35255 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35256 ctl6 = SM(i->keytype, AR_EncrType);
35257@@ -198,26 +198,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35258
35259 if ((i->is_first || i->is_last) &&
35260 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35261- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35262+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35263 | set11nTries(i->rates, 1)
35264 | set11nTries(i->rates, 2)
35265 | set11nTries(i->rates, 3)
35266 | (i->dur_update ? AR_DurUpdateEna : 0)
35267 | SM(0, AR_BurstDur);
35268
35269- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35270+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35271 | set11nRate(i->rates, 1)
35272 | set11nRate(i->rates, 2)
35273 | set11nRate(i->rates, 3);
35274 } else {
35275- ACCESS_ONCE(ads->ds_ctl2) = 0;
35276- ACCESS_ONCE(ads->ds_ctl3) = 0;
35277+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35278+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35279 }
35280
35281 if (!i->is_first) {
35282- ACCESS_ONCE(ads->ds_ctl0) = 0;
35283- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35284- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35285+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35286+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35287+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35288 return;
35289 }
35290
35291@@ -242,7 +242,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35292 break;
35293 }
35294
35295- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35296+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35297 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35298 | SM(i->txpower, AR_XmitPower)
35299 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35300@@ -252,19 +252,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35301 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35302 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35303
35304- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35305- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35306+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35307+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35308
35309 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35310 return;
35311
35312- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35313+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35314 | set11nPktDurRTSCTS(i->rates, 1);
35315
35316- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35317+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35318 | set11nPktDurRTSCTS(i->rates, 3);
35319
35320- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35321+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35322 | set11nRateFlags(i->rates, 1)
35323 | set11nRateFlags(i->rates, 2)
35324 | set11nRateFlags(i->rates, 3)
35325diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35326index a66a13b..0ef399e 100644
35327--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35328+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35329@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35330 (i->qcu << AR_TxQcuNum_S) | desc_len;
35331
35332 checksum += val;
35333- ACCESS_ONCE(ads->info) = val;
35334+ ACCESS_ONCE_RW(ads->info) = val;
35335
35336 checksum += i->link;
35337- ACCESS_ONCE(ads->link) = i->link;
35338+ ACCESS_ONCE_RW(ads->link) = i->link;
35339
35340 checksum += i->buf_addr[0];
35341- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35342+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35343 checksum += i->buf_addr[1];
35344- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35345+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35346 checksum += i->buf_addr[2];
35347- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35348+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35349 checksum += i->buf_addr[3];
35350- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35351+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35352
35353 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35354- ACCESS_ONCE(ads->ctl3) = val;
35355+ ACCESS_ONCE_RW(ads->ctl3) = val;
35356 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35357- ACCESS_ONCE(ads->ctl5) = val;
35358+ ACCESS_ONCE_RW(ads->ctl5) = val;
35359 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35360- ACCESS_ONCE(ads->ctl7) = val;
35361+ ACCESS_ONCE_RW(ads->ctl7) = val;
35362 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35363- ACCESS_ONCE(ads->ctl9) = val;
35364+ ACCESS_ONCE_RW(ads->ctl9) = val;
35365
35366 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35367- ACCESS_ONCE(ads->ctl10) = checksum;
35368+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
35369
35370 if (i->is_first || i->is_last) {
35371- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35372+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35373 | set11nTries(i->rates, 1)
35374 | set11nTries(i->rates, 2)
35375 | set11nTries(i->rates, 3)
35376 | (i->dur_update ? AR_DurUpdateEna : 0)
35377 | SM(0, AR_BurstDur);
35378
35379- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35380+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35381 | set11nRate(i->rates, 1)
35382 | set11nRate(i->rates, 2)
35383 | set11nRate(i->rates, 3);
35384 } else {
35385- ACCESS_ONCE(ads->ctl13) = 0;
35386- ACCESS_ONCE(ads->ctl14) = 0;
35387+ ACCESS_ONCE_RW(ads->ctl13) = 0;
35388+ ACCESS_ONCE_RW(ads->ctl14) = 0;
35389 }
35390
35391 ads->ctl20 = 0;
35392@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35393
35394 ctl17 = SM(i->keytype, AR_EncrType);
35395 if (!i->is_first) {
35396- ACCESS_ONCE(ads->ctl11) = 0;
35397- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35398- ACCESS_ONCE(ads->ctl15) = 0;
35399- ACCESS_ONCE(ads->ctl16) = 0;
35400- ACCESS_ONCE(ads->ctl17) = ctl17;
35401- ACCESS_ONCE(ads->ctl18) = 0;
35402- ACCESS_ONCE(ads->ctl19) = 0;
35403+ ACCESS_ONCE_RW(ads->ctl11) = 0;
35404+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35405+ ACCESS_ONCE_RW(ads->ctl15) = 0;
35406+ ACCESS_ONCE_RW(ads->ctl16) = 0;
35407+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35408+ ACCESS_ONCE_RW(ads->ctl18) = 0;
35409+ ACCESS_ONCE_RW(ads->ctl19) = 0;
35410 return;
35411 }
35412
35413- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35414+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35415 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35416 | SM(i->txpower, AR_XmitPower)
35417 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35418@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35419 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35420 ctl12 |= SM(val, AR_PAPRDChainMask);
35421
35422- ACCESS_ONCE(ads->ctl12) = ctl12;
35423- ACCESS_ONCE(ads->ctl17) = ctl17;
35424+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35425+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35426
35427- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35428+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35429 | set11nPktDurRTSCTS(i->rates, 1);
35430
35431- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35432+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35433 | set11nPktDurRTSCTS(i->rates, 3);
35434
35435- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35436+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35437 | set11nRateFlags(i->rates, 1)
35438 | set11nRateFlags(i->rates, 2)
35439 | set11nRateFlags(i->rates, 3)
35440 | SM(i->rtscts_rate, AR_RTSCTSRate);
35441
35442- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35443+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35444 }
35445
35446 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35447diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35448index e88f182..4e57f5d 100644
35449--- a/drivers/net/wireless/ath/ath9k/hw.h
35450+++ b/drivers/net/wireless/ath/ath9k/hw.h
35451@@ -614,7 +614,7 @@ struct ath_hw_private_ops {
35452
35453 /* ANI */
35454 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35455-};
35456+} __no_const;
35457
35458 /**
35459 * struct ath_hw_ops - callbacks used by hardware code and driver code
35460@@ -644,7 +644,7 @@ struct ath_hw_ops {
35461 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35462 struct ath_hw_antcomb_conf *antconf);
35463
35464-};
35465+} __no_const;
35466
35467 struct ath_nf_limits {
35468 s16 max;
35469@@ -664,7 +664,7 @@ enum ath_cal_list {
35470 #define AH_FASTCC 0x4
35471
35472 struct ath_hw {
35473- struct ath_ops reg_ops;
35474+ ath_ops_no_const reg_ops;
35475
35476 struct ieee80211_hw *hw;
35477 struct ath_common common;
35478diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35479index af00e2c..ab04d34 100644
35480--- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35481+++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35482@@ -545,7 +545,7 @@ struct phy_func_ptr {
35483 void (*carrsuppr)(struct brcms_phy *);
35484 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35485 void (*detach)(struct brcms_phy *);
35486-};
35487+} __no_const;
35488
35489 struct brcms_phy {
35490 struct brcms_phy_pub pubpi_ro;
35491diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35492index faec404..a5277f1 100644
35493--- a/drivers/net/wireless/iwlegacy/3945-mac.c
35494+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35495@@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35496 */
35497 if (il3945_mod_params.disable_hw_scan) {
35498 D_INFO("Disabling hw_scan\n");
35499- il3945_mac_ops.hw_scan = NULL;
35500+ pax_open_kernel();
35501+ *(void **)&il3945_mac_ops.hw_scan = NULL;
35502+ pax_close_kernel();
35503 }
35504
35505 D_INFO("*** LOAD DRIVER ***\n");
35506diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35507index b7ce6a6..5649756 100644
35508--- a/drivers/net/wireless/mac80211_hwsim.c
35509+++ b/drivers/net/wireless/mac80211_hwsim.c
35510@@ -1721,9 +1721,11 @@ static int __init init_mac80211_hwsim(void)
35511 return -EINVAL;
35512
35513 if (fake_hw_scan) {
35514- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35515- mac80211_hwsim_ops.sw_scan_start = NULL;
35516- mac80211_hwsim_ops.sw_scan_complete = NULL;
35517+ pax_open_kernel();
35518+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35519+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35520+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35521+ pax_close_kernel();
35522 }
35523
35524 spin_lock_init(&hwsim_radio_lock);
35525diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35526index 35225e9..95e6bf9 100644
35527--- a/drivers/net/wireless/mwifiex/main.h
35528+++ b/drivers/net/wireless/mwifiex/main.h
35529@@ -537,7 +537,7 @@ struct mwifiex_if_ops {
35530 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
35531 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
35532 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35533-};
35534+} __no_const;
35535
35536 struct mwifiex_adapter {
35537 u8 iface_type;
35538diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35539index d66e298..55b0a89 100644
35540--- a/drivers/net/wireless/rndis_wlan.c
35541+++ b/drivers/net/wireless/rndis_wlan.c
35542@@ -1278,7 +1278,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35543
35544 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35545
35546- if (rts_threshold < 0 || rts_threshold > 2347)
35547+ if (rts_threshold > 2347)
35548 rts_threshold = 2347;
35549
35550 tmp = cpu_to_le32(rts_threshold);
35551diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35552index c264dfa..08ee30e 100644
35553--- a/drivers/net/wireless/rt2x00/rt2x00.h
35554+++ b/drivers/net/wireless/rt2x00/rt2x00.h
35555@@ -396,7 +396,7 @@ struct rt2x00_intf {
35556 * for hardware which doesn't support hardware
35557 * sequence counting.
35558 */
35559- atomic_t seqno;
35560+ atomic_unchecked_t seqno;
35561 };
35562
35563 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35564diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35565index 50f92d5..f3afc41 100644
35566--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35567+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35568@@ -229,9 +229,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35569 * sequence counter given by mac80211.
35570 */
35571 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35572- seqno = atomic_add_return(0x10, &intf->seqno);
35573+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35574 else
35575- seqno = atomic_read(&intf->seqno);
35576+ seqno = atomic_read_unchecked(&intf->seqno);
35577
35578 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
35579 hdr->seq_ctrl |= cpu_to_le16(seqno);
35580diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
35581index 9d8f581..0f6589e 100644
35582--- a/drivers/net/wireless/wl1251/wl1251.h
35583+++ b/drivers/net/wireless/wl1251/wl1251.h
35584@@ -266,7 +266,7 @@ struct wl1251_if_operations {
35585 void (*reset)(struct wl1251 *wl);
35586 void (*enable_irq)(struct wl1251 *wl);
35587 void (*disable_irq)(struct wl1251 *wl);
35588-};
35589+} __no_const;
35590
35591 struct wl1251 {
35592 struct ieee80211_hw *hw;
35593diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35594index f34b5b2..b5abb9f 100644
35595--- a/drivers/oprofile/buffer_sync.c
35596+++ b/drivers/oprofile/buffer_sync.c
35597@@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35598 if (cookie == NO_COOKIE)
35599 offset = pc;
35600 if (cookie == INVALID_COOKIE) {
35601- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35602+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35603 offset = pc;
35604 }
35605 if (cookie != last_cookie) {
35606@@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35607 /* add userspace sample */
35608
35609 if (!mm) {
35610- atomic_inc(&oprofile_stats.sample_lost_no_mm);
35611+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35612 return 0;
35613 }
35614
35615 cookie = lookup_dcookie(mm, s->eip, &offset);
35616
35617 if (cookie == INVALID_COOKIE) {
35618- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35619+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35620 return 0;
35621 }
35622
35623@@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35624 /* ignore backtraces if failed to add a sample */
35625 if (state == sb_bt_start) {
35626 state = sb_bt_ignore;
35627- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35628+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35629 }
35630 }
35631 release_mm(mm);
35632diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35633index c0cc4e7..44d4e54 100644
35634--- a/drivers/oprofile/event_buffer.c
35635+++ b/drivers/oprofile/event_buffer.c
35636@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35637 }
35638
35639 if (buffer_pos == buffer_size) {
35640- atomic_inc(&oprofile_stats.event_lost_overflow);
35641+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35642 return;
35643 }
35644
35645diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35646index ed2c3ec..deda85a 100644
35647--- a/drivers/oprofile/oprof.c
35648+++ b/drivers/oprofile/oprof.c
35649@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35650 if (oprofile_ops.switch_events())
35651 return;
35652
35653- atomic_inc(&oprofile_stats.multiplex_counter);
35654+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35655 start_switch_worker();
35656 }
35657
35658diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35659index 917d28e..d62d981 100644
35660--- a/drivers/oprofile/oprofile_stats.c
35661+++ b/drivers/oprofile/oprofile_stats.c
35662@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35663 cpu_buf->sample_invalid_eip = 0;
35664 }
35665
35666- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35667- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35668- atomic_set(&oprofile_stats.event_lost_overflow, 0);
35669- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35670- atomic_set(&oprofile_stats.multiplex_counter, 0);
35671+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35672+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35673+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35674+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35675+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35676 }
35677
35678
35679diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35680index 38b6fc0..b5cbfce 100644
35681--- a/drivers/oprofile/oprofile_stats.h
35682+++ b/drivers/oprofile/oprofile_stats.h
35683@@ -13,11 +13,11 @@
35684 #include <linux/atomic.h>
35685
35686 struct oprofile_stat_struct {
35687- atomic_t sample_lost_no_mm;
35688- atomic_t sample_lost_no_mapping;
35689- atomic_t bt_lost_no_mapping;
35690- atomic_t event_lost_overflow;
35691- atomic_t multiplex_counter;
35692+ atomic_unchecked_t sample_lost_no_mm;
35693+ atomic_unchecked_t sample_lost_no_mapping;
35694+ atomic_unchecked_t bt_lost_no_mapping;
35695+ atomic_unchecked_t event_lost_overflow;
35696+ atomic_unchecked_t multiplex_counter;
35697 };
35698
35699 extern struct oprofile_stat_struct oprofile_stats;
35700diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35701index 849357c..b83c1e0 100644
35702--- a/drivers/oprofile/oprofilefs.c
35703+++ b/drivers/oprofile/oprofilefs.c
35704@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
35705
35706
35707 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35708- char const *name, atomic_t *val)
35709+ char const *name, atomic_unchecked_t *val)
35710 {
35711 return __oprofilefs_create_file(sb, root, name,
35712 &atomic_ro_fops, 0444, val);
35713diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
35714index 3f56bc0..707d642 100644
35715--- a/drivers/parport/procfs.c
35716+++ b/drivers/parport/procfs.c
35717@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
35718
35719 *ppos += len;
35720
35721- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
35722+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
35723 }
35724
35725 #ifdef CONFIG_PARPORT_1284
35726@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
35727
35728 *ppos += len;
35729
35730- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
35731+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
35732 }
35733 #endif /* IEEE1284.3 support. */
35734
35735diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
35736index 9fff878..ad0ad53 100644
35737--- a/drivers/pci/hotplug/cpci_hotplug.h
35738+++ b/drivers/pci/hotplug/cpci_hotplug.h
35739@@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
35740 int (*hardware_test) (struct slot* slot, u32 value);
35741 u8 (*get_power) (struct slot* slot);
35742 int (*set_power) (struct slot* slot, int value);
35743-};
35744+} __no_const;
35745
35746 struct cpci_hp_controller {
35747 unsigned int irq;
35748diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
35749index 76ba8a1..20ca857 100644
35750--- a/drivers/pci/hotplug/cpqphp_nvram.c
35751+++ b/drivers/pci/hotplug/cpqphp_nvram.c
35752@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
35753
35754 void compaq_nvram_init (void __iomem *rom_start)
35755 {
35756+
35757+#ifndef CONFIG_PAX_KERNEXEC
35758 if (rom_start) {
35759 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
35760 }
35761+#endif
35762+
35763 dbg("int15 entry = %p\n", compaq_int15_entry_point);
35764
35765 /* initialize our int15 lock */
35766diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
35767index b500840..d7159d3 100644
35768--- a/drivers/pci/pcie/aspm.c
35769+++ b/drivers/pci/pcie/aspm.c
35770@@ -27,9 +27,9 @@
35771 #define MODULE_PARAM_PREFIX "pcie_aspm."
35772
35773 /* Note: those are not register definitions */
35774-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
35775-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
35776-#define ASPM_STATE_L1 (4) /* L1 state */
35777+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
35778+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
35779+#define ASPM_STATE_L1 (4U) /* L1 state */
35780 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
35781 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
35782
35783diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
35784index 5e1ca3c..08082fe 100644
35785--- a/drivers/pci/probe.c
35786+++ b/drivers/pci/probe.c
35787@@ -215,7 +215,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
35788 u16 orig_cmd;
35789 struct pci_bus_region region;
35790
35791- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
35792+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
35793
35794 if (!dev->mmio_always_on) {
35795 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
35796diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
35797index 27911b5..5b6db88 100644
35798--- a/drivers/pci/proc.c
35799+++ b/drivers/pci/proc.c
35800@@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
35801 static int __init pci_proc_init(void)
35802 {
35803 struct pci_dev *dev = NULL;
35804+
35805+#ifdef CONFIG_GRKERNSEC_PROC_ADD
35806+#ifdef CONFIG_GRKERNSEC_PROC_USER
35807+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
35808+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
35809+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
35810+#endif
35811+#else
35812 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
35813+#endif
35814 proc_create("devices", 0, proc_bus_pci_dir,
35815 &proc_bus_pci_dev_operations);
35816 proc_initialized = 1;
35817diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
35818index d68c000..f6094ca 100644
35819--- a/drivers/platform/x86/thinkpad_acpi.c
35820+++ b/drivers/platform/x86/thinkpad_acpi.c
35821@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
35822 return 0;
35823 }
35824
35825-void static hotkey_mask_warn_incomplete_mask(void)
35826+static void hotkey_mask_warn_incomplete_mask(void)
35827 {
35828 /* log only what the user can fix... */
35829 const u32 wantedmask = hotkey_driver_mask &
35830@@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
35831 }
35832 }
35833
35834-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35835- struct tp_nvram_state *newn,
35836- const u32 event_mask)
35837-{
35838-
35839 #define TPACPI_COMPARE_KEY(__scancode, __member) \
35840 do { \
35841 if ((event_mask & (1 << __scancode)) && \
35842@@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35843 tpacpi_hotkey_send_key(__scancode); \
35844 } while (0)
35845
35846- void issue_volchange(const unsigned int oldvol,
35847- const unsigned int newvol)
35848- {
35849- unsigned int i = oldvol;
35850+static void issue_volchange(const unsigned int oldvol,
35851+ const unsigned int newvol,
35852+ const u32 event_mask)
35853+{
35854+ unsigned int i = oldvol;
35855
35856- while (i > newvol) {
35857- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35858- i--;
35859- }
35860- while (i < newvol) {
35861- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35862- i++;
35863- }
35864+ while (i > newvol) {
35865+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35866+ i--;
35867 }
35868+ while (i < newvol) {
35869+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35870+ i++;
35871+ }
35872+}
35873
35874- void issue_brightnesschange(const unsigned int oldbrt,
35875- const unsigned int newbrt)
35876- {
35877- unsigned int i = oldbrt;
35878+static void issue_brightnesschange(const unsigned int oldbrt,
35879+ const unsigned int newbrt,
35880+ const u32 event_mask)
35881+{
35882+ unsigned int i = oldbrt;
35883
35884- while (i > newbrt) {
35885- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35886- i--;
35887- }
35888- while (i < newbrt) {
35889- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35890- i++;
35891- }
35892+ while (i > newbrt) {
35893+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35894+ i--;
35895+ }
35896+ while (i < newbrt) {
35897+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35898+ i++;
35899 }
35900+}
35901
35902+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35903+ struct tp_nvram_state *newn,
35904+ const u32 event_mask)
35905+{
35906 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
35907 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
35908 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
35909@@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35910 oldn->volume_level != newn->volume_level) {
35911 /* recently muted, or repeated mute keypress, or
35912 * multiple presses ending in mute */
35913- issue_volchange(oldn->volume_level, newn->volume_level);
35914+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35915 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
35916 }
35917 } else {
35918@@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35919 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35920 }
35921 if (oldn->volume_level != newn->volume_level) {
35922- issue_volchange(oldn->volume_level, newn->volume_level);
35923+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35924 } else if (oldn->volume_toggle != newn->volume_toggle) {
35925 /* repeated vol up/down keypress at end of scale ? */
35926 if (newn->volume_level == 0)
35927@@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35928 /* handle brightness */
35929 if (oldn->brightness_level != newn->brightness_level) {
35930 issue_brightnesschange(oldn->brightness_level,
35931- newn->brightness_level);
35932+ newn->brightness_level,
35933+ event_mask);
35934 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
35935 /* repeated key presses that didn't change state */
35936 if (newn->brightness_level == 0)
35937@@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35938 && !tp_features.bright_unkfw)
35939 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35940 }
35941+}
35942
35943 #undef TPACPI_COMPARE_KEY
35944 #undef TPACPI_MAY_SEND_KEY
35945-}
35946
35947 /*
35948 * Polling driver
35949diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
35950index 769d265..a3a05ca 100644
35951--- a/drivers/pnp/pnpbios/bioscalls.c
35952+++ b/drivers/pnp/pnpbios/bioscalls.c
35953@@ -58,7 +58,7 @@ do { \
35954 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
35955 } while(0)
35956
35957-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
35958+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
35959 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
35960
35961 /*
35962@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35963
35964 cpu = get_cpu();
35965 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
35966+
35967+ pax_open_kernel();
35968 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
35969+ pax_close_kernel();
35970
35971 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
35972 spin_lock_irqsave(&pnp_bios_lock, flags);
35973@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35974 :"memory");
35975 spin_unlock_irqrestore(&pnp_bios_lock, flags);
35976
35977+ pax_open_kernel();
35978 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
35979+ pax_close_kernel();
35980+
35981 put_cpu();
35982
35983 /* If we get here and this is set then the PnP BIOS faulted on us. */
35984@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
35985 return status;
35986 }
35987
35988-void pnpbios_calls_init(union pnp_bios_install_struct *header)
35989+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
35990 {
35991 int i;
35992
35993@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35994 pnp_bios_callpoint.offset = header->fields.pm16offset;
35995 pnp_bios_callpoint.segment = PNP_CS16;
35996
35997+ pax_open_kernel();
35998+
35999 for_each_possible_cpu(i) {
36000 struct desc_struct *gdt = get_cpu_gdt_table(i);
36001 if (!gdt)
36002@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36003 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36004 (unsigned long)__va(header->fields.pm16dseg));
36005 }
36006+
36007+ pax_close_kernel();
36008 }
36009diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36010index b0ecacb..7c9da2e 100644
36011--- a/drivers/pnp/resource.c
36012+++ b/drivers/pnp/resource.c
36013@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36014 return 1;
36015
36016 /* check if the resource is valid */
36017- if (*irq < 0 || *irq > 15)
36018+ if (*irq > 15)
36019 return 0;
36020
36021 /* check if the resource is reserved */
36022@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36023 return 1;
36024
36025 /* check if the resource is valid */
36026- if (*dma < 0 || *dma == 4 || *dma > 7)
36027+ if (*dma == 4 || *dma > 7)
36028 return 0;
36029
36030 /* check if the resource is reserved */
36031diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36032index 222ccd8..6275fa5 100644
36033--- a/drivers/power/bq27x00_battery.c
36034+++ b/drivers/power/bq27x00_battery.c
36035@@ -72,7 +72,7 @@
36036 struct bq27x00_device_info;
36037 struct bq27x00_access_methods {
36038 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36039-};
36040+} __no_const;
36041
36042 enum bq27x00_chip { BQ27000, BQ27500 };
36043
36044diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36045index 4c5b053..104263e 100644
36046--- a/drivers/regulator/max8660.c
36047+++ b/drivers/regulator/max8660.c
36048@@ -385,8 +385,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36049 max8660->shadow_regs[MAX8660_OVER1] = 5;
36050 } else {
36051 /* Otherwise devices can be toggled via software */
36052- max8660_dcdc_ops.enable = max8660_dcdc_enable;
36053- max8660_dcdc_ops.disable = max8660_dcdc_disable;
36054+ pax_open_kernel();
36055+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36056+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36057+ pax_close_kernel();
36058 }
36059
36060 /*
36061diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36062index 845aa22..99ec402 100644
36063--- a/drivers/regulator/mc13892-regulator.c
36064+++ b/drivers/regulator/mc13892-regulator.c
36065@@ -574,10 +574,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36066 }
36067 mc13xxx_unlock(mc13892);
36068
36069- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36070+ pax_open_kernel();
36071+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36072 = mc13892_vcam_set_mode;
36073- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36074+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36075 = mc13892_vcam_get_mode;
36076+ pax_close_kernel();
36077
36078 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36079 ARRAY_SIZE(mc13892_regulators));
36080diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36081index cace6d3..f623fda 100644
36082--- a/drivers/rtc/rtc-dev.c
36083+++ b/drivers/rtc/rtc-dev.c
36084@@ -14,6 +14,7 @@
36085 #include <linux/module.h>
36086 #include <linux/rtc.h>
36087 #include <linux/sched.h>
36088+#include <linux/grsecurity.h>
36089 #include "rtc-core.h"
36090
36091 static dev_t rtc_devt;
36092@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36093 if (copy_from_user(&tm, uarg, sizeof(tm)))
36094 return -EFAULT;
36095
36096+ gr_log_timechange();
36097+
36098 return rtc_set_time(rtc, &tm);
36099
36100 case RTC_PIE_ON:
36101diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36102index 3fcf627..f334910 100644
36103--- a/drivers/scsi/aacraid/aacraid.h
36104+++ b/drivers/scsi/aacraid/aacraid.h
36105@@ -492,7 +492,7 @@ struct adapter_ops
36106 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36107 /* Administrative operations */
36108 int (*adapter_comm)(struct aac_dev * dev, int comm);
36109-};
36110+} __no_const;
36111
36112 /*
36113 * Define which interrupt handler needs to be installed
36114diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36115index 0d279c44..3d25a97 100644
36116--- a/drivers/scsi/aacraid/linit.c
36117+++ b/drivers/scsi/aacraid/linit.c
36118@@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36119 #elif defined(__devinitconst)
36120 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36121 #else
36122-static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36123+static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36124 #endif
36125 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36126 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36127diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36128index ff80552..1c4120c 100644
36129--- a/drivers/scsi/aic94xx/aic94xx_init.c
36130+++ b/drivers/scsi/aic94xx/aic94xx_init.c
36131@@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36132 .lldd_ata_set_dmamode = asd_set_dmamode,
36133 };
36134
36135-static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36136+static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36137 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36138 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36139 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36140diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36141index 4ad7e36..d004679 100644
36142--- a/drivers/scsi/bfa/bfa.h
36143+++ b/drivers/scsi/bfa/bfa.h
36144@@ -196,7 +196,7 @@ struct bfa_hwif_s {
36145 u32 *end);
36146 int cpe_vec_q0;
36147 int rme_vec_q0;
36148-};
36149+} __no_const;
36150 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36151
36152 struct bfa_faa_cbfn_s {
36153diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36154index f0f80e2..8ec946b 100644
36155--- a/drivers/scsi/bfa/bfa_fcpim.c
36156+++ b/drivers/scsi/bfa/bfa_fcpim.c
36157@@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36158
36159 bfa_iotag_attach(fcp);
36160
36161- fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36162+ fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36163 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36164 (fcp->num_itns * sizeof(struct bfa_itn_s));
36165 memset(fcp->itn_arr, 0,
36166@@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36167 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36168 {
36169 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36170- struct bfa_itn_s *itn;
36171+ bfa_itn_s_no_const *itn;
36172
36173 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36174 itn->isr = isr;
36175diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36176index 36f26da..38a34a8 100644
36177--- a/drivers/scsi/bfa/bfa_fcpim.h
36178+++ b/drivers/scsi/bfa/bfa_fcpim.h
36179@@ -37,6 +37,7 @@ struct bfa_iotag_s {
36180 struct bfa_itn_s {
36181 bfa_isr_func_t isr;
36182 };
36183+typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36184
36185 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36186 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36187@@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36188 struct list_head iotag_tio_free_q; /* free IO resources */
36189 struct list_head iotag_unused_q; /* unused IO resources*/
36190 struct bfa_iotag_s *iotag_arr;
36191- struct bfa_itn_s *itn_arr;
36192+ bfa_itn_s_no_const *itn_arr;
36193 int num_ioim_reqs;
36194 int num_fwtio_reqs;
36195 int num_itns;
36196diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36197index 1a99d4b..e85d64b 100644
36198--- a/drivers/scsi/bfa/bfa_ioc.h
36199+++ b/drivers/scsi/bfa/bfa_ioc.h
36200@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36201 bfa_ioc_disable_cbfn_t disable_cbfn;
36202 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36203 bfa_ioc_reset_cbfn_t reset_cbfn;
36204-};
36205+} __no_const;
36206
36207 /*
36208 * IOC event notification mechanism.
36209@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36210 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36211 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36212 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36213-};
36214+} __no_const;
36215
36216 /*
36217 * Queue element to wait for room in request queue. FIFO order is
36218diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36219index a3a056a..b9bbc2f 100644
36220--- a/drivers/scsi/hosts.c
36221+++ b/drivers/scsi/hosts.c
36222@@ -42,7 +42,7 @@
36223 #include "scsi_logging.h"
36224
36225
36226-static atomic_t scsi_host_next_hn; /* host_no for next new host */
36227+static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36228
36229
36230 static void scsi_host_cls_release(struct device *dev)
36231@@ -360,7 +360,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36232 * subtract one because we increment first then return, but we need to
36233 * know what the next host number was before increment
36234 */
36235- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36236+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36237 shost->dma_channel = 0xff;
36238
36239 /* These three are default values which can be overridden */
36240diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36241index 500e20d..ebd3059 100644
36242--- a/drivers/scsi/hpsa.c
36243+++ b/drivers/scsi/hpsa.c
36244@@ -521,7 +521,7 @@ static inline u32 next_command(struct ctlr_info *h)
36245 u32 a;
36246
36247 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36248- return h->access.command_completed(h);
36249+ return h->access->command_completed(h);
36250
36251 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36252 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36253@@ -3002,7 +3002,7 @@ static void start_io(struct ctlr_info *h)
36254 while (!list_empty(&h->reqQ)) {
36255 c = list_entry(h->reqQ.next, struct CommandList, list);
36256 /* can't do anything if fifo is full */
36257- if ((h->access.fifo_full(h))) {
36258+ if ((h->access->fifo_full(h))) {
36259 dev_warn(&h->pdev->dev, "fifo full\n");
36260 break;
36261 }
36262@@ -3012,7 +3012,7 @@ static void start_io(struct ctlr_info *h)
36263 h->Qdepth--;
36264
36265 /* Tell the controller execute command */
36266- h->access.submit_command(h, c);
36267+ h->access->submit_command(h, c);
36268
36269 /* Put job onto the completed Q */
36270 addQ(&h->cmpQ, c);
36271@@ -3021,17 +3021,17 @@ static void start_io(struct ctlr_info *h)
36272
36273 static inline unsigned long get_next_completion(struct ctlr_info *h)
36274 {
36275- return h->access.command_completed(h);
36276+ return h->access->command_completed(h);
36277 }
36278
36279 static inline bool interrupt_pending(struct ctlr_info *h)
36280 {
36281- return h->access.intr_pending(h);
36282+ return h->access->intr_pending(h);
36283 }
36284
36285 static inline long interrupt_not_for_us(struct ctlr_info *h)
36286 {
36287- return (h->access.intr_pending(h) == 0) ||
36288+ return (h->access->intr_pending(h) == 0) ||
36289 (h->interrupts_enabled == 0);
36290 }
36291
36292@@ -3930,7 +3930,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36293 if (prod_index < 0)
36294 return -ENODEV;
36295 h->product_name = products[prod_index].product_name;
36296- h->access = *(products[prod_index].access);
36297+ h->access = products[prod_index].access;
36298
36299 if (hpsa_board_disabled(h->pdev)) {
36300 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36301@@ -4175,7 +4175,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36302
36303 assert_spin_locked(&lockup_detector_lock);
36304 remove_ctlr_from_lockup_detector_list(h);
36305- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36306+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36307 spin_lock_irqsave(&h->lock, flags);
36308 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36309 spin_unlock_irqrestore(&h->lock, flags);
36310@@ -4355,7 +4355,7 @@ reinit_after_soft_reset:
36311 }
36312
36313 /* make sure the board interrupts are off */
36314- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36315+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36316
36317 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36318 goto clean2;
36319@@ -4389,7 +4389,7 @@ reinit_after_soft_reset:
36320 * fake ones to scoop up any residual completions.
36321 */
36322 spin_lock_irqsave(&h->lock, flags);
36323- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36324+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36325 spin_unlock_irqrestore(&h->lock, flags);
36326 free_irq(h->intr[h->intr_mode], h);
36327 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36328@@ -4408,9 +4408,9 @@ reinit_after_soft_reset:
36329 dev_info(&h->pdev->dev, "Board READY.\n");
36330 dev_info(&h->pdev->dev,
36331 "Waiting for stale completions to drain.\n");
36332- h->access.set_intr_mask(h, HPSA_INTR_ON);
36333+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36334 msleep(10000);
36335- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36336+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36337
36338 rc = controller_reset_failed(h->cfgtable);
36339 if (rc)
36340@@ -4431,7 +4431,7 @@ reinit_after_soft_reset:
36341 }
36342
36343 /* Turn the interrupts on so we can service requests */
36344- h->access.set_intr_mask(h, HPSA_INTR_ON);
36345+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36346
36347 hpsa_hba_inquiry(h);
36348 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36349@@ -4483,7 +4483,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36350 * To write all data in the battery backed cache to disks
36351 */
36352 hpsa_flush_cache(h);
36353- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36354+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36355 free_irq(h->intr[h->intr_mode], h);
36356 #ifdef CONFIG_PCI_MSI
36357 if (h->msix_vector)
36358@@ -4657,7 +4657,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36359 return;
36360 }
36361 /* Change the access methods to the performant access methods */
36362- h->access = SA5_performant_access;
36363+ h->access = &SA5_performant_access;
36364 h->transMethod = CFGTBL_Trans_Performant;
36365 }
36366
36367diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36368index 7b28d54..952f23a 100644
36369--- a/drivers/scsi/hpsa.h
36370+++ b/drivers/scsi/hpsa.h
36371@@ -72,7 +72,7 @@ struct ctlr_info {
36372 unsigned int msix_vector;
36373 unsigned int msi_vector;
36374 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36375- struct access_method access;
36376+ struct access_method *access;
36377
36378 /* queue and queue Info */
36379 struct list_head reqQ;
36380diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36381index f2df059..a3a9930 100644
36382--- a/drivers/scsi/ips.h
36383+++ b/drivers/scsi/ips.h
36384@@ -1027,7 +1027,7 @@ typedef struct {
36385 int (*intr)(struct ips_ha *);
36386 void (*enableint)(struct ips_ha *);
36387 uint32_t (*statupd)(struct ips_ha *);
36388-} ips_hw_func_t;
36389+} __no_const ips_hw_func_t;
36390
36391 typedef struct ips_ha {
36392 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36393diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36394index aceffad..c35c08d 100644
36395--- a/drivers/scsi/libfc/fc_exch.c
36396+++ b/drivers/scsi/libfc/fc_exch.c
36397@@ -105,12 +105,12 @@ struct fc_exch_mgr {
36398 * all together if not used XXX
36399 */
36400 struct {
36401- atomic_t no_free_exch;
36402- atomic_t no_free_exch_xid;
36403- atomic_t xid_not_found;
36404- atomic_t xid_busy;
36405- atomic_t seq_not_found;
36406- atomic_t non_bls_resp;
36407+ atomic_unchecked_t no_free_exch;
36408+ atomic_unchecked_t no_free_exch_xid;
36409+ atomic_unchecked_t xid_not_found;
36410+ atomic_unchecked_t xid_busy;
36411+ atomic_unchecked_t seq_not_found;
36412+ atomic_unchecked_t non_bls_resp;
36413 } stats;
36414 };
36415
36416@@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36417 /* allocate memory for exchange */
36418 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36419 if (!ep) {
36420- atomic_inc(&mp->stats.no_free_exch);
36421+ atomic_inc_unchecked(&mp->stats.no_free_exch);
36422 goto out;
36423 }
36424 memset(ep, 0, sizeof(*ep));
36425@@ -780,7 +780,7 @@ out:
36426 return ep;
36427 err:
36428 spin_unlock_bh(&pool->lock);
36429- atomic_inc(&mp->stats.no_free_exch_xid);
36430+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36431 mempool_free(ep, mp->ep_pool);
36432 return NULL;
36433 }
36434@@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36435 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36436 ep = fc_exch_find(mp, xid);
36437 if (!ep) {
36438- atomic_inc(&mp->stats.xid_not_found);
36439+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36440 reject = FC_RJT_OX_ID;
36441 goto out;
36442 }
36443@@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36444 ep = fc_exch_find(mp, xid);
36445 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36446 if (ep) {
36447- atomic_inc(&mp->stats.xid_busy);
36448+ atomic_inc_unchecked(&mp->stats.xid_busy);
36449 reject = FC_RJT_RX_ID;
36450 goto rel;
36451 }
36452@@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36453 }
36454 xid = ep->xid; /* get our XID */
36455 } else if (!ep) {
36456- atomic_inc(&mp->stats.xid_not_found);
36457+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36458 reject = FC_RJT_RX_ID; /* XID not found */
36459 goto out;
36460 }
36461@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36462 } else {
36463 sp = &ep->seq;
36464 if (sp->id != fh->fh_seq_id) {
36465- atomic_inc(&mp->stats.seq_not_found);
36466+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36467 if (f_ctl & FC_FC_END_SEQ) {
36468 /*
36469 * Update sequence_id based on incoming last
36470@@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36471
36472 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36473 if (!ep) {
36474- atomic_inc(&mp->stats.xid_not_found);
36475+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36476 goto out;
36477 }
36478 if (ep->esb_stat & ESB_ST_COMPLETE) {
36479- atomic_inc(&mp->stats.xid_not_found);
36480+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36481 goto rel;
36482 }
36483 if (ep->rxid == FC_XID_UNKNOWN)
36484 ep->rxid = ntohs(fh->fh_rx_id);
36485 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36486- atomic_inc(&mp->stats.xid_not_found);
36487+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36488 goto rel;
36489 }
36490 if (ep->did != ntoh24(fh->fh_s_id) &&
36491 ep->did != FC_FID_FLOGI) {
36492- atomic_inc(&mp->stats.xid_not_found);
36493+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36494 goto rel;
36495 }
36496 sof = fr_sof(fp);
36497@@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36498 sp->ssb_stat |= SSB_ST_RESP;
36499 sp->id = fh->fh_seq_id;
36500 } else if (sp->id != fh->fh_seq_id) {
36501- atomic_inc(&mp->stats.seq_not_found);
36502+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36503 goto rel;
36504 }
36505
36506@@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36507 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36508
36509 if (!sp)
36510- atomic_inc(&mp->stats.xid_not_found);
36511+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36512 else
36513- atomic_inc(&mp->stats.non_bls_resp);
36514+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
36515
36516 fc_frame_free(fp);
36517 }
36518diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36519index 441d88a..689ad71 100644
36520--- a/drivers/scsi/libsas/sas_ata.c
36521+++ b/drivers/scsi/libsas/sas_ata.c
36522@@ -529,7 +529,7 @@ static struct ata_port_operations sas_sata_ops = {
36523 .postreset = ata_std_postreset,
36524 .error_handler = ata_std_error_handler,
36525 .post_internal_cmd = sas_ata_post_internal,
36526- .qc_defer = ata_std_qc_defer,
36527+ .qc_defer = ata_std_qc_defer,
36528 .qc_prep = ata_noop_qc_prep,
36529 .qc_issue = sas_ata_qc_issue,
36530 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36531diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36532index 3a1ffdd..8eb7c71 100644
36533--- a/drivers/scsi/lpfc/lpfc.h
36534+++ b/drivers/scsi/lpfc/lpfc.h
36535@@ -413,7 +413,7 @@ struct lpfc_vport {
36536 struct dentry *debug_nodelist;
36537 struct dentry *vport_debugfs_root;
36538 struct lpfc_debugfs_trc *disc_trc;
36539- atomic_t disc_trc_cnt;
36540+ atomic_unchecked_t disc_trc_cnt;
36541 #endif
36542 uint8_t stat_data_enabled;
36543 uint8_t stat_data_blocked;
36544@@ -826,8 +826,8 @@ struct lpfc_hba {
36545 struct timer_list fabric_block_timer;
36546 unsigned long bit_flags;
36547 #define FABRIC_COMANDS_BLOCKED 0
36548- atomic_t num_rsrc_err;
36549- atomic_t num_cmd_success;
36550+ atomic_unchecked_t num_rsrc_err;
36551+ atomic_unchecked_t num_cmd_success;
36552 unsigned long last_rsrc_error_time;
36553 unsigned long last_ramp_down_time;
36554 unsigned long last_ramp_up_time;
36555@@ -863,7 +863,7 @@ struct lpfc_hba {
36556
36557 struct dentry *debug_slow_ring_trc;
36558 struct lpfc_debugfs_trc *slow_ring_trc;
36559- atomic_t slow_ring_trc_cnt;
36560+ atomic_unchecked_t slow_ring_trc_cnt;
36561 /* iDiag debugfs sub-directory */
36562 struct dentry *idiag_root;
36563 struct dentry *idiag_pci_cfg;
36564diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36565index af04b0d..8f1a97e 100644
36566--- a/drivers/scsi/lpfc/lpfc_debugfs.c
36567+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36568@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36569
36570 #include <linux/debugfs.h>
36571
36572-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36573+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36574 static unsigned long lpfc_debugfs_start_time = 0L;
36575
36576 /* iDiag */
36577@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36578 lpfc_debugfs_enable = 0;
36579
36580 len = 0;
36581- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36582+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36583 (lpfc_debugfs_max_disc_trc - 1);
36584 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36585 dtp = vport->disc_trc + i;
36586@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36587 lpfc_debugfs_enable = 0;
36588
36589 len = 0;
36590- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36591+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36592 (lpfc_debugfs_max_slow_ring_trc - 1);
36593 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36594 dtp = phba->slow_ring_trc + i;
36595@@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36596 !vport || !vport->disc_trc)
36597 return;
36598
36599- index = atomic_inc_return(&vport->disc_trc_cnt) &
36600+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36601 (lpfc_debugfs_max_disc_trc - 1);
36602 dtp = vport->disc_trc + index;
36603 dtp->fmt = fmt;
36604 dtp->data1 = data1;
36605 dtp->data2 = data2;
36606 dtp->data3 = data3;
36607- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36608+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36609 dtp->jif = jiffies;
36610 #endif
36611 return;
36612@@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36613 !phba || !phba->slow_ring_trc)
36614 return;
36615
36616- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36617+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36618 (lpfc_debugfs_max_slow_ring_trc - 1);
36619 dtp = phba->slow_ring_trc + index;
36620 dtp->fmt = fmt;
36621 dtp->data1 = data1;
36622 dtp->data2 = data2;
36623 dtp->data3 = data3;
36624- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36625+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36626 dtp->jif = jiffies;
36627 #endif
36628 return;
36629@@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36630 "slow_ring buffer\n");
36631 goto debug_failed;
36632 }
36633- atomic_set(&phba->slow_ring_trc_cnt, 0);
36634+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36635 memset(phba->slow_ring_trc, 0,
36636 (sizeof(struct lpfc_debugfs_trc) *
36637 lpfc_debugfs_max_slow_ring_trc));
36638@@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36639 "buffer\n");
36640 goto debug_failed;
36641 }
36642- atomic_set(&vport->disc_trc_cnt, 0);
36643+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36644
36645 snprintf(name, sizeof(name), "discovery_trace");
36646 vport->debug_disc_trc =
36647diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36648index 9598fdc..7e9f3d9 100644
36649--- a/drivers/scsi/lpfc/lpfc_init.c
36650+++ b/drivers/scsi/lpfc/lpfc_init.c
36651@@ -10266,8 +10266,10 @@ lpfc_init(void)
36652 "misc_register returned with status %d", error);
36653
36654 if (lpfc_enable_npiv) {
36655- lpfc_transport_functions.vport_create = lpfc_vport_create;
36656- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36657+ pax_open_kernel();
36658+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36659+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36660+ pax_close_kernel();
36661 }
36662 lpfc_transport_template =
36663 fc_attach_transport(&lpfc_transport_functions);
36664diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36665index 88f3a83..686d3fa 100644
36666--- a/drivers/scsi/lpfc/lpfc_scsi.c
36667+++ b/drivers/scsi/lpfc/lpfc_scsi.c
36668@@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36669 uint32_t evt_posted;
36670
36671 spin_lock_irqsave(&phba->hbalock, flags);
36672- atomic_inc(&phba->num_rsrc_err);
36673+ atomic_inc_unchecked(&phba->num_rsrc_err);
36674 phba->last_rsrc_error_time = jiffies;
36675
36676 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36677@@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36678 unsigned long flags;
36679 struct lpfc_hba *phba = vport->phba;
36680 uint32_t evt_posted;
36681- atomic_inc(&phba->num_cmd_success);
36682+ atomic_inc_unchecked(&phba->num_cmd_success);
36683
36684 if (vport->cfg_lun_queue_depth <= queue_depth)
36685 return;
36686@@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36687 unsigned long num_rsrc_err, num_cmd_success;
36688 int i;
36689
36690- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
36691- num_cmd_success = atomic_read(&phba->num_cmd_success);
36692+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
36693+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
36694
36695 vports = lpfc_create_vport_work_array(phba);
36696 if (vports != NULL)
36697@@ -417,8 +417,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36698 }
36699 }
36700 lpfc_destroy_vport_work_array(phba, vports);
36701- atomic_set(&phba->num_rsrc_err, 0);
36702- atomic_set(&phba->num_cmd_success, 0);
36703+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
36704+ atomic_set_unchecked(&phba->num_cmd_success, 0);
36705 }
36706
36707 /**
36708@@ -452,8 +452,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
36709 }
36710 }
36711 lpfc_destroy_vport_work_array(phba, vports);
36712- atomic_set(&phba->num_rsrc_err, 0);
36713- atomic_set(&phba->num_cmd_success, 0);
36714+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
36715+ atomic_set_unchecked(&phba->num_cmd_success, 0);
36716 }
36717
36718 /**
36719diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
36720index ea8a0b4..812a124 100644
36721--- a/drivers/scsi/pmcraid.c
36722+++ b/drivers/scsi/pmcraid.c
36723@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
36724 res->scsi_dev = scsi_dev;
36725 scsi_dev->hostdata = res;
36726 res->change_detected = 0;
36727- atomic_set(&res->read_failures, 0);
36728- atomic_set(&res->write_failures, 0);
36729+ atomic_set_unchecked(&res->read_failures, 0);
36730+ atomic_set_unchecked(&res->write_failures, 0);
36731 rc = 0;
36732 }
36733 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
36734@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
36735
36736 /* If this was a SCSI read/write command keep count of errors */
36737 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
36738- atomic_inc(&res->read_failures);
36739+ atomic_inc_unchecked(&res->read_failures);
36740 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
36741- atomic_inc(&res->write_failures);
36742+ atomic_inc_unchecked(&res->write_failures);
36743
36744 if (!RES_IS_GSCSI(res->cfg_entry) &&
36745 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
36746@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
36747 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36748 * hrrq_id assigned here in queuecommand
36749 */
36750- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36751+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36752 pinstance->num_hrrq;
36753 cmd->cmd_done = pmcraid_io_done;
36754
36755@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
36756 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36757 * hrrq_id assigned here in queuecommand
36758 */
36759- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36760+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36761 pinstance->num_hrrq;
36762
36763 if (request_size) {
36764@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
36765
36766 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
36767 /* add resources only after host is added into system */
36768- if (!atomic_read(&pinstance->expose_resources))
36769+ if (!atomic_read_unchecked(&pinstance->expose_resources))
36770 return;
36771
36772 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
36773@@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
36774 init_waitqueue_head(&pinstance->reset_wait_q);
36775
36776 atomic_set(&pinstance->outstanding_cmds, 0);
36777- atomic_set(&pinstance->last_message_id, 0);
36778- atomic_set(&pinstance->expose_resources, 0);
36779+ atomic_set_unchecked(&pinstance->last_message_id, 0);
36780+ atomic_set_unchecked(&pinstance->expose_resources, 0);
36781
36782 INIT_LIST_HEAD(&pinstance->free_res_q);
36783 INIT_LIST_HEAD(&pinstance->used_res_q);
36784@@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
36785 /* Schedule worker thread to handle CCN and take care of adding and
36786 * removing devices to OS
36787 */
36788- atomic_set(&pinstance->expose_resources, 1);
36789+ atomic_set_unchecked(&pinstance->expose_resources, 1);
36790 schedule_work(&pinstance->worker_q);
36791 return rc;
36792
36793diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
36794index e1d150f..6c6df44 100644
36795--- a/drivers/scsi/pmcraid.h
36796+++ b/drivers/scsi/pmcraid.h
36797@@ -748,7 +748,7 @@ struct pmcraid_instance {
36798 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
36799
36800 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
36801- atomic_t last_message_id;
36802+ atomic_unchecked_t last_message_id;
36803
36804 /* configuration table */
36805 struct pmcraid_config_table *cfg_table;
36806@@ -777,7 +777,7 @@ struct pmcraid_instance {
36807 atomic_t outstanding_cmds;
36808
36809 /* should add/delete resources to mid-layer now ?*/
36810- atomic_t expose_resources;
36811+ atomic_unchecked_t expose_resources;
36812
36813
36814
36815@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
36816 struct pmcraid_config_table_entry_ext cfg_entry_ext;
36817 };
36818 struct scsi_device *scsi_dev; /* Link scsi_device structure */
36819- atomic_t read_failures; /* count of failed READ commands */
36820- atomic_t write_failures; /* count of failed WRITE commands */
36821+ atomic_unchecked_t read_failures; /* count of failed READ commands */
36822+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
36823
36824 /* To indicate add/delete/modify during CCN */
36825 u8 change_detected;
36826diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
36827index a244303..6015eb7 100644
36828--- a/drivers/scsi/qla2xxx/qla_def.h
36829+++ b/drivers/scsi/qla2xxx/qla_def.h
36830@@ -2264,7 +2264,7 @@ struct isp_operations {
36831 int (*start_scsi) (srb_t *);
36832 int (*abort_isp) (struct scsi_qla_host *);
36833 int (*iospace_config)(struct qla_hw_data*);
36834-};
36835+} __no_const;
36836
36837 /* MSI-X Support *************************************************************/
36838
36839diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
36840index 7f2492e..5113877 100644
36841--- a/drivers/scsi/qla4xxx/ql4_def.h
36842+++ b/drivers/scsi/qla4xxx/ql4_def.h
36843@@ -268,7 +268,7 @@ struct ddb_entry {
36844 * (4000 only) */
36845 atomic_t relogin_timer; /* Max Time to wait for
36846 * relogin to complete */
36847- atomic_t relogin_retry_count; /* Num of times relogin has been
36848+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
36849 * retried */
36850 uint32_t default_time2wait; /* Default Min time between
36851 * relogins (+aens) */
36852diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
36853index ee47820..a83b1f4 100644
36854--- a/drivers/scsi/qla4xxx/ql4_os.c
36855+++ b/drivers/scsi/qla4xxx/ql4_os.c
36856@@ -2551,12 +2551,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
36857 */
36858 if (!iscsi_is_session_online(cls_sess)) {
36859 /* Reset retry relogin timer */
36860- atomic_inc(&ddb_entry->relogin_retry_count);
36861+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
36862 DEBUG2(ql4_printk(KERN_INFO, ha,
36863 "%s: index[%d] relogin timed out-retrying"
36864 " relogin (%d), retry (%d)\n", __func__,
36865 ddb_entry->fw_ddb_index,
36866- atomic_read(&ddb_entry->relogin_retry_count),
36867+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
36868 ddb_entry->default_time2wait + 4));
36869 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
36870 atomic_set(&ddb_entry->retry_relogin_timer,
36871@@ -4453,7 +4453,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
36872
36873 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
36874 atomic_set(&ddb_entry->relogin_timer, 0);
36875- atomic_set(&ddb_entry->relogin_retry_count, 0);
36876+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
36877 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
36878 ddb_entry->default_relogin_timeout =
36879 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
36880diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
36881index 07322ec..91ccc23 100644
36882--- a/drivers/scsi/scsi.c
36883+++ b/drivers/scsi/scsi.c
36884@@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
36885 unsigned long timeout;
36886 int rtn = 0;
36887
36888- atomic_inc(&cmd->device->iorequest_cnt);
36889+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36890
36891 /* check if the device is still usable */
36892 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
36893diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
36894index 4037fd5..a19fcc7 100644
36895--- a/drivers/scsi/scsi_lib.c
36896+++ b/drivers/scsi/scsi_lib.c
36897@@ -1415,7 +1415,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
36898 shost = sdev->host;
36899 scsi_init_cmd_errh(cmd);
36900 cmd->result = DID_NO_CONNECT << 16;
36901- atomic_inc(&cmd->device->iorequest_cnt);
36902+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36903
36904 /*
36905 * SCSI request completion path will do scsi_device_unbusy(),
36906@@ -1441,9 +1441,9 @@ static void scsi_softirq_done(struct request *rq)
36907
36908 INIT_LIST_HEAD(&cmd->eh_entry);
36909
36910- atomic_inc(&cmd->device->iodone_cnt);
36911+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
36912 if (cmd->result)
36913- atomic_inc(&cmd->device->ioerr_cnt);
36914+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
36915
36916 disposition = scsi_decide_disposition(cmd);
36917 if (disposition != SUCCESS &&
36918diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
36919index 04c2a27..9d8bd66 100644
36920--- a/drivers/scsi/scsi_sysfs.c
36921+++ b/drivers/scsi/scsi_sysfs.c
36922@@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
36923 char *buf) \
36924 { \
36925 struct scsi_device *sdev = to_scsi_device(dev); \
36926- unsigned long long count = atomic_read(&sdev->field); \
36927+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
36928 return snprintf(buf, 20, "0x%llx\n", count); \
36929 } \
36930 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
36931diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
36932index 84a1fdf..693b0d6 100644
36933--- a/drivers/scsi/scsi_tgt_lib.c
36934+++ b/drivers/scsi/scsi_tgt_lib.c
36935@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
36936 int err;
36937
36938 dprintk("%lx %u\n", uaddr, len);
36939- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
36940+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
36941 if (err) {
36942 /*
36943 * TODO: need to fixup sg_tablesize, max_segment_size,
36944diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
36945index 80fbe2a..efa223b 100644
36946--- a/drivers/scsi/scsi_transport_fc.c
36947+++ b/drivers/scsi/scsi_transport_fc.c
36948@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
36949 * Netlink Infrastructure
36950 */
36951
36952-static atomic_t fc_event_seq;
36953+static atomic_unchecked_t fc_event_seq;
36954
36955 /**
36956 * fc_get_event_number - Obtain the next sequential FC event number
36957@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
36958 u32
36959 fc_get_event_number(void)
36960 {
36961- return atomic_add_return(1, &fc_event_seq);
36962+ return atomic_add_return_unchecked(1, &fc_event_seq);
36963 }
36964 EXPORT_SYMBOL(fc_get_event_number);
36965
36966@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
36967 {
36968 int error;
36969
36970- atomic_set(&fc_event_seq, 0);
36971+ atomic_set_unchecked(&fc_event_seq, 0);
36972
36973 error = transport_class_register(&fc_host_class);
36974 if (error)
36975@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
36976 char *cp;
36977
36978 *val = simple_strtoul(buf, &cp, 0);
36979- if ((*cp && (*cp != '\n')) || (*val < 0))
36980+ if (*cp && (*cp != '\n'))
36981 return -EINVAL;
36982 /*
36983 * Check for overflow; dev_loss_tmo is u32
36984diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
36985index 1cf640e..78e9014 100644
36986--- a/drivers/scsi/scsi_transport_iscsi.c
36987+++ b/drivers/scsi/scsi_transport_iscsi.c
36988@@ -79,7 +79,7 @@ struct iscsi_internal {
36989 struct transport_container session_cont;
36990 };
36991
36992-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
36993+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
36994 static struct workqueue_struct *iscsi_eh_timer_workq;
36995
36996 static DEFINE_IDA(iscsi_sess_ida);
36997@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
36998 int err;
36999
37000 ihost = shost->shost_data;
37001- session->sid = atomic_add_return(1, &iscsi_session_nr);
37002+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37003
37004 if (target_id == ISCSI_MAX_TARGET) {
37005 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37006@@ -2940,7 +2940,7 @@ static __init int iscsi_transport_init(void)
37007 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37008 ISCSI_TRANSPORT_VERSION);
37009
37010- atomic_set(&iscsi_session_nr, 0);
37011+ atomic_set_unchecked(&iscsi_session_nr, 0);
37012
37013 err = class_register(&iscsi_transport_class);
37014 if (err)
37015diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37016index 21a045e..ec89e03 100644
37017--- a/drivers/scsi/scsi_transport_srp.c
37018+++ b/drivers/scsi/scsi_transport_srp.c
37019@@ -33,7 +33,7 @@
37020 #include "scsi_transport_srp_internal.h"
37021
37022 struct srp_host_attrs {
37023- atomic_t next_port_id;
37024+ atomic_unchecked_t next_port_id;
37025 };
37026 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37027
37028@@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37029 struct Scsi_Host *shost = dev_to_shost(dev);
37030 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37031
37032- atomic_set(&srp_host->next_port_id, 0);
37033+ atomic_set_unchecked(&srp_host->next_port_id, 0);
37034 return 0;
37035 }
37036
37037@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37038 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37039 rport->roles = ids->roles;
37040
37041- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37042+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37043 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37044
37045 transport_setup_device(&rport->dev);
37046diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37047index eacd46b..e3f4d62 100644
37048--- a/drivers/scsi/sg.c
37049+++ b/drivers/scsi/sg.c
37050@@ -1077,7 +1077,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37051 sdp->disk->disk_name,
37052 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37053 NULL,
37054- (char *)arg);
37055+ (char __user *)arg);
37056 case BLKTRACESTART:
37057 return blk_trace_startstop(sdp->device->request_queue, 1);
37058 case BLKTRACESTOP:
37059@@ -2312,7 +2312,7 @@ struct sg_proc_leaf {
37060 const struct file_operations * fops;
37061 };
37062
37063-static struct sg_proc_leaf sg_proc_leaf_arr[] = {
37064+static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
37065 {"allow_dio", &adio_fops},
37066 {"debug", &debug_fops},
37067 {"def_reserved_size", &dressz_fops},
37068@@ -2332,7 +2332,7 @@ sg_proc_init(void)
37069 if (!sg_proc_sgp)
37070 return 1;
37071 for (k = 0; k < num_leaves; ++k) {
37072- struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37073+ const struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37074 umode_t mask = leaf->fops->write ? S_IRUGO | S_IWUSR : S_IRUGO;
37075 proc_create(leaf->name, mask, sg_proc_sgp, leaf->fops);
37076 }
37077diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37078index 3d8f662..070f1a5 100644
37079--- a/drivers/spi/spi.c
37080+++ b/drivers/spi/spi.c
37081@@ -1361,7 +1361,7 @@ int spi_bus_unlock(struct spi_master *master)
37082 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37083
37084 /* portable code must never pass more than 32 bytes */
37085-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37086+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37087
37088 static u8 *buf;
37089
37090diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37091index d91751f..a3a9e36 100644
37092--- a/drivers/staging/octeon/ethernet-rx.c
37093+++ b/drivers/staging/octeon/ethernet-rx.c
37094@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37095 /* Increment RX stats for virtual ports */
37096 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37097 #ifdef CONFIG_64BIT
37098- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37099- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37100+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37101+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37102 #else
37103- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37104- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37105+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37106+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37107 #endif
37108 }
37109 netif_receive_skb(skb);
37110@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37111 dev->name);
37112 */
37113 #ifdef CONFIG_64BIT
37114- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37115+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37116 #else
37117- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37118+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37119 #endif
37120 dev_kfree_skb_irq(skb);
37121 }
37122diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37123index 60cba81..71eb239 100644
37124--- a/drivers/staging/octeon/ethernet.c
37125+++ b/drivers/staging/octeon/ethernet.c
37126@@ -259,11 +259,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37127 * since the RX tasklet also increments it.
37128 */
37129 #ifdef CONFIG_64BIT
37130- atomic64_add(rx_status.dropped_packets,
37131- (atomic64_t *)&priv->stats.rx_dropped);
37132+ atomic64_add_unchecked(rx_status.dropped_packets,
37133+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37134 #else
37135- atomic_add(rx_status.dropped_packets,
37136- (atomic_t *)&priv->stats.rx_dropped);
37137+ atomic_add_unchecked(rx_status.dropped_packets,
37138+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
37139 #endif
37140 }
37141
37142diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37143index d3d8727..f9327bb8 100644
37144--- a/drivers/staging/rtl8712/rtl871x_io.h
37145+++ b/drivers/staging/rtl8712/rtl871x_io.h
37146@@ -108,7 +108,7 @@ struct _io_ops {
37147 u8 *pmem);
37148 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37149 u8 *pmem);
37150-};
37151+} __no_const;
37152
37153 struct io_req {
37154 struct list_head list;
37155diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37156index c7b5e8b..783d6cb 100644
37157--- a/drivers/staging/sbe-2t3e3/netdev.c
37158+++ b/drivers/staging/sbe-2t3e3/netdev.c
37159@@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37160 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37161
37162 if (rlen)
37163- if (copy_to_user(data, &resp, rlen))
37164+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37165 return -EFAULT;
37166
37167 return 0;
37168diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37169index 42cdafe..2769103 100644
37170--- a/drivers/staging/speakup/speakup_soft.c
37171+++ b/drivers/staging/speakup/speakup_soft.c
37172@@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37173 break;
37174 } else if (!initialized) {
37175 if (*init) {
37176- ch = *init;
37177 init++;
37178 } else {
37179 initialized = 1;
37180 }
37181+ ch = *init;
37182 } else {
37183 ch = synth_buffer_getc();
37184 }
37185diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37186index c7b888c..c94be93 100644
37187--- a/drivers/staging/usbip/usbip_common.h
37188+++ b/drivers/staging/usbip/usbip_common.h
37189@@ -289,7 +289,7 @@ struct usbip_device {
37190 void (*shutdown)(struct usbip_device *);
37191 void (*reset)(struct usbip_device *);
37192 void (*unusable)(struct usbip_device *);
37193- } eh_ops;
37194+ } __no_const eh_ops;
37195 };
37196
37197 /* usbip_common.c */
37198diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37199index 88b3298..3783eee 100644
37200--- a/drivers/staging/usbip/vhci.h
37201+++ b/drivers/staging/usbip/vhci.h
37202@@ -88,7 +88,7 @@ struct vhci_hcd {
37203 unsigned resuming:1;
37204 unsigned long re_timeout;
37205
37206- atomic_t seqnum;
37207+ atomic_unchecked_t seqnum;
37208
37209 /*
37210 * NOTE:
37211diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37212index dca9bf1..80735c9 100644
37213--- a/drivers/staging/usbip/vhci_hcd.c
37214+++ b/drivers/staging/usbip/vhci_hcd.c
37215@@ -488,7 +488,7 @@ static void vhci_tx_urb(struct urb *urb)
37216 return;
37217 }
37218
37219- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37220+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37221 if (priv->seqnum == 0xffff)
37222 dev_info(&urb->dev->dev, "seqnum max\n");
37223
37224@@ -740,7 +740,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37225 return -ENOMEM;
37226 }
37227
37228- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37229+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37230 if (unlink->seqnum == 0xffff)
37231 pr_info("seqnum max\n");
37232
37233@@ -928,7 +928,7 @@ static int vhci_start(struct usb_hcd *hcd)
37234 vdev->rhport = rhport;
37235 }
37236
37237- atomic_set(&vhci->seqnum, 0);
37238+ atomic_set_unchecked(&vhci->seqnum, 0);
37239 spin_lock_init(&vhci->lock);
37240
37241 hcd->power_budget = 0; /* no limit */
37242diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37243index f5fba732..210a16c 100644
37244--- a/drivers/staging/usbip/vhci_rx.c
37245+++ b/drivers/staging/usbip/vhci_rx.c
37246@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37247 if (!urb) {
37248 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37249 pr_info("max seqnum %d\n",
37250- atomic_read(&the_controller->seqnum));
37251+ atomic_read_unchecked(&the_controller->seqnum));
37252 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37253 return;
37254 }
37255diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37256index 7735027..30eed13 100644
37257--- a/drivers/staging/vt6655/hostap.c
37258+++ b/drivers/staging/vt6655/hostap.c
37259@@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37260 *
37261 */
37262
37263+static net_device_ops_no_const apdev_netdev_ops;
37264+
37265 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37266 {
37267 PSDevice apdev_priv;
37268 struct net_device *dev = pDevice->dev;
37269 int ret;
37270- const struct net_device_ops apdev_netdev_ops = {
37271- .ndo_start_xmit = pDevice->tx_80211,
37272- };
37273
37274 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37275
37276@@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37277 *apdev_priv = *pDevice;
37278 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37279
37280+ /* only half broken now */
37281+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37282 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37283
37284 pDevice->apdev->type = ARPHRD_IEEE80211;
37285diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37286index 51b5adf..098e320 100644
37287--- a/drivers/staging/vt6656/hostap.c
37288+++ b/drivers/staging/vt6656/hostap.c
37289@@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37290 *
37291 */
37292
37293+static net_device_ops_no_const apdev_netdev_ops;
37294+
37295 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37296 {
37297 PSDevice apdev_priv;
37298 struct net_device *dev = pDevice->dev;
37299 int ret;
37300- const struct net_device_ops apdev_netdev_ops = {
37301- .ndo_start_xmit = pDevice->tx_80211,
37302- };
37303
37304 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37305
37306@@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37307 *apdev_priv = *pDevice;
37308 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37309
37310+ /* only half broken now */
37311+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37312 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37313
37314 pDevice->apdev->type = ARPHRD_IEEE80211;
37315diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37316index 7843dfd..3db105f 100644
37317--- a/drivers/staging/wlan-ng/hfa384x_usb.c
37318+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37319@@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37320
37321 struct usbctlx_completor {
37322 int (*complete) (struct usbctlx_completor *);
37323-};
37324+} __no_const;
37325
37326 static int
37327 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37328diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37329index 1ca66ea..76f1343 100644
37330--- a/drivers/staging/zcache/tmem.c
37331+++ b/drivers/staging/zcache/tmem.c
37332@@ -39,7 +39,7 @@
37333 * A tmem host implementation must use this function to register callbacks
37334 * for memory allocation.
37335 */
37336-static struct tmem_hostops tmem_hostops;
37337+static tmem_hostops_no_const tmem_hostops;
37338
37339 static void tmem_objnode_tree_init(void);
37340
37341@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37342 * A tmem host implementation must use this function to register
37343 * callbacks for a page-accessible memory (PAM) implementation
37344 */
37345-static struct tmem_pamops tmem_pamops;
37346+static tmem_pamops_no_const tmem_pamops;
37347
37348 void tmem_register_pamops(struct tmem_pamops *m)
37349 {
37350diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37351index 0d4aa82..f7832d4 100644
37352--- a/drivers/staging/zcache/tmem.h
37353+++ b/drivers/staging/zcache/tmem.h
37354@@ -180,6 +180,7 @@ struct tmem_pamops {
37355 void (*new_obj)(struct tmem_obj *);
37356 int (*replace_in_obj)(void *, struct tmem_obj *);
37357 };
37358+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37359 extern void tmem_register_pamops(struct tmem_pamops *m);
37360
37361 /* memory allocation methods provided by the host implementation */
37362@@ -189,6 +190,7 @@ struct tmem_hostops {
37363 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37364 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37365 };
37366+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37367 extern void tmem_register_hostops(struct tmem_hostops *m);
37368
37369 /* core tmem accessor functions */
37370diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
37371index f015839..b15dfc4 100644
37372--- a/drivers/target/target_core_tmr.c
37373+++ b/drivers/target/target_core_tmr.c
37374@@ -327,7 +327,7 @@ static void core_tmr_drain_task_list(
37375 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
37376 cmd->t_task_list_num,
37377 atomic_read(&cmd->t_task_cdbs_left),
37378- atomic_read(&cmd->t_task_cdbs_sent),
37379+ atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37380 (cmd->transport_state & CMD_T_ACTIVE) != 0,
37381 (cmd->transport_state & CMD_T_STOP) != 0,
37382 (cmd->transport_state & CMD_T_SENT) != 0);
37383diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37384index 443704f..92d3517 100644
37385--- a/drivers/target/target_core_transport.c
37386+++ b/drivers/target/target_core_transport.c
37387@@ -1355,7 +1355,7 @@ struct se_device *transport_add_device_to_core_hba(
37388 spin_lock_init(&dev->se_port_lock);
37389 spin_lock_init(&dev->se_tmr_lock);
37390 spin_lock_init(&dev->qf_cmd_lock);
37391- atomic_set(&dev->dev_ordered_id, 0);
37392+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
37393
37394 se_dev_set_default_attribs(dev, dev_limits);
37395
37396@@ -1542,7 +1542,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37397 * Used to determine when ORDERED commands should go from
37398 * Dormant to Active status.
37399 */
37400- cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37401+ cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37402 smp_mb__after_atomic_inc();
37403 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37404 cmd->se_ordered_id, cmd->sam_task_attr,
37405@@ -1956,7 +1956,7 @@ void transport_generic_request_failure(struct se_cmd *cmd)
37406 " CMD_T_ACTIVE: %d CMD_T_STOP: %d CMD_T_SENT: %d\n",
37407 cmd->t_task_list_num,
37408 atomic_read(&cmd->t_task_cdbs_left),
37409- atomic_read(&cmd->t_task_cdbs_sent),
37410+ atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37411 atomic_read(&cmd->t_task_cdbs_ex_left),
37412 (cmd->transport_state & CMD_T_ACTIVE) != 0,
37413 (cmd->transport_state & CMD_T_STOP) != 0,
37414@@ -2216,9 +2216,9 @@ check_depth:
37415 cmd = task->task_se_cmd;
37416 spin_lock_irqsave(&cmd->t_state_lock, flags);
37417 task->task_flags |= (TF_ACTIVE | TF_SENT);
37418- atomic_inc(&cmd->t_task_cdbs_sent);
37419+ atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
37420
37421- if (atomic_read(&cmd->t_task_cdbs_sent) ==
37422+ if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
37423 cmd->t_task_list_num)
37424 cmd->transport_state |= CMD_T_SENT;
37425
37426diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37427index 3436436..772237b 100644
37428--- a/drivers/tty/hvc/hvcs.c
37429+++ b/drivers/tty/hvc/hvcs.c
37430@@ -83,6 +83,7 @@
37431 #include <asm/hvcserver.h>
37432 #include <asm/uaccess.h>
37433 #include <asm/vio.h>
37434+#include <asm/local.h>
37435
37436 /*
37437 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37438@@ -270,7 +271,7 @@ struct hvcs_struct {
37439 unsigned int index;
37440
37441 struct tty_struct *tty;
37442- int open_count;
37443+ local_t open_count;
37444
37445 /*
37446 * Used to tell the driver kernel_thread what operations need to take
37447@@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37448
37449 spin_lock_irqsave(&hvcsd->lock, flags);
37450
37451- if (hvcsd->open_count > 0) {
37452+ if (local_read(&hvcsd->open_count) > 0) {
37453 spin_unlock_irqrestore(&hvcsd->lock, flags);
37454 printk(KERN_INFO "HVCS: vterm state unchanged. "
37455 "The hvcs device node is still in use.\n");
37456@@ -1138,7 +1139,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37457 if ((retval = hvcs_partner_connect(hvcsd)))
37458 goto error_release;
37459
37460- hvcsd->open_count = 1;
37461+ local_set(&hvcsd->open_count, 1);
37462 hvcsd->tty = tty;
37463 tty->driver_data = hvcsd;
37464
37465@@ -1172,7 +1173,7 @@ fast_open:
37466
37467 spin_lock_irqsave(&hvcsd->lock, flags);
37468 kref_get(&hvcsd->kref);
37469- hvcsd->open_count++;
37470+ local_inc(&hvcsd->open_count);
37471 hvcsd->todo_mask |= HVCS_SCHED_READ;
37472 spin_unlock_irqrestore(&hvcsd->lock, flags);
37473
37474@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37475 hvcsd = tty->driver_data;
37476
37477 spin_lock_irqsave(&hvcsd->lock, flags);
37478- if (--hvcsd->open_count == 0) {
37479+ if (local_dec_and_test(&hvcsd->open_count)) {
37480
37481 vio_disable_interrupts(hvcsd->vdev);
37482
37483@@ -1242,10 +1243,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37484 free_irq(irq, hvcsd);
37485 kref_put(&hvcsd->kref, destroy_hvcs_struct);
37486 return;
37487- } else if (hvcsd->open_count < 0) {
37488+ } else if (local_read(&hvcsd->open_count) < 0) {
37489 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37490 " is missmanaged.\n",
37491- hvcsd->vdev->unit_address, hvcsd->open_count);
37492+ hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
37493 }
37494
37495 spin_unlock_irqrestore(&hvcsd->lock, flags);
37496@@ -1261,7 +1262,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37497
37498 spin_lock_irqsave(&hvcsd->lock, flags);
37499 /* Preserve this so that we know how many kref refs to put */
37500- temp_open_count = hvcsd->open_count;
37501+ temp_open_count = local_read(&hvcsd->open_count);
37502
37503 /*
37504 * Don't kref put inside the spinlock because the destruction
37505@@ -1276,7 +1277,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37506 hvcsd->tty->driver_data = NULL;
37507 hvcsd->tty = NULL;
37508
37509- hvcsd->open_count = 0;
37510+ local_set(&hvcsd->open_count, 0);
37511
37512 /* This will drop any buffered data on the floor which is OK in a hangup
37513 * scenario. */
37514@@ -1347,7 +1348,7 @@ static int hvcs_write(struct tty_struct *tty,
37515 * the middle of a write operation? This is a crummy place to do this
37516 * but we want to keep it all in the spinlock.
37517 */
37518- if (hvcsd->open_count <= 0) {
37519+ if (local_read(&hvcsd->open_count) <= 0) {
37520 spin_unlock_irqrestore(&hvcsd->lock, flags);
37521 return -ENODEV;
37522 }
37523@@ -1421,7 +1422,7 @@ static int hvcs_write_room(struct tty_struct *tty)
37524 {
37525 struct hvcs_struct *hvcsd = tty->driver_data;
37526
37527- if (!hvcsd || hvcsd->open_count <= 0)
37528+ if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
37529 return 0;
37530
37531 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
37532diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
37533index 4daf962..b4a2281 100644
37534--- a/drivers/tty/ipwireless/tty.c
37535+++ b/drivers/tty/ipwireless/tty.c
37536@@ -29,6 +29,7 @@
37537 #include <linux/tty_driver.h>
37538 #include <linux/tty_flip.h>
37539 #include <linux/uaccess.h>
37540+#include <asm/local.h>
37541
37542 #include "tty.h"
37543 #include "network.h"
37544@@ -51,7 +52,7 @@ struct ipw_tty {
37545 int tty_type;
37546 struct ipw_network *network;
37547 struct tty_struct *linux_tty;
37548- int open_count;
37549+ local_t open_count;
37550 unsigned int control_lines;
37551 struct mutex ipw_tty_mutex;
37552 int tx_bytes_queued;
37553@@ -117,10 +118,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37554 mutex_unlock(&tty->ipw_tty_mutex);
37555 return -ENODEV;
37556 }
37557- if (tty->open_count == 0)
37558+ if (local_read(&tty->open_count) == 0)
37559 tty->tx_bytes_queued = 0;
37560
37561- tty->open_count++;
37562+ local_inc(&tty->open_count);
37563
37564 tty->linux_tty = linux_tty;
37565 linux_tty->driver_data = tty;
37566@@ -136,9 +137,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37567
37568 static void do_ipw_close(struct ipw_tty *tty)
37569 {
37570- tty->open_count--;
37571-
37572- if (tty->open_count == 0) {
37573+ if (local_dec_return(&tty->open_count) == 0) {
37574 struct tty_struct *linux_tty = tty->linux_tty;
37575
37576 if (linux_tty != NULL) {
37577@@ -159,7 +158,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
37578 return;
37579
37580 mutex_lock(&tty->ipw_tty_mutex);
37581- if (tty->open_count == 0) {
37582+ if (local_read(&tty->open_count) == 0) {
37583 mutex_unlock(&tty->ipw_tty_mutex);
37584 return;
37585 }
37586@@ -188,7 +187,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
37587 return;
37588 }
37589
37590- if (!tty->open_count) {
37591+ if (!local_read(&tty->open_count)) {
37592 mutex_unlock(&tty->ipw_tty_mutex);
37593 return;
37594 }
37595@@ -230,7 +229,7 @@ static int ipw_write(struct tty_struct *linux_tty,
37596 return -ENODEV;
37597
37598 mutex_lock(&tty->ipw_tty_mutex);
37599- if (!tty->open_count) {
37600+ if (!local_read(&tty->open_count)) {
37601 mutex_unlock(&tty->ipw_tty_mutex);
37602 return -EINVAL;
37603 }
37604@@ -270,7 +269,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
37605 if (!tty)
37606 return -ENODEV;
37607
37608- if (!tty->open_count)
37609+ if (!local_read(&tty->open_count))
37610 return -EINVAL;
37611
37612 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
37613@@ -312,7 +311,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
37614 if (!tty)
37615 return 0;
37616
37617- if (!tty->open_count)
37618+ if (!local_read(&tty->open_count))
37619 return 0;
37620
37621 return tty->tx_bytes_queued;
37622@@ -393,7 +392,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
37623 if (!tty)
37624 return -ENODEV;
37625
37626- if (!tty->open_count)
37627+ if (!local_read(&tty->open_count))
37628 return -EINVAL;
37629
37630 return get_control_lines(tty);
37631@@ -409,7 +408,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
37632 if (!tty)
37633 return -ENODEV;
37634
37635- if (!tty->open_count)
37636+ if (!local_read(&tty->open_count))
37637 return -EINVAL;
37638
37639 return set_control_lines(tty, set, clear);
37640@@ -423,7 +422,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
37641 if (!tty)
37642 return -ENODEV;
37643
37644- if (!tty->open_count)
37645+ if (!local_read(&tty->open_count))
37646 return -EINVAL;
37647
37648 /* FIXME: Exactly how is the tty object locked here .. */
37649@@ -572,7 +571,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
37650 against a parallel ioctl etc */
37651 mutex_lock(&ttyj->ipw_tty_mutex);
37652 }
37653- while (ttyj->open_count)
37654+ while (local_read(&ttyj->open_count))
37655 do_ipw_close(ttyj);
37656 ipwireless_disassociate_network_ttys(network,
37657 ttyj->channel_idx);
37658diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
37659index c43b683..0a88f1c 100644
37660--- a/drivers/tty/n_gsm.c
37661+++ b/drivers/tty/n_gsm.c
37662@@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
37663 kref_init(&dlci->ref);
37664 mutex_init(&dlci->mutex);
37665 dlci->fifo = &dlci->_fifo;
37666- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
37667+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
37668 kfree(dlci);
37669 return NULL;
37670 }
37671diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
37672index 94b6eda..15f7cec 100644
37673--- a/drivers/tty/n_tty.c
37674+++ b/drivers/tty/n_tty.c
37675@@ -2122,6 +2122,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
37676 {
37677 *ops = tty_ldisc_N_TTY;
37678 ops->owner = NULL;
37679- ops->refcount = ops->flags = 0;
37680+ atomic_set(&ops->refcount, 0);
37681+ ops->flags = 0;
37682 }
37683 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
37684diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
37685index eeae7fa..177a743 100644
37686--- a/drivers/tty/pty.c
37687+++ b/drivers/tty/pty.c
37688@@ -707,8 +707,10 @@ static void __init unix98_pty_init(void)
37689 panic("Couldn't register Unix98 pts driver");
37690
37691 /* Now create the /dev/ptmx special device */
37692+ pax_open_kernel();
37693 tty_default_fops(&ptmx_fops);
37694- ptmx_fops.open = ptmx_open;
37695+ *(void **)&ptmx_fops.open = ptmx_open;
37696+ pax_close_kernel();
37697
37698 cdev_init(&ptmx_cdev, &ptmx_fops);
37699 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
37700diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
37701index 2b42a01..32a2ed3 100644
37702--- a/drivers/tty/serial/kgdboc.c
37703+++ b/drivers/tty/serial/kgdboc.c
37704@@ -24,8 +24,9 @@
37705 #define MAX_CONFIG_LEN 40
37706
37707 static struct kgdb_io kgdboc_io_ops;
37708+static struct kgdb_io kgdboc_io_ops_console;
37709
37710-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
37711+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
37712 static int configured = -1;
37713
37714 static char config[MAX_CONFIG_LEN];
37715@@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
37716 kgdboc_unregister_kbd();
37717 if (configured == 1)
37718 kgdb_unregister_io_module(&kgdboc_io_ops);
37719+ else if (configured == 2)
37720+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
37721 }
37722
37723 static int configure_kgdboc(void)
37724@@ -157,13 +160,13 @@ static int configure_kgdboc(void)
37725 int err;
37726 char *cptr = config;
37727 struct console *cons;
37728+ int is_console = 0;
37729
37730 err = kgdboc_option_setup(config);
37731 if (err || !strlen(config) || isspace(config[0]))
37732 goto noconfig;
37733
37734 err = -ENODEV;
37735- kgdboc_io_ops.is_console = 0;
37736 kgdb_tty_driver = NULL;
37737
37738 kgdboc_use_kms = 0;
37739@@ -184,7 +187,7 @@ static int configure_kgdboc(void)
37740 int idx;
37741 if (cons->device && cons->device(cons, &idx) == p &&
37742 idx == tty_line) {
37743- kgdboc_io_ops.is_console = 1;
37744+ is_console = 1;
37745 break;
37746 }
37747 cons = cons->next;
37748@@ -194,12 +197,16 @@ static int configure_kgdboc(void)
37749 kgdb_tty_line = tty_line;
37750
37751 do_register:
37752- err = kgdb_register_io_module(&kgdboc_io_ops);
37753+ if (is_console) {
37754+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
37755+ configured = 2;
37756+ } else {
37757+ err = kgdb_register_io_module(&kgdboc_io_ops);
37758+ configured = 1;
37759+ }
37760 if (err)
37761 goto noconfig;
37762
37763- configured = 1;
37764-
37765 return 0;
37766
37767 noconfig:
37768@@ -213,7 +220,7 @@ noconfig:
37769 static int __init init_kgdboc(void)
37770 {
37771 /* Already configured? */
37772- if (configured == 1)
37773+ if (configured >= 1)
37774 return 0;
37775
37776 return configure_kgdboc();
37777@@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
37778 if (config[len - 1] == '\n')
37779 config[len - 1] = '\0';
37780
37781- if (configured == 1)
37782+ if (configured >= 1)
37783 cleanup_kgdboc();
37784
37785 /* Go and configure with the new params. */
37786@@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
37787 .post_exception = kgdboc_post_exp_handler,
37788 };
37789
37790+static struct kgdb_io kgdboc_io_ops_console = {
37791+ .name = "kgdboc",
37792+ .read_char = kgdboc_get_char,
37793+ .write_char = kgdboc_put_char,
37794+ .pre_exception = kgdboc_pre_exp_handler,
37795+ .post_exception = kgdboc_post_exp_handler,
37796+ .is_console = 1
37797+};
37798+
37799 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
37800 /* This is only available if kgdboc is a built in for early debugging */
37801 static int __init kgdboc_early_init(char *opt)
37802diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
37803index 05728894..b9d44c6 100644
37804--- a/drivers/tty/sysrq.c
37805+++ b/drivers/tty/sysrq.c
37806@@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
37807 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
37808 size_t count, loff_t *ppos)
37809 {
37810- if (count) {
37811+ if (count && capable(CAP_SYS_ADMIN)) {
37812 char c;
37813
37814 if (get_user(c, buf))
37815diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
37816index d939bd7..33d92cd 100644
37817--- a/drivers/tty/tty_io.c
37818+++ b/drivers/tty/tty_io.c
37819@@ -3278,7 +3278,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
37820
37821 void tty_default_fops(struct file_operations *fops)
37822 {
37823- *fops = tty_fops;
37824+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
37825 }
37826
37827 /*
37828diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
37829index 24b95db..9c078d0 100644
37830--- a/drivers/tty/tty_ldisc.c
37831+++ b/drivers/tty/tty_ldisc.c
37832@@ -57,7 +57,7 @@ static void put_ldisc(struct tty_ldisc *ld)
37833 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
37834 struct tty_ldisc_ops *ldo = ld->ops;
37835
37836- ldo->refcount--;
37837+ atomic_dec(&ldo->refcount);
37838 module_put(ldo->owner);
37839 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
37840
37841@@ -92,7 +92,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
37842 spin_lock_irqsave(&tty_ldisc_lock, flags);
37843 tty_ldiscs[disc] = new_ldisc;
37844 new_ldisc->num = disc;
37845- new_ldisc->refcount = 0;
37846+ atomic_set(&new_ldisc->refcount, 0);
37847 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
37848
37849 return ret;
37850@@ -120,7 +120,7 @@ int tty_unregister_ldisc(int disc)
37851 return -EINVAL;
37852
37853 spin_lock_irqsave(&tty_ldisc_lock, flags);
37854- if (tty_ldiscs[disc]->refcount)
37855+ if (atomic_read(&tty_ldiscs[disc]->refcount))
37856 ret = -EBUSY;
37857 else
37858 tty_ldiscs[disc] = NULL;
37859@@ -141,7 +141,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
37860 if (ldops) {
37861 ret = ERR_PTR(-EAGAIN);
37862 if (try_module_get(ldops->owner)) {
37863- ldops->refcount++;
37864+ atomic_inc(&ldops->refcount);
37865 ret = ldops;
37866 }
37867 }
37868@@ -154,7 +154,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
37869 unsigned long flags;
37870
37871 spin_lock_irqsave(&tty_ldisc_lock, flags);
37872- ldops->refcount--;
37873+ atomic_dec(&ldops->refcount);
37874 module_put(ldops->owner);
37875 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
37876 }
37877diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
37878index 3b0c4e3..f98a992 100644
37879--- a/drivers/tty/vt/keyboard.c
37880+++ b/drivers/tty/vt/keyboard.c
37881@@ -663,6 +663,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
37882 kbd->kbdmode == VC_OFF) &&
37883 value != KVAL(K_SAK))
37884 return; /* SAK is allowed even in raw mode */
37885+
37886+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
37887+ {
37888+ void *func = fn_handler[value];
37889+ if (func == fn_show_state || func == fn_show_ptregs ||
37890+ func == fn_show_mem)
37891+ return;
37892+ }
37893+#endif
37894+
37895 fn_handler[value](vc);
37896 }
37897
37898@@ -1812,9 +1822,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
37899 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
37900 return -EFAULT;
37901
37902- if (!capable(CAP_SYS_TTY_CONFIG))
37903- perm = 0;
37904-
37905 switch (cmd) {
37906 case KDGKBENT:
37907 /* Ensure another thread doesn't free it under us */
37908@@ -1829,6 +1836,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
37909 spin_unlock_irqrestore(&kbd_event_lock, flags);
37910 return put_user(val, &user_kbe->kb_value);
37911 case KDSKBENT:
37912+ if (!capable(CAP_SYS_TTY_CONFIG))
37913+ perm = 0;
37914+
37915 if (!perm)
37916 return -EPERM;
37917 if (!i && v == K_NOSUCHMAP) {
37918@@ -1919,9 +1929,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
37919 int i, j, k;
37920 int ret;
37921
37922- if (!capable(CAP_SYS_TTY_CONFIG))
37923- perm = 0;
37924-
37925 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
37926 if (!kbs) {
37927 ret = -ENOMEM;
37928@@ -1955,6 +1962,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
37929 kfree(kbs);
37930 return ((p && *p) ? -EOVERFLOW : 0);
37931 case KDSKBSENT:
37932+ if (!capable(CAP_SYS_TTY_CONFIG))
37933+ perm = 0;
37934+
37935 if (!perm) {
37936 ret = -EPERM;
37937 goto reterr;
37938diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
37939index a783d53..cb30d94 100644
37940--- a/drivers/uio/uio.c
37941+++ b/drivers/uio/uio.c
37942@@ -25,6 +25,7 @@
37943 #include <linux/kobject.h>
37944 #include <linux/cdev.h>
37945 #include <linux/uio_driver.h>
37946+#include <asm/local.h>
37947
37948 #define UIO_MAX_DEVICES (1U << MINORBITS)
37949
37950@@ -32,10 +33,10 @@ struct uio_device {
37951 struct module *owner;
37952 struct device *dev;
37953 int minor;
37954- atomic_t event;
37955+ atomic_unchecked_t event;
37956 struct fasync_struct *async_queue;
37957 wait_queue_head_t wait;
37958- int vma_count;
37959+ local_t vma_count;
37960 struct uio_info *info;
37961 struct kobject *map_dir;
37962 struct kobject *portio_dir;
37963@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
37964 struct device_attribute *attr, char *buf)
37965 {
37966 struct uio_device *idev = dev_get_drvdata(dev);
37967- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
37968+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
37969 }
37970
37971 static struct device_attribute uio_class_attributes[] = {
37972@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
37973 {
37974 struct uio_device *idev = info->uio_dev;
37975
37976- atomic_inc(&idev->event);
37977+ atomic_inc_unchecked(&idev->event);
37978 wake_up_interruptible(&idev->wait);
37979 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
37980 }
37981@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
37982 }
37983
37984 listener->dev = idev;
37985- listener->event_count = atomic_read(&idev->event);
37986+ listener->event_count = atomic_read_unchecked(&idev->event);
37987 filep->private_data = listener;
37988
37989 if (idev->info->open) {
37990@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
37991 return -EIO;
37992
37993 poll_wait(filep, &idev->wait, wait);
37994- if (listener->event_count != atomic_read(&idev->event))
37995+ if (listener->event_count != atomic_read_unchecked(&idev->event))
37996 return POLLIN | POLLRDNORM;
37997 return 0;
37998 }
37999@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38000 do {
38001 set_current_state(TASK_INTERRUPTIBLE);
38002
38003- event_count = atomic_read(&idev->event);
38004+ event_count = atomic_read_unchecked(&idev->event);
38005 if (event_count != listener->event_count) {
38006 if (copy_to_user(buf, &event_count, count))
38007 retval = -EFAULT;
38008@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38009 static void uio_vma_open(struct vm_area_struct *vma)
38010 {
38011 struct uio_device *idev = vma->vm_private_data;
38012- idev->vma_count++;
38013+ local_inc(&idev->vma_count);
38014 }
38015
38016 static void uio_vma_close(struct vm_area_struct *vma)
38017 {
38018 struct uio_device *idev = vma->vm_private_data;
38019- idev->vma_count--;
38020+ local_dec(&idev->vma_count);
38021 }
38022
38023 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38024@@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
38025 idev->owner = owner;
38026 idev->info = info;
38027 init_waitqueue_head(&idev->wait);
38028- atomic_set(&idev->event, 0);
38029+ atomic_set_unchecked(&idev->event, 0);
38030
38031 ret = uio_get_minor(idev);
38032 if (ret)
38033diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38034index 98b89fe..aff824e 100644
38035--- a/drivers/usb/atm/cxacru.c
38036+++ b/drivers/usb/atm/cxacru.c
38037@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38038 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38039 if (ret < 2)
38040 return -EINVAL;
38041- if (index < 0 || index > 0x7f)
38042+ if (index > 0x7f)
38043 return -EINVAL;
38044 pos += tmp;
38045
38046diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38047index d3448ca..d2864ca 100644
38048--- a/drivers/usb/atm/usbatm.c
38049+++ b/drivers/usb/atm/usbatm.c
38050@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38051 if (printk_ratelimit())
38052 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38053 __func__, vpi, vci);
38054- atomic_inc(&vcc->stats->rx_err);
38055+ atomic_inc_unchecked(&vcc->stats->rx_err);
38056 return;
38057 }
38058
38059@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38060 if (length > ATM_MAX_AAL5_PDU) {
38061 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38062 __func__, length, vcc);
38063- atomic_inc(&vcc->stats->rx_err);
38064+ atomic_inc_unchecked(&vcc->stats->rx_err);
38065 goto out;
38066 }
38067
38068@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38069 if (sarb->len < pdu_length) {
38070 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38071 __func__, pdu_length, sarb->len, vcc);
38072- atomic_inc(&vcc->stats->rx_err);
38073+ atomic_inc_unchecked(&vcc->stats->rx_err);
38074 goto out;
38075 }
38076
38077 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38078 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38079 __func__, vcc);
38080- atomic_inc(&vcc->stats->rx_err);
38081+ atomic_inc_unchecked(&vcc->stats->rx_err);
38082 goto out;
38083 }
38084
38085@@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38086 if (printk_ratelimit())
38087 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38088 __func__, length);
38089- atomic_inc(&vcc->stats->rx_drop);
38090+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38091 goto out;
38092 }
38093
38094@@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38095
38096 vcc->push(vcc, skb);
38097
38098- atomic_inc(&vcc->stats->rx);
38099+ atomic_inc_unchecked(&vcc->stats->rx);
38100 out:
38101 skb_trim(sarb, 0);
38102 }
38103@@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38104 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38105
38106 usbatm_pop(vcc, skb);
38107- atomic_inc(&vcc->stats->tx);
38108+ atomic_inc_unchecked(&vcc->stats->tx);
38109
38110 skb = skb_dequeue(&instance->sndqueue);
38111 }
38112@@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38113 if (!left--)
38114 return sprintf(page,
38115 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38116- atomic_read(&atm_dev->stats.aal5.tx),
38117- atomic_read(&atm_dev->stats.aal5.tx_err),
38118- atomic_read(&atm_dev->stats.aal5.rx),
38119- atomic_read(&atm_dev->stats.aal5.rx_err),
38120- atomic_read(&atm_dev->stats.aal5.rx_drop));
38121+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38122+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38123+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38124+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38125+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38126
38127 if (!left--) {
38128 if (instance->disconnected)
38129diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38130index d956965..4179a77 100644
38131--- a/drivers/usb/core/devices.c
38132+++ b/drivers/usb/core/devices.c
38133@@ -126,7 +126,7 @@ static const char format_endpt[] =
38134 * time it gets called.
38135 */
38136 static struct device_connect_event {
38137- atomic_t count;
38138+ atomic_unchecked_t count;
38139 wait_queue_head_t wait;
38140 } device_event = {
38141 .count = ATOMIC_INIT(1),
38142@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38143
38144 void usbfs_conn_disc_event(void)
38145 {
38146- atomic_add(2, &device_event.count);
38147+ atomic_add_unchecked(2, &device_event.count);
38148 wake_up(&device_event.wait);
38149 }
38150
38151@@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38152
38153 poll_wait(file, &device_event.wait, wait);
38154
38155- event_count = atomic_read(&device_event.count);
38156+ event_count = atomic_read_unchecked(&device_event.count);
38157 if (file->f_version != event_count) {
38158 file->f_version = event_count;
38159 return POLLIN | POLLRDNORM;
38160diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38161index 1fc8f12..20647c1 100644
38162--- a/drivers/usb/early/ehci-dbgp.c
38163+++ b/drivers/usb/early/ehci-dbgp.c
38164@@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38165
38166 #ifdef CONFIG_KGDB
38167 static struct kgdb_io kgdbdbgp_io_ops;
38168-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38169+static struct kgdb_io kgdbdbgp_io_ops_console;
38170+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38171 #else
38172 #define dbgp_kgdb_mode (0)
38173 #endif
38174@@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38175 .write_char = kgdbdbgp_write_char,
38176 };
38177
38178+static struct kgdb_io kgdbdbgp_io_ops_console = {
38179+ .name = "kgdbdbgp",
38180+ .read_char = kgdbdbgp_read_char,
38181+ .write_char = kgdbdbgp_write_char,
38182+ .is_console = 1
38183+};
38184+
38185 static int kgdbdbgp_wait_time;
38186
38187 static int __init kgdbdbgp_parse_config(char *str)
38188@@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38189 ptr++;
38190 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38191 }
38192- kgdb_register_io_module(&kgdbdbgp_io_ops);
38193- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38194+ if (early_dbgp_console.index != -1)
38195+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38196+ else
38197+ kgdb_register_io_module(&kgdbdbgp_io_ops);
38198
38199 return 0;
38200 }
38201diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38202index d6bea3e..60b250e 100644
38203--- a/drivers/usb/wusbcore/wa-hc.h
38204+++ b/drivers/usb/wusbcore/wa-hc.h
38205@@ -192,7 +192,7 @@ struct wahc {
38206 struct list_head xfer_delayed_list;
38207 spinlock_t xfer_list_lock;
38208 struct work_struct xfer_work;
38209- atomic_t xfer_id_count;
38210+ atomic_unchecked_t xfer_id_count;
38211 };
38212
38213
38214@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
38215 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38216 spin_lock_init(&wa->xfer_list_lock);
38217 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38218- atomic_set(&wa->xfer_id_count, 1);
38219+ atomic_set_unchecked(&wa->xfer_id_count, 1);
38220 }
38221
38222 /**
38223diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
38224index 57c01ab..8a05959 100644
38225--- a/drivers/usb/wusbcore/wa-xfer.c
38226+++ b/drivers/usb/wusbcore/wa-xfer.c
38227@@ -296,7 +296,7 @@ out:
38228 */
38229 static void wa_xfer_id_init(struct wa_xfer *xfer)
38230 {
38231- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38232+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38233 }
38234
38235 /*
38236diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
38237index 51e4c1e..9d87e2a 100644
38238--- a/drivers/vhost/vhost.c
38239+++ b/drivers/vhost/vhost.c
38240@@ -632,7 +632,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
38241 return 0;
38242 }
38243
38244-static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
38245+static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
38246 {
38247 struct file *eventfp, *filep = NULL,
38248 *pollstart = NULL, *pollstop = NULL;
38249diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
38250index b0b2ac3..89a4399 100644
38251--- a/drivers/video/aty/aty128fb.c
38252+++ b/drivers/video/aty/aty128fb.c
38253@@ -148,7 +148,7 @@ enum {
38254 };
38255
38256 /* Must match above enum */
38257-static const char *r128_family[] __devinitdata = {
38258+static const char *r128_family[] __devinitconst = {
38259 "AGP",
38260 "PCI",
38261 "PRO AGP",
38262diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
38263index 5c3960d..15cf8fc 100644
38264--- a/drivers/video/fbcmap.c
38265+++ b/drivers/video/fbcmap.c
38266@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
38267 rc = -ENODEV;
38268 goto out;
38269 }
38270- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
38271- !info->fbops->fb_setcmap)) {
38272+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
38273 rc = -EINVAL;
38274 goto out1;
38275 }
38276diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
38277index c6ce416..3b9b642 100644
38278--- a/drivers/video/fbmem.c
38279+++ b/drivers/video/fbmem.c
38280@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38281 image->dx += image->width + 8;
38282 }
38283 } else if (rotate == FB_ROTATE_UD) {
38284- for (x = 0; x < num && image->dx >= 0; x++) {
38285+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
38286 info->fbops->fb_imageblit(info, image);
38287 image->dx -= image->width + 8;
38288 }
38289@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38290 image->dy += image->height + 8;
38291 }
38292 } else if (rotate == FB_ROTATE_CCW) {
38293- for (x = 0; x < num && image->dy >= 0; x++) {
38294+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
38295 info->fbops->fb_imageblit(info, image);
38296 image->dy -= image->height + 8;
38297 }
38298@@ -1157,7 +1157,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
38299 return -EFAULT;
38300 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
38301 return -EINVAL;
38302- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
38303+ if (con2fb.framebuffer >= FB_MAX)
38304 return -EINVAL;
38305 if (!registered_fb[con2fb.framebuffer])
38306 request_module("fb%d", con2fb.framebuffer);
38307diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
38308index 5a5d092..265c5ed 100644
38309--- a/drivers/video/geode/gx1fb_core.c
38310+++ b/drivers/video/geode/gx1fb_core.c
38311@@ -29,7 +29,7 @@ static int crt_option = 1;
38312 static char panel_option[32] = "";
38313
38314 /* Modes relevant to the GX1 (taken from modedb.c) */
38315-static const struct fb_videomode __devinitdata gx1_modedb[] = {
38316+static const struct fb_videomode __devinitconst gx1_modedb[] = {
38317 /* 640x480-60 VESA */
38318 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
38319 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
38320diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
38321index 0fad23f..0e9afa4 100644
38322--- a/drivers/video/gxt4500.c
38323+++ b/drivers/video/gxt4500.c
38324@@ -156,7 +156,7 @@ struct gxt4500_par {
38325 static char *mode_option;
38326
38327 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
38328-static const struct fb_videomode defaultmode __devinitdata = {
38329+static const struct fb_videomode defaultmode __devinitconst = {
38330 .refresh = 60,
38331 .xres = 1280,
38332 .yres = 1024,
38333@@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
38334 return 0;
38335 }
38336
38337-static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
38338+static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
38339 .id = "IBM GXT4500P",
38340 .type = FB_TYPE_PACKED_PIXELS,
38341 .visual = FB_VISUAL_PSEUDOCOLOR,
38342diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
38343index 7672d2e..b56437f 100644
38344--- a/drivers/video/i810/i810_accel.c
38345+++ b/drivers/video/i810/i810_accel.c
38346@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
38347 }
38348 }
38349 printk("ringbuffer lockup!!!\n");
38350+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
38351 i810_report_error(mmio);
38352 par->dev_flags |= LOCKUP;
38353 info->pixmap.scan_align = 1;
38354diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
38355index b83f361..2b05a91 100644
38356--- a/drivers/video/i810/i810_main.c
38357+++ b/drivers/video/i810/i810_main.c
38358@@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
38359 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
38360
38361 /* PCI */
38362-static const char *i810_pci_list[] __devinitdata = {
38363+static const char *i810_pci_list[] __devinitconst = {
38364 "Intel(R) 810 Framebuffer Device" ,
38365 "Intel(R) 810-DC100 Framebuffer Device" ,
38366 "Intel(R) 810E Framebuffer Device" ,
38367diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
38368index de36693..3c63fc2 100644
38369--- a/drivers/video/jz4740_fb.c
38370+++ b/drivers/video/jz4740_fb.c
38371@@ -136,7 +136,7 @@ struct jzfb {
38372 uint32_t pseudo_palette[16];
38373 };
38374
38375-static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
38376+static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
38377 .id = "JZ4740 FB",
38378 .type = FB_TYPE_PACKED_PIXELS,
38379 .visual = FB_VISUAL_TRUECOLOR,
38380diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
38381index 3c14e43..eafa544 100644
38382--- a/drivers/video/logo/logo_linux_clut224.ppm
38383+++ b/drivers/video/logo/logo_linux_clut224.ppm
38384@@ -1,1604 +1,1123 @@
38385 P3
38386-# Standard 224-color Linux logo
38387 80 80
38388 255
38389- 0 0 0 0 0 0 0 0 0 0 0 0
38390- 0 0 0 0 0 0 0 0 0 0 0 0
38391- 0 0 0 0 0 0 0 0 0 0 0 0
38392- 0 0 0 0 0 0 0 0 0 0 0 0
38393- 0 0 0 0 0 0 0 0 0 0 0 0
38394- 0 0 0 0 0 0 0 0 0 0 0 0
38395- 0 0 0 0 0 0 0 0 0 0 0 0
38396- 0 0 0 0 0 0 0 0 0 0 0 0
38397- 0 0 0 0 0 0 0 0 0 0 0 0
38398- 6 6 6 6 6 6 10 10 10 10 10 10
38399- 10 10 10 6 6 6 6 6 6 6 6 6
38400- 0 0 0 0 0 0 0 0 0 0 0 0
38401- 0 0 0 0 0 0 0 0 0 0 0 0
38402- 0 0 0 0 0 0 0 0 0 0 0 0
38403- 0 0 0 0 0 0 0 0 0 0 0 0
38404- 0 0 0 0 0 0 0 0 0 0 0 0
38405- 0 0 0 0 0 0 0 0 0 0 0 0
38406- 0 0 0 0 0 0 0 0 0 0 0 0
38407- 0 0 0 0 0 0 0 0 0 0 0 0
38408- 0 0 0 0 0 0 0 0 0 0 0 0
38409- 0 0 0 0 0 0 0 0 0 0 0 0
38410- 0 0 0 0 0 0 0 0 0 0 0 0
38411- 0 0 0 0 0 0 0 0 0 0 0 0
38412- 0 0 0 0 0 0 0 0 0 0 0 0
38413- 0 0 0 0 0 0 0 0 0 0 0 0
38414- 0 0 0 0 0 0 0 0 0 0 0 0
38415- 0 0 0 0 0 0 0 0 0 0 0 0
38416- 0 0 0 0 0 0 0 0 0 0 0 0
38417- 0 0 0 6 6 6 10 10 10 14 14 14
38418- 22 22 22 26 26 26 30 30 30 34 34 34
38419- 30 30 30 30 30 30 26 26 26 18 18 18
38420- 14 14 14 10 10 10 6 6 6 0 0 0
38421- 0 0 0 0 0 0 0 0 0 0 0 0
38422- 0 0 0 0 0 0 0 0 0 0 0 0
38423- 0 0 0 0 0 0 0 0 0 0 0 0
38424- 0 0 0 0 0 0 0 0 0 0 0 0
38425- 0 0 0 0 0 0 0 0 0 0 0 0
38426- 0 0 0 0 0 0 0 0 0 0 0 0
38427- 0 0 0 0 0 0 0 0 0 0 0 0
38428- 0 0 0 0 0 0 0 0 0 0 0 0
38429- 0 0 0 0 0 0 0 0 0 0 0 0
38430- 0 0 0 0 0 1 0 0 1 0 0 0
38431- 0 0 0 0 0 0 0 0 0 0 0 0
38432- 0 0 0 0 0 0 0 0 0 0 0 0
38433- 0 0 0 0 0 0 0 0 0 0 0 0
38434- 0 0 0 0 0 0 0 0 0 0 0 0
38435- 0 0 0 0 0 0 0 0 0 0 0 0
38436- 0 0 0 0 0 0 0 0 0 0 0 0
38437- 6 6 6 14 14 14 26 26 26 42 42 42
38438- 54 54 54 66 66 66 78 78 78 78 78 78
38439- 78 78 78 74 74 74 66 66 66 54 54 54
38440- 42 42 42 26 26 26 18 18 18 10 10 10
38441- 6 6 6 0 0 0 0 0 0 0 0 0
38442- 0 0 0 0 0 0 0 0 0 0 0 0
38443- 0 0 0 0 0 0 0 0 0 0 0 0
38444- 0 0 0 0 0 0 0 0 0 0 0 0
38445- 0 0 0 0 0 0 0 0 0 0 0 0
38446- 0 0 0 0 0 0 0 0 0 0 0 0
38447- 0 0 0 0 0 0 0 0 0 0 0 0
38448- 0 0 0 0 0 0 0 0 0 0 0 0
38449- 0 0 0 0 0 0 0 0 0 0 0 0
38450- 0 0 1 0 0 0 0 0 0 0 0 0
38451- 0 0 0 0 0 0 0 0 0 0 0 0
38452- 0 0 0 0 0 0 0 0 0 0 0 0
38453- 0 0 0 0 0 0 0 0 0 0 0 0
38454- 0 0 0 0 0 0 0 0 0 0 0 0
38455- 0 0 0 0 0 0 0 0 0 0 0 0
38456- 0 0 0 0 0 0 0 0 0 10 10 10
38457- 22 22 22 42 42 42 66 66 66 86 86 86
38458- 66 66 66 38 38 38 38 38 38 22 22 22
38459- 26 26 26 34 34 34 54 54 54 66 66 66
38460- 86 86 86 70 70 70 46 46 46 26 26 26
38461- 14 14 14 6 6 6 0 0 0 0 0 0
38462- 0 0 0 0 0 0 0 0 0 0 0 0
38463- 0 0 0 0 0 0 0 0 0 0 0 0
38464- 0 0 0 0 0 0 0 0 0 0 0 0
38465- 0 0 0 0 0 0 0 0 0 0 0 0
38466- 0 0 0 0 0 0 0 0 0 0 0 0
38467- 0 0 0 0 0 0 0 0 0 0 0 0
38468- 0 0 0 0 0 0 0 0 0 0 0 0
38469- 0 0 0 0 0 0 0 0 0 0 0 0
38470- 0 0 1 0 0 1 0 0 1 0 0 0
38471- 0 0 0 0 0 0 0 0 0 0 0 0
38472- 0 0 0 0 0 0 0 0 0 0 0 0
38473- 0 0 0 0 0 0 0 0 0 0 0 0
38474- 0 0 0 0 0 0 0 0 0 0 0 0
38475- 0 0 0 0 0 0 0 0 0 0 0 0
38476- 0 0 0 0 0 0 10 10 10 26 26 26
38477- 50 50 50 82 82 82 58 58 58 6 6 6
38478- 2 2 6 2 2 6 2 2 6 2 2 6
38479- 2 2 6 2 2 6 2 2 6 2 2 6
38480- 6 6 6 54 54 54 86 86 86 66 66 66
38481- 38 38 38 18 18 18 6 6 6 0 0 0
38482- 0 0 0 0 0 0 0 0 0 0 0 0
38483- 0 0 0 0 0 0 0 0 0 0 0 0
38484- 0 0 0 0 0 0 0 0 0 0 0 0
38485- 0 0 0 0 0 0 0 0 0 0 0 0
38486- 0 0 0 0 0 0 0 0 0 0 0 0
38487- 0 0 0 0 0 0 0 0 0 0 0 0
38488- 0 0 0 0 0 0 0 0 0 0 0 0
38489- 0 0 0 0 0 0 0 0 0 0 0 0
38490- 0 0 0 0 0 0 0 0 0 0 0 0
38491- 0 0 0 0 0 0 0 0 0 0 0 0
38492- 0 0 0 0 0 0 0 0 0 0 0 0
38493- 0 0 0 0 0 0 0 0 0 0 0 0
38494- 0 0 0 0 0 0 0 0 0 0 0 0
38495- 0 0 0 0 0 0 0 0 0 0 0 0
38496- 0 0 0 6 6 6 22 22 22 50 50 50
38497- 78 78 78 34 34 34 2 2 6 2 2 6
38498- 2 2 6 2 2 6 2 2 6 2 2 6
38499- 2 2 6 2 2 6 2 2 6 2 2 6
38500- 2 2 6 2 2 6 6 6 6 70 70 70
38501- 78 78 78 46 46 46 22 22 22 6 6 6
38502- 0 0 0 0 0 0 0 0 0 0 0 0
38503- 0 0 0 0 0 0 0 0 0 0 0 0
38504- 0 0 0 0 0 0 0 0 0 0 0 0
38505- 0 0 0 0 0 0 0 0 0 0 0 0
38506- 0 0 0 0 0 0 0 0 0 0 0 0
38507- 0 0 0 0 0 0 0 0 0 0 0 0
38508- 0 0 0 0 0 0 0 0 0 0 0 0
38509- 0 0 0 0 0 0 0 0 0 0 0 0
38510- 0 0 1 0 0 1 0 0 1 0 0 0
38511- 0 0 0 0 0 0 0 0 0 0 0 0
38512- 0 0 0 0 0 0 0 0 0 0 0 0
38513- 0 0 0 0 0 0 0 0 0 0 0 0
38514- 0 0 0 0 0 0 0 0 0 0 0 0
38515- 0 0 0 0 0 0 0 0 0 0 0 0
38516- 6 6 6 18 18 18 42 42 42 82 82 82
38517- 26 26 26 2 2 6 2 2 6 2 2 6
38518- 2 2 6 2 2 6 2 2 6 2 2 6
38519- 2 2 6 2 2 6 2 2 6 14 14 14
38520- 46 46 46 34 34 34 6 6 6 2 2 6
38521- 42 42 42 78 78 78 42 42 42 18 18 18
38522- 6 6 6 0 0 0 0 0 0 0 0 0
38523- 0 0 0 0 0 0 0 0 0 0 0 0
38524- 0 0 0 0 0 0 0 0 0 0 0 0
38525- 0 0 0 0 0 0 0 0 0 0 0 0
38526- 0 0 0 0 0 0 0 0 0 0 0 0
38527- 0 0 0 0 0 0 0 0 0 0 0 0
38528- 0 0 0 0 0 0 0 0 0 0 0 0
38529- 0 0 0 0 0 0 0 0 0 0 0 0
38530- 0 0 1 0 0 0 0 0 1 0 0 0
38531- 0 0 0 0 0 0 0 0 0 0 0 0
38532- 0 0 0 0 0 0 0 0 0 0 0 0
38533- 0 0 0 0 0 0 0 0 0 0 0 0
38534- 0 0 0 0 0 0 0 0 0 0 0 0
38535- 0 0 0 0 0 0 0 0 0 0 0 0
38536- 10 10 10 30 30 30 66 66 66 58 58 58
38537- 2 2 6 2 2 6 2 2 6 2 2 6
38538- 2 2 6 2 2 6 2 2 6 2 2 6
38539- 2 2 6 2 2 6 2 2 6 26 26 26
38540- 86 86 86 101 101 101 46 46 46 10 10 10
38541- 2 2 6 58 58 58 70 70 70 34 34 34
38542- 10 10 10 0 0 0 0 0 0 0 0 0
38543- 0 0 0 0 0 0 0 0 0 0 0 0
38544- 0 0 0 0 0 0 0 0 0 0 0 0
38545- 0 0 0 0 0 0 0 0 0 0 0 0
38546- 0 0 0 0 0 0 0 0 0 0 0 0
38547- 0 0 0 0 0 0 0 0 0 0 0 0
38548- 0 0 0 0 0 0 0 0 0 0 0 0
38549- 0 0 0 0 0 0 0 0 0 0 0 0
38550- 0 0 1 0 0 1 0 0 1 0 0 0
38551- 0 0 0 0 0 0 0 0 0 0 0 0
38552- 0 0 0 0 0 0 0 0 0 0 0 0
38553- 0 0 0 0 0 0 0 0 0 0 0 0
38554- 0 0 0 0 0 0 0 0 0 0 0 0
38555- 0 0 0 0 0 0 0 0 0 0 0 0
38556- 14 14 14 42 42 42 86 86 86 10 10 10
38557- 2 2 6 2 2 6 2 2 6 2 2 6
38558- 2 2 6 2 2 6 2 2 6 2 2 6
38559- 2 2 6 2 2 6 2 2 6 30 30 30
38560- 94 94 94 94 94 94 58 58 58 26 26 26
38561- 2 2 6 6 6 6 78 78 78 54 54 54
38562- 22 22 22 6 6 6 0 0 0 0 0 0
38563- 0 0 0 0 0 0 0 0 0 0 0 0
38564- 0 0 0 0 0 0 0 0 0 0 0 0
38565- 0 0 0 0 0 0 0 0 0 0 0 0
38566- 0 0 0 0 0 0 0 0 0 0 0 0
38567- 0 0 0 0 0 0 0 0 0 0 0 0
38568- 0 0 0 0 0 0 0 0 0 0 0 0
38569- 0 0 0 0 0 0 0 0 0 0 0 0
38570- 0 0 0 0 0 0 0 0 0 0 0 0
38571- 0 0 0 0 0 0 0 0 0 0 0 0
38572- 0 0 0 0 0 0 0 0 0 0 0 0
38573- 0 0 0 0 0 0 0 0 0 0 0 0
38574- 0 0 0 0 0 0 0 0 0 0 0 0
38575- 0 0 0 0 0 0 0 0 0 6 6 6
38576- 22 22 22 62 62 62 62 62 62 2 2 6
38577- 2 2 6 2 2 6 2 2 6 2 2 6
38578- 2 2 6 2 2 6 2 2 6 2 2 6
38579- 2 2 6 2 2 6 2 2 6 26 26 26
38580- 54 54 54 38 38 38 18 18 18 10 10 10
38581- 2 2 6 2 2 6 34 34 34 82 82 82
38582- 38 38 38 14 14 14 0 0 0 0 0 0
38583- 0 0 0 0 0 0 0 0 0 0 0 0
38584- 0 0 0 0 0 0 0 0 0 0 0 0
38585- 0 0 0 0 0 0 0 0 0 0 0 0
38586- 0 0 0 0 0 0 0 0 0 0 0 0
38587- 0 0 0 0 0 0 0 0 0 0 0 0
38588- 0 0 0 0 0 0 0 0 0 0 0 0
38589- 0 0 0 0 0 0 0 0 0 0 0 0
38590- 0 0 0 0 0 1 0 0 1 0 0 0
38591- 0 0 0 0 0 0 0 0 0 0 0 0
38592- 0 0 0 0 0 0 0 0 0 0 0 0
38593- 0 0 0 0 0 0 0 0 0 0 0 0
38594- 0 0 0 0 0 0 0 0 0 0 0 0
38595- 0 0 0 0 0 0 0 0 0 6 6 6
38596- 30 30 30 78 78 78 30 30 30 2 2 6
38597- 2 2 6 2 2 6 2 2 6 2 2 6
38598- 2 2 6 2 2 6 2 2 6 2 2 6
38599- 2 2 6 2 2 6 2 2 6 10 10 10
38600- 10 10 10 2 2 6 2 2 6 2 2 6
38601- 2 2 6 2 2 6 2 2 6 78 78 78
38602- 50 50 50 18 18 18 6 6 6 0 0 0
38603- 0 0 0 0 0 0 0 0 0 0 0 0
38604- 0 0 0 0 0 0 0 0 0 0 0 0
38605- 0 0 0 0 0 0 0 0 0 0 0 0
38606- 0 0 0 0 0 0 0 0 0 0 0 0
38607- 0 0 0 0 0 0 0 0 0 0 0 0
38608- 0 0 0 0 0 0 0 0 0 0 0 0
38609- 0 0 0 0 0 0 0 0 0 0 0 0
38610- 0 0 1 0 0 0 0 0 0 0 0 0
38611- 0 0 0 0 0 0 0 0 0 0 0 0
38612- 0 0 0 0 0 0 0 0 0 0 0 0
38613- 0 0 0 0 0 0 0 0 0 0 0 0
38614- 0 0 0 0 0 0 0 0 0 0 0 0
38615- 0 0 0 0 0 0 0 0 0 10 10 10
38616- 38 38 38 86 86 86 14 14 14 2 2 6
38617- 2 2 6 2 2 6 2 2 6 2 2 6
38618- 2 2 6 2 2 6 2 2 6 2 2 6
38619- 2 2 6 2 2 6 2 2 6 2 2 6
38620- 2 2 6 2 2 6 2 2 6 2 2 6
38621- 2 2 6 2 2 6 2 2 6 54 54 54
38622- 66 66 66 26 26 26 6 6 6 0 0 0
38623- 0 0 0 0 0 0 0 0 0 0 0 0
38624- 0 0 0 0 0 0 0 0 0 0 0 0
38625- 0 0 0 0 0 0 0 0 0 0 0 0
38626- 0 0 0 0 0 0 0 0 0 0 0 0
38627- 0 0 0 0 0 0 0 0 0 0 0 0
38628- 0 0 0 0 0 0 0 0 0 0 0 0
38629- 0 0 0 0 0 0 0 0 0 0 0 0
38630- 0 0 0 0 0 1 0 0 1 0 0 0
38631- 0 0 0 0 0 0 0 0 0 0 0 0
38632- 0 0 0 0 0 0 0 0 0 0 0 0
38633- 0 0 0 0 0 0 0 0 0 0 0 0
38634- 0 0 0 0 0 0 0 0 0 0 0 0
38635- 0 0 0 0 0 0 0 0 0 14 14 14
38636- 42 42 42 82 82 82 2 2 6 2 2 6
38637- 2 2 6 6 6 6 10 10 10 2 2 6
38638- 2 2 6 2 2 6 2 2 6 2 2 6
38639- 2 2 6 2 2 6 2 2 6 6 6 6
38640- 14 14 14 10 10 10 2 2 6 2 2 6
38641- 2 2 6 2 2 6 2 2 6 18 18 18
38642- 82 82 82 34 34 34 10 10 10 0 0 0
38643- 0 0 0 0 0 0 0 0 0 0 0 0
38644- 0 0 0 0 0 0 0 0 0 0 0 0
38645- 0 0 0 0 0 0 0 0 0 0 0 0
38646- 0 0 0 0 0 0 0 0 0 0 0 0
38647- 0 0 0 0 0 0 0 0 0 0 0 0
38648- 0 0 0 0 0 0 0 0 0 0 0 0
38649- 0 0 0 0 0 0 0 0 0 0 0 0
38650- 0 0 1 0 0 0 0 0 0 0 0 0
38651- 0 0 0 0 0 0 0 0 0 0 0 0
38652- 0 0 0 0 0 0 0 0 0 0 0 0
38653- 0 0 0 0 0 0 0 0 0 0 0 0
38654- 0 0 0 0 0 0 0 0 0 0 0 0
38655- 0 0 0 0 0 0 0 0 0 14 14 14
38656- 46 46 46 86 86 86 2 2 6 2 2 6
38657- 6 6 6 6 6 6 22 22 22 34 34 34
38658- 6 6 6 2 2 6 2 2 6 2 2 6
38659- 2 2 6 2 2 6 18 18 18 34 34 34
38660- 10 10 10 50 50 50 22 22 22 2 2 6
38661- 2 2 6 2 2 6 2 2 6 10 10 10
38662- 86 86 86 42 42 42 14 14 14 0 0 0
38663- 0 0 0 0 0 0 0 0 0 0 0 0
38664- 0 0 0 0 0 0 0 0 0 0 0 0
38665- 0 0 0 0 0 0 0 0 0 0 0 0
38666- 0 0 0 0 0 0 0 0 0 0 0 0
38667- 0 0 0 0 0 0 0 0 0 0 0 0
38668- 0 0 0 0 0 0 0 0 0 0 0 0
38669- 0 0 0 0 0 0 0 0 0 0 0 0
38670- 0 0 1 0 0 1 0 0 1 0 0 0
38671- 0 0 0 0 0 0 0 0 0 0 0 0
38672- 0 0 0 0 0 0 0 0 0 0 0 0
38673- 0 0 0 0 0 0 0 0 0 0 0 0
38674- 0 0 0 0 0 0 0 0 0 0 0 0
38675- 0 0 0 0 0 0 0 0 0 14 14 14
38676- 46 46 46 86 86 86 2 2 6 2 2 6
38677- 38 38 38 116 116 116 94 94 94 22 22 22
38678- 22 22 22 2 2 6 2 2 6 2 2 6
38679- 14 14 14 86 86 86 138 138 138 162 162 162
38680-154 154 154 38 38 38 26 26 26 6 6 6
38681- 2 2 6 2 2 6 2 2 6 2 2 6
38682- 86 86 86 46 46 46 14 14 14 0 0 0
38683- 0 0 0 0 0 0 0 0 0 0 0 0
38684- 0 0 0 0 0 0 0 0 0 0 0 0
38685- 0 0 0 0 0 0 0 0 0 0 0 0
38686- 0 0 0 0 0 0 0 0 0 0 0 0
38687- 0 0 0 0 0 0 0 0 0 0 0 0
38688- 0 0 0 0 0 0 0 0 0 0 0 0
38689- 0 0 0 0 0 0 0 0 0 0 0 0
38690- 0 0 0 0 0 0 0 0 0 0 0 0
38691- 0 0 0 0 0 0 0 0 0 0 0 0
38692- 0 0 0 0 0 0 0 0 0 0 0 0
38693- 0 0 0 0 0 0 0 0 0 0 0 0
38694- 0 0 0 0 0 0 0 0 0 0 0 0
38695- 0 0 0 0 0 0 0 0 0 14 14 14
38696- 46 46 46 86 86 86 2 2 6 14 14 14
38697-134 134 134 198 198 198 195 195 195 116 116 116
38698- 10 10 10 2 2 6 2 2 6 6 6 6
38699-101 98 89 187 187 187 210 210 210 218 218 218
38700-214 214 214 134 134 134 14 14 14 6 6 6
38701- 2 2 6 2 2 6 2 2 6 2 2 6
38702- 86 86 86 50 50 50 18 18 18 6 6 6
38703- 0 0 0 0 0 0 0 0 0 0 0 0
38704- 0 0 0 0 0 0 0 0 0 0 0 0
38705- 0 0 0 0 0 0 0 0 0 0 0 0
38706- 0 0 0 0 0 0 0 0 0 0 0 0
38707- 0 0 0 0 0 0 0 0 0 0 0 0
38708- 0 0 0 0 0 0 0 0 0 0 0 0
38709- 0 0 0 0 0 0 0 0 1 0 0 0
38710- 0 0 1 0 0 1 0 0 1 0 0 0
38711- 0 0 0 0 0 0 0 0 0 0 0 0
38712- 0 0 0 0 0 0 0 0 0 0 0 0
38713- 0 0 0 0 0 0 0 0 0 0 0 0
38714- 0 0 0 0 0 0 0 0 0 0 0 0
38715- 0 0 0 0 0 0 0 0 0 14 14 14
38716- 46 46 46 86 86 86 2 2 6 54 54 54
38717-218 218 218 195 195 195 226 226 226 246 246 246
38718- 58 58 58 2 2 6 2 2 6 30 30 30
38719-210 210 210 253 253 253 174 174 174 123 123 123
38720-221 221 221 234 234 234 74 74 74 2 2 6
38721- 2 2 6 2 2 6 2 2 6 2 2 6
38722- 70 70 70 58 58 58 22 22 22 6 6 6
38723- 0 0 0 0 0 0 0 0 0 0 0 0
38724- 0 0 0 0 0 0 0 0 0 0 0 0
38725- 0 0 0 0 0 0 0 0 0 0 0 0
38726- 0 0 0 0 0 0 0 0 0 0 0 0
38727- 0 0 0 0 0 0 0 0 0 0 0 0
38728- 0 0 0 0 0 0 0 0 0 0 0 0
38729- 0 0 0 0 0 0 0 0 0 0 0 0
38730- 0 0 0 0 0 0 0 0 0 0 0 0
38731- 0 0 0 0 0 0 0 0 0 0 0 0
38732- 0 0 0 0 0 0 0 0 0 0 0 0
38733- 0 0 0 0 0 0 0 0 0 0 0 0
38734- 0 0 0 0 0 0 0 0 0 0 0 0
38735- 0 0 0 0 0 0 0 0 0 14 14 14
38736- 46 46 46 82 82 82 2 2 6 106 106 106
38737-170 170 170 26 26 26 86 86 86 226 226 226
38738-123 123 123 10 10 10 14 14 14 46 46 46
38739-231 231 231 190 190 190 6 6 6 70 70 70
38740- 90 90 90 238 238 238 158 158 158 2 2 6
38741- 2 2 6 2 2 6 2 2 6 2 2 6
38742- 70 70 70 58 58 58 22 22 22 6 6 6
38743- 0 0 0 0 0 0 0 0 0 0 0 0
38744- 0 0 0 0 0 0 0 0 0 0 0 0
38745- 0 0 0 0 0 0 0 0 0 0 0 0
38746- 0 0 0 0 0 0 0 0 0 0 0 0
38747- 0 0 0 0 0 0 0 0 0 0 0 0
38748- 0 0 0 0 0 0 0 0 0 0 0 0
38749- 0 0 0 0 0 0 0 0 1 0 0 0
38750- 0 0 1 0 0 1 0 0 1 0 0 0
38751- 0 0 0 0 0 0 0 0 0 0 0 0
38752- 0 0 0 0 0 0 0 0 0 0 0 0
38753- 0 0 0 0 0 0 0 0 0 0 0 0
38754- 0 0 0 0 0 0 0 0 0 0 0 0
38755- 0 0 0 0 0 0 0 0 0 14 14 14
38756- 42 42 42 86 86 86 6 6 6 116 116 116
38757-106 106 106 6 6 6 70 70 70 149 149 149
38758-128 128 128 18 18 18 38 38 38 54 54 54
38759-221 221 221 106 106 106 2 2 6 14 14 14
38760- 46 46 46 190 190 190 198 198 198 2 2 6
38761- 2 2 6 2 2 6 2 2 6 2 2 6
38762- 74 74 74 62 62 62 22 22 22 6 6 6
38763- 0 0 0 0 0 0 0 0 0 0 0 0
38764- 0 0 0 0 0 0 0 0 0 0 0 0
38765- 0 0 0 0 0 0 0 0 0 0 0 0
38766- 0 0 0 0 0 0 0 0 0 0 0 0
38767- 0 0 0 0 0 0 0 0 0 0 0 0
38768- 0 0 0 0 0 0 0 0 0 0 0 0
38769- 0 0 0 0 0 0 0 0 1 0 0 0
38770- 0 0 1 0 0 0 0 0 1 0 0 0
38771- 0 0 0 0 0 0 0 0 0 0 0 0
38772- 0 0 0 0 0 0 0 0 0 0 0 0
38773- 0 0 0 0 0 0 0 0 0 0 0 0
38774- 0 0 0 0 0 0 0 0 0 0 0 0
38775- 0 0 0 0 0 0 0 0 0 14 14 14
38776- 42 42 42 94 94 94 14 14 14 101 101 101
38777-128 128 128 2 2 6 18 18 18 116 116 116
38778-118 98 46 121 92 8 121 92 8 98 78 10
38779-162 162 162 106 106 106 2 2 6 2 2 6
38780- 2 2 6 195 195 195 195 195 195 6 6 6
38781- 2 2 6 2 2 6 2 2 6 2 2 6
38782- 74 74 74 62 62 62 22 22 22 6 6 6
38783- 0 0 0 0 0 0 0 0 0 0 0 0
38784- 0 0 0 0 0 0 0 0 0 0 0 0
38785- 0 0 0 0 0 0 0 0 0 0 0 0
38786- 0 0 0 0 0 0 0 0 0 0 0 0
38787- 0 0 0 0 0 0 0 0 0 0 0 0
38788- 0 0 0 0 0 0 0 0 0 0 0 0
38789- 0 0 0 0 0 0 0 0 1 0 0 1
38790- 0 0 1 0 0 0 0 0 1 0 0 0
38791- 0 0 0 0 0 0 0 0 0 0 0 0
38792- 0 0 0 0 0 0 0 0 0 0 0 0
38793- 0 0 0 0 0 0 0 0 0 0 0 0
38794- 0 0 0 0 0 0 0 0 0 0 0 0
38795- 0 0 0 0 0 0 0 0 0 10 10 10
38796- 38 38 38 90 90 90 14 14 14 58 58 58
38797-210 210 210 26 26 26 54 38 6 154 114 10
38798-226 170 11 236 186 11 225 175 15 184 144 12
38799-215 174 15 175 146 61 37 26 9 2 2 6
38800- 70 70 70 246 246 246 138 138 138 2 2 6
38801- 2 2 6 2 2 6 2 2 6 2 2 6
38802- 70 70 70 66 66 66 26 26 26 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
38806- 0 0 0 0 0 0 0 0 0 0 0 0
38807- 0 0 0 0 0 0 0 0 0 0 0 0
38808- 0 0 0 0 0 0 0 0 0 0 0 0
38809- 0 0 0 0 0 0 0 0 0 0 0 0
38810- 0 0 0 0 0 0 0 0 0 0 0 0
38811- 0 0 0 0 0 0 0 0 0 0 0 0
38812- 0 0 0 0 0 0 0 0 0 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 10 10 10
38816- 38 38 38 86 86 86 14 14 14 10 10 10
38817-195 195 195 188 164 115 192 133 9 225 175 15
38818-239 182 13 234 190 10 232 195 16 232 200 30
38819-245 207 45 241 208 19 232 195 16 184 144 12
38820-218 194 134 211 206 186 42 42 42 2 2 6
38821- 2 2 6 2 2 6 2 2 6 2 2 6
38822- 50 50 50 74 74 74 30 30 30 6 6 6
38823- 0 0 0 0 0 0 0 0 0 0 0 0
38824- 0 0 0 0 0 0 0 0 0 0 0 0
38825- 0 0 0 0 0 0 0 0 0 0 0 0
38826- 0 0 0 0 0 0 0 0 0 0 0 0
38827- 0 0 0 0 0 0 0 0 0 0 0 0
38828- 0 0 0 0 0 0 0 0 0 0 0 0
38829- 0 0 0 0 0 0 0 0 0 0 0 0
38830- 0 0 0 0 0 0 0 0 0 0 0 0
38831- 0 0 0 0 0 0 0 0 0 0 0 0
38832- 0 0 0 0 0 0 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 10 10 10
38836- 34 34 34 86 86 86 14 14 14 2 2 6
38837-121 87 25 192 133 9 219 162 10 239 182 13
38838-236 186 11 232 195 16 241 208 19 244 214 54
38839-246 218 60 246 218 38 246 215 20 241 208 19
38840-241 208 19 226 184 13 121 87 25 2 2 6
38841- 2 2 6 2 2 6 2 2 6 2 2 6
38842- 50 50 50 82 82 82 34 34 34 10 10 10
38843- 0 0 0 0 0 0 0 0 0 0 0 0
38844- 0 0 0 0 0 0 0 0 0 0 0 0
38845- 0 0 0 0 0 0 0 0 0 0 0 0
38846- 0 0 0 0 0 0 0 0 0 0 0 0
38847- 0 0 0 0 0 0 0 0 0 0 0 0
38848- 0 0 0 0 0 0 0 0 0 0 0 0
38849- 0 0 0 0 0 0 0 0 0 0 0 0
38850- 0 0 0 0 0 0 0 0 0 0 0 0
38851- 0 0 0 0 0 0 0 0 0 0 0 0
38852- 0 0 0 0 0 0 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 10 10 10
38856- 34 34 34 82 82 82 30 30 30 61 42 6
38857-180 123 7 206 145 10 230 174 11 239 182 13
38858-234 190 10 238 202 15 241 208 19 246 218 74
38859-246 218 38 246 215 20 246 215 20 246 215 20
38860-226 184 13 215 174 15 184 144 12 6 6 6
38861- 2 2 6 2 2 6 2 2 6 2 2 6
38862- 26 26 26 94 94 94 42 42 42 14 14 14
38863- 0 0 0 0 0 0 0 0 0 0 0 0
38864- 0 0 0 0 0 0 0 0 0 0 0 0
38865- 0 0 0 0 0 0 0 0 0 0 0 0
38866- 0 0 0 0 0 0 0 0 0 0 0 0
38867- 0 0 0 0 0 0 0 0 0 0 0 0
38868- 0 0 0 0 0 0 0 0 0 0 0 0
38869- 0 0 0 0 0 0 0 0 0 0 0 0
38870- 0 0 0 0 0 0 0 0 0 0 0 0
38871- 0 0 0 0 0 0 0 0 0 0 0 0
38872- 0 0 0 0 0 0 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 10 10 10
38876- 30 30 30 78 78 78 50 50 50 104 69 6
38877-192 133 9 216 158 10 236 178 12 236 186 11
38878-232 195 16 241 208 19 244 214 54 245 215 43
38879-246 215 20 246 215 20 241 208 19 198 155 10
38880-200 144 11 216 158 10 156 118 10 2 2 6
38881- 2 2 6 2 2 6 2 2 6 2 2 6
38882- 6 6 6 90 90 90 54 54 54 18 18 18
38883- 6 6 6 0 0 0 0 0 0 0 0 0
38884- 0 0 0 0 0 0 0 0 0 0 0 0
38885- 0 0 0 0 0 0 0 0 0 0 0 0
38886- 0 0 0 0 0 0 0 0 0 0 0 0
38887- 0 0 0 0 0 0 0 0 0 0 0 0
38888- 0 0 0 0 0 0 0 0 0 0 0 0
38889- 0 0 0 0 0 0 0 0 0 0 0 0
38890- 0 0 0 0 0 0 0 0 0 0 0 0
38891- 0 0 0 0 0 0 0 0 0 0 0 0
38892- 0 0 0 0 0 0 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 10 10 10
38896- 30 30 30 78 78 78 46 46 46 22 22 22
38897-137 92 6 210 162 10 239 182 13 238 190 10
38898-238 202 15 241 208 19 246 215 20 246 215 20
38899-241 208 19 203 166 17 185 133 11 210 150 10
38900-216 158 10 210 150 10 102 78 10 2 2 6
38901- 6 6 6 54 54 54 14 14 14 2 2 6
38902- 2 2 6 62 62 62 74 74 74 30 30 30
38903- 10 10 10 0 0 0 0 0 0 0 0 0
38904- 0 0 0 0 0 0 0 0 0 0 0 0
38905- 0 0 0 0 0 0 0 0 0 0 0 0
38906- 0 0 0 0 0 0 0 0 0 0 0 0
38907- 0 0 0 0 0 0 0 0 0 0 0 0
38908- 0 0 0 0 0 0 0 0 0 0 0 0
38909- 0 0 0 0 0 0 0 0 0 0 0 0
38910- 0 0 0 0 0 0 0 0 0 0 0 0
38911- 0 0 0 0 0 0 0 0 0 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 10 10 10
38916- 34 34 34 78 78 78 50 50 50 6 6 6
38917- 94 70 30 139 102 15 190 146 13 226 184 13
38918-232 200 30 232 195 16 215 174 15 190 146 13
38919-168 122 10 192 133 9 210 150 10 213 154 11
38920-202 150 34 182 157 106 101 98 89 2 2 6
38921- 2 2 6 78 78 78 116 116 116 58 58 58
38922- 2 2 6 22 22 22 90 90 90 46 46 46
38923- 18 18 18 6 6 6 0 0 0 0 0 0
38924- 0 0 0 0 0 0 0 0 0 0 0 0
38925- 0 0 0 0 0 0 0 0 0 0 0 0
38926- 0 0 0 0 0 0 0 0 0 0 0 0
38927- 0 0 0 0 0 0 0 0 0 0 0 0
38928- 0 0 0 0 0 0 0 0 0 0 0 0
38929- 0 0 0 0 0 0 0 0 0 0 0 0
38930- 0 0 0 0 0 0 0 0 0 0 0 0
38931- 0 0 0 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 10 10 10
38936- 38 38 38 86 86 86 50 50 50 6 6 6
38937-128 128 128 174 154 114 156 107 11 168 122 10
38938-198 155 10 184 144 12 197 138 11 200 144 11
38939-206 145 10 206 145 10 197 138 11 188 164 115
38940-195 195 195 198 198 198 174 174 174 14 14 14
38941- 2 2 6 22 22 22 116 116 116 116 116 116
38942- 22 22 22 2 2 6 74 74 74 70 70 70
38943- 30 30 30 10 10 10 0 0 0 0 0 0
38944- 0 0 0 0 0 0 0 0 0 0 0 0
38945- 0 0 0 0 0 0 0 0 0 0 0 0
38946- 0 0 0 0 0 0 0 0 0 0 0 0
38947- 0 0 0 0 0 0 0 0 0 0 0 0
38948- 0 0 0 0 0 0 0 0 0 0 0 0
38949- 0 0 0 0 0 0 0 0 0 0 0 0
38950- 0 0 0 0 0 0 0 0 0 0 0 0
38951- 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 6 6 6 18 18 18
38956- 50 50 50 101 101 101 26 26 26 10 10 10
38957-138 138 138 190 190 190 174 154 114 156 107 11
38958-197 138 11 200 144 11 197 138 11 192 133 9
38959-180 123 7 190 142 34 190 178 144 187 187 187
38960-202 202 202 221 221 221 214 214 214 66 66 66
38961- 2 2 6 2 2 6 50 50 50 62 62 62
38962- 6 6 6 2 2 6 10 10 10 90 90 90
38963- 50 50 50 18 18 18 6 6 6 0 0 0
38964- 0 0 0 0 0 0 0 0 0 0 0 0
38965- 0 0 0 0 0 0 0 0 0 0 0 0
38966- 0 0 0 0 0 0 0 0 0 0 0 0
38967- 0 0 0 0 0 0 0 0 0 0 0 0
38968- 0 0 0 0 0 0 0 0 0 0 0 0
38969- 0 0 0 0 0 0 0 0 0 0 0 0
38970- 0 0 0 0 0 0 0 0 0 0 0 0
38971- 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 10 10 10 34 34 34
38976- 74 74 74 74 74 74 2 2 6 6 6 6
38977-144 144 144 198 198 198 190 190 190 178 166 146
38978-154 121 60 156 107 11 156 107 11 168 124 44
38979-174 154 114 187 187 187 190 190 190 210 210 210
38980-246 246 246 253 253 253 253 253 253 182 182 182
38981- 6 6 6 2 2 6 2 2 6 2 2 6
38982- 2 2 6 2 2 6 2 2 6 62 62 62
38983- 74 74 74 34 34 34 14 14 14 0 0 0
38984- 0 0 0 0 0 0 0 0 0 0 0 0
38985- 0 0 0 0 0 0 0 0 0 0 0 0
38986- 0 0 0 0 0 0 0 0 0 0 0 0
38987- 0 0 0 0 0 0 0 0 0 0 0 0
38988- 0 0 0 0 0 0 0 0 0 0 0 0
38989- 0 0 0 0 0 0 0 0 0 0 0 0
38990- 0 0 0 0 0 0 0 0 0 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 10 10 10 22 22 22 54 54 54
38996- 94 94 94 18 18 18 2 2 6 46 46 46
38997-234 234 234 221 221 221 190 190 190 190 190 190
38998-190 190 190 187 187 187 187 187 187 190 190 190
38999-190 190 190 195 195 195 214 214 214 242 242 242
39000-253 253 253 253 253 253 253 253 253 253 253 253
39001- 82 82 82 2 2 6 2 2 6 2 2 6
39002- 2 2 6 2 2 6 2 2 6 14 14 14
39003- 86 86 86 54 54 54 22 22 22 6 6 6
39004- 0 0 0 0 0 0 0 0 0 0 0 0
39005- 0 0 0 0 0 0 0 0 0 0 0 0
39006- 0 0 0 0 0 0 0 0 0 0 0 0
39007- 0 0 0 0 0 0 0 0 0 0 0 0
39008- 0 0 0 0 0 0 0 0 0 0 0 0
39009- 0 0 0 0 0 0 0 0 0 0 0 0
39010- 0 0 0 0 0 0 0 0 0 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- 6 6 6 18 18 18 46 46 46 90 90 90
39016- 46 46 46 18 18 18 6 6 6 182 182 182
39017-253 253 253 246 246 246 206 206 206 190 190 190
39018-190 190 190 190 190 190 190 190 190 190 190 190
39019-206 206 206 231 231 231 250 250 250 253 253 253
39020-253 253 253 253 253 253 253 253 253 253 253 253
39021-202 202 202 14 14 14 2 2 6 2 2 6
39022- 2 2 6 2 2 6 2 2 6 2 2 6
39023- 42 42 42 86 86 86 42 42 42 18 18 18
39024- 6 6 6 0 0 0 0 0 0 0 0 0
39025- 0 0 0 0 0 0 0 0 0 0 0 0
39026- 0 0 0 0 0 0 0 0 0 0 0 0
39027- 0 0 0 0 0 0 0 0 0 0 0 0
39028- 0 0 0 0 0 0 0 0 0 0 0 0
39029- 0 0 0 0 0 0 0 0 0 0 0 0
39030- 0 0 0 0 0 0 0 0 0 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 6 6 6
39035- 14 14 14 38 38 38 74 74 74 66 66 66
39036- 2 2 6 6 6 6 90 90 90 250 250 250
39037-253 253 253 253 253 253 238 238 238 198 198 198
39038-190 190 190 190 190 190 195 195 195 221 221 221
39039-246 246 246 253 253 253 253 253 253 253 253 253
39040-253 253 253 253 253 253 253 253 253 253 253 253
39041-253 253 253 82 82 82 2 2 6 2 2 6
39042- 2 2 6 2 2 6 2 2 6 2 2 6
39043- 2 2 6 78 78 78 70 70 70 34 34 34
39044- 14 14 14 6 6 6 0 0 0 0 0 0
39045- 0 0 0 0 0 0 0 0 0 0 0 0
39046- 0 0 0 0 0 0 0 0 0 0 0 0
39047- 0 0 0 0 0 0 0 0 0 0 0 0
39048- 0 0 0 0 0 0 0 0 0 0 0 0
39049- 0 0 0 0 0 0 0 0 0 0 0 0
39050- 0 0 0 0 0 0 0 0 0 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 14 14 14
39055- 34 34 34 66 66 66 78 78 78 6 6 6
39056- 2 2 6 18 18 18 218 218 218 253 253 253
39057-253 253 253 253 253 253 253 253 253 246 246 246
39058-226 226 226 231 231 231 246 246 246 253 253 253
39059-253 253 253 253 253 253 253 253 253 253 253 253
39060-253 253 253 253 253 253 253 253 253 253 253 253
39061-253 253 253 178 178 178 2 2 6 2 2 6
39062- 2 2 6 2 2 6 2 2 6 2 2 6
39063- 2 2 6 18 18 18 90 90 90 62 62 62
39064- 30 30 30 10 10 10 0 0 0 0 0 0
39065- 0 0 0 0 0 0 0 0 0 0 0 0
39066- 0 0 0 0 0 0 0 0 0 0 0 0
39067- 0 0 0 0 0 0 0 0 0 0 0 0
39068- 0 0 0 0 0 0 0 0 0 0 0 0
39069- 0 0 0 0 0 0 0 0 0 0 0 0
39070- 0 0 0 0 0 0 0 0 0 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 10 10 10 26 26 26
39075- 58 58 58 90 90 90 18 18 18 2 2 6
39076- 2 2 6 110 110 110 253 253 253 253 253 253
39077-253 253 253 253 253 253 253 253 253 253 253 253
39078-250 250 250 253 253 253 253 253 253 253 253 253
39079-253 253 253 253 253 253 253 253 253 253 253 253
39080-253 253 253 253 253 253 253 253 253 253 253 253
39081-253 253 253 231 231 231 18 18 18 2 2 6
39082- 2 2 6 2 2 6 2 2 6 2 2 6
39083- 2 2 6 2 2 6 18 18 18 94 94 94
39084- 54 54 54 26 26 26 10 10 10 0 0 0
39085- 0 0 0 0 0 0 0 0 0 0 0 0
39086- 0 0 0 0 0 0 0 0 0 0 0 0
39087- 0 0 0 0 0 0 0 0 0 0 0 0
39088- 0 0 0 0 0 0 0 0 0 0 0 0
39089- 0 0 0 0 0 0 0 0 0 0 0 0
39090- 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
39095- 90 90 90 26 26 26 2 2 6 2 2 6
39096- 14 14 14 195 195 195 250 250 250 253 253 253
39097-253 253 253 253 253 253 253 253 253 253 253 253
39098-253 253 253 253 253 253 253 253 253 253 253 253
39099-253 253 253 253 253 253 253 253 253 253 253 253
39100-253 253 253 253 253 253 253 253 253 253 253 253
39101-250 250 250 242 242 242 54 54 54 2 2 6
39102- 2 2 6 2 2 6 2 2 6 2 2 6
39103- 2 2 6 2 2 6 2 2 6 38 38 38
39104- 86 86 86 50 50 50 22 22 22 6 6 6
39105- 0 0 0 0 0 0 0 0 0 0 0 0
39106- 0 0 0 0 0 0 0 0 0 0 0 0
39107- 0 0 0 0 0 0 0 0 0 0 0 0
39108- 0 0 0 0 0 0 0 0 0 0 0 0
39109- 0 0 0 0 0 0 0 0 0 0 0 0
39110- 0 0 0 0 0 0 0 0 0 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- 6 6 6 14 14 14 38 38 38 82 82 82
39115- 34 34 34 2 2 6 2 2 6 2 2 6
39116- 42 42 42 195 195 195 246 246 246 253 253 253
39117-253 253 253 253 253 253 253 253 253 250 250 250
39118-242 242 242 242 242 242 250 250 250 253 253 253
39119-253 253 253 253 253 253 253 253 253 253 253 253
39120-253 253 253 250 250 250 246 246 246 238 238 238
39121-226 226 226 231 231 231 101 101 101 6 6 6
39122- 2 2 6 2 2 6 2 2 6 2 2 6
39123- 2 2 6 2 2 6 2 2 6 2 2 6
39124- 38 38 38 82 82 82 42 42 42 14 14 14
39125- 6 6 6 0 0 0 0 0 0 0 0 0
39126- 0 0 0 0 0 0 0 0 0 0 0 0
39127- 0 0 0 0 0 0 0 0 0 0 0 0
39128- 0 0 0 0 0 0 0 0 0 0 0 0
39129- 0 0 0 0 0 0 0 0 0 0 0 0
39130- 0 0 0 0 0 0 0 0 0 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- 10 10 10 26 26 26 62 62 62 66 66 66
39135- 2 2 6 2 2 6 2 2 6 6 6 6
39136- 70 70 70 170 170 170 206 206 206 234 234 234
39137-246 246 246 250 250 250 250 250 250 238 238 238
39138-226 226 226 231 231 231 238 238 238 250 250 250
39139-250 250 250 250 250 250 246 246 246 231 231 231
39140-214 214 214 206 206 206 202 202 202 202 202 202
39141-198 198 198 202 202 202 182 182 182 18 18 18
39142- 2 2 6 2 2 6 2 2 6 2 2 6
39143- 2 2 6 2 2 6 2 2 6 2 2 6
39144- 2 2 6 62 62 62 66 66 66 30 30 30
39145- 10 10 10 0 0 0 0 0 0 0 0 0
39146- 0 0 0 0 0 0 0 0 0 0 0 0
39147- 0 0 0 0 0 0 0 0 0 0 0 0
39148- 0 0 0 0 0 0 0 0 0 0 0 0
39149- 0 0 0 0 0 0 0 0 0 0 0 0
39150- 0 0 0 0 0 0 0 0 0 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- 14 14 14 42 42 42 82 82 82 18 18 18
39155- 2 2 6 2 2 6 2 2 6 10 10 10
39156- 94 94 94 182 182 182 218 218 218 242 242 242
39157-250 250 250 253 253 253 253 253 253 250 250 250
39158-234 234 234 253 253 253 253 253 253 253 253 253
39159-253 253 253 253 253 253 253 253 253 246 246 246
39160-238 238 238 226 226 226 210 210 210 202 202 202
39161-195 195 195 195 195 195 210 210 210 158 158 158
39162- 6 6 6 14 14 14 50 50 50 14 14 14
39163- 2 2 6 2 2 6 2 2 6 2 2 6
39164- 2 2 6 6 6 6 86 86 86 46 46 46
39165- 18 18 18 6 6 6 0 0 0 0 0 0
39166- 0 0 0 0 0 0 0 0 0 0 0 0
39167- 0 0 0 0 0 0 0 0 0 0 0 0
39168- 0 0 0 0 0 0 0 0 0 0 0 0
39169- 0 0 0 0 0 0 0 0 0 0 0 0
39170- 0 0 0 0 0 0 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 6 6 6
39174- 22 22 22 54 54 54 70 70 70 2 2 6
39175- 2 2 6 10 10 10 2 2 6 22 22 22
39176-166 166 166 231 231 231 250 250 250 253 253 253
39177-253 253 253 253 253 253 253 253 253 250 250 250
39178-242 242 242 253 253 253 253 253 253 253 253 253
39179-253 253 253 253 253 253 253 253 253 253 253 253
39180-253 253 253 253 253 253 253 253 253 246 246 246
39181-231 231 231 206 206 206 198 198 198 226 226 226
39182- 94 94 94 2 2 6 6 6 6 38 38 38
39183- 30 30 30 2 2 6 2 2 6 2 2 6
39184- 2 2 6 2 2 6 62 62 62 66 66 66
39185- 26 26 26 10 10 10 0 0 0 0 0 0
39186- 0 0 0 0 0 0 0 0 0 0 0 0
39187- 0 0 0 0 0 0 0 0 0 0 0 0
39188- 0 0 0 0 0 0 0 0 0 0 0 0
39189- 0 0 0 0 0 0 0 0 0 0 0 0
39190- 0 0 0 0 0 0 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 10 10 10
39194- 30 30 30 74 74 74 50 50 50 2 2 6
39195- 26 26 26 26 26 26 2 2 6 106 106 106
39196-238 238 238 253 253 253 253 253 253 253 253 253
39197-253 253 253 253 253 253 253 253 253 253 253 253
39198-253 253 253 253 253 253 253 253 253 253 253 253
39199-253 253 253 253 253 253 253 253 253 253 253 253
39200-253 253 253 253 253 253 253 253 253 253 253 253
39201-253 253 253 246 246 246 218 218 218 202 202 202
39202-210 210 210 14 14 14 2 2 6 2 2 6
39203- 30 30 30 22 22 22 2 2 6 2 2 6
39204- 2 2 6 2 2 6 18 18 18 86 86 86
39205- 42 42 42 14 14 14 0 0 0 0 0 0
39206- 0 0 0 0 0 0 0 0 0 0 0 0
39207- 0 0 0 0 0 0 0 0 0 0 0 0
39208- 0 0 0 0 0 0 0 0 0 0 0 0
39209- 0 0 0 0 0 0 0 0 0 0 0 0
39210- 0 0 0 0 0 0 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 14 14 14
39214- 42 42 42 90 90 90 22 22 22 2 2 6
39215- 42 42 42 2 2 6 18 18 18 218 218 218
39216-253 253 253 253 253 253 253 253 253 253 253 253
39217-253 253 253 253 253 253 253 253 253 253 253 253
39218-253 253 253 253 253 253 253 253 253 253 253 253
39219-253 253 253 253 253 253 253 253 253 253 253 253
39220-253 253 253 253 253 253 253 253 253 253 253 253
39221-253 253 253 253 253 253 250 250 250 221 221 221
39222-218 218 218 101 101 101 2 2 6 14 14 14
39223- 18 18 18 38 38 38 10 10 10 2 2 6
39224- 2 2 6 2 2 6 2 2 6 78 78 78
39225- 58 58 58 22 22 22 6 6 6 0 0 0
39226- 0 0 0 0 0 0 0 0 0 0 0 0
39227- 0 0 0 0 0 0 0 0 0 0 0 0
39228- 0 0 0 0 0 0 0 0 0 0 0 0
39229- 0 0 0 0 0 0 0 0 0 0 0 0
39230- 0 0 0 0 0 0 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 6 6 6 18 18 18
39234- 54 54 54 82 82 82 2 2 6 26 26 26
39235- 22 22 22 2 2 6 123 123 123 253 253 253
39236-253 253 253 253 253 253 253 253 253 253 253 253
39237-253 253 253 253 253 253 253 253 253 253 253 253
39238-253 253 253 253 253 253 253 253 253 253 253 253
39239-253 253 253 253 253 253 253 253 253 253 253 253
39240-253 253 253 253 253 253 253 253 253 253 253 253
39241-253 253 253 253 253 253 253 253 253 250 250 250
39242-238 238 238 198 198 198 6 6 6 38 38 38
39243- 58 58 58 26 26 26 38 38 38 2 2 6
39244- 2 2 6 2 2 6 2 2 6 46 46 46
39245- 78 78 78 30 30 30 10 10 10 0 0 0
39246- 0 0 0 0 0 0 0 0 0 0 0 0
39247- 0 0 0 0 0 0 0 0 0 0 0 0
39248- 0 0 0 0 0 0 0 0 0 0 0 0
39249- 0 0 0 0 0 0 0 0 0 0 0 0
39250- 0 0 0 0 0 0 0 0 0 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 10 10 10 30 30 30
39254- 74 74 74 58 58 58 2 2 6 42 42 42
39255- 2 2 6 22 22 22 231 231 231 253 253 253
39256-253 253 253 253 253 253 253 253 253 253 253 253
39257-253 253 253 253 253 253 253 253 253 250 250 250
39258-253 253 253 253 253 253 253 253 253 253 253 253
39259-253 253 253 253 253 253 253 253 253 253 253 253
39260-253 253 253 253 253 253 253 253 253 253 253 253
39261-253 253 253 253 253 253 253 253 253 253 253 253
39262-253 253 253 246 246 246 46 46 46 38 38 38
39263- 42 42 42 14 14 14 38 38 38 14 14 14
39264- 2 2 6 2 2 6 2 2 6 6 6 6
39265- 86 86 86 46 46 46 14 14 14 0 0 0
39266- 0 0 0 0 0 0 0 0 0 0 0 0
39267- 0 0 0 0 0 0 0 0 0 0 0 0
39268- 0 0 0 0 0 0 0 0 0 0 0 0
39269- 0 0 0 0 0 0 0 0 0 0 0 0
39270- 0 0 0 0 0 0 0 0 0 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 6 6 6 14 14 14 42 42 42
39274- 90 90 90 18 18 18 18 18 18 26 26 26
39275- 2 2 6 116 116 116 253 253 253 253 253 253
39276-253 253 253 253 253 253 253 253 253 253 253 253
39277-253 253 253 253 253 253 250 250 250 238 238 238
39278-253 253 253 253 253 253 253 253 253 253 253 253
39279-253 253 253 253 253 253 253 253 253 253 253 253
39280-253 253 253 253 253 253 253 253 253 253 253 253
39281-253 253 253 253 253 253 253 253 253 253 253 253
39282-253 253 253 253 253 253 94 94 94 6 6 6
39283- 2 2 6 2 2 6 10 10 10 34 34 34
39284- 2 2 6 2 2 6 2 2 6 2 2 6
39285- 74 74 74 58 58 58 22 22 22 6 6 6
39286- 0 0 0 0 0 0 0 0 0 0 0 0
39287- 0 0 0 0 0 0 0 0 0 0 0 0
39288- 0 0 0 0 0 0 0 0 0 0 0 0
39289- 0 0 0 0 0 0 0 0 0 0 0 0
39290- 0 0 0 0 0 0 0 0 0 0 0 0
39291- 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 10 10 10 26 26 26 66 66 66
39294- 82 82 82 2 2 6 38 38 38 6 6 6
39295- 14 14 14 210 210 210 253 253 253 253 253 253
39296-253 253 253 253 253 253 253 253 253 253 253 253
39297-253 253 253 253 253 253 246 246 246 242 242 242
39298-253 253 253 253 253 253 253 253 253 253 253 253
39299-253 253 253 253 253 253 253 253 253 253 253 253
39300-253 253 253 253 253 253 253 253 253 253 253 253
39301-253 253 253 253 253 253 253 253 253 253 253 253
39302-253 253 253 253 253 253 144 144 144 2 2 6
39303- 2 2 6 2 2 6 2 2 6 46 46 46
39304- 2 2 6 2 2 6 2 2 6 2 2 6
39305- 42 42 42 74 74 74 30 30 30 10 10 10
39306- 0 0 0 0 0 0 0 0 0 0 0 0
39307- 0 0 0 0 0 0 0 0 0 0 0 0
39308- 0 0 0 0 0 0 0 0 0 0 0 0
39309- 0 0 0 0 0 0 0 0 0 0 0 0
39310- 0 0 0 0 0 0 0 0 0 0 0 0
39311- 0 0 0 0 0 0 0 0 0 0 0 0
39312- 0 0 0 0 0 0 0 0 0 0 0 0
39313- 6 6 6 14 14 14 42 42 42 90 90 90
39314- 26 26 26 6 6 6 42 42 42 2 2 6
39315- 74 74 74 250 250 250 253 253 253 253 253 253
39316-253 253 253 253 253 253 253 253 253 253 253 253
39317-253 253 253 253 253 253 242 242 242 242 242 242
39318-253 253 253 253 253 253 253 253 253 253 253 253
39319-253 253 253 253 253 253 253 253 253 253 253 253
39320-253 253 253 253 253 253 253 253 253 253 253 253
39321-253 253 253 253 253 253 253 253 253 253 253 253
39322-253 253 253 253 253 253 182 182 182 2 2 6
39323- 2 2 6 2 2 6 2 2 6 46 46 46
39324- 2 2 6 2 2 6 2 2 6 2 2 6
39325- 10 10 10 86 86 86 38 38 38 10 10 10
39326- 0 0 0 0 0 0 0 0 0 0 0 0
39327- 0 0 0 0 0 0 0 0 0 0 0 0
39328- 0 0 0 0 0 0 0 0 0 0 0 0
39329- 0 0 0 0 0 0 0 0 0 0 0 0
39330- 0 0 0 0 0 0 0 0 0 0 0 0
39331- 0 0 0 0 0 0 0 0 0 0 0 0
39332- 0 0 0 0 0 0 0 0 0 0 0 0
39333- 10 10 10 26 26 26 66 66 66 82 82 82
39334- 2 2 6 22 22 22 18 18 18 2 2 6
39335-149 149 149 253 253 253 253 253 253 253 253 253
39336-253 253 253 253 253 253 253 253 253 253 253 253
39337-253 253 253 253 253 253 234 234 234 242 242 242
39338-253 253 253 253 253 253 253 253 253 253 253 253
39339-253 253 253 253 253 253 253 253 253 253 253 253
39340-253 253 253 253 253 253 253 253 253 253 253 253
39341-253 253 253 253 253 253 253 253 253 253 253 253
39342-253 253 253 253 253 253 206 206 206 2 2 6
39343- 2 2 6 2 2 6 2 2 6 38 38 38
39344- 2 2 6 2 2 6 2 2 6 2 2 6
39345- 6 6 6 86 86 86 46 46 46 14 14 14
39346- 0 0 0 0 0 0 0 0 0 0 0 0
39347- 0 0 0 0 0 0 0 0 0 0 0 0
39348- 0 0 0 0 0 0 0 0 0 0 0 0
39349- 0 0 0 0 0 0 0 0 0 0 0 0
39350- 0 0 0 0 0 0 0 0 0 0 0 0
39351- 0 0 0 0 0 0 0 0 0 0 0 0
39352- 0 0 0 0 0 0 0 0 0 6 6 6
39353- 18 18 18 46 46 46 86 86 86 18 18 18
39354- 2 2 6 34 34 34 10 10 10 6 6 6
39355-210 210 210 253 253 253 253 253 253 253 253 253
39356-253 253 253 253 253 253 253 253 253 253 253 253
39357-253 253 253 253 253 253 234 234 234 242 242 242
39358-253 253 253 253 253 253 253 253 253 253 253 253
39359-253 253 253 253 253 253 253 253 253 253 253 253
39360-253 253 253 253 253 253 253 253 253 253 253 253
39361-253 253 253 253 253 253 253 253 253 253 253 253
39362-253 253 253 253 253 253 221 221 221 6 6 6
39363- 2 2 6 2 2 6 6 6 6 30 30 30
39364- 2 2 6 2 2 6 2 2 6 2 2 6
39365- 2 2 6 82 82 82 54 54 54 18 18 18
39366- 6 6 6 0 0 0 0 0 0 0 0 0
39367- 0 0 0 0 0 0 0 0 0 0 0 0
39368- 0 0 0 0 0 0 0 0 0 0 0 0
39369- 0 0 0 0 0 0 0 0 0 0 0 0
39370- 0 0 0 0 0 0 0 0 0 0 0 0
39371- 0 0 0 0 0 0 0 0 0 0 0 0
39372- 0 0 0 0 0 0 0 0 0 10 10 10
39373- 26 26 26 66 66 66 62 62 62 2 2 6
39374- 2 2 6 38 38 38 10 10 10 26 26 26
39375-238 238 238 253 253 253 253 253 253 253 253 253
39376-253 253 253 253 253 253 253 253 253 253 253 253
39377-253 253 253 253 253 253 231 231 231 238 238 238
39378-253 253 253 253 253 253 253 253 253 253 253 253
39379-253 253 253 253 253 253 253 253 253 253 253 253
39380-253 253 253 253 253 253 253 253 253 253 253 253
39381-253 253 253 253 253 253 253 253 253 253 253 253
39382-253 253 253 253 253 253 231 231 231 6 6 6
39383- 2 2 6 2 2 6 10 10 10 30 30 30
39384- 2 2 6 2 2 6 2 2 6 2 2 6
39385- 2 2 6 66 66 66 58 58 58 22 22 22
39386- 6 6 6 0 0 0 0 0 0 0 0 0
39387- 0 0 0 0 0 0 0 0 0 0 0 0
39388- 0 0 0 0 0 0 0 0 0 0 0 0
39389- 0 0 0 0 0 0 0 0 0 0 0 0
39390- 0 0 0 0 0 0 0 0 0 0 0 0
39391- 0 0 0 0 0 0 0 0 0 0 0 0
39392- 0 0 0 0 0 0 0 0 0 10 10 10
39393- 38 38 38 78 78 78 6 6 6 2 2 6
39394- 2 2 6 46 46 46 14 14 14 42 42 42
39395-246 246 246 253 253 253 253 253 253 253 253 253
39396-253 253 253 253 253 253 253 253 253 253 253 253
39397-253 253 253 253 253 253 231 231 231 242 242 242
39398-253 253 253 253 253 253 253 253 253 253 253 253
39399-253 253 253 253 253 253 253 253 253 253 253 253
39400-253 253 253 253 253 253 253 253 253 253 253 253
39401-253 253 253 253 253 253 253 253 253 253 253 253
39402-253 253 253 253 253 253 234 234 234 10 10 10
39403- 2 2 6 2 2 6 22 22 22 14 14 14
39404- 2 2 6 2 2 6 2 2 6 2 2 6
39405- 2 2 6 66 66 66 62 62 62 22 22 22
39406- 6 6 6 0 0 0 0 0 0 0 0 0
39407- 0 0 0 0 0 0 0 0 0 0 0 0
39408- 0 0 0 0 0 0 0 0 0 0 0 0
39409- 0 0 0 0 0 0 0 0 0 0 0 0
39410- 0 0 0 0 0 0 0 0 0 0 0 0
39411- 0 0 0 0 0 0 0 0 0 0 0 0
39412- 0 0 0 0 0 0 6 6 6 18 18 18
39413- 50 50 50 74 74 74 2 2 6 2 2 6
39414- 14 14 14 70 70 70 34 34 34 62 62 62
39415-250 250 250 253 253 253 253 253 253 253 253 253
39416-253 253 253 253 253 253 253 253 253 253 253 253
39417-253 253 253 253 253 253 231 231 231 246 246 246
39418-253 253 253 253 253 253 253 253 253 253 253 253
39419-253 253 253 253 253 253 253 253 253 253 253 253
39420-253 253 253 253 253 253 253 253 253 253 253 253
39421-253 253 253 253 253 253 253 253 253 253 253 253
39422-253 253 253 253 253 253 234 234 234 14 14 14
39423- 2 2 6 2 2 6 30 30 30 2 2 6
39424- 2 2 6 2 2 6 2 2 6 2 2 6
39425- 2 2 6 66 66 66 62 62 62 22 22 22
39426- 6 6 6 0 0 0 0 0 0 0 0 0
39427- 0 0 0 0 0 0 0 0 0 0 0 0
39428- 0 0 0 0 0 0 0 0 0 0 0 0
39429- 0 0 0 0 0 0 0 0 0 0 0 0
39430- 0 0 0 0 0 0 0 0 0 0 0 0
39431- 0 0 0 0 0 0 0 0 0 0 0 0
39432- 0 0 0 0 0 0 6 6 6 18 18 18
39433- 54 54 54 62 62 62 2 2 6 2 2 6
39434- 2 2 6 30 30 30 46 46 46 70 70 70
39435-250 250 250 253 253 253 253 253 253 253 253 253
39436-253 253 253 253 253 253 253 253 253 253 253 253
39437-253 253 253 253 253 253 231 231 231 246 246 246
39438-253 253 253 253 253 253 253 253 253 253 253 253
39439-253 253 253 253 253 253 253 253 253 253 253 253
39440-253 253 253 253 253 253 253 253 253 253 253 253
39441-253 253 253 253 253 253 253 253 253 253 253 253
39442-253 253 253 253 253 253 226 226 226 10 10 10
39443- 2 2 6 6 6 6 30 30 30 2 2 6
39444- 2 2 6 2 2 6 2 2 6 2 2 6
39445- 2 2 6 66 66 66 58 58 58 22 22 22
39446- 6 6 6 0 0 0 0 0 0 0 0 0
39447- 0 0 0 0 0 0 0 0 0 0 0 0
39448- 0 0 0 0 0 0 0 0 0 0 0 0
39449- 0 0 0 0 0 0 0 0 0 0 0 0
39450- 0 0 0 0 0 0 0 0 0 0 0 0
39451- 0 0 0 0 0 0 0 0 0 0 0 0
39452- 0 0 0 0 0 0 6 6 6 22 22 22
39453- 58 58 58 62 62 62 2 2 6 2 2 6
39454- 2 2 6 2 2 6 30 30 30 78 78 78
39455-250 250 250 253 253 253 253 253 253 253 253 253
39456-253 253 253 253 253 253 253 253 253 253 253 253
39457-253 253 253 253 253 253 231 231 231 246 246 246
39458-253 253 253 253 253 253 253 253 253 253 253 253
39459-253 253 253 253 253 253 253 253 253 253 253 253
39460-253 253 253 253 253 253 253 253 253 253 253 253
39461-253 253 253 253 253 253 253 253 253 253 253 253
39462-253 253 253 253 253 253 206 206 206 2 2 6
39463- 22 22 22 34 34 34 18 14 6 22 22 22
39464- 26 26 26 18 18 18 6 6 6 2 2 6
39465- 2 2 6 82 82 82 54 54 54 18 18 18
39466- 6 6 6 0 0 0 0 0 0 0 0 0
39467- 0 0 0 0 0 0 0 0 0 0 0 0
39468- 0 0 0 0 0 0 0 0 0 0 0 0
39469- 0 0 0 0 0 0 0 0 0 0 0 0
39470- 0 0 0 0 0 0 0 0 0 0 0 0
39471- 0 0 0 0 0 0 0 0 0 0 0 0
39472- 0 0 0 0 0 0 6 6 6 26 26 26
39473- 62 62 62 106 106 106 74 54 14 185 133 11
39474-210 162 10 121 92 8 6 6 6 62 62 62
39475-238 238 238 253 253 253 253 253 253 253 253 253
39476-253 253 253 253 253 253 253 253 253 253 253 253
39477-253 253 253 253 253 253 231 231 231 246 246 246
39478-253 253 253 253 253 253 253 253 253 253 253 253
39479-253 253 253 253 253 253 253 253 253 253 253 253
39480-253 253 253 253 253 253 253 253 253 253 253 253
39481-253 253 253 253 253 253 253 253 253 253 253 253
39482-253 253 253 253 253 253 158 158 158 18 18 18
39483- 14 14 14 2 2 6 2 2 6 2 2 6
39484- 6 6 6 18 18 18 66 66 66 38 38 38
39485- 6 6 6 94 94 94 50 50 50 18 18 18
39486- 6 6 6 0 0 0 0 0 0 0 0 0
39487- 0 0 0 0 0 0 0 0 0 0 0 0
39488- 0 0 0 0 0 0 0 0 0 0 0 0
39489- 0 0 0 0 0 0 0 0 0 0 0 0
39490- 0 0 0 0 0 0 0 0 0 0 0 0
39491- 0 0 0 0 0 0 0 0 0 6 6 6
39492- 10 10 10 10 10 10 18 18 18 38 38 38
39493- 78 78 78 142 134 106 216 158 10 242 186 14
39494-246 190 14 246 190 14 156 118 10 10 10 10
39495- 90 90 90 238 238 238 253 253 253 253 253 253
39496-253 253 253 253 253 253 253 253 253 253 253 253
39497-253 253 253 253 253 253 231 231 231 250 250 250
39498-253 253 253 253 253 253 253 253 253 253 253 253
39499-253 253 253 253 253 253 253 253 253 253 253 253
39500-253 253 253 253 253 253 253 253 253 253 253 253
39501-253 253 253 253 253 253 253 253 253 246 230 190
39502-238 204 91 238 204 91 181 142 44 37 26 9
39503- 2 2 6 2 2 6 2 2 6 2 2 6
39504- 2 2 6 2 2 6 38 38 38 46 46 46
39505- 26 26 26 106 106 106 54 54 54 18 18 18
39506- 6 6 6 0 0 0 0 0 0 0 0 0
39507- 0 0 0 0 0 0 0 0 0 0 0 0
39508- 0 0 0 0 0 0 0 0 0 0 0 0
39509- 0 0 0 0 0 0 0 0 0 0 0 0
39510- 0 0 0 0 0 0 0 0 0 0 0 0
39511- 0 0 0 6 6 6 14 14 14 22 22 22
39512- 30 30 30 38 38 38 50 50 50 70 70 70
39513-106 106 106 190 142 34 226 170 11 242 186 14
39514-246 190 14 246 190 14 246 190 14 154 114 10
39515- 6 6 6 74 74 74 226 226 226 253 253 253
39516-253 253 253 253 253 253 253 253 253 253 253 253
39517-253 253 253 253 253 253 231 231 231 250 250 250
39518-253 253 253 253 253 253 253 253 253 253 253 253
39519-253 253 253 253 253 253 253 253 253 253 253 253
39520-253 253 253 253 253 253 253 253 253 253 253 253
39521-253 253 253 253 253 253 253 253 253 228 184 62
39522-241 196 14 241 208 19 232 195 16 38 30 10
39523- 2 2 6 2 2 6 2 2 6 2 2 6
39524- 2 2 6 6 6 6 30 30 30 26 26 26
39525-203 166 17 154 142 90 66 66 66 26 26 26
39526- 6 6 6 0 0 0 0 0 0 0 0 0
39527- 0 0 0 0 0 0 0 0 0 0 0 0
39528- 0 0 0 0 0 0 0 0 0 0 0 0
39529- 0 0 0 0 0 0 0 0 0 0 0 0
39530- 0 0 0 0 0 0 0 0 0 0 0 0
39531- 6 6 6 18 18 18 38 38 38 58 58 58
39532- 78 78 78 86 86 86 101 101 101 123 123 123
39533-175 146 61 210 150 10 234 174 13 246 186 14
39534-246 190 14 246 190 14 246 190 14 238 190 10
39535-102 78 10 2 2 6 46 46 46 198 198 198
39536-253 253 253 253 253 253 253 253 253 253 253 253
39537-253 253 253 253 253 253 234 234 234 242 242 242
39538-253 253 253 253 253 253 253 253 253 253 253 253
39539-253 253 253 253 253 253 253 253 253 253 253 253
39540-253 253 253 253 253 253 253 253 253 253 253 253
39541-253 253 253 253 253 253 253 253 253 224 178 62
39542-242 186 14 241 196 14 210 166 10 22 18 6
39543- 2 2 6 2 2 6 2 2 6 2 2 6
39544- 2 2 6 2 2 6 6 6 6 121 92 8
39545-238 202 15 232 195 16 82 82 82 34 34 34
39546- 10 10 10 0 0 0 0 0 0 0 0 0
39547- 0 0 0 0 0 0 0 0 0 0 0 0
39548- 0 0 0 0 0 0 0 0 0 0 0 0
39549- 0 0 0 0 0 0 0 0 0 0 0 0
39550- 0 0 0 0 0 0 0 0 0 0 0 0
39551- 14 14 14 38 38 38 70 70 70 154 122 46
39552-190 142 34 200 144 11 197 138 11 197 138 11
39553-213 154 11 226 170 11 242 186 14 246 190 14
39554-246 190 14 246 190 14 246 190 14 246 190 14
39555-225 175 15 46 32 6 2 2 6 22 22 22
39556-158 158 158 250 250 250 253 253 253 253 253 253
39557-253 253 253 253 253 253 253 253 253 253 253 253
39558-253 253 253 253 253 253 253 253 253 253 253 253
39559-253 253 253 253 253 253 253 253 253 253 253 253
39560-253 253 253 253 253 253 253 253 253 253 253 253
39561-253 253 253 250 250 250 242 242 242 224 178 62
39562-239 182 13 236 186 11 213 154 11 46 32 6
39563- 2 2 6 2 2 6 2 2 6 2 2 6
39564- 2 2 6 2 2 6 61 42 6 225 175 15
39565-238 190 10 236 186 11 112 100 78 42 42 42
39566- 14 14 14 0 0 0 0 0 0 0 0 0
39567- 0 0 0 0 0 0 0 0 0 0 0 0
39568- 0 0 0 0 0 0 0 0 0 0 0 0
39569- 0 0 0 0 0 0 0 0 0 0 0 0
39570- 0 0 0 0 0 0 0 0 0 6 6 6
39571- 22 22 22 54 54 54 154 122 46 213 154 11
39572-226 170 11 230 174 11 226 170 11 226 170 11
39573-236 178 12 242 186 14 246 190 14 246 190 14
39574-246 190 14 246 190 14 246 190 14 246 190 14
39575-241 196 14 184 144 12 10 10 10 2 2 6
39576- 6 6 6 116 116 116 242 242 242 253 253 253
39577-253 253 253 253 253 253 253 253 253 253 253 253
39578-253 253 253 253 253 253 253 253 253 253 253 253
39579-253 253 253 253 253 253 253 253 253 253 253 253
39580-253 253 253 253 253 253 253 253 253 253 253 253
39581-253 253 253 231 231 231 198 198 198 214 170 54
39582-236 178 12 236 178 12 210 150 10 137 92 6
39583- 18 14 6 2 2 6 2 2 6 2 2 6
39584- 6 6 6 70 47 6 200 144 11 236 178 12
39585-239 182 13 239 182 13 124 112 88 58 58 58
39586- 22 22 22 6 6 6 0 0 0 0 0 0
39587- 0 0 0 0 0 0 0 0 0 0 0 0
39588- 0 0 0 0 0 0 0 0 0 0 0 0
39589- 0 0 0 0 0 0 0 0 0 0 0 0
39590- 0 0 0 0 0 0 0 0 0 10 10 10
39591- 30 30 30 70 70 70 180 133 36 226 170 11
39592-239 182 13 242 186 14 242 186 14 246 186 14
39593-246 190 14 246 190 14 246 190 14 246 190 14
39594-246 190 14 246 190 14 246 190 14 246 190 14
39595-246 190 14 232 195 16 98 70 6 2 2 6
39596- 2 2 6 2 2 6 66 66 66 221 221 221
39597-253 253 253 253 253 253 253 253 253 253 253 253
39598-253 253 253 253 253 253 253 253 253 253 253 253
39599-253 253 253 253 253 253 253 253 253 253 253 253
39600-253 253 253 253 253 253 253 253 253 253 253 253
39601-253 253 253 206 206 206 198 198 198 214 166 58
39602-230 174 11 230 174 11 216 158 10 192 133 9
39603-163 110 8 116 81 8 102 78 10 116 81 8
39604-167 114 7 197 138 11 226 170 11 239 182 13
39605-242 186 14 242 186 14 162 146 94 78 78 78
39606- 34 34 34 14 14 14 6 6 6 0 0 0
39607- 0 0 0 0 0 0 0 0 0 0 0 0
39608- 0 0 0 0 0 0 0 0 0 0 0 0
39609- 0 0 0 0 0 0 0 0 0 0 0 0
39610- 0 0 0 0 0 0 0 0 0 6 6 6
39611- 30 30 30 78 78 78 190 142 34 226 170 11
39612-239 182 13 246 190 14 246 190 14 246 190 14
39613-246 190 14 246 190 14 246 190 14 246 190 14
39614-246 190 14 246 190 14 246 190 14 246 190 14
39615-246 190 14 241 196 14 203 166 17 22 18 6
39616- 2 2 6 2 2 6 2 2 6 38 38 38
39617-218 218 218 253 253 253 253 253 253 253 253 253
39618-253 253 253 253 253 253 253 253 253 253 253 253
39619-253 253 253 253 253 253 253 253 253 253 253 253
39620-253 253 253 253 253 253 253 253 253 253 253 253
39621-250 250 250 206 206 206 198 198 198 202 162 69
39622-226 170 11 236 178 12 224 166 10 210 150 10
39623-200 144 11 197 138 11 192 133 9 197 138 11
39624-210 150 10 226 170 11 242 186 14 246 190 14
39625-246 190 14 246 186 14 225 175 15 124 112 88
39626- 62 62 62 30 30 30 14 14 14 6 6 6
39627- 0 0 0 0 0 0 0 0 0 0 0 0
39628- 0 0 0 0 0 0 0 0 0 0 0 0
39629- 0 0 0 0 0 0 0 0 0 0 0 0
39630- 0 0 0 0 0 0 0 0 0 10 10 10
39631- 30 30 30 78 78 78 174 135 50 224 166 10
39632-239 182 13 246 190 14 246 190 14 246 190 14
39633-246 190 14 246 190 14 246 190 14 246 190 14
39634-246 190 14 246 190 14 246 190 14 246 190 14
39635-246 190 14 246 190 14 241 196 14 139 102 15
39636- 2 2 6 2 2 6 2 2 6 2 2 6
39637- 78 78 78 250 250 250 253 253 253 253 253 253
39638-253 253 253 253 253 253 253 253 253 253 253 253
39639-253 253 253 253 253 253 253 253 253 253 253 253
39640-253 253 253 253 253 253 253 253 253 253 253 253
39641-250 250 250 214 214 214 198 198 198 190 150 46
39642-219 162 10 236 178 12 234 174 13 224 166 10
39643-216 158 10 213 154 11 213 154 11 216 158 10
39644-226 170 11 239 182 13 246 190 14 246 190 14
39645-246 190 14 246 190 14 242 186 14 206 162 42
39646-101 101 101 58 58 58 30 30 30 14 14 14
39647- 6 6 6 0 0 0 0 0 0 0 0 0
39648- 0 0 0 0 0 0 0 0 0 0 0 0
39649- 0 0 0 0 0 0 0 0 0 0 0 0
39650- 0 0 0 0 0 0 0 0 0 10 10 10
39651- 30 30 30 74 74 74 174 135 50 216 158 10
39652-236 178 12 246 190 14 246 190 14 246 190 14
39653-246 190 14 246 190 14 246 190 14 246 190 14
39654-246 190 14 246 190 14 246 190 14 246 190 14
39655-246 190 14 246 190 14 241 196 14 226 184 13
39656- 61 42 6 2 2 6 2 2 6 2 2 6
39657- 22 22 22 238 238 238 253 253 253 253 253 253
39658-253 253 253 253 253 253 253 253 253 253 253 253
39659-253 253 253 253 253 253 253 253 253 253 253 253
39660-253 253 253 253 253 253 253 253 253 253 253 253
39661-253 253 253 226 226 226 187 187 187 180 133 36
39662-216 158 10 236 178 12 239 182 13 236 178 12
39663-230 174 11 226 170 11 226 170 11 230 174 11
39664-236 178 12 242 186 14 246 190 14 246 190 14
39665-246 190 14 246 190 14 246 186 14 239 182 13
39666-206 162 42 106 106 106 66 66 66 34 34 34
39667- 14 14 14 6 6 6 0 0 0 0 0 0
39668- 0 0 0 0 0 0 0 0 0 0 0 0
39669- 0 0 0 0 0 0 0 0 0 0 0 0
39670- 0 0 0 0 0 0 0 0 0 6 6 6
39671- 26 26 26 70 70 70 163 133 67 213 154 11
39672-236 178 12 246 190 14 246 190 14 246 190 14
39673-246 190 14 246 190 14 246 190 14 246 190 14
39674-246 190 14 246 190 14 246 190 14 246 190 14
39675-246 190 14 246 190 14 246 190 14 241 196 14
39676-190 146 13 18 14 6 2 2 6 2 2 6
39677- 46 46 46 246 246 246 253 253 253 253 253 253
39678-253 253 253 253 253 253 253 253 253 253 253 253
39679-253 253 253 253 253 253 253 253 253 253 253 253
39680-253 253 253 253 253 253 253 253 253 253 253 253
39681-253 253 253 221 221 221 86 86 86 156 107 11
39682-216 158 10 236 178 12 242 186 14 246 186 14
39683-242 186 14 239 182 13 239 182 13 242 186 14
39684-242 186 14 246 186 14 246 190 14 246 190 14
39685-246 190 14 246 190 14 246 190 14 246 190 14
39686-242 186 14 225 175 15 142 122 72 66 66 66
39687- 30 30 30 10 10 10 0 0 0 0 0 0
39688- 0 0 0 0 0 0 0 0 0 0 0 0
39689- 0 0 0 0 0 0 0 0 0 0 0 0
39690- 0 0 0 0 0 0 0 0 0 6 6 6
39691- 26 26 26 70 70 70 163 133 67 210 150 10
39692-236 178 12 246 190 14 246 190 14 246 190 14
39693-246 190 14 246 190 14 246 190 14 246 190 14
39694-246 190 14 246 190 14 246 190 14 246 190 14
39695-246 190 14 246 190 14 246 190 14 246 190 14
39696-232 195 16 121 92 8 34 34 34 106 106 106
39697-221 221 221 253 253 253 253 253 253 253 253 253
39698-253 253 253 253 253 253 253 253 253 253 253 253
39699-253 253 253 253 253 253 253 253 253 253 253 253
39700-253 253 253 253 253 253 253 253 253 253 253 253
39701-242 242 242 82 82 82 18 14 6 163 110 8
39702-216 158 10 236 178 12 242 186 14 246 190 14
39703-246 190 14 246 190 14 246 190 14 246 190 14
39704-246 190 14 246 190 14 246 190 14 246 190 14
39705-246 190 14 246 190 14 246 190 14 246 190 14
39706-246 190 14 246 190 14 242 186 14 163 133 67
39707- 46 46 46 18 18 18 6 6 6 0 0 0
39708- 0 0 0 0 0 0 0 0 0 0 0 0
39709- 0 0 0 0 0 0 0 0 0 0 0 0
39710- 0 0 0 0 0 0 0 0 0 10 10 10
39711- 30 30 30 78 78 78 163 133 67 210 150 10
39712-236 178 12 246 186 14 246 190 14 246 190 14
39713-246 190 14 246 190 14 246 190 14 246 190 14
39714-246 190 14 246 190 14 246 190 14 246 190 14
39715-246 190 14 246 190 14 246 190 14 246 190 14
39716-241 196 14 215 174 15 190 178 144 253 253 253
39717-253 253 253 253 253 253 253 253 253 253 253 253
39718-253 253 253 253 253 253 253 253 253 253 253 253
39719-253 253 253 253 253 253 253 253 253 253 253 253
39720-253 253 253 253 253 253 253 253 253 218 218 218
39721- 58 58 58 2 2 6 22 18 6 167 114 7
39722-216 158 10 236 178 12 246 186 14 246 190 14
39723-246 190 14 246 190 14 246 190 14 246 190 14
39724-246 190 14 246 190 14 246 190 14 246 190 14
39725-246 190 14 246 190 14 246 190 14 246 190 14
39726-246 190 14 246 186 14 242 186 14 190 150 46
39727- 54 54 54 22 22 22 6 6 6 0 0 0
39728- 0 0 0 0 0 0 0 0 0 0 0 0
39729- 0 0 0 0 0 0 0 0 0 0 0 0
39730- 0 0 0 0 0 0 0 0 0 14 14 14
39731- 38 38 38 86 86 86 180 133 36 213 154 11
39732-236 178 12 246 186 14 246 190 14 246 190 14
39733-246 190 14 246 190 14 246 190 14 246 190 14
39734-246 190 14 246 190 14 246 190 14 246 190 14
39735-246 190 14 246 190 14 246 190 14 246 190 14
39736-246 190 14 232 195 16 190 146 13 214 214 214
39737-253 253 253 253 253 253 253 253 253 253 253 253
39738-253 253 253 253 253 253 253 253 253 253 253 253
39739-253 253 253 253 253 253 253 253 253 253 253 253
39740-253 253 253 250 250 250 170 170 170 26 26 26
39741- 2 2 6 2 2 6 37 26 9 163 110 8
39742-219 162 10 239 182 13 246 186 14 246 190 14
39743-246 190 14 246 190 14 246 190 14 246 190 14
39744-246 190 14 246 190 14 246 190 14 246 190 14
39745-246 190 14 246 190 14 246 190 14 246 190 14
39746-246 186 14 236 178 12 224 166 10 142 122 72
39747- 46 46 46 18 18 18 6 6 6 0 0 0
39748- 0 0 0 0 0 0 0 0 0 0 0 0
39749- 0 0 0 0 0 0 0 0 0 0 0 0
39750- 0 0 0 0 0 0 6 6 6 18 18 18
39751- 50 50 50 109 106 95 192 133 9 224 166 10
39752-242 186 14 246 190 14 246 190 14 246 190 14
39753-246 190 14 246 190 14 246 190 14 246 190 14
39754-246 190 14 246 190 14 246 190 14 246 190 14
39755-246 190 14 246 190 14 246 190 14 246 190 14
39756-242 186 14 226 184 13 210 162 10 142 110 46
39757-226 226 226 253 253 253 253 253 253 253 253 253
39758-253 253 253 253 253 253 253 253 253 253 253 253
39759-253 253 253 253 253 253 253 253 253 253 253 253
39760-198 198 198 66 66 66 2 2 6 2 2 6
39761- 2 2 6 2 2 6 50 34 6 156 107 11
39762-219 162 10 239 182 13 246 186 14 246 190 14
39763-246 190 14 246 190 14 246 190 14 246 190 14
39764-246 190 14 246 190 14 246 190 14 246 190 14
39765-246 190 14 246 190 14 246 190 14 242 186 14
39766-234 174 13 213 154 11 154 122 46 66 66 66
39767- 30 30 30 10 10 10 0 0 0 0 0 0
39768- 0 0 0 0 0 0 0 0 0 0 0 0
39769- 0 0 0 0 0 0 0 0 0 0 0 0
39770- 0 0 0 0 0 0 6 6 6 22 22 22
39771- 58 58 58 154 121 60 206 145 10 234 174 13
39772-242 186 14 246 186 14 246 190 14 246 190 14
39773-246 190 14 246 190 14 246 190 14 246 190 14
39774-246 190 14 246 190 14 246 190 14 246 190 14
39775-246 190 14 246 190 14 246 190 14 246 190 14
39776-246 186 14 236 178 12 210 162 10 163 110 8
39777- 61 42 6 138 138 138 218 218 218 250 250 250
39778-253 253 253 253 253 253 253 253 253 250 250 250
39779-242 242 242 210 210 210 144 144 144 66 66 66
39780- 6 6 6 2 2 6 2 2 6 2 2 6
39781- 2 2 6 2 2 6 61 42 6 163 110 8
39782-216 158 10 236 178 12 246 190 14 246 190 14
39783-246 190 14 246 190 14 246 190 14 246 190 14
39784-246 190 14 246 190 14 246 190 14 246 190 14
39785-246 190 14 239 182 13 230 174 11 216 158 10
39786-190 142 34 124 112 88 70 70 70 38 38 38
39787- 18 18 18 6 6 6 0 0 0 0 0 0
39788- 0 0 0 0 0 0 0 0 0 0 0 0
39789- 0 0 0 0 0 0 0 0 0 0 0 0
39790- 0 0 0 0 0 0 6 6 6 22 22 22
39791- 62 62 62 168 124 44 206 145 10 224 166 10
39792-236 178 12 239 182 13 242 186 14 242 186 14
39793-246 186 14 246 190 14 246 190 14 246 190 14
39794-246 190 14 246 190 14 246 190 14 246 190 14
39795-246 190 14 246 190 14 246 190 14 246 190 14
39796-246 190 14 236 178 12 216 158 10 175 118 6
39797- 80 54 7 2 2 6 6 6 6 30 30 30
39798- 54 54 54 62 62 62 50 50 50 38 38 38
39799- 14 14 14 2 2 6 2 2 6 2 2 6
39800- 2 2 6 2 2 6 2 2 6 2 2 6
39801- 2 2 6 6 6 6 80 54 7 167 114 7
39802-213 154 11 236 178 12 246 190 14 246 190 14
39803-246 190 14 246 190 14 246 190 14 246 190 14
39804-246 190 14 242 186 14 239 182 13 239 182 13
39805-230 174 11 210 150 10 174 135 50 124 112 88
39806- 82 82 82 54 54 54 34 34 34 18 18 18
39807- 6 6 6 0 0 0 0 0 0 0 0 0
39808- 0 0 0 0 0 0 0 0 0 0 0 0
39809- 0 0 0 0 0 0 0 0 0 0 0 0
39810- 0 0 0 0 0 0 6 6 6 18 18 18
39811- 50 50 50 158 118 36 192 133 9 200 144 11
39812-216 158 10 219 162 10 224 166 10 226 170 11
39813-230 174 11 236 178 12 239 182 13 239 182 13
39814-242 186 14 246 186 14 246 190 14 246 190 14
39815-246 190 14 246 190 14 246 190 14 246 190 14
39816-246 186 14 230 174 11 210 150 10 163 110 8
39817-104 69 6 10 10 10 2 2 6 2 2 6
39818- 2 2 6 2 2 6 2 2 6 2 2 6
39819- 2 2 6 2 2 6 2 2 6 2 2 6
39820- 2 2 6 2 2 6 2 2 6 2 2 6
39821- 2 2 6 6 6 6 91 60 6 167 114 7
39822-206 145 10 230 174 11 242 186 14 246 190 14
39823-246 190 14 246 190 14 246 186 14 242 186 14
39824-239 182 13 230 174 11 224 166 10 213 154 11
39825-180 133 36 124 112 88 86 86 86 58 58 58
39826- 38 38 38 22 22 22 10 10 10 6 6 6
39827- 0 0 0 0 0 0 0 0 0 0 0 0
39828- 0 0 0 0 0 0 0 0 0 0 0 0
39829- 0 0 0 0 0 0 0 0 0 0 0 0
39830- 0 0 0 0 0 0 0 0 0 14 14 14
39831- 34 34 34 70 70 70 138 110 50 158 118 36
39832-167 114 7 180 123 7 192 133 9 197 138 11
39833-200 144 11 206 145 10 213 154 11 219 162 10
39834-224 166 10 230 174 11 239 182 13 242 186 14
39835-246 186 14 246 186 14 246 186 14 246 186 14
39836-239 182 13 216 158 10 185 133 11 152 99 6
39837-104 69 6 18 14 6 2 2 6 2 2 6
39838- 2 2 6 2 2 6 2 2 6 2 2 6
39839- 2 2 6 2 2 6 2 2 6 2 2 6
39840- 2 2 6 2 2 6 2 2 6 2 2 6
39841- 2 2 6 6 6 6 80 54 7 152 99 6
39842-192 133 9 219 162 10 236 178 12 239 182 13
39843-246 186 14 242 186 14 239 182 13 236 178 12
39844-224 166 10 206 145 10 192 133 9 154 121 60
39845- 94 94 94 62 62 62 42 42 42 22 22 22
39846- 14 14 14 6 6 6 0 0 0 0 0 0
39847- 0 0 0 0 0 0 0 0 0 0 0 0
39848- 0 0 0 0 0 0 0 0 0 0 0 0
39849- 0 0 0 0 0 0 0 0 0 0 0 0
39850- 0 0 0 0 0 0 0 0 0 6 6 6
39851- 18 18 18 34 34 34 58 58 58 78 78 78
39852-101 98 89 124 112 88 142 110 46 156 107 11
39853-163 110 8 167 114 7 175 118 6 180 123 7
39854-185 133 11 197 138 11 210 150 10 219 162 10
39855-226 170 11 236 178 12 236 178 12 234 174 13
39856-219 162 10 197 138 11 163 110 8 130 83 6
39857- 91 60 6 10 10 10 2 2 6 2 2 6
39858- 18 18 18 38 38 38 38 38 38 38 38 38
39859- 38 38 38 38 38 38 38 38 38 38 38 38
39860- 38 38 38 38 38 38 26 26 26 2 2 6
39861- 2 2 6 6 6 6 70 47 6 137 92 6
39862-175 118 6 200 144 11 219 162 10 230 174 11
39863-234 174 13 230 174 11 219 162 10 210 150 10
39864-192 133 9 163 110 8 124 112 88 82 82 82
39865- 50 50 50 30 30 30 14 14 14 6 6 6
39866- 0 0 0 0 0 0 0 0 0 0 0 0
39867- 0 0 0 0 0 0 0 0 0 0 0 0
39868- 0 0 0 0 0 0 0 0 0 0 0 0
39869- 0 0 0 0 0 0 0 0 0 0 0 0
39870- 0 0 0 0 0 0 0 0 0 0 0 0
39871- 6 6 6 14 14 14 22 22 22 34 34 34
39872- 42 42 42 58 58 58 74 74 74 86 86 86
39873-101 98 89 122 102 70 130 98 46 121 87 25
39874-137 92 6 152 99 6 163 110 8 180 123 7
39875-185 133 11 197 138 11 206 145 10 200 144 11
39876-180 123 7 156 107 11 130 83 6 104 69 6
39877- 50 34 6 54 54 54 110 110 110 101 98 89
39878- 86 86 86 82 82 82 78 78 78 78 78 78
39879- 78 78 78 78 78 78 78 78 78 78 78 78
39880- 78 78 78 82 82 82 86 86 86 94 94 94
39881-106 106 106 101 101 101 86 66 34 124 80 6
39882-156 107 11 180 123 7 192 133 9 200 144 11
39883-206 145 10 200 144 11 192 133 9 175 118 6
39884-139 102 15 109 106 95 70 70 70 42 42 42
39885- 22 22 22 10 10 10 0 0 0 0 0 0
39886- 0 0 0 0 0 0 0 0 0 0 0 0
39887- 0 0 0 0 0 0 0 0 0 0 0 0
39888- 0 0 0 0 0 0 0 0 0 0 0 0
39889- 0 0 0 0 0 0 0 0 0 0 0 0
39890- 0 0 0 0 0 0 0 0 0 0 0 0
39891- 0 0 0 0 0 0 6 6 6 10 10 10
39892- 14 14 14 22 22 22 30 30 30 38 38 38
39893- 50 50 50 62 62 62 74 74 74 90 90 90
39894-101 98 89 112 100 78 121 87 25 124 80 6
39895-137 92 6 152 99 6 152 99 6 152 99 6
39896-138 86 6 124 80 6 98 70 6 86 66 30
39897-101 98 89 82 82 82 58 58 58 46 46 46
39898- 38 38 38 34 34 34 34 34 34 34 34 34
39899- 34 34 34 34 34 34 34 34 34 34 34 34
39900- 34 34 34 34 34 34 38 38 38 42 42 42
39901- 54 54 54 82 82 82 94 86 76 91 60 6
39902-134 86 6 156 107 11 167 114 7 175 118 6
39903-175 118 6 167 114 7 152 99 6 121 87 25
39904-101 98 89 62 62 62 34 34 34 18 18 18
39905- 6 6 6 0 0 0 0 0 0 0 0 0
39906- 0 0 0 0 0 0 0 0 0 0 0 0
39907- 0 0 0 0 0 0 0 0 0 0 0 0
39908- 0 0 0 0 0 0 0 0 0 0 0 0
39909- 0 0 0 0 0 0 0 0 0 0 0 0
39910- 0 0 0 0 0 0 0 0 0 0 0 0
39911- 0 0 0 0 0 0 0 0 0 0 0 0
39912- 0 0 0 6 6 6 6 6 6 10 10 10
39913- 18 18 18 22 22 22 30 30 30 42 42 42
39914- 50 50 50 66 66 66 86 86 86 101 98 89
39915-106 86 58 98 70 6 104 69 6 104 69 6
39916-104 69 6 91 60 6 82 62 34 90 90 90
39917- 62 62 62 38 38 38 22 22 22 14 14 14
39918- 10 10 10 10 10 10 10 10 10 10 10 10
39919- 10 10 10 10 10 10 6 6 6 10 10 10
39920- 10 10 10 10 10 10 10 10 10 14 14 14
39921- 22 22 22 42 42 42 70 70 70 89 81 66
39922- 80 54 7 104 69 6 124 80 6 137 92 6
39923-134 86 6 116 81 8 100 82 52 86 86 86
39924- 58 58 58 30 30 30 14 14 14 6 6 6
39925- 0 0 0 0 0 0 0 0 0 0 0 0
39926- 0 0 0 0 0 0 0 0 0 0 0 0
39927- 0 0 0 0 0 0 0 0 0 0 0 0
39928- 0 0 0 0 0 0 0 0 0 0 0 0
39929- 0 0 0 0 0 0 0 0 0 0 0 0
39930- 0 0 0 0 0 0 0 0 0 0 0 0
39931- 0 0 0 0 0 0 0 0 0 0 0 0
39932- 0 0 0 0 0 0 0 0 0 0 0 0
39933- 0 0 0 6 6 6 10 10 10 14 14 14
39934- 18 18 18 26 26 26 38 38 38 54 54 54
39935- 70 70 70 86 86 86 94 86 76 89 81 66
39936- 89 81 66 86 86 86 74 74 74 50 50 50
39937- 30 30 30 14 14 14 6 6 6 0 0 0
39938- 0 0 0 0 0 0 0 0 0 0 0 0
39939- 0 0 0 0 0 0 0 0 0 0 0 0
39940- 0 0 0 0 0 0 0 0 0 0 0 0
39941- 6 6 6 18 18 18 34 34 34 58 58 58
39942- 82 82 82 89 81 66 89 81 66 89 81 66
39943- 94 86 66 94 86 76 74 74 74 50 50 50
39944- 26 26 26 14 14 14 6 6 6 0 0 0
39945- 0 0 0 0 0 0 0 0 0 0 0 0
39946- 0 0 0 0 0 0 0 0 0 0 0 0
39947- 0 0 0 0 0 0 0 0 0 0 0 0
39948- 0 0 0 0 0 0 0 0 0 0 0 0
39949- 0 0 0 0 0 0 0 0 0 0 0 0
39950- 0 0 0 0 0 0 0 0 0 0 0 0
39951- 0 0 0 0 0 0 0 0 0 0 0 0
39952- 0 0 0 0 0 0 0 0 0 0 0 0
39953- 0 0 0 0 0 0 0 0 0 0 0 0
39954- 6 6 6 6 6 6 14 14 14 18 18 18
39955- 30 30 30 38 38 38 46 46 46 54 54 54
39956- 50 50 50 42 42 42 30 30 30 18 18 18
39957- 10 10 10 0 0 0 0 0 0 0 0 0
39958- 0 0 0 0 0 0 0 0 0 0 0 0
39959- 0 0 0 0 0 0 0 0 0 0 0 0
39960- 0 0 0 0 0 0 0 0 0 0 0 0
39961- 0 0 0 6 6 6 14 14 14 26 26 26
39962- 38 38 38 50 50 50 58 58 58 58 58 58
39963- 54 54 54 42 42 42 30 30 30 18 18 18
39964- 10 10 10 0 0 0 0 0 0 0 0 0
39965- 0 0 0 0 0 0 0 0 0 0 0 0
39966- 0 0 0 0 0 0 0 0 0 0 0 0
39967- 0 0 0 0 0 0 0 0 0 0 0 0
39968- 0 0 0 0 0 0 0 0 0 0 0 0
39969- 0 0 0 0 0 0 0 0 0 0 0 0
39970- 0 0 0 0 0 0 0 0 0 0 0 0
39971- 0 0 0 0 0 0 0 0 0 0 0 0
39972- 0 0 0 0 0 0 0 0 0 0 0 0
39973- 0 0 0 0 0 0 0 0 0 0 0 0
39974- 0 0 0 0 0 0 0 0 0 6 6 6
39975- 6 6 6 10 10 10 14 14 14 18 18 18
39976- 18 18 18 14 14 14 10 10 10 6 6 6
39977- 0 0 0 0 0 0 0 0 0 0 0 0
39978- 0 0 0 0 0 0 0 0 0 0 0 0
39979- 0 0 0 0 0 0 0 0 0 0 0 0
39980- 0 0 0 0 0 0 0 0 0 0 0 0
39981- 0 0 0 0 0 0 0 0 0 6 6 6
39982- 14 14 14 18 18 18 22 22 22 22 22 22
39983- 18 18 18 14 14 14 10 10 10 6 6 6
39984- 0 0 0 0 0 0 0 0 0 0 0 0
39985- 0 0 0 0 0 0 0 0 0 0 0 0
39986- 0 0 0 0 0 0 0 0 0 0 0 0
39987- 0 0 0 0 0 0 0 0 0 0 0 0
39988- 0 0 0 0 0 0 0 0 0 0 0 0
39989+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39990+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39991+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39992+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39993+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39994+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39995+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39996+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39997+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39998+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39999+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40000+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40001+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40002+4 4 4 4 4 4
40003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40005+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40006+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40007+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40008+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40009+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40010+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40011+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40013+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40014+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40015+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40016+4 4 4 4 4 4
40017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40019+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40020+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40021+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40022+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40023+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40024+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40025+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40026+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40027+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40028+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40029+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40030+4 4 4 4 4 4
40031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40032+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40033+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40034+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40035+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40036+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40037+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40038+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40039+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40040+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40041+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40042+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40044+4 4 4 4 4 4
40045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40046+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40047+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40048+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40049+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40050+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40051+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40052+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40053+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40054+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40055+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40056+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40057+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40058+4 4 4 4 4 4
40059+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40060+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40061+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40062+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40063+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40064+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40065+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40066+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40067+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40068+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40069+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40070+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40071+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40072+4 4 4 4 4 4
40073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40074+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40075+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40076+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40077+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
40078+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
40079+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40080+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40081+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40082+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
40083+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40084+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
40085+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40086+4 4 4 4 4 4
40087+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40088+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40089+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40090+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40091+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
40092+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40093+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40094+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40095+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40096+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
40097+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40098+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40099+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40100+4 4 4 4 4 4
40101+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40102+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40103+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40104+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40105+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40106+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40107+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40108+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40109+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40110+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
40111+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40112+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40113+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40114+4 4 4 4 4 4
40115+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40116+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40117+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40118+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
40119+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40120+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40121+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
40122+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40123+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40124+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40125+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40126+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40127+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40128+4 4 4 4 4 4
40129+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40130+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40131+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40132+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40133+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40134+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40135+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40136+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40137+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40138+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40139+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40140+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40141+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40142+4 4 4 4 4 4
40143+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40144+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40145+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40146+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40147+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40148+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40149+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40150+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40151+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40152+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40153+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40154+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40155+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40156+4 4 4 4 4 4
40157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40158+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40159+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40160+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40161+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40162+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40163+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40164+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40165+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40166+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40167+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40168+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40169+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40170+4 4 4 4 4 4
40171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40172+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40173+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
40174+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40175+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40176+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40177+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40178+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40179+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40180+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40181+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40182+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40183+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40184+4 4 4 4 4 4
40185+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40186+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40187+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40188+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40189+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40190+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40191+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40192+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40193+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40194+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40195+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40196+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40197+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40198+4 4 4 4 4 4
40199+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40200+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40201+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40202+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40203+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40204+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40205+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40206+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40207+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
40208+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
40209+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
40210+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
40211+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
40212+4 4 4 4 4 4
40213+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40214+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
40215+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
40216+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
40217+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
40218+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
40219+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
40220+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
40221+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
40222+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
40223+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
40224+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
40225+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
40226+4 4 4 4 4 4
40227+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40228+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
40229+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
40230+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
40231+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40232+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
40233+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
40234+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
40235+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
40236+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
40237+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
40238+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
40239+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
40240+0 0 0 4 4 4
40241+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40242+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
40243+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
40244+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
40245+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
40246+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
40247+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
40248+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
40249+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
40250+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
40251+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
40252+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
40253+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
40254+2 0 0 0 0 0
40255+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
40256+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
40257+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
40258+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
40259+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
40260+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
40261+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
40262+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
40263+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
40264+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
40265+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
40266+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
40267+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
40268+37 38 37 0 0 0
40269+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40270+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
40271+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
40272+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
40273+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
40274+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
40275+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
40276+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
40277+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
40278+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
40279+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
40280+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
40281+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
40282+85 115 134 4 0 0
40283+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
40284+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
40285+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
40286+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
40287+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
40288+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
40289+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
40290+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
40291+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
40292+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
40293+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
40294+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
40295+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
40296+60 73 81 4 0 0
40297+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
40298+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
40299+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
40300+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
40301+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
40302+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
40303+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
40304+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
40305+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
40306+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
40307+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
40308+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
40309+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
40310+16 19 21 4 0 0
40311+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
40312+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
40313+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
40314+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
40315+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
40316+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
40317+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
40318+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
40319+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
40320+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
40321+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
40322+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
40323+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
40324+4 0 0 4 3 3
40325+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
40326+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
40327+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
40328+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
40329+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
40330+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
40331+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
40332+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
40333+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
40334+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
40335+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
40336+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
40337+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
40338+3 2 2 4 4 4
40339+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
40340+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
40341+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
40342+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40343+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
40344+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
40345+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
40346+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
40347+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
40348+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
40349+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
40350+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
40351+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
40352+4 4 4 4 4 4
40353+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
40354+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
40355+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
40356+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
40357+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
40358+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
40359+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
40360+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
40361+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
40362+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
40363+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
40364+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
40365+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
40366+4 4 4 4 4 4
40367+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
40368+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
40369+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
40370+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
40371+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
40372+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40373+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
40374+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
40375+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
40376+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
40377+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
40378+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
40379+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
40380+5 5 5 5 5 5
40381+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
40382+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
40383+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
40384+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
40385+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
40386+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40387+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
40388+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
40389+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
40390+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
40391+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
40392+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
40393+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
40394+5 5 5 4 4 4
40395+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
40396+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
40397+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
40398+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
40399+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40400+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
40401+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
40402+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
40403+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
40404+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
40405+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
40406+4 0 0 4 0 0 5 5 5 5 5 5 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
40409+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
40410+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
40411+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
40412+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
40413+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
40414+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40415+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40416+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
40417+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
40418+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
40419+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
40420+3 3 3 5 5 5 6 6 6 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
40423+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
40424+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
40425+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
40426+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
40427+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40428+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
40429+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
40430+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
40431+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
40432+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
40433+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 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
40437+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
40438+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
40439+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
40440+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
40441+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40442+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40443+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40444+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
40445+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
40446+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
40447+6 6 6 4 0 0 4 0 0 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
40451+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
40452+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
40453+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
40454+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
40455+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40456+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
40457+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40458+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
40459+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
40460+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
40461+4 0 0 4 3 3 5 5 5 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
40465+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
40466+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
40467+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
40468+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
40469+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40470+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
40471+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
40472+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
40473+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
40474+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
40475+6 6 6 4 0 0 6 6 6 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
40479+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
40480+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
40481+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
40482+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
40483+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40484+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
40485+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
40486+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
40487+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
40488+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
40489+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
40490+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40491+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40492+4 4 4 4 4 4
40493+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
40494+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
40495+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
40496+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40497+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
40498+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
40499+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
40500+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
40501+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
40502+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
40503+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40504+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40505+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40506+4 4 4 4 4 4
40507+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
40508+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
40509+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
40510+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40511+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40512+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
40513+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
40514+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
40515+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
40516+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
40517+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40518+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40519+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40520+4 4 4 4 4 4
40521+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
40522+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
40523+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40524+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40525+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40526+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
40527+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
40528+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
40529+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
40530+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
40531+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40532+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40533+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40534+4 4 4 4 4 4
40535+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
40536+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
40537+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40538+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40539+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40540+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
40541+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
40542+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
40543+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
40544+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40545+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40546+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40547+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40548+4 4 4 4 4 4
40549+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
40550+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
40551+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40552+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
40553+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
40554+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
40555+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
40556+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
40557+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40558+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40559+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40560+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40561+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40562+4 4 4 4 4 4
40563+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
40564+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
40565+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40566+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
40567+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40568+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
40569+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
40570+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
40571+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40572+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40573+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40574+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40575+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40576+4 4 4 4 4 4
40577+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
40578+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
40579+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
40580+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
40581+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
40582+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
40583+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
40584+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
40585+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40586+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40587+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40588+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40589+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40590+4 4 4 4 4 4
40591+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
40592+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
40593+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40594+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
40595+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
40596+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
40597+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
40598+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
40599+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
40600+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40601+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40602+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40603+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40604+4 4 4 4 4 4
40605+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
40606+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
40607+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
40608+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
40609+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
40610+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
40611+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
40612+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
40613+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40614+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40615+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40618+4 4 4 4 4 4
40619+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
40620+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
40621+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40622+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
40623+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
40624+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
40625+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
40626+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
40627+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
40628+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40629+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40632+4 4 4 4 4 4
40633+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
40634+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
40635+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
40636+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
40637+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
40638+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
40639+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
40640+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
40641+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40642+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40643+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40646+4 4 4 4 4 4
40647+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40648+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
40649+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40650+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
40651+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
40652+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
40653+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
40654+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
40655+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40656+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40657+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40660+4 4 4 4 4 4
40661+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
40662+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
40663+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
40664+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
40665+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
40666+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
40667+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40668+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
40669+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40670+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40671+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40674+4 4 4 4 4 4
40675+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40676+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
40677+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
40678+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
40679+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
40680+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
40681+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40682+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
40683+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40684+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40685+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40688+4 4 4 4 4 4
40689+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
40690+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
40691+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
40692+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
40693+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
40694+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
40695+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
40696+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
40697+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
40698+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40699+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40702+4 4 4 4 4 4
40703+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40704+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
40705+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
40706+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
40707+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
40708+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
40709+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
40710+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
40711+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
40712+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40713+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40716+4 4 4 4 4 4
40717+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
40718+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
40719+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
40720+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
40721+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
40722+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
40723+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
40724+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
40725+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
40726+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40727+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40730+4 4 4 4 4 4
40731+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40732+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
40733+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
40734+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
40735+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
40736+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
40737+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
40738+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
40739+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
40740+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40741+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40744+4 4 4 4 4 4
40745+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
40746+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
40747+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
40748+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
40749+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
40750+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
40751+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
40752+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
40753+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
40754+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
40755+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40758+4 4 4 4 4 4
40759+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
40760+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
40761+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
40762+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
40763+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
40764+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
40765+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
40766+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
40767+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
40768+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
40769+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40772+4 4 4 4 4 4
40773+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
40774+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
40775+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
40776+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
40777+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
40778+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
40779+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40780+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
40781+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
40782+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
40783+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40786+4 4 4 4 4 4
40787+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
40788+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
40789+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
40790+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
40791+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
40792+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
40793+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
40794+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
40795+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
40796+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
40797+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40800+4 4 4 4 4 4
40801+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
40802+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
40803+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
40804+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
40805+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
40806+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
40807+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
40808+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
40809+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
40810+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
40811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40814+4 4 4 4 4 4
40815+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
40816+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
40817+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
40818+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
40819+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
40820+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
40821+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
40822+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
40823+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
40824+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
40825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40828+4 4 4 4 4 4
40829+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
40830+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
40831+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
40832+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
40833+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
40834+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
40835+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
40836+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
40837+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
40838+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
40839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
40843+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
40844+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
40845+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
40846+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
40847+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
40848+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
40849+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
40850+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
40851+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40852+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40853+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40854+4 4 4 4 4 4 4 4 4 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
40857+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
40858+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
40859+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
40860+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
40861+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
40862+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
40863+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
40864+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
40865+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
40866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40868+4 4 4 4 4 4 4 4 4 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
40871+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
40872+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
40873+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
40874+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
40875+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
40876+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
40877+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
40878+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
40879+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
40880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40882+4 4 4 4 4 4 4 4 4 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
40885+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
40886+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
40887+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
40888+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
40889+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
40890+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
40891+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
40892+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
40893+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40895+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40896+4 4 4 4 4 4 4 4 4 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
40899+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
40900+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
40901+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
40902+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
40903+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
40904+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
40905+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
40906+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
40907+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40908+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40909+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40910+4 4 4 4 4 4 4 4 4 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
40913+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
40914+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
40915+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
40916+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
40917+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
40918+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
40919+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
40920+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
40921+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40922+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40923+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40924+4 4 4 4 4 4 4 4 4 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
40927+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40928+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
40929+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
40930+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
40931+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
40932+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
40933+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
40934+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
40935+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40936+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40937+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40938+4 4 4 4 4 4 4 4 4 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
40941+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40942+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
40943+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
40944+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
40945+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
40946+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
40947+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
40948+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
40949+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40950+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40951+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40952+4 4 4 4 4 4 4 4 4 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
40955+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40956+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
40957+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
40958+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
40959+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
40960+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
40961+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
40962+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40963+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40964+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40965+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40966+4 4 4 4 4 4 4 4 4 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
40969+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40970+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40971+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
40972+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
40973+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
40974+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
40975+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
40976+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40977+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40978+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40979+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40980+4 4 4 4 4 4 4 4 4 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
40983+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40984+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40985+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40986+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
40987+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
40988+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
40989+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
40990+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40991+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40992+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40993+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40994+4 4 4 4 4 4 4 4 4 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
40997+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40998+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40999+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41000+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41001+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41002+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41003+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
41004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41005+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41006+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41007+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41008+4 4 4 4 4 4 4 4 4 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
41011+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41013+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41014+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41015+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41016+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41017+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
41018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41019+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41020+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41021+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41022+4 4 4 4 4 4 4 4 4 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
41025+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41026+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41027+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41028+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
41029+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41030+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41031+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
41032+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41033+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41034+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41035+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41036+4 4 4 4 4 4 4 4 4 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
41039+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41040+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41041+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41042+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41043+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41044+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41045+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41046+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41047+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41048+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41049+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41050+4 4 4 4 4 4 4 4 4 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
41053+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41054+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41055+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41056+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41057+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41058+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41059+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41060+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41061+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41062+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41063+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41064+4 4 4 4 4 4 4 4 4 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
41067+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41068+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41069+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41070+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41071+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41072+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41073+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41074+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41075+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41076+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41077+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41078+4 4 4 4 4 4 4 4 4 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
41081+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41082+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41083+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41084+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41085+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
41086+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
41087+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41088+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41089+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41090+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41091+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41092+4 4 4 4 4 4 4 4 4 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
41095+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41096+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41097+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41098+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41099+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41100+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
41101+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41102+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41103+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41104+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41105+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41106+4 4 4 4 4 4 4 4 4 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
41109diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41110index a159b63..4ab532d 100644
41111--- a/drivers/video/udlfb.c
41112+++ b/drivers/video/udlfb.c
41113@@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41114 dlfb_urb_completion(urb);
41115
41116 error:
41117- atomic_add(bytes_sent, &dev->bytes_sent);
41118- atomic_add(bytes_identical, &dev->bytes_identical);
41119- atomic_add(width*height*2, &dev->bytes_rendered);
41120+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41121+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41122+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41123 end_cycles = get_cycles();
41124- atomic_add(((unsigned int) ((end_cycles - start_cycles)
41125+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41126 >> 10)), /* Kcycles */
41127 &dev->cpu_kcycles_used);
41128
41129@@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41130 dlfb_urb_completion(urb);
41131
41132 error:
41133- atomic_add(bytes_sent, &dev->bytes_sent);
41134- atomic_add(bytes_identical, &dev->bytes_identical);
41135- atomic_add(bytes_rendered, &dev->bytes_rendered);
41136+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41137+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41138+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41139 end_cycles = get_cycles();
41140- atomic_add(((unsigned int) ((end_cycles - start_cycles)
41141+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41142 >> 10)), /* Kcycles */
41143 &dev->cpu_kcycles_used);
41144 }
41145@@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41146 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41147 struct dlfb_data *dev = fb_info->par;
41148 return snprintf(buf, PAGE_SIZE, "%u\n",
41149- atomic_read(&dev->bytes_rendered));
41150+ atomic_read_unchecked(&dev->bytes_rendered));
41151 }
41152
41153 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41154@@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41155 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41156 struct dlfb_data *dev = fb_info->par;
41157 return snprintf(buf, PAGE_SIZE, "%u\n",
41158- atomic_read(&dev->bytes_identical));
41159+ atomic_read_unchecked(&dev->bytes_identical));
41160 }
41161
41162 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41163@@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41164 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41165 struct dlfb_data *dev = fb_info->par;
41166 return snprintf(buf, PAGE_SIZE, "%u\n",
41167- atomic_read(&dev->bytes_sent));
41168+ atomic_read_unchecked(&dev->bytes_sent));
41169 }
41170
41171 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41172@@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41173 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41174 struct dlfb_data *dev = fb_info->par;
41175 return snprintf(buf, PAGE_SIZE, "%u\n",
41176- atomic_read(&dev->cpu_kcycles_used));
41177+ atomic_read_unchecked(&dev->cpu_kcycles_used));
41178 }
41179
41180 static ssize_t edid_show(
41181@@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41182 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41183 struct dlfb_data *dev = fb_info->par;
41184
41185- atomic_set(&dev->bytes_rendered, 0);
41186- atomic_set(&dev->bytes_identical, 0);
41187- atomic_set(&dev->bytes_sent, 0);
41188- atomic_set(&dev->cpu_kcycles_used, 0);
41189+ atomic_set_unchecked(&dev->bytes_rendered, 0);
41190+ atomic_set_unchecked(&dev->bytes_identical, 0);
41191+ atomic_set_unchecked(&dev->bytes_sent, 0);
41192+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41193
41194 return count;
41195 }
41196diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41197index b0e2a42..e2df3ad 100644
41198--- a/drivers/video/uvesafb.c
41199+++ b/drivers/video/uvesafb.c
41200@@ -19,6 +19,7 @@
41201 #include <linux/io.h>
41202 #include <linux/mutex.h>
41203 #include <linux/slab.h>
41204+#include <linux/moduleloader.h>
41205 #include <video/edid.h>
41206 #include <video/uvesafb.h>
41207 #ifdef CONFIG_X86
41208@@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
41209 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
41210 par->pmi_setpal = par->ypan = 0;
41211 } else {
41212+
41213+#ifdef CONFIG_PAX_KERNEXEC
41214+#ifdef CONFIG_MODULES
41215+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
41216+#endif
41217+ if (!par->pmi_code) {
41218+ par->pmi_setpal = par->ypan = 0;
41219+ return 0;
41220+ }
41221+#endif
41222+
41223 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
41224 + task->t.regs.edi);
41225+
41226+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41227+ pax_open_kernel();
41228+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
41229+ pax_close_kernel();
41230+
41231+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
41232+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
41233+#else
41234 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
41235 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
41236+#endif
41237+
41238 printk(KERN_INFO "uvesafb: protected mode interface info at "
41239 "%04x:%04x\n",
41240 (u16)task->t.regs.es, (u16)task->t.regs.edi);
41241@@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
41242 par->ypan = ypan;
41243
41244 if (par->pmi_setpal || par->ypan) {
41245+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
41246 if (__supported_pte_mask & _PAGE_NX) {
41247 par->pmi_setpal = par->ypan = 0;
41248 printk(KERN_WARNING "uvesafb: NX protection is actively."
41249 "We have better not to use the PMI.\n");
41250- } else {
41251+ } else
41252+#endif
41253 uvesafb_vbe_getpmi(task, par);
41254- }
41255 }
41256 #else
41257 /* The protected mode interface is not available on non-x86. */
41258@@ -1836,6 +1860,11 @@ out:
41259 if (par->vbe_modes)
41260 kfree(par->vbe_modes);
41261
41262+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41263+ if (par->pmi_code)
41264+ module_free_exec(NULL, par->pmi_code);
41265+#endif
41266+
41267 framebuffer_release(info);
41268 return err;
41269 }
41270@@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
41271 kfree(par->vbe_state_orig);
41272 if (par->vbe_state_saved)
41273 kfree(par->vbe_state_saved);
41274+
41275+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41276+ if (par->pmi_code)
41277+ module_free_exec(NULL, par->pmi_code);
41278+#endif
41279+
41280 }
41281
41282 framebuffer_release(info);
41283diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
41284index 501b340..86bd4cf 100644
41285--- a/drivers/video/vesafb.c
41286+++ b/drivers/video/vesafb.c
41287@@ -9,6 +9,7 @@
41288 */
41289
41290 #include <linux/module.h>
41291+#include <linux/moduleloader.h>
41292 #include <linux/kernel.h>
41293 #include <linux/errno.h>
41294 #include <linux/string.h>
41295@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
41296 static int vram_total __initdata; /* Set total amount of memory */
41297 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
41298 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
41299-static void (*pmi_start)(void) __read_mostly;
41300-static void (*pmi_pal) (void) __read_mostly;
41301+static void (*pmi_start)(void) __read_only;
41302+static void (*pmi_pal) (void) __read_only;
41303 static int depth __read_mostly;
41304 static int vga_compat __read_mostly;
41305 /* --------------------------------------------------------------------- */
41306@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
41307 unsigned int size_vmode;
41308 unsigned int size_remap;
41309 unsigned int size_total;
41310+ void *pmi_code = NULL;
41311
41312 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
41313 return -ENODEV;
41314@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
41315 size_remap = size_total;
41316 vesafb_fix.smem_len = size_remap;
41317
41318-#ifndef __i386__
41319- screen_info.vesapm_seg = 0;
41320-#endif
41321-
41322 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
41323 printk(KERN_WARNING
41324 "vesafb: cannot reserve video memory at 0x%lx\n",
41325@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
41326 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
41327 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
41328
41329+#ifdef __i386__
41330+
41331+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41332+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
41333+ if (!pmi_code)
41334+#elif !defined(CONFIG_PAX_KERNEXEC)
41335+ if (0)
41336+#endif
41337+
41338+#endif
41339+ screen_info.vesapm_seg = 0;
41340+
41341 if (screen_info.vesapm_seg) {
41342- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
41343- screen_info.vesapm_seg,screen_info.vesapm_off);
41344+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
41345+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
41346 }
41347
41348 if (screen_info.vesapm_seg < 0xc000)
41349@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
41350
41351 if (ypan || pmi_setpal) {
41352 unsigned short *pmi_base;
41353+
41354 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
41355- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
41356- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
41357+
41358+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41359+ pax_open_kernel();
41360+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
41361+#else
41362+ pmi_code = pmi_base;
41363+#endif
41364+
41365+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
41366+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
41367+
41368+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41369+ pmi_start = ktva_ktla(pmi_start);
41370+ pmi_pal = ktva_ktla(pmi_pal);
41371+ pax_close_kernel();
41372+#endif
41373+
41374 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
41375 if (pmi_base[3]) {
41376 printk(KERN_INFO "vesafb: pmi: ports = ");
41377@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
41378 info->node, info->fix.id);
41379 return 0;
41380 err:
41381+
41382+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41383+ module_free_exec(NULL, pmi_code);
41384+#endif
41385+
41386 if (info->screen_base)
41387 iounmap(info->screen_base);
41388 framebuffer_release(info);
41389diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
41390index 88714ae..16c2e11 100644
41391--- a/drivers/video/via/via_clock.h
41392+++ b/drivers/video/via/via_clock.h
41393@@ -56,7 +56,7 @@ struct via_clock {
41394
41395 void (*set_engine_pll_state)(u8 state);
41396 void (*set_engine_pll)(struct via_pll_config config);
41397-};
41398+} __no_const;
41399
41400
41401 static inline u32 get_pll_internal_frequency(u32 ref_freq,
41402diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
41403index e56c934..fc22f4b 100644
41404--- a/drivers/xen/xen-pciback/conf_space.h
41405+++ b/drivers/xen/xen-pciback/conf_space.h
41406@@ -44,15 +44,15 @@ struct config_field {
41407 struct {
41408 conf_dword_write write;
41409 conf_dword_read read;
41410- } dw;
41411+ } __no_const dw;
41412 struct {
41413 conf_word_write write;
41414 conf_word_read read;
41415- } w;
41416+ } __no_const w;
41417 struct {
41418 conf_byte_write write;
41419 conf_byte_read read;
41420- } b;
41421+ } __no_const b;
41422 } u;
41423 struct list_head list;
41424 };
41425diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
41426index 014c8dd..6f3dfe6 100644
41427--- a/fs/9p/vfs_inode.c
41428+++ b/fs/9p/vfs_inode.c
41429@@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
41430 void
41431 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41432 {
41433- char *s = nd_get_link(nd);
41434+ const char *s = nd_get_link(nd);
41435
41436 p9_debug(P9_DEBUG_VFS, " %s %s\n",
41437 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
41438diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
41439index e95d1b6..3454244 100644
41440--- a/fs/Kconfig.binfmt
41441+++ b/fs/Kconfig.binfmt
41442@@ -89,7 +89,7 @@ config HAVE_AOUT
41443
41444 config BINFMT_AOUT
41445 tristate "Kernel support for a.out and ECOFF binaries"
41446- depends on HAVE_AOUT
41447+ depends on HAVE_AOUT && BROKEN
41448 ---help---
41449 A.out (Assembler.OUTput) is a set of formats for libraries and
41450 executables used in the earliest versions of UNIX. Linux used
41451diff --git a/fs/aio.c b/fs/aio.c
41452index e7f2fad..15ad8a4 100644
41453--- a/fs/aio.c
41454+++ b/fs/aio.c
41455@@ -118,7 +118,7 @@ static int aio_setup_ring(struct kioctx *ctx)
41456 size += sizeof(struct io_event) * nr_events;
41457 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
41458
41459- if (nr_pages < 0)
41460+ if (nr_pages <= 0)
41461 return -EINVAL;
41462
41463 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
41464@@ -1440,18 +1440,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
41465 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
41466 {
41467 ssize_t ret;
41468+ struct iovec iovstack;
41469
41470 #ifdef CONFIG_COMPAT
41471 if (compat)
41472 ret = compat_rw_copy_check_uvector(type,
41473 (struct compat_iovec __user *)kiocb->ki_buf,
41474- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41475+ kiocb->ki_nbytes, 1, &iovstack,
41476 &kiocb->ki_iovec, 1);
41477 else
41478 #endif
41479 ret = rw_copy_check_uvector(type,
41480 (struct iovec __user *)kiocb->ki_buf,
41481- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41482+ kiocb->ki_nbytes, 1, &iovstack,
41483 &kiocb->ki_iovec, 1);
41484 if (ret < 0)
41485 goto out;
41486@@ -1460,6 +1461,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
41487 if (ret < 0)
41488 goto out;
41489
41490+ if (kiocb->ki_iovec == &iovstack) {
41491+ kiocb->ki_inline_vec = iovstack;
41492+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
41493+ }
41494 kiocb->ki_nr_segs = kiocb->ki_nbytes;
41495 kiocb->ki_cur_seg = 0;
41496 /* ki_nbytes/left now reflect bytes instead of segs */
41497diff --git a/fs/attr.c b/fs/attr.c
41498index d94d1b6..f9bccd6 100644
41499--- a/fs/attr.c
41500+++ b/fs/attr.c
41501@@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
41502 unsigned long limit;
41503
41504 limit = rlimit(RLIMIT_FSIZE);
41505+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
41506 if (limit != RLIM_INFINITY && offset > limit)
41507 goto out_sig;
41508 if (offset > inode->i_sb->s_maxbytes)
41509diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
41510index da8876d..9f3e6d8 100644
41511--- a/fs/autofs4/waitq.c
41512+++ b/fs/autofs4/waitq.c
41513@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
41514 {
41515 unsigned long sigpipe, flags;
41516 mm_segment_t fs;
41517- const char *data = (const char *)addr;
41518+ const char __user *data = (const char __force_user *)addr;
41519 ssize_t wr = 0;
41520
41521 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
41522diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
41523index e18da23..affc30e 100644
41524--- a/fs/befs/linuxvfs.c
41525+++ b/fs/befs/linuxvfs.c
41526@@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41527 {
41528 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
41529 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
41530- char *link = nd_get_link(nd);
41531+ const char *link = nd_get_link(nd);
41532 if (!IS_ERR(link))
41533 kfree(link);
41534 }
41535diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
41536index d146e18..12d1bd1 100644
41537--- a/fs/binfmt_aout.c
41538+++ b/fs/binfmt_aout.c
41539@@ -16,6 +16,7 @@
41540 #include <linux/string.h>
41541 #include <linux/fs.h>
41542 #include <linux/file.h>
41543+#include <linux/security.h>
41544 #include <linux/stat.h>
41545 #include <linux/fcntl.h>
41546 #include <linux/ptrace.h>
41547@@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
41548 #endif
41549 # define START_STACK(u) ((void __user *)u.start_stack)
41550
41551+ memset(&dump, 0, sizeof(dump));
41552+
41553 fs = get_fs();
41554 set_fs(KERNEL_DS);
41555 has_dumped = 1;
41556@@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
41557
41558 /* If the size of the dump file exceeds the rlimit, then see what would happen
41559 if we wrote the stack, but not the data area. */
41560+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
41561 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
41562 dump.u_dsize = 0;
41563
41564 /* Make sure we have enough room to write the stack and data areas. */
41565+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
41566 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
41567 dump.u_ssize = 0;
41568
41569@@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41570 rlim = rlimit(RLIMIT_DATA);
41571 if (rlim >= RLIM_INFINITY)
41572 rlim = ~0;
41573+
41574+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
41575 if (ex.a_data + ex.a_bss > rlim)
41576 return -ENOMEM;
41577
41578@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41579
41580 install_exec_creds(bprm);
41581
41582+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
41583+ current->mm->pax_flags = 0UL;
41584+#endif
41585+
41586+#ifdef CONFIG_PAX_PAGEEXEC
41587+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
41588+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
41589+
41590+#ifdef CONFIG_PAX_EMUTRAMP
41591+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
41592+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
41593+#endif
41594+
41595+#ifdef CONFIG_PAX_MPROTECT
41596+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
41597+ current->mm->pax_flags |= MF_PAX_MPROTECT;
41598+#endif
41599+
41600+ }
41601+#endif
41602+
41603 if (N_MAGIC(ex) == OMAGIC) {
41604 unsigned long text_addr, map_size;
41605 loff_t pos;
41606@@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41607 }
41608
41609 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
41610- PROT_READ | PROT_WRITE | PROT_EXEC,
41611+ PROT_READ | PROT_WRITE,
41612 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
41613 fd_offset + ex.a_text);
41614 if (error != N_DATADDR(ex)) {
41615diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
41616index 16f7354..185d8dc 100644
41617--- a/fs/binfmt_elf.c
41618+++ b/fs/binfmt_elf.c
41619@@ -32,6 +32,7 @@
41620 #include <linux/elf.h>
41621 #include <linux/utsname.h>
41622 #include <linux/coredump.h>
41623+#include <linux/xattr.h>
41624 #include <asm/uaccess.h>
41625 #include <asm/param.h>
41626 #include <asm/page.h>
41627@@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
41628 #define elf_core_dump NULL
41629 #endif
41630
41631+#ifdef CONFIG_PAX_MPROTECT
41632+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
41633+#endif
41634+
41635 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
41636 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
41637 #else
41638@@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
41639 .load_binary = load_elf_binary,
41640 .load_shlib = load_elf_library,
41641 .core_dump = elf_core_dump,
41642+
41643+#ifdef CONFIG_PAX_MPROTECT
41644+ .handle_mprotect= elf_handle_mprotect,
41645+#endif
41646+
41647 .min_coredump = ELF_EXEC_PAGESIZE,
41648 };
41649
41650@@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
41651
41652 static int set_brk(unsigned long start, unsigned long end)
41653 {
41654+ unsigned long e = end;
41655+
41656 start = ELF_PAGEALIGN(start);
41657 end = ELF_PAGEALIGN(end);
41658 if (end > start) {
41659@@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
41660 if (BAD_ADDR(addr))
41661 return addr;
41662 }
41663- current->mm->start_brk = current->mm->brk = end;
41664+ current->mm->start_brk = current->mm->brk = e;
41665 return 0;
41666 }
41667
41668@@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41669 elf_addr_t __user *u_rand_bytes;
41670 const char *k_platform = ELF_PLATFORM;
41671 const char *k_base_platform = ELF_BASE_PLATFORM;
41672- unsigned char k_rand_bytes[16];
41673+ u32 k_rand_bytes[4];
41674 int items;
41675 elf_addr_t *elf_info;
41676 int ei_index = 0;
41677 const struct cred *cred = current_cred();
41678 struct vm_area_struct *vma;
41679+ unsigned long saved_auxv[AT_VECTOR_SIZE];
41680
41681 /*
41682 * In some cases (e.g. Hyper-Threading), we want to avoid L1
41683@@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41684 * Generate 16 random bytes for userspace PRNG seeding.
41685 */
41686 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
41687- u_rand_bytes = (elf_addr_t __user *)
41688- STACK_ALLOC(p, sizeof(k_rand_bytes));
41689+ srandom32(k_rand_bytes[0] ^ random32());
41690+ srandom32(k_rand_bytes[1] ^ random32());
41691+ srandom32(k_rand_bytes[2] ^ random32());
41692+ srandom32(k_rand_bytes[3] ^ random32());
41693+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
41694+ u_rand_bytes = (elf_addr_t __user *) p;
41695 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
41696 return -EFAULT;
41697
41698@@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41699 return -EFAULT;
41700 current->mm->env_end = p;
41701
41702+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
41703+
41704 /* Put the elf_info on the stack in the right place. */
41705 sp = (elf_addr_t __user *)envp + 1;
41706- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
41707+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
41708 return -EFAULT;
41709 return 0;
41710 }
41711@@ -380,10 +399,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41712 {
41713 struct elf_phdr *elf_phdata;
41714 struct elf_phdr *eppnt;
41715- unsigned long load_addr = 0;
41716+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
41717 int load_addr_set = 0;
41718 unsigned long last_bss = 0, elf_bss = 0;
41719- unsigned long error = ~0UL;
41720+ unsigned long error = -EINVAL;
41721 unsigned long total_size;
41722 int retval, i, size;
41723
41724@@ -429,6 +448,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41725 goto out_close;
41726 }
41727
41728+#ifdef CONFIG_PAX_SEGMEXEC
41729+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
41730+ pax_task_size = SEGMEXEC_TASK_SIZE;
41731+#endif
41732+
41733 eppnt = elf_phdata;
41734 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
41735 if (eppnt->p_type == PT_LOAD) {
41736@@ -472,8 +496,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41737 k = load_addr + eppnt->p_vaddr;
41738 if (BAD_ADDR(k) ||
41739 eppnt->p_filesz > eppnt->p_memsz ||
41740- eppnt->p_memsz > TASK_SIZE ||
41741- TASK_SIZE - eppnt->p_memsz < k) {
41742+ eppnt->p_memsz > pax_task_size ||
41743+ pax_task_size - eppnt->p_memsz < k) {
41744 error = -ENOMEM;
41745 goto out_close;
41746 }
41747@@ -525,6 +549,351 @@ out:
41748 return error;
41749 }
41750
41751+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
41752+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
41753+{
41754+ unsigned long pax_flags = 0UL;
41755+
41756+#ifdef CONFIG_PAX_PT_PAX_FLAGS
41757+
41758+#ifdef CONFIG_PAX_PAGEEXEC
41759+ if (elf_phdata->p_flags & PF_PAGEEXEC)
41760+ pax_flags |= MF_PAX_PAGEEXEC;
41761+#endif
41762+
41763+#ifdef CONFIG_PAX_SEGMEXEC
41764+ if (elf_phdata->p_flags & PF_SEGMEXEC)
41765+ pax_flags |= MF_PAX_SEGMEXEC;
41766+#endif
41767+
41768+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41769+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41770+ if ((__supported_pte_mask & _PAGE_NX))
41771+ pax_flags &= ~MF_PAX_SEGMEXEC;
41772+ else
41773+ pax_flags &= ~MF_PAX_PAGEEXEC;
41774+ }
41775+#endif
41776+
41777+#ifdef CONFIG_PAX_EMUTRAMP
41778+ if (elf_phdata->p_flags & PF_EMUTRAMP)
41779+ pax_flags |= MF_PAX_EMUTRAMP;
41780+#endif
41781+
41782+#ifdef CONFIG_PAX_MPROTECT
41783+ if (elf_phdata->p_flags & PF_MPROTECT)
41784+ pax_flags |= MF_PAX_MPROTECT;
41785+#endif
41786+
41787+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41788+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
41789+ pax_flags |= MF_PAX_RANDMMAP;
41790+#endif
41791+
41792+#endif
41793+
41794+ return pax_flags;
41795+}
41796+
41797+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
41798+{
41799+ unsigned long pax_flags = 0UL;
41800+
41801+#ifdef CONFIG_PAX_PT_PAX_FLAGS
41802+
41803+#ifdef CONFIG_PAX_PAGEEXEC
41804+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
41805+ pax_flags |= MF_PAX_PAGEEXEC;
41806+#endif
41807+
41808+#ifdef CONFIG_PAX_SEGMEXEC
41809+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
41810+ pax_flags |= MF_PAX_SEGMEXEC;
41811+#endif
41812+
41813+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41814+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41815+ if ((__supported_pte_mask & _PAGE_NX))
41816+ pax_flags &= ~MF_PAX_SEGMEXEC;
41817+ else
41818+ pax_flags &= ~MF_PAX_PAGEEXEC;
41819+ }
41820+#endif
41821+
41822+#ifdef CONFIG_PAX_EMUTRAMP
41823+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
41824+ pax_flags |= MF_PAX_EMUTRAMP;
41825+#endif
41826+
41827+#ifdef CONFIG_PAX_MPROTECT
41828+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
41829+ pax_flags |= MF_PAX_MPROTECT;
41830+#endif
41831+
41832+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41833+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
41834+ pax_flags |= MF_PAX_RANDMMAP;
41835+#endif
41836+
41837+#endif
41838+
41839+ return pax_flags;
41840+}
41841+
41842+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
41843+{
41844+ unsigned long pax_flags = 0UL;
41845+
41846+#ifdef CONFIG_PAX_EI_PAX
41847+
41848+#ifdef CONFIG_PAX_PAGEEXEC
41849+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
41850+ pax_flags |= MF_PAX_PAGEEXEC;
41851+#endif
41852+
41853+#ifdef CONFIG_PAX_SEGMEXEC
41854+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
41855+ pax_flags |= MF_PAX_SEGMEXEC;
41856+#endif
41857+
41858+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41859+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41860+ if ((__supported_pte_mask & _PAGE_NX))
41861+ pax_flags &= ~MF_PAX_SEGMEXEC;
41862+ else
41863+ pax_flags &= ~MF_PAX_PAGEEXEC;
41864+ }
41865+#endif
41866+
41867+#ifdef CONFIG_PAX_EMUTRAMP
41868+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
41869+ pax_flags |= MF_PAX_EMUTRAMP;
41870+#endif
41871+
41872+#ifdef CONFIG_PAX_MPROTECT
41873+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
41874+ pax_flags |= MF_PAX_MPROTECT;
41875+#endif
41876+
41877+#ifdef CONFIG_PAX_ASLR
41878+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
41879+ pax_flags |= MF_PAX_RANDMMAP;
41880+#endif
41881+
41882+#else
41883+
41884+#ifdef CONFIG_PAX_PAGEEXEC
41885+ pax_flags |= MF_PAX_PAGEEXEC;
41886+#endif
41887+
41888+#ifdef CONFIG_PAX_MPROTECT
41889+ pax_flags |= MF_PAX_MPROTECT;
41890+#endif
41891+
41892+#ifdef CONFIG_PAX_RANDMMAP
41893+ pax_flags |= MF_PAX_RANDMMAP;
41894+#endif
41895+
41896+#ifdef CONFIG_PAX_SEGMEXEC
41897+ if (!(pax_flags & MF_PAX_PAGEEXEC) || !(__supported_pte_mask & _PAGE_NX)) {
41898+ pax_flags &= ~MF_PAX_PAGEEXEC;
41899+ pax_flags |= MF_PAX_SEGMEXEC;
41900+ }
41901+#endif
41902+
41903+#endif
41904+
41905+ return pax_flags;
41906+}
41907+
41908+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
41909+{
41910+
41911+#ifdef CONFIG_PAX_PT_PAX_FLAGS
41912+ unsigned long i;
41913+
41914+ for (i = 0UL; i < elf_ex->e_phnum; i++)
41915+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
41916+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
41917+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
41918+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
41919+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
41920+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
41921+ return ~0UL;
41922+
41923+#ifdef CONFIG_PAX_SOFTMODE
41924+ if (pax_softmode)
41925+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
41926+ else
41927+#endif
41928+
41929+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
41930+ break;
41931+ }
41932+#endif
41933+
41934+ return ~0UL;
41935+}
41936+
41937+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
41938+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
41939+{
41940+ unsigned long pax_flags = 0UL;
41941+
41942+#ifdef CONFIG_PAX_PAGEEXEC
41943+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
41944+ pax_flags |= MF_PAX_PAGEEXEC;
41945+#endif
41946+
41947+#ifdef CONFIG_PAX_SEGMEXEC
41948+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
41949+ pax_flags |= MF_PAX_SEGMEXEC;
41950+#endif
41951+
41952+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41953+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41954+ if ((__supported_pte_mask & _PAGE_NX))
41955+ pax_flags &= ~MF_PAX_SEGMEXEC;
41956+ else
41957+ pax_flags &= ~MF_PAX_PAGEEXEC;
41958+ }
41959+#endif
41960+
41961+#ifdef CONFIG_PAX_EMUTRAMP
41962+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
41963+ pax_flags |= MF_PAX_EMUTRAMP;
41964+#endif
41965+
41966+#ifdef CONFIG_PAX_MPROTECT
41967+ if (pax_flags_softmode & MF_PAX_MPROTECT)
41968+ pax_flags |= MF_PAX_MPROTECT;
41969+#endif
41970+
41971+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41972+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
41973+ pax_flags |= MF_PAX_RANDMMAP;
41974+#endif
41975+
41976+ return pax_flags;
41977+}
41978+
41979+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
41980+{
41981+ unsigned long pax_flags = 0UL;
41982+
41983+#ifdef CONFIG_PAX_PAGEEXEC
41984+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
41985+ pax_flags |= MF_PAX_PAGEEXEC;
41986+#endif
41987+
41988+#ifdef CONFIG_PAX_SEGMEXEC
41989+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
41990+ pax_flags |= MF_PAX_SEGMEXEC;
41991+#endif
41992+
41993+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41994+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41995+ if ((__supported_pte_mask & _PAGE_NX))
41996+ pax_flags &= ~MF_PAX_SEGMEXEC;
41997+ else
41998+ pax_flags &= ~MF_PAX_PAGEEXEC;
41999+ }
42000+#endif
42001+
42002+#ifdef CONFIG_PAX_EMUTRAMP
42003+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42004+ pax_flags |= MF_PAX_EMUTRAMP;
42005+#endif
42006+
42007+#ifdef CONFIG_PAX_MPROTECT
42008+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42009+ pax_flags |= MF_PAX_MPROTECT;
42010+#endif
42011+
42012+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42013+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42014+ pax_flags |= MF_PAX_RANDMMAP;
42015+#endif
42016+
42017+ return pax_flags;
42018+}
42019+#endif
42020+
42021+static unsigned long pax_parse_xattr_pax(struct file * const file)
42022+{
42023+
42024+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42025+ ssize_t xattr_size, i;
42026+ unsigned char xattr_value[5];
42027+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42028+
42029+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42030+ if (xattr_size <= 0)
42031+ return ~0UL;
42032+
42033+ for (i = 0; i < xattr_size; i++)
42034+ switch (xattr_value[i]) {
42035+ default:
42036+ return ~0UL;
42037+
42038+#define parse_flag(option1, option2, flag) \
42039+ case option1: \
42040+ pax_flags_hardmode |= MF_PAX_##flag; \
42041+ break; \
42042+ case option2: \
42043+ pax_flags_softmode |= MF_PAX_##flag; \
42044+ break;
42045+
42046+ parse_flag('p', 'P', PAGEEXEC);
42047+ parse_flag('e', 'E', EMUTRAMP);
42048+ parse_flag('m', 'M', MPROTECT);
42049+ parse_flag('r', 'R', RANDMMAP);
42050+ parse_flag('s', 'S', SEGMEXEC);
42051+
42052+#undef parse_flag
42053+ }
42054+
42055+ if (pax_flags_hardmode & pax_flags_softmode)
42056+ return ~0UL;
42057+
42058+#ifdef CONFIG_PAX_SOFTMODE
42059+ if (pax_softmode)
42060+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42061+ else
42062+#endif
42063+
42064+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42065+#else
42066+ return ~0UL;
42067+#endif
42068+
42069+}
42070+
42071+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42072+{
42073+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42074+
42075+ pax_flags = pax_parse_ei_pax(elf_ex);
42076+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42077+ xattr_pax_flags = pax_parse_xattr_pax(file);
42078+
42079+ if (pt_pax_flags == ~0UL)
42080+ pt_pax_flags = xattr_pax_flags;
42081+ else if (xattr_pax_flags == ~0UL)
42082+ xattr_pax_flags = pt_pax_flags;
42083+ if (pt_pax_flags != xattr_pax_flags)
42084+ return -EINVAL;
42085+ if (pt_pax_flags != ~0UL)
42086+ pax_flags = pt_pax_flags;
42087+
42088+ if (0 > pax_check_flags(&pax_flags))
42089+ return -EINVAL;
42090+
42091+ current->mm->pax_flags = pax_flags;
42092+ return 0;
42093+}
42094+#endif
42095+
42096 /*
42097 * These are the functions used to load ELF style executables and shared
42098 * libraries. There is no binary dependent code anywhere else.
42099@@ -541,6 +910,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42100 {
42101 unsigned int random_variable = 0;
42102
42103+#ifdef CONFIG_PAX_RANDUSTACK
42104+ if (randomize_va_space)
42105+ return stack_top - current->mm->delta_stack;
42106+#endif
42107+
42108 if ((current->flags & PF_RANDOMIZE) &&
42109 !(current->personality & ADDR_NO_RANDOMIZE)) {
42110 random_variable = get_random_int() & STACK_RND_MASK;
42111@@ -559,7 +933,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42112 unsigned long load_addr = 0, load_bias = 0;
42113 int load_addr_set = 0;
42114 char * elf_interpreter = NULL;
42115- unsigned long error;
42116+ unsigned long error = 0;
42117 struct elf_phdr *elf_ppnt, *elf_phdata;
42118 unsigned long elf_bss, elf_brk;
42119 int retval, i;
42120@@ -569,11 +943,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42121 unsigned long start_code, end_code, start_data, end_data;
42122 unsigned long reloc_func_desc __maybe_unused = 0;
42123 int executable_stack = EXSTACK_DEFAULT;
42124- unsigned long def_flags = 0;
42125 struct {
42126 struct elfhdr elf_ex;
42127 struct elfhdr interp_elf_ex;
42128 } *loc;
42129+ unsigned long pax_task_size = TASK_SIZE;
42130
42131 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42132 if (!loc) {
42133@@ -709,11 +1083,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42134 goto out_free_dentry;
42135
42136 /* OK, This is the point of no return */
42137- current->mm->def_flags = def_flags;
42138+
42139+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42140+ current->mm->pax_flags = 0UL;
42141+#endif
42142+
42143+#ifdef CONFIG_PAX_DLRESOLVE
42144+ current->mm->call_dl_resolve = 0UL;
42145+#endif
42146+
42147+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42148+ current->mm->call_syscall = 0UL;
42149+#endif
42150+
42151+#ifdef CONFIG_PAX_ASLR
42152+ current->mm->delta_mmap = 0UL;
42153+ current->mm->delta_stack = 0UL;
42154+#endif
42155+
42156+ current->mm->def_flags = 0;
42157+
42158+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42159+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42160+ send_sig(SIGKILL, current, 0);
42161+ goto out_free_dentry;
42162+ }
42163+#endif
42164+
42165+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42166+ pax_set_initial_flags(bprm);
42167+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42168+ if (pax_set_initial_flags_func)
42169+ (pax_set_initial_flags_func)(bprm);
42170+#endif
42171+
42172+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42173+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42174+ current->mm->context.user_cs_limit = PAGE_SIZE;
42175+ current->mm->def_flags |= VM_PAGEEXEC;
42176+ }
42177+#endif
42178+
42179+#ifdef CONFIG_PAX_SEGMEXEC
42180+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42181+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42182+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42183+ pax_task_size = SEGMEXEC_TASK_SIZE;
42184+ current->mm->def_flags |= VM_NOHUGEPAGE;
42185+ }
42186+#endif
42187+
42188+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42189+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42190+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42191+ put_cpu();
42192+ }
42193+#endif
42194
42195 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42196 may depend on the personality. */
42197 SET_PERSONALITY(loc->elf_ex);
42198+
42199+#ifdef CONFIG_PAX_ASLR
42200+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42201+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42202+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42203+ }
42204+#endif
42205+
42206+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42207+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42208+ executable_stack = EXSTACK_DISABLE_X;
42209+ current->personality &= ~READ_IMPLIES_EXEC;
42210+ } else
42211+#endif
42212+
42213 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42214 current->personality |= READ_IMPLIES_EXEC;
42215
42216@@ -804,6 +1248,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42217 #else
42218 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42219 #endif
42220+
42221+#ifdef CONFIG_PAX_RANDMMAP
42222+ /* PaX: randomize base address at the default exe base if requested */
42223+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
42224+#ifdef CONFIG_SPARC64
42225+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
42226+#else
42227+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
42228+#endif
42229+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
42230+ elf_flags |= MAP_FIXED;
42231+ }
42232+#endif
42233+
42234 }
42235
42236 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
42237@@ -836,9 +1294,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42238 * allowed task size. Note that p_filesz must always be
42239 * <= p_memsz so it is only necessary to check p_memsz.
42240 */
42241- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42242- elf_ppnt->p_memsz > TASK_SIZE ||
42243- TASK_SIZE - elf_ppnt->p_memsz < k) {
42244+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42245+ elf_ppnt->p_memsz > pax_task_size ||
42246+ pax_task_size - elf_ppnt->p_memsz < k) {
42247 /* set_brk can never work. Avoid overflows. */
42248 send_sig(SIGKILL, current, 0);
42249 retval = -EINVAL;
42250@@ -877,11 +1335,40 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42251 goto out_free_dentry;
42252 }
42253 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
42254- send_sig(SIGSEGV, current, 0);
42255- retval = -EFAULT; /* Nobody gets to see this, but.. */
42256- goto out_free_dentry;
42257+ /*
42258+ * This bss-zeroing can fail if the ELF
42259+ * file specifies odd protections. So
42260+ * we don't check the return value
42261+ */
42262 }
42263
42264+#ifdef CONFIG_PAX_RANDMMAP
42265+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42266+ unsigned long start, size;
42267+
42268+ start = ELF_PAGEALIGN(elf_brk);
42269+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
42270+ down_write(&current->mm->mmap_sem);
42271+ retval = -ENOMEM;
42272+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
42273+ unsigned long prot = PROT_NONE;
42274+
42275+ current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
42276+// if (current->personality & ADDR_NO_RANDOMIZE)
42277+// prot = PROT_READ;
42278+ start = do_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
42279+ retval = IS_ERR_VALUE(start) ? start : 0;
42280+ }
42281+ up_write(&current->mm->mmap_sem);
42282+ if (retval == 0)
42283+ retval = set_brk(start + size, start + size + PAGE_SIZE);
42284+ if (retval < 0) {
42285+ send_sig(SIGKILL, current, 0);
42286+ goto out_free_dentry;
42287+ }
42288+ }
42289+#endif
42290+
42291 if (elf_interpreter) {
42292 unsigned long uninitialized_var(interp_map_addr);
42293
42294@@ -1109,7 +1596,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
42295 * Decide what to dump of a segment, part, all or none.
42296 */
42297 static unsigned long vma_dump_size(struct vm_area_struct *vma,
42298- unsigned long mm_flags)
42299+ unsigned long mm_flags, long signr)
42300 {
42301 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
42302
42303@@ -1146,7 +1633,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
42304 if (vma->vm_file == NULL)
42305 return 0;
42306
42307- if (FILTER(MAPPED_PRIVATE))
42308+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
42309 goto whole;
42310
42311 /*
42312@@ -1368,9 +1855,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
42313 {
42314 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
42315 int i = 0;
42316- do
42317+ do {
42318 i += 2;
42319- while (auxv[i - 2] != AT_NULL);
42320+ } while (auxv[i - 2] != AT_NULL);
42321 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
42322 }
42323
42324@@ -1892,14 +2379,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
42325 }
42326
42327 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
42328- unsigned long mm_flags)
42329+ struct coredump_params *cprm)
42330 {
42331 struct vm_area_struct *vma;
42332 size_t size = 0;
42333
42334 for (vma = first_vma(current, gate_vma); vma != NULL;
42335 vma = next_vma(vma, gate_vma))
42336- size += vma_dump_size(vma, mm_flags);
42337+ size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42338 return size;
42339 }
42340
42341@@ -1993,7 +2480,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42342
42343 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
42344
42345- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
42346+ offset += elf_core_vma_data_size(gate_vma, cprm);
42347 offset += elf_core_extra_data_size();
42348 e_shoff = offset;
42349
42350@@ -2007,10 +2494,12 @@ static int elf_core_dump(struct coredump_params *cprm)
42351 offset = dataoff;
42352
42353 size += sizeof(*elf);
42354+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
42355 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
42356 goto end_coredump;
42357
42358 size += sizeof(*phdr4note);
42359+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
42360 if (size > cprm->limit
42361 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
42362 goto end_coredump;
42363@@ -2024,7 +2513,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42364 phdr.p_offset = offset;
42365 phdr.p_vaddr = vma->vm_start;
42366 phdr.p_paddr = 0;
42367- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
42368+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42369 phdr.p_memsz = vma->vm_end - vma->vm_start;
42370 offset += phdr.p_filesz;
42371 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
42372@@ -2035,6 +2524,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42373 phdr.p_align = ELF_EXEC_PAGESIZE;
42374
42375 size += sizeof(phdr);
42376+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
42377 if (size > cprm->limit
42378 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
42379 goto end_coredump;
42380@@ -2059,7 +2549,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42381 unsigned long addr;
42382 unsigned long end;
42383
42384- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
42385+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42386
42387 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
42388 struct page *page;
42389@@ -2068,6 +2558,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42390 page = get_dump_page(addr);
42391 if (page) {
42392 void *kaddr = kmap(page);
42393+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
42394 stop = ((size += PAGE_SIZE) > cprm->limit) ||
42395 !dump_write(cprm->file, kaddr,
42396 PAGE_SIZE);
42397@@ -2085,6 +2576,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42398
42399 if (e_phnum == PN_XNUM) {
42400 size += sizeof(*shdr4extnum);
42401+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
42402 if (size > cprm->limit
42403 || !dump_write(cprm->file, shdr4extnum,
42404 sizeof(*shdr4extnum)))
42405@@ -2105,6 +2597,97 @@ out:
42406
42407 #endif /* CONFIG_ELF_CORE */
42408
42409+#ifdef CONFIG_PAX_MPROTECT
42410+/* PaX: non-PIC ELF libraries need relocations on their executable segments
42411+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
42412+ * we'll remove VM_MAYWRITE for good on RELRO segments.
42413+ *
42414+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
42415+ * basis because we want to allow the common case and not the special ones.
42416+ */
42417+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
42418+{
42419+ struct elfhdr elf_h;
42420+ struct elf_phdr elf_p;
42421+ unsigned long i;
42422+ unsigned long oldflags;
42423+ bool is_textrel_rw, is_textrel_rx, is_relro;
42424+
42425+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
42426+ return;
42427+
42428+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
42429+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
42430+
42431+#ifdef CONFIG_PAX_ELFRELOCS
42432+ /* possible TEXTREL */
42433+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
42434+ 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);
42435+#else
42436+ is_textrel_rw = false;
42437+ is_textrel_rx = false;
42438+#endif
42439+
42440+ /* possible RELRO */
42441+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
42442+
42443+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
42444+ return;
42445+
42446+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
42447+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
42448+
42449+#ifdef CONFIG_PAX_ETEXECRELOCS
42450+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42451+#else
42452+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
42453+#endif
42454+
42455+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42456+ !elf_check_arch(&elf_h) ||
42457+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
42458+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
42459+ return;
42460+
42461+ for (i = 0UL; i < elf_h.e_phnum; i++) {
42462+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
42463+ return;
42464+ switch (elf_p.p_type) {
42465+ case PT_DYNAMIC:
42466+ if (!is_textrel_rw && !is_textrel_rx)
42467+ continue;
42468+ i = 0UL;
42469+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
42470+ elf_dyn dyn;
42471+
42472+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
42473+ return;
42474+ if (dyn.d_tag == DT_NULL)
42475+ return;
42476+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
42477+ gr_log_textrel(vma);
42478+ if (is_textrel_rw)
42479+ vma->vm_flags |= VM_MAYWRITE;
42480+ else
42481+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
42482+ vma->vm_flags &= ~VM_MAYWRITE;
42483+ return;
42484+ }
42485+ i++;
42486+ }
42487+ return;
42488+
42489+ case PT_GNU_RELRO:
42490+ if (!is_relro)
42491+ continue;
42492+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
42493+ vma->vm_flags &= ~VM_MAYWRITE;
42494+ return;
42495+ }
42496+ }
42497+}
42498+#endif
42499+
42500 static int __init init_elf_binfmt(void)
42501 {
42502 register_binfmt(&elf_format);
42503diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
42504index 6b2daf9..a70dccb 100644
42505--- a/fs/binfmt_flat.c
42506+++ b/fs/binfmt_flat.c
42507@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
42508 realdatastart = (unsigned long) -ENOMEM;
42509 printk("Unable to allocate RAM for process data, errno %d\n",
42510 (int)-realdatastart);
42511+ down_write(&current->mm->mmap_sem);
42512 do_munmap(current->mm, textpos, text_len);
42513+ up_write(&current->mm->mmap_sem);
42514 ret = realdatastart;
42515 goto err;
42516 }
42517@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42518 }
42519 if (IS_ERR_VALUE(result)) {
42520 printk("Unable to read data+bss, errno %d\n", (int)-result);
42521+ down_write(&current->mm->mmap_sem);
42522 do_munmap(current->mm, textpos, text_len);
42523 do_munmap(current->mm, realdatastart, len);
42524+ up_write(&current->mm->mmap_sem);
42525 ret = result;
42526 goto err;
42527 }
42528@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42529 }
42530 if (IS_ERR_VALUE(result)) {
42531 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
42532+ down_write(&current->mm->mmap_sem);
42533 do_munmap(current->mm, textpos, text_len + data_len + extra +
42534 MAX_SHARED_LIBS * sizeof(unsigned long));
42535+ up_write(&current->mm->mmap_sem);
42536 ret = result;
42537 goto err;
42538 }
42539diff --git a/fs/bio.c b/fs/bio.c
42540index 84da885..2149cd9 100644
42541--- a/fs/bio.c
42542+++ b/fs/bio.c
42543@@ -838,7 +838,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
42544 /*
42545 * Overflow, abort
42546 */
42547- if (end < start)
42548+ if (end < start || end - start > INT_MAX - nr_pages)
42549 return ERR_PTR(-EINVAL);
42550
42551 nr_pages += end - start;
42552@@ -1234,7 +1234,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
42553 const int read = bio_data_dir(bio) == READ;
42554 struct bio_map_data *bmd = bio->bi_private;
42555 int i;
42556- char *p = bmd->sgvecs[0].iov_base;
42557+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
42558
42559 __bio_for_each_segment(bvec, bio, i, 0) {
42560 char *addr = page_address(bvec->bv_page);
42561diff --git a/fs/block_dev.c b/fs/block_dev.c
42562index ba11c30..623d736 100644
42563--- a/fs/block_dev.c
42564+++ b/fs/block_dev.c
42565@@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
42566 else if (bdev->bd_contains == bdev)
42567 return true; /* is a whole device which isn't held */
42568
42569- else if (whole->bd_holder == bd_may_claim)
42570+ else if (whole->bd_holder == (void *)bd_may_claim)
42571 return true; /* is a partition of a device that is being partitioned */
42572 else if (whole->bd_holder != NULL)
42573 return false; /* is a partition of a held device */
42574diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
42575index c053e90..e5f1afc 100644
42576--- a/fs/btrfs/check-integrity.c
42577+++ b/fs/btrfs/check-integrity.c
42578@@ -156,7 +156,7 @@ struct btrfsic_block {
42579 union {
42580 bio_end_io_t *bio;
42581 bh_end_io_t *bh;
42582- } orig_bio_bh_end_io;
42583+ } __no_const orig_bio_bh_end_io;
42584 int submit_bio_bh_rw;
42585 u64 flush_gen; /* only valid if !never_written */
42586 };
42587diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
42588index 4106264..8157ede 100644
42589--- a/fs/btrfs/ctree.c
42590+++ b/fs/btrfs/ctree.c
42591@@ -513,9 +513,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
42592 free_extent_buffer(buf);
42593 add_root_to_dirty_list(root);
42594 } else {
42595- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
42596- parent_start = parent->start;
42597- else
42598+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
42599+ if (parent)
42600+ parent_start = parent->start;
42601+ else
42602+ parent_start = 0;
42603+ } else
42604 parent_start = 0;
42605
42606 WARN_ON(trans->transid != btrfs_header_generation(parent));
42607diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
42608index 0df0d1f..4bdcbfe 100644
42609--- a/fs/btrfs/inode.c
42610+++ b/fs/btrfs/inode.c
42611@@ -7074,7 +7074,7 @@ fail:
42612 return -ENOMEM;
42613 }
42614
42615-static int btrfs_getattr(struct vfsmount *mnt,
42616+int btrfs_getattr(struct vfsmount *mnt,
42617 struct dentry *dentry, struct kstat *stat)
42618 {
42619 struct inode *inode = dentry->d_inode;
42620@@ -7088,6 +7088,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
42621 return 0;
42622 }
42623
42624+EXPORT_SYMBOL(btrfs_getattr);
42625+
42626+dev_t get_btrfs_dev_from_inode(struct inode *inode)
42627+{
42628+ return BTRFS_I(inode)->root->anon_dev;
42629+}
42630+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
42631+
42632 /*
42633 * If a file is moved, it will inherit the cow and compression flags of the new
42634 * directory.
42635diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
42636index 14f8e1f..ab8d81f 100644
42637--- a/fs/btrfs/ioctl.c
42638+++ b/fs/btrfs/ioctl.c
42639@@ -2882,9 +2882,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
42640 for (i = 0; i < num_types; i++) {
42641 struct btrfs_space_info *tmp;
42642
42643+ /* Don't copy in more than we allocated */
42644 if (!slot_count)
42645 break;
42646
42647+ slot_count--;
42648+
42649 info = NULL;
42650 rcu_read_lock();
42651 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
42652@@ -2906,15 +2909,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
42653 memcpy(dest, &space, sizeof(space));
42654 dest++;
42655 space_args.total_spaces++;
42656- slot_count--;
42657 }
42658- if (!slot_count)
42659- break;
42660 }
42661 up_read(&info->groups_sem);
42662 }
42663
42664- user_dest = (struct btrfs_ioctl_space_info *)
42665+ user_dest = (struct btrfs_ioctl_space_info __user *)
42666 (arg + sizeof(struct btrfs_ioctl_space_args));
42667
42668 if (copy_to_user(user_dest, dest_orig, alloc_size))
42669diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
42670index 646ee21..f020f87 100644
42671--- a/fs/btrfs/relocation.c
42672+++ b/fs/btrfs/relocation.c
42673@@ -1268,7 +1268,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
42674 }
42675 spin_unlock(&rc->reloc_root_tree.lock);
42676
42677- BUG_ON((struct btrfs_root *)node->data != root);
42678+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
42679
42680 if (!del) {
42681 spin_lock(&rc->reloc_root_tree.lock);
42682diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
42683index 622f469..e8d2d55 100644
42684--- a/fs/cachefiles/bind.c
42685+++ b/fs/cachefiles/bind.c
42686@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
42687 args);
42688
42689 /* start by checking things over */
42690- ASSERT(cache->fstop_percent >= 0 &&
42691- cache->fstop_percent < cache->fcull_percent &&
42692+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
42693 cache->fcull_percent < cache->frun_percent &&
42694 cache->frun_percent < 100);
42695
42696- ASSERT(cache->bstop_percent >= 0 &&
42697- cache->bstop_percent < cache->bcull_percent &&
42698+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
42699 cache->bcull_percent < cache->brun_percent &&
42700 cache->brun_percent < 100);
42701
42702diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
42703index 0a1467b..6a53245 100644
42704--- a/fs/cachefiles/daemon.c
42705+++ b/fs/cachefiles/daemon.c
42706@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
42707 if (n > buflen)
42708 return -EMSGSIZE;
42709
42710- if (copy_to_user(_buffer, buffer, n) != 0)
42711+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
42712 return -EFAULT;
42713
42714 return n;
42715@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
42716 if (test_bit(CACHEFILES_DEAD, &cache->flags))
42717 return -EIO;
42718
42719- if (datalen < 0 || datalen > PAGE_SIZE - 1)
42720+ if (datalen > PAGE_SIZE - 1)
42721 return -EOPNOTSUPP;
42722
42723 /* drag the command string into the kernel so we can parse it */
42724@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
42725 if (args[0] != '%' || args[1] != '\0')
42726 return -EINVAL;
42727
42728- if (fstop < 0 || fstop >= cache->fcull_percent)
42729+ if (fstop >= cache->fcull_percent)
42730 return cachefiles_daemon_range_error(cache, args);
42731
42732 cache->fstop_percent = fstop;
42733@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
42734 if (args[0] != '%' || args[1] != '\0')
42735 return -EINVAL;
42736
42737- if (bstop < 0 || bstop >= cache->bcull_percent)
42738+ if (bstop >= cache->bcull_percent)
42739 return cachefiles_daemon_range_error(cache, args);
42740
42741 cache->bstop_percent = bstop;
42742diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
42743index bd6bc1b..b627b53 100644
42744--- a/fs/cachefiles/internal.h
42745+++ b/fs/cachefiles/internal.h
42746@@ -57,7 +57,7 @@ struct cachefiles_cache {
42747 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
42748 struct rb_root active_nodes; /* active nodes (can't be culled) */
42749 rwlock_t active_lock; /* lock for active_nodes */
42750- atomic_t gravecounter; /* graveyard uniquifier */
42751+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
42752 unsigned frun_percent; /* when to stop culling (% files) */
42753 unsigned fcull_percent; /* when to start culling (% files) */
42754 unsigned fstop_percent; /* when to stop allocating (% files) */
42755@@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
42756 * proc.c
42757 */
42758 #ifdef CONFIG_CACHEFILES_HISTOGRAM
42759-extern atomic_t cachefiles_lookup_histogram[HZ];
42760-extern atomic_t cachefiles_mkdir_histogram[HZ];
42761-extern atomic_t cachefiles_create_histogram[HZ];
42762+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
42763+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
42764+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
42765
42766 extern int __init cachefiles_proc_init(void);
42767 extern void cachefiles_proc_cleanup(void);
42768 static inline
42769-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
42770+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
42771 {
42772 unsigned long jif = jiffies - start_jif;
42773 if (jif >= HZ)
42774 jif = HZ - 1;
42775- atomic_inc(&histogram[jif]);
42776+ atomic_inc_unchecked(&histogram[jif]);
42777 }
42778
42779 #else
42780diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
42781index 7f0771d..87d4f36 100644
42782--- a/fs/cachefiles/namei.c
42783+++ b/fs/cachefiles/namei.c
42784@@ -318,7 +318,7 @@ try_again:
42785 /* first step is to make up a grave dentry in the graveyard */
42786 sprintf(nbuffer, "%08x%08x",
42787 (uint32_t) get_seconds(),
42788- (uint32_t) atomic_inc_return(&cache->gravecounter));
42789+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
42790
42791 /* do the multiway lock magic */
42792 trap = lock_rename(cache->graveyard, dir);
42793diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
42794index eccd339..4c1d995 100644
42795--- a/fs/cachefiles/proc.c
42796+++ b/fs/cachefiles/proc.c
42797@@ -14,9 +14,9 @@
42798 #include <linux/seq_file.h>
42799 #include "internal.h"
42800
42801-atomic_t cachefiles_lookup_histogram[HZ];
42802-atomic_t cachefiles_mkdir_histogram[HZ];
42803-atomic_t cachefiles_create_histogram[HZ];
42804+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
42805+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
42806+atomic_unchecked_t cachefiles_create_histogram[HZ];
42807
42808 /*
42809 * display the latency histogram
42810@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
42811 return 0;
42812 default:
42813 index = (unsigned long) v - 3;
42814- x = atomic_read(&cachefiles_lookup_histogram[index]);
42815- y = atomic_read(&cachefiles_mkdir_histogram[index]);
42816- z = atomic_read(&cachefiles_create_histogram[index]);
42817+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
42818+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
42819+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
42820 if (x == 0 && y == 0 && z == 0)
42821 return 0;
42822
42823diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
42824index 0e3c092..818480e 100644
42825--- a/fs/cachefiles/rdwr.c
42826+++ b/fs/cachefiles/rdwr.c
42827@@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
42828 old_fs = get_fs();
42829 set_fs(KERNEL_DS);
42830 ret = file->f_op->write(
42831- file, (const void __user *) data, len, &pos);
42832+ file, (const void __force_user *) data, len, &pos);
42833 set_fs(old_fs);
42834 kunmap(page);
42835 if (ret != len)
42836diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
42837index 3e8094b..cb3ff3d 100644
42838--- a/fs/ceph/dir.c
42839+++ b/fs/ceph/dir.c
42840@@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
42841 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
42842 struct ceph_mds_client *mdsc = fsc->mdsc;
42843 unsigned frag = fpos_frag(filp->f_pos);
42844- int off = fpos_off(filp->f_pos);
42845+ unsigned int off = fpos_off(filp->f_pos);
42846 int err;
42847 u32 ftype;
42848 struct ceph_mds_reply_info_parsed *rinfo;
42849@@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
42850 if (nd &&
42851 (nd->flags & LOOKUP_OPEN) &&
42852 !(nd->intent.open.flags & O_CREAT)) {
42853- int mode = nd->intent.open.create_mode & ~current->fs->umask;
42854+ int mode = nd->intent.open.create_mode & ~current_umask();
42855 return ceph_lookup_open(dir, dentry, nd, mode, 1);
42856 }
42857
42858diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
42859index 2704646..c581c91 100644
42860--- a/fs/cifs/cifs_debug.c
42861+++ b/fs/cifs/cifs_debug.c
42862@@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
42863
42864 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
42865 #ifdef CONFIG_CIFS_STATS2
42866- atomic_set(&totBufAllocCount, 0);
42867- atomic_set(&totSmBufAllocCount, 0);
42868+ atomic_set_unchecked(&totBufAllocCount, 0);
42869+ atomic_set_unchecked(&totSmBufAllocCount, 0);
42870 #endif /* CONFIG_CIFS_STATS2 */
42871 spin_lock(&cifs_tcp_ses_lock);
42872 list_for_each(tmp1, &cifs_tcp_ses_list) {
42873@@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
42874 tcon = list_entry(tmp3,
42875 struct cifs_tcon,
42876 tcon_list);
42877- atomic_set(&tcon->num_smbs_sent, 0);
42878- atomic_set(&tcon->num_writes, 0);
42879- atomic_set(&tcon->num_reads, 0);
42880- atomic_set(&tcon->num_oplock_brks, 0);
42881- atomic_set(&tcon->num_opens, 0);
42882- atomic_set(&tcon->num_posixopens, 0);
42883- atomic_set(&tcon->num_posixmkdirs, 0);
42884- atomic_set(&tcon->num_closes, 0);
42885- atomic_set(&tcon->num_deletes, 0);
42886- atomic_set(&tcon->num_mkdirs, 0);
42887- atomic_set(&tcon->num_rmdirs, 0);
42888- atomic_set(&tcon->num_renames, 0);
42889- atomic_set(&tcon->num_t2renames, 0);
42890- atomic_set(&tcon->num_ffirst, 0);
42891- atomic_set(&tcon->num_fnext, 0);
42892- atomic_set(&tcon->num_fclose, 0);
42893- atomic_set(&tcon->num_hardlinks, 0);
42894- atomic_set(&tcon->num_symlinks, 0);
42895- atomic_set(&tcon->num_locks, 0);
42896+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
42897+ atomic_set_unchecked(&tcon->num_writes, 0);
42898+ atomic_set_unchecked(&tcon->num_reads, 0);
42899+ atomic_set_unchecked(&tcon->num_oplock_brks, 0);
42900+ atomic_set_unchecked(&tcon->num_opens, 0);
42901+ atomic_set_unchecked(&tcon->num_posixopens, 0);
42902+ atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
42903+ atomic_set_unchecked(&tcon->num_closes, 0);
42904+ atomic_set_unchecked(&tcon->num_deletes, 0);
42905+ atomic_set_unchecked(&tcon->num_mkdirs, 0);
42906+ atomic_set_unchecked(&tcon->num_rmdirs, 0);
42907+ atomic_set_unchecked(&tcon->num_renames, 0);
42908+ atomic_set_unchecked(&tcon->num_t2renames, 0);
42909+ atomic_set_unchecked(&tcon->num_ffirst, 0);
42910+ atomic_set_unchecked(&tcon->num_fnext, 0);
42911+ atomic_set_unchecked(&tcon->num_fclose, 0);
42912+ atomic_set_unchecked(&tcon->num_hardlinks, 0);
42913+ atomic_set_unchecked(&tcon->num_symlinks, 0);
42914+ atomic_set_unchecked(&tcon->num_locks, 0);
42915 }
42916 }
42917 }
42918@@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
42919 smBufAllocCount.counter, cifs_min_small);
42920 #ifdef CONFIG_CIFS_STATS2
42921 seq_printf(m, "Total Large %d Small %d Allocations\n",
42922- atomic_read(&totBufAllocCount),
42923- atomic_read(&totSmBufAllocCount));
42924+ atomic_read_unchecked(&totBufAllocCount),
42925+ atomic_read_unchecked(&totSmBufAllocCount));
42926 #endif /* CONFIG_CIFS_STATS2 */
42927
42928 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
42929@@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
42930 if (tcon->need_reconnect)
42931 seq_puts(m, "\tDISCONNECTED ");
42932 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
42933- atomic_read(&tcon->num_smbs_sent),
42934- atomic_read(&tcon->num_oplock_brks));
42935+ atomic_read_unchecked(&tcon->num_smbs_sent),
42936+ atomic_read_unchecked(&tcon->num_oplock_brks));
42937 seq_printf(m, "\nReads: %d Bytes: %lld",
42938- atomic_read(&tcon->num_reads),
42939+ atomic_read_unchecked(&tcon->num_reads),
42940 (long long)(tcon->bytes_read));
42941 seq_printf(m, "\nWrites: %d Bytes: %lld",
42942- atomic_read(&tcon->num_writes),
42943+ atomic_read_unchecked(&tcon->num_writes),
42944 (long long)(tcon->bytes_written));
42945 seq_printf(m, "\nFlushes: %d",
42946- atomic_read(&tcon->num_flushes));
42947+ atomic_read_unchecked(&tcon->num_flushes));
42948 seq_printf(m, "\nLocks: %d HardLinks: %d "
42949 "Symlinks: %d",
42950- atomic_read(&tcon->num_locks),
42951- atomic_read(&tcon->num_hardlinks),
42952- atomic_read(&tcon->num_symlinks));
42953+ atomic_read_unchecked(&tcon->num_locks),
42954+ atomic_read_unchecked(&tcon->num_hardlinks),
42955+ atomic_read_unchecked(&tcon->num_symlinks));
42956 seq_printf(m, "\nOpens: %d Closes: %d "
42957 "Deletes: %d",
42958- atomic_read(&tcon->num_opens),
42959- atomic_read(&tcon->num_closes),
42960- atomic_read(&tcon->num_deletes));
42961+ atomic_read_unchecked(&tcon->num_opens),
42962+ atomic_read_unchecked(&tcon->num_closes),
42963+ atomic_read_unchecked(&tcon->num_deletes));
42964 seq_printf(m, "\nPosix Opens: %d "
42965 "Posix Mkdirs: %d",
42966- atomic_read(&tcon->num_posixopens),
42967- atomic_read(&tcon->num_posixmkdirs));
42968+ atomic_read_unchecked(&tcon->num_posixopens),
42969+ atomic_read_unchecked(&tcon->num_posixmkdirs));
42970 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
42971- atomic_read(&tcon->num_mkdirs),
42972- atomic_read(&tcon->num_rmdirs));
42973+ atomic_read_unchecked(&tcon->num_mkdirs),
42974+ atomic_read_unchecked(&tcon->num_rmdirs));
42975 seq_printf(m, "\nRenames: %d T2 Renames %d",
42976- atomic_read(&tcon->num_renames),
42977- atomic_read(&tcon->num_t2renames));
42978+ atomic_read_unchecked(&tcon->num_renames),
42979+ atomic_read_unchecked(&tcon->num_t2renames));
42980 seq_printf(m, "\nFindFirst: %d FNext %d "
42981 "FClose %d",
42982- atomic_read(&tcon->num_ffirst),
42983- atomic_read(&tcon->num_fnext),
42984- atomic_read(&tcon->num_fclose));
42985+ atomic_read_unchecked(&tcon->num_ffirst),
42986+ atomic_read_unchecked(&tcon->num_fnext),
42987+ atomic_read_unchecked(&tcon->num_fclose));
42988 }
42989 }
42990 }
42991diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
42992index 541ef81..a78deb8 100644
42993--- a/fs/cifs/cifsfs.c
42994+++ b/fs/cifs/cifsfs.c
42995@@ -985,7 +985,7 @@ cifs_init_request_bufs(void)
42996 cifs_req_cachep = kmem_cache_create("cifs_request",
42997 CIFSMaxBufSize +
42998 MAX_CIFS_HDR_SIZE, 0,
42999- SLAB_HWCACHE_ALIGN, NULL);
43000+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43001 if (cifs_req_cachep == NULL)
43002 return -ENOMEM;
43003
43004@@ -1012,7 +1012,7 @@ cifs_init_request_bufs(void)
43005 efficient to alloc 1 per page off the slab compared to 17K (5page)
43006 alloc of large cifs buffers even when page debugging is on */
43007 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43008- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43009+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43010 NULL);
43011 if (cifs_sm_req_cachep == NULL) {
43012 mempool_destroy(cifs_req_poolp);
43013@@ -1097,8 +1097,8 @@ init_cifs(void)
43014 atomic_set(&bufAllocCount, 0);
43015 atomic_set(&smBufAllocCount, 0);
43016 #ifdef CONFIG_CIFS_STATS2
43017- atomic_set(&totBufAllocCount, 0);
43018- atomic_set(&totSmBufAllocCount, 0);
43019+ atomic_set_unchecked(&totBufAllocCount, 0);
43020+ atomic_set_unchecked(&totSmBufAllocCount, 0);
43021 #endif /* CONFIG_CIFS_STATS2 */
43022
43023 atomic_set(&midCount, 0);
43024diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43025index 73fea28..b996b84 100644
43026--- a/fs/cifs/cifsglob.h
43027+++ b/fs/cifs/cifsglob.h
43028@@ -439,28 +439,28 @@ struct cifs_tcon {
43029 __u16 Flags; /* optional support bits */
43030 enum statusEnum tidStatus;
43031 #ifdef CONFIG_CIFS_STATS
43032- atomic_t num_smbs_sent;
43033- atomic_t num_writes;
43034- atomic_t num_reads;
43035- atomic_t num_flushes;
43036- atomic_t num_oplock_brks;
43037- atomic_t num_opens;
43038- atomic_t num_closes;
43039- atomic_t num_deletes;
43040- atomic_t num_mkdirs;
43041- atomic_t num_posixopens;
43042- atomic_t num_posixmkdirs;
43043- atomic_t num_rmdirs;
43044- atomic_t num_renames;
43045- atomic_t num_t2renames;
43046- atomic_t num_ffirst;
43047- atomic_t num_fnext;
43048- atomic_t num_fclose;
43049- atomic_t num_hardlinks;
43050- atomic_t num_symlinks;
43051- atomic_t num_locks;
43052- atomic_t num_acl_get;
43053- atomic_t num_acl_set;
43054+ atomic_unchecked_t num_smbs_sent;
43055+ atomic_unchecked_t num_writes;
43056+ atomic_unchecked_t num_reads;
43057+ atomic_unchecked_t num_flushes;
43058+ atomic_unchecked_t num_oplock_brks;
43059+ atomic_unchecked_t num_opens;
43060+ atomic_unchecked_t num_closes;
43061+ atomic_unchecked_t num_deletes;
43062+ atomic_unchecked_t num_mkdirs;
43063+ atomic_unchecked_t num_posixopens;
43064+ atomic_unchecked_t num_posixmkdirs;
43065+ atomic_unchecked_t num_rmdirs;
43066+ atomic_unchecked_t num_renames;
43067+ atomic_unchecked_t num_t2renames;
43068+ atomic_unchecked_t num_ffirst;
43069+ atomic_unchecked_t num_fnext;
43070+ atomic_unchecked_t num_fclose;
43071+ atomic_unchecked_t num_hardlinks;
43072+ atomic_unchecked_t num_symlinks;
43073+ atomic_unchecked_t num_locks;
43074+ atomic_unchecked_t num_acl_get;
43075+ atomic_unchecked_t num_acl_set;
43076 #ifdef CONFIG_CIFS_STATS2
43077 unsigned long long time_writes;
43078 unsigned long long time_reads;
43079@@ -677,7 +677,7 @@ convert_delimiter(char *path, char delim)
43080 }
43081
43082 #ifdef CONFIG_CIFS_STATS
43083-#define cifs_stats_inc atomic_inc
43084+#define cifs_stats_inc atomic_inc_unchecked
43085
43086 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43087 unsigned int bytes)
43088@@ -1036,8 +1036,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43089 /* Various Debug counters */
43090 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43091 #ifdef CONFIG_CIFS_STATS2
43092-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43093-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43094+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43095+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43096 #endif
43097 GLOBAL_EXTERN atomic_t smBufAllocCount;
43098 GLOBAL_EXTERN atomic_t midCount;
43099diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43100index 6b0e064..94e6c3c 100644
43101--- a/fs/cifs/link.c
43102+++ b/fs/cifs/link.c
43103@@ -600,7 +600,7 @@ symlink_exit:
43104
43105 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43106 {
43107- char *p = nd_get_link(nd);
43108+ const char *p = nd_get_link(nd);
43109 if (!IS_ERR(p))
43110 kfree(p);
43111 }
43112diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43113index c29d1aa..58018da 100644
43114--- a/fs/cifs/misc.c
43115+++ b/fs/cifs/misc.c
43116@@ -156,7 +156,7 @@ cifs_buf_get(void)
43117 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43118 atomic_inc(&bufAllocCount);
43119 #ifdef CONFIG_CIFS_STATS2
43120- atomic_inc(&totBufAllocCount);
43121+ atomic_inc_unchecked(&totBufAllocCount);
43122 #endif /* CONFIG_CIFS_STATS2 */
43123 }
43124
43125@@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43126 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43127 atomic_inc(&smBufAllocCount);
43128 #ifdef CONFIG_CIFS_STATS2
43129- atomic_inc(&totSmBufAllocCount);
43130+ atomic_inc_unchecked(&totSmBufAllocCount);
43131 #endif /* CONFIG_CIFS_STATS2 */
43132
43133 }
43134diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43135index 6901578..d402eb5 100644
43136--- a/fs/coda/cache.c
43137+++ b/fs/coda/cache.c
43138@@ -24,7 +24,7 @@
43139 #include "coda_linux.h"
43140 #include "coda_cache.h"
43141
43142-static atomic_t permission_epoch = ATOMIC_INIT(0);
43143+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43144
43145 /* replace or extend an acl cache hit */
43146 void coda_cache_enter(struct inode *inode, int mask)
43147@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43148 struct coda_inode_info *cii = ITOC(inode);
43149
43150 spin_lock(&cii->c_lock);
43151- cii->c_cached_epoch = atomic_read(&permission_epoch);
43152+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43153 if (cii->c_uid != current_fsuid()) {
43154 cii->c_uid = current_fsuid();
43155 cii->c_cached_perm = mask;
43156@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43157 {
43158 struct coda_inode_info *cii = ITOC(inode);
43159 spin_lock(&cii->c_lock);
43160- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43161+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43162 spin_unlock(&cii->c_lock);
43163 }
43164
43165 /* remove all acl caches */
43166 void coda_cache_clear_all(struct super_block *sb)
43167 {
43168- atomic_inc(&permission_epoch);
43169+ atomic_inc_unchecked(&permission_epoch);
43170 }
43171
43172
43173@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43174 spin_lock(&cii->c_lock);
43175 hit = (mask & cii->c_cached_perm) == mask &&
43176 cii->c_uid == current_fsuid() &&
43177- cii->c_cached_epoch == atomic_read(&permission_epoch);
43178+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43179 spin_unlock(&cii->c_lock);
43180
43181 return hit;
43182diff --git a/fs/compat.c b/fs/compat.c
43183index f2944ac..62845d2 100644
43184--- a/fs/compat.c
43185+++ b/fs/compat.c
43186@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43187
43188 set_fs(KERNEL_DS);
43189 /* The __user pointer cast is valid because of the set_fs() */
43190- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43191+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43192 set_fs(oldfs);
43193 /* truncating is ok because it's a user address */
43194 if (!ret)
43195@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43196 goto out;
43197
43198 ret = -EINVAL;
43199- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43200+ if (nr_segs > UIO_MAXIOV)
43201 goto out;
43202 if (nr_segs > fast_segs) {
43203 ret = -ENOMEM;
43204@@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
43205
43206 struct compat_readdir_callback {
43207 struct compat_old_linux_dirent __user *dirent;
43208+ struct file * file;
43209 int result;
43210 };
43211
43212@@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43213 buf->result = -EOVERFLOW;
43214 return -EOVERFLOW;
43215 }
43216+
43217+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43218+ return 0;
43219+
43220 buf->result++;
43221 dirent = buf->dirent;
43222 if (!access_ok(VERIFY_WRITE, dirent,
43223@@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
43224
43225 buf.result = 0;
43226 buf.dirent = dirent;
43227+ buf.file = file;
43228
43229 error = vfs_readdir(file, compat_fillonedir, &buf);
43230 if (buf.result)
43231@@ -900,6 +906,7 @@ struct compat_linux_dirent {
43232 struct compat_getdents_callback {
43233 struct compat_linux_dirent __user *current_dir;
43234 struct compat_linux_dirent __user *previous;
43235+ struct file * file;
43236 int count;
43237 int error;
43238 };
43239@@ -921,6 +928,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
43240 buf->error = -EOVERFLOW;
43241 return -EOVERFLOW;
43242 }
43243+
43244+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43245+ return 0;
43246+
43247 dirent = buf->previous;
43248 if (dirent) {
43249 if (__put_user(offset, &dirent->d_off))
43250@@ -968,6 +979,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43251 buf.previous = NULL;
43252 buf.count = count;
43253 buf.error = 0;
43254+ buf.file = file;
43255
43256 error = vfs_readdir(file, compat_filldir, &buf);
43257 if (error >= 0)
43258@@ -989,6 +1001,7 @@ out:
43259 struct compat_getdents_callback64 {
43260 struct linux_dirent64 __user *current_dir;
43261 struct linux_dirent64 __user *previous;
43262+ struct file * file;
43263 int count;
43264 int error;
43265 };
43266@@ -1005,6 +1018,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
43267 buf->error = -EINVAL; /* only used if we fail.. */
43268 if (reclen > buf->count)
43269 return -EINVAL;
43270+
43271+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43272+ return 0;
43273+
43274 dirent = buf->previous;
43275
43276 if (dirent) {
43277@@ -1056,13 +1073,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
43278 buf.previous = NULL;
43279 buf.count = count;
43280 buf.error = 0;
43281+ buf.file = file;
43282
43283 error = vfs_readdir(file, compat_filldir64, &buf);
43284 if (error >= 0)
43285 error = buf.error;
43286 lastdirent = buf.previous;
43287 if (lastdirent) {
43288- typeof(lastdirent->d_off) d_off = file->f_pos;
43289+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
43290 if (__put_user_unaligned(d_off, &lastdirent->d_off))
43291 error = -EFAULT;
43292 else
43293diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
43294index 112e45a..b59845b 100644
43295--- a/fs/compat_binfmt_elf.c
43296+++ b/fs/compat_binfmt_elf.c
43297@@ -30,11 +30,13 @@
43298 #undef elf_phdr
43299 #undef elf_shdr
43300 #undef elf_note
43301+#undef elf_dyn
43302 #undef elf_addr_t
43303 #define elfhdr elf32_hdr
43304 #define elf_phdr elf32_phdr
43305 #define elf_shdr elf32_shdr
43306 #define elf_note elf32_note
43307+#define elf_dyn Elf32_Dyn
43308 #define elf_addr_t Elf32_Addr
43309
43310 /*
43311diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
43312index debdfe0..75d31d4 100644
43313--- a/fs/compat_ioctl.c
43314+++ b/fs/compat_ioctl.c
43315@@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
43316
43317 err = get_user(palp, &up->palette);
43318 err |= get_user(length, &up->length);
43319+ if (err)
43320+ return -EFAULT;
43321
43322 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
43323 err = put_user(compat_ptr(palp), &up_native->palette);
43324@@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
43325 return -EFAULT;
43326 if (__get_user(udata, &ss32->iomem_base))
43327 return -EFAULT;
43328- ss.iomem_base = compat_ptr(udata);
43329+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
43330 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
43331 __get_user(ss.port_high, &ss32->port_high))
43332 return -EFAULT;
43333@@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
43334 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
43335 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
43336 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
43337- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43338+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43339 return -EFAULT;
43340
43341 return ioctl_preallocate(file, p);
43342@@ -1610,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
43343 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
43344 {
43345 unsigned int a, b;
43346- a = *(unsigned int *)p;
43347- b = *(unsigned int *)q;
43348+ a = *(const unsigned int *)p;
43349+ b = *(const unsigned int *)q;
43350 if (a > b)
43351 return 1;
43352 if (a < b)
43353diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
43354index 7e6c52d..94bc756 100644
43355--- a/fs/configfs/dir.c
43356+++ b/fs/configfs/dir.c
43357@@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43358 }
43359 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
43360 struct configfs_dirent *next;
43361- const char * name;
43362+ const unsigned char * name;
43363+ char d_name[sizeof(next->s_dentry->d_iname)];
43364 int len;
43365 struct inode *inode = NULL;
43366
43367@@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43368 continue;
43369
43370 name = configfs_get_name(next);
43371- len = strlen(name);
43372+ if (next->s_dentry && name == next->s_dentry->d_iname) {
43373+ len = next->s_dentry->d_name.len;
43374+ memcpy(d_name, name, len);
43375+ name = d_name;
43376+ } else
43377+ len = strlen(name);
43378
43379 /*
43380 * We'll have a dentry and an inode for
43381diff --git a/fs/dcache.c b/fs/dcache.c
43382index b80531c..8ca7e2d 100644
43383--- a/fs/dcache.c
43384+++ b/fs/dcache.c
43385@@ -3084,7 +3084,7 @@ void __init vfs_caches_init(unsigned long mempages)
43386 mempages -= reserve;
43387
43388 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
43389- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
43390+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
43391
43392 dcache_init();
43393 inode_init();
43394diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
43395index b80bc84..0d46d1a 100644
43396--- a/fs/debugfs/inode.c
43397+++ b/fs/debugfs/inode.c
43398@@ -408,7 +408,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
43399 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
43400 {
43401 return debugfs_create_file(name,
43402+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
43403+ S_IFDIR | S_IRWXU,
43404+#else
43405 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
43406+#endif
43407 parent, NULL, NULL);
43408 }
43409 EXPORT_SYMBOL_GPL(debugfs_create_dir);
43410diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
43411index ab35b11..b30af66 100644
43412--- a/fs/ecryptfs/inode.c
43413+++ b/fs/ecryptfs/inode.c
43414@@ -672,7 +672,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
43415 old_fs = get_fs();
43416 set_fs(get_ds());
43417 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
43418- (char __user *)lower_buf,
43419+ (char __force_user *)lower_buf,
43420 lower_bufsiz);
43421 set_fs(old_fs);
43422 if (rc < 0)
43423@@ -718,7 +718,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
43424 }
43425 old_fs = get_fs();
43426 set_fs(get_ds());
43427- rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
43428+ rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
43429 set_fs(old_fs);
43430 if (rc < 0) {
43431 kfree(buf);
43432@@ -733,7 +733,7 @@ out:
43433 static void
43434 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
43435 {
43436- char *buf = nd_get_link(nd);
43437+ const char *buf = nd_get_link(nd);
43438 if (!IS_ERR(buf)) {
43439 /* Free the char* */
43440 kfree(buf);
43441diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
43442index 3a06f40..f7af544 100644
43443--- a/fs/ecryptfs/miscdev.c
43444+++ b/fs/ecryptfs/miscdev.c
43445@@ -345,7 +345,7 @@ check_list:
43446 goto out_unlock_msg_ctx;
43447 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
43448 if (msg_ctx->msg) {
43449- if (copy_to_user(&buf[i], packet_length, packet_length_size))
43450+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
43451 goto out_unlock_msg_ctx;
43452 i += packet_length_size;
43453 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
43454diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
43455index b2a34a1..162fa69 100644
43456--- a/fs/ecryptfs/read_write.c
43457+++ b/fs/ecryptfs/read_write.c
43458@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
43459 return -EIO;
43460 fs_save = get_fs();
43461 set_fs(get_ds());
43462- rc = vfs_write(lower_file, data, size, &offset);
43463+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
43464 set_fs(fs_save);
43465 mark_inode_dirty_sync(ecryptfs_inode);
43466 return rc;
43467@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
43468 return -EIO;
43469 fs_save = get_fs();
43470 set_fs(get_ds());
43471- rc = vfs_read(lower_file, data, size, &offset);
43472+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
43473 set_fs(fs_save);
43474 return rc;
43475 }
43476diff --git a/fs/exec.c b/fs/exec.c
43477index b1fd202..582240d 100644
43478--- a/fs/exec.c
43479+++ b/fs/exec.c
43480@@ -55,6 +55,15 @@
43481 #include <linux/pipe_fs_i.h>
43482 #include <linux/oom.h>
43483 #include <linux/compat.h>
43484+#include <linux/random.h>
43485+#include <linux/seq_file.h>
43486+
43487+#ifdef CONFIG_PAX_REFCOUNT
43488+#include <linux/kallsyms.h>
43489+#include <linux/kdebug.h>
43490+#endif
43491+
43492+#include <trace/events/fs.h>
43493
43494 #include <asm/uaccess.h>
43495 #include <asm/mmu_context.h>
43496@@ -66,6 +75,18 @@
43497
43498 #include <trace/events/sched.h>
43499
43500+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43501+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
43502+{
43503+ WARN_ONCE(1, "PAX: PAX_HAVE_ACL_FLAGS was enabled without providing the pax_set_initial_flags callback, this is probably not what you wanted.\n");
43504+}
43505+#endif
43506+
43507+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
43508+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
43509+EXPORT_SYMBOL(pax_set_initial_flags_func);
43510+#endif
43511+
43512 int core_uses_pid;
43513 char core_pattern[CORENAME_MAX_SIZE] = "core";
43514 unsigned int core_pipe_limit;
43515@@ -75,7 +96,7 @@ struct core_name {
43516 char *corename;
43517 int used, size;
43518 };
43519-static atomic_t call_count = ATOMIC_INIT(1);
43520+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
43521
43522 /* The maximal length of core_pattern is also specified in sysctl.c */
43523
43524@@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
43525 int write)
43526 {
43527 struct page *page;
43528- int ret;
43529
43530-#ifdef CONFIG_STACK_GROWSUP
43531- if (write) {
43532- ret = expand_downwards(bprm->vma, pos);
43533- if (ret < 0)
43534- return NULL;
43535- }
43536-#endif
43537- ret = get_user_pages(current, bprm->mm, pos,
43538- 1, write, 1, &page, NULL);
43539- if (ret <= 0)
43540+ if (0 > expand_downwards(bprm->vma, pos))
43541+ return NULL;
43542+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
43543 return NULL;
43544
43545 if (write) {
43546@@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
43547 if (size <= ARG_MAX)
43548 return page;
43549
43550+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43551+ // only allow 512KB for argv+env on suid/sgid binaries
43552+ // to prevent easy ASLR exhaustion
43553+ if (((bprm->cred->euid != current_euid()) ||
43554+ (bprm->cred->egid != current_egid())) &&
43555+ (size > (512 * 1024))) {
43556+ put_page(page);
43557+ return NULL;
43558+ }
43559+#endif
43560+
43561 /*
43562 * Limit to 1/4-th the stack size for the argv+env strings.
43563 * This ensures that:
43564@@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
43565 vma->vm_end = STACK_TOP_MAX;
43566 vma->vm_start = vma->vm_end - PAGE_SIZE;
43567 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
43568+
43569+#ifdef CONFIG_PAX_SEGMEXEC
43570+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
43571+#endif
43572+
43573 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
43574 INIT_LIST_HEAD(&vma->anon_vma_chain);
43575
43576@@ -291,6 +320,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
43577 mm->stack_vm = mm->total_vm = 1;
43578 up_write(&mm->mmap_sem);
43579 bprm->p = vma->vm_end - sizeof(void *);
43580+
43581+#ifdef CONFIG_PAX_RANDUSTACK
43582+ if (randomize_va_space)
43583+ bprm->p ^= random32() & ~PAGE_MASK;
43584+#endif
43585+
43586 return 0;
43587 err:
43588 up_write(&mm->mmap_sem);
43589@@ -399,19 +434,7 @@ err:
43590 return err;
43591 }
43592
43593-struct user_arg_ptr {
43594-#ifdef CONFIG_COMPAT
43595- bool is_compat;
43596-#endif
43597- union {
43598- const char __user *const __user *native;
43599-#ifdef CONFIG_COMPAT
43600- compat_uptr_t __user *compat;
43601-#endif
43602- } ptr;
43603-};
43604-
43605-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43606+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43607 {
43608 const char __user *native;
43609
43610@@ -420,14 +443,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43611 compat_uptr_t compat;
43612
43613 if (get_user(compat, argv.ptr.compat + nr))
43614- return ERR_PTR(-EFAULT);
43615+ return (const char __force_user *)ERR_PTR(-EFAULT);
43616
43617 return compat_ptr(compat);
43618 }
43619 #endif
43620
43621 if (get_user(native, argv.ptr.native + nr))
43622- return ERR_PTR(-EFAULT);
43623+ return (const char __force_user *)ERR_PTR(-EFAULT);
43624
43625 return native;
43626 }
43627@@ -446,7 +469,7 @@ static int count(struct user_arg_ptr argv, int max)
43628 if (!p)
43629 break;
43630
43631- if (IS_ERR(p))
43632+ if (IS_ERR((const char __force_kernel *)p))
43633 return -EFAULT;
43634
43635 if (i++ >= max)
43636@@ -480,7 +503,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
43637
43638 ret = -EFAULT;
43639 str = get_user_arg_ptr(argv, argc);
43640- if (IS_ERR(str))
43641+ if (IS_ERR((const char __force_kernel *)str))
43642 goto out;
43643
43644 len = strnlen_user(str, MAX_ARG_STRLEN);
43645@@ -562,7 +585,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
43646 int r;
43647 mm_segment_t oldfs = get_fs();
43648 struct user_arg_ptr argv = {
43649- .ptr.native = (const char __user *const __user *)__argv,
43650+ .ptr.native = (const char __force_user *const __force_user *)__argv,
43651 };
43652
43653 set_fs(KERNEL_DS);
43654@@ -597,7 +620,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
43655 unsigned long new_end = old_end - shift;
43656 struct mmu_gather tlb;
43657
43658- BUG_ON(new_start > new_end);
43659+ if (new_start >= new_end || new_start < mmap_min_addr)
43660+ return -ENOMEM;
43661
43662 /*
43663 * ensure there are no vmas between where we want to go
43664@@ -606,6 +630,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
43665 if (vma != find_vma(mm, new_start))
43666 return -EFAULT;
43667
43668+#ifdef CONFIG_PAX_SEGMEXEC
43669+ BUG_ON(pax_find_mirror_vma(vma));
43670+#endif
43671+
43672 /*
43673 * cover the whole range: [new_start, old_end)
43674 */
43675@@ -686,10 +714,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
43676 stack_top = arch_align_stack(stack_top);
43677 stack_top = PAGE_ALIGN(stack_top);
43678
43679- if (unlikely(stack_top < mmap_min_addr) ||
43680- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
43681- return -ENOMEM;
43682-
43683 stack_shift = vma->vm_end - stack_top;
43684
43685 bprm->p -= stack_shift;
43686@@ -701,8 +725,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
43687 bprm->exec -= stack_shift;
43688
43689 down_write(&mm->mmap_sem);
43690+
43691+ /* Move stack pages down in memory. */
43692+ if (stack_shift) {
43693+ ret = shift_arg_pages(vma, stack_shift);
43694+ if (ret)
43695+ goto out_unlock;
43696+ }
43697+
43698 vm_flags = VM_STACK_FLAGS;
43699
43700+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43701+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43702+ vm_flags &= ~VM_EXEC;
43703+
43704+#ifdef CONFIG_PAX_MPROTECT
43705+ if (mm->pax_flags & MF_PAX_MPROTECT)
43706+ vm_flags &= ~VM_MAYEXEC;
43707+#endif
43708+
43709+ }
43710+#endif
43711+
43712 /*
43713 * Adjust stack execute permissions; explicitly enable for
43714 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
43715@@ -721,13 +765,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
43716 goto out_unlock;
43717 BUG_ON(prev != vma);
43718
43719- /* Move stack pages down in memory. */
43720- if (stack_shift) {
43721- ret = shift_arg_pages(vma, stack_shift);
43722- if (ret)
43723- goto out_unlock;
43724- }
43725-
43726 /* mprotect_fixup is overkill to remove the temporary stack flags */
43727 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
43728
43729@@ -785,6 +822,8 @@ struct file *open_exec(const char *name)
43730
43731 fsnotify_open(file);
43732
43733+ trace_open_exec(name);
43734+
43735 err = deny_write_access(file);
43736 if (err)
43737 goto exit;
43738@@ -808,7 +847,7 @@ int kernel_read(struct file *file, loff_t offset,
43739 old_fs = get_fs();
43740 set_fs(get_ds());
43741 /* The cast to a user pointer is valid due to the set_fs() */
43742- result = vfs_read(file, (void __user *)addr, count, &pos);
43743+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
43744 set_fs(old_fs);
43745 return result;
43746 }
43747@@ -1254,7 +1293,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
43748 }
43749 rcu_read_unlock();
43750
43751- if (p->fs->users > n_fs) {
43752+ if (atomic_read(&p->fs->users) > n_fs) {
43753 bprm->unsafe |= LSM_UNSAFE_SHARE;
43754 } else {
43755 res = -EAGAIN;
43756@@ -1451,6 +1490,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
43757
43758 EXPORT_SYMBOL(search_binary_handler);
43759
43760+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43761+static DEFINE_PER_CPU(u64, exec_counter);
43762+static int __init init_exec_counters(void)
43763+{
43764+ unsigned int cpu;
43765+
43766+ for_each_possible_cpu(cpu) {
43767+ per_cpu(exec_counter, cpu) = (u64)cpu;
43768+ }
43769+
43770+ return 0;
43771+}
43772+early_initcall(init_exec_counters);
43773+static inline void increment_exec_counter(void)
43774+{
43775+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
43776+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
43777+}
43778+#else
43779+static inline void increment_exec_counter(void) {}
43780+#endif
43781+
43782 /*
43783 * sys_execve() executes a new program.
43784 */
43785@@ -1459,6 +1520,11 @@ static int do_execve_common(const char *filename,
43786 struct user_arg_ptr envp,
43787 struct pt_regs *regs)
43788 {
43789+#ifdef CONFIG_GRKERNSEC
43790+ struct file *old_exec_file;
43791+ struct acl_subject_label *old_acl;
43792+ struct rlimit old_rlim[RLIM_NLIMITS];
43793+#endif
43794 struct linux_binprm *bprm;
43795 struct file *file;
43796 struct files_struct *displaced;
43797@@ -1466,6 +1532,8 @@ static int do_execve_common(const char *filename,
43798 int retval;
43799 const struct cred *cred = current_cred();
43800
43801+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
43802+
43803 /*
43804 * We move the actual failure in case of RLIMIT_NPROC excess from
43805 * set*uid() to execve() because too many poorly written programs
43806@@ -1506,12 +1574,27 @@ static int do_execve_common(const char *filename,
43807 if (IS_ERR(file))
43808 goto out_unmark;
43809
43810+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
43811+ retval = -EPERM;
43812+ goto out_file;
43813+ }
43814+
43815 sched_exec();
43816
43817 bprm->file = file;
43818 bprm->filename = filename;
43819 bprm->interp = filename;
43820
43821+ if (gr_process_user_ban()) {
43822+ retval = -EPERM;
43823+ goto out_file;
43824+ }
43825+
43826+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
43827+ retval = -EACCES;
43828+ goto out_file;
43829+ }
43830+
43831 retval = bprm_mm_init(bprm);
43832 if (retval)
43833 goto out_file;
43834@@ -1528,24 +1611,65 @@ static int do_execve_common(const char *filename,
43835 if (retval < 0)
43836 goto out;
43837
43838+#ifdef CONFIG_GRKERNSEC
43839+ old_acl = current->acl;
43840+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
43841+ old_exec_file = current->exec_file;
43842+ get_file(file);
43843+ current->exec_file = file;
43844+#endif
43845+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43846+ /* limit suid stack to 8MB
43847+ we saved the old limits above and will restore them if this exec fails
43848+ */
43849+ if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
43850+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
43851+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
43852+#endif
43853+
43854+ if (!gr_tpe_allow(file)) {
43855+ retval = -EACCES;
43856+ goto out_fail;
43857+ }
43858+
43859+ if (gr_check_crash_exec(file)) {
43860+ retval = -EACCES;
43861+ goto out_fail;
43862+ }
43863+
43864+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
43865+ bprm->unsafe);
43866+ if (retval < 0)
43867+ goto out_fail;
43868+
43869 retval = copy_strings_kernel(1, &bprm->filename, bprm);
43870 if (retval < 0)
43871- goto out;
43872+ goto out_fail;
43873
43874 bprm->exec = bprm->p;
43875 retval = copy_strings(bprm->envc, envp, bprm);
43876 if (retval < 0)
43877- goto out;
43878+ goto out_fail;
43879
43880 retval = copy_strings(bprm->argc, argv, bprm);
43881 if (retval < 0)
43882- goto out;
43883+ goto out_fail;
43884+
43885+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
43886+
43887+ gr_handle_exec_args(bprm, argv);
43888
43889 retval = search_binary_handler(bprm,regs);
43890 if (retval < 0)
43891- goto out;
43892+ goto out_fail;
43893+#ifdef CONFIG_GRKERNSEC
43894+ if (old_exec_file)
43895+ fput(old_exec_file);
43896+#endif
43897
43898 /* execve succeeded */
43899+
43900+ increment_exec_counter();
43901 current->fs->in_exec = 0;
43902 current->in_execve = 0;
43903 acct_update_integrals(current);
43904@@ -1554,6 +1678,14 @@ static int do_execve_common(const char *filename,
43905 put_files_struct(displaced);
43906 return retval;
43907
43908+out_fail:
43909+#ifdef CONFIG_GRKERNSEC
43910+ current->acl = old_acl;
43911+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
43912+ fput(current->exec_file);
43913+ current->exec_file = old_exec_file;
43914+#endif
43915+
43916 out:
43917 if (bprm->mm) {
43918 acct_arg_size(bprm, 0);
43919@@ -1627,7 +1759,7 @@ static int expand_corename(struct core_name *cn)
43920 {
43921 char *old_corename = cn->corename;
43922
43923- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
43924+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
43925 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
43926
43927 if (!cn->corename) {
43928@@ -1724,7 +1856,7 @@ static int format_corename(struct core_name *cn, long signr)
43929 int pid_in_pattern = 0;
43930 int err = 0;
43931
43932- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
43933+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
43934 cn->corename = kmalloc(cn->size, GFP_KERNEL);
43935 cn->used = 0;
43936
43937@@ -1821,6 +1953,228 @@ out:
43938 return ispipe;
43939 }
43940
43941+int pax_check_flags(unsigned long *flags)
43942+{
43943+ int retval = 0;
43944+
43945+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
43946+ if (*flags & MF_PAX_SEGMEXEC)
43947+ {
43948+ *flags &= ~MF_PAX_SEGMEXEC;
43949+ retval = -EINVAL;
43950+ }
43951+#endif
43952+
43953+ if ((*flags & MF_PAX_PAGEEXEC)
43954+
43955+#ifdef CONFIG_PAX_PAGEEXEC
43956+ && (*flags & MF_PAX_SEGMEXEC)
43957+#endif
43958+
43959+ )
43960+ {
43961+ *flags &= ~MF_PAX_PAGEEXEC;
43962+ retval = -EINVAL;
43963+ }
43964+
43965+ if ((*flags & MF_PAX_MPROTECT)
43966+
43967+#ifdef CONFIG_PAX_MPROTECT
43968+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
43969+#endif
43970+
43971+ )
43972+ {
43973+ *flags &= ~MF_PAX_MPROTECT;
43974+ retval = -EINVAL;
43975+ }
43976+
43977+ if ((*flags & MF_PAX_EMUTRAMP)
43978+
43979+#ifdef CONFIG_PAX_EMUTRAMP
43980+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
43981+#endif
43982+
43983+ )
43984+ {
43985+ *flags &= ~MF_PAX_EMUTRAMP;
43986+ retval = -EINVAL;
43987+ }
43988+
43989+ return retval;
43990+}
43991+
43992+EXPORT_SYMBOL(pax_check_flags);
43993+
43994+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43995+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
43996+{
43997+ struct task_struct *tsk = current;
43998+ struct mm_struct *mm = current->mm;
43999+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44000+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44001+ char *path_exec = NULL;
44002+ char *path_fault = NULL;
44003+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
44004+
44005+ if (buffer_exec && buffer_fault) {
44006+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44007+
44008+ down_read(&mm->mmap_sem);
44009+ vma = mm->mmap;
44010+ while (vma && (!vma_exec || !vma_fault)) {
44011+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44012+ vma_exec = vma;
44013+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44014+ vma_fault = vma;
44015+ vma = vma->vm_next;
44016+ }
44017+ if (vma_exec) {
44018+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44019+ if (IS_ERR(path_exec))
44020+ path_exec = "<path too long>";
44021+ else {
44022+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44023+ if (path_exec) {
44024+ *path_exec = 0;
44025+ path_exec = buffer_exec;
44026+ } else
44027+ path_exec = "<path too long>";
44028+ }
44029+ }
44030+ if (vma_fault) {
44031+ start = vma_fault->vm_start;
44032+ end = vma_fault->vm_end;
44033+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44034+ if (vma_fault->vm_file) {
44035+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44036+ if (IS_ERR(path_fault))
44037+ path_fault = "<path too long>";
44038+ else {
44039+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44040+ if (path_fault) {
44041+ *path_fault = 0;
44042+ path_fault = buffer_fault;
44043+ } else
44044+ path_fault = "<path too long>";
44045+ }
44046+ } else
44047+ path_fault = "<anonymous mapping>";
44048+ }
44049+ up_read(&mm->mmap_sem);
44050+ }
44051+ if (tsk->signal->curr_ip)
44052+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44053+ else
44054+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44055+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44056+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44057+ task_uid(tsk), task_euid(tsk), pc, sp);
44058+ free_page((unsigned long)buffer_exec);
44059+ free_page((unsigned long)buffer_fault);
44060+ pax_report_insns(regs, pc, sp);
44061+ do_coredump(SIGKILL, SIGKILL, regs);
44062+}
44063+#endif
44064+
44065+#ifdef CONFIG_PAX_REFCOUNT
44066+void pax_report_refcount_overflow(struct pt_regs *regs)
44067+{
44068+ if (current->signal->curr_ip)
44069+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44070+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44071+ else
44072+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44073+ current->comm, task_pid_nr(current), current_uid(), current_euid());
44074+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44075+ show_regs(regs);
44076+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44077+}
44078+#endif
44079+
44080+#ifdef CONFIG_PAX_USERCOPY
44081+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44082+int object_is_on_stack(const void *obj, unsigned long len)
44083+{
44084+ const void * const stack = task_stack_page(current);
44085+ const void * const stackend = stack + THREAD_SIZE;
44086+
44087+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44088+ const void *frame = NULL;
44089+ const void *oldframe;
44090+#endif
44091+
44092+ if (obj + len < obj)
44093+ return -1;
44094+
44095+ if (obj + len <= stack || stackend <= obj)
44096+ return 0;
44097+
44098+ if (obj < stack || stackend < obj + len)
44099+ return -1;
44100+
44101+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44102+ oldframe = __builtin_frame_address(1);
44103+ if (oldframe)
44104+ frame = __builtin_frame_address(2);
44105+ /*
44106+ low ----------------------------------------------> high
44107+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
44108+ ^----------------^
44109+ allow copies only within here
44110+ */
44111+ while (stack <= frame && frame < stackend) {
44112+ /* if obj + len extends past the last frame, this
44113+ check won't pass and the next frame will be 0,
44114+ causing us to bail out and correctly report
44115+ the copy as invalid
44116+ */
44117+ if (obj + len <= frame)
44118+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44119+ oldframe = frame;
44120+ frame = *(const void * const *)frame;
44121+ }
44122+ return -1;
44123+#else
44124+ return 1;
44125+#endif
44126+}
44127+
44128+__noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44129+{
44130+ if (current->signal->curr_ip)
44131+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44132+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44133+ else
44134+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44135+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44136+ dump_stack();
44137+ gr_handle_kernel_exploit();
44138+ do_group_exit(SIGKILL);
44139+}
44140+#endif
44141+
44142+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44143+void pax_track_stack(void)
44144+{
44145+ unsigned long sp = (unsigned long)&sp;
44146+ if (sp < current_thread_info()->lowest_stack &&
44147+ sp > (unsigned long)task_stack_page(current))
44148+ current_thread_info()->lowest_stack = sp;
44149+}
44150+EXPORT_SYMBOL(pax_track_stack);
44151+#endif
44152+
44153+#ifdef CONFIG_PAX_SIZE_OVERFLOW
44154+void report_size_overflow(const char *file, unsigned int line, const char *func)
44155+{
44156+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u\n", func, file, line);
44157+ dump_stack();
44158+ do_group_exit(SIGKILL);
44159+}
44160+EXPORT_SYMBOL(report_size_overflow);
44161+#endif
44162+
44163 static int zap_process(struct task_struct *start, int exit_code)
44164 {
44165 struct task_struct *t;
44166@@ -2018,17 +2372,17 @@ static void wait_for_dump_helpers(struct file *file)
44167 pipe = file->f_path.dentry->d_inode->i_pipe;
44168
44169 pipe_lock(pipe);
44170- pipe->readers++;
44171- pipe->writers--;
44172+ atomic_inc(&pipe->readers);
44173+ atomic_dec(&pipe->writers);
44174
44175- while ((pipe->readers > 1) && (!signal_pending(current))) {
44176+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44177 wake_up_interruptible_sync(&pipe->wait);
44178 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44179 pipe_wait(pipe);
44180 }
44181
44182- pipe->readers--;
44183- pipe->writers++;
44184+ atomic_dec(&pipe->readers);
44185+ atomic_inc(&pipe->writers);
44186 pipe_unlock(pipe);
44187
44188 }
44189@@ -2089,7 +2443,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44190 int retval = 0;
44191 int flag = 0;
44192 int ispipe;
44193- static atomic_t core_dump_count = ATOMIC_INIT(0);
44194+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44195 struct coredump_params cprm = {
44196 .signr = signr,
44197 .regs = regs,
44198@@ -2104,6 +2458,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44199
44200 audit_core_dumps(signr);
44201
44202+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44203+ gr_handle_brute_attach(current, cprm.mm_flags);
44204+
44205 binfmt = mm->binfmt;
44206 if (!binfmt || !binfmt->core_dump)
44207 goto fail;
44208@@ -2171,7 +2528,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44209 }
44210 cprm.limit = RLIM_INFINITY;
44211
44212- dump_count = atomic_inc_return(&core_dump_count);
44213+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
44214 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
44215 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
44216 task_tgid_vnr(current), current->comm);
44217@@ -2198,6 +2555,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44218 } else {
44219 struct inode *inode;
44220
44221+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
44222+
44223 if (cprm.limit < binfmt->min_coredump)
44224 goto fail_unlock;
44225
44226@@ -2241,7 +2600,7 @@ close_fail:
44227 filp_close(cprm.file, NULL);
44228 fail_dropcount:
44229 if (ispipe)
44230- atomic_dec(&core_dump_count);
44231+ atomic_dec_unchecked(&core_dump_count);
44232 fail_unlock:
44233 kfree(cn.corename);
44234 fail_corename:
44235@@ -2260,7 +2619,7 @@ fail:
44236 */
44237 int dump_write(struct file *file, const void *addr, int nr)
44238 {
44239- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
44240+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
44241 }
44242 EXPORT_SYMBOL(dump_write);
44243
44244diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
44245index a8cbe1b..fed04cb 100644
44246--- a/fs/ext2/balloc.c
44247+++ b/fs/ext2/balloc.c
44248@@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
44249
44250 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44251 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44252- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44253+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
44254 sbi->s_resuid != current_fsuid() &&
44255 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44256 return 0;
44257diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
44258index baac1b1..1499b62 100644
44259--- a/fs/ext3/balloc.c
44260+++ b/fs/ext3/balloc.c
44261@@ -1438,9 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
44262
44263 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44264 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44265- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44266+ if (free_blocks < root_blocks + 1 &&
44267 !use_reservation && sbi->s_resuid != current_fsuid() &&
44268- (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44269+ (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)) &&
44270+ !capable_nolog(CAP_SYS_RESOURCE)) {
44271 return 0;
44272 }
44273 return 1;
44274diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
44275index 8da837b..ed3835b 100644
44276--- a/fs/ext4/balloc.c
44277+++ b/fs/ext4/balloc.c
44278@@ -463,8 +463,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
44279 /* Hm, nope. Are (enough) root reserved clusters available? */
44280 if (sbi->s_resuid == current_fsuid() ||
44281 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
44282- capable(CAP_SYS_RESOURCE) ||
44283- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
44284+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
44285+ capable_nolog(CAP_SYS_RESOURCE)) {
44286
44287 if (free_clusters >= (nclusters + dirty_clusters))
44288 return 1;
44289diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
44290index 0e01e90..ae2bd5e 100644
44291--- a/fs/ext4/ext4.h
44292+++ b/fs/ext4/ext4.h
44293@@ -1225,19 +1225,19 @@ struct ext4_sb_info {
44294 unsigned long s_mb_last_start;
44295
44296 /* stats for buddy allocator */
44297- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
44298- atomic_t s_bal_success; /* we found long enough chunks */
44299- atomic_t s_bal_allocated; /* in blocks */
44300- atomic_t s_bal_ex_scanned; /* total extents scanned */
44301- atomic_t s_bal_goals; /* goal hits */
44302- atomic_t s_bal_breaks; /* too long searches */
44303- atomic_t s_bal_2orders; /* 2^order hits */
44304+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
44305+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
44306+ atomic_unchecked_t s_bal_allocated; /* in blocks */
44307+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
44308+ atomic_unchecked_t s_bal_goals; /* goal hits */
44309+ atomic_unchecked_t s_bal_breaks; /* too long searches */
44310+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
44311 spinlock_t s_bal_lock;
44312 unsigned long s_mb_buddies_generated;
44313 unsigned long long s_mb_generation_time;
44314- atomic_t s_mb_lost_chunks;
44315- atomic_t s_mb_preallocated;
44316- atomic_t s_mb_discarded;
44317+ atomic_unchecked_t s_mb_lost_chunks;
44318+ atomic_unchecked_t s_mb_preallocated;
44319+ atomic_unchecked_t s_mb_discarded;
44320 atomic_t s_lock_busy;
44321
44322 /* locality groups */
44323diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
44324index 6b0a57e..1955a44 100644
44325--- a/fs/ext4/mballoc.c
44326+++ b/fs/ext4/mballoc.c
44327@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
44328 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
44329
44330 if (EXT4_SB(sb)->s_mb_stats)
44331- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
44332+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
44333
44334 break;
44335 }
44336@@ -2041,7 +2041,7 @@ repeat:
44337 ac->ac_status = AC_STATUS_CONTINUE;
44338 ac->ac_flags |= EXT4_MB_HINT_FIRST;
44339 cr = 3;
44340- atomic_inc(&sbi->s_mb_lost_chunks);
44341+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
44342 goto repeat;
44343 }
44344 }
44345@@ -2545,25 +2545,25 @@ int ext4_mb_release(struct super_block *sb)
44346 if (sbi->s_mb_stats) {
44347 ext4_msg(sb, KERN_INFO,
44348 "mballoc: %u blocks %u reqs (%u success)",
44349- atomic_read(&sbi->s_bal_allocated),
44350- atomic_read(&sbi->s_bal_reqs),
44351- atomic_read(&sbi->s_bal_success));
44352+ atomic_read_unchecked(&sbi->s_bal_allocated),
44353+ atomic_read_unchecked(&sbi->s_bal_reqs),
44354+ atomic_read_unchecked(&sbi->s_bal_success));
44355 ext4_msg(sb, KERN_INFO,
44356 "mballoc: %u extents scanned, %u goal hits, "
44357 "%u 2^N hits, %u breaks, %u lost",
44358- atomic_read(&sbi->s_bal_ex_scanned),
44359- atomic_read(&sbi->s_bal_goals),
44360- atomic_read(&sbi->s_bal_2orders),
44361- atomic_read(&sbi->s_bal_breaks),
44362- atomic_read(&sbi->s_mb_lost_chunks));
44363+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
44364+ atomic_read_unchecked(&sbi->s_bal_goals),
44365+ atomic_read_unchecked(&sbi->s_bal_2orders),
44366+ atomic_read_unchecked(&sbi->s_bal_breaks),
44367+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
44368 ext4_msg(sb, KERN_INFO,
44369 "mballoc: %lu generated and it took %Lu",
44370 sbi->s_mb_buddies_generated,
44371 sbi->s_mb_generation_time);
44372 ext4_msg(sb, KERN_INFO,
44373 "mballoc: %u preallocated, %u discarded",
44374- atomic_read(&sbi->s_mb_preallocated),
44375- atomic_read(&sbi->s_mb_discarded));
44376+ atomic_read_unchecked(&sbi->s_mb_preallocated),
44377+ atomic_read_unchecked(&sbi->s_mb_discarded));
44378 }
44379
44380 free_percpu(sbi->s_locality_groups);
44381@@ -3045,16 +3045,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
44382 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
44383
44384 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
44385- atomic_inc(&sbi->s_bal_reqs);
44386- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44387+ atomic_inc_unchecked(&sbi->s_bal_reqs);
44388+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44389 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
44390- atomic_inc(&sbi->s_bal_success);
44391- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
44392+ atomic_inc_unchecked(&sbi->s_bal_success);
44393+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
44394 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
44395 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
44396- atomic_inc(&sbi->s_bal_goals);
44397+ atomic_inc_unchecked(&sbi->s_bal_goals);
44398 if (ac->ac_found > sbi->s_mb_max_to_scan)
44399- atomic_inc(&sbi->s_bal_breaks);
44400+ atomic_inc_unchecked(&sbi->s_bal_breaks);
44401 }
44402
44403 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
44404@@ -3458,7 +3458,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
44405 trace_ext4_mb_new_inode_pa(ac, pa);
44406
44407 ext4_mb_use_inode_pa(ac, pa);
44408- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
44409+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
44410
44411 ei = EXT4_I(ac->ac_inode);
44412 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44413@@ -3518,7 +3518,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
44414 trace_ext4_mb_new_group_pa(ac, pa);
44415
44416 ext4_mb_use_group_pa(ac, pa);
44417- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44418+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44419
44420 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44421 lg = ac->ac_lg;
44422@@ -3607,7 +3607,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
44423 * from the bitmap and continue.
44424 */
44425 }
44426- atomic_add(free, &sbi->s_mb_discarded);
44427+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
44428
44429 return err;
44430 }
44431@@ -3625,7 +3625,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
44432 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
44433 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
44434 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
44435- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44436+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44437 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
44438
44439 return 0;
44440diff --git a/fs/fcntl.c b/fs/fcntl.c
44441index 75e7c1f..1eb3e4d 100644
44442--- a/fs/fcntl.c
44443+++ b/fs/fcntl.c
44444@@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
44445 if (err)
44446 return err;
44447
44448+ if (gr_handle_chroot_fowner(pid, type))
44449+ return -ENOENT;
44450+ if (gr_check_protected_task_fowner(pid, type))
44451+ return -EACCES;
44452+
44453 f_modown(filp, pid, type, force);
44454 return 0;
44455 }
44456@@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
44457
44458 static int f_setown_ex(struct file *filp, unsigned long arg)
44459 {
44460- struct f_owner_ex * __user owner_p = (void * __user)arg;
44461+ struct f_owner_ex __user *owner_p = (void __user *)arg;
44462 struct f_owner_ex owner;
44463 struct pid *pid;
44464 int type;
44465@@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
44466
44467 static int f_getown_ex(struct file *filp, unsigned long arg)
44468 {
44469- struct f_owner_ex * __user owner_p = (void * __user)arg;
44470+ struct f_owner_ex __user *owner_p = (void __user *)arg;
44471 struct f_owner_ex owner;
44472 int ret = 0;
44473
44474@@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
44475 switch (cmd) {
44476 case F_DUPFD:
44477 case F_DUPFD_CLOEXEC:
44478+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
44479 if (arg >= rlimit(RLIMIT_NOFILE))
44480 break;
44481 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
44482diff --git a/fs/fifo.c b/fs/fifo.c
44483index b1a524d..4ee270e 100644
44484--- a/fs/fifo.c
44485+++ b/fs/fifo.c
44486@@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
44487 */
44488 filp->f_op = &read_pipefifo_fops;
44489 pipe->r_counter++;
44490- if (pipe->readers++ == 0)
44491+ if (atomic_inc_return(&pipe->readers) == 1)
44492 wake_up_partner(inode);
44493
44494- if (!pipe->writers) {
44495+ if (!atomic_read(&pipe->writers)) {
44496 if ((filp->f_flags & O_NONBLOCK)) {
44497 /* suppress POLLHUP until we have
44498 * seen a writer */
44499@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
44500 * errno=ENXIO when there is no process reading the FIFO.
44501 */
44502 ret = -ENXIO;
44503- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
44504+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
44505 goto err;
44506
44507 filp->f_op = &write_pipefifo_fops;
44508 pipe->w_counter++;
44509- if (!pipe->writers++)
44510+ if (atomic_inc_return(&pipe->writers) == 1)
44511 wake_up_partner(inode);
44512
44513- if (!pipe->readers) {
44514+ if (!atomic_read(&pipe->readers)) {
44515 wait_for_partner(inode, &pipe->r_counter);
44516 if (signal_pending(current))
44517 goto err_wr;
44518@@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
44519 */
44520 filp->f_op = &rdwr_pipefifo_fops;
44521
44522- pipe->readers++;
44523- pipe->writers++;
44524+ atomic_inc(&pipe->readers);
44525+ atomic_inc(&pipe->writers);
44526 pipe->r_counter++;
44527 pipe->w_counter++;
44528- if (pipe->readers == 1 || pipe->writers == 1)
44529+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
44530 wake_up_partner(inode);
44531 break;
44532
44533@@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
44534 return 0;
44535
44536 err_rd:
44537- if (!--pipe->readers)
44538+ if (atomic_dec_and_test(&pipe->readers))
44539 wake_up_interruptible(&pipe->wait);
44540 ret = -ERESTARTSYS;
44541 goto err;
44542
44543 err_wr:
44544- if (!--pipe->writers)
44545+ if (atomic_dec_and_test(&pipe->writers))
44546 wake_up_interruptible(&pipe->wait);
44547 ret = -ERESTARTSYS;
44548 goto err;
44549
44550 err:
44551- if (!pipe->readers && !pipe->writers)
44552+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
44553 free_pipe_info(inode);
44554
44555 err_nocleanup:
44556diff --git a/fs/file.c b/fs/file.c
44557index ba3f605..fade102 100644
44558--- a/fs/file.c
44559+++ b/fs/file.c
44560@@ -15,6 +15,7 @@
44561 #include <linux/slab.h>
44562 #include <linux/vmalloc.h>
44563 #include <linux/file.h>
44564+#include <linux/security.h>
44565 #include <linux/fdtable.h>
44566 #include <linux/bitops.h>
44567 #include <linux/interrupt.h>
44568@@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
44569 * N.B. For clone tasks sharing a files structure, this test
44570 * will limit the total number of files that can be opened.
44571 */
44572+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
44573 if (nr >= rlimit(RLIMIT_NOFILE))
44574 return -EMFILE;
44575
44576diff --git a/fs/filesystems.c b/fs/filesystems.c
44577index 96f2428..f5eeb8e 100644
44578--- a/fs/filesystems.c
44579+++ b/fs/filesystems.c
44580@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
44581 int len = dot ? dot - name : strlen(name);
44582
44583 fs = __get_fs_type(name, len);
44584+
44585+#ifdef CONFIG_GRKERNSEC_MODHARDEN
44586+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
44587+#else
44588 if (!fs && (request_module("%.*s", len, name) == 0))
44589+#endif
44590 fs = __get_fs_type(name, len);
44591
44592 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
44593diff --git a/fs/fs_struct.c b/fs/fs_struct.c
44594index e159e68..e7d2a6f 100644
44595--- a/fs/fs_struct.c
44596+++ b/fs/fs_struct.c
44597@@ -4,6 +4,7 @@
44598 #include <linux/path.h>
44599 #include <linux/slab.h>
44600 #include <linux/fs_struct.h>
44601+#include <linux/grsecurity.h>
44602 #include "internal.h"
44603
44604 static inline void path_get_longterm(struct path *path)
44605@@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
44606 write_seqcount_begin(&fs->seq);
44607 old_root = fs->root;
44608 fs->root = *path;
44609+ gr_set_chroot_entries(current, path);
44610 write_seqcount_end(&fs->seq);
44611 spin_unlock(&fs->lock);
44612 if (old_root.dentry)
44613@@ -65,6 +67,17 @@ static inline int replace_path(struct path *p, const struct path *old, const str
44614 return 1;
44615 }
44616
44617+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
44618+{
44619+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
44620+ return 0;
44621+ *p = *new;
44622+
44623+ gr_set_chroot_entries(task, new);
44624+
44625+ return 1;
44626+}
44627+
44628 void chroot_fs_refs(struct path *old_root, struct path *new_root)
44629 {
44630 struct task_struct *g, *p;
44631@@ -79,7 +92,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
44632 int hits = 0;
44633 spin_lock(&fs->lock);
44634 write_seqcount_begin(&fs->seq);
44635- hits += replace_path(&fs->root, old_root, new_root);
44636+ hits += replace_root_path(p, &fs->root, old_root, new_root);
44637 hits += replace_path(&fs->pwd, old_root, new_root);
44638 write_seqcount_end(&fs->seq);
44639 while (hits--) {
44640@@ -111,7 +124,8 @@ void exit_fs(struct task_struct *tsk)
44641 task_lock(tsk);
44642 spin_lock(&fs->lock);
44643 tsk->fs = NULL;
44644- kill = !--fs->users;
44645+ gr_clear_chroot_entries(tsk);
44646+ kill = !atomic_dec_return(&fs->users);
44647 spin_unlock(&fs->lock);
44648 task_unlock(tsk);
44649 if (kill)
44650@@ -124,7 +138,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
44651 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
44652 /* We don't need to lock fs - think why ;-) */
44653 if (fs) {
44654- fs->users = 1;
44655+ atomic_set(&fs->users, 1);
44656 fs->in_exec = 0;
44657 spin_lock_init(&fs->lock);
44658 seqcount_init(&fs->seq);
44659@@ -133,6 +147,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
44660 spin_lock(&old->lock);
44661 fs->root = old->root;
44662 path_get_longterm(&fs->root);
44663+ /* instead of calling gr_set_chroot_entries here,
44664+ we call it from every caller of this function
44665+ */
44666 fs->pwd = old->pwd;
44667 path_get_longterm(&fs->pwd);
44668 spin_unlock(&old->lock);
44669@@ -151,8 +168,9 @@ int unshare_fs_struct(void)
44670
44671 task_lock(current);
44672 spin_lock(&fs->lock);
44673- kill = !--fs->users;
44674+ kill = !atomic_dec_return(&fs->users);
44675 current->fs = new_fs;
44676+ gr_set_chroot_entries(current, &new_fs->root);
44677 spin_unlock(&fs->lock);
44678 task_unlock(current);
44679
44680@@ -165,13 +183,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
44681
44682 int current_umask(void)
44683 {
44684- return current->fs->umask;
44685+ return current->fs->umask | gr_acl_umask();
44686 }
44687 EXPORT_SYMBOL(current_umask);
44688
44689 /* to be mentioned only in INIT_TASK */
44690 struct fs_struct init_fs = {
44691- .users = 1,
44692+ .users = ATOMIC_INIT(1),
44693 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
44694 .seq = SEQCNT_ZERO,
44695 .umask = 0022,
44696@@ -187,12 +205,13 @@ void daemonize_fs_struct(void)
44697 task_lock(current);
44698
44699 spin_lock(&init_fs.lock);
44700- init_fs.users++;
44701+ atomic_inc(&init_fs.users);
44702 spin_unlock(&init_fs.lock);
44703
44704 spin_lock(&fs->lock);
44705 current->fs = &init_fs;
44706- kill = !--fs->users;
44707+ gr_set_chroot_entries(current, &current->fs->root);
44708+ kill = !atomic_dec_return(&fs->users);
44709 spin_unlock(&fs->lock);
44710
44711 task_unlock(current);
44712diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
44713index 9905350..02eaec4 100644
44714--- a/fs/fscache/cookie.c
44715+++ b/fs/fscache/cookie.c
44716@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
44717 parent ? (char *) parent->def->name : "<no-parent>",
44718 def->name, netfs_data);
44719
44720- fscache_stat(&fscache_n_acquires);
44721+ fscache_stat_unchecked(&fscache_n_acquires);
44722
44723 /* if there's no parent cookie, then we don't create one here either */
44724 if (!parent) {
44725- fscache_stat(&fscache_n_acquires_null);
44726+ fscache_stat_unchecked(&fscache_n_acquires_null);
44727 _leave(" [no parent]");
44728 return NULL;
44729 }
44730@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
44731 /* allocate and initialise a cookie */
44732 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
44733 if (!cookie) {
44734- fscache_stat(&fscache_n_acquires_oom);
44735+ fscache_stat_unchecked(&fscache_n_acquires_oom);
44736 _leave(" [ENOMEM]");
44737 return NULL;
44738 }
44739@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
44740
44741 switch (cookie->def->type) {
44742 case FSCACHE_COOKIE_TYPE_INDEX:
44743- fscache_stat(&fscache_n_cookie_index);
44744+ fscache_stat_unchecked(&fscache_n_cookie_index);
44745 break;
44746 case FSCACHE_COOKIE_TYPE_DATAFILE:
44747- fscache_stat(&fscache_n_cookie_data);
44748+ fscache_stat_unchecked(&fscache_n_cookie_data);
44749 break;
44750 default:
44751- fscache_stat(&fscache_n_cookie_special);
44752+ fscache_stat_unchecked(&fscache_n_cookie_special);
44753 break;
44754 }
44755
44756@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
44757 if (fscache_acquire_non_index_cookie(cookie) < 0) {
44758 atomic_dec(&parent->n_children);
44759 __fscache_cookie_put(cookie);
44760- fscache_stat(&fscache_n_acquires_nobufs);
44761+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
44762 _leave(" = NULL");
44763 return NULL;
44764 }
44765 }
44766
44767- fscache_stat(&fscache_n_acquires_ok);
44768+ fscache_stat_unchecked(&fscache_n_acquires_ok);
44769 _leave(" = %p", cookie);
44770 return cookie;
44771 }
44772@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
44773 cache = fscache_select_cache_for_object(cookie->parent);
44774 if (!cache) {
44775 up_read(&fscache_addremove_sem);
44776- fscache_stat(&fscache_n_acquires_no_cache);
44777+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
44778 _leave(" = -ENOMEDIUM [no cache]");
44779 return -ENOMEDIUM;
44780 }
44781@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
44782 object = cache->ops->alloc_object(cache, cookie);
44783 fscache_stat_d(&fscache_n_cop_alloc_object);
44784 if (IS_ERR(object)) {
44785- fscache_stat(&fscache_n_object_no_alloc);
44786+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
44787 ret = PTR_ERR(object);
44788 goto error;
44789 }
44790
44791- fscache_stat(&fscache_n_object_alloc);
44792+ fscache_stat_unchecked(&fscache_n_object_alloc);
44793
44794 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
44795
44796@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
44797 struct fscache_object *object;
44798 struct hlist_node *_p;
44799
44800- fscache_stat(&fscache_n_updates);
44801+ fscache_stat_unchecked(&fscache_n_updates);
44802
44803 if (!cookie) {
44804- fscache_stat(&fscache_n_updates_null);
44805+ fscache_stat_unchecked(&fscache_n_updates_null);
44806 _leave(" [no cookie]");
44807 return;
44808 }
44809@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
44810 struct fscache_object *object;
44811 unsigned long event;
44812
44813- fscache_stat(&fscache_n_relinquishes);
44814+ fscache_stat_unchecked(&fscache_n_relinquishes);
44815 if (retire)
44816- fscache_stat(&fscache_n_relinquishes_retire);
44817+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
44818
44819 if (!cookie) {
44820- fscache_stat(&fscache_n_relinquishes_null);
44821+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
44822 _leave(" [no cookie]");
44823 return;
44824 }
44825@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
44826
44827 /* wait for the cookie to finish being instantiated (or to fail) */
44828 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
44829- fscache_stat(&fscache_n_relinquishes_waitcrt);
44830+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
44831 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
44832 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
44833 }
44834diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
44835index f6aad48..88dcf26 100644
44836--- a/fs/fscache/internal.h
44837+++ b/fs/fscache/internal.h
44838@@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
44839 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
44840 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
44841
44842-extern atomic_t fscache_n_op_pend;
44843-extern atomic_t fscache_n_op_run;
44844-extern atomic_t fscache_n_op_enqueue;
44845-extern atomic_t fscache_n_op_deferred_release;
44846-extern atomic_t fscache_n_op_release;
44847-extern atomic_t fscache_n_op_gc;
44848-extern atomic_t fscache_n_op_cancelled;
44849-extern atomic_t fscache_n_op_rejected;
44850+extern atomic_unchecked_t fscache_n_op_pend;
44851+extern atomic_unchecked_t fscache_n_op_run;
44852+extern atomic_unchecked_t fscache_n_op_enqueue;
44853+extern atomic_unchecked_t fscache_n_op_deferred_release;
44854+extern atomic_unchecked_t fscache_n_op_release;
44855+extern atomic_unchecked_t fscache_n_op_gc;
44856+extern atomic_unchecked_t fscache_n_op_cancelled;
44857+extern atomic_unchecked_t fscache_n_op_rejected;
44858
44859-extern atomic_t fscache_n_attr_changed;
44860-extern atomic_t fscache_n_attr_changed_ok;
44861-extern atomic_t fscache_n_attr_changed_nobufs;
44862-extern atomic_t fscache_n_attr_changed_nomem;
44863-extern atomic_t fscache_n_attr_changed_calls;
44864+extern atomic_unchecked_t fscache_n_attr_changed;
44865+extern atomic_unchecked_t fscache_n_attr_changed_ok;
44866+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
44867+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
44868+extern atomic_unchecked_t fscache_n_attr_changed_calls;
44869
44870-extern atomic_t fscache_n_allocs;
44871-extern atomic_t fscache_n_allocs_ok;
44872-extern atomic_t fscache_n_allocs_wait;
44873-extern atomic_t fscache_n_allocs_nobufs;
44874-extern atomic_t fscache_n_allocs_intr;
44875-extern atomic_t fscache_n_allocs_object_dead;
44876-extern atomic_t fscache_n_alloc_ops;
44877-extern atomic_t fscache_n_alloc_op_waits;
44878+extern atomic_unchecked_t fscache_n_allocs;
44879+extern atomic_unchecked_t fscache_n_allocs_ok;
44880+extern atomic_unchecked_t fscache_n_allocs_wait;
44881+extern atomic_unchecked_t fscache_n_allocs_nobufs;
44882+extern atomic_unchecked_t fscache_n_allocs_intr;
44883+extern atomic_unchecked_t fscache_n_allocs_object_dead;
44884+extern atomic_unchecked_t fscache_n_alloc_ops;
44885+extern atomic_unchecked_t fscache_n_alloc_op_waits;
44886
44887-extern atomic_t fscache_n_retrievals;
44888-extern atomic_t fscache_n_retrievals_ok;
44889-extern atomic_t fscache_n_retrievals_wait;
44890-extern atomic_t fscache_n_retrievals_nodata;
44891-extern atomic_t fscache_n_retrievals_nobufs;
44892-extern atomic_t fscache_n_retrievals_intr;
44893-extern atomic_t fscache_n_retrievals_nomem;
44894-extern atomic_t fscache_n_retrievals_object_dead;
44895-extern atomic_t fscache_n_retrieval_ops;
44896-extern atomic_t fscache_n_retrieval_op_waits;
44897+extern atomic_unchecked_t fscache_n_retrievals;
44898+extern atomic_unchecked_t fscache_n_retrievals_ok;
44899+extern atomic_unchecked_t fscache_n_retrievals_wait;
44900+extern atomic_unchecked_t fscache_n_retrievals_nodata;
44901+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
44902+extern atomic_unchecked_t fscache_n_retrievals_intr;
44903+extern atomic_unchecked_t fscache_n_retrievals_nomem;
44904+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
44905+extern atomic_unchecked_t fscache_n_retrieval_ops;
44906+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
44907
44908-extern atomic_t fscache_n_stores;
44909-extern atomic_t fscache_n_stores_ok;
44910-extern atomic_t fscache_n_stores_again;
44911-extern atomic_t fscache_n_stores_nobufs;
44912-extern atomic_t fscache_n_stores_oom;
44913-extern atomic_t fscache_n_store_ops;
44914-extern atomic_t fscache_n_store_calls;
44915-extern atomic_t fscache_n_store_pages;
44916-extern atomic_t fscache_n_store_radix_deletes;
44917-extern atomic_t fscache_n_store_pages_over_limit;
44918+extern atomic_unchecked_t fscache_n_stores;
44919+extern atomic_unchecked_t fscache_n_stores_ok;
44920+extern atomic_unchecked_t fscache_n_stores_again;
44921+extern atomic_unchecked_t fscache_n_stores_nobufs;
44922+extern atomic_unchecked_t fscache_n_stores_oom;
44923+extern atomic_unchecked_t fscache_n_store_ops;
44924+extern atomic_unchecked_t fscache_n_store_calls;
44925+extern atomic_unchecked_t fscache_n_store_pages;
44926+extern atomic_unchecked_t fscache_n_store_radix_deletes;
44927+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
44928
44929-extern atomic_t fscache_n_store_vmscan_not_storing;
44930-extern atomic_t fscache_n_store_vmscan_gone;
44931-extern atomic_t fscache_n_store_vmscan_busy;
44932-extern atomic_t fscache_n_store_vmscan_cancelled;
44933+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
44934+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
44935+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
44936+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
44937
44938-extern atomic_t fscache_n_marks;
44939-extern atomic_t fscache_n_uncaches;
44940+extern atomic_unchecked_t fscache_n_marks;
44941+extern atomic_unchecked_t fscache_n_uncaches;
44942
44943-extern atomic_t fscache_n_acquires;
44944-extern atomic_t fscache_n_acquires_null;
44945-extern atomic_t fscache_n_acquires_no_cache;
44946-extern atomic_t fscache_n_acquires_ok;
44947-extern atomic_t fscache_n_acquires_nobufs;
44948-extern atomic_t fscache_n_acquires_oom;
44949+extern atomic_unchecked_t fscache_n_acquires;
44950+extern atomic_unchecked_t fscache_n_acquires_null;
44951+extern atomic_unchecked_t fscache_n_acquires_no_cache;
44952+extern atomic_unchecked_t fscache_n_acquires_ok;
44953+extern atomic_unchecked_t fscache_n_acquires_nobufs;
44954+extern atomic_unchecked_t fscache_n_acquires_oom;
44955
44956-extern atomic_t fscache_n_updates;
44957-extern atomic_t fscache_n_updates_null;
44958-extern atomic_t fscache_n_updates_run;
44959+extern atomic_unchecked_t fscache_n_updates;
44960+extern atomic_unchecked_t fscache_n_updates_null;
44961+extern atomic_unchecked_t fscache_n_updates_run;
44962
44963-extern atomic_t fscache_n_relinquishes;
44964-extern atomic_t fscache_n_relinquishes_null;
44965-extern atomic_t fscache_n_relinquishes_waitcrt;
44966-extern atomic_t fscache_n_relinquishes_retire;
44967+extern atomic_unchecked_t fscache_n_relinquishes;
44968+extern atomic_unchecked_t fscache_n_relinquishes_null;
44969+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
44970+extern atomic_unchecked_t fscache_n_relinquishes_retire;
44971
44972-extern atomic_t fscache_n_cookie_index;
44973-extern atomic_t fscache_n_cookie_data;
44974-extern atomic_t fscache_n_cookie_special;
44975+extern atomic_unchecked_t fscache_n_cookie_index;
44976+extern atomic_unchecked_t fscache_n_cookie_data;
44977+extern atomic_unchecked_t fscache_n_cookie_special;
44978
44979-extern atomic_t fscache_n_object_alloc;
44980-extern atomic_t fscache_n_object_no_alloc;
44981-extern atomic_t fscache_n_object_lookups;
44982-extern atomic_t fscache_n_object_lookups_negative;
44983-extern atomic_t fscache_n_object_lookups_positive;
44984-extern atomic_t fscache_n_object_lookups_timed_out;
44985-extern atomic_t fscache_n_object_created;
44986-extern atomic_t fscache_n_object_avail;
44987-extern atomic_t fscache_n_object_dead;
44988+extern atomic_unchecked_t fscache_n_object_alloc;
44989+extern atomic_unchecked_t fscache_n_object_no_alloc;
44990+extern atomic_unchecked_t fscache_n_object_lookups;
44991+extern atomic_unchecked_t fscache_n_object_lookups_negative;
44992+extern atomic_unchecked_t fscache_n_object_lookups_positive;
44993+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
44994+extern atomic_unchecked_t fscache_n_object_created;
44995+extern atomic_unchecked_t fscache_n_object_avail;
44996+extern atomic_unchecked_t fscache_n_object_dead;
44997
44998-extern atomic_t fscache_n_checkaux_none;
44999-extern atomic_t fscache_n_checkaux_okay;
45000-extern atomic_t fscache_n_checkaux_update;
45001-extern atomic_t fscache_n_checkaux_obsolete;
45002+extern atomic_unchecked_t fscache_n_checkaux_none;
45003+extern atomic_unchecked_t fscache_n_checkaux_okay;
45004+extern atomic_unchecked_t fscache_n_checkaux_update;
45005+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45006
45007 extern atomic_t fscache_n_cop_alloc_object;
45008 extern atomic_t fscache_n_cop_lookup_object;
45009@@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45010 atomic_inc(stat);
45011 }
45012
45013+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45014+{
45015+ atomic_inc_unchecked(stat);
45016+}
45017+
45018 static inline void fscache_stat_d(atomic_t *stat)
45019 {
45020 atomic_dec(stat);
45021@@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45022
45023 #define __fscache_stat(stat) (NULL)
45024 #define fscache_stat(stat) do {} while (0)
45025+#define fscache_stat_unchecked(stat) do {} while (0)
45026 #define fscache_stat_d(stat) do {} while (0)
45027 #endif
45028
45029diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45030index b6b897c..0ffff9c 100644
45031--- a/fs/fscache/object.c
45032+++ b/fs/fscache/object.c
45033@@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45034 /* update the object metadata on disk */
45035 case FSCACHE_OBJECT_UPDATING:
45036 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45037- fscache_stat(&fscache_n_updates_run);
45038+ fscache_stat_unchecked(&fscache_n_updates_run);
45039 fscache_stat(&fscache_n_cop_update_object);
45040 object->cache->ops->update_object(object);
45041 fscache_stat_d(&fscache_n_cop_update_object);
45042@@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45043 spin_lock(&object->lock);
45044 object->state = FSCACHE_OBJECT_DEAD;
45045 spin_unlock(&object->lock);
45046- fscache_stat(&fscache_n_object_dead);
45047+ fscache_stat_unchecked(&fscache_n_object_dead);
45048 goto terminal_transit;
45049
45050 /* handle the parent cache of this object being withdrawn from
45051@@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45052 spin_lock(&object->lock);
45053 object->state = FSCACHE_OBJECT_DEAD;
45054 spin_unlock(&object->lock);
45055- fscache_stat(&fscache_n_object_dead);
45056+ fscache_stat_unchecked(&fscache_n_object_dead);
45057 goto terminal_transit;
45058
45059 /* complain about the object being woken up once it is
45060@@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45061 parent->cookie->def->name, cookie->def->name,
45062 object->cache->tag->name);
45063
45064- fscache_stat(&fscache_n_object_lookups);
45065+ fscache_stat_unchecked(&fscache_n_object_lookups);
45066 fscache_stat(&fscache_n_cop_lookup_object);
45067 ret = object->cache->ops->lookup_object(object);
45068 fscache_stat_d(&fscache_n_cop_lookup_object);
45069@@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45070 if (ret == -ETIMEDOUT) {
45071 /* probably stuck behind another object, so move this one to
45072 * the back of the queue */
45073- fscache_stat(&fscache_n_object_lookups_timed_out);
45074+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45075 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45076 }
45077
45078@@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45079
45080 spin_lock(&object->lock);
45081 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45082- fscache_stat(&fscache_n_object_lookups_negative);
45083+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45084
45085 /* transit here to allow write requests to begin stacking up
45086 * and read requests to begin returning ENODATA */
45087@@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45088 * result, in which case there may be data available */
45089 spin_lock(&object->lock);
45090 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45091- fscache_stat(&fscache_n_object_lookups_positive);
45092+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45093
45094 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
45095
45096@@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
45097 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45098 } else {
45099 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
45100- fscache_stat(&fscache_n_object_created);
45101+ fscache_stat_unchecked(&fscache_n_object_created);
45102
45103 object->state = FSCACHE_OBJECT_AVAILABLE;
45104 spin_unlock(&object->lock);
45105@@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
45106 fscache_enqueue_dependents(object);
45107
45108 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
45109- fscache_stat(&fscache_n_object_avail);
45110+ fscache_stat_unchecked(&fscache_n_object_avail);
45111
45112 _leave("");
45113 }
45114@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45115 enum fscache_checkaux result;
45116
45117 if (!object->cookie->def->check_aux) {
45118- fscache_stat(&fscache_n_checkaux_none);
45119+ fscache_stat_unchecked(&fscache_n_checkaux_none);
45120 return FSCACHE_CHECKAUX_OKAY;
45121 }
45122
45123@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45124 switch (result) {
45125 /* entry okay as is */
45126 case FSCACHE_CHECKAUX_OKAY:
45127- fscache_stat(&fscache_n_checkaux_okay);
45128+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
45129 break;
45130
45131 /* entry requires update */
45132 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
45133- fscache_stat(&fscache_n_checkaux_update);
45134+ fscache_stat_unchecked(&fscache_n_checkaux_update);
45135 break;
45136
45137 /* entry requires deletion */
45138 case FSCACHE_CHECKAUX_OBSOLETE:
45139- fscache_stat(&fscache_n_checkaux_obsolete);
45140+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
45141 break;
45142
45143 default:
45144diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
45145index 30afdfa..2256596 100644
45146--- a/fs/fscache/operation.c
45147+++ b/fs/fscache/operation.c
45148@@ -17,7 +17,7 @@
45149 #include <linux/slab.h>
45150 #include "internal.h"
45151
45152-atomic_t fscache_op_debug_id;
45153+atomic_unchecked_t fscache_op_debug_id;
45154 EXPORT_SYMBOL(fscache_op_debug_id);
45155
45156 /**
45157@@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
45158 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
45159 ASSERTCMP(atomic_read(&op->usage), >, 0);
45160
45161- fscache_stat(&fscache_n_op_enqueue);
45162+ fscache_stat_unchecked(&fscache_n_op_enqueue);
45163 switch (op->flags & FSCACHE_OP_TYPE) {
45164 case FSCACHE_OP_ASYNC:
45165 _debug("queue async");
45166@@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
45167 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
45168 if (op->processor)
45169 fscache_enqueue_operation(op);
45170- fscache_stat(&fscache_n_op_run);
45171+ fscache_stat_unchecked(&fscache_n_op_run);
45172 }
45173
45174 /*
45175@@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45176 if (object->n_ops > 1) {
45177 atomic_inc(&op->usage);
45178 list_add_tail(&op->pend_link, &object->pending_ops);
45179- fscache_stat(&fscache_n_op_pend);
45180+ fscache_stat_unchecked(&fscache_n_op_pend);
45181 } else if (!list_empty(&object->pending_ops)) {
45182 atomic_inc(&op->usage);
45183 list_add_tail(&op->pend_link, &object->pending_ops);
45184- fscache_stat(&fscache_n_op_pend);
45185+ fscache_stat_unchecked(&fscache_n_op_pend);
45186 fscache_start_operations(object);
45187 } else {
45188 ASSERTCMP(object->n_in_progress, ==, 0);
45189@@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45190 object->n_exclusive++; /* reads and writes must wait */
45191 atomic_inc(&op->usage);
45192 list_add_tail(&op->pend_link, &object->pending_ops);
45193- fscache_stat(&fscache_n_op_pend);
45194+ fscache_stat_unchecked(&fscache_n_op_pend);
45195 ret = 0;
45196 } else {
45197 /* not allowed to submit ops in any other state */
45198@@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
45199 if (object->n_exclusive > 0) {
45200 atomic_inc(&op->usage);
45201 list_add_tail(&op->pend_link, &object->pending_ops);
45202- fscache_stat(&fscache_n_op_pend);
45203+ fscache_stat_unchecked(&fscache_n_op_pend);
45204 } else if (!list_empty(&object->pending_ops)) {
45205 atomic_inc(&op->usage);
45206 list_add_tail(&op->pend_link, &object->pending_ops);
45207- fscache_stat(&fscache_n_op_pend);
45208+ fscache_stat_unchecked(&fscache_n_op_pend);
45209 fscache_start_operations(object);
45210 } else {
45211 ASSERTCMP(object->n_exclusive, ==, 0);
45212@@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
45213 object->n_ops++;
45214 atomic_inc(&op->usage);
45215 list_add_tail(&op->pend_link, &object->pending_ops);
45216- fscache_stat(&fscache_n_op_pend);
45217+ fscache_stat_unchecked(&fscache_n_op_pend);
45218 ret = 0;
45219 } else if (object->state == FSCACHE_OBJECT_DYING ||
45220 object->state == FSCACHE_OBJECT_LC_DYING ||
45221 object->state == FSCACHE_OBJECT_WITHDRAWING) {
45222- fscache_stat(&fscache_n_op_rejected);
45223+ fscache_stat_unchecked(&fscache_n_op_rejected);
45224 ret = -ENOBUFS;
45225 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
45226 fscache_report_unexpected_submission(object, op, ostate);
45227@@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
45228
45229 ret = -EBUSY;
45230 if (!list_empty(&op->pend_link)) {
45231- fscache_stat(&fscache_n_op_cancelled);
45232+ fscache_stat_unchecked(&fscache_n_op_cancelled);
45233 list_del_init(&op->pend_link);
45234 object->n_ops--;
45235 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
45236@@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
45237 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
45238 BUG();
45239
45240- fscache_stat(&fscache_n_op_release);
45241+ fscache_stat_unchecked(&fscache_n_op_release);
45242
45243 if (op->release) {
45244 op->release(op);
45245@@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
45246 * lock, and defer it otherwise */
45247 if (!spin_trylock(&object->lock)) {
45248 _debug("defer put");
45249- fscache_stat(&fscache_n_op_deferred_release);
45250+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
45251
45252 cache = object->cache;
45253 spin_lock(&cache->op_gc_list_lock);
45254@@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
45255
45256 _debug("GC DEFERRED REL OBJ%x OP%x",
45257 object->debug_id, op->debug_id);
45258- fscache_stat(&fscache_n_op_gc);
45259+ fscache_stat_unchecked(&fscache_n_op_gc);
45260
45261 ASSERTCMP(atomic_read(&op->usage), ==, 0);
45262
45263diff --git a/fs/fscache/page.c b/fs/fscache/page.c
45264index 3f7a59b..cf196cc 100644
45265--- a/fs/fscache/page.c
45266+++ b/fs/fscache/page.c
45267@@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45268 val = radix_tree_lookup(&cookie->stores, page->index);
45269 if (!val) {
45270 rcu_read_unlock();
45271- fscache_stat(&fscache_n_store_vmscan_not_storing);
45272+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
45273 __fscache_uncache_page(cookie, page);
45274 return true;
45275 }
45276@@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45277 spin_unlock(&cookie->stores_lock);
45278
45279 if (xpage) {
45280- fscache_stat(&fscache_n_store_vmscan_cancelled);
45281- fscache_stat(&fscache_n_store_radix_deletes);
45282+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
45283+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45284 ASSERTCMP(xpage, ==, page);
45285 } else {
45286- fscache_stat(&fscache_n_store_vmscan_gone);
45287+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
45288 }
45289
45290 wake_up_bit(&cookie->flags, 0);
45291@@ -107,7 +107,7 @@ page_busy:
45292 /* we might want to wait here, but that could deadlock the allocator as
45293 * the work threads writing to the cache may all end up sleeping
45294 * on memory allocation */
45295- fscache_stat(&fscache_n_store_vmscan_busy);
45296+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
45297 return false;
45298 }
45299 EXPORT_SYMBOL(__fscache_maybe_release_page);
45300@@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
45301 FSCACHE_COOKIE_STORING_TAG);
45302 if (!radix_tree_tag_get(&cookie->stores, page->index,
45303 FSCACHE_COOKIE_PENDING_TAG)) {
45304- fscache_stat(&fscache_n_store_radix_deletes);
45305+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45306 xpage = radix_tree_delete(&cookie->stores, page->index);
45307 }
45308 spin_unlock(&cookie->stores_lock);
45309@@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
45310
45311 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
45312
45313- fscache_stat(&fscache_n_attr_changed_calls);
45314+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
45315
45316 if (fscache_object_is_active(object)) {
45317 fscache_stat(&fscache_n_cop_attr_changed);
45318@@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45319
45320 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45321
45322- fscache_stat(&fscache_n_attr_changed);
45323+ fscache_stat_unchecked(&fscache_n_attr_changed);
45324
45325 op = kzalloc(sizeof(*op), GFP_KERNEL);
45326 if (!op) {
45327- fscache_stat(&fscache_n_attr_changed_nomem);
45328+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
45329 _leave(" = -ENOMEM");
45330 return -ENOMEM;
45331 }
45332@@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45333 if (fscache_submit_exclusive_op(object, op) < 0)
45334 goto nobufs;
45335 spin_unlock(&cookie->lock);
45336- fscache_stat(&fscache_n_attr_changed_ok);
45337+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
45338 fscache_put_operation(op);
45339 _leave(" = 0");
45340 return 0;
45341@@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45342 nobufs:
45343 spin_unlock(&cookie->lock);
45344 kfree(op);
45345- fscache_stat(&fscache_n_attr_changed_nobufs);
45346+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
45347 _leave(" = %d", -ENOBUFS);
45348 return -ENOBUFS;
45349 }
45350@@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
45351 /* allocate a retrieval operation and attempt to submit it */
45352 op = kzalloc(sizeof(*op), GFP_NOIO);
45353 if (!op) {
45354- fscache_stat(&fscache_n_retrievals_nomem);
45355+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45356 return NULL;
45357 }
45358
45359@@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45360 return 0;
45361 }
45362
45363- fscache_stat(&fscache_n_retrievals_wait);
45364+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
45365
45366 jif = jiffies;
45367 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
45368 fscache_wait_bit_interruptible,
45369 TASK_INTERRUPTIBLE) != 0) {
45370- fscache_stat(&fscache_n_retrievals_intr);
45371+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
45372 _leave(" = -ERESTARTSYS");
45373 return -ERESTARTSYS;
45374 }
45375@@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45376 */
45377 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45378 struct fscache_retrieval *op,
45379- atomic_t *stat_op_waits,
45380- atomic_t *stat_object_dead)
45381+ atomic_unchecked_t *stat_op_waits,
45382+ atomic_unchecked_t *stat_object_dead)
45383 {
45384 int ret;
45385
45386@@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45387 goto check_if_dead;
45388
45389 _debug(">>> WT");
45390- fscache_stat(stat_op_waits);
45391+ fscache_stat_unchecked(stat_op_waits);
45392 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
45393 fscache_wait_bit_interruptible,
45394 TASK_INTERRUPTIBLE) < 0) {
45395@@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45396
45397 check_if_dead:
45398 if (unlikely(fscache_object_is_dead(object))) {
45399- fscache_stat(stat_object_dead);
45400+ fscache_stat_unchecked(stat_object_dead);
45401 return -ENOBUFS;
45402 }
45403 return 0;
45404@@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45405
45406 _enter("%p,%p,,,", cookie, page);
45407
45408- fscache_stat(&fscache_n_retrievals);
45409+ fscache_stat_unchecked(&fscache_n_retrievals);
45410
45411 if (hlist_empty(&cookie->backing_objects))
45412 goto nobufs;
45413@@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45414 goto nobufs_unlock;
45415 spin_unlock(&cookie->lock);
45416
45417- fscache_stat(&fscache_n_retrieval_ops);
45418+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
45419
45420 /* pin the netfs read context in case we need to do the actual netfs
45421 * read because we've encountered a cache read failure */
45422@@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45423
45424 error:
45425 if (ret == -ENOMEM)
45426- fscache_stat(&fscache_n_retrievals_nomem);
45427+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45428 else if (ret == -ERESTARTSYS)
45429- fscache_stat(&fscache_n_retrievals_intr);
45430+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
45431 else if (ret == -ENODATA)
45432- fscache_stat(&fscache_n_retrievals_nodata);
45433+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45434 else if (ret < 0)
45435- fscache_stat(&fscache_n_retrievals_nobufs);
45436+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45437 else
45438- fscache_stat(&fscache_n_retrievals_ok);
45439+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
45440
45441 fscache_put_retrieval(op);
45442 _leave(" = %d", ret);
45443@@ -429,7 +429,7 @@ nobufs_unlock:
45444 spin_unlock(&cookie->lock);
45445 kfree(op);
45446 nobufs:
45447- fscache_stat(&fscache_n_retrievals_nobufs);
45448+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45449 _leave(" = -ENOBUFS");
45450 return -ENOBUFS;
45451 }
45452@@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45453
45454 _enter("%p,,%d,,,", cookie, *nr_pages);
45455
45456- fscache_stat(&fscache_n_retrievals);
45457+ fscache_stat_unchecked(&fscache_n_retrievals);
45458
45459 if (hlist_empty(&cookie->backing_objects))
45460 goto nobufs;
45461@@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45462 goto nobufs_unlock;
45463 spin_unlock(&cookie->lock);
45464
45465- fscache_stat(&fscache_n_retrieval_ops);
45466+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
45467
45468 /* pin the netfs read context in case we need to do the actual netfs
45469 * read because we've encountered a cache read failure */
45470@@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45471
45472 error:
45473 if (ret == -ENOMEM)
45474- fscache_stat(&fscache_n_retrievals_nomem);
45475+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45476 else if (ret == -ERESTARTSYS)
45477- fscache_stat(&fscache_n_retrievals_intr);
45478+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
45479 else if (ret == -ENODATA)
45480- fscache_stat(&fscache_n_retrievals_nodata);
45481+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45482 else if (ret < 0)
45483- fscache_stat(&fscache_n_retrievals_nobufs);
45484+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45485 else
45486- fscache_stat(&fscache_n_retrievals_ok);
45487+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
45488
45489 fscache_put_retrieval(op);
45490 _leave(" = %d", ret);
45491@@ -545,7 +545,7 @@ nobufs_unlock:
45492 spin_unlock(&cookie->lock);
45493 kfree(op);
45494 nobufs:
45495- fscache_stat(&fscache_n_retrievals_nobufs);
45496+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45497 _leave(" = -ENOBUFS");
45498 return -ENOBUFS;
45499 }
45500@@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45501
45502 _enter("%p,%p,,,", cookie, page);
45503
45504- fscache_stat(&fscache_n_allocs);
45505+ fscache_stat_unchecked(&fscache_n_allocs);
45506
45507 if (hlist_empty(&cookie->backing_objects))
45508 goto nobufs;
45509@@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45510 goto nobufs_unlock;
45511 spin_unlock(&cookie->lock);
45512
45513- fscache_stat(&fscache_n_alloc_ops);
45514+ fscache_stat_unchecked(&fscache_n_alloc_ops);
45515
45516 ret = fscache_wait_for_retrieval_activation(
45517 object, op,
45518@@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45519
45520 error:
45521 if (ret == -ERESTARTSYS)
45522- fscache_stat(&fscache_n_allocs_intr);
45523+ fscache_stat_unchecked(&fscache_n_allocs_intr);
45524 else if (ret < 0)
45525- fscache_stat(&fscache_n_allocs_nobufs);
45526+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45527 else
45528- fscache_stat(&fscache_n_allocs_ok);
45529+ fscache_stat_unchecked(&fscache_n_allocs_ok);
45530
45531 fscache_put_retrieval(op);
45532 _leave(" = %d", ret);
45533@@ -625,7 +625,7 @@ nobufs_unlock:
45534 spin_unlock(&cookie->lock);
45535 kfree(op);
45536 nobufs:
45537- fscache_stat(&fscache_n_allocs_nobufs);
45538+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45539 _leave(" = -ENOBUFS");
45540 return -ENOBUFS;
45541 }
45542@@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45543
45544 spin_lock(&cookie->stores_lock);
45545
45546- fscache_stat(&fscache_n_store_calls);
45547+ fscache_stat_unchecked(&fscache_n_store_calls);
45548
45549 /* find a page to store */
45550 page = NULL;
45551@@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45552 page = results[0];
45553 _debug("gang %d [%lx]", n, page->index);
45554 if (page->index > op->store_limit) {
45555- fscache_stat(&fscache_n_store_pages_over_limit);
45556+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
45557 goto superseded;
45558 }
45559
45560@@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45561 spin_unlock(&cookie->stores_lock);
45562 spin_unlock(&object->lock);
45563
45564- fscache_stat(&fscache_n_store_pages);
45565+ fscache_stat_unchecked(&fscache_n_store_pages);
45566 fscache_stat(&fscache_n_cop_write_page);
45567 ret = object->cache->ops->write_page(op, page);
45568 fscache_stat_d(&fscache_n_cop_write_page);
45569@@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45570 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45571 ASSERT(PageFsCache(page));
45572
45573- fscache_stat(&fscache_n_stores);
45574+ fscache_stat_unchecked(&fscache_n_stores);
45575
45576 op = kzalloc(sizeof(*op), GFP_NOIO);
45577 if (!op)
45578@@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45579 spin_unlock(&cookie->stores_lock);
45580 spin_unlock(&object->lock);
45581
45582- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
45583+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
45584 op->store_limit = object->store_limit;
45585
45586 if (fscache_submit_op(object, &op->op) < 0)
45587@@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45588
45589 spin_unlock(&cookie->lock);
45590 radix_tree_preload_end();
45591- fscache_stat(&fscache_n_store_ops);
45592- fscache_stat(&fscache_n_stores_ok);
45593+ fscache_stat_unchecked(&fscache_n_store_ops);
45594+ fscache_stat_unchecked(&fscache_n_stores_ok);
45595
45596 /* the work queue now carries its own ref on the object */
45597 fscache_put_operation(&op->op);
45598@@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45599 return 0;
45600
45601 already_queued:
45602- fscache_stat(&fscache_n_stores_again);
45603+ fscache_stat_unchecked(&fscache_n_stores_again);
45604 already_pending:
45605 spin_unlock(&cookie->stores_lock);
45606 spin_unlock(&object->lock);
45607 spin_unlock(&cookie->lock);
45608 radix_tree_preload_end();
45609 kfree(op);
45610- fscache_stat(&fscache_n_stores_ok);
45611+ fscache_stat_unchecked(&fscache_n_stores_ok);
45612 _leave(" = 0");
45613 return 0;
45614
45615@@ -851,14 +851,14 @@ nobufs:
45616 spin_unlock(&cookie->lock);
45617 radix_tree_preload_end();
45618 kfree(op);
45619- fscache_stat(&fscache_n_stores_nobufs);
45620+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
45621 _leave(" = -ENOBUFS");
45622 return -ENOBUFS;
45623
45624 nomem_free:
45625 kfree(op);
45626 nomem:
45627- fscache_stat(&fscache_n_stores_oom);
45628+ fscache_stat_unchecked(&fscache_n_stores_oom);
45629 _leave(" = -ENOMEM");
45630 return -ENOMEM;
45631 }
45632@@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
45633 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45634 ASSERTCMP(page, !=, NULL);
45635
45636- fscache_stat(&fscache_n_uncaches);
45637+ fscache_stat_unchecked(&fscache_n_uncaches);
45638
45639 /* cache withdrawal may beat us to it */
45640 if (!PageFsCache(page))
45641@@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
45642 unsigned long loop;
45643
45644 #ifdef CONFIG_FSCACHE_STATS
45645- atomic_add(pagevec->nr, &fscache_n_marks);
45646+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
45647 #endif
45648
45649 for (loop = 0; loop < pagevec->nr; loop++) {
45650diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
45651index 4765190..2a067f2 100644
45652--- a/fs/fscache/stats.c
45653+++ b/fs/fscache/stats.c
45654@@ -18,95 +18,95 @@
45655 /*
45656 * operation counters
45657 */
45658-atomic_t fscache_n_op_pend;
45659-atomic_t fscache_n_op_run;
45660-atomic_t fscache_n_op_enqueue;
45661-atomic_t fscache_n_op_requeue;
45662-atomic_t fscache_n_op_deferred_release;
45663-atomic_t fscache_n_op_release;
45664-atomic_t fscache_n_op_gc;
45665-atomic_t fscache_n_op_cancelled;
45666-atomic_t fscache_n_op_rejected;
45667+atomic_unchecked_t fscache_n_op_pend;
45668+atomic_unchecked_t fscache_n_op_run;
45669+atomic_unchecked_t fscache_n_op_enqueue;
45670+atomic_unchecked_t fscache_n_op_requeue;
45671+atomic_unchecked_t fscache_n_op_deferred_release;
45672+atomic_unchecked_t fscache_n_op_release;
45673+atomic_unchecked_t fscache_n_op_gc;
45674+atomic_unchecked_t fscache_n_op_cancelled;
45675+atomic_unchecked_t fscache_n_op_rejected;
45676
45677-atomic_t fscache_n_attr_changed;
45678-atomic_t fscache_n_attr_changed_ok;
45679-atomic_t fscache_n_attr_changed_nobufs;
45680-atomic_t fscache_n_attr_changed_nomem;
45681-atomic_t fscache_n_attr_changed_calls;
45682+atomic_unchecked_t fscache_n_attr_changed;
45683+atomic_unchecked_t fscache_n_attr_changed_ok;
45684+atomic_unchecked_t fscache_n_attr_changed_nobufs;
45685+atomic_unchecked_t fscache_n_attr_changed_nomem;
45686+atomic_unchecked_t fscache_n_attr_changed_calls;
45687
45688-atomic_t fscache_n_allocs;
45689-atomic_t fscache_n_allocs_ok;
45690-atomic_t fscache_n_allocs_wait;
45691-atomic_t fscache_n_allocs_nobufs;
45692-atomic_t fscache_n_allocs_intr;
45693-atomic_t fscache_n_allocs_object_dead;
45694-atomic_t fscache_n_alloc_ops;
45695-atomic_t fscache_n_alloc_op_waits;
45696+atomic_unchecked_t fscache_n_allocs;
45697+atomic_unchecked_t fscache_n_allocs_ok;
45698+atomic_unchecked_t fscache_n_allocs_wait;
45699+atomic_unchecked_t fscache_n_allocs_nobufs;
45700+atomic_unchecked_t fscache_n_allocs_intr;
45701+atomic_unchecked_t fscache_n_allocs_object_dead;
45702+atomic_unchecked_t fscache_n_alloc_ops;
45703+atomic_unchecked_t fscache_n_alloc_op_waits;
45704
45705-atomic_t fscache_n_retrievals;
45706-atomic_t fscache_n_retrievals_ok;
45707-atomic_t fscache_n_retrievals_wait;
45708-atomic_t fscache_n_retrievals_nodata;
45709-atomic_t fscache_n_retrievals_nobufs;
45710-atomic_t fscache_n_retrievals_intr;
45711-atomic_t fscache_n_retrievals_nomem;
45712-atomic_t fscache_n_retrievals_object_dead;
45713-atomic_t fscache_n_retrieval_ops;
45714-atomic_t fscache_n_retrieval_op_waits;
45715+atomic_unchecked_t fscache_n_retrievals;
45716+atomic_unchecked_t fscache_n_retrievals_ok;
45717+atomic_unchecked_t fscache_n_retrievals_wait;
45718+atomic_unchecked_t fscache_n_retrievals_nodata;
45719+atomic_unchecked_t fscache_n_retrievals_nobufs;
45720+atomic_unchecked_t fscache_n_retrievals_intr;
45721+atomic_unchecked_t fscache_n_retrievals_nomem;
45722+atomic_unchecked_t fscache_n_retrievals_object_dead;
45723+atomic_unchecked_t fscache_n_retrieval_ops;
45724+atomic_unchecked_t fscache_n_retrieval_op_waits;
45725
45726-atomic_t fscache_n_stores;
45727-atomic_t fscache_n_stores_ok;
45728-atomic_t fscache_n_stores_again;
45729-atomic_t fscache_n_stores_nobufs;
45730-atomic_t fscache_n_stores_oom;
45731-atomic_t fscache_n_store_ops;
45732-atomic_t fscache_n_store_calls;
45733-atomic_t fscache_n_store_pages;
45734-atomic_t fscache_n_store_radix_deletes;
45735-atomic_t fscache_n_store_pages_over_limit;
45736+atomic_unchecked_t fscache_n_stores;
45737+atomic_unchecked_t fscache_n_stores_ok;
45738+atomic_unchecked_t fscache_n_stores_again;
45739+atomic_unchecked_t fscache_n_stores_nobufs;
45740+atomic_unchecked_t fscache_n_stores_oom;
45741+atomic_unchecked_t fscache_n_store_ops;
45742+atomic_unchecked_t fscache_n_store_calls;
45743+atomic_unchecked_t fscache_n_store_pages;
45744+atomic_unchecked_t fscache_n_store_radix_deletes;
45745+atomic_unchecked_t fscache_n_store_pages_over_limit;
45746
45747-atomic_t fscache_n_store_vmscan_not_storing;
45748-atomic_t fscache_n_store_vmscan_gone;
45749-atomic_t fscache_n_store_vmscan_busy;
45750-atomic_t fscache_n_store_vmscan_cancelled;
45751+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45752+atomic_unchecked_t fscache_n_store_vmscan_gone;
45753+atomic_unchecked_t fscache_n_store_vmscan_busy;
45754+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45755
45756-atomic_t fscache_n_marks;
45757-atomic_t fscache_n_uncaches;
45758+atomic_unchecked_t fscache_n_marks;
45759+atomic_unchecked_t fscache_n_uncaches;
45760
45761-atomic_t fscache_n_acquires;
45762-atomic_t fscache_n_acquires_null;
45763-atomic_t fscache_n_acquires_no_cache;
45764-atomic_t fscache_n_acquires_ok;
45765-atomic_t fscache_n_acquires_nobufs;
45766-atomic_t fscache_n_acquires_oom;
45767+atomic_unchecked_t fscache_n_acquires;
45768+atomic_unchecked_t fscache_n_acquires_null;
45769+atomic_unchecked_t fscache_n_acquires_no_cache;
45770+atomic_unchecked_t fscache_n_acquires_ok;
45771+atomic_unchecked_t fscache_n_acquires_nobufs;
45772+atomic_unchecked_t fscache_n_acquires_oom;
45773
45774-atomic_t fscache_n_updates;
45775-atomic_t fscache_n_updates_null;
45776-atomic_t fscache_n_updates_run;
45777+atomic_unchecked_t fscache_n_updates;
45778+atomic_unchecked_t fscache_n_updates_null;
45779+atomic_unchecked_t fscache_n_updates_run;
45780
45781-atomic_t fscache_n_relinquishes;
45782-atomic_t fscache_n_relinquishes_null;
45783-atomic_t fscache_n_relinquishes_waitcrt;
45784-atomic_t fscache_n_relinquishes_retire;
45785+atomic_unchecked_t fscache_n_relinquishes;
45786+atomic_unchecked_t fscache_n_relinquishes_null;
45787+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45788+atomic_unchecked_t fscache_n_relinquishes_retire;
45789
45790-atomic_t fscache_n_cookie_index;
45791-atomic_t fscache_n_cookie_data;
45792-atomic_t fscache_n_cookie_special;
45793+atomic_unchecked_t fscache_n_cookie_index;
45794+atomic_unchecked_t fscache_n_cookie_data;
45795+atomic_unchecked_t fscache_n_cookie_special;
45796
45797-atomic_t fscache_n_object_alloc;
45798-atomic_t fscache_n_object_no_alloc;
45799-atomic_t fscache_n_object_lookups;
45800-atomic_t fscache_n_object_lookups_negative;
45801-atomic_t fscache_n_object_lookups_positive;
45802-atomic_t fscache_n_object_lookups_timed_out;
45803-atomic_t fscache_n_object_created;
45804-atomic_t fscache_n_object_avail;
45805-atomic_t fscache_n_object_dead;
45806+atomic_unchecked_t fscache_n_object_alloc;
45807+atomic_unchecked_t fscache_n_object_no_alloc;
45808+atomic_unchecked_t fscache_n_object_lookups;
45809+atomic_unchecked_t fscache_n_object_lookups_negative;
45810+atomic_unchecked_t fscache_n_object_lookups_positive;
45811+atomic_unchecked_t fscache_n_object_lookups_timed_out;
45812+atomic_unchecked_t fscache_n_object_created;
45813+atomic_unchecked_t fscache_n_object_avail;
45814+atomic_unchecked_t fscache_n_object_dead;
45815
45816-atomic_t fscache_n_checkaux_none;
45817-atomic_t fscache_n_checkaux_okay;
45818-atomic_t fscache_n_checkaux_update;
45819-atomic_t fscache_n_checkaux_obsolete;
45820+atomic_unchecked_t fscache_n_checkaux_none;
45821+atomic_unchecked_t fscache_n_checkaux_okay;
45822+atomic_unchecked_t fscache_n_checkaux_update;
45823+atomic_unchecked_t fscache_n_checkaux_obsolete;
45824
45825 atomic_t fscache_n_cop_alloc_object;
45826 atomic_t fscache_n_cop_lookup_object;
45827@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
45828 seq_puts(m, "FS-Cache statistics\n");
45829
45830 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
45831- atomic_read(&fscache_n_cookie_index),
45832- atomic_read(&fscache_n_cookie_data),
45833- atomic_read(&fscache_n_cookie_special));
45834+ atomic_read_unchecked(&fscache_n_cookie_index),
45835+ atomic_read_unchecked(&fscache_n_cookie_data),
45836+ atomic_read_unchecked(&fscache_n_cookie_special));
45837
45838 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
45839- atomic_read(&fscache_n_object_alloc),
45840- atomic_read(&fscache_n_object_no_alloc),
45841- atomic_read(&fscache_n_object_avail),
45842- atomic_read(&fscache_n_object_dead));
45843+ atomic_read_unchecked(&fscache_n_object_alloc),
45844+ atomic_read_unchecked(&fscache_n_object_no_alloc),
45845+ atomic_read_unchecked(&fscache_n_object_avail),
45846+ atomic_read_unchecked(&fscache_n_object_dead));
45847 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
45848- atomic_read(&fscache_n_checkaux_none),
45849- atomic_read(&fscache_n_checkaux_okay),
45850- atomic_read(&fscache_n_checkaux_update),
45851- atomic_read(&fscache_n_checkaux_obsolete));
45852+ atomic_read_unchecked(&fscache_n_checkaux_none),
45853+ atomic_read_unchecked(&fscache_n_checkaux_okay),
45854+ atomic_read_unchecked(&fscache_n_checkaux_update),
45855+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
45856
45857 seq_printf(m, "Pages : mrk=%u unc=%u\n",
45858- atomic_read(&fscache_n_marks),
45859- atomic_read(&fscache_n_uncaches));
45860+ atomic_read_unchecked(&fscache_n_marks),
45861+ atomic_read_unchecked(&fscache_n_uncaches));
45862
45863 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
45864 " oom=%u\n",
45865- atomic_read(&fscache_n_acquires),
45866- atomic_read(&fscache_n_acquires_null),
45867- atomic_read(&fscache_n_acquires_no_cache),
45868- atomic_read(&fscache_n_acquires_ok),
45869- atomic_read(&fscache_n_acquires_nobufs),
45870- atomic_read(&fscache_n_acquires_oom));
45871+ atomic_read_unchecked(&fscache_n_acquires),
45872+ atomic_read_unchecked(&fscache_n_acquires_null),
45873+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
45874+ atomic_read_unchecked(&fscache_n_acquires_ok),
45875+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
45876+ atomic_read_unchecked(&fscache_n_acquires_oom));
45877
45878 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
45879- atomic_read(&fscache_n_object_lookups),
45880- atomic_read(&fscache_n_object_lookups_negative),
45881- atomic_read(&fscache_n_object_lookups_positive),
45882- atomic_read(&fscache_n_object_created),
45883- atomic_read(&fscache_n_object_lookups_timed_out));
45884+ atomic_read_unchecked(&fscache_n_object_lookups),
45885+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
45886+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
45887+ atomic_read_unchecked(&fscache_n_object_created),
45888+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
45889
45890 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
45891- atomic_read(&fscache_n_updates),
45892- atomic_read(&fscache_n_updates_null),
45893- atomic_read(&fscache_n_updates_run));
45894+ atomic_read_unchecked(&fscache_n_updates),
45895+ atomic_read_unchecked(&fscache_n_updates_null),
45896+ atomic_read_unchecked(&fscache_n_updates_run));
45897
45898 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
45899- atomic_read(&fscache_n_relinquishes),
45900- atomic_read(&fscache_n_relinquishes_null),
45901- atomic_read(&fscache_n_relinquishes_waitcrt),
45902- atomic_read(&fscache_n_relinquishes_retire));
45903+ atomic_read_unchecked(&fscache_n_relinquishes),
45904+ atomic_read_unchecked(&fscache_n_relinquishes_null),
45905+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
45906+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
45907
45908 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
45909- atomic_read(&fscache_n_attr_changed),
45910- atomic_read(&fscache_n_attr_changed_ok),
45911- atomic_read(&fscache_n_attr_changed_nobufs),
45912- atomic_read(&fscache_n_attr_changed_nomem),
45913- atomic_read(&fscache_n_attr_changed_calls));
45914+ atomic_read_unchecked(&fscache_n_attr_changed),
45915+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
45916+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
45917+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
45918+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
45919
45920 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
45921- atomic_read(&fscache_n_allocs),
45922- atomic_read(&fscache_n_allocs_ok),
45923- atomic_read(&fscache_n_allocs_wait),
45924- atomic_read(&fscache_n_allocs_nobufs),
45925- atomic_read(&fscache_n_allocs_intr));
45926+ atomic_read_unchecked(&fscache_n_allocs),
45927+ atomic_read_unchecked(&fscache_n_allocs_ok),
45928+ atomic_read_unchecked(&fscache_n_allocs_wait),
45929+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
45930+ atomic_read_unchecked(&fscache_n_allocs_intr));
45931 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
45932- atomic_read(&fscache_n_alloc_ops),
45933- atomic_read(&fscache_n_alloc_op_waits),
45934- atomic_read(&fscache_n_allocs_object_dead));
45935+ atomic_read_unchecked(&fscache_n_alloc_ops),
45936+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
45937+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
45938
45939 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
45940 " int=%u oom=%u\n",
45941- atomic_read(&fscache_n_retrievals),
45942- atomic_read(&fscache_n_retrievals_ok),
45943- atomic_read(&fscache_n_retrievals_wait),
45944- atomic_read(&fscache_n_retrievals_nodata),
45945- atomic_read(&fscache_n_retrievals_nobufs),
45946- atomic_read(&fscache_n_retrievals_intr),
45947- atomic_read(&fscache_n_retrievals_nomem));
45948+ atomic_read_unchecked(&fscache_n_retrievals),
45949+ atomic_read_unchecked(&fscache_n_retrievals_ok),
45950+ atomic_read_unchecked(&fscache_n_retrievals_wait),
45951+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
45952+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
45953+ atomic_read_unchecked(&fscache_n_retrievals_intr),
45954+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
45955 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
45956- atomic_read(&fscache_n_retrieval_ops),
45957- atomic_read(&fscache_n_retrieval_op_waits),
45958- atomic_read(&fscache_n_retrievals_object_dead));
45959+ atomic_read_unchecked(&fscache_n_retrieval_ops),
45960+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
45961+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
45962
45963 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
45964- atomic_read(&fscache_n_stores),
45965- atomic_read(&fscache_n_stores_ok),
45966- atomic_read(&fscache_n_stores_again),
45967- atomic_read(&fscache_n_stores_nobufs),
45968- atomic_read(&fscache_n_stores_oom));
45969+ atomic_read_unchecked(&fscache_n_stores),
45970+ atomic_read_unchecked(&fscache_n_stores_ok),
45971+ atomic_read_unchecked(&fscache_n_stores_again),
45972+ atomic_read_unchecked(&fscache_n_stores_nobufs),
45973+ atomic_read_unchecked(&fscache_n_stores_oom));
45974 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
45975- atomic_read(&fscache_n_store_ops),
45976- atomic_read(&fscache_n_store_calls),
45977- atomic_read(&fscache_n_store_pages),
45978- atomic_read(&fscache_n_store_radix_deletes),
45979- atomic_read(&fscache_n_store_pages_over_limit));
45980+ atomic_read_unchecked(&fscache_n_store_ops),
45981+ atomic_read_unchecked(&fscache_n_store_calls),
45982+ atomic_read_unchecked(&fscache_n_store_pages),
45983+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
45984+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
45985
45986 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
45987- atomic_read(&fscache_n_store_vmscan_not_storing),
45988- atomic_read(&fscache_n_store_vmscan_gone),
45989- atomic_read(&fscache_n_store_vmscan_busy),
45990- atomic_read(&fscache_n_store_vmscan_cancelled));
45991+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
45992+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
45993+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
45994+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
45995
45996 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
45997- atomic_read(&fscache_n_op_pend),
45998- atomic_read(&fscache_n_op_run),
45999- atomic_read(&fscache_n_op_enqueue),
46000- atomic_read(&fscache_n_op_cancelled),
46001- atomic_read(&fscache_n_op_rejected));
46002+ atomic_read_unchecked(&fscache_n_op_pend),
46003+ atomic_read_unchecked(&fscache_n_op_run),
46004+ atomic_read_unchecked(&fscache_n_op_enqueue),
46005+ atomic_read_unchecked(&fscache_n_op_cancelled),
46006+ atomic_read_unchecked(&fscache_n_op_rejected));
46007 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46008- atomic_read(&fscache_n_op_deferred_release),
46009- atomic_read(&fscache_n_op_release),
46010- atomic_read(&fscache_n_op_gc));
46011+ atomic_read_unchecked(&fscache_n_op_deferred_release),
46012+ atomic_read_unchecked(&fscache_n_op_release),
46013+ atomic_read_unchecked(&fscache_n_op_gc));
46014
46015 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46016 atomic_read(&fscache_n_cop_alloc_object),
46017diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46018index 3426521..3b75162 100644
46019--- a/fs/fuse/cuse.c
46020+++ b/fs/fuse/cuse.c
46021@@ -587,10 +587,12 @@ static int __init cuse_init(void)
46022 INIT_LIST_HEAD(&cuse_conntbl[i]);
46023
46024 /* inherit and extend fuse_dev_operations */
46025- cuse_channel_fops = fuse_dev_operations;
46026- cuse_channel_fops.owner = THIS_MODULE;
46027- cuse_channel_fops.open = cuse_channel_open;
46028- cuse_channel_fops.release = cuse_channel_release;
46029+ pax_open_kernel();
46030+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46031+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46032+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
46033+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
46034+ pax_close_kernel();
46035
46036 cuse_class = class_create(THIS_MODULE, "cuse");
46037 if (IS_ERR(cuse_class))
46038diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46039index 7df2b5e..5804aa7 100644
46040--- a/fs/fuse/dev.c
46041+++ b/fs/fuse/dev.c
46042@@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46043 ret = 0;
46044 pipe_lock(pipe);
46045
46046- if (!pipe->readers) {
46047+ if (!atomic_read(&pipe->readers)) {
46048 send_sig(SIGPIPE, current, 0);
46049 if (!ret)
46050 ret = -EPIPE;
46051diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46052index bc43832..0cfe5a6 100644
46053--- a/fs/fuse/dir.c
46054+++ b/fs/fuse/dir.c
46055@@ -1181,7 +1181,7 @@ static char *read_link(struct dentry *dentry)
46056 return link;
46057 }
46058
46059-static void free_link(char *link)
46060+static void free_link(const char *link)
46061 {
46062 if (!IS_ERR(link))
46063 free_page((unsigned long) link);
46064diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46065index a9ba244..d9df391 100644
46066--- a/fs/gfs2/inode.c
46067+++ b/fs/gfs2/inode.c
46068@@ -1496,7 +1496,7 @@ out:
46069
46070 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46071 {
46072- char *s = nd_get_link(nd);
46073+ const char *s = nd_get_link(nd);
46074 if (!IS_ERR(s))
46075 kfree(s);
46076 }
46077diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46078index 001ef01..f7d5f07 100644
46079--- a/fs/hugetlbfs/inode.c
46080+++ b/fs/hugetlbfs/inode.c
46081@@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46082 .kill_sb = kill_litter_super,
46083 };
46084
46085-static struct vfsmount *hugetlbfs_vfsmount;
46086+struct vfsmount *hugetlbfs_vfsmount;
46087
46088 static int can_do_hugetlb_shm(void)
46089 {
46090diff --git a/fs/inode.c b/fs/inode.c
46091index 9f4f5fe..6214688 100644
46092--- a/fs/inode.c
46093+++ b/fs/inode.c
46094@@ -860,8 +860,8 @@ unsigned int get_next_ino(void)
46095
46096 #ifdef CONFIG_SMP
46097 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
46098- static atomic_t shared_last_ino;
46099- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
46100+ static atomic_unchecked_t shared_last_ino;
46101+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
46102
46103 res = next - LAST_INO_BATCH;
46104 }
46105diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
46106index 4a6cf28..d3a29d3 100644
46107--- a/fs/jffs2/erase.c
46108+++ b/fs/jffs2/erase.c
46109@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
46110 struct jffs2_unknown_node marker = {
46111 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
46112 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46113- .totlen = cpu_to_je32(c->cleanmarker_size)
46114+ .totlen = cpu_to_je32(c->cleanmarker_size),
46115+ .hdr_crc = cpu_to_je32(0)
46116 };
46117
46118 jffs2_prealloc_raw_node_refs(c, jeb, 1);
46119diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
46120index 74d9be1..d5dd140 100644
46121--- a/fs/jffs2/wbuf.c
46122+++ b/fs/jffs2/wbuf.c
46123@@ -1022,7 +1022,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
46124 {
46125 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
46126 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46127- .totlen = constant_cpu_to_je32(8)
46128+ .totlen = constant_cpu_to_je32(8),
46129+ .hdr_crc = constant_cpu_to_je32(0)
46130 };
46131
46132 /*
46133diff --git a/fs/jfs/super.c b/fs/jfs/super.c
46134index 4a82950..bcaa0cb 100644
46135--- a/fs/jfs/super.c
46136+++ b/fs/jfs/super.c
46137@@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
46138
46139 jfs_inode_cachep =
46140 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
46141- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
46142+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
46143 init_once);
46144 if (jfs_inode_cachep == NULL)
46145 return -ENOMEM;
46146diff --git a/fs/libfs.c b/fs/libfs.c
46147index 18d08f5..fe3dc64 100644
46148--- a/fs/libfs.c
46149+++ b/fs/libfs.c
46150@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46151
46152 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
46153 struct dentry *next;
46154+ char d_name[sizeof(next->d_iname)];
46155+ const unsigned char *name;
46156+
46157 next = list_entry(p, struct dentry, d_u.d_child);
46158 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
46159 if (!simple_positive(next)) {
46160@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46161
46162 spin_unlock(&next->d_lock);
46163 spin_unlock(&dentry->d_lock);
46164- if (filldir(dirent, next->d_name.name,
46165+ name = next->d_name.name;
46166+ if (name == next->d_iname) {
46167+ memcpy(d_name, name, next->d_name.len);
46168+ name = d_name;
46169+ }
46170+ if (filldir(dirent, name,
46171 next->d_name.len, filp->f_pos,
46172 next->d_inode->i_ino,
46173 dt_type(next->d_inode)) < 0)
46174diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
46175index 8392cb8..80d6193 100644
46176--- a/fs/lockd/clntproc.c
46177+++ b/fs/lockd/clntproc.c
46178@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
46179 /*
46180 * Cookie counter for NLM requests
46181 */
46182-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
46183+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
46184
46185 void nlmclnt_next_cookie(struct nlm_cookie *c)
46186 {
46187- u32 cookie = atomic_inc_return(&nlm_cookie);
46188+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
46189
46190 memcpy(c->data, &cookie, 4);
46191 c->len=4;
46192diff --git a/fs/locks.c b/fs/locks.c
46193index 0d68f1f..f216b79 100644
46194--- a/fs/locks.c
46195+++ b/fs/locks.c
46196@@ -2075,16 +2075,16 @@ void locks_remove_flock(struct file *filp)
46197 return;
46198
46199 if (filp->f_op && filp->f_op->flock) {
46200- struct file_lock fl = {
46201+ struct file_lock flock = {
46202 .fl_pid = current->tgid,
46203 .fl_file = filp,
46204 .fl_flags = FL_FLOCK,
46205 .fl_type = F_UNLCK,
46206 .fl_end = OFFSET_MAX,
46207 };
46208- filp->f_op->flock(filp, F_SETLKW, &fl);
46209- if (fl.fl_ops && fl.fl_ops->fl_release_private)
46210- fl.fl_ops->fl_release_private(&fl);
46211+ filp->f_op->flock(filp, F_SETLKW, &flock);
46212+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
46213+ flock.fl_ops->fl_release_private(&flock);
46214 }
46215
46216 lock_flocks();
46217diff --git a/fs/namei.c b/fs/namei.c
46218index c427919..e37fd3f 100644
46219--- a/fs/namei.c
46220+++ b/fs/namei.c
46221@@ -278,16 +278,32 @@ int generic_permission(struct inode *inode, int mask)
46222 if (ret != -EACCES)
46223 return ret;
46224
46225+#ifdef CONFIG_GRKERNSEC
46226+ /* we'll block if we have to log due to a denied capability use */
46227+ if (mask & MAY_NOT_BLOCK)
46228+ return -ECHILD;
46229+#endif
46230+
46231 if (S_ISDIR(inode->i_mode)) {
46232 /* DACs are overridable for directories */
46233- if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46234- return 0;
46235 if (!(mask & MAY_WRITE))
46236- if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46237+ if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46238+ ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46239 return 0;
46240+ if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46241+ return 0;
46242 return -EACCES;
46243 }
46244 /*
46245+ * Searching includes executable on directories, else just read.
46246+ */
46247+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46248+ if (mask == MAY_READ)
46249+ if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46250+ ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46251+ return 0;
46252+
46253+ /*
46254 * Read/write DACs are always overridable.
46255 * Executable DACs are overridable when there is
46256 * at least one exec bit set.
46257@@ -296,14 +312,6 @@ int generic_permission(struct inode *inode, int mask)
46258 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46259 return 0;
46260
46261- /*
46262- * Searching includes executable on directories, else just read.
46263- */
46264- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46265- if (mask == MAY_READ)
46266- if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46267- return 0;
46268-
46269 return -EACCES;
46270 }
46271
46272@@ -652,11 +660,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
46273 return error;
46274 }
46275
46276+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
46277+ dentry->d_inode, dentry, nd->path.mnt)) {
46278+ error = -EACCES;
46279+ *p = ERR_PTR(error); /* no ->put_link(), please */
46280+ path_put(&nd->path);
46281+ return error;
46282+ }
46283+
46284 nd->last_type = LAST_BIND;
46285 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
46286 error = PTR_ERR(*p);
46287 if (!IS_ERR(*p)) {
46288- char *s = nd_get_link(nd);
46289+ const char *s = nd_get_link(nd);
46290 error = 0;
46291 if (s)
46292 error = __vfs_follow_link(nd, s);
46293@@ -1753,6 +1769,21 @@ static int path_lookupat(int dfd, const char *name,
46294 if (!err)
46295 err = complete_walk(nd);
46296
46297+ if (!(nd->flags & LOOKUP_PARENT)) {
46298+#ifdef CONFIG_GRKERNSEC
46299+ if (flags & LOOKUP_RCU) {
46300+ if (!err)
46301+ path_put(&nd->path);
46302+ err = -ECHILD;
46303+ } else
46304+#endif
46305+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46306+ if (!err)
46307+ path_put(&nd->path);
46308+ err = -ENOENT;
46309+ }
46310+ }
46311+
46312 if (!err && nd->flags & LOOKUP_DIRECTORY) {
46313 if (!nd->inode->i_op->lookup) {
46314 path_put(&nd->path);
46315@@ -1780,6 +1811,15 @@ static int do_path_lookup(int dfd, const char *name,
46316 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
46317
46318 if (likely(!retval)) {
46319+ if (*name != '/' && nd->path.dentry && nd->inode) {
46320+#ifdef CONFIG_GRKERNSEC
46321+ if (flags & LOOKUP_RCU)
46322+ return -ECHILD;
46323+#endif
46324+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
46325+ return -ENOENT;
46326+ }
46327+
46328 if (unlikely(!audit_dummy_context())) {
46329 if (nd->path.dentry && nd->inode)
46330 audit_inode(name, nd->path.dentry);
46331@@ -2126,6 +2166,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
46332 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
46333 return -EPERM;
46334
46335+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
46336+ return -EPERM;
46337+ if (gr_handle_rawio(inode))
46338+ return -EPERM;
46339+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
46340+ return -EACCES;
46341+
46342 return 0;
46343 }
46344
46345@@ -2187,6 +2234,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46346 error = complete_walk(nd);
46347 if (error)
46348 return ERR_PTR(error);
46349+#ifdef CONFIG_GRKERNSEC
46350+ if (nd->flags & LOOKUP_RCU) {
46351+ error = -ECHILD;
46352+ goto exit;
46353+ }
46354+#endif
46355+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46356+ error = -ENOENT;
46357+ goto exit;
46358+ }
46359 audit_inode(pathname, nd->path.dentry);
46360 if (open_flag & O_CREAT) {
46361 error = -EISDIR;
46362@@ -2197,6 +2254,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46363 error = complete_walk(nd);
46364 if (error)
46365 return ERR_PTR(error);
46366+#ifdef CONFIG_GRKERNSEC
46367+ if (nd->flags & LOOKUP_RCU) {
46368+ error = -ECHILD;
46369+ goto exit;
46370+ }
46371+#endif
46372+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
46373+ error = -ENOENT;
46374+ goto exit;
46375+ }
46376 audit_inode(pathname, dir);
46377 goto ok;
46378 }
46379@@ -2218,6 +2285,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46380 error = complete_walk(nd);
46381 if (error)
46382 return ERR_PTR(error);
46383+#ifdef CONFIG_GRKERNSEC
46384+ if (nd->flags & LOOKUP_RCU) {
46385+ error = -ECHILD;
46386+ goto exit;
46387+ }
46388+#endif
46389+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46390+ error = -ENOENT;
46391+ goto exit;
46392+ }
46393
46394 error = -ENOTDIR;
46395 if (nd->flags & LOOKUP_DIRECTORY) {
46396@@ -2258,6 +2335,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46397 /* Negative dentry, just create the file */
46398 if (!dentry->d_inode) {
46399 umode_t mode = op->mode;
46400+
46401+ if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
46402+ error = -EACCES;
46403+ goto exit_mutex_unlock;
46404+ }
46405+
46406 if (!IS_POSIXACL(dir->d_inode))
46407 mode &= ~current_umask();
46408 /*
46409@@ -2281,6 +2364,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46410 error = vfs_create(dir->d_inode, dentry, mode, nd);
46411 if (error)
46412 goto exit_mutex_unlock;
46413+ else
46414+ gr_handle_create(path->dentry, path->mnt);
46415 mutex_unlock(&dir->d_inode->i_mutex);
46416 dput(nd->path.dentry);
46417 nd->path.dentry = dentry;
46418@@ -2290,6 +2375,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46419 /*
46420 * It already exists.
46421 */
46422+
46423+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
46424+ error = -ENOENT;
46425+ goto exit_mutex_unlock;
46426+ }
46427+
46428+ /* only check if O_CREAT is specified, all other checks need to go
46429+ into may_open */
46430+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
46431+ error = -EACCES;
46432+ goto exit_mutex_unlock;
46433+ }
46434+
46435 mutex_unlock(&dir->d_inode->i_mutex);
46436 audit_inode(pathname, path->dentry);
46437
46438@@ -2502,6 +2600,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
46439 *path = nd.path;
46440 return dentry;
46441 eexist:
46442+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
46443+ dput(dentry);
46444+ dentry = ERR_PTR(-ENOENT);
46445+ goto fail;
46446+ }
46447 dput(dentry);
46448 dentry = ERR_PTR(-EEXIST);
46449 fail:
46450@@ -2524,6 +2627,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
46451 }
46452 EXPORT_SYMBOL(user_path_create);
46453
46454+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
46455+{
46456+ char *tmp = getname(pathname);
46457+ struct dentry *res;
46458+ if (IS_ERR(tmp))
46459+ return ERR_CAST(tmp);
46460+ res = kern_path_create(dfd, tmp, path, is_dir);
46461+ if (IS_ERR(res))
46462+ putname(tmp);
46463+ else
46464+ *to = tmp;
46465+ return res;
46466+}
46467+
46468 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
46469 {
46470 int error = may_create(dir, dentry);
46471@@ -2591,6 +2708,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46472 error = mnt_want_write(path.mnt);
46473 if (error)
46474 goto out_dput;
46475+
46476+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
46477+ error = -EPERM;
46478+ goto out_drop_write;
46479+ }
46480+
46481+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
46482+ error = -EACCES;
46483+ goto out_drop_write;
46484+ }
46485+
46486 error = security_path_mknod(&path, dentry, mode, dev);
46487 if (error)
46488 goto out_drop_write;
46489@@ -2608,6 +2736,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46490 }
46491 out_drop_write:
46492 mnt_drop_write(path.mnt);
46493+
46494+ if (!error)
46495+ gr_handle_create(dentry, path.mnt);
46496 out_dput:
46497 dput(dentry);
46498 mutex_unlock(&path.dentry->d_inode->i_mutex);
46499@@ -2661,12 +2792,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
46500 error = mnt_want_write(path.mnt);
46501 if (error)
46502 goto out_dput;
46503+
46504+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
46505+ error = -EACCES;
46506+ goto out_drop_write;
46507+ }
46508+
46509 error = security_path_mkdir(&path, dentry, mode);
46510 if (error)
46511 goto out_drop_write;
46512 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
46513 out_drop_write:
46514 mnt_drop_write(path.mnt);
46515+
46516+ if (!error)
46517+ gr_handle_create(dentry, path.mnt);
46518 out_dput:
46519 dput(dentry);
46520 mutex_unlock(&path.dentry->d_inode->i_mutex);
46521@@ -2746,6 +2886,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
46522 char * name;
46523 struct dentry *dentry;
46524 struct nameidata nd;
46525+ ino_t saved_ino = 0;
46526+ dev_t saved_dev = 0;
46527
46528 error = user_path_parent(dfd, pathname, &nd, &name);
46529 if (error)
46530@@ -2774,6 +2916,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
46531 error = -ENOENT;
46532 goto exit3;
46533 }
46534+
46535+ saved_ino = dentry->d_inode->i_ino;
46536+ saved_dev = gr_get_dev_from_dentry(dentry);
46537+
46538+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
46539+ error = -EACCES;
46540+ goto exit3;
46541+ }
46542+
46543 error = mnt_want_write(nd.path.mnt);
46544 if (error)
46545 goto exit3;
46546@@ -2781,6 +2932,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
46547 if (error)
46548 goto exit4;
46549 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
46550+ if (!error && (saved_dev || saved_ino))
46551+ gr_handle_delete(saved_ino, saved_dev);
46552 exit4:
46553 mnt_drop_write(nd.path.mnt);
46554 exit3:
46555@@ -2843,6 +2996,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46556 struct dentry *dentry;
46557 struct nameidata nd;
46558 struct inode *inode = NULL;
46559+ ino_t saved_ino = 0;
46560+ dev_t saved_dev = 0;
46561
46562 error = user_path_parent(dfd, pathname, &nd, &name);
46563 if (error)
46564@@ -2865,6 +3020,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46565 if (!inode)
46566 goto slashes;
46567 ihold(inode);
46568+
46569+ if (inode->i_nlink <= 1) {
46570+ saved_ino = inode->i_ino;
46571+ saved_dev = gr_get_dev_from_dentry(dentry);
46572+ }
46573+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
46574+ error = -EACCES;
46575+ goto exit2;
46576+ }
46577+
46578 error = mnt_want_write(nd.path.mnt);
46579 if (error)
46580 goto exit2;
46581@@ -2872,6 +3037,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46582 if (error)
46583 goto exit3;
46584 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
46585+ if (!error && (saved_ino || saved_dev))
46586+ gr_handle_delete(saved_ino, saved_dev);
46587 exit3:
46588 mnt_drop_write(nd.path.mnt);
46589 exit2:
46590@@ -2947,10 +3114,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
46591 error = mnt_want_write(path.mnt);
46592 if (error)
46593 goto out_dput;
46594+
46595+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
46596+ error = -EACCES;
46597+ goto out_drop_write;
46598+ }
46599+
46600 error = security_path_symlink(&path, dentry, from);
46601 if (error)
46602 goto out_drop_write;
46603 error = vfs_symlink(path.dentry->d_inode, dentry, from);
46604+ if (!error)
46605+ gr_handle_create(dentry, path.mnt);
46606 out_drop_write:
46607 mnt_drop_write(path.mnt);
46608 out_dput:
46609@@ -3025,6 +3200,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
46610 {
46611 struct dentry *new_dentry;
46612 struct path old_path, new_path;
46613+ char *to = NULL;
46614 int how = 0;
46615 int error;
46616
46617@@ -3048,7 +3224,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
46618 if (error)
46619 return error;
46620
46621- new_dentry = user_path_create(newdfd, newname, &new_path, 0);
46622+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
46623 error = PTR_ERR(new_dentry);
46624 if (IS_ERR(new_dentry))
46625 goto out;
46626@@ -3059,13 +3235,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
46627 error = mnt_want_write(new_path.mnt);
46628 if (error)
46629 goto out_dput;
46630+
46631+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
46632+ old_path.dentry->d_inode,
46633+ old_path.dentry->d_inode->i_mode, to)) {
46634+ error = -EACCES;
46635+ goto out_drop_write;
46636+ }
46637+
46638+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
46639+ old_path.dentry, old_path.mnt, to)) {
46640+ error = -EACCES;
46641+ goto out_drop_write;
46642+ }
46643+
46644 error = security_path_link(old_path.dentry, &new_path, new_dentry);
46645 if (error)
46646 goto out_drop_write;
46647 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
46648+ if (!error)
46649+ gr_handle_create(new_dentry, new_path.mnt);
46650 out_drop_write:
46651 mnt_drop_write(new_path.mnt);
46652 out_dput:
46653+ putname(to);
46654 dput(new_dentry);
46655 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
46656 path_put(&new_path);
46657@@ -3299,6 +3492,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
46658 if (new_dentry == trap)
46659 goto exit5;
46660
46661+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
46662+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
46663+ to);
46664+ if (error)
46665+ goto exit5;
46666+
46667 error = mnt_want_write(oldnd.path.mnt);
46668 if (error)
46669 goto exit5;
46670@@ -3308,6 +3507,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
46671 goto exit6;
46672 error = vfs_rename(old_dir->d_inode, old_dentry,
46673 new_dir->d_inode, new_dentry);
46674+ if (!error)
46675+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
46676+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
46677 exit6:
46678 mnt_drop_write(oldnd.path.mnt);
46679 exit5:
46680@@ -3333,6 +3535,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
46681
46682 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
46683 {
46684+ char tmpbuf[64];
46685+ const char *newlink;
46686 int len;
46687
46688 len = PTR_ERR(link);
46689@@ -3342,7 +3546,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
46690 len = strlen(link);
46691 if (len > (unsigned) buflen)
46692 len = buflen;
46693- if (copy_to_user(buffer, link, len))
46694+
46695+ if (len < sizeof(tmpbuf)) {
46696+ memcpy(tmpbuf, link, len);
46697+ newlink = tmpbuf;
46698+ } else
46699+ newlink = link;
46700+
46701+ if (copy_to_user(buffer, newlink, len))
46702 len = -EFAULT;
46703 out:
46704 return len;
46705diff --git a/fs/namespace.c b/fs/namespace.c
46706index 4e46539..b28253c 100644
46707--- a/fs/namespace.c
46708+++ b/fs/namespace.c
46709@@ -1156,6 +1156,9 @@ static int do_umount(struct mount *mnt, int flags)
46710 if (!(sb->s_flags & MS_RDONLY))
46711 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
46712 up_write(&sb->s_umount);
46713+
46714+ gr_log_remount(mnt->mnt_devname, retval);
46715+
46716 return retval;
46717 }
46718
46719@@ -1175,6 +1178,9 @@ static int do_umount(struct mount *mnt, int flags)
46720 br_write_unlock(vfsmount_lock);
46721 up_write(&namespace_sem);
46722 release_mounts(&umount_list);
46723+
46724+ gr_log_unmount(mnt->mnt_devname, retval);
46725+
46726 return retval;
46727 }
46728
46729@@ -2176,6 +2182,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
46730 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
46731 MS_STRICTATIME);
46732
46733+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
46734+ retval = -EPERM;
46735+ goto dput_out;
46736+ }
46737+
46738+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
46739+ retval = -EPERM;
46740+ goto dput_out;
46741+ }
46742+
46743 if (flags & MS_REMOUNT)
46744 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
46745 data_page);
46746@@ -2190,6 +2206,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
46747 dev_name, data_page);
46748 dput_out:
46749 path_put(&path);
46750+
46751+ gr_log_mount(dev_name, dir_name, retval);
46752+
46753 return retval;
46754 }
46755
46756@@ -2471,6 +2490,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
46757 if (error)
46758 goto out2;
46759
46760+ if (gr_handle_chroot_pivot()) {
46761+ error = -EPERM;
46762+ goto out2;
46763+ }
46764+
46765 get_fs_root(current->fs, &root);
46766 error = lock_mount(&old);
46767 if (error)
46768diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
46769index e8bbfa5..864f936 100644
46770--- a/fs/nfs/inode.c
46771+++ b/fs/nfs/inode.c
46772@@ -152,7 +152,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
46773 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
46774 nfsi->attrtimeo_timestamp = jiffies;
46775
46776- memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
46777+ memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
46778 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
46779 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
46780 else
46781@@ -1005,16 +1005,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
46782 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
46783 }
46784
46785-static atomic_long_t nfs_attr_generation_counter;
46786+static atomic_long_unchecked_t nfs_attr_generation_counter;
46787
46788 static unsigned long nfs_read_attr_generation_counter(void)
46789 {
46790- return atomic_long_read(&nfs_attr_generation_counter);
46791+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
46792 }
46793
46794 unsigned long nfs_inc_attr_generation_counter(void)
46795 {
46796- return atomic_long_inc_return(&nfs_attr_generation_counter);
46797+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
46798 }
46799
46800 void nfs_fattr_init(struct nfs_fattr *fattr)
46801diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
46802index 5686661..80a9a3a 100644
46803--- a/fs/nfsd/vfs.c
46804+++ b/fs/nfsd/vfs.c
46805@@ -933,7 +933,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
46806 } else {
46807 oldfs = get_fs();
46808 set_fs(KERNEL_DS);
46809- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
46810+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
46811 set_fs(oldfs);
46812 }
46813
46814@@ -1037,7 +1037,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
46815
46816 /* Write the data. */
46817 oldfs = get_fs(); set_fs(KERNEL_DS);
46818- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
46819+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
46820 set_fs(oldfs);
46821 if (host_err < 0)
46822 goto out_nfserr;
46823@@ -1573,7 +1573,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
46824 */
46825
46826 oldfs = get_fs(); set_fs(KERNEL_DS);
46827- host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
46828+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
46829 set_fs(oldfs);
46830
46831 if (host_err < 0)
46832diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
46833index 3568c8a..e0240d8 100644
46834--- a/fs/notify/fanotify/fanotify_user.c
46835+++ b/fs/notify/fanotify/fanotify_user.c
46836@@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
46837 goto out_close_fd;
46838
46839 ret = -EFAULT;
46840- if (copy_to_user(buf, &fanotify_event_metadata,
46841+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
46842+ copy_to_user(buf, &fanotify_event_metadata,
46843 fanotify_event_metadata.event_len))
46844 goto out_kill_access_response;
46845
46846diff --git a/fs/notify/notification.c b/fs/notify/notification.c
46847index c887b13..0fdf472 100644
46848--- a/fs/notify/notification.c
46849+++ b/fs/notify/notification.c
46850@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
46851 * get set to 0 so it will never get 'freed'
46852 */
46853 static struct fsnotify_event *q_overflow_event;
46854-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
46855+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
46856
46857 /**
46858 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
46859@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
46860 */
46861 u32 fsnotify_get_cookie(void)
46862 {
46863- return atomic_inc_return(&fsnotify_sync_cookie);
46864+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
46865 }
46866 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
46867
46868diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
46869index 99e3610..02c1068 100644
46870--- a/fs/ntfs/dir.c
46871+++ b/fs/ntfs/dir.c
46872@@ -1329,7 +1329,7 @@ find_next_index_buffer:
46873 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
46874 ~(s64)(ndir->itype.index.block_size - 1)));
46875 /* Bounds checks. */
46876- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
46877+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
46878 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
46879 "inode 0x%lx or driver bug.", vdir->i_ino);
46880 goto err_out;
46881diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
46882index 8639169..76697aa 100644
46883--- a/fs/ntfs/file.c
46884+++ b/fs/ntfs/file.c
46885@@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
46886 #endif /* NTFS_RW */
46887 };
46888
46889-const struct file_operations ntfs_empty_file_ops = {};
46890+const struct file_operations ntfs_empty_file_ops __read_only;
46891
46892-const struct inode_operations ntfs_empty_inode_ops = {};
46893+const struct inode_operations ntfs_empty_inode_ops __read_only;
46894diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
46895index 210c352..a174f83 100644
46896--- a/fs/ocfs2/localalloc.c
46897+++ b/fs/ocfs2/localalloc.c
46898@@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
46899 goto bail;
46900 }
46901
46902- atomic_inc(&osb->alloc_stats.moves);
46903+ atomic_inc_unchecked(&osb->alloc_stats.moves);
46904
46905 bail:
46906 if (handle)
46907diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
46908index d355e6e..578d905 100644
46909--- a/fs/ocfs2/ocfs2.h
46910+++ b/fs/ocfs2/ocfs2.h
46911@@ -235,11 +235,11 @@ enum ocfs2_vol_state
46912
46913 struct ocfs2_alloc_stats
46914 {
46915- atomic_t moves;
46916- atomic_t local_data;
46917- atomic_t bitmap_data;
46918- atomic_t bg_allocs;
46919- atomic_t bg_extends;
46920+ atomic_unchecked_t moves;
46921+ atomic_unchecked_t local_data;
46922+ atomic_unchecked_t bitmap_data;
46923+ atomic_unchecked_t bg_allocs;
46924+ atomic_unchecked_t bg_extends;
46925 };
46926
46927 enum ocfs2_local_alloc_state
46928diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
46929index f169da4..9112253 100644
46930--- a/fs/ocfs2/suballoc.c
46931+++ b/fs/ocfs2/suballoc.c
46932@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
46933 mlog_errno(status);
46934 goto bail;
46935 }
46936- atomic_inc(&osb->alloc_stats.bg_extends);
46937+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
46938
46939 /* You should never ask for this much metadata */
46940 BUG_ON(bits_wanted >
46941@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
46942 mlog_errno(status);
46943 goto bail;
46944 }
46945- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46946+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46947
46948 *suballoc_loc = res.sr_bg_blkno;
46949 *suballoc_bit_start = res.sr_bit_offset;
46950@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
46951 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
46952 res->sr_bits);
46953
46954- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46955+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46956
46957 BUG_ON(res->sr_bits != 1);
46958
46959@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
46960 mlog_errno(status);
46961 goto bail;
46962 }
46963- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46964+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46965
46966 BUG_ON(res.sr_bits != 1);
46967
46968@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
46969 cluster_start,
46970 num_clusters);
46971 if (!status)
46972- atomic_inc(&osb->alloc_stats.local_data);
46973+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
46974 } else {
46975 if (min_clusters > (osb->bitmap_cpg - 1)) {
46976 /* The only paths asking for contiguousness
46977@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
46978 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
46979 res.sr_bg_blkno,
46980 res.sr_bit_offset);
46981- atomic_inc(&osb->alloc_stats.bitmap_data);
46982+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
46983 *num_clusters = res.sr_bits;
46984 }
46985 }
46986diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
46987index 68f4541..89cfe6a 100644
46988--- a/fs/ocfs2/super.c
46989+++ b/fs/ocfs2/super.c
46990@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
46991 "%10s => GlobalAllocs: %d LocalAllocs: %d "
46992 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
46993 "Stats",
46994- atomic_read(&osb->alloc_stats.bitmap_data),
46995- atomic_read(&osb->alloc_stats.local_data),
46996- atomic_read(&osb->alloc_stats.bg_allocs),
46997- atomic_read(&osb->alloc_stats.moves),
46998- atomic_read(&osb->alloc_stats.bg_extends));
46999+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
47000+ atomic_read_unchecked(&osb->alloc_stats.local_data),
47001+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
47002+ atomic_read_unchecked(&osb->alloc_stats.moves),
47003+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
47004
47005 out += snprintf(buf + out, len - out,
47006 "%10s => State: %u Descriptor: %llu Size: %u bits "
47007@@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
47008 spin_lock_init(&osb->osb_xattr_lock);
47009 ocfs2_init_steal_slots(osb);
47010
47011- atomic_set(&osb->alloc_stats.moves, 0);
47012- atomic_set(&osb->alloc_stats.local_data, 0);
47013- atomic_set(&osb->alloc_stats.bitmap_data, 0);
47014- atomic_set(&osb->alloc_stats.bg_allocs, 0);
47015- atomic_set(&osb->alloc_stats.bg_extends, 0);
47016+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
47017+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
47018+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
47019+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
47020+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
47021
47022 /* Copy the blockcheck stats from the superblock probe */
47023 osb->osb_ecc_stats = *stats;
47024diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
47025index 5d22872..523db20 100644
47026--- a/fs/ocfs2/symlink.c
47027+++ b/fs/ocfs2/symlink.c
47028@@ -142,7 +142,7 @@ bail:
47029
47030 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
47031 {
47032- char *link = nd_get_link(nd);
47033+ const char *link = nd_get_link(nd);
47034 if (!IS_ERR(link))
47035 kfree(link);
47036 }
47037diff --git a/fs/open.c b/fs/open.c
47038index 5720854..ccfe124 100644
47039--- a/fs/open.c
47040+++ b/fs/open.c
47041@@ -31,6 +31,8 @@
47042 #include <linux/ima.h>
47043 #include <linux/dnotify.h>
47044
47045+#define CREATE_TRACE_POINTS
47046+#include <trace/events/fs.h>
47047 #include "internal.h"
47048
47049 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
47050@@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
47051 error = locks_verify_truncate(inode, NULL, length);
47052 if (!error)
47053 error = security_path_truncate(&path);
47054+
47055+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
47056+ error = -EACCES;
47057+
47058 if (!error)
47059 error = do_truncate(path.dentry, length, 0, NULL);
47060
47061@@ -358,6 +364,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
47062 if (__mnt_is_readonly(path.mnt))
47063 res = -EROFS;
47064
47065+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
47066+ res = -EACCES;
47067+
47068 out_path_release:
47069 path_put(&path);
47070 out:
47071@@ -384,6 +393,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
47072 if (error)
47073 goto dput_and_out;
47074
47075+ gr_log_chdir(path.dentry, path.mnt);
47076+
47077 set_fs_pwd(current->fs, &path);
47078
47079 dput_and_out:
47080@@ -410,6 +421,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
47081 goto out_putf;
47082
47083 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
47084+
47085+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
47086+ error = -EPERM;
47087+
47088+ if (!error)
47089+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
47090+
47091 if (!error)
47092 set_fs_pwd(current->fs, &file->f_path);
47093 out_putf:
47094@@ -438,7 +456,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
47095 if (error)
47096 goto dput_and_out;
47097
47098+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
47099+ goto dput_and_out;
47100+
47101 set_fs_root(current->fs, &path);
47102+
47103+ gr_handle_chroot_chdir(&path);
47104+
47105 error = 0;
47106 dput_and_out:
47107 path_put(&path);
47108@@ -456,6 +480,16 @@ static int chmod_common(struct path *path, umode_t mode)
47109 if (error)
47110 return error;
47111 mutex_lock(&inode->i_mutex);
47112+
47113+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
47114+ error = -EACCES;
47115+ goto out_unlock;
47116+ }
47117+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
47118+ error = -EACCES;
47119+ goto out_unlock;
47120+ }
47121+
47122 error = security_path_chmod(path, mode);
47123 if (error)
47124 goto out_unlock;
47125@@ -506,6 +540,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
47126 int error;
47127 struct iattr newattrs;
47128
47129+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
47130+ return -EACCES;
47131+
47132 newattrs.ia_valid = ATTR_CTIME;
47133 if (user != (uid_t) -1) {
47134 newattrs.ia_valid |= ATTR_UID;
47135@@ -987,6 +1024,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
47136 } else {
47137 fsnotify_open(f);
47138 fd_install(fd, f);
47139+ trace_do_sys_open(tmp, flags, mode);
47140 }
47141 }
47142 putname(tmp);
47143diff --git a/fs/pipe.c b/fs/pipe.c
47144index fec5e4a..f4210f9 100644
47145--- a/fs/pipe.c
47146+++ b/fs/pipe.c
47147@@ -438,9 +438,9 @@ redo:
47148 }
47149 if (bufs) /* More to do? */
47150 continue;
47151- if (!pipe->writers)
47152+ if (!atomic_read(&pipe->writers))
47153 break;
47154- if (!pipe->waiting_writers) {
47155+ if (!atomic_read(&pipe->waiting_writers)) {
47156 /* syscall merging: Usually we must not sleep
47157 * if O_NONBLOCK is set, or if we got some data.
47158 * But if a writer sleeps in kernel space, then
47159@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
47160 mutex_lock(&inode->i_mutex);
47161 pipe = inode->i_pipe;
47162
47163- if (!pipe->readers) {
47164+ if (!atomic_read(&pipe->readers)) {
47165 send_sig(SIGPIPE, current, 0);
47166 ret = -EPIPE;
47167 goto out;
47168@@ -553,7 +553,7 @@ redo1:
47169 for (;;) {
47170 int bufs;
47171
47172- if (!pipe->readers) {
47173+ if (!atomic_read(&pipe->readers)) {
47174 send_sig(SIGPIPE, current, 0);
47175 if (!ret)
47176 ret = -EPIPE;
47177@@ -644,9 +644,9 @@ redo2:
47178 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47179 do_wakeup = 0;
47180 }
47181- pipe->waiting_writers++;
47182+ atomic_inc(&pipe->waiting_writers);
47183 pipe_wait(pipe);
47184- pipe->waiting_writers--;
47185+ atomic_dec(&pipe->waiting_writers);
47186 }
47187 out:
47188 mutex_unlock(&inode->i_mutex);
47189@@ -713,7 +713,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47190 mask = 0;
47191 if (filp->f_mode & FMODE_READ) {
47192 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
47193- if (!pipe->writers && filp->f_version != pipe->w_counter)
47194+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
47195 mask |= POLLHUP;
47196 }
47197
47198@@ -723,7 +723,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47199 * Most Unices do not set POLLERR for FIFOs but on Linux they
47200 * behave exactly like pipes for poll().
47201 */
47202- if (!pipe->readers)
47203+ if (!atomic_read(&pipe->readers))
47204 mask |= POLLERR;
47205 }
47206
47207@@ -737,10 +737,10 @@ pipe_release(struct inode *inode, int decr, int decw)
47208
47209 mutex_lock(&inode->i_mutex);
47210 pipe = inode->i_pipe;
47211- pipe->readers -= decr;
47212- pipe->writers -= decw;
47213+ atomic_sub(decr, &pipe->readers);
47214+ atomic_sub(decw, &pipe->writers);
47215
47216- if (!pipe->readers && !pipe->writers) {
47217+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
47218 free_pipe_info(inode);
47219 } else {
47220 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
47221@@ -830,7 +830,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
47222
47223 if (inode->i_pipe) {
47224 ret = 0;
47225- inode->i_pipe->readers++;
47226+ atomic_inc(&inode->i_pipe->readers);
47227 }
47228
47229 mutex_unlock(&inode->i_mutex);
47230@@ -847,7 +847,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
47231
47232 if (inode->i_pipe) {
47233 ret = 0;
47234- inode->i_pipe->writers++;
47235+ atomic_inc(&inode->i_pipe->writers);
47236 }
47237
47238 mutex_unlock(&inode->i_mutex);
47239@@ -865,9 +865,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
47240 if (inode->i_pipe) {
47241 ret = 0;
47242 if (filp->f_mode & FMODE_READ)
47243- inode->i_pipe->readers++;
47244+ atomic_inc(&inode->i_pipe->readers);
47245 if (filp->f_mode & FMODE_WRITE)
47246- inode->i_pipe->writers++;
47247+ atomic_inc(&inode->i_pipe->writers);
47248 }
47249
47250 mutex_unlock(&inode->i_mutex);
47251@@ -959,7 +959,7 @@ void free_pipe_info(struct inode *inode)
47252 inode->i_pipe = NULL;
47253 }
47254
47255-static struct vfsmount *pipe_mnt __read_mostly;
47256+struct vfsmount *pipe_mnt __read_mostly;
47257
47258 /*
47259 * pipefs_dname() is called from d_path().
47260@@ -989,7 +989,8 @@ static struct inode * get_pipe_inode(void)
47261 goto fail_iput;
47262 inode->i_pipe = pipe;
47263
47264- pipe->readers = pipe->writers = 1;
47265+ atomic_set(&pipe->readers, 1);
47266+ atomic_set(&pipe->writers, 1);
47267 inode->i_fop = &rdwr_pipefifo_fops;
47268
47269 /*
47270diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
47271index 15af622..0e9f4467 100644
47272--- a/fs/proc/Kconfig
47273+++ b/fs/proc/Kconfig
47274@@ -30,12 +30,12 @@ config PROC_FS
47275
47276 config PROC_KCORE
47277 bool "/proc/kcore support" if !ARM
47278- depends on PROC_FS && MMU
47279+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
47280
47281 config PROC_VMCORE
47282 bool "/proc/vmcore support"
47283- depends on PROC_FS && CRASH_DUMP
47284- default y
47285+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
47286+ default n
47287 help
47288 Exports the dump image of crashed kernel in ELF format.
47289
47290@@ -59,8 +59,8 @@ config PROC_SYSCTL
47291 limited in memory.
47292
47293 config PROC_PAGE_MONITOR
47294- default y
47295- depends on PROC_FS && MMU
47296+ default n
47297+ depends on PROC_FS && MMU && !GRKERNSEC
47298 bool "Enable /proc page monitoring" if EXPERT
47299 help
47300 Various /proc files exist to monitor process memory utilization:
47301diff --git a/fs/proc/array.c b/fs/proc/array.c
47302index f9bd395..acb7847 100644
47303--- a/fs/proc/array.c
47304+++ b/fs/proc/array.c
47305@@ -60,6 +60,7 @@
47306 #include <linux/tty.h>
47307 #include <linux/string.h>
47308 #include <linux/mman.h>
47309+#include <linux/grsecurity.h>
47310 #include <linux/proc_fs.h>
47311 #include <linux/ioport.h>
47312 #include <linux/uaccess.h>
47313@@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
47314 seq_putc(m, '\n');
47315 }
47316
47317+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47318+static inline void task_pax(struct seq_file *m, struct task_struct *p)
47319+{
47320+ if (p->mm)
47321+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
47322+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
47323+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
47324+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
47325+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
47326+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
47327+ else
47328+ seq_printf(m, "PaX:\t-----\n");
47329+}
47330+#endif
47331+
47332 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47333 struct pid *pid, struct task_struct *task)
47334 {
47335@@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47336 task_cpus_allowed(m, task);
47337 cpuset_task_status_allowed(m, task);
47338 task_context_switch_counts(m, task);
47339+
47340+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47341+ task_pax(m, task);
47342+#endif
47343+
47344+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
47345+ task_grsec_rbac(m, task);
47346+#endif
47347+
47348 return 0;
47349 }
47350
47351+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47352+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47353+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
47354+ _mm->pax_flags & MF_PAX_SEGMEXEC))
47355+#endif
47356+
47357 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47358 struct pid *pid, struct task_struct *task, int whole)
47359 {
47360@@ -378,6 +409,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47361 char tcomm[sizeof(task->comm)];
47362 unsigned long flags;
47363
47364+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47365+ if (current->exec_id != m->exec_id) {
47366+ gr_log_badprocpid("stat");
47367+ return 0;
47368+ }
47369+#endif
47370+
47371 state = *get_task_state(task);
47372 vsize = eip = esp = 0;
47373 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
47374@@ -449,6 +487,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47375 gtime = task->gtime;
47376 }
47377
47378+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47379+ if (PAX_RAND_FLAGS(mm)) {
47380+ eip = 0;
47381+ esp = 0;
47382+ wchan = 0;
47383+ }
47384+#endif
47385+#ifdef CONFIG_GRKERNSEC_HIDESYM
47386+ wchan = 0;
47387+ eip =0;
47388+ esp =0;
47389+#endif
47390+
47391 /* scale priority and nice values from timeslices to -20..20 */
47392 /* to make it look like a "normal" Unix priority/nice value */
47393 priority = task_prio(task);
47394@@ -485,9 +536,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47395 seq_put_decimal_ull(m, ' ', vsize);
47396 seq_put_decimal_ll(m, ' ', mm ? get_mm_rss(mm) : 0);
47397 seq_put_decimal_ull(m, ' ', rsslim);
47398+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47399+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
47400+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
47401+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
47402+#else
47403 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
47404 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
47405 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
47406+#endif
47407 seq_put_decimal_ull(m, ' ', esp);
47408 seq_put_decimal_ull(m, ' ', eip);
47409 /* The signal information here is obsolete.
47410@@ -508,9 +565,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47411 seq_put_decimal_ull(m, ' ', delayacct_blkio_ticks(task));
47412 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
47413 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
47414+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47415+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((mm && permitted) ? mm->start_data : 0));
47416+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((mm && permitted) ? mm->end_data : 0));
47417+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((mm && permitted) ? mm->start_brk : 0));
47418+#else
47419 seq_put_decimal_ull(m, ' ', (mm && permitted) ? mm->start_data : 0);
47420 seq_put_decimal_ull(m, ' ', (mm && permitted) ? mm->end_data : 0);
47421 seq_put_decimal_ull(m, ' ', (mm && permitted) ? mm->start_brk : 0);
47422+#endif
47423 seq_putc(m, '\n');
47424 if (mm)
47425 mmput(mm);
47426@@ -533,8 +596,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47427 struct pid *pid, struct task_struct *task)
47428 {
47429 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
47430- struct mm_struct *mm = get_task_mm(task);
47431+ struct mm_struct *mm;
47432
47433+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47434+ if (current->exec_id != m->exec_id) {
47435+ gr_log_badprocpid("statm");
47436+ return 0;
47437+ }
47438+#endif
47439+ mm = get_task_mm(task);
47440 if (mm) {
47441 size = task_statm(mm, &shared, &text, &data, &resident);
47442 mmput(mm);
47443@@ -556,3 +626,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47444
47445 return 0;
47446 }
47447+
47448+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47449+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
47450+{
47451+ u32 curr_ip = 0;
47452+ unsigned long flags;
47453+
47454+ if (lock_task_sighand(task, &flags)) {
47455+ curr_ip = task->signal->curr_ip;
47456+ unlock_task_sighand(task, &flags);
47457+ }
47458+
47459+ return sprintf(buffer, "%pI4\n", &curr_ip);
47460+}
47461+#endif
47462diff --git a/fs/proc/base.c b/fs/proc/base.c
47463index 9fc77b4..04761b8 100644
47464--- a/fs/proc/base.c
47465+++ b/fs/proc/base.c
47466@@ -109,6 +109,14 @@ struct pid_entry {
47467 union proc_op op;
47468 };
47469
47470+struct getdents_callback {
47471+ struct linux_dirent __user * current_dir;
47472+ struct linux_dirent __user * previous;
47473+ struct file * file;
47474+ int count;
47475+ int error;
47476+};
47477+
47478 #define NOD(NAME, MODE, IOP, FOP, OP) { \
47479 .name = (NAME), \
47480 .len = sizeof(NAME) - 1, \
47481@@ -213,6 +221,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
47482 if (!mm->arg_end)
47483 goto out_mm; /* Shh! No looking before we're done */
47484
47485+ if (gr_acl_handle_procpidmem(task))
47486+ goto out_mm;
47487+
47488 len = mm->arg_end - mm->arg_start;
47489
47490 if (len > PAGE_SIZE)
47491@@ -240,12 +251,28 @@ out:
47492 return res;
47493 }
47494
47495+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47496+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47497+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
47498+ _mm->pax_flags & MF_PAX_SEGMEXEC))
47499+#endif
47500+
47501 static int proc_pid_auxv(struct task_struct *task, char *buffer)
47502 {
47503 struct mm_struct *mm = mm_for_maps(task);
47504 int res = PTR_ERR(mm);
47505 if (mm && !IS_ERR(mm)) {
47506 unsigned int nwords = 0;
47507+
47508+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47509+ /* allow if we're currently ptracing this task */
47510+ if (PAX_RAND_FLAGS(mm) &&
47511+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
47512+ mmput(mm);
47513+ return 0;
47514+ }
47515+#endif
47516+
47517 do {
47518 nwords += 2;
47519 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
47520@@ -259,7 +286,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
47521 }
47522
47523
47524-#ifdef CONFIG_KALLSYMS
47525+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47526 /*
47527 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
47528 * Returns the resolved symbol. If that fails, simply return the address.
47529@@ -298,7 +325,7 @@ static void unlock_trace(struct task_struct *task)
47530 mutex_unlock(&task->signal->cred_guard_mutex);
47531 }
47532
47533-#ifdef CONFIG_STACKTRACE
47534+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47535
47536 #define MAX_STACK_TRACE_DEPTH 64
47537
47538@@ -489,7 +516,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
47539 return count;
47540 }
47541
47542-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47543+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47544 static int proc_pid_syscall(struct task_struct *task, char *buffer)
47545 {
47546 long nr;
47547@@ -518,7 +545,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
47548 /************************************************************************/
47549
47550 /* permission checks */
47551-static int proc_fd_access_allowed(struct inode *inode)
47552+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
47553 {
47554 struct task_struct *task;
47555 int allowed = 0;
47556@@ -528,7 +555,10 @@ static int proc_fd_access_allowed(struct inode *inode)
47557 */
47558 task = get_proc_task(inode);
47559 if (task) {
47560- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
47561+ if (log)
47562+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
47563+ else
47564+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
47565 put_task_struct(task);
47566 }
47567 return allowed;
47568@@ -566,10 +596,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
47569 struct task_struct *task,
47570 int hide_pid_min)
47571 {
47572+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47573+ return false;
47574+
47575+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47576+ rcu_read_lock();
47577+ {
47578+ const struct cred *tmpcred = current_cred();
47579+ const struct cred *cred = __task_cred(task);
47580+
47581+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
47582+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47583+ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
47584+#endif
47585+ ) {
47586+ rcu_read_unlock();
47587+ return true;
47588+ }
47589+ }
47590+ rcu_read_unlock();
47591+
47592+ if (!pid->hide_pid)
47593+ return false;
47594+#endif
47595+
47596 if (pid->hide_pid < hide_pid_min)
47597 return true;
47598 if (in_group_p(pid->pid_gid))
47599 return true;
47600+
47601 return ptrace_may_access(task, PTRACE_MODE_READ);
47602 }
47603
47604@@ -587,7 +642,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
47605 put_task_struct(task);
47606
47607 if (!has_perms) {
47608+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47609+ {
47610+#else
47611 if (pid->hide_pid == 2) {
47612+#endif
47613 /*
47614 * Let's make getdents(), stat(), and open()
47615 * consistent with each other. If a process
47616@@ -702,6 +761,10 @@ static int mem_open(struct inode* inode, struct file* file)
47617 file->f_mode |= FMODE_UNSIGNED_OFFSET;
47618 file->private_data = mm;
47619
47620+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47621+ file->f_version = current->exec_id;
47622+#endif
47623+
47624 return 0;
47625 }
47626
47627@@ -713,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
47628 ssize_t copied;
47629 char *page;
47630
47631+#ifdef CONFIG_GRKERNSEC
47632+ if (write)
47633+ return -EPERM;
47634+#endif
47635+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47636+ if (file->f_version != current->exec_id) {
47637+ gr_log_badprocpid("mem");
47638+ return 0;
47639+ }
47640+#endif
47641+
47642 if (!mm)
47643 return 0;
47644
47645@@ -813,6 +887,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
47646 if (!task)
47647 goto out_no_task;
47648
47649+ if (gr_acl_handle_procpidmem(task))
47650+ goto out;
47651+
47652 ret = -ENOMEM;
47653 page = (char *)__get_free_page(GFP_TEMPORARY);
47654 if (!page)
47655@@ -1433,7 +1510,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
47656 path_put(&nd->path);
47657
47658 /* Are we allowed to snoop on the tasks file descriptors? */
47659- if (!proc_fd_access_allowed(inode))
47660+ if (!proc_fd_access_allowed(inode, 0))
47661 goto out;
47662
47663 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
47664@@ -1472,8 +1549,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
47665 struct path path;
47666
47667 /* Are we allowed to snoop on the tasks file descriptors? */
47668- if (!proc_fd_access_allowed(inode))
47669- goto out;
47670+ /* logging this is needed for learning on chromium to work properly,
47671+ but we don't want to flood the logs from 'ps' which does a readlink
47672+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
47673+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
47674+ */
47675+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
47676+ if (!proc_fd_access_allowed(inode,0))
47677+ goto out;
47678+ } else {
47679+ if (!proc_fd_access_allowed(inode,1))
47680+ goto out;
47681+ }
47682
47683 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
47684 if (error)
47685@@ -1538,7 +1625,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
47686 rcu_read_lock();
47687 cred = __task_cred(task);
47688 inode->i_uid = cred->euid;
47689+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47690+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47691+#else
47692 inode->i_gid = cred->egid;
47693+#endif
47694 rcu_read_unlock();
47695 }
47696 security_task_to_inode(task, inode);
47697@@ -1574,10 +1665,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
47698 return -ENOENT;
47699 }
47700 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
47701+#ifdef CONFIG_GRKERNSEC_PROC_USER
47702+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
47703+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47704+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
47705+#endif
47706 task_dumpable(task)) {
47707 cred = __task_cred(task);
47708 stat->uid = cred->euid;
47709+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47710+ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
47711+#else
47712 stat->gid = cred->egid;
47713+#endif
47714 }
47715 }
47716 rcu_read_unlock();
47717@@ -1615,11 +1715,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
47718
47719 if (task) {
47720 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
47721+#ifdef CONFIG_GRKERNSEC_PROC_USER
47722+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
47723+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47724+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
47725+#endif
47726 task_dumpable(task)) {
47727 rcu_read_lock();
47728 cred = __task_cred(task);
47729 inode->i_uid = cred->euid;
47730+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47731+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47732+#else
47733 inode->i_gid = cred->egid;
47734+#endif
47735 rcu_read_unlock();
47736 } else {
47737 inode->i_uid = 0;
47738@@ -1737,7 +1846,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
47739 int fd = proc_fd(inode);
47740
47741 if (task) {
47742- files = get_files_struct(task);
47743+ if (!gr_acl_handle_procpidmem(task))
47744+ files = get_files_struct(task);
47745 put_task_struct(task);
47746 }
47747 if (files) {
47748@@ -2338,11 +2448,21 @@ static const struct file_operations proc_map_files_operations = {
47749 */
47750 static int proc_fd_permission(struct inode *inode, int mask)
47751 {
47752+ struct task_struct *task;
47753 int rv = generic_permission(inode, mask);
47754- if (rv == 0)
47755- return 0;
47756+
47757 if (task_pid(current) == proc_pid(inode))
47758 rv = 0;
47759+
47760+ task = get_proc_task(inode);
47761+ if (task == NULL)
47762+ return rv;
47763+
47764+ if (gr_acl_handle_procpidmem(task))
47765+ rv = -EACCES;
47766+
47767+ put_task_struct(task);
47768+
47769 return rv;
47770 }
47771
47772@@ -2452,6 +2572,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
47773 if (!task)
47774 goto out_no_task;
47775
47776+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47777+ goto out;
47778+
47779 /*
47780 * Yes, it does not scale. And it should not. Don't add
47781 * new entries into /proc/<tgid>/ without very good reasons.
47782@@ -2496,6 +2619,9 @@ static int proc_pident_readdir(struct file *filp,
47783 if (!task)
47784 goto out_no_task;
47785
47786+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47787+ goto out;
47788+
47789 ret = 0;
47790 i = filp->f_pos;
47791 switch (i) {
47792@@ -2766,7 +2892,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
47793 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
47794 void *cookie)
47795 {
47796- char *s = nd_get_link(nd);
47797+ const char *s = nd_get_link(nd);
47798 if (!IS_ERR(s))
47799 __putname(s);
47800 }
47801@@ -2967,7 +3093,7 @@ static const struct pid_entry tgid_base_stuff[] = {
47802 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
47803 #endif
47804 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
47805-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47806+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47807 INF("syscall", S_IRUGO, proc_pid_syscall),
47808 #endif
47809 INF("cmdline", S_IRUGO, proc_pid_cmdline),
47810@@ -2992,10 +3118,10 @@ static const struct pid_entry tgid_base_stuff[] = {
47811 #ifdef CONFIG_SECURITY
47812 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
47813 #endif
47814-#ifdef CONFIG_KALLSYMS
47815+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47816 INF("wchan", S_IRUGO, proc_pid_wchan),
47817 #endif
47818-#ifdef CONFIG_STACKTRACE
47819+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47820 ONE("stack", S_IRUGO, proc_pid_stack),
47821 #endif
47822 #ifdef CONFIG_SCHEDSTATS
47823@@ -3029,6 +3155,9 @@ static const struct pid_entry tgid_base_stuff[] = {
47824 #ifdef CONFIG_HARDWALL
47825 INF("hardwall", S_IRUGO, proc_pid_hardwall),
47826 #endif
47827+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47828+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
47829+#endif
47830 };
47831
47832 static int proc_tgid_base_readdir(struct file * filp,
47833@@ -3155,7 +3284,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
47834 if (!inode)
47835 goto out;
47836
47837+#ifdef CONFIG_GRKERNSEC_PROC_USER
47838+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
47839+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47840+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47841+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
47842+#else
47843 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
47844+#endif
47845 inode->i_op = &proc_tgid_base_inode_operations;
47846 inode->i_fop = &proc_tgid_base_operations;
47847 inode->i_flags|=S_IMMUTABLE;
47848@@ -3197,7 +3333,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
47849 if (!task)
47850 goto out;
47851
47852+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47853+ goto out_put_task;
47854+
47855 result = proc_pid_instantiate(dir, dentry, task, NULL);
47856+out_put_task:
47857 put_task_struct(task);
47858 out:
47859 return result;
47860@@ -3260,6 +3400,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
47861 static int fake_filldir(void *buf, const char *name, int namelen,
47862 loff_t offset, u64 ino, unsigned d_type)
47863 {
47864+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
47865+ __buf->error = -EINVAL;
47866 return 0;
47867 }
47868
47869@@ -3326,7 +3468,7 @@ static const struct pid_entry tid_base_stuff[] = {
47870 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
47871 #endif
47872 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
47873-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47874+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47875 INF("syscall", S_IRUGO, proc_pid_syscall),
47876 #endif
47877 INF("cmdline", S_IRUGO, proc_pid_cmdline),
47878@@ -3350,10 +3492,10 @@ static const struct pid_entry tid_base_stuff[] = {
47879 #ifdef CONFIG_SECURITY
47880 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
47881 #endif
47882-#ifdef CONFIG_KALLSYMS
47883+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47884 INF("wchan", S_IRUGO, proc_pid_wchan),
47885 #endif
47886-#ifdef CONFIG_STACKTRACE
47887+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47888 ONE("stack", S_IRUGO, proc_pid_stack),
47889 #endif
47890 #ifdef CONFIG_SCHEDSTATS
47891diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
47892index 82676e3..5f8518a 100644
47893--- a/fs/proc/cmdline.c
47894+++ b/fs/proc/cmdline.c
47895@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
47896
47897 static int __init proc_cmdline_init(void)
47898 {
47899+#ifdef CONFIG_GRKERNSEC_PROC_ADD
47900+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
47901+#else
47902 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
47903+#endif
47904 return 0;
47905 }
47906 module_init(proc_cmdline_init);
47907diff --git a/fs/proc/devices.c b/fs/proc/devices.c
47908index b143471..bb105e5 100644
47909--- a/fs/proc/devices.c
47910+++ b/fs/proc/devices.c
47911@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
47912
47913 static int __init proc_devices_init(void)
47914 {
47915+#ifdef CONFIG_GRKERNSEC_PROC_ADD
47916+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
47917+#else
47918 proc_create("devices", 0, NULL, &proc_devinfo_operations);
47919+#endif
47920 return 0;
47921 }
47922 module_init(proc_devices_init);
47923diff --git a/fs/proc/inode.c b/fs/proc/inode.c
47924index 205c922..2ee4c57 100644
47925--- a/fs/proc/inode.c
47926+++ b/fs/proc/inode.c
47927@@ -21,11 +21,17 @@
47928 #include <linux/seq_file.h>
47929 #include <linux/slab.h>
47930 #include <linux/mount.h>
47931+#include <linux/grsecurity.h>
47932
47933 #include <asm/uaccess.h>
47934
47935 #include "internal.h"
47936
47937+#ifdef CONFIG_PROC_SYSCTL
47938+extern const struct inode_operations proc_sys_inode_operations;
47939+extern const struct inode_operations proc_sys_dir_operations;
47940+#endif
47941+
47942 static void proc_evict_inode(struct inode *inode)
47943 {
47944 struct proc_dir_entry *de;
47945@@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
47946 ns_ops = PROC_I(inode)->ns_ops;
47947 if (ns_ops && ns_ops->put)
47948 ns_ops->put(PROC_I(inode)->ns);
47949+
47950+#ifdef CONFIG_PROC_SYSCTL
47951+ if (inode->i_op == &proc_sys_inode_operations ||
47952+ inode->i_op == &proc_sys_dir_operations)
47953+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
47954+#endif
47955+
47956 }
47957
47958 static struct kmem_cache * proc_inode_cachep;
47959@@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
47960 if (de->mode) {
47961 inode->i_mode = de->mode;
47962 inode->i_uid = de->uid;
47963+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47964+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47965+#else
47966 inode->i_gid = de->gid;
47967+#endif
47968 }
47969 if (de->size)
47970 inode->i_size = de->size;
47971diff --git a/fs/proc/internal.h b/fs/proc/internal.h
47972index 5f79bb8..eeccee4 100644
47973--- a/fs/proc/internal.h
47974+++ b/fs/proc/internal.h
47975@@ -54,6 +54,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47976 struct pid *pid, struct task_struct *task);
47977 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47978 struct pid *pid, struct task_struct *task);
47979+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47980+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
47981+#endif
47982 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
47983
47984 extern const struct file_operations proc_pid_maps_operations;
47985diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
47986index 86c67ee..cdca321 100644
47987--- a/fs/proc/kcore.c
47988+++ b/fs/proc/kcore.c
47989@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
47990 * the addresses in the elf_phdr on our list.
47991 */
47992 start = kc_offset_to_vaddr(*fpos - elf_buflen);
47993- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
47994+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
47995+ if (tsz > buflen)
47996 tsz = buflen;
47997-
47998+
47999 while (buflen) {
48000 struct kcore_list *m;
48001
48002@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48003 kfree(elf_buf);
48004 } else {
48005 if (kern_addr_valid(start)) {
48006- unsigned long n;
48007+ char *elf_buf;
48008+ mm_segment_t oldfs;
48009
48010- n = copy_to_user(buffer, (char *)start, tsz);
48011- /*
48012- * We cannot distinguish between fault on source
48013- * and fault on destination. When this happens
48014- * we clear too and hope it will trigger the
48015- * EFAULT again.
48016- */
48017- if (n) {
48018- if (clear_user(buffer + tsz - n,
48019- n))
48020+ elf_buf = kmalloc(tsz, GFP_KERNEL);
48021+ if (!elf_buf)
48022+ return -ENOMEM;
48023+ oldfs = get_fs();
48024+ set_fs(KERNEL_DS);
48025+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
48026+ set_fs(oldfs);
48027+ if (copy_to_user(buffer, elf_buf, tsz)) {
48028+ kfree(elf_buf);
48029 return -EFAULT;
48030+ }
48031 }
48032+ set_fs(oldfs);
48033+ kfree(elf_buf);
48034 } else {
48035 if (clear_user(buffer, tsz))
48036 return -EFAULT;
48037@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48038
48039 static int open_kcore(struct inode *inode, struct file *filp)
48040 {
48041+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
48042+ return -EPERM;
48043+#endif
48044 if (!capable(CAP_SYS_RAWIO))
48045 return -EPERM;
48046 if (kcore_need_update)
48047diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
48048index 80e4645..53e5fcf 100644
48049--- a/fs/proc/meminfo.c
48050+++ b/fs/proc/meminfo.c
48051@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
48052 vmi.used >> 10,
48053 vmi.largest_chunk >> 10
48054 #ifdef CONFIG_MEMORY_FAILURE
48055- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
48056+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
48057 #endif
48058 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
48059 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
48060diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
48061index b1822dd..df622cb 100644
48062--- a/fs/proc/nommu.c
48063+++ b/fs/proc/nommu.c
48064@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
48065 if (len < 1)
48066 len = 1;
48067 seq_printf(m, "%*c", len, ' ');
48068- seq_path(m, &file->f_path, "");
48069+ seq_path(m, &file->f_path, "\n\\");
48070 }
48071
48072 seq_putc(m, '\n');
48073diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
48074index 06e1cc1..177cd98 100644
48075--- a/fs/proc/proc_net.c
48076+++ b/fs/proc/proc_net.c
48077@@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
48078 struct task_struct *task;
48079 struct nsproxy *ns;
48080 struct net *net = NULL;
48081+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48082+ const struct cred *cred = current_cred();
48083+#endif
48084+
48085+#ifdef CONFIG_GRKERNSEC_PROC_USER
48086+ if (cred->fsuid)
48087+ return net;
48088+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48089+ if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
48090+ return net;
48091+#endif
48092
48093 rcu_read_lock();
48094 task = pid_task(proc_pid(dir), PIDTYPE_PID);
48095diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
48096index 21d836f..bebf3ee 100644
48097--- a/fs/proc/proc_sysctl.c
48098+++ b/fs/proc/proc_sysctl.c
48099@@ -12,11 +12,15 @@
48100 #include <linux/module.h>
48101 #include "internal.h"
48102
48103+extern int gr_handle_chroot_sysctl(const int op);
48104+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
48105+ const int op);
48106+
48107 static const struct dentry_operations proc_sys_dentry_operations;
48108 static const struct file_operations proc_sys_file_operations;
48109-static const struct inode_operations proc_sys_inode_operations;
48110+const struct inode_operations proc_sys_inode_operations;
48111 static const struct file_operations proc_sys_dir_file_operations;
48112-static const struct inode_operations proc_sys_dir_operations;
48113+const struct inode_operations proc_sys_dir_operations;
48114
48115 void proc_sys_poll_notify(struct ctl_table_poll *poll)
48116 {
48117@@ -470,8 +474,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
48118
48119 err = NULL;
48120 d_set_d_op(dentry, &proc_sys_dentry_operations);
48121+
48122+ gr_handle_proc_create(dentry, inode);
48123+
48124 d_add(dentry, inode);
48125
48126+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt))
48127+ err = ERR_PTR(-ENOENT);
48128+
48129 out:
48130 sysctl_head_finish(head);
48131 return err;
48132@@ -483,18 +493,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48133 struct inode *inode = filp->f_path.dentry->d_inode;
48134 struct ctl_table_header *head = grab_header(inode);
48135 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
48136+ int op = write ? MAY_WRITE : MAY_READ;
48137 ssize_t error;
48138 size_t res;
48139
48140 if (IS_ERR(head))
48141 return PTR_ERR(head);
48142
48143+
48144 /*
48145 * At this point we know that the sysctl was not unregistered
48146 * and won't be until we finish.
48147 */
48148 error = -EPERM;
48149- if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
48150+ if (sysctl_perm(head->root, table, op))
48151 goto out;
48152
48153 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
48154@@ -502,6 +514,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48155 if (!table->proc_handler)
48156 goto out;
48157
48158+#ifdef CONFIG_GRKERNSEC
48159+ error = -EPERM;
48160+ if (gr_handle_chroot_sysctl(op))
48161+ goto out;
48162+ dget(filp->f_path.dentry);
48163+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
48164+ dput(filp->f_path.dentry);
48165+ goto out;
48166+ }
48167+ dput(filp->f_path.dentry);
48168+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
48169+ goto out;
48170+ if (write && !capable(CAP_SYS_ADMIN))
48171+ goto out;
48172+#endif
48173+
48174 /* careful: calling conventions are nasty here */
48175 res = count;
48176 error = table->proc_handler(table, write, buf, &res, ppos);
48177@@ -599,6 +627,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
48178 return -ENOMEM;
48179 } else {
48180 d_set_d_op(child, &proc_sys_dentry_operations);
48181+
48182+ gr_handle_proc_create(child, inode);
48183+
48184 d_add(child, inode);
48185 }
48186 } else {
48187@@ -642,6 +673,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
48188 if ((*pos)++ < file->f_pos)
48189 return 0;
48190
48191+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
48192+ return 0;
48193+
48194 if (unlikely(S_ISLNK(table->mode)))
48195 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
48196 else
48197@@ -759,6 +793,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
48198 if (IS_ERR(head))
48199 return PTR_ERR(head);
48200
48201+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
48202+ return -ENOENT;
48203+
48204 generic_fillattr(inode, stat);
48205 if (table)
48206 stat->mode = (stat->mode & S_IFMT) | table->mode;
48207@@ -781,13 +818,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
48208 .llseek = generic_file_llseek,
48209 };
48210
48211-static const struct inode_operations proc_sys_inode_operations = {
48212+const struct inode_operations proc_sys_inode_operations = {
48213 .permission = proc_sys_permission,
48214 .setattr = proc_sys_setattr,
48215 .getattr = proc_sys_getattr,
48216 };
48217
48218-static const struct inode_operations proc_sys_dir_operations = {
48219+const struct inode_operations proc_sys_dir_operations = {
48220 .lookup = proc_sys_lookup,
48221 .permission = proc_sys_permission,
48222 .setattr = proc_sys_setattr,
48223diff --git a/fs/proc/root.c b/fs/proc/root.c
48224index eed44bf..abeb499 100644
48225--- a/fs/proc/root.c
48226+++ b/fs/proc/root.c
48227@@ -188,7 +188,15 @@ void __init proc_root_init(void)
48228 #ifdef CONFIG_PROC_DEVICETREE
48229 proc_device_tree_init();
48230 #endif
48231+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48232+#ifdef CONFIG_GRKERNSEC_PROC_USER
48233+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
48234+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48235+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48236+#endif
48237+#else
48238 proc_mkdir("bus", NULL);
48239+#endif
48240 proc_sys_init();
48241 }
48242
48243diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
48244index 7faaf2a..096c28b 100644
48245--- a/fs/proc/task_mmu.c
48246+++ b/fs/proc/task_mmu.c
48247@@ -11,12 +11,19 @@
48248 #include <linux/rmap.h>
48249 #include <linux/swap.h>
48250 #include <linux/swapops.h>
48251+#include <linux/grsecurity.h>
48252
48253 #include <asm/elf.h>
48254 #include <asm/uaccess.h>
48255 #include <asm/tlbflush.h>
48256 #include "internal.h"
48257
48258+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48259+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48260+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
48261+ _mm->pax_flags & MF_PAX_SEGMEXEC))
48262+#endif
48263+
48264 void task_mem(struct seq_file *m, struct mm_struct *mm)
48265 {
48266 unsigned long data, text, lib, swap;
48267@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48268 "VmExe:\t%8lu kB\n"
48269 "VmLib:\t%8lu kB\n"
48270 "VmPTE:\t%8lu kB\n"
48271- "VmSwap:\t%8lu kB\n",
48272- hiwater_vm << (PAGE_SHIFT-10),
48273+ "VmSwap:\t%8lu kB\n"
48274+
48275+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48276+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
48277+#endif
48278+
48279+ ,hiwater_vm << (PAGE_SHIFT-10),
48280 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
48281 mm->locked_vm << (PAGE_SHIFT-10),
48282 mm->pinned_vm << (PAGE_SHIFT-10),
48283@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48284 data << (PAGE_SHIFT-10),
48285 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
48286 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
48287- swap << (PAGE_SHIFT-10));
48288+ swap << (PAGE_SHIFT-10)
48289+
48290+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48291+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48292+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
48293+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
48294+#else
48295+ , mm->context.user_cs_base
48296+ , mm->context.user_cs_limit
48297+#endif
48298+#endif
48299+
48300+ );
48301 }
48302
48303 unsigned long task_vsize(struct mm_struct *mm)
48304@@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
48305 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
48306 }
48307
48308- /* We don't show the stack guard page in /proc/maps */
48309+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48310+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
48311+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
48312+#else
48313 start = vma->vm_start;
48314- if (stack_guard_page_start(vma, start))
48315- start += PAGE_SIZE;
48316 end = vma->vm_end;
48317- if (stack_guard_page_end(vma, end))
48318- end -= PAGE_SIZE;
48319+#endif
48320
48321 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
48322 start,
48323@@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
48324 flags & VM_WRITE ? 'w' : '-',
48325 flags & VM_EXEC ? 'x' : '-',
48326 flags & VM_MAYSHARE ? 's' : 'p',
48327+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48328+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
48329+#else
48330 pgoff,
48331+#endif
48332 MAJOR(dev), MINOR(dev), ino, &len);
48333
48334 /*
48335@@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
48336 */
48337 if (file) {
48338 pad_len_spaces(m, len);
48339- seq_path(m, &file->f_path, "\n");
48340+ seq_path(m, &file->f_path, "\n\\");
48341 goto done;
48342 }
48343
48344@@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
48345 * Thread stack in /proc/PID/task/TID/maps or
48346 * the main process stack.
48347 */
48348- if (!is_pid || (vma->vm_start <= mm->start_stack &&
48349- vma->vm_end >= mm->start_stack)) {
48350+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
48351+ (vma->vm_start <= mm->start_stack &&
48352+ vma->vm_end >= mm->start_stack)) {
48353 name = "[stack]";
48354 } else {
48355 /* Thread stack in /proc/PID/maps */
48356@@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
48357 struct proc_maps_private *priv = m->private;
48358 struct task_struct *task = priv->task;
48359
48360+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48361+ if (current->exec_id != m->exec_id) {
48362+ gr_log_badprocpid("maps");
48363+ return 0;
48364+ }
48365+#endif
48366+
48367 show_map_vma(m, vma, is_pid);
48368
48369 if (m->count < m->size) /* vma is copied successfully */
48370@@ -482,12 +518,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
48371 .private = &mss,
48372 };
48373
48374+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48375+ if (current->exec_id != m->exec_id) {
48376+ gr_log_badprocpid("smaps");
48377+ return 0;
48378+ }
48379+#endif
48380 memset(&mss, 0, sizeof mss);
48381- mss.vma = vma;
48382- /* mmap_sem is held in m_start */
48383- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48384- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48385-
48386+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48387+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
48388+#endif
48389+ mss.vma = vma;
48390+ /* mmap_sem is held in m_start */
48391+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48392+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48393+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48394+ }
48395+#endif
48396 show_map_vma(m, vma, is_pid);
48397
48398 seq_printf(m,
48399@@ -505,7 +552,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
48400 "KernelPageSize: %8lu kB\n"
48401 "MMUPageSize: %8lu kB\n"
48402 "Locked: %8lu kB\n",
48403+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48404+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
48405+#else
48406 (vma->vm_end - vma->vm_start) >> 10,
48407+#endif
48408 mss.resident >> 10,
48409 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
48410 mss.shared_clean >> 10,
48411@@ -1138,6 +1189,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
48412 int n;
48413 char buffer[50];
48414
48415+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48416+ if (current->exec_id != m->exec_id) {
48417+ gr_log_badprocpid("numa_maps");
48418+ return 0;
48419+ }
48420+#endif
48421+
48422 if (!mm)
48423 return 0;
48424
48425@@ -1155,11 +1213,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
48426 mpol_to_str(buffer, sizeof(buffer), pol, 0);
48427 mpol_cond_put(pol);
48428
48429+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48430+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
48431+#else
48432 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
48433+#endif
48434
48435 if (file) {
48436 seq_printf(m, " file=");
48437- seq_path(m, &file->f_path, "\n\t= ");
48438+ seq_path(m, &file->f_path, "\n\t\\= ");
48439 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
48440 seq_printf(m, " heap");
48441 } else {
48442diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
48443index 74fe164..899e77b 100644
48444--- a/fs/proc/task_nommu.c
48445+++ b/fs/proc/task_nommu.c
48446@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48447 else
48448 bytes += kobjsize(mm);
48449
48450- if (current->fs && current->fs->users > 1)
48451+ if (current->fs && atomic_read(&current->fs->users) > 1)
48452 sbytes += kobjsize(current->fs);
48453 else
48454 bytes += kobjsize(current->fs);
48455@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
48456
48457 if (file) {
48458 pad_len_spaces(m, len);
48459- seq_path(m, &file->f_path, "");
48460+ seq_path(m, &file->f_path, "\n\\");
48461 } else if (mm) {
48462 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
48463
48464diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
48465index d67908b..d13f6a6 100644
48466--- a/fs/quota/netlink.c
48467+++ b/fs/quota/netlink.c
48468@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
48469 void quota_send_warning(short type, unsigned int id, dev_t dev,
48470 const char warntype)
48471 {
48472- static atomic_t seq;
48473+ static atomic_unchecked_t seq;
48474 struct sk_buff *skb;
48475 void *msg_head;
48476 int ret;
48477@@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
48478 "VFS: Not enough memory to send quota warning.\n");
48479 return;
48480 }
48481- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
48482+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
48483 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
48484 if (!msg_head) {
48485 printk(KERN_ERR
48486diff --git a/fs/readdir.c b/fs/readdir.c
48487index cc0a822..43cb195 100644
48488--- a/fs/readdir.c
48489+++ b/fs/readdir.c
48490@@ -17,6 +17,7 @@
48491 #include <linux/security.h>
48492 #include <linux/syscalls.h>
48493 #include <linux/unistd.h>
48494+#include <linux/namei.h>
48495
48496 #include <asm/uaccess.h>
48497
48498@@ -67,6 +68,7 @@ struct old_linux_dirent {
48499
48500 struct readdir_callback {
48501 struct old_linux_dirent __user * dirent;
48502+ struct file * file;
48503 int result;
48504 };
48505
48506@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
48507 buf->result = -EOVERFLOW;
48508 return -EOVERFLOW;
48509 }
48510+
48511+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48512+ return 0;
48513+
48514 buf->result++;
48515 dirent = buf->dirent;
48516 if (!access_ok(VERIFY_WRITE, dirent,
48517@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
48518
48519 buf.result = 0;
48520 buf.dirent = dirent;
48521+ buf.file = file;
48522
48523 error = vfs_readdir(file, fillonedir, &buf);
48524 if (buf.result)
48525@@ -142,6 +149,7 @@ struct linux_dirent {
48526 struct getdents_callback {
48527 struct linux_dirent __user * current_dir;
48528 struct linux_dirent __user * previous;
48529+ struct file * file;
48530 int count;
48531 int error;
48532 };
48533@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
48534 buf->error = -EOVERFLOW;
48535 return -EOVERFLOW;
48536 }
48537+
48538+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48539+ return 0;
48540+
48541 dirent = buf->previous;
48542 if (dirent) {
48543 if (__put_user(offset, &dirent->d_off))
48544@@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
48545 buf.previous = NULL;
48546 buf.count = count;
48547 buf.error = 0;
48548+ buf.file = file;
48549
48550 error = vfs_readdir(file, filldir, &buf);
48551 if (error >= 0)
48552@@ -229,6 +242,7 @@ out:
48553 struct getdents_callback64 {
48554 struct linux_dirent64 __user * current_dir;
48555 struct linux_dirent64 __user * previous;
48556+ struct file *file;
48557 int count;
48558 int error;
48559 };
48560@@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
48561 buf->error = -EINVAL; /* only used if we fail.. */
48562 if (reclen > buf->count)
48563 return -EINVAL;
48564+
48565+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48566+ return 0;
48567+
48568 dirent = buf->previous;
48569 if (dirent) {
48570 if (__put_user(offset, &dirent->d_off))
48571@@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48572
48573 buf.current_dir = dirent;
48574 buf.previous = NULL;
48575+ buf.file = file;
48576 buf.count = count;
48577 buf.error = 0;
48578
48579@@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48580 error = buf.error;
48581 lastdirent = buf.previous;
48582 if (lastdirent) {
48583- typeof(lastdirent->d_off) d_off = file->f_pos;
48584+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
48585 if (__put_user(d_off, &lastdirent->d_off))
48586 error = -EFAULT;
48587 else
48588diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
48589index 2b7882b..1c5ef48 100644
48590--- a/fs/reiserfs/do_balan.c
48591+++ b/fs/reiserfs/do_balan.c
48592@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
48593 return;
48594 }
48595
48596- atomic_inc(&(fs_generation(tb->tb_sb)));
48597+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
48598 do_balance_starts(tb);
48599
48600 /* balance leaf returns 0 except if combining L R and S into
48601diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
48602index 2c1ade6..8c59d8d 100644
48603--- a/fs/reiserfs/procfs.c
48604+++ b/fs/reiserfs/procfs.c
48605@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
48606 "SMALL_TAILS " : "NO_TAILS ",
48607 replay_only(sb) ? "REPLAY_ONLY " : "",
48608 convert_reiserfs(sb) ? "CONV " : "",
48609- atomic_read(&r->s_generation_counter),
48610+ atomic_read_unchecked(&r->s_generation_counter),
48611 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
48612 SF(s_do_balance), SF(s_unneeded_left_neighbor),
48613 SF(s_good_search_by_key_reada), SF(s_bmaps),
48614diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
48615index a59d271..e12d1cf 100644
48616--- a/fs/reiserfs/reiserfs.h
48617+++ b/fs/reiserfs/reiserfs.h
48618@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
48619 /* Comment? -Hans */
48620 wait_queue_head_t s_wait;
48621 /* To be obsoleted soon by per buffer seals.. -Hans */
48622- atomic_t s_generation_counter; // increased by one every time the
48623+ atomic_unchecked_t s_generation_counter; // increased by one every time the
48624 // tree gets re-balanced
48625 unsigned long s_properties; /* File system properties. Currently holds
48626 on-disk FS format */
48627@@ -1973,7 +1973,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
48628 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
48629
48630 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
48631-#define get_generation(s) atomic_read (&fs_generation(s))
48632+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
48633 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
48634 #define __fs_changed(gen,s) (gen != get_generation (s))
48635 #define fs_changed(gen,s) \
48636diff --git a/fs/select.c b/fs/select.c
48637index 17d33d0..da0bf5c 100644
48638--- a/fs/select.c
48639+++ b/fs/select.c
48640@@ -20,6 +20,7 @@
48641 #include <linux/export.h>
48642 #include <linux/slab.h>
48643 #include <linux/poll.h>
48644+#include <linux/security.h>
48645 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
48646 #include <linux/file.h>
48647 #include <linux/fdtable.h>
48648@@ -833,6 +834,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
48649 struct poll_list *walk = head;
48650 unsigned long todo = nfds;
48651
48652+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
48653 if (nfds > rlimit(RLIMIT_NOFILE))
48654 return -EINVAL;
48655
48656diff --git a/fs/seq_file.c b/fs/seq_file.c
48657index 0cbd049..cab1127 100644
48658--- a/fs/seq_file.c
48659+++ b/fs/seq_file.c
48660@@ -9,6 +9,7 @@
48661 #include <linux/export.h>
48662 #include <linux/seq_file.h>
48663 #include <linux/slab.h>
48664+#include <linux/sched.h>
48665
48666 #include <asm/uaccess.h>
48667 #include <asm/page.h>
48668@@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
48669 memset(p, 0, sizeof(*p));
48670 mutex_init(&p->lock);
48671 p->op = op;
48672+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48673+ p->exec_id = current->exec_id;
48674+#endif
48675
48676 /*
48677 * Wrappers around seq_open(e.g. swaps_open) need to be
48678@@ -567,7 +571,7 @@ static void single_stop(struct seq_file *p, void *v)
48679 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
48680 void *data)
48681 {
48682- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
48683+ seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
48684 int res = -ENOMEM;
48685
48686 if (op) {
48687diff --git a/fs/splice.c b/fs/splice.c
48688index f847684..156619e 100644
48689--- a/fs/splice.c
48690+++ b/fs/splice.c
48691@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
48692 pipe_lock(pipe);
48693
48694 for (;;) {
48695- if (!pipe->readers) {
48696+ if (!atomic_read(&pipe->readers)) {
48697 send_sig(SIGPIPE, current, 0);
48698 if (!ret)
48699 ret = -EPIPE;
48700@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
48701 do_wakeup = 0;
48702 }
48703
48704- pipe->waiting_writers++;
48705+ atomic_inc(&pipe->waiting_writers);
48706 pipe_wait(pipe);
48707- pipe->waiting_writers--;
48708+ atomic_dec(&pipe->waiting_writers);
48709 }
48710
48711 pipe_unlock(pipe);
48712@@ -560,7 +560,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
48713 old_fs = get_fs();
48714 set_fs(get_ds());
48715 /* The cast to a user pointer is valid due to the set_fs() */
48716- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
48717+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
48718 set_fs(old_fs);
48719
48720 return res;
48721@@ -575,7 +575,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
48722 old_fs = get_fs();
48723 set_fs(get_ds());
48724 /* The cast to a user pointer is valid due to the set_fs() */
48725- res = vfs_write(file, (const char __user *)buf, count, &pos);
48726+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
48727 set_fs(old_fs);
48728
48729 return res;
48730@@ -626,7 +626,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
48731 goto err;
48732
48733 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
48734- vec[i].iov_base = (void __user *) page_address(page);
48735+ vec[i].iov_base = (void __force_user *) page_address(page);
48736 vec[i].iov_len = this_len;
48737 spd.pages[i] = page;
48738 spd.nr_pages++;
48739@@ -845,10 +845,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
48740 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
48741 {
48742 while (!pipe->nrbufs) {
48743- if (!pipe->writers)
48744+ if (!atomic_read(&pipe->writers))
48745 return 0;
48746
48747- if (!pipe->waiting_writers && sd->num_spliced)
48748+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
48749 return 0;
48750
48751 if (sd->flags & SPLICE_F_NONBLOCK)
48752@@ -1181,7 +1181,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
48753 * out of the pipe right after the splice_to_pipe(). So set
48754 * PIPE_READERS appropriately.
48755 */
48756- pipe->readers = 1;
48757+ atomic_set(&pipe->readers, 1);
48758
48759 current->splice_pipe = pipe;
48760 }
48761@@ -1733,9 +1733,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48762 ret = -ERESTARTSYS;
48763 break;
48764 }
48765- if (!pipe->writers)
48766+ if (!atomic_read(&pipe->writers))
48767 break;
48768- if (!pipe->waiting_writers) {
48769+ if (!atomic_read(&pipe->waiting_writers)) {
48770 if (flags & SPLICE_F_NONBLOCK) {
48771 ret = -EAGAIN;
48772 break;
48773@@ -1767,7 +1767,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48774 pipe_lock(pipe);
48775
48776 while (pipe->nrbufs >= pipe->buffers) {
48777- if (!pipe->readers) {
48778+ if (!atomic_read(&pipe->readers)) {
48779 send_sig(SIGPIPE, current, 0);
48780 ret = -EPIPE;
48781 break;
48782@@ -1780,9 +1780,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48783 ret = -ERESTARTSYS;
48784 break;
48785 }
48786- pipe->waiting_writers++;
48787+ atomic_inc(&pipe->waiting_writers);
48788 pipe_wait(pipe);
48789- pipe->waiting_writers--;
48790+ atomic_dec(&pipe->waiting_writers);
48791 }
48792
48793 pipe_unlock(pipe);
48794@@ -1818,14 +1818,14 @@ retry:
48795 pipe_double_lock(ipipe, opipe);
48796
48797 do {
48798- if (!opipe->readers) {
48799+ if (!atomic_read(&opipe->readers)) {
48800 send_sig(SIGPIPE, current, 0);
48801 if (!ret)
48802 ret = -EPIPE;
48803 break;
48804 }
48805
48806- if (!ipipe->nrbufs && !ipipe->writers)
48807+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
48808 break;
48809
48810 /*
48811@@ -1922,7 +1922,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
48812 pipe_double_lock(ipipe, opipe);
48813
48814 do {
48815- if (!opipe->readers) {
48816+ if (!atomic_read(&opipe->readers)) {
48817 send_sig(SIGPIPE, current, 0);
48818 if (!ret)
48819 ret = -EPIPE;
48820@@ -1967,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
48821 * return EAGAIN if we have the potential of some data in the
48822 * future, otherwise just return 0
48823 */
48824- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
48825+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
48826 ret = -EAGAIN;
48827
48828 pipe_unlock(ipipe);
48829diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
48830index 35a36d3..23424b2 100644
48831--- a/fs/sysfs/dir.c
48832+++ b/fs/sysfs/dir.c
48833@@ -657,6 +657,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
48834 struct sysfs_dirent *sd;
48835 int rc;
48836
48837+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
48838+ const char *parent_name = parent_sd->s_name;
48839+
48840+ mode = S_IFDIR | S_IRWXU;
48841+
48842+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
48843+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
48844+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
48845+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
48846+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
48847+#endif
48848+
48849 /* allocate */
48850 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
48851 if (!sd)
48852diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
48853index 00012e3..8392349 100644
48854--- a/fs/sysfs/file.c
48855+++ b/fs/sysfs/file.c
48856@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
48857
48858 struct sysfs_open_dirent {
48859 atomic_t refcnt;
48860- atomic_t event;
48861+ atomic_unchecked_t event;
48862 wait_queue_head_t poll;
48863 struct list_head buffers; /* goes through sysfs_buffer.list */
48864 };
48865@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
48866 if (!sysfs_get_active(attr_sd))
48867 return -ENODEV;
48868
48869- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
48870+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
48871 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
48872
48873 sysfs_put_active(attr_sd);
48874@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
48875 return -ENOMEM;
48876
48877 atomic_set(&new_od->refcnt, 0);
48878- atomic_set(&new_od->event, 1);
48879+ atomic_set_unchecked(&new_od->event, 1);
48880 init_waitqueue_head(&new_od->poll);
48881 INIT_LIST_HEAD(&new_od->buffers);
48882 goto retry;
48883@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
48884
48885 sysfs_put_active(attr_sd);
48886
48887- if (buffer->event != atomic_read(&od->event))
48888+ if (buffer->event != atomic_read_unchecked(&od->event))
48889 goto trigger;
48890
48891 return DEFAULT_POLLMASK;
48892@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
48893
48894 od = sd->s_attr.open;
48895 if (od) {
48896- atomic_inc(&od->event);
48897+ atomic_inc_unchecked(&od->event);
48898 wake_up_interruptible(&od->poll);
48899 }
48900
48901diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
48902index a7ac78f..02158e1 100644
48903--- a/fs/sysfs/symlink.c
48904+++ b/fs/sysfs/symlink.c
48905@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
48906
48907 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
48908 {
48909- char *page = nd_get_link(nd);
48910+ const char *page = nd_get_link(nd);
48911 if (!IS_ERR(page))
48912 free_page((unsigned long)page);
48913 }
48914diff --git a/fs/udf/misc.c b/fs/udf/misc.c
48915index c175b4d..8f36a16 100644
48916--- a/fs/udf/misc.c
48917+++ b/fs/udf/misc.c
48918@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
48919
48920 u8 udf_tag_checksum(const struct tag *t)
48921 {
48922- u8 *data = (u8 *)t;
48923+ const u8 *data = (const u8 *)t;
48924 u8 checksum = 0;
48925 int i;
48926 for (i = 0; i < sizeof(struct tag); ++i)
48927diff --git a/fs/utimes.c b/fs/utimes.c
48928index ba653f3..06ea4b1 100644
48929--- a/fs/utimes.c
48930+++ b/fs/utimes.c
48931@@ -1,6 +1,7 @@
48932 #include <linux/compiler.h>
48933 #include <linux/file.h>
48934 #include <linux/fs.h>
48935+#include <linux/security.h>
48936 #include <linux/linkage.h>
48937 #include <linux/mount.h>
48938 #include <linux/namei.h>
48939@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
48940 goto mnt_drop_write_and_out;
48941 }
48942 }
48943+
48944+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
48945+ error = -EACCES;
48946+ goto mnt_drop_write_and_out;
48947+ }
48948+
48949 mutex_lock(&inode->i_mutex);
48950 error = notify_change(path->dentry, &newattrs);
48951 mutex_unlock(&inode->i_mutex);
48952diff --git a/fs/xattr.c b/fs/xattr.c
48953index 3c8c1cc..a83c398 100644
48954--- a/fs/xattr.c
48955+++ b/fs/xattr.c
48956@@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
48957 * Extended attribute SET operations
48958 */
48959 static long
48960-setxattr(struct dentry *d, const char __user *name, const void __user *value,
48961+setxattr(struct path *path, const char __user *name, const void __user *value,
48962 size_t size, int flags)
48963 {
48964 int error;
48965@@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
48966 }
48967 }
48968
48969- error = vfs_setxattr(d, kname, kvalue, size, flags);
48970+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
48971+ error = -EACCES;
48972+ goto out;
48973+ }
48974+
48975+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
48976 out:
48977 if (vvalue)
48978 vfree(vvalue);
48979@@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
48980 return error;
48981 error = mnt_want_write(path.mnt);
48982 if (!error) {
48983- error = setxattr(path.dentry, name, value, size, flags);
48984+ error = setxattr(&path, name, value, size, flags);
48985 mnt_drop_write(path.mnt);
48986 }
48987 path_put(&path);
48988@@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
48989 return error;
48990 error = mnt_want_write(path.mnt);
48991 if (!error) {
48992- error = setxattr(path.dentry, name, value, size, flags);
48993+ error = setxattr(&path, name, value, size, flags);
48994 mnt_drop_write(path.mnt);
48995 }
48996 path_put(&path);
48997@@ -400,17 +405,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
48998 const void __user *,value, size_t, size, int, flags)
48999 {
49000 struct file *f;
49001- struct dentry *dentry;
49002 int error = -EBADF;
49003
49004 f = fget(fd);
49005 if (!f)
49006 return error;
49007- dentry = f->f_path.dentry;
49008- audit_inode(NULL, dentry);
49009+ audit_inode(NULL, f->f_path.dentry);
49010 error = mnt_want_write_file(f);
49011 if (!error) {
49012- error = setxattr(dentry, name, value, size, flags);
49013+ error = setxattr(&f->f_path, name, value, size, flags);
49014 mnt_drop_write_file(f);
49015 }
49016 fput(f);
49017diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
49018index 69d06b0..c0996e5 100644
49019--- a/fs/xattr_acl.c
49020+++ b/fs/xattr_acl.c
49021@@ -17,8 +17,8 @@
49022 struct posix_acl *
49023 posix_acl_from_xattr(const void *value, size_t size)
49024 {
49025- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
49026- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
49027+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
49028+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
49029 int count;
49030 struct posix_acl *acl;
49031 struct posix_acl_entry *acl_e;
49032diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
49033index 85e7e32..5344e52 100644
49034--- a/fs/xfs/xfs_bmap.c
49035+++ b/fs/xfs/xfs_bmap.c
49036@@ -190,7 +190,7 @@ xfs_bmap_validate_ret(
49037 int nmap,
49038 int ret_nmap);
49039 #else
49040-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
49041+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
49042 #endif /* DEBUG */
49043
49044 STATIC int
49045diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
49046index 79d05e8..e3e5861 100644
49047--- a/fs/xfs/xfs_dir2_sf.c
49048+++ b/fs/xfs/xfs_dir2_sf.c
49049@@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
49050 }
49051
49052 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
49053- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49054+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
49055+ char name[sfep->namelen];
49056+ memcpy(name, sfep->name, sfep->namelen);
49057+ if (filldir(dirent, name, sfep->namelen,
49058+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
49059+ *offset = off & 0x7fffffff;
49060+ return 0;
49061+ }
49062+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49063 off & 0x7fffffff, ino, DT_UNKNOWN)) {
49064 *offset = off & 0x7fffffff;
49065 return 0;
49066diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
49067index 91f8ff5..0ce68f9 100644
49068--- a/fs/xfs/xfs_ioctl.c
49069+++ b/fs/xfs/xfs_ioctl.c
49070@@ -128,7 +128,7 @@ xfs_find_handle(
49071 }
49072
49073 error = -EFAULT;
49074- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
49075+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
49076 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
49077 goto out_put;
49078
49079diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
49080index 3011b87..1ab03e9 100644
49081--- a/fs/xfs/xfs_iops.c
49082+++ b/fs/xfs/xfs_iops.c
49083@@ -397,7 +397,7 @@ xfs_vn_put_link(
49084 struct nameidata *nd,
49085 void *p)
49086 {
49087- char *s = nd_get_link(nd);
49088+ const char *s = nd_get_link(nd);
49089
49090 if (!IS_ERR(s))
49091 kfree(s);
49092diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
49093new file mode 100644
49094index 0000000..2645296
49095--- /dev/null
49096+++ b/grsecurity/Kconfig
49097@@ -0,0 +1,1079 @@
49098+#
49099+# grecurity configuration
49100+#
49101+
49102+menu "Grsecurity"
49103+
49104+config GRKERNSEC
49105+ bool "Grsecurity"
49106+ select CRYPTO
49107+ select CRYPTO_SHA256
49108+ help
49109+ If you say Y here, you will be able to configure many features
49110+ that will enhance the security of your system. It is highly
49111+ recommended that you say Y here and read through the help
49112+ for each option so that you fully understand the features and
49113+ can evaluate their usefulness for your machine.
49114+
49115+choice
49116+ prompt "Security Level"
49117+ depends on GRKERNSEC
49118+ default GRKERNSEC_CUSTOM
49119+
49120+config GRKERNSEC_LOW
49121+ bool "Low"
49122+ select GRKERNSEC_LINK
49123+ select GRKERNSEC_FIFO
49124+ select GRKERNSEC_RANDNET
49125+ select GRKERNSEC_DMESG
49126+ select GRKERNSEC_CHROOT
49127+ select GRKERNSEC_CHROOT_CHDIR
49128+
49129+ help
49130+ If you choose this option, several of the grsecurity options will
49131+ be enabled that will give you greater protection against a number
49132+ of attacks, while assuring that none of your software will have any
49133+ conflicts with the additional security measures. If you run a lot
49134+ of unusual software, or you are having problems with the higher
49135+ security levels, you should say Y here. With this option, the
49136+ following features are enabled:
49137+
49138+ - Linking restrictions
49139+ - FIFO restrictions
49140+ - Restricted dmesg
49141+ - Enforced chdir("/") on chroot
49142+ - Runtime module disabling
49143+
49144+config GRKERNSEC_MEDIUM
49145+ bool "Medium"
49146+ select PAX
49147+ select PAX_EI_PAX
49148+ select PAX_PT_PAX_FLAGS
49149+ select PAX_HAVE_ACL_FLAGS
49150+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
49151+ select GRKERNSEC_CHROOT
49152+ select GRKERNSEC_CHROOT_SYSCTL
49153+ select GRKERNSEC_LINK
49154+ select GRKERNSEC_FIFO
49155+ select GRKERNSEC_DMESG
49156+ select GRKERNSEC_RANDNET
49157+ select GRKERNSEC_FORKFAIL
49158+ select GRKERNSEC_TIME
49159+ select GRKERNSEC_SIGNAL
49160+ select GRKERNSEC_CHROOT
49161+ select GRKERNSEC_CHROOT_UNIX
49162+ select GRKERNSEC_CHROOT_MOUNT
49163+ select GRKERNSEC_CHROOT_PIVOT
49164+ select GRKERNSEC_CHROOT_DOUBLE
49165+ select GRKERNSEC_CHROOT_CHDIR
49166+ select GRKERNSEC_CHROOT_MKNOD
49167+ select GRKERNSEC_PROC
49168+ select GRKERNSEC_PROC_USERGROUP
49169+ select PAX_RANDUSTACK
49170+ select PAX_ASLR
49171+ select PAX_RANDMMAP
49172+ select PAX_REFCOUNT if (X86 || SPARC64)
49173+ select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
49174+
49175+ help
49176+ If you say Y here, several features in addition to those included
49177+ in the low additional security level will be enabled. These
49178+ features provide even more security to your system, though in rare
49179+ cases they may be incompatible with very old or poorly written
49180+ software. If you enable this option, make sure that your auth
49181+ service (identd) is running as gid 1001. With this option,
49182+ the following features (in addition to those provided in the
49183+ low additional security level) will be enabled:
49184+
49185+ - Failed fork logging
49186+ - Time change logging
49187+ - Signal logging
49188+ - Deny mounts in chroot
49189+ - Deny double chrooting
49190+ - Deny sysctl writes in chroot
49191+ - Deny mknod in chroot
49192+ - Deny access to abstract AF_UNIX sockets out of chroot
49193+ - Deny pivot_root in chroot
49194+ - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
49195+ - /proc restrictions with special GID set to 10 (usually wheel)
49196+ - Address Space Layout Randomization (ASLR)
49197+ - Prevent exploitation of most refcount overflows
49198+ - Bounds checking of copying between the kernel and userland
49199+
49200+config GRKERNSEC_HIGH
49201+ bool "High"
49202+ select GRKERNSEC_LINK
49203+ select GRKERNSEC_FIFO
49204+ select GRKERNSEC_DMESG
49205+ select GRKERNSEC_FORKFAIL
49206+ select GRKERNSEC_TIME
49207+ select GRKERNSEC_SIGNAL
49208+ select GRKERNSEC_CHROOT
49209+ select GRKERNSEC_CHROOT_SHMAT
49210+ select GRKERNSEC_CHROOT_UNIX
49211+ select GRKERNSEC_CHROOT_MOUNT
49212+ select GRKERNSEC_CHROOT_FCHDIR
49213+ select GRKERNSEC_CHROOT_PIVOT
49214+ select GRKERNSEC_CHROOT_DOUBLE
49215+ select GRKERNSEC_CHROOT_CHDIR
49216+ select GRKERNSEC_CHROOT_MKNOD
49217+ select GRKERNSEC_CHROOT_CAPS
49218+ select GRKERNSEC_CHROOT_SYSCTL
49219+ select GRKERNSEC_CHROOT_FINDTASK
49220+ select GRKERNSEC_SYSFS_RESTRICT
49221+ select GRKERNSEC_PROC
49222+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
49223+ select GRKERNSEC_HIDESYM
49224+ select GRKERNSEC_BRUTE
49225+ select GRKERNSEC_PROC_USERGROUP
49226+ select GRKERNSEC_KMEM
49227+ select GRKERNSEC_RESLOG
49228+ select GRKERNSEC_RANDNET
49229+ select GRKERNSEC_PROC_ADD
49230+ select GRKERNSEC_CHROOT_CHMOD
49231+ select GRKERNSEC_CHROOT_NICE
49232+ select GRKERNSEC_SETXID if (X86 || SPARC64 || PPC || ARM || MIPS)
49233+ select GRKERNSEC_AUDIT_MOUNT
49234+ select GRKERNSEC_MODHARDEN if (MODULES)
49235+ select GRKERNSEC_HARDEN_PTRACE
49236+ select GRKERNSEC_PTRACE_READEXEC
49237+ select GRKERNSEC_VM86 if (X86_32)
49238+ select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
49239+ select PAX
49240+ select PAX_RANDUSTACK
49241+ select PAX_ASLR
49242+ select PAX_RANDMMAP
49243+ select PAX_NOEXEC
49244+ select PAX_MPROTECT
49245+ select PAX_EI_PAX
49246+ select PAX_PT_PAX_FLAGS
49247+ select PAX_HAVE_ACL_FLAGS
49248+ select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
49249+ select PAX_MEMORY_UDEREF if (X86 && !XEN)
49250+ select PAX_RANDKSTACK if (X86_TSC && X86)
49251+ select PAX_SEGMEXEC if (X86_32)
49252+ select PAX_PAGEEXEC
49253+ select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
49254+ select PAX_EMUTRAMP if (PARISC)
49255+ select PAX_EMUSIGRT if (PARISC)
49256+ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
49257+ select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
49258+ select PAX_REFCOUNT if (X86 || SPARC64)
49259+ select PAX_USERCOPY if ((X86 || PPC || SPARC || ARM) && (SLAB || SLUB || SLOB))
49260+ help
49261+ If you say Y here, many of the features of grsecurity will be
49262+ enabled, which will protect you against many kinds of attacks
49263+ against your system. The heightened security comes at a cost
49264+ of an increased chance of incompatibilities with rare software
49265+ on your machine. Since this security level enables PaX, you should
49266+ view <http://pax.grsecurity.net> and read about the PaX
49267+ project. While you are there, download chpax and run it on
49268+ binaries that cause problems with PaX. Also remember that
49269+ since the /proc restrictions are enabled, you must run your
49270+ identd as gid 1001. This security level enables the following
49271+ features in addition to those listed in the low and medium
49272+ security levels:
49273+
49274+ - Additional /proc restrictions
49275+ - Chmod restrictions in chroot
49276+ - No signals, ptrace, or viewing of processes outside of chroot
49277+ - Capability restrictions in chroot
49278+ - Deny fchdir out of chroot
49279+ - Priority restrictions in chroot
49280+ - Segmentation-based implementation of PaX
49281+ - Mprotect restrictions
49282+ - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
49283+ - Kernel stack randomization
49284+ - Mount/unmount/remount logging
49285+ - Kernel symbol hiding
49286+ - Hardening of module auto-loading
49287+ - Ptrace restrictions
49288+ - Restricted vm86 mode
49289+ - Restricted sysfs/debugfs
49290+ - Active kernel exploit response
49291+
49292+config GRKERNSEC_CUSTOM
49293+ bool "Custom"
49294+ help
49295+ If you say Y here, you will be able to configure every grsecurity
49296+ option, which allows you to enable many more features that aren't
49297+ covered in the basic security levels. These additional features
49298+ include TPE, socket restrictions, and the sysctl system for
49299+ grsecurity. It is advised that you read through the help for
49300+ each option to determine its usefulness in your situation.
49301+
49302+endchoice
49303+
49304+menu "Memory Protections"
49305+depends on GRKERNSEC
49306+
49307+config GRKERNSEC_KMEM
49308+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
49309+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
49310+ help
49311+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
49312+ be written to or read from to modify or leak the contents of the running
49313+ kernel. /dev/port will also not be allowed to be opened. If you have module
49314+ support disabled, enabling this will close up four ways that are
49315+ currently used to insert malicious code into the running kernel.
49316+ Even with all these features enabled, we still highly recommend that
49317+ you use the RBAC system, as it is still possible for an attacker to
49318+ modify the running kernel through privileged I/O granted by ioperm/iopl.
49319+ If you are not using XFree86, you may be able to stop this additional
49320+ case by enabling the 'Disable privileged I/O' option. Though nothing
49321+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
49322+ but only to video memory, which is the only writing we allow in this
49323+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
49324+ not be allowed to mprotect it with PROT_WRITE later.
49325+ It is highly recommended that you say Y here if you meet all the
49326+ conditions above.
49327+
49328+config GRKERNSEC_VM86
49329+ bool "Restrict VM86 mode"
49330+ depends on X86_32
49331+
49332+ help
49333+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
49334+ make use of a special execution mode on 32bit x86 processors called
49335+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
49336+ video cards and will still work with this option enabled. The purpose
49337+ of the option is to prevent exploitation of emulation errors in
49338+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
49339+ Nearly all users should be able to enable this option.
49340+
49341+config GRKERNSEC_IO
49342+ bool "Disable privileged I/O"
49343+ depends on X86
49344+ select RTC_CLASS
49345+ select RTC_INTF_DEV
49346+ select RTC_DRV_CMOS
49347+
49348+ help
49349+ If you say Y here, all ioperm and iopl calls will return an error.
49350+ Ioperm and iopl can be used to modify the running kernel.
49351+ Unfortunately, some programs need this access to operate properly,
49352+ the most notable of which are XFree86 and hwclock. hwclock can be
49353+ remedied by having RTC support in the kernel, so real-time
49354+ clock support is enabled if this option is enabled, to ensure
49355+ that hwclock operates correctly. XFree86 still will not
49356+ operate correctly with this option enabled, so DO NOT CHOOSE Y
49357+ IF YOU USE XFree86. If you use XFree86 and you still want to
49358+ protect your kernel against modification, use the RBAC system.
49359+
49360+config GRKERNSEC_PROC_MEMMAP
49361+ bool "Harden ASLR against information leaks and entropy reduction"
49362+ default y if (PAX_NOEXEC || PAX_ASLR)
49363+ depends on PAX_NOEXEC || PAX_ASLR
49364+ help
49365+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
49366+ give no information about the addresses of its mappings if
49367+ PaX features that rely on random addresses are enabled on the task.
49368+ In addition to sanitizing this information and disabling other
49369+ dangerous sources of information, this option causes reads of sensitive
49370+ /proc/<pid> entries where the file descriptor was opened in a different
49371+ task than the one performing the read. Such attempts are logged.
49372+ This option also limits argv/env strings for suid/sgid binaries
49373+ to 512KB to prevent a complete exhaustion of the stack entropy provided
49374+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
49375+ binaries to prevent alternative mmap layouts from being abused.
49376+
49377+ If you use PaX it is essential that you say Y here as it closes up
49378+ several holes that make full ASLR useless locally.
49379+
49380+config GRKERNSEC_BRUTE
49381+ bool "Deter exploit bruteforcing"
49382+ help
49383+ If you say Y here, attempts to bruteforce exploits against forking
49384+ daemons such as apache or sshd, as well as against suid/sgid binaries
49385+ will be deterred. When a child of a forking daemon is killed by PaX
49386+ or crashes due to an illegal instruction or other suspicious signal,
49387+ the parent process will be delayed 30 seconds upon every subsequent
49388+ fork until the administrator is able to assess the situation and
49389+ restart the daemon.
49390+ In the suid/sgid case, the attempt is logged, the user has all their
49391+ processes terminated, and they are prevented from executing any further
49392+ processes for 15 minutes.
49393+ It is recommended that you also enable signal logging in the auditing
49394+ section so that logs are generated when a process triggers a suspicious
49395+ signal.
49396+ If the sysctl option is enabled, a sysctl option with name
49397+ "deter_bruteforce" is created.
49398+
49399+
49400+config GRKERNSEC_MODHARDEN
49401+ bool "Harden module auto-loading"
49402+ depends on MODULES
49403+ help
49404+ If you say Y here, module auto-loading in response to use of some
49405+ feature implemented by an unloaded module will be restricted to
49406+ root users. Enabling this option helps defend against attacks
49407+ by unprivileged users who abuse the auto-loading behavior to
49408+ cause a vulnerable module to load that is then exploited.
49409+
49410+ If this option prevents a legitimate use of auto-loading for a
49411+ non-root user, the administrator can execute modprobe manually
49412+ with the exact name of the module mentioned in the alert log.
49413+ Alternatively, the administrator can add the module to the list
49414+ of modules loaded at boot by modifying init scripts.
49415+
49416+ Modification of init scripts will most likely be needed on
49417+ Ubuntu servers with encrypted home directory support enabled,
49418+ as the first non-root user logging in will cause the ecb(aes),
49419+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
49420+
49421+config GRKERNSEC_HIDESYM
49422+ bool "Hide kernel symbols"
49423+ help
49424+ If you say Y here, getting information on loaded modules, and
49425+ displaying all kernel symbols through a syscall will be restricted
49426+ to users with CAP_SYS_MODULE. For software compatibility reasons,
49427+ /proc/kallsyms will be restricted to the root user. The RBAC
49428+ system can hide that entry even from root.
49429+
49430+ This option also prevents leaking of kernel addresses through
49431+ several /proc entries.
49432+
49433+ Note that this option is only effective provided the following
49434+ conditions are met:
49435+ 1) The kernel using grsecurity is not precompiled by some distribution
49436+ 2) You have also enabled GRKERNSEC_DMESG
49437+ 3) You are using the RBAC system and hiding other files such as your
49438+ kernel image and System.map. Alternatively, enabling this option
49439+ causes the permissions on /boot, /lib/modules, and the kernel
49440+ source directory to change at compile time to prevent
49441+ reading by non-root users.
49442+ If the above conditions are met, this option will aid in providing a
49443+ useful protection against local kernel exploitation of overflows
49444+ and arbitrary read/write vulnerabilities.
49445+
49446+config GRKERNSEC_KERN_LOCKOUT
49447+ bool "Active kernel exploit response"
49448+ depends on X86 || ARM || PPC || SPARC
49449+ help
49450+ If you say Y here, when a PaX alert is triggered due to suspicious
49451+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
49452+ or an OOPs occurs due to bad memory accesses, instead of just
49453+ terminating the offending process (and potentially allowing
49454+ a subsequent exploit from the same user), we will take one of two
49455+ actions:
49456+ If the user was root, we will panic the system
49457+ If the user was non-root, we will log the attempt, terminate
49458+ all processes owned by the user, then prevent them from creating
49459+ any new processes until the system is restarted
49460+ This deters repeated kernel exploitation/bruteforcing attempts
49461+ and is useful for later forensics.
49462+
49463+endmenu
49464+menu "Role Based Access Control Options"
49465+depends on GRKERNSEC
49466+
49467+config GRKERNSEC_RBAC_DEBUG
49468+ bool
49469+
49470+config GRKERNSEC_NO_RBAC
49471+ bool "Disable RBAC system"
49472+ help
49473+ If you say Y here, the /dev/grsec device will be removed from the kernel,
49474+ preventing the RBAC system from being enabled. You should only say Y
49475+ here if you have no intention of using the RBAC system, so as to prevent
49476+ an attacker with root access from misusing the RBAC system to hide files
49477+ and processes when loadable module support and /dev/[k]mem have been
49478+ locked down.
49479+
49480+config GRKERNSEC_ACL_HIDEKERN
49481+ bool "Hide kernel processes"
49482+ help
49483+ If you say Y here, all kernel threads will be hidden to all
49484+ processes but those whose subject has the "view hidden processes"
49485+ flag.
49486+
49487+config GRKERNSEC_ACL_MAXTRIES
49488+ int "Maximum tries before password lockout"
49489+ default 3
49490+ help
49491+ This option enforces the maximum number of times a user can attempt
49492+ to authorize themselves with the grsecurity RBAC system before being
49493+ denied the ability to attempt authorization again for a specified time.
49494+ The lower the number, the harder it will be to brute-force a password.
49495+
49496+config GRKERNSEC_ACL_TIMEOUT
49497+ int "Time to wait after max password tries, in seconds"
49498+ default 30
49499+ help
49500+ This option specifies the time the user must wait after attempting to
49501+ authorize to the RBAC system with the maximum number of invalid
49502+ passwords. The higher the number, the harder it will be to brute-force
49503+ a password.
49504+
49505+endmenu
49506+menu "Filesystem Protections"
49507+depends on GRKERNSEC
49508+
49509+config GRKERNSEC_PROC
49510+ bool "Proc restrictions"
49511+ help
49512+ If you say Y here, the permissions of the /proc filesystem
49513+ will be altered to enhance system security and privacy. You MUST
49514+ choose either a user only restriction or a user and group restriction.
49515+ Depending upon the option you choose, you can either restrict users to
49516+ see only the processes they themselves run, or choose a group that can
49517+ view all processes and files normally restricted to root if you choose
49518+ the "restrict to user only" option. NOTE: If you're running identd or
49519+ ntpd as a non-root user, you will have to run it as the group you
49520+ specify here.
49521+
49522+config GRKERNSEC_PROC_USER
49523+ bool "Restrict /proc to user only"
49524+ depends on GRKERNSEC_PROC
49525+ help
49526+ If you say Y here, non-root users will only be able to view their own
49527+ processes, and restricts them from viewing network-related information,
49528+ and viewing kernel symbol and module information.
49529+
49530+config GRKERNSEC_PROC_USERGROUP
49531+ bool "Allow special group"
49532+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
49533+ help
49534+ If you say Y here, you will be able to select a group that will be
49535+ able to view all processes and network-related information. If you've
49536+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
49537+ remain hidden. This option is useful if you want to run identd as
49538+ a non-root user.
49539+
49540+config GRKERNSEC_PROC_GID
49541+ int "GID for special group"
49542+ depends on GRKERNSEC_PROC_USERGROUP
49543+ default 1001
49544+
49545+config GRKERNSEC_PROC_ADD
49546+ bool "Additional restrictions"
49547+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
49548+ help
49549+ If you say Y here, additional restrictions will be placed on
49550+ /proc that keep normal users from viewing device information and
49551+ slabinfo information that could be useful for exploits.
49552+
49553+config GRKERNSEC_LINK
49554+ bool "Linking restrictions"
49555+ help
49556+ If you say Y here, /tmp race exploits will be prevented, since users
49557+ will no longer be able to follow symlinks owned by other users in
49558+ world-writable +t directories (e.g. /tmp), unless the owner of the
49559+ symlink is the owner of the directory. users will also not be
49560+ able to hardlink to files they do not own. If the sysctl option is
49561+ enabled, a sysctl option with name "linking_restrictions" is created.
49562+
49563+config GRKERNSEC_FIFO
49564+ bool "FIFO restrictions"
49565+ help
49566+ If you say Y here, users will not be able to write to FIFOs they don't
49567+ own in world-writable +t directories (e.g. /tmp), unless the owner of
49568+ the FIFO is the same owner of the directory it's held in. If the sysctl
49569+ option is enabled, a sysctl option with name "fifo_restrictions" is
49570+ created.
49571+
49572+config GRKERNSEC_SYSFS_RESTRICT
49573+ bool "Sysfs/debugfs restriction"
49574+ depends on SYSFS
49575+ help
49576+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
49577+ any filesystem normally mounted under it (e.g. debugfs) will be
49578+ mostly accessible only by root. These filesystems generally provide access
49579+ to hardware and debug information that isn't appropriate for unprivileged
49580+ users of the system. Sysfs and debugfs have also become a large source
49581+ of new vulnerabilities, ranging from infoleaks to local compromise.
49582+ There has been very little oversight with an eye toward security involved
49583+ in adding new exporters of information to these filesystems, so their
49584+ use is discouraged.
49585+ For reasons of compatibility, a few directories have been whitelisted
49586+ for access by non-root users:
49587+ /sys/fs/selinux
49588+ /sys/fs/fuse
49589+ /sys/devices/system/cpu
49590+
49591+config GRKERNSEC_ROFS
49592+ bool "Runtime read-only mount protection"
49593+ help
49594+ If you say Y here, a sysctl option with name "romount_protect" will
49595+ be created. By setting this option to 1 at runtime, filesystems
49596+ will be protected in the following ways:
49597+ * No new writable mounts will be allowed
49598+ * Existing read-only mounts won't be able to be remounted read/write
49599+ * Write operations will be denied on all block devices
49600+ This option acts independently of grsec_lock: once it is set to 1,
49601+ it cannot be turned off. Therefore, please be mindful of the resulting
49602+ behavior if this option is enabled in an init script on a read-only
49603+ filesystem. This feature is mainly intended for secure embedded systems.
49604+
49605+config GRKERNSEC_CHROOT
49606+ bool "Chroot jail restrictions"
49607+ help
49608+ If you say Y here, you will be able to choose several options that will
49609+ make breaking out of a chrooted jail much more difficult. If you
49610+ encounter no software incompatibilities with the following options, it
49611+ is recommended that you enable each one.
49612+
49613+config GRKERNSEC_CHROOT_MOUNT
49614+ bool "Deny mounts"
49615+ depends on GRKERNSEC_CHROOT
49616+ help
49617+ If you say Y here, processes inside a chroot will not be able to
49618+ mount or remount filesystems. If the sysctl option is enabled, a
49619+ sysctl option with name "chroot_deny_mount" is created.
49620+
49621+config GRKERNSEC_CHROOT_DOUBLE
49622+ bool "Deny double-chroots"
49623+ depends on GRKERNSEC_CHROOT
49624+ help
49625+ If you say Y here, processes inside a chroot will not be able to chroot
49626+ again outside the chroot. This is a widely used method of breaking
49627+ out of a chroot jail and should not be allowed. If the sysctl
49628+ option is enabled, a sysctl option with name
49629+ "chroot_deny_chroot" is created.
49630+
49631+config GRKERNSEC_CHROOT_PIVOT
49632+ bool "Deny pivot_root in chroot"
49633+ depends on GRKERNSEC_CHROOT
49634+ help
49635+ If you say Y here, processes inside a chroot will not be able to use
49636+ a function called pivot_root() that was introduced in Linux 2.3.41. It
49637+ works similar to chroot in that it changes the root filesystem. This
49638+ function could be misused in a chrooted process to attempt to break out
49639+ of the chroot, and therefore should not be allowed. If the sysctl
49640+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
49641+ created.
49642+
49643+config GRKERNSEC_CHROOT_CHDIR
49644+ bool "Enforce chdir(\"/\") on all chroots"
49645+ depends on GRKERNSEC_CHROOT
49646+ help
49647+ If you say Y here, the current working directory of all newly-chrooted
49648+ applications will be set to the the root directory of the chroot.
49649+ The man page on chroot(2) states:
49650+ Note that this call does not change the current working
49651+ directory, so that `.' can be outside the tree rooted at
49652+ `/'. In particular, the super-user can escape from a
49653+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
49654+
49655+ It is recommended that you say Y here, since it's not known to break
49656+ any software. If the sysctl option is enabled, a sysctl option with
49657+ name "chroot_enforce_chdir" is created.
49658+
49659+config GRKERNSEC_CHROOT_CHMOD
49660+ bool "Deny (f)chmod +s"
49661+ depends on GRKERNSEC_CHROOT
49662+ help
49663+ If you say Y here, processes inside a chroot will not be able to chmod
49664+ or fchmod files to make them have suid or sgid bits. This protects
49665+ against another published method of breaking a chroot. If the sysctl
49666+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
49667+ created.
49668+
49669+config GRKERNSEC_CHROOT_FCHDIR
49670+ bool "Deny fchdir out of chroot"
49671+ depends on GRKERNSEC_CHROOT
49672+ help
49673+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
49674+ to a file descriptor of the chrooting process that points to a directory
49675+ outside the filesystem will be stopped. If the sysctl option
49676+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
49677+
49678+config GRKERNSEC_CHROOT_MKNOD
49679+ bool "Deny mknod"
49680+ depends on GRKERNSEC_CHROOT
49681+ help
49682+ If you say Y here, processes inside a chroot will not be allowed to
49683+ mknod. The problem with using mknod inside a chroot is that it
49684+ would allow an attacker to create a device entry that is the same
49685+ as one on the physical root of your system, which could range from
49686+ anything from the console device to a device for your harddrive (which
49687+ they could then use to wipe the drive or steal data). It is recommended
49688+ that you say Y here, unless you run into software incompatibilities.
49689+ If the sysctl option is enabled, a sysctl option with name
49690+ "chroot_deny_mknod" is created.
49691+
49692+config GRKERNSEC_CHROOT_SHMAT
49693+ bool "Deny shmat() out of chroot"
49694+ depends on GRKERNSEC_CHROOT
49695+ help
49696+ If you say Y here, processes inside a chroot will not be able to attach
49697+ to shared memory segments that were created outside of the chroot jail.
49698+ It is recommended that you say Y here. If the sysctl option is enabled,
49699+ a sysctl option with name "chroot_deny_shmat" is created.
49700+
49701+config GRKERNSEC_CHROOT_UNIX
49702+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
49703+ depends on GRKERNSEC_CHROOT
49704+ help
49705+ If you say Y here, processes inside a chroot will not be able to
49706+ connect to abstract (meaning not belonging to a filesystem) Unix
49707+ domain sockets that were bound outside of a chroot. It is recommended
49708+ that you say Y here. If the sysctl option is enabled, a sysctl option
49709+ with name "chroot_deny_unix" is created.
49710+
49711+config GRKERNSEC_CHROOT_FINDTASK
49712+ bool "Protect outside processes"
49713+ depends on GRKERNSEC_CHROOT
49714+ help
49715+ If you say Y here, processes inside a chroot will not be able to
49716+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
49717+ getsid, or view any process outside of the chroot. If the sysctl
49718+ option is enabled, a sysctl option with name "chroot_findtask" is
49719+ created.
49720+
49721+config GRKERNSEC_CHROOT_NICE
49722+ bool "Restrict priority changes"
49723+ depends on GRKERNSEC_CHROOT
49724+ help
49725+ If you say Y here, processes inside a chroot will not be able to raise
49726+ the priority of processes in the chroot, or alter the priority of
49727+ processes outside the chroot. This provides more security than simply
49728+ removing CAP_SYS_NICE from the process' capability set. If the
49729+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
49730+ is created.
49731+
49732+config GRKERNSEC_CHROOT_SYSCTL
49733+ bool "Deny sysctl writes"
49734+ depends on GRKERNSEC_CHROOT
49735+ help
49736+ If you say Y here, an attacker in a chroot will not be able to
49737+ write to sysctl entries, either by sysctl(2) or through a /proc
49738+ interface. It is strongly recommended that you say Y here. If the
49739+ sysctl option is enabled, a sysctl option with name
49740+ "chroot_deny_sysctl" is created.
49741+
49742+config GRKERNSEC_CHROOT_CAPS
49743+ bool "Capability restrictions"
49744+ depends on GRKERNSEC_CHROOT
49745+ help
49746+ If you say Y here, the capabilities on all processes within a
49747+ chroot jail will be lowered to stop module insertion, raw i/o,
49748+ system and net admin tasks, rebooting the system, modifying immutable
49749+ files, modifying IPC owned by another, and changing the system time.
49750+ This is left an option because it can break some apps. Disable this
49751+ if your chrooted apps are having problems performing those kinds of
49752+ tasks. If the sysctl option is enabled, a sysctl option with
49753+ name "chroot_caps" is created.
49754+
49755+endmenu
49756+menu "Kernel Auditing"
49757+depends on GRKERNSEC
49758+
49759+config GRKERNSEC_AUDIT_GROUP
49760+ bool "Single group for auditing"
49761+ help
49762+ If you say Y here, the exec, chdir, and (un)mount logging features
49763+ will only operate on a group you specify. This option is recommended
49764+ if you only want to watch certain users instead of having a large
49765+ amount of logs from the entire system. If the sysctl option is enabled,
49766+ a sysctl option with name "audit_group" is created.
49767+
49768+config GRKERNSEC_AUDIT_GID
49769+ int "GID for auditing"
49770+ depends on GRKERNSEC_AUDIT_GROUP
49771+ default 1007
49772+
49773+config GRKERNSEC_EXECLOG
49774+ bool "Exec logging"
49775+ help
49776+ If you say Y here, all execve() calls will be logged (since the
49777+ other exec*() calls are frontends to execve(), all execution
49778+ will be logged). Useful for shell-servers that like to keep track
49779+ of their users. If the sysctl option is enabled, a sysctl option with
49780+ name "exec_logging" is created.
49781+ WARNING: This option when enabled will produce a LOT of logs, especially
49782+ on an active system.
49783+
49784+config GRKERNSEC_RESLOG
49785+ bool "Resource logging"
49786+ help
49787+ If you say Y here, all attempts to overstep resource limits will
49788+ be logged with the resource name, the requested size, and the current
49789+ limit. It is highly recommended that you say Y here. If the sysctl
49790+ option is enabled, a sysctl option with name "resource_logging" is
49791+ created. If the RBAC system is enabled, the sysctl value is ignored.
49792+
49793+config GRKERNSEC_CHROOT_EXECLOG
49794+ bool "Log execs within chroot"
49795+ help
49796+ If you say Y here, all executions inside a chroot jail will be logged
49797+ to syslog. This can cause a large amount of logs if certain
49798+ applications (eg. djb's daemontools) are installed on the system, and
49799+ is therefore left as an option. If the sysctl option is enabled, a
49800+ sysctl option with name "chroot_execlog" is created.
49801+
49802+config GRKERNSEC_AUDIT_PTRACE
49803+ bool "Ptrace logging"
49804+ help
49805+ If you say Y here, all attempts to attach to a process via ptrace
49806+ will be logged. If the sysctl option is enabled, a sysctl option
49807+ with name "audit_ptrace" is created.
49808+
49809+config GRKERNSEC_AUDIT_CHDIR
49810+ bool "Chdir logging"
49811+ help
49812+ If you say Y here, all chdir() calls will be logged. If the sysctl
49813+ option is enabled, a sysctl option with name "audit_chdir" is created.
49814+
49815+config GRKERNSEC_AUDIT_MOUNT
49816+ bool "(Un)Mount logging"
49817+ help
49818+ If you say Y here, all mounts and unmounts will be logged. If the
49819+ sysctl option is enabled, a sysctl option with name "audit_mount" is
49820+ created.
49821+
49822+config GRKERNSEC_SIGNAL
49823+ bool "Signal logging"
49824+ help
49825+ If you say Y here, certain important signals will be logged, such as
49826+ SIGSEGV, which will as a result inform you of when a error in a program
49827+ occurred, which in some cases could mean a possible exploit attempt.
49828+ If the sysctl option is enabled, a sysctl option with name
49829+ "signal_logging" is created.
49830+
49831+config GRKERNSEC_FORKFAIL
49832+ bool "Fork failure logging"
49833+ help
49834+ If you say Y here, all failed fork() attempts will be logged.
49835+ This could suggest a fork bomb, or someone attempting to overstep
49836+ their process limit. If the sysctl option is enabled, a sysctl option
49837+ with name "forkfail_logging" is created.
49838+
49839+config GRKERNSEC_TIME
49840+ bool "Time change logging"
49841+ help
49842+ If you say Y here, any changes of the system clock will be logged.
49843+ If the sysctl option is enabled, a sysctl option with name
49844+ "timechange_logging" is created.
49845+
49846+config GRKERNSEC_PROC_IPADDR
49847+ bool "/proc/<pid>/ipaddr support"
49848+ help
49849+ If you say Y here, a new entry will be added to each /proc/<pid>
49850+ directory that contains the IP address of the person using the task.
49851+ The IP is carried across local TCP and AF_UNIX stream sockets.
49852+ This information can be useful for IDS/IPSes to perform remote response
49853+ to a local attack. The entry is readable by only the owner of the
49854+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
49855+ the RBAC system), and thus does not create privacy concerns.
49856+
49857+config GRKERNSEC_RWXMAP_LOG
49858+ bool 'Denied RWX mmap/mprotect logging'
49859+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
49860+ help
49861+ If you say Y here, calls to mmap() and mprotect() with explicit
49862+ usage of PROT_WRITE and PROT_EXEC together will be logged when
49863+ denied by the PAX_MPROTECT feature. If the sysctl option is
49864+ enabled, a sysctl option with name "rwxmap_logging" is created.
49865+
49866+config GRKERNSEC_AUDIT_TEXTREL
49867+ bool 'ELF text relocations logging (READ HELP)'
49868+ depends on PAX_MPROTECT
49869+ help
49870+ If you say Y here, text relocations will be logged with the filename
49871+ of the offending library or binary. The purpose of the feature is
49872+ to help Linux distribution developers get rid of libraries and
49873+ binaries that need text relocations which hinder the future progress
49874+ of PaX. Only Linux distribution developers should say Y here, and
49875+ never on a production machine, as this option creates an information
49876+ leak that could aid an attacker in defeating the randomization of
49877+ a single memory region. If the sysctl option is enabled, a sysctl
49878+ option with name "audit_textrel" is created.
49879+
49880+endmenu
49881+
49882+menu "Executable Protections"
49883+depends on GRKERNSEC
49884+
49885+config GRKERNSEC_DMESG
49886+ bool "Dmesg(8) restriction"
49887+ help
49888+ If you say Y here, non-root users will not be able to use dmesg(8)
49889+ to view up to the last 4kb of messages in the kernel's log buffer.
49890+ The kernel's log buffer often contains kernel addresses and other
49891+ identifying information useful to an attacker in fingerprinting a
49892+ system for a targeted exploit.
49893+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
49894+ created.
49895+
49896+config GRKERNSEC_HARDEN_PTRACE
49897+ bool "Deter ptrace-based process snooping"
49898+ help
49899+ If you say Y here, TTY sniffers and other malicious monitoring
49900+ programs implemented through ptrace will be defeated. If you
49901+ have been using the RBAC system, this option has already been
49902+ enabled for several years for all users, with the ability to make
49903+ fine-grained exceptions.
49904+
49905+ This option only affects the ability of non-root users to ptrace
49906+ processes that are not a descendent of the ptracing process.
49907+ This means that strace ./binary and gdb ./binary will still work,
49908+ but attaching to arbitrary processes will not. If the sysctl
49909+ option is enabled, a sysctl option with name "harden_ptrace" is
49910+ created.
49911+
49912+config GRKERNSEC_PTRACE_READEXEC
49913+ bool "Require read access to ptrace sensitive binaries"
49914+ help
49915+ If you say Y here, unprivileged users will not be able to ptrace unreadable
49916+ binaries. This option is useful in environments that
49917+ remove the read bits (e.g. file mode 4711) from suid binaries to
49918+ prevent infoleaking of their contents. This option adds
49919+ consistency to the use of that file mode, as the binary could normally
49920+ be read out when run without privileges while ptracing.
49921+
49922+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
49923+ is created.
49924+
49925+config GRKERNSEC_SETXID
49926+ bool "Enforce consistent multithreaded privileges"
49927+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
49928+ help
49929+ If you say Y here, a change from a root uid to a non-root uid
49930+ in a multithreaded application will cause the resulting uids,
49931+ gids, supplementary groups, and capabilities in that thread
49932+ to be propagated to the other threads of the process. In most
49933+ cases this is unnecessary, as glibc will emulate this behavior
49934+ on behalf of the application. Other libcs do not act in the
49935+ same way, allowing the other threads of the process to continue
49936+ running with root privileges. If the sysctl option is enabled,
49937+ a sysctl option with name "consistent_setxid" is created.
49938+
49939+config GRKERNSEC_TPE
49940+ bool "Trusted Path Execution (TPE)"
49941+ help
49942+ If you say Y here, you will be able to choose a gid to add to the
49943+ supplementary groups of users you want to mark as "untrusted."
49944+ These users will not be able to execute any files that are not in
49945+ root-owned directories writable only by root. If the sysctl option
49946+ is enabled, a sysctl option with name "tpe" is created.
49947+
49948+config GRKERNSEC_TPE_ALL
49949+ bool "Partially restrict all non-root users"
49950+ depends on GRKERNSEC_TPE
49951+ help
49952+ If you say Y here, all non-root users will be covered under
49953+ a weaker TPE restriction. This is separate from, and in addition to,
49954+ the main TPE options that you have selected elsewhere. Thus, if a
49955+ "trusted" GID is chosen, this restriction applies to even that GID.
49956+ Under this restriction, all non-root users will only be allowed to
49957+ execute files in directories they own that are not group or
49958+ world-writable, or in directories owned by root and writable only by
49959+ root. If the sysctl option is enabled, a sysctl option with name
49960+ "tpe_restrict_all" is created.
49961+
49962+config GRKERNSEC_TPE_INVERT
49963+ bool "Invert GID option"
49964+ depends on GRKERNSEC_TPE
49965+ help
49966+ If you say Y here, the group you specify in the TPE configuration will
49967+ decide what group TPE restrictions will be *disabled* for. This
49968+ option is useful if you want TPE restrictions to be applied to most
49969+ users on the system. If the sysctl option is enabled, a sysctl option
49970+ with name "tpe_invert" is created. Unlike other sysctl options, this
49971+ entry will default to on for backward-compatibility.
49972+
49973+config GRKERNSEC_TPE_GID
49974+ int "GID for untrusted users"
49975+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
49976+ default 1005
49977+ help
49978+ Setting this GID determines what group TPE restrictions will be
49979+ *enabled* for. If the sysctl option is enabled, a sysctl option
49980+ with name "tpe_gid" is created.
49981+
49982+config GRKERNSEC_TPE_GID
49983+ int "GID for trusted users"
49984+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
49985+ default 1005
49986+ help
49987+ Setting this GID determines what group TPE restrictions will be
49988+ *disabled* for. If the sysctl option is enabled, a sysctl option
49989+ with name "tpe_gid" is created.
49990+
49991+endmenu
49992+menu "Network Protections"
49993+depends on GRKERNSEC
49994+
49995+config GRKERNSEC_RANDNET
49996+ bool "Larger entropy pools"
49997+ help
49998+ If you say Y here, the entropy pools used for many features of Linux
49999+ and grsecurity will be doubled in size. Since several grsecurity
50000+ features use additional randomness, it is recommended that you say Y
50001+ here. Saying Y here has a similar effect as modifying
50002+ /proc/sys/kernel/random/poolsize.
50003+
50004+config GRKERNSEC_BLACKHOLE
50005+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
50006+ depends on NET
50007+ help
50008+ If you say Y here, neither TCP resets nor ICMP
50009+ destination-unreachable packets will be sent in response to packets
50010+ sent to ports for which no associated listening process exists.
50011+ This feature supports both IPV4 and IPV6 and exempts the
50012+ loopback interface from blackholing. Enabling this feature
50013+ makes a host more resilient to DoS attacks and reduces network
50014+ visibility against scanners.
50015+
50016+ The blackhole feature as-implemented is equivalent to the FreeBSD
50017+ blackhole feature, as it prevents RST responses to all packets, not
50018+ just SYNs. Under most application behavior this causes no
50019+ problems, but applications (like haproxy) may not close certain
50020+ connections in a way that cleanly terminates them on the remote
50021+ end, leaving the remote host in LAST_ACK state. Because of this
50022+ side-effect and to prevent intentional LAST_ACK DoSes, this
50023+ feature also adds automatic mitigation against such attacks.
50024+ The mitigation drastically reduces the amount of time a socket
50025+ can spend in LAST_ACK state. If you're using haproxy and not
50026+ all servers it connects to have this option enabled, consider
50027+ disabling this feature on the haproxy host.
50028+
50029+ If the sysctl option is enabled, two sysctl options with names
50030+ "ip_blackhole" and "lastack_retries" will be created.
50031+ While "ip_blackhole" takes the standard zero/non-zero on/off
50032+ toggle, "lastack_retries" uses the same kinds of values as
50033+ "tcp_retries1" and "tcp_retries2". The default value of 4
50034+ prevents a socket from lasting more than 45 seconds in LAST_ACK
50035+ state.
50036+
50037+config GRKERNSEC_SOCKET
50038+ bool "Socket restrictions"
50039+ depends on NET
50040+ help
50041+ If you say Y here, you will be able to choose from several options.
50042+ If you assign a GID on your system and add it to the supplementary
50043+ groups of users you want to restrict socket access to, this patch
50044+ will perform up to three things, based on the option(s) you choose.
50045+
50046+config GRKERNSEC_SOCKET_ALL
50047+ bool "Deny any sockets to group"
50048+ depends on GRKERNSEC_SOCKET
50049+ help
50050+ If you say Y here, you will be able to choose a GID of whose users will
50051+ be unable to connect to other hosts from your machine or run server
50052+ applications from your machine. If the sysctl option is enabled, a
50053+ sysctl option with name "socket_all" is created.
50054+
50055+config GRKERNSEC_SOCKET_ALL_GID
50056+ int "GID to deny all sockets for"
50057+ depends on GRKERNSEC_SOCKET_ALL
50058+ default 1004
50059+ help
50060+ Here you can choose the GID to disable socket access for. Remember to
50061+ add the users you want socket access disabled for to the GID
50062+ specified here. If the sysctl option is enabled, a sysctl option
50063+ with name "socket_all_gid" is created.
50064+
50065+config GRKERNSEC_SOCKET_CLIENT
50066+ bool "Deny client sockets to group"
50067+ depends on GRKERNSEC_SOCKET
50068+ help
50069+ If you say Y here, you will be able to choose a GID of whose users will
50070+ be unable to connect to other hosts from your machine, but will be
50071+ able to run servers. If this option is enabled, all users in the group
50072+ you specify will have to use passive mode when initiating ftp transfers
50073+ from the shell on your machine. If the sysctl option is enabled, a
50074+ sysctl option with name "socket_client" is created.
50075+
50076+config GRKERNSEC_SOCKET_CLIENT_GID
50077+ int "GID to deny client sockets for"
50078+ depends on GRKERNSEC_SOCKET_CLIENT
50079+ default 1003
50080+ help
50081+ Here you can choose the GID to disable client socket access for.
50082+ Remember to add the users you want client socket access disabled for to
50083+ the GID specified here. If the sysctl option is enabled, a sysctl
50084+ option with name "socket_client_gid" is created.
50085+
50086+config GRKERNSEC_SOCKET_SERVER
50087+ bool "Deny server sockets to group"
50088+ depends on GRKERNSEC_SOCKET
50089+ help
50090+ If you say Y here, you will be able to choose a GID of whose users will
50091+ be unable to run server applications from your machine. If the sysctl
50092+ option is enabled, a sysctl option with name "socket_server" is created.
50093+
50094+config GRKERNSEC_SOCKET_SERVER_GID
50095+ int "GID to deny server sockets for"
50096+ depends on GRKERNSEC_SOCKET_SERVER
50097+ default 1002
50098+ help
50099+ Here you can choose the GID to disable server socket access for.
50100+ Remember to add the users you want server socket access disabled for to
50101+ the GID specified here. If the sysctl option is enabled, a sysctl
50102+ option with name "socket_server_gid" is created.
50103+
50104+endmenu
50105+menu "Sysctl support"
50106+depends on GRKERNSEC && SYSCTL
50107+
50108+config GRKERNSEC_SYSCTL
50109+ bool "Sysctl support"
50110+ help
50111+ If you say Y here, you will be able to change the options that
50112+ grsecurity runs with at bootup, without having to recompile your
50113+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
50114+ to enable (1) or disable (0) various features. All the sysctl entries
50115+ are mutable until the "grsec_lock" entry is set to a non-zero value.
50116+ All features enabled in the kernel configuration are disabled at boot
50117+ if you do not say Y to the "Turn on features by default" option.
50118+ All options should be set at startup, and the grsec_lock entry should
50119+ be set to a non-zero value after all the options are set.
50120+ *THIS IS EXTREMELY IMPORTANT*
50121+
50122+config GRKERNSEC_SYSCTL_DISTRO
50123+ bool "Extra sysctl support for distro makers (READ HELP)"
50124+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
50125+ help
50126+ If you say Y here, additional sysctl options will be created
50127+ for features that affect processes running as root. Therefore,
50128+ it is critical when using this option that the grsec_lock entry be
50129+ enabled after boot. Only distros with prebuilt kernel packages
50130+ with this option enabled that can ensure grsec_lock is enabled
50131+ after boot should use this option.
50132+ *Failure to set grsec_lock after boot makes all grsec features
50133+ this option covers useless*
50134+
50135+ Currently this option creates the following sysctl entries:
50136+ "Disable Privileged I/O": "disable_priv_io"
50137+
50138+config GRKERNSEC_SYSCTL_ON
50139+ bool "Turn on features by default"
50140+ depends on GRKERNSEC_SYSCTL
50141+ help
50142+ If you say Y here, instead of having all features enabled in the
50143+ kernel configuration disabled at boot time, the features will be
50144+ enabled at boot time. It is recommended you say Y here unless
50145+ there is some reason you would want all sysctl-tunable features to
50146+ be disabled by default. As mentioned elsewhere, it is important
50147+ to enable the grsec_lock entry once you have finished modifying
50148+ the sysctl entries.
50149+
50150+endmenu
50151+menu "Logging Options"
50152+depends on GRKERNSEC
50153+
50154+config GRKERNSEC_FLOODTIME
50155+ int "Seconds in between log messages (minimum)"
50156+ default 10
50157+ help
50158+ This option allows you to enforce the number of seconds between
50159+ grsecurity log messages. The default should be suitable for most
50160+ people, however, if you choose to change it, choose a value small enough
50161+ to allow informative logs to be produced, but large enough to
50162+ prevent flooding.
50163+
50164+config GRKERNSEC_FLOODBURST
50165+ int "Number of messages in a burst (maximum)"
50166+ default 6
50167+ help
50168+ This option allows you to choose the maximum number of messages allowed
50169+ within the flood time interval you chose in a separate option. The
50170+ default should be suitable for most people, however if you find that
50171+ many of your logs are being interpreted as flooding, you may want to
50172+ raise this value.
50173+
50174+endmenu
50175+
50176+endmenu
50177diff --git a/grsecurity/Makefile b/grsecurity/Makefile
50178new file mode 100644
50179index 0000000..1b9afa9
50180--- /dev/null
50181+++ b/grsecurity/Makefile
50182@@ -0,0 +1,38 @@
50183+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
50184+# during 2001-2009 it has been completely redesigned by Brad Spengler
50185+# into an RBAC system
50186+#
50187+# All code in this directory and various hooks inserted throughout the kernel
50188+# are copyright Brad Spengler - Open Source Security, Inc., and released
50189+# under the GPL v2 or higher
50190+
50191+KBUILD_CFLAGS += -Werror
50192+
50193+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
50194+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
50195+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
50196+
50197+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
50198+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
50199+ gracl_learn.o grsec_log.o
50200+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
50201+
50202+ifdef CONFIG_NET
50203+obj-y += grsec_sock.o
50204+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
50205+endif
50206+
50207+ifndef CONFIG_GRKERNSEC
50208+obj-y += grsec_disabled.o
50209+endif
50210+
50211+ifdef CONFIG_GRKERNSEC_HIDESYM
50212+extra-y := grsec_hidesym.o
50213+$(obj)/grsec_hidesym.o:
50214+ @-chmod -f 500 /boot
50215+ @-chmod -f 500 /lib/modules
50216+ @-chmod -f 500 /lib64/modules
50217+ @-chmod -f 500 /lib32/modules
50218+ @-chmod -f 700 .
50219+ @echo ' grsec: protected kernel image paths'
50220+endif
50221diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
50222new file mode 100644
50223index 0000000..00b6c54
50224--- /dev/null
50225+++ b/grsecurity/gracl.c
50226@@ -0,0 +1,4012 @@
50227+#include <linux/kernel.h>
50228+#include <linux/module.h>
50229+#include <linux/sched.h>
50230+#include <linux/mm.h>
50231+#include <linux/file.h>
50232+#include <linux/fs.h>
50233+#include <linux/namei.h>
50234+#include <linux/mount.h>
50235+#include <linux/tty.h>
50236+#include <linux/proc_fs.h>
50237+#include <linux/lglock.h>
50238+#include <linux/slab.h>
50239+#include <linux/vmalloc.h>
50240+#include <linux/types.h>
50241+#include <linux/sysctl.h>
50242+#include <linux/netdevice.h>
50243+#include <linux/ptrace.h>
50244+#include <linux/gracl.h>
50245+#include <linux/gralloc.h>
50246+#include <linux/security.h>
50247+#include <linux/grinternal.h>
50248+#include <linux/pid_namespace.h>
50249+#include <linux/fdtable.h>
50250+#include <linux/percpu.h>
50251+#include "../fs/mount.h"
50252+
50253+#include <asm/uaccess.h>
50254+#include <asm/errno.h>
50255+#include <asm/mman.h>
50256+
50257+static struct acl_role_db acl_role_set;
50258+static struct name_db name_set;
50259+static struct inodev_db inodev_set;
50260+
50261+/* for keeping track of userspace pointers used for subjects, so we
50262+ can share references in the kernel as well
50263+*/
50264+
50265+static struct path real_root;
50266+
50267+static struct acl_subj_map_db subj_map_set;
50268+
50269+static struct acl_role_label *default_role;
50270+
50271+static struct acl_role_label *role_list;
50272+
50273+static u16 acl_sp_role_value;
50274+
50275+extern char *gr_shared_page[4];
50276+static DEFINE_MUTEX(gr_dev_mutex);
50277+DEFINE_RWLOCK(gr_inode_lock);
50278+
50279+struct gr_arg *gr_usermode;
50280+
50281+static unsigned int gr_status __read_only = GR_STATUS_INIT;
50282+
50283+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
50284+extern void gr_clear_learn_entries(void);
50285+
50286+#ifdef CONFIG_GRKERNSEC_RESLOG
50287+extern void gr_log_resource(const struct task_struct *task,
50288+ const int res, const unsigned long wanted, const int gt);
50289+#endif
50290+
50291+unsigned char *gr_system_salt;
50292+unsigned char *gr_system_sum;
50293+
50294+static struct sprole_pw **acl_special_roles = NULL;
50295+static __u16 num_sprole_pws = 0;
50296+
50297+static struct acl_role_label *kernel_role = NULL;
50298+
50299+static unsigned int gr_auth_attempts = 0;
50300+static unsigned long gr_auth_expires = 0UL;
50301+
50302+#ifdef CONFIG_NET
50303+extern struct vfsmount *sock_mnt;
50304+#endif
50305+
50306+extern struct vfsmount *pipe_mnt;
50307+extern struct vfsmount *shm_mnt;
50308+#ifdef CONFIG_HUGETLBFS
50309+extern struct vfsmount *hugetlbfs_vfsmount;
50310+#endif
50311+
50312+static struct acl_object_label *fakefs_obj_rw;
50313+static struct acl_object_label *fakefs_obj_rwx;
50314+
50315+extern int gr_init_uidset(void);
50316+extern void gr_free_uidset(void);
50317+extern void gr_remove_uid(uid_t uid);
50318+extern int gr_find_uid(uid_t uid);
50319+
50320+DECLARE_BRLOCK(vfsmount_lock);
50321+
50322+__inline__ int
50323+gr_acl_is_enabled(void)
50324+{
50325+ return (gr_status & GR_READY);
50326+}
50327+
50328+#ifdef CONFIG_BTRFS_FS
50329+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
50330+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
50331+#endif
50332+
50333+static inline dev_t __get_dev(const struct dentry *dentry)
50334+{
50335+#ifdef CONFIG_BTRFS_FS
50336+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
50337+ return get_btrfs_dev_from_inode(dentry->d_inode);
50338+ else
50339+#endif
50340+ return dentry->d_inode->i_sb->s_dev;
50341+}
50342+
50343+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
50344+{
50345+ return __get_dev(dentry);
50346+}
50347+
50348+static char gr_task_roletype_to_char(struct task_struct *task)
50349+{
50350+ switch (task->role->roletype &
50351+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
50352+ GR_ROLE_SPECIAL)) {
50353+ case GR_ROLE_DEFAULT:
50354+ return 'D';
50355+ case GR_ROLE_USER:
50356+ return 'U';
50357+ case GR_ROLE_GROUP:
50358+ return 'G';
50359+ case GR_ROLE_SPECIAL:
50360+ return 'S';
50361+ }
50362+
50363+ return 'X';
50364+}
50365+
50366+char gr_roletype_to_char(void)
50367+{
50368+ return gr_task_roletype_to_char(current);
50369+}
50370+
50371+__inline__ int
50372+gr_acl_tpe_check(void)
50373+{
50374+ if (unlikely(!(gr_status & GR_READY)))
50375+ return 0;
50376+ if (current->role->roletype & GR_ROLE_TPE)
50377+ return 1;
50378+ else
50379+ return 0;
50380+}
50381+
50382+int
50383+gr_handle_rawio(const struct inode *inode)
50384+{
50385+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
50386+ if (inode && S_ISBLK(inode->i_mode) &&
50387+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
50388+ !capable(CAP_SYS_RAWIO))
50389+ return 1;
50390+#endif
50391+ return 0;
50392+}
50393+
50394+static int
50395+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
50396+{
50397+ if (likely(lena != lenb))
50398+ return 0;
50399+
50400+ return !memcmp(a, b, lena);
50401+}
50402+
50403+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
50404+{
50405+ *buflen -= namelen;
50406+ if (*buflen < 0)
50407+ return -ENAMETOOLONG;
50408+ *buffer -= namelen;
50409+ memcpy(*buffer, str, namelen);
50410+ return 0;
50411+}
50412+
50413+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
50414+{
50415+ return prepend(buffer, buflen, name->name, name->len);
50416+}
50417+
50418+static int prepend_path(const struct path *path, struct path *root,
50419+ char **buffer, int *buflen)
50420+{
50421+ struct dentry *dentry = path->dentry;
50422+ struct vfsmount *vfsmnt = path->mnt;
50423+ struct mount *mnt = real_mount(vfsmnt);
50424+ bool slash = false;
50425+ int error = 0;
50426+
50427+ while (dentry != root->dentry || vfsmnt != root->mnt) {
50428+ struct dentry * parent;
50429+
50430+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
50431+ /* Global root? */
50432+ if (!mnt_has_parent(mnt)) {
50433+ goto out;
50434+ }
50435+ dentry = mnt->mnt_mountpoint;
50436+ mnt = mnt->mnt_parent;
50437+ vfsmnt = &mnt->mnt;
50438+ continue;
50439+ }
50440+ parent = dentry->d_parent;
50441+ prefetch(parent);
50442+ spin_lock(&dentry->d_lock);
50443+ error = prepend_name(buffer, buflen, &dentry->d_name);
50444+ spin_unlock(&dentry->d_lock);
50445+ if (!error)
50446+ error = prepend(buffer, buflen, "/", 1);
50447+ if (error)
50448+ break;
50449+
50450+ slash = true;
50451+ dentry = parent;
50452+ }
50453+
50454+out:
50455+ if (!error && !slash)
50456+ error = prepend(buffer, buflen, "/", 1);
50457+
50458+ return error;
50459+}
50460+
50461+/* this must be called with vfsmount_lock and rename_lock held */
50462+
50463+static char *__our_d_path(const struct path *path, struct path *root,
50464+ char *buf, int buflen)
50465+{
50466+ char *res = buf + buflen;
50467+ int error;
50468+
50469+ prepend(&res, &buflen, "\0", 1);
50470+ error = prepend_path(path, root, &res, &buflen);
50471+ if (error)
50472+ return ERR_PTR(error);
50473+
50474+ return res;
50475+}
50476+
50477+static char *
50478+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
50479+{
50480+ char *retval;
50481+
50482+ retval = __our_d_path(path, root, buf, buflen);
50483+ if (unlikely(IS_ERR(retval)))
50484+ retval = strcpy(buf, "<path too long>");
50485+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
50486+ retval[1] = '\0';
50487+
50488+ return retval;
50489+}
50490+
50491+static char *
50492+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50493+ char *buf, int buflen)
50494+{
50495+ struct path path;
50496+ char *res;
50497+
50498+ path.dentry = (struct dentry *)dentry;
50499+ path.mnt = (struct vfsmount *)vfsmnt;
50500+
50501+ /* we can use real_root.dentry, real_root.mnt, because this is only called
50502+ by the RBAC system */
50503+ res = gen_full_path(&path, &real_root, buf, buflen);
50504+
50505+ return res;
50506+}
50507+
50508+static char *
50509+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50510+ char *buf, int buflen)
50511+{
50512+ char *res;
50513+ struct path path;
50514+ struct path root;
50515+ struct task_struct *reaper = init_pid_ns.child_reaper;
50516+
50517+ path.dentry = (struct dentry *)dentry;
50518+ path.mnt = (struct vfsmount *)vfsmnt;
50519+
50520+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
50521+ get_fs_root(reaper->fs, &root);
50522+
50523+ write_seqlock(&rename_lock);
50524+ br_read_lock(vfsmount_lock);
50525+ res = gen_full_path(&path, &root, buf, buflen);
50526+ br_read_unlock(vfsmount_lock);
50527+ write_sequnlock(&rename_lock);
50528+
50529+ path_put(&root);
50530+ return res;
50531+}
50532+
50533+static char *
50534+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50535+{
50536+ char *ret;
50537+ write_seqlock(&rename_lock);
50538+ br_read_lock(vfsmount_lock);
50539+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50540+ PAGE_SIZE);
50541+ br_read_unlock(vfsmount_lock);
50542+ write_sequnlock(&rename_lock);
50543+ return ret;
50544+}
50545+
50546+static char *
50547+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50548+{
50549+ char *ret;
50550+ char *buf;
50551+ int buflen;
50552+
50553+ write_seqlock(&rename_lock);
50554+ br_read_lock(vfsmount_lock);
50555+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
50556+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
50557+ buflen = (int)(ret - buf);
50558+ if (buflen >= 5)
50559+ prepend(&ret, &buflen, "/proc", 5);
50560+ else
50561+ ret = strcpy(buf, "<path too long>");
50562+ br_read_unlock(vfsmount_lock);
50563+ write_sequnlock(&rename_lock);
50564+ return ret;
50565+}
50566+
50567+char *
50568+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
50569+{
50570+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50571+ PAGE_SIZE);
50572+}
50573+
50574+char *
50575+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
50576+{
50577+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
50578+ PAGE_SIZE);
50579+}
50580+
50581+char *
50582+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
50583+{
50584+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
50585+ PAGE_SIZE);
50586+}
50587+
50588+char *
50589+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
50590+{
50591+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
50592+ PAGE_SIZE);
50593+}
50594+
50595+char *
50596+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
50597+{
50598+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
50599+ PAGE_SIZE);
50600+}
50601+
50602+__inline__ __u32
50603+to_gr_audit(const __u32 reqmode)
50604+{
50605+ /* masks off auditable permission flags, then shifts them to create
50606+ auditing flags, and adds the special case of append auditing if
50607+ we're requesting write */
50608+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
50609+}
50610+
50611+struct acl_subject_label *
50612+lookup_subject_map(const struct acl_subject_label *userp)
50613+{
50614+ unsigned int index = shash(userp, subj_map_set.s_size);
50615+ struct subject_map *match;
50616+
50617+ match = subj_map_set.s_hash[index];
50618+
50619+ while (match && match->user != userp)
50620+ match = match->next;
50621+
50622+ if (match != NULL)
50623+ return match->kernel;
50624+ else
50625+ return NULL;
50626+}
50627+
50628+static void
50629+insert_subj_map_entry(struct subject_map *subjmap)
50630+{
50631+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
50632+ struct subject_map **curr;
50633+
50634+ subjmap->prev = NULL;
50635+
50636+ curr = &subj_map_set.s_hash[index];
50637+ if (*curr != NULL)
50638+ (*curr)->prev = subjmap;
50639+
50640+ subjmap->next = *curr;
50641+ *curr = subjmap;
50642+
50643+ return;
50644+}
50645+
50646+static struct acl_role_label *
50647+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
50648+ const gid_t gid)
50649+{
50650+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
50651+ struct acl_role_label *match;
50652+ struct role_allowed_ip *ipp;
50653+ unsigned int x;
50654+ u32 curr_ip = task->signal->curr_ip;
50655+
50656+ task->signal->saved_ip = curr_ip;
50657+
50658+ match = acl_role_set.r_hash[index];
50659+
50660+ while (match) {
50661+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
50662+ for (x = 0; x < match->domain_child_num; x++) {
50663+ if (match->domain_children[x] == uid)
50664+ goto found;
50665+ }
50666+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
50667+ break;
50668+ match = match->next;
50669+ }
50670+found:
50671+ if (match == NULL) {
50672+ try_group:
50673+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
50674+ match = acl_role_set.r_hash[index];
50675+
50676+ while (match) {
50677+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
50678+ for (x = 0; x < match->domain_child_num; x++) {
50679+ if (match->domain_children[x] == gid)
50680+ goto found2;
50681+ }
50682+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
50683+ break;
50684+ match = match->next;
50685+ }
50686+found2:
50687+ if (match == NULL)
50688+ match = default_role;
50689+ if (match->allowed_ips == NULL)
50690+ return match;
50691+ else {
50692+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
50693+ if (likely
50694+ ((ntohl(curr_ip) & ipp->netmask) ==
50695+ (ntohl(ipp->addr) & ipp->netmask)))
50696+ return match;
50697+ }
50698+ match = default_role;
50699+ }
50700+ } else if (match->allowed_ips == NULL) {
50701+ return match;
50702+ } else {
50703+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
50704+ if (likely
50705+ ((ntohl(curr_ip) & ipp->netmask) ==
50706+ (ntohl(ipp->addr) & ipp->netmask)))
50707+ return match;
50708+ }
50709+ goto try_group;
50710+ }
50711+
50712+ return match;
50713+}
50714+
50715+struct acl_subject_label *
50716+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
50717+ const struct acl_role_label *role)
50718+{
50719+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
50720+ struct acl_subject_label *match;
50721+
50722+ match = role->subj_hash[index];
50723+
50724+ while (match && (match->inode != ino || match->device != dev ||
50725+ (match->mode & GR_DELETED))) {
50726+ match = match->next;
50727+ }
50728+
50729+ if (match && !(match->mode & GR_DELETED))
50730+ return match;
50731+ else
50732+ return NULL;
50733+}
50734+
50735+struct acl_subject_label *
50736+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
50737+ const struct acl_role_label *role)
50738+{
50739+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
50740+ struct acl_subject_label *match;
50741+
50742+ match = role->subj_hash[index];
50743+
50744+ while (match && (match->inode != ino || match->device != dev ||
50745+ !(match->mode & GR_DELETED))) {
50746+ match = match->next;
50747+ }
50748+
50749+ if (match && (match->mode & GR_DELETED))
50750+ return match;
50751+ else
50752+ return NULL;
50753+}
50754+
50755+static struct acl_object_label *
50756+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
50757+ const struct acl_subject_label *subj)
50758+{
50759+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
50760+ struct acl_object_label *match;
50761+
50762+ match = subj->obj_hash[index];
50763+
50764+ while (match && (match->inode != ino || match->device != dev ||
50765+ (match->mode & GR_DELETED))) {
50766+ match = match->next;
50767+ }
50768+
50769+ if (match && !(match->mode & GR_DELETED))
50770+ return match;
50771+ else
50772+ return NULL;
50773+}
50774+
50775+static struct acl_object_label *
50776+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
50777+ const struct acl_subject_label *subj)
50778+{
50779+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
50780+ struct acl_object_label *match;
50781+
50782+ match = subj->obj_hash[index];
50783+
50784+ while (match && (match->inode != ino || match->device != dev ||
50785+ !(match->mode & GR_DELETED))) {
50786+ match = match->next;
50787+ }
50788+
50789+ if (match && (match->mode & GR_DELETED))
50790+ return match;
50791+
50792+ match = subj->obj_hash[index];
50793+
50794+ while (match && (match->inode != ino || match->device != dev ||
50795+ (match->mode & GR_DELETED))) {
50796+ match = match->next;
50797+ }
50798+
50799+ if (match && !(match->mode & GR_DELETED))
50800+ return match;
50801+ else
50802+ return NULL;
50803+}
50804+
50805+static struct name_entry *
50806+lookup_name_entry(const char *name)
50807+{
50808+ unsigned int len = strlen(name);
50809+ unsigned int key = full_name_hash(name, len);
50810+ unsigned int index = key % name_set.n_size;
50811+ struct name_entry *match;
50812+
50813+ match = name_set.n_hash[index];
50814+
50815+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
50816+ match = match->next;
50817+
50818+ return match;
50819+}
50820+
50821+static struct name_entry *
50822+lookup_name_entry_create(const char *name)
50823+{
50824+ unsigned int len = strlen(name);
50825+ unsigned int key = full_name_hash(name, len);
50826+ unsigned int index = key % name_set.n_size;
50827+ struct name_entry *match;
50828+
50829+ match = name_set.n_hash[index];
50830+
50831+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
50832+ !match->deleted))
50833+ match = match->next;
50834+
50835+ if (match && match->deleted)
50836+ return match;
50837+
50838+ match = name_set.n_hash[index];
50839+
50840+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
50841+ match->deleted))
50842+ match = match->next;
50843+
50844+ if (match && !match->deleted)
50845+ return match;
50846+ else
50847+ return NULL;
50848+}
50849+
50850+static struct inodev_entry *
50851+lookup_inodev_entry(const ino_t ino, const dev_t dev)
50852+{
50853+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
50854+ struct inodev_entry *match;
50855+
50856+ match = inodev_set.i_hash[index];
50857+
50858+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
50859+ match = match->next;
50860+
50861+ return match;
50862+}
50863+
50864+static void
50865+insert_inodev_entry(struct inodev_entry *entry)
50866+{
50867+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
50868+ inodev_set.i_size);
50869+ struct inodev_entry **curr;
50870+
50871+ entry->prev = NULL;
50872+
50873+ curr = &inodev_set.i_hash[index];
50874+ if (*curr != NULL)
50875+ (*curr)->prev = entry;
50876+
50877+ entry->next = *curr;
50878+ *curr = entry;
50879+
50880+ return;
50881+}
50882+
50883+static void
50884+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
50885+{
50886+ unsigned int index =
50887+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
50888+ struct acl_role_label **curr;
50889+ struct acl_role_label *tmp, *tmp2;
50890+
50891+ curr = &acl_role_set.r_hash[index];
50892+
50893+ /* simple case, slot is empty, just set it to our role */
50894+ if (*curr == NULL) {
50895+ *curr = role;
50896+ } else {
50897+ /* example:
50898+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
50899+ 2 -> 3
50900+ */
50901+ /* first check to see if we can already be reached via this slot */
50902+ tmp = *curr;
50903+ while (tmp && tmp != role)
50904+ tmp = tmp->next;
50905+ if (tmp == role) {
50906+ /* we don't need to add ourselves to this slot's chain */
50907+ return;
50908+ }
50909+ /* we need to add ourselves to this chain, two cases */
50910+ if (role->next == NULL) {
50911+ /* simple case, append the current chain to our role */
50912+ role->next = *curr;
50913+ *curr = role;
50914+ } else {
50915+ /* 1 -> 2 -> 3 -> 4
50916+ 2 -> 3 -> 4
50917+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
50918+ */
50919+ /* trickier case: walk our role's chain until we find
50920+ the role for the start of the current slot's chain */
50921+ tmp = role;
50922+ tmp2 = *curr;
50923+ while (tmp->next && tmp->next != tmp2)
50924+ tmp = tmp->next;
50925+ if (tmp->next == tmp2) {
50926+ /* from example above, we found 3, so just
50927+ replace this slot's chain with ours */
50928+ *curr = role;
50929+ } else {
50930+ /* we didn't find a subset of our role's chain
50931+ in the current slot's chain, so append their
50932+ chain to ours, and set us as the first role in
50933+ the slot's chain
50934+
50935+ we could fold this case with the case above,
50936+ but making it explicit for clarity
50937+ */
50938+ tmp->next = tmp2;
50939+ *curr = role;
50940+ }
50941+ }
50942+ }
50943+
50944+ return;
50945+}
50946+
50947+static void
50948+insert_acl_role_label(struct acl_role_label *role)
50949+{
50950+ int i;
50951+
50952+ if (role_list == NULL) {
50953+ role_list = role;
50954+ role->prev = NULL;
50955+ } else {
50956+ role->prev = role_list;
50957+ role_list = role;
50958+ }
50959+
50960+ /* used for hash chains */
50961+ role->next = NULL;
50962+
50963+ if (role->roletype & GR_ROLE_DOMAIN) {
50964+ for (i = 0; i < role->domain_child_num; i++)
50965+ __insert_acl_role_label(role, role->domain_children[i]);
50966+ } else
50967+ __insert_acl_role_label(role, role->uidgid);
50968+}
50969+
50970+static int
50971+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
50972+{
50973+ struct name_entry **curr, *nentry;
50974+ struct inodev_entry *ientry;
50975+ unsigned int len = strlen(name);
50976+ unsigned int key = full_name_hash(name, len);
50977+ unsigned int index = key % name_set.n_size;
50978+
50979+ curr = &name_set.n_hash[index];
50980+
50981+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
50982+ curr = &((*curr)->next);
50983+
50984+ if (*curr != NULL)
50985+ return 1;
50986+
50987+ nentry = acl_alloc(sizeof (struct name_entry));
50988+ if (nentry == NULL)
50989+ return 0;
50990+ ientry = acl_alloc(sizeof (struct inodev_entry));
50991+ if (ientry == NULL)
50992+ return 0;
50993+ ientry->nentry = nentry;
50994+
50995+ nentry->key = key;
50996+ nentry->name = name;
50997+ nentry->inode = inode;
50998+ nentry->device = device;
50999+ nentry->len = len;
51000+ nentry->deleted = deleted;
51001+
51002+ nentry->prev = NULL;
51003+ curr = &name_set.n_hash[index];
51004+ if (*curr != NULL)
51005+ (*curr)->prev = nentry;
51006+ nentry->next = *curr;
51007+ *curr = nentry;
51008+
51009+ /* insert us into the table searchable by inode/dev */
51010+ insert_inodev_entry(ientry);
51011+
51012+ return 1;
51013+}
51014+
51015+static void
51016+insert_acl_obj_label(struct acl_object_label *obj,
51017+ struct acl_subject_label *subj)
51018+{
51019+ unsigned int index =
51020+ fhash(obj->inode, obj->device, subj->obj_hash_size);
51021+ struct acl_object_label **curr;
51022+
51023+
51024+ obj->prev = NULL;
51025+
51026+ curr = &subj->obj_hash[index];
51027+ if (*curr != NULL)
51028+ (*curr)->prev = obj;
51029+
51030+ obj->next = *curr;
51031+ *curr = obj;
51032+
51033+ return;
51034+}
51035+
51036+static void
51037+insert_acl_subj_label(struct acl_subject_label *obj,
51038+ struct acl_role_label *role)
51039+{
51040+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
51041+ struct acl_subject_label **curr;
51042+
51043+ obj->prev = NULL;
51044+
51045+ curr = &role->subj_hash[index];
51046+ if (*curr != NULL)
51047+ (*curr)->prev = obj;
51048+
51049+ obj->next = *curr;
51050+ *curr = obj;
51051+
51052+ return;
51053+}
51054+
51055+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
51056+
51057+static void *
51058+create_table(__u32 * len, int elementsize)
51059+{
51060+ unsigned int table_sizes[] = {
51061+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
51062+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
51063+ 4194301, 8388593, 16777213, 33554393, 67108859
51064+ };
51065+ void *newtable = NULL;
51066+ unsigned int pwr = 0;
51067+
51068+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
51069+ table_sizes[pwr] <= *len)
51070+ pwr++;
51071+
51072+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
51073+ return newtable;
51074+
51075+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
51076+ newtable =
51077+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
51078+ else
51079+ newtable = vmalloc(table_sizes[pwr] * elementsize);
51080+
51081+ *len = table_sizes[pwr];
51082+
51083+ return newtable;
51084+}
51085+
51086+static int
51087+init_variables(const struct gr_arg *arg)
51088+{
51089+ struct task_struct *reaper = init_pid_ns.child_reaper;
51090+ unsigned int stacksize;
51091+
51092+ subj_map_set.s_size = arg->role_db.num_subjects;
51093+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
51094+ name_set.n_size = arg->role_db.num_objects;
51095+ inodev_set.i_size = arg->role_db.num_objects;
51096+
51097+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
51098+ !name_set.n_size || !inodev_set.i_size)
51099+ return 1;
51100+
51101+ if (!gr_init_uidset())
51102+ return 1;
51103+
51104+ /* set up the stack that holds allocation info */
51105+
51106+ stacksize = arg->role_db.num_pointers + 5;
51107+
51108+ if (!acl_alloc_stack_init(stacksize))
51109+ return 1;
51110+
51111+ /* grab reference for the real root dentry and vfsmount */
51112+ get_fs_root(reaper->fs, &real_root);
51113+
51114+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51115+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
51116+#endif
51117+
51118+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
51119+ if (fakefs_obj_rw == NULL)
51120+ return 1;
51121+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
51122+
51123+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
51124+ if (fakefs_obj_rwx == NULL)
51125+ return 1;
51126+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
51127+
51128+ subj_map_set.s_hash =
51129+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
51130+ acl_role_set.r_hash =
51131+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
51132+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
51133+ inodev_set.i_hash =
51134+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
51135+
51136+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
51137+ !name_set.n_hash || !inodev_set.i_hash)
51138+ return 1;
51139+
51140+ memset(subj_map_set.s_hash, 0,
51141+ sizeof(struct subject_map *) * subj_map_set.s_size);
51142+ memset(acl_role_set.r_hash, 0,
51143+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
51144+ memset(name_set.n_hash, 0,
51145+ sizeof (struct name_entry *) * name_set.n_size);
51146+ memset(inodev_set.i_hash, 0,
51147+ sizeof (struct inodev_entry *) * inodev_set.i_size);
51148+
51149+ return 0;
51150+}
51151+
51152+/* free information not needed after startup
51153+ currently contains user->kernel pointer mappings for subjects
51154+*/
51155+
51156+static void
51157+free_init_variables(void)
51158+{
51159+ __u32 i;
51160+
51161+ if (subj_map_set.s_hash) {
51162+ for (i = 0; i < subj_map_set.s_size; i++) {
51163+ if (subj_map_set.s_hash[i]) {
51164+ kfree(subj_map_set.s_hash[i]);
51165+ subj_map_set.s_hash[i] = NULL;
51166+ }
51167+ }
51168+
51169+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
51170+ PAGE_SIZE)
51171+ kfree(subj_map_set.s_hash);
51172+ else
51173+ vfree(subj_map_set.s_hash);
51174+ }
51175+
51176+ return;
51177+}
51178+
51179+static void
51180+free_variables(void)
51181+{
51182+ struct acl_subject_label *s;
51183+ struct acl_role_label *r;
51184+ struct task_struct *task, *task2;
51185+ unsigned int x;
51186+
51187+ gr_clear_learn_entries();
51188+
51189+ read_lock(&tasklist_lock);
51190+ do_each_thread(task2, task) {
51191+ task->acl_sp_role = 0;
51192+ task->acl_role_id = 0;
51193+ task->acl = NULL;
51194+ task->role = NULL;
51195+ } while_each_thread(task2, task);
51196+ read_unlock(&tasklist_lock);
51197+
51198+ /* release the reference to the real root dentry and vfsmount */
51199+ path_put(&real_root);
51200+ memset(&real_root, 0, sizeof(real_root));
51201+
51202+ /* free all object hash tables */
51203+
51204+ FOR_EACH_ROLE_START(r)
51205+ if (r->subj_hash == NULL)
51206+ goto next_role;
51207+ FOR_EACH_SUBJECT_START(r, s, x)
51208+ if (s->obj_hash == NULL)
51209+ break;
51210+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51211+ kfree(s->obj_hash);
51212+ else
51213+ vfree(s->obj_hash);
51214+ FOR_EACH_SUBJECT_END(s, x)
51215+ FOR_EACH_NESTED_SUBJECT_START(r, s)
51216+ if (s->obj_hash == NULL)
51217+ break;
51218+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51219+ kfree(s->obj_hash);
51220+ else
51221+ vfree(s->obj_hash);
51222+ FOR_EACH_NESTED_SUBJECT_END(s)
51223+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
51224+ kfree(r->subj_hash);
51225+ else
51226+ vfree(r->subj_hash);
51227+ r->subj_hash = NULL;
51228+next_role:
51229+ FOR_EACH_ROLE_END(r)
51230+
51231+ acl_free_all();
51232+
51233+ if (acl_role_set.r_hash) {
51234+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
51235+ PAGE_SIZE)
51236+ kfree(acl_role_set.r_hash);
51237+ else
51238+ vfree(acl_role_set.r_hash);
51239+ }
51240+ if (name_set.n_hash) {
51241+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
51242+ PAGE_SIZE)
51243+ kfree(name_set.n_hash);
51244+ else
51245+ vfree(name_set.n_hash);
51246+ }
51247+
51248+ if (inodev_set.i_hash) {
51249+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
51250+ PAGE_SIZE)
51251+ kfree(inodev_set.i_hash);
51252+ else
51253+ vfree(inodev_set.i_hash);
51254+ }
51255+
51256+ gr_free_uidset();
51257+
51258+ memset(&name_set, 0, sizeof (struct name_db));
51259+ memset(&inodev_set, 0, sizeof (struct inodev_db));
51260+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
51261+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
51262+
51263+ default_role = NULL;
51264+ kernel_role = NULL;
51265+ role_list = NULL;
51266+
51267+ return;
51268+}
51269+
51270+static __u32
51271+count_user_objs(struct acl_object_label *userp)
51272+{
51273+ struct acl_object_label o_tmp;
51274+ __u32 num = 0;
51275+
51276+ while (userp) {
51277+ if (copy_from_user(&o_tmp, userp,
51278+ sizeof (struct acl_object_label)))
51279+ break;
51280+
51281+ userp = o_tmp.prev;
51282+ num++;
51283+ }
51284+
51285+ return num;
51286+}
51287+
51288+static struct acl_subject_label *
51289+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
51290+
51291+static int
51292+copy_user_glob(struct acl_object_label *obj)
51293+{
51294+ struct acl_object_label *g_tmp, **guser;
51295+ unsigned int len;
51296+ char *tmp;
51297+
51298+ if (obj->globbed == NULL)
51299+ return 0;
51300+
51301+ guser = &obj->globbed;
51302+ while (*guser) {
51303+ g_tmp = (struct acl_object_label *)
51304+ acl_alloc(sizeof (struct acl_object_label));
51305+ if (g_tmp == NULL)
51306+ return -ENOMEM;
51307+
51308+ if (copy_from_user(g_tmp, *guser,
51309+ sizeof (struct acl_object_label)))
51310+ return -EFAULT;
51311+
51312+ len = strnlen_user(g_tmp->filename, PATH_MAX);
51313+
51314+ if (!len || len >= PATH_MAX)
51315+ return -EINVAL;
51316+
51317+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51318+ return -ENOMEM;
51319+
51320+ if (copy_from_user(tmp, g_tmp->filename, len))
51321+ return -EFAULT;
51322+ tmp[len-1] = '\0';
51323+ g_tmp->filename = tmp;
51324+
51325+ *guser = g_tmp;
51326+ guser = &(g_tmp->next);
51327+ }
51328+
51329+ return 0;
51330+}
51331+
51332+static int
51333+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
51334+ struct acl_role_label *role)
51335+{
51336+ struct acl_object_label *o_tmp;
51337+ unsigned int len;
51338+ int ret;
51339+ char *tmp;
51340+
51341+ while (userp) {
51342+ if ((o_tmp = (struct acl_object_label *)
51343+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
51344+ return -ENOMEM;
51345+
51346+ if (copy_from_user(o_tmp, userp,
51347+ sizeof (struct acl_object_label)))
51348+ return -EFAULT;
51349+
51350+ userp = o_tmp->prev;
51351+
51352+ len = strnlen_user(o_tmp->filename, PATH_MAX);
51353+
51354+ if (!len || len >= PATH_MAX)
51355+ return -EINVAL;
51356+
51357+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51358+ return -ENOMEM;
51359+
51360+ if (copy_from_user(tmp, o_tmp->filename, len))
51361+ return -EFAULT;
51362+ tmp[len-1] = '\0';
51363+ o_tmp->filename = tmp;
51364+
51365+ insert_acl_obj_label(o_tmp, subj);
51366+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
51367+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
51368+ return -ENOMEM;
51369+
51370+ ret = copy_user_glob(o_tmp);
51371+ if (ret)
51372+ return ret;
51373+
51374+ if (o_tmp->nested) {
51375+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
51376+ if (IS_ERR(o_tmp->nested))
51377+ return PTR_ERR(o_tmp->nested);
51378+
51379+ /* insert into nested subject list */
51380+ o_tmp->nested->next = role->hash->first;
51381+ role->hash->first = o_tmp->nested;
51382+ }
51383+ }
51384+
51385+ return 0;
51386+}
51387+
51388+static __u32
51389+count_user_subjs(struct acl_subject_label *userp)
51390+{
51391+ struct acl_subject_label s_tmp;
51392+ __u32 num = 0;
51393+
51394+ while (userp) {
51395+ if (copy_from_user(&s_tmp, userp,
51396+ sizeof (struct acl_subject_label)))
51397+ break;
51398+
51399+ userp = s_tmp.prev;
51400+ /* do not count nested subjects against this count, since
51401+ they are not included in the hash table, but are
51402+ attached to objects. We have already counted
51403+ the subjects in userspace for the allocation
51404+ stack
51405+ */
51406+ if (!(s_tmp.mode & GR_NESTED))
51407+ num++;
51408+ }
51409+
51410+ return num;
51411+}
51412+
51413+static int
51414+copy_user_allowedips(struct acl_role_label *rolep)
51415+{
51416+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
51417+
51418+ ruserip = rolep->allowed_ips;
51419+
51420+ while (ruserip) {
51421+ rlast = rtmp;
51422+
51423+ if ((rtmp = (struct role_allowed_ip *)
51424+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
51425+ return -ENOMEM;
51426+
51427+ if (copy_from_user(rtmp, ruserip,
51428+ sizeof (struct role_allowed_ip)))
51429+ return -EFAULT;
51430+
51431+ ruserip = rtmp->prev;
51432+
51433+ if (!rlast) {
51434+ rtmp->prev = NULL;
51435+ rolep->allowed_ips = rtmp;
51436+ } else {
51437+ rlast->next = rtmp;
51438+ rtmp->prev = rlast;
51439+ }
51440+
51441+ if (!ruserip)
51442+ rtmp->next = NULL;
51443+ }
51444+
51445+ return 0;
51446+}
51447+
51448+static int
51449+copy_user_transitions(struct acl_role_label *rolep)
51450+{
51451+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
51452+
51453+ unsigned int len;
51454+ char *tmp;
51455+
51456+ rusertp = rolep->transitions;
51457+
51458+ while (rusertp) {
51459+ rlast = rtmp;
51460+
51461+ if ((rtmp = (struct role_transition *)
51462+ acl_alloc(sizeof (struct role_transition))) == NULL)
51463+ return -ENOMEM;
51464+
51465+ if (copy_from_user(rtmp, rusertp,
51466+ sizeof (struct role_transition)))
51467+ return -EFAULT;
51468+
51469+ rusertp = rtmp->prev;
51470+
51471+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
51472+
51473+ if (!len || len >= GR_SPROLE_LEN)
51474+ return -EINVAL;
51475+
51476+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51477+ return -ENOMEM;
51478+
51479+ if (copy_from_user(tmp, rtmp->rolename, len))
51480+ return -EFAULT;
51481+ tmp[len-1] = '\0';
51482+ rtmp->rolename = tmp;
51483+
51484+ if (!rlast) {
51485+ rtmp->prev = NULL;
51486+ rolep->transitions = rtmp;
51487+ } else {
51488+ rlast->next = rtmp;
51489+ rtmp->prev = rlast;
51490+ }
51491+
51492+ if (!rusertp)
51493+ rtmp->next = NULL;
51494+ }
51495+
51496+ return 0;
51497+}
51498+
51499+static struct acl_subject_label *
51500+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
51501+{
51502+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
51503+ unsigned int len;
51504+ char *tmp;
51505+ __u32 num_objs;
51506+ struct acl_ip_label **i_tmp, *i_utmp2;
51507+ struct gr_hash_struct ghash;
51508+ struct subject_map *subjmap;
51509+ unsigned int i_num;
51510+ int err;
51511+
51512+ s_tmp = lookup_subject_map(userp);
51513+
51514+ /* we've already copied this subject into the kernel, just return
51515+ the reference to it, and don't copy it over again
51516+ */
51517+ if (s_tmp)
51518+ return(s_tmp);
51519+
51520+ if ((s_tmp = (struct acl_subject_label *)
51521+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
51522+ return ERR_PTR(-ENOMEM);
51523+
51524+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
51525+ if (subjmap == NULL)
51526+ return ERR_PTR(-ENOMEM);
51527+
51528+ subjmap->user = userp;
51529+ subjmap->kernel = s_tmp;
51530+ insert_subj_map_entry(subjmap);
51531+
51532+ if (copy_from_user(s_tmp, userp,
51533+ sizeof (struct acl_subject_label)))
51534+ return ERR_PTR(-EFAULT);
51535+
51536+ len = strnlen_user(s_tmp->filename, PATH_MAX);
51537+
51538+ if (!len || len >= PATH_MAX)
51539+ return ERR_PTR(-EINVAL);
51540+
51541+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51542+ return ERR_PTR(-ENOMEM);
51543+
51544+ if (copy_from_user(tmp, s_tmp->filename, len))
51545+ return ERR_PTR(-EFAULT);
51546+ tmp[len-1] = '\0';
51547+ s_tmp->filename = tmp;
51548+
51549+ if (!strcmp(s_tmp->filename, "/"))
51550+ role->root_label = s_tmp;
51551+
51552+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
51553+ return ERR_PTR(-EFAULT);
51554+
51555+ /* copy user and group transition tables */
51556+
51557+ if (s_tmp->user_trans_num) {
51558+ uid_t *uidlist;
51559+
51560+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
51561+ if (uidlist == NULL)
51562+ return ERR_PTR(-ENOMEM);
51563+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
51564+ return ERR_PTR(-EFAULT);
51565+
51566+ s_tmp->user_transitions = uidlist;
51567+ }
51568+
51569+ if (s_tmp->group_trans_num) {
51570+ gid_t *gidlist;
51571+
51572+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
51573+ if (gidlist == NULL)
51574+ return ERR_PTR(-ENOMEM);
51575+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
51576+ return ERR_PTR(-EFAULT);
51577+
51578+ s_tmp->group_transitions = gidlist;
51579+ }
51580+
51581+ /* set up object hash table */
51582+ num_objs = count_user_objs(ghash.first);
51583+
51584+ s_tmp->obj_hash_size = num_objs;
51585+ s_tmp->obj_hash =
51586+ (struct acl_object_label **)
51587+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
51588+
51589+ if (!s_tmp->obj_hash)
51590+ return ERR_PTR(-ENOMEM);
51591+
51592+ memset(s_tmp->obj_hash, 0,
51593+ s_tmp->obj_hash_size *
51594+ sizeof (struct acl_object_label *));
51595+
51596+ /* add in objects */
51597+ err = copy_user_objs(ghash.first, s_tmp, role);
51598+
51599+ if (err)
51600+ return ERR_PTR(err);
51601+
51602+ /* set pointer for parent subject */
51603+ if (s_tmp->parent_subject) {
51604+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
51605+
51606+ if (IS_ERR(s_tmp2))
51607+ return s_tmp2;
51608+
51609+ s_tmp->parent_subject = s_tmp2;
51610+ }
51611+
51612+ /* add in ip acls */
51613+
51614+ if (!s_tmp->ip_num) {
51615+ s_tmp->ips = NULL;
51616+ goto insert;
51617+ }
51618+
51619+ i_tmp =
51620+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
51621+ sizeof (struct acl_ip_label *));
51622+
51623+ if (!i_tmp)
51624+ return ERR_PTR(-ENOMEM);
51625+
51626+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
51627+ *(i_tmp + i_num) =
51628+ (struct acl_ip_label *)
51629+ acl_alloc(sizeof (struct acl_ip_label));
51630+ if (!*(i_tmp + i_num))
51631+ return ERR_PTR(-ENOMEM);
51632+
51633+ if (copy_from_user
51634+ (&i_utmp2, s_tmp->ips + i_num,
51635+ sizeof (struct acl_ip_label *)))
51636+ return ERR_PTR(-EFAULT);
51637+
51638+ if (copy_from_user
51639+ (*(i_tmp + i_num), i_utmp2,
51640+ sizeof (struct acl_ip_label)))
51641+ return ERR_PTR(-EFAULT);
51642+
51643+ if ((*(i_tmp + i_num))->iface == NULL)
51644+ continue;
51645+
51646+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
51647+ if (!len || len >= IFNAMSIZ)
51648+ return ERR_PTR(-EINVAL);
51649+ tmp = acl_alloc(len);
51650+ if (tmp == NULL)
51651+ return ERR_PTR(-ENOMEM);
51652+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
51653+ return ERR_PTR(-EFAULT);
51654+ (*(i_tmp + i_num))->iface = tmp;
51655+ }
51656+
51657+ s_tmp->ips = i_tmp;
51658+
51659+insert:
51660+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
51661+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
51662+ return ERR_PTR(-ENOMEM);
51663+
51664+ return s_tmp;
51665+}
51666+
51667+static int
51668+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
51669+{
51670+ struct acl_subject_label s_pre;
51671+ struct acl_subject_label * ret;
51672+ int err;
51673+
51674+ while (userp) {
51675+ if (copy_from_user(&s_pre, userp,
51676+ sizeof (struct acl_subject_label)))
51677+ return -EFAULT;
51678+
51679+ /* do not add nested subjects here, add
51680+ while parsing objects
51681+ */
51682+
51683+ if (s_pre.mode & GR_NESTED) {
51684+ userp = s_pre.prev;
51685+ continue;
51686+ }
51687+
51688+ ret = do_copy_user_subj(userp, role);
51689+
51690+ err = PTR_ERR(ret);
51691+ if (IS_ERR(ret))
51692+ return err;
51693+
51694+ insert_acl_subj_label(ret, role);
51695+
51696+ userp = s_pre.prev;
51697+ }
51698+
51699+ return 0;
51700+}
51701+
51702+static int
51703+copy_user_acl(struct gr_arg *arg)
51704+{
51705+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
51706+ struct sprole_pw *sptmp;
51707+ struct gr_hash_struct *ghash;
51708+ uid_t *domainlist;
51709+ unsigned int r_num;
51710+ unsigned int len;
51711+ char *tmp;
51712+ int err = 0;
51713+ __u16 i;
51714+ __u32 num_subjs;
51715+
51716+ /* we need a default and kernel role */
51717+ if (arg->role_db.num_roles < 2)
51718+ return -EINVAL;
51719+
51720+ /* copy special role authentication info from userspace */
51721+
51722+ num_sprole_pws = arg->num_sprole_pws;
51723+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
51724+
51725+ if (!acl_special_roles && num_sprole_pws)
51726+ return -ENOMEM;
51727+
51728+ for (i = 0; i < num_sprole_pws; i++) {
51729+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
51730+ if (!sptmp)
51731+ return -ENOMEM;
51732+ if (copy_from_user(sptmp, arg->sprole_pws + i,
51733+ sizeof (struct sprole_pw)))
51734+ return -EFAULT;
51735+
51736+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
51737+
51738+ if (!len || len >= GR_SPROLE_LEN)
51739+ return -EINVAL;
51740+
51741+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51742+ return -ENOMEM;
51743+
51744+ if (copy_from_user(tmp, sptmp->rolename, len))
51745+ return -EFAULT;
51746+
51747+ tmp[len-1] = '\0';
51748+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51749+ printk(KERN_ALERT "Copying special role %s\n", tmp);
51750+#endif
51751+ sptmp->rolename = tmp;
51752+ acl_special_roles[i] = sptmp;
51753+ }
51754+
51755+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
51756+
51757+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
51758+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
51759+
51760+ if (!r_tmp)
51761+ return -ENOMEM;
51762+
51763+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
51764+ sizeof (struct acl_role_label *)))
51765+ return -EFAULT;
51766+
51767+ if (copy_from_user(r_tmp, r_utmp2,
51768+ sizeof (struct acl_role_label)))
51769+ return -EFAULT;
51770+
51771+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
51772+
51773+ if (!len || len >= PATH_MAX)
51774+ return -EINVAL;
51775+
51776+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51777+ return -ENOMEM;
51778+
51779+ if (copy_from_user(tmp, r_tmp->rolename, len))
51780+ return -EFAULT;
51781+
51782+ tmp[len-1] = '\0';
51783+ r_tmp->rolename = tmp;
51784+
51785+ if (!strcmp(r_tmp->rolename, "default")
51786+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
51787+ default_role = r_tmp;
51788+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
51789+ kernel_role = r_tmp;
51790+ }
51791+
51792+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
51793+ return -ENOMEM;
51794+
51795+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
51796+ return -EFAULT;
51797+
51798+ r_tmp->hash = ghash;
51799+
51800+ num_subjs = count_user_subjs(r_tmp->hash->first);
51801+
51802+ r_tmp->subj_hash_size = num_subjs;
51803+ r_tmp->subj_hash =
51804+ (struct acl_subject_label **)
51805+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
51806+
51807+ if (!r_tmp->subj_hash)
51808+ return -ENOMEM;
51809+
51810+ err = copy_user_allowedips(r_tmp);
51811+ if (err)
51812+ return err;
51813+
51814+ /* copy domain info */
51815+ if (r_tmp->domain_children != NULL) {
51816+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
51817+ if (domainlist == NULL)
51818+ return -ENOMEM;
51819+
51820+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
51821+ return -EFAULT;
51822+
51823+ r_tmp->domain_children = domainlist;
51824+ }
51825+
51826+ err = copy_user_transitions(r_tmp);
51827+ if (err)
51828+ return err;
51829+
51830+ memset(r_tmp->subj_hash, 0,
51831+ r_tmp->subj_hash_size *
51832+ sizeof (struct acl_subject_label *));
51833+
51834+ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
51835+
51836+ if (err)
51837+ return err;
51838+
51839+ /* set nested subject list to null */
51840+ r_tmp->hash->first = NULL;
51841+
51842+ insert_acl_role_label(r_tmp);
51843+ }
51844+
51845+ if (default_role == NULL || kernel_role == NULL)
51846+ return -EINVAL;
51847+
51848+ return err;
51849+}
51850+
51851+static int
51852+gracl_init(struct gr_arg *args)
51853+{
51854+ int error = 0;
51855+
51856+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
51857+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
51858+
51859+ if (init_variables(args)) {
51860+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
51861+ error = -ENOMEM;
51862+ free_variables();
51863+ goto out;
51864+ }
51865+
51866+ error = copy_user_acl(args);
51867+ free_init_variables();
51868+ if (error) {
51869+ free_variables();
51870+ goto out;
51871+ }
51872+
51873+ if ((error = gr_set_acls(0))) {
51874+ free_variables();
51875+ goto out;
51876+ }
51877+
51878+ pax_open_kernel();
51879+ gr_status |= GR_READY;
51880+ pax_close_kernel();
51881+
51882+ out:
51883+ return error;
51884+}
51885+
51886+/* derived from glibc fnmatch() 0: match, 1: no match*/
51887+
51888+static int
51889+glob_match(const char *p, const char *n)
51890+{
51891+ char c;
51892+
51893+ while ((c = *p++) != '\0') {
51894+ switch (c) {
51895+ case '?':
51896+ if (*n == '\0')
51897+ return 1;
51898+ else if (*n == '/')
51899+ return 1;
51900+ break;
51901+ case '\\':
51902+ if (*n != c)
51903+ return 1;
51904+ break;
51905+ case '*':
51906+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
51907+ if (*n == '/')
51908+ return 1;
51909+ else if (c == '?') {
51910+ if (*n == '\0')
51911+ return 1;
51912+ else
51913+ ++n;
51914+ }
51915+ }
51916+ if (c == '\0') {
51917+ return 0;
51918+ } else {
51919+ const char *endp;
51920+
51921+ if ((endp = strchr(n, '/')) == NULL)
51922+ endp = n + strlen(n);
51923+
51924+ if (c == '[') {
51925+ for (--p; n < endp; ++n)
51926+ if (!glob_match(p, n))
51927+ return 0;
51928+ } else if (c == '/') {
51929+ while (*n != '\0' && *n != '/')
51930+ ++n;
51931+ if (*n == '/' && !glob_match(p, n + 1))
51932+ return 0;
51933+ } else {
51934+ for (--p; n < endp; ++n)
51935+ if (*n == c && !glob_match(p, n))
51936+ return 0;
51937+ }
51938+
51939+ return 1;
51940+ }
51941+ case '[':
51942+ {
51943+ int not;
51944+ char cold;
51945+
51946+ if (*n == '\0' || *n == '/')
51947+ return 1;
51948+
51949+ not = (*p == '!' || *p == '^');
51950+ if (not)
51951+ ++p;
51952+
51953+ c = *p++;
51954+ for (;;) {
51955+ unsigned char fn = (unsigned char)*n;
51956+
51957+ if (c == '\0')
51958+ return 1;
51959+ else {
51960+ if (c == fn)
51961+ goto matched;
51962+ cold = c;
51963+ c = *p++;
51964+
51965+ if (c == '-' && *p != ']') {
51966+ unsigned char cend = *p++;
51967+
51968+ if (cend == '\0')
51969+ return 1;
51970+
51971+ if (cold <= fn && fn <= cend)
51972+ goto matched;
51973+
51974+ c = *p++;
51975+ }
51976+ }
51977+
51978+ if (c == ']')
51979+ break;
51980+ }
51981+ if (!not)
51982+ return 1;
51983+ break;
51984+ matched:
51985+ while (c != ']') {
51986+ if (c == '\0')
51987+ return 1;
51988+
51989+ c = *p++;
51990+ }
51991+ if (not)
51992+ return 1;
51993+ }
51994+ break;
51995+ default:
51996+ if (c != *n)
51997+ return 1;
51998+ }
51999+
52000+ ++n;
52001+ }
52002+
52003+ if (*n == '\0')
52004+ return 0;
52005+
52006+ if (*n == '/')
52007+ return 0;
52008+
52009+ return 1;
52010+}
52011+
52012+static struct acl_object_label *
52013+chk_glob_label(struct acl_object_label *globbed,
52014+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
52015+{
52016+ struct acl_object_label *tmp;
52017+
52018+ if (*path == NULL)
52019+ *path = gr_to_filename_nolock(dentry, mnt);
52020+
52021+ tmp = globbed;
52022+
52023+ while (tmp) {
52024+ if (!glob_match(tmp->filename, *path))
52025+ return tmp;
52026+ tmp = tmp->next;
52027+ }
52028+
52029+ return NULL;
52030+}
52031+
52032+static struct acl_object_label *
52033+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52034+ const ino_t curr_ino, const dev_t curr_dev,
52035+ const struct acl_subject_label *subj, char **path, const int checkglob)
52036+{
52037+ struct acl_subject_label *tmpsubj;
52038+ struct acl_object_label *retval;
52039+ struct acl_object_label *retval2;
52040+
52041+ tmpsubj = (struct acl_subject_label *) subj;
52042+ read_lock(&gr_inode_lock);
52043+ do {
52044+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
52045+ if (retval) {
52046+ if (checkglob && retval->globbed) {
52047+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
52048+ if (retval2)
52049+ retval = retval2;
52050+ }
52051+ break;
52052+ }
52053+ } while ((tmpsubj = tmpsubj->parent_subject));
52054+ read_unlock(&gr_inode_lock);
52055+
52056+ return retval;
52057+}
52058+
52059+static __inline__ struct acl_object_label *
52060+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52061+ struct dentry *curr_dentry,
52062+ const struct acl_subject_label *subj, char **path, const int checkglob)
52063+{
52064+ int newglob = checkglob;
52065+ ino_t inode;
52066+ dev_t device;
52067+
52068+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
52069+ as we don't want a / * rule to match instead of the / object
52070+ don't do this for create lookups that call this function though, since they're looking up
52071+ on the parent and thus need globbing checks on all paths
52072+ */
52073+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
52074+ newglob = GR_NO_GLOB;
52075+
52076+ spin_lock(&curr_dentry->d_lock);
52077+ inode = curr_dentry->d_inode->i_ino;
52078+ device = __get_dev(curr_dentry);
52079+ spin_unlock(&curr_dentry->d_lock);
52080+
52081+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
52082+}
52083+
52084+static struct acl_object_label *
52085+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52086+ const struct acl_subject_label *subj, char *path, const int checkglob)
52087+{
52088+ struct dentry *dentry = (struct dentry *) l_dentry;
52089+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52090+ struct mount *real_mnt = real_mount(mnt);
52091+ struct acl_object_label *retval;
52092+ struct dentry *parent;
52093+
52094+ write_seqlock(&rename_lock);
52095+ br_read_lock(vfsmount_lock);
52096+
52097+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
52098+#ifdef CONFIG_NET
52099+ mnt == sock_mnt ||
52100+#endif
52101+#ifdef CONFIG_HUGETLBFS
52102+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
52103+#endif
52104+ /* ignore Eric Biederman */
52105+ IS_PRIVATE(l_dentry->d_inode))) {
52106+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
52107+ goto out;
52108+ }
52109+
52110+ for (;;) {
52111+ if (dentry == real_root.dentry && mnt == real_root.mnt)
52112+ break;
52113+
52114+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52115+ if (!mnt_has_parent(real_mnt))
52116+ break;
52117+
52118+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52119+ if (retval != NULL)
52120+ goto out;
52121+
52122+ dentry = real_mnt->mnt_mountpoint;
52123+ real_mnt = real_mnt->mnt_parent;
52124+ mnt = &real_mnt->mnt;
52125+ continue;
52126+ }
52127+
52128+ parent = dentry->d_parent;
52129+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52130+ if (retval != NULL)
52131+ goto out;
52132+
52133+ dentry = parent;
52134+ }
52135+
52136+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52137+
52138+ /* real_root is pinned so we don't have to hold a reference */
52139+ if (retval == NULL)
52140+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
52141+out:
52142+ br_read_unlock(vfsmount_lock);
52143+ write_sequnlock(&rename_lock);
52144+
52145+ BUG_ON(retval == NULL);
52146+
52147+ return retval;
52148+}
52149+
52150+static __inline__ struct acl_object_label *
52151+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52152+ const struct acl_subject_label *subj)
52153+{
52154+ char *path = NULL;
52155+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
52156+}
52157+
52158+static __inline__ struct acl_object_label *
52159+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52160+ const struct acl_subject_label *subj)
52161+{
52162+ char *path = NULL;
52163+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
52164+}
52165+
52166+static __inline__ struct acl_object_label *
52167+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52168+ const struct acl_subject_label *subj, char *path)
52169+{
52170+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
52171+}
52172+
52173+static struct acl_subject_label *
52174+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52175+ const struct acl_role_label *role)
52176+{
52177+ struct dentry *dentry = (struct dentry *) l_dentry;
52178+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52179+ struct mount *real_mnt = real_mount(mnt);
52180+ struct acl_subject_label *retval;
52181+ struct dentry *parent;
52182+
52183+ write_seqlock(&rename_lock);
52184+ br_read_lock(vfsmount_lock);
52185+
52186+ for (;;) {
52187+ if (dentry == real_root.dentry && mnt == real_root.mnt)
52188+ break;
52189+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52190+ if (!mnt_has_parent(real_mnt))
52191+ break;
52192+
52193+ spin_lock(&dentry->d_lock);
52194+ read_lock(&gr_inode_lock);
52195+ retval =
52196+ lookup_acl_subj_label(dentry->d_inode->i_ino,
52197+ __get_dev(dentry), role);
52198+ read_unlock(&gr_inode_lock);
52199+ spin_unlock(&dentry->d_lock);
52200+ if (retval != NULL)
52201+ goto out;
52202+
52203+ dentry = real_mnt->mnt_mountpoint;
52204+ real_mnt = real_mnt->mnt_parent;
52205+ mnt = &real_mnt->mnt;
52206+ continue;
52207+ }
52208+
52209+ spin_lock(&dentry->d_lock);
52210+ read_lock(&gr_inode_lock);
52211+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52212+ __get_dev(dentry), role);
52213+ read_unlock(&gr_inode_lock);
52214+ parent = dentry->d_parent;
52215+ spin_unlock(&dentry->d_lock);
52216+
52217+ if (retval != NULL)
52218+ goto out;
52219+
52220+ dentry = parent;
52221+ }
52222+
52223+ spin_lock(&dentry->d_lock);
52224+ read_lock(&gr_inode_lock);
52225+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52226+ __get_dev(dentry), role);
52227+ read_unlock(&gr_inode_lock);
52228+ spin_unlock(&dentry->d_lock);
52229+
52230+ if (unlikely(retval == NULL)) {
52231+ /* real_root is pinned, we don't need to hold a reference */
52232+ read_lock(&gr_inode_lock);
52233+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
52234+ __get_dev(real_root.dentry), role);
52235+ read_unlock(&gr_inode_lock);
52236+ }
52237+out:
52238+ br_read_unlock(vfsmount_lock);
52239+ write_sequnlock(&rename_lock);
52240+
52241+ BUG_ON(retval == NULL);
52242+
52243+ return retval;
52244+}
52245+
52246+static void
52247+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
52248+{
52249+ struct task_struct *task = current;
52250+ const struct cred *cred = current_cred();
52251+
52252+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52253+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52254+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52255+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
52256+
52257+ return;
52258+}
52259+
52260+static void
52261+gr_log_learn_id_change(const char type, const unsigned int real,
52262+ const unsigned int effective, const unsigned int fs)
52263+{
52264+ struct task_struct *task = current;
52265+ const struct cred *cred = current_cred();
52266+
52267+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
52268+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52269+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52270+ type, real, effective, fs, &task->signal->saved_ip);
52271+
52272+ return;
52273+}
52274+
52275+__u32
52276+gr_search_file(const struct dentry * dentry, const __u32 mode,
52277+ const struct vfsmount * mnt)
52278+{
52279+ __u32 retval = mode;
52280+ struct acl_subject_label *curracl;
52281+ struct acl_object_label *currobj;
52282+
52283+ if (unlikely(!(gr_status & GR_READY)))
52284+ return (mode & ~GR_AUDITS);
52285+
52286+ curracl = current->acl;
52287+
52288+ currobj = chk_obj_label(dentry, mnt, curracl);
52289+ retval = currobj->mode & mode;
52290+
52291+ /* if we're opening a specified transfer file for writing
52292+ (e.g. /dev/initctl), then transfer our role to init
52293+ */
52294+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
52295+ current->role->roletype & GR_ROLE_PERSIST)) {
52296+ struct task_struct *task = init_pid_ns.child_reaper;
52297+
52298+ if (task->role != current->role) {
52299+ task->acl_sp_role = 0;
52300+ task->acl_role_id = current->acl_role_id;
52301+ task->role = current->role;
52302+ rcu_read_lock();
52303+ read_lock(&grsec_exec_file_lock);
52304+ gr_apply_subject_to_task(task);
52305+ read_unlock(&grsec_exec_file_lock);
52306+ rcu_read_unlock();
52307+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
52308+ }
52309+ }
52310+
52311+ if (unlikely
52312+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
52313+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
52314+ __u32 new_mode = mode;
52315+
52316+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52317+
52318+ retval = new_mode;
52319+
52320+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
52321+ new_mode |= GR_INHERIT;
52322+
52323+ if (!(mode & GR_NOLEARN))
52324+ gr_log_learn(dentry, mnt, new_mode);
52325+ }
52326+
52327+ return retval;
52328+}
52329+
52330+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
52331+ const struct dentry *parent,
52332+ const struct vfsmount *mnt)
52333+{
52334+ struct name_entry *match;
52335+ struct acl_object_label *matchpo;
52336+ struct acl_subject_label *curracl;
52337+ char *path;
52338+
52339+ if (unlikely(!(gr_status & GR_READY)))
52340+ return NULL;
52341+
52342+ preempt_disable();
52343+ path = gr_to_filename_rbac(new_dentry, mnt);
52344+ match = lookup_name_entry_create(path);
52345+
52346+ curracl = current->acl;
52347+
52348+ if (match) {
52349+ read_lock(&gr_inode_lock);
52350+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
52351+ read_unlock(&gr_inode_lock);
52352+
52353+ if (matchpo) {
52354+ preempt_enable();
52355+ return matchpo;
52356+ }
52357+ }
52358+
52359+ // lookup parent
52360+
52361+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
52362+
52363+ preempt_enable();
52364+ return matchpo;
52365+}
52366+
52367+__u32
52368+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
52369+ const struct vfsmount * mnt, const __u32 mode)
52370+{
52371+ struct acl_object_label *matchpo;
52372+ __u32 retval;
52373+
52374+ if (unlikely(!(gr_status & GR_READY)))
52375+ return (mode & ~GR_AUDITS);
52376+
52377+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
52378+
52379+ retval = matchpo->mode & mode;
52380+
52381+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
52382+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
52383+ __u32 new_mode = mode;
52384+
52385+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52386+
52387+ gr_log_learn(new_dentry, mnt, new_mode);
52388+ return new_mode;
52389+ }
52390+
52391+ return retval;
52392+}
52393+
52394+__u32
52395+gr_check_link(const struct dentry * new_dentry,
52396+ const struct dentry * parent_dentry,
52397+ const struct vfsmount * parent_mnt,
52398+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
52399+{
52400+ struct acl_object_label *obj;
52401+ __u32 oldmode, newmode;
52402+ __u32 needmode;
52403+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
52404+ GR_DELETE | GR_INHERIT;
52405+
52406+ if (unlikely(!(gr_status & GR_READY)))
52407+ return (GR_CREATE | GR_LINK);
52408+
52409+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
52410+ oldmode = obj->mode;
52411+
52412+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
52413+ newmode = obj->mode;
52414+
52415+ needmode = newmode & checkmodes;
52416+
52417+ // old name for hardlink must have at least the permissions of the new name
52418+ if ((oldmode & needmode) != needmode)
52419+ goto bad;
52420+
52421+ // if old name had restrictions/auditing, make sure the new name does as well
52422+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
52423+
52424+ // don't allow hardlinking of suid/sgid files without permission
52425+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52426+ needmode |= GR_SETID;
52427+
52428+ if ((newmode & needmode) != needmode)
52429+ goto bad;
52430+
52431+ // enforce minimum permissions
52432+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
52433+ return newmode;
52434+bad:
52435+ needmode = oldmode;
52436+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52437+ needmode |= GR_SETID;
52438+
52439+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
52440+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
52441+ return (GR_CREATE | GR_LINK);
52442+ } else if (newmode & GR_SUPPRESS)
52443+ return GR_SUPPRESS;
52444+ else
52445+ return 0;
52446+}
52447+
52448+int
52449+gr_check_hidden_task(const struct task_struct *task)
52450+{
52451+ if (unlikely(!(gr_status & GR_READY)))
52452+ return 0;
52453+
52454+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
52455+ return 1;
52456+
52457+ return 0;
52458+}
52459+
52460+int
52461+gr_check_protected_task(const struct task_struct *task)
52462+{
52463+ if (unlikely(!(gr_status & GR_READY) || !task))
52464+ return 0;
52465+
52466+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52467+ task->acl != current->acl)
52468+ return 1;
52469+
52470+ return 0;
52471+}
52472+
52473+int
52474+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
52475+{
52476+ struct task_struct *p;
52477+ int ret = 0;
52478+
52479+ if (unlikely(!(gr_status & GR_READY) || !pid))
52480+ return ret;
52481+
52482+ read_lock(&tasklist_lock);
52483+ do_each_pid_task(pid, type, p) {
52484+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52485+ p->acl != current->acl) {
52486+ ret = 1;
52487+ goto out;
52488+ }
52489+ } while_each_pid_task(pid, type, p);
52490+out:
52491+ read_unlock(&tasklist_lock);
52492+
52493+ return ret;
52494+}
52495+
52496+void
52497+gr_copy_label(struct task_struct *tsk)
52498+{
52499+ /* plain copying of fields is already done by dup_task_struct */
52500+ tsk->signal->used_accept = 0;
52501+ tsk->acl_sp_role = 0;
52502+ //tsk->acl_role_id = current->acl_role_id;
52503+ //tsk->acl = current->acl;
52504+ //tsk->role = current->role;
52505+ tsk->signal->curr_ip = current->signal->curr_ip;
52506+ tsk->signal->saved_ip = current->signal->saved_ip;
52507+ if (current->exec_file)
52508+ get_file(current->exec_file);
52509+ //tsk->exec_file = current->exec_file;
52510+ //tsk->is_writable = current->is_writable;
52511+ if (unlikely(current->signal->used_accept)) {
52512+ current->signal->curr_ip = 0;
52513+ current->signal->saved_ip = 0;
52514+ }
52515+
52516+ return;
52517+}
52518+
52519+static void
52520+gr_set_proc_res(struct task_struct *task)
52521+{
52522+ struct acl_subject_label *proc;
52523+ unsigned short i;
52524+
52525+ proc = task->acl;
52526+
52527+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
52528+ return;
52529+
52530+ for (i = 0; i < RLIM_NLIMITS; i++) {
52531+ if (!(proc->resmask & (1 << i)))
52532+ continue;
52533+
52534+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
52535+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
52536+ }
52537+
52538+ return;
52539+}
52540+
52541+extern int __gr_process_user_ban(struct user_struct *user);
52542+
52543+int
52544+gr_check_user_change(int real, int effective, int fs)
52545+{
52546+ unsigned int i;
52547+ __u16 num;
52548+ uid_t *uidlist;
52549+ int curuid;
52550+ int realok = 0;
52551+ int effectiveok = 0;
52552+ int fsok = 0;
52553+
52554+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
52555+ struct user_struct *user;
52556+
52557+ if (real == -1)
52558+ goto skipit;
52559+
52560+ user = find_user(real);
52561+ if (user == NULL)
52562+ goto skipit;
52563+
52564+ if (__gr_process_user_ban(user)) {
52565+ /* for find_user */
52566+ free_uid(user);
52567+ return 1;
52568+ }
52569+
52570+ /* for find_user */
52571+ free_uid(user);
52572+
52573+skipit:
52574+#endif
52575+
52576+ if (unlikely(!(gr_status & GR_READY)))
52577+ return 0;
52578+
52579+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52580+ gr_log_learn_id_change('u', real, effective, fs);
52581+
52582+ num = current->acl->user_trans_num;
52583+ uidlist = current->acl->user_transitions;
52584+
52585+ if (uidlist == NULL)
52586+ return 0;
52587+
52588+ if (real == -1)
52589+ realok = 1;
52590+ if (effective == -1)
52591+ effectiveok = 1;
52592+ if (fs == -1)
52593+ fsok = 1;
52594+
52595+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
52596+ for (i = 0; i < num; i++) {
52597+ curuid = (int)uidlist[i];
52598+ if (real == curuid)
52599+ realok = 1;
52600+ if (effective == curuid)
52601+ effectiveok = 1;
52602+ if (fs == curuid)
52603+ fsok = 1;
52604+ }
52605+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
52606+ for (i = 0; i < num; i++) {
52607+ curuid = (int)uidlist[i];
52608+ if (real == curuid)
52609+ break;
52610+ if (effective == curuid)
52611+ break;
52612+ if (fs == curuid)
52613+ break;
52614+ }
52615+ /* not in deny list */
52616+ if (i == num) {
52617+ realok = 1;
52618+ effectiveok = 1;
52619+ fsok = 1;
52620+ }
52621+ }
52622+
52623+ if (realok && effectiveok && fsok)
52624+ return 0;
52625+ else {
52626+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
52627+ return 1;
52628+ }
52629+}
52630+
52631+int
52632+gr_check_group_change(int real, int effective, int fs)
52633+{
52634+ unsigned int i;
52635+ __u16 num;
52636+ gid_t *gidlist;
52637+ int curgid;
52638+ int realok = 0;
52639+ int effectiveok = 0;
52640+ int fsok = 0;
52641+
52642+ if (unlikely(!(gr_status & GR_READY)))
52643+ return 0;
52644+
52645+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52646+ gr_log_learn_id_change('g', real, effective, fs);
52647+
52648+ num = current->acl->group_trans_num;
52649+ gidlist = current->acl->group_transitions;
52650+
52651+ if (gidlist == NULL)
52652+ return 0;
52653+
52654+ if (real == -1)
52655+ realok = 1;
52656+ if (effective == -1)
52657+ effectiveok = 1;
52658+ if (fs == -1)
52659+ fsok = 1;
52660+
52661+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
52662+ for (i = 0; i < num; i++) {
52663+ curgid = (int)gidlist[i];
52664+ if (real == curgid)
52665+ realok = 1;
52666+ if (effective == curgid)
52667+ effectiveok = 1;
52668+ if (fs == curgid)
52669+ fsok = 1;
52670+ }
52671+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
52672+ for (i = 0; i < num; i++) {
52673+ curgid = (int)gidlist[i];
52674+ if (real == curgid)
52675+ break;
52676+ if (effective == curgid)
52677+ break;
52678+ if (fs == curgid)
52679+ break;
52680+ }
52681+ /* not in deny list */
52682+ if (i == num) {
52683+ realok = 1;
52684+ effectiveok = 1;
52685+ fsok = 1;
52686+ }
52687+ }
52688+
52689+ if (realok && effectiveok && fsok)
52690+ return 0;
52691+ else {
52692+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
52693+ return 1;
52694+ }
52695+}
52696+
52697+extern int gr_acl_is_capable(const int cap);
52698+
52699+void
52700+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
52701+{
52702+ struct acl_role_label *role = task->role;
52703+ struct acl_subject_label *subj = NULL;
52704+ struct acl_object_label *obj;
52705+ struct file *filp;
52706+
52707+ if (unlikely(!(gr_status & GR_READY)))
52708+ return;
52709+
52710+ filp = task->exec_file;
52711+
52712+ /* kernel process, we'll give them the kernel role */
52713+ if (unlikely(!filp)) {
52714+ task->role = kernel_role;
52715+ task->acl = kernel_role->root_label;
52716+ return;
52717+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
52718+ role = lookup_acl_role_label(task, uid, gid);
52719+
52720+ /* don't change the role if we're not a privileged process */
52721+ if (role && task->role != role &&
52722+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
52723+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
52724+ return;
52725+
52726+ /* perform subject lookup in possibly new role
52727+ we can use this result below in the case where role == task->role
52728+ */
52729+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
52730+
52731+ /* if we changed uid/gid, but result in the same role
52732+ and are using inheritance, don't lose the inherited subject
52733+ if current subject is other than what normal lookup
52734+ would result in, we arrived via inheritance, don't
52735+ lose subject
52736+ */
52737+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
52738+ (subj == task->acl)))
52739+ task->acl = subj;
52740+
52741+ task->role = role;
52742+
52743+ task->is_writable = 0;
52744+
52745+ /* ignore additional mmap checks for processes that are writable
52746+ by the default ACL */
52747+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
52748+ if (unlikely(obj->mode & GR_WRITE))
52749+ task->is_writable = 1;
52750+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
52751+ if (unlikely(obj->mode & GR_WRITE))
52752+ task->is_writable = 1;
52753+
52754+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52755+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
52756+#endif
52757+
52758+ gr_set_proc_res(task);
52759+
52760+ return;
52761+}
52762+
52763+int
52764+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
52765+ const int unsafe_flags)
52766+{
52767+ struct task_struct *task = current;
52768+ struct acl_subject_label *newacl;
52769+ struct acl_object_label *obj;
52770+ __u32 retmode;
52771+
52772+ if (unlikely(!(gr_status & GR_READY)))
52773+ return 0;
52774+
52775+ newacl = chk_subj_label(dentry, mnt, task->role);
52776+
52777+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
52778+ did an exec
52779+ */
52780+ rcu_read_lock();
52781+ read_lock(&tasklist_lock);
52782+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
52783+ (task->parent->acl->mode & GR_POVERRIDE))) {
52784+ read_unlock(&tasklist_lock);
52785+ rcu_read_unlock();
52786+ goto skip_check;
52787+ }
52788+ read_unlock(&tasklist_lock);
52789+ rcu_read_unlock();
52790+
52791+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
52792+ !(task->role->roletype & GR_ROLE_GOD) &&
52793+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
52794+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
52795+ if (unsafe_flags & LSM_UNSAFE_SHARE)
52796+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
52797+ else
52798+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
52799+ return -EACCES;
52800+ }
52801+
52802+skip_check:
52803+
52804+ obj = chk_obj_label(dentry, mnt, task->acl);
52805+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
52806+
52807+ if (!(task->acl->mode & GR_INHERITLEARN) &&
52808+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
52809+ if (obj->nested)
52810+ task->acl = obj->nested;
52811+ else
52812+ task->acl = newacl;
52813+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
52814+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
52815+
52816+ task->is_writable = 0;
52817+
52818+ /* ignore additional mmap checks for processes that are writable
52819+ by the default ACL */
52820+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
52821+ if (unlikely(obj->mode & GR_WRITE))
52822+ task->is_writable = 1;
52823+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
52824+ if (unlikely(obj->mode & GR_WRITE))
52825+ task->is_writable = 1;
52826+
52827+ gr_set_proc_res(task);
52828+
52829+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52830+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
52831+#endif
52832+ return 0;
52833+}
52834+
52835+/* always called with valid inodev ptr */
52836+static void
52837+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
52838+{
52839+ struct acl_object_label *matchpo;
52840+ struct acl_subject_label *matchps;
52841+ struct acl_subject_label *subj;
52842+ struct acl_role_label *role;
52843+ unsigned int x;
52844+
52845+ FOR_EACH_ROLE_START(role)
52846+ FOR_EACH_SUBJECT_START(role, subj, x)
52847+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
52848+ matchpo->mode |= GR_DELETED;
52849+ FOR_EACH_SUBJECT_END(subj,x)
52850+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
52851+ if (subj->inode == ino && subj->device == dev)
52852+ subj->mode |= GR_DELETED;
52853+ FOR_EACH_NESTED_SUBJECT_END(subj)
52854+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
52855+ matchps->mode |= GR_DELETED;
52856+ FOR_EACH_ROLE_END(role)
52857+
52858+ inodev->nentry->deleted = 1;
52859+
52860+ return;
52861+}
52862+
52863+void
52864+gr_handle_delete(const ino_t ino, const dev_t dev)
52865+{
52866+ struct inodev_entry *inodev;
52867+
52868+ if (unlikely(!(gr_status & GR_READY)))
52869+ return;
52870+
52871+ write_lock(&gr_inode_lock);
52872+ inodev = lookup_inodev_entry(ino, dev);
52873+ if (inodev != NULL)
52874+ do_handle_delete(inodev, ino, dev);
52875+ write_unlock(&gr_inode_lock);
52876+
52877+ return;
52878+}
52879+
52880+static void
52881+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
52882+ const ino_t newinode, const dev_t newdevice,
52883+ struct acl_subject_label *subj)
52884+{
52885+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
52886+ struct acl_object_label *match;
52887+
52888+ match = subj->obj_hash[index];
52889+
52890+ while (match && (match->inode != oldinode ||
52891+ match->device != olddevice ||
52892+ !(match->mode & GR_DELETED)))
52893+ match = match->next;
52894+
52895+ if (match && (match->inode == oldinode)
52896+ && (match->device == olddevice)
52897+ && (match->mode & GR_DELETED)) {
52898+ if (match->prev == NULL) {
52899+ subj->obj_hash[index] = match->next;
52900+ if (match->next != NULL)
52901+ match->next->prev = NULL;
52902+ } else {
52903+ match->prev->next = match->next;
52904+ if (match->next != NULL)
52905+ match->next->prev = match->prev;
52906+ }
52907+ match->prev = NULL;
52908+ match->next = NULL;
52909+ match->inode = newinode;
52910+ match->device = newdevice;
52911+ match->mode &= ~GR_DELETED;
52912+
52913+ insert_acl_obj_label(match, subj);
52914+ }
52915+
52916+ return;
52917+}
52918+
52919+static void
52920+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
52921+ const ino_t newinode, const dev_t newdevice,
52922+ struct acl_role_label *role)
52923+{
52924+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
52925+ struct acl_subject_label *match;
52926+
52927+ match = role->subj_hash[index];
52928+
52929+ while (match && (match->inode != oldinode ||
52930+ match->device != olddevice ||
52931+ !(match->mode & GR_DELETED)))
52932+ match = match->next;
52933+
52934+ if (match && (match->inode == oldinode)
52935+ && (match->device == olddevice)
52936+ && (match->mode & GR_DELETED)) {
52937+ if (match->prev == NULL) {
52938+ role->subj_hash[index] = match->next;
52939+ if (match->next != NULL)
52940+ match->next->prev = NULL;
52941+ } else {
52942+ match->prev->next = match->next;
52943+ if (match->next != NULL)
52944+ match->next->prev = match->prev;
52945+ }
52946+ match->prev = NULL;
52947+ match->next = NULL;
52948+ match->inode = newinode;
52949+ match->device = newdevice;
52950+ match->mode &= ~GR_DELETED;
52951+
52952+ insert_acl_subj_label(match, role);
52953+ }
52954+
52955+ return;
52956+}
52957+
52958+static void
52959+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
52960+ const ino_t newinode, const dev_t newdevice)
52961+{
52962+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
52963+ struct inodev_entry *match;
52964+
52965+ match = inodev_set.i_hash[index];
52966+
52967+ while (match && (match->nentry->inode != oldinode ||
52968+ match->nentry->device != olddevice || !match->nentry->deleted))
52969+ match = match->next;
52970+
52971+ if (match && (match->nentry->inode == oldinode)
52972+ && (match->nentry->device == olddevice) &&
52973+ match->nentry->deleted) {
52974+ if (match->prev == NULL) {
52975+ inodev_set.i_hash[index] = match->next;
52976+ if (match->next != NULL)
52977+ match->next->prev = NULL;
52978+ } else {
52979+ match->prev->next = match->next;
52980+ if (match->next != NULL)
52981+ match->next->prev = match->prev;
52982+ }
52983+ match->prev = NULL;
52984+ match->next = NULL;
52985+ match->nentry->inode = newinode;
52986+ match->nentry->device = newdevice;
52987+ match->nentry->deleted = 0;
52988+
52989+ insert_inodev_entry(match);
52990+ }
52991+
52992+ return;
52993+}
52994+
52995+static void
52996+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
52997+{
52998+ struct acl_subject_label *subj;
52999+ struct acl_role_label *role;
53000+ unsigned int x;
53001+
53002+ FOR_EACH_ROLE_START(role)
53003+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
53004+
53005+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
53006+ if ((subj->inode == ino) && (subj->device == dev)) {
53007+ subj->inode = ino;
53008+ subj->device = dev;
53009+ }
53010+ FOR_EACH_NESTED_SUBJECT_END(subj)
53011+ FOR_EACH_SUBJECT_START(role, subj, x)
53012+ update_acl_obj_label(matchn->inode, matchn->device,
53013+ ino, dev, subj);
53014+ FOR_EACH_SUBJECT_END(subj,x)
53015+ FOR_EACH_ROLE_END(role)
53016+
53017+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
53018+
53019+ return;
53020+}
53021+
53022+static void
53023+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
53024+ const struct vfsmount *mnt)
53025+{
53026+ ino_t ino = dentry->d_inode->i_ino;
53027+ dev_t dev = __get_dev(dentry);
53028+
53029+ __do_handle_create(matchn, ino, dev);
53030+
53031+ return;
53032+}
53033+
53034+void
53035+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
53036+{
53037+ struct name_entry *matchn;
53038+
53039+ if (unlikely(!(gr_status & GR_READY)))
53040+ return;
53041+
53042+ preempt_disable();
53043+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
53044+
53045+ if (unlikely((unsigned long)matchn)) {
53046+ write_lock(&gr_inode_lock);
53047+ do_handle_create(matchn, dentry, mnt);
53048+ write_unlock(&gr_inode_lock);
53049+ }
53050+ preempt_enable();
53051+
53052+ return;
53053+}
53054+
53055+void
53056+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
53057+{
53058+ struct name_entry *matchn;
53059+
53060+ if (unlikely(!(gr_status & GR_READY)))
53061+ return;
53062+
53063+ preempt_disable();
53064+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
53065+
53066+ if (unlikely((unsigned long)matchn)) {
53067+ write_lock(&gr_inode_lock);
53068+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
53069+ write_unlock(&gr_inode_lock);
53070+ }
53071+ preempt_enable();
53072+
53073+ return;
53074+}
53075+
53076+void
53077+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
53078+ struct dentry *old_dentry,
53079+ struct dentry *new_dentry,
53080+ struct vfsmount *mnt, const __u8 replace)
53081+{
53082+ struct name_entry *matchn;
53083+ struct inodev_entry *inodev;
53084+ struct inode *inode = new_dentry->d_inode;
53085+ ino_t old_ino = old_dentry->d_inode->i_ino;
53086+ dev_t old_dev = __get_dev(old_dentry);
53087+
53088+ /* vfs_rename swaps the name and parent link for old_dentry and
53089+ new_dentry
53090+ at this point, old_dentry has the new name, parent link, and inode
53091+ for the renamed file
53092+ if a file is being replaced by a rename, new_dentry has the inode
53093+ and name for the replaced file
53094+ */
53095+
53096+ if (unlikely(!(gr_status & GR_READY)))
53097+ return;
53098+
53099+ preempt_disable();
53100+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
53101+
53102+ /* we wouldn't have to check d_inode if it weren't for
53103+ NFS silly-renaming
53104+ */
53105+
53106+ write_lock(&gr_inode_lock);
53107+ if (unlikely(replace && inode)) {
53108+ ino_t new_ino = inode->i_ino;
53109+ dev_t new_dev = __get_dev(new_dentry);
53110+
53111+ inodev = lookup_inodev_entry(new_ino, new_dev);
53112+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
53113+ do_handle_delete(inodev, new_ino, new_dev);
53114+ }
53115+
53116+ inodev = lookup_inodev_entry(old_ino, old_dev);
53117+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
53118+ do_handle_delete(inodev, old_ino, old_dev);
53119+
53120+ if (unlikely((unsigned long)matchn))
53121+ do_handle_create(matchn, old_dentry, mnt);
53122+
53123+ write_unlock(&gr_inode_lock);
53124+ preempt_enable();
53125+
53126+ return;
53127+}
53128+
53129+static int
53130+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
53131+ unsigned char **sum)
53132+{
53133+ struct acl_role_label *r;
53134+ struct role_allowed_ip *ipp;
53135+ struct role_transition *trans;
53136+ unsigned int i;
53137+ int found = 0;
53138+ u32 curr_ip = current->signal->curr_ip;
53139+
53140+ current->signal->saved_ip = curr_ip;
53141+
53142+ /* check transition table */
53143+
53144+ for (trans = current->role->transitions; trans; trans = trans->next) {
53145+ if (!strcmp(rolename, trans->rolename)) {
53146+ found = 1;
53147+ break;
53148+ }
53149+ }
53150+
53151+ if (!found)
53152+ return 0;
53153+
53154+ /* handle special roles that do not require authentication
53155+ and check ip */
53156+
53157+ FOR_EACH_ROLE_START(r)
53158+ if (!strcmp(rolename, r->rolename) &&
53159+ (r->roletype & GR_ROLE_SPECIAL)) {
53160+ found = 0;
53161+ if (r->allowed_ips != NULL) {
53162+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
53163+ if ((ntohl(curr_ip) & ipp->netmask) ==
53164+ (ntohl(ipp->addr) & ipp->netmask))
53165+ found = 1;
53166+ }
53167+ } else
53168+ found = 2;
53169+ if (!found)
53170+ return 0;
53171+
53172+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
53173+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
53174+ *salt = NULL;
53175+ *sum = NULL;
53176+ return 1;
53177+ }
53178+ }
53179+ FOR_EACH_ROLE_END(r)
53180+
53181+ for (i = 0; i < num_sprole_pws; i++) {
53182+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
53183+ *salt = acl_special_roles[i]->salt;
53184+ *sum = acl_special_roles[i]->sum;
53185+ return 1;
53186+ }
53187+ }
53188+
53189+ return 0;
53190+}
53191+
53192+static void
53193+assign_special_role(char *rolename)
53194+{
53195+ struct acl_object_label *obj;
53196+ struct acl_role_label *r;
53197+ struct acl_role_label *assigned = NULL;
53198+ struct task_struct *tsk;
53199+ struct file *filp;
53200+
53201+ FOR_EACH_ROLE_START(r)
53202+ if (!strcmp(rolename, r->rolename) &&
53203+ (r->roletype & GR_ROLE_SPECIAL)) {
53204+ assigned = r;
53205+ break;
53206+ }
53207+ FOR_EACH_ROLE_END(r)
53208+
53209+ if (!assigned)
53210+ return;
53211+
53212+ read_lock(&tasklist_lock);
53213+ read_lock(&grsec_exec_file_lock);
53214+
53215+ tsk = current->real_parent;
53216+ if (tsk == NULL)
53217+ goto out_unlock;
53218+
53219+ filp = tsk->exec_file;
53220+ if (filp == NULL)
53221+ goto out_unlock;
53222+
53223+ tsk->is_writable = 0;
53224+
53225+ tsk->acl_sp_role = 1;
53226+ tsk->acl_role_id = ++acl_sp_role_value;
53227+ tsk->role = assigned;
53228+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
53229+
53230+ /* ignore additional mmap checks for processes that are writable
53231+ by the default ACL */
53232+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53233+ if (unlikely(obj->mode & GR_WRITE))
53234+ tsk->is_writable = 1;
53235+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
53236+ if (unlikely(obj->mode & GR_WRITE))
53237+ tsk->is_writable = 1;
53238+
53239+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53240+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
53241+#endif
53242+
53243+out_unlock:
53244+ read_unlock(&grsec_exec_file_lock);
53245+ read_unlock(&tasklist_lock);
53246+ return;
53247+}
53248+
53249+int gr_check_secure_terminal(struct task_struct *task)
53250+{
53251+ struct task_struct *p, *p2, *p3;
53252+ struct files_struct *files;
53253+ struct fdtable *fdt;
53254+ struct file *our_file = NULL, *file;
53255+ int i;
53256+
53257+ if (task->signal->tty == NULL)
53258+ return 1;
53259+
53260+ files = get_files_struct(task);
53261+ if (files != NULL) {
53262+ rcu_read_lock();
53263+ fdt = files_fdtable(files);
53264+ for (i=0; i < fdt->max_fds; i++) {
53265+ file = fcheck_files(files, i);
53266+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
53267+ get_file(file);
53268+ our_file = file;
53269+ }
53270+ }
53271+ rcu_read_unlock();
53272+ put_files_struct(files);
53273+ }
53274+
53275+ if (our_file == NULL)
53276+ return 1;
53277+
53278+ read_lock(&tasklist_lock);
53279+ do_each_thread(p2, p) {
53280+ files = get_files_struct(p);
53281+ if (files == NULL ||
53282+ (p->signal && p->signal->tty == task->signal->tty)) {
53283+ if (files != NULL)
53284+ put_files_struct(files);
53285+ continue;
53286+ }
53287+ rcu_read_lock();
53288+ fdt = files_fdtable(files);
53289+ for (i=0; i < fdt->max_fds; i++) {
53290+ file = fcheck_files(files, i);
53291+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
53292+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
53293+ p3 = task;
53294+ while (p3->pid > 0) {
53295+ if (p3 == p)
53296+ break;
53297+ p3 = p3->real_parent;
53298+ }
53299+ if (p3 == p)
53300+ break;
53301+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
53302+ gr_handle_alertkill(p);
53303+ rcu_read_unlock();
53304+ put_files_struct(files);
53305+ read_unlock(&tasklist_lock);
53306+ fput(our_file);
53307+ return 0;
53308+ }
53309+ }
53310+ rcu_read_unlock();
53311+ put_files_struct(files);
53312+ } while_each_thread(p2, p);
53313+ read_unlock(&tasklist_lock);
53314+
53315+ fput(our_file);
53316+ return 1;
53317+}
53318+
53319+ssize_t
53320+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
53321+{
53322+ struct gr_arg_wrapper uwrap;
53323+ unsigned char *sprole_salt = NULL;
53324+ unsigned char *sprole_sum = NULL;
53325+ int error = sizeof (struct gr_arg_wrapper);
53326+ int error2 = 0;
53327+
53328+ mutex_lock(&gr_dev_mutex);
53329+
53330+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
53331+ error = -EPERM;
53332+ goto out;
53333+ }
53334+
53335+ if (count != sizeof (struct gr_arg_wrapper)) {
53336+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
53337+ error = -EINVAL;
53338+ goto out;
53339+ }
53340+
53341+
53342+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
53343+ gr_auth_expires = 0;
53344+ gr_auth_attempts = 0;
53345+ }
53346+
53347+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
53348+ error = -EFAULT;
53349+ goto out;
53350+ }
53351+
53352+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
53353+ error = -EINVAL;
53354+ goto out;
53355+ }
53356+
53357+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
53358+ error = -EFAULT;
53359+ goto out;
53360+ }
53361+
53362+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53363+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53364+ time_after(gr_auth_expires, get_seconds())) {
53365+ error = -EBUSY;
53366+ goto out;
53367+ }
53368+
53369+ /* if non-root trying to do anything other than use a special role,
53370+ do not attempt authentication, do not count towards authentication
53371+ locking
53372+ */
53373+
53374+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
53375+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53376+ current_uid()) {
53377+ error = -EPERM;
53378+ goto out;
53379+ }
53380+
53381+ /* ensure pw and special role name are null terminated */
53382+
53383+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
53384+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
53385+
53386+ /* Okay.
53387+ * We have our enough of the argument structure..(we have yet
53388+ * to copy_from_user the tables themselves) . Copy the tables
53389+ * only if we need them, i.e. for loading operations. */
53390+
53391+ switch (gr_usermode->mode) {
53392+ case GR_STATUS:
53393+ if (gr_status & GR_READY) {
53394+ error = 1;
53395+ if (!gr_check_secure_terminal(current))
53396+ error = 3;
53397+ } else
53398+ error = 2;
53399+ goto out;
53400+ case GR_SHUTDOWN:
53401+ if ((gr_status & GR_READY)
53402+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53403+ pax_open_kernel();
53404+ gr_status &= ~GR_READY;
53405+ pax_close_kernel();
53406+
53407+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
53408+ free_variables();
53409+ memset(gr_usermode, 0, sizeof (struct gr_arg));
53410+ memset(gr_system_salt, 0, GR_SALT_LEN);
53411+ memset(gr_system_sum, 0, GR_SHA_LEN);
53412+ } else if (gr_status & GR_READY) {
53413+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
53414+ error = -EPERM;
53415+ } else {
53416+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
53417+ error = -EAGAIN;
53418+ }
53419+ break;
53420+ case GR_ENABLE:
53421+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
53422+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
53423+ else {
53424+ if (gr_status & GR_READY)
53425+ error = -EAGAIN;
53426+ else
53427+ error = error2;
53428+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
53429+ }
53430+ break;
53431+ case GR_RELOAD:
53432+ if (!(gr_status & GR_READY)) {
53433+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
53434+ error = -EAGAIN;
53435+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53436+ preempt_disable();
53437+
53438+ pax_open_kernel();
53439+ gr_status &= ~GR_READY;
53440+ pax_close_kernel();
53441+
53442+ free_variables();
53443+ if (!(error2 = gracl_init(gr_usermode))) {
53444+ preempt_enable();
53445+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
53446+ } else {
53447+ preempt_enable();
53448+ error = error2;
53449+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53450+ }
53451+ } else {
53452+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53453+ error = -EPERM;
53454+ }
53455+ break;
53456+ case GR_SEGVMOD:
53457+ if (unlikely(!(gr_status & GR_READY))) {
53458+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
53459+ error = -EAGAIN;
53460+ break;
53461+ }
53462+
53463+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53464+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
53465+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
53466+ struct acl_subject_label *segvacl;
53467+ segvacl =
53468+ lookup_acl_subj_label(gr_usermode->segv_inode,
53469+ gr_usermode->segv_device,
53470+ current->role);
53471+ if (segvacl) {
53472+ segvacl->crashes = 0;
53473+ segvacl->expires = 0;
53474+ }
53475+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
53476+ gr_remove_uid(gr_usermode->segv_uid);
53477+ }
53478+ } else {
53479+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
53480+ error = -EPERM;
53481+ }
53482+ break;
53483+ case GR_SPROLE:
53484+ case GR_SPROLEPAM:
53485+ if (unlikely(!(gr_status & GR_READY))) {
53486+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
53487+ error = -EAGAIN;
53488+ break;
53489+ }
53490+
53491+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
53492+ current->role->expires = 0;
53493+ current->role->auth_attempts = 0;
53494+ }
53495+
53496+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53497+ time_after(current->role->expires, get_seconds())) {
53498+ error = -EBUSY;
53499+ goto out;
53500+ }
53501+
53502+ if (lookup_special_role_auth
53503+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
53504+ && ((!sprole_salt && !sprole_sum)
53505+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
53506+ char *p = "";
53507+ assign_special_role(gr_usermode->sp_role);
53508+ read_lock(&tasklist_lock);
53509+ if (current->real_parent)
53510+ p = current->real_parent->role->rolename;
53511+ read_unlock(&tasklist_lock);
53512+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
53513+ p, acl_sp_role_value);
53514+ } else {
53515+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
53516+ error = -EPERM;
53517+ if(!(current->role->auth_attempts++))
53518+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53519+
53520+ goto out;
53521+ }
53522+ break;
53523+ case GR_UNSPROLE:
53524+ if (unlikely(!(gr_status & GR_READY))) {
53525+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
53526+ error = -EAGAIN;
53527+ break;
53528+ }
53529+
53530+ if (current->role->roletype & GR_ROLE_SPECIAL) {
53531+ char *p = "";
53532+ int i = 0;
53533+
53534+ read_lock(&tasklist_lock);
53535+ if (current->real_parent) {
53536+ p = current->real_parent->role->rolename;
53537+ i = current->real_parent->acl_role_id;
53538+ }
53539+ read_unlock(&tasklist_lock);
53540+
53541+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
53542+ gr_set_acls(1);
53543+ } else {
53544+ error = -EPERM;
53545+ goto out;
53546+ }
53547+ break;
53548+ default:
53549+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
53550+ error = -EINVAL;
53551+ break;
53552+ }
53553+
53554+ if (error != -EPERM)
53555+ goto out;
53556+
53557+ if(!(gr_auth_attempts++))
53558+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53559+
53560+ out:
53561+ mutex_unlock(&gr_dev_mutex);
53562+ return error;
53563+}
53564+
53565+/* must be called with
53566+ rcu_read_lock();
53567+ read_lock(&tasklist_lock);
53568+ read_lock(&grsec_exec_file_lock);
53569+*/
53570+int gr_apply_subject_to_task(struct task_struct *task)
53571+{
53572+ struct acl_object_label *obj;
53573+ char *tmpname;
53574+ struct acl_subject_label *tmpsubj;
53575+ struct file *filp;
53576+ struct name_entry *nmatch;
53577+
53578+ filp = task->exec_file;
53579+ if (filp == NULL)
53580+ return 0;
53581+
53582+ /* the following is to apply the correct subject
53583+ on binaries running when the RBAC system
53584+ is enabled, when the binaries have been
53585+ replaced or deleted since their execution
53586+ -----
53587+ when the RBAC system starts, the inode/dev
53588+ from exec_file will be one the RBAC system
53589+ is unaware of. It only knows the inode/dev
53590+ of the present file on disk, or the absence
53591+ of it.
53592+ */
53593+ preempt_disable();
53594+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
53595+
53596+ nmatch = lookup_name_entry(tmpname);
53597+ preempt_enable();
53598+ tmpsubj = NULL;
53599+ if (nmatch) {
53600+ if (nmatch->deleted)
53601+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
53602+ else
53603+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
53604+ if (tmpsubj != NULL)
53605+ task->acl = tmpsubj;
53606+ }
53607+ if (tmpsubj == NULL)
53608+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
53609+ task->role);
53610+ if (task->acl) {
53611+ task->is_writable = 0;
53612+ /* ignore additional mmap checks for processes that are writable
53613+ by the default ACL */
53614+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53615+ if (unlikely(obj->mode & GR_WRITE))
53616+ task->is_writable = 1;
53617+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53618+ if (unlikely(obj->mode & GR_WRITE))
53619+ task->is_writable = 1;
53620+
53621+ gr_set_proc_res(task);
53622+
53623+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53624+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53625+#endif
53626+ } else {
53627+ return 1;
53628+ }
53629+
53630+ return 0;
53631+}
53632+
53633+int
53634+gr_set_acls(const int type)
53635+{
53636+ struct task_struct *task, *task2;
53637+ struct acl_role_label *role = current->role;
53638+ __u16 acl_role_id = current->acl_role_id;
53639+ const struct cred *cred;
53640+ int ret;
53641+
53642+ rcu_read_lock();
53643+ read_lock(&tasklist_lock);
53644+ read_lock(&grsec_exec_file_lock);
53645+ do_each_thread(task2, task) {
53646+ /* check to see if we're called from the exit handler,
53647+ if so, only replace ACLs that have inherited the admin
53648+ ACL */
53649+
53650+ if (type && (task->role != role ||
53651+ task->acl_role_id != acl_role_id))
53652+ continue;
53653+
53654+ task->acl_role_id = 0;
53655+ task->acl_sp_role = 0;
53656+
53657+ if (task->exec_file) {
53658+ cred = __task_cred(task);
53659+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
53660+ ret = gr_apply_subject_to_task(task);
53661+ if (ret) {
53662+ read_unlock(&grsec_exec_file_lock);
53663+ read_unlock(&tasklist_lock);
53664+ rcu_read_unlock();
53665+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
53666+ return ret;
53667+ }
53668+ } else {
53669+ // it's a kernel process
53670+ task->role = kernel_role;
53671+ task->acl = kernel_role->root_label;
53672+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
53673+ task->acl->mode &= ~GR_PROCFIND;
53674+#endif
53675+ }
53676+ } while_each_thread(task2, task);
53677+ read_unlock(&grsec_exec_file_lock);
53678+ read_unlock(&tasklist_lock);
53679+ rcu_read_unlock();
53680+
53681+ return 0;
53682+}
53683+
53684+void
53685+gr_learn_resource(const struct task_struct *task,
53686+ const int res, const unsigned long wanted, const int gt)
53687+{
53688+ struct acl_subject_label *acl;
53689+ const struct cred *cred;
53690+
53691+ if (unlikely((gr_status & GR_READY) &&
53692+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
53693+ goto skip_reslog;
53694+
53695+#ifdef CONFIG_GRKERNSEC_RESLOG
53696+ gr_log_resource(task, res, wanted, gt);
53697+#endif
53698+ skip_reslog:
53699+
53700+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
53701+ return;
53702+
53703+ acl = task->acl;
53704+
53705+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
53706+ !(acl->resmask & (1 << (unsigned short) res))))
53707+ return;
53708+
53709+ if (wanted >= acl->res[res].rlim_cur) {
53710+ unsigned long res_add;
53711+
53712+ res_add = wanted;
53713+ switch (res) {
53714+ case RLIMIT_CPU:
53715+ res_add += GR_RLIM_CPU_BUMP;
53716+ break;
53717+ case RLIMIT_FSIZE:
53718+ res_add += GR_RLIM_FSIZE_BUMP;
53719+ break;
53720+ case RLIMIT_DATA:
53721+ res_add += GR_RLIM_DATA_BUMP;
53722+ break;
53723+ case RLIMIT_STACK:
53724+ res_add += GR_RLIM_STACK_BUMP;
53725+ break;
53726+ case RLIMIT_CORE:
53727+ res_add += GR_RLIM_CORE_BUMP;
53728+ break;
53729+ case RLIMIT_RSS:
53730+ res_add += GR_RLIM_RSS_BUMP;
53731+ break;
53732+ case RLIMIT_NPROC:
53733+ res_add += GR_RLIM_NPROC_BUMP;
53734+ break;
53735+ case RLIMIT_NOFILE:
53736+ res_add += GR_RLIM_NOFILE_BUMP;
53737+ break;
53738+ case RLIMIT_MEMLOCK:
53739+ res_add += GR_RLIM_MEMLOCK_BUMP;
53740+ break;
53741+ case RLIMIT_AS:
53742+ res_add += GR_RLIM_AS_BUMP;
53743+ break;
53744+ case RLIMIT_LOCKS:
53745+ res_add += GR_RLIM_LOCKS_BUMP;
53746+ break;
53747+ case RLIMIT_SIGPENDING:
53748+ res_add += GR_RLIM_SIGPENDING_BUMP;
53749+ break;
53750+ case RLIMIT_MSGQUEUE:
53751+ res_add += GR_RLIM_MSGQUEUE_BUMP;
53752+ break;
53753+ case RLIMIT_NICE:
53754+ res_add += GR_RLIM_NICE_BUMP;
53755+ break;
53756+ case RLIMIT_RTPRIO:
53757+ res_add += GR_RLIM_RTPRIO_BUMP;
53758+ break;
53759+ case RLIMIT_RTTIME:
53760+ res_add += GR_RLIM_RTTIME_BUMP;
53761+ break;
53762+ }
53763+
53764+ acl->res[res].rlim_cur = res_add;
53765+
53766+ if (wanted > acl->res[res].rlim_max)
53767+ acl->res[res].rlim_max = res_add;
53768+
53769+ /* only log the subject filename, since resource logging is supported for
53770+ single-subject learning only */
53771+ rcu_read_lock();
53772+ cred = __task_cred(task);
53773+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
53774+ task->role->roletype, cred->uid, cred->gid, acl->filename,
53775+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
53776+ "", (unsigned long) res, &task->signal->saved_ip);
53777+ rcu_read_unlock();
53778+ }
53779+
53780+ return;
53781+}
53782+
53783+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
53784+void
53785+pax_set_initial_flags(struct linux_binprm *bprm)
53786+{
53787+ struct task_struct *task = current;
53788+ struct acl_subject_label *proc;
53789+ unsigned long flags;
53790+
53791+ if (unlikely(!(gr_status & GR_READY)))
53792+ return;
53793+
53794+ flags = pax_get_flags(task);
53795+
53796+ proc = task->acl;
53797+
53798+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
53799+ flags &= ~MF_PAX_PAGEEXEC;
53800+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
53801+ flags &= ~MF_PAX_SEGMEXEC;
53802+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
53803+ flags &= ~MF_PAX_RANDMMAP;
53804+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
53805+ flags &= ~MF_PAX_EMUTRAMP;
53806+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
53807+ flags &= ~MF_PAX_MPROTECT;
53808+
53809+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
53810+ flags |= MF_PAX_PAGEEXEC;
53811+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
53812+ flags |= MF_PAX_SEGMEXEC;
53813+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
53814+ flags |= MF_PAX_RANDMMAP;
53815+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
53816+ flags |= MF_PAX_EMUTRAMP;
53817+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
53818+ flags |= MF_PAX_MPROTECT;
53819+
53820+ pax_set_flags(task, flags);
53821+
53822+ return;
53823+}
53824+#endif
53825+
53826+int
53827+gr_handle_proc_ptrace(struct task_struct *task)
53828+{
53829+ struct file *filp;
53830+ struct task_struct *tmp = task;
53831+ struct task_struct *curtemp = current;
53832+ __u32 retmode;
53833+
53834+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
53835+ if (unlikely(!(gr_status & GR_READY)))
53836+ return 0;
53837+#endif
53838+
53839+ read_lock(&tasklist_lock);
53840+ read_lock(&grsec_exec_file_lock);
53841+ filp = task->exec_file;
53842+
53843+ while (tmp->pid > 0) {
53844+ if (tmp == curtemp)
53845+ break;
53846+ tmp = tmp->real_parent;
53847+ }
53848+
53849+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
53850+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
53851+ read_unlock(&grsec_exec_file_lock);
53852+ read_unlock(&tasklist_lock);
53853+ return 1;
53854+ }
53855+
53856+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
53857+ if (!(gr_status & GR_READY)) {
53858+ read_unlock(&grsec_exec_file_lock);
53859+ read_unlock(&tasklist_lock);
53860+ return 0;
53861+ }
53862+#endif
53863+
53864+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
53865+ read_unlock(&grsec_exec_file_lock);
53866+ read_unlock(&tasklist_lock);
53867+
53868+ if (retmode & GR_NOPTRACE)
53869+ return 1;
53870+
53871+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
53872+ && (current->acl != task->acl || (current->acl != current->role->root_label
53873+ && current->pid != task->pid)))
53874+ return 1;
53875+
53876+ return 0;
53877+}
53878+
53879+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
53880+{
53881+ if (unlikely(!(gr_status & GR_READY)))
53882+ return;
53883+
53884+ if (!(current->role->roletype & GR_ROLE_GOD))
53885+ return;
53886+
53887+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
53888+ p->role->rolename, gr_task_roletype_to_char(p),
53889+ p->acl->filename);
53890+}
53891+
53892+int
53893+gr_handle_ptrace(struct task_struct *task, const long request)
53894+{
53895+ struct task_struct *tmp = task;
53896+ struct task_struct *curtemp = current;
53897+ __u32 retmode;
53898+
53899+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
53900+ if (unlikely(!(gr_status & GR_READY)))
53901+ return 0;
53902+#endif
53903+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
53904+ read_lock(&tasklist_lock);
53905+ while (tmp->pid > 0) {
53906+ if (tmp == curtemp)
53907+ break;
53908+ tmp = tmp->real_parent;
53909+ }
53910+
53911+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
53912+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
53913+ read_unlock(&tasklist_lock);
53914+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
53915+ return 1;
53916+ }
53917+ read_unlock(&tasklist_lock);
53918+ }
53919+
53920+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
53921+ if (!(gr_status & GR_READY))
53922+ return 0;
53923+#endif
53924+
53925+ read_lock(&grsec_exec_file_lock);
53926+ if (unlikely(!task->exec_file)) {
53927+ read_unlock(&grsec_exec_file_lock);
53928+ return 0;
53929+ }
53930+
53931+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
53932+ read_unlock(&grsec_exec_file_lock);
53933+
53934+ if (retmode & GR_NOPTRACE) {
53935+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
53936+ return 1;
53937+ }
53938+
53939+ if (retmode & GR_PTRACERD) {
53940+ switch (request) {
53941+ case PTRACE_SEIZE:
53942+ case PTRACE_POKETEXT:
53943+ case PTRACE_POKEDATA:
53944+ case PTRACE_POKEUSR:
53945+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
53946+ case PTRACE_SETREGS:
53947+ case PTRACE_SETFPREGS:
53948+#endif
53949+#ifdef CONFIG_X86
53950+ case PTRACE_SETFPXREGS:
53951+#endif
53952+#ifdef CONFIG_ALTIVEC
53953+ case PTRACE_SETVRREGS:
53954+#endif
53955+ return 1;
53956+ default:
53957+ return 0;
53958+ }
53959+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
53960+ !(current->role->roletype & GR_ROLE_GOD) &&
53961+ (current->acl != task->acl)) {
53962+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
53963+ return 1;
53964+ }
53965+
53966+ return 0;
53967+}
53968+
53969+static int is_writable_mmap(const struct file *filp)
53970+{
53971+ struct task_struct *task = current;
53972+ struct acl_object_label *obj, *obj2;
53973+
53974+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
53975+ !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))) {
53976+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53977+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
53978+ task->role->root_label);
53979+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
53980+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
53981+ return 1;
53982+ }
53983+ }
53984+ return 0;
53985+}
53986+
53987+int
53988+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
53989+{
53990+ __u32 mode;
53991+
53992+ if (unlikely(!file || !(prot & PROT_EXEC)))
53993+ return 1;
53994+
53995+ if (is_writable_mmap(file))
53996+ return 0;
53997+
53998+ mode =
53999+ gr_search_file(file->f_path.dentry,
54000+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54001+ file->f_path.mnt);
54002+
54003+ if (!gr_tpe_allow(file))
54004+ return 0;
54005+
54006+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54007+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54008+ return 0;
54009+ } else if (unlikely(!(mode & GR_EXEC))) {
54010+ return 0;
54011+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54012+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54013+ return 1;
54014+ }
54015+
54016+ return 1;
54017+}
54018+
54019+int
54020+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
54021+{
54022+ __u32 mode;
54023+
54024+ if (unlikely(!file || !(prot & PROT_EXEC)))
54025+ return 1;
54026+
54027+ if (is_writable_mmap(file))
54028+ return 0;
54029+
54030+ mode =
54031+ gr_search_file(file->f_path.dentry,
54032+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54033+ file->f_path.mnt);
54034+
54035+ if (!gr_tpe_allow(file))
54036+ return 0;
54037+
54038+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54039+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54040+ return 0;
54041+ } else if (unlikely(!(mode & GR_EXEC))) {
54042+ return 0;
54043+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54044+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54045+ return 1;
54046+ }
54047+
54048+ return 1;
54049+}
54050+
54051+void
54052+gr_acl_handle_psacct(struct task_struct *task, const long code)
54053+{
54054+ unsigned long runtime;
54055+ unsigned long cputime;
54056+ unsigned int wday, cday;
54057+ __u8 whr, chr;
54058+ __u8 wmin, cmin;
54059+ __u8 wsec, csec;
54060+ struct timespec timeval;
54061+
54062+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
54063+ !(task->acl->mode & GR_PROCACCT)))
54064+ return;
54065+
54066+ do_posix_clock_monotonic_gettime(&timeval);
54067+ runtime = timeval.tv_sec - task->start_time.tv_sec;
54068+ wday = runtime / (3600 * 24);
54069+ runtime -= wday * (3600 * 24);
54070+ whr = runtime / 3600;
54071+ runtime -= whr * 3600;
54072+ wmin = runtime / 60;
54073+ runtime -= wmin * 60;
54074+ wsec = runtime;
54075+
54076+ cputime = (task->utime + task->stime) / HZ;
54077+ cday = cputime / (3600 * 24);
54078+ cputime -= cday * (3600 * 24);
54079+ chr = cputime / 3600;
54080+ cputime -= chr * 3600;
54081+ cmin = cputime / 60;
54082+ cputime -= cmin * 60;
54083+ csec = cputime;
54084+
54085+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
54086+
54087+ return;
54088+}
54089+
54090+void gr_set_kernel_label(struct task_struct *task)
54091+{
54092+ if (gr_status & GR_READY) {
54093+ task->role = kernel_role;
54094+ task->acl = kernel_role->root_label;
54095+ }
54096+ return;
54097+}
54098+
54099+#ifdef CONFIG_TASKSTATS
54100+int gr_is_taskstats_denied(int pid)
54101+{
54102+ struct task_struct *task;
54103+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54104+ const struct cred *cred;
54105+#endif
54106+ int ret = 0;
54107+
54108+ /* restrict taskstats viewing to un-chrooted root users
54109+ who have the 'view' subject flag if the RBAC system is enabled
54110+ */
54111+
54112+ rcu_read_lock();
54113+ read_lock(&tasklist_lock);
54114+ task = find_task_by_vpid(pid);
54115+ if (task) {
54116+#ifdef CONFIG_GRKERNSEC_CHROOT
54117+ if (proc_is_chrooted(task))
54118+ ret = -EACCES;
54119+#endif
54120+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54121+ cred = __task_cred(task);
54122+#ifdef CONFIG_GRKERNSEC_PROC_USER
54123+ if (cred->uid != 0)
54124+ ret = -EACCES;
54125+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54126+ if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
54127+ ret = -EACCES;
54128+#endif
54129+#endif
54130+ if (gr_status & GR_READY) {
54131+ if (!(task->acl->mode & GR_VIEW))
54132+ ret = -EACCES;
54133+ }
54134+ } else
54135+ ret = -ENOENT;
54136+
54137+ read_unlock(&tasklist_lock);
54138+ rcu_read_unlock();
54139+
54140+ return ret;
54141+}
54142+#endif
54143+
54144+/* AUXV entries are filled via a descendant of search_binary_handler
54145+ after we've already applied the subject for the target
54146+*/
54147+int gr_acl_enable_at_secure(void)
54148+{
54149+ if (unlikely(!(gr_status & GR_READY)))
54150+ return 0;
54151+
54152+ if (current->acl->mode & GR_ATSECURE)
54153+ return 1;
54154+
54155+ return 0;
54156+}
54157+
54158+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
54159+{
54160+ struct task_struct *task = current;
54161+ struct dentry *dentry = file->f_path.dentry;
54162+ struct vfsmount *mnt = file->f_path.mnt;
54163+ struct acl_object_label *obj, *tmp;
54164+ struct acl_subject_label *subj;
54165+ unsigned int bufsize;
54166+ int is_not_root;
54167+ char *path;
54168+ dev_t dev = __get_dev(dentry);
54169+
54170+ if (unlikely(!(gr_status & GR_READY)))
54171+ return 1;
54172+
54173+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54174+ return 1;
54175+
54176+ /* ignore Eric Biederman */
54177+ if (IS_PRIVATE(dentry->d_inode))
54178+ return 1;
54179+
54180+ subj = task->acl;
54181+ do {
54182+ obj = lookup_acl_obj_label(ino, dev, subj);
54183+ if (obj != NULL)
54184+ return (obj->mode & GR_FIND) ? 1 : 0;
54185+ } while ((subj = subj->parent_subject));
54186+
54187+ /* this is purely an optimization since we're looking for an object
54188+ for the directory we're doing a readdir on
54189+ if it's possible for any globbed object to match the entry we're
54190+ filling into the directory, then the object we find here will be
54191+ an anchor point with attached globbed objects
54192+ */
54193+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
54194+ if (obj->globbed == NULL)
54195+ return (obj->mode & GR_FIND) ? 1 : 0;
54196+
54197+ is_not_root = ((obj->filename[0] == '/') &&
54198+ (obj->filename[1] == '\0')) ? 0 : 1;
54199+ bufsize = PAGE_SIZE - namelen - is_not_root;
54200+
54201+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
54202+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
54203+ return 1;
54204+
54205+ preempt_disable();
54206+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54207+ bufsize);
54208+
54209+ bufsize = strlen(path);
54210+
54211+ /* if base is "/", don't append an additional slash */
54212+ if (is_not_root)
54213+ *(path + bufsize) = '/';
54214+ memcpy(path + bufsize + is_not_root, name, namelen);
54215+ *(path + bufsize + namelen + is_not_root) = '\0';
54216+
54217+ tmp = obj->globbed;
54218+ while (tmp) {
54219+ if (!glob_match(tmp->filename, path)) {
54220+ preempt_enable();
54221+ return (tmp->mode & GR_FIND) ? 1 : 0;
54222+ }
54223+ tmp = tmp->next;
54224+ }
54225+ preempt_enable();
54226+ return (obj->mode & GR_FIND) ? 1 : 0;
54227+}
54228+
54229+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
54230+EXPORT_SYMBOL(gr_acl_is_enabled);
54231+#endif
54232+EXPORT_SYMBOL(gr_learn_resource);
54233+EXPORT_SYMBOL(gr_set_kernel_label);
54234+#ifdef CONFIG_SECURITY
54235+EXPORT_SYMBOL(gr_check_user_change);
54236+EXPORT_SYMBOL(gr_check_group_change);
54237+#endif
54238+
54239diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
54240new file mode 100644
54241index 0000000..34fefda
54242--- /dev/null
54243+++ b/grsecurity/gracl_alloc.c
54244@@ -0,0 +1,105 @@
54245+#include <linux/kernel.h>
54246+#include <linux/mm.h>
54247+#include <linux/slab.h>
54248+#include <linux/vmalloc.h>
54249+#include <linux/gracl.h>
54250+#include <linux/grsecurity.h>
54251+
54252+static unsigned long alloc_stack_next = 1;
54253+static unsigned long alloc_stack_size = 1;
54254+static void **alloc_stack;
54255+
54256+static __inline__ int
54257+alloc_pop(void)
54258+{
54259+ if (alloc_stack_next == 1)
54260+ return 0;
54261+
54262+ kfree(alloc_stack[alloc_stack_next - 2]);
54263+
54264+ alloc_stack_next--;
54265+
54266+ return 1;
54267+}
54268+
54269+static __inline__ int
54270+alloc_push(void *buf)
54271+{
54272+ if (alloc_stack_next >= alloc_stack_size)
54273+ return 1;
54274+
54275+ alloc_stack[alloc_stack_next - 1] = buf;
54276+
54277+ alloc_stack_next++;
54278+
54279+ return 0;
54280+}
54281+
54282+void *
54283+acl_alloc(unsigned long len)
54284+{
54285+ void *ret = NULL;
54286+
54287+ if (!len || len > PAGE_SIZE)
54288+ goto out;
54289+
54290+ ret = kmalloc(len, GFP_KERNEL);
54291+
54292+ if (ret) {
54293+ if (alloc_push(ret)) {
54294+ kfree(ret);
54295+ ret = NULL;
54296+ }
54297+ }
54298+
54299+out:
54300+ return ret;
54301+}
54302+
54303+void *
54304+acl_alloc_num(unsigned long num, unsigned long len)
54305+{
54306+ if (!len || (num > (PAGE_SIZE / len)))
54307+ return NULL;
54308+
54309+ return acl_alloc(num * len);
54310+}
54311+
54312+void
54313+acl_free_all(void)
54314+{
54315+ if (gr_acl_is_enabled() || !alloc_stack)
54316+ return;
54317+
54318+ while (alloc_pop()) ;
54319+
54320+ if (alloc_stack) {
54321+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
54322+ kfree(alloc_stack);
54323+ else
54324+ vfree(alloc_stack);
54325+ }
54326+
54327+ alloc_stack = NULL;
54328+ alloc_stack_size = 1;
54329+ alloc_stack_next = 1;
54330+
54331+ return;
54332+}
54333+
54334+int
54335+acl_alloc_stack_init(unsigned long size)
54336+{
54337+ if ((size * sizeof (void *)) <= PAGE_SIZE)
54338+ alloc_stack =
54339+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
54340+ else
54341+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
54342+
54343+ alloc_stack_size = size;
54344+
54345+ if (!alloc_stack)
54346+ return 0;
54347+ else
54348+ return 1;
54349+}
54350diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
54351new file mode 100644
54352index 0000000..6d21049
54353--- /dev/null
54354+++ b/grsecurity/gracl_cap.c
54355@@ -0,0 +1,110 @@
54356+#include <linux/kernel.h>
54357+#include <linux/module.h>
54358+#include <linux/sched.h>
54359+#include <linux/gracl.h>
54360+#include <linux/grsecurity.h>
54361+#include <linux/grinternal.h>
54362+
54363+extern const char *captab_log[];
54364+extern int captab_log_entries;
54365+
54366+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
54367+{
54368+ struct acl_subject_label *curracl;
54369+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54370+ kernel_cap_t cap_audit = __cap_empty_set;
54371+
54372+ if (!gr_acl_is_enabled())
54373+ return 1;
54374+
54375+ curracl = task->acl;
54376+
54377+ cap_drop = curracl->cap_lower;
54378+ cap_mask = curracl->cap_mask;
54379+ cap_audit = curracl->cap_invert_audit;
54380+
54381+ while ((curracl = curracl->parent_subject)) {
54382+ /* if the cap isn't specified in the current computed mask but is specified in the
54383+ current level subject, and is lowered in the current level subject, then add
54384+ it to the set of dropped capabilities
54385+ otherwise, add the current level subject's mask to the current computed mask
54386+ */
54387+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54388+ cap_raise(cap_mask, cap);
54389+ if (cap_raised(curracl->cap_lower, cap))
54390+ cap_raise(cap_drop, cap);
54391+ if (cap_raised(curracl->cap_invert_audit, cap))
54392+ cap_raise(cap_audit, cap);
54393+ }
54394+ }
54395+
54396+ if (!cap_raised(cap_drop, cap)) {
54397+ if (cap_raised(cap_audit, cap))
54398+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
54399+ return 1;
54400+ }
54401+
54402+ curracl = task->acl;
54403+
54404+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
54405+ && cap_raised(cred->cap_effective, cap)) {
54406+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54407+ task->role->roletype, cred->uid,
54408+ cred->gid, task->exec_file ?
54409+ gr_to_filename(task->exec_file->f_path.dentry,
54410+ task->exec_file->f_path.mnt) : curracl->filename,
54411+ curracl->filename, 0UL,
54412+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
54413+ return 1;
54414+ }
54415+
54416+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
54417+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
54418+
54419+ return 0;
54420+}
54421+
54422+int
54423+gr_acl_is_capable(const int cap)
54424+{
54425+ return gr_task_acl_is_capable(current, current_cred(), cap);
54426+}
54427+
54428+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
54429+{
54430+ struct acl_subject_label *curracl;
54431+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54432+
54433+ if (!gr_acl_is_enabled())
54434+ return 1;
54435+
54436+ curracl = task->acl;
54437+
54438+ cap_drop = curracl->cap_lower;
54439+ cap_mask = curracl->cap_mask;
54440+
54441+ while ((curracl = curracl->parent_subject)) {
54442+ /* if the cap isn't specified in the current computed mask but is specified in the
54443+ current level subject, and is lowered in the current level subject, then add
54444+ it to the set of dropped capabilities
54445+ otherwise, add the current level subject's mask to the current computed mask
54446+ */
54447+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54448+ cap_raise(cap_mask, cap);
54449+ if (cap_raised(curracl->cap_lower, cap))
54450+ cap_raise(cap_drop, cap);
54451+ }
54452+ }
54453+
54454+ if (!cap_raised(cap_drop, cap))
54455+ return 1;
54456+
54457+ return 0;
54458+}
54459+
54460+int
54461+gr_acl_is_capable_nolog(const int cap)
54462+{
54463+ return gr_task_acl_is_capable_nolog(current, cap);
54464+}
54465+
54466diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
54467new file mode 100644
54468index 0000000..88d0e87
54469--- /dev/null
54470+++ b/grsecurity/gracl_fs.c
54471@@ -0,0 +1,435 @@
54472+#include <linux/kernel.h>
54473+#include <linux/sched.h>
54474+#include <linux/types.h>
54475+#include <linux/fs.h>
54476+#include <linux/file.h>
54477+#include <linux/stat.h>
54478+#include <linux/grsecurity.h>
54479+#include <linux/grinternal.h>
54480+#include <linux/gracl.h>
54481+
54482+umode_t
54483+gr_acl_umask(void)
54484+{
54485+ if (unlikely(!gr_acl_is_enabled()))
54486+ return 0;
54487+
54488+ return current->role->umask;
54489+}
54490+
54491+__u32
54492+gr_acl_handle_hidden_file(const struct dentry * dentry,
54493+ const struct vfsmount * mnt)
54494+{
54495+ __u32 mode;
54496+
54497+ if (unlikely(!dentry->d_inode))
54498+ return GR_FIND;
54499+
54500+ mode =
54501+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
54502+
54503+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
54504+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
54505+ return mode;
54506+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
54507+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
54508+ return 0;
54509+ } else if (unlikely(!(mode & GR_FIND)))
54510+ return 0;
54511+
54512+ return GR_FIND;
54513+}
54514+
54515+__u32
54516+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
54517+ int acc_mode)
54518+{
54519+ __u32 reqmode = GR_FIND;
54520+ __u32 mode;
54521+
54522+ if (unlikely(!dentry->d_inode))
54523+ return reqmode;
54524+
54525+ if (acc_mode & MAY_APPEND)
54526+ reqmode |= GR_APPEND;
54527+ else if (acc_mode & MAY_WRITE)
54528+ reqmode |= GR_WRITE;
54529+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
54530+ reqmode |= GR_READ;
54531+
54532+ mode =
54533+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
54534+ mnt);
54535+
54536+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54537+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
54538+ reqmode & GR_READ ? " reading" : "",
54539+ reqmode & GR_WRITE ? " writing" : reqmode &
54540+ GR_APPEND ? " appending" : "");
54541+ return reqmode;
54542+ } else
54543+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54544+ {
54545+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
54546+ reqmode & GR_READ ? " reading" : "",
54547+ reqmode & GR_WRITE ? " writing" : reqmode &
54548+ GR_APPEND ? " appending" : "");
54549+ return 0;
54550+ } else if (unlikely((mode & reqmode) != reqmode))
54551+ return 0;
54552+
54553+ return reqmode;
54554+}
54555+
54556+__u32
54557+gr_acl_handle_creat(const struct dentry * dentry,
54558+ const struct dentry * p_dentry,
54559+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
54560+ const int imode)
54561+{
54562+ __u32 reqmode = GR_WRITE | GR_CREATE;
54563+ __u32 mode;
54564+
54565+ if (acc_mode & MAY_APPEND)
54566+ reqmode |= GR_APPEND;
54567+ // if a directory was required or the directory already exists, then
54568+ // don't count this open as a read
54569+ if ((acc_mode & MAY_READ) &&
54570+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
54571+ reqmode |= GR_READ;
54572+ if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
54573+ reqmode |= GR_SETID;
54574+
54575+ mode =
54576+ gr_check_create(dentry, p_dentry, p_mnt,
54577+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
54578+
54579+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54580+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
54581+ reqmode & GR_READ ? " reading" : "",
54582+ reqmode & GR_WRITE ? " writing" : reqmode &
54583+ GR_APPEND ? " appending" : "");
54584+ return reqmode;
54585+ } else
54586+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54587+ {
54588+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
54589+ reqmode & GR_READ ? " reading" : "",
54590+ reqmode & GR_WRITE ? " writing" : reqmode &
54591+ GR_APPEND ? " appending" : "");
54592+ return 0;
54593+ } else if (unlikely((mode & reqmode) != reqmode))
54594+ return 0;
54595+
54596+ return reqmode;
54597+}
54598+
54599+__u32
54600+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
54601+ const int fmode)
54602+{
54603+ __u32 mode, reqmode = GR_FIND;
54604+
54605+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
54606+ reqmode |= GR_EXEC;
54607+ if (fmode & S_IWOTH)
54608+ reqmode |= GR_WRITE;
54609+ if (fmode & S_IROTH)
54610+ reqmode |= GR_READ;
54611+
54612+ mode =
54613+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
54614+ mnt);
54615+
54616+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54617+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
54618+ reqmode & GR_READ ? " reading" : "",
54619+ reqmode & GR_WRITE ? " writing" : "",
54620+ reqmode & GR_EXEC ? " executing" : "");
54621+ return reqmode;
54622+ } else
54623+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54624+ {
54625+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
54626+ reqmode & GR_READ ? " reading" : "",
54627+ reqmode & GR_WRITE ? " writing" : "",
54628+ reqmode & GR_EXEC ? " executing" : "");
54629+ return 0;
54630+ } else if (unlikely((mode & reqmode) != reqmode))
54631+ return 0;
54632+
54633+ return reqmode;
54634+}
54635+
54636+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
54637+{
54638+ __u32 mode;
54639+
54640+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
54641+
54642+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
54643+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
54644+ return mode;
54645+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
54646+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
54647+ return 0;
54648+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
54649+ return 0;
54650+
54651+ return (reqmode);
54652+}
54653+
54654+__u32
54655+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
54656+{
54657+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
54658+}
54659+
54660+__u32
54661+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
54662+{
54663+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
54664+}
54665+
54666+__u32
54667+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
54668+{
54669+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
54670+}
54671+
54672+__u32
54673+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
54674+{
54675+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
54676+}
54677+
54678+__u32
54679+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
54680+ umode_t *modeptr)
54681+{
54682+ umode_t mode;
54683+
54684+ *modeptr &= ~gr_acl_umask();
54685+ mode = *modeptr;
54686+
54687+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
54688+ return 1;
54689+
54690+ if (unlikely(mode & (S_ISUID | S_ISGID))) {
54691+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
54692+ GR_CHMOD_ACL_MSG);
54693+ } else {
54694+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
54695+ }
54696+}
54697+
54698+__u32
54699+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
54700+{
54701+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
54702+}
54703+
54704+__u32
54705+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
54706+{
54707+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
54708+}
54709+
54710+__u32
54711+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
54712+{
54713+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
54714+}
54715+
54716+__u32
54717+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
54718+{
54719+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
54720+ GR_UNIXCONNECT_ACL_MSG);
54721+}
54722+
54723+/* hardlinks require at minimum create and link permission,
54724+ any additional privilege required is based on the
54725+ privilege of the file being linked to
54726+*/
54727+__u32
54728+gr_acl_handle_link(const struct dentry * new_dentry,
54729+ const struct dentry * parent_dentry,
54730+ const struct vfsmount * parent_mnt,
54731+ const struct dentry * old_dentry,
54732+ const struct vfsmount * old_mnt, const char *to)
54733+{
54734+ __u32 mode;
54735+ __u32 needmode = GR_CREATE | GR_LINK;
54736+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
54737+
54738+ mode =
54739+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
54740+ old_mnt);
54741+
54742+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
54743+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
54744+ return mode;
54745+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
54746+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
54747+ return 0;
54748+ } else if (unlikely((mode & needmode) != needmode))
54749+ return 0;
54750+
54751+ return 1;
54752+}
54753+
54754+__u32
54755+gr_acl_handle_symlink(const struct dentry * new_dentry,
54756+ const struct dentry * parent_dentry,
54757+ const struct vfsmount * parent_mnt, const char *from)
54758+{
54759+ __u32 needmode = GR_WRITE | GR_CREATE;
54760+ __u32 mode;
54761+
54762+ mode =
54763+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
54764+ GR_CREATE | GR_AUDIT_CREATE |
54765+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
54766+
54767+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
54768+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
54769+ return mode;
54770+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
54771+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
54772+ return 0;
54773+ } else if (unlikely((mode & needmode) != needmode))
54774+ return 0;
54775+
54776+ return (GR_WRITE | GR_CREATE);
54777+}
54778+
54779+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)
54780+{
54781+ __u32 mode;
54782+
54783+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
54784+
54785+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
54786+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
54787+ return mode;
54788+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
54789+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
54790+ return 0;
54791+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
54792+ return 0;
54793+
54794+ return (reqmode);
54795+}
54796+
54797+__u32
54798+gr_acl_handle_mknod(const struct dentry * new_dentry,
54799+ const struct dentry * parent_dentry,
54800+ const struct vfsmount * parent_mnt,
54801+ const int mode)
54802+{
54803+ __u32 reqmode = GR_WRITE | GR_CREATE;
54804+ if (unlikely(mode & (S_ISUID | S_ISGID)))
54805+ reqmode |= GR_SETID;
54806+
54807+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
54808+ reqmode, GR_MKNOD_ACL_MSG);
54809+}
54810+
54811+__u32
54812+gr_acl_handle_mkdir(const struct dentry *new_dentry,
54813+ const struct dentry *parent_dentry,
54814+ const struct vfsmount *parent_mnt)
54815+{
54816+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
54817+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
54818+}
54819+
54820+#define RENAME_CHECK_SUCCESS(old, new) \
54821+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
54822+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
54823+
54824+int
54825+gr_acl_handle_rename(struct dentry *new_dentry,
54826+ struct dentry *parent_dentry,
54827+ const struct vfsmount *parent_mnt,
54828+ struct dentry *old_dentry,
54829+ struct inode *old_parent_inode,
54830+ struct vfsmount *old_mnt, const char *newname)
54831+{
54832+ __u32 comp1, comp2;
54833+ int error = 0;
54834+
54835+ if (unlikely(!gr_acl_is_enabled()))
54836+ return 0;
54837+
54838+ if (!new_dentry->d_inode) {
54839+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
54840+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
54841+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
54842+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
54843+ GR_DELETE | GR_AUDIT_DELETE |
54844+ GR_AUDIT_READ | GR_AUDIT_WRITE |
54845+ GR_SUPPRESS, old_mnt);
54846+ } else {
54847+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
54848+ GR_CREATE | GR_DELETE |
54849+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
54850+ GR_AUDIT_READ | GR_AUDIT_WRITE |
54851+ GR_SUPPRESS, parent_mnt);
54852+ comp2 =
54853+ gr_search_file(old_dentry,
54854+ GR_READ | GR_WRITE | GR_AUDIT_READ |
54855+ GR_DELETE | GR_AUDIT_DELETE |
54856+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
54857+ }
54858+
54859+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
54860+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
54861+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
54862+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
54863+ && !(comp2 & GR_SUPPRESS)) {
54864+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
54865+ error = -EACCES;
54866+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
54867+ error = -EACCES;
54868+
54869+ return error;
54870+}
54871+
54872+void
54873+gr_acl_handle_exit(void)
54874+{
54875+ u16 id;
54876+ char *rolename;
54877+ struct file *exec_file;
54878+
54879+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
54880+ !(current->role->roletype & GR_ROLE_PERSIST))) {
54881+ id = current->acl_role_id;
54882+ rolename = current->role->rolename;
54883+ gr_set_acls(1);
54884+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
54885+ }
54886+
54887+ write_lock(&grsec_exec_file_lock);
54888+ exec_file = current->exec_file;
54889+ current->exec_file = NULL;
54890+ write_unlock(&grsec_exec_file_lock);
54891+
54892+ if (exec_file)
54893+ fput(exec_file);
54894+}
54895+
54896+int
54897+gr_acl_handle_procpidmem(const struct task_struct *task)
54898+{
54899+ if (unlikely(!gr_acl_is_enabled()))
54900+ return 0;
54901+
54902+ if (task != current && task->acl->mode & GR_PROTPROCFD)
54903+ return -EACCES;
54904+
54905+ return 0;
54906+}
54907diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
54908new file mode 100644
54909index 0000000..58800a7
54910--- /dev/null
54911+++ b/grsecurity/gracl_ip.c
54912@@ -0,0 +1,384 @@
54913+#include <linux/kernel.h>
54914+#include <asm/uaccess.h>
54915+#include <asm/errno.h>
54916+#include <net/sock.h>
54917+#include <linux/file.h>
54918+#include <linux/fs.h>
54919+#include <linux/net.h>
54920+#include <linux/in.h>
54921+#include <linux/skbuff.h>
54922+#include <linux/ip.h>
54923+#include <linux/udp.h>
54924+#include <linux/types.h>
54925+#include <linux/sched.h>
54926+#include <linux/netdevice.h>
54927+#include <linux/inetdevice.h>
54928+#include <linux/gracl.h>
54929+#include <linux/grsecurity.h>
54930+#include <linux/grinternal.h>
54931+
54932+#define GR_BIND 0x01
54933+#define GR_CONNECT 0x02
54934+#define GR_INVERT 0x04
54935+#define GR_BINDOVERRIDE 0x08
54936+#define GR_CONNECTOVERRIDE 0x10
54937+#define GR_SOCK_FAMILY 0x20
54938+
54939+static const char * gr_protocols[IPPROTO_MAX] = {
54940+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
54941+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
54942+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
54943+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
54944+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
54945+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
54946+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
54947+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
54948+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
54949+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
54950+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
54951+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
54952+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
54953+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
54954+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
54955+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
54956+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
54957+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
54958+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
54959+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
54960+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
54961+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
54962+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
54963+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
54964+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
54965+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
54966+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
54967+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
54968+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
54969+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
54970+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
54971+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
54972+ };
54973+
54974+static const char * gr_socktypes[SOCK_MAX] = {
54975+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
54976+ "unknown:7", "unknown:8", "unknown:9", "packet"
54977+ };
54978+
54979+static const char * gr_sockfamilies[AF_MAX+1] = {
54980+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
54981+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
54982+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
54983+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
54984+ };
54985+
54986+const char *
54987+gr_proto_to_name(unsigned char proto)
54988+{
54989+ return gr_protocols[proto];
54990+}
54991+
54992+const char *
54993+gr_socktype_to_name(unsigned char type)
54994+{
54995+ return gr_socktypes[type];
54996+}
54997+
54998+const char *
54999+gr_sockfamily_to_name(unsigned char family)
55000+{
55001+ return gr_sockfamilies[family];
55002+}
55003+
55004+int
55005+gr_search_socket(const int domain, const int type, const int protocol)
55006+{
55007+ struct acl_subject_label *curr;
55008+ const struct cred *cred = current_cred();
55009+
55010+ if (unlikely(!gr_acl_is_enabled()))
55011+ goto exit;
55012+
55013+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
55014+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
55015+ goto exit; // let the kernel handle it
55016+
55017+ curr = current->acl;
55018+
55019+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
55020+ /* the family is allowed, if this is PF_INET allow it only if
55021+ the extra sock type/protocol checks pass */
55022+ if (domain == PF_INET)
55023+ goto inet_check;
55024+ goto exit;
55025+ } else {
55026+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55027+ __u32 fakeip = 0;
55028+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55029+ current->role->roletype, cred->uid,
55030+ cred->gid, current->exec_file ?
55031+ gr_to_filename(current->exec_file->f_path.dentry,
55032+ current->exec_file->f_path.mnt) :
55033+ curr->filename, curr->filename,
55034+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
55035+ &current->signal->saved_ip);
55036+ goto exit;
55037+ }
55038+ goto exit_fail;
55039+ }
55040+
55041+inet_check:
55042+ /* the rest of this checking is for IPv4 only */
55043+ if (!curr->ips)
55044+ goto exit;
55045+
55046+ if ((curr->ip_type & (1 << type)) &&
55047+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
55048+ goto exit;
55049+
55050+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55051+ /* we don't place acls on raw sockets , and sometimes
55052+ dgram/ip sockets are opened for ioctl and not
55053+ bind/connect, so we'll fake a bind learn log */
55054+ if (type == SOCK_RAW || type == SOCK_PACKET) {
55055+ __u32 fakeip = 0;
55056+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55057+ current->role->roletype, cred->uid,
55058+ cred->gid, current->exec_file ?
55059+ gr_to_filename(current->exec_file->f_path.dentry,
55060+ current->exec_file->f_path.mnt) :
55061+ curr->filename, curr->filename,
55062+ &fakeip, 0, type,
55063+ protocol, GR_CONNECT, &current->signal->saved_ip);
55064+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
55065+ __u32 fakeip = 0;
55066+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55067+ current->role->roletype, cred->uid,
55068+ cred->gid, current->exec_file ?
55069+ gr_to_filename(current->exec_file->f_path.dentry,
55070+ current->exec_file->f_path.mnt) :
55071+ curr->filename, curr->filename,
55072+ &fakeip, 0, type,
55073+ protocol, GR_BIND, &current->signal->saved_ip);
55074+ }
55075+ /* we'll log when they use connect or bind */
55076+ goto exit;
55077+ }
55078+
55079+exit_fail:
55080+ if (domain == PF_INET)
55081+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
55082+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
55083+ else
55084+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
55085+ gr_socktype_to_name(type), protocol);
55086+
55087+ return 0;
55088+exit:
55089+ return 1;
55090+}
55091+
55092+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)
55093+{
55094+ if ((ip->mode & mode) &&
55095+ (ip_port >= ip->low) &&
55096+ (ip_port <= ip->high) &&
55097+ ((ntohl(ip_addr) & our_netmask) ==
55098+ (ntohl(our_addr) & our_netmask))
55099+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
55100+ && (ip->type & (1 << type))) {
55101+ if (ip->mode & GR_INVERT)
55102+ return 2; // specifically denied
55103+ else
55104+ return 1; // allowed
55105+ }
55106+
55107+ return 0; // not specifically allowed, may continue parsing
55108+}
55109+
55110+static int
55111+gr_search_connectbind(const int full_mode, struct sock *sk,
55112+ struct sockaddr_in *addr, const int type)
55113+{
55114+ char iface[IFNAMSIZ] = {0};
55115+ struct acl_subject_label *curr;
55116+ struct acl_ip_label *ip;
55117+ struct inet_sock *isk;
55118+ struct net_device *dev;
55119+ struct in_device *idev;
55120+ unsigned long i;
55121+ int ret;
55122+ int mode = full_mode & (GR_BIND | GR_CONNECT);
55123+ __u32 ip_addr = 0;
55124+ __u32 our_addr;
55125+ __u32 our_netmask;
55126+ char *p;
55127+ __u16 ip_port = 0;
55128+ const struct cred *cred = current_cred();
55129+
55130+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
55131+ return 0;
55132+
55133+ curr = current->acl;
55134+ isk = inet_sk(sk);
55135+
55136+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
55137+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
55138+ addr->sin_addr.s_addr = curr->inaddr_any_override;
55139+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
55140+ struct sockaddr_in saddr;
55141+ int err;
55142+
55143+ saddr.sin_family = AF_INET;
55144+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
55145+ saddr.sin_port = isk->inet_sport;
55146+
55147+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55148+ if (err)
55149+ return err;
55150+
55151+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55152+ if (err)
55153+ return err;
55154+ }
55155+
55156+ if (!curr->ips)
55157+ return 0;
55158+
55159+ ip_addr = addr->sin_addr.s_addr;
55160+ ip_port = ntohs(addr->sin_port);
55161+
55162+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55163+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55164+ current->role->roletype, cred->uid,
55165+ cred->gid, current->exec_file ?
55166+ gr_to_filename(current->exec_file->f_path.dentry,
55167+ current->exec_file->f_path.mnt) :
55168+ curr->filename, curr->filename,
55169+ &ip_addr, ip_port, type,
55170+ sk->sk_protocol, mode, &current->signal->saved_ip);
55171+ return 0;
55172+ }
55173+
55174+ for (i = 0; i < curr->ip_num; i++) {
55175+ ip = *(curr->ips + i);
55176+ if (ip->iface != NULL) {
55177+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
55178+ p = strchr(iface, ':');
55179+ if (p != NULL)
55180+ *p = '\0';
55181+ dev = dev_get_by_name(sock_net(sk), iface);
55182+ if (dev == NULL)
55183+ continue;
55184+ idev = in_dev_get(dev);
55185+ if (idev == NULL) {
55186+ dev_put(dev);
55187+ continue;
55188+ }
55189+ rcu_read_lock();
55190+ for_ifa(idev) {
55191+ if (!strcmp(ip->iface, ifa->ifa_label)) {
55192+ our_addr = ifa->ifa_address;
55193+ our_netmask = 0xffffffff;
55194+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55195+ if (ret == 1) {
55196+ rcu_read_unlock();
55197+ in_dev_put(idev);
55198+ dev_put(dev);
55199+ return 0;
55200+ } else if (ret == 2) {
55201+ rcu_read_unlock();
55202+ in_dev_put(idev);
55203+ dev_put(dev);
55204+ goto denied;
55205+ }
55206+ }
55207+ } endfor_ifa(idev);
55208+ rcu_read_unlock();
55209+ in_dev_put(idev);
55210+ dev_put(dev);
55211+ } else {
55212+ our_addr = ip->addr;
55213+ our_netmask = ip->netmask;
55214+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55215+ if (ret == 1)
55216+ return 0;
55217+ else if (ret == 2)
55218+ goto denied;
55219+ }
55220+ }
55221+
55222+denied:
55223+ if (mode == GR_BIND)
55224+ 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));
55225+ else if (mode == GR_CONNECT)
55226+ 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));
55227+
55228+ return -EACCES;
55229+}
55230+
55231+int
55232+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
55233+{
55234+ /* always allow disconnection of dgram sockets with connect */
55235+ if (addr->sin_family == AF_UNSPEC)
55236+ return 0;
55237+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
55238+}
55239+
55240+int
55241+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
55242+{
55243+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
55244+}
55245+
55246+int gr_search_listen(struct socket *sock)
55247+{
55248+ struct sock *sk = sock->sk;
55249+ struct sockaddr_in addr;
55250+
55251+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55252+ addr.sin_port = inet_sk(sk)->inet_sport;
55253+
55254+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55255+}
55256+
55257+int gr_search_accept(struct socket *sock)
55258+{
55259+ struct sock *sk = sock->sk;
55260+ struct sockaddr_in addr;
55261+
55262+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55263+ addr.sin_port = inet_sk(sk)->inet_sport;
55264+
55265+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55266+}
55267+
55268+int
55269+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
55270+{
55271+ if (addr)
55272+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
55273+ else {
55274+ struct sockaddr_in sin;
55275+ const struct inet_sock *inet = inet_sk(sk);
55276+
55277+ sin.sin_addr.s_addr = inet->inet_daddr;
55278+ sin.sin_port = inet->inet_dport;
55279+
55280+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55281+ }
55282+}
55283+
55284+int
55285+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
55286+{
55287+ struct sockaddr_in sin;
55288+
55289+ if (unlikely(skb->len < sizeof (struct udphdr)))
55290+ return 0; // skip this packet
55291+
55292+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
55293+ sin.sin_port = udp_hdr(skb)->source;
55294+
55295+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55296+}
55297diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
55298new file mode 100644
55299index 0000000..25f54ef
55300--- /dev/null
55301+++ b/grsecurity/gracl_learn.c
55302@@ -0,0 +1,207 @@
55303+#include <linux/kernel.h>
55304+#include <linux/mm.h>
55305+#include <linux/sched.h>
55306+#include <linux/poll.h>
55307+#include <linux/string.h>
55308+#include <linux/file.h>
55309+#include <linux/types.h>
55310+#include <linux/vmalloc.h>
55311+#include <linux/grinternal.h>
55312+
55313+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
55314+ size_t count, loff_t *ppos);
55315+extern int gr_acl_is_enabled(void);
55316+
55317+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
55318+static int gr_learn_attached;
55319+
55320+/* use a 512k buffer */
55321+#define LEARN_BUFFER_SIZE (512 * 1024)
55322+
55323+static DEFINE_SPINLOCK(gr_learn_lock);
55324+static DEFINE_MUTEX(gr_learn_user_mutex);
55325+
55326+/* we need to maintain two buffers, so that the kernel context of grlearn
55327+ uses a semaphore around the userspace copying, and the other kernel contexts
55328+ use a spinlock when copying into the buffer, since they cannot sleep
55329+*/
55330+static char *learn_buffer;
55331+static char *learn_buffer_user;
55332+static int learn_buffer_len;
55333+static int learn_buffer_user_len;
55334+
55335+static ssize_t
55336+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
55337+{
55338+ DECLARE_WAITQUEUE(wait, current);
55339+ ssize_t retval = 0;
55340+
55341+ add_wait_queue(&learn_wait, &wait);
55342+ set_current_state(TASK_INTERRUPTIBLE);
55343+ do {
55344+ mutex_lock(&gr_learn_user_mutex);
55345+ spin_lock(&gr_learn_lock);
55346+ if (learn_buffer_len)
55347+ break;
55348+ spin_unlock(&gr_learn_lock);
55349+ mutex_unlock(&gr_learn_user_mutex);
55350+ if (file->f_flags & O_NONBLOCK) {
55351+ retval = -EAGAIN;
55352+ goto out;
55353+ }
55354+ if (signal_pending(current)) {
55355+ retval = -ERESTARTSYS;
55356+ goto out;
55357+ }
55358+
55359+ schedule();
55360+ } while (1);
55361+
55362+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
55363+ learn_buffer_user_len = learn_buffer_len;
55364+ retval = learn_buffer_len;
55365+ learn_buffer_len = 0;
55366+
55367+ spin_unlock(&gr_learn_lock);
55368+
55369+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
55370+ retval = -EFAULT;
55371+
55372+ mutex_unlock(&gr_learn_user_mutex);
55373+out:
55374+ set_current_state(TASK_RUNNING);
55375+ remove_wait_queue(&learn_wait, &wait);
55376+ return retval;
55377+}
55378+
55379+static unsigned int
55380+poll_learn(struct file * file, poll_table * wait)
55381+{
55382+ poll_wait(file, &learn_wait, wait);
55383+
55384+ if (learn_buffer_len)
55385+ return (POLLIN | POLLRDNORM);
55386+
55387+ return 0;
55388+}
55389+
55390+void
55391+gr_clear_learn_entries(void)
55392+{
55393+ char *tmp;
55394+
55395+ mutex_lock(&gr_learn_user_mutex);
55396+ spin_lock(&gr_learn_lock);
55397+ tmp = learn_buffer;
55398+ learn_buffer = NULL;
55399+ spin_unlock(&gr_learn_lock);
55400+ if (tmp)
55401+ vfree(tmp);
55402+ if (learn_buffer_user != NULL) {
55403+ vfree(learn_buffer_user);
55404+ learn_buffer_user = NULL;
55405+ }
55406+ learn_buffer_len = 0;
55407+ mutex_unlock(&gr_learn_user_mutex);
55408+
55409+ return;
55410+}
55411+
55412+void
55413+gr_add_learn_entry(const char *fmt, ...)
55414+{
55415+ va_list args;
55416+ unsigned int len;
55417+
55418+ if (!gr_learn_attached)
55419+ return;
55420+
55421+ spin_lock(&gr_learn_lock);
55422+
55423+ /* leave a gap at the end so we know when it's "full" but don't have to
55424+ compute the exact length of the string we're trying to append
55425+ */
55426+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
55427+ spin_unlock(&gr_learn_lock);
55428+ wake_up_interruptible(&learn_wait);
55429+ return;
55430+ }
55431+ if (learn_buffer == NULL) {
55432+ spin_unlock(&gr_learn_lock);
55433+ return;
55434+ }
55435+
55436+ va_start(args, fmt);
55437+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
55438+ va_end(args);
55439+
55440+ learn_buffer_len += len + 1;
55441+
55442+ spin_unlock(&gr_learn_lock);
55443+ wake_up_interruptible(&learn_wait);
55444+
55445+ return;
55446+}
55447+
55448+static int
55449+open_learn(struct inode *inode, struct file *file)
55450+{
55451+ if (file->f_mode & FMODE_READ && gr_learn_attached)
55452+ return -EBUSY;
55453+ if (file->f_mode & FMODE_READ) {
55454+ int retval = 0;
55455+ mutex_lock(&gr_learn_user_mutex);
55456+ if (learn_buffer == NULL)
55457+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
55458+ if (learn_buffer_user == NULL)
55459+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
55460+ if (learn_buffer == NULL) {
55461+ retval = -ENOMEM;
55462+ goto out_error;
55463+ }
55464+ if (learn_buffer_user == NULL) {
55465+ retval = -ENOMEM;
55466+ goto out_error;
55467+ }
55468+ learn_buffer_len = 0;
55469+ learn_buffer_user_len = 0;
55470+ gr_learn_attached = 1;
55471+out_error:
55472+ mutex_unlock(&gr_learn_user_mutex);
55473+ return retval;
55474+ }
55475+ return 0;
55476+}
55477+
55478+static int
55479+close_learn(struct inode *inode, struct file *file)
55480+{
55481+ if (file->f_mode & FMODE_READ) {
55482+ char *tmp = NULL;
55483+ mutex_lock(&gr_learn_user_mutex);
55484+ spin_lock(&gr_learn_lock);
55485+ tmp = learn_buffer;
55486+ learn_buffer = NULL;
55487+ spin_unlock(&gr_learn_lock);
55488+ if (tmp)
55489+ vfree(tmp);
55490+ if (learn_buffer_user != NULL) {
55491+ vfree(learn_buffer_user);
55492+ learn_buffer_user = NULL;
55493+ }
55494+ learn_buffer_len = 0;
55495+ learn_buffer_user_len = 0;
55496+ gr_learn_attached = 0;
55497+ mutex_unlock(&gr_learn_user_mutex);
55498+ }
55499+
55500+ return 0;
55501+}
55502+
55503+const struct file_operations grsec_fops = {
55504+ .read = read_learn,
55505+ .write = write_grsec_handler,
55506+ .open = open_learn,
55507+ .release = close_learn,
55508+ .poll = poll_learn,
55509+};
55510diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
55511new file mode 100644
55512index 0000000..39645c9
55513--- /dev/null
55514+++ b/grsecurity/gracl_res.c
55515@@ -0,0 +1,68 @@
55516+#include <linux/kernel.h>
55517+#include <linux/sched.h>
55518+#include <linux/gracl.h>
55519+#include <linux/grinternal.h>
55520+
55521+static const char *restab_log[] = {
55522+ [RLIMIT_CPU] = "RLIMIT_CPU",
55523+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
55524+ [RLIMIT_DATA] = "RLIMIT_DATA",
55525+ [RLIMIT_STACK] = "RLIMIT_STACK",
55526+ [RLIMIT_CORE] = "RLIMIT_CORE",
55527+ [RLIMIT_RSS] = "RLIMIT_RSS",
55528+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
55529+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
55530+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
55531+ [RLIMIT_AS] = "RLIMIT_AS",
55532+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
55533+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
55534+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
55535+ [RLIMIT_NICE] = "RLIMIT_NICE",
55536+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
55537+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
55538+ [GR_CRASH_RES] = "RLIMIT_CRASH"
55539+};
55540+
55541+void
55542+gr_log_resource(const struct task_struct *task,
55543+ const int res, const unsigned long wanted, const int gt)
55544+{
55545+ const struct cred *cred;
55546+ unsigned long rlim;
55547+
55548+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
55549+ return;
55550+
55551+ // not yet supported resource
55552+ if (unlikely(!restab_log[res]))
55553+ return;
55554+
55555+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
55556+ rlim = task_rlimit_max(task, res);
55557+ else
55558+ rlim = task_rlimit(task, res);
55559+
55560+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
55561+ return;
55562+
55563+ rcu_read_lock();
55564+ cred = __task_cred(task);
55565+
55566+ if (res == RLIMIT_NPROC &&
55567+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
55568+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
55569+ goto out_rcu_unlock;
55570+ else if (res == RLIMIT_MEMLOCK &&
55571+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
55572+ goto out_rcu_unlock;
55573+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
55574+ goto out_rcu_unlock;
55575+ rcu_read_unlock();
55576+
55577+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
55578+
55579+ return;
55580+out_rcu_unlock:
55581+ rcu_read_unlock();
55582+ return;
55583+}
55584diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
55585new file mode 100644
55586index 0000000..5556be3
55587--- /dev/null
55588+++ b/grsecurity/gracl_segv.c
55589@@ -0,0 +1,299 @@
55590+#include <linux/kernel.h>
55591+#include <linux/mm.h>
55592+#include <asm/uaccess.h>
55593+#include <asm/errno.h>
55594+#include <asm/mman.h>
55595+#include <net/sock.h>
55596+#include <linux/file.h>
55597+#include <linux/fs.h>
55598+#include <linux/net.h>
55599+#include <linux/in.h>
55600+#include <linux/slab.h>
55601+#include <linux/types.h>
55602+#include <linux/sched.h>
55603+#include <linux/timer.h>
55604+#include <linux/gracl.h>
55605+#include <linux/grsecurity.h>
55606+#include <linux/grinternal.h>
55607+
55608+static struct crash_uid *uid_set;
55609+static unsigned short uid_used;
55610+static DEFINE_SPINLOCK(gr_uid_lock);
55611+extern rwlock_t gr_inode_lock;
55612+extern struct acl_subject_label *
55613+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
55614+ struct acl_role_label *role);
55615+
55616+#ifdef CONFIG_BTRFS_FS
55617+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
55618+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
55619+#endif
55620+
55621+static inline dev_t __get_dev(const struct dentry *dentry)
55622+{
55623+#ifdef CONFIG_BTRFS_FS
55624+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
55625+ return get_btrfs_dev_from_inode(dentry->d_inode);
55626+ else
55627+#endif
55628+ return dentry->d_inode->i_sb->s_dev;
55629+}
55630+
55631+int
55632+gr_init_uidset(void)
55633+{
55634+ uid_set =
55635+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
55636+ uid_used = 0;
55637+
55638+ return uid_set ? 1 : 0;
55639+}
55640+
55641+void
55642+gr_free_uidset(void)
55643+{
55644+ if (uid_set)
55645+ kfree(uid_set);
55646+
55647+ return;
55648+}
55649+
55650+int
55651+gr_find_uid(const uid_t uid)
55652+{
55653+ struct crash_uid *tmp = uid_set;
55654+ uid_t buid;
55655+ int low = 0, high = uid_used - 1, mid;
55656+
55657+ while (high >= low) {
55658+ mid = (low + high) >> 1;
55659+ buid = tmp[mid].uid;
55660+ if (buid == uid)
55661+ return mid;
55662+ if (buid > uid)
55663+ high = mid - 1;
55664+ if (buid < uid)
55665+ low = mid + 1;
55666+ }
55667+
55668+ return -1;
55669+}
55670+
55671+static __inline__ void
55672+gr_insertsort(void)
55673+{
55674+ unsigned short i, j;
55675+ struct crash_uid index;
55676+
55677+ for (i = 1; i < uid_used; i++) {
55678+ index = uid_set[i];
55679+ j = i;
55680+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
55681+ uid_set[j] = uid_set[j - 1];
55682+ j--;
55683+ }
55684+ uid_set[j] = index;
55685+ }
55686+
55687+ return;
55688+}
55689+
55690+static __inline__ void
55691+gr_insert_uid(const uid_t uid, const unsigned long expires)
55692+{
55693+ int loc;
55694+
55695+ if (uid_used == GR_UIDTABLE_MAX)
55696+ return;
55697+
55698+ loc = gr_find_uid(uid);
55699+
55700+ if (loc >= 0) {
55701+ uid_set[loc].expires = expires;
55702+ return;
55703+ }
55704+
55705+ uid_set[uid_used].uid = uid;
55706+ uid_set[uid_used].expires = expires;
55707+ uid_used++;
55708+
55709+ gr_insertsort();
55710+
55711+ return;
55712+}
55713+
55714+void
55715+gr_remove_uid(const unsigned short loc)
55716+{
55717+ unsigned short i;
55718+
55719+ for (i = loc + 1; i < uid_used; i++)
55720+ uid_set[i - 1] = uid_set[i];
55721+
55722+ uid_used--;
55723+
55724+ return;
55725+}
55726+
55727+int
55728+gr_check_crash_uid(const uid_t uid)
55729+{
55730+ int loc;
55731+ int ret = 0;
55732+
55733+ if (unlikely(!gr_acl_is_enabled()))
55734+ return 0;
55735+
55736+ spin_lock(&gr_uid_lock);
55737+ loc = gr_find_uid(uid);
55738+
55739+ if (loc < 0)
55740+ goto out_unlock;
55741+
55742+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
55743+ gr_remove_uid(loc);
55744+ else
55745+ ret = 1;
55746+
55747+out_unlock:
55748+ spin_unlock(&gr_uid_lock);
55749+ return ret;
55750+}
55751+
55752+static __inline__ int
55753+proc_is_setxid(const struct cred *cred)
55754+{
55755+ if (cred->uid != cred->euid || cred->uid != cred->suid ||
55756+ cred->uid != cred->fsuid)
55757+ return 1;
55758+ if (cred->gid != cred->egid || cred->gid != cred->sgid ||
55759+ cred->gid != cred->fsgid)
55760+ return 1;
55761+
55762+ return 0;
55763+}
55764+
55765+extern int gr_fake_force_sig(int sig, struct task_struct *t);
55766+
55767+void
55768+gr_handle_crash(struct task_struct *task, const int sig)
55769+{
55770+ struct acl_subject_label *curr;
55771+ struct task_struct *tsk, *tsk2;
55772+ const struct cred *cred;
55773+ const struct cred *cred2;
55774+
55775+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
55776+ return;
55777+
55778+ if (unlikely(!gr_acl_is_enabled()))
55779+ return;
55780+
55781+ curr = task->acl;
55782+
55783+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
55784+ return;
55785+
55786+ if (time_before_eq(curr->expires, get_seconds())) {
55787+ curr->expires = 0;
55788+ curr->crashes = 0;
55789+ }
55790+
55791+ curr->crashes++;
55792+
55793+ if (!curr->expires)
55794+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
55795+
55796+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
55797+ time_after(curr->expires, get_seconds())) {
55798+ rcu_read_lock();
55799+ cred = __task_cred(task);
55800+ if (cred->uid && proc_is_setxid(cred)) {
55801+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
55802+ spin_lock(&gr_uid_lock);
55803+ gr_insert_uid(cred->uid, curr->expires);
55804+ spin_unlock(&gr_uid_lock);
55805+ curr->expires = 0;
55806+ curr->crashes = 0;
55807+ read_lock(&tasklist_lock);
55808+ do_each_thread(tsk2, tsk) {
55809+ cred2 = __task_cred(tsk);
55810+ if (tsk != task && cred2->uid == cred->uid)
55811+ gr_fake_force_sig(SIGKILL, tsk);
55812+ } while_each_thread(tsk2, tsk);
55813+ read_unlock(&tasklist_lock);
55814+ } else {
55815+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
55816+ read_lock(&tasklist_lock);
55817+ read_lock(&grsec_exec_file_lock);
55818+ do_each_thread(tsk2, tsk) {
55819+ if (likely(tsk != task)) {
55820+ // if this thread has the same subject as the one that triggered
55821+ // RES_CRASH and it's the same binary, kill it
55822+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
55823+ gr_fake_force_sig(SIGKILL, tsk);
55824+ }
55825+ } while_each_thread(tsk2, tsk);
55826+ read_unlock(&grsec_exec_file_lock);
55827+ read_unlock(&tasklist_lock);
55828+ }
55829+ rcu_read_unlock();
55830+ }
55831+
55832+ return;
55833+}
55834+
55835+int
55836+gr_check_crash_exec(const struct file *filp)
55837+{
55838+ struct acl_subject_label *curr;
55839+
55840+ if (unlikely(!gr_acl_is_enabled()))
55841+ return 0;
55842+
55843+ read_lock(&gr_inode_lock);
55844+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
55845+ __get_dev(filp->f_path.dentry),
55846+ current->role);
55847+ read_unlock(&gr_inode_lock);
55848+
55849+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
55850+ (!curr->crashes && !curr->expires))
55851+ return 0;
55852+
55853+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
55854+ time_after(curr->expires, get_seconds()))
55855+ return 1;
55856+ else if (time_before_eq(curr->expires, get_seconds())) {
55857+ curr->crashes = 0;
55858+ curr->expires = 0;
55859+ }
55860+
55861+ return 0;
55862+}
55863+
55864+void
55865+gr_handle_alertkill(struct task_struct *task)
55866+{
55867+ struct acl_subject_label *curracl;
55868+ __u32 curr_ip;
55869+ struct task_struct *p, *p2;
55870+
55871+ if (unlikely(!gr_acl_is_enabled()))
55872+ return;
55873+
55874+ curracl = task->acl;
55875+ curr_ip = task->signal->curr_ip;
55876+
55877+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
55878+ read_lock(&tasklist_lock);
55879+ do_each_thread(p2, p) {
55880+ if (p->signal->curr_ip == curr_ip)
55881+ gr_fake_force_sig(SIGKILL, p);
55882+ } while_each_thread(p2, p);
55883+ read_unlock(&tasklist_lock);
55884+ } else if (curracl->mode & GR_KILLPROC)
55885+ gr_fake_force_sig(SIGKILL, task);
55886+
55887+ return;
55888+}
55889diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
55890new file mode 100644
55891index 0000000..9d83a69
55892--- /dev/null
55893+++ b/grsecurity/gracl_shm.c
55894@@ -0,0 +1,40 @@
55895+#include <linux/kernel.h>
55896+#include <linux/mm.h>
55897+#include <linux/sched.h>
55898+#include <linux/file.h>
55899+#include <linux/ipc.h>
55900+#include <linux/gracl.h>
55901+#include <linux/grsecurity.h>
55902+#include <linux/grinternal.h>
55903+
55904+int
55905+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
55906+ const time_t shm_createtime, const uid_t cuid, const int shmid)
55907+{
55908+ struct task_struct *task;
55909+
55910+ if (!gr_acl_is_enabled())
55911+ return 1;
55912+
55913+ rcu_read_lock();
55914+ read_lock(&tasklist_lock);
55915+
55916+ task = find_task_by_vpid(shm_cprid);
55917+
55918+ if (unlikely(!task))
55919+ task = find_task_by_vpid(shm_lapid);
55920+
55921+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
55922+ (task->pid == shm_lapid)) &&
55923+ (task->acl->mode & GR_PROTSHM) &&
55924+ (task->acl != current->acl))) {
55925+ read_unlock(&tasklist_lock);
55926+ rcu_read_unlock();
55927+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
55928+ return 0;
55929+ }
55930+ read_unlock(&tasklist_lock);
55931+ rcu_read_unlock();
55932+
55933+ return 1;
55934+}
55935diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
55936new file mode 100644
55937index 0000000..bc0be01
55938--- /dev/null
55939+++ b/grsecurity/grsec_chdir.c
55940@@ -0,0 +1,19 @@
55941+#include <linux/kernel.h>
55942+#include <linux/sched.h>
55943+#include <linux/fs.h>
55944+#include <linux/file.h>
55945+#include <linux/grsecurity.h>
55946+#include <linux/grinternal.h>
55947+
55948+void
55949+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
55950+{
55951+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
55952+ if ((grsec_enable_chdir && grsec_enable_group &&
55953+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
55954+ !grsec_enable_group)) {
55955+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
55956+ }
55957+#endif
55958+ return;
55959+}
55960diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
55961new file mode 100644
55962index 0000000..9807ee2
55963--- /dev/null
55964+++ b/grsecurity/grsec_chroot.c
55965@@ -0,0 +1,368 @@
55966+#include <linux/kernel.h>
55967+#include <linux/module.h>
55968+#include <linux/sched.h>
55969+#include <linux/file.h>
55970+#include <linux/fs.h>
55971+#include <linux/mount.h>
55972+#include <linux/types.h>
55973+#include "../fs/mount.h"
55974+#include <linux/grsecurity.h>
55975+#include <linux/grinternal.h>
55976+
55977+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
55978+{
55979+#ifdef CONFIG_GRKERNSEC
55980+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
55981+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
55982+ task->gr_is_chrooted = 1;
55983+ else
55984+ task->gr_is_chrooted = 0;
55985+
55986+ task->gr_chroot_dentry = path->dentry;
55987+#endif
55988+ return;
55989+}
55990+
55991+void gr_clear_chroot_entries(struct task_struct *task)
55992+{
55993+#ifdef CONFIG_GRKERNSEC
55994+ task->gr_is_chrooted = 0;
55995+ task->gr_chroot_dentry = NULL;
55996+#endif
55997+ return;
55998+}
55999+
56000+int
56001+gr_handle_chroot_unix(const pid_t pid)
56002+{
56003+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56004+ struct task_struct *p;
56005+
56006+ if (unlikely(!grsec_enable_chroot_unix))
56007+ return 1;
56008+
56009+ if (likely(!proc_is_chrooted(current)))
56010+ return 1;
56011+
56012+ rcu_read_lock();
56013+ read_lock(&tasklist_lock);
56014+ p = find_task_by_vpid_unrestricted(pid);
56015+ if (unlikely(p && !have_same_root(current, p))) {
56016+ read_unlock(&tasklist_lock);
56017+ rcu_read_unlock();
56018+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
56019+ return 0;
56020+ }
56021+ read_unlock(&tasklist_lock);
56022+ rcu_read_unlock();
56023+#endif
56024+ return 1;
56025+}
56026+
56027+int
56028+gr_handle_chroot_nice(void)
56029+{
56030+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56031+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
56032+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
56033+ return -EPERM;
56034+ }
56035+#endif
56036+ return 0;
56037+}
56038+
56039+int
56040+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
56041+{
56042+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56043+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
56044+ && proc_is_chrooted(current)) {
56045+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
56046+ return -EACCES;
56047+ }
56048+#endif
56049+ return 0;
56050+}
56051+
56052+int
56053+gr_handle_chroot_rawio(const struct inode *inode)
56054+{
56055+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56056+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56057+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
56058+ return 1;
56059+#endif
56060+ return 0;
56061+}
56062+
56063+int
56064+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
56065+{
56066+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56067+ struct task_struct *p;
56068+ int ret = 0;
56069+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
56070+ return ret;
56071+
56072+ read_lock(&tasklist_lock);
56073+ do_each_pid_task(pid, type, p) {
56074+ if (!have_same_root(current, p)) {
56075+ ret = 1;
56076+ goto out;
56077+ }
56078+ } while_each_pid_task(pid, type, p);
56079+out:
56080+ read_unlock(&tasklist_lock);
56081+ return ret;
56082+#endif
56083+ return 0;
56084+}
56085+
56086+int
56087+gr_pid_is_chrooted(struct task_struct *p)
56088+{
56089+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56090+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
56091+ return 0;
56092+
56093+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
56094+ !have_same_root(current, p)) {
56095+ return 1;
56096+ }
56097+#endif
56098+ return 0;
56099+}
56100+
56101+EXPORT_SYMBOL(gr_pid_is_chrooted);
56102+
56103+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
56104+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
56105+{
56106+ struct path path, currentroot;
56107+ int ret = 0;
56108+
56109+ path.dentry = (struct dentry *)u_dentry;
56110+ path.mnt = (struct vfsmount *)u_mnt;
56111+ get_fs_root(current->fs, &currentroot);
56112+ if (path_is_under(&path, &currentroot))
56113+ ret = 1;
56114+ path_put(&currentroot);
56115+
56116+ return ret;
56117+}
56118+#endif
56119+
56120+int
56121+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
56122+{
56123+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56124+ if (!grsec_enable_chroot_fchdir)
56125+ return 1;
56126+
56127+ if (!proc_is_chrooted(current))
56128+ return 1;
56129+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
56130+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
56131+ return 0;
56132+ }
56133+#endif
56134+ return 1;
56135+}
56136+
56137+int
56138+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56139+ const time_t shm_createtime)
56140+{
56141+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56142+ struct task_struct *p;
56143+ time_t starttime;
56144+
56145+ if (unlikely(!grsec_enable_chroot_shmat))
56146+ return 1;
56147+
56148+ if (likely(!proc_is_chrooted(current)))
56149+ return 1;
56150+
56151+ rcu_read_lock();
56152+ read_lock(&tasklist_lock);
56153+
56154+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
56155+ starttime = p->start_time.tv_sec;
56156+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
56157+ if (have_same_root(current, p)) {
56158+ goto allow;
56159+ } else {
56160+ read_unlock(&tasklist_lock);
56161+ rcu_read_unlock();
56162+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56163+ return 0;
56164+ }
56165+ }
56166+ /* creator exited, pid reuse, fall through to next check */
56167+ }
56168+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
56169+ if (unlikely(!have_same_root(current, p))) {
56170+ read_unlock(&tasklist_lock);
56171+ rcu_read_unlock();
56172+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56173+ return 0;
56174+ }
56175+ }
56176+
56177+allow:
56178+ read_unlock(&tasklist_lock);
56179+ rcu_read_unlock();
56180+#endif
56181+ return 1;
56182+}
56183+
56184+void
56185+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
56186+{
56187+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56188+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
56189+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
56190+#endif
56191+ return;
56192+}
56193+
56194+int
56195+gr_handle_chroot_mknod(const struct dentry *dentry,
56196+ const struct vfsmount *mnt, const int mode)
56197+{
56198+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56199+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
56200+ proc_is_chrooted(current)) {
56201+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
56202+ return -EPERM;
56203+ }
56204+#endif
56205+ return 0;
56206+}
56207+
56208+int
56209+gr_handle_chroot_mount(const struct dentry *dentry,
56210+ const struct vfsmount *mnt, const char *dev_name)
56211+{
56212+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56213+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
56214+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
56215+ return -EPERM;
56216+ }
56217+#endif
56218+ return 0;
56219+}
56220+
56221+int
56222+gr_handle_chroot_pivot(void)
56223+{
56224+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56225+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
56226+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
56227+ return -EPERM;
56228+ }
56229+#endif
56230+ return 0;
56231+}
56232+
56233+int
56234+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
56235+{
56236+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
56237+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
56238+ !gr_is_outside_chroot(dentry, mnt)) {
56239+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
56240+ return -EPERM;
56241+ }
56242+#endif
56243+ return 0;
56244+}
56245+
56246+extern const char *captab_log[];
56247+extern int captab_log_entries;
56248+
56249+int
56250+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56251+{
56252+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56253+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56254+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56255+ if (cap_raised(chroot_caps, cap)) {
56256+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
56257+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
56258+ }
56259+ return 0;
56260+ }
56261+ }
56262+#endif
56263+ return 1;
56264+}
56265+
56266+int
56267+gr_chroot_is_capable(const int cap)
56268+{
56269+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56270+ return gr_task_chroot_is_capable(current, current_cred(), cap);
56271+#endif
56272+ return 1;
56273+}
56274+
56275+int
56276+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
56277+{
56278+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56279+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56280+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56281+ if (cap_raised(chroot_caps, cap)) {
56282+ return 0;
56283+ }
56284+ }
56285+#endif
56286+ return 1;
56287+}
56288+
56289+int
56290+gr_chroot_is_capable_nolog(const int cap)
56291+{
56292+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56293+ return gr_task_chroot_is_capable_nolog(current, cap);
56294+#endif
56295+ return 1;
56296+}
56297+
56298+int
56299+gr_handle_chroot_sysctl(const int op)
56300+{
56301+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
56302+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
56303+ proc_is_chrooted(current))
56304+ return -EACCES;
56305+#endif
56306+ return 0;
56307+}
56308+
56309+void
56310+gr_handle_chroot_chdir(struct path *path)
56311+{
56312+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
56313+ if (grsec_enable_chroot_chdir)
56314+ set_fs_pwd(current->fs, path);
56315+#endif
56316+ return;
56317+}
56318+
56319+int
56320+gr_handle_chroot_chmod(const struct dentry *dentry,
56321+ const struct vfsmount *mnt, const int mode)
56322+{
56323+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
56324+ /* allow chmod +s on directories, but not files */
56325+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
56326+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
56327+ proc_is_chrooted(current)) {
56328+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
56329+ return -EPERM;
56330+ }
56331+#endif
56332+ return 0;
56333+}
56334diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
56335new file mode 100644
56336index 0000000..213ad8b
56337--- /dev/null
56338+++ b/grsecurity/grsec_disabled.c
56339@@ -0,0 +1,437 @@
56340+#include <linux/kernel.h>
56341+#include <linux/module.h>
56342+#include <linux/sched.h>
56343+#include <linux/file.h>
56344+#include <linux/fs.h>
56345+#include <linux/kdev_t.h>
56346+#include <linux/net.h>
56347+#include <linux/in.h>
56348+#include <linux/ip.h>
56349+#include <linux/skbuff.h>
56350+#include <linux/sysctl.h>
56351+
56352+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56353+void
56354+pax_set_initial_flags(struct linux_binprm *bprm)
56355+{
56356+ return;
56357+}
56358+#endif
56359+
56360+#ifdef CONFIG_SYSCTL
56361+__u32
56362+gr_handle_sysctl(const struct ctl_table * table, const int op)
56363+{
56364+ return 0;
56365+}
56366+#endif
56367+
56368+#ifdef CONFIG_TASKSTATS
56369+int gr_is_taskstats_denied(int pid)
56370+{
56371+ return 0;
56372+}
56373+#endif
56374+
56375+int
56376+gr_acl_is_enabled(void)
56377+{
56378+ return 0;
56379+}
56380+
56381+void
56382+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
56383+{
56384+ return;
56385+}
56386+
56387+int
56388+gr_handle_rawio(const struct inode *inode)
56389+{
56390+ return 0;
56391+}
56392+
56393+void
56394+gr_acl_handle_psacct(struct task_struct *task, const long code)
56395+{
56396+ return;
56397+}
56398+
56399+int
56400+gr_handle_ptrace(struct task_struct *task, const long request)
56401+{
56402+ return 0;
56403+}
56404+
56405+int
56406+gr_handle_proc_ptrace(struct task_struct *task)
56407+{
56408+ return 0;
56409+}
56410+
56411+void
56412+gr_learn_resource(const struct task_struct *task,
56413+ const int res, const unsigned long wanted, const int gt)
56414+{
56415+ return;
56416+}
56417+
56418+int
56419+gr_set_acls(const int type)
56420+{
56421+ return 0;
56422+}
56423+
56424+int
56425+gr_check_hidden_task(const struct task_struct *tsk)
56426+{
56427+ return 0;
56428+}
56429+
56430+int
56431+gr_check_protected_task(const struct task_struct *task)
56432+{
56433+ return 0;
56434+}
56435+
56436+int
56437+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
56438+{
56439+ return 0;
56440+}
56441+
56442+void
56443+gr_copy_label(struct task_struct *tsk)
56444+{
56445+ return;
56446+}
56447+
56448+void
56449+gr_set_pax_flags(struct task_struct *task)
56450+{
56451+ return;
56452+}
56453+
56454+int
56455+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
56456+ const int unsafe_share)
56457+{
56458+ return 0;
56459+}
56460+
56461+void
56462+gr_handle_delete(const ino_t ino, const dev_t dev)
56463+{
56464+ return;
56465+}
56466+
56467+void
56468+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
56469+{
56470+ return;
56471+}
56472+
56473+void
56474+gr_handle_crash(struct task_struct *task, const int sig)
56475+{
56476+ return;
56477+}
56478+
56479+int
56480+gr_check_crash_exec(const struct file *filp)
56481+{
56482+ return 0;
56483+}
56484+
56485+int
56486+gr_check_crash_uid(const uid_t uid)
56487+{
56488+ return 0;
56489+}
56490+
56491+void
56492+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
56493+ struct dentry *old_dentry,
56494+ struct dentry *new_dentry,
56495+ struct vfsmount *mnt, const __u8 replace)
56496+{
56497+ return;
56498+}
56499+
56500+int
56501+gr_search_socket(const int family, const int type, const int protocol)
56502+{
56503+ return 1;
56504+}
56505+
56506+int
56507+gr_search_connectbind(const int mode, const struct socket *sock,
56508+ const struct sockaddr_in *addr)
56509+{
56510+ return 0;
56511+}
56512+
56513+void
56514+gr_handle_alertkill(struct task_struct *task)
56515+{
56516+ return;
56517+}
56518+
56519+__u32
56520+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
56521+{
56522+ return 1;
56523+}
56524+
56525+__u32
56526+gr_acl_handle_hidden_file(const struct dentry * dentry,
56527+ const struct vfsmount * mnt)
56528+{
56529+ return 1;
56530+}
56531+
56532+__u32
56533+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
56534+ int acc_mode)
56535+{
56536+ return 1;
56537+}
56538+
56539+__u32
56540+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56541+{
56542+ return 1;
56543+}
56544+
56545+__u32
56546+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
56547+{
56548+ return 1;
56549+}
56550+
56551+int
56552+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
56553+ unsigned int *vm_flags)
56554+{
56555+ return 1;
56556+}
56557+
56558+__u32
56559+gr_acl_handle_truncate(const struct dentry * dentry,
56560+ const struct vfsmount * mnt)
56561+{
56562+ return 1;
56563+}
56564+
56565+__u32
56566+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
56567+{
56568+ return 1;
56569+}
56570+
56571+__u32
56572+gr_acl_handle_access(const struct dentry * dentry,
56573+ const struct vfsmount * mnt, const int fmode)
56574+{
56575+ return 1;
56576+}
56577+
56578+__u32
56579+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
56580+ umode_t *mode)
56581+{
56582+ return 1;
56583+}
56584+
56585+__u32
56586+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
56587+{
56588+ return 1;
56589+}
56590+
56591+__u32
56592+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
56593+{
56594+ return 1;
56595+}
56596+
56597+void
56598+grsecurity_init(void)
56599+{
56600+ return;
56601+}
56602+
56603+umode_t gr_acl_umask(void)
56604+{
56605+ return 0;
56606+}
56607+
56608+__u32
56609+gr_acl_handle_mknod(const struct dentry * new_dentry,
56610+ const struct dentry * parent_dentry,
56611+ const struct vfsmount * parent_mnt,
56612+ const int mode)
56613+{
56614+ return 1;
56615+}
56616+
56617+__u32
56618+gr_acl_handle_mkdir(const struct dentry * new_dentry,
56619+ const struct dentry * parent_dentry,
56620+ const struct vfsmount * parent_mnt)
56621+{
56622+ return 1;
56623+}
56624+
56625+__u32
56626+gr_acl_handle_symlink(const struct dentry * new_dentry,
56627+ const struct dentry * parent_dentry,
56628+ const struct vfsmount * parent_mnt, const char *from)
56629+{
56630+ return 1;
56631+}
56632+
56633+__u32
56634+gr_acl_handle_link(const struct dentry * new_dentry,
56635+ const struct dentry * parent_dentry,
56636+ const struct vfsmount * parent_mnt,
56637+ const struct dentry * old_dentry,
56638+ const struct vfsmount * old_mnt, const char *to)
56639+{
56640+ return 1;
56641+}
56642+
56643+int
56644+gr_acl_handle_rename(const struct dentry *new_dentry,
56645+ const struct dentry *parent_dentry,
56646+ const struct vfsmount *parent_mnt,
56647+ const struct dentry *old_dentry,
56648+ const struct inode *old_parent_inode,
56649+ const struct vfsmount *old_mnt, const char *newname)
56650+{
56651+ return 0;
56652+}
56653+
56654+int
56655+gr_acl_handle_filldir(const struct file *file, const char *name,
56656+ const int namelen, const ino_t ino)
56657+{
56658+ return 1;
56659+}
56660+
56661+int
56662+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56663+ const time_t shm_createtime, const uid_t cuid, const int shmid)
56664+{
56665+ return 1;
56666+}
56667+
56668+int
56669+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
56670+{
56671+ return 0;
56672+}
56673+
56674+int
56675+gr_search_accept(const struct socket *sock)
56676+{
56677+ return 0;
56678+}
56679+
56680+int
56681+gr_search_listen(const struct socket *sock)
56682+{
56683+ return 0;
56684+}
56685+
56686+int
56687+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
56688+{
56689+ return 0;
56690+}
56691+
56692+__u32
56693+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
56694+{
56695+ return 1;
56696+}
56697+
56698+__u32
56699+gr_acl_handle_creat(const struct dentry * dentry,
56700+ const struct dentry * p_dentry,
56701+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
56702+ const int imode)
56703+{
56704+ return 1;
56705+}
56706+
56707+void
56708+gr_acl_handle_exit(void)
56709+{
56710+ return;
56711+}
56712+
56713+int
56714+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
56715+{
56716+ return 1;
56717+}
56718+
56719+void
56720+gr_set_role_label(const uid_t uid, const gid_t gid)
56721+{
56722+ return;
56723+}
56724+
56725+int
56726+gr_acl_handle_procpidmem(const struct task_struct *task)
56727+{
56728+ return 0;
56729+}
56730+
56731+int
56732+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
56733+{
56734+ return 0;
56735+}
56736+
56737+int
56738+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
56739+{
56740+ return 0;
56741+}
56742+
56743+void
56744+gr_set_kernel_label(struct task_struct *task)
56745+{
56746+ return;
56747+}
56748+
56749+int
56750+gr_check_user_change(int real, int effective, int fs)
56751+{
56752+ return 0;
56753+}
56754+
56755+int
56756+gr_check_group_change(int real, int effective, int fs)
56757+{
56758+ return 0;
56759+}
56760+
56761+int gr_acl_enable_at_secure(void)
56762+{
56763+ return 0;
56764+}
56765+
56766+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
56767+{
56768+ return dentry->d_inode->i_sb->s_dev;
56769+}
56770+
56771+EXPORT_SYMBOL(gr_learn_resource);
56772+EXPORT_SYMBOL(gr_set_kernel_label);
56773+#ifdef CONFIG_SECURITY
56774+EXPORT_SYMBOL(gr_check_user_change);
56775+EXPORT_SYMBOL(gr_check_group_change);
56776+#endif
56777diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
56778new file mode 100644
56779index 0000000..abfa971
56780--- /dev/null
56781+++ b/grsecurity/grsec_exec.c
56782@@ -0,0 +1,174 @@
56783+#include <linux/kernel.h>
56784+#include <linux/sched.h>
56785+#include <linux/file.h>
56786+#include <linux/binfmts.h>
56787+#include <linux/fs.h>
56788+#include <linux/types.h>
56789+#include <linux/grdefs.h>
56790+#include <linux/grsecurity.h>
56791+#include <linux/grinternal.h>
56792+#include <linux/capability.h>
56793+#include <linux/module.h>
56794+
56795+#include <asm/uaccess.h>
56796+
56797+#ifdef CONFIG_GRKERNSEC_EXECLOG
56798+static char gr_exec_arg_buf[132];
56799+static DEFINE_MUTEX(gr_exec_arg_mutex);
56800+#endif
56801+
56802+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
56803+
56804+void
56805+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
56806+{
56807+#ifdef CONFIG_GRKERNSEC_EXECLOG
56808+ char *grarg = gr_exec_arg_buf;
56809+ unsigned int i, x, execlen = 0;
56810+ char c;
56811+
56812+ if (!((grsec_enable_execlog && grsec_enable_group &&
56813+ in_group_p(grsec_audit_gid))
56814+ || (grsec_enable_execlog && !grsec_enable_group)))
56815+ return;
56816+
56817+ mutex_lock(&gr_exec_arg_mutex);
56818+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
56819+
56820+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
56821+ const char __user *p;
56822+ unsigned int len;
56823+
56824+ p = get_user_arg_ptr(argv, i);
56825+ if (IS_ERR(p))
56826+ goto log;
56827+
56828+ len = strnlen_user(p, 128 - execlen);
56829+ if (len > 128 - execlen)
56830+ len = 128 - execlen;
56831+ else if (len > 0)
56832+ len--;
56833+ if (copy_from_user(grarg + execlen, p, len))
56834+ goto log;
56835+
56836+ /* rewrite unprintable characters */
56837+ for (x = 0; x < len; x++) {
56838+ c = *(grarg + execlen + x);
56839+ if (c < 32 || c > 126)
56840+ *(grarg + execlen + x) = ' ';
56841+ }
56842+
56843+ execlen += len;
56844+ *(grarg + execlen) = ' ';
56845+ *(grarg + execlen + 1) = '\0';
56846+ execlen++;
56847+ }
56848+
56849+ log:
56850+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
56851+ bprm->file->f_path.mnt, grarg);
56852+ mutex_unlock(&gr_exec_arg_mutex);
56853+#endif
56854+ return;
56855+}
56856+
56857+#ifdef CONFIG_GRKERNSEC
56858+extern int gr_acl_is_capable(const int cap);
56859+extern int gr_acl_is_capable_nolog(const int cap);
56860+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
56861+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
56862+extern int gr_chroot_is_capable(const int cap);
56863+extern int gr_chroot_is_capable_nolog(const int cap);
56864+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
56865+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
56866+#endif
56867+
56868+const char *captab_log[] = {
56869+ "CAP_CHOWN",
56870+ "CAP_DAC_OVERRIDE",
56871+ "CAP_DAC_READ_SEARCH",
56872+ "CAP_FOWNER",
56873+ "CAP_FSETID",
56874+ "CAP_KILL",
56875+ "CAP_SETGID",
56876+ "CAP_SETUID",
56877+ "CAP_SETPCAP",
56878+ "CAP_LINUX_IMMUTABLE",
56879+ "CAP_NET_BIND_SERVICE",
56880+ "CAP_NET_BROADCAST",
56881+ "CAP_NET_ADMIN",
56882+ "CAP_NET_RAW",
56883+ "CAP_IPC_LOCK",
56884+ "CAP_IPC_OWNER",
56885+ "CAP_SYS_MODULE",
56886+ "CAP_SYS_RAWIO",
56887+ "CAP_SYS_CHROOT",
56888+ "CAP_SYS_PTRACE",
56889+ "CAP_SYS_PACCT",
56890+ "CAP_SYS_ADMIN",
56891+ "CAP_SYS_BOOT",
56892+ "CAP_SYS_NICE",
56893+ "CAP_SYS_RESOURCE",
56894+ "CAP_SYS_TIME",
56895+ "CAP_SYS_TTY_CONFIG",
56896+ "CAP_MKNOD",
56897+ "CAP_LEASE",
56898+ "CAP_AUDIT_WRITE",
56899+ "CAP_AUDIT_CONTROL",
56900+ "CAP_SETFCAP",
56901+ "CAP_MAC_OVERRIDE",
56902+ "CAP_MAC_ADMIN",
56903+ "CAP_SYSLOG",
56904+ "CAP_WAKE_ALARM"
56905+};
56906+
56907+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
56908+
56909+int gr_is_capable(const int cap)
56910+{
56911+#ifdef CONFIG_GRKERNSEC
56912+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
56913+ return 1;
56914+ return 0;
56915+#else
56916+ return 1;
56917+#endif
56918+}
56919+
56920+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56921+{
56922+#ifdef CONFIG_GRKERNSEC
56923+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
56924+ return 1;
56925+ return 0;
56926+#else
56927+ return 1;
56928+#endif
56929+}
56930+
56931+int gr_is_capable_nolog(const int cap)
56932+{
56933+#ifdef CONFIG_GRKERNSEC
56934+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
56935+ return 1;
56936+ return 0;
56937+#else
56938+ return 1;
56939+#endif
56940+}
56941+
56942+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
56943+{
56944+#ifdef CONFIG_GRKERNSEC
56945+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
56946+ return 1;
56947+ return 0;
56948+#else
56949+ return 1;
56950+#endif
56951+}
56952+
56953+EXPORT_SYMBOL(gr_is_capable);
56954+EXPORT_SYMBOL(gr_is_capable_nolog);
56955+EXPORT_SYMBOL(gr_task_is_capable);
56956+EXPORT_SYMBOL(gr_task_is_capable_nolog);
56957diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
56958new file mode 100644
56959index 0000000..d3ee748
56960--- /dev/null
56961+++ b/grsecurity/grsec_fifo.c
56962@@ -0,0 +1,24 @@
56963+#include <linux/kernel.h>
56964+#include <linux/sched.h>
56965+#include <linux/fs.h>
56966+#include <linux/file.h>
56967+#include <linux/grinternal.h>
56968+
56969+int
56970+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
56971+ const struct dentry *dir, const int flag, const int acc_mode)
56972+{
56973+#ifdef CONFIG_GRKERNSEC_FIFO
56974+ const struct cred *cred = current_cred();
56975+
56976+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
56977+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
56978+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
56979+ (cred->fsuid != dentry->d_inode->i_uid)) {
56980+ if (!inode_permission(dentry->d_inode, acc_mode))
56981+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
56982+ return -EACCES;
56983+ }
56984+#endif
56985+ return 0;
56986+}
56987diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
56988new file mode 100644
56989index 0000000..8ca18bf
56990--- /dev/null
56991+++ b/grsecurity/grsec_fork.c
56992@@ -0,0 +1,23 @@
56993+#include <linux/kernel.h>
56994+#include <linux/sched.h>
56995+#include <linux/grsecurity.h>
56996+#include <linux/grinternal.h>
56997+#include <linux/errno.h>
56998+
56999+void
57000+gr_log_forkfail(const int retval)
57001+{
57002+#ifdef CONFIG_GRKERNSEC_FORKFAIL
57003+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
57004+ switch (retval) {
57005+ case -EAGAIN:
57006+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
57007+ break;
57008+ case -ENOMEM:
57009+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
57010+ break;
57011+ }
57012+ }
57013+#endif
57014+ return;
57015+}
57016diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
57017new file mode 100644
57018index 0000000..01ddde4
57019--- /dev/null
57020+++ b/grsecurity/grsec_init.c
57021@@ -0,0 +1,277 @@
57022+#include <linux/kernel.h>
57023+#include <linux/sched.h>
57024+#include <linux/mm.h>
57025+#include <linux/gracl.h>
57026+#include <linux/slab.h>
57027+#include <linux/vmalloc.h>
57028+#include <linux/percpu.h>
57029+#include <linux/module.h>
57030+
57031+int grsec_enable_ptrace_readexec;
57032+int grsec_enable_setxid;
57033+int grsec_enable_brute;
57034+int grsec_enable_link;
57035+int grsec_enable_dmesg;
57036+int grsec_enable_harden_ptrace;
57037+int grsec_enable_fifo;
57038+int grsec_enable_execlog;
57039+int grsec_enable_signal;
57040+int grsec_enable_forkfail;
57041+int grsec_enable_audit_ptrace;
57042+int grsec_enable_time;
57043+int grsec_enable_audit_textrel;
57044+int grsec_enable_group;
57045+int grsec_audit_gid;
57046+int grsec_enable_chdir;
57047+int grsec_enable_mount;
57048+int grsec_enable_rofs;
57049+int grsec_enable_chroot_findtask;
57050+int grsec_enable_chroot_mount;
57051+int grsec_enable_chroot_shmat;
57052+int grsec_enable_chroot_fchdir;
57053+int grsec_enable_chroot_double;
57054+int grsec_enable_chroot_pivot;
57055+int grsec_enable_chroot_chdir;
57056+int grsec_enable_chroot_chmod;
57057+int grsec_enable_chroot_mknod;
57058+int grsec_enable_chroot_nice;
57059+int grsec_enable_chroot_execlog;
57060+int grsec_enable_chroot_caps;
57061+int grsec_enable_chroot_sysctl;
57062+int grsec_enable_chroot_unix;
57063+int grsec_enable_tpe;
57064+int grsec_tpe_gid;
57065+int grsec_enable_blackhole;
57066+#ifdef CONFIG_IPV6_MODULE
57067+EXPORT_SYMBOL(grsec_enable_blackhole);
57068+#endif
57069+int grsec_lastack_retries;
57070+int grsec_enable_tpe_all;
57071+int grsec_enable_tpe_invert;
57072+int grsec_enable_socket_all;
57073+int grsec_socket_all_gid;
57074+int grsec_enable_socket_client;
57075+int grsec_socket_client_gid;
57076+int grsec_enable_socket_server;
57077+int grsec_socket_server_gid;
57078+int grsec_resource_logging;
57079+int grsec_disable_privio;
57080+int grsec_enable_log_rwxmaps;
57081+int grsec_lock;
57082+
57083+DEFINE_SPINLOCK(grsec_alert_lock);
57084+unsigned long grsec_alert_wtime = 0;
57085+unsigned long grsec_alert_fyet = 0;
57086+
57087+DEFINE_SPINLOCK(grsec_audit_lock);
57088+
57089+DEFINE_RWLOCK(grsec_exec_file_lock);
57090+
57091+char *gr_shared_page[4];
57092+
57093+char *gr_alert_log_fmt;
57094+char *gr_audit_log_fmt;
57095+char *gr_alert_log_buf;
57096+char *gr_audit_log_buf;
57097+
57098+extern struct gr_arg *gr_usermode;
57099+extern unsigned char *gr_system_salt;
57100+extern unsigned char *gr_system_sum;
57101+
57102+void __init
57103+grsecurity_init(void)
57104+{
57105+ int j;
57106+ /* create the per-cpu shared pages */
57107+
57108+#ifdef CONFIG_X86
57109+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
57110+#endif
57111+
57112+ for (j = 0; j < 4; j++) {
57113+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
57114+ if (gr_shared_page[j] == NULL) {
57115+ panic("Unable to allocate grsecurity shared page");
57116+ return;
57117+ }
57118+ }
57119+
57120+ /* allocate log buffers */
57121+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
57122+ if (!gr_alert_log_fmt) {
57123+ panic("Unable to allocate grsecurity alert log format buffer");
57124+ return;
57125+ }
57126+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
57127+ if (!gr_audit_log_fmt) {
57128+ panic("Unable to allocate grsecurity audit log format buffer");
57129+ return;
57130+ }
57131+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57132+ if (!gr_alert_log_buf) {
57133+ panic("Unable to allocate grsecurity alert log buffer");
57134+ return;
57135+ }
57136+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57137+ if (!gr_audit_log_buf) {
57138+ panic("Unable to allocate grsecurity audit log buffer");
57139+ return;
57140+ }
57141+
57142+ /* allocate memory for authentication structure */
57143+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
57144+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
57145+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
57146+
57147+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
57148+ panic("Unable to allocate grsecurity authentication structure");
57149+ return;
57150+ }
57151+
57152+
57153+#ifdef CONFIG_GRKERNSEC_IO
57154+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
57155+ grsec_disable_privio = 1;
57156+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57157+ grsec_disable_privio = 1;
57158+#else
57159+ grsec_disable_privio = 0;
57160+#endif
57161+#endif
57162+
57163+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
57164+ /* for backward compatibility, tpe_invert always defaults to on if
57165+ enabled in the kernel
57166+ */
57167+ grsec_enable_tpe_invert = 1;
57168+#endif
57169+
57170+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57171+#ifndef CONFIG_GRKERNSEC_SYSCTL
57172+ grsec_lock = 1;
57173+#endif
57174+
57175+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57176+ grsec_enable_audit_textrel = 1;
57177+#endif
57178+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57179+ grsec_enable_log_rwxmaps = 1;
57180+#endif
57181+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
57182+ grsec_enable_group = 1;
57183+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
57184+#endif
57185+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57186+ grsec_enable_ptrace_readexec = 1;
57187+#endif
57188+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57189+ grsec_enable_chdir = 1;
57190+#endif
57191+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57192+ grsec_enable_harden_ptrace = 1;
57193+#endif
57194+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57195+ grsec_enable_mount = 1;
57196+#endif
57197+#ifdef CONFIG_GRKERNSEC_LINK
57198+ grsec_enable_link = 1;
57199+#endif
57200+#ifdef CONFIG_GRKERNSEC_BRUTE
57201+ grsec_enable_brute = 1;
57202+#endif
57203+#ifdef CONFIG_GRKERNSEC_DMESG
57204+ grsec_enable_dmesg = 1;
57205+#endif
57206+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
57207+ grsec_enable_blackhole = 1;
57208+ grsec_lastack_retries = 4;
57209+#endif
57210+#ifdef CONFIG_GRKERNSEC_FIFO
57211+ grsec_enable_fifo = 1;
57212+#endif
57213+#ifdef CONFIG_GRKERNSEC_EXECLOG
57214+ grsec_enable_execlog = 1;
57215+#endif
57216+#ifdef CONFIG_GRKERNSEC_SETXID
57217+ grsec_enable_setxid = 1;
57218+#endif
57219+#ifdef CONFIG_GRKERNSEC_SIGNAL
57220+ grsec_enable_signal = 1;
57221+#endif
57222+#ifdef CONFIG_GRKERNSEC_FORKFAIL
57223+ grsec_enable_forkfail = 1;
57224+#endif
57225+#ifdef CONFIG_GRKERNSEC_TIME
57226+ grsec_enable_time = 1;
57227+#endif
57228+#ifdef CONFIG_GRKERNSEC_RESLOG
57229+ grsec_resource_logging = 1;
57230+#endif
57231+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57232+ grsec_enable_chroot_findtask = 1;
57233+#endif
57234+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57235+ grsec_enable_chroot_unix = 1;
57236+#endif
57237+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57238+ grsec_enable_chroot_mount = 1;
57239+#endif
57240+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57241+ grsec_enable_chroot_fchdir = 1;
57242+#endif
57243+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57244+ grsec_enable_chroot_shmat = 1;
57245+#endif
57246+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57247+ grsec_enable_audit_ptrace = 1;
57248+#endif
57249+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57250+ grsec_enable_chroot_double = 1;
57251+#endif
57252+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57253+ grsec_enable_chroot_pivot = 1;
57254+#endif
57255+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57256+ grsec_enable_chroot_chdir = 1;
57257+#endif
57258+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57259+ grsec_enable_chroot_chmod = 1;
57260+#endif
57261+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57262+ grsec_enable_chroot_mknod = 1;
57263+#endif
57264+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57265+ grsec_enable_chroot_nice = 1;
57266+#endif
57267+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57268+ grsec_enable_chroot_execlog = 1;
57269+#endif
57270+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57271+ grsec_enable_chroot_caps = 1;
57272+#endif
57273+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57274+ grsec_enable_chroot_sysctl = 1;
57275+#endif
57276+#ifdef CONFIG_GRKERNSEC_TPE
57277+ grsec_enable_tpe = 1;
57278+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
57279+#ifdef CONFIG_GRKERNSEC_TPE_ALL
57280+ grsec_enable_tpe_all = 1;
57281+#endif
57282+#endif
57283+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
57284+ grsec_enable_socket_all = 1;
57285+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
57286+#endif
57287+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
57288+ grsec_enable_socket_client = 1;
57289+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
57290+#endif
57291+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
57292+ grsec_enable_socket_server = 1;
57293+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
57294+#endif
57295+#endif
57296+
57297+ return;
57298+}
57299diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
57300new file mode 100644
57301index 0000000..3efe141
57302--- /dev/null
57303+++ b/grsecurity/grsec_link.c
57304@@ -0,0 +1,43 @@
57305+#include <linux/kernel.h>
57306+#include <linux/sched.h>
57307+#include <linux/fs.h>
57308+#include <linux/file.h>
57309+#include <linux/grinternal.h>
57310+
57311+int
57312+gr_handle_follow_link(const struct inode *parent,
57313+ const struct inode *inode,
57314+ const struct dentry *dentry, const struct vfsmount *mnt)
57315+{
57316+#ifdef CONFIG_GRKERNSEC_LINK
57317+ const struct cred *cred = current_cred();
57318+
57319+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
57320+ (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
57321+ (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
57322+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
57323+ return -EACCES;
57324+ }
57325+#endif
57326+ return 0;
57327+}
57328+
57329+int
57330+gr_handle_hardlink(const struct dentry *dentry,
57331+ const struct vfsmount *mnt,
57332+ struct inode *inode, const int mode, const char *to)
57333+{
57334+#ifdef CONFIG_GRKERNSEC_LINK
57335+ const struct cred *cred = current_cred();
57336+
57337+ if (grsec_enable_link && cred->fsuid != inode->i_uid &&
57338+ (!S_ISREG(mode) || (mode & S_ISUID) ||
57339+ ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
57340+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
57341+ !capable(CAP_FOWNER) && cred->uid) {
57342+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
57343+ return -EPERM;
57344+ }
57345+#endif
57346+ return 0;
57347+}
57348diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
57349new file mode 100644
57350index 0000000..a45d2e9
57351--- /dev/null
57352+++ b/grsecurity/grsec_log.c
57353@@ -0,0 +1,322 @@
57354+#include <linux/kernel.h>
57355+#include <linux/sched.h>
57356+#include <linux/file.h>
57357+#include <linux/tty.h>
57358+#include <linux/fs.h>
57359+#include <linux/grinternal.h>
57360+
57361+#ifdef CONFIG_TREE_PREEMPT_RCU
57362+#define DISABLE_PREEMPT() preempt_disable()
57363+#define ENABLE_PREEMPT() preempt_enable()
57364+#else
57365+#define DISABLE_PREEMPT()
57366+#define ENABLE_PREEMPT()
57367+#endif
57368+
57369+#define BEGIN_LOCKS(x) \
57370+ DISABLE_PREEMPT(); \
57371+ rcu_read_lock(); \
57372+ read_lock(&tasklist_lock); \
57373+ read_lock(&grsec_exec_file_lock); \
57374+ if (x != GR_DO_AUDIT) \
57375+ spin_lock(&grsec_alert_lock); \
57376+ else \
57377+ spin_lock(&grsec_audit_lock)
57378+
57379+#define END_LOCKS(x) \
57380+ if (x != GR_DO_AUDIT) \
57381+ spin_unlock(&grsec_alert_lock); \
57382+ else \
57383+ spin_unlock(&grsec_audit_lock); \
57384+ read_unlock(&grsec_exec_file_lock); \
57385+ read_unlock(&tasklist_lock); \
57386+ rcu_read_unlock(); \
57387+ ENABLE_PREEMPT(); \
57388+ if (x == GR_DONT_AUDIT) \
57389+ gr_handle_alertkill(current)
57390+
57391+enum {
57392+ FLOODING,
57393+ NO_FLOODING
57394+};
57395+
57396+extern char *gr_alert_log_fmt;
57397+extern char *gr_audit_log_fmt;
57398+extern char *gr_alert_log_buf;
57399+extern char *gr_audit_log_buf;
57400+
57401+static int gr_log_start(int audit)
57402+{
57403+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
57404+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
57405+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57406+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
57407+ unsigned long curr_secs = get_seconds();
57408+
57409+ if (audit == GR_DO_AUDIT)
57410+ goto set_fmt;
57411+
57412+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
57413+ grsec_alert_wtime = curr_secs;
57414+ grsec_alert_fyet = 0;
57415+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
57416+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
57417+ grsec_alert_fyet++;
57418+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
57419+ grsec_alert_wtime = curr_secs;
57420+ grsec_alert_fyet++;
57421+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
57422+ return FLOODING;
57423+ }
57424+ else return FLOODING;
57425+
57426+set_fmt:
57427+#endif
57428+ memset(buf, 0, PAGE_SIZE);
57429+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
57430+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
57431+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
57432+ } else if (current->signal->curr_ip) {
57433+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
57434+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
57435+ } else if (gr_acl_is_enabled()) {
57436+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
57437+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
57438+ } else {
57439+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
57440+ strcpy(buf, fmt);
57441+ }
57442+
57443+ return NO_FLOODING;
57444+}
57445+
57446+static void gr_log_middle(int audit, const char *msg, va_list ap)
57447+ __attribute__ ((format (printf, 2, 0)));
57448+
57449+static void gr_log_middle(int audit, const char *msg, va_list ap)
57450+{
57451+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57452+ unsigned int len = strlen(buf);
57453+
57454+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
57455+
57456+ return;
57457+}
57458+
57459+static void gr_log_middle_varargs(int audit, const char *msg, ...)
57460+ __attribute__ ((format (printf, 2, 3)));
57461+
57462+static void gr_log_middle_varargs(int audit, const char *msg, ...)
57463+{
57464+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57465+ unsigned int len = strlen(buf);
57466+ va_list ap;
57467+
57468+ va_start(ap, msg);
57469+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
57470+ va_end(ap);
57471+
57472+ return;
57473+}
57474+
57475+static void gr_log_end(int audit, int append_default)
57476+{
57477+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57478+
57479+ if (append_default) {
57480+ unsigned int len = strlen(buf);
57481+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
57482+ }
57483+
57484+ printk("%s\n", buf);
57485+
57486+ return;
57487+}
57488+
57489+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
57490+{
57491+ int logtype;
57492+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
57493+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
57494+ void *voidptr = NULL;
57495+ int num1 = 0, num2 = 0;
57496+ unsigned long ulong1 = 0, ulong2 = 0;
57497+ struct dentry *dentry = NULL;
57498+ struct vfsmount *mnt = NULL;
57499+ struct file *file = NULL;
57500+ struct task_struct *task = NULL;
57501+ const struct cred *cred, *pcred;
57502+ va_list ap;
57503+
57504+ BEGIN_LOCKS(audit);
57505+ logtype = gr_log_start(audit);
57506+ if (logtype == FLOODING) {
57507+ END_LOCKS(audit);
57508+ return;
57509+ }
57510+ va_start(ap, argtypes);
57511+ switch (argtypes) {
57512+ case GR_TTYSNIFF:
57513+ task = va_arg(ap, struct task_struct *);
57514+ 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);
57515+ break;
57516+ case GR_SYSCTL_HIDDEN:
57517+ str1 = va_arg(ap, char *);
57518+ gr_log_middle_varargs(audit, msg, result, str1);
57519+ break;
57520+ case GR_RBAC:
57521+ dentry = va_arg(ap, struct dentry *);
57522+ mnt = va_arg(ap, struct vfsmount *);
57523+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
57524+ break;
57525+ case GR_RBAC_STR:
57526+ dentry = va_arg(ap, struct dentry *);
57527+ mnt = va_arg(ap, struct vfsmount *);
57528+ str1 = va_arg(ap, char *);
57529+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
57530+ break;
57531+ case GR_STR_RBAC:
57532+ str1 = va_arg(ap, char *);
57533+ dentry = va_arg(ap, struct dentry *);
57534+ mnt = va_arg(ap, struct vfsmount *);
57535+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
57536+ break;
57537+ case GR_RBAC_MODE2:
57538+ dentry = va_arg(ap, struct dentry *);
57539+ mnt = va_arg(ap, struct vfsmount *);
57540+ str1 = va_arg(ap, char *);
57541+ str2 = va_arg(ap, char *);
57542+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
57543+ break;
57544+ case GR_RBAC_MODE3:
57545+ dentry = va_arg(ap, struct dentry *);
57546+ mnt = va_arg(ap, struct vfsmount *);
57547+ str1 = va_arg(ap, char *);
57548+ str2 = va_arg(ap, char *);
57549+ str3 = va_arg(ap, char *);
57550+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
57551+ break;
57552+ case GR_FILENAME:
57553+ dentry = va_arg(ap, struct dentry *);
57554+ mnt = va_arg(ap, struct vfsmount *);
57555+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
57556+ break;
57557+ case GR_STR_FILENAME:
57558+ str1 = va_arg(ap, char *);
57559+ dentry = va_arg(ap, struct dentry *);
57560+ mnt = va_arg(ap, struct vfsmount *);
57561+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
57562+ break;
57563+ case GR_FILENAME_STR:
57564+ dentry = va_arg(ap, struct dentry *);
57565+ mnt = va_arg(ap, struct vfsmount *);
57566+ str1 = va_arg(ap, char *);
57567+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
57568+ break;
57569+ case GR_FILENAME_TWO_INT:
57570+ dentry = va_arg(ap, struct dentry *);
57571+ mnt = va_arg(ap, struct vfsmount *);
57572+ num1 = va_arg(ap, int);
57573+ num2 = va_arg(ap, int);
57574+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
57575+ break;
57576+ case GR_FILENAME_TWO_INT_STR:
57577+ dentry = va_arg(ap, struct dentry *);
57578+ mnt = va_arg(ap, struct vfsmount *);
57579+ num1 = va_arg(ap, int);
57580+ num2 = va_arg(ap, int);
57581+ str1 = va_arg(ap, char *);
57582+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
57583+ break;
57584+ case GR_TEXTREL:
57585+ file = va_arg(ap, struct file *);
57586+ ulong1 = va_arg(ap, unsigned long);
57587+ ulong2 = va_arg(ap, unsigned long);
57588+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
57589+ break;
57590+ case GR_PTRACE:
57591+ task = va_arg(ap, struct task_struct *);
57592+ 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);
57593+ break;
57594+ case GR_RESOURCE:
57595+ task = va_arg(ap, struct task_struct *);
57596+ cred = __task_cred(task);
57597+ pcred = __task_cred(task->real_parent);
57598+ ulong1 = va_arg(ap, unsigned long);
57599+ str1 = va_arg(ap, char *);
57600+ ulong2 = va_arg(ap, unsigned long);
57601+ 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);
57602+ break;
57603+ case GR_CAP:
57604+ task = va_arg(ap, struct task_struct *);
57605+ cred = __task_cred(task);
57606+ pcred = __task_cred(task->real_parent);
57607+ str1 = va_arg(ap, char *);
57608+ 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);
57609+ break;
57610+ case GR_SIG:
57611+ str1 = va_arg(ap, char *);
57612+ voidptr = va_arg(ap, void *);
57613+ gr_log_middle_varargs(audit, msg, str1, voidptr);
57614+ break;
57615+ case GR_SIG2:
57616+ task = va_arg(ap, struct task_struct *);
57617+ cred = __task_cred(task);
57618+ pcred = __task_cred(task->real_parent);
57619+ num1 = va_arg(ap, int);
57620+ 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);
57621+ break;
57622+ case GR_CRASH1:
57623+ task = va_arg(ap, struct task_struct *);
57624+ cred = __task_cred(task);
57625+ pcred = __task_cred(task->real_parent);
57626+ ulong1 = va_arg(ap, unsigned long);
57627+ 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);
57628+ break;
57629+ case GR_CRASH2:
57630+ task = va_arg(ap, struct task_struct *);
57631+ cred = __task_cred(task);
57632+ pcred = __task_cred(task->real_parent);
57633+ ulong1 = va_arg(ap, unsigned long);
57634+ 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);
57635+ break;
57636+ case GR_RWXMAP:
57637+ file = va_arg(ap, struct file *);
57638+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
57639+ break;
57640+ case GR_PSACCT:
57641+ {
57642+ unsigned int wday, cday;
57643+ __u8 whr, chr;
57644+ __u8 wmin, cmin;
57645+ __u8 wsec, csec;
57646+ char cur_tty[64] = { 0 };
57647+ char parent_tty[64] = { 0 };
57648+
57649+ task = va_arg(ap, struct task_struct *);
57650+ wday = va_arg(ap, unsigned int);
57651+ cday = va_arg(ap, unsigned int);
57652+ whr = va_arg(ap, int);
57653+ chr = va_arg(ap, int);
57654+ wmin = va_arg(ap, int);
57655+ cmin = va_arg(ap, int);
57656+ wsec = va_arg(ap, int);
57657+ csec = va_arg(ap, int);
57658+ ulong1 = va_arg(ap, unsigned long);
57659+ cred = __task_cred(task);
57660+ pcred = __task_cred(task->real_parent);
57661+
57662+ 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);
57663+ }
57664+ break;
57665+ default:
57666+ gr_log_middle(audit, msg, ap);
57667+ }
57668+ va_end(ap);
57669+ // these don't need DEFAULTSECARGS printed on the end
57670+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
57671+ gr_log_end(audit, 0);
57672+ else
57673+ gr_log_end(audit, 1);
57674+ END_LOCKS(audit);
57675+}
57676diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
57677new file mode 100644
57678index 0000000..f536303
57679--- /dev/null
57680+++ b/grsecurity/grsec_mem.c
57681@@ -0,0 +1,40 @@
57682+#include <linux/kernel.h>
57683+#include <linux/sched.h>
57684+#include <linux/mm.h>
57685+#include <linux/mman.h>
57686+#include <linux/grinternal.h>
57687+
57688+void
57689+gr_handle_ioperm(void)
57690+{
57691+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
57692+ return;
57693+}
57694+
57695+void
57696+gr_handle_iopl(void)
57697+{
57698+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
57699+ return;
57700+}
57701+
57702+void
57703+gr_handle_mem_readwrite(u64 from, u64 to)
57704+{
57705+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
57706+ return;
57707+}
57708+
57709+void
57710+gr_handle_vm86(void)
57711+{
57712+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
57713+ return;
57714+}
57715+
57716+void
57717+gr_log_badprocpid(const char *entry)
57718+{
57719+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
57720+ return;
57721+}
57722diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
57723new file mode 100644
57724index 0000000..2131422
57725--- /dev/null
57726+++ b/grsecurity/grsec_mount.c
57727@@ -0,0 +1,62 @@
57728+#include <linux/kernel.h>
57729+#include <linux/sched.h>
57730+#include <linux/mount.h>
57731+#include <linux/grsecurity.h>
57732+#include <linux/grinternal.h>
57733+
57734+void
57735+gr_log_remount(const char *devname, const int retval)
57736+{
57737+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57738+ if (grsec_enable_mount && (retval >= 0))
57739+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
57740+#endif
57741+ return;
57742+}
57743+
57744+void
57745+gr_log_unmount(const char *devname, const int retval)
57746+{
57747+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57748+ if (grsec_enable_mount && (retval >= 0))
57749+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
57750+#endif
57751+ return;
57752+}
57753+
57754+void
57755+gr_log_mount(const char *from, const char *to, const int retval)
57756+{
57757+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57758+ if (grsec_enable_mount && (retval >= 0))
57759+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
57760+#endif
57761+ return;
57762+}
57763+
57764+int
57765+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
57766+{
57767+#ifdef CONFIG_GRKERNSEC_ROFS
57768+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
57769+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
57770+ return -EPERM;
57771+ } else
57772+ return 0;
57773+#endif
57774+ return 0;
57775+}
57776+
57777+int
57778+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
57779+{
57780+#ifdef CONFIG_GRKERNSEC_ROFS
57781+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
57782+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
57783+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
57784+ return -EPERM;
57785+ } else
57786+ return 0;
57787+#endif
57788+ return 0;
57789+}
57790diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
57791new file mode 100644
57792index 0000000..a3b12a0
57793--- /dev/null
57794+++ b/grsecurity/grsec_pax.c
57795@@ -0,0 +1,36 @@
57796+#include <linux/kernel.h>
57797+#include <linux/sched.h>
57798+#include <linux/mm.h>
57799+#include <linux/file.h>
57800+#include <linux/grinternal.h>
57801+#include <linux/grsecurity.h>
57802+
57803+void
57804+gr_log_textrel(struct vm_area_struct * vma)
57805+{
57806+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57807+ if (grsec_enable_audit_textrel)
57808+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
57809+#endif
57810+ return;
57811+}
57812+
57813+void
57814+gr_log_rwxmmap(struct file *file)
57815+{
57816+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57817+ if (grsec_enable_log_rwxmaps)
57818+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
57819+#endif
57820+ return;
57821+}
57822+
57823+void
57824+gr_log_rwxmprotect(struct file *file)
57825+{
57826+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57827+ if (grsec_enable_log_rwxmaps)
57828+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
57829+#endif
57830+ return;
57831+}
57832diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
57833new file mode 100644
57834index 0000000..f7f29aa
57835--- /dev/null
57836+++ b/grsecurity/grsec_ptrace.c
57837@@ -0,0 +1,30 @@
57838+#include <linux/kernel.h>
57839+#include <linux/sched.h>
57840+#include <linux/grinternal.h>
57841+#include <linux/security.h>
57842+
57843+void
57844+gr_audit_ptrace(struct task_struct *task)
57845+{
57846+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57847+ if (grsec_enable_audit_ptrace)
57848+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
57849+#endif
57850+ return;
57851+}
57852+
57853+int
57854+gr_ptrace_readexec(struct file *file, int unsafe_flags)
57855+{
57856+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57857+ const struct dentry *dentry = file->f_path.dentry;
57858+ const struct vfsmount *mnt = file->f_path.mnt;
57859+
57860+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
57861+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
57862+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
57863+ return -EACCES;
57864+ }
57865+#endif
57866+ return 0;
57867+}
57868diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
57869new file mode 100644
57870index 0000000..7a5b2de
57871--- /dev/null
57872+++ b/grsecurity/grsec_sig.c
57873@@ -0,0 +1,207 @@
57874+#include <linux/kernel.h>
57875+#include <linux/sched.h>
57876+#include <linux/delay.h>
57877+#include <linux/grsecurity.h>
57878+#include <linux/grinternal.h>
57879+#include <linux/hardirq.h>
57880+
57881+char *signames[] = {
57882+ [SIGSEGV] = "Segmentation fault",
57883+ [SIGILL] = "Illegal instruction",
57884+ [SIGABRT] = "Abort",
57885+ [SIGBUS] = "Invalid alignment/Bus error"
57886+};
57887+
57888+void
57889+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
57890+{
57891+#ifdef CONFIG_GRKERNSEC_SIGNAL
57892+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
57893+ (sig == SIGABRT) || (sig == SIGBUS))) {
57894+ if (t->pid == current->pid) {
57895+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
57896+ } else {
57897+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
57898+ }
57899+ }
57900+#endif
57901+ return;
57902+}
57903+
57904+int
57905+gr_handle_signal(const struct task_struct *p, const int sig)
57906+{
57907+#ifdef CONFIG_GRKERNSEC
57908+ /* ignore the 0 signal for protected task checks */
57909+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
57910+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
57911+ return -EPERM;
57912+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
57913+ return -EPERM;
57914+ }
57915+#endif
57916+ return 0;
57917+}
57918+
57919+#ifdef CONFIG_GRKERNSEC
57920+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
57921+
57922+int gr_fake_force_sig(int sig, struct task_struct *t)
57923+{
57924+ unsigned long int flags;
57925+ int ret, blocked, ignored;
57926+ struct k_sigaction *action;
57927+
57928+ spin_lock_irqsave(&t->sighand->siglock, flags);
57929+ action = &t->sighand->action[sig-1];
57930+ ignored = action->sa.sa_handler == SIG_IGN;
57931+ blocked = sigismember(&t->blocked, sig);
57932+ if (blocked || ignored) {
57933+ action->sa.sa_handler = SIG_DFL;
57934+ if (blocked) {
57935+ sigdelset(&t->blocked, sig);
57936+ recalc_sigpending_and_wake(t);
57937+ }
57938+ }
57939+ if (action->sa.sa_handler == SIG_DFL)
57940+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
57941+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
57942+
57943+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
57944+
57945+ return ret;
57946+}
57947+#endif
57948+
57949+#ifdef CONFIG_GRKERNSEC_BRUTE
57950+#define GR_USER_BAN_TIME (15 * 60)
57951+
57952+static int __get_dumpable(unsigned long mm_flags)
57953+{
57954+ int ret;
57955+
57956+ ret = mm_flags & MMF_DUMPABLE_MASK;
57957+ return (ret >= 2) ? 2 : ret;
57958+}
57959+#endif
57960+
57961+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
57962+{
57963+#ifdef CONFIG_GRKERNSEC_BRUTE
57964+ uid_t uid = 0;
57965+
57966+ if (!grsec_enable_brute)
57967+ return;
57968+
57969+ rcu_read_lock();
57970+ read_lock(&tasklist_lock);
57971+ read_lock(&grsec_exec_file_lock);
57972+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
57973+ p->real_parent->brute = 1;
57974+ else {
57975+ const struct cred *cred = __task_cred(p), *cred2;
57976+ struct task_struct *tsk, *tsk2;
57977+
57978+ if (!__get_dumpable(mm_flags) && cred->uid) {
57979+ struct user_struct *user;
57980+
57981+ uid = cred->uid;
57982+
57983+ /* this is put upon execution past expiration */
57984+ user = find_user(uid);
57985+ if (user == NULL)
57986+ goto unlock;
57987+ user->banned = 1;
57988+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
57989+ if (user->ban_expires == ~0UL)
57990+ user->ban_expires--;
57991+
57992+ do_each_thread(tsk2, tsk) {
57993+ cred2 = __task_cred(tsk);
57994+ if (tsk != p && cred2->uid == uid)
57995+ gr_fake_force_sig(SIGKILL, tsk);
57996+ } while_each_thread(tsk2, tsk);
57997+ }
57998+ }
57999+unlock:
58000+ read_unlock(&grsec_exec_file_lock);
58001+ read_unlock(&tasklist_lock);
58002+ rcu_read_unlock();
58003+
58004+ if (uid)
58005+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
58006+
58007+#endif
58008+ return;
58009+}
58010+
58011+void gr_handle_brute_check(void)
58012+{
58013+#ifdef CONFIG_GRKERNSEC_BRUTE
58014+ if (current->brute)
58015+ msleep(30 * 1000);
58016+#endif
58017+ return;
58018+}
58019+
58020+void gr_handle_kernel_exploit(void)
58021+{
58022+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
58023+ const struct cred *cred;
58024+ struct task_struct *tsk, *tsk2;
58025+ struct user_struct *user;
58026+ uid_t uid;
58027+
58028+ if (in_irq() || in_serving_softirq() || in_nmi())
58029+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
58030+
58031+ uid = current_uid();
58032+
58033+ if (uid == 0)
58034+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
58035+ else {
58036+ /* kill all the processes of this user, hold a reference
58037+ to their creds struct, and prevent them from creating
58038+ another process until system reset
58039+ */
58040+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
58041+ /* we intentionally leak this ref */
58042+ user = get_uid(current->cred->user);
58043+ if (user) {
58044+ user->banned = 1;
58045+ user->ban_expires = ~0UL;
58046+ }
58047+
58048+ read_lock(&tasklist_lock);
58049+ do_each_thread(tsk2, tsk) {
58050+ cred = __task_cred(tsk);
58051+ if (cred->uid == uid)
58052+ gr_fake_force_sig(SIGKILL, tsk);
58053+ } while_each_thread(tsk2, tsk);
58054+ read_unlock(&tasklist_lock);
58055+ }
58056+#endif
58057+}
58058+
58059+int __gr_process_user_ban(struct user_struct *user)
58060+{
58061+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58062+ if (unlikely(user->banned)) {
58063+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
58064+ user->banned = 0;
58065+ user->ban_expires = 0;
58066+ free_uid(user);
58067+ } else
58068+ return -EPERM;
58069+ }
58070+#endif
58071+ return 0;
58072+}
58073+
58074+int gr_process_user_ban(void)
58075+{
58076+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58077+ return __gr_process_user_ban(current->cred->user);
58078+#endif
58079+ return 0;
58080+}
58081diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
58082new file mode 100644
58083index 0000000..4030d57
58084--- /dev/null
58085+++ b/grsecurity/grsec_sock.c
58086@@ -0,0 +1,244 @@
58087+#include <linux/kernel.h>
58088+#include <linux/module.h>
58089+#include <linux/sched.h>
58090+#include <linux/file.h>
58091+#include <linux/net.h>
58092+#include <linux/in.h>
58093+#include <linux/ip.h>
58094+#include <net/sock.h>
58095+#include <net/inet_sock.h>
58096+#include <linux/grsecurity.h>
58097+#include <linux/grinternal.h>
58098+#include <linux/gracl.h>
58099+
58100+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
58101+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
58102+
58103+EXPORT_SYMBOL(gr_search_udp_recvmsg);
58104+EXPORT_SYMBOL(gr_search_udp_sendmsg);
58105+
58106+#ifdef CONFIG_UNIX_MODULE
58107+EXPORT_SYMBOL(gr_acl_handle_unix);
58108+EXPORT_SYMBOL(gr_acl_handle_mknod);
58109+EXPORT_SYMBOL(gr_handle_chroot_unix);
58110+EXPORT_SYMBOL(gr_handle_create);
58111+#endif
58112+
58113+#ifdef CONFIG_GRKERNSEC
58114+#define gr_conn_table_size 32749
58115+struct conn_table_entry {
58116+ struct conn_table_entry *next;
58117+ struct signal_struct *sig;
58118+};
58119+
58120+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
58121+DEFINE_SPINLOCK(gr_conn_table_lock);
58122+
58123+extern const char * gr_socktype_to_name(unsigned char type);
58124+extern const char * gr_proto_to_name(unsigned char proto);
58125+extern const char * gr_sockfamily_to_name(unsigned char family);
58126+
58127+static __inline__ int
58128+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
58129+{
58130+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
58131+}
58132+
58133+static __inline__ int
58134+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
58135+ __u16 sport, __u16 dport)
58136+{
58137+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
58138+ sig->gr_sport == sport && sig->gr_dport == dport))
58139+ return 1;
58140+ else
58141+ return 0;
58142+}
58143+
58144+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
58145+{
58146+ struct conn_table_entry **match;
58147+ unsigned int index;
58148+
58149+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58150+ sig->gr_sport, sig->gr_dport,
58151+ gr_conn_table_size);
58152+
58153+ newent->sig = sig;
58154+
58155+ match = &gr_conn_table[index];
58156+ newent->next = *match;
58157+ *match = newent;
58158+
58159+ return;
58160+}
58161+
58162+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
58163+{
58164+ struct conn_table_entry *match, *last = NULL;
58165+ unsigned int index;
58166+
58167+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58168+ sig->gr_sport, sig->gr_dport,
58169+ gr_conn_table_size);
58170+
58171+ match = gr_conn_table[index];
58172+ while (match && !conn_match(match->sig,
58173+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
58174+ sig->gr_dport)) {
58175+ last = match;
58176+ match = match->next;
58177+ }
58178+
58179+ if (match) {
58180+ if (last)
58181+ last->next = match->next;
58182+ else
58183+ gr_conn_table[index] = NULL;
58184+ kfree(match);
58185+ }
58186+
58187+ return;
58188+}
58189+
58190+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
58191+ __u16 sport, __u16 dport)
58192+{
58193+ struct conn_table_entry *match;
58194+ unsigned int index;
58195+
58196+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
58197+
58198+ match = gr_conn_table[index];
58199+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
58200+ match = match->next;
58201+
58202+ if (match)
58203+ return match->sig;
58204+ else
58205+ return NULL;
58206+}
58207+
58208+#endif
58209+
58210+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
58211+{
58212+#ifdef CONFIG_GRKERNSEC
58213+ struct signal_struct *sig = task->signal;
58214+ struct conn_table_entry *newent;
58215+
58216+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
58217+ if (newent == NULL)
58218+ return;
58219+ /* no bh lock needed since we are called with bh disabled */
58220+ spin_lock(&gr_conn_table_lock);
58221+ gr_del_task_from_ip_table_nolock(sig);
58222+ sig->gr_saddr = inet->inet_rcv_saddr;
58223+ sig->gr_daddr = inet->inet_daddr;
58224+ sig->gr_sport = inet->inet_sport;
58225+ sig->gr_dport = inet->inet_dport;
58226+ gr_add_to_task_ip_table_nolock(sig, newent);
58227+ spin_unlock(&gr_conn_table_lock);
58228+#endif
58229+ return;
58230+}
58231+
58232+void gr_del_task_from_ip_table(struct task_struct *task)
58233+{
58234+#ifdef CONFIG_GRKERNSEC
58235+ spin_lock_bh(&gr_conn_table_lock);
58236+ gr_del_task_from_ip_table_nolock(task->signal);
58237+ spin_unlock_bh(&gr_conn_table_lock);
58238+#endif
58239+ return;
58240+}
58241+
58242+void
58243+gr_attach_curr_ip(const struct sock *sk)
58244+{
58245+#ifdef CONFIG_GRKERNSEC
58246+ struct signal_struct *p, *set;
58247+ const struct inet_sock *inet = inet_sk(sk);
58248+
58249+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
58250+ return;
58251+
58252+ set = current->signal;
58253+
58254+ spin_lock_bh(&gr_conn_table_lock);
58255+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
58256+ inet->inet_dport, inet->inet_sport);
58257+ if (unlikely(p != NULL)) {
58258+ set->curr_ip = p->curr_ip;
58259+ set->used_accept = 1;
58260+ gr_del_task_from_ip_table_nolock(p);
58261+ spin_unlock_bh(&gr_conn_table_lock);
58262+ return;
58263+ }
58264+ spin_unlock_bh(&gr_conn_table_lock);
58265+
58266+ set->curr_ip = inet->inet_daddr;
58267+ set->used_accept = 1;
58268+#endif
58269+ return;
58270+}
58271+
58272+int
58273+gr_handle_sock_all(const int family, const int type, const int protocol)
58274+{
58275+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58276+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
58277+ (family != AF_UNIX)) {
58278+ if (family == AF_INET)
58279+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
58280+ else
58281+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
58282+ return -EACCES;
58283+ }
58284+#endif
58285+ return 0;
58286+}
58287+
58288+int
58289+gr_handle_sock_server(const struct sockaddr *sck)
58290+{
58291+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58292+ if (grsec_enable_socket_server &&
58293+ in_group_p(grsec_socket_server_gid) &&
58294+ sck && (sck->sa_family != AF_UNIX) &&
58295+ (sck->sa_family != AF_LOCAL)) {
58296+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58297+ return -EACCES;
58298+ }
58299+#endif
58300+ return 0;
58301+}
58302+
58303+int
58304+gr_handle_sock_server_other(const struct sock *sck)
58305+{
58306+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58307+ if (grsec_enable_socket_server &&
58308+ in_group_p(grsec_socket_server_gid) &&
58309+ sck && (sck->sk_family != AF_UNIX) &&
58310+ (sck->sk_family != AF_LOCAL)) {
58311+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58312+ return -EACCES;
58313+ }
58314+#endif
58315+ return 0;
58316+}
58317+
58318+int
58319+gr_handle_sock_client(const struct sockaddr *sck)
58320+{
58321+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58322+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
58323+ sck && (sck->sa_family != AF_UNIX) &&
58324+ (sck->sa_family != AF_LOCAL)) {
58325+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
58326+ return -EACCES;
58327+ }
58328+#endif
58329+ return 0;
58330+}
58331diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
58332new file mode 100644
58333index 0000000..8316f6f
58334--- /dev/null
58335+++ b/grsecurity/grsec_sysctl.c
58336@@ -0,0 +1,453 @@
58337+#include <linux/kernel.h>
58338+#include <linux/sched.h>
58339+#include <linux/sysctl.h>
58340+#include <linux/grsecurity.h>
58341+#include <linux/grinternal.h>
58342+
58343+int
58344+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
58345+{
58346+#ifdef CONFIG_GRKERNSEC_SYSCTL
58347+ if (dirname == NULL || name == NULL)
58348+ return 0;
58349+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
58350+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
58351+ return -EACCES;
58352+ }
58353+#endif
58354+ return 0;
58355+}
58356+
58357+#ifdef CONFIG_GRKERNSEC_ROFS
58358+static int __maybe_unused one = 1;
58359+#endif
58360+
58361+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
58362+struct ctl_table grsecurity_table[] = {
58363+#ifdef CONFIG_GRKERNSEC_SYSCTL
58364+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
58365+#ifdef CONFIG_GRKERNSEC_IO
58366+ {
58367+ .procname = "disable_priv_io",
58368+ .data = &grsec_disable_privio,
58369+ .maxlen = sizeof(int),
58370+ .mode = 0600,
58371+ .proc_handler = &proc_dointvec,
58372+ },
58373+#endif
58374+#endif
58375+#ifdef CONFIG_GRKERNSEC_LINK
58376+ {
58377+ .procname = "linking_restrictions",
58378+ .data = &grsec_enable_link,
58379+ .maxlen = sizeof(int),
58380+ .mode = 0600,
58381+ .proc_handler = &proc_dointvec,
58382+ },
58383+#endif
58384+#ifdef CONFIG_GRKERNSEC_BRUTE
58385+ {
58386+ .procname = "deter_bruteforce",
58387+ .data = &grsec_enable_brute,
58388+ .maxlen = sizeof(int),
58389+ .mode = 0600,
58390+ .proc_handler = &proc_dointvec,
58391+ },
58392+#endif
58393+#ifdef CONFIG_GRKERNSEC_FIFO
58394+ {
58395+ .procname = "fifo_restrictions",
58396+ .data = &grsec_enable_fifo,
58397+ .maxlen = sizeof(int),
58398+ .mode = 0600,
58399+ .proc_handler = &proc_dointvec,
58400+ },
58401+#endif
58402+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58403+ {
58404+ .procname = "ptrace_readexec",
58405+ .data = &grsec_enable_ptrace_readexec,
58406+ .maxlen = sizeof(int),
58407+ .mode = 0600,
58408+ .proc_handler = &proc_dointvec,
58409+ },
58410+#endif
58411+#ifdef CONFIG_GRKERNSEC_SETXID
58412+ {
58413+ .procname = "consistent_setxid",
58414+ .data = &grsec_enable_setxid,
58415+ .maxlen = sizeof(int),
58416+ .mode = 0600,
58417+ .proc_handler = &proc_dointvec,
58418+ },
58419+#endif
58420+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58421+ {
58422+ .procname = "ip_blackhole",
58423+ .data = &grsec_enable_blackhole,
58424+ .maxlen = sizeof(int),
58425+ .mode = 0600,
58426+ .proc_handler = &proc_dointvec,
58427+ },
58428+ {
58429+ .procname = "lastack_retries",
58430+ .data = &grsec_lastack_retries,
58431+ .maxlen = sizeof(int),
58432+ .mode = 0600,
58433+ .proc_handler = &proc_dointvec,
58434+ },
58435+#endif
58436+#ifdef CONFIG_GRKERNSEC_EXECLOG
58437+ {
58438+ .procname = "exec_logging",
58439+ .data = &grsec_enable_execlog,
58440+ .maxlen = sizeof(int),
58441+ .mode = 0600,
58442+ .proc_handler = &proc_dointvec,
58443+ },
58444+#endif
58445+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58446+ {
58447+ .procname = "rwxmap_logging",
58448+ .data = &grsec_enable_log_rwxmaps,
58449+ .maxlen = sizeof(int),
58450+ .mode = 0600,
58451+ .proc_handler = &proc_dointvec,
58452+ },
58453+#endif
58454+#ifdef CONFIG_GRKERNSEC_SIGNAL
58455+ {
58456+ .procname = "signal_logging",
58457+ .data = &grsec_enable_signal,
58458+ .maxlen = sizeof(int),
58459+ .mode = 0600,
58460+ .proc_handler = &proc_dointvec,
58461+ },
58462+#endif
58463+#ifdef CONFIG_GRKERNSEC_FORKFAIL
58464+ {
58465+ .procname = "forkfail_logging",
58466+ .data = &grsec_enable_forkfail,
58467+ .maxlen = sizeof(int),
58468+ .mode = 0600,
58469+ .proc_handler = &proc_dointvec,
58470+ },
58471+#endif
58472+#ifdef CONFIG_GRKERNSEC_TIME
58473+ {
58474+ .procname = "timechange_logging",
58475+ .data = &grsec_enable_time,
58476+ .maxlen = sizeof(int),
58477+ .mode = 0600,
58478+ .proc_handler = &proc_dointvec,
58479+ },
58480+#endif
58481+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58482+ {
58483+ .procname = "chroot_deny_shmat",
58484+ .data = &grsec_enable_chroot_shmat,
58485+ .maxlen = sizeof(int),
58486+ .mode = 0600,
58487+ .proc_handler = &proc_dointvec,
58488+ },
58489+#endif
58490+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58491+ {
58492+ .procname = "chroot_deny_unix",
58493+ .data = &grsec_enable_chroot_unix,
58494+ .maxlen = sizeof(int),
58495+ .mode = 0600,
58496+ .proc_handler = &proc_dointvec,
58497+ },
58498+#endif
58499+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58500+ {
58501+ .procname = "chroot_deny_mount",
58502+ .data = &grsec_enable_chroot_mount,
58503+ .maxlen = sizeof(int),
58504+ .mode = 0600,
58505+ .proc_handler = &proc_dointvec,
58506+ },
58507+#endif
58508+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58509+ {
58510+ .procname = "chroot_deny_fchdir",
58511+ .data = &grsec_enable_chroot_fchdir,
58512+ .maxlen = sizeof(int),
58513+ .mode = 0600,
58514+ .proc_handler = &proc_dointvec,
58515+ },
58516+#endif
58517+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58518+ {
58519+ .procname = "chroot_deny_chroot",
58520+ .data = &grsec_enable_chroot_double,
58521+ .maxlen = sizeof(int),
58522+ .mode = 0600,
58523+ .proc_handler = &proc_dointvec,
58524+ },
58525+#endif
58526+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58527+ {
58528+ .procname = "chroot_deny_pivot",
58529+ .data = &grsec_enable_chroot_pivot,
58530+ .maxlen = sizeof(int),
58531+ .mode = 0600,
58532+ .proc_handler = &proc_dointvec,
58533+ },
58534+#endif
58535+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58536+ {
58537+ .procname = "chroot_enforce_chdir",
58538+ .data = &grsec_enable_chroot_chdir,
58539+ .maxlen = sizeof(int),
58540+ .mode = 0600,
58541+ .proc_handler = &proc_dointvec,
58542+ },
58543+#endif
58544+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58545+ {
58546+ .procname = "chroot_deny_chmod",
58547+ .data = &grsec_enable_chroot_chmod,
58548+ .maxlen = sizeof(int),
58549+ .mode = 0600,
58550+ .proc_handler = &proc_dointvec,
58551+ },
58552+#endif
58553+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58554+ {
58555+ .procname = "chroot_deny_mknod",
58556+ .data = &grsec_enable_chroot_mknod,
58557+ .maxlen = sizeof(int),
58558+ .mode = 0600,
58559+ .proc_handler = &proc_dointvec,
58560+ },
58561+#endif
58562+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58563+ {
58564+ .procname = "chroot_restrict_nice",
58565+ .data = &grsec_enable_chroot_nice,
58566+ .maxlen = sizeof(int),
58567+ .mode = 0600,
58568+ .proc_handler = &proc_dointvec,
58569+ },
58570+#endif
58571+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58572+ {
58573+ .procname = "chroot_execlog",
58574+ .data = &grsec_enable_chroot_execlog,
58575+ .maxlen = sizeof(int),
58576+ .mode = 0600,
58577+ .proc_handler = &proc_dointvec,
58578+ },
58579+#endif
58580+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58581+ {
58582+ .procname = "chroot_caps",
58583+ .data = &grsec_enable_chroot_caps,
58584+ .maxlen = sizeof(int),
58585+ .mode = 0600,
58586+ .proc_handler = &proc_dointvec,
58587+ },
58588+#endif
58589+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58590+ {
58591+ .procname = "chroot_deny_sysctl",
58592+ .data = &grsec_enable_chroot_sysctl,
58593+ .maxlen = sizeof(int),
58594+ .mode = 0600,
58595+ .proc_handler = &proc_dointvec,
58596+ },
58597+#endif
58598+#ifdef CONFIG_GRKERNSEC_TPE
58599+ {
58600+ .procname = "tpe",
58601+ .data = &grsec_enable_tpe,
58602+ .maxlen = sizeof(int),
58603+ .mode = 0600,
58604+ .proc_handler = &proc_dointvec,
58605+ },
58606+ {
58607+ .procname = "tpe_gid",
58608+ .data = &grsec_tpe_gid,
58609+ .maxlen = sizeof(int),
58610+ .mode = 0600,
58611+ .proc_handler = &proc_dointvec,
58612+ },
58613+#endif
58614+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58615+ {
58616+ .procname = "tpe_invert",
58617+ .data = &grsec_enable_tpe_invert,
58618+ .maxlen = sizeof(int),
58619+ .mode = 0600,
58620+ .proc_handler = &proc_dointvec,
58621+ },
58622+#endif
58623+#ifdef CONFIG_GRKERNSEC_TPE_ALL
58624+ {
58625+ .procname = "tpe_restrict_all",
58626+ .data = &grsec_enable_tpe_all,
58627+ .maxlen = sizeof(int),
58628+ .mode = 0600,
58629+ .proc_handler = &proc_dointvec,
58630+ },
58631+#endif
58632+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58633+ {
58634+ .procname = "socket_all",
58635+ .data = &grsec_enable_socket_all,
58636+ .maxlen = sizeof(int),
58637+ .mode = 0600,
58638+ .proc_handler = &proc_dointvec,
58639+ },
58640+ {
58641+ .procname = "socket_all_gid",
58642+ .data = &grsec_socket_all_gid,
58643+ .maxlen = sizeof(int),
58644+ .mode = 0600,
58645+ .proc_handler = &proc_dointvec,
58646+ },
58647+#endif
58648+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58649+ {
58650+ .procname = "socket_client",
58651+ .data = &grsec_enable_socket_client,
58652+ .maxlen = sizeof(int),
58653+ .mode = 0600,
58654+ .proc_handler = &proc_dointvec,
58655+ },
58656+ {
58657+ .procname = "socket_client_gid",
58658+ .data = &grsec_socket_client_gid,
58659+ .maxlen = sizeof(int),
58660+ .mode = 0600,
58661+ .proc_handler = &proc_dointvec,
58662+ },
58663+#endif
58664+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58665+ {
58666+ .procname = "socket_server",
58667+ .data = &grsec_enable_socket_server,
58668+ .maxlen = sizeof(int),
58669+ .mode = 0600,
58670+ .proc_handler = &proc_dointvec,
58671+ },
58672+ {
58673+ .procname = "socket_server_gid",
58674+ .data = &grsec_socket_server_gid,
58675+ .maxlen = sizeof(int),
58676+ .mode = 0600,
58677+ .proc_handler = &proc_dointvec,
58678+ },
58679+#endif
58680+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58681+ {
58682+ .procname = "audit_group",
58683+ .data = &grsec_enable_group,
58684+ .maxlen = sizeof(int),
58685+ .mode = 0600,
58686+ .proc_handler = &proc_dointvec,
58687+ },
58688+ {
58689+ .procname = "audit_gid",
58690+ .data = &grsec_audit_gid,
58691+ .maxlen = sizeof(int),
58692+ .mode = 0600,
58693+ .proc_handler = &proc_dointvec,
58694+ },
58695+#endif
58696+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58697+ {
58698+ .procname = "audit_chdir",
58699+ .data = &grsec_enable_chdir,
58700+ .maxlen = sizeof(int),
58701+ .mode = 0600,
58702+ .proc_handler = &proc_dointvec,
58703+ },
58704+#endif
58705+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58706+ {
58707+ .procname = "audit_mount",
58708+ .data = &grsec_enable_mount,
58709+ .maxlen = sizeof(int),
58710+ .mode = 0600,
58711+ .proc_handler = &proc_dointvec,
58712+ },
58713+#endif
58714+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58715+ {
58716+ .procname = "audit_textrel",
58717+ .data = &grsec_enable_audit_textrel,
58718+ .maxlen = sizeof(int),
58719+ .mode = 0600,
58720+ .proc_handler = &proc_dointvec,
58721+ },
58722+#endif
58723+#ifdef CONFIG_GRKERNSEC_DMESG
58724+ {
58725+ .procname = "dmesg",
58726+ .data = &grsec_enable_dmesg,
58727+ .maxlen = sizeof(int),
58728+ .mode = 0600,
58729+ .proc_handler = &proc_dointvec,
58730+ },
58731+#endif
58732+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58733+ {
58734+ .procname = "chroot_findtask",
58735+ .data = &grsec_enable_chroot_findtask,
58736+ .maxlen = sizeof(int),
58737+ .mode = 0600,
58738+ .proc_handler = &proc_dointvec,
58739+ },
58740+#endif
58741+#ifdef CONFIG_GRKERNSEC_RESLOG
58742+ {
58743+ .procname = "resource_logging",
58744+ .data = &grsec_resource_logging,
58745+ .maxlen = sizeof(int),
58746+ .mode = 0600,
58747+ .proc_handler = &proc_dointvec,
58748+ },
58749+#endif
58750+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58751+ {
58752+ .procname = "audit_ptrace",
58753+ .data = &grsec_enable_audit_ptrace,
58754+ .maxlen = sizeof(int),
58755+ .mode = 0600,
58756+ .proc_handler = &proc_dointvec,
58757+ },
58758+#endif
58759+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58760+ {
58761+ .procname = "harden_ptrace",
58762+ .data = &grsec_enable_harden_ptrace,
58763+ .maxlen = sizeof(int),
58764+ .mode = 0600,
58765+ .proc_handler = &proc_dointvec,
58766+ },
58767+#endif
58768+ {
58769+ .procname = "grsec_lock",
58770+ .data = &grsec_lock,
58771+ .maxlen = sizeof(int),
58772+ .mode = 0600,
58773+ .proc_handler = &proc_dointvec,
58774+ },
58775+#endif
58776+#ifdef CONFIG_GRKERNSEC_ROFS
58777+ {
58778+ .procname = "romount_protect",
58779+ .data = &grsec_enable_rofs,
58780+ .maxlen = sizeof(int),
58781+ .mode = 0600,
58782+ .proc_handler = &proc_dointvec_minmax,
58783+ .extra1 = &one,
58784+ .extra2 = &one,
58785+ },
58786+#endif
58787+ { }
58788+};
58789+#endif
58790diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
58791new file mode 100644
58792index 0000000..0dc13c3
58793--- /dev/null
58794+++ b/grsecurity/grsec_time.c
58795@@ -0,0 +1,16 @@
58796+#include <linux/kernel.h>
58797+#include <linux/sched.h>
58798+#include <linux/grinternal.h>
58799+#include <linux/module.h>
58800+
58801+void
58802+gr_log_timechange(void)
58803+{
58804+#ifdef CONFIG_GRKERNSEC_TIME
58805+ if (grsec_enable_time)
58806+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
58807+#endif
58808+ return;
58809+}
58810+
58811+EXPORT_SYMBOL(gr_log_timechange);
58812diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
58813new file mode 100644
58814index 0000000..07e0dc0
58815--- /dev/null
58816+++ b/grsecurity/grsec_tpe.c
58817@@ -0,0 +1,73 @@
58818+#include <linux/kernel.h>
58819+#include <linux/sched.h>
58820+#include <linux/file.h>
58821+#include <linux/fs.h>
58822+#include <linux/grinternal.h>
58823+
58824+extern int gr_acl_tpe_check(void);
58825+
58826+int
58827+gr_tpe_allow(const struct file *file)
58828+{
58829+#ifdef CONFIG_GRKERNSEC
58830+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
58831+ const struct cred *cred = current_cred();
58832+ char *msg = NULL;
58833+ char *msg2 = NULL;
58834+
58835+ // never restrict root
58836+ if (!cred->uid)
58837+ return 1;
58838+
58839+ if (grsec_enable_tpe) {
58840+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58841+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
58842+ msg = "not being in trusted group";
58843+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
58844+ msg = "being in untrusted group";
58845+#else
58846+ if (in_group_p(grsec_tpe_gid))
58847+ msg = "being in untrusted group";
58848+#endif
58849+ }
58850+ if (!msg && gr_acl_tpe_check())
58851+ msg = "being in untrusted role";
58852+
58853+ // not in any affected group/role
58854+ if (!msg)
58855+ goto next_check;
58856+
58857+ if (inode->i_uid)
58858+ msg2 = "file in non-root-owned directory";
58859+ else if (inode->i_mode & S_IWOTH)
58860+ msg2 = "file in world-writable directory";
58861+ else if (inode->i_mode & S_IWGRP)
58862+ msg2 = "file in group-writable directory";
58863+
58864+ if (msg && msg2) {
58865+ char fullmsg[70] = {0};
58866+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
58867+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
58868+ return 0;
58869+ }
58870+ msg = NULL;
58871+next_check:
58872+#ifdef CONFIG_GRKERNSEC_TPE_ALL
58873+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
58874+ return 1;
58875+
58876+ if (inode->i_uid && (inode->i_uid != cred->uid))
58877+ msg = "directory not owned by user";
58878+ else if (inode->i_mode & S_IWOTH)
58879+ msg = "file in world-writable directory";
58880+ else if (inode->i_mode & S_IWGRP)
58881+ msg = "file in group-writable directory";
58882+
58883+ if (msg) {
58884+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
58885+ return 0;
58886+ }
58887+#endif
58888+#endif
58889+ return 1;
58890+}
58891diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
58892new file mode 100644
58893index 0000000..9f7b1ac
58894--- /dev/null
58895+++ b/grsecurity/grsum.c
58896@@ -0,0 +1,61 @@
58897+#include <linux/err.h>
58898+#include <linux/kernel.h>
58899+#include <linux/sched.h>
58900+#include <linux/mm.h>
58901+#include <linux/scatterlist.h>
58902+#include <linux/crypto.h>
58903+#include <linux/gracl.h>
58904+
58905+
58906+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
58907+#error "crypto and sha256 must be built into the kernel"
58908+#endif
58909+
58910+int
58911+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
58912+{
58913+ char *p;
58914+ struct crypto_hash *tfm;
58915+ struct hash_desc desc;
58916+ struct scatterlist sg;
58917+ unsigned char temp_sum[GR_SHA_LEN];
58918+ volatile int retval = 0;
58919+ volatile int dummy = 0;
58920+ unsigned int i;
58921+
58922+ sg_init_table(&sg, 1);
58923+
58924+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
58925+ if (IS_ERR(tfm)) {
58926+ /* should never happen, since sha256 should be built in */
58927+ return 1;
58928+ }
58929+
58930+ desc.tfm = tfm;
58931+ desc.flags = 0;
58932+
58933+ crypto_hash_init(&desc);
58934+
58935+ p = salt;
58936+ sg_set_buf(&sg, p, GR_SALT_LEN);
58937+ crypto_hash_update(&desc, &sg, sg.length);
58938+
58939+ p = entry->pw;
58940+ sg_set_buf(&sg, p, strlen(p));
58941+
58942+ crypto_hash_update(&desc, &sg, sg.length);
58943+
58944+ crypto_hash_final(&desc, temp_sum);
58945+
58946+ memset(entry->pw, 0, GR_PW_LEN);
58947+
58948+ for (i = 0; i < GR_SHA_LEN; i++)
58949+ if (sum[i] != temp_sum[i])
58950+ retval = 1;
58951+ else
58952+ dummy = 1; // waste a cycle
58953+
58954+ crypto_free_hash(tfm);
58955+
58956+ return retval;
58957+}
58958diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
58959index f1c8ca6..b5c1cc7 100644
58960--- a/include/acpi/acpi_bus.h
58961+++ b/include/acpi/acpi_bus.h
58962@@ -107,7 +107,7 @@ struct acpi_device_ops {
58963 acpi_op_bind bind;
58964 acpi_op_unbind unbind;
58965 acpi_op_notify notify;
58966-};
58967+} __no_const;
58968
58969 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
58970
58971diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
58972index b7babf0..71e4e74 100644
58973--- a/include/asm-generic/atomic-long.h
58974+++ b/include/asm-generic/atomic-long.h
58975@@ -22,6 +22,12 @@
58976
58977 typedef atomic64_t atomic_long_t;
58978
58979+#ifdef CONFIG_PAX_REFCOUNT
58980+typedef atomic64_unchecked_t atomic_long_unchecked_t;
58981+#else
58982+typedef atomic64_t atomic_long_unchecked_t;
58983+#endif
58984+
58985 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
58986
58987 static inline long atomic_long_read(atomic_long_t *l)
58988@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
58989 return (long)atomic64_read(v);
58990 }
58991
58992+#ifdef CONFIG_PAX_REFCOUNT
58993+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
58994+{
58995+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58996+
58997+ return (long)atomic64_read_unchecked(v);
58998+}
58999+#endif
59000+
59001 static inline void atomic_long_set(atomic_long_t *l, long i)
59002 {
59003 atomic64_t *v = (atomic64_t *)l;
59004@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59005 atomic64_set(v, i);
59006 }
59007
59008+#ifdef CONFIG_PAX_REFCOUNT
59009+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59010+{
59011+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59012+
59013+ atomic64_set_unchecked(v, i);
59014+}
59015+#endif
59016+
59017 static inline void atomic_long_inc(atomic_long_t *l)
59018 {
59019 atomic64_t *v = (atomic64_t *)l;
59020@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59021 atomic64_inc(v);
59022 }
59023
59024+#ifdef CONFIG_PAX_REFCOUNT
59025+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59026+{
59027+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59028+
59029+ atomic64_inc_unchecked(v);
59030+}
59031+#endif
59032+
59033 static inline void atomic_long_dec(atomic_long_t *l)
59034 {
59035 atomic64_t *v = (atomic64_t *)l;
59036@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59037 atomic64_dec(v);
59038 }
59039
59040+#ifdef CONFIG_PAX_REFCOUNT
59041+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59042+{
59043+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59044+
59045+ atomic64_dec_unchecked(v);
59046+}
59047+#endif
59048+
59049 static inline void atomic_long_add(long i, atomic_long_t *l)
59050 {
59051 atomic64_t *v = (atomic64_t *)l;
59052@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59053 atomic64_add(i, v);
59054 }
59055
59056+#ifdef CONFIG_PAX_REFCOUNT
59057+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59058+{
59059+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59060+
59061+ atomic64_add_unchecked(i, v);
59062+}
59063+#endif
59064+
59065 static inline void atomic_long_sub(long i, atomic_long_t *l)
59066 {
59067 atomic64_t *v = (atomic64_t *)l;
59068@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59069 atomic64_sub(i, v);
59070 }
59071
59072+#ifdef CONFIG_PAX_REFCOUNT
59073+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59074+{
59075+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59076+
59077+ atomic64_sub_unchecked(i, v);
59078+}
59079+#endif
59080+
59081 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59082 {
59083 atomic64_t *v = (atomic64_t *)l;
59084@@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59085 return (long)atomic64_inc_return(v);
59086 }
59087
59088+#ifdef CONFIG_PAX_REFCOUNT
59089+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59090+{
59091+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59092+
59093+ return (long)atomic64_inc_return_unchecked(v);
59094+}
59095+#endif
59096+
59097 static inline long atomic_long_dec_return(atomic_long_t *l)
59098 {
59099 atomic64_t *v = (atomic64_t *)l;
59100@@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59101
59102 typedef atomic_t atomic_long_t;
59103
59104+#ifdef CONFIG_PAX_REFCOUNT
59105+typedef atomic_unchecked_t atomic_long_unchecked_t;
59106+#else
59107+typedef atomic_t atomic_long_unchecked_t;
59108+#endif
59109+
59110 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
59111 static inline long atomic_long_read(atomic_long_t *l)
59112 {
59113@@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59114 return (long)atomic_read(v);
59115 }
59116
59117+#ifdef CONFIG_PAX_REFCOUNT
59118+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59119+{
59120+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59121+
59122+ return (long)atomic_read_unchecked(v);
59123+}
59124+#endif
59125+
59126 static inline void atomic_long_set(atomic_long_t *l, long i)
59127 {
59128 atomic_t *v = (atomic_t *)l;
59129@@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59130 atomic_set(v, i);
59131 }
59132
59133+#ifdef CONFIG_PAX_REFCOUNT
59134+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59135+{
59136+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59137+
59138+ atomic_set_unchecked(v, i);
59139+}
59140+#endif
59141+
59142 static inline void atomic_long_inc(atomic_long_t *l)
59143 {
59144 atomic_t *v = (atomic_t *)l;
59145@@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59146 atomic_inc(v);
59147 }
59148
59149+#ifdef CONFIG_PAX_REFCOUNT
59150+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59151+{
59152+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59153+
59154+ atomic_inc_unchecked(v);
59155+}
59156+#endif
59157+
59158 static inline void atomic_long_dec(atomic_long_t *l)
59159 {
59160 atomic_t *v = (atomic_t *)l;
59161@@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59162 atomic_dec(v);
59163 }
59164
59165+#ifdef CONFIG_PAX_REFCOUNT
59166+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59167+{
59168+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59169+
59170+ atomic_dec_unchecked(v);
59171+}
59172+#endif
59173+
59174 static inline void atomic_long_add(long i, atomic_long_t *l)
59175 {
59176 atomic_t *v = (atomic_t *)l;
59177@@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59178 atomic_add(i, v);
59179 }
59180
59181+#ifdef CONFIG_PAX_REFCOUNT
59182+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59183+{
59184+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59185+
59186+ atomic_add_unchecked(i, v);
59187+}
59188+#endif
59189+
59190 static inline void atomic_long_sub(long i, atomic_long_t *l)
59191 {
59192 atomic_t *v = (atomic_t *)l;
59193@@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59194 atomic_sub(i, v);
59195 }
59196
59197+#ifdef CONFIG_PAX_REFCOUNT
59198+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59199+{
59200+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59201+
59202+ atomic_sub_unchecked(i, v);
59203+}
59204+#endif
59205+
59206 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59207 {
59208 atomic_t *v = (atomic_t *)l;
59209@@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59210 return (long)atomic_inc_return(v);
59211 }
59212
59213+#ifdef CONFIG_PAX_REFCOUNT
59214+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59215+{
59216+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59217+
59218+ return (long)atomic_inc_return_unchecked(v);
59219+}
59220+#endif
59221+
59222 static inline long atomic_long_dec_return(atomic_long_t *l)
59223 {
59224 atomic_t *v = (atomic_t *)l;
59225@@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59226
59227 #endif /* BITS_PER_LONG == 64 */
59228
59229+#ifdef CONFIG_PAX_REFCOUNT
59230+static inline void pax_refcount_needs_these_functions(void)
59231+{
59232+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
59233+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
59234+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
59235+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
59236+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
59237+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
59238+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
59239+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
59240+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
59241+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
59242+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
59243+
59244+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
59245+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
59246+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
59247+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
59248+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
59249+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
59250+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
59251+}
59252+#else
59253+#define atomic_read_unchecked(v) atomic_read(v)
59254+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
59255+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
59256+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
59257+#define atomic_inc_unchecked(v) atomic_inc(v)
59258+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
59259+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
59260+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
59261+#define atomic_dec_unchecked(v) atomic_dec(v)
59262+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
59263+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
59264+
59265+#define atomic_long_read_unchecked(v) atomic_long_read(v)
59266+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
59267+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
59268+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
59269+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
59270+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
59271+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
59272+#endif
59273+
59274 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
59275diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
59276index b18ce4f..2ee2843 100644
59277--- a/include/asm-generic/atomic64.h
59278+++ b/include/asm-generic/atomic64.h
59279@@ -16,6 +16,8 @@ typedef struct {
59280 long long counter;
59281 } atomic64_t;
59282
59283+typedef atomic64_t atomic64_unchecked_t;
59284+
59285 #define ATOMIC64_INIT(i) { (i) }
59286
59287 extern long long atomic64_read(const atomic64_t *v);
59288@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
59289 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
59290 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
59291
59292+#define atomic64_read_unchecked(v) atomic64_read(v)
59293+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
59294+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
59295+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
59296+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
59297+#define atomic64_inc_unchecked(v) atomic64_inc(v)
59298+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
59299+#define atomic64_dec_unchecked(v) atomic64_dec(v)
59300+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
59301+
59302 #endif /* _ASM_GENERIC_ATOMIC64_H */
59303diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
59304index 1bfcfe5..e04c5c9 100644
59305--- a/include/asm-generic/cache.h
59306+++ b/include/asm-generic/cache.h
59307@@ -6,7 +6,7 @@
59308 * cache lines need to provide their own cache.h.
59309 */
59310
59311-#define L1_CACHE_SHIFT 5
59312-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
59313+#define L1_CACHE_SHIFT 5UL
59314+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
59315
59316 #endif /* __ASM_GENERIC_CACHE_H */
59317diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
59318index 0d68a1e..b74a761 100644
59319--- a/include/asm-generic/emergency-restart.h
59320+++ b/include/asm-generic/emergency-restart.h
59321@@ -1,7 +1,7 @@
59322 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
59323 #define _ASM_GENERIC_EMERGENCY_RESTART_H
59324
59325-static inline void machine_emergency_restart(void)
59326+static inline __noreturn void machine_emergency_restart(void)
59327 {
59328 machine_restart(NULL);
59329 }
59330diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
59331index 0232ccb..13d9165 100644
59332--- a/include/asm-generic/kmap_types.h
59333+++ b/include/asm-generic/kmap_types.h
59334@@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
59335 KMAP_D(17) KM_NMI,
59336 KMAP_D(18) KM_NMI_PTE,
59337 KMAP_D(19) KM_KDB,
59338+KMAP_D(20) KM_CLEARPAGE,
59339 /*
59340 * Remember to update debug_kmap_atomic() when adding new kmap types!
59341 */
59342-KMAP_D(20) KM_TYPE_NR
59343+KMAP_D(21) KM_TYPE_NR
59344 };
59345
59346 #undef KMAP_D
59347diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
59348index 9ceb03b..2efbcbd 100644
59349--- a/include/asm-generic/local.h
59350+++ b/include/asm-generic/local.h
59351@@ -39,6 +39,7 @@ typedef struct
59352 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
59353 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
59354 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
59355+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
59356
59357 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
59358 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
59359diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
59360index 725612b..9cc513a 100644
59361--- a/include/asm-generic/pgtable-nopmd.h
59362+++ b/include/asm-generic/pgtable-nopmd.h
59363@@ -1,14 +1,19 @@
59364 #ifndef _PGTABLE_NOPMD_H
59365 #define _PGTABLE_NOPMD_H
59366
59367-#ifndef __ASSEMBLY__
59368-
59369 #include <asm-generic/pgtable-nopud.h>
59370
59371-struct mm_struct;
59372-
59373 #define __PAGETABLE_PMD_FOLDED
59374
59375+#define PMD_SHIFT PUD_SHIFT
59376+#define PTRS_PER_PMD 1
59377+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
59378+#define PMD_MASK (~(PMD_SIZE-1))
59379+
59380+#ifndef __ASSEMBLY__
59381+
59382+struct mm_struct;
59383+
59384 /*
59385 * Having the pmd type consist of a pud gets the size right, and allows
59386 * us to conceptually access the pud entry that this pmd is folded into
59387@@ -16,11 +21,6 @@ struct mm_struct;
59388 */
59389 typedef struct { pud_t pud; } pmd_t;
59390
59391-#define PMD_SHIFT PUD_SHIFT
59392-#define PTRS_PER_PMD 1
59393-#define PMD_SIZE (1UL << PMD_SHIFT)
59394-#define PMD_MASK (~(PMD_SIZE-1))
59395-
59396 /*
59397 * The "pud_xxx()" functions here are trivial for a folded two-level
59398 * setup: the pmd is never bad, and a pmd always exists (as it's folded
59399diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
59400index 810431d..0ec4804f 100644
59401--- a/include/asm-generic/pgtable-nopud.h
59402+++ b/include/asm-generic/pgtable-nopud.h
59403@@ -1,10 +1,15 @@
59404 #ifndef _PGTABLE_NOPUD_H
59405 #define _PGTABLE_NOPUD_H
59406
59407-#ifndef __ASSEMBLY__
59408-
59409 #define __PAGETABLE_PUD_FOLDED
59410
59411+#define PUD_SHIFT PGDIR_SHIFT
59412+#define PTRS_PER_PUD 1
59413+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
59414+#define PUD_MASK (~(PUD_SIZE-1))
59415+
59416+#ifndef __ASSEMBLY__
59417+
59418 /*
59419 * Having the pud type consist of a pgd gets the size right, and allows
59420 * us to conceptually access the pgd entry that this pud is folded into
59421@@ -12,11 +17,6 @@
59422 */
59423 typedef struct { pgd_t pgd; } pud_t;
59424
59425-#define PUD_SHIFT PGDIR_SHIFT
59426-#define PTRS_PER_PUD 1
59427-#define PUD_SIZE (1UL << PUD_SHIFT)
59428-#define PUD_MASK (~(PUD_SIZE-1))
59429-
59430 /*
59431 * The "pgd_xxx()" functions here are trivial for a folded two-level
59432 * setup: the pud is never bad, and a pud always exists (as it's folded
59433@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
59434 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
59435
59436 #define pgd_populate(mm, pgd, pud) do { } while (0)
59437+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
59438 /*
59439 * (puds are folded into pgds so this doesn't get actually called,
59440 * but the define is needed for a generic inline function.)
59441diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
59442index 125c54e..e95c18e 100644
59443--- a/include/asm-generic/pgtable.h
59444+++ b/include/asm-generic/pgtable.h
59445@@ -446,6 +446,18 @@ static inline int pmd_write(pmd_t pmd)
59446 #endif /* __HAVE_ARCH_PMD_WRITE */
59447 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
59448
59449+#ifndef __HAVE_ARCH_READ_PMD_ATOMIC
59450+static inline pmd_t read_pmd_atomic(pmd_t *pmdp)
59451+{
59452+ /*
59453+ * Depend on compiler for an atomic pmd read. NOTE: this is
59454+ * only going to work, if the pmdval_t isn't larger than
59455+ * an unsigned long.
59456+ */
59457+ return *pmdp;
59458+}
59459+#endif /* __HAVE_ARCH_READ_PMD_ATOMIC */
59460+
59461 /*
59462 * This function is meant to be used by sites walking pagetables with
59463 * the mmap_sem hold in read mode to protect against MADV_DONTNEED and
59464@@ -459,11 +471,17 @@ static inline int pmd_write(pmd_t pmd)
59465 * undefined so behaving like if the pmd was none is safe (because it
59466 * can return none anyway). The compiler level barrier() is critically
59467 * important to compute the two checks atomically on the same pmdval.
59468+ *
59469+ * For 32bit kernels with a 64bit large pmd_t this automatically takes
59470+ * care of reading the pmd atomically to avoid SMP race conditions
59471+ * against pmd_populate() when the mmap_sem is hold for reading by the
59472+ * caller (a special atomic read not done by "gcc" as in the generic
59473+ * version above, is also needed when THP is disabled because the page
59474+ * fault can populate the pmd from under us).
59475 */
59476 static inline int pmd_none_or_trans_huge_or_clear_bad(pmd_t *pmd)
59477 {
59478- /* depend on compiler for an atomic pmd read */
59479- pmd_t pmdval = *pmd;
59480+ pmd_t pmdval = read_pmd_atomic(pmd);
59481 /*
59482 * The barrier will stabilize the pmdval in a register or on
59483 * the stack so that it will stop changing under the code.
59484@@ -503,6 +521,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
59485 #endif
59486 }
59487
59488+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
59489+static inline unsigned long pax_open_kernel(void) { return 0; }
59490+#endif
59491+
59492+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
59493+static inline unsigned long pax_close_kernel(void) { return 0; }
59494+#endif
59495+
59496 #endif /* CONFIG_MMU */
59497
59498 #endif /* !__ASSEMBLY__ */
59499diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
59500index 8aeadf6..f1dc019 100644
59501--- a/include/asm-generic/vmlinux.lds.h
59502+++ b/include/asm-generic/vmlinux.lds.h
59503@@ -218,6 +218,7 @@
59504 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
59505 VMLINUX_SYMBOL(__start_rodata) = .; \
59506 *(.rodata) *(.rodata.*) \
59507+ *(.data..read_only) \
59508 *(__vermagic) /* Kernel version magic */ \
59509 . = ALIGN(8); \
59510 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
59511@@ -716,17 +717,18 @@
59512 * section in the linker script will go there too. @phdr should have
59513 * a leading colon.
59514 *
59515- * Note that this macros defines __per_cpu_load as an absolute symbol.
59516+ * Note that this macros defines per_cpu_load as an absolute symbol.
59517 * If there is no need to put the percpu section at a predetermined
59518 * address, use PERCPU_SECTION.
59519 */
59520 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
59521- VMLINUX_SYMBOL(__per_cpu_load) = .; \
59522- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
59523+ per_cpu_load = .; \
59524+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
59525 - LOAD_OFFSET) { \
59526+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
59527 PERCPU_INPUT(cacheline) \
59528 } phdr \
59529- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
59530+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
59531
59532 /**
59533 * PERCPU_SECTION - define output section for percpu area, simple version
59534diff --git a/include/drm/drmP.h b/include/drm/drmP.h
59535index dd73104..fde86bd 100644
59536--- a/include/drm/drmP.h
59537+++ b/include/drm/drmP.h
59538@@ -72,6 +72,7 @@
59539 #include <linux/workqueue.h>
59540 #include <linux/poll.h>
59541 #include <asm/pgalloc.h>
59542+#include <asm/local.h>
59543 #include "drm.h"
59544
59545 #include <linux/idr.h>
59546@@ -1074,7 +1075,7 @@ struct drm_device {
59547
59548 /** \name Usage Counters */
59549 /*@{ */
59550- int open_count; /**< Outstanding files open */
59551+ local_t open_count; /**< Outstanding files open */
59552 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
59553 atomic_t vma_count; /**< Outstanding vma areas open */
59554 int buf_use; /**< Buffers in use -- cannot alloc */
59555@@ -1085,7 +1086,7 @@ struct drm_device {
59556 /*@{ */
59557 unsigned long counters;
59558 enum drm_stat_type types[15];
59559- atomic_t counts[15];
59560+ atomic_unchecked_t counts[15];
59561 /*@} */
59562
59563 struct list_head filelist;
59564diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
59565index 37515d1..34fa8b0 100644
59566--- a/include/drm/drm_crtc_helper.h
59567+++ b/include/drm/drm_crtc_helper.h
59568@@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
59569
59570 /* disable crtc when not in use - more explicit than dpms off */
59571 void (*disable)(struct drm_crtc *crtc);
59572-};
59573+} __no_const;
59574
59575 struct drm_encoder_helper_funcs {
59576 void (*dpms)(struct drm_encoder *encoder, int mode);
59577@@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
59578 struct drm_connector *connector);
59579 /* disable encoder when not in use - more explicit than dpms off */
59580 void (*disable)(struct drm_encoder *encoder);
59581-};
59582+} __no_const;
59583
59584 struct drm_connector_helper_funcs {
59585 int (*get_modes)(struct drm_connector *connector);
59586diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
59587index d6d1da4..fdd1ac5 100644
59588--- a/include/drm/ttm/ttm_memory.h
59589+++ b/include/drm/ttm/ttm_memory.h
59590@@ -48,7 +48,7 @@
59591
59592 struct ttm_mem_shrink {
59593 int (*do_shrink) (struct ttm_mem_shrink *);
59594-};
59595+} __no_const;
59596
59597 /**
59598 * struct ttm_mem_global - Global memory accounting structure.
59599diff --git a/include/linux/a.out.h b/include/linux/a.out.h
59600index e86dfca..40cc55f 100644
59601--- a/include/linux/a.out.h
59602+++ b/include/linux/a.out.h
59603@@ -39,6 +39,14 @@ enum machine_type {
59604 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
59605 };
59606
59607+/* Constants for the N_FLAGS field */
59608+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
59609+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
59610+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
59611+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
59612+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
59613+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
59614+
59615 #if !defined (N_MAGIC)
59616 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
59617 #endif
59618diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
59619index 06fd4bb..1caec0d 100644
59620--- a/include/linux/atmdev.h
59621+++ b/include/linux/atmdev.h
59622@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
59623 #endif
59624
59625 struct k_atm_aal_stats {
59626-#define __HANDLE_ITEM(i) atomic_t i
59627+#define __HANDLE_ITEM(i) atomic_unchecked_t i
59628 __AAL_STAT_ITEMS
59629 #undef __HANDLE_ITEM
59630 };
59631diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
59632index 366422b..1fa7f84 100644
59633--- a/include/linux/binfmts.h
59634+++ b/include/linux/binfmts.h
59635@@ -89,6 +89,7 @@ struct linux_binfmt {
59636 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
59637 int (*load_shlib)(struct file *);
59638 int (*core_dump)(struct coredump_params *cprm);
59639+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
59640 unsigned long min_coredump; /* minimal dump size */
59641 };
59642
59643diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
59644index 4d4ac24..2c3ccce 100644
59645--- a/include/linux/blkdev.h
59646+++ b/include/linux/blkdev.h
59647@@ -1376,7 +1376,7 @@ struct block_device_operations {
59648 /* this callback is with swap_lock and sometimes page table lock held */
59649 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
59650 struct module *owner;
59651-};
59652+} __do_const;
59653
59654 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
59655 unsigned long);
59656diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
59657index 4d1a074..88f929a 100644
59658--- a/include/linux/blktrace_api.h
59659+++ b/include/linux/blktrace_api.h
59660@@ -162,7 +162,7 @@ struct blk_trace {
59661 struct dentry *dir;
59662 struct dentry *dropped_file;
59663 struct dentry *msg_file;
59664- atomic_t dropped;
59665+ atomic_unchecked_t dropped;
59666 };
59667
59668 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
59669diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
59670index 83195fb..0b0f77d 100644
59671--- a/include/linux/byteorder/little_endian.h
59672+++ b/include/linux/byteorder/little_endian.h
59673@@ -42,51 +42,51 @@
59674
59675 static inline __le64 __cpu_to_le64p(const __u64 *p)
59676 {
59677- return (__force __le64)*p;
59678+ return (__force const __le64)*p;
59679 }
59680 static inline __u64 __le64_to_cpup(const __le64 *p)
59681 {
59682- return (__force __u64)*p;
59683+ return (__force const __u64)*p;
59684 }
59685 static inline __le32 __cpu_to_le32p(const __u32 *p)
59686 {
59687- return (__force __le32)*p;
59688+ return (__force const __le32)*p;
59689 }
59690 static inline __u32 __le32_to_cpup(const __le32 *p)
59691 {
59692- return (__force __u32)*p;
59693+ return (__force const __u32)*p;
59694 }
59695 static inline __le16 __cpu_to_le16p(const __u16 *p)
59696 {
59697- return (__force __le16)*p;
59698+ return (__force const __le16)*p;
59699 }
59700 static inline __u16 __le16_to_cpup(const __le16 *p)
59701 {
59702- return (__force __u16)*p;
59703+ return (__force const __u16)*p;
59704 }
59705 static inline __be64 __cpu_to_be64p(const __u64 *p)
59706 {
59707- return (__force __be64)__swab64p(p);
59708+ return (__force const __be64)__swab64p(p);
59709 }
59710 static inline __u64 __be64_to_cpup(const __be64 *p)
59711 {
59712- return __swab64p((__u64 *)p);
59713+ return __swab64p((const __u64 *)p);
59714 }
59715 static inline __be32 __cpu_to_be32p(const __u32 *p)
59716 {
59717- return (__force __be32)__swab32p(p);
59718+ return (__force const __be32)__swab32p(p);
59719 }
59720 static inline __u32 __be32_to_cpup(const __be32 *p)
59721 {
59722- return __swab32p((__u32 *)p);
59723+ return __swab32p((const __u32 *)p);
59724 }
59725 static inline __be16 __cpu_to_be16p(const __u16 *p)
59726 {
59727- return (__force __be16)__swab16p(p);
59728+ return (__force const __be16)__swab16p(p);
59729 }
59730 static inline __u16 __be16_to_cpup(const __be16 *p)
59731 {
59732- return __swab16p((__u16 *)p);
59733+ return __swab16p((const __u16 *)p);
59734 }
59735 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
59736 #define __le64_to_cpus(x) do { (void)(x); } while (0)
59737diff --git a/include/linux/cache.h b/include/linux/cache.h
59738index 4c57065..4307975 100644
59739--- a/include/linux/cache.h
59740+++ b/include/linux/cache.h
59741@@ -16,6 +16,10 @@
59742 #define __read_mostly
59743 #endif
59744
59745+#ifndef __read_only
59746+#define __read_only __read_mostly
59747+#endif
59748+
59749 #ifndef ____cacheline_aligned
59750 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
59751 #endif
59752diff --git a/include/linux/capability.h b/include/linux/capability.h
59753index 12d52de..b5f7fa7 100644
59754--- a/include/linux/capability.h
59755+++ b/include/linux/capability.h
59756@@ -548,6 +548,8 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
59757 extern bool capable(int cap);
59758 extern bool ns_capable(struct user_namespace *ns, int cap);
59759 extern bool nsown_capable(int cap);
59760+extern bool capable_nolog(int cap);
59761+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
59762
59763 /* audit system wants to get cap info from files as well */
59764 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
59765diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
59766index 42e55de..1cd0e66 100644
59767--- a/include/linux/cleancache.h
59768+++ b/include/linux/cleancache.h
59769@@ -31,7 +31,7 @@ struct cleancache_ops {
59770 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
59771 void (*invalidate_inode)(int, struct cleancache_filekey);
59772 void (*invalidate_fs)(int);
59773-};
59774+} __no_const;
59775
59776 extern struct cleancache_ops
59777 cleancache_register_ops(struct cleancache_ops *ops);
59778diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
59779index 2f40791..a62d196 100644
59780--- a/include/linux/compiler-gcc4.h
59781+++ b/include/linux/compiler-gcc4.h
59782@@ -32,6 +32,16 @@
59783 #define __linktime_error(message) __attribute__((__error__(message)))
59784
59785 #if __GNUC_MINOR__ >= 5
59786+
59787+#ifdef CONSTIFY_PLUGIN
59788+#define __no_const __attribute__((no_const))
59789+#define __do_const __attribute__((do_const))
59790+#endif
59791+
59792+#ifdef SIZE_OVERFLOW_PLUGIN
59793+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
59794+#endif
59795+
59796 /*
59797 * Mark a position in code as unreachable. This can be used to
59798 * suppress control flow warnings after asm blocks that transfer
59799@@ -47,6 +57,11 @@
59800 #define __noclone __attribute__((__noclone__))
59801
59802 #endif
59803+
59804+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
59805+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
59806+#define __bos0(ptr) __bos((ptr), 0)
59807+#define __bos1(ptr) __bos((ptr), 1)
59808 #endif
59809
59810 #if __GNUC_MINOR__ > 0
59811diff --git a/include/linux/compiler.h b/include/linux/compiler.h
59812index 923d093..726c17f 100644
59813--- a/include/linux/compiler.h
59814+++ b/include/linux/compiler.h
59815@@ -5,31 +5,62 @@
59816
59817 #ifdef __CHECKER__
59818 # define __user __attribute__((noderef, address_space(1)))
59819+# define __force_user __force __user
59820 # define __kernel __attribute__((address_space(0)))
59821+# define __force_kernel __force __kernel
59822 # define __safe __attribute__((safe))
59823 # define __force __attribute__((force))
59824 # define __nocast __attribute__((nocast))
59825 # define __iomem __attribute__((noderef, address_space(2)))
59826+# define __force_iomem __force __iomem
59827 # define __acquires(x) __attribute__((context(x,0,1)))
59828 # define __releases(x) __attribute__((context(x,1,0)))
59829 # define __acquire(x) __context__(x,1)
59830 # define __release(x) __context__(x,-1)
59831 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
59832 # define __percpu __attribute__((noderef, address_space(3)))
59833+# define __force_percpu __force __percpu
59834 #ifdef CONFIG_SPARSE_RCU_POINTER
59835 # define __rcu __attribute__((noderef, address_space(4)))
59836+# define __force_rcu __force __rcu
59837 #else
59838 # define __rcu
59839+# define __force_rcu
59840 #endif
59841 extern void __chk_user_ptr(const volatile void __user *);
59842 extern void __chk_io_ptr(const volatile void __iomem *);
59843+#elif defined(CHECKER_PLUGIN)
59844+//# define __user
59845+//# define __force_user
59846+//# define __kernel
59847+//# define __force_kernel
59848+# define __safe
59849+# define __force
59850+# define __nocast
59851+# define __iomem
59852+# define __force_iomem
59853+# define __chk_user_ptr(x) (void)0
59854+# define __chk_io_ptr(x) (void)0
59855+# define __builtin_warning(x, y...) (1)
59856+# define __acquires(x)
59857+# define __releases(x)
59858+# define __acquire(x) (void)0
59859+# define __release(x) (void)0
59860+# define __cond_lock(x,c) (c)
59861+# define __percpu
59862+# define __force_percpu
59863+# define __rcu
59864+# define __force_rcu
59865 #else
59866 # define __user
59867+# define __force_user
59868 # define __kernel
59869+# define __force_kernel
59870 # define __safe
59871 # define __force
59872 # define __nocast
59873 # define __iomem
59874+# define __force_iomem
59875 # define __chk_user_ptr(x) (void)0
59876 # define __chk_io_ptr(x) (void)0
59877 # define __builtin_warning(x, y...) (1)
59878@@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
59879 # define __release(x) (void)0
59880 # define __cond_lock(x,c) (c)
59881 # define __percpu
59882+# define __force_percpu
59883 # define __rcu
59884+# define __force_rcu
59885 #endif
59886
59887 #ifdef __KERNEL__
59888@@ -264,6 +297,18 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59889 # define __attribute_const__ /* unimplemented */
59890 #endif
59891
59892+#ifndef __no_const
59893+# define __no_const
59894+#endif
59895+
59896+#ifndef __do_const
59897+# define __do_const
59898+#endif
59899+
59900+#ifndef __size_overflow
59901+# define __size_overflow(...)
59902+#endif
59903+
59904 /*
59905 * Tell gcc if a function is cold. The compiler will assume any path
59906 * directly leading to the call is unlikely.
59907@@ -273,6 +318,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59908 #define __cold
59909 #endif
59910
59911+#ifndef __alloc_size
59912+#define __alloc_size(...)
59913+#endif
59914+
59915+#ifndef __bos
59916+#define __bos(ptr, arg)
59917+#endif
59918+
59919+#ifndef __bos0
59920+#define __bos0(ptr)
59921+#endif
59922+
59923+#ifndef __bos1
59924+#define __bos1(ptr)
59925+#endif
59926+
59927 /* Simple shorthand for a section definition */
59928 #ifndef __section
59929 # define __section(S) __attribute__ ((__section__(#S)))
59930@@ -308,6 +369,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59931 * use is to mediate communication between process-level code and irq/NMI
59932 * handlers, all running on the same CPU.
59933 */
59934-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
59935+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
59936+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
59937
59938 #endif /* __LINUX_COMPILER_H */
59939diff --git a/include/linux/cred.h b/include/linux/cred.h
59940index adadf71..6af5560 100644
59941--- a/include/linux/cred.h
59942+++ b/include/linux/cred.h
59943@@ -207,6 +207,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
59944 static inline void validate_process_creds(void)
59945 {
59946 }
59947+static inline void validate_task_creds(struct task_struct *task)
59948+{
59949+}
59950 #endif
59951
59952 /**
59953diff --git a/include/linux/crypto.h b/include/linux/crypto.h
59954index b92eadf..b4ecdc1 100644
59955--- a/include/linux/crypto.h
59956+++ b/include/linux/crypto.h
59957@@ -373,7 +373,7 @@ struct cipher_tfm {
59958 const u8 *key, unsigned int keylen);
59959 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
59960 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
59961-};
59962+} __no_const;
59963
59964 struct hash_tfm {
59965 int (*init)(struct hash_desc *desc);
59966@@ -394,13 +394,13 @@ struct compress_tfm {
59967 int (*cot_decompress)(struct crypto_tfm *tfm,
59968 const u8 *src, unsigned int slen,
59969 u8 *dst, unsigned int *dlen);
59970-};
59971+} __no_const;
59972
59973 struct rng_tfm {
59974 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
59975 unsigned int dlen);
59976 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
59977-};
59978+} __no_const;
59979
59980 #define crt_ablkcipher crt_u.ablkcipher
59981 #define crt_aead crt_u.aead
59982diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
59983index 7925bf0..d5143d2 100644
59984--- a/include/linux/decompress/mm.h
59985+++ b/include/linux/decompress/mm.h
59986@@ -77,7 +77,7 @@ static void free(void *where)
59987 * warnings when not needed (indeed large_malloc / large_free are not
59988 * needed by inflate */
59989
59990-#define malloc(a) kmalloc(a, GFP_KERNEL)
59991+#define malloc(a) kmalloc((a), GFP_KERNEL)
59992 #define free(a) kfree(a)
59993
59994 #define large_malloc(a) vmalloc(a)
59995diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
59996index dfc099e..e583e66 100644
59997--- a/include/linux/dma-mapping.h
59998+++ b/include/linux/dma-mapping.h
59999@@ -51,7 +51,7 @@ struct dma_map_ops {
60000 u64 (*get_required_mask)(struct device *dev);
60001 #endif
60002 int is_phys;
60003-};
60004+} __do_const;
60005
60006 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
60007
60008diff --git a/include/linux/efi.h b/include/linux/efi.h
60009index ec45ccd..9923c32 100644
60010--- a/include/linux/efi.h
60011+++ b/include/linux/efi.h
60012@@ -635,7 +635,7 @@ struct efivar_operations {
60013 efi_get_variable_t *get_variable;
60014 efi_get_next_variable_t *get_next_variable;
60015 efi_set_variable_t *set_variable;
60016-};
60017+} __no_const;
60018
60019 struct efivars {
60020 /*
60021diff --git a/include/linux/elf.h b/include/linux/elf.h
60022index 999b4f5..57753b4 100644
60023--- a/include/linux/elf.h
60024+++ b/include/linux/elf.h
60025@@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
60026 #define PT_GNU_EH_FRAME 0x6474e550
60027
60028 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
60029+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
60030+
60031+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
60032+
60033+/* Constants for the e_flags field */
60034+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60035+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
60036+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
60037+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
60038+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60039+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60040
60041 /*
60042 * Extended Numbering
60043@@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
60044 #define DT_DEBUG 21
60045 #define DT_TEXTREL 22
60046 #define DT_JMPREL 23
60047+#define DT_FLAGS 30
60048+ #define DF_TEXTREL 0x00000004
60049 #define DT_ENCODING 32
60050 #define OLD_DT_LOOS 0x60000000
60051 #define DT_LOOS 0x6000000d
60052@@ -243,6 +256,19 @@ typedef struct elf64_hdr {
60053 #define PF_W 0x2
60054 #define PF_X 0x1
60055
60056+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
60057+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
60058+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
60059+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
60060+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
60061+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
60062+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
60063+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
60064+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
60065+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
60066+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
60067+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
60068+
60069 typedef struct elf32_phdr{
60070 Elf32_Word p_type;
60071 Elf32_Off p_offset;
60072@@ -335,6 +361,8 @@ typedef struct elf64_shdr {
60073 #define EI_OSABI 7
60074 #define EI_PAD 8
60075
60076+#define EI_PAX 14
60077+
60078 #define ELFMAG0 0x7f /* EI_MAG */
60079 #define ELFMAG1 'E'
60080 #define ELFMAG2 'L'
60081@@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
60082 #define elf_note elf32_note
60083 #define elf_addr_t Elf32_Off
60084 #define Elf_Half Elf32_Half
60085+#define elf_dyn Elf32_Dyn
60086
60087 #else
60088
60089@@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
60090 #define elf_note elf64_note
60091 #define elf_addr_t Elf64_Off
60092 #define Elf_Half Elf64_Half
60093+#define elf_dyn Elf64_Dyn
60094
60095 #endif
60096
60097diff --git a/include/linux/filter.h b/include/linux/filter.h
60098index 8eeb205..d59bfa2 100644
60099--- a/include/linux/filter.h
60100+++ b/include/linux/filter.h
60101@@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
60102
60103 struct sk_buff;
60104 struct sock;
60105+struct bpf_jit_work;
60106
60107 struct sk_filter
60108 {
60109@@ -141,6 +142,9 @@ struct sk_filter
60110 unsigned int len; /* Number of filter blocks */
60111 unsigned int (*bpf_func)(const struct sk_buff *skb,
60112 const struct sock_filter *filter);
60113+#ifdef CONFIG_BPF_JIT
60114+ struct bpf_jit_work *work;
60115+#endif
60116 struct rcu_head rcu;
60117 struct sock_filter insns[0];
60118 };
60119diff --git a/include/linux/firewire.h b/include/linux/firewire.h
60120index cdc9b71..ce69fb5 100644
60121--- a/include/linux/firewire.h
60122+++ b/include/linux/firewire.h
60123@@ -413,7 +413,7 @@ struct fw_iso_context {
60124 union {
60125 fw_iso_callback_t sc;
60126 fw_iso_mc_callback_t mc;
60127- } callback;
60128+ } __no_const callback;
60129 void *callback_data;
60130 };
60131
60132diff --git a/include/linux/fs.h b/include/linux/fs.h
60133index 25c40b9..1bfd4f4 100644
60134--- a/include/linux/fs.h
60135+++ b/include/linux/fs.h
60136@@ -1634,7 +1634,8 @@ struct file_operations {
60137 int (*setlease)(struct file *, long, struct file_lock **);
60138 long (*fallocate)(struct file *file, int mode, loff_t offset,
60139 loff_t len);
60140-};
60141+} __do_const;
60142+typedef struct file_operations __no_const file_operations_no_const;
60143
60144 struct inode_operations {
60145 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
60146diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
60147index 003dc0f..3c4ea97 100644
60148--- a/include/linux/fs_struct.h
60149+++ b/include/linux/fs_struct.h
60150@@ -6,7 +6,7 @@
60151 #include <linux/seqlock.h>
60152
60153 struct fs_struct {
60154- int users;
60155+ atomic_t users;
60156 spinlock_t lock;
60157 seqcount_t seq;
60158 int umask;
60159diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
60160index ce31408..b1ad003 100644
60161--- a/include/linux/fscache-cache.h
60162+++ b/include/linux/fscache-cache.h
60163@@ -102,7 +102,7 @@ struct fscache_operation {
60164 fscache_operation_release_t release;
60165 };
60166
60167-extern atomic_t fscache_op_debug_id;
60168+extern atomic_unchecked_t fscache_op_debug_id;
60169 extern void fscache_op_work_func(struct work_struct *work);
60170
60171 extern void fscache_enqueue_operation(struct fscache_operation *);
60172@@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
60173 {
60174 INIT_WORK(&op->work, fscache_op_work_func);
60175 atomic_set(&op->usage, 1);
60176- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60177+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60178 op->processor = processor;
60179 op->release = release;
60180 INIT_LIST_HEAD(&op->pend_link);
60181diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
60182index a6dfe69..569586df 100644
60183--- a/include/linux/fsnotify.h
60184+++ b/include/linux/fsnotify.h
60185@@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
60186 */
60187 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
60188 {
60189- return kstrdup(name, GFP_KERNEL);
60190+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
60191 }
60192
60193 /*
60194diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
60195index 91d0e0a3..035666b 100644
60196--- a/include/linux/fsnotify_backend.h
60197+++ b/include/linux/fsnotify_backend.h
60198@@ -105,6 +105,7 @@ struct fsnotify_ops {
60199 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
60200 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
60201 };
60202+typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
60203
60204 /*
60205 * A group is a "thing" that wants to receive notification about filesystem
60206diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
60207index 176a939..1462211 100644
60208--- a/include/linux/ftrace_event.h
60209+++ b/include/linux/ftrace_event.h
60210@@ -97,7 +97,7 @@ struct trace_event_functions {
60211 trace_print_func raw;
60212 trace_print_func hex;
60213 trace_print_func binary;
60214-};
60215+} __no_const;
60216
60217 struct trace_event {
60218 struct hlist_node node;
60219@@ -263,7 +263,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
60220 extern int trace_add_event_call(struct ftrace_event_call *call);
60221 extern void trace_remove_event_call(struct ftrace_event_call *call);
60222
60223-#define is_signed_type(type) (((type)(-1)) < 0)
60224+#define is_signed_type(type) (((type)(-1)) < (type)1)
60225
60226 int trace_set_clr_event(const char *system, const char *event, int set);
60227
60228diff --git a/include/linux/genhd.h b/include/linux/genhd.h
60229index 017a7fb..33a8507 100644
60230--- a/include/linux/genhd.h
60231+++ b/include/linux/genhd.h
60232@@ -185,7 +185,7 @@ struct gendisk {
60233 struct kobject *slave_dir;
60234
60235 struct timer_rand_state *random;
60236- atomic_t sync_io; /* RAID */
60237+ atomic_unchecked_t sync_io; /* RAID */
60238 struct disk_events *ev;
60239 #ifdef CONFIG_BLK_DEV_INTEGRITY
60240 struct blk_integrity *integrity;
60241diff --git a/include/linux/gracl.h b/include/linux/gracl.h
60242new file mode 100644
60243index 0000000..c938b1f
60244--- /dev/null
60245+++ b/include/linux/gracl.h
60246@@ -0,0 +1,319 @@
60247+#ifndef GR_ACL_H
60248+#define GR_ACL_H
60249+
60250+#include <linux/grdefs.h>
60251+#include <linux/resource.h>
60252+#include <linux/capability.h>
60253+#include <linux/dcache.h>
60254+#include <asm/resource.h>
60255+
60256+/* Major status information */
60257+
60258+#define GR_VERSION "grsecurity 2.9.1"
60259+#define GRSECURITY_VERSION 0x2901
60260+
60261+enum {
60262+ GR_SHUTDOWN = 0,
60263+ GR_ENABLE = 1,
60264+ GR_SPROLE = 2,
60265+ GR_RELOAD = 3,
60266+ GR_SEGVMOD = 4,
60267+ GR_STATUS = 5,
60268+ GR_UNSPROLE = 6,
60269+ GR_PASSSET = 7,
60270+ GR_SPROLEPAM = 8,
60271+};
60272+
60273+/* Password setup definitions
60274+ * kernel/grhash.c */
60275+enum {
60276+ GR_PW_LEN = 128,
60277+ GR_SALT_LEN = 16,
60278+ GR_SHA_LEN = 32,
60279+};
60280+
60281+enum {
60282+ GR_SPROLE_LEN = 64,
60283+};
60284+
60285+enum {
60286+ GR_NO_GLOB = 0,
60287+ GR_REG_GLOB,
60288+ GR_CREATE_GLOB
60289+};
60290+
60291+#define GR_NLIMITS 32
60292+
60293+/* Begin Data Structures */
60294+
60295+struct sprole_pw {
60296+ unsigned char *rolename;
60297+ unsigned char salt[GR_SALT_LEN];
60298+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
60299+};
60300+
60301+struct name_entry {
60302+ __u32 key;
60303+ ino_t inode;
60304+ dev_t device;
60305+ char *name;
60306+ __u16 len;
60307+ __u8 deleted;
60308+ struct name_entry *prev;
60309+ struct name_entry *next;
60310+};
60311+
60312+struct inodev_entry {
60313+ struct name_entry *nentry;
60314+ struct inodev_entry *prev;
60315+ struct inodev_entry *next;
60316+};
60317+
60318+struct acl_role_db {
60319+ struct acl_role_label **r_hash;
60320+ __u32 r_size;
60321+};
60322+
60323+struct inodev_db {
60324+ struct inodev_entry **i_hash;
60325+ __u32 i_size;
60326+};
60327+
60328+struct name_db {
60329+ struct name_entry **n_hash;
60330+ __u32 n_size;
60331+};
60332+
60333+struct crash_uid {
60334+ uid_t uid;
60335+ unsigned long expires;
60336+};
60337+
60338+struct gr_hash_struct {
60339+ void **table;
60340+ void **nametable;
60341+ void *first;
60342+ __u32 table_size;
60343+ __u32 used_size;
60344+ int type;
60345+};
60346+
60347+/* Userspace Grsecurity ACL data structures */
60348+
60349+struct acl_subject_label {
60350+ char *filename;
60351+ ino_t inode;
60352+ dev_t device;
60353+ __u32 mode;
60354+ kernel_cap_t cap_mask;
60355+ kernel_cap_t cap_lower;
60356+ kernel_cap_t cap_invert_audit;
60357+
60358+ struct rlimit res[GR_NLIMITS];
60359+ __u32 resmask;
60360+
60361+ __u8 user_trans_type;
60362+ __u8 group_trans_type;
60363+ uid_t *user_transitions;
60364+ gid_t *group_transitions;
60365+ __u16 user_trans_num;
60366+ __u16 group_trans_num;
60367+
60368+ __u32 sock_families[2];
60369+ __u32 ip_proto[8];
60370+ __u32 ip_type;
60371+ struct acl_ip_label **ips;
60372+ __u32 ip_num;
60373+ __u32 inaddr_any_override;
60374+
60375+ __u32 crashes;
60376+ unsigned long expires;
60377+
60378+ struct acl_subject_label *parent_subject;
60379+ struct gr_hash_struct *hash;
60380+ struct acl_subject_label *prev;
60381+ struct acl_subject_label *next;
60382+
60383+ struct acl_object_label **obj_hash;
60384+ __u32 obj_hash_size;
60385+ __u16 pax_flags;
60386+};
60387+
60388+struct role_allowed_ip {
60389+ __u32 addr;
60390+ __u32 netmask;
60391+
60392+ struct role_allowed_ip *prev;
60393+ struct role_allowed_ip *next;
60394+};
60395+
60396+struct role_transition {
60397+ char *rolename;
60398+
60399+ struct role_transition *prev;
60400+ struct role_transition *next;
60401+};
60402+
60403+struct acl_role_label {
60404+ char *rolename;
60405+ uid_t uidgid;
60406+ __u16 roletype;
60407+
60408+ __u16 auth_attempts;
60409+ unsigned long expires;
60410+
60411+ struct acl_subject_label *root_label;
60412+ struct gr_hash_struct *hash;
60413+
60414+ struct acl_role_label *prev;
60415+ struct acl_role_label *next;
60416+
60417+ struct role_transition *transitions;
60418+ struct role_allowed_ip *allowed_ips;
60419+ uid_t *domain_children;
60420+ __u16 domain_child_num;
60421+
60422+ umode_t umask;
60423+
60424+ struct acl_subject_label **subj_hash;
60425+ __u32 subj_hash_size;
60426+};
60427+
60428+struct user_acl_role_db {
60429+ struct acl_role_label **r_table;
60430+ __u32 num_pointers; /* Number of allocations to track */
60431+ __u32 num_roles; /* Number of roles */
60432+ __u32 num_domain_children; /* Number of domain children */
60433+ __u32 num_subjects; /* Number of subjects */
60434+ __u32 num_objects; /* Number of objects */
60435+};
60436+
60437+struct acl_object_label {
60438+ char *filename;
60439+ ino_t inode;
60440+ dev_t device;
60441+ __u32 mode;
60442+
60443+ struct acl_subject_label *nested;
60444+ struct acl_object_label *globbed;
60445+
60446+ /* next two structures not used */
60447+
60448+ struct acl_object_label *prev;
60449+ struct acl_object_label *next;
60450+};
60451+
60452+struct acl_ip_label {
60453+ char *iface;
60454+ __u32 addr;
60455+ __u32 netmask;
60456+ __u16 low, high;
60457+ __u8 mode;
60458+ __u32 type;
60459+ __u32 proto[8];
60460+
60461+ /* next two structures not used */
60462+
60463+ struct acl_ip_label *prev;
60464+ struct acl_ip_label *next;
60465+};
60466+
60467+struct gr_arg {
60468+ struct user_acl_role_db role_db;
60469+ unsigned char pw[GR_PW_LEN];
60470+ unsigned char salt[GR_SALT_LEN];
60471+ unsigned char sum[GR_SHA_LEN];
60472+ unsigned char sp_role[GR_SPROLE_LEN];
60473+ struct sprole_pw *sprole_pws;
60474+ dev_t segv_device;
60475+ ino_t segv_inode;
60476+ uid_t segv_uid;
60477+ __u16 num_sprole_pws;
60478+ __u16 mode;
60479+};
60480+
60481+struct gr_arg_wrapper {
60482+ struct gr_arg *arg;
60483+ __u32 version;
60484+ __u32 size;
60485+};
60486+
60487+struct subject_map {
60488+ struct acl_subject_label *user;
60489+ struct acl_subject_label *kernel;
60490+ struct subject_map *prev;
60491+ struct subject_map *next;
60492+};
60493+
60494+struct acl_subj_map_db {
60495+ struct subject_map **s_hash;
60496+ __u32 s_size;
60497+};
60498+
60499+/* End Data Structures Section */
60500+
60501+/* Hash functions generated by empirical testing by Brad Spengler
60502+ Makes good use of the low bits of the inode. Generally 0-1 times
60503+ in loop for successful match. 0-3 for unsuccessful match.
60504+ Shift/add algorithm with modulus of table size and an XOR*/
60505+
60506+static __inline__ unsigned int
60507+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
60508+{
60509+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
60510+}
60511+
60512+ static __inline__ unsigned int
60513+shash(const struct acl_subject_label *userp, const unsigned int sz)
60514+{
60515+ return ((const unsigned long)userp % sz);
60516+}
60517+
60518+static __inline__ unsigned int
60519+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
60520+{
60521+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
60522+}
60523+
60524+static __inline__ unsigned int
60525+nhash(const char *name, const __u16 len, const unsigned int sz)
60526+{
60527+ return full_name_hash((const unsigned char *)name, len) % sz;
60528+}
60529+
60530+#define FOR_EACH_ROLE_START(role) \
60531+ role = role_list; \
60532+ while (role) {
60533+
60534+#define FOR_EACH_ROLE_END(role) \
60535+ role = role->prev; \
60536+ }
60537+
60538+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
60539+ subj = NULL; \
60540+ iter = 0; \
60541+ while (iter < role->subj_hash_size) { \
60542+ if (subj == NULL) \
60543+ subj = role->subj_hash[iter]; \
60544+ if (subj == NULL) { \
60545+ iter++; \
60546+ continue; \
60547+ }
60548+
60549+#define FOR_EACH_SUBJECT_END(subj,iter) \
60550+ subj = subj->next; \
60551+ if (subj == NULL) \
60552+ iter++; \
60553+ }
60554+
60555+
60556+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
60557+ subj = role->hash->first; \
60558+ while (subj != NULL) {
60559+
60560+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
60561+ subj = subj->next; \
60562+ }
60563+
60564+#endif
60565+
60566diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
60567new file mode 100644
60568index 0000000..323ecf2
60569--- /dev/null
60570+++ b/include/linux/gralloc.h
60571@@ -0,0 +1,9 @@
60572+#ifndef __GRALLOC_H
60573+#define __GRALLOC_H
60574+
60575+void acl_free_all(void);
60576+int acl_alloc_stack_init(unsigned long size);
60577+void *acl_alloc(unsigned long len);
60578+void *acl_alloc_num(unsigned long num, unsigned long len);
60579+
60580+#endif
60581diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
60582new file mode 100644
60583index 0000000..b30e9bc
60584--- /dev/null
60585+++ b/include/linux/grdefs.h
60586@@ -0,0 +1,140 @@
60587+#ifndef GRDEFS_H
60588+#define GRDEFS_H
60589+
60590+/* Begin grsecurity status declarations */
60591+
60592+enum {
60593+ GR_READY = 0x01,
60594+ GR_STATUS_INIT = 0x00 // disabled state
60595+};
60596+
60597+/* Begin ACL declarations */
60598+
60599+/* Role flags */
60600+
60601+enum {
60602+ GR_ROLE_USER = 0x0001,
60603+ GR_ROLE_GROUP = 0x0002,
60604+ GR_ROLE_DEFAULT = 0x0004,
60605+ GR_ROLE_SPECIAL = 0x0008,
60606+ GR_ROLE_AUTH = 0x0010,
60607+ GR_ROLE_NOPW = 0x0020,
60608+ GR_ROLE_GOD = 0x0040,
60609+ GR_ROLE_LEARN = 0x0080,
60610+ GR_ROLE_TPE = 0x0100,
60611+ GR_ROLE_DOMAIN = 0x0200,
60612+ GR_ROLE_PAM = 0x0400,
60613+ GR_ROLE_PERSIST = 0x0800
60614+};
60615+
60616+/* ACL Subject and Object mode flags */
60617+enum {
60618+ GR_DELETED = 0x80000000
60619+};
60620+
60621+/* ACL Object-only mode flags */
60622+enum {
60623+ GR_READ = 0x00000001,
60624+ GR_APPEND = 0x00000002,
60625+ GR_WRITE = 0x00000004,
60626+ GR_EXEC = 0x00000008,
60627+ GR_FIND = 0x00000010,
60628+ GR_INHERIT = 0x00000020,
60629+ GR_SETID = 0x00000040,
60630+ GR_CREATE = 0x00000080,
60631+ GR_DELETE = 0x00000100,
60632+ GR_LINK = 0x00000200,
60633+ GR_AUDIT_READ = 0x00000400,
60634+ GR_AUDIT_APPEND = 0x00000800,
60635+ GR_AUDIT_WRITE = 0x00001000,
60636+ GR_AUDIT_EXEC = 0x00002000,
60637+ GR_AUDIT_FIND = 0x00004000,
60638+ GR_AUDIT_INHERIT= 0x00008000,
60639+ GR_AUDIT_SETID = 0x00010000,
60640+ GR_AUDIT_CREATE = 0x00020000,
60641+ GR_AUDIT_DELETE = 0x00040000,
60642+ GR_AUDIT_LINK = 0x00080000,
60643+ GR_PTRACERD = 0x00100000,
60644+ GR_NOPTRACE = 0x00200000,
60645+ GR_SUPPRESS = 0x00400000,
60646+ GR_NOLEARN = 0x00800000,
60647+ GR_INIT_TRANSFER= 0x01000000
60648+};
60649+
60650+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
60651+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
60652+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
60653+
60654+/* ACL subject-only mode flags */
60655+enum {
60656+ GR_KILL = 0x00000001,
60657+ GR_VIEW = 0x00000002,
60658+ GR_PROTECTED = 0x00000004,
60659+ GR_LEARN = 0x00000008,
60660+ GR_OVERRIDE = 0x00000010,
60661+ /* just a placeholder, this mode is only used in userspace */
60662+ GR_DUMMY = 0x00000020,
60663+ GR_PROTSHM = 0x00000040,
60664+ GR_KILLPROC = 0x00000080,
60665+ GR_KILLIPPROC = 0x00000100,
60666+ /* just a placeholder, this mode is only used in userspace */
60667+ GR_NOTROJAN = 0x00000200,
60668+ GR_PROTPROCFD = 0x00000400,
60669+ GR_PROCACCT = 0x00000800,
60670+ GR_RELAXPTRACE = 0x00001000,
60671+ GR_NESTED = 0x00002000,
60672+ GR_INHERITLEARN = 0x00004000,
60673+ GR_PROCFIND = 0x00008000,
60674+ GR_POVERRIDE = 0x00010000,
60675+ GR_KERNELAUTH = 0x00020000,
60676+ GR_ATSECURE = 0x00040000,
60677+ GR_SHMEXEC = 0x00080000
60678+};
60679+
60680+enum {
60681+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
60682+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
60683+ GR_PAX_ENABLE_MPROTECT = 0x0004,
60684+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
60685+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
60686+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
60687+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
60688+ GR_PAX_DISABLE_MPROTECT = 0x0400,
60689+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
60690+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
60691+};
60692+
60693+enum {
60694+ GR_ID_USER = 0x01,
60695+ GR_ID_GROUP = 0x02,
60696+};
60697+
60698+enum {
60699+ GR_ID_ALLOW = 0x01,
60700+ GR_ID_DENY = 0x02,
60701+};
60702+
60703+#define GR_CRASH_RES 31
60704+#define GR_UIDTABLE_MAX 500
60705+
60706+/* begin resource learning section */
60707+enum {
60708+ GR_RLIM_CPU_BUMP = 60,
60709+ GR_RLIM_FSIZE_BUMP = 50000,
60710+ GR_RLIM_DATA_BUMP = 10000,
60711+ GR_RLIM_STACK_BUMP = 1000,
60712+ GR_RLIM_CORE_BUMP = 10000,
60713+ GR_RLIM_RSS_BUMP = 500000,
60714+ GR_RLIM_NPROC_BUMP = 1,
60715+ GR_RLIM_NOFILE_BUMP = 5,
60716+ GR_RLIM_MEMLOCK_BUMP = 50000,
60717+ GR_RLIM_AS_BUMP = 500000,
60718+ GR_RLIM_LOCKS_BUMP = 2,
60719+ GR_RLIM_SIGPENDING_BUMP = 5,
60720+ GR_RLIM_MSGQUEUE_BUMP = 10000,
60721+ GR_RLIM_NICE_BUMP = 1,
60722+ GR_RLIM_RTPRIO_BUMP = 1,
60723+ GR_RLIM_RTTIME_BUMP = 1000000
60724+};
60725+
60726+#endif
60727diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
60728new file mode 100644
60729index 0000000..da390f1
60730--- /dev/null
60731+++ b/include/linux/grinternal.h
60732@@ -0,0 +1,221 @@
60733+#ifndef __GRINTERNAL_H
60734+#define __GRINTERNAL_H
60735+
60736+#ifdef CONFIG_GRKERNSEC
60737+
60738+#include <linux/fs.h>
60739+#include <linux/mnt_namespace.h>
60740+#include <linux/nsproxy.h>
60741+#include <linux/gracl.h>
60742+#include <linux/grdefs.h>
60743+#include <linux/grmsg.h>
60744+
60745+void gr_add_learn_entry(const char *fmt, ...)
60746+ __attribute__ ((format (printf, 1, 2)));
60747+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
60748+ const struct vfsmount *mnt);
60749+__u32 gr_check_create(const struct dentry *new_dentry,
60750+ const struct dentry *parent,
60751+ const struct vfsmount *mnt, const __u32 mode);
60752+int gr_check_protected_task(const struct task_struct *task);
60753+__u32 to_gr_audit(const __u32 reqmode);
60754+int gr_set_acls(const int type);
60755+int gr_apply_subject_to_task(struct task_struct *task);
60756+int gr_acl_is_enabled(void);
60757+char gr_roletype_to_char(void);
60758+
60759+void gr_handle_alertkill(struct task_struct *task);
60760+char *gr_to_filename(const struct dentry *dentry,
60761+ const struct vfsmount *mnt);
60762+char *gr_to_filename1(const struct dentry *dentry,
60763+ const struct vfsmount *mnt);
60764+char *gr_to_filename2(const struct dentry *dentry,
60765+ const struct vfsmount *mnt);
60766+char *gr_to_filename3(const struct dentry *dentry,
60767+ const struct vfsmount *mnt);
60768+
60769+extern int grsec_enable_ptrace_readexec;
60770+extern int grsec_enable_harden_ptrace;
60771+extern int grsec_enable_link;
60772+extern int grsec_enable_fifo;
60773+extern int grsec_enable_execve;
60774+extern int grsec_enable_shm;
60775+extern int grsec_enable_execlog;
60776+extern int grsec_enable_signal;
60777+extern int grsec_enable_audit_ptrace;
60778+extern int grsec_enable_forkfail;
60779+extern int grsec_enable_time;
60780+extern int grsec_enable_rofs;
60781+extern int grsec_enable_chroot_shmat;
60782+extern int grsec_enable_chroot_mount;
60783+extern int grsec_enable_chroot_double;
60784+extern int grsec_enable_chroot_pivot;
60785+extern int grsec_enable_chroot_chdir;
60786+extern int grsec_enable_chroot_chmod;
60787+extern int grsec_enable_chroot_mknod;
60788+extern int grsec_enable_chroot_fchdir;
60789+extern int grsec_enable_chroot_nice;
60790+extern int grsec_enable_chroot_execlog;
60791+extern int grsec_enable_chroot_caps;
60792+extern int grsec_enable_chroot_sysctl;
60793+extern int grsec_enable_chroot_unix;
60794+extern int grsec_enable_tpe;
60795+extern int grsec_tpe_gid;
60796+extern int grsec_enable_tpe_all;
60797+extern int grsec_enable_tpe_invert;
60798+extern int grsec_enable_socket_all;
60799+extern int grsec_socket_all_gid;
60800+extern int grsec_enable_socket_client;
60801+extern int grsec_socket_client_gid;
60802+extern int grsec_enable_socket_server;
60803+extern int grsec_socket_server_gid;
60804+extern int grsec_audit_gid;
60805+extern int grsec_enable_group;
60806+extern int grsec_enable_audit_textrel;
60807+extern int grsec_enable_log_rwxmaps;
60808+extern int grsec_enable_mount;
60809+extern int grsec_enable_chdir;
60810+extern int grsec_resource_logging;
60811+extern int grsec_enable_blackhole;
60812+extern int grsec_lastack_retries;
60813+extern int grsec_enable_brute;
60814+extern int grsec_lock;
60815+
60816+extern spinlock_t grsec_alert_lock;
60817+extern unsigned long grsec_alert_wtime;
60818+extern unsigned long grsec_alert_fyet;
60819+
60820+extern spinlock_t grsec_audit_lock;
60821+
60822+extern rwlock_t grsec_exec_file_lock;
60823+
60824+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
60825+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
60826+ (tsk)->exec_file->f_vfsmnt) : "/")
60827+
60828+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
60829+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
60830+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
60831+
60832+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
60833+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
60834+ (tsk)->exec_file->f_vfsmnt) : "/")
60835+
60836+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
60837+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
60838+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
60839+
60840+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
60841+
60842+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
60843+
60844+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
60845+ (task)->pid, (cred)->uid, \
60846+ (cred)->euid, (cred)->gid, (cred)->egid, \
60847+ gr_parent_task_fullpath(task), \
60848+ (task)->real_parent->comm, (task)->real_parent->pid, \
60849+ (pcred)->uid, (pcred)->euid, \
60850+ (pcred)->gid, (pcred)->egid
60851+
60852+#define GR_CHROOT_CAPS {{ \
60853+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
60854+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
60855+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
60856+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
60857+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
60858+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
60859+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
60860+
60861+#define security_learn(normal_msg,args...) \
60862+({ \
60863+ read_lock(&grsec_exec_file_lock); \
60864+ gr_add_learn_entry(normal_msg "\n", ## args); \
60865+ read_unlock(&grsec_exec_file_lock); \
60866+})
60867+
60868+enum {
60869+ GR_DO_AUDIT,
60870+ GR_DONT_AUDIT,
60871+ /* used for non-audit messages that we shouldn't kill the task on */
60872+ GR_DONT_AUDIT_GOOD
60873+};
60874+
60875+enum {
60876+ GR_TTYSNIFF,
60877+ GR_RBAC,
60878+ GR_RBAC_STR,
60879+ GR_STR_RBAC,
60880+ GR_RBAC_MODE2,
60881+ GR_RBAC_MODE3,
60882+ GR_FILENAME,
60883+ GR_SYSCTL_HIDDEN,
60884+ GR_NOARGS,
60885+ GR_ONE_INT,
60886+ GR_ONE_INT_TWO_STR,
60887+ GR_ONE_STR,
60888+ GR_STR_INT,
60889+ GR_TWO_STR_INT,
60890+ GR_TWO_INT,
60891+ GR_TWO_U64,
60892+ GR_THREE_INT,
60893+ GR_FIVE_INT_TWO_STR,
60894+ GR_TWO_STR,
60895+ GR_THREE_STR,
60896+ GR_FOUR_STR,
60897+ GR_STR_FILENAME,
60898+ GR_FILENAME_STR,
60899+ GR_FILENAME_TWO_INT,
60900+ GR_FILENAME_TWO_INT_STR,
60901+ GR_TEXTREL,
60902+ GR_PTRACE,
60903+ GR_RESOURCE,
60904+ GR_CAP,
60905+ GR_SIG,
60906+ GR_SIG2,
60907+ GR_CRASH1,
60908+ GR_CRASH2,
60909+ GR_PSACCT,
60910+ GR_RWXMAP
60911+};
60912+
60913+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
60914+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
60915+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
60916+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
60917+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
60918+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
60919+#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)
60920+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
60921+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
60922+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
60923+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
60924+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
60925+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
60926+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
60927+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
60928+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
60929+#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)
60930+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
60931+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
60932+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
60933+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
60934+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
60935+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
60936+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
60937+#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)
60938+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
60939+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
60940+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
60941+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
60942+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
60943+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
60944+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
60945+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
60946+#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)
60947+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
60948+
60949+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
60950+
60951+#endif
60952+
60953+#endif
60954diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
60955new file mode 100644
60956index 0000000..ae576a1
60957--- /dev/null
60958+++ b/include/linux/grmsg.h
60959@@ -0,0 +1,109 @@
60960+#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"
60961+#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"
60962+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
60963+#define GR_STOPMOD_MSG "denied modification of module state by "
60964+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
60965+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
60966+#define GR_IOPERM_MSG "denied use of ioperm() by "
60967+#define GR_IOPL_MSG "denied use of iopl() by "
60968+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
60969+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
60970+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
60971+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
60972+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
60973+#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"
60974+#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"
60975+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
60976+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
60977+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
60978+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
60979+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
60980+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
60981+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
60982+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
60983+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
60984+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
60985+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
60986+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
60987+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
60988+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
60989+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
60990+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
60991+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
60992+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
60993+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
60994+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
60995+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
60996+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
60997+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
60998+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
60999+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
61000+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
61001+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
61002+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
61003+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
61004+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
61005+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
61006+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
61007+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
61008+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
61009+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
61010+#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"
61011+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
61012+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
61013+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
61014+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
61015+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
61016+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
61017+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
61018+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
61019+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
61020+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
61021+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
61022+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
61023+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
61024+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
61025+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
61026+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
61027+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
61028+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
61029+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
61030+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
61031+#define GR_FAILFORK_MSG "failed fork with errno %s by "
61032+#define GR_NICE_CHROOT_MSG "denied priority change by "
61033+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
61034+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
61035+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
61036+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
61037+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
61038+#define GR_TIME_MSG "time set by "
61039+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
61040+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
61041+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
61042+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
61043+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
61044+#define GR_BIND_MSG "denied bind() by "
61045+#define GR_CONNECT_MSG "denied connect() by "
61046+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
61047+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
61048+#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"
61049+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
61050+#define GR_CAP_ACL_MSG "use of %s denied for "
61051+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
61052+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
61053+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
61054+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
61055+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
61056+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
61057+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
61058+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
61059+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
61060+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
61061+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
61062+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
61063+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
61064+#define GR_VM86_MSG "denied use of vm86 by "
61065+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
61066+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
61067+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
61068+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
61069diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
61070new file mode 100644
61071index 0000000..acd05db
61072--- /dev/null
61073+++ b/include/linux/grsecurity.h
61074@@ -0,0 +1,232 @@
61075+#ifndef GR_SECURITY_H
61076+#define GR_SECURITY_H
61077+#include <linux/fs.h>
61078+#include <linux/fs_struct.h>
61079+#include <linux/binfmts.h>
61080+#include <linux/gracl.h>
61081+
61082+/* notify of brain-dead configs */
61083+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61084+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
61085+#endif
61086+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
61087+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
61088+#endif
61089+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
61090+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
61091+#endif
61092+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
61093+#error "CONFIG_PAX enabled, but no PaX options are enabled."
61094+#endif
61095+
61096+#include <linux/compat.h>
61097+
61098+struct user_arg_ptr {
61099+#ifdef CONFIG_COMPAT
61100+ bool is_compat;
61101+#endif
61102+ union {
61103+ const char __user *const __user *native;
61104+#ifdef CONFIG_COMPAT
61105+ compat_uptr_t __user *compat;
61106+#endif
61107+ } ptr;
61108+};
61109+
61110+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
61111+void gr_handle_brute_check(void);
61112+void gr_handle_kernel_exploit(void);
61113+int gr_process_user_ban(void);
61114+
61115+char gr_roletype_to_char(void);
61116+
61117+int gr_acl_enable_at_secure(void);
61118+
61119+int gr_check_user_change(int real, int effective, int fs);
61120+int gr_check_group_change(int real, int effective, int fs);
61121+
61122+void gr_del_task_from_ip_table(struct task_struct *p);
61123+
61124+int gr_pid_is_chrooted(struct task_struct *p);
61125+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
61126+int gr_handle_chroot_nice(void);
61127+int gr_handle_chroot_sysctl(const int op);
61128+int gr_handle_chroot_setpriority(struct task_struct *p,
61129+ const int niceval);
61130+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
61131+int gr_handle_chroot_chroot(const struct dentry *dentry,
61132+ const struct vfsmount *mnt);
61133+void gr_handle_chroot_chdir(struct path *path);
61134+int gr_handle_chroot_chmod(const struct dentry *dentry,
61135+ const struct vfsmount *mnt, const int mode);
61136+int gr_handle_chroot_mknod(const struct dentry *dentry,
61137+ const struct vfsmount *mnt, const int mode);
61138+int gr_handle_chroot_mount(const struct dentry *dentry,
61139+ const struct vfsmount *mnt,
61140+ const char *dev_name);
61141+int gr_handle_chroot_pivot(void);
61142+int gr_handle_chroot_unix(const pid_t pid);
61143+
61144+int gr_handle_rawio(const struct inode *inode);
61145+
61146+void gr_handle_ioperm(void);
61147+void gr_handle_iopl(void);
61148+
61149+umode_t gr_acl_umask(void);
61150+
61151+int gr_tpe_allow(const struct file *file);
61152+
61153+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
61154+void gr_clear_chroot_entries(struct task_struct *task);
61155+
61156+void gr_log_forkfail(const int retval);
61157+void gr_log_timechange(void);
61158+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
61159+void gr_log_chdir(const struct dentry *dentry,
61160+ const struct vfsmount *mnt);
61161+void gr_log_chroot_exec(const struct dentry *dentry,
61162+ const struct vfsmount *mnt);
61163+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
61164+void gr_log_remount(const char *devname, const int retval);
61165+void gr_log_unmount(const char *devname, const int retval);
61166+void gr_log_mount(const char *from, const char *to, const int retval);
61167+void gr_log_textrel(struct vm_area_struct *vma);
61168+void gr_log_rwxmmap(struct file *file);
61169+void gr_log_rwxmprotect(struct file *file);
61170+
61171+int gr_handle_follow_link(const struct inode *parent,
61172+ const struct inode *inode,
61173+ const struct dentry *dentry,
61174+ const struct vfsmount *mnt);
61175+int gr_handle_fifo(const struct dentry *dentry,
61176+ const struct vfsmount *mnt,
61177+ const struct dentry *dir, const int flag,
61178+ const int acc_mode);
61179+int gr_handle_hardlink(const struct dentry *dentry,
61180+ const struct vfsmount *mnt,
61181+ struct inode *inode,
61182+ const int mode, const char *to);
61183+
61184+int gr_is_capable(const int cap);
61185+int gr_is_capable_nolog(const int cap);
61186+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
61187+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
61188+
61189+void gr_learn_resource(const struct task_struct *task, const int limit,
61190+ const unsigned long wanted, const int gt);
61191+void gr_copy_label(struct task_struct *tsk);
61192+void gr_handle_crash(struct task_struct *task, const int sig);
61193+int gr_handle_signal(const struct task_struct *p, const int sig);
61194+int gr_check_crash_uid(const uid_t uid);
61195+int gr_check_protected_task(const struct task_struct *task);
61196+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
61197+int gr_acl_handle_mmap(const struct file *file,
61198+ const unsigned long prot);
61199+int gr_acl_handle_mprotect(const struct file *file,
61200+ const unsigned long prot);
61201+int gr_check_hidden_task(const struct task_struct *tsk);
61202+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
61203+ const struct vfsmount *mnt);
61204+__u32 gr_acl_handle_utime(const struct dentry *dentry,
61205+ const struct vfsmount *mnt);
61206+__u32 gr_acl_handle_access(const struct dentry *dentry,
61207+ const struct vfsmount *mnt, const int fmode);
61208+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
61209+ const struct vfsmount *mnt, umode_t *mode);
61210+__u32 gr_acl_handle_chown(const struct dentry *dentry,
61211+ const struct vfsmount *mnt);
61212+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
61213+ const struct vfsmount *mnt);
61214+int gr_handle_ptrace(struct task_struct *task, const long request);
61215+int gr_handle_proc_ptrace(struct task_struct *task);
61216+__u32 gr_acl_handle_execve(const struct dentry *dentry,
61217+ const struct vfsmount *mnt);
61218+int gr_check_crash_exec(const struct file *filp);
61219+int gr_acl_is_enabled(void);
61220+void gr_set_kernel_label(struct task_struct *task);
61221+void gr_set_role_label(struct task_struct *task, const uid_t uid,
61222+ const gid_t gid);
61223+int gr_set_proc_label(const struct dentry *dentry,
61224+ const struct vfsmount *mnt,
61225+ const int unsafe_flags);
61226+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
61227+ const struct vfsmount *mnt);
61228+__u32 gr_acl_handle_open(const struct dentry *dentry,
61229+ const struct vfsmount *mnt, int acc_mode);
61230+__u32 gr_acl_handle_creat(const struct dentry *dentry,
61231+ const struct dentry *p_dentry,
61232+ const struct vfsmount *p_mnt,
61233+ int open_flags, int acc_mode, const int imode);
61234+void gr_handle_create(const struct dentry *dentry,
61235+ const struct vfsmount *mnt);
61236+void gr_handle_proc_create(const struct dentry *dentry,
61237+ const struct inode *inode);
61238+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
61239+ const struct dentry *parent_dentry,
61240+ const struct vfsmount *parent_mnt,
61241+ const int mode);
61242+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
61243+ const struct dentry *parent_dentry,
61244+ const struct vfsmount *parent_mnt);
61245+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
61246+ const struct vfsmount *mnt);
61247+void gr_handle_delete(const ino_t ino, const dev_t dev);
61248+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
61249+ const struct vfsmount *mnt);
61250+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
61251+ const struct dentry *parent_dentry,
61252+ const struct vfsmount *parent_mnt,
61253+ const char *from);
61254+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
61255+ const struct dentry *parent_dentry,
61256+ const struct vfsmount *parent_mnt,
61257+ const struct dentry *old_dentry,
61258+ const struct vfsmount *old_mnt, const char *to);
61259+int gr_acl_handle_rename(struct dentry *new_dentry,
61260+ struct dentry *parent_dentry,
61261+ const struct vfsmount *parent_mnt,
61262+ struct dentry *old_dentry,
61263+ struct inode *old_parent_inode,
61264+ struct vfsmount *old_mnt, const char *newname);
61265+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61266+ struct dentry *old_dentry,
61267+ struct dentry *new_dentry,
61268+ struct vfsmount *mnt, const __u8 replace);
61269+__u32 gr_check_link(const struct dentry *new_dentry,
61270+ const struct dentry *parent_dentry,
61271+ const struct vfsmount *parent_mnt,
61272+ const struct dentry *old_dentry,
61273+ const struct vfsmount *old_mnt);
61274+int gr_acl_handle_filldir(const struct file *file, const char *name,
61275+ const unsigned int namelen, const ino_t ino);
61276+
61277+__u32 gr_acl_handle_unix(const struct dentry *dentry,
61278+ const struct vfsmount *mnt);
61279+void gr_acl_handle_exit(void);
61280+void gr_acl_handle_psacct(struct task_struct *task, const long code);
61281+int gr_acl_handle_procpidmem(const struct task_struct *task);
61282+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
61283+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
61284+void gr_audit_ptrace(struct task_struct *task);
61285+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
61286+
61287+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
61288+
61289+#ifdef CONFIG_GRKERNSEC
61290+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
61291+void gr_handle_vm86(void);
61292+void gr_handle_mem_readwrite(u64 from, u64 to);
61293+
61294+void gr_log_badprocpid(const char *entry);
61295+
61296+extern int grsec_enable_dmesg;
61297+extern int grsec_disable_privio;
61298+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61299+extern int grsec_enable_chroot_findtask;
61300+#endif
61301+#ifdef CONFIG_GRKERNSEC_SETXID
61302+extern int grsec_enable_setxid;
61303+#endif
61304+#endif
61305+
61306+#endif
61307diff --git a/include/linux/grsock.h b/include/linux/grsock.h
61308new file mode 100644
61309index 0000000..e7ffaaf
61310--- /dev/null
61311+++ b/include/linux/grsock.h
61312@@ -0,0 +1,19 @@
61313+#ifndef __GRSOCK_H
61314+#define __GRSOCK_H
61315+
61316+extern void gr_attach_curr_ip(const struct sock *sk);
61317+extern int gr_handle_sock_all(const int family, const int type,
61318+ const int protocol);
61319+extern int gr_handle_sock_server(const struct sockaddr *sck);
61320+extern int gr_handle_sock_server_other(const struct sock *sck);
61321+extern int gr_handle_sock_client(const struct sockaddr *sck);
61322+extern int gr_search_connect(struct socket * sock,
61323+ struct sockaddr_in * addr);
61324+extern int gr_search_bind(struct socket * sock,
61325+ struct sockaddr_in * addr);
61326+extern int gr_search_listen(struct socket * sock);
61327+extern int gr_search_accept(struct socket * sock);
61328+extern int gr_search_socket(const int domain, const int type,
61329+ const int protocol);
61330+
61331+#endif
61332diff --git a/include/linux/hid.h b/include/linux/hid.h
61333index 3a95da6..51986f1 100644
61334--- a/include/linux/hid.h
61335+++ b/include/linux/hid.h
61336@@ -696,7 +696,7 @@ struct hid_ll_driver {
61337 unsigned int code, int value);
61338
61339 int (*parse)(struct hid_device *hdev);
61340-};
61341+} __no_const;
61342
61343 #define PM_HINT_FULLON 1<<5
61344 #define PM_HINT_NORMAL 1<<1
61345diff --git a/include/linux/highmem.h b/include/linux/highmem.h
61346index d3999b4..1304cb4 100644
61347--- a/include/linux/highmem.h
61348+++ b/include/linux/highmem.h
61349@@ -221,6 +221,18 @@ static inline void clear_highpage(struct page *page)
61350 kunmap_atomic(kaddr);
61351 }
61352
61353+static inline void sanitize_highpage(struct page *page)
61354+{
61355+ void *kaddr;
61356+ unsigned long flags;
61357+
61358+ local_irq_save(flags);
61359+ kaddr = kmap_atomic(page);
61360+ clear_page(kaddr);
61361+ kunmap_atomic(kaddr);
61362+ local_irq_restore(flags);
61363+}
61364+
61365 static inline void zero_user_segments(struct page *page,
61366 unsigned start1, unsigned end1,
61367 unsigned start2, unsigned end2)
61368diff --git a/include/linux/i2c.h b/include/linux/i2c.h
61369index 195d8b3..e20cfab 100644
61370--- a/include/linux/i2c.h
61371+++ b/include/linux/i2c.h
61372@@ -365,6 +365,7 @@ struct i2c_algorithm {
61373 /* To determine what the adapter supports */
61374 u32 (*functionality) (struct i2c_adapter *);
61375 };
61376+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
61377
61378 /*
61379 * i2c_adapter is the structure used to identify a physical i2c bus along
61380diff --git a/include/linux/i2o.h b/include/linux/i2o.h
61381index d23c3c2..eb63c81 100644
61382--- a/include/linux/i2o.h
61383+++ b/include/linux/i2o.h
61384@@ -565,7 +565,7 @@ struct i2o_controller {
61385 struct i2o_device *exec; /* Executive */
61386 #if BITS_PER_LONG == 64
61387 spinlock_t context_list_lock; /* lock for context_list */
61388- atomic_t context_list_counter; /* needed for unique contexts */
61389+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
61390 struct list_head context_list; /* list of context id's
61391 and pointers */
61392 #endif
61393diff --git a/include/linux/if_team.h b/include/linux/if_team.h
61394index 58404b0..439ed95 100644
61395--- a/include/linux/if_team.h
61396+++ b/include/linux/if_team.h
61397@@ -64,6 +64,7 @@ struct team_mode_ops {
61398 void (*port_leave)(struct team *team, struct team_port *port);
61399 void (*port_change_mac)(struct team *team, struct team_port *port);
61400 };
61401+typedef struct team_mode_ops __no_const team_mode_ops_no_const;
61402
61403 enum team_option_type {
61404 TEAM_OPTION_TYPE_U32,
61405@@ -112,7 +113,7 @@ struct team {
61406 struct list_head option_list;
61407
61408 const struct team_mode *mode;
61409- struct team_mode_ops ops;
61410+ team_mode_ops_no_const ops;
61411 long mode_priv[TEAM_MODE_PRIV_LONGS];
61412 };
61413
61414diff --git a/include/linux/init.h b/include/linux/init.h
61415index 6b95109..4aca62c 100644
61416--- a/include/linux/init.h
61417+++ b/include/linux/init.h
61418@@ -294,13 +294,13 @@ void __init parse_early_options(char *cmdline);
61419
61420 /* Each module must use one module_init(). */
61421 #define module_init(initfn) \
61422- static inline initcall_t __inittest(void) \
61423+ static inline __used initcall_t __inittest(void) \
61424 { return initfn; } \
61425 int init_module(void) __attribute__((alias(#initfn)));
61426
61427 /* This is only required if you want to be unloadable. */
61428 #define module_exit(exitfn) \
61429- static inline exitcall_t __exittest(void) \
61430+ static inline __used exitcall_t __exittest(void) \
61431 { return exitfn; } \
61432 void cleanup_module(void) __attribute__((alias(#exitfn)));
61433
61434diff --git a/include/linux/init_task.h b/include/linux/init_task.h
61435index e4baff5..83bb175 100644
61436--- a/include/linux/init_task.h
61437+++ b/include/linux/init_task.h
61438@@ -134,6 +134,12 @@ extern struct cred init_cred;
61439
61440 #define INIT_TASK_COMM "swapper"
61441
61442+#ifdef CONFIG_X86
61443+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
61444+#else
61445+#define INIT_TASK_THREAD_INFO
61446+#endif
61447+
61448 /*
61449 * INIT_TASK is used to set up the first task table, touch at
61450 * your own risk!. Base=0, limit=0x1fffff (=2MB)
61451@@ -172,6 +178,7 @@ extern struct cred init_cred;
61452 RCU_INIT_POINTER(.cred, &init_cred), \
61453 .comm = INIT_TASK_COMM, \
61454 .thread = INIT_THREAD, \
61455+ INIT_TASK_THREAD_INFO \
61456 .fs = &init_fs, \
61457 .files = &init_files, \
61458 .signal = &init_signals, \
61459diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
61460index e6ca56d..8583707 100644
61461--- a/include/linux/intel-iommu.h
61462+++ b/include/linux/intel-iommu.h
61463@@ -296,7 +296,7 @@ struct iommu_flush {
61464 u8 fm, u64 type);
61465 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
61466 unsigned int size_order, u64 type);
61467-};
61468+} __no_const;
61469
61470 enum {
61471 SR_DMAR_FECTL_REG,
61472diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
61473index 2aea5d2..0b82f0c 100644
61474--- a/include/linux/interrupt.h
61475+++ b/include/linux/interrupt.h
61476@@ -439,7 +439,7 @@ enum
61477 /* map softirq index to softirq name. update 'softirq_to_name' in
61478 * kernel/softirq.c when adding a new softirq.
61479 */
61480-extern char *softirq_to_name[NR_SOFTIRQS];
61481+extern const char * const softirq_to_name[NR_SOFTIRQS];
61482
61483 /* softirq mask and active fields moved to irq_cpustat_t in
61484 * asm/hardirq.h to get better cache usage. KAO
61485@@ -447,12 +447,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
61486
61487 struct softirq_action
61488 {
61489- void (*action)(struct softirq_action *);
61490+ void (*action)(void);
61491 };
61492
61493 asmlinkage void do_softirq(void);
61494 asmlinkage void __do_softirq(void);
61495-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
61496+extern void open_softirq(int nr, void (*action)(void));
61497 extern void softirq_init(void);
61498 extern void __raise_softirq_irqoff(unsigned int nr);
61499
61500diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
61501index 3875719..4cd454c 100644
61502--- a/include/linux/kallsyms.h
61503+++ b/include/linux/kallsyms.h
61504@@ -15,7 +15,8 @@
61505
61506 struct module;
61507
61508-#ifdef CONFIG_KALLSYMS
61509+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
61510+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
61511 /* Lookup the address for a symbol. Returns 0 if not found. */
61512 unsigned long kallsyms_lookup_name(const char *name);
61513
61514@@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
61515 /* Stupid that this does nothing, but I didn't create this mess. */
61516 #define __print_symbol(fmt, addr)
61517 #endif /*CONFIG_KALLSYMS*/
61518+#else /* when included by kallsyms.c, vsnprintf.c, or
61519+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
61520+extern void __print_symbol(const char *fmt, unsigned long address);
61521+extern int sprint_backtrace(char *buffer, unsigned long address);
61522+extern int sprint_symbol(char *buffer, unsigned long address);
61523+const char *kallsyms_lookup(unsigned long addr,
61524+ unsigned long *symbolsize,
61525+ unsigned long *offset,
61526+ char **modname, char *namebuf);
61527+#endif
61528
61529 /* This macro allows us to keep printk typechecking */
61530 static __printf(1, 2)
61531diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
61532index c4d2fc1..5df9c19 100644
61533--- a/include/linux/kgdb.h
61534+++ b/include/linux/kgdb.h
61535@@ -53,7 +53,7 @@ extern int kgdb_connected;
61536 extern int kgdb_io_module_registered;
61537
61538 extern atomic_t kgdb_setting_breakpoint;
61539-extern atomic_t kgdb_cpu_doing_single_step;
61540+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
61541
61542 extern struct task_struct *kgdb_usethread;
61543 extern struct task_struct *kgdb_contthread;
61544@@ -252,7 +252,7 @@ struct kgdb_arch {
61545 void (*disable_hw_break)(struct pt_regs *regs);
61546 void (*remove_all_hw_break)(void);
61547 void (*correct_hw_break)(void);
61548-};
61549+} __do_const;
61550
61551 /**
61552 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
61553@@ -277,7 +277,7 @@ struct kgdb_io {
61554 void (*pre_exception) (void);
61555 void (*post_exception) (void);
61556 int is_console;
61557-};
61558+} __do_const;
61559
61560 extern struct kgdb_arch arch_kgdb_ops;
61561
61562diff --git a/include/linux/kmod.h b/include/linux/kmod.h
61563index dd99c32..da06047 100644
61564--- a/include/linux/kmod.h
61565+++ b/include/linux/kmod.h
61566@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
61567 * usually useless though. */
61568 extern __printf(2, 3)
61569 int __request_module(bool wait, const char *name, ...);
61570+extern __printf(3, 4)
61571+int ___request_module(bool wait, char *param_name, const char *name, ...);
61572 #define request_module(mod...) __request_module(true, mod)
61573 #define request_module_nowait(mod...) __request_module(false, mod)
61574 #define try_then_request_module(x, mod...) \
61575diff --git a/include/linux/kref.h b/include/linux/kref.h
61576index 9c07dce..a92fa71 100644
61577--- a/include/linux/kref.h
61578+++ b/include/linux/kref.h
61579@@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
61580 static inline int kref_sub(struct kref *kref, unsigned int count,
61581 void (*release)(struct kref *kref))
61582 {
61583- WARN_ON(release == NULL);
61584+ BUG_ON(release == NULL);
61585
61586 if (atomic_sub_and_test((int) count, &kref->refcount)) {
61587 release(kref);
61588diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
61589index 72cbf08..dd0201d 100644
61590--- a/include/linux/kvm_host.h
61591+++ b/include/linux/kvm_host.h
61592@@ -322,7 +322,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
61593 void vcpu_load(struct kvm_vcpu *vcpu);
61594 void vcpu_put(struct kvm_vcpu *vcpu);
61595
61596-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
61597+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
61598 struct module *module);
61599 void kvm_exit(void);
61600
61601@@ -486,7 +486,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
61602 struct kvm_guest_debug *dbg);
61603 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
61604
61605-int kvm_arch_init(void *opaque);
61606+int kvm_arch_init(const void *opaque);
61607 void kvm_arch_exit(void);
61608
61609 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
61610diff --git a/include/linux/libata.h b/include/linux/libata.h
61611index 6e887c7..4539601 100644
61612--- a/include/linux/libata.h
61613+++ b/include/linux/libata.h
61614@@ -910,7 +910,7 @@ struct ata_port_operations {
61615 * fields must be pointers.
61616 */
61617 const struct ata_port_operations *inherits;
61618-};
61619+} __do_const;
61620
61621 struct ata_port_info {
61622 unsigned long flags;
61623diff --git a/include/linux/mca.h b/include/linux/mca.h
61624index 3797270..7765ede 100644
61625--- a/include/linux/mca.h
61626+++ b/include/linux/mca.h
61627@@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
61628 int region);
61629 void * (*mca_transform_memory)(struct mca_device *,
61630 void *memory);
61631-};
61632+} __no_const;
61633
61634 struct mca_bus {
61635 u64 default_dma_mask;
61636diff --git a/include/linux/memory.h b/include/linux/memory.h
61637index 1ac7f6e..a5794d0 100644
61638--- a/include/linux/memory.h
61639+++ b/include/linux/memory.h
61640@@ -143,7 +143,7 @@ struct memory_accessor {
61641 size_t count);
61642 ssize_t (*write)(struct memory_accessor *, const char *buf,
61643 off_t offset, size_t count);
61644-};
61645+} __no_const;
61646
61647 /*
61648 * Kernel text modification mutex, used for code patching. Users of this lock
61649diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
61650index ee96cd5..7823c3a 100644
61651--- a/include/linux/mfd/abx500.h
61652+++ b/include/linux/mfd/abx500.h
61653@@ -455,6 +455,7 @@ struct abx500_ops {
61654 int (*event_registers_startup_state_get) (struct device *, u8 *);
61655 int (*startup_irq_enabled) (struct device *, unsigned int);
61656 };
61657+typedef struct abx500_ops __no_const abx500_ops_no_const;
61658
61659 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
61660 void abx500_remove_ops(struct device *dev);
61661diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
61662index 9b07725..3d55001 100644
61663--- a/include/linux/mfd/abx500/ux500_chargalg.h
61664+++ b/include/linux/mfd/abx500/ux500_chargalg.h
61665@@ -19,7 +19,7 @@ struct ux500_charger_ops {
61666 int (*enable) (struct ux500_charger *, int, int, int);
61667 int (*kick_wd) (struct ux500_charger *);
61668 int (*update_curr) (struct ux500_charger *, int);
61669-};
61670+} __no_const;
61671
61672 /**
61673 * struct ux500_charger - power supply ux500 charger sub class
61674diff --git a/include/linux/mm.h b/include/linux/mm.h
61675index 74aa71b..4ae97ba 100644
61676--- a/include/linux/mm.h
61677+++ b/include/linux/mm.h
61678@@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
61679
61680 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
61681 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
61682+
61683+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
61684+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
61685+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
61686+#else
61687 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
61688+#endif
61689+
61690 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
61691 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
61692
61693@@ -1013,34 +1020,6 @@ int set_page_dirty(struct page *page);
61694 int set_page_dirty_lock(struct page *page);
61695 int clear_page_dirty_for_io(struct page *page);
61696
61697-/* Is the vma a continuation of the stack vma above it? */
61698-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
61699-{
61700- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
61701-}
61702-
61703-static inline int stack_guard_page_start(struct vm_area_struct *vma,
61704- unsigned long addr)
61705-{
61706- return (vma->vm_flags & VM_GROWSDOWN) &&
61707- (vma->vm_start == addr) &&
61708- !vma_growsdown(vma->vm_prev, addr);
61709-}
61710-
61711-/* Is the vma a continuation of the stack vma below it? */
61712-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
61713-{
61714- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
61715-}
61716-
61717-static inline int stack_guard_page_end(struct vm_area_struct *vma,
61718- unsigned long addr)
61719-{
61720- return (vma->vm_flags & VM_GROWSUP) &&
61721- (vma->vm_end == addr) &&
61722- !vma_growsup(vma->vm_next, addr);
61723-}
61724-
61725 extern pid_t
61726 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
61727
61728@@ -1139,6 +1118,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
61729 }
61730 #endif
61731
61732+#ifdef CONFIG_MMU
61733+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
61734+#else
61735+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
61736+{
61737+ return __pgprot(0);
61738+}
61739+#endif
61740+
61741 int vma_wants_writenotify(struct vm_area_struct *vma);
61742
61743 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
61744@@ -1157,8 +1145,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
61745 {
61746 return 0;
61747 }
61748+
61749+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
61750+ unsigned long address)
61751+{
61752+ return 0;
61753+}
61754 #else
61755 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
61756+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
61757 #endif
61758
61759 #ifdef __PAGETABLE_PMD_FOLDED
61760@@ -1167,8 +1162,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
61761 {
61762 return 0;
61763 }
61764+
61765+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
61766+ unsigned long address)
61767+{
61768+ return 0;
61769+}
61770 #else
61771 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
61772+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
61773 #endif
61774
61775 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
61776@@ -1186,11 +1188,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
61777 NULL: pud_offset(pgd, address);
61778 }
61779
61780+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
61781+{
61782+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
61783+ NULL: pud_offset(pgd, address);
61784+}
61785+
61786 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
61787 {
61788 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
61789 NULL: pmd_offset(pud, address);
61790 }
61791+
61792+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
61793+{
61794+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
61795+ NULL: pmd_offset(pud, address);
61796+}
61797 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
61798
61799 #if USE_SPLIT_PTLOCKS
61800@@ -1400,6 +1414,7 @@ extern unsigned long do_mmap(struct file *, unsigned long,
61801 unsigned long, unsigned long,
61802 unsigned long, unsigned long);
61803 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
61804+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
61805
61806 /* These take the mm semaphore themselves */
61807 extern unsigned long vm_brk(unsigned long, unsigned long);
61808@@ -1462,6 +1477,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
61809 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
61810 struct vm_area_struct **pprev);
61811
61812+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
61813+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
61814+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
61815+
61816 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
61817 NULL if none. Assume start_addr < end_addr. */
61818 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
61819@@ -1490,15 +1509,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
61820 return vma;
61821 }
61822
61823-#ifdef CONFIG_MMU
61824-pgprot_t vm_get_page_prot(unsigned long vm_flags);
61825-#else
61826-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
61827-{
61828- return __pgprot(0);
61829-}
61830-#endif
61831-
61832 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
61833 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
61834 unsigned long pfn, unsigned long size, pgprot_t);
61835@@ -1602,7 +1612,7 @@ extern int unpoison_memory(unsigned long pfn);
61836 extern int sysctl_memory_failure_early_kill;
61837 extern int sysctl_memory_failure_recovery;
61838 extern void shake_page(struct page *p, int access);
61839-extern atomic_long_t mce_bad_pages;
61840+extern atomic_long_unchecked_t mce_bad_pages;
61841 extern int soft_offline_page(struct page *page, int flags);
61842
61843 extern void dump_page(struct page *page);
61844@@ -1633,5 +1643,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
61845 static inline bool page_is_guard(struct page *page) { return false; }
61846 #endif /* CONFIG_DEBUG_PAGEALLOC */
61847
61848+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
61849+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
61850+#else
61851+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
61852+#endif
61853+
61854 #endif /* __KERNEL__ */
61855 #endif /* _LINUX_MM_H */
61856diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
61857index 3cc3062..efeaeb7 100644
61858--- a/include/linux/mm_types.h
61859+++ b/include/linux/mm_types.h
61860@@ -252,6 +252,8 @@ struct vm_area_struct {
61861 #ifdef CONFIG_NUMA
61862 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
61863 #endif
61864+
61865+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
61866 };
61867
61868 struct core_thread {
61869@@ -326,7 +328,7 @@ struct mm_struct {
61870 unsigned long def_flags;
61871 unsigned long nr_ptes; /* Page table pages */
61872 unsigned long start_code, end_code, start_data, end_data;
61873- unsigned long start_brk, brk, start_stack;
61874+ unsigned long brk_gap, start_brk, brk, start_stack;
61875 unsigned long arg_start, arg_end, env_start, env_end;
61876
61877 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
61878@@ -388,6 +390,24 @@ struct mm_struct {
61879 #ifdef CONFIG_CPUMASK_OFFSTACK
61880 struct cpumask cpumask_allocation;
61881 #endif
61882+
61883+#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)
61884+ unsigned long pax_flags;
61885+#endif
61886+
61887+#ifdef CONFIG_PAX_DLRESOLVE
61888+ unsigned long call_dl_resolve;
61889+#endif
61890+
61891+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
61892+ unsigned long call_syscall;
61893+#endif
61894+
61895+#ifdef CONFIG_PAX_ASLR
61896+ unsigned long delta_mmap; /* randomized offset */
61897+ unsigned long delta_stack; /* randomized offset */
61898+#endif
61899+
61900 };
61901
61902 static inline void mm_init_cpumask(struct mm_struct *mm)
61903diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
61904index 1d1b1e1..2a13c78 100644
61905--- a/include/linux/mmu_notifier.h
61906+++ b/include/linux/mmu_notifier.h
61907@@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
61908 */
61909 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
61910 ({ \
61911- pte_t __pte; \
61912+ pte_t ___pte; \
61913 struct vm_area_struct *___vma = __vma; \
61914 unsigned long ___address = __address; \
61915- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
61916+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
61917 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
61918- __pte; \
61919+ ___pte; \
61920 })
61921
61922 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
61923diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
61924index dff7115..0e001c8 100644
61925--- a/include/linux/mmzone.h
61926+++ b/include/linux/mmzone.h
61927@@ -380,7 +380,7 @@ struct zone {
61928 unsigned long flags; /* zone flags, see below */
61929
61930 /* Zone statistics */
61931- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61932+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61933
61934 /*
61935 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
61936diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
61937index 501da4c..ba79bb4 100644
61938--- a/include/linux/mod_devicetable.h
61939+++ b/include/linux/mod_devicetable.h
61940@@ -12,7 +12,7 @@
61941 typedef unsigned long kernel_ulong_t;
61942 #endif
61943
61944-#define PCI_ANY_ID (~0)
61945+#define PCI_ANY_ID ((__u16)~0)
61946
61947 struct pci_device_id {
61948 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
61949@@ -131,7 +131,7 @@ struct usb_device_id {
61950 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
61951 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
61952
61953-#define HID_ANY_ID (~0)
61954+#define HID_ANY_ID (~0U)
61955
61956 struct hid_device_id {
61957 __u16 bus;
61958diff --git a/include/linux/module.h b/include/linux/module.h
61959index fbcafe2..e5d9587 100644
61960--- a/include/linux/module.h
61961+++ b/include/linux/module.h
61962@@ -17,6 +17,7 @@
61963 #include <linux/moduleparam.h>
61964 #include <linux/tracepoint.h>
61965 #include <linux/export.h>
61966+#include <linux/fs.h>
61967
61968 #include <linux/percpu.h>
61969 #include <asm/module.h>
61970@@ -273,19 +274,16 @@ struct module
61971 int (*init)(void);
61972
61973 /* If this is non-NULL, vfree after init() returns */
61974- void *module_init;
61975+ void *module_init_rx, *module_init_rw;
61976
61977 /* Here is the actual code + data, vfree'd on unload. */
61978- void *module_core;
61979+ void *module_core_rx, *module_core_rw;
61980
61981 /* Here are the sizes of the init and core sections */
61982- unsigned int init_size, core_size;
61983+ unsigned int init_size_rw, core_size_rw;
61984
61985 /* The size of the executable code in each section. */
61986- unsigned int init_text_size, core_text_size;
61987-
61988- /* Size of RO sections of the module (text+rodata) */
61989- unsigned int init_ro_size, core_ro_size;
61990+ unsigned int init_size_rx, core_size_rx;
61991
61992 /* Arch-specific module values */
61993 struct mod_arch_specific arch;
61994@@ -341,6 +339,10 @@ struct module
61995 #ifdef CONFIG_EVENT_TRACING
61996 struct ftrace_event_call **trace_events;
61997 unsigned int num_trace_events;
61998+ struct file_operations trace_id;
61999+ struct file_operations trace_enable;
62000+ struct file_operations trace_format;
62001+ struct file_operations trace_filter;
62002 #endif
62003 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
62004 unsigned int num_ftrace_callsites;
62005@@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
62006 bool is_module_percpu_address(unsigned long addr);
62007 bool is_module_text_address(unsigned long addr);
62008
62009+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
62010+{
62011+
62012+#ifdef CONFIG_PAX_KERNEXEC
62013+ if (ktla_ktva(addr) >= (unsigned long)start &&
62014+ ktla_ktva(addr) < (unsigned long)start + size)
62015+ return 1;
62016+#endif
62017+
62018+ return ((void *)addr >= start && (void *)addr < start + size);
62019+}
62020+
62021+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
62022+{
62023+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
62024+}
62025+
62026+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
62027+{
62028+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
62029+}
62030+
62031+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
62032+{
62033+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
62034+}
62035+
62036+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
62037+{
62038+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
62039+}
62040+
62041 static inline int within_module_core(unsigned long addr, struct module *mod)
62042 {
62043- return (unsigned long)mod->module_core <= addr &&
62044- addr < (unsigned long)mod->module_core + mod->core_size;
62045+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
62046 }
62047
62048 static inline int within_module_init(unsigned long addr, struct module *mod)
62049 {
62050- return (unsigned long)mod->module_init <= addr &&
62051- addr < (unsigned long)mod->module_init + mod->init_size;
62052+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
62053 }
62054
62055 /* Search for module by name: must hold module_mutex. */
62056diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
62057index b2be02e..72d2f78 100644
62058--- a/include/linux/moduleloader.h
62059+++ b/include/linux/moduleloader.h
62060@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
62061
62062 /* Allocator used for allocating struct module, core sections and init
62063 sections. Returns NULL on failure. */
62064-void *module_alloc(unsigned long size);
62065+void *module_alloc(unsigned long size) __size_overflow(1);
62066+
62067+#ifdef CONFIG_PAX_KERNEXEC
62068+void *module_alloc_exec(unsigned long size) __size_overflow(1);
62069+#else
62070+#define module_alloc_exec(x) module_alloc(x)
62071+#endif
62072
62073 /* Free memory returned from module_alloc. */
62074 void module_free(struct module *mod, void *module_region);
62075
62076+#ifdef CONFIG_PAX_KERNEXEC
62077+void module_free_exec(struct module *mod, void *module_region);
62078+#else
62079+#define module_free_exec(x, y) module_free((x), (y))
62080+#endif
62081+
62082 /* Apply the given relocation to the (simplified) ELF. Return -error
62083 or 0. */
62084 int apply_relocate(Elf_Shdr *sechdrs,
62085diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
62086index 944bc18..042d291 100644
62087--- a/include/linux/moduleparam.h
62088+++ b/include/linux/moduleparam.h
62089@@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
62090 * @len is usually just sizeof(string).
62091 */
62092 #define module_param_string(name, string, len, perm) \
62093- static const struct kparam_string __param_string_##name \
62094+ static const struct kparam_string __param_string_##name __used \
62095 = { len, string }; \
62096 __module_param_call(MODULE_PARAM_PREFIX, name, \
62097 &param_ops_string, \
62098@@ -424,7 +424,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
62099 */
62100 #define module_param_array_named(name, array, type, nump, perm) \
62101 param_check_##type(name, &(array)[0]); \
62102- static const struct kparam_array __param_arr_##name \
62103+ static const struct kparam_array __param_arr_##name __used \
62104 = { .max = ARRAY_SIZE(array), .num = nump, \
62105 .ops = &param_ops_##type, \
62106 .elemsize = sizeof(array[0]), .elem = array }; \
62107diff --git a/include/linux/namei.h b/include/linux/namei.h
62108index ffc0213..2c1f2cb 100644
62109--- a/include/linux/namei.h
62110+++ b/include/linux/namei.h
62111@@ -24,7 +24,7 @@ struct nameidata {
62112 unsigned seq;
62113 int last_type;
62114 unsigned depth;
62115- char *saved_names[MAX_NESTED_LINKS + 1];
62116+ const char *saved_names[MAX_NESTED_LINKS + 1];
62117
62118 /* Intent data */
62119 union {
62120@@ -94,12 +94,12 @@ extern int follow_up(struct path *);
62121 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
62122 extern void unlock_rename(struct dentry *, struct dentry *);
62123
62124-static inline void nd_set_link(struct nameidata *nd, char *path)
62125+static inline void nd_set_link(struct nameidata *nd, const char *path)
62126 {
62127 nd->saved_names[nd->depth] = path;
62128 }
62129
62130-static inline char *nd_get_link(struct nameidata *nd)
62131+static inline const char *nd_get_link(const struct nameidata *nd)
62132 {
62133 return nd->saved_names[nd->depth];
62134 }
62135diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
62136index 33900a5..2072000 100644
62137--- a/include/linux/netdevice.h
62138+++ b/include/linux/netdevice.h
62139@@ -1003,6 +1003,7 @@ struct net_device_ops {
62140 int (*ndo_neigh_construct)(struct neighbour *n);
62141 void (*ndo_neigh_destroy)(struct neighbour *n);
62142 };
62143+typedef struct net_device_ops __no_const net_device_ops_no_const;
62144
62145 /*
62146 * The DEVICE structure.
62147@@ -1064,7 +1065,7 @@ struct net_device {
62148 int iflink;
62149
62150 struct net_device_stats stats;
62151- atomic_long_t rx_dropped; /* dropped packets by core network
62152+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
62153 * Do not use this in drivers.
62154 */
62155
62156diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
62157new file mode 100644
62158index 0000000..33f4af8
62159--- /dev/null
62160+++ b/include/linux/netfilter/xt_gradm.h
62161@@ -0,0 +1,9 @@
62162+#ifndef _LINUX_NETFILTER_XT_GRADM_H
62163+#define _LINUX_NETFILTER_XT_GRADM_H 1
62164+
62165+struct xt_gradm_mtinfo {
62166+ __u16 flags;
62167+ __u16 invflags;
62168+};
62169+
62170+#endif
62171diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
62172index c65a18a..0c05f3a 100644
62173--- a/include/linux/of_pdt.h
62174+++ b/include/linux/of_pdt.h
62175@@ -32,7 +32,7 @@ struct of_pdt_ops {
62176
62177 /* return 0 on success; fill in 'len' with number of bytes in path */
62178 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
62179-};
62180+} __no_const;
62181
62182 extern void *prom_early_alloc(unsigned long size);
62183
62184diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
62185index a4c5624..79d6d88 100644
62186--- a/include/linux/oprofile.h
62187+++ b/include/linux/oprofile.h
62188@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
62189 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
62190 char const * name, ulong * val);
62191
62192-/** Create a file for read-only access to an atomic_t. */
62193+/** Create a file for read-only access to an atomic_unchecked_t. */
62194 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
62195- char const * name, atomic_t * val);
62196+ char const * name, atomic_unchecked_t * val);
62197
62198 /** create a directory */
62199 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
62200diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
62201index ddbb6a9..be1680e 100644
62202--- a/include/linux/perf_event.h
62203+++ b/include/linux/perf_event.h
62204@@ -879,8 +879,8 @@ struct perf_event {
62205
62206 enum perf_event_active_state state;
62207 unsigned int attach_state;
62208- local64_t count;
62209- atomic64_t child_count;
62210+ local64_t count; /* PaX: fix it one day */
62211+ atomic64_unchecked_t child_count;
62212
62213 /*
62214 * These are the total time in nanoseconds that the event
62215@@ -931,8 +931,8 @@ struct perf_event {
62216 * These accumulate total time (in nanoseconds) that children
62217 * events have been enabled and running, respectively.
62218 */
62219- atomic64_t child_total_time_enabled;
62220- atomic64_t child_total_time_running;
62221+ atomic64_unchecked_t child_total_time_enabled;
62222+ atomic64_unchecked_t child_total_time_running;
62223
62224 /*
62225 * Protect attach/detach and child_list:
62226diff --git a/include/linux/personality.h b/include/linux/personality.h
62227index 8fc7dd1a..c19d89e 100644
62228--- a/include/linux/personality.h
62229+++ b/include/linux/personality.h
62230@@ -44,6 +44,7 @@ enum {
62231 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
62232 ADDR_NO_RANDOMIZE | \
62233 ADDR_COMPAT_LAYOUT | \
62234+ ADDR_LIMIT_3GB | \
62235 MMAP_PAGE_ZERO)
62236
62237 /*
62238diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
62239index e1ac1ce..0675fed 100644
62240--- a/include/linux/pipe_fs_i.h
62241+++ b/include/linux/pipe_fs_i.h
62242@@ -45,9 +45,9 @@ struct pipe_buffer {
62243 struct pipe_inode_info {
62244 wait_queue_head_t wait;
62245 unsigned int nrbufs, curbuf, buffers;
62246- unsigned int readers;
62247- unsigned int writers;
62248- unsigned int waiting_writers;
62249+ atomic_t readers;
62250+ atomic_t writers;
62251+ atomic_t waiting_writers;
62252 unsigned int r_counter;
62253 unsigned int w_counter;
62254 struct page *tmp_page;
62255diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
62256index 609daae..5392427 100644
62257--- a/include/linux/pm_runtime.h
62258+++ b/include/linux/pm_runtime.h
62259@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
62260
62261 static inline void pm_runtime_mark_last_busy(struct device *dev)
62262 {
62263- ACCESS_ONCE(dev->power.last_busy) = jiffies;
62264+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
62265 }
62266
62267 #else /* !CONFIG_PM_RUNTIME */
62268diff --git a/include/linux/poison.h b/include/linux/poison.h
62269index 2110a81..13a11bb 100644
62270--- a/include/linux/poison.h
62271+++ b/include/linux/poison.h
62272@@ -19,8 +19,8 @@
62273 * under normal circumstances, used to verify that nobody uses
62274 * non-initialized list entries.
62275 */
62276-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
62277-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
62278+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
62279+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
62280
62281 /********** include/linux/timer.h **********/
62282 /*
62283diff --git a/include/linux/preempt.h b/include/linux/preempt.h
62284index 5a710b9..0b0dab9 100644
62285--- a/include/linux/preempt.h
62286+++ b/include/linux/preempt.h
62287@@ -126,7 +126,7 @@ struct preempt_ops {
62288 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
62289 void (*sched_out)(struct preempt_notifier *notifier,
62290 struct task_struct *next);
62291-};
62292+} __no_const;
62293
62294 /**
62295 * preempt_notifier - key for installing preemption notifiers
62296diff --git a/include/linux/printk.h b/include/linux/printk.h
62297index 0525927..a5388b6 100644
62298--- a/include/linux/printk.h
62299+++ b/include/linux/printk.h
62300@@ -94,6 +94,8 @@ void early_printk(const char *fmt, ...);
62301 extern int printk_needs_cpu(int cpu);
62302 extern void printk_tick(void);
62303
62304+extern int kptr_restrict;
62305+
62306 #ifdef CONFIG_PRINTK
62307 asmlinkage __printf(1, 0)
62308 int vprintk(const char *fmt, va_list args);
62309@@ -117,7 +119,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
62310
62311 extern int printk_delay_msec;
62312 extern int dmesg_restrict;
62313-extern int kptr_restrict;
62314
62315 void log_buf_kexec_setup(void);
62316 void __init setup_log_buf(int early);
62317diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
62318index 85c5073..51fac8b 100644
62319--- a/include/linux/proc_fs.h
62320+++ b/include/linux/proc_fs.h
62321@@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
62322 return proc_create_data(name, mode, parent, proc_fops, NULL);
62323 }
62324
62325+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
62326+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
62327+{
62328+#ifdef CONFIG_GRKERNSEC_PROC_USER
62329+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
62330+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62331+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
62332+#else
62333+ return proc_create_data(name, mode, parent, proc_fops, NULL);
62334+#endif
62335+}
62336+
62337 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
62338 umode_t mode, struct proc_dir_entry *base,
62339 read_proc_t *read_proc, void * data)
62340@@ -258,7 +270,7 @@ union proc_op {
62341 int (*proc_show)(struct seq_file *m,
62342 struct pid_namespace *ns, struct pid *pid,
62343 struct task_struct *task);
62344-};
62345+} __no_const;
62346
62347 struct ctl_table_header;
62348 struct ctl_table;
62349diff --git a/include/linux/random.h b/include/linux/random.h
62350index 8f74538..02a1012 100644
62351--- a/include/linux/random.h
62352+++ b/include/linux/random.h
62353@@ -69,12 +69,17 @@ void srandom32(u32 seed);
62354
62355 u32 prandom32(struct rnd_state *);
62356
62357+static inline unsigned long pax_get_random_long(void)
62358+{
62359+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
62360+}
62361+
62362 /*
62363 * Handle minimum values for seeds
62364 */
62365 static inline u32 __seed(u32 x, u32 m)
62366 {
62367- return (x < m) ? x + m : x;
62368+ return (x <= m) ? x + m + 1 : x;
62369 }
62370
62371 /**
62372diff --git a/include/linux/reboot.h b/include/linux/reboot.h
62373index e0879a7..a12f962 100644
62374--- a/include/linux/reboot.h
62375+++ b/include/linux/reboot.h
62376@@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
62377 * Architecture-specific implementations of sys_reboot commands.
62378 */
62379
62380-extern void machine_restart(char *cmd);
62381-extern void machine_halt(void);
62382-extern void machine_power_off(void);
62383+extern void machine_restart(char *cmd) __noreturn;
62384+extern void machine_halt(void) __noreturn;
62385+extern void machine_power_off(void) __noreturn;
62386
62387 extern void machine_shutdown(void);
62388 struct pt_regs;
62389@@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
62390 */
62391
62392 extern void kernel_restart_prepare(char *cmd);
62393-extern void kernel_restart(char *cmd);
62394-extern void kernel_halt(void);
62395-extern void kernel_power_off(void);
62396+extern void kernel_restart(char *cmd) __noreturn;
62397+extern void kernel_halt(void) __noreturn;
62398+extern void kernel_power_off(void) __noreturn;
62399
62400 extern int C_A_D; /* for sysctl */
62401 void ctrl_alt_del(void);
62402@@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
62403 * Emergency restart, callable from an interrupt handler.
62404 */
62405
62406-extern void emergency_restart(void);
62407+extern void emergency_restart(void) __noreturn;
62408 #include <asm/emergency-restart.h>
62409
62410 #endif
62411diff --git a/include/linux/relay.h b/include/linux/relay.h
62412index 91cacc3..b55ff74 100644
62413--- a/include/linux/relay.h
62414+++ b/include/linux/relay.h
62415@@ -160,7 +160,7 @@ struct rchan_callbacks
62416 * The callback should return 0 if successful, negative if not.
62417 */
62418 int (*remove_buf_file)(struct dentry *dentry);
62419-};
62420+} __no_const;
62421
62422 /*
62423 * CONFIG_RELAY kernel API, kernel/relay.c
62424diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
62425index 6fdf027..ff72610 100644
62426--- a/include/linux/rfkill.h
62427+++ b/include/linux/rfkill.h
62428@@ -147,6 +147,7 @@ struct rfkill_ops {
62429 void (*query)(struct rfkill *rfkill, void *data);
62430 int (*set_block)(void *data, bool blocked);
62431 };
62432+typedef struct rfkill_ops __no_const rfkill_ops_no_const;
62433
62434 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
62435 /**
62436diff --git a/include/linux/rio.h b/include/linux/rio.h
62437index 4d50611..c6858a2 100644
62438--- a/include/linux/rio.h
62439+++ b/include/linux/rio.h
62440@@ -315,7 +315,7 @@ struct rio_ops {
62441 int mbox, void *buffer, size_t len);
62442 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
62443 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
62444-};
62445+} __no_const;
62446
62447 #define RIO_RESOURCE_MEM 0x00000100
62448 #define RIO_RESOURCE_DOORBELL 0x00000200
62449diff --git a/include/linux/rmap.h b/include/linux/rmap.h
62450index fd07c45..4676b8e 100644
62451--- a/include/linux/rmap.h
62452+++ b/include/linux/rmap.h
62453@@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
62454 void anon_vma_init(void); /* create anon_vma_cachep */
62455 int anon_vma_prepare(struct vm_area_struct *);
62456 void unlink_anon_vmas(struct vm_area_struct *);
62457-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
62458+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
62459 void anon_vma_moveto_tail(struct vm_area_struct *);
62460-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
62461+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
62462
62463 static inline void anon_vma_merge(struct vm_area_struct *vma,
62464 struct vm_area_struct *next)
62465diff --git a/include/linux/sched.h b/include/linux/sched.h
62466index 81a173c..85ccd8f 100644
62467--- a/include/linux/sched.h
62468+++ b/include/linux/sched.h
62469@@ -100,6 +100,7 @@ struct bio_list;
62470 struct fs_struct;
62471 struct perf_event_context;
62472 struct blk_plug;
62473+struct linux_binprm;
62474
62475 /*
62476 * List of flags we want to share for kernel threads,
62477@@ -382,10 +383,13 @@ struct user_namespace;
62478 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
62479
62480 extern int sysctl_max_map_count;
62481+extern unsigned long sysctl_heap_stack_gap;
62482
62483 #include <linux/aio.h>
62484
62485 #ifdef CONFIG_MMU
62486+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
62487+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
62488 extern void arch_pick_mmap_layout(struct mm_struct *mm);
62489 extern unsigned long
62490 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
62491@@ -643,6 +647,17 @@ struct signal_struct {
62492 #ifdef CONFIG_TASKSTATS
62493 struct taskstats *stats;
62494 #endif
62495+
62496+#ifdef CONFIG_GRKERNSEC
62497+ u32 curr_ip;
62498+ u32 saved_ip;
62499+ u32 gr_saddr;
62500+ u32 gr_daddr;
62501+ u16 gr_sport;
62502+ u16 gr_dport;
62503+ u8 used_accept:1;
62504+#endif
62505+
62506 #ifdef CONFIG_AUDIT
62507 unsigned audit_tty;
62508 struct tty_audit_buf *tty_audit_buf;
62509@@ -726,6 +741,11 @@ struct user_struct {
62510 struct key *session_keyring; /* UID's default session keyring */
62511 #endif
62512
62513+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
62514+ unsigned int banned;
62515+ unsigned long ban_expires;
62516+#endif
62517+
62518 /* Hash table maintenance information */
62519 struct hlist_node uidhash_node;
62520 uid_t uid;
62521@@ -1386,8 +1406,8 @@ struct task_struct {
62522 struct list_head thread_group;
62523
62524 struct completion *vfork_done; /* for vfork() */
62525- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
62526- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
62527+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
62528+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
62529
62530 cputime_t utime, stime, utimescaled, stimescaled;
62531 cputime_t gtime;
62532@@ -1403,13 +1423,6 @@ struct task_struct {
62533 struct task_cputime cputime_expires;
62534 struct list_head cpu_timers[3];
62535
62536-/* process credentials */
62537- const struct cred __rcu *real_cred; /* objective and real subjective task
62538- * credentials (COW) */
62539- const struct cred __rcu *cred; /* effective (overridable) subjective task
62540- * credentials (COW) */
62541- struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
62542-
62543 char comm[TASK_COMM_LEN]; /* executable name excluding path
62544 - access with [gs]et_task_comm (which lock
62545 it with task_lock())
62546@@ -1426,8 +1439,16 @@ struct task_struct {
62547 #endif
62548 /* CPU-specific state of this task */
62549 struct thread_struct thread;
62550+/* thread_info moved to task_struct */
62551+#ifdef CONFIG_X86
62552+ struct thread_info tinfo;
62553+#endif
62554 /* filesystem information */
62555 struct fs_struct *fs;
62556+
62557+ const struct cred __rcu *cred; /* effective (overridable) subjective task
62558+ * credentials (COW) */
62559+
62560 /* open file information */
62561 struct files_struct *files;
62562 /* namespaces */
62563@@ -1469,6 +1490,11 @@ struct task_struct {
62564 struct rt_mutex_waiter *pi_blocked_on;
62565 #endif
62566
62567+/* process credentials */
62568+ const struct cred __rcu *real_cred; /* objective and real subjective task
62569+ * credentials (COW) */
62570+ struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
62571+
62572 #ifdef CONFIG_DEBUG_MUTEXES
62573 /* mutex deadlock detection */
62574 struct mutex_waiter *blocked_on;
62575@@ -1585,6 +1611,27 @@ struct task_struct {
62576 unsigned long default_timer_slack_ns;
62577
62578 struct list_head *scm_work_list;
62579+
62580+#ifdef CONFIG_GRKERNSEC
62581+ /* grsecurity */
62582+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62583+ u64 exec_id;
62584+#endif
62585+#ifdef CONFIG_GRKERNSEC_SETXID
62586+ const struct cred *delayed_cred;
62587+#endif
62588+ struct dentry *gr_chroot_dentry;
62589+ struct acl_subject_label *acl;
62590+ struct acl_role_label *role;
62591+ struct file *exec_file;
62592+ u16 acl_role_id;
62593+ /* is this the task that authenticated to the special role */
62594+ u8 acl_sp_role;
62595+ u8 is_writable;
62596+ u8 brute;
62597+ u8 gr_is_chrooted;
62598+#endif
62599+
62600 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
62601 /* Index of current stored address in ret_stack */
62602 int curr_ret_stack;
62603@@ -1619,6 +1666,51 @@ struct task_struct {
62604 #endif
62605 };
62606
62607+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
62608+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
62609+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
62610+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
62611+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
62612+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
62613+
62614+#ifdef CONFIG_PAX_SOFTMODE
62615+extern int pax_softmode;
62616+#endif
62617+
62618+extern int pax_check_flags(unsigned long *);
62619+
62620+/* if tsk != current then task_lock must be held on it */
62621+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62622+static inline unsigned long pax_get_flags(struct task_struct *tsk)
62623+{
62624+ if (likely(tsk->mm))
62625+ return tsk->mm->pax_flags;
62626+ else
62627+ return 0UL;
62628+}
62629+
62630+/* if tsk != current then task_lock must be held on it */
62631+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
62632+{
62633+ if (likely(tsk->mm)) {
62634+ tsk->mm->pax_flags = flags;
62635+ return 0;
62636+ }
62637+ return -EINVAL;
62638+}
62639+#endif
62640+
62641+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
62642+extern void pax_set_initial_flags(struct linux_binprm *bprm);
62643+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
62644+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
62645+#endif
62646+
62647+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
62648+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
62649+extern void pax_report_refcount_overflow(struct pt_regs *regs);
62650+extern __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
62651+
62652 /* Future-safe accessor for struct task_struct's cpus_allowed. */
62653 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
62654
62655@@ -2138,7 +2230,9 @@ void yield(void);
62656 extern struct exec_domain default_exec_domain;
62657
62658 union thread_union {
62659+#ifndef CONFIG_X86
62660 struct thread_info thread_info;
62661+#endif
62662 unsigned long stack[THREAD_SIZE/sizeof(long)];
62663 };
62664
62665@@ -2171,6 +2265,7 @@ extern struct pid_namespace init_pid_ns;
62666 */
62667
62668 extern struct task_struct *find_task_by_vpid(pid_t nr);
62669+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
62670 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
62671 struct pid_namespace *ns);
62672
62673@@ -2314,7 +2409,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
62674 extern void exit_itimers(struct signal_struct *);
62675 extern void flush_itimer_signals(void);
62676
62677-extern void do_group_exit(int);
62678+extern __noreturn void do_group_exit(int);
62679
62680 extern void daemonize(const char *, ...);
62681 extern int allow_signal(int);
62682@@ -2515,13 +2610,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
62683
62684 #endif
62685
62686-static inline int object_is_on_stack(void *obj)
62687+static inline int object_starts_on_stack(void *obj)
62688 {
62689- void *stack = task_stack_page(current);
62690+ const void *stack = task_stack_page(current);
62691
62692 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
62693 }
62694
62695+#ifdef CONFIG_PAX_USERCOPY
62696+extern int object_is_on_stack(const void *obj, unsigned long len);
62697+#endif
62698+
62699 extern void thread_info_cache_init(void);
62700
62701 #ifdef CONFIG_DEBUG_STACK_USAGE
62702diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
62703index 899fbb4..1cb4138 100644
62704--- a/include/linux/screen_info.h
62705+++ b/include/linux/screen_info.h
62706@@ -43,7 +43,8 @@ struct screen_info {
62707 __u16 pages; /* 0x32 */
62708 __u16 vesa_attributes; /* 0x34 */
62709 __u32 capabilities; /* 0x36 */
62710- __u8 _reserved[6]; /* 0x3a */
62711+ __u16 vesapm_size; /* 0x3a */
62712+ __u8 _reserved[4]; /* 0x3c */
62713 } __attribute__((packed));
62714
62715 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
62716diff --git a/include/linux/security.h b/include/linux/security.h
62717index 673afbb..2b7454b 100644
62718--- a/include/linux/security.h
62719+++ b/include/linux/security.h
62720@@ -26,6 +26,7 @@
62721 #include <linux/capability.h>
62722 #include <linux/slab.h>
62723 #include <linux/err.h>
62724+#include <linux/grsecurity.h>
62725
62726 struct linux_binprm;
62727 struct cred;
62728diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
62729index fc61854..d7c490b 100644
62730--- a/include/linux/seq_file.h
62731+++ b/include/linux/seq_file.h
62732@@ -25,6 +25,9 @@ struct seq_file {
62733 struct mutex lock;
62734 const struct seq_operations *op;
62735 int poll_event;
62736+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62737+ u64 exec_id;
62738+#endif
62739 void *private;
62740 };
62741
62742@@ -34,6 +37,7 @@ struct seq_operations {
62743 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
62744 int (*show) (struct seq_file *m, void *v);
62745 };
62746+typedef struct seq_operations __no_const seq_operations_no_const;
62747
62748 #define SEQ_SKIP 1
62749
62750diff --git a/include/linux/shm.h b/include/linux/shm.h
62751index 92808b8..c28cac4 100644
62752--- a/include/linux/shm.h
62753+++ b/include/linux/shm.h
62754@@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
62755
62756 /* The task created the shm object. NULL if the task is dead. */
62757 struct task_struct *shm_creator;
62758+#ifdef CONFIG_GRKERNSEC
62759+ time_t shm_createtime;
62760+ pid_t shm_lapid;
62761+#endif
62762 };
62763
62764 /* shm_mode upper byte flags */
62765diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
62766index c168907..c7756db 100644
62767--- a/include/linux/skbuff.h
62768+++ b/include/linux/skbuff.h
62769@@ -666,7 +666,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
62770 */
62771 static inline int skb_queue_empty(const struct sk_buff_head *list)
62772 {
62773- return list->next == (struct sk_buff *)list;
62774+ return list->next == (const struct sk_buff *)list;
62775 }
62776
62777 /**
62778@@ -679,7 +679,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
62779 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
62780 const struct sk_buff *skb)
62781 {
62782- return skb->next == (struct sk_buff *)list;
62783+ return skb->next == (const struct sk_buff *)list;
62784 }
62785
62786 /**
62787@@ -692,7 +692,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
62788 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
62789 const struct sk_buff *skb)
62790 {
62791- return skb->prev == (struct sk_buff *)list;
62792+ return skb->prev == (const struct sk_buff *)list;
62793 }
62794
62795 /**
62796@@ -1587,7 +1587,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
62797 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
62798 */
62799 #ifndef NET_SKB_PAD
62800-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
62801+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
62802 #endif
62803
62804 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
62805diff --git a/include/linux/slab.h b/include/linux/slab.h
62806index a595dce..c403597 100644
62807--- a/include/linux/slab.h
62808+++ b/include/linux/slab.h
62809@@ -11,12 +11,20 @@
62810
62811 #include <linux/gfp.h>
62812 #include <linux/types.h>
62813+#include <linux/err.h>
62814
62815 /*
62816 * Flags to pass to kmem_cache_create().
62817 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
62818 */
62819 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
62820+
62821+#ifdef CONFIG_PAX_USERCOPY
62822+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
62823+#else
62824+#define SLAB_USERCOPY 0x00000000UL
62825+#endif
62826+
62827 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
62828 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
62829 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
62830@@ -87,10 +95,13 @@
62831 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
62832 * Both make kfree a no-op.
62833 */
62834-#define ZERO_SIZE_PTR ((void *)16)
62835+#define ZERO_SIZE_PTR \
62836+({ \
62837+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
62838+ (void *)(-MAX_ERRNO-1L); \
62839+})
62840
62841-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
62842- (unsigned long)ZERO_SIZE_PTR)
62843+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
62844
62845 /*
62846 * struct kmem_cache related prototypes
62847@@ -161,6 +172,7 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
62848 void kfree(const void *);
62849 void kzfree(const void *);
62850 size_t ksize(const void *);
62851+void check_object_size(const void *ptr, unsigned long n, bool to);
62852
62853 /*
62854 * Allocator specific definitions. These are mainly used to establish optimized
62855@@ -240,6 +252,7 @@ size_t ksize(const void *);
62856 * for general use, and so are not documented here. For a full list of
62857 * potential flags, always refer to linux/gfp.h.
62858 */
62859+static void *kmalloc_array(size_t n, size_t size, gfp_t flags) __size_overflow(1, 2);
62860 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
62861 {
62862 if (size != 0 && n > ULONG_MAX / size)
62863@@ -298,7 +311,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
62864 */
62865 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
62866 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
62867-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
62868+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
62869 #define kmalloc_track_caller(size, flags) \
62870 __kmalloc_track_caller(size, flags, _RET_IP_)
62871 #else
62872@@ -317,7 +330,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
62873 */
62874 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
62875 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
62876-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
62877+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
62878 #define kmalloc_node_track_caller(size, flags, node) \
62879 __kmalloc_node_track_caller(size, flags, node, \
62880 _RET_IP_)
62881diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
62882index fbd1117..d4d8ef8 100644
62883--- a/include/linux/slab_def.h
62884+++ b/include/linux/slab_def.h
62885@@ -66,10 +66,10 @@ struct kmem_cache {
62886 unsigned long node_allocs;
62887 unsigned long node_frees;
62888 unsigned long node_overflow;
62889- atomic_t allochit;
62890- atomic_t allocmiss;
62891- atomic_t freehit;
62892- atomic_t freemiss;
62893+ atomic_unchecked_t allochit;
62894+ atomic_unchecked_t allocmiss;
62895+ atomic_unchecked_t freehit;
62896+ atomic_unchecked_t freemiss;
62897
62898 /*
62899 * If debugging is enabled, then the allocator can add additional
62900@@ -107,7 +107,7 @@ struct cache_sizes {
62901 extern struct cache_sizes malloc_sizes[];
62902
62903 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
62904-void *__kmalloc(size_t size, gfp_t flags);
62905+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
62906
62907 #ifdef CONFIG_TRACING
62908 extern void *kmem_cache_alloc_trace(size_t size,
62909@@ -160,7 +160,7 @@ found:
62910 }
62911
62912 #ifdef CONFIG_NUMA
62913-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
62914+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
62915 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
62916
62917 #ifdef CONFIG_TRACING
62918diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
62919index 0ec00b3..39cb7fc 100644
62920--- a/include/linux/slob_def.h
62921+++ b/include/linux/slob_def.h
62922@@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
62923 return kmem_cache_alloc_node(cachep, flags, -1);
62924 }
62925
62926-void *__kmalloc_node(size_t size, gfp_t flags, int node);
62927+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
62928
62929 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
62930 {
62931@@ -29,6 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
62932 return __kmalloc_node(size, flags, -1);
62933 }
62934
62935+static __always_inline void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
62936 static __always_inline void *__kmalloc(size_t size, gfp_t flags)
62937 {
62938 return kmalloc(size, flags);
62939diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
62940index c2f8c8b..be9e036 100644
62941--- a/include/linux/slub_def.h
62942+++ b/include/linux/slub_def.h
62943@@ -92,7 +92,7 @@ struct kmem_cache {
62944 struct kmem_cache_order_objects max;
62945 struct kmem_cache_order_objects min;
62946 gfp_t allocflags; /* gfp flags to use on each alloc */
62947- int refcount; /* Refcount for slab cache destroy */
62948+ atomic_t refcount; /* Refcount for slab cache destroy */
62949 void (*ctor)(void *);
62950 int inuse; /* Offset to metadata */
62951 int align; /* Alignment */
62952@@ -153,6 +153,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
62953 * Sorry that the following has to be that ugly but some versions of GCC
62954 * have trouble with constant propagation and loops.
62955 */
62956+static __always_inline int kmalloc_index(size_t size) __size_overflow(1);
62957 static __always_inline int kmalloc_index(size_t size)
62958 {
62959 if (!size)
62960@@ -218,7 +219,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
62961 }
62962
62963 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
62964-void *__kmalloc(size_t size, gfp_t flags);
62965+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
62966
62967 static __always_inline void *
62968 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
62969@@ -259,6 +260,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
62970 }
62971 #endif
62972
62973+static __always_inline void *kmalloc_large(size_t size, gfp_t flags) __size_overflow(1);
62974 static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
62975 {
62976 unsigned int order = get_order(size);
62977@@ -284,7 +286,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
62978 }
62979
62980 #ifdef CONFIG_NUMA
62981-void *__kmalloc_node(size_t size, gfp_t flags, int node);
62982+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
62983 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
62984
62985 #ifdef CONFIG_TRACING
62986diff --git a/include/linux/sonet.h b/include/linux/sonet.h
62987index de8832d..0147b46 100644
62988--- a/include/linux/sonet.h
62989+++ b/include/linux/sonet.h
62990@@ -61,7 +61,7 @@ struct sonet_stats {
62991 #include <linux/atomic.h>
62992
62993 struct k_sonet_stats {
62994-#define __HANDLE_ITEM(i) atomic_t i
62995+#define __HANDLE_ITEM(i) atomic_unchecked_t i
62996 __SONET_ITEMS
62997 #undef __HANDLE_ITEM
62998 };
62999diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
63000index 523547e..2cb7140 100644
63001--- a/include/linux/sunrpc/clnt.h
63002+++ b/include/linux/sunrpc/clnt.h
63003@@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
63004 {
63005 switch (sap->sa_family) {
63006 case AF_INET:
63007- return ntohs(((struct sockaddr_in *)sap)->sin_port);
63008+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
63009 case AF_INET6:
63010- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
63011+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
63012 }
63013 return 0;
63014 }
63015@@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
63016 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
63017 const struct sockaddr *src)
63018 {
63019- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
63020+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
63021 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
63022
63023 dsin->sin_family = ssin->sin_family;
63024@@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
63025 if (sa->sa_family != AF_INET6)
63026 return 0;
63027
63028- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
63029+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
63030 }
63031
63032 #endif /* __KERNEL__ */
63033diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
63034index dc0c3cc..8503fb6 100644
63035--- a/include/linux/sunrpc/sched.h
63036+++ b/include/linux/sunrpc/sched.h
63037@@ -106,6 +106,7 @@ struct rpc_call_ops {
63038 void (*rpc_count_stats)(struct rpc_task *, void *);
63039 void (*rpc_release)(void *);
63040 };
63041+typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
63042
63043 struct rpc_task_setup {
63044 struct rpc_task *task;
63045diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
63046index 0b8e3e6..33e0a01 100644
63047--- a/include/linux/sunrpc/svc_rdma.h
63048+++ b/include/linux/sunrpc/svc_rdma.h
63049@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
63050 extern unsigned int svcrdma_max_requests;
63051 extern unsigned int svcrdma_max_req_size;
63052
63053-extern atomic_t rdma_stat_recv;
63054-extern atomic_t rdma_stat_read;
63055-extern atomic_t rdma_stat_write;
63056-extern atomic_t rdma_stat_sq_starve;
63057-extern atomic_t rdma_stat_rq_starve;
63058-extern atomic_t rdma_stat_rq_poll;
63059-extern atomic_t rdma_stat_rq_prod;
63060-extern atomic_t rdma_stat_sq_poll;
63061-extern atomic_t rdma_stat_sq_prod;
63062+extern atomic_unchecked_t rdma_stat_recv;
63063+extern atomic_unchecked_t rdma_stat_read;
63064+extern atomic_unchecked_t rdma_stat_write;
63065+extern atomic_unchecked_t rdma_stat_sq_starve;
63066+extern atomic_unchecked_t rdma_stat_rq_starve;
63067+extern atomic_unchecked_t rdma_stat_rq_poll;
63068+extern atomic_unchecked_t rdma_stat_rq_prod;
63069+extern atomic_unchecked_t rdma_stat_sq_poll;
63070+extern atomic_unchecked_t rdma_stat_sq_prod;
63071
63072 #define RPCRDMA_VERSION 1
63073
63074diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
63075index c34b4c8..a65b67d 100644
63076--- a/include/linux/sysctl.h
63077+++ b/include/linux/sysctl.h
63078@@ -155,7 +155,11 @@ enum
63079 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
63080 };
63081
63082-
63083+#ifdef CONFIG_PAX_SOFTMODE
63084+enum {
63085+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
63086+};
63087+#endif
63088
63089 /* CTL_VM names: */
63090 enum
63091@@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
63092
63093 extern int proc_dostring(struct ctl_table *, int,
63094 void __user *, size_t *, loff_t *);
63095+extern int proc_dostring_modpriv(struct ctl_table *, int,
63096+ void __user *, size_t *, loff_t *);
63097 extern int proc_dointvec(struct ctl_table *, int,
63098 void __user *, size_t *, loff_t *);
63099 extern int proc_dointvec_minmax(struct ctl_table *, int,
63100diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
63101index ff7dc08..893e1bd 100644
63102--- a/include/linux/tty_ldisc.h
63103+++ b/include/linux/tty_ldisc.h
63104@@ -148,7 +148,7 @@ struct tty_ldisc_ops {
63105
63106 struct module *owner;
63107
63108- int refcount;
63109+ atomic_t refcount;
63110 };
63111
63112 struct tty_ldisc {
63113diff --git a/include/linux/types.h b/include/linux/types.h
63114index 7f480db..175c256 100644
63115--- a/include/linux/types.h
63116+++ b/include/linux/types.h
63117@@ -220,10 +220,26 @@ typedef struct {
63118 int counter;
63119 } atomic_t;
63120
63121+#ifdef CONFIG_PAX_REFCOUNT
63122+typedef struct {
63123+ int counter;
63124+} atomic_unchecked_t;
63125+#else
63126+typedef atomic_t atomic_unchecked_t;
63127+#endif
63128+
63129 #ifdef CONFIG_64BIT
63130 typedef struct {
63131 long counter;
63132 } atomic64_t;
63133+
63134+#ifdef CONFIG_PAX_REFCOUNT
63135+typedef struct {
63136+ long counter;
63137+} atomic64_unchecked_t;
63138+#else
63139+typedef atomic64_t atomic64_unchecked_t;
63140+#endif
63141 #endif
63142
63143 struct list_head {
63144diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
63145index 5ca0951..ab496a5 100644
63146--- a/include/linux/uaccess.h
63147+++ b/include/linux/uaccess.h
63148@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
63149 long ret; \
63150 mm_segment_t old_fs = get_fs(); \
63151 \
63152- set_fs(KERNEL_DS); \
63153 pagefault_disable(); \
63154- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
63155- pagefault_enable(); \
63156+ set_fs(KERNEL_DS); \
63157+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
63158 set_fs(old_fs); \
63159+ pagefault_enable(); \
63160 ret; \
63161 })
63162
63163diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
63164index 99c1b4d..bb94261 100644
63165--- a/include/linux/unaligned/access_ok.h
63166+++ b/include/linux/unaligned/access_ok.h
63167@@ -6,32 +6,32 @@
63168
63169 static inline u16 get_unaligned_le16(const void *p)
63170 {
63171- return le16_to_cpup((__le16 *)p);
63172+ return le16_to_cpup((const __le16 *)p);
63173 }
63174
63175 static inline u32 get_unaligned_le32(const void *p)
63176 {
63177- return le32_to_cpup((__le32 *)p);
63178+ return le32_to_cpup((const __le32 *)p);
63179 }
63180
63181 static inline u64 get_unaligned_le64(const void *p)
63182 {
63183- return le64_to_cpup((__le64 *)p);
63184+ return le64_to_cpup((const __le64 *)p);
63185 }
63186
63187 static inline u16 get_unaligned_be16(const void *p)
63188 {
63189- return be16_to_cpup((__be16 *)p);
63190+ return be16_to_cpup((const __be16 *)p);
63191 }
63192
63193 static inline u32 get_unaligned_be32(const void *p)
63194 {
63195- return be32_to_cpup((__be32 *)p);
63196+ return be32_to_cpup((const __be32 *)p);
63197 }
63198
63199 static inline u64 get_unaligned_be64(const void *p)
63200 {
63201- return be64_to_cpup((__be64 *)p);
63202+ return be64_to_cpup((const __be64 *)p);
63203 }
63204
63205 static inline void put_unaligned_le16(u16 val, void *p)
63206diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
63207index 547e59c..db6ad19 100644
63208--- a/include/linux/usb/renesas_usbhs.h
63209+++ b/include/linux/usb/renesas_usbhs.h
63210@@ -39,7 +39,7 @@ enum {
63211 */
63212 struct renesas_usbhs_driver_callback {
63213 int (*notify_hotplug)(struct platform_device *pdev);
63214-};
63215+} __no_const;
63216
63217 /*
63218 * callback functions for platform
63219@@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
63220 * VBUS control is needed for Host
63221 */
63222 int (*set_vbus)(struct platform_device *pdev, int enable);
63223-};
63224+} __no_const;
63225
63226 /*
63227 * parameters for renesas usbhs
63228diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
63229index 6f8fbcf..8259001 100644
63230--- a/include/linux/vermagic.h
63231+++ b/include/linux/vermagic.h
63232@@ -25,9 +25,35 @@
63233 #define MODULE_ARCH_VERMAGIC ""
63234 #endif
63235
63236+#ifdef CONFIG_PAX_REFCOUNT
63237+#define MODULE_PAX_REFCOUNT "REFCOUNT "
63238+#else
63239+#define MODULE_PAX_REFCOUNT ""
63240+#endif
63241+
63242+#ifdef CONSTIFY_PLUGIN
63243+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
63244+#else
63245+#define MODULE_CONSTIFY_PLUGIN ""
63246+#endif
63247+
63248+#ifdef STACKLEAK_PLUGIN
63249+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
63250+#else
63251+#define MODULE_STACKLEAK_PLUGIN ""
63252+#endif
63253+
63254+#ifdef CONFIG_GRKERNSEC
63255+#define MODULE_GRSEC "GRSEC "
63256+#else
63257+#define MODULE_GRSEC ""
63258+#endif
63259+
63260 #define VERMAGIC_STRING \
63261 UTS_RELEASE " " \
63262 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
63263 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
63264- MODULE_ARCH_VERMAGIC
63265+ MODULE_ARCH_VERMAGIC \
63266+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
63267+ MODULE_GRSEC
63268
63269diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
63270index dcdfc2b..ec79ab5 100644
63271--- a/include/linux/vmalloc.h
63272+++ b/include/linux/vmalloc.h
63273@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
63274 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
63275 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
63276 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
63277+
63278+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
63279+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
63280+#endif
63281+
63282 /* bits [20..32] reserved for arch specific ioremap internals */
63283
63284 /*
63285@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
63286 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
63287 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
63288 unsigned long start, unsigned long end, gfp_t gfp_mask,
63289- pgprot_t prot, int node, void *caller);
63290+ pgprot_t prot, int node, void *caller) __size_overflow(1);
63291 extern void vfree(const void *addr);
63292
63293 extern void *vmap(struct page **pages, unsigned int count,
63294@@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
63295 extern void free_vm_area(struct vm_struct *area);
63296
63297 /* for /dev/kmem */
63298-extern long vread(char *buf, char *addr, unsigned long count);
63299-extern long vwrite(char *buf, char *addr, unsigned long count);
63300+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
63301+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
63302
63303 /*
63304 * Internals. Dont't use..
63305diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
63306index 65efb92..137adbb 100644
63307--- a/include/linux/vmstat.h
63308+++ b/include/linux/vmstat.h
63309@@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
63310 /*
63311 * Zone based page accounting with per cpu differentials.
63312 */
63313-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63314+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63315
63316 static inline void zone_page_state_add(long x, struct zone *zone,
63317 enum zone_stat_item item)
63318 {
63319- atomic_long_add(x, &zone->vm_stat[item]);
63320- atomic_long_add(x, &vm_stat[item]);
63321+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
63322+ atomic_long_add_unchecked(x, &vm_stat[item]);
63323 }
63324
63325 static inline unsigned long global_page_state(enum zone_stat_item item)
63326 {
63327- long x = atomic_long_read(&vm_stat[item]);
63328+ long x = atomic_long_read_unchecked(&vm_stat[item]);
63329 #ifdef CONFIG_SMP
63330 if (x < 0)
63331 x = 0;
63332@@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
63333 static inline unsigned long zone_page_state(struct zone *zone,
63334 enum zone_stat_item item)
63335 {
63336- long x = atomic_long_read(&zone->vm_stat[item]);
63337+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
63338 #ifdef CONFIG_SMP
63339 if (x < 0)
63340 x = 0;
63341@@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
63342 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
63343 enum zone_stat_item item)
63344 {
63345- long x = atomic_long_read(&zone->vm_stat[item]);
63346+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
63347
63348 #ifdef CONFIG_SMP
63349 int cpu;
63350@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
63351
63352 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
63353 {
63354- atomic_long_inc(&zone->vm_stat[item]);
63355- atomic_long_inc(&vm_stat[item]);
63356+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
63357+ atomic_long_inc_unchecked(&vm_stat[item]);
63358 }
63359
63360 static inline void __inc_zone_page_state(struct page *page,
63361@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
63362
63363 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
63364 {
63365- atomic_long_dec(&zone->vm_stat[item]);
63366- atomic_long_dec(&vm_stat[item]);
63367+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
63368+ atomic_long_dec_unchecked(&vm_stat[item]);
63369 }
63370
63371 static inline void __dec_zone_page_state(struct page *page,
63372diff --git a/include/linux/xattr.h b/include/linux/xattr.h
63373index e5d1220..ef6e406 100644
63374--- a/include/linux/xattr.h
63375+++ b/include/linux/xattr.h
63376@@ -57,6 +57,11 @@
63377 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
63378 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
63379
63380+/* User namespace */
63381+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
63382+#define XATTR_PAX_FLAGS_SUFFIX "flags"
63383+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
63384+
63385 #ifdef __KERNEL__
63386
63387 #include <linux/types.h>
63388diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
63389index 4aeff96..b378cdc 100644
63390--- a/include/media/saa7146_vv.h
63391+++ b/include/media/saa7146_vv.h
63392@@ -163,7 +163,7 @@ struct saa7146_ext_vv
63393 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
63394
63395 /* the extension can override this */
63396- struct v4l2_ioctl_ops ops;
63397+ v4l2_ioctl_ops_no_const ops;
63398 /* pointer to the saa7146 core ops */
63399 const struct v4l2_ioctl_ops *core_ops;
63400
63401diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
63402index 96d2221..2292f89 100644
63403--- a/include/media/v4l2-dev.h
63404+++ b/include/media/v4l2-dev.h
63405@@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
63406
63407
63408 struct v4l2_file_operations {
63409- struct module *owner;
63410+ struct module * const owner;
63411 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
63412 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
63413 unsigned int (*poll) (struct file *, struct poll_table_struct *);
63414@@ -71,6 +71,7 @@ struct v4l2_file_operations {
63415 int (*open) (struct file *);
63416 int (*release) (struct file *);
63417 };
63418+typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
63419
63420 /*
63421 * Newer version of video_device, handled by videodev2.c
63422diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
63423index 3cb939c..f23c6bb 100644
63424--- a/include/media/v4l2-ioctl.h
63425+++ b/include/media/v4l2-ioctl.h
63426@@ -281,7 +281,7 @@ struct v4l2_ioctl_ops {
63427 long (*vidioc_default) (struct file *file, void *fh,
63428 bool valid_prio, int cmd, void *arg);
63429 };
63430-
63431+typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
63432
63433 /* v4l debugging and diagnostics */
63434
63435diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
63436index 6db8ecf..8c23861 100644
63437--- a/include/net/caif/caif_hsi.h
63438+++ b/include/net/caif/caif_hsi.h
63439@@ -98,7 +98,7 @@ struct cfhsi_drv {
63440 void (*rx_done_cb) (struct cfhsi_drv *drv);
63441 void (*wake_up_cb) (struct cfhsi_drv *drv);
63442 void (*wake_down_cb) (struct cfhsi_drv *drv);
63443-};
63444+} __no_const;
63445
63446 /* Structure implemented by HSI device. */
63447 struct cfhsi_dev {
63448diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
63449index 9e5425b..8136ffc 100644
63450--- a/include/net/caif/cfctrl.h
63451+++ b/include/net/caif/cfctrl.h
63452@@ -52,7 +52,7 @@ struct cfctrl_rsp {
63453 void (*radioset_rsp)(void);
63454 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
63455 struct cflayer *client_layer);
63456-};
63457+} __no_const;
63458
63459 /* Link Setup Parameters for CAIF-Links. */
63460 struct cfctrl_link_param {
63461@@ -101,8 +101,8 @@ struct cfctrl_request_info {
63462 struct cfctrl {
63463 struct cfsrvl serv;
63464 struct cfctrl_rsp res;
63465- atomic_t req_seq_no;
63466- atomic_t rsp_seq_no;
63467+ atomic_unchecked_t req_seq_no;
63468+ atomic_unchecked_t rsp_seq_no;
63469 struct list_head list;
63470 /* Protects from simultaneous access to first_req list */
63471 spinlock_t info_list_lock;
63472diff --git a/include/net/flow.h b/include/net/flow.h
63473index 6c469db..7743b8e 100644
63474--- a/include/net/flow.h
63475+++ b/include/net/flow.h
63476@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
63477
63478 extern void flow_cache_flush(void);
63479 extern void flow_cache_flush_deferred(void);
63480-extern atomic_t flow_cache_genid;
63481+extern atomic_unchecked_t flow_cache_genid;
63482
63483 #endif
63484diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
63485index b94765e..053f68b 100644
63486--- a/include/net/inetpeer.h
63487+++ b/include/net/inetpeer.h
63488@@ -48,8 +48,8 @@ struct inet_peer {
63489 */
63490 union {
63491 struct {
63492- atomic_t rid; /* Frag reception counter */
63493- atomic_t ip_id_count; /* IP ID for the next packet */
63494+ atomic_unchecked_t rid; /* Frag reception counter */
63495+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
63496 __u32 tcp_ts;
63497 __u32 tcp_ts_stamp;
63498 };
63499@@ -115,11 +115,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
63500 more++;
63501 inet_peer_refcheck(p);
63502 do {
63503- old = atomic_read(&p->ip_id_count);
63504+ old = atomic_read_unchecked(&p->ip_id_count);
63505 new = old + more;
63506 if (!new)
63507 new = 1;
63508- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
63509+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
63510 return new;
63511 }
63512
63513diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
63514index 10422ef..662570f 100644
63515--- a/include/net/ip_fib.h
63516+++ b/include/net/ip_fib.h
63517@@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
63518
63519 #define FIB_RES_SADDR(net, res) \
63520 ((FIB_RES_NH(res).nh_saddr_genid == \
63521- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
63522+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
63523 FIB_RES_NH(res).nh_saddr : \
63524 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
63525 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
63526diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
63527index 72522f0..6f03a2b 100644
63528--- a/include/net/ip_vs.h
63529+++ b/include/net/ip_vs.h
63530@@ -510,7 +510,7 @@ struct ip_vs_conn {
63531 struct ip_vs_conn *control; /* Master control connection */
63532 atomic_t n_control; /* Number of controlled ones */
63533 struct ip_vs_dest *dest; /* real server */
63534- atomic_t in_pkts; /* incoming packet counter */
63535+ atomic_unchecked_t in_pkts; /* incoming packet counter */
63536
63537 /* packet transmitter for different forwarding methods. If it
63538 mangles the packet, it must return NF_DROP or better NF_STOLEN,
63539@@ -648,7 +648,7 @@ struct ip_vs_dest {
63540 __be16 port; /* port number of the server */
63541 union nf_inet_addr addr; /* IP address of the server */
63542 volatile unsigned flags; /* dest status flags */
63543- atomic_t conn_flags; /* flags to copy to conn */
63544+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
63545 atomic_t weight; /* server weight */
63546
63547 atomic_t refcnt; /* reference counter */
63548diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
63549index 69b610a..fe3962c 100644
63550--- a/include/net/irda/ircomm_core.h
63551+++ b/include/net/irda/ircomm_core.h
63552@@ -51,7 +51,7 @@ typedef struct {
63553 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
63554 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
63555 struct ircomm_info *);
63556-} call_t;
63557+} __no_const call_t;
63558
63559 struct ircomm_cb {
63560 irda_queue_t queue;
63561diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
63562index 59ba38bc..d515662 100644
63563--- a/include/net/irda/ircomm_tty.h
63564+++ b/include/net/irda/ircomm_tty.h
63565@@ -35,6 +35,7 @@
63566 #include <linux/termios.h>
63567 #include <linux/timer.h>
63568 #include <linux/tty.h> /* struct tty_struct */
63569+#include <asm/local.h>
63570
63571 #include <net/irda/irias_object.h>
63572 #include <net/irda/ircomm_core.h>
63573@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
63574 unsigned short close_delay;
63575 unsigned short closing_wait; /* time to wait before closing */
63576
63577- int open_count;
63578- int blocked_open; /* # of blocked opens */
63579+ local_t open_count;
63580+ local_t blocked_open; /* # of blocked opens */
63581
63582 /* Protect concurent access to :
63583 * o self->open_count
63584diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
63585index cc7c197..9f2da2a 100644
63586--- a/include/net/iucv/af_iucv.h
63587+++ b/include/net/iucv/af_iucv.h
63588@@ -141,7 +141,7 @@ struct iucv_sock {
63589 struct iucv_sock_list {
63590 struct hlist_head head;
63591 rwlock_t lock;
63592- atomic_t autobind_name;
63593+ atomic_unchecked_t autobind_name;
63594 };
63595
63596 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
63597diff --git a/include/net/neighbour.h b/include/net/neighbour.h
63598index 34c996f..bb3b4d4 100644
63599--- a/include/net/neighbour.h
63600+++ b/include/net/neighbour.h
63601@@ -123,7 +123,7 @@ struct neigh_ops {
63602 void (*error_report)(struct neighbour *, struct sk_buff *);
63603 int (*output)(struct neighbour *, struct sk_buff *);
63604 int (*connected_output)(struct neighbour *, struct sk_buff *);
63605-};
63606+} __do_const;
63607
63608 struct pneigh_entry {
63609 struct pneigh_entry *next;
63610diff --git a/include/net/netlink.h b/include/net/netlink.h
63611index f394fe5..fd073f9 100644
63612--- a/include/net/netlink.h
63613+++ b/include/net/netlink.h
63614@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
63615 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
63616 {
63617 if (mark)
63618- skb_trim(skb, (unsigned char *) mark - skb->data);
63619+ skb_trim(skb, (const unsigned char *) mark - skb->data);
63620 }
63621
63622 /**
63623diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
63624index bbd023a..97c6d0d 100644
63625--- a/include/net/netns/ipv4.h
63626+++ b/include/net/netns/ipv4.h
63627@@ -57,8 +57,8 @@ struct netns_ipv4 {
63628 unsigned int sysctl_ping_group_range[2];
63629 long sysctl_tcp_mem[3];
63630
63631- atomic_t rt_genid;
63632- atomic_t dev_addr_genid;
63633+ atomic_unchecked_t rt_genid;
63634+ atomic_unchecked_t dev_addr_genid;
63635
63636 #ifdef CONFIG_IP_MROUTE
63637 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
63638diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
63639index a2ef814..31a8e3f 100644
63640--- a/include/net/sctp/sctp.h
63641+++ b/include/net/sctp/sctp.h
63642@@ -318,9 +318,9 @@ do { \
63643
63644 #else /* SCTP_DEBUG */
63645
63646-#define SCTP_DEBUG_PRINTK(whatever...)
63647-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
63648-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
63649+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
63650+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
63651+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
63652 #define SCTP_ENABLE_DEBUG
63653 #define SCTP_DISABLE_DEBUG
63654 #define SCTP_ASSERT(expr, str, func)
63655diff --git a/include/net/sock.h b/include/net/sock.h
63656index 5a0a58a..2e3d4d0 100644
63657--- a/include/net/sock.h
63658+++ b/include/net/sock.h
63659@@ -302,7 +302,7 @@ struct sock {
63660 #ifdef CONFIG_RPS
63661 __u32 sk_rxhash;
63662 #endif
63663- atomic_t sk_drops;
63664+ atomic_unchecked_t sk_drops;
63665 int sk_rcvbuf;
63666
63667 struct sk_filter __rcu *sk_filter;
63668@@ -1691,7 +1691,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
63669 }
63670
63671 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
63672- char __user *from, char *to,
63673+ char __user *from, unsigned char *to,
63674 int copy, int offset)
63675 {
63676 if (skb->ip_summed == CHECKSUM_NONE) {
63677diff --git a/include/net/tcp.h b/include/net/tcp.h
63678index f75a04d..702cf06 100644
63679--- a/include/net/tcp.h
63680+++ b/include/net/tcp.h
63681@@ -1425,7 +1425,7 @@ struct tcp_seq_afinfo {
63682 char *name;
63683 sa_family_t family;
63684 const struct file_operations *seq_fops;
63685- struct seq_operations seq_ops;
63686+ seq_operations_no_const seq_ops;
63687 };
63688
63689 struct tcp_iter_state {
63690diff --git a/include/net/udp.h b/include/net/udp.h
63691index 5d606d9..e879f7b 100644
63692--- a/include/net/udp.h
63693+++ b/include/net/udp.h
63694@@ -244,7 +244,7 @@ struct udp_seq_afinfo {
63695 sa_family_t family;
63696 struct udp_table *udp_table;
63697 const struct file_operations *seq_fops;
63698- struct seq_operations seq_ops;
63699+ seq_operations_no_const seq_ops;
63700 };
63701
63702 struct udp_iter_state {
63703diff --git a/include/net/xfrm.h b/include/net/xfrm.h
63704index 96239e7..c85b032 100644
63705--- a/include/net/xfrm.h
63706+++ b/include/net/xfrm.h
63707@@ -505,7 +505,7 @@ struct xfrm_policy {
63708 struct timer_list timer;
63709
63710 struct flow_cache_object flo;
63711- atomic_t genid;
63712+ atomic_unchecked_t genid;
63713 u32 priority;
63714 u32 index;
63715 struct xfrm_mark mark;
63716diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
63717index 1a046b1..ee0bef0 100644
63718--- a/include/rdma/iw_cm.h
63719+++ b/include/rdma/iw_cm.h
63720@@ -122,7 +122,7 @@ struct iw_cm_verbs {
63721 int backlog);
63722
63723 int (*destroy_listen)(struct iw_cm_id *cm_id);
63724-};
63725+} __no_const;
63726
63727 /**
63728 * iw_create_cm_id - Create an IW CM identifier.
63729diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
63730index 8f9dfba..610ab6c 100644
63731--- a/include/scsi/libfc.h
63732+++ b/include/scsi/libfc.h
63733@@ -756,6 +756,7 @@ struct libfc_function_template {
63734 */
63735 void (*disc_stop_final) (struct fc_lport *);
63736 };
63737+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
63738
63739 /**
63740 * struct fc_disc - Discovery context
63741@@ -861,7 +862,7 @@ struct fc_lport {
63742 struct fc_vport *vport;
63743
63744 /* Operational Information */
63745- struct libfc_function_template tt;
63746+ libfc_function_template_no_const tt;
63747 u8 link_up;
63748 u8 qfull;
63749 enum fc_lport_state state;
63750diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
63751index 6efb2e1..cdad57f 100644
63752--- a/include/scsi/scsi_device.h
63753+++ b/include/scsi/scsi_device.h
63754@@ -162,9 +162,9 @@ struct scsi_device {
63755 unsigned int max_device_blocked; /* what device_blocked counts down from */
63756 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
63757
63758- atomic_t iorequest_cnt;
63759- atomic_t iodone_cnt;
63760- atomic_t ioerr_cnt;
63761+ atomic_unchecked_t iorequest_cnt;
63762+ atomic_unchecked_t iodone_cnt;
63763+ atomic_unchecked_t ioerr_cnt;
63764
63765 struct device sdev_gendev,
63766 sdev_dev;
63767diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
63768index 719faf1..d1154d4 100644
63769--- a/include/scsi/scsi_transport_fc.h
63770+++ b/include/scsi/scsi_transport_fc.h
63771@@ -739,7 +739,7 @@ struct fc_function_template {
63772 unsigned long show_host_system_hostname:1;
63773
63774 unsigned long disable_target_scan:1;
63775-};
63776+} __do_const;
63777
63778
63779 /**
63780diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
63781index 030b87c..98a6954 100644
63782--- a/include/sound/ak4xxx-adda.h
63783+++ b/include/sound/ak4xxx-adda.h
63784@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
63785 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
63786 unsigned char val);
63787 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
63788-};
63789+} __no_const;
63790
63791 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
63792
63793diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
63794index 8c05e47..2b5df97 100644
63795--- a/include/sound/hwdep.h
63796+++ b/include/sound/hwdep.h
63797@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
63798 struct snd_hwdep_dsp_status *status);
63799 int (*dsp_load)(struct snd_hwdep *hw,
63800 struct snd_hwdep_dsp_image *image);
63801-};
63802+} __no_const;
63803
63804 struct snd_hwdep {
63805 struct snd_card *card;
63806diff --git a/include/sound/info.h b/include/sound/info.h
63807index 9ca1a49..aba1728 100644
63808--- a/include/sound/info.h
63809+++ b/include/sound/info.h
63810@@ -44,7 +44,7 @@ struct snd_info_entry_text {
63811 struct snd_info_buffer *buffer);
63812 void (*write)(struct snd_info_entry *entry,
63813 struct snd_info_buffer *buffer);
63814-};
63815+} __no_const;
63816
63817 struct snd_info_entry_ops {
63818 int (*open)(struct snd_info_entry *entry,
63819diff --git a/include/sound/pcm.h b/include/sound/pcm.h
63820index 0d11128..814178e 100644
63821--- a/include/sound/pcm.h
63822+++ b/include/sound/pcm.h
63823@@ -81,6 +81,7 @@ struct snd_pcm_ops {
63824 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
63825 int (*ack)(struct snd_pcm_substream *substream);
63826 };
63827+typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
63828
63829 /*
63830 *
63831diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
63832index af1b49e..a5d55a5 100644
63833--- a/include/sound/sb16_csp.h
63834+++ b/include/sound/sb16_csp.h
63835@@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
63836 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
63837 int (*csp_stop) (struct snd_sb_csp * p);
63838 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
63839-};
63840+} __no_const;
63841
63842 /*
63843 * CSP private data
63844diff --git a/include/sound/soc.h b/include/sound/soc.h
63845index 2ebf787..0276839 100644
63846--- a/include/sound/soc.h
63847+++ b/include/sound/soc.h
63848@@ -711,7 +711,7 @@ struct snd_soc_platform_driver {
63849 /* platform IO - used for platform DAPM */
63850 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
63851 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
63852-};
63853+} __do_const;
63854
63855 struct snd_soc_platform {
63856 const char *name;
63857@@ -887,7 +887,7 @@ struct snd_soc_pcm_runtime {
63858 struct snd_soc_dai_link *dai_link;
63859 struct mutex pcm_mutex;
63860 enum snd_soc_pcm_subclass pcm_subclass;
63861- struct snd_pcm_ops ops;
63862+ snd_pcm_ops_no_const ops;
63863
63864 unsigned int complete:1;
63865 unsigned int dev_registered:1;
63866diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
63867index 4119966..1a4671c 100644
63868--- a/include/sound/ymfpci.h
63869+++ b/include/sound/ymfpci.h
63870@@ -358,7 +358,7 @@ struct snd_ymfpci {
63871 spinlock_t reg_lock;
63872 spinlock_t voice_lock;
63873 wait_queue_head_t interrupt_sleep;
63874- atomic_t interrupt_sleep_count;
63875+ atomic_unchecked_t interrupt_sleep_count;
63876 struct snd_info_entry *proc_entry;
63877 const struct firmware *dsp_microcode;
63878 const struct firmware *controller_microcode;
63879diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
63880index aaccc5f..092d568 100644
63881--- a/include/target/target_core_base.h
63882+++ b/include/target/target_core_base.h
63883@@ -447,7 +447,7 @@ struct t10_reservation_ops {
63884 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
63885 int (*t10_pr_register)(struct se_cmd *);
63886 int (*t10_pr_clear)(struct se_cmd *);
63887-};
63888+} __no_const;
63889
63890 struct t10_reservation {
63891 /* Reservation effects all target ports */
63892@@ -576,7 +576,7 @@ struct se_cmd {
63893 atomic_t t_se_count;
63894 atomic_t t_task_cdbs_left;
63895 atomic_t t_task_cdbs_ex_left;
63896- atomic_t t_task_cdbs_sent;
63897+ atomic_unchecked_t t_task_cdbs_sent;
63898 unsigned int transport_state;
63899 #define CMD_T_ABORTED (1 << 0)
63900 #define CMD_T_ACTIVE (1 << 1)
63901@@ -802,7 +802,7 @@ struct se_device {
63902 spinlock_t stats_lock;
63903 /* Active commands on this virtual SE device */
63904 atomic_t simple_cmds;
63905- atomic_t dev_ordered_id;
63906+ atomic_unchecked_t dev_ordered_id;
63907 atomic_t execute_tasks;
63908 atomic_t dev_ordered_sync;
63909 atomic_t dev_qf_count;
63910diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
63911new file mode 100644
63912index 0000000..2efe49d
63913--- /dev/null
63914+++ b/include/trace/events/fs.h
63915@@ -0,0 +1,53 @@
63916+#undef TRACE_SYSTEM
63917+#define TRACE_SYSTEM fs
63918+
63919+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
63920+#define _TRACE_FS_H
63921+
63922+#include <linux/fs.h>
63923+#include <linux/tracepoint.h>
63924+
63925+TRACE_EVENT(do_sys_open,
63926+
63927+ TP_PROTO(char *filename, int flags, int mode),
63928+
63929+ TP_ARGS(filename, flags, mode),
63930+
63931+ TP_STRUCT__entry(
63932+ __string( filename, filename )
63933+ __field( int, flags )
63934+ __field( int, mode )
63935+ ),
63936+
63937+ TP_fast_assign(
63938+ __assign_str(filename, filename);
63939+ __entry->flags = flags;
63940+ __entry->mode = mode;
63941+ ),
63942+
63943+ TP_printk("\"%s\" %x %o",
63944+ __get_str(filename), __entry->flags, __entry->mode)
63945+);
63946+
63947+TRACE_EVENT(open_exec,
63948+
63949+ TP_PROTO(const char *filename),
63950+
63951+ TP_ARGS(filename),
63952+
63953+ TP_STRUCT__entry(
63954+ __string( filename, filename )
63955+ ),
63956+
63957+ TP_fast_assign(
63958+ __assign_str(filename, filename);
63959+ ),
63960+
63961+ TP_printk("\"%s\"",
63962+ __get_str(filename))
63963+);
63964+
63965+#endif /* _TRACE_FS_H */
63966+
63967+/* This part must be outside protection */
63968+#include <trace/define_trace.h>
63969diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
63970index 1c09820..7f5ec79 100644
63971--- a/include/trace/events/irq.h
63972+++ b/include/trace/events/irq.h
63973@@ -36,7 +36,7 @@ struct softirq_action;
63974 */
63975 TRACE_EVENT(irq_handler_entry,
63976
63977- TP_PROTO(int irq, struct irqaction *action),
63978+ TP_PROTO(int irq, const struct irqaction *action),
63979
63980 TP_ARGS(irq, action),
63981
63982@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
63983 */
63984 TRACE_EVENT(irq_handler_exit,
63985
63986- TP_PROTO(int irq, struct irqaction *action, int ret),
63987+ TP_PROTO(int irq, const struct irqaction *action, int ret),
63988
63989 TP_ARGS(irq, action, ret),
63990
63991diff --git a/include/video/udlfb.h b/include/video/udlfb.h
63992index f9466fa..f4e2b81 100644
63993--- a/include/video/udlfb.h
63994+++ b/include/video/udlfb.h
63995@@ -53,10 +53,10 @@ struct dlfb_data {
63996 u32 pseudo_palette[256];
63997 int blank_mode; /*one of FB_BLANK_ */
63998 /* blit-only rendering path metrics, exposed through sysfs */
63999- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64000- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
64001- atomic_t bytes_sent; /* to usb, after compression including overhead */
64002- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
64003+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64004+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
64005+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
64006+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
64007 };
64008
64009 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
64010diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
64011index 0993a22..32ba2fe 100644
64012--- a/include/video/uvesafb.h
64013+++ b/include/video/uvesafb.h
64014@@ -177,6 +177,7 @@ struct uvesafb_par {
64015 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
64016 u8 pmi_setpal; /* PMI for palette changes */
64017 u16 *pmi_base; /* protected mode interface location */
64018+ u8 *pmi_code; /* protected mode code location */
64019 void *pmi_start;
64020 void *pmi_pal;
64021 u8 *vbe_state_orig; /*
64022diff --git a/init/Kconfig b/init/Kconfig
64023index 6cfd71d..73cb68d 100644
64024--- a/init/Kconfig
64025+++ b/init/Kconfig
64026@@ -790,6 +790,7 @@ endif # CGROUPS
64027
64028 config CHECKPOINT_RESTORE
64029 bool "Checkpoint/restore support" if EXPERT
64030+ depends on !GRKERNSEC
64031 default n
64032 help
64033 Enables additional kernel features in a sake of checkpoint/restore.
64034@@ -1240,7 +1241,7 @@ config SLUB_DEBUG
64035
64036 config COMPAT_BRK
64037 bool "Disable heap randomization"
64038- default y
64039+ default n
64040 help
64041 Randomizing heap placement makes heap exploits harder, but it
64042 also breaks ancient binaries (including anything libc5 based).
64043diff --git a/init/do_mounts.c b/init/do_mounts.c
64044index 42b0707..c06eef4 100644
64045--- a/init/do_mounts.c
64046+++ b/init/do_mounts.c
64047@@ -326,11 +326,11 @@ static void __init get_fs_names(char *page)
64048 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
64049 {
64050 struct super_block *s;
64051- int err = sys_mount(name, "/root", fs, flags, data);
64052+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
64053 if (err)
64054 return err;
64055
64056- sys_chdir((const char __user __force *)"/root");
64057+ sys_chdir((const char __force_user *)"/root");
64058 s = current->fs->pwd.dentry->d_sb;
64059 ROOT_DEV = s->s_dev;
64060 printk(KERN_INFO
64061@@ -450,18 +450,18 @@ void __init change_floppy(char *fmt, ...)
64062 va_start(args, fmt);
64063 vsprintf(buf, fmt, args);
64064 va_end(args);
64065- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
64066+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
64067 if (fd >= 0) {
64068 sys_ioctl(fd, FDEJECT, 0);
64069 sys_close(fd);
64070 }
64071 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
64072- fd = sys_open("/dev/console", O_RDWR, 0);
64073+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
64074 if (fd >= 0) {
64075 sys_ioctl(fd, TCGETS, (long)&termios);
64076 termios.c_lflag &= ~ICANON;
64077 sys_ioctl(fd, TCSETSF, (long)&termios);
64078- sys_read(fd, &c, 1);
64079+ sys_read(fd, (char __user *)&c, 1);
64080 termios.c_lflag |= ICANON;
64081 sys_ioctl(fd, TCSETSF, (long)&termios);
64082 sys_close(fd);
64083@@ -555,6 +555,6 @@ void __init prepare_namespace(void)
64084 mount_root();
64085 out:
64086 devtmpfs_mount("dev");
64087- sys_mount(".", "/", NULL, MS_MOVE, NULL);
64088- sys_chroot((const char __user __force *)".");
64089+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64090+ sys_chroot((const char __force_user *)".");
64091 }
64092diff --git a/init/do_mounts.h b/init/do_mounts.h
64093index f5b978a..69dbfe8 100644
64094--- a/init/do_mounts.h
64095+++ b/init/do_mounts.h
64096@@ -15,15 +15,15 @@ extern int root_mountflags;
64097
64098 static inline int create_dev(char *name, dev_t dev)
64099 {
64100- sys_unlink(name);
64101- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
64102+ sys_unlink((char __force_user *)name);
64103+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
64104 }
64105
64106 #if BITS_PER_LONG == 32
64107 static inline u32 bstat(char *name)
64108 {
64109 struct stat64 stat;
64110- if (sys_stat64(name, &stat) != 0)
64111+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
64112 return 0;
64113 if (!S_ISBLK(stat.st_mode))
64114 return 0;
64115@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
64116 static inline u32 bstat(char *name)
64117 {
64118 struct stat stat;
64119- if (sys_newstat(name, &stat) != 0)
64120+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
64121 return 0;
64122 if (!S_ISBLK(stat.st_mode))
64123 return 0;
64124diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
64125index 9047330..de0d1fb 100644
64126--- a/init/do_mounts_initrd.c
64127+++ b/init/do_mounts_initrd.c
64128@@ -43,13 +43,13 @@ static void __init handle_initrd(void)
64129 create_dev("/dev/root.old", Root_RAM0);
64130 /* mount initrd on rootfs' /root */
64131 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
64132- sys_mkdir("/old", 0700);
64133- root_fd = sys_open("/", 0, 0);
64134- old_fd = sys_open("/old", 0, 0);
64135+ sys_mkdir((const char __force_user *)"/old", 0700);
64136+ root_fd = sys_open((const char __force_user *)"/", 0, 0);
64137+ old_fd = sys_open((const char __force_user *)"/old", 0, 0);
64138 /* move initrd over / and chdir/chroot in initrd root */
64139- sys_chdir("/root");
64140- sys_mount(".", "/", NULL, MS_MOVE, NULL);
64141- sys_chroot(".");
64142+ sys_chdir((const char __force_user *)"/root");
64143+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64144+ sys_chroot((const char __force_user *)".");
64145
64146 /*
64147 * In case that a resume from disk is carried out by linuxrc or one of
64148@@ -66,15 +66,15 @@ static void __init handle_initrd(void)
64149
64150 /* move initrd to rootfs' /old */
64151 sys_fchdir(old_fd);
64152- sys_mount("/", ".", NULL, MS_MOVE, NULL);
64153+ sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
64154 /* switch root and cwd back to / of rootfs */
64155 sys_fchdir(root_fd);
64156- sys_chroot(".");
64157+ sys_chroot((const char __force_user *)".");
64158 sys_close(old_fd);
64159 sys_close(root_fd);
64160
64161 if (new_decode_dev(real_root_dev) == Root_RAM0) {
64162- sys_chdir("/old");
64163+ sys_chdir((const char __force_user *)"/old");
64164 return;
64165 }
64166
64167@@ -82,17 +82,17 @@ static void __init handle_initrd(void)
64168 mount_root();
64169
64170 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
64171- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
64172+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
64173 if (!error)
64174 printk("okay\n");
64175 else {
64176- int fd = sys_open("/dev/root.old", O_RDWR, 0);
64177+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
64178 if (error == -ENOENT)
64179 printk("/initrd does not exist. Ignored.\n");
64180 else
64181 printk("failed\n");
64182 printk(KERN_NOTICE "Unmounting old root\n");
64183- sys_umount("/old", MNT_DETACH);
64184+ sys_umount((char __force_user *)"/old", MNT_DETACH);
64185 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
64186 if (fd < 0) {
64187 error = fd;
64188@@ -115,11 +115,11 @@ int __init initrd_load(void)
64189 * mounted in the normal path.
64190 */
64191 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
64192- sys_unlink("/initrd.image");
64193+ sys_unlink((const char __force_user *)"/initrd.image");
64194 handle_initrd();
64195 return 1;
64196 }
64197 }
64198- sys_unlink("/initrd.image");
64199+ sys_unlink((const char __force_user *)"/initrd.image");
64200 return 0;
64201 }
64202diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
64203index 32c4799..c27ee74 100644
64204--- a/init/do_mounts_md.c
64205+++ b/init/do_mounts_md.c
64206@@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
64207 partitioned ? "_d" : "", minor,
64208 md_setup_args[ent].device_names);
64209
64210- fd = sys_open(name, 0, 0);
64211+ fd = sys_open((char __force_user *)name, 0, 0);
64212 if (fd < 0) {
64213 printk(KERN_ERR "md: open failed - cannot start "
64214 "array %s\n", name);
64215@@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
64216 * array without it
64217 */
64218 sys_close(fd);
64219- fd = sys_open(name, 0, 0);
64220+ fd = sys_open((char __force_user *)name, 0, 0);
64221 sys_ioctl(fd, BLKRRPART, 0);
64222 }
64223 sys_close(fd);
64224@@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
64225
64226 wait_for_device_probe();
64227
64228- fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
64229+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
64230 if (fd >= 0) {
64231 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
64232 sys_close(fd);
64233diff --git a/init/initramfs.c b/init/initramfs.c
64234index 8216c30..25e8e32 100644
64235--- a/init/initramfs.c
64236+++ b/init/initramfs.c
64237@@ -74,7 +74,7 @@ static void __init free_hash(void)
64238 }
64239 }
64240
64241-static long __init do_utime(char __user *filename, time_t mtime)
64242+static long __init do_utime(__force char __user *filename, time_t mtime)
64243 {
64244 struct timespec t[2];
64245
64246@@ -109,7 +109,7 @@ static void __init dir_utime(void)
64247 struct dir_entry *de, *tmp;
64248 list_for_each_entry_safe(de, tmp, &dir_list, list) {
64249 list_del(&de->list);
64250- do_utime(de->name, de->mtime);
64251+ do_utime((char __force_user *)de->name, de->mtime);
64252 kfree(de->name);
64253 kfree(de);
64254 }
64255@@ -271,7 +271,7 @@ static int __init maybe_link(void)
64256 if (nlink >= 2) {
64257 char *old = find_link(major, minor, ino, mode, collected);
64258 if (old)
64259- return (sys_link(old, collected) < 0) ? -1 : 1;
64260+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
64261 }
64262 return 0;
64263 }
64264@@ -280,11 +280,11 @@ static void __init clean_path(char *path, umode_t mode)
64265 {
64266 struct stat st;
64267
64268- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
64269+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
64270 if (S_ISDIR(st.st_mode))
64271- sys_rmdir(path);
64272+ sys_rmdir((char __force_user *)path);
64273 else
64274- sys_unlink(path);
64275+ sys_unlink((char __force_user *)path);
64276 }
64277 }
64278
64279@@ -305,7 +305,7 @@ static int __init do_name(void)
64280 int openflags = O_WRONLY|O_CREAT;
64281 if (ml != 1)
64282 openflags |= O_TRUNC;
64283- wfd = sys_open(collected, openflags, mode);
64284+ wfd = sys_open((char __force_user *)collected, openflags, mode);
64285
64286 if (wfd >= 0) {
64287 sys_fchown(wfd, uid, gid);
64288@@ -317,17 +317,17 @@ static int __init do_name(void)
64289 }
64290 }
64291 } else if (S_ISDIR(mode)) {
64292- sys_mkdir(collected, mode);
64293- sys_chown(collected, uid, gid);
64294- sys_chmod(collected, mode);
64295+ sys_mkdir((char __force_user *)collected, mode);
64296+ sys_chown((char __force_user *)collected, uid, gid);
64297+ sys_chmod((char __force_user *)collected, mode);
64298 dir_add(collected, mtime);
64299 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
64300 S_ISFIFO(mode) || S_ISSOCK(mode)) {
64301 if (maybe_link() == 0) {
64302- sys_mknod(collected, mode, rdev);
64303- sys_chown(collected, uid, gid);
64304- sys_chmod(collected, mode);
64305- do_utime(collected, mtime);
64306+ sys_mknod((char __force_user *)collected, mode, rdev);
64307+ sys_chown((char __force_user *)collected, uid, gid);
64308+ sys_chmod((char __force_user *)collected, mode);
64309+ do_utime((char __force_user *)collected, mtime);
64310 }
64311 }
64312 return 0;
64313@@ -336,15 +336,15 @@ static int __init do_name(void)
64314 static int __init do_copy(void)
64315 {
64316 if (count >= body_len) {
64317- sys_write(wfd, victim, body_len);
64318+ sys_write(wfd, (char __force_user *)victim, body_len);
64319 sys_close(wfd);
64320- do_utime(vcollected, mtime);
64321+ do_utime((char __force_user *)vcollected, mtime);
64322 kfree(vcollected);
64323 eat(body_len);
64324 state = SkipIt;
64325 return 0;
64326 } else {
64327- sys_write(wfd, victim, count);
64328+ sys_write(wfd, (char __force_user *)victim, count);
64329 body_len -= count;
64330 eat(count);
64331 return 1;
64332@@ -355,9 +355,9 @@ static int __init do_symlink(void)
64333 {
64334 collected[N_ALIGN(name_len) + body_len] = '\0';
64335 clean_path(collected, 0);
64336- sys_symlink(collected + N_ALIGN(name_len), collected);
64337- sys_lchown(collected, uid, gid);
64338- do_utime(collected, mtime);
64339+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
64340+ sys_lchown((char __force_user *)collected, uid, gid);
64341+ do_utime((char __force_user *)collected, mtime);
64342 state = SkipIt;
64343 next_state = Reset;
64344 return 0;
64345diff --git a/init/main.c b/init/main.c
64346index b08c5f7..09f865e 100644
64347--- a/init/main.c
64348+++ b/init/main.c
64349@@ -95,6 +95,8 @@ static inline void mark_rodata_ro(void) { }
64350 extern void tc_init(void);
64351 #endif
64352
64353+extern void grsecurity_init(void);
64354+
64355 /*
64356 * Debug helper: via this flag we know that we are in 'early bootup code'
64357 * where only the boot processor is running with IRQ disabled. This means
64358@@ -148,6 +150,49 @@ static int __init set_reset_devices(char *str)
64359
64360 __setup("reset_devices", set_reset_devices);
64361
64362+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
64363+extern char pax_enter_kernel_user[];
64364+extern char pax_exit_kernel_user[];
64365+extern pgdval_t clone_pgd_mask;
64366+#endif
64367+
64368+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
64369+static int __init setup_pax_nouderef(char *str)
64370+{
64371+#ifdef CONFIG_X86_32
64372+ unsigned int cpu;
64373+ struct desc_struct *gdt;
64374+
64375+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
64376+ gdt = get_cpu_gdt_table(cpu);
64377+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
64378+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
64379+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
64380+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
64381+ }
64382+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
64383+#else
64384+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
64385+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
64386+ clone_pgd_mask = ~(pgdval_t)0UL;
64387+#endif
64388+
64389+ return 0;
64390+}
64391+early_param("pax_nouderef", setup_pax_nouderef);
64392+#endif
64393+
64394+#ifdef CONFIG_PAX_SOFTMODE
64395+int pax_softmode;
64396+
64397+static int __init setup_pax_softmode(char *str)
64398+{
64399+ get_option(&str, &pax_softmode);
64400+ return 1;
64401+}
64402+__setup("pax_softmode=", setup_pax_softmode);
64403+#endif
64404+
64405 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
64406 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
64407 static const char *panic_later, *panic_param;
64408@@ -674,6 +719,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
64409 {
64410 int count = preempt_count();
64411 int ret;
64412+ const char *msg1 = "", *msg2 = "";
64413
64414 if (initcall_debug)
64415 ret = do_one_initcall_debug(fn);
64416@@ -686,15 +732,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
64417 sprintf(msgbuf, "error code %d ", ret);
64418
64419 if (preempt_count() != count) {
64420- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
64421+ msg1 = " preemption imbalance";
64422 preempt_count() = count;
64423 }
64424 if (irqs_disabled()) {
64425- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
64426+ msg2 = " disabled interrupts";
64427 local_irq_enable();
64428 }
64429- if (msgbuf[0]) {
64430- printk("initcall %pF returned with %s\n", fn, msgbuf);
64431+ if (msgbuf[0] || *msg1 || *msg2) {
64432+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
64433 }
64434
64435 return ret;
64436@@ -865,7 +911,7 @@ static int __init kernel_init(void * unused)
64437 do_basic_setup();
64438
64439 /* Open the /dev/console on the rootfs, this should never fail */
64440- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
64441+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
64442 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
64443
64444 (void) sys_dup(0);
64445@@ -878,11 +924,13 @@ static int __init kernel_init(void * unused)
64446 if (!ramdisk_execute_command)
64447 ramdisk_execute_command = "/init";
64448
64449- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
64450+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
64451 ramdisk_execute_command = NULL;
64452 prepare_namespace();
64453 }
64454
64455+ grsecurity_init();
64456+
64457 /*
64458 * Ok, we have completed the initial bootup, and
64459 * we're essentially up and running. Get rid of the
64460diff --git a/ipc/mqueue.c b/ipc/mqueue.c
64461index 28bd64d..c66b72a 100644
64462--- a/ipc/mqueue.c
64463+++ b/ipc/mqueue.c
64464@@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
64465 mq_bytes = (mq_msg_tblsz +
64466 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
64467
64468+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
64469 spin_lock(&mq_lock);
64470 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
64471 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
64472diff --git a/ipc/msg.c b/ipc/msg.c
64473index 7385de2..a8180e08 100644
64474--- a/ipc/msg.c
64475+++ b/ipc/msg.c
64476@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
64477 return security_msg_queue_associate(msq, msgflg);
64478 }
64479
64480+static struct ipc_ops msg_ops = {
64481+ .getnew = newque,
64482+ .associate = msg_security,
64483+ .more_checks = NULL
64484+};
64485+
64486 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
64487 {
64488 struct ipc_namespace *ns;
64489- struct ipc_ops msg_ops;
64490 struct ipc_params msg_params;
64491
64492 ns = current->nsproxy->ipc_ns;
64493
64494- msg_ops.getnew = newque;
64495- msg_ops.associate = msg_security;
64496- msg_ops.more_checks = NULL;
64497-
64498 msg_params.key = key;
64499 msg_params.flg = msgflg;
64500
64501diff --git a/ipc/sem.c b/ipc/sem.c
64502index 5215a81..cfc0cac 100644
64503--- a/ipc/sem.c
64504+++ b/ipc/sem.c
64505@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
64506 return 0;
64507 }
64508
64509+static struct ipc_ops sem_ops = {
64510+ .getnew = newary,
64511+ .associate = sem_security,
64512+ .more_checks = sem_more_checks
64513+};
64514+
64515 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
64516 {
64517 struct ipc_namespace *ns;
64518- struct ipc_ops sem_ops;
64519 struct ipc_params sem_params;
64520
64521 ns = current->nsproxy->ipc_ns;
64522@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
64523 if (nsems < 0 || nsems > ns->sc_semmsl)
64524 return -EINVAL;
64525
64526- sem_ops.getnew = newary;
64527- sem_ops.associate = sem_security;
64528- sem_ops.more_checks = sem_more_checks;
64529-
64530 sem_params.key = key;
64531 sem_params.flg = semflg;
64532 sem_params.u.nsems = nsems;
64533diff --git a/ipc/shm.c b/ipc/shm.c
64534index 406c5b2..bc66d67 100644
64535--- a/ipc/shm.c
64536+++ b/ipc/shm.c
64537@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
64538 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
64539 #endif
64540
64541+#ifdef CONFIG_GRKERNSEC
64542+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64543+ const time_t shm_createtime, const uid_t cuid,
64544+ const int shmid);
64545+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64546+ const time_t shm_createtime);
64547+#endif
64548+
64549 void shm_init_ns(struct ipc_namespace *ns)
64550 {
64551 ns->shm_ctlmax = SHMMAX;
64552@@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
64553 shp->shm_lprid = 0;
64554 shp->shm_atim = shp->shm_dtim = 0;
64555 shp->shm_ctim = get_seconds();
64556+#ifdef CONFIG_GRKERNSEC
64557+ {
64558+ struct timespec timeval;
64559+ do_posix_clock_monotonic_gettime(&timeval);
64560+
64561+ shp->shm_createtime = timeval.tv_sec;
64562+ }
64563+#endif
64564 shp->shm_segsz = size;
64565 shp->shm_nattch = 0;
64566 shp->shm_file = file;
64567@@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
64568 return 0;
64569 }
64570
64571+static struct ipc_ops shm_ops = {
64572+ .getnew = newseg,
64573+ .associate = shm_security,
64574+ .more_checks = shm_more_checks
64575+};
64576+
64577 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
64578 {
64579 struct ipc_namespace *ns;
64580- struct ipc_ops shm_ops;
64581 struct ipc_params shm_params;
64582
64583 ns = current->nsproxy->ipc_ns;
64584
64585- shm_ops.getnew = newseg;
64586- shm_ops.associate = shm_security;
64587- shm_ops.more_checks = shm_more_checks;
64588-
64589 shm_params.key = key;
64590 shm_params.flg = shmflg;
64591 shm_params.u.size = size;
64592@@ -988,6 +1005,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
64593 f_mode = FMODE_READ | FMODE_WRITE;
64594 }
64595 if (shmflg & SHM_EXEC) {
64596+
64597+#ifdef CONFIG_PAX_MPROTECT
64598+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
64599+ goto out;
64600+#endif
64601+
64602 prot |= PROT_EXEC;
64603 acc_mode |= S_IXUGO;
64604 }
64605@@ -1011,9 +1034,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
64606 if (err)
64607 goto out_unlock;
64608
64609+#ifdef CONFIG_GRKERNSEC
64610+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
64611+ shp->shm_perm.cuid, shmid) ||
64612+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
64613+ err = -EACCES;
64614+ goto out_unlock;
64615+ }
64616+#endif
64617+
64618 path = shp->shm_file->f_path;
64619 path_get(&path);
64620 shp->shm_nattch++;
64621+#ifdef CONFIG_GRKERNSEC
64622+ shp->shm_lapid = current->pid;
64623+#endif
64624 size = i_size_read(path.dentry->d_inode);
64625 shm_unlock(shp);
64626
64627diff --git a/kernel/acct.c b/kernel/acct.c
64628index 02e6167..54824f7 100644
64629--- a/kernel/acct.c
64630+++ b/kernel/acct.c
64631@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
64632 */
64633 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
64634 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
64635- file->f_op->write(file, (char *)&ac,
64636+ file->f_op->write(file, (char __force_user *)&ac,
64637 sizeof(acct_t), &file->f_pos);
64638 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
64639 set_fs(fs);
64640diff --git a/kernel/audit.c b/kernel/audit.c
64641index 1c7f2c6..9ba5359 100644
64642--- a/kernel/audit.c
64643+++ b/kernel/audit.c
64644@@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
64645 3) suppressed due to audit_rate_limit
64646 4) suppressed due to audit_backlog_limit
64647 */
64648-static atomic_t audit_lost = ATOMIC_INIT(0);
64649+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
64650
64651 /* The netlink socket. */
64652 static struct sock *audit_sock;
64653@@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
64654 unsigned long now;
64655 int print;
64656
64657- atomic_inc(&audit_lost);
64658+ atomic_inc_unchecked(&audit_lost);
64659
64660 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
64661
64662@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
64663 printk(KERN_WARNING
64664 "audit: audit_lost=%d audit_rate_limit=%d "
64665 "audit_backlog_limit=%d\n",
64666- atomic_read(&audit_lost),
64667+ atomic_read_unchecked(&audit_lost),
64668 audit_rate_limit,
64669 audit_backlog_limit);
64670 audit_panic(message);
64671@@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
64672 status_set.pid = audit_pid;
64673 status_set.rate_limit = audit_rate_limit;
64674 status_set.backlog_limit = audit_backlog_limit;
64675- status_set.lost = atomic_read(&audit_lost);
64676+ status_set.lost = atomic_read_unchecked(&audit_lost);
64677 status_set.backlog = skb_queue_len(&audit_skb_queue);
64678 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
64679 &status_set, sizeof(status_set));
64680diff --git a/kernel/auditsc.c b/kernel/auditsc.c
64681index af1de0f..06dfe57 100644
64682--- a/kernel/auditsc.c
64683+++ b/kernel/auditsc.c
64684@@ -2288,7 +2288,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
64685 }
64686
64687 /* global counter which is incremented every time something logs in */
64688-static atomic_t session_id = ATOMIC_INIT(0);
64689+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
64690
64691 /**
64692 * audit_set_loginuid - set current task's audit_context loginuid
64693@@ -2312,7 +2312,7 @@ int audit_set_loginuid(uid_t loginuid)
64694 return -EPERM;
64695 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
64696
64697- sessionid = atomic_inc_return(&session_id);
64698+ sessionid = atomic_inc_return_unchecked(&session_id);
64699 if (context && context->in_syscall) {
64700 struct audit_buffer *ab;
64701
64702diff --git a/kernel/capability.c b/kernel/capability.c
64703index 3f1adb6..c564db0 100644
64704--- a/kernel/capability.c
64705+++ b/kernel/capability.c
64706@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
64707 * before modification is attempted and the application
64708 * fails.
64709 */
64710+ if (tocopy > ARRAY_SIZE(kdata))
64711+ return -EFAULT;
64712+
64713 if (copy_to_user(dataptr, kdata, tocopy
64714 * sizeof(struct __user_cap_data_struct))) {
64715 return -EFAULT;
64716@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
64717 int ret;
64718
64719 rcu_read_lock();
64720- ret = security_capable(__task_cred(t), ns, cap);
64721+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
64722+ gr_task_is_capable(t, __task_cred(t), cap);
64723 rcu_read_unlock();
64724
64725- return (ret == 0);
64726+ return ret;
64727 }
64728
64729 /**
64730@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
64731 int ret;
64732
64733 rcu_read_lock();
64734- ret = security_capable_noaudit(__task_cred(t), ns, cap);
64735+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
64736 rcu_read_unlock();
64737
64738- return (ret == 0);
64739+ return ret;
64740 }
64741
64742 /**
64743@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
64744 BUG();
64745 }
64746
64747- if (security_capable(current_cred(), ns, cap) == 0) {
64748+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
64749 current->flags |= PF_SUPERPRIV;
64750 return true;
64751 }
64752@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
64753 }
64754 EXPORT_SYMBOL(ns_capable);
64755
64756+bool ns_capable_nolog(struct user_namespace *ns, int cap)
64757+{
64758+ if (unlikely(!cap_valid(cap))) {
64759+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
64760+ BUG();
64761+ }
64762+
64763+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
64764+ current->flags |= PF_SUPERPRIV;
64765+ return true;
64766+ }
64767+ return false;
64768+}
64769+EXPORT_SYMBOL(ns_capable_nolog);
64770+
64771 /**
64772 * capable - Determine if the current task has a superior capability in effect
64773 * @cap: The capability to be tested for
64774@@ -408,6 +427,12 @@ bool capable(int cap)
64775 }
64776 EXPORT_SYMBOL(capable);
64777
64778+bool capable_nolog(int cap)
64779+{
64780+ return ns_capable_nolog(&init_user_ns, cap);
64781+}
64782+EXPORT_SYMBOL(capable_nolog);
64783+
64784 /**
64785 * nsown_capable - Check superior capability to one's own user_ns
64786 * @cap: The capability in question
64787diff --git a/kernel/compat.c b/kernel/compat.c
64788index d2c67aa..a629b2e 100644
64789--- a/kernel/compat.c
64790+++ b/kernel/compat.c
64791@@ -13,6 +13,7 @@
64792
64793 #include <linux/linkage.h>
64794 #include <linux/compat.h>
64795+#include <linux/module.h>
64796 #include <linux/errno.h>
64797 #include <linux/time.h>
64798 #include <linux/signal.h>
64799@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
64800 mm_segment_t oldfs;
64801 long ret;
64802
64803- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
64804+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
64805 oldfs = get_fs();
64806 set_fs(KERNEL_DS);
64807 ret = hrtimer_nanosleep_restart(restart);
64808@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
64809 oldfs = get_fs();
64810 set_fs(KERNEL_DS);
64811 ret = hrtimer_nanosleep(&tu,
64812- rmtp ? (struct timespec __user *)&rmt : NULL,
64813+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
64814 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
64815 set_fs(oldfs);
64816
64817@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
64818 mm_segment_t old_fs = get_fs();
64819
64820 set_fs(KERNEL_DS);
64821- ret = sys_sigpending((old_sigset_t __user *) &s);
64822+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
64823 set_fs(old_fs);
64824 if (ret == 0)
64825 ret = put_user(s, set);
64826@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
64827 mm_segment_t old_fs = get_fs();
64828
64829 set_fs(KERNEL_DS);
64830- ret = sys_old_getrlimit(resource, &r);
64831+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
64832 set_fs(old_fs);
64833
64834 if (!ret) {
64835@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
64836 mm_segment_t old_fs = get_fs();
64837
64838 set_fs(KERNEL_DS);
64839- ret = sys_getrusage(who, (struct rusage __user *) &r);
64840+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
64841 set_fs(old_fs);
64842
64843 if (ret)
64844@@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
64845 set_fs (KERNEL_DS);
64846 ret = sys_wait4(pid,
64847 (stat_addr ?
64848- (unsigned int __user *) &status : NULL),
64849- options, (struct rusage __user *) &r);
64850+ (unsigned int __force_user *) &status : NULL),
64851+ options, (struct rusage __force_user *) &r);
64852 set_fs (old_fs);
64853
64854 if (ret > 0) {
64855@@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
64856 memset(&info, 0, sizeof(info));
64857
64858 set_fs(KERNEL_DS);
64859- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
64860- uru ? (struct rusage __user *)&ru : NULL);
64861+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
64862+ uru ? (struct rusage __force_user *)&ru : NULL);
64863 set_fs(old_fs);
64864
64865 if ((ret < 0) || (info.si_signo == 0))
64866@@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
64867 oldfs = get_fs();
64868 set_fs(KERNEL_DS);
64869 err = sys_timer_settime(timer_id, flags,
64870- (struct itimerspec __user *) &newts,
64871- (struct itimerspec __user *) &oldts);
64872+ (struct itimerspec __force_user *) &newts,
64873+ (struct itimerspec __force_user *) &oldts);
64874 set_fs(oldfs);
64875 if (!err && old && put_compat_itimerspec(old, &oldts))
64876 return -EFAULT;
64877@@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
64878 oldfs = get_fs();
64879 set_fs(KERNEL_DS);
64880 err = sys_timer_gettime(timer_id,
64881- (struct itimerspec __user *) &ts);
64882+ (struct itimerspec __force_user *) &ts);
64883 set_fs(oldfs);
64884 if (!err && put_compat_itimerspec(setting, &ts))
64885 return -EFAULT;
64886@@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
64887 oldfs = get_fs();
64888 set_fs(KERNEL_DS);
64889 err = sys_clock_settime(which_clock,
64890- (struct timespec __user *) &ts);
64891+ (struct timespec __force_user *) &ts);
64892 set_fs(oldfs);
64893 return err;
64894 }
64895@@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
64896 oldfs = get_fs();
64897 set_fs(KERNEL_DS);
64898 err = sys_clock_gettime(which_clock,
64899- (struct timespec __user *) &ts);
64900+ (struct timespec __force_user *) &ts);
64901 set_fs(oldfs);
64902 if (!err && put_compat_timespec(&ts, tp))
64903 return -EFAULT;
64904@@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
64905
64906 oldfs = get_fs();
64907 set_fs(KERNEL_DS);
64908- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
64909+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
64910 set_fs(oldfs);
64911
64912 err = compat_put_timex(utp, &txc);
64913@@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
64914 oldfs = get_fs();
64915 set_fs(KERNEL_DS);
64916 err = sys_clock_getres(which_clock,
64917- (struct timespec __user *) &ts);
64918+ (struct timespec __force_user *) &ts);
64919 set_fs(oldfs);
64920 if (!err && tp && put_compat_timespec(&ts, tp))
64921 return -EFAULT;
64922@@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
64923 long err;
64924 mm_segment_t oldfs;
64925 struct timespec tu;
64926- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
64927+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
64928
64929- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
64930+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
64931 oldfs = get_fs();
64932 set_fs(KERNEL_DS);
64933 err = clock_nanosleep_restart(restart);
64934@@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
64935 oldfs = get_fs();
64936 set_fs(KERNEL_DS);
64937 err = sys_clock_nanosleep(which_clock, flags,
64938- (struct timespec __user *) &in,
64939- (struct timespec __user *) &out);
64940+ (struct timespec __force_user *) &in,
64941+ (struct timespec __force_user *) &out);
64942 set_fs(oldfs);
64943
64944 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
64945diff --git a/kernel/configs.c b/kernel/configs.c
64946index 42e8fa0..9e7406b 100644
64947--- a/kernel/configs.c
64948+++ b/kernel/configs.c
64949@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
64950 struct proc_dir_entry *entry;
64951
64952 /* create the current config file */
64953+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
64954+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
64955+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
64956+ &ikconfig_file_ops);
64957+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64958+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
64959+ &ikconfig_file_ops);
64960+#endif
64961+#else
64962 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
64963 &ikconfig_file_ops);
64964+#endif
64965+
64966 if (!entry)
64967 return -ENOMEM;
64968
64969diff --git a/kernel/cred.c b/kernel/cred.c
64970index e70683d..27761b6 100644
64971--- a/kernel/cred.c
64972+++ b/kernel/cred.c
64973@@ -205,6 +205,15 @@ void exit_creds(struct task_struct *tsk)
64974 validate_creds(cred);
64975 put_cred(cred);
64976 }
64977+
64978+#ifdef CONFIG_GRKERNSEC_SETXID
64979+ cred = (struct cred *) tsk->delayed_cred;
64980+ if (cred) {
64981+ tsk->delayed_cred = NULL;
64982+ validate_creds(cred);
64983+ put_cred(cred);
64984+ }
64985+#endif
64986 }
64987
64988 /**
64989@@ -473,7 +482,7 @@ error_put:
64990 * Always returns 0 thus allowing this function to be tail-called at the end
64991 * of, say, sys_setgid().
64992 */
64993-int commit_creds(struct cred *new)
64994+static int __commit_creds(struct cred *new)
64995 {
64996 struct task_struct *task = current;
64997 const struct cred *old = task->real_cred;
64998@@ -492,6 +501,8 @@ int commit_creds(struct cred *new)
64999
65000 get_cred(new); /* we will require a ref for the subj creds too */
65001
65002+ gr_set_role_label(task, new->uid, new->gid);
65003+
65004 /* dumpability changes */
65005 if (old->euid != new->euid ||
65006 old->egid != new->egid ||
65007@@ -541,6 +552,101 @@ int commit_creds(struct cred *new)
65008 put_cred(old);
65009 return 0;
65010 }
65011+#ifdef CONFIG_GRKERNSEC_SETXID
65012+extern int set_user(struct cred *new);
65013+
65014+void gr_delayed_cred_worker(void)
65015+{
65016+ const struct cred *new = current->delayed_cred;
65017+ struct cred *ncred;
65018+
65019+ current->delayed_cred = NULL;
65020+
65021+ if (current_uid() && new != NULL) {
65022+ // from doing get_cred on it when queueing this
65023+ put_cred(new);
65024+ return;
65025+ } else if (new == NULL)
65026+ return;
65027+
65028+ ncred = prepare_creds();
65029+ if (!ncred)
65030+ goto die;
65031+ // uids
65032+ ncred->uid = new->uid;
65033+ ncred->euid = new->euid;
65034+ ncred->suid = new->suid;
65035+ ncred->fsuid = new->fsuid;
65036+ // gids
65037+ ncred->gid = new->gid;
65038+ ncred->egid = new->egid;
65039+ ncred->sgid = new->sgid;
65040+ ncred->fsgid = new->fsgid;
65041+ // groups
65042+ if (set_groups(ncred, new->group_info) < 0) {
65043+ abort_creds(ncred);
65044+ goto die;
65045+ }
65046+ // caps
65047+ ncred->securebits = new->securebits;
65048+ ncred->cap_inheritable = new->cap_inheritable;
65049+ ncred->cap_permitted = new->cap_permitted;
65050+ ncred->cap_effective = new->cap_effective;
65051+ ncred->cap_bset = new->cap_bset;
65052+
65053+ if (set_user(ncred)) {
65054+ abort_creds(ncred);
65055+ goto die;
65056+ }
65057+
65058+ // from doing get_cred on it when queueing this
65059+ put_cred(new);
65060+
65061+ __commit_creds(ncred);
65062+ return;
65063+die:
65064+ // from doing get_cred on it when queueing this
65065+ put_cred(new);
65066+ do_group_exit(SIGKILL);
65067+}
65068+#endif
65069+
65070+int commit_creds(struct cred *new)
65071+{
65072+#ifdef CONFIG_GRKERNSEC_SETXID
65073+ int ret;
65074+ int schedule_it = 0;
65075+ struct task_struct *t;
65076+
65077+ /* we won't get called with tasklist_lock held for writing
65078+ and interrupts disabled as the cred struct in that case is
65079+ init_cred
65080+ */
65081+ if (grsec_enable_setxid && !current_is_single_threaded() &&
65082+ !current_uid() && new->uid) {
65083+ schedule_it = 1;
65084+ }
65085+ ret = __commit_creds(new);
65086+ if (schedule_it) {
65087+ rcu_read_lock();
65088+ read_lock(&tasklist_lock);
65089+ for (t = next_thread(current); t != current;
65090+ t = next_thread(t)) {
65091+ if (t->delayed_cred == NULL) {
65092+ t->delayed_cred = get_cred(new);
65093+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
65094+ set_tsk_need_resched(t);
65095+ }
65096+ }
65097+ read_unlock(&tasklist_lock);
65098+ rcu_read_unlock();
65099+ }
65100+ return ret;
65101+#else
65102+ return __commit_creds(new);
65103+#endif
65104+}
65105+
65106 EXPORT_SYMBOL(commit_creds);
65107
65108 /**
65109diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
65110index 0557f24..1a00d9a 100644
65111--- a/kernel/debug/debug_core.c
65112+++ b/kernel/debug/debug_core.c
65113@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
65114 */
65115 static atomic_t masters_in_kgdb;
65116 static atomic_t slaves_in_kgdb;
65117-static atomic_t kgdb_break_tasklet_var;
65118+static atomic_unchecked_t kgdb_break_tasklet_var;
65119 atomic_t kgdb_setting_breakpoint;
65120
65121 struct task_struct *kgdb_usethread;
65122@@ -132,7 +132,7 @@ int kgdb_single_step;
65123 static pid_t kgdb_sstep_pid;
65124
65125 /* to keep track of the CPU which is doing the single stepping*/
65126-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65127+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65128
65129 /*
65130 * If you are debugging a problem where roundup (the collection of
65131@@ -540,7 +540,7 @@ return_normal:
65132 * kernel will only try for the value of sstep_tries before
65133 * giving up and continuing on.
65134 */
65135- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
65136+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
65137 (kgdb_info[cpu].task &&
65138 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
65139 atomic_set(&kgdb_active, -1);
65140@@ -634,8 +634,8 @@ cpu_master_loop:
65141 }
65142
65143 kgdb_restore:
65144- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
65145- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
65146+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
65147+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
65148 if (kgdb_info[sstep_cpu].task)
65149 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
65150 else
65151@@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
65152 static void kgdb_tasklet_bpt(unsigned long ing)
65153 {
65154 kgdb_breakpoint();
65155- atomic_set(&kgdb_break_tasklet_var, 0);
65156+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
65157 }
65158
65159 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
65160
65161 void kgdb_schedule_breakpoint(void)
65162 {
65163- if (atomic_read(&kgdb_break_tasklet_var) ||
65164+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
65165 atomic_read(&kgdb_active) != -1 ||
65166 atomic_read(&kgdb_setting_breakpoint))
65167 return;
65168- atomic_inc(&kgdb_break_tasklet_var);
65169+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
65170 tasklet_schedule(&kgdb_tasklet_breakpoint);
65171 }
65172 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
65173diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
65174index 67b847d..93834dd 100644
65175--- a/kernel/debug/kdb/kdb_main.c
65176+++ b/kernel/debug/kdb/kdb_main.c
65177@@ -1983,7 +1983,7 @@ static int kdb_lsmod(int argc, const char **argv)
65178 list_for_each_entry(mod, kdb_modules, list) {
65179
65180 kdb_printf("%-20s%8u 0x%p ", mod->name,
65181- mod->core_size, (void *)mod);
65182+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
65183 #ifdef CONFIG_MODULE_UNLOAD
65184 kdb_printf("%4ld ", module_refcount(mod));
65185 #endif
65186@@ -1993,7 +1993,7 @@ static int kdb_lsmod(int argc, const char **argv)
65187 kdb_printf(" (Loading)");
65188 else
65189 kdb_printf(" (Live)");
65190- kdb_printf(" 0x%p", mod->module_core);
65191+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
65192
65193 #ifdef CONFIG_MODULE_UNLOAD
65194 {
65195diff --git a/kernel/events/core.c b/kernel/events/core.c
65196index fd126f8..70b755b 100644
65197--- a/kernel/events/core.c
65198+++ b/kernel/events/core.c
65199@@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
65200 return 0;
65201 }
65202
65203-static atomic64_t perf_event_id;
65204+static atomic64_unchecked_t perf_event_id;
65205
65206 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
65207 enum event_type_t event_type);
65208@@ -2659,7 +2659,7 @@ static void __perf_event_read(void *info)
65209
65210 static inline u64 perf_event_count(struct perf_event *event)
65211 {
65212- return local64_read(&event->count) + atomic64_read(&event->child_count);
65213+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
65214 }
65215
65216 static u64 perf_event_read(struct perf_event *event)
65217@@ -2983,9 +2983,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
65218 mutex_lock(&event->child_mutex);
65219 total += perf_event_read(event);
65220 *enabled += event->total_time_enabled +
65221- atomic64_read(&event->child_total_time_enabled);
65222+ atomic64_read_unchecked(&event->child_total_time_enabled);
65223 *running += event->total_time_running +
65224- atomic64_read(&event->child_total_time_running);
65225+ atomic64_read_unchecked(&event->child_total_time_running);
65226
65227 list_for_each_entry(child, &event->child_list, child_list) {
65228 total += perf_event_read(child);
65229@@ -3393,10 +3393,10 @@ void perf_event_update_userpage(struct perf_event *event)
65230 userpg->offset -= local64_read(&event->hw.prev_count);
65231
65232 userpg->time_enabled = enabled +
65233- atomic64_read(&event->child_total_time_enabled);
65234+ atomic64_read_unchecked(&event->child_total_time_enabled);
65235
65236 userpg->time_running = running +
65237- atomic64_read(&event->child_total_time_running);
65238+ atomic64_read_unchecked(&event->child_total_time_running);
65239
65240 arch_perf_update_userpage(userpg, now);
65241
65242@@ -3829,11 +3829,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
65243 values[n++] = perf_event_count(event);
65244 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
65245 values[n++] = enabled +
65246- atomic64_read(&event->child_total_time_enabled);
65247+ atomic64_read_unchecked(&event->child_total_time_enabled);
65248 }
65249 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
65250 values[n++] = running +
65251- atomic64_read(&event->child_total_time_running);
65252+ atomic64_read_unchecked(&event->child_total_time_running);
65253 }
65254 if (read_format & PERF_FORMAT_ID)
65255 values[n++] = primary_event_id(event);
65256@@ -4511,12 +4511,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
65257 * need to add enough zero bytes after the string to handle
65258 * the 64bit alignment we do later.
65259 */
65260- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
65261+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
65262 if (!buf) {
65263 name = strncpy(tmp, "//enomem", sizeof(tmp));
65264 goto got_name;
65265 }
65266- name = d_path(&file->f_path, buf, PATH_MAX);
65267+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
65268 if (IS_ERR(name)) {
65269 name = strncpy(tmp, "//toolong", sizeof(tmp));
65270 goto got_name;
65271@@ -5929,7 +5929,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
65272 event->parent = parent_event;
65273
65274 event->ns = get_pid_ns(current->nsproxy->pid_ns);
65275- event->id = atomic64_inc_return(&perf_event_id);
65276+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
65277
65278 event->state = PERF_EVENT_STATE_INACTIVE;
65279
65280@@ -6491,10 +6491,10 @@ static void sync_child_event(struct perf_event *child_event,
65281 /*
65282 * Add back the child's count to the parent's count:
65283 */
65284- atomic64_add(child_val, &parent_event->child_count);
65285- atomic64_add(child_event->total_time_enabled,
65286+ atomic64_add_unchecked(child_val, &parent_event->child_count);
65287+ atomic64_add_unchecked(child_event->total_time_enabled,
65288 &parent_event->child_total_time_enabled);
65289- atomic64_add(child_event->total_time_running,
65290+ atomic64_add_unchecked(child_event->total_time_running,
65291 &parent_event->child_total_time_running);
65292
65293 /*
65294diff --git a/kernel/exit.c b/kernel/exit.c
65295index d8bd3b42..26bd8dc 100644
65296--- a/kernel/exit.c
65297+++ b/kernel/exit.c
65298@@ -59,6 +59,10 @@
65299 #include <asm/pgtable.h>
65300 #include <asm/mmu_context.h>
65301
65302+#ifdef CONFIG_GRKERNSEC
65303+extern rwlock_t grsec_exec_file_lock;
65304+#endif
65305+
65306 static void exit_mm(struct task_struct * tsk);
65307
65308 static void __unhash_process(struct task_struct *p, bool group_dead)
65309@@ -170,6 +174,10 @@ void release_task(struct task_struct * p)
65310 struct task_struct *leader;
65311 int zap_leader;
65312 repeat:
65313+#ifdef CONFIG_NET
65314+ gr_del_task_from_ip_table(p);
65315+#endif
65316+
65317 /* don't need to get the RCU readlock here - the process is dead and
65318 * can't be modifying its own credentials. But shut RCU-lockdep up */
65319 rcu_read_lock();
65320@@ -382,7 +390,7 @@ int allow_signal(int sig)
65321 * know it'll be handled, so that they don't get converted to
65322 * SIGKILL or just silently dropped.
65323 */
65324- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
65325+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
65326 recalc_sigpending();
65327 spin_unlock_irq(&current->sighand->siglock);
65328 return 0;
65329@@ -418,6 +426,17 @@ void daemonize(const char *name, ...)
65330 vsnprintf(current->comm, sizeof(current->comm), name, args);
65331 va_end(args);
65332
65333+#ifdef CONFIG_GRKERNSEC
65334+ write_lock(&grsec_exec_file_lock);
65335+ if (current->exec_file) {
65336+ fput(current->exec_file);
65337+ current->exec_file = NULL;
65338+ }
65339+ write_unlock(&grsec_exec_file_lock);
65340+#endif
65341+
65342+ gr_set_kernel_label(current);
65343+
65344 /*
65345 * If we were started as result of loading a module, close all of the
65346 * user space pages. We don't need them, and if we didn't close them
65347@@ -900,6 +919,8 @@ void do_exit(long code)
65348 struct task_struct *tsk = current;
65349 int group_dead;
65350
65351+ set_fs(USER_DS);
65352+
65353 profile_task_exit(tsk);
65354
65355 WARN_ON(blk_needs_flush_plug(tsk));
65356@@ -916,7 +937,6 @@ void do_exit(long code)
65357 * mm_release()->clear_child_tid() from writing to a user-controlled
65358 * kernel address.
65359 */
65360- set_fs(USER_DS);
65361
65362 ptrace_event(PTRACE_EVENT_EXIT, code);
65363
65364@@ -977,6 +997,9 @@ void do_exit(long code)
65365 tsk->exit_code = code;
65366 taskstats_exit(tsk, group_dead);
65367
65368+ gr_acl_handle_psacct(tsk, code);
65369+ gr_acl_handle_exit();
65370+
65371 exit_mm(tsk);
65372
65373 if (group_dead)
65374@@ -1093,7 +1116,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
65375 * Take down every thread in the group. This is called by fatal signals
65376 * as well as by sys_exit_group (below).
65377 */
65378-void
65379+__noreturn void
65380 do_group_exit(int exit_code)
65381 {
65382 struct signal_struct *sig = current->signal;
65383diff --git a/kernel/fork.c b/kernel/fork.c
65384index 8163333..efb4692 100644
65385--- a/kernel/fork.c
65386+++ b/kernel/fork.c
65387@@ -286,7 +286,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
65388 *stackend = STACK_END_MAGIC; /* for overflow detection */
65389
65390 #ifdef CONFIG_CC_STACKPROTECTOR
65391- tsk->stack_canary = get_random_int();
65392+ tsk->stack_canary = pax_get_random_long();
65393 #endif
65394
65395 /*
65396@@ -310,13 +310,78 @@ out:
65397 }
65398
65399 #ifdef CONFIG_MMU
65400+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
65401+{
65402+ struct vm_area_struct *tmp;
65403+ unsigned long charge;
65404+ struct mempolicy *pol;
65405+ struct file *file;
65406+
65407+ charge = 0;
65408+ if (mpnt->vm_flags & VM_ACCOUNT) {
65409+ unsigned long len;
65410+ len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
65411+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
65412+ goto fail_nomem;
65413+ charge = len;
65414+ }
65415+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
65416+ if (!tmp)
65417+ goto fail_nomem;
65418+ *tmp = *mpnt;
65419+ tmp->vm_mm = mm;
65420+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
65421+ pol = mpol_dup(vma_policy(mpnt));
65422+ if (IS_ERR(pol))
65423+ goto fail_nomem_policy;
65424+ vma_set_policy(tmp, pol);
65425+ if (anon_vma_fork(tmp, mpnt))
65426+ goto fail_nomem_anon_vma_fork;
65427+ tmp->vm_flags &= ~VM_LOCKED;
65428+ tmp->vm_next = tmp->vm_prev = NULL;
65429+ tmp->vm_mirror = NULL;
65430+ file = tmp->vm_file;
65431+ if (file) {
65432+ struct inode *inode = file->f_path.dentry->d_inode;
65433+ struct address_space *mapping = file->f_mapping;
65434+
65435+ get_file(file);
65436+ if (tmp->vm_flags & VM_DENYWRITE)
65437+ atomic_dec(&inode->i_writecount);
65438+ mutex_lock(&mapping->i_mmap_mutex);
65439+ if (tmp->vm_flags & VM_SHARED)
65440+ mapping->i_mmap_writable++;
65441+ flush_dcache_mmap_lock(mapping);
65442+ /* insert tmp into the share list, just after mpnt */
65443+ vma_prio_tree_add(tmp, mpnt);
65444+ flush_dcache_mmap_unlock(mapping);
65445+ mutex_unlock(&mapping->i_mmap_mutex);
65446+ }
65447+
65448+ /*
65449+ * Clear hugetlb-related page reserves for children. This only
65450+ * affects MAP_PRIVATE mappings. Faults generated by the child
65451+ * are not guaranteed to succeed, even if read-only
65452+ */
65453+ if (is_vm_hugetlb_page(tmp))
65454+ reset_vma_resv_huge_pages(tmp);
65455+
65456+ return tmp;
65457+
65458+fail_nomem_anon_vma_fork:
65459+ mpol_put(pol);
65460+fail_nomem_policy:
65461+ kmem_cache_free(vm_area_cachep, tmp);
65462+fail_nomem:
65463+ vm_unacct_memory(charge);
65464+ return NULL;
65465+}
65466+
65467 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65468 {
65469 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
65470 struct rb_node **rb_link, *rb_parent;
65471 int retval;
65472- unsigned long charge;
65473- struct mempolicy *pol;
65474
65475 down_write(&oldmm->mmap_sem);
65476 flush_cache_dup_mm(oldmm);
65477@@ -328,8 +393,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65478 mm->locked_vm = 0;
65479 mm->mmap = NULL;
65480 mm->mmap_cache = NULL;
65481- mm->free_area_cache = oldmm->mmap_base;
65482- mm->cached_hole_size = ~0UL;
65483+ mm->free_area_cache = oldmm->free_area_cache;
65484+ mm->cached_hole_size = oldmm->cached_hole_size;
65485 mm->map_count = 0;
65486 cpumask_clear(mm_cpumask(mm));
65487 mm->mm_rb = RB_ROOT;
65488@@ -345,8 +410,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65489
65490 prev = NULL;
65491 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
65492- struct file *file;
65493-
65494 if (mpnt->vm_flags & VM_DONTCOPY) {
65495 long pages = vma_pages(mpnt);
65496 mm->total_vm -= pages;
65497@@ -354,54 +417,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65498 -pages);
65499 continue;
65500 }
65501- charge = 0;
65502- if (mpnt->vm_flags & VM_ACCOUNT) {
65503- unsigned long len;
65504- len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
65505- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
65506- goto fail_nomem;
65507- charge = len;
65508+ tmp = dup_vma(mm, oldmm, mpnt);
65509+ if (!tmp) {
65510+ retval = -ENOMEM;
65511+ goto out;
65512 }
65513- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
65514- if (!tmp)
65515- goto fail_nomem;
65516- *tmp = *mpnt;
65517- INIT_LIST_HEAD(&tmp->anon_vma_chain);
65518- pol = mpol_dup(vma_policy(mpnt));
65519- retval = PTR_ERR(pol);
65520- if (IS_ERR(pol))
65521- goto fail_nomem_policy;
65522- vma_set_policy(tmp, pol);
65523- tmp->vm_mm = mm;
65524- if (anon_vma_fork(tmp, mpnt))
65525- goto fail_nomem_anon_vma_fork;
65526- tmp->vm_flags &= ~VM_LOCKED;
65527- tmp->vm_next = tmp->vm_prev = NULL;
65528- file = tmp->vm_file;
65529- if (file) {
65530- struct inode *inode = file->f_path.dentry->d_inode;
65531- struct address_space *mapping = file->f_mapping;
65532-
65533- get_file(file);
65534- if (tmp->vm_flags & VM_DENYWRITE)
65535- atomic_dec(&inode->i_writecount);
65536- mutex_lock(&mapping->i_mmap_mutex);
65537- if (tmp->vm_flags & VM_SHARED)
65538- mapping->i_mmap_writable++;
65539- flush_dcache_mmap_lock(mapping);
65540- /* insert tmp into the share list, just after mpnt */
65541- vma_prio_tree_add(tmp, mpnt);
65542- flush_dcache_mmap_unlock(mapping);
65543- mutex_unlock(&mapping->i_mmap_mutex);
65544- }
65545-
65546- /*
65547- * Clear hugetlb-related page reserves for children. This only
65548- * affects MAP_PRIVATE mappings. Faults generated by the child
65549- * are not guaranteed to succeed, even if read-only
65550- */
65551- if (is_vm_hugetlb_page(tmp))
65552- reset_vma_resv_huge_pages(tmp);
65553
65554 /*
65555 * Link in the new vma and copy the page table entries.
65556@@ -424,6 +444,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65557 if (retval)
65558 goto out;
65559 }
65560+
65561+#ifdef CONFIG_PAX_SEGMEXEC
65562+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
65563+ struct vm_area_struct *mpnt_m;
65564+
65565+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
65566+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
65567+
65568+ if (!mpnt->vm_mirror)
65569+ continue;
65570+
65571+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
65572+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
65573+ mpnt->vm_mirror = mpnt_m;
65574+ } else {
65575+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
65576+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
65577+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
65578+ mpnt->vm_mirror->vm_mirror = mpnt;
65579+ }
65580+ }
65581+ BUG_ON(mpnt_m);
65582+ }
65583+#endif
65584+
65585 /* a new mm has just been created */
65586 arch_dup_mmap(oldmm, mm);
65587 retval = 0;
65588@@ -432,14 +477,6 @@ out:
65589 flush_tlb_mm(oldmm);
65590 up_write(&oldmm->mmap_sem);
65591 return retval;
65592-fail_nomem_anon_vma_fork:
65593- mpol_put(pol);
65594-fail_nomem_policy:
65595- kmem_cache_free(vm_area_cachep, tmp);
65596-fail_nomem:
65597- retval = -ENOMEM;
65598- vm_unacct_memory(charge);
65599- goto out;
65600 }
65601
65602 static inline int mm_alloc_pgd(struct mm_struct *mm)
65603@@ -676,8 +713,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
65604 return ERR_PTR(err);
65605
65606 mm = get_task_mm(task);
65607- if (mm && mm != current->mm &&
65608- !ptrace_may_access(task, mode)) {
65609+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
65610+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
65611 mmput(mm);
65612 mm = ERR_PTR(-EACCES);
65613 }
65614@@ -899,13 +936,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
65615 spin_unlock(&fs->lock);
65616 return -EAGAIN;
65617 }
65618- fs->users++;
65619+ atomic_inc(&fs->users);
65620 spin_unlock(&fs->lock);
65621 return 0;
65622 }
65623 tsk->fs = copy_fs_struct(fs);
65624 if (!tsk->fs)
65625 return -ENOMEM;
65626+ gr_set_chroot_entries(tsk, &tsk->fs->root);
65627 return 0;
65628 }
65629
65630@@ -1172,6 +1210,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
65631 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
65632 #endif
65633 retval = -EAGAIN;
65634+
65635+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
65636+
65637 if (atomic_read(&p->real_cred->user->processes) >=
65638 task_rlimit(p, RLIMIT_NPROC)) {
65639 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
65640@@ -1328,6 +1369,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
65641 if (clone_flags & CLONE_THREAD)
65642 p->tgid = current->tgid;
65643
65644+ gr_copy_label(p);
65645+
65646 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
65647 /*
65648 * Clear TID on mm_release()?
65649@@ -1502,6 +1545,8 @@ bad_fork_cleanup_count:
65650 bad_fork_free:
65651 free_task(p);
65652 fork_out:
65653+ gr_log_forkfail(retval);
65654+
65655 return ERR_PTR(retval);
65656 }
65657
65658@@ -1602,6 +1647,8 @@ long do_fork(unsigned long clone_flags,
65659 if (clone_flags & CLONE_PARENT_SETTID)
65660 put_user(nr, parent_tidptr);
65661
65662+ gr_handle_brute_check();
65663+
65664 if (clone_flags & CLONE_VFORK) {
65665 p->vfork_done = &vfork;
65666 init_completion(&vfork);
65667@@ -1700,7 +1747,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
65668 return 0;
65669
65670 /* don't need lock here; in the worst case we'll do useless copy */
65671- if (fs->users == 1)
65672+ if (atomic_read(&fs->users) == 1)
65673 return 0;
65674
65675 *new_fsp = copy_fs_struct(fs);
65676@@ -1789,7 +1836,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
65677 fs = current->fs;
65678 spin_lock(&fs->lock);
65679 current->fs = new_fs;
65680- if (--fs->users)
65681+ gr_set_chroot_entries(current, &current->fs->root);
65682+ if (atomic_dec_return(&fs->users))
65683 new_fs = NULL;
65684 else
65685 new_fs = fs;
65686diff --git a/kernel/futex.c b/kernel/futex.c
65687index e2b0fb9..db818ac 100644
65688--- a/kernel/futex.c
65689+++ b/kernel/futex.c
65690@@ -54,6 +54,7 @@
65691 #include <linux/mount.h>
65692 #include <linux/pagemap.h>
65693 #include <linux/syscalls.h>
65694+#include <linux/ptrace.h>
65695 #include <linux/signal.h>
65696 #include <linux/export.h>
65697 #include <linux/magic.h>
65698@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
65699 struct page *page, *page_head;
65700 int err, ro = 0;
65701
65702+#ifdef CONFIG_PAX_SEGMEXEC
65703+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
65704+ return -EFAULT;
65705+#endif
65706+
65707 /*
65708 * The futex address must be "naturally" aligned.
65709 */
65710@@ -2711,6 +2717,7 @@ static int __init futex_init(void)
65711 {
65712 u32 curval;
65713 int i;
65714+ mm_segment_t oldfs;
65715
65716 /*
65717 * This will fail and we want it. Some arch implementations do
65718@@ -2722,8 +2729,11 @@ static int __init futex_init(void)
65719 * implementation, the non-functional ones will return
65720 * -ENOSYS.
65721 */
65722+ oldfs = get_fs();
65723+ set_fs(USER_DS);
65724 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
65725 futex_cmpxchg_enabled = 1;
65726+ set_fs(oldfs);
65727
65728 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
65729 plist_head_init(&futex_queues[i].chain);
65730diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
65731index 9b22d03..6295b62 100644
65732--- a/kernel/gcov/base.c
65733+++ b/kernel/gcov/base.c
65734@@ -102,11 +102,6 @@ void gcov_enable_events(void)
65735 }
65736
65737 #ifdef CONFIG_MODULES
65738-static inline int within(void *addr, void *start, unsigned long size)
65739-{
65740- return ((addr >= start) && (addr < start + size));
65741-}
65742-
65743 /* Update list and generate events when modules are unloaded. */
65744 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
65745 void *data)
65746@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
65747 prev = NULL;
65748 /* Remove entries located in module from linked list. */
65749 for (info = gcov_info_head; info; info = info->next) {
65750- if (within(info, mod->module_core, mod->core_size)) {
65751+ if (within_module_core_rw((unsigned long)info, mod)) {
65752 if (prev)
65753 prev->next = info->next;
65754 else
65755diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
65756index ae34bf5..4e2f3d0 100644
65757--- a/kernel/hrtimer.c
65758+++ b/kernel/hrtimer.c
65759@@ -1393,7 +1393,7 @@ void hrtimer_peek_ahead_timers(void)
65760 local_irq_restore(flags);
65761 }
65762
65763-static void run_hrtimer_softirq(struct softirq_action *h)
65764+static void run_hrtimer_softirq(void)
65765 {
65766 hrtimer_peek_ahead_timers();
65767 }
65768diff --git a/kernel/jump_label.c b/kernel/jump_label.c
65769index 4304919..408c4c0 100644
65770--- a/kernel/jump_label.c
65771+++ b/kernel/jump_label.c
65772@@ -13,6 +13,7 @@
65773 #include <linux/sort.h>
65774 #include <linux/err.h>
65775 #include <linux/static_key.h>
65776+#include <linux/mm.h>
65777
65778 #ifdef HAVE_JUMP_LABEL
65779
65780@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
65781
65782 size = (((unsigned long)stop - (unsigned long)start)
65783 / sizeof(struct jump_entry));
65784+ pax_open_kernel();
65785 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
65786+ pax_close_kernel();
65787 }
65788
65789 static void jump_label_update(struct static_key *key, int enable);
65790@@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
65791 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
65792 struct jump_entry *iter;
65793
65794+ pax_open_kernel();
65795 for (iter = iter_start; iter < iter_stop; iter++) {
65796 if (within_module_init(iter->code, mod))
65797 iter->code = 0;
65798 }
65799+ pax_close_kernel();
65800 }
65801
65802 static int
65803diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
65804index 079f1d3..a407562 100644
65805--- a/kernel/kallsyms.c
65806+++ b/kernel/kallsyms.c
65807@@ -11,6 +11,9 @@
65808 * Changed the compression method from stem compression to "table lookup"
65809 * compression (see scripts/kallsyms.c for a more complete description)
65810 */
65811+#ifdef CONFIG_GRKERNSEC_HIDESYM
65812+#define __INCLUDED_BY_HIDESYM 1
65813+#endif
65814 #include <linux/kallsyms.h>
65815 #include <linux/module.h>
65816 #include <linux/init.h>
65817@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
65818
65819 static inline int is_kernel_inittext(unsigned long addr)
65820 {
65821+ if (system_state != SYSTEM_BOOTING)
65822+ return 0;
65823+
65824 if (addr >= (unsigned long)_sinittext
65825 && addr <= (unsigned long)_einittext)
65826 return 1;
65827 return 0;
65828 }
65829
65830+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65831+#ifdef CONFIG_MODULES
65832+static inline int is_module_text(unsigned long addr)
65833+{
65834+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
65835+ return 1;
65836+
65837+ addr = ktla_ktva(addr);
65838+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
65839+}
65840+#else
65841+static inline int is_module_text(unsigned long addr)
65842+{
65843+ return 0;
65844+}
65845+#endif
65846+#endif
65847+
65848 static inline int is_kernel_text(unsigned long addr)
65849 {
65850 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
65851@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
65852
65853 static inline int is_kernel(unsigned long addr)
65854 {
65855+
65856+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65857+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
65858+ return 1;
65859+
65860+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
65861+#else
65862 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
65863+#endif
65864+
65865 return 1;
65866 return in_gate_area_no_mm(addr);
65867 }
65868
65869 static int is_ksym_addr(unsigned long addr)
65870 {
65871+
65872+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65873+ if (is_module_text(addr))
65874+ return 0;
65875+#endif
65876+
65877 if (all_var)
65878 return is_kernel(addr);
65879
65880@@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
65881
65882 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
65883 {
65884- iter->name[0] = '\0';
65885 iter->nameoff = get_symbol_offset(new_pos);
65886 iter->pos = new_pos;
65887 }
65888@@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
65889 {
65890 struct kallsym_iter *iter = m->private;
65891
65892+#ifdef CONFIG_GRKERNSEC_HIDESYM
65893+ if (current_uid())
65894+ return 0;
65895+#endif
65896+
65897 /* Some debugging symbols have no name. Ignore them. */
65898 if (!iter->name[0])
65899 return 0;
65900@@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
65901 struct kallsym_iter *iter;
65902 int ret;
65903
65904- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
65905+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
65906 if (!iter)
65907 return -ENOMEM;
65908 reset_iter(iter, 0);
65909diff --git a/kernel/kexec.c b/kernel/kexec.c
65910index 4e2e472..cd0c7ae 100644
65911--- a/kernel/kexec.c
65912+++ b/kernel/kexec.c
65913@@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
65914 unsigned long flags)
65915 {
65916 struct compat_kexec_segment in;
65917- struct kexec_segment out, __user *ksegments;
65918+ struct kexec_segment out;
65919+ struct kexec_segment __user *ksegments;
65920 unsigned long i, result;
65921
65922 /* Don't allow clients that don't understand the native
65923diff --git a/kernel/kmod.c b/kernel/kmod.c
65924index 05698a7..a4c1e3a 100644
65925--- a/kernel/kmod.c
65926+++ b/kernel/kmod.c
65927@@ -66,7 +66,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
65928 kfree(info->argv);
65929 }
65930
65931-static int call_modprobe(char *module_name, int wait)
65932+static int call_modprobe(char *module_name, char *module_param, int wait)
65933 {
65934 static char *envp[] = {
65935 "HOME=/",
65936@@ -75,7 +75,7 @@ static int call_modprobe(char *module_name, int wait)
65937 NULL
65938 };
65939
65940- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
65941+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
65942 if (!argv)
65943 goto out;
65944
65945@@ -87,7 +87,8 @@ static int call_modprobe(char *module_name, int wait)
65946 argv[1] = "-q";
65947 argv[2] = "--";
65948 argv[3] = module_name; /* check free_modprobe_argv() */
65949- argv[4] = NULL;
65950+ argv[4] = module_param;
65951+ argv[5] = NULL;
65952
65953 return call_usermodehelper_fns(modprobe_path, argv, envp,
65954 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
65955@@ -112,9 +113,8 @@ out:
65956 * If module auto-loading support is disabled then this function
65957 * becomes a no-operation.
65958 */
65959-int __request_module(bool wait, const char *fmt, ...)
65960+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
65961 {
65962- va_list args;
65963 char module_name[MODULE_NAME_LEN];
65964 unsigned int max_modprobes;
65965 int ret;
65966@@ -122,9 +122,7 @@ int __request_module(bool wait, const char *fmt, ...)
65967 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
65968 static int kmod_loop_msg;
65969
65970- va_start(args, fmt);
65971- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
65972- va_end(args);
65973+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
65974 if (ret >= MODULE_NAME_LEN)
65975 return -ENAMETOOLONG;
65976
65977@@ -132,6 +130,20 @@ int __request_module(bool wait, const char *fmt, ...)
65978 if (ret)
65979 return ret;
65980
65981+#ifdef CONFIG_GRKERNSEC_MODHARDEN
65982+ if (!current_uid()) {
65983+ /* hack to workaround consolekit/udisks stupidity */
65984+ read_lock(&tasklist_lock);
65985+ if (!strcmp(current->comm, "mount") &&
65986+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
65987+ read_unlock(&tasklist_lock);
65988+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
65989+ return -EPERM;
65990+ }
65991+ read_unlock(&tasklist_lock);
65992+ }
65993+#endif
65994+
65995 /* If modprobe needs a service that is in a module, we get a recursive
65996 * loop. Limit the number of running kmod threads to max_threads/2 or
65997 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
65998@@ -160,11 +172,52 @@ int __request_module(bool wait, const char *fmt, ...)
65999
66000 trace_module_request(module_name, wait, _RET_IP_);
66001
66002- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
66003+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
66004
66005 atomic_dec(&kmod_concurrent);
66006 return ret;
66007 }
66008+
66009+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
66010+{
66011+ va_list args;
66012+ int ret;
66013+
66014+ va_start(args, fmt);
66015+ ret = ____request_module(wait, module_param, fmt, args);
66016+ va_end(args);
66017+
66018+ return ret;
66019+}
66020+
66021+int __request_module(bool wait, const char *fmt, ...)
66022+{
66023+ va_list args;
66024+ int ret;
66025+
66026+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66027+ if (current_uid()) {
66028+ char module_param[MODULE_NAME_LEN];
66029+
66030+ memset(module_param, 0, sizeof(module_param));
66031+
66032+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
66033+
66034+ va_start(args, fmt);
66035+ ret = ____request_module(wait, module_param, fmt, args);
66036+ va_end(args);
66037+
66038+ return ret;
66039+ }
66040+#endif
66041+
66042+ va_start(args, fmt);
66043+ ret = ____request_module(wait, NULL, fmt, args);
66044+ va_end(args);
66045+
66046+ return ret;
66047+}
66048+
66049 EXPORT_SYMBOL(__request_module);
66050 #endif /* CONFIG_MODULES */
66051
66052@@ -267,7 +320,7 @@ static int wait_for_helper(void *data)
66053 *
66054 * Thus the __user pointer cast is valid here.
66055 */
66056- sys_wait4(pid, (int __user *)&ret, 0, NULL);
66057+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
66058
66059 /*
66060 * If ret is 0, either ____call_usermodehelper failed and the
66061diff --git a/kernel/kprobes.c b/kernel/kprobes.c
66062index c62b854..cb67968 100644
66063--- a/kernel/kprobes.c
66064+++ b/kernel/kprobes.c
66065@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
66066 * kernel image and loaded module images reside. This is required
66067 * so x86_64 can correctly handle the %rip-relative fixups.
66068 */
66069- kip->insns = module_alloc(PAGE_SIZE);
66070+ kip->insns = module_alloc_exec(PAGE_SIZE);
66071 if (!kip->insns) {
66072 kfree(kip);
66073 return NULL;
66074@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
66075 */
66076 if (!list_is_singular(&kip->list)) {
66077 list_del(&kip->list);
66078- module_free(NULL, kip->insns);
66079+ module_free_exec(NULL, kip->insns);
66080 kfree(kip);
66081 }
66082 return 1;
66083@@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
66084 {
66085 int i, err = 0;
66086 unsigned long offset = 0, size = 0;
66087- char *modname, namebuf[128];
66088+ char *modname, namebuf[KSYM_NAME_LEN];
66089 const char *symbol_name;
66090 void *addr;
66091 struct kprobe_blackpoint *kb;
66092@@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
66093 const char *sym = NULL;
66094 unsigned int i = *(loff_t *) v;
66095 unsigned long offset = 0;
66096- char *modname, namebuf[128];
66097+ char *modname, namebuf[KSYM_NAME_LEN];
66098
66099 head = &kprobe_table[i];
66100 preempt_disable();
66101diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
66102index 4e316e1..5501eef 100644
66103--- a/kernel/ksysfs.c
66104+++ b/kernel/ksysfs.c
66105@@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
66106 {
66107 if (count+1 > UEVENT_HELPER_PATH_LEN)
66108 return -ENOENT;
66109+ if (!capable(CAP_SYS_ADMIN))
66110+ return -EPERM;
66111 memcpy(uevent_helper, buf, count);
66112 uevent_helper[count] = '\0';
66113 if (count && uevent_helper[count-1] == '\n')
66114diff --git a/kernel/lockdep.c b/kernel/lockdep.c
66115index ea9ee45..67ebc8f 100644
66116--- a/kernel/lockdep.c
66117+++ b/kernel/lockdep.c
66118@@ -590,6 +590,10 @@ static int static_obj(void *obj)
66119 end = (unsigned long) &_end,
66120 addr = (unsigned long) obj;
66121
66122+#ifdef CONFIG_PAX_KERNEXEC
66123+ start = ktla_ktva(start);
66124+#endif
66125+
66126 /*
66127 * static variable?
66128 */
66129@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
66130 if (!static_obj(lock->key)) {
66131 debug_locks_off();
66132 printk("INFO: trying to register non-static key.\n");
66133+ printk("lock:%pS key:%pS.\n", lock, lock->key);
66134 printk("the code is fine but needs lockdep annotation.\n");
66135 printk("turning off the locking correctness validator.\n");
66136 dump_stack();
66137@@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
66138 if (!class)
66139 return 0;
66140 }
66141- atomic_inc((atomic_t *)&class->ops);
66142+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
66143 if (very_verbose(class)) {
66144 printk("\nacquire class [%p] %s", class->key, class->name);
66145 if (class->name_version > 1)
66146diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
66147index 91c32a0..b2c71c5 100644
66148--- a/kernel/lockdep_proc.c
66149+++ b/kernel/lockdep_proc.c
66150@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
66151
66152 static void print_name(struct seq_file *m, struct lock_class *class)
66153 {
66154- char str[128];
66155+ char str[KSYM_NAME_LEN];
66156 const char *name = class->name;
66157
66158 if (!name) {
66159diff --git a/kernel/module.c b/kernel/module.c
66160index 78ac6ec..e87db0e 100644
66161--- a/kernel/module.c
66162+++ b/kernel/module.c
66163@@ -58,6 +58,7 @@
66164 #include <linux/jump_label.h>
66165 #include <linux/pfn.h>
66166 #include <linux/bsearch.h>
66167+#include <linux/grsecurity.h>
66168
66169 #define CREATE_TRACE_POINTS
66170 #include <trace/events/module.h>
66171@@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
66172
66173 /* Bounds of module allocation, for speeding __module_address.
66174 * Protected by module_mutex. */
66175-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
66176+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
66177+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
66178
66179 int register_module_notifier(struct notifier_block * nb)
66180 {
66181@@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66182 return true;
66183
66184 list_for_each_entry_rcu(mod, &modules, list) {
66185- struct symsearch arr[] = {
66186+ struct symsearch modarr[] = {
66187 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
66188 NOT_GPL_ONLY, false },
66189 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
66190@@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66191 #endif
66192 };
66193
66194- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
66195+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
66196 return true;
66197 }
66198 return false;
66199@@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
66200 static int percpu_modalloc(struct module *mod,
66201 unsigned long size, unsigned long align)
66202 {
66203- if (align > PAGE_SIZE) {
66204+ if (align-1 >= PAGE_SIZE) {
66205 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
66206 mod->name, align, PAGE_SIZE);
66207 align = PAGE_SIZE;
66208@@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
66209 static ssize_t show_coresize(struct module_attribute *mattr,
66210 struct module_kobject *mk, char *buffer)
66211 {
66212- return sprintf(buffer, "%u\n", mk->mod->core_size);
66213+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
66214 }
66215
66216 static struct module_attribute modinfo_coresize =
66217@@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
66218 static ssize_t show_initsize(struct module_attribute *mattr,
66219 struct module_kobject *mk, char *buffer)
66220 {
66221- return sprintf(buffer, "%u\n", mk->mod->init_size);
66222+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
66223 }
66224
66225 static struct module_attribute modinfo_initsize =
66226@@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
66227 */
66228 #ifdef CONFIG_SYSFS
66229
66230-#ifdef CONFIG_KALLSYMS
66231+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66232 static inline bool sect_empty(const Elf_Shdr *sect)
66233 {
66234 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
66235@@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
66236
66237 static void unset_module_core_ro_nx(struct module *mod)
66238 {
66239- set_page_attributes(mod->module_core + mod->core_text_size,
66240- mod->module_core + mod->core_size,
66241+ set_page_attributes(mod->module_core_rw,
66242+ mod->module_core_rw + mod->core_size_rw,
66243 set_memory_x);
66244- set_page_attributes(mod->module_core,
66245- mod->module_core + mod->core_ro_size,
66246+ set_page_attributes(mod->module_core_rx,
66247+ mod->module_core_rx + mod->core_size_rx,
66248 set_memory_rw);
66249 }
66250
66251 static void unset_module_init_ro_nx(struct module *mod)
66252 {
66253- set_page_attributes(mod->module_init + mod->init_text_size,
66254- mod->module_init + mod->init_size,
66255+ set_page_attributes(mod->module_init_rw,
66256+ mod->module_init_rw + mod->init_size_rw,
66257 set_memory_x);
66258- set_page_attributes(mod->module_init,
66259- mod->module_init + mod->init_ro_size,
66260+ set_page_attributes(mod->module_init_rx,
66261+ mod->module_init_rx + mod->init_size_rx,
66262 set_memory_rw);
66263 }
66264
66265@@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
66266
66267 mutex_lock(&module_mutex);
66268 list_for_each_entry_rcu(mod, &modules, list) {
66269- if ((mod->module_core) && (mod->core_text_size)) {
66270- set_page_attributes(mod->module_core,
66271- mod->module_core + mod->core_text_size,
66272+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
66273+ set_page_attributes(mod->module_core_rx,
66274+ mod->module_core_rx + mod->core_size_rx,
66275 set_memory_rw);
66276 }
66277- if ((mod->module_init) && (mod->init_text_size)) {
66278- set_page_attributes(mod->module_init,
66279- mod->module_init + mod->init_text_size,
66280+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
66281+ set_page_attributes(mod->module_init_rx,
66282+ mod->module_init_rx + mod->init_size_rx,
66283 set_memory_rw);
66284 }
66285 }
66286@@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
66287
66288 mutex_lock(&module_mutex);
66289 list_for_each_entry_rcu(mod, &modules, list) {
66290- if ((mod->module_core) && (mod->core_text_size)) {
66291- set_page_attributes(mod->module_core,
66292- mod->module_core + mod->core_text_size,
66293+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
66294+ set_page_attributes(mod->module_core_rx,
66295+ mod->module_core_rx + mod->core_size_rx,
66296 set_memory_ro);
66297 }
66298- if ((mod->module_init) && (mod->init_text_size)) {
66299- set_page_attributes(mod->module_init,
66300- mod->module_init + mod->init_text_size,
66301+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
66302+ set_page_attributes(mod->module_init_rx,
66303+ mod->module_init_rx + mod->init_size_rx,
66304 set_memory_ro);
66305 }
66306 }
66307@@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
66308
66309 /* This may be NULL, but that's OK */
66310 unset_module_init_ro_nx(mod);
66311- module_free(mod, mod->module_init);
66312+ module_free(mod, mod->module_init_rw);
66313+ module_free_exec(mod, mod->module_init_rx);
66314 kfree(mod->args);
66315 percpu_modfree(mod);
66316
66317 /* Free lock-classes: */
66318- lockdep_free_key_range(mod->module_core, mod->core_size);
66319+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
66320+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
66321
66322 /* Finally, free the core (containing the module structure) */
66323 unset_module_core_ro_nx(mod);
66324- module_free(mod, mod->module_core);
66325+ module_free_exec(mod, mod->module_core_rx);
66326+ module_free(mod, mod->module_core_rw);
66327
66328 #ifdef CONFIG_MPU
66329 update_protections(current->mm);
66330@@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66331 int ret = 0;
66332 const struct kernel_symbol *ksym;
66333
66334+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66335+ int is_fs_load = 0;
66336+ int register_filesystem_found = 0;
66337+ char *p;
66338+
66339+ p = strstr(mod->args, "grsec_modharden_fs");
66340+ if (p) {
66341+ char *endptr = p + strlen("grsec_modharden_fs");
66342+ /* copy \0 as well */
66343+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
66344+ is_fs_load = 1;
66345+ }
66346+#endif
66347+
66348 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
66349 const char *name = info->strtab + sym[i].st_name;
66350
66351+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66352+ /* it's a real shame this will never get ripped and copied
66353+ upstream! ;(
66354+ */
66355+ if (is_fs_load && !strcmp(name, "register_filesystem"))
66356+ register_filesystem_found = 1;
66357+#endif
66358+
66359 switch (sym[i].st_shndx) {
66360 case SHN_COMMON:
66361 /* We compiled with -fno-common. These are not
66362@@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66363 ksym = resolve_symbol_wait(mod, info, name);
66364 /* Ok if resolved. */
66365 if (ksym && !IS_ERR(ksym)) {
66366+ pax_open_kernel();
66367 sym[i].st_value = ksym->value;
66368+ pax_close_kernel();
66369 break;
66370 }
66371
66372@@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66373 secbase = (unsigned long)mod_percpu(mod);
66374 else
66375 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
66376+ pax_open_kernel();
66377 sym[i].st_value += secbase;
66378+ pax_close_kernel();
66379 break;
66380 }
66381 }
66382
66383+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66384+ if (is_fs_load && !register_filesystem_found) {
66385+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
66386+ ret = -EPERM;
66387+ }
66388+#endif
66389+
66390 return ret;
66391 }
66392
66393@@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
66394 || s->sh_entsize != ~0UL
66395 || strstarts(sname, ".init"))
66396 continue;
66397- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
66398+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
66399+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
66400+ else
66401+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
66402 pr_debug("\t%s\n", sname);
66403 }
66404- switch (m) {
66405- case 0: /* executable */
66406- mod->core_size = debug_align(mod->core_size);
66407- mod->core_text_size = mod->core_size;
66408- break;
66409- case 1: /* RO: text and ro-data */
66410- mod->core_size = debug_align(mod->core_size);
66411- mod->core_ro_size = mod->core_size;
66412- break;
66413- case 3: /* whole core */
66414- mod->core_size = debug_align(mod->core_size);
66415- break;
66416- }
66417 }
66418
66419 pr_debug("Init section allocation order:\n");
66420@@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
66421 || s->sh_entsize != ~0UL
66422 || !strstarts(sname, ".init"))
66423 continue;
66424- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
66425- | INIT_OFFSET_MASK);
66426+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
66427+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
66428+ else
66429+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
66430+ s->sh_entsize |= INIT_OFFSET_MASK;
66431 pr_debug("\t%s\n", sname);
66432 }
66433- switch (m) {
66434- case 0: /* executable */
66435- mod->init_size = debug_align(mod->init_size);
66436- mod->init_text_size = mod->init_size;
66437- break;
66438- case 1: /* RO: text and ro-data */
66439- mod->init_size = debug_align(mod->init_size);
66440- mod->init_ro_size = mod->init_size;
66441- break;
66442- case 3: /* whole init */
66443- mod->init_size = debug_align(mod->init_size);
66444- break;
66445- }
66446 }
66447 }
66448
66449@@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
66450
66451 /* Put symbol section at end of init part of module. */
66452 symsect->sh_flags |= SHF_ALLOC;
66453- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
66454+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
66455 info->index.sym) | INIT_OFFSET_MASK;
66456 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
66457
66458@@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
66459 }
66460
66461 /* Append room for core symbols at end of core part. */
66462- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
66463- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
66464- mod->core_size += strtab_size;
66465+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
66466+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
66467+ mod->core_size_rx += strtab_size;
66468
66469 /* Put string table section at end of init part of module. */
66470 strsect->sh_flags |= SHF_ALLOC;
66471- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
66472+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
66473 info->index.str) | INIT_OFFSET_MASK;
66474 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
66475 }
66476@@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
66477 /* Make sure we get permanent strtab: don't use info->strtab. */
66478 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
66479
66480+ pax_open_kernel();
66481+
66482 /* Set types up while we still have access to sections. */
66483 for (i = 0; i < mod->num_symtab; i++)
66484 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
66485
66486- mod->core_symtab = dst = mod->module_core + info->symoffs;
66487- mod->core_strtab = s = mod->module_core + info->stroffs;
66488+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
66489+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
66490 src = mod->symtab;
66491 *dst = *src;
66492 *s++ = 0;
66493@@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
66494 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
66495 }
66496 mod->core_num_syms = ndst;
66497+
66498+ pax_close_kernel();
66499 }
66500 #else
66501 static inline void layout_symtab(struct module *mod, struct load_info *info)
66502@@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
66503 return size == 0 ? NULL : vmalloc_exec(size);
66504 }
66505
66506-static void *module_alloc_update_bounds(unsigned long size)
66507+static void *module_alloc_update_bounds_rw(unsigned long size)
66508 {
66509 void *ret = module_alloc(size);
66510
66511 if (ret) {
66512 mutex_lock(&module_mutex);
66513 /* Update module bounds. */
66514- if ((unsigned long)ret < module_addr_min)
66515- module_addr_min = (unsigned long)ret;
66516- if ((unsigned long)ret + size > module_addr_max)
66517- module_addr_max = (unsigned long)ret + size;
66518+ if ((unsigned long)ret < module_addr_min_rw)
66519+ module_addr_min_rw = (unsigned long)ret;
66520+ if ((unsigned long)ret + size > module_addr_max_rw)
66521+ module_addr_max_rw = (unsigned long)ret + size;
66522+ mutex_unlock(&module_mutex);
66523+ }
66524+ return ret;
66525+}
66526+
66527+static void *module_alloc_update_bounds_rx(unsigned long size)
66528+{
66529+ void *ret = module_alloc_exec(size);
66530+
66531+ if (ret) {
66532+ mutex_lock(&module_mutex);
66533+ /* Update module bounds. */
66534+ if ((unsigned long)ret < module_addr_min_rx)
66535+ module_addr_min_rx = (unsigned long)ret;
66536+ if ((unsigned long)ret + size > module_addr_max_rx)
66537+ module_addr_max_rx = (unsigned long)ret + size;
66538 mutex_unlock(&module_mutex);
66539 }
66540 return ret;
66541@@ -2543,8 +2581,14 @@ static struct module *setup_load_info(struct load_info *info)
66542 static int check_modinfo(struct module *mod, struct load_info *info)
66543 {
66544 const char *modmagic = get_modinfo(info, "vermagic");
66545+ const char *license = get_modinfo(info, "license");
66546 int err;
66547
66548+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
66549+ if (!license || !license_is_gpl_compatible(license))
66550+ return -ENOEXEC;
66551+#endif
66552+
66553 /* This is allowed: modprobe --force will invalidate it. */
66554 if (!modmagic) {
66555 err = try_to_force_load(mod, "bad vermagic");
66556@@ -2567,7 +2611,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
66557 }
66558
66559 /* Set up license info based on the info section */
66560- set_license(mod, get_modinfo(info, "license"));
66561+ set_license(mod, license);
66562
66563 return 0;
66564 }
66565@@ -2661,7 +2705,7 @@ static int move_module(struct module *mod, struct load_info *info)
66566 void *ptr;
66567
66568 /* Do the allocs. */
66569- ptr = module_alloc_update_bounds(mod->core_size);
66570+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
66571 /*
66572 * The pointer to this block is stored in the module structure
66573 * which is inside the block. Just mark it as not being a
66574@@ -2671,23 +2715,50 @@ static int move_module(struct module *mod, struct load_info *info)
66575 if (!ptr)
66576 return -ENOMEM;
66577
66578- memset(ptr, 0, mod->core_size);
66579- mod->module_core = ptr;
66580+ memset(ptr, 0, mod->core_size_rw);
66581+ mod->module_core_rw = ptr;
66582
66583- ptr = module_alloc_update_bounds(mod->init_size);
66584+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
66585 /*
66586 * The pointer to this block is stored in the module structure
66587 * which is inside the block. This block doesn't need to be
66588 * scanned as it contains data and code that will be freed
66589 * after the module is initialized.
66590 */
66591- kmemleak_ignore(ptr);
66592- if (!ptr && mod->init_size) {
66593- module_free(mod, mod->module_core);
66594+ kmemleak_not_leak(ptr);
66595+ if (!ptr && mod->init_size_rw) {
66596+ module_free(mod, mod->module_core_rw);
66597 return -ENOMEM;
66598 }
66599- memset(ptr, 0, mod->init_size);
66600- mod->module_init = ptr;
66601+ memset(ptr, 0, mod->init_size_rw);
66602+ mod->module_init_rw = ptr;
66603+
66604+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
66605+ kmemleak_not_leak(ptr);
66606+ if (!ptr) {
66607+ module_free(mod, mod->module_init_rw);
66608+ module_free(mod, mod->module_core_rw);
66609+ return -ENOMEM;
66610+ }
66611+
66612+ pax_open_kernel();
66613+ memset(ptr, 0, mod->core_size_rx);
66614+ pax_close_kernel();
66615+ mod->module_core_rx = ptr;
66616+
66617+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
66618+ kmemleak_not_leak(ptr);
66619+ if (!ptr && mod->init_size_rx) {
66620+ module_free_exec(mod, mod->module_core_rx);
66621+ module_free(mod, mod->module_init_rw);
66622+ module_free(mod, mod->module_core_rw);
66623+ return -ENOMEM;
66624+ }
66625+
66626+ pax_open_kernel();
66627+ memset(ptr, 0, mod->init_size_rx);
66628+ pax_close_kernel();
66629+ mod->module_init_rx = ptr;
66630
66631 /* Transfer each section which specifies SHF_ALLOC */
66632 pr_debug("final section addresses:\n");
66633@@ -2698,16 +2769,45 @@ static int move_module(struct module *mod, struct load_info *info)
66634 if (!(shdr->sh_flags & SHF_ALLOC))
66635 continue;
66636
66637- if (shdr->sh_entsize & INIT_OFFSET_MASK)
66638- dest = mod->module_init
66639- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66640- else
66641- dest = mod->module_core + shdr->sh_entsize;
66642+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
66643+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
66644+ dest = mod->module_init_rw
66645+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66646+ else
66647+ dest = mod->module_init_rx
66648+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66649+ } else {
66650+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
66651+ dest = mod->module_core_rw + shdr->sh_entsize;
66652+ else
66653+ dest = mod->module_core_rx + shdr->sh_entsize;
66654+ }
66655+
66656+ if (shdr->sh_type != SHT_NOBITS) {
66657+
66658+#ifdef CONFIG_PAX_KERNEXEC
66659+#ifdef CONFIG_X86_64
66660+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
66661+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
66662+#endif
66663+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
66664+ pax_open_kernel();
66665+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
66666+ pax_close_kernel();
66667+ } else
66668+#endif
66669
66670- if (shdr->sh_type != SHT_NOBITS)
66671 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
66672+ }
66673 /* Update sh_addr to point to copy in image. */
66674- shdr->sh_addr = (unsigned long)dest;
66675+
66676+#ifdef CONFIG_PAX_KERNEXEC
66677+ if (shdr->sh_flags & SHF_EXECINSTR)
66678+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
66679+ else
66680+#endif
66681+
66682+ shdr->sh_addr = (unsigned long)dest;
66683 pr_debug("\t0x%lx %s\n",
66684 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
66685 }
66686@@ -2758,12 +2858,12 @@ static void flush_module_icache(const struct module *mod)
66687 * Do it before processing of module parameters, so the module
66688 * can provide parameter accessor functions of its own.
66689 */
66690- if (mod->module_init)
66691- flush_icache_range((unsigned long)mod->module_init,
66692- (unsigned long)mod->module_init
66693- + mod->init_size);
66694- flush_icache_range((unsigned long)mod->module_core,
66695- (unsigned long)mod->module_core + mod->core_size);
66696+ if (mod->module_init_rx)
66697+ flush_icache_range((unsigned long)mod->module_init_rx,
66698+ (unsigned long)mod->module_init_rx
66699+ + mod->init_size_rx);
66700+ flush_icache_range((unsigned long)mod->module_core_rx,
66701+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
66702
66703 set_fs(old_fs);
66704 }
66705@@ -2833,8 +2933,10 @@ out:
66706 static void module_deallocate(struct module *mod, struct load_info *info)
66707 {
66708 percpu_modfree(mod);
66709- module_free(mod, mod->module_init);
66710- module_free(mod, mod->module_core);
66711+ module_free_exec(mod, mod->module_init_rx);
66712+ module_free_exec(mod, mod->module_core_rx);
66713+ module_free(mod, mod->module_init_rw);
66714+ module_free(mod, mod->module_core_rw);
66715 }
66716
66717 int __weak module_finalize(const Elf_Ehdr *hdr,
66718@@ -2898,9 +3000,38 @@ static struct module *load_module(void __user *umod,
66719 if (err)
66720 goto free_unload;
66721
66722+ /* Now copy in args */
66723+ mod->args = strndup_user(uargs, ~0UL >> 1);
66724+ if (IS_ERR(mod->args)) {
66725+ err = PTR_ERR(mod->args);
66726+ goto free_unload;
66727+ }
66728+
66729 /* Set up MODINFO_ATTR fields */
66730 setup_modinfo(mod, &info);
66731
66732+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66733+ {
66734+ char *p, *p2;
66735+
66736+ if (strstr(mod->args, "grsec_modharden_netdev")) {
66737+ 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);
66738+ err = -EPERM;
66739+ goto free_modinfo;
66740+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
66741+ p += strlen("grsec_modharden_normal");
66742+ p2 = strstr(p, "_");
66743+ if (p2) {
66744+ *p2 = '\0';
66745+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
66746+ *p2 = '_';
66747+ }
66748+ err = -EPERM;
66749+ goto free_modinfo;
66750+ }
66751+ }
66752+#endif
66753+
66754 /* Fix up syms, so that st_value is a pointer to location. */
66755 err = simplify_symbols(mod, &info);
66756 if (err < 0)
66757@@ -2916,13 +3047,6 @@ static struct module *load_module(void __user *umod,
66758
66759 flush_module_icache(mod);
66760
66761- /* Now copy in args */
66762- mod->args = strndup_user(uargs, ~0UL >> 1);
66763- if (IS_ERR(mod->args)) {
66764- err = PTR_ERR(mod->args);
66765- goto free_arch_cleanup;
66766- }
66767-
66768 /* Mark state as coming so strong_try_module_get() ignores us. */
66769 mod->state = MODULE_STATE_COMING;
66770
66771@@ -2980,11 +3104,10 @@ static struct module *load_module(void __user *umod,
66772 unlock:
66773 mutex_unlock(&module_mutex);
66774 synchronize_sched();
66775- kfree(mod->args);
66776- free_arch_cleanup:
66777 module_arch_cleanup(mod);
66778 free_modinfo:
66779 free_modinfo(mod);
66780+ kfree(mod->args);
66781 free_unload:
66782 module_unload_free(mod);
66783 free_module:
66784@@ -3025,16 +3148,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
66785 MODULE_STATE_COMING, mod);
66786
66787 /* Set RO and NX regions for core */
66788- set_section_ro_nx(mod->module_core,
66789- mod->core_text_size,
66790- mod->core_ro_size,
66791- mod->core_size);
66792+ set_section_ro_nx(mod->module_core_rx,
66793+ mod->core_size_rx,
66794+ mod->core_size_rx,
66795+ mod->core_size_rx);
66796
66797 /* Set RO and NX regions for init */
66798- set_section_ro_nx(mod->module_init,
66799- mod->init_text_size,
66800- mod->init_ro_size,
66801- mod->init_size);
66802+ set_section_ro_nx(mod->module_init_rx,
66803+ mod->init_size_rx,
66804+ mod->init_size_rx,
66805+ mod->init_size_rx);
66806
66807 do_mod_ctors(mod);
66808 /* Start the module */
66809@@ -3080,11 +3203,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
66810 mod->strtab = mod->core_strtab;
66811 #endif
66812 unset_module_init_ro_nx(mod);
66813- module_free(mod, mod->module_init);
66814- mod->module_init = NULL;
66815- mod->init_size = 0;
66816- mod->init_ro_size = 0;
66817- mod->init_text_size = 0;
66818+ module_free(mod, mod->module_init_rw);
66819+ module_free_exec(mod, mod->module_init_rx);
66820+ mod->module_init_rw = NULL;
66821+ mod->module_init_rx = NULL;
66822+ mod->init_size_rw = 0;
66823+ mod->init_size_rx = 0;
66824 mutex_unlock(&module_mutex);
66825
66826 return 0;
66827@@ -3115,10 +3239,16 @@ static const char *get_ksymbol(struct module *mod,
66828 unsigned long nextval;
66829
66830 /* At worse, next value is at end of module */
66831- if (within_module_init(addr, mod))
66832- nextval = (unsigned long)mod->module_init+mod->init_text_size;
66833+ if (within_module_init_rx(addr, mod))
66834+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
66835+ else if (within_module_init_rw(addr, mod))
66836+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
66837+ else if (within_module_core_rx(addr, mod))
66838+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
66839+ else if (within_module_core_rw(addr, mod))
66840+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
66841 else
66842- nextval = (unsigned long)mod->module_core+mod->core_text_size;
66843+ return NULL;
66844
66845 /* Scan for closest preceding symbol, and next symbol. (ELF
66846 starts real symbols at 1). */
66847@@ -3353,7 +3483,7 @@ static int m_show(struct seq_file *m, void *p)
66848 char buf[8];
66849
66850 seq_printf(m, "%s %u",
66851- mod->name, mod->init_size + mod->core_size);
66852+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
66853 print_unload_info(m, mod);
66854
66855 /* Informative for users. */
66856@@ -3362,7 +3492,7 @@ static int m_show(struct seq_file *m, void *p)
66857 mod->state == MODULE_STATE_COMING ? "Loading":
66858 "Live");
66859 /* Used by oprofile and other similar tools. */
66860- seq_printf(m, " 0x%pK", mod->module_core);
66861+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
66862
66863 /* Taints info */
66864 if (mod->taints)
66865@@ -3398,7 +3528,17 @@ static const struct file_operations proc_modules_operations = {
66866
66867 static int __init proc_modules_init(void)
66868 {
66869+#ifndef CONFIG_GRKERNSEC_HIDESYM
66870+#ifdef CONFIG_GRKERNSEC_PROC_USER
66871+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
66872+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66873+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
66874+#else
66875 proc_create("modules", 0, NULL, &proc_modules_operations);
66876+#endif
66877+#else
66878+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
66879+#endif
66880 return 0;
66881 }
66882 module_init(proc_modules_init);
66883@@ -3457,12 +3597,12 @@ struct module *__module_address(unsigned long addr)
66884 {
66885 struct module *mod;
66886
66887- if (addr < module_addr_min || addr > module_addr_max)
66888+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
66889+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
66890 return NULL;
66891
66892 list_for_each_entry_rcu(mod, &modules, list)
66893- if (within_module_core(addr, mod)
66894- || within_module_init(addr, mod))
66895+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
66896 return mod;
66897 return NULL;
66898 }
66899@@ -3496,11 +3636,20 @@ bool is_module_text_address(unsigned long addr)
66900 */
66901 struct module *__module_text_address(unsigned long addr)
66902 {
66903- struct module *mod = __module_address(addr);
66904+ struct module *mod;
66905+
66906+#ifdef CONFIG_X86_32
66907+ addr = ktla_ktva(addr);
66908+#endif
66909+
66910+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
66911+ return NULL;
66912+
66913+ mod = __module_address(addr);
66914+
66915 if (mod) {
66916 /* Make sure it's within the text section. */
66917- if (!within(addr, mod->module_init, mod->init_text_size)
66918- && !within(addr, mod->module_core, mod->core_text_size))
66919+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
66920 mod = NULL;
66921 }
66922 return mod;
66923diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
66924index 7e3443f..b2a1e6b 100644
66925--- a/kernel/mutex-debug.c
66926+++ b/kernel/mutex-debug.c
66927@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
66928 }
66929
66930 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
66931- struct thread_info *ti)
66932+ struct task_struct *task)
66933 {
66934 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
66935
66936 /* Mark the current thread as blocked on the lock: */
66937- ti->task->blocked_on = waiter;
66938+ task->blocked_on = waiter;
66939 }
66940
66941 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
66942- struct thread_info *ti)
66943+ struct task_struct *task)
66944 {
66945 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
66946- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
66947- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
66948- ti->task->blocked_on = NULL;
66949+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
66950+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
66951+ task->blocked_on = NULL;
66952
66953 list_del_init(&waiter->list);
66954 waiter->task = NULL;
66955diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
66956index 0799fd3..d06ae3b 100644
66957--- a/kernel/mutex-debug.h
66958+++ b/kernel/mutex-debug.h
66959@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
66960 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
66961 extern void debug_mutex_add_waiter(struct mutex *lock,
66962 struct mutex_waiter *waiter,
66963- struct thread_info *ti);
66964+ struct task_struct *task);
66965 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
66966- struct thread_info *ti);
66967+ struct task_struct *task);
66968 extern void debug_mutex_unlock(struct mutex *lock);
66969 extern void debug_mutex_init(struct mutex *lock, const char *name,
66970 struct lock_class_key *key);
66971diff --git a/kernel/mutex.c b/kernel/mutex.c
66972index a307cc9..27fd2e9 100644
66973--- a/kernel/mutex.c
66974+++ b/kernel/mutex.c
66975@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
66976 spin_lock_mutex(&lock->wait_lock, flags);
66977
66978 debug_mutex_lock_common(lock, &waiter);
66979- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
66980+ debug_mutex_add_waiter(lock, &waiter, task);
66981
66982 /* add waiting tasks to the end of the waitqueue (FIFO): */
66983 list_add_tail(&waiter.list, &lock->wait_list);
66984@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
66985 * TASK_UNINTERRUPTIBLE case.)
66986 */
66987 if (unlikely(signal_pending_state(state, task))) {
66988- mutex_remove_waiter(lock, &waiter,
66989- task_thread_info(task));
66990+ mutex_remove_waiter(lock, &waiter, task);
66991 mutex_release(&lock->dep_map, 1, ip);
66992 spin_unlock_mutex(&lock->wait_lock, flags);
66993
66994@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
66995 done:
66996 lock_acquired(&lock->dep_map, ip);
66997 /* got the lock - rejoice! */
66998- mutex_remove_waiter(lock, &waiter, current_thread_info());
66999+ mutex_remove_waiter(lock, &waiter, task);
67000 mutex_set_owner(lock);
67001
67002 /* set it to 0 if there are no waiters left: */
67003diff --git a/kernel/panic.c b/kernel/panic.c
67004index 8ed89a1..e83856a 100644
67005--- a/kernel/panic.c
67006+++ b/kernel/panic.c
67007@@ -402,7 +402,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
67008 const char *board;
67009
67010 printk(KERN_WARNING "------------[ cut here ]------------\n");
67011- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
67012+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
67013 board = dmi_get_system_info(DMI_PRODUCT_NAME);
67014 if (board)
67015 printk(KERN_WARNING "Hardware name: %s\n", board);
67016@@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
67017 */
67018 void __stack_chk_fail(void)
67019 {
67020- panic("stack-protector: Kernel stack is corrupted in: %p\n",
67021+ dump_stack();
67022+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
67023 __builtin_return_address(0));
67024 }
67025 EXPORT_SYMBOL(__stack_chk_fail);
67026diff --git a/kernel/pid.c b/kernel/pid.c
67027index 9f08dfa..6765c40 100644
67028--- a/kernel/pid.c
67029+++ b/kernel/pid.c
67030@@ -33,6 +33,7 @@
67031 #include <linux/rculist.h>
67032 #include <linux/bootmem.h>
67033 #include <linux/hash.h>
67034+#include <linux/security.h>
67035 #include <linux/pid_namespace.h>
67036 #include <linux/init_task.h>
67037 #include <linux/syscalls.h>
67038@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
67039
67040 int pid_max = PID_MAX_DEFAULT;
67041
67042-#define RESERVED_PIDS 300
67043+#define RESERVED_PIDS 500
67044
67045 int pid_max_min = RESERVED_PIDS + 1;
67046 int pid_max_max = PID_MAX_LIMIT;
67047@@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
67048 */
67049 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
67050 {
67051+ struct task_struct *task;
67052+
67053 rcu_lockdep_assert(rcu_read_lock_held(),
67054 "find_task_by_pid_ns() needs rcu_read_lock()"
67055 " protection");
67056- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67057+
67058+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67059+
67060+ if (gr_pid_is_chrooted(task))
67061+ return NULL;
67062+
67063+ return task;
67064 }
67065
67066 struct task_struct *find_task_by_vpid(pid_t vnr)
67067@@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
67068 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
67069 }
67070
67071+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
67072+{
67073+ rcu_lockdep_assert(rcu_read_lock_held(),
67074+ "find_task_by_pid_ns() needs rcu_read_lock()"
67075+ " protection");
67076+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
67077+}
67078+
67079 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
67080 {
67081 struct pid *pid;
67082diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
67083index 125cb67..a4d1c30 100644
67084--- a/kernel/posix-cpu-timers.c
67085+++ b/kernel/posix-cpu-timers.c
67086@@ -6,6 +6,7 @@
67087 #include <linux/posix-timers.h>
67088 #include <linux/errno.h>
67089 #include <linux/math64.h>
67090+#include <linux/security.h>
67091 #include <asm/uaccess.h>
67092 #include <linux/kernel_stat.h>
67093 #include <trace/events/timer.h>
67094@@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
67095
67096 static __init int init_posix_cpu_timers(void)
67097 {
67098- struct k_clock process = {
67099+ static struct k_clock process = {
67100 .clock_getres = process_cpu_clock_getres,
67101 .clock_get = process_cpu_clock_get,
67102 .timer_create = process_cpu_timer_create,
67103 .nsleep = process_cpu_nsleep,
67104 .nsleep_restart = process_cpu_nsleep_restart,
67105 };
67106- struct k_clock thread = {
67107+ static struct k_clock thread = {
67108 .clock_getres = thread_cpu_clock_getres,
67109 .clock_get = thread_cpu_clock_get,
67110 .timer_create = thread_cpu_timer_create,
67111diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
67112index 69185ae..cc2847a 100644
67113--- a/kernel/posix-timers.c
67114+++ b/kernel/posix-timers.c
67115@@ -43,6 +43,7 @@
67116 #include <linux/idr.h>
67117 #include <linux/posix-clock.h>
67118 #include <linux/posix-timers.h>
67119+#include <linux/grsecurity.h>
67120 #include <linux/syscalls.h>
67121 #include <linux/wait.h>
67122 #include <linux/workqueue.h>
67123@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
67124 * which we beg off on and pass to do_sys_settimeofday().
67125 */
67126
67127-static struct k_clock posix_clocks[MAX_CLOCKS];
67128+static struct k_clock *posix_clocks[MAX_CLOCKS];
67129
67130 /*
67131 * These ones are defined below.
67132@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
67133 */
67134 static __init int init_posix_timers(void)
67135 {
67136- struct k_clock clock_realtime = {
67137+ static struct k_clock clock_realtime = {
67138 .clock_getres = hrtimer_get_res,
67139 .clock_get = posix_clock_realtime_get,
67140 .clock_set = posix_clock_realtime_set,
67141@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
67142 .timer_get = common_timer_get,
67143 .timer_del = common_timer_del,
67144 };
67145- struct k_clock clock_monotonic = {
67146+ static struct k_clock clock_monotonic = {
67147 .clock_getres = hrtimer_get_res,
67148 .clock_get = posix_ktime_get_ts,
67149 .nsleep = common_nsleep,
67150@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
67151 .timer_get = common_timer_get,
67152 .timer_del = common_timer_del,
67153 };
67154- struct k_clock clock_monotonic_raw = {
67155+ static struct k_clock clock_monotonic_raw = {
67156 .clock_getres = hrtimer_get_res,
67157 .clock_get = posix_get_monotonic_raw,
67158 };
67159- struct k_clock clock_realtime_coarse = {
67160+ static struct k_clock clock_realtime_coarse = {
67161 .clock_getres = posix_get_coarse_res,
67162 .clock_get = posix_get_realtime_coarse,
67163 };
67164- struct k_clock clock_monotonic_coarse = {
67165+ static struct k_clock clock_monotonic_coarse = {
67166 .clock_getres = posix_get_coarse_res,
67167 .clock_get = posix_get_monotonic_coarse,
67168 };
67169- struct k_clock clock_boottime = {
67170+ static struct k_clock clock_boottime = {
67171 .clock_getres = hrtimer_get_res,
67172 .clock_get = posix_get_boottime,
67173 .nsleep = common_nsleep,
67174@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
67175 return;
67176 }
67177
67178- posix_clocks[clock_id] = *new_clock;
67179+ posix_clocks[clock_id] = new_clock;
67180 }
67181 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
67182
67183@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
67184 return (id & CLOCKFD_MASK) == CLOCKFD ?
67185 &clock_posix_dynamic : &clock_posix_cpu;
67186
67187- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
67188+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
67189 return NULL;
67190- return &posix_clocks[id];
67191+ return posix_clocks[id];
67192 }
67193
67194 static int common_timer_create(struct k_itimer *new_timer)
67195@@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
67196 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
67197 return -EFAULT;
67198
67199+ /* only the CLOCK_REALTIME clock can be set, all other clocks
67200+ have their clock_set fptr set to a nosettime dummy function
67201+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
67202+ call common_clock_set, which calls do_sys_settimeofday, which
67203+ we hook
67204+ */
67205+
67206 return kc->clock_set(which_clock, &new_tp);
67207 }
67208
67209diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
67210index d523593..68197a4 100644
67211--- a/kernel/power/poweroff.c
67212+++ b/kernel/power/poweroff.c
67213@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
67214 .enable_mask = SYSRQ_ENABLE_BOOT,
67215 };
67216
67217-static int pm_sysrq_init(void)
67218+static int __init pm_sysrq_init(void)
67219 {
67220 register_sysrq_key('o', &sysrq_poweroff_op);
67221 return 0;
67222diff --git a/kernel/power/process.c b/kernel/power/process.c
67223index 19db29f..33b52b6 100644
67224--- a/kernel/power/process.c
67225+++ b/kernel/power/process.c
67226@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
67227 u64 elapsed_csecs64;
67228 unsigned int elapsed_csecs;
67229 bool wakeup = false;
67230+ bool timedout = false;
67231
67232 do_gettimeofday(&start);
67233
67234@@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
67235
67236 while (true) {
67237 todo = 0;
67238+ if (time_after(jiffies, end_time))
67239+ timedout = true;
67240 read_lock(&tasklist_lock);
67241 do_each_thread(g, p) {
67242 if (p == current || !freeze_task(p))
67243@@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
67244 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
67245 * transition can't race with task state testing here.
67246 */
67247- if (!task_is_stopped_or_traced(p) &&
67248- !freezer_should_skip(p))
67249+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
67250 todo++;
67251+ if (timedout) {
67252+ printk(KERN_ERR "Task refusing to freeze:\n");
67253+ sched_show_task(p);
67254+ }
67255+ }
67256 } while_each_thread(g, p);
67257 read_unlock(&tasklist_lock);
67258
67259@@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
67260 todo += wq_busy;
67261 }
67262
67263- if (!todo || time_after(jiffies, end_time))
67264+ if (!todo || timedout)
67265 break;
67266
67267 if (pm_wakeup_pending()) {
67268diff --git a/kernel/printk.c b/kernel/printk.c
67269index b663c2c..1d6ba7a 100644
67270--- a/kernel/printk.c
67271+++ b/kernel/printk.c
67272@@ -316,6 +316,11 @@ static int check_syslog_permissions(int type, bool from_file)
67273 if (from_file && type != SYSLOG_ACTION_OPEN)
67274 return 0;
67275
67276+#ifdef CONFIG_GRKERNSEC_DMESG
67277+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
67278+ return -EPERM;
67279+#endif
67280+
67281 if (syslog_action_restricted(type)) {
67282 if (capable(CAP_SYSLOG))
67283 return 0;
67284diff --git a/kernel/profile.c b/kernel/profile.c
67285index 76b8e77..a2930e8 100644
67286--- a/kernel/profile.c
67287+++ b/kernel/profile.c
67288@@ -39,7 +39,7 @@ struct profile_hit {
67289 /* Oprofile timer tick hook */
67290 static int (*timer_hook)(struct pt_regs *) __read_mostly;
67291
67292-static atomic_t *prof_buffer;
67293+static atomic_unchecked_t *prof_buffer;
67294 static unsigned long prof_len, prof_shift;
67295
67296 int prof_on __read_mostly;
67297@@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
67298 hits[i].pc = 0;
67299 continue;
67300 }
67301- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67302+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67303 hits[i].hits = hits[i].pc = 0;
67304 }
67305 }
67306@@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
67307 * Add the current hit(s) and flush the write-queue out
67308 * to the global buffer:
67309 */
67310- atomic_add(nr_hits, &prof_buffer[pc]);
67311+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
67312 for (i = 0; i < NR_PROFILE_HIT; ++i) {
67313- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67314+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67315 hits[i].pc = hits[i].hits = 0;
67316 }
67317 out:
67318@@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
67319 {
67320 unsigned long pc;
67321 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
67322- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
67323+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
67324 }
67325 #endif /* !CONFIG_SMP */
67326
67327@@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
67328 return -EFAULT;
67329 buf++; p++; count--; read++;
67330 }
67331- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
67332+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
67333 if (copy_to_user(buf, (void *)pnt, count))
67334 return -EFAULT;
67335 read += count;
67336@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
67337 }
67338 #endif
67339 profile_discard_flip_buffers();
67340- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
67341+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
67342 return count;
67343 }
67344
67345diff --git a/kernel/ptrace.c b/kernel/ptrace.c
67346index ee8d49b..bd3d790 100644
67347--- a/kernel/ptrace.c
67348+++ b/kernel/ptrace.c
67349@@ -280,7 +280,7 @@ static int ptrace_attach(struct task_struct *task, long request,
67350
67351 if (seize)
67352 flags |= PT_SEIZED;
67353- if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
67354+ if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
67355 flags |= PT_PTRACE_CAP;
67356 task->ptrace = flags;
67357
67358@@ -487,7 +487,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
67359 break;
67360 return -EIO;
67361 }
67362- if (copy_to_user(dst, buf, retval))
67363+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
67364 return -EFAULT;
67365 copied += retval;
67366 src += retval;
67367@@ -672,7 +672,7 @@ int ptrace_request(struct task_struct *child, long request,
67368 bool seized = child->ptrace & PT_SEIZED;
67369 int ret = -EIO;
67370 siginfo_t siginfo, *si;
67371- void __user *datavp = (void __user *) data;
67372+ void __user *datavp = (__force void __user *) data;
67373 unsigned long __user *datalp = datavp;
67374 unsigned long flags;
67375
67376@@ -874,14 +874,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
67377 goto out;
67378 }
67379
67380+ if (gr_handle_ptrace(child, request)) {
67381+ ret = -EPERM;
67382+ goto out_put_task_struct;
67383+ }
67384+
67385 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67386 ret = ptrace_attach(child, request, addr, data);
67387 /*
67388 * Some architectures need to do book-keeping after
67389 * a ptrace attach.
67390 */
67391- if (!ret)
67392+ if (!ret) {
67393 arch_ptrace_attach(child);
67394+ gr_audit_ptrace(child);
67395+ }
67396 goto out_put_task_struct;
67397 }
67398
67399@@ -907,7 +914,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
67400 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
67401 if (copied != sizeof(tmp))
67402 return -EIO;
67403- return put_user(tmp, (unsigned long __user *)data);
67404+ return put_user(tmp, (__force unsigned long __user *)data);
67405 }
67406
67407 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
67408@@ -1017,14 +1024,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
67409 goto out;
67410 }
67411
67412+ if (gr_handle_ptrace(child, request)) {
67413+ ret = -EPERM;
67414+ goto out_put_task_struct;
67415+ }
67416+
67417 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67418 ret = ptrace_attach(child, request, addr, data);
67419 /*
67420 * Some architectures need to do book-keeping after
67421 * a ptrace attach.
67422 */
67423- if (!ret)
67424+ if (!ret) {
67425 arch_ptrace_attach(child);
67426+ gr_audit_ptrace(child);
67427+ }
67428 goto out_put_task_struct;
67429 }
67430
67431diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
67432index 37a5444..eec170a 100644
67433--- a/kernel/rcutiny.c
67434+++ b/kernel/rcutiny.c
67435@@ -46,7 +46,7 @@
67436 struct rcu_ctrlblk;
67437 static void invoke_rcu_callbacks(void);
67438 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
67439-static void rcu_process_callbacks(struct softirq_action *unused);
67440+static void rcu_process_callbacks(void);
67441 static void __call_rcu(struct rcu_head *head,
67442 void (*func)(struct rcu_head *rcu),
67443 struct rcu_ctrlblk *rcp);
67444@@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
67445 rcu_is_callbacks_kthread()));
67446 }
67447
67448-static void rcu_process_callbacks(struct softirq_action *unused)
67449+static void rcu_process_callbacks(void)
67450 {
67451 __rcu_process_callbacks(&rcu_sched_ctrlblk);
67452 __rcu_process_callbacks(&rcu_bh_ctrlblk);
67453diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
67454index 22ecea0..3789898 100644
67455--- a/kernel/rcutiny_plugin.h
67456+++ b/kernel/rcutiny_plugin.h
67457@@ -955,7 +955,7 @@ static int rcu_kthread(void *arg)
67458 have_rcu_kthread_work = morework;
67459 local_irq_restore(flags);
67460 if (work)
67461- rcu_process_callbacks(NULL);
67462+ rcu_process_callbacks();
67463 schedule_timeout_interruptible(1); /* Leave CPU for others. */
67464 }
67465
67466diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
67467index a89b381..efdcad8 100644
67468--- a/kernel/rcutorture.c
67469+++ b/kernel/rcutorture.c
67470@@ -158,12 +158,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
67471 { 0 };
67472 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
67473 { 0 };
67474-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
67475-static atomic_t n_rcu_torture_alloc;
67476-static atomic_t n_rcu_torture_alloc_fail;
67477-static atomic_t n_rcu_torture_free;
67478-static atomic_t n_rcu_torture_mberror;
67479-static atomic_t n_rcu_torture_error;
67480+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
67481+static atomic_unchecked_t n_rcu_torture_alloc;
67482+static atomic_unchecked_t n_rcu_torture_alloc_fail;
67483+static atomic_unchecked_t n_rcu_torture_free;
67484+static atomic_unchecked_t n_rcu_torture_mberror;
67485+static atomic_unchecked_t n_rcu_torture_error;
67486 static long n_rcu_torture_boost_ktrerror;
67487 static long n_rcu_torture_boost_rterror;
67488 static long n_rcu_torture_boost_failure;
67489@@ -253,11 +253,11 @@ rcu_torture_alloc(void)
67490
67491 spin_lock_bh(&rcu_torture_lock);
67492 if (list_empty(&rcu_torture_freelist)) {
67493- atomic_inc(&n_rcu_torture_alloc_fail);
67494+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
67495 spin_unlock_bh(&rcu_torture_lock);
67496 return NULL;
67497 }
67498- atomic_inc(&n_rcu_torture_alloc);
67499+ atomic_inc_unchecked(&n_rcu_torture_alloc);
67500 p = rcu_torture_freelist.next;
67501 list_del_init(p);
67502 spin_unlock_bh(&rcu_torture_lock);
67503@@ -270,7 +270,7 @@ rcu_torture_alloc(void)
67504 static void
67505 rcu_torture_free(struct rcu_torture *p)
67506 {
67507- atomic_inc(&n_rcu_torture_free);
67508+ atomic_inc_unchecked(&n_rcu_torture_free);
67509 spin_lock_bh(&rcu_torture_lock);
67510 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
67511 spin_unlock_bh(&rcu_torture_lock);
67512@@ -390,7 +390,7 @@ rcu_torture_cb(struct rcu_head *p)
67513 i = rp->rtort_pipe_count;
67514 if (i > RCU_TORTURE_PIPE_LEN)
67515 i = RCU_TORTURE_PIPE_LEN;
67516- atomic_inc(&rcu_torture_wcount[i]);
67517+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
67518 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
67519 rp->rtort_mbtest = 0;
67520 rcu_torture_free(rp);
67521@@ -437,7 +437,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
67522 i = rp->rtort_pipe_count;
67523 if (i > RCU_TORTURE_PIPE_LEN)
67524 i = RCU_TORTURE_PIPE_LEN;
67525- atomic_inc(&rcu_torture_wcount[i]);
67526+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
67527 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
67528 rp->rtort_mbtest = 0;
67529 list_del(&rp->rtort_free);
67530@@ -926,7 +926,7 @@ rcu_torture_writer(void *arg)
67531 i = old_rp->rtort_pipe_count;
67532 if (i > RCU_TORTURE_PIPE_LEN)
67533 i = RCU_TORTURE_PIPE_LEN;
67534- atomic_inc(&rcu_torture_wcount[i]);
67535+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
67536 old_rp->rtort_pipe_count++;
67537 cur_ops->deferred_free(old_rp);
67538 }
67539@@ -1007,7 +1007,7 @@ static void rcu_torture_timer(unsigned long unused)
67540 }
67541 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
67542 if (p->rtort_mbtest == 0)
67543- atomic_inc(&n_rcu_torture_mberror);
67544+ atomic_inc_unchecked(&n_rcu_torture_mberror);
67545 spin_lock(&rand_lock);
67546 cur_ops->read_delay(&rand);
67547 n_rcu_torture_timers++;
67548@@ -1071,7 +1071,7 @@ rcu_torture_reader(void *arg)
67549 }
67550 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
67551 if (p->rtort_mbtest == 0)
67552- atomic_inc(&n_rcu_torture_mberror);
67553+ atomic_inc_unchecked(&n_rcu_torture_mberror);
67554 cur_ops->read_delay(&rand);
67555 preempt_disable();
67556 pipe_count = p->rtort_pipe_count;
67557@@ -1133,10 +1133,10 @@ rcu_torture_printk(char *page)
67558 rcu_torture_current,
67559 rcu_torture_current_version,
67560 list_empty(&rcu_torture_freelist),
67561- atomic_read(&n_rcu_torture_alloc),
67562- atomic_read(&n_rcu_torture_alloc_fail),
67563- atomic_read(&n_rcu_torture_free),
67564- atomic_read(&n_rcu_torture_mberror),
67565+ atomic_read_unchecked(&n_rcu_torture_alloc),
67566+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
67567+ atomic_read_unchecked(&n_rcu_torture_free),
67568+ atomic_read_unchecked(&n_rcu_torture_mberror),
67569 n_rcu_torture_boost_ktrerror,
67570 n_rcu_torture_boost_rterror,
67571 n_rcu_torture_boost_failure,
67572@@ -1146,7 +1146,7 @@ rcu_torture_printk(char *page)
67573 n_online_attempts,
67574 n_offline_successes,
67575 n_offline_attempts);
67576- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
67577+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
67578 n_rcu_torture_boost_ktrerror != 0 ||
67579 n_rcu_torture_boost_rterror != 0 ||
67580 n_rcu_torture_boost_failure != 0)
67581@@ -1154,7 +1154,7 @@ rcu_torture_printk(char *page)
67582 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
67583 if (i > 1) {
67584 cnt += sprintf(&page[cnt], "!!! ");
67585- atomic_inc(&n_rcu_torture_error);
67586+ atomic_inc_unchecked(&n_rcu_torture_error);
67587 WARN_ON_ONCE(1);
67588 }
67589 cnt += sprintf(&page[cnt], "Reader Pipe: ");
67590@@ -1168,7 +1168,7 @@ rcu_torture_printk(char *page)
67591 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
67592 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
67593 cnt += sprintf(&page[cnt], " %d",
67594- atomic_read(&rcu_torture_wcount[i]));
67595+ atomic_read_unchecked(&rcu_torture_wcount[i]));
67596 }
67597 cnt += sprintf(&page[cnt], "\n");
67598 if (cur_ops->stats)
67599@@ -1676,7 +1676,7 @@ rcu_torture_cleanup(void)
67600
67601 if (cur_ops->cleanup)
67602 cur_ops->cleanup();
67603- if (atomic_read(&n_rcu_torture_error))
67604+ if (atomic_read_unchecked(&n_rcu_torture_error))
67605 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
67606 else if (n_online_successes != n_online_attempts ||
67607 n_offline_successes != n_offline_attempts)
67608@@ -1744,17 +1744,17 @@ rcu_torture_init(void)
67609
67610 rcu_torture_current = NULL;
67611 rcu_torture_current_version = 0;
67612- atomic_set(&n_rcu_torture_alloc, 0);
67613- atomic_set(&n_rcu_torture_alloc_fail, 0);
67614- atomic_set(&n_rcu_torture_free, 0);
67615- atomic_set(&n_rcu_torture_mberror, 0);
67616- atomic_set(&n_rcu_torture_error, 0);
67617+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
67618+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
67619+ atomic_set_unchecked(&n_rcu_torture_free, 0);
67620+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
67621+ atomic_set_unchecked(&n_rcu_torture_error, 0);
67622 n_rcu_torture_boost_ktrerror = 0;
67623 n_rcu_torture_boost_rterror = 0;
67624 n_rcu_torture_boost_failure = 0;
67625 n_rcu_torture_boosts = 0;
67626 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
67627- atomic_set(&rcu_torture_wcount[i], 0);
67628+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
67629 for_each_possible_cpu(cpu) {
67630 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
67631 per_cpu(rcu_torture_count, cpu)[i] = 0;
67632diff --git a/kernel/rcutree.c b/kernel/rcutree.c
67633index d0c5baf..109b2e7 100644
67634--- a/kernel/rcutree.c
67635+++ b/kernel/rcutree.c
67636@@ -357,9 +357,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
67637 rcu_prepare_for_idle(smp_processor_id());
67638 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
67639 smp_mb__before_atomic_inc(); /* See above. */
67640- atomic_inc(&rdtp->dynticks);
67641+ atomic_inc_unchecked(&rdtp->dynticks);
67642 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
67643- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
67644+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
67645
67646 /*
67647 * The idle task is not permitted to enter the idle loop while
67648@@ -448,10 +448,10 @@ void rcu_irq_exit(void)
67649 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
67650 {
67651 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
67652- atomic_inc(&rdtp->dynticks);
67653+ atomic_inc_unchecked(&rdtp->dynticks);
67654 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
67655 smp_mb__after_atomic_inc(); /* See above. */
67656- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
67657+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
67658 rcu_cleanup_after_idle(smp_processor_id());
67659 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
67660 if (!is_idle_task(current)) {
67661@@ -545,14 +545,14 @@ void rcu_nmi_enter(void)
67662 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
67663
67664 if (rdtp->dynticks_nmi_nesting == 0 &&
67665- (atomic_read(&rdtp->dynticks) & 0x1))
67666+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
67667 return;
67668 rdtp->dynticks_nmi_nesting++;
67669 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
67670- atomic_inc(&rdtp->dynticks);
67671+ atomic_inc_unchecked(&rdtp->dynticks);
67672 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
67673 smp_mb__after_atomic_inc(); /* See above. */
67674- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
67675+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
67676 }
67677
67678 /**
67679@@ -571,9 +571,9 @@ void rcu_nmi_exit(void)
67680 return;
67681 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
67682 smp_mb__before_atomic_inc(); /* See above. */
67683- atomic_inc(&rdtp->dynticks);
67684+ atomic_inc_unchecked(&rdtp->dynticks);
67685 smp_mb__after_atomic_inc(); /* Force delay to next write. */
67686- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
67687+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
67688 }
67689
67690 #ifdef CONFIG_PROVE_RCU
67691@@ -589,7 +589,7 @@ int rcu_is_cpu_idle(void)
67692 int ret;
67693
67694 preempt_disable();
67695- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
67696+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
67697 preempt_enable();
67698 return ret;
67699 }
67700@@ -659,7 +659,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
67701 */
67702 static int dyntick_save_progress_counter(struct rcu_data *rdp)
67703 {
67704- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
67705+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
67706 return (rdp->dynticks_snap & 0x1) == 0;
67707 }
67708
67709@@ -674,7 +674,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
67710 unsigned int curr;
67711 unsigned int snap;
67712
67713- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
67714+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
67715 snap = (unsigned int)rdp->dynticks_snap;
67716
67717 /*
67718@@ -704,10 +704,10 @@ static int jiffies_till_stall_check(void)
67719 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
67720 */
67721 if (till_stall_check < 3) {
67722- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
67723+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
67724 till_stall_check = 3;
67725 } else if (till_stall_check > 300) {
67726- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
67727+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
67728 till_stall_check = 300;
67729 }
67730 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
67731@@ -1766,7 +1766,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
67732 /*
67733 * Do RCU core processing for the current CPU.
67734 */
67735-static void rcu_process_callbacks(struct softirq_action *unused)
67736+static void rcu_process_callbacks(void)
67737 {
67738 trace_rcu_utilization("Start RCU core");
67739 __rcu_process_callbacks(&rcu_sched_state,
67740@@ -1949,8 +1949,8 @@ void synchronize_rcu_bh(void)
67741 }
67742 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
67743
67744-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
67745-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
67746+static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
67747+static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
67748
67749 static int synchronize_sched_expedited_cpu_stop(void *data)
67750 {
67751@@ -2011,7 +2011,7 @@ void synchronize_sched_expedited(void)
67752 int firstsnap, s, snap, trycount = 0;
67753
67754 /* Note that atomic_inc_return() implies full memory barrier. */
67755- firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
67756+ firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
67757 get_online_cpus();
67758 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
67759
67760@@ -2033,7 +2033,7 @@ void synchronize_sched_expedited(void)
67761 }
67762
67763 /* Check to see if someone else did our work for us. */
67764- s = atomic_read(&sync_sched_expedited_done);
67765+ s = atomic_read_unchecked(&sync_sched_expedited_done);
67766 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
67767 smp_mb(); /* ensure test happens before caller kfree */
67768 return;
67769@@ -2048,7 +2048,7 @@ void synchronize_sched_expedited(void)
67770 * grace period works for us.
67771 */
67772 get_online_cpus();
67773- snap = atomic_read(&sync_sched_expedited_started);
67774+ snap = atomic_read_unchecked(&sync_sched_expedited_started);
67775 smp_mb(); /* ensure read is before try_stop_cpus(). */
67776 }
67777
67778@@ -2059,12 +2059,12 @@ void synchronize_sched_expedited(void)
67779 * than we did beat us to the punch.
67780 */
67781 do {
67782- s = atomic_read(&sync_sched_expedited_done);
67783+ s = atomic_read_unchecked(&sync_sched_expedited_done);
67784 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
67785 smp_mb(); /* ensure test happens before caller kfree */
67786 break;
67787 }
67788- } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
67789+ } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
67790
67791 put_online_cpus();
67792 }
67793@@ -2262,7 +2262,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
67794 rdp->qlen = 0;
67795 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
67796 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
67797- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
67798+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
67799 rdp->cpu = cpu;
67800 rdp->rsp = rsp;
67801 raw_spin_unlock_irqrestore(&rnp->lock, flags);
67802@@ -2290,8 +2290,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
67803 rdp->n_force_qs_snap = rsp->n_force_qs;
67804 rdp->blimit = blimit;
67805 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
67806- atomic_set(&rdp->dynticks->dynticks,
67807- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
67808+ atomic_set_unchecked(&rdp->dynticks->dynticks,
67809+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
67810 rcu_prepare_for_idle_init(cpu);
67811 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
67812
67813diff --git a/kernel/rcutree.h b/kernel/rcutree.h
67814index cdd1be0..5b2efb4 100644
67815--- a/kernel/rcutree.h
67816+++ b/kernel/rcutree.h
67817@@ -87,7 +87,7 @@ struct rcu_dynticks {
67818 long long dynticks_nesting; /* Track irq/process nesting level. */
67819 /* Process level is worth LLONG_MAX/2. */
67820 int dynticks_nmi_nesting; /* Track NMI nesting level. */
67821- atomic_t dynticks; /* Even value for idle, else odd. */
67822+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
67823 };
67824
67825 /* RCU's kthread states for tracing. */
67826diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
67827index c023464..7f57225 100644
67828--- a/kernel/rcutree_plugin.h
67829+++ b/kernel/rcutree_plugin.h
67830@@ -909,7 +909,7 @@ void synchronize_rcu_expedited(void)
67831
67832 /* Clean up and exit. */
67833 smp_mb(); /* ensure expedited GP seen before counter increment. */
67834- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
67835+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
67836 unlock_mb_ret:
67837 mutex_unlock(&sync_rcu_preempt_exp_mutex);
67838 mb_ret:
67839diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
67840index ed459ed..a03c3fa 100644
67841--- a/kernel/rcutree_trace.c
67842+++ b/kernel/rcutree_trace.c
67843@@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
67844 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
67845 rdp->qs_pending);
67846 seq_printf(m, " dt=%d/%llx/%d df=%lu",
67847- atomic_read(&rdp->dynticks->dynticks),
67848+ atomic_read_unchecked(&rdp->dynticks->dynticks),
67849 rdp->dynticks->dynticks_nesting,
67850 rdp->dynticks->dynticks_nmi_nesting,
67851 rdp->dynticks_fqs);
67852@@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
67853 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
67854 rdp->qs_pending);
67855 seq_printf(m, ",%d,%llx,%d,%lu",
67856- atomic_read(&rdp->dynticks->dynticks),
67857+ atomic_read_unchecked(&rdp->dynticks->dynticks),
67858 rdp->dynticks->dynticks_nesting,
67859 rdp->dynticks->dynticks_nmi_nesting,
67860 rdp->dynticks_fqs);
67861diff --git a/kernel/resource.c b/kernel/resource.c
67862index 7e8ea66..1efd11f 100644
67863--- a/kernel/resource.c
67864+++ b/kernel/resource.c
67865@@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
67866
67867 static int __init ioresources_init(void)
67868 {
67869+#ifdef CONFIG_GRKERNSEC_PROC_ADD
67870+#ifdef CONFIG_GRKERNSEC_PROC_USER
67871+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
67872+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
67873+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67874+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
67875+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
67876+#endif
67877+#else
67878 proc_create("ioports", 0, NULL, &proc_ioports_operations);
67879 proc_create("iomem", 0, NULL, &proc_iomem_operations);
67880+#endif
67881 return 0;
67882 }
67883 __initcall(ioresources_init);
67884diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
67885index 98ec494..4241d6d 100644
67886--- a/kernel/rtmutex-tester.c
67887+++ b/kernel/rtmutex-tester.c
67888@@ -20,7 +20,7 @@
67889 #define MAX_RT_TEST_MUTEXES 8
67890
67891 static spinlock_t rttest_lock;
67892-static atomic_t rttest_event;
67893+static atomic_unchecked_t rttest_event;
67894
67895 struct test_thread_data {
67896 int opcode;
67897@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67898
67899 case RTTEST_LOCKCONT:
67900 td->mutexes[td->opdata] = 1;
67901- td->event = atomic_add_return(1, &rttest_event);
67902+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67903 return 0;
67904
67905 case RTTEST_RESET:
67906@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67907 return 0;
67908
67909 case RTTEST_RESETEVENT:
67910- atomic_set(&rttest_event, 0);
67911+ atomic_set_unchecked(&rttest_event, 0);
67912 return 0;
67913
67914 default:
67915@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67916 return ret;
67917
67918 td->mutexes[id] = 1;
67919- td->event = atomic_add_return(1, &rttest_event);
67920+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67921 rt_mutex_lock(&mutexes[id]);
67922- td->event = atomic_add_return(1, &rttest_event);
67923+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67924 td->mutexes[id] = 4;
67925 return 0;
67926
67927@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67928 return ret;
67929
67930 td->mutexes[id] = 1;
67931- td->event = atomic_add_return(1, &rttest_event);
67932+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67933 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
67934- td->event = atomic_add_return(1, &rttest_event);
67935+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67936 td->mutexes[id] = ret ? 0 : 4;
67937 return ret ? -EINTR : 0;
67938
67939@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67940 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
67941 return ret;
67942
67943- td->event = atomic_add_return(1, &rttest_event);
67944+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67945 rt_mutex_unlock(&mutexes[id]);
67946- td->event = atomic_add_return(1, &rttest_event);
67947+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67948 td->mutexes[id] = 0;
67949 return 0;
67950
67951@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
67952 break;
67953
67954 td->mutexes[dat] = 2;
67955- td->event = atomic_add_return(1, &rttest_event);
67956+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67957 break;
67958
67959 default:
67960@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
67961 return;
67962
67963 td->mutexes[dat] = 3;
67964- td->event = atomic_add_return(1, &rttest_event);
67965+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67966 break;
67967
67968 case RTTEST_LOCKNOWAIT:
67969@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
67970 return;
67971
67972 td->mutexes[dat] = 1;
67973- td->event = atomic_add_return(1, &rttest_event);
67974+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67975 return;
67976
67977 default:
67978diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
67979index 0984a21..939f183 100644
67980--- a/kernel/sched/auto_group.c
67981+++ b/kernel/sched/auto_group.c
67982@@ -11,7 +11,7 @@
67983
67984 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
67985 static struct autogroup autogroup_default;
67986-static atomic_t autogroup_seq_nr;
67987+static atomic_unchecked_t autogroup_seq_nr;
67988
67989 void __init autogroup_init(struct task_struct *init_task)
67990 {
67991@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
67992
67993 kref_init(&ag->kref);
67994 init_rwsem(&ag->lock);
67995- ag->id = atomic_inc_return(&autogroup_seq_nr);
67996+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
67997 ag->tg = tg;
67998 #ifdef CONFIG_RT_GROUP_SCHED
67999 /*
68000diff --git a/kernel/sched/core.c b/kernel/sched/core.c
68001index 2000e06..79cf3d8 100644
68002--- a/kernel/sched/core.c
68003+++ b/kernel/sched/core.c
68004@@ -3907,6 +3907,8 @@ int can_nice(const struct task_struct *p, const int nice)
68005 /* convert nice value [19,-20] to rlimit style value [1,40] */
68006 int nice_rlim = 20 - nice;
68007
68008+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
68009+
68010 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
68011 capable(CAP_SYS_NICE));
68012 }
68013@@ -3940,7 +3942,8 @@ SYSCALL_DEFINE1(nice, int, increment)
68014 if (nice > 19)
68015 nice = 19;
68016
68017- if (increment < 0 && !can_nice(current, nice))
68018+ if (increment < 0 && (!can_nice(current, nice) ||
68019+ gr_handle_chroot_nice()))
68020 return -EPERM;
68021
68022 retval = security_task_setnice(current, nice);
68023@@ -4097,6 +4100,7 @@ recheck:
68024 unsigned long rlim_rtprio =
68025 task_rlimit(p, RLIMIT_RTPRIO);
68026
68027+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
68028 /* can't set/change the rt policy */
68029 if (policy != p->policy && !rlim_rtprio)
68030 return -EPERM;
68031diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
68032index e955364..eacd2a4 100644
68033--- a/kernel/sched/fair.c
68034+++ b/kernel/sched/fair.c
68035@@ -5107,7 +5107,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
68036 * run_rebalance_domains is triggered when needed from the scheduler tick.
68037 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
68038 */
68039-static void run_rebalance_domains(struct softirq_action *h)
68040+static void run_rebalance_domains(void)
68041 {
68042 int this_cpu = smp_processor_id();
68043 struct rq *this_rq = cpu_rq(this_cpu);
68044diff --git a/kernel/signal.c b/kernel/signal.c
68045index 17afcaf..4500b05 100644
68046--- a/kernel/signal.c
68047+++ b/kernel/signal.c
68048@@ -47,12 +47,12 @@ static struct kmem_cache *sigqueue_cachep;
68049
68050 int print_fatal_signals __read_mostly;
68051
68052-static void __user *sig_handler(struct task_struct *t, int sig)
68053+static __sighandler_t sig_handler(struct task_struct *t, int sig)
68054 {
68055 return t->sighand->action[sig - 1].sa.sa_handler;
68056 }
68057
68058-static int sig_handler_ignored(void __user *handler, int sig)
68059+static int sig_handler_ignored(__sighandler_t handler, int sig)
68060 {
68061 /* Is it explicitly or implicitly ignored? */
68062 return handler == SIG_IGN ||
68063@@ -61,7 +61,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
68064
68065 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
68066 {
68067- void __user *handler;
68068+ __sighandler_t handler;
68069
68070 handler = sig_handler(t, sig);
68071
68072@@ -365,6 +365,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
68073 atomic_inc(&user->sigpending);
68074 rcu_read_unlock();
68075
68076+ if (!override_rlimit)
68077+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
68078+
68079 if (override_rlimit ||
68080 atomic_read(&user->sigpending) <=
68081 task_rlimit(t, RLIMIT_SIGPENDING)) {
68082@@ -489,7 +492,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
68083
68084 int unhandled_signal(struct task_struct *tsk, int sig)
68085 {
68086- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
68087+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
68088 if (is_global_init(tsk))
68089 return 1;
68090 if (handler != SIG_IGN && handler != SIG_DFL)
68091@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
68092 }
68093 }
68094
68095+ /* allow glibc communication via tgkill to other threads in our
68096+ thread group */
68097+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
68098+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
68099+ && gr_handle_signal(t, sig))
68100+ return -EPERM;
68101+
68102 return security_task_kill(t, info, sig, 0);
68103 }
68104
68105@@ -1204,7 +1214,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68106 return send_signal(sig, info, p, 1);
68107 }
68108
68109-static int
68110+int
68111 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68112 {
68113 return send_signal(sig, info, t, 0);
68114@@ -1241,6 +1251,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68115 unsigned long int flags;
68116 int ret, blocked, ignored;
68117 struct k_sigaction *action;
68118+ int is_unhandled = 0;
68119
68120 spin_lock_irqsave(&t->sighand->siglock, flags);
68121 action = &t->sighand->action[sig-1];
68122@@ -1255,9 +1266,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68123 }
68124 if (action->sa.sa_handler == SIG_DFL)
68125 t->signal->flags &= ~SIGNAL_UNKILLABLE;
68126+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
68127+ is_unhandled = 1;
68128 ret = specific_send_sig_info(sig, info, t);
68129 spin_unlock_irqrestore(&t->sighand->siglock, flags);
68130
68131+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
68132+ normal operation */
68133+ if (is_unhandled) {
68134+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
68135+ gr_handle_crash(t, sig);
68136+ }
68137+
68138 return ret;
68139 }
68140
68141@@ -1324,8 +1344,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68142 ret = check_kill_permission(sig, info, p);
68143 rcu_read_unlock();
68144
68145- if (!ret && sig)
68146+ if (!ret && sig) {
68147 ret = do_send_sig_info(sig, info, p, true);
68148+ if (!ret)
68149+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
68150+ }
68151
68152 return ret;
68153 }
68154@@ -2840,7 +2863,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
68155 int error = -ESRCH;
68156
68157 rcu_read_lock();
68158- p = find_task_by_vpid(pid);
68159+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68160+ /* allow glibc communication via tgkill to other threads in our
68161+ thread group */
68162+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
68163+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
68164+ p = find_task_by_vpid_unrestricted(pid);
68165+ else
68166+#endif
68167+ p = find_task_by_vpid(pid);
68168 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
68169 error = check_kill_permission(sig, info, p);
68170 /*
68171diff --git a/kernel/smp.c b/kernel/smp.c
68172index 2f8b10e..a41bc14 100644
68173--- a/kernel/smp.c
68174+++ b/kernel/smp.c
68175@@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
68176 }
68177 EXPORT_SYMBOL(smp_call_function);
68178
68179-void ipi_call_lock(void)
68180+void ipi_call_lock(void) __acquires(call_function.lock)
68181 {
68182 raw_spin_lock(&call_function.lock);
68183 }
68184
68185-void ipi_call_unlock(void)
68186+void ipi_call_unlock(void) __releases(call_function.lock)
68187 {
68188 raw_spin_unlock(&call_function.lock);
68189 }
68190
68191-void ipi_call_lock_irq(void)
68192+void ipi_call_lock_irq(void) __acquires(call_function.lock)
68193 {
68194 raw_spin_lock_irq(&call_function.lock);
68195 }
68196
68197-void ipi_call_unlock_irq(void)
68198+void ipi_call_unlock_irq(void) __releases(call_function.lock)
68199 {
68200 raw_spin_unlock_irq(&call_function.lock);
68201 }
68202diff --git a/kernel/softirq.c b/kernel/softirq.c
68203index 671f959..91c51cb 100644
68204--- a/kernel/softirq.c
68205+++ b/kernel/softirq.c
68206@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
68207
68208 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
68209
68210-char *softirq_to_name[NR_SOFTIRQS] = {
68211+const char * const softirq_to_name[NR_SOFTIRQS] = {
68212 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
68213 "TASKLET", "SCHED", "HRTIMER", "RCU"
68214 };
68215@@ -235,7 +235,7 @@ restart:
68216 kstat_incr_softirqs_this_cpu(vec_nr);
68217
68218 trace_softirq_entry(vec_nr);
68219- h->action(h);
68220+ h->action();
68221 trace_softirq_exit(vec_nr);
68222 if (unlikely(prev_count != preempt_count())) {
68223 printk(KERN_ERR "huh, entered softirq %u %s %p"
68224@@ -381,9 +381,11 @@ void __raise_softirq_irqoff(unsigned int nr)
68225 or_softirq_pending(1UL << nr);
68226 }
68227
68228-void open_softirq(int nr, void (*action)(struct softirq_action *))
68229+void open_softirq(int nr, void (*action)(void))
68230 {
68231- softirq_vec[nr].action = action;
68232+ pax_open_kernel();
68233+ *(void **)&softirq_vec[nr].action = action;
68234+ pax_close_kernel();
68235 }
68236
68237 /*
68238@@ -437,7 +439,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
68239
68240 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
68241
68242-static void tasklet_action(struct softirq_action *a)
68243+static void tasklet_action(void)
68244 {
68245 struct tasklet_struct *list;
68246
68247@@ -472,7 +474,7 @@ static void tasklet_action(struct softirq_action *a)
68248 }
68249 }
68250
68251-static void tasklet_hi_action(struct softirq_action *a)
68252+static void tasklet_hi_action(void)
68253 {
68254 struct tasklet_struct *list;
68255
68256diff --git a/kernel/sys.c b/kernel/sys.c
68257index e7006eb..8fb7c51 100644
68258--- a/kernel/sys.c
68259+++ b/kernel/sys.c
68260@@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
68261 error = -EACCES;
68262 goto out;
68263 }
68264+
68265+ if (gr_handle_chroot_setpriority(p, niceval)) {
68266+ error = -EACCES;
68267+ goto out;
68268+ }
68269+
68270 no_nice = security_task_setnice(p, niceval);
68271 if (no_nice) {
68272 error = no_nice;
68273@@ -581,6 +587,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
68274 goto error;
68275 }
68276
68277+ if (gr_check_group_change(new->gid, new->egid, -1))
68278+ goto error;
68279+
68280 if (rgid != (gid_t) -1 ||
68281 (egid != (gid_t) -1 && egid != old->gid))
68282 new->sgid = new->egid;
68283@@ -610,6 +619,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
68284 old = current_cred();
68285
68286 retval = -EPERM;
68287+
68288+ if (gr_check_group_change(gid, gid, gid))
68289+ goto error;
68290+
68291 if (nsown_capable(CAP_SETGID))
68292 new->gid = new->egid = new->sgid = new->fsgid = gid;
68293 else if (gid == old->gid || gid == old->sgid)
68294@@ -627,7 +640,7 @@ error:
68295 /*
68296 * change the user struct in a credentials set to match the new UID
68297 */
68298-static int set_user(struct cred *new)
68299+int set_user(struct cred *new)
68300 {
68301 struct user_struct *new_user;
68302
68303@@ -697,6 +710,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
68304 goto error;
68305 }
68306
68307+ if (gr_check_user_change(new->uid, new->euid, -1))
68308+ goto error;
68309+
68310 if (new->uid != old->uid) {
68311 retval = set_user(new);
68312 if (retval < 0)
68313@@ -741,6 +757,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
68314 old = current_cred();
68315
68316 retval = -EPERM;
68317+
68318+ if (gr_check_crash_uid(uid))
68319+ goto error;
68320+ if (gr_check_user_change(uid, uid, uid))
68321+ goto error;
68322+
68323 if (nsown_capable(CAP_SETUID)) {
68324 new->suid = new->uid = uid;
68325 if (uid != old->uid) {
68326@@ -795,6 +817,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
68327 goto error;
68328 }
68329
68330+ if (gr_check_user_change(ruid, euid, -1))
68331+ goto error;
68332+
68333 if (ruid != (uid_t) -1) {
68334 new->uid = ruid;
68335 if (ruid != old->uid) {
68336@@ -859,6 +884,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
68337 goto error;
68338 }
68339
68340+ if (gr_check_group_change(rgid, egid, -1))
68341+ goto error;
68342+
68343 if (rgid != (gid_t) -1)
68344 new->gid = rgid;
68345 if (egid != (gid_t) -1)
68346@@ -905,6 +933,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
68347 old = current_cred();
68348 old_fsuid = old->fsuid;
68349
68350+ if (gr_check_user_change(-1, -1, uid))
68351+ goto error;
68352+
68353 if (uid == old->uid || uid == old->euid ||
68354 uid == old->suid || uid == old->fsuid ||
68355 nsown_capable(CAP_SETUID)) {
68356@@ -915,6 +946,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
68357 }
68358 }
68359
68360+error:
68361 abort_creds(new);
68362 return old_fsuid;
68363
68364@@ -941,12 +973,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
68365 if (gid == old->gid || gid == old->egid ||
68366 gid == old->sgid || gid == old->fsgid ||
68367 nsown_capable(CAP_SETGID)) {
68368+ if (gr_check_group_change(-1, -1, gid))
68369+ goto error;
68370+
68371 if (gid != old_fsgid) {
68372 new->fsgid = gid;
68373 goto change_okay;
68374 }
68375 }
68376
68377+error:
68378 abort_creds(new);
68379 return old_fsgid;
68380
68381@@ -1198,7 +1234,10 @@ static int override_release(char __user *release, int len)
68382 }
68383 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
68384 snprintf(buf, len, "2.6.%u%s", v, rest);
68385- ret = copy_to_user(release, buf, len);
68386+ if (len > sizeof(buf))
68387+ ret = -EFAULT;
68388+ else
68389+ ret = copy_to_user(release, buf, len);
68390 }
68391 return ret;
68392 }
68393@@ -1252,19 +1291,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
68394 return -EFAULT;
68395
68396 down_read(&uts_sem);
68397- error = __copy_to_user(&name->sysname, &utsname()->sysname,
68398+ error = __copy_to_user(name->sysname, &utsname()->sysname,
68399 __OLD_UTS_LEN);
68400 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
68401- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
68402+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
68403 __OLD_UTS_LEN);
68404 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
68405- error |= __copy_to_user(&name->release, &utsname()->release,
68406+ error |= __copy_to_user(name->release, &utsname()->release,
68407 __OLD_UTS_LEN);
68408 error |= __put_user(0, name->release + __OLD_UTS_LEN);
68409- error |= __copy_to_user(&name->version, &utsname()->version,
68410+ error |= __copy_to_user(name->version, &utsname()->version,
68411 __OLD_UTS_LEN);
68412 error |= __put_user(0, name->version + __OLD_UTS_LEN);
68413- error |= __copy_to_user(&name->machine, &utsname()->machine,
68414+ error |= __copy_to_user(name->machine, &utsname()->machine,
68415 __OLD_UTS_LEN);
68416 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
68417 up_read(&uts_sem);
68418@@ -1847,7 +1886,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
68419 error = get_dumpable(me->mm);
68420 break;
68421 case PR_SET_DUMPABLE:
68422- if (arg2 < 0 || arg2 > 1) {
68423+ if (arg2 > 1) {
68424 error = -EINVAL;
68425 break;
68426 }
68427diff --git a/kernel/sysctl.c b/kernel/sysctl.c
68428index 4ab1187..0b75ced 100644
68429--- a/kernel/sysctl.c
68430+++ b/kernel/sysctl.c
68431@@ -91,7 +91,6 @@
68432
68433
68434 #if defined(CONFIG_SYSCTL)
68435-
68436 /* External variables not in a header file. */
68437 extern int sysctl_overcommit_memory;
68438 extern int sysctl_overcommit_ratio;
68439@@ -169,10 +168,8 @@ static int proc_taint(struct ctl_table *table, int write,
68440 void __user *buffer, size_t *lenp, loff_t *ppos);
68441 #endif
68442
68443-#ifdef CONFIG_PRINTK
68444 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
68445 void __user *buffer, size_t *lenp, loff_t *ppos);
68446-#endif
68447
68448 #ifdef CONFIG_MAGIC_SYSRQ
68449 /* Note: sysrq code uses it's own private copy */
68450@@ -196,6 +193,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
68451
68452 #endif
68453
68454+extern struct ctl_table grsecurity_table[];
68455+
68456 static struct ctl_table kern_table[];
68457 static struct ctl_table vm_table[];
68458 static struct ctl_table fs_table[];
68459@@ -210,6 +209,20 @@ extern struct ctl_table epoll_table[];
68460 int sysctl_legacy_va_layout;
68461 #endif
68462
68463+#ifdef CONFIG_PAX_SOFTMODE
68464+static ctl_table pax_table[] = {
68465+ {
68466+ .procname = "softmode",
68467+ .data = &pax_softmode,
68468+ .maxlen = sizeof(unsigned int),
68469+ .mode = 0600,
68470+ .proc_handler = &proc_dointvec,
68471+ },
68472+
68473+ { }
68474+};
68475+#endif
68476+
68477 /* The default sysctl tables: */
68478
68479 static struct ctl_table sysctl_base_table[] = {
68480@@ -256,6 +269,22 @@ static int max_extfrag_threshold = 1000;
68481 #endif
68482
68483 static struct ctl_table kern_table[] = {
68484+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
68485+ {
68486+ .procname = "grsecurity",
68487+ .mode = 0500,
68488+ .child = grsecurity_table,
68489+ },
68490+#endif
68491+
68492+#ifdef CONFIG_PAX_SOFTMODE
68493+ {
68494+ .procname = "pax",
68495+ .mode = 0500,
68496+ .child = pax_table,
68497+ },
68498+#endif
68499+
68500 {
68501 .procname = "sched_child_runs_first",
68502 .data = &sysctl_sched_child_runs_first,
68503@@ -540,7 +569,7 @@ static struct ctl_table kern_table[] = {
68504 .data = &modprobe_path,
68505 .maxlen = KMOD_PATH_LEN,
68506 .mode = 0644,
68507- .proc_handler = proc_dostring,
68508+ .proc_handler = proc_dostring_modpriv,
68509 },
68510 {
68511 .procname = "modules_disabled",
68512@@ -707,16 +736,20 @@ static struct ctl_table kern_table[] = {
68513 .extra1 = &zero,
68514 .extra2 = &one,
68515 },
68516+#endif
68517 {
68518 .procname = "kptr_restrict",
68519 .data = &kptr_restrict,
68520 .maxlen = sizeof(int),
68521 .mode = 0644,
68522 .proc_handler = proc_dointvec_minmax_sysadmin,
68523+#ifdef CONFIG_GRKERNSEC_HIDESYM
68524+ .extra1 = &two,
68525+#else
68526 .extra1 = &zero,
68527+#endif
68528 .extra2 = &two,
68529 },
68530-#endif
68531 {
68532 .procname = "ngroups_max",
68533 .data = &ngroups_max,
68534@@ -1215,6 +1248,13 @@ static struct ctl_table vm_table[] = {
68535 .proc_handler = proc_dointvec_minmax,
68536 .extra1 = &zero,
68537 },
68538+ {
68539+ .procname = "heap_stack_gap",
68540+ .data = &sysctl_heap_stack_gap,
68541+ .maxlen = sizeof(sysctl_heap_stack_gap),
68542+ .mode = 0644,
68543+ .proc_handler = proc_doulongvec_minmax,
68544+ },
68545 #else
68546 {
68547 .procname = "nr_trim_pages",
68548@@ -1645,6 +1685,16 @@ int proc_dostring(struct ctl_table *table, int write,
68549 buffer, lenp, ppos);
68550 }
68551
68552+int proc_dostring_modpriv(struct ctl_table *table, int write,
68553+ void __user *buffer, size_t *lenp, loff_t *ppos)
68554+{
68555+ if (write && !capable(CAP_SYS_MODULE))
68556+ return -EPERM;
68557+
68558+ return _proc_do_string(table->data, table->maxlen, write,
68559+ buffer, lenp, ppos);
68560+}
68561+
68562 static size_t proc_skip_spaces(char **buf)
68563 {
68564 size_t ret;
68565@@ -1750,6 +1800,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
68566 len = strlen(tmp);
68567 if (len > *size)
68568 len = *size;
68569+ if (len > sizeof(tmp))
68570+ len = sizeof(tmp);
68571 if (copy_to_user(*buf, tmp, len))
68572 return -EFAULT;
68573 *size -= len;
68574@@ -1942,7 +1994,6 @@ static int proc_taint(struct ctl_table *table, int write,
68575 return err;
68576 }
68577
68578-#ifdef CONFIG_PRINTK
68579 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
68580 void __user *buffer, size_t *lenp, loff_t *ppos)
68581 {
68582@@ -1951,7 +2002,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
68583
68584 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
68585 }
68586-#endif
68587
68588 struct do_proc_dointvec_minmax_conv_param {
68589 int *min;
68590@@ -2066,8 +2116,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
68591 *i = val;
68592 } else {
68593 val = convdiv * (*i) / convmul;
68594- if (!first)
68595+ if (!first) {
68596 err = proc_put_char(&buffer, &left, '\t');
68597+ if (err)
68598+ break;
68599+ }
68600 err = proc_put_long(&buffer, &left, val, false);
68601 if (err)
68602 break;
68603@@ -2459,6 +2512,12 @@ int proc_dostring(struct ctl_table *table, int write,
68604 return -ENOSYS;
68605 }
68606
68607+int proc_dostring_modpriv(struct ctl_table *table, int write,
68608+ void __user *buffer, size_t *lenp, loff_t *ppos)
68609+{
68610+ return -ENOSYS;
68611+}
68612+
68613 int proc_dointvec(struct ctl_table *table, int write,
68614 void __user *buffer, size_t *lenp, loff_t *ppos)
68615 {
68616@@ -2515,5 +2574,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
68617 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
68618 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
68619 EXPORT_SYMBOL(proc_dostring);
68620+EXPORT_SYMBOL(proc_dostring_modpriv);
68621 EXPORT_SYMBOL(proc_doulongvec_minmax);
68622 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
68623diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
68624index a650694..aaeeb20 100644
68625--- a/kernel/sysctl_binary.c
68626+++ b/kernel/sysctl_binary.c
68627@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
68628 int i;
68629
68630 set_fs(KERNEL_DS);
68631- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
68632+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
68633 set_fs(old_fs);
68634 if (result < 0)
68635 goto out_kfree;
68636@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
68637 }
68638
68639 set_fs(KERNEL_DS);
68640- result = vfs_write(file, buffer, str - buffer, &pos);
68641+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
68642 set_fs(old_fs);
68643 if (result < 0)
68644 goto out_kfree;
68645@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
68646 int i;
68647
68648 set_fs(KERNEL_DS);
68649- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
68650+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
68651 set_fs(old_fs);
68652 if (result < 0)
68653 goto out_kfree;
68654@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
68655 }
68656
68657 set_fs(KERNEL_DS);
68658- result = vfs_write(file, buffer, str - buffer, &pos);
68659+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
68660 set_fs(old_fs);
68661 if (result < 0)
68662 goto out_kfree;
68663@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
68664 int i;
68665
68666 set_fs(KERNEL_DS);
68667- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
68668+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
68669 set_fs(old_fs);
68670 if (result < 0)
68671 goto out;
68672@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
68673 __le16 dnaddr;
68674
68675 set_fs(KERNEL_DS);
68676- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
68677+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
68678 set_fs(old_fs);
68679 if (result < 0)
68680 goto out;
68681@@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
68682 le16_to_cpu(dnaddr) & 0x3ff);
68683
68684 set_fs(KERNEL_DS);
68685- result = vfs_write(file, buf, len, &pos);
68686+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
68687 set_fs(old_fs);
68688 if (result < 0)
68689 goto out;
68690diff --git a/kernel/taskstats.c b/kernel/taskstats.c
68691index e660464..c8b9e67 100644
68692--- a/kernel/taskstats.c
68693+++ b/kernel/taskstats.c
68694@@ -27,9 +27,12 @@
68695 #include <linux/cgroup.h>
68696 #include <linux/fs.h>
68697 #include <linux/file.h>
68698+#include <linux/grsecurity.h>
68699 #include <net/genetlink.h>
68700 #include <linux/atomic.h>
68701
68702+extern int gr_is_taskstats_denied(int pid);
68703+
68704 /*
68705 * Maximum length of a cpumask that can be specified in
68706 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
68707@@ -556,6 +559,9 @@ err:
68708
68709 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
68710 {
68711+ if (gr_is_taskstats_denied(current->pid))
68712+ return -EACCES;
68713+
68714 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
68715 return cmd_attr_register_cpumask(info);
68716 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
68717diff --git a/kernel/time.c b/kernel/time.c
68718index ba744cf..267b7c5 100644
68719--- a/kernel/time.c
68720+++ b/kernel/time.c
68721@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
68722 return error;
68723
68724 if (tz) {
68725+ /* we log in do_settimeofday called below, so don't log twice
68726+ */
68727+ if (!tv)
68728+ gr_log_timechange();
68729+
68730 sys_tz = *tz;
68731 update_vsyscall_tz();
68732 if (firsttime) {
68733diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
68734index 8a538c5..def79d4 100644
68735--- a/kernel/time/alarmtimer.c
68736+++ b/kernel/time/alarmtimer.c
68737@@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
68738 struct platform_device *pdev;
68739 int error = 0;
68740 int i;
68741- struct k_clock alarm_clock = {
68742+ static struct k_clock alarm_clock = {
68743 .clock_getres = alarm_clock_getres,
68744 .clock_get = alarm_clock_get,
68745 .timer_create = alarm_timer_create,
68746diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
68747index f113755..ec24223 100644
68748--- a/kernel/time/tick-broadcast.c
68749+++ b/kernel/time/tick-broadcast.c
68750@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
68751 * then clear the broadcast bit.
68752 */
68753 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
68754- int cpu = smp_processor_id();
68755+ cpu = smp_processor_id();
68756
68757 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
68758 tick_broadcast_clear_oneshot(cpu);
68759diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
68760index d42574df..247414c 100644
68761--- a/kernel/time/timekeeping.c
68762+++ b/kernel/time/timekeeping.c
68763@@ -14,6 +14,7 @@
68764 #include <linux/init.h>
68765 #include <linux/mm.h>
68766 #include <linux/sched.h>
68767+#include <linux/grsecurity.h>
68768 #include <linux/syscore_ops.h>
68769 #include <linux/clocksource.h>
68770 #include <linux/jiffies.h>
68771@@ -373,6 +374,8 @@ int do_settimeofday(const struct timespec *tv)
68772 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
68773 return -EINVAL;
68774
68775+ gr_log_timechange();
68776+
68777 write_seqlock_irqsave(&timekeeper.lock, flags);
68778
68779 timekeeping_forward_now();
68780diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
68781index 3258455..f35227d 100644
68782--- a/kernel/time/timer_list.c
68783+++ b/kernel/time/timer_list.c
68784@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
68785
68786 static void print_name_offset(struct seq_file *m, void *sym)
68787 {
68788+#ifdef CONFIG_GRKERNSEC_HIDESYM
68789+ SEQ_printf(m, "<%p>", NULL);
68790+#else
68791 char symname[KSYM_NAME_LEN];
68792
68793 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
68794 SEQ_printf(m, "<%pK>", sym);
68795 else
68796 SEQ_printf(m, "%s", symname);
68797+#endif
68798 }
68799
68800 static void
68801@@ -112,7 +116,11 @@ next_one:
68802 static void
68803 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
68804 {
68805+#ifdef CONFIG_GRKERNSEC_HIDESYM
68806+ SEQ_printf(m, " .base: %p\n", NULL);
68807+#else
68808 SEQ_printf(m, " .base: %pK\n", base);
68809+#endif
68810 SEQ_printf(m, " .index: %d\n",
68811 base->index);
68812 SEQ_printf(m, " .resolution: %Lu nsecs\n",
68813@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
68814 {
68815 struct proc_dir_entry *pe;
68816
68817+#ifdef CONFIG_GRKERNSEC_PROC_ADD
68818+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
68819+#else
68820 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
68821+#endif
68822 if (!pe)
68823 return -ENOMEM;
68824 return 0;
68825diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
68826index 0b537f2..9e71eca 100644
68827--- a/kernel/time/timer_stats.c
68828+++ b/kernel/time/timer_stats.c
68829@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
68830 static unsigned long nr_entries;
68831 static struct entry entries[MAX_ENTRIES];
68832
68833-static atomic_t overflow_count;
68834+static atomic_unchecked_t overflow_count;
68835
68836 /*
68837 * The entries are in a hash-table, for fast lookup:
68838@@ -140,7 +140,7 @@ static void reset_entries(void)
68839 nr_entries = 0;
68840 memset(entries, 0, sizeof(entries));
68841 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
68842- atomic_set(&overflow_count, 0);
68843+ atomic_set_unchecked(&overflow_count, 0);
68844 }
68845
68846 static struct entry *alloc_entry(void)
68847@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
68848 if (likely(entry))
68849 entry->count++;
68850 else
68851- atomic_inc(&overflow_count);
68852+ atomic_inc_unchecked(&overflow_count);
68853
68854 out_unlock:
68855 raw_spin_unlock_irqrestore(lock, flags);
68856@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
68857
68858 static void print_name_offset(struct seq_file *m, unsigned long addr)
68859 {
68860+#ifdef CONFIG_GRKERNSEC_HIDESYM
68861+ seq_printf(m, "<%p>", NULL);
68862+#else
68863 char symname[KSYM_NAME_LEN];
68864
68865 if (lookup_symbol_name(addr, symname) < 0)
68866 seq_printf(m, "<%p>", (void *)addr);
68867 else
68868 seq_printf(m, "%s", symname);
68869+#endif
68870 }
68871
68872 static int tstats_show(struct seq_file *m, void *v)
68873@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
68874
68875 seq_puts(m, "Timer Stats Version: v0.2\n");
68876 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
68877- if (atomic_read(&overflow_count))
68878+ if (atomic_read_unchecked(&overflow_count))
68879 seq_printf(m, "Overflow: %d entries\n",
68880- atomic_read(&overflow_count));
68881+ atomic_read_unchecked(&overflow_count));
68882
68883 for (i = 0; i < nr_entries; i++) {
68884 entry = entries + i;
68885@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
68886 {
68887 struct proc_dir_entry *pe;
68888
68889+#ifdef CONFIG_GRKERNSEC_PROC_ADD
68890+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
68891+#else
68892 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
68893+#endif
68894 if (!pe)
68895 return -ENOMEM;
68896 return 0;
68897diff --git a/kernel/timer.c b/kernel/timer.c
68898index a297ffc..5e16b0b 100644
68899--- a/kernel/timer.c
68900+++ b/kernel/timer.c
68901@@ -1354,7 +1354,7 @@ void update_process_times(int user_tick)
68902 /*
68903 * This function runs timers and the timer-tq in bottom half context.
68904 */
68905-static void run_timer_softirq(struct softirq_action *h)
68906+static void run_timer_softirq(void)
68907 {
68908 struct tvec_base *base = __this_cpu_read(tvec_bases);
68909
68910diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
68911index c0bd030..62a1927 100644
68912--- a/kernel/trace/blktrace.c
68913+++ b/kernel/trace/blktrace.c
68914@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
68915 struct blk_trace *bt = filp->private_data;
68916 char buf[16];
68917
68918- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
68919+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
68920
68921 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
68922 }
68923@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
68924 return 1;
68925
68926 bt = buf->chan->private_data;
68927- atomic_inc(&bt->dropped);
68928+ atomic_inc_unchecked(&bt->dropped);
68929 return 0;
68930 }
68931
68932@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
68933
68934 bt->dir = dir;
68935 bt->dev = dev;
68936- atomic_set(&bt->dropped, 0);
68937+ atomic_set_unchecked(&bt->dropped, 0);
68938
68939 ret = -EIO;
68940 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
68941diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
68942index 0fa92f6..89950b2 100644
68943--- a/kernel/trace/ftrace.c
68944+++ b/kernel/trace/ftrace.c
68945@@ -1800,12 +1800,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
68946 if (unlikely(ftrace_disabled))
68947 return 0;
68948
68949+ ret = ftrace_arch_code_modify_prepare();
68950+ FTRACE_WARN_ON(ret);
68951+ if (ret)
68952+ return 0;
68953+
68954 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
68955+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
68956 if (ret) {
68957 ftrace_bug(ret, ip);
68958- return 0;
68959 }
68960- return 1;
68961+ return ret ? 0 : 1;
68962 }
68963
68964 /*
68965@@ -2917,7 +2922,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
68966
68967 int
68968 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
68969- void *data)
68970+ void *data)
68971 {
68972 struct ftrace_func_probe *entry;
68973 struct ftrace_page *pg;
68974diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
68975index 2a22255..cdcdd06 100644
68976--- a/kernel/trace/trace.c
68977+++ b/kernel/trace/trace.c
68978@@ -4312,10 +4312,9 @@ static const struct file_operations tracing_dyn_info_fops = {
68979 };
68980 #endif
68981
68982-static struct dentry *d_tracer;
68983-
68984 struct dentry *tracing_init_dentry(void)
68985 {
68986+ static struct dentry *d_tracer;
68987 static int once;
68988
68989 if (d_tracer)
68990@@ -4335,10 +4334,9 @@ struct dentry *tracing_init_dentry(void)
68991 return d_tracer;
68992 }
68993
68994-static struct dentry *d_percpu;
68995-
68996 struct dentry *tracing_dentry_percpu(void)
68997 {
68998+ static struct dentry *d_percpu;
68999 static int once;
69000 struct dentry *d_tracer;
69001
69002diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
69003index 29111da..d190fe2 100644
69004--- a/kernel/trace/trace_events.c
69005+++ b/kernel/trace/trace_events.c
69006@@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
69007 struct ftrace_module_file_ops {
69008 struct list_head list;
69009 struct module *mod;
69010- struct file_operations id;
69011- struct file_operations enable;
69012- struct file_operations format;
69013- struct file_operations filter;
69014 };
69015
69016 static struct ftrace_module_file_ops *
69017@@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
69018
69019 file_ops->mod = mod;
69020
69021- file_ops->id = ftrace_event_id_fops;
69022- file_ops->id.owner = mod;
69023-
69024- file_ops->enable = ftrace_enable_fops;
69025- file_ops->enable.owner = mod;
69026-
69027- file_ops->filter = ftrace_event_filter_fops;
69028- file_ops->filter.owner = mod;
69029-
69030- file_ops->format = ftrace_event_format_fops;
69031- file_ops->format.owner = mod;
69032+ pax_open_kernel();
69033+ *(void **)&mod->trace_id.owner = mod;
69034+ *(void **)&mod->trace_enable.owner = mod;
69035+ *(void **)&mod->trace_filter.owner = mod;
69036+ *(void **)&mod->trace_format.owner = mod;
69037+ pax_close_kernel();
69038
69039 list_add(&file_ops->list, &ftrace_module_file_list);
69040
69041@@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
69042
69043 for_each_event(call, start, end) {
69044 __trace_add_event_call(*call, mod,
69045- &file_ops->id, &file_ops->enable,
69046- &file_ops->filter, &file_ops->format);
69047+ &mod->trace_id, &mod->trace_enable,
69048+ &mod->trace_filter, &mod->trace_format);
69049 }
69050 }
69051
69052diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
69053index 580a05e..9b31acb 100644
69054--- a/kernel/trace/trace_kprobe.c
69055+++ b/kernel/trace/trace_kprobe.c
69056@@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69057 long ret;
69058 int maxlen = get_rloc_len(*(u32 *)dest);
69059 u8 *dst = get_rloc_data(dest);
69060- u8 *src = addr;
69061+ const u8 __user *src = (const u8 __force_user *)addr;
69062 mm_segment_t old_fs = get_fs();
69063 if (!maxlen)
69064 return;
69065@@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69066 pagefault_disable();
69067 do
69068 ret = __copy_from_user_inatomic(dst++, src++, 1);
69069- while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
69070+ while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
69071 dst[-1] = '\0';
69072 pagefault_enable();
69073 set_fs(old_fs);
69074@@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69075 ((u8 *)get_rloc_data(dest))[0] = '\0';
69076 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
69077 } else
69078- *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
69079+ *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
69080 get_rloc_offs(*(u32 *)dest));
69081 }
69082 /* Return the length of string -- including null terminal byte */
69083@@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
69084 set_fs(KERNEL_DS);
69085 pagefault_disable();
69086 do {
69087- ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
69088+ ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
69089 len++;
69090 } while (c && ret == 0 && len < MAX_STRING_SIZE);
69091 pagefault_enable();
69092diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
69093index fd3c8aa..5f324a6 100644
69094--- a/kernel/trace/trace_mmiotrace.c
69095+++ b/kernel/trace/trace_mmiotrace.c
69096@@ -24,7 +24,7 @@ struct header_iter {
69097 static struct trace_array *mmio_trace_array;
69098 static bool overrun_detected;
69099 static unsigned long prev_overruns;
69100-static atomic_t dropped_count;
69101+static atomic_unchecked_t dropped_count;
69102
69103 static void mmio_reset_data(struct trace_array *tr)
69104 {
69105@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
69106
69107 static unsigned long count_overruns(struct trace_iterator *iter)
69108 {
69109- unsigned long cnt = atomic_xchg(&dropped_count, 0);
69110+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
69111 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
69112
69113 if (over > prev_overruns)
69114@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
69115 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
69116 sizeof(*entry), 0, pc);
69117 if (!event) {
69118- atomic_inc(&dropped_count);
69119+ atomic_inc_unchecked(&dropped_count);
69120 return;
69121 }
69122 entry = ring_buffer_event_data(event);
69123@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
69124 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
69125 sizeof(*entry), 0, pc);
69126 if (!event) {
69127- atomic_inc(&dropped_count);
69128+ atomic_inc_unchecked(&dropped_count);
69129 return;
69130 }
69131 entry = ring_buffer_event_data(event);
69132diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
69133index df611a0..10d8b32 100644
69134--- a/kernel/trace/trace_output.c
69135+++ b/kernel/trace/trace_output.c
69136@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
69137
69138 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
69139 if (!IS_ERR(p)) {
69140- p = mangle_path(s->buffer + s->len, p, "\n");
69141+ p = mangle_path(s->buffer + s->len, p, "\n\\");
69142 if (p) {
69143 s->len = p - s->buffer;
69144 return 1;
69145diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
69146index d4545f4..a9010a1 100644
69147--- a/kernel/trace/trace_stack.c
69148+++ b/kernel/trace/trace_stack.c
69149@@ -53,7 +53,7 @@ static inline void check_stack(void)
69150 return;
69151
69152 /* we do not handle interrupt stacks yet */
69153- if (!object_is_on_stack(&this_size))
69154+ if (!object_starts_on_stack(&this_size))
69155 return;
69156
69157 local_irq_save(flags);
69158diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
69159index 209b379..7f76423 100644
69160--- a/kernel/trace/trace_workqueue.c
69161+++ b/kernel/trace/trace_workqueue.c
69162@@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
69163 int cpu;
69164 pid_t pid;
69165 /* Can be inserted from interrupt or user context, need to be atomic */
69166- atomic_t inserted;
69167+ atomic_unchecked_t inserted;
69168 /*
69169 * Don't need to be atomic, works are serialized in a single workqueue thread
69170 * on a single CPU.
69171@@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
69172 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
69173 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
69174 if (node->pid == wq_thread->pid) {
69175- atomic_inc(&node->inserted);
69176+ atomic_inc_unchecked(&node->inserted);
69177 goto found;
69178 }
69179 }
69180@@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
69181 tsk = get_pid_task(pid, PIDTYPE_PID);
69182 if (tsk) {
69183 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
69184- atomic_read(&cws->inserted), cws->executed,
69185+ atomic_read_unchecked(&cws->inserted), cws->executed,
69186 tsk->comm);
69187 put_task_struct(tsk);
69188 }
69189diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
69190index 6777153..8519f60 100644
69191--- a/lib/Kconfig.debug
69192+++ b/lib/Kconfig.debug
69193@@ -1132,6 +1132,7 @@ config LATENCYTOP
69194 depends on DEBUG_KERNEL
69195 depends on STACKTRACE_SUPPORT
69196 depends on PROC_FS
69197+ depends on !GRKERNSEC_HIDESYM
69198 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
69199 select KALLSYMS
69200 select KALLSYMS_ALL
69201diff --git a/lib/bitmap.c b/lib/bitmap.c
69202index b5a8b6a..a69623c 100644
69203--- a/lib/bitmap.c
69204+++ b/lib/bitmap.c
69205@@ -421,7 +421,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
69206 {
69207 int c, old_c, totaldigits, ndigits, nchunks, nbits;
69208 u32 chunk;
69209- const char __user __force *ubuf = (const char __user __force *)buf;
69210+ const char __user *ubuf = (const char __force_user *)buf;
69211
69212 bitmap_zero(maskp, nmaskbits);
69213
69214@@ -506,7 +506,7 @@ int bitmap_parse_user(const char __user *ubuf,
69215 {
69216 if (!access_ok(VERIFY_READ, ubuf, ulen))
69217 return -EFAULT;
69218- return __bitmap_parse((const char __force *)ubuf,
69219+ return __bitmap_parse((const char __force_kernel *)ubuf,
69220 ulen, 1, maskp, nmaskbits);
69221
69222 }
69223@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
69224 {
69225 unsigned a, b;
69226 int c, old_c, totaldigits;
69227- const char __user __force *ubuf = (const char __user __force *)buf;
69228+ const char __user *ubuf = (const char __force_user *)buf;
69229 int exp_digit, in_range;
69230
69231 totaldigits = c = 0;
69232@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
69233 {
69234 if (!access_ok(VERIFY_READ, ubuf, ulen))
69235 return -EFAULT;
69236- return __bitmap_parselist((const char __force *)ubuf,
69237+ return __bitmap_parselist((const char __force_kernel *)ubuf,
69238 ulen, 1, maskp, nmaskbits);
69239 }
69240 EXPORT_SYMBOL(bitmap_parselist_user);
69241diff --git a/lib/bug.c b/lib/bug.c
69242index a28c141..2bd3d95 100644
69243--- a/lib/bug.c
69244+++ b/lib/bug.c
69245@@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
69246 return BUG_TRAP_TYPE_NONE;
69247
69248 bug = find_bug(bugaddr);
69249+ if (!bug)
69250+ return BUG_TRAP_TYPE_NONE;
69251
69252 file = NULL;
69253 line = 0;
69254diff --git a/lib/debugobjects.c b/lib/debugobjects.c
69255index 0ab9ae8..f01ceca 100644
69256--- a/lib/debugobjects.c
69257+++ b/lib/debugobjects.c
69258@@ -288,7 +288,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
69259 if (limit > 4)
69260 return;
69261
69262- is_on_stack = object_is_on_stack(addr);
69263+ is_on_stack = object_starts_on_stack(addr);
69264 if (is_on_stack == onstack)
69265 return;
69266
69267diff --git a/lib/devres.c b/lib/devres.c
69268index 80b9c76..9e32279 100644
69269--- a/lib/devres.c
69270+++ b/lib/devres.c
69271@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
69272 void devm_iounmap(struct device *dev, void __iomem *addr)
69273 {
69274 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
69275- (void *)addr));
69276+ (void __force *)addr));
69277 iounmap(addr);
69278 }
69279 EXPORT_SYMBOL(devm_iounmap);
69280@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
69281 {
69282 ioport_unmap(addr);
69283 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
69284- devm_ioport_map_match, (void *)addr));
69285+ devm_ioport_map_match, (void __force *)addr));
69286 }
69287 EXPORT_SYMBOL(devm_ioport_unmap);
69288
69289diff --git a/lib/dma-debug.c b/lib/dma-debug.c
69290index 13ef233..5241683 100644
69291--- a/lib/dma-debug.c
69292+++ b/lib/dma-debug.c
69293@@ -924,7 +924,7 @@ out:
69294
69295 static void check_for_stack(struct device *dev, void *addr)
69296 {
69297- if (object_is_on_stack(addr))
69298+ if (object_starts_on_stack(addr))
69299 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
69300 "stack [addr=%p]\n", addr);
69301 }
69302diff --git a/lib/extable.c b/lib/extable.c
69303index 4cac81e..63e9b8f 100644
69304--- a/lib/extable.c
69305+++ b/lib/extable.c
69306@@ -13,6 +13,7 @@
69307 #include <linux/init.h>
69308 #include <linux/sort.h>
69309 #include <asm/uaccess.h>
69310+#include <asm/pgtable.h>
69311
69312 #ifndef ARCH_HAS_SORT_EXTABLE
69313 /*
69314@@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
69315 void sort_extable(struct exception_table_entry *start,
69316 struct exception_table_entry *finish)
69317 {
69318+ pax_open_kernel();
69319 sort(start, finish - start, sizeof(struct exception_table_entry),
69320 cmp_ex, NULL);
69321+ pax_close_kernel();
69322 }
69323
69324 #ifdef CONFIG_MODULES
69325diff --git a/lib/inflate.c b/lib/inflate.c
69326index 013a761..c28f3fc 100644
69327--- a/lib/inflate.c
69328+++ b/lib/inflate.c
69329@@ -269,7 +269,7 @@ static void free(void *where)
69330 malloc_ptr = free_mem_ptr;
69331 }
69332 #else
69333-#define malloc(a) kmalloc(a, GFP_KERNEL)
69334+#define malloc(a) kmalloc((a), GFP_KERNEL)
69335 #define free(a) kfree(a)
69336 #endif
69337
69338diff --git a/lib/ioremap.c b/lib/ioremap.c
69339index 0c9216c..863bd89 100644
69340--- a/lib/ioremap.c
69341+++ b/lib/ioremap.c
69342@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
69343 unsigned long next;
69344
69345 phys_addr -= addr;
69346- pmd = pmd_alloc(&init_mm, pud, addr);
69347+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
69348 if (!pmd)
69349 return -ENOMEM;
69350 do {
69351@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
69352 unsigned long next;
69353
69354 phys_addr -= addr;
69355- pud = pud_alloc(&init_mm, pgd, addr);
69356+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
69357 if (!pud)
69358 return -ENOMEM;
69359 do {
69360diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
69361index bd2bea9..6b3c95e 100644
69362--- a/lib/is_single_threaded.c
69363+++ b/lib/is_single_threaded.c
69364@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
69365 struct task_struct *p, *t;
69366 bool ret;
69367
69368+ if (!mm)
69369+ return true;
69370+
69371 if (atomic_read(&task->signal->live) != 1)
69372 return false;
69373
69374diff --git a/lib/radix-tree.c b/lib/radix-tree.c
69375index 3ac50dc..240bb7e 100644
69376--- a/lib/radix-tree.c
69377+++ b/lib/radix-tree.c
69378@@ -79,7 +79,7 @@ struct radix_tree_preload {
69379 int nr;
69380 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
69381 };
69382-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
69383+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
69384
69385 static inline void *ptr_to_indirect(void *ptr)
69386 {
69387diff --git a/lib/vsprintf.c b/lib/vsprintf.c
69388index abbabec..362988d 100644
69389--- a/lib/vsprintf.c
69390+++ b/lib/vsprintf.c
69391@@ -16,6 +16,9 @@
69392 * - scnprintf and vscnprintf
69393 */
69394
69395+#ifdef CONFIG_GRKERNSEC_HIDESYM
69396+#define __INCLUDED_BY_HIDESYM 1
69397+#endif
69398 #include <stdarg.h>
69399 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
69400 #include <linux/types.h>
69401@@ -433,7 +436,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
69402 char sym[KSYM_SYMBOL_LEN];
69403 if (ext == 'B')
69404 sprint_backtrace(sym, value);
69405- else if (ext != 'f' && ext != 's')
69406+ else if (ext != 'f' && ext != 's' && ext != 'a')
69407 sprint_symbol(sym, value);
69408 else
69409 kallsyms_lookup(value, NULL, NULL, NULL, sym);
69410@@ -809,7 +812,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
69411 return number(buf, end, *(const netdev_features_t *)addr, spec);
69412 }
69413
69414+#ifdef CONFIG_GRKERNSEC_HIDESYM
69415+int kptr_restrict __read_mostly = 2;
69416+#else
69417 int kptr_restrict __read_mostly;
69418+#endif
69419
69420 /*
69421 * Show a '%p' thing. A kernel extension is that the '%p' is followed
69422@@ -823,6 +830,8 @@ int kptr_restrict __read_mostly;
69423 * - 'S' For symbolic direct pointers with offset
69424 * - 's' For symbolic direct pointers without offset
69425 * - 'B' For backtraced symbolic direct pointers with offset
69426+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
69427+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
69428 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
69429 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
69430 * - 'M' For a 6-byte MAC address, it prints the address in the
69431@@ -868,12 +877,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
69432 {
69433 if (!ptr && *fmt != 'K') {
69434 /*
69435- * Print (null) with the same width as a pointer so it makes
69436+ * Print (nil) with the same width as a pointer so it makes
69437 * tabular output look nice.
69438 */
69439 if (spec.field_width == -1)
69440 spec.field_width = 2 * sizeof(void *);
69441- return string(buf, end, "(null)", spec);
69442+ return string(buf, end, "(nil)", spec);
69443 }
69444
69445 switch (*fmt) {
69446@@ -883,6 +892,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
69447 /* Fallthrough */
69448 case 'S':
69449 case 's':
69450+#ifdef CONFIG_GRKERNSEC_HIDESYM
69451+ break;
69452+#else
69453+ return symbol_string(buf, end, ptr, spec, *fmt);
69454+#endif
69455+ case 'A':
69456+ case 'a':
69457 case 'B':
69458 return symbol_string(buf, end, ptr, spec, *fmt);
69459 case 'R':
69460@@ -1653,11 +1669,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
69461 typeof(type) value; \
69462 if (sizeof(type) == 8) { \
69463 args = PTR_ALIGN(args, sizeof(u32)); \
69464- *(u32 *)&value = *(u32 *)args; \
69465- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
69466+ *(u32 *)&value = *(const u32 *)args; \
69467+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
69468 } else { \
69469 args = PTR_ALIGN(args, sizeof(type)); \
69470- value = *(typeof(type) *)args; \
69471+ value = *(const typeof(type) *)args; \
69472 } \
69473 args += sizeof(type); \
69474 value; \
69475@@ -1720,7 +1736,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
69476 case FORMAT_TYPE_STR: {
69477 const char *str_arg = args;
69478 args += strlen(str_arg) + 1;
69479- str = string(str, end, (char *)str_arg, spec);
69480+ str = string(str, end, str_arg, spec);
69481 break;
69482 }
69483
69484diff --git a/localversion-grsec b/localversion-grsec
69485new file mode 100644
69486index 0000000..7cd6065
69487--- /dev/null
69488+++ b/localversion-grsec
69489@@ -0,0 +1 @@
69490+-grsec
69491diff --git a/mm/Kconfig b/mm/Kconfig
69492index e338407..4210331 100644
69493--- a/mm/Kconfig
69494+++ b/mm/Kconfig
69495@@ -247,10 +247,10 @@ config KSM
69496 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
69497
69498 config DEFAULT_MMAP_MIN_ADDR
69499- int "Low address space to protect from user allocation"
69500+ int "Low address space to protect from user allocation"
69501 depends on MMU
69502- default 4096
69503- help
69504+ default 65536
69505+ help
69506 This is the portion of low virtual memory which should be protected
69507 from userspace allocation. Keeping a user from writing to low pages
69508 can help reduce the impact of kernel NULL pointer bugs.
69509@@ -280,7 +280,7 @@ config MEMORY_FAILURE
69510
69511 config HWPOISON_INJECT
69512 tristate "HWPoison pages injector"
69513- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
69514+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
69515 select PROC_PAGE_MONITOR
69516
69517 config NOMMU_INITIAL_TRIM_EXCESS
69518diff --git a/mm/filemap.c b/mm/filemap.c
69519index 79c4b2b..596b417 100644
69520--- a/mm/filemap.c
69521+++ b/mm/filemap.c
69522@@ -1762,7 +1762,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
69523 struct address_space *mapping = file->f_mapping;
69524
69525 if (!mapping->a_ops->readpage)
69526- return -ENOEXEC;
69527+ return -ENODEV;
69528 file_accessed(file);
69529 vma->vm_ops = &generic_file_vm_ops;
69530 vma->vm_flags |= VM_CAN_NONLINEAR;
69531@@ -2168,6 +2168,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
69532 *pos = i_size_read(inode);
69533
69534 if (limit != RLIM_INFINITY) {
69535+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
69536 if (*pos >= limit) {
69537 send_sig(SIGXFSZ, current, 0);
69538 return -EFBIG;
69539diff --git a/mm/fremap.c b/mm/fremap.c
69540index 9ed4fd4..c42648d 100644
69541--- a/mm/fremap.c
69542+++ b/mm/fremap.c
69543@@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
69544 retry:
69545 vma = find_vma(mm, start);
69546
69547+#ifdef CONFIG_PAX_SEGMEXEC
69548+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
69549+ goto out;
69550+#endif
69551+
69552 /*
69553 * Make sure the vma is shared, that it supports prefaulting,
69554 * and that the remapped range is valid and fully within
69555diff --git a/mm/highmem.c b/mm/highmem.c
69556index 57d82c6..e9e0552 100644
69557--- a/mm/highmem.c
69558+++ b/mm/highmem.c
69559@@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
69560 * So no dangers, even with speculative execution.
69561 */
69562 page = pte_page(pkmap_page_table[i]);
69563+ pax_open_kernel();
69564 pte_clear(&init_mm, (unsigned long)page_address(page),
69565 &pkmap_page_table[i]);
69566-
69567+ pax_close_kernel();
69568 set_page_address(page, NULL);
69569 need_flush = 1;
69570 }
69571@@ -186,9 +187,11 @@ start:
69572 }
69573 }
69574 vaddr = PKMAP_ADDR(last_pkmap_nr);
69575+
69576+ pax_open_kernel();
69577 set_pte_at(&init_mm, vaddr,
69578 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
69579-
69580+ pax_close_kernel();
69581 pkmap_count[last_pkmap_nr] = 1;
69582 set_page_address(page, (void *)vaddr);
69583
69584diff --git a/mm/huge_memory.c b/mm/huge_memory.c
69585index f0e5306..cb9398e 100644
69586--- a/mm/huge_memory.c
69587+++ b/mm/huge_memory.c
69588@@ -733,7 +733,7 @@ out:
69589 * run pte_offset_map on the pmd, if an huge pmd could
69590 * materialize from under us from a different thread.
69591 */
69592- if (unlikely(__pte_alloc(mm, vma, pmd, address)))
69593+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
69594 return VM_FAULT_OOM;
69595 /* if an huge pmd materialized from under us just retry later */
69596 if (unlikely(pmd_trans_huge(*pmd)))
69597diff --git a/mm/hugetlb.c b/mm/hugetlb.c
69598index 263e177..3f36aec 100644
69599--- a/mm/hugetlb.c
69600+++ b/mm/hugetlb.c
69601@@ -2446,6 +2446,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
69602 return 1;
69603 }
69604
69605+#ifdef CONFIG_PAX_SEGMEXEC
69606+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
69607+{
69608+ struct mm_struct *mm = vma->vm_mm;
69609+ struct vm_area_struct *vma_m;
69610+ unsigned long address_m;
69611+ pte_t *ptep_m;
69612+
69613+ vma_m = pax_find_mirror_vma(vma);
69614+ if (!vma_m)
69615+ return;
69616+
69617+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
69618+ address_m = address + SEGMEXEC_TASK_SIZE;
69619+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
69620+ get_page(page_m);
69621+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
69622+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
69623+}
69624+#endif
69625+
69626 /*
69627 * Hugetlb_cow() should be called with page lock of the original hugepage held.
69628 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
69629@@ -2558,6 +2579,11 @@ retry_avoidcopy:
69630 make_huge_pte(vma, new_page, 1));
69631 page_remove_rmap(old_page);
69632 hugepage_add_new_anon_rmap(new_page, vma, address);
69633+
69634+#ifdef CONFIG_PAX_SEGMEXEC
69635+ pax_mirror_huge_pte(vma, address, new_page);
69636+#endif
69637+
69638 /* Make the old page be freed below */
69639 new_page = old_page;
69640 mmu_notifier_invalidate_range_end(mm,
69641@@ -2712,6 +2738,10 @@ retry:
69642 && (vma->vm_flags & VM_SHARED)));
69643 set_huge_pte_at(mm, address, ptep, new_pte);
69644
69645+#ifdef CONFIG_PAX_SEGMEXEC
69646+ pax_mirror_huge_pte(vma, address, page);
69647+#endif
69648+
69649 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
69650 /* Optimization, do the COW without a second fault */
69651 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
69652@@ -2741,6 +2771,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69653 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
69654 struct hstate *h = hstate_vma(vma);
69655
69656+#ifdef CONFIG_PAX_SEGMEXEC
69657+ struct vm_area_struct *vma_m;
69658+#endif
69659+
69660 address &= huge_page_mask(h);
69661
69662 ptep = huge_pte_offset(mm, address);
69663@@ -2754,6 +2788,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69664 VM_FAULT_SET_HINDEX(h - hstates);
69665 }
69666
69667+#ifdef CONFIG_PAX_SEGMEXEC
69668+ vma_m = pax_find_mirror_vma(vma);
69669+ if (vma_m) {
69670+ unsigned long address_m;
69671+
69672+ if (vma->vm_start > vma_m->vm_start) {
69673+ address_m = address;
69674+ address -= SEGMEXEC_TASK_SIZE;
69675+ vma = vma_m;
69676+ h = hstate_vma(vma);
69677+ } else
69678+ address_m = address + SEGMEXEC_TASK_SIZE;
69679+
69680+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
69681+ return VM_FAULT_OOM;
69682+ address_m &= HPAGE_MASK;
69683+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
69684+ }
69685+#endif
69686+
69687 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
69688 if (!ptep)
69689 return VM_FAULT_OOM;
69690diff --git a/mm/internal.h b/mm/internal.h
69691index 2189af4..f2ca332 100644
69692--- a/mm/internal.h
69693+++ b/mm/internal.h
69694@@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
69695 * in mm/page_alloc.c
69696 */
69697 extern void __free_pages_bootmem(struct page *page, unsigned int order);
69698+extern void free_compound_page(struct page *page);
69699 extern void prep_compound_page(struct page *page, unsigned long order);
69700 #ifdef CONFIG_MEMORY_FAILURE
69701 extern bool is_free_buddy_page(struct page *page);
69702diff --git a/mm/kmemleak.c b/mm/kmemleak.c
69703index 45eb621..6ccd8ea 100644
69704--- a/mm/kmemleak.c
69705+++ b/mm/kmemleak.c
69706@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
69707
69708 for (i = 0; i < object->trace_len; i++) {
69709 void *ptr = (void *)object->trace[i];
69710- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
69711+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
69712 }
69713 }
69714
69715diff --git a/mm/maccess.c b/mm/maccess.c
69716index d53adf9..03a24bf 100644
69717--- a/mm/maccess.c
69718+++ b/mm/maccess.c
69719@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
69720 set_fs(KERNEL_DS);
69721 pagefault_disable();
69722 ret = __copy_from_user_inatomic(dst,
69723- (__force const void __user *)src, size);
69724+ (const void __force_user *)src, size);
69725 pagefault_enable();
69726 set_fs(old_fs);
69727
69728@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
69729
69730 set_fs(KERNEL_DS);
69731 pagefault_disable();
69732- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
69733+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
69734 pagefault_enable();
69735 set_fs(old_fs);
69736
69737diff --git a/mm/madvise.c b/mm/madvise.c
69738index 1ccbba5..79e16f9 100644
69739--- a/mm/madvise.c
69740+++ b/mm/madvise.c
69741@@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
69742 pgoff_t pgoff;
69743 unsigned long new_flags = vma->vm_flags;
69744
69745+#ifdef CONFIG_PAX_SEGMEXEC
69746+ struct vm_area_struct *vma_m;
69747+#endif
69748+
69749 switch (behavior) {
69750 case MADV_NORMAL:
69751 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
69752@@ -116,6 +120,13 @@ success:
69753 /*
69754 * vm_flags is protected by the mmap_sem held in write mode.
69755 */
69756+
69757+#ifdef CONFIG_PAX_SEGMEXEC
69758+ vma_m = pax_find_mirror_vma(vma);
69759+ if (vma_m)
69760+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
69761+#endif
69762+
69763 vma->vm_flags = new_flags;
69764
69765 out:
69766@@ -174,6 +185,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
69767 struct vm_area_struct ** prev,
69768 unsigned long start, unsigned long end)
69769 {
69770+
69771+#ifdef CONFIG_PAX_SEGMEXEC
69772+ struct vm_area_struct *vma_m;
69773+#endif
69774+
69775 *prev = vma;
69776 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
69777 return -EINVAL;
69778@@ -186,6 +202,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
69779 zap_page_range(vma, start, end - start, &details);
69780 } else
69781 zap_page_range(vma, start, end - start, NULL);
69782+
69783+#ifdef CONFIG_PAX_SEGMEXEC
69784+ vma_m = pax_find_mirror_vma(vma);
69785+ if (vma_m) {
69786+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
69787+ struct zap_details details = {
69788+ .nonlinear_vma = vma_m,
69789+ .last_index = ULONG_MAX,
69790+ };
69791+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
69792+ } else
69793+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
69794+ }
69795+#endif
69796+
69797 return 0;
69798 }
69799
69800@@ -384,6 +415,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
69801 if (end < start)
69802 goto out;
69803
69804+#ifdef CONFIG_PAX_SEGMEXEC
69805+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
69806+ if (end > SEGMEXEC_TASK_SIZE)
69807+ goto out;
69808+ } else
69809+#endif
69810+
69811+ if (end > TASK_SIZE)
69812+ goto out;
69813+
69814 error = 0;
69815 if (end == start)
69816 goto out;
69817diff --git a/mm/memory-failure.c b/mm/memory-failure.c
69818index 97cc273..6ed703f 100644
69819--- a/mm/memory-failure.c
69820+++ b/mm/memory-failure.c
69821@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
69822
69823 int sysctl_memory_failure_recovery __read_mostly = 1;
69824
69825-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
69826+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
69827
69828 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
69829
69830@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
69831 pfn, t->comm, t->pid);
69832 si.si_signo = SIGBUS;
69833 si.si_errno = 0;
69834- si.si_addr = (void *)addr;
69835+ si.si_addr = (void __user *)addr;
69836 #ifdef __ARCH_SI_TRAPNO
69837 si.si_trapno = trapno;
69838 #endif
69839@@ -1036,7 +1036,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
69840 }
69841
69842 nr_pages = 1 << compound_trans_order(hpage);
69843- atomic_long_add(nr_pages, &mce_bad_pages);
69844+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
69845
69846 /*
69847 * We need/can do nothing about count=0 pages.
69848@@ -1066,7 +1066,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
69849 if (!PageHWPoison(hpage)
69850 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
69851 || (p != hpage && TestSetPageHWPoison(hpage))) {
69852- atomic_long_sub(nr_pages, &mce_bad_pages);
69853+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69854 return 0;
69855 }
69856 set_page_hwpoison_huge_page(hpage);
69857@@ -1124,7 +1124,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
69858 }
69859 if (hwpoison_filter(p)) {
69860 if (TestClearPageHWPoison(p))
69861- atomic_long_sub(nr_pages, &mce_bad_pages);
69862+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69863 unlock_page(hpage);
69864 put_page(hpage);
69865 return 0;
69866@@ -1319,7 +1319,7 @@ int unpoison_memory(unsigned long pfn)
69867 return 0;
69868 }
69869 if (TestClearPageHWPoison(p))
69870- atomic_long_sub(nr_pages, &mce_bad_pages);
69871+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69872 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
69873 return 0;
69874 }
69875@@ -1333,7 +1333,7 @@ int unpoison_memory(unsigned long pfn)
69876 */
69877 if (TestClearPageHWPoison(page)) {
69878 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
69879- atomic_long_sub(nr_pages, &mce_bad_pages);
69880+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69881 freeit = 1;
69882 if (PageHuge(page))
69883 clear_page_hwpoison_huge_page(page);
69884@@ -1446,7 +1446,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
69885 }
69886 done:
69887 if (!PageHWPoison(hpage))
69888- atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
69889+ atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
69890 set_page_hwpoison_huge_page(hpage);
69891 dequeue_hwpoisoned_huge_page(hpage);
69892 /* keep elevated page count for bad page */
69893@@ -1577,7 +1577,7 @@ int soft_offline_page(struct page *page, int flags)
69894 return ret;
69895
69896 done:
69897- atomic_long_add(1, &mce_bad_pages);
69898+ atomic_long_add_unchecked(1, &mce_bad_pages);
69899 SetPageHWPoison(page);
69900 /* keep elevated page count for bad page */
69901 return ret;
69902diff --git a/mm/memory.c b/mm/memory.c
69903index 6105f47..3363489 100644
69904--- a/mm/memory.c
69905+++ b/mm/memory.c
69906@@ -434,8 +434,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
69907 return;
69908
69909 pmd = pmd_offset(pud, start);
69910+
69911+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
69912 pud_clear(pud);
69913 pmd_free_tlb(tlb, pmd, start);
69914+#endif
69915+
69916 }
69917
69918 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
69919@@ -466,9 +470,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
69920 if (end - 1 > ceiling - 1)
69921 return;
69922
69923+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
69924 pud = pud_offset(pgd, start);
69925 pgd_clear(pgd);
69926 pud_free_tlb(tlb, pud, start);
69927+#endif
69928+
69929 }
69930
69931 /*
69932@@ -1597,12 +1604,6 @@ no_page_table:
69933 return page;
69934 }
69935
69936-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
69937-{
69938- return stack_guard_page_start(vma, addr) ||
69939- stack_guard_page_end(vma, addr+PAGE_SIZE);
69940-}
69941-
69942 /**
69943 * __get_user_pages() - pin user pages in memory
69944 * @tsk: task_struct of target task
69945@@ -1675,10 +1676,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69946 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
69947 i = 0;
69948
69949- do {
69950+ while (nr_pages) {
69951 struct vm_area_struct *vma;
69952
69953- vma = find_extend_vma(mm, start);
69954+ vma = find_vma(mm, start);
69955 if (!vma && in_gate_area(mm, start)) {
69956 unsigned long pg = start & PAGE_MASK;
69957 pgd_t *pgd;
69958@@ -1726,7 +1727,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69959 goto next_page;
69960 }
69961
69962- if (!vma ||
69963+ if (!vma || start < vma->vm_start ||
69964 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
69965 !(vm_flags & vma->vm_flags))
69966 return i ? : -EFAULT;
69967@@ -1753,11 +1754,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69968 int ret;
69969 unsigned int fault_flags = 0;
69970
69971- /* For mlock, just skip the stack guard page. */
69972- if (foll_flags & FOLL_MLOCK) {
69973- if (stack_guard_page(vma, start))
69974- goto next_page;
69975- }
69976 if (foll_flags & FOLL_WRITE)
69977 fault_flags |= FAULT_FLAG_WRITE;
69978 if (nonblocking)
69979@@ -1831,7 +1827,7 @@ next_page:
69980 start += PAGE_SIZE;
69981 nr_pages--;
69982 } while (nr_pages && start < vma->vm_end);
69983- } while (nr_pages);
69984+ }
69985 return i;
69986 }
69987 EXPORT_SYMBOL(__get_user_pages);
69988@@ -2038,6 +2034,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
69989 page_add_file_rmap(page);
69990 set_pte_at(mm, addr, pte, mk_pte(page, prot));
69991
69992+#ifdef CONFIG_PAX_SEGMEXEC
69993+ pax_mirror_file_pte(vma, addr, page, ptl);
69994+#endif
69995+
69996 retval = 0;
69997 pte_unmap_unlock(pte, ptl);
69998 return retval;
69999@@ -2072,10 +2072,22 @@ out:
70000 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
70001 struct page *page)
70002 {
70003+
70004+#ifdef CONFIG_PAX_SEGMEXEC
70005+ struct vm_area_struct *vma_m;
70006+#endif
70007+
70008 if (addr < vma->vm_start || addr >= vma->vm_end)
70009 return -EFAULT;
70010 if (!page_count(page))
70011 return -EINVAL;
70012+
70013+#ifdef CONFIG_PAX_SEGMEXEC
70014+ vma_m = pax_find_mirror_vma(vma);
70015+ if (vma_m)
70016+ vma_m->vm_flags |= VM_INSERTPAGE;
70017+#endif
70018+
70019 vma->vm_flags |= VM_INSERTPAGE;
70020 return insert_page(vma, addr, page, vma->vm_page_prot);
70021 }
70022@@ -2161,6 +2173,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
70023 unsigned long pfn)
70024 {
70025 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
70026+ BUG_ON(vma->vm_mirror);
70027
70028 if (addr < vma->vm_start || addr >= vma->vm_end)
70029 return -EFAULT;
70030@@ -2368,7 +2381,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
70031
70032 BUG_ON(pud_huge(*pud));
70033
70034- pmd = pmd_alloc(mm, pud, addr);
70035+ pmd = (mm == &init_mm) ?
70036+ pmd_alloc_kernel(mm, pud, addr) :
70037+ pmd_alloc(mm, pud, addr);
70038 if (!pmd)
70039 return -ENOMEM;
70040 do {
70041@@ -2388,7 +2403,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
70042 unsigned long next;
70043 int err;
70044
70045- pud = pud_alloc(mm, pgd, addr);
70046+ pud = (mm == &init_mm) ?
70047+ pud_alloc_kernel(mm, pgd, addr) :
70048+ pud_alloc(mm, pgd, addr);
70049 if (!pud)
70050 return -ENOMEM;
70051 do {
70052@@ -2476,6 +2493,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
70053 copy_user_highpage(dst, src, va, vma);
70054 }
70055
70056+#ifdef CONFIG_PAX_SEGMEXEC
70057+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
70058+{
70059+ struct mm_struct *mm = vma->vm_mm;
70060+ spinlock_t *ptl;
70061+ pte_t *pte, entry;
70062+
70063+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
70064+ entry = *pte;
70065+ if (!pte_present(entry)) {
70066+ if (!pte_none(entry)) {
70067+ BUG_ON(pte_file(entry));
70068+ free_swap_and_cache(pte_to_swp_entry(entry));
70069+ pte_clear_not_present_full(mm, address, pte, 0);
70070+ }
70071+ } else {
70072+ struct page *page;
70073+
70074+ flush_cache_page(vma, address, pte_pfn(entry));
70075+ entry = ptep_clear_flush(vma, address, pte);
70076+ BUG_ON(pte_dirty(entry));
70077+ page = vm_normal_page(vma, address, entry);
70078+ if (page) {
70079+ update_hiwater_rss(mm);
70080+ if (PageAnon(page))
70081+ dec_mm_counter_fast(mm, MM_ANONPAGES);
70082+ else
70083+ dec_mm_counter_fast(mm, MM_FILEPAGES);
70084+ page_remove_rmap(page);
70085+ page_cache_release(page);
70086+ }
70087+ }
70088+ pte_unmap_unlock(pte, ptl);
70089+}
70090+
70091+/* PaX: if vma is mirrored, synchronize the mirror's PTE
70092+ *
70093+ * the ptl of the lower mapped page is held on entry and is not released on exit
70094+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
70095+ */
70096+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70097+{
70098+ struct mm_struct *mm = vma->vm_mm;
70099+ unsigned long address_m;
70100+ spinlock_t *ptl_m;
70101+ struct vm_area_struct *vma_m;
70102+ pmd_t *pmd_m;
70103+ pte_t *pte_m, entry_m;
70104+
70105+ BUG_ON(!page_m || !PageAnon(page_m));
70106+
70107+ vma_m = pax_find_mirror_vma(vma);
70108+ if (!vma_m)
70109+ return;
70110+
70111+ BUG_ON(!PageLocked(page_m));
70112+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70113+ address_m = address + SEGMEXEC_TASK_SIZE;
70114+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70115+ pte_m = pte_offset_map(pmd_m, address_m);
70116+ ptl_m = pte_lockptr(mm, pmd_m);
70117+ if (ptl != ptl_m) {
70118+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70119+ if (!pte_none(*pte_m))
70120+ goto out;
70121+ }
70122+
70123+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70124+ page_cache_get(page_m);
70125+ page_add_anon_rmap(page_m, vma_m, address_m);
70126+ inc_mm_counter_fast(mm, MM_ANONPAGES);
70127+ set_pte_at(mm, address_m, pte_m, entry_m);
70128+ update_mmu_cache(vma_m, address_m, entry_m);
70129+out:
70130+ if (ptl != ptl_m)
70131+ spin_unlock(ptl_m);
70132+ pte_unmap(pte_m);
70133+ unlock_page(page_m);
70134+}
70135+
70136+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70137+{
70138+ struct mm_struct *mm = vma->vm_mm;
70139+ unsigned long address_m;
70140+ spinlock_t *ptl_m;
70141+ struct vm_area_struct *vma_m;
70142+ pmd_t *pmd_m;
70143+ pte_t *pte_m, entry_m;
70144+
70145+ BUG_ON(!page_m || PageAnon(page_m));
70146+
70147+ vma_m = pax_find_mirror_vma(vma);
70148+ if (!vma_m)
70149+ return;
70150+
70151+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70152+ address_m = address + SEGMEXEC_TASK_SIZE;
70153+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70154+ pte_m = pte_offset_map(pmd_m, address_m);
70155+ ptl_m = pte_lockptr(mm, pmd_m);
70156+ if (ptl != ptl_m) {
70157+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70158+ if (!pte_none(*pte_m))
70159+ goto out;
70160+ }
70161+
70162+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70163+ page_cache_get(page_m);
70164+ page_add_file_rmap(page_m);
70165+ inc_mm_counter_fast(mm, MM_FILEPAGES);
70166+ set_pte_at(mm, address_m, pte_m, entry_m);
70167+ update_mmu_cache(vma_m, address_m, entry_m);
70168+out:
70169+ if (ptl != ptl_m)
70170+ spin_unlock(ptl_m);
70171+ pte_unmap(pte_m);
70172+}
70173+
70174+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
70175+{
70176+ struct mm_struct *mm = vma->vm_mm;
70177+ unsigned long address_m;
70178+ spinlock_t *ptl_m;
70179+ struct vm_area_struct *vma_m;
70180+ pmd_t *pmd_m;
70181+ pte_t *pte_m, entry_m;
70182+
70183+ vma_m = pax_find_mirror_vma(vma);
70184+ if (!vma_m)
70185+ return;
70186+
70187+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70188+ address_m = address + SEGMEXEC_TASK_SIZE;
70189+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70190+ pte_m = pte_offset_map(pmd_m, address_m);
70191+ ptl_m = pte_lockptr(mm, pmd_m);
70192+ if (ptl != ptl_m) {
70193+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70194+ if (!pte_none(*pte_m))
70195+ goto out;
70196+ }
70197+
70198+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
70199+ set_pte_at(mm, address_m, pte_m, entry_m);
70200+out:
70201+ if (ptl != ptl_m)
70202+ spin_unlock(ptl_m);
70203+ pte_unmap(pte_m);
70204+}
70205+
70206+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
70207+{
70208+ struct page *page_m;
70209+ pte_t entry;
70210+
70211+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
70212+ goto out;
70213+
70214+ entry = *pte;
70215+ page_m = vm_normal_page(vma, address, entry);
70216+ if (!page_m)
70217+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
70218+ else if (PageAnon(page_m)) {
70219+ if (pax_find_mirror_vma(vma)) {
70220+ pte_unmap_unlock(pte, ptl);
70221+ lock_page(page_m);
70222+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
70223+ if (pte_same(entry, *pte))
70224+ pax_mirror_anon_pte(vma, address, page_m, ptl);
70225+ else
70226+ unlock_page(page_m);
70227+ }
70228+ } else
70229+ pax_mirror_file_pte(vma, address, page_m, ptl);
70230+
70231+out:
70232+ pte_unmap_unlock(pte, ptl);
70233+}
70234+#endif
70235+
70236 /*
70237 * This routine handles present pages, when users try to write
70238 * to a shared page. It is done by copying the page to a new address
70239@@ -2687,6 +2884,12 @@ gotten:
70240 */
70241 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
70242 if (likely(pte_same(*page_table, orig_pte))) {
70243+
70244+#ifdef CONFIG_PAX_SEGMEXEC
70245+ if (pax_find_mirror_vma(vma))
70246+ BUG_ON(!trylock_page(new_page));
70247+#endif
70248+
70249 if (old_page) {
70250 if (!PageAnon(old_page)) {
70251 dec_mm_counter_fast(mm, MM_FILEPAGES);
70252@@ -2738,6 +2941,10 @@ gotten:
70253 page_remove_rmap(old_page);
70254 }
70255
70256+#ifdef CONFIG_PAX_SEGMEXEC
70257+ pax_mirror_anon_pte(vma, address, new_page, ptl);
70258+#endif
70259+
70260 /* Free the old page.. */
70261 new_page = old_page;
70262 ret |= VM_FAULT_WRITE;
70263@@ -3017,6 +3224,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70264 swap_free(entry);
70265 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
70266 try_to_free_swap(page);
70267+
70268+#ifdef CONFIG_PAX_SEGMEXEC
70269+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
70270+#endif
70271+
70272 unlock_page(page);
70273 if (swapcache) {
70274 /*
70275@@ -3040,6 +3252,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70276
70277 /* No need to invalidate - it was non-present before */
70278 update_mmu_cache(vma, address, page_table);
70279+
70280+#ifdef CONFIG_PAX_SEGMEXEC
70281+ pax_mirror_anon_pte(vma, address, page, ptl);
70282+#endif
70283+
70284 unlock:
70285 pte_unmap_unlock(page_table, ptl);
70286 out:
70287@@ -3059,40 +3276,6 @@ out_release:
70288 }
70289
70290 /*
70291- * This is like a special single-page "expand_{down|up}wards()",
70292- * except we must first make sure that 'address{-|+}PAGE_SIZE'
70293- * doesn't hit another vma.
70294- */
70295-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
70296-{
70297- address &= PAGE_MASK;
70298- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
70299- struct vm_area_struct *prev = vma->vm_prev;
70300-
70301- /*
70302- * Is there a mapping abutting this one below?
70303- *
70304- * That's only ok if it's the same stack mapping
70305- * that has gotten split..
70306- */
70307- if (prev && prev->vm_end == address)
70308- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
70309-
70310- expand_downwards(vma, address - PAGE_SIZE);
70311- }
70312- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
70313- struct vm_area_struct *next = vma->vm_next;
70314-
70315- /* As VM_GROWSDOWN but s/below/above/ */
70316- if (next && next->vm_start == address + PAGE_SIZE)
70317- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
70318-
70319- expand_upwards(vma, address + PAGE_SIZE);
70320- }
70321- return 0;
70322-}
70323-
70324-/*
70325 * We enter with non-exclusive mmap_sem (to exclude vma changes,
70326 * but allow concurrent faults), and pte mapped but not yet locked.
70327 * We return with mmap_sem still held, but pte unmapped and unlocked.
70328@@ -3101,27 +3284,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
70329 unsigned long address, pte_t *page_table, pmd_t *pmd,
70330 unsigned int flags)
70331 {
70332- struct page *page;
70333+ struct page *page = NULL;
70334 spinlock_t *ptl;
70335 pte_t entry;
70336
70337- pte_unmap(page_table);
70338-
70339- /* Check if we need to add a guard page to the stack */
70340- if (check_stack_guard_page(vma, address) < 0)
70341- return VM_FAULT_SIGBUS;
70342-
70343- /* Use the zero-page for reads */
70344 if (!(flags & FAULT_FLAG_WRITE)) {
70345 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
70346 vma->vm_page_prot));
70347- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
70348+ ptl = pte_lockptr(mm, pmd);
70349+ spin_lock(ptl);
70350 if (!pte_none(*page_table))
70351 goto unlock;
70352 goto setpte;
70353 }
70354
70355 /* Allocate our own private page. */
70356+ pte_unmap(page_table);
70357+
70358 if (unlikely(anon_vma_prepare(vma)))
70359 goto oom;
70360 page = alloc_zeroed_user_highpage_movable(vma, address);
70361@@ -3140,6 +3319,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
70362 if (!pte_none(*page_table))
70363 goto release;
70364
70365+#ifdef CONFIG_PAX_SEGMEXEC
70366+ if (pax_find_mirror_vma(vma))
70367+ BUG_ON(!trylock_page(page));
70368+#endif
70369+
70370 inc_mm_counter_fast(mm, MM_ANONPAGES);
70371 page_add_new_anon_rmap(page, vma, address);
70372 setpte:
70373@@ -3147,6 +3331,12 @@ setpte:
70374
70375 /* No need to invalidate - it was non-present before */
70376 update_mmu_cache(vma, address, page_table);
70377+
70378+#ifdef CONFIG_PAX_SEGMEXEC
70379+ if (page)
70380+ pax_mirror_anon_pte(vma, address, page, ptl);
70381+#endif
70382+
70383 unlock:
70384 pte_unmap_unlock(page_table, ptl);
70385 return 0;
70386@@ -3290,6 +3480,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70387 */
70388 /* Only go through if we didn't race with anybody else... */
70389 if (likely(pte_same(*page_table, orig_pte))) {
70390+
70391+#ifdef CONFIG_PAX_SEGMEXEC
70392+ if (anon && pax_find_mirror_vma(vma))
70393+ BUG_ON(!trylock_page(page));
70394+#endif
70395+
70396 flush_icache_page(vma, page);
70397 entry = mk_pte(page, vma->vm_page_prot);
70398 if (flags & FAULT_FLAG_WRITE)
70399@@ -3309,6 +3505,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70400
70401 /* no need to invalidate: a not-present page won't be cached */
70402 update_mmu_cache(vma, address, page_table);
70403+
70404+#ifdef CONFIG_PAX_SEGMEXEC
70405+ if (anon)
70406+ pax_mirror_anon_pte(vma, address, page, ptl);
70407+ else
70408+ pax_mirror_file_pte(vma, address, page, ptl);
70409+#endif
70410+
70411 } else {
70412 if (cow_page)
70413 mem_cgroup_uncharge_page(cow_page);
70414@@ -3462,6 +3666,12 @@ int handle_pte_fault(struct mm_struct *mm,
70415 if (flags & FAULT_FLAG_WRITE)
70416 flush_tlb_fix_spurious_fault(vma, address);
70417 }
70418+
70419+#ifdef CONFIG_PAX_SEGMEXEC
70420+ pax_mirror_pte(vma, address, pte, pmd, ptl);
70421+ return 0;
70422+#endif
70423+
70424 unlock:
70425 pte_unmap_unlock(pte, ptl);
70426 return 0;
70427@@ -3478,6 +3688,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70428 pmd_t *pmd;
70429 pte_t *pte;
70430
70431+#ifdef CONFIG_PAX_SEGMEXEC
70432+ struct vm_area_struct *vma_m;
70433+#endif
70434+
70435 __set_current_state(TASK_RUNNING);
70436
70437 count_vm_event(PGFAULT);
70438@@ -3489,6 +3703,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70439 if (unlikely(is_vm_hugetlb_page(vma)))
70440 return hugetlb_fault(mm, vma, address, flags);
70441
70442+#ifdef CONFIG_PAX_SEGMEXEC
70443+ vma_m = pax_find_mirror_vma(vma);
70444+ if (vma_m) {
70445+ unsigned long address_m;
70446+ pgd_t *pgd_m;
70447+ pud_t *pud_m;
70448+ pmd_t *pmd_m;
70449+
70450+ if (vma->vm_start > vma_m->vm_start) {
70451+ address_m = address;
70452+ address -= SEGMEXEC_TASK_SIZE;
70453+ vma = vma_m;
70454+ } else
70455+ address_m = address + SEGMEXEC_TASK_SIZE;
70456+
70457+ pgd_m = pgd_offset(mm, address_m);
70458+ pud_m = pud_alloc(mm, pgd_m, address_m);
70459+ if (!pud_m)
70460+ return VM_FAULT_OOM;
70461+ pmd_m = pmd_alloc(mm, pud_m, address_m);
70462+ if (!pmd_m)
70463+ return VM_FAULT_OOM;
70464+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
70465+ return VM_FAULT_OOM;
70466+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
70467+ }
70468+#endif
70469+
70470 pgd = pgd_offset(mm, address);
70471 pud = pud_alloc(mm, pgd, address);
70472 if (!pud)
70473@@ -3518,7 +3760,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70474 * run pte_offset_map on the pmd, if an huge pmd could
70475 * materialize from under us from a different thread.
70476 */
70477- if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
70478+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70479 return VM_FAULT_OOM;
70480 /* if an huge pmd materialized from under us just retry later */
70481 if (unlikely(pmd_trans_huge(*pmd)))
70482@@ -3555,6 +3797,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
70483 spin_unlock(&mm->page_table_lock);
70484 return 0;
70485 }
70486+
70487+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
70488+{
70489+ pud_t *new = pud_alloc_one(mm, address);
70490+ if (!new)
70491+ return -ENOMEM;
70492+
70493+ smp_wmb(); /* See comment in __pte_alloc */
70494+
70495+ spin_lock(&mm->page_table_lock);
70496+ if (pgd_present(*pgd)) /* Another has populated it */
70497+ pud_free(mm, new);
70498+ else
70499+ pgd_populate_kernel(mm, pgd, new);
70500+ spin_unlock(&mm->page_table_lock);
70501+ return 0;
70502+}
70503 #endif /* __PAGETABLE_PUD_FOLDED */
70504
70505 #ifndef __PAGETABLE_PMD_FOLDED
70506@@ -3585,6 +3844,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
70507 spin_unlock(&mm->page_table_lock);
70508 return 0;
70509 }
70510+
70511+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
70512+{
70513+ pmd_t *new = pmd_alloc_one(mm, address);
70514+ if (!new)
70515+ return -ENOMEM;
70516+
70517+ smp_wmb(); /* See comment in __pte_alloc */
70518+
70519+ spin_lock(&mm->page_table_lock);
70520+#ifndef __ARCH_HAS_4LEVEL_HACK
70521+ if (pud_present(*pud)) /* Another has populated it */
70522+ pmd_free(mm, new);
70523+ else
70524+ pud_populate_kernel(mm, pud, new);
70525+#else
70526+ if (pgd_present(*pud)) /* Another has populated it */
70527+ pmd_free(mm, new);
70528+ else
70529+ pgd_populate_kernel(mm, pud, new);
70530+#endif /* __ARCH_HAS_4LEVEL_HACK */
70531+ spin_unlock(&mm->page_table_lock);
70532+ return 0;
70533+}
70534 #endif /* __PAGETABLE_PMD_FOLDED */
70535
70536 int make_pages_present(unsigned long addr, unsigned long end)
70537@@ -3622,7 +3905,7 @@ static int __init gate_vma_init(void)
70538 gate_vma.vm_start = FIXADDR_USER_START;
70539 gate_vma.vm_end = FIXADDR_USER_END;
70540 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
70541- gate_vma.vm_page_prot = __P101;
70542+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
70543
70544 return 0;
70545 }
70546diff --git a/mm/mempolicy.c b/mm/mempolicy.c
70547index bf5b485..e44c2cb 100644
70548--- a/mm/mempolicy.c
70549+++ b/mm/mempolicy.c
70550@@ -619,6 +619,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
70551 unsigned long vmstart;
70552 unsigned long vmend;
70553
70554+#ifdef CONFIG_PAX_SEGMEXEC
70555+ struct vm_area_struct *vma_m;
70556+#endif
70557+
70558 vma = find_vma(mm, start);
70559 if (!vma || vma->vm_start > start)
70560 return -EFAULT;
70561@@ -672,6 +676,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
70562 if (err)
70563 goto out;
70564 }
70565+
70566+#ifdef CONFIG_PAX_SEGMEXEC
70567+ vma_m = pax_find_mirror_vma(vma);
70568+ if (vma_m && vma_m->vm_ops && vma_m->vm_ops->set_policy) {
70569+ err = vma_m->vm_ops->set_policy(vma_m, new_pol);
70570+ if (err)
70571+ goto out;
70572+ }
70573+#endif
70574+
70575 }
70576
70577 out:
70578@@ -1105,6 +1119,17 @@ static long do_mbind(unsigned long start, unsigned long len,
70579
70580 if (end < start)
70581 return -EINVAL;
70582+
70583+#ifdef CONFIG_PAX_SEGMEXEC
70584+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
70585+ if (end > SEGMEXEC_TASK_SIZE)
70586+ return -EINVAL;
70587+ } else
70588+#endif
70589+
70590+ if (end > TASK_SIZE)
70591+ return -EINVAL;
70592+
70593 if (end == start)
70594 return 0;
70595
70596@@ -1328,8 +1353,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
70597 */
70598 tcred = __task_cred(task);
70599 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
70600- cred->uid != tcred->suid && cred->uid != tcred->uid &&
70601- !capable(CAP_SYS_NICE)) {
70602+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
70603 rcu_read_unlock();
70604 err = -EPERM;
70605 goto out_put;
70606@@ -1360,6 +1384,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
70607 goto out;
70608 }
70609
70610+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
70611+ if (mm != current->mm &&
70612+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
70613+ mmput(mm);
70614+ err = -EPERM;
70615+ goto out;
70616+ }
70617+#endif
70618+
70619 err = do_migrate_pages(mm, old, new,
70620 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
70621
70622diff --git a/mm/mlock.c b/mm/mlock.c
70623index ef726e8..13e0901 100644
70624--- a/mm/mlock.c
70625+++ b/mm/mlock.c
70626@@ -13,6 +13,7 @@
70627 #include <linux/pagemap.h>
70628 #include <linux/mempolicy.h>
70629 #include <linux/syscalls.h>
70630+#include <linux/security.h>
70631 #include <linux/sched.h>
70632 #include <linux/export.h>
70633 #include <linux/rmap.h>
70634@@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
70635 return -EINVAL;
70636 if (end == start)
70637 return 0;
70638+ if (end > TASK_SIZE)
70639+ return -EINVAL;
70640+
70641 vma = find_vma(current->mm, start);
70642 if (!vma || vma->vm_start > start)
70643 return -ENOMEM;
70644@@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
70645 for (nstart = start ; ; ) {
70646 vm_flags_t newflags;
70647
70648+#ifdef CONFIG_PAX_SEGMEXEC
70649+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
70650+ break;
70651+#endif
70652+
70653 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
70654
70655 newflags = vma->vm_flags | VM_LOCKED;
70656@@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
70657 lock_limit >>= PAGE_SHIFT;
70658
70659 /* check against resource limits */
70660+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
70661 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
70662 error = do_mlock(start, len, 1);
70663 up_write(&current->mm->mmap_sem);
70664@@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
70665 static int do_mlockall(int flags)
70666 {
70667 struct vm_area_struct * vma, * prev = NULL;
70668- unsigned int def_flags = 0;
70669
70670 if (flags & MCL_FUTURE)
70671- def_flags = VM_LOCKED;
70672- current->mm->def_flags = def_flags;
70673+ current->mm->def_flags |= VM_LOCKED;
70674+ else
70675+ current->mm->def_flags &= ~VM_LOCKED;
70676 if (flags == MCL_FUTURE)
70677 goto out;
70678
70679 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
70680 vm_flags_t newflags;
70681
70682+#ifdef CONFIG_PAX_SEGMEXEC
70683+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
70684+ break;
70685+#endif
70686+
70687+ BUG_ON(vma->vm_end > TASK_SIZE);
70688 newflags = vma->vm_flags | VM_LOCKED;
70689 if (!(flags & MCL_CURRENT))
70690 newflags &= ~VM_LOCKED;
70691@@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
70692 lock_limit >>= PAGE_SHIFT;
70693
70694 ret = -ENOMEM;
70695+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
70696 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
70697 capable(CAP_IPC_LOCK))
70698 ret = do_mlockall(flags);
70699diff --git a/mm/mmap.c b/mm/mmap.c
70700index 848ef52..d2b586c 100644
70701--- a/mm/mmap.c
70702+++ b/mm/mmap.c
70703@@ -46,6 +46,16 @@
70704 #define arch_rebalance_pgtables(addr, len) (addr)
70705 #endif
70706
70707+static inline void verify_mm_writelocked(struct mm_struct *mm)
70708+{
70709+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
70710+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
70711+ up_read(&mm->mmap_sem);
70712+ BUG();
70713+ }
70714+#endif
70715+}
70716+
70717 static void unmap_region(struct mm_struct *mm,
70718 struct vm_area_struct *vma, struct vm_area_struct *prev,
70719 unsigned long start, unsigned long end);
70720@@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
70721 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
70722 *
70723 */
70724-pgprot_t protection_map[16] = {
70725+pgprot_t protection_map[16] __read_only = {
70726 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
70727 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
70728 };
70729
70730-pgprot_t vm_get_page_prot(unsigned long vm_flags)
70731+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
70732 {
70733- return __pgprot(pgprot_val(protection_map[vm_flags &
70734+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
70735 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
70736 pgprot_val(arch_vm_get_page_prot(vm_flags)));
70737+
70738+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70739+ if (!(__supported_pte_mask & _PAGE_NX) &&
70740+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
70741+ (vm_flags & (VM_READ | VM_WRITE)))
70742+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
70743+#endif
70744+
70745+ return prot;
70746 }
70747 EXPORT_SYMBOL(vm_get_page_prot);
70748
70749 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
70750 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
70751 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
70752+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
70753 /*
70754 * Make sure vm_committed_as in one cacheline and not cacheline shared with
70755 * other variables. It can be updated by several CPUs frequently.
70756@@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
70757 struct vm_area_struct *next = vma->vm_next;
70758
70759 might_sleep();
70760+ BUG_ON(vma->vm_mirror);
70761 if (vma->vm_ops && vma->vm_ops->close)
70762 vma->vm_ops->close(vma);
70763 if (vma->vm_file) {
70764@@ -274,6 +295,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
70765 * not page aligned -Ram Gupta
70766 */
70767 rlim = rlimit(RLIMIT_DATA);
70768+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
70769 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
70770 (mm->end_data - mm->start_data) > rlim)
70771 goto out;
70772@@ -690,6 +712,12 @@ static int
70773 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
70774 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
70775 {
70776+
70777+#ifdef CONFIG_PAX_SEGMEXEC
70778+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
70779+ return 0;
70780+#endif
70781+
70782 if (is_mergeable_vma(vma, file, vm_flags) &&
70783 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
70784 if (vma->vm_pgoff == vm_pgoff)
70785@@ -709,6 +737,12 @@ static int
70786 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
70787 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
70788 {
70789+
70790+#ifdef CONFIG_PAX_SEGMEXEC
70791+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
70792+ return 0;
70793+#endif
70794+
70795 if (is_mergeable_vma(vma, file, vm_flags) &&
70796 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
70797 pgoff_t vm_pglen;
70798@@ -751,13 +785,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
70799 struct vm_area_struct *vma_merge(struct mm_struct *mm,
70800 struct vm_area_struct *prev, unsigned long addr,
70801 unsigned long end, unsigned long vm_flags,
70802- struct anon_vma *anon_vma, struct file *file,
70803+ struct anon_vma *anon_vma, struct file *file,
70804 pgoff_t pgoff, struct mempolicy *policy)
70805 {
70806 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
70807 struct vm_area_struct *area, *next;
70808 int err;
70809
70810+#ifdef CONFIG_PAX_SEGMEXEC
70811+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
70812+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
70813+
70814+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
70815+#endif
70816+
70817 /*
70818 * We later require that vma->vm_flags == vm_flags,
70819 * so this tests vma->vm_flags & VM_SPECIAL, too.
70820@@ -773,6 +814,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70821 if (next && next->vm_end == end) /* cases 6, 7, 8 */
70822 next = next->vm_next;
70823
70824+#ifdef CONFIG_PAX_SEGMEXEC
70825+ if (prev)
70826+ prev_m = pax_find_mirror_vma(prev);
70827+ if (area)
70828+ area_m = pax_find_mirror_vma(area);
70829+ if (next)
70830+ next_m = pax_find_mirror_vma(next);
70831+#endif
70832+
70833 /*
70834 * Can it merge with the predecessor?
70835 */
70836@@ -792,9 +842,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70837 /* cases 1, 6 */
70838 err = vma_adjust(prev, prev->vm_start,
70839 next->vm_end, prev->vm_pgoff, NULL);
70840- } else /* cases 2, 5, 7 */
70841+
70842+#ifdef CONFIG_PAX_SEGMEXEC
70843+ if (!err && prev_m)
70844+ err = vma_adjust(prev_m, prev_m->vm_start,
70845+ next_m->vm_end, prev_m->vm_pgoff, NULL);
70846+#endif
70847+
70848+ } else { /* cases 2, 5, 7 */
70849 err = vma_adjust(prev, prev->vm_start,
70850 end, prev->vm_pgoff, NULL);
70851+
70852+#ifdef CONFIG_PAX_SEGMEXEC
70853+ if (!err && prev_m)
70854+ err = vma_adjust(prev_m, prev_m->vm_start,
70855+ end_m, prev_m->vm_pgoff, NULL);
70856+#endif
70857+
70858+ }
70859 if (err)
70860 return NULL;
70861 khugepaged_enter_vma_merge(prev);
70862@@ -808,12 +873,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70863 mpol_equal(policy, vma_policy(next)) &&
70864 can_vma_merge_before(next, vm_flags,
70865 anon_vma, file, pgoff+pglen)) {
70866- if (prev && addr < prev->vm_end) /* case 4 */
70867+ if (prev && addr < prev->vm_end) { /* case 4 */
70868 err = vma_adjust(prev, prev->vm_start,
70869 addr, prev->vm_pgoff, NULL);
70870- else /* cases 3, 8 */
70871+
70872+#ifdef CONFIG_PAX_SEGMEXEC
70873+ if (!err && prev_m)
70874+ err = vma_adjust(prev_m, prev_m->vm_start,
70875+ addr_m, prev_m->vm_pgoff, NULL);
70876+#endif
70877+
70878+ } else { /* cases 3, 8 */
70879 err = vma_adjust(area, addr, next->vm_end,
70880 next->vm_pgoff - pglen, NULL);
70881+
70882+#ifdef CONFIG_PAX_SEGMEXEC
70883+ if (!err && area_m)
70884+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
70885+ next_m->vm_pgoff - pglen, NULL);
70886+#endif
70887+
70888+ }
70889 if (err)
70890 return NULL;
70891 khugepaged_enter_vma_merge(area);
70892@@ -922,14 +1002,11 @@ none:
70893 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
70894 struct file *file, long pages)
70895 {
70896- const unsigned long stack_flags
70897- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
70898-
70899 if (file) {
70900 mm->shared_vm += pages;
70901 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
70902 mm->exec_vm += pages;
70903- } else if (flags & stack_flags)
70904+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
70905 mm->stack_vm += pages;
70906 if (flags & (VM_RESERVED|VM_IO))
70907 mm->reserved_vm += pages;
70908@@ -969,7 +1046,7 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70909 * (the exception is when the underlying filesystem is noexec
70910 * mounted, in which case we dont add PROT_EXEC.)
70911 */
70912- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
70913+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
70914 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
70915 prot |= PROT_EXEC;
70916
70917@@ -995,7 +1072,7 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70918 /* Obtain the address to map to. we verify (or select) it and ensure
70919 * that it represents a valid section of the address space.
70920 */
70921- addr = get_unmapped_area(file, addr, len, pgoff, flags);
70922+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
70923 if (addr & ~PAGE_MASK)
70924 return addr;
70925
70926@@ -1006,6 +1083,36 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70927 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
70928 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
70929
70930+#ifdef CONFIG_PAX_MPROTECT
70931+ if (mm->pax_flags & MF_PAX_MPROTECT) {
70932+#ifndef CONFIG_PAX_MPROTECT_COMPAT
70933+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
70934+ gr_log_rwxmmap(file);
70935+
70936+#ifdef CONFIG_PAX_EMUPLT
70937+ vm_flags &= ~VM_EXEC;
70938+#else
70939+ return -EPERM;
70940+#endif
70941+
70942+ }
70943+
70944+ if (!(vm_flags & VM_EXEC))
70945+ vm_flags &= ~VM_MAYEXEC;
70946+#else
70947+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
70948+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
70949+#endif
70950+ else
70951+ vm_flags &= ~VM_MAYWRITE;
70952+ }
70953+#endif
70954+
70955+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70956+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
70957+ vm_flags &= ~VM_PAGEEXEC;
70958+#endif
70959+
70960 if (flags & MAP_LOCKED)
70961 if (!can_do_mlock())
70962 return -EPERM;
70963@@ -1017,6 +1124,7 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70964 locked += mm->locked_vm;
70965 lock_limit = rlimit(RLIMIT_MEMLOCK);
70966 lock_limit >>= PAGE_SHIFT;
70967+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
70968 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
70969 return -EAGAIN;
70970 }
70971@@ -1087,6 +1195,9 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70972 if (error)
70973 return error;
70974
70975+ if (!gr_acl_handle_mmap(file, prot))
70976+ return -EACCES;
70977+
70978 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
70979 }
70980
70981@@ -1192,7 +1303,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
70982 vm_flags_t vm_flags = vma->vm_flags;
70983
70984 /* If it was private or non-writable, the write bit is already clear */
70985- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
70986+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
70987 return 0;
70988
70989 /* The backer wishes to know when pages are first written to? */
70990@@ -1241,14 +1352,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
70991 unsigned long charged = 0;
70992 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
70993
70994+#ifdef CONFIG_PAX_SEGMEXEC
70995+ struct vm_area_struct *vma_m = NULL;
70996+#endif
70997+
70998+ /*
70999+ * mm->mmap_sem is required to protect against another thread
71000+ * changing the mappings in case we sleep.
71001+ */
71002+ verify_mm_writelocked(mm);
71003+
71004 /* Clear old maps */
71005 error = -ENOMEM;
71006-munmap_back:
71007 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71008 if (vma && vma->vm_start < addr + len) {
71009 if (do_munmap(mm, addr, len))
71010 return -ENOMEM;
71011- goto munmap_back;
71012+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71013+ BUG_ON(vma && vma->vm_start < addr + len);
71014 }
71015
71016 /* Check against address space limit. */
71017@@ -1297,6 +1418,16 @@ munmap_back:
71018 goto unacct_error;
71019 }
71020
71021+#ifdef CONFIG_PAX_SEGMEXEC
71022+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
71023+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71024+ if (!vma_m) {
71025+ error = -ENOMEM;
71026+ goto free_vma;
71027+ }
71028+ }
71029+#endif
71030+
71031 vma->vm_mm = mm;
71032 vma->vm_start = addr;
71033 vma->vm_end = addr + len;
71034@@ -1321,6 +1452,19 @@ munmap_back:
71035 error = file->f_op->mmap(file, vma);
71036 if (error)
71037 goto unmap_and_free_vma;
71038+
71039+#ifdef CONFIG_PAX_SEGMEXEC
71040+ if (vma_m && (vm_flags & VM_EXECUTABLE))
71041+ added_exe_file_vma(mm);
71042+#endif
71043+
71044+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71045+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
71046+ vma->vm_flags |= VM_PAGEEXEC;
71047+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
71048+ }
71049+#endif
71050+
71051 if (vm_flags & VM_EXECUTABLE)
71052 added_exe_file_vma(mm);
71053
71054@@ -1358,6 +1502,11 @@ munmap_back:
71055 vma_link(mm, vma, prev, rb_link, rb_parent);
71056 file = vma->vm_file;
71057
71058+#ifdef CONFIG_PAX_SEGMEXEC
71059+ if (vma_m)
71060+ BUG_ON(pax_mirror_vma(vma_m, vma));
71061+#endif
71062+
71063 /* Once vma denies write, undo our temporary denial count */
71064 if (correct_wcount)
71065 atomic_inc(&inode->i_writecount);
71066@@ -1366,6 +1515,7 @@ out:
71067
71068 mm->total_vm += len >> PAGE_SHIFT;
71069 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
71070+ track_exec_limit(mm, addr, addr + len, vm_flags);
71071 if (vm_flags & VM_LOCKED) {
71072 if (!mlock_vma_pages_range(vma, addr, addr + len))
71073 mm->locked_vm += (len >> PAGE_SHIFT);
71074@@ -1383,6 +1533,12 @@ unmap_and_free_vma:
71075 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
71076 charged = 0;
71077 free_vma:
71078+
71079+#ifdef CONFIG_PAX_SEGMEXEC
71080+ if (vma_m)
71081+ kmem_cache_free(vm_area_cachep, vma_m);
71082+#endif
71083+
71084 kmem_cache_free(vm_area_cachep, vma);
71085 unacct_error:
71086 if (charged)
71087@@ -1390,6 +1546,44 @@ unacct_error:
71088 return error;
71089 }
71090
71091+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
71092+{
71093+ if (!vma) {
71094+#ifdef CONFIG_STACK_GROWSUP
71095+ if (addr > sysctl_heap_stack_gap)
71096+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
71097+ else
71098+ vma = find_vma(current->mm, 0);
71099+ if (vma && (vma->vm_flags & VM_GROWSUP))
71100+ return false;
71101+#endif
71102+ return true;
71103+ }
71104+
71105+ if (addr + len > vma->vm_start)
71106+ return false;
71107+
71108+ if (vma->vm_flags & VM_GROWSDOWN)
71109+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
71110+#ifdef CONFIG_STACK_GROWSUP
71111+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
71112+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
71113+#endif
71114+
71115+ return true;
71116+}
71117+
71118+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
71119+{
71120+ if (vma->vm_start < len)
71121+ return -ENOMEM;
71122+ if (!(vma->vm_flags & VM_GROWSDOWN))
71123+ return vma->vm_start - len;
71124+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
71125+ return vma->vm_start - len - sysctl_heap_stack_gap;
71126+ return -ENOMEM;
71127+}
71128+
71129 /* Get an address range which is currently unmapped.
71130 * For shmat() with addr=0.
71131 *
71132@@ -1416,18 +1610,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
71133 if (flags & MAP_FIXED)
71134 return addr;
71135
71136+#ifdef CONFIG_PAX_RANDMMAP
71137+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71138+#endif
71139+
71140 if (addr) {
71141 addr = PAGE_ALIGN(addr);
71142- vma = find_vma(mm, addr);
71143- if (TASK_SIZE - len >= addr &&
71144- (!vma || addr + len <= vma->vm_start))
71145- return addr;
71146+ if (TASK_SIZE - len >= addr) {
71147+ vma = find_vma(mm, addr);
71148+ if (check_heap_stack_gap(vma, addr, len))
71149+ return addr;
71150+ }
71151 }
71152 if (len > mm->cached_hole_size) {
71153- start_addr = addr = mm->free_area_cache;
71154+ start_addr = addr = mm->free_area_cache;
71155 } else {
71156- start_addr = addr = TASK_UNMAPPED_BASE;
71157- mm->cached_hole_size = 0;
71158+ start_addr = addr = mm->mmap_base;
71159+ mm->cached_hole_size = 0;
71160 }
71161
71162 full_search:
71163@@ -1438,34 +1637,40 @@ full_search:
71164 * Start a new search - just in case we missed
71165 * some holes.
71166 */
71167- if (start_addr != TASK_UNMAPPED_BASE) {
71168- addr = TASK_UNMAPPED_BASE;
71169- start_addr = addr;
71170+ if (start_addr != mm->mmap_base) {
71171+ start_addr = addr = mm->mmap_base;
71172 mm->cached_hole_size = 0;
71173 goto full_search;
71174 }
71175 return -ENOMEM;
71176 }
71177- if (!vma || addr + len <= vma->vm_start) {
71178- /*
71179- * Remember the place where we stopped the search:
71180- */
71181- mm->free_area_cache = addr + len;
71182- return addr;
71183- }
71184+ if (check_heap_stack_gap(vma, addr, len))
71185+ break;
71186 if (addr + mm->cached_hole_size < vma->vm_start)
71187 mm->cached_hole_size = vma->vm_start - addr;
71188 addr = vma->vm_end;
71189 }
71190+
71191+ /*
71192+ * Remember the place where we stopped the search:
71193+ */
71194+ mm->free_area_cache = addr + len;
71195+ return addr;
71196 }
71197 #endif
71198
71199 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
71200 {
71201+
71202+#ifdef CONFIG_PAX_SEGMEXEC
71203+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71204+ return;
71205+#endif
71206+
71207 /*
71208 * Is this a new hole at the lowest possible address?
71209 */
71210- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
71211+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
71212 mm->free_area_cache = addr;
71213 }
71214
71215@@ -1481,7 +1686,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71216 {
71217 struct vm_area_struct *vma;
71218 struct mm_struct *mm = current->mm;
71219- unsigned long addr = addr0, start_addr;
71220+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
71221
71222 /* requested length too big for entire address space */
71223 if (len > TASK_SIZE)
71224@@ -1490,13 +1695,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71225 if (flags & MAP_FIXED)
71226 return addr;
71227
71228+#ifdef CONFIG_PAX_RANDMMAP
71229+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71230+#endif
71231+
71232 /* requesting a specific address */
71233 if (addr) {
71234 addr = PAGE_ALIGN(addr);
71235- vma = find_vma(mm, addr);
71236- if (TASK_SIZE - len >= addr &&
71237- (!vma || addr + len <= vma->vm_start))
71238- return addr;
71239+ if (TASK_SIZE - len >= addr) {
71240+ vma = find_vma(mm, addr);
71241+ if (check_heap_stack_gap(vma, addr, len))
71242+ return addr;
71243+ }
71244 }
71245
71246 /* check if free_area_cache is useful for us */
71247@@ -1520,7 +1730,7 @@ try_again:
71248 * return with success:
71249 */
71250 vma = find_vma(mm, addr);
71251- if (!vma || addr+len <= vma->vm_start)
71252+ if (check_heap_stack_gap(vma, addr, len))
71253 /* remember the address as a hint for next time */
71254 return (mm->free_area_cache = addr);
71255
71256@@ -1529,8 +1739,8 @@ try_again:
71257 mm->cached_hole_size = vma->vm_start - addr;
71258
71259 /* try just below the current vma->vm_start */
71260- addr = vma->vm_start-len;
71261- } while (len < vma->vm_start);
71262+ addr = skip_heap_stack_gap(vma, len);
71263+ } while (!IS_ERR_VALUE(addr));
71264
71265 fail:
71266 /*
71267@@ -1553,13 +1763,21 @@ fail:
71268 * can happen with large stack limits and large mmap()
71269 * allocations.
71270 */
71271+ mm->mmap_base = TASK_UNMAPPED_BASE;
71272+
71273+#ifdef CONFIG_PAX_RANDMMAP
71274+ if (mm->pax_flags & MF_PAX_RANDMMAP)
71275+ mm->mmap_base += mm->delta_mmap;
71276+#endif
71277+
71278+ mm->free_area_cache = mm->mmap_base;
71279 mm->cached_hole_size = ~0UL;
71280- mm->free_area_cache = TASK_UNMAPPED_BASE;
71281 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
71282 /*
71283 * Restore the topdown base:
71284 */
71285- mm->free_area_cache = mm->mmap_base;
71286+ mm->mmap_base = base;
71287+ mm->free_area_cache = base;
71288 mm->cached_hole_size = ~0UL;
71289
71290 return addr;
71291@@ -1568,6 +1786,12 @@ fail:
71292
71293 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
71294 {
71295+
71296+#ifdef CONFIG_PAX_SEGMEXEC
71297+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71298+ return;
71299+#endif
71300+
71301 /*
71302 * Is this a new hole at the highest possible address?
71303 */
71304@@ -1575,8 +1799,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
71305 mm->free_area_cache = addr;
71306
71307 /* dont allow allocations above current base */
71308- if (mm->free_area_cache > mm->mmap_base)
71309+ if (mm->free_area_cache > mm->mmap_base) {
71310 mm->free_area_cache = mm->mmap_base;
71311+ mm->cached_hole_size = ~0UL;
71312+ }
71313 }
71314
71315 unsigned long
71316@@ -1672,6 +1898,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
71317 return vma;
71318 }
71319
71320+#ifdef CONFIG_PAX_SEGMEXEC
71321+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
71322+{
71323+ struct vm_area_struct *vma_m;
71324+
71325+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
71326+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
71327+ BUG_ON(vma->vm_mirror);
71328+ return NULL;
71329+ }
71330+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
71331+ vma_m = vma->vm_mirror;
71332+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
71333+ BUG_ON(vma->vm_file != vma_m->vm_file);
71334+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
71335+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
71336+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
71337+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
71338+ return vma_m;
71339+}
71340+#endif
71341+
71342 /*
71343 * Verify that the stack growth is acceptable and
71344 * update accounting. This is shared with both the
71345@@ -1688,6 +1936,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71346 return -ENOMEM;
71347
71348 /* Stack limit test */
71349+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
71350 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
71351 return -ENOMEM;
71352
71353@@ -1698,6 +1947,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71354 locked = mm->locked_vm + grow;
71355 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
71356 limit >>= PAGE_SHIFT;
71357+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
71358 if (locked > limit && !capable(CAP_IPC_LOCK))
71359 return -ENOMEM;
71360 }
71361@@ -1728,37 +1978,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71362 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
71363 * vma is the last one with address > vma->vm_end. Have to extend vma.
71364 */
71365+#ifndef CONFIG_IA64
71366+static
71367+#endif
71368 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
71369 {
71370 int error;
71371+ bool locknext;
71372
71373 if (!(vma->vm_flags & VM_GROWSUP))
71374 return -EFAULT;
71375
71376+ /* Also guard against wrapping around to address 0. */
71377+ if (address < PAGE_ALIGN(address+1))
71378+ address = PAGE_ALIGN(address+1);
71379+ else
71380+ return -ENOMEM;
71381+
71382 /*
71383 * We must make sure the anon_vma is allocated
71384 * so that the anon_vma locking is not a noop.
71385 */
71386 if (unlikely(anon_vma_prepare(vma)))
71387 return -ENOMEM;
71388+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
71389+ if (locknext && anon_vma_prepare(vma->vm_next))
71390+ return -ENOMEM;
71391 vma_lock_anon_vma(vma);
71392+ if (locknext)
71393+ vma_lock_anon_vma(vma->vm_next);
71394
71395 /*
71396 * vma->vm_start/vm_end cannot change under us because the caller
71397 * is required to hold the mmap_sem in read mode. We need the
71398- * anon_vma lock to serialize against concurrent expand_stacks.
71399- * Also guard against wrapping around to address 0.
71400+ * anon_vma locks to serialize against concurrent expand_stacks
71401+ * and expand_upwards.
71402 */
71403- if (address < PAGE_ALIGN(address+4))
71404- address = PAGE_ALIGN(address+4);
71405- else {
71406- vma_unlock_anon_vma(vma);
71407- return -ENOMEM;
71408- }
71409 error = 0;
71410
71411 /* Somebody else might have raced and expanded it already */
71412- if (address > vma->vm_end) {
71413+ 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)
71414+ error = -ENOMEM;
71415+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
71416 unsigned long size, grow;
71417
71418 size = address - vma->vm_start;
71419@@ -1773,6 +2034,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
71420 }
71421 }
71422 }
71423+ if (locknext)
71424+ vma_unlock_anon_vma(vma->vm_next);
71425 vma_unlock_anon_vma(vma);
71426 khugepaged_enter_vma_merge(vma);
71427 return error;
71428@@ -1786,6 +2049,8 @@ int expand_downwards(struct vm_area_struct *vma,
71429 unsigned long address)
71430 {
71431 int error;
71432+ bool lockprev = false;
71433+ struct vm_area_struct *prev;
71434
71435 /*
71436 * We must make sure the anon_vma is allocated
71437@@ -1799,6 +2064,15 @@ int expand_downwards(struct vm_area_struct *vma,
71438 if (error)
71439 return error;
71440
71441+ prev = vma->vm_prev;
71442+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
71443+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
71444+#endif
71445+ if (lockprev && anon_vma_prepare(prev))
71446+ return -ENOMEM;
71447+ if (lockprev)
71448+ vma_lock_anon_vma(prev);
71449+
71450 vma_lock_anon_vma(vma);
71451
71452 /*
71453@@ -1808,9 +2082,17 @@ int expand_downwards(struct vm_area_struct *vma,
71454 */
71455
71456 /* Somebody else might have raced and expanded it already */
71457- if (address < vma->vm_start) {
71458+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
71459+ error = -ENOMEM;
71460+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
71461 unsigned long size, grow;
71462
71463+#ifdef CONFIG_PAX_SEGMEXEC
71464+ struct vm_area_struct *vma_m;
71465+
71466+ vma_m = pax_find_mirror_vma(vma);
71467+#endif
71468+
71469 size = vma->vm_end - address;
71470 grow = (vma->vm_start - address) >> PAGE_SHIFT;
71471
71472@@ -1820,11 +2102,22 @@ int expand_downwards(struct vm_area_struct *vma,
71473 if (!error) {
71474 vma->vm_start = address;
71475 vma->vm_pgoff -= grow;
71476+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
71477+
71478+#ifdef CONFIG_PAX_SEGMEXEC
71479+ if (vma_m) {
71480+ vma_m->vm_start -= grow << PAGE_SHIFT;
71481+ vma_m->vm_pgoff -= grow;
71482+ }
71483+#endif
71484+
71485 perf_event_mmap(vma);
71486 }
71487 }
71488 }
71489 vma_unlock_anon_vma(vma);
71490+ if (lockprev)
71491+ vma_unlock_anon_vma(prev);
71492 khugepaged_enter_vma_merge(vma);
71493 return error;
71494 }
71495@@ -1894,6 +2187,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
71496 do {
71497 long nrpages = vma_pages(vma);
71498
71499+#ifdef CONFIG_PAX_SEGMEXEC
71500+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
71501+ vma = remove_vma(vma);
71502+ continue;
71503+ }
71504+#endif
71505+
71506 mm->total_vm -= nrpages;
71507 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
71508 vma = remove_vma(vma);
71509@@ -1939,6 +2239,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
71510 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
71511 vma->vm_prev = NULL;
71512 do {
71513+
71514+#ifdef CONFIG_PAX_SEGMEXEC
71515+ if (vma->vm_mirror) {
71516+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
71517+ vma->vm_mirror->vm_mirror = NULL;
71518+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
71519+ vma->vm_mirror = NULL;
71520+ }
71521+#endif
71522+
71523 rb_erase(&vma->vm_rb, &mm->mm_rb);
71524 mm->map_count--;
71525 tail_vma = vma;
71526@@ -1967,14 +2277,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71527 struct vm_area_struct *new;
71528 int err = -ENOMEM;
71529
71530+#ifdef CONFIG_PAX_SEGMEXEC
71531+ struct vm_area_struct *vma_m, *new_m = NULL;
71532+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
71533+#endif
71534+
71535 if (is_vm_hugetlb_page(vma) && (addr &
71536 ~(huge_page_mask(hstate_vma(vma)))))
71537 return -EINVAL;
71538
71539+#ifdef CONFIG_PAX_SEGMEXEC
71540+ vma_m = pax_find_mirror_vma(vma);
71541+#endif
71542+
71543 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
71544 if (!new)
71545 goto out_err;
71546
71547+#ifdef CONFIG_PAX_SEGMEXEC
71548+ if (vma_m) {
71549+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
71550+ if (!new_m) {
71551+ kmem_cache_free(vm_area_cachep, new);
71552+ goto out_err;
71553+ }
71554+ }
71555+#endif
71556+
71557 /* most fields are the same, copy all, and then fixup */
71558 *new = *vma;
71559
71560@@ -1987,6 +2316,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71561 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
71562 }
71563
71564+#ifdef CONFIG_PAX_SEGMEXEC
71565+ if (vma_m) {
71566+ *new_m = *vma_m;
71567+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
71568+ new_m->vm_mirror = new;
71569+ new->vm_mirror = new_m;
71570+
71571+ if (new_below)
71572+ new_m->vm_end = addr_m;
71573+ else {
71574+ new_m->vm_start = addr_m;
71575+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
71576+ }
71577+ }
71578+#endif
71579+
71580 pol = mpol_dup(vma_policy(vma));
71581 if (IS_ERR(pol)) {
71582 err = PTR_ERR(pol);
71583@@ -2012,6 +2357,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71584 else
71585 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
71586
71587+#ifdef CONFIG_PAX_SEGMEXEC
71588+ if (!err && vma_m) {
71589+ if (anon_vma_clone(new_m, vma_m))
71590+ goto out_free_mpol;
71591+
71592+ mpol_get(pol);
71593+ vma_set_policy(new_m, pol);
71594+
71595+ if (new_m->vm_file) {
71596+ get_file(new_m->vm_file);
71597+ if (vma_m->vm_flags & VM_EXECUTABLE)
71598+ added_exe_file_vma(mm);
71599+ }
71600+
71601+ if (new_m->vm_ops && new_m->vm_ops->open)
71602+ new_m->vm_ops->open(new_m);
71603+
71604+ if (new_below)
71605+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
71606+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
71607+ else
71608+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
71609+
71610+ if (err) {
71611+ if (new_m->vm_ops && new_m->vm_ops->close)
71612+ new_m->vm_ops->close(new_m);
71613+ if (new_m->vm_file) {
71614+ if (vma_m->vm_flags & VM_EXECUTABLE)
71615+ removed_exe_file_vma(mm);
71616+ fput(new_m->vm_file);
71617+ }
71618+ mpol_put(pol);
71619+ }
71620+ }
71621+#endif
71622+
71623 /* Success. */
71624 if (!err)
71625 return 0;
71626@@ -2024,10 +2405,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71627 removed_exe_file_vma(mm);
71628 fput(new->vm_file);
71629 }
71630- unlink_anon_vmas(new);
71631 out_free_mpol:
71632 mpol_put(pol);
71633 out_free_vma:
71634+
71635+#ifdef CONFIG_PAX_SEGMEXEC
71636+ if (new_m) {
71637+ unlink_anon_vmas(new_m);
71638+ kmem_cache_free(vm_area_cachep, new_m);
71639+ }
71640+#endif
71641+
71642+ unlink_anon_vmas(new);
71643 kmem_cache_free(vm_area_cachep, new);
71644 out_err:
71645 return err;
71646@@ -2040,6 +2429,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71647 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
71648 unsigned long addr, int new_below)
71649 {
71650+
71651+#ifdef CONFIG_PAX_SEGMEXEC
71652+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71653+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
71654+ if (mm->map_count >= sysctl_max_map_count-1)
71655+ return -ENOMEM;
71656+ } else
71657+#endif
71658+
71659 if (mm->map_count >= sysctl_max_map_count)
71660 return -ENOMEM;
71661
71662@@ -2051,11 +2449,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
71663 * work. This now handles partial unmappings.
71664 * Jeremy Fitzhardinge <jeremy@goop.org>
71665 */
71666+#ifdef CONFIG_PAX_SEGMEXEC
71667 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71668 {
71669+ int ret = __do_munmap(mm, start, len);
71670+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
71671+ return ret;
71672+
71673+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
71674+}
71675+
71676+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71677+#else
71678+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71679+#endif
71680+{
71681 unsigned long end;
71682 struct vm_area_struct *vma, *prev, *last;
71683
71684+ /*
71685+ * mm->mmap_sem is required to protect against another thread
71686+ * changing the mappings in case we sleep.
71687+ */
71688+ verify_mm_writelocked(mm);
71689+
71690 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
71691 return -EINVAL;
71692
71693@@ -2130,6 +2547,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71694 /* Fix up all other VM information */
71695 remove_vma_list(mm, vma);
71696
71697+ track_exec_limit(mm, start, end, 0UL);
71698+
71699 return 0;
71700 }
71701 EXPORT_SYMBOL(do_munmap);
71702@@ -2139,6 +2558,13 @@ int vm_munmap(unsigned long start, size_t len)
71703 int ret;
71704 struct mm_struct *mm = current->mm;
71705
71706+
71707+#ifdef CONFIG_PAX_SEGMEXEC
71708+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
71709+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
71710+ return -EINVAL;
71711+#endif
71712+
71713 down_write(&mm->mmap_sem);
71714 ret = do_munmap(mm, start, len);
71715 up_write(&mm->mmap_sem);
71716@@ -2152,16 +2578,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
71717 return vm_munmap(addr, len);
71718 }
71719
71720-static inline void verify_mm_writelocked(struct mm_struct *mm)
71721-{
71722-#ifdef CONFIG_DEBUG_VM
71723- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71724- WARN_ON(1);
71725- up_read(&mm->mmap_sem);
71726- }
71727-#endif
71728-}
71729-
71730 /*
71731 * this is really a simplified "do_mmap". it only handles
71732 * anonymous maps. eventually we may be able to do some
71733@@ -2175,6 +2591,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71734 struct rb_node ** rb_link, * rb_parent;
71735 pgoff_t pgoff = addr >> PAGE_SHIFT;
71736 int error;
71737+ unsigned long charged;
71738
71739 len = PAGE_ALIGN(len);
71740 if (!len)
71741@@ -2186,16 +2603,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71742
71743 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
71744
71745+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
71746+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
71747+ flags &= ~VM_EXEC;
71748+
71749+#ifdef CONFIG_PAX_MPROTECT
71750+ if (mm->pax_flags & MF_PAX_MPROTECT)
71751+ flags &= ~VM_MAYEXEC;
71752+#endif
71753+
71754+ }
71755+#endif
71756+
71757 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
71758 if (error & ~PAGE_MASK)
71759 return error;
71760
71761+ charged = len >> PAGE_SHIFT;
71762+
71763 /*
71764 * mlock MCL_FUTURE?
71765 */
71766 if (mm->def_flags & VM_LOCKED) {
71767 unsigned long locked, lock_limit;
71768- locked = len >> PAGE_SHIFT;
71769+ locked = charged;
71770 locked += mm->locked_vm;
71771 lock_limit = rlimit(RLIMIT_MEMLOCK);
71772 lock_limit >>= PAGE_SHIFT;
71773@@ -2212,22 +2643,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71774 /*
71775 * Clear old maps. this also does some error checking for us
71776 */
71777- munmap_back:
71778 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71779 if (vma && vma->vm_start < addr + len) {
71780 if (do_munmap(mm, addr, len))
71781 return -ENOMEM;
71782- goto munmap_back;
71783- }
71784+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71785+ BUG_ON(vma && vma->vm_start < addr + len);
71786+ }
71787
71788 /* Check against address space limits *after* clearing old maps... */
71789- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
71790+ if (!may_expand_vm(mm, charged))
71791 return -ENOMEM;
71792
71793 if (mm->map_count > sysctl_max_map_count)
71794 return -ENOMEM;
71795
71796- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
71797+ if (security_vm_enough_memory_mm(mm, charged))
71798 return -ENOMEM;
71799
71800 /* Can we just expand an old private anonymous mapping? */
71801@@ -2241,7 +2672,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71802 */
71803 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71804 if (!vma) {
71805- vm_unacct_memory(len >> PAGE_SHIFT);
71806+ vm_unacct_memory(charged);
71807 return -ENOMEM;
71808 }
71809
71810@@ -2255,11 +2686,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71811 vma_link(mm, vma, prev, rb_link, rb_parent);
71812 out:
71813 perf_event_mmap(vma);
71814- mm->total_vm += len >> PAGE_SHIFT;
71815+ mm->total_vm += charged;
71816 if (flags & VM_LOCKED) {
71817 if (!mlock_vma_pages_range(vma, addr, addr + len))
71818- mm->locked_vm += (len >> PAGE_SHIFT);
71819+ mm->locked_vm += charged;
71820 }
71821+ track_exec_limit(mm, addr, addr + len, flags);
71822 return addr;
71823 }
71824
71825@@ -2315,8 +2747,10 @@ void exit_mmap(struct mm_struct *mm)
71826 * Walk the list again, actually closing and freeing it,
71827 * with preemption enabled, without holding any MM locks.
71828 */
71829- while (vma)
71830+ while (vma) {
71831+ vma->vm_mirror = NULL;
71832 vma = remove_vma(vma);
71833+ }
71834
71835 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
71836 }
71837@@ -2330,6 +2764,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
71838 struct vm_area_struct * __vma, * prev;
71839 struct rb_node ** rb_link, * rb_parent;
71840
71841+#ifdef CONFIG_PAX_SEGMEXEC
71842+ struct vm_area_struct *vma_m = NULL;
71843+#endif
71844+
71845+ if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
71846+ return -EPERM;
71847+
71848 /*
71849 * The vm_pgoff of a purely anonymous vma should be irrelevant
71850 * until its first write fault, when page's anon_vma and index
71851@@ -2352,7 +2793,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
71852 if ((vma->vm_flags & VM_ACCOUNT) &&
71853 security_vm_enough_memory_mm(mm, vma_pages(vma)))
71854 return -ENOMEM;
71855+
71856+#ifdef CONFIG_PAX_SEGMEXEC
71857+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
71858+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71859+ if (!vma_m)
71860+ return -ENOMEM;
71861+ }
71862+#endif
71863+
71864 vma_link(mm, vma, prev, rb_link, rb_parent);
71865+
71866+#ifdef CONFIG_PAX_SEGMEXEC
71867+ if (vma_m)
71868+ BUG_ON(pax_mirror_vma(vma_m, vma));
71869+#endif
71870+
71871 return 0;
71872 }
71873
71874@@ -2371,6 +2827,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
71875 struct mempolicy *pol;
71876 bool faulted_in_anon_vma = true;
71877
71878+ BUG_ON(vma->vm_mirror);
71879+
71880 /*
71881 * If anonymous vma has not yet been faulted, update new pgoff
71882 * to match new location, to increase its chance of merging.
71883@@ -2438,6 +2896,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
71884 return NULL;
71885 }
71886
71887+#ifdef CONFIG_PAX_SEGMEXEC
71888+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
71889+{
71890+ struct vm_area_struct *prev_m;
71891+ struct rb_node **rb_link_m, *rb_parent_m;
71892+ struct mempolicy *pol_m;
71893+
71894+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
71895+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
71896+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
71897+ *vma_m = *vma;
71898+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
71899+ if (anon_vma_clone(vma_m, vma))
71900+ return -ENOMEM;
71901+ pol_m = vma_policy(vma_m);
71902+ mpol_get(pol_m);
71903+ vma_set_policy(vma_m, pol_m);
71904+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
71905+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
71906+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
71907+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
71908+ if (vma_m->vm_file)
71909+ get_file(vma_m->vm_file);
71910+ if (vma_m->vm_ops && vma_m->vm_ops->open)
71911+ vma_m->vm_ops->open(vma_m);
71912+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
71913+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
71914+ vma_m->vm_mirror = vma;
71915+ vma->vm_mirror = vma_m;
71916+ return 0;
71917+}
71918+#endif
71919+
71920 /*
71921 * Return true if the calling process may expand its vm space by the passed
71922 * number of pages
71923@@ -2449,6 +2940,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
71924
71925 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
71926
71927+#ifdef CONFIG_PAX_RANDMMAP
71928+ if (mm->pax_flags & MF_PAX_RANDMMAP)
71929+ cur -= mm->brk_gap;
71930+#endif
71931+
71932+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
71933 if (cur + npages > lim)
71934 return 0;
71935 return 1;
71936@@ -2519,6 +3016,22 @@ int install_special_mapping(struct mm_struct *mm,
71937 vma->vm_start = addr;
71938 vma->vm_end = addr + len;
71939
71940+#ifdef CONFIG_PAX_MPROTECT
71941+ if (mm->pax_flags & MF_PAX_MPROTECT) {
71942+#ifndef CONFIG_PAX_MPROTECT_COMPAT
71943+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
71944+ return -EPERM;
71945+ if (!(vm_flags & VM_EXEC))
71946+ vm_flags &= ~VM_MAYEXEC;
71947+#else
71948+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
71949+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
71950+#endif
71951+ else
71952+ vm_flags &= ~VM_MAYWRITE;
71953+ }
71954+#endif
71955+
71956 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
71957 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
71958
71959diff --git a/mm/mprotect.c b/mm/mprotect.c
71960index a409926..8b32e6d 100644
71961--- a/mm/mprotect.c
71962+++ b/mm/mprotect.c
71963@@ -23,10 +23,17 @@
71964 #include <linux/mmu_notifier.h>
71965 #include <linux/migrate.h>
71966 #include <linux/perf_event.h>
71967+
71968+#ifdef CONFIG_PAX_MPROTECT
71969+#include <linux/elf.h>
71970+#include <linux/binfmts.h>
71971+#endif
71972+
71973 #include <asm/uaccess.h>
71974 #include <asm/pgtable.h>
71975 #include <asm/cacheflush.h>
71976 #include <asm/tlbflush.h>
71977+#include <asm/mmu_context.h>
71978
71979 #ifndef pgprot_modify
71980 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
71981@@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
71982 flush_tlb_range(vma, start, end);
71983 }
71984
71985+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
71986+/* called while holding the mmap semaphor for writing except stack expansion */
71987+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
71988+{
71989+ unsigned long oldlimit, newlimit = 0UL;
71990+
71991+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
71992+ return;
71993+
71994+ spin_lock(&mm->page_table_lock);
71995+ oldlimit = mm->context.user_cs_limit;
71996+ if ((prot & VM_EXEC) && oldlimit < end)
71997+ /* USER_CS limit moved up */
71998+ newlimit = end;
71999+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
72000+ /* USER_CS limit moved down */
72001+ newlimit = start;
72002+
72003+ if (newlimit) {
72004+ mm->context.user_cs_limit = newlimit;
72005+
72006+#ifdef CONFIG_SMP
72007+ wmb();
72008+ cpus_clear(mm->context.cpu_user_cs_mask);
72009+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
72010+#endif
72011+
72012+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
72013+ }
72014+ spin_unlock(&mm->page_table_lock);
72015+ if (newlimit == end) {
72016+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
72017+
72018+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
72019+ if (is_vm_hugetlb_page(vma))
72020+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
72021+ else
72022+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
72023+ }
72024+}
72025+#endif
72026+
72027 int
72028 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72029 unsigned long start, unsigned long end, unsigned long newflags)
72030@@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72031 int error;
72032 int dirty_accountable = 0;
72033
72034+#ifdef CONFIG_PAX_SEGMEXEC
72035+ struct vm_area_struct *vma_m = NULL;
72036+ unsigned long start_m, end_m;
72037+
72038+ start_m = start + SEGMEXEC_TASK_SIZE;
72039+ end_m = end + SEGMEXEC_TASK_SIZE;
72040+#endif
72041+
72042 if (newflags == oldflags) {
72043 *pprev = vma;
72044 return 0;
72045 }
72046
72047+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
72048+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
72049+
72050+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
72051+ return -ENOMEM;
72052+
72053+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
72054+ return -ENOMEM;
72055+ }
72056+
72057 /*
72058 * If we make a private mapping writable we increase our commit;
72059 * but (without finer accounting) cannot reduce our commit if we
72060@@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72061 }
72062 }
72063
72064+#ifdef CONFIG_PAX_SEGMEXEC
72065+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
72066+ if (start != vma->vm_start) {
72067+ error = split_vma(mm, vma, start, 1);
72068+ if (error)
72069+ goto fail;
72070+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
72071+ *pprev = (*pprev)->vm_next;
72072+ }
72073+
72074+ if (end != vma->vm_end) {
72075+ error = split_vma(mm, vma, end, 0);
72076+ if (error)
72077+ goto fail;
72078+ }
72079+
72080+ if (pax_find_mirror_vma(vma)) {
72081+ error = __do_munmap(mm, start_m, end_m - start_m);
72082+ if (error)
72083+ goto fail;
72084+ } else {
72085+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72086+ if (!vma_m) {
72087+ error = -ENOMEM;
72088+ goto fail;
72089+ }
72090+ vma->vm_flags = newflags;
72091+ error = pax_mirror_vma(vma_m, vma);
72092+ if (error) {
72093+ vma->vm_flags = oldflags;
72094+ goto fail;
72095+ }
72096+ }
72097+ }
72098+#endif
72099+
72100 /*
72101 * First try to merge with previous and/or next vma.
72102 */
72103@@ -204,9 +307,21 @@ success:
72104 * vm_flags and vm_page_prot are protected by the mmap_sem
72105 * held in write mode.
72106 */
72107+
72108+#ifdef CONFIG_PAX_SEGMEXEC
72109+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
72110+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
72111+#endif
72112+
72113 vma->vm_flags = newflags;
72114+
72115+#ifdef CONFIG_PAX_MPROTECT
72116+ if (mm->binfmt && mm->binfmt->handle_mprotect)
72117+ mm->binfmt->handle_mprotect(vma, newflags);
72118+#endif
72119+
72120 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
72121- vm_get_page_prot(newflags));
72122+ vm_get_page_prot(vma->vm_flags));
72123
72124 if (vma_wants_writenotify(vma)) {
72125 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
72126@@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72127 end = start + len;
72128 if (end <= start)
72129 return -ENOMEM;
72130+
72131+#ifdef CONFIG_PAX_SEGMEXEC
72132+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72133+ if (end > SEGMEXEC_TASK_SIZE)
72134+ return -EINVAL;
72135+ } else
72136+#endif
72137+
72138+ if (end > TASK_SIZE)
72139+ return -EINVAL;
72140+
72141 if (!arch_validate_prot(prot))
72142 return -EINVAL;
72143
72144@@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72145 /*
72146 * Does the application expect PROT_READ to imply PROT_EXEC:
72147 */
72148- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72149+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72150 prot |= PROT_EXEC;
72151
72152 vm_flags = calc_vm_prot_bits(prot);
72153@@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72154 if (start > vma->vm_start)
72155 prev = vma;
72156
72157+#ifdef CONFIG_PAX_MPROTECT
72158+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
72159+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
72160+#endif
72161+
72162 for (nstart = start ; ; ) {
72163 unsigned long newflags;
72164
72165@@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72166
72167 /* newflags >> 4 shift VM_MAY% in place of VM_% */
72168 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
72169+ if (prot & (PROT_WRITE | PROT_EXEC))
72170+ gr_log_rwxmprotect(vma->vm_file);
72171+
72172+ error = -EACCES;
72173+ goto out;
72174+ }
72175+
72176+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
72177 error = -EACCES;
72178 goto out;
72179 }
72180@@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72181 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
72182 if (error)
72183 goto out;
72184+
72185+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
72186+
72187 nstart = tmp;
72188
72189 if (nstart < prev->vm_end)
72190diff --git a/mm/mremap.c b/mm/mremap.c
72191index db8d983..76506cb 100644
72192--- a/mm/mremap.c
72193+++ b/mm/mremap.c
72194@@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
72195 continue;
72196 pte = ptep_get_and_clear(mm, old_addr, old_pte);
72197 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
72198+
72199+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72200+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
72201+ pte = pte_exprotect(pte);
72202+#endif
72203+
72204 set_pte_at(mm, new_addr, new_pte, pte);
72205 }
72206
72207@@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
72208 if (is_vm_hugetlb_page(vma))
72209 goto Einval;
72210
72211+#ifdef CONFIG_PAX_SEGMEXEC
72212+ if (pax_find_mirror_vma(vma))
72213+ goto Einval;
72214+#endif
72215+
72216 /* We can't remap across vm area boundaries */
72217 if (old_len > vma->vm_end - addr)
72218 goto Efault;
72219@@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
72220 unsigned long ret = -EINVAL;
72221 unsigned long charged = 0;
72222 unsigned long map_flags;
72223+ unsigned long pax_task_size = TASK_SIZE;
72224
72225 if (new_addr & ~PAGE_MASK)
72226 goto out;
72227
72228- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
72229+#ifdef CONFIG_PAX_SEGMEXEC
72230+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
72231+ pax_task_size = SEGMEXEC_TASK_SIZE;
72232+#endif
72233+
72234+ pax_task_size -= PAGE_SIZE;
72235+
72236+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
72237 goto out;
72238
72239 /* Check if the location we're moving into overlaps the
72240 * old location at all, and fail if it does.
72241 */
72242- if ((new_addr <= addr) && (new_addr+new_len) > addr)
72243- goto out;
72244-
72245- if ((addr <= new_addr) && (addr+old_len) > new_addr)
72246+ if (addr + old_len > new_addr && new_addr + new_len > addr)
72247 goto out;
72248
72249 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72250@@ -440,6 +456,7 @@ unsigned long do_mremap(unsigned long addr,
72251 struct vm_area_struct *vma;
72252 unsigned long ret = -EINVAL;
72253 unsigned long charged = 0;
72254+ unsigned long pax_task_size = TASK_SIZE;
72255
72256 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
72257 goto out;
72258@@ -458,6 +475,17 @@ unsigned long do_mremap(unsigned long addr,
72259 if (!new_len)
72260 goto out;
72261
72262+#ifdef CONFIG_PAX_SEGMEXEC
72263+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
72264+ pax_task_size = SEGMEXEC_TASK_SIZE;
72265+#endif
72266+
72267+ pax_task_size -= PAGE_SIZE;
72268+
72269+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
72270+ old_len > pax_task_size || addr > pax_task_size-old_len)
72271+ goto out;
72272+
72273 if (flags & MREMAP_FIXED) {
72274 if (flags & MREMAP_MAYMOVE)
72275 ret = mremap_to(addr, old_len, new_addr, new_len);
72276@@ -507,6 +535,7 @@ unsigned long do_mremap(unsigned long addr,
72277 addr + new_len);
72278 }
72279 ret = addr;
72280+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
72281 goto out;
72282 }
72283 }
72284@@ -533,7 +562,13 @@ unsigned long do_mremap(unsigned long addr,
72285 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72286 if (ret)
72287 goto out;
72288+
72289+ map_flags = vma->vm_flags;
72290 ret = move_vma(vma, addr, old_len, new_len, new_addr);
72291+ if (!(ret & ~PAGE_MASK)) {
72292+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
72293+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
72294+ }
72295 }
72296 out:
72297 if (ret & ~PAGE_MASK)
72298diff --git a/mm/nommu.c b/mm/nommu.c
72299index bb8f4f0..40d3e02 100644
72300--- a/mm/nommu.c
72301+++ b/mm/nommu.c
72302@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
72303 int sysctl_overcommit_ratio = 50; /* default is 50% */
72304 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
72305 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
72306-int heap_stack_gap = 0;
72307
72308 atomic_long_t mmap_pages_allocated;
72309
72310@@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
72311 EXPORT_SYMBOL(find_vma);
72312
72313 /*
72314- * find a VMA
72315- * - we don't extend stack VMAs under NOMMU conditions
72316- */
72317-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
72318-{
72319- return find_vma(mm, addr);
72320-}
72321-
72322-/*
72323 * expand a stack to a given address
72324 * - not supported under NOMMU conditions
72325 */
72326@@ -1580,6 +1570,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72327
72328 /* most fields are the same, copy all, and then fixup */
72329 *new = *vma;
72330+ INIT_LIST_HEAD(&new->anon_vma_chain);
72331 *region = *vma->vm_region;
72332 new->vm_region = region;
72333
72334diff --git a/mm/page_alloc.c b/mm/page_alloc.c
72335index 918330f..ae99ae1 100644
72336--- a/mm/page_alloc.c
72337+++ b/mm/page_alloc.c
72338@@ -335,7 +335,7 @@ out:
72339 * This usage means that zero-order pages may not be compound.
72340 */
72341
72342-static void free_compound_page(struct page *page)
72343+void free_compound_page(struct page *page)
72344 {
72345 __free_pages_ok(page, compound_order(page));
72346 }
72347@@ -692,6 +692,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
72348 int i;
72349 int bad = 0;
72350
72351+#ifdef CONFIG_PAX_MEMORY_SANITIZE
72352+ unsigned long index = 1UL << order;
72353+#endif
72354+
72355 trace_mm_page_free(page, order);
72356 kmemcheck_free_shadow(page, order);
72357
72358@@ -707,6 +711,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
72359 debug_check_no_obj_freed(page_address(page),
72360 PAGE_SIZE << order);
72361 }
72362+
72363+#ifdef CONFIG_PAX_MEMORY_SANITIZE
72364+ for (; index; --index)
72365+ sanitize_highpage(page + index - 1);
72366+#endif
72367+
72368 arch_free_page(page, order);
72369 kernel_map_pages(page, 1 << order, 0);
72370
72371@@ -830,8 +840,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
72372 arch_alloc_page(page, order);
72373 kernel_map_pages(page, 1 << order, 1);
72374
72375+#ifndef CONFIG_PAX_MEMORY_SANITIZE
72376 if (gfp_flags & __GFP_ZERO)
72377 prep_zero_page(page, order, gfp_flags);
72378+#endif
72379
72380 if (order && (gfp_flags & __GFP_COMP))
72381 prep_compound_page(page, order);
72382@@ -3523,7 +3535,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
72383 unsigned long pfn;
72384
72385 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
72386+#ifdef CONFIG_X86_32
72387+ /* boot failures in VMware 8 on 32bit vanilla since
72388+ this change */
72389+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
72390+#else
72391 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
72392+#endif
72393 return 1;
72394 }
72395 return 0;
72396diff --git a/mm/percpu.c b/mm/percpu.c
72397index bb4be74..a43ea85 100644
72398--- a/mm/percpu.c
72399+++ b/mm/percpu.c
72400@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
72401 static unsigned int pcpu_high_unit_cpu __read_mostly;
72402
72403 /* the address of the first chunk which starts with the kernel static area */
72404-void *pcpu_base_addr __read_mostly;
72405+void *pcpu_base_addr __read_only;
72406 EXPORT_SYMBOL_GPL(pcpu_base_addr);
72407
72408 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
72409diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
72410index c20ff48..137702a 100644
72411--- a/mm/process_vm_access.c
72412+++ b/mm/process_vm_access.c
72413@@ -13,6 +13,7 @@
72414 #include <linux/uio.h>
72415 #include <linux/sched.h>
72416 #include <linux/highmem.h>
72417+#include <linux/security.h>
72418 #include <linux/ptrace.h>
72419 #include <linux/slab.h>
72420 #include <linux/syscalls.h>
72421@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
72422 size_t iov_l_curr_offset = 0;
72423 ssize_t iov_len;
72424
72425+ return -ENOSYS; // PaX: until properly audited
72426+
72427 /*
72428 * Work out how many pages of struct pages we're going to need
72429 * when eventually calling get_user_pages
72430 */
72431 for (i = 0; i < riovcnt; i++) {
72432 iov_len = rvec[i].iov_len;
72433- if (iov_len > 0) {
72434- nr_pages_iov = ((unsigned long)rvec[i].iov_base
72435- + iov_len)
72436- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
72437- / PAGE_SIZE + 1;
72438- nr_pages = max(nr_pages, nr_pages_iov);
72439- }
72440+ if (iov_len <= 0)
72441+ continue;
72442+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
72443+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
72444+ nr_pages = max(nr_pages, nr_pages_iov);
72445 }
72446
72447 if (nr_pages == 0)
72448@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
72449 goto free_proc_pages;
72450 }
72451
72452+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
72453+ rc = -EPERM;
72454+ goto put_task_struct;
72455+ }
72456+
72457 mm = mm_access(task, PTRACE_MODE_ATTACH);
72458 if (!mm || IS_ERR(mm)) {
72459 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
72460diff --git a/mm/rmap.c b/mm/rmap.c
72461index 5b5ad58..0f77903 100644
72462--- a/mm/rmap.c
72463+++ b/mm/rmap.c
72464@@ -167,6 +167,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72465 struct anon_vma *anon_vma = vma->anon_vma;
72466 struct anon_vma_chain *avc;
72467
72468+#ifdef CONFIG_PAX_SEGMEXEC
72469+ struct anon_vma_chain *avc_m = NULL;
72470+#endif
72471+
72472 might_sleep();
72473 if (unlikely(!anon_vma)) {
72474 struct mm_struct *mm = vma->vm_mm;
72475@@ -176,6 +180,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72476 if (!avc)
72477 goto out_enomem;
72478
72479+#ifdef CONFIG_PAX_SEGMEXEC
72480+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
72481+ if (!avc_m)
72482+ goto out_enomem_free_avc;
72483+#endif
72484+
72485 anon_vma = find_mergeable_anon_vma(vma);
72486 allocated = NULL;
72487 if (!anon_vma) {
72488@@ -189,6 +199,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72489 /* page_table_lock to protect against threads */
72490 spin_lock(&mm->page_table_lock);
72491 if (likely(!vma->anon_vma)) {
72492+
72493+#ifdef CONFIG_PAX_SEGMEXEC
72494+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
72495+
72496+ if (vma_m) {
72497+ BUG_ON(vma_m->anon_vma);
72498+ vma_m->anon_vma = anon_vma;
72499+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
72500+ avc_m = NULL;
72501+ }
72502+#endif
72503+
72504 vma->anon_vma = anon_vma;
72505 anon_vma_chain_link(vma, avc, anon_vma);
72506 allocated = NULL;
72507@@ -199,12 +221,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72508
72509 if (unlikely(allocated))
72510 put_anon_vma(allocated);
72511+
72512+#ifdef CONFIG_PAX_SEGMEXEC
72513+ if (unlikely(avc_m))
72514+ anon_vma_chain_free(avc_m);
72515+#endif
72516+
72517 if (unlikely(avc))
72518 anon_vma_chain_free(avc);
72519 }
72520 return 0;
72521
72522 out_enomem_free_avc:
72523+
72524+#ifdef CONFIG_PAX_SEGMEXEC
72525+ if (avc_m)
72526+ anon_vma_chain_free(avc_m);
72527+#endif
72528+
72529 anon_vma_chain_free(avc);
72530 out_enomem:
72531 return -ENOMEM;
72532@@ -240,7 +274,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
72533 * Attach the anon_vmas from src to dst.
72534 * Returns 0 on success, -ENOMEM on failure.
72535 */
72536-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
72537+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
72538 {
72539 struct anon_vma_chain *avc, *pavc;
72540 struct anon_vma *root = NULL;
72541@@ -318,7 +352,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
72542 * the corresponding VMA in the parent process is attached to.
72543 * Returns 0 on success, non-zero on failure.
72544 */
72545-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
72546+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
72547 {
72548 struct anon_vma_chain *avc;
72549 struct anon_vma *anon_vma;
72550diff --git a/mm/shmem.c b/mm/shmem.c
72551index f99ff3e..faea8b6 100644
72552--- a/mm/shmem.c
72553+++ b/mm/shmem.c
72554@@ -31,7 +31,7 @@
72555 #include <linux/export.h>
72556 #include <linux/swap.h>
72557
72558-static struct vfsmount *shm_mnt;
72559+struct vfsmount *shm_mnt;
72560
72561 #ifdef CONFIG_SHMEM
72562 /*
72563@@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
72564 #define BOGO_DIRENT_SIZE 20
72565
72566 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
72567-#define SHORT_SYMLINK_LEN 128
72568+#define SHORT_SYMLINK_LEN 64
72569
72570 struct shmem_xattr {
72571 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
72572@@ -2235,8 +2235,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
72573 int err = -ENOMEM;
72574
72575 /* Round up to L1_CACHE_BYTES to resist false sharing */
72576- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
72577- L1_CACHE_BYTES), GFP_KERNEL);
72578+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
72579 if (!sbinfo)
72580 return -ENOMEM;
72581
72582diff --git a/mm/slab.c b/mm/slab.c
72583index e901a36..ee8fe97 100644
72584--- a/mm/slab.c
72585+++ b/mm/slab.c
72586@@ -153,7 +153,7 @@
72587
72588 /* Legal flag mask for kmem_cache_create(). */
72589 #if DEBUG
72590-# define CREATE_MASK (SLAB_RED_ZONE | \
72591+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
72592 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
72593 SLAB_CACHE_DMA | \
72594 SLAB_STORE_USER | \
72595@@ -161,7 +161,7 @@
72596 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
72597 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
72598 #else
72599-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
72600+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
72601 SLAB_CACHE_DMA | \
72602 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
72603 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
72604@@ -290,7 +290,7 @@ struct kmem_list3 {
72605 * Need this for bootstrapping a per node allocator.
72606 */
72607 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
72608-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
72609+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
72610 #define CACHE_CACHE 0
72611 #define SIZE_AC MAX_NUMNODES
72612 #define SIZE_L3 (2 * MAX_NUMNODES)
72613@@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
72614 if ((x)->max_freeable < i) \
72615 (x)->max_freeable = i; \
72616 } while (0)
72617-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
72618-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
72619-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
72620-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
72621+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
72622+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
72623+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
72624+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
72625 #else
72626 #define STATS_INC_ACTIVE(x) do { } while (0)
72627 #define STATS_DEC_ACTIVE(x) do { } while (0)
72628@@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
72629 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
72630 */
72631 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
72632- const struct slab *slab, void *obj)
72633+ const struct slab *slab, const void *obj)
72634 {
72635 u32 offset = (obj - slab->s_mem);
72636 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
72637@@ -568,7 +568,7 @@ struct cache_names {
72638 static struct cache_names __initdata cache_names[] = {
72639 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
72640 #include <linux/kmalloc_sizes.h>
72641- {NULL,}
72642+ {NULL}
72643 #undef CACHE
72644 };
72645
72646@@ -1588,7 +1588,7 @@ void __init kmem_cache_init(void)
72647 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
72648 sizes[INDEX_AC].cs_size,
72649 ARCH_KMALLOC_MINALIGN,
72650- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72651+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72652 NULL);
72653
72654 if (INDEX_AC != INDEX_L3) {
72655@@ -1596,7 +1596,7 @@ void __init kmem_cache_init(void)
72656 kmem_cache_create(names[INDEX_L3].name,
72657 sizes[INDEX_L3].cs_size,
72658 ARCH_KMALLOC_MINALIGN,
72659- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72660+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72661 NULL);
72662 }
72663
72664@@ -1614,7 +1614,7 @@ void __init kmem_cache_init(void)
72665 sizes->cs_cachep = kmem_cache_create(names->name,
72666 sizes->cs_size,
72667 ARCH_KMALLOC_MINALIGN,
72668- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72669+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72670 NULL);
72671 }
72672 #ifdef CONFIG_ZONE_DMA
72673@@ -4390,10 +4390,10 @@ static int s_show(struct seq_file *m, void *p)
72674 }
72675 /* cpu stats */
72676 {
72677- unsigned long allochit = atomic_read(&cachep->allochit);
72678- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
72679- unsigned long freehit = atomic_read(&cachep->freehit);
72680- unsigned long freemiss = atomic_read(&cachep->freemiss);
72681+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
72682+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
72683+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
72684+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
72685
72686 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
72687 allochit, allocmiss, freehit, freemiss);
72688@@ -4652,13 +4652,62 @@ static int __init slab_proc_init(void)
72689 {
72690 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
72691 #ifdef CONFIG_DEBUG_SLAB_LEAK
72692- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
72693+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
72694 #endif
72695 return 0;
72696 }
72697 module_init(slab_proc_init);
72698 #endif
72699
72700+void check_object_size(const void *ptr, unsigned long n, bool to)
72701+{
72702+
72703+#ifdef CONFIG_PAX_USERCOPY
72704+ struct page *page;
72705+ struct kmem_cache *cachep = NULL;
72706+ struct slab *slabp;
72707+ unsigned int objnr;
72708+ unsigned long offset;
72709+ const char *type;
72710+
72711+ if (!n)
72712+ return;
72713+
72714+ type = "<null>";
72715+ if (ZERO_OR_NULL_PTR(ptr))
72716+ goto report;
72717+
72718+ if (!virt_addr_valid(ptr))
72719+ return;
72720+
72721+ page = virt_to_head_page(ptr);
72722+
72723+ type = "<process stack>";
72724+ if (!PageSlab(page)) {
72725+ if (object_is_on_stack(ptr, n) == -1)
72726+ goto report;
72727+ return;
72728+ }
72729+
72730+ cachep = page_get_cache(page);
72731+ type = cachep->name;
72732+ if (!(cachep->flags & SLAB_USERCOPY))
72733+ goto report;
72734+
72735+ slabp = page_get_slab(page);
72736+ objnr = obj_to_index(cachep, slabp, ptr);
72737+ BUG_ON(objnr >= cachep->num);
72738+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
72739+ if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
72740+ return;
72741+
72742+report:
72743+ pax_report_usercopy(ptr, n, to, type);
72744+#endif
72745+
72746+}
72747+EXPORT_SYMBOL(check_object_size);
72748+
72749 /**
72750 * ksize - get the actual amount of memory allocated for a given object
72751 * @objp: Pointer to the object
72752diff --git a/mm/slob.c b/mm/slob.c
72753index 8105be4..e045f96 100644
72754--- a/mm/slob.c
72755+++ b/mm/slob.c
72756@@ -29,7 +29,7 @@
72757 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
72758 * alloc_pages() directly, allocating compound pages so the page order
72759 * does not have to be separately tracked, and also stores the exact
72760- * allocation size in page->private so that it can be used to accurately
72761+ * allocation size in slob_page->size so that it can be used to accurately
72762 * provide ksize(). These objects are detected in kfree() because slob_page()
72763 * is false for them.
72764 *
72765@@ -58,6 +58,7 @@
72766 */
72767
72768 #include <linux/kernel.h>
72769+#include <linux/sched.h>
72770 #include <linux/slab.h>
72771 #include <linux/mm.h>
72772 #include <linux/swap.h> /* struct reclaim_state */
72773@@ -102,7 +103,8 @@ struct slob_page {
72774 unsigned long flags; /* mandatory */
72775 atomic_t _count; /* mandatory */
72776 slobidx_t units; /* free units left in page */
72777- unsigned long pad[2];
72778+ unsigned long pad[1];
72779+ unsigned long size; /* size when >=PAGE_SIZE */
72780 slob_t *free; /* first free slob_t in page */
72781 struct list_head list; /* linked list of free pages */
72782 };
72783@@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
72784 */
72785 static inline int is_slob_page(struct slob_page *sp)
72786 {
72787- return PageSlab((struct page *)sp);
72788+ return PageSlab((struct page *)sp) && !sp->size;
72789 }
72790
72791 static inline void set_slob_page(struct slob_page *sp)
72792@@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
72793
72794 static inline struct slob_page *slob_page(const void *addr)
72795 {
72796- return (struct slob_page *)virt_to_page(addr);
72797+ return (struct slob_page *)virt_to_head_page(addr);
72798 }
72799
72800 /*
72801@@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
72802 /*
72803 * Return the size of a slob block.
72804 */
72805-static slobidx_t slob_units(slob_t *s)
72806+static slobidx_t slob_units(const slob_t *s)
72807 {
72808 if (s->units > 0)
72809 return s->units;
72810@@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
72811 /*
72812 * Return the next free slob block pointer after this one.
72813 */
72814-static slob_t *slob_next(slob_t *s)
72815+static slob_t *slob_next(const slob_t *s)
72816 {
72817 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
72818 slobidx_t next;
72819@@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
72820 /*
72821 * Returns true if s is the last free block in its page.
72822 */
72823-static int slob_last(slob_t *s)
72824+static int slob_last(const slob_t *s)
72825 {
72826 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
72827 }
72828@@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
72829 if (!page)
72830 return NULL;
72831
72832+ set_slob_page(page);
72833 return page_address(page);
72834 }
72835
72836@@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
72837 if (!b)
72838 return NULL;
72839 sp = slob_page(b);
72840- set_slob_page(sp);
72841
72842 spin_lock_irqsave(&slob_lock, flags);
72843 sp->units = SLOB_UNITS(PAGE_SIZE);
72844 sp->free = b;
72845+ sp->size = 0;
72846 INIT_LIST_HEAD(&sp->list);
72847 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
72848 set_slob_page_free(sp, slob_list);
72849@@ -476,10 +479,9 @@ out:
72850 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
72851 */
72852
72853-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72854+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
72855 {
72856- unsigned int *m;
72857- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72858+ slob_t *m;
72859 void *ret;
72860
72861 gfp &= gfp_allowed_mask;
72862@@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72863
72864 if (!m)
72865 return NULL;
72866- *m = size;
72867+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
72868+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
72869+ m[0].units = size;
72870+ m[1].units = align;
72871 ret = (void *)m + align;
72872
72873 trace_kmalloc_node(_RET_IP_, ret,
72874@@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72875 gfp |= __GFP_COMP;
72876 ret = slob_new_pages(gfp, order, node);
72877 if (ret) {
72878- struct page *page;
72879- page = virt_to_page(ret);
72880- page->private = size;
72881+ struct slob_page *sp;
72882+ sp = slob_page(ret);
72883+ sp->size = size;
72884 }
72885
72886 trace_kmalloc_node(_RET_IP_, ret,
72887 size, PAGE_SIZE << order, gfp, node);
72888 }
72889
72890- kmemleak_alloc(ret, size, 1, gfp);
72891+ return ret;
72892+}
72893+
72894+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72895+{
72896+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72897+ void *ret = __kmalloc_node_align(size, gfp, node, align);
72898+
72899+ if (!ZERO_OR_NULL_PTR(ret))
72900+ kmemleak_alloc(ret, size, 1, gfp);
72901 return ret;
72902 }
72903 EXPORT_SYMBOL(__kmalloc_node);
72904@@ -533,13 +547,92 @@ void kfree(const void *block)
72905 sp = slob_page(block);
72906 if (is_slob_page(sp)) {
72907 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72908- unsigned int *m = (unsigned int *)(block - align);
72909- slob_free(m, *m + align);
72910- } else
72911+ slob_t *m = (slob_t *)(block - align);
72912+ slob_free(m, m[0].units + align);
72913+ } else {
72914+ clear_slob_page(sp);
72915+ free_slob_page(sp);
72916+ sp->size = 0;
72917 put_page(&sp->page);
72918+ }
72919 }
72920 EXPORT_SYMBOL(kfree);
72921
72922+void check_object_size(const void *ptr, unsigned long n, bool to)
72923+{
72924+
72925+#ifdef CONFIG_PAX_USERCOPY
72926+ struct slob_page *sp;
72927+ const slob_t *free;
72928+ const void *base;
72929+ unsigned long flags;
72930+ const char *type;
72931+
72932+ if (!n)
72933+ return;
72934+
72935+ type = "<null>";
72936+ if (ZERO_OR_NULL_PTR(ptr))
72937+ goto report;
72938+
72939+ if (!virt_addr_valid(ptr))
72940+ return;
72941+
72942+ type = "<process stack>";
72943+ sp = slob_page(ptr);
72944+ if (!PageSlab((struct page *)sp)) {
72945+ if (object_is_on_stack(ptr, n) == -1)
72946+ goto report;
72947+ return;
72948+ }
72949+
72950+ type = "<slob>";
72951+ if (sp->size) {
72952+ base = page_address(&sp->page);
72953+ if (base <= ptr && n <= sp->size - (ptr - base))
72954+ return;
72955+ goto report;
72956+ }
72957+
72958+ /* some tricky double walking to find the chunk */
72959+ spin_lock_irqsave(&slob_lock, flags);
72960+ base = (void *)((unsigned long)ptr & PAGE_MASK);
72961+ free = sp->free;
72962+
72963+ while (!slob_last(free) && (void *)free <= ptr) {
72964+ base = free + slob_units(free);
72965+ free = slob_next(free);
72966+ }
72967+
72968+ while (base < (void *)free) {
72969+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
72970+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
72971+ int offset;
72972+
72973+ if (ptr < base + align)
72974+ break;
72975+
72976+ offset = ptr - base - align;
72977+ if (offset >= m) {
72978+ base += size;
72979+ continue;
72980+ }
72981+
72982+ if (n > m - offset)
72983+ break;
72984+
72985+ spin_unlock_irqrestore(&slob_lock, flags);
72986+ return;
72987+ }
72988+
72989+ spin_unlock_irqrestore(&slob_lock, flags);
72990+report:
72991+ pax_report_usercopy(ptr, n, to, type);
72992+#endif
72993+
72994+}
72995+EXPORT_SYMBOL(check_object_size);
72996+
72997 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
72998 size_t ksize(const void *block)
72999 {
73000@@ -552,10 +645,10 @@ size_t ksize(const void *block)
73001 sp = slob_page(block);
73002 if (is_slob_page(sp)) {
73003 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73004- unsigned int *m = (unsigned int *)(block - align);
73005- return SLOB_UNITS(*m) * SLOB_UNIT;
73006+ slob_t *m = (slob_t *)(block - align);
73007+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
73008 } else
73009- return sp->page.private;
73010+ return sp->size;
73011 }
73012 EXPORT_SYMBOL(ksize);
73013
73014@@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73015 {
73016 struct kmem_cache *c;
73017
73018+#ifdef CONFIG_PAX_USERCOPY
73019+ c = __kmalloc_node_align(sizeof(struct kmem_cache),
73020+ GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
73021+#else
73022 c = slob_alloc(sizeof(struct kmem_cache),
73023 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
73024+#endif
73025
73026 if (c) {
73027 c->name = name;
73028@@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
73029
73030 lockdep_trace_alloc(flags);
73031
73032+#ifdef CONFIG_PAX_USERCOPY
73033+ b = __kmalloc_node_align(c->size, flags, node, c->align);
73034+#else
73035 if (c->size < PAGE_SIZE) {
73036 b = slob_alloc(c->size, flags, c->align, node);
73037 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73038 SLOB_UNITS(c->size) * SLOB_UNIT,
73039 flags, node);
73040 } else {
73041+ struct slob_page *sp;
73042+
73043 b = slob_new_pages(flags, get_order(c->size), node);
73044+ sp = slob_page(b);
73045+ sp->size = c->size;
73046 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73047 PAGE_SIZE << get_order(c->size),
73048 flags, node);
73049 }
73050+#endif
73051
73052 if (c->ctor)
73053 c->ctor(b);
73054@@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
73055
73056 static void __kmem_cache_free(void *b, int size)
73057 {
73058- if (size < PAGE_SIZE)
73059+ struct slob_page *sp = slob_page(b);
73060+
73061+ if (is_slob_page(sp))
73062 slob_free(b, size);
73063- else
73064+ else {
73065+ clear_slob_page(sp);
73066+ free_slob_page(sp);
73067+ sp->size = 0;
73068 slob_free_pages(b, get_order(size));
73069+ }
73070 }
73071
73072 static void kmem_rcu_free(struct rcu_head *head)
73073@@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
73074
73075 void kmem_cache_free(struct kmem_cache *c, void *b)
73076 {
73077+ int size = c->size;
73078+
73079+#ifdef CONFIG_PAX_USERCOPY
73080+ if (size + c->align < PAGE_SIZE) {
73081+ size += c->align;
73082+ b -= c->align;
73083+ }
73084+#endif
73085+
73086 kmemleak_free_recursive(b, c->flags);
73087 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
73088 struct slob_rcu *slob_rcu;
73089- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
73090- slob_rcu->size = c->size;
73091+ slob_rcu = b + (size - sizeof(struct slob_rcu));
73092+ slob_rcu->size = size;
73093 call_rcu(&slob_rcu->head, kmem_rcu_free);
73094 } else {
73095- __kmem_cache_free(b, c->size);
73096+ __kmem_cache_free(b, size);
73097 }
73098
73099+#ifdef CONFIG_PAX_USERCOPY
73100+ trace_kfree(_RET_IP_, b);
73101+#else
73102 trace_kmem_cache_free(_RET_IP_, b);
73103+#endif
73104+
73105 }
73106 EXPORT_SYMBOL(kmem_cache_free);
73107
73108diff --git a/mm/slub.c b/mm/slub.c
73109index 71de9b5..dd263c5 100644
73110--- a/mm/slub.c
73111+++ b/mm/slub.c
73112@@ -209,7 +209,7 @@ struct track {
73113
73114 enum track_item { TRACK_ALLOC, TRACK_FREE };
73115
73116-#ifdef CONFIG_SYSFS
73117+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73118 static int sysfs_slab_add(struct kmem_cache *);
73119 static int sysfs_slab_alias(struct kmem_cache *, const char *);
73120 static void sysfs_slab_remove(struct kmem_cache *);
73121@@ -538,7 +538,7 @@ static void print_track(const char *s, struct track *t)
73122 if (!t->addr)
73123 return;
73124
73125- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
73126+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
73127 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
73128 #ifdef CONFIG_STACKTRACE
73129 {
73130@@ -2603,6 +2603,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
73131
73132 page = virt_to_head_page(x);
73133
73134+ BUG_ON(!PageSlab(page));
73135+
73136 slab_free(s, page, x, _RET_IP_);
73137
73138 trace_kmem_cache_free(_RET_IP_, x);
73139@@ -2636,7 +2638,7 @@ static int slub_min_objects;
73140 * Merge control. If this is set then no merging of slab caches will occur.
73141 * (Could be removed. This was introduced to pacify the merge skeptics.)
73142 */
73143-static int slub_nomerge;
73144+static int slub_nomerge = 1;
73145
73146 /*
73147 * Calculate the order of allocation given an slab object size.
73148@@ -3089,7 +3091,7 @@ static int kmem_cache_open(struct kmem_cache *s,
73149 else
73150 s->cpu_partial = 30;
73151
73152- s->refcount = 1;
73153+ atomic_set(&s->refcount, 1);
73154 #ifdef CONFIG_NUMA
73155 s->remote_node_defrag_ratio = 1000;
73156 #endif
73157@@ -3193,8 +3195,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
73158 void kmem_cache_destroy(struct kmem_cache *s)
73159 {
73160 down_write(&slub_lock);
73161- s->refcount--;
73162- if (!s->refcount) {
73163+ if (atomic_dec_and_test(&s->refcount)) {
73164 list_del(&s->list);
73165 up_write(&slub_lock);
73166 if (kmem_cache_close(s)) {
73167@@ -3405,6 +3406,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
73168 EXPORT_SYMBOL(__kmalloc_node);
73169 #endif
73170
73171+void check_object_size(const void *ptr, unsigned long n, bool to)
73172+{
73173+
73174+#ifdef CONFIG_PAX_USERCOPY
73175+ struct page *page;
73176+ struct kmem_cache *s = NULL;
73177+ unsigned long offset;
73178+ const char *type;
73179+
73180+ if (!n)
73181+ return;
73182+
73183+ type = "<null>";
73184+ if (ZERO_OR_NULL_PTR(ptr))
73185+ goto report;
73186+
73187+ if (!virt_addr_valid(ptr))
73188+ return;
73189+
73190+ page = virt_to_head_page(ptr);
73191+
73192+ type = "<process stack>";
73193+ if (!PageSlab(page)) {
73194+ if (object_is_on_stack(ptr, n) == -1)
73195+ goto report;
73196+ return;
73197+ }
73198+
73199+ s = page->slab;
73200+ type = s->name;
73201+ if (!(s->flags & SLAB_USERCOPY))
73202+ goto report;
73203+
73204+ offset = (ptr - page_address(page)) % s->size;
73205+ if (offset <= s->objsize && n <= s->objsize - offset)
73206+ return;
73207+
73208+report:
73209+ pax_report_usercopy(ptr, n, to, type);
73210+#endif
73211+
73212+}
73213+EXPORT_SYMBOL(check_object_size);
73214+
73215 size_t ksize(const void *object)
73216 {
73217 struct page *page;
73218@@ -3679,7 +3724,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
73219 int node;
73220
73221 list_add(&s->list, &slab_caches);
73222- s->refcount = -1;
73223+ atomic_set(&s->refcount, -1);
73224
73225 for_each_node_state(node, N_NORMAL_MEMORY) {
73226 struct kmem_cache_node *n = get_node(s, node);
73227@@ -3799,17 +3844,17 @@ void __init kmem_cache_init(void)
73228
73229 /* Caches that are not of the two-to-the-power-of size */
73230 if (KMALLOC_MIN_SIZE <= 32) {
73231- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
73232+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
73233 caches++;
73234 }
73235
73236 if (KMALLOC_MIN_SIZE <= 64) {
73237- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
73238+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
73239 caches++;
73240 }
73241
73242 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
73243- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
73244+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
73245 caches++;
73246 }
73247
73248@@ -3877,7 +3922,7 @@ static int slab_unmergeable(struct kmem_cache *s)
73249 /*
73250 * We may have set a slab to be unmergeable during bootstrap.
73251 */
73252- if (s->refcount < 0)
73253+ if (atomic_read(&s->refcount) < 0)
73254 return 1;
73255
73256 return 0;
73257@@ -3936,7 +3981,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73258 down_write(&slub_lock);
73259 s = find_mergeable(size, align, flags, name, ctor);
73260 if (s) {
73261- s->refcount++;
73262+ atomic_inc(&s->refcount);
73263 /*
73264 * Adjust the object sizes so that we clear
73265 * the complete object on kzalloc.
73266@@ -3945,7 +3990,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73267 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
73268
73269 if (sysfs_slab_alias(s, name)) {
73270- s->refcount--;
73271+ atomic_dec(&s->refcount);
73272 goto err;
73273 }
73274 up_write(&slub_lock);
73275@@ -4074,7 +4119,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
73276 }
73277 #endif
73278
73279-#ifdef CONFIG_SYSFS
73280+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73281 static int count_inuse(struct page *page)
73282 {
73283 return page->inuse;
73284@@ -4461,12 +4506,12 @@ static void resiliency_test(void)
73285 validate_slab_cache(kmalloc_caches[9]);
73286 }
73287 #else
73288-#ifdef CONFIG_SYSFS
73289+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73290 static void resiliency_test(void) {};
73291 #endif
73292 #endif
73293
73294-#ifdef CONFIG_SYSFS
73295+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73296 enum slab_stat_type {
73297 SL_ALL, /* All slabs */
73298 SL_PARTIAL, /* Only partially allocated slabs */
73299@@ -4709,7 +4754,7 @@ SLAB_ATTR_RO(ctor);
73300
73301 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
73302 {
73303- return sprintf(buf, "%d\n", s->refcount - 1);
73304+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
73305 }
73306 SLAB_ATTR_RO(aliases);
73307
73308@@ -5280,6 +5325,7 @@ static char *create_unique_id(struct kmem_cache *s)
73309 return name;
73310 }
73311
73312+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73313 static int sysfs_slab_add(struct kmem_cache *s)
73314 {
73315 int err;
73316@@ -5342,6 +5388,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
73317 kobject_del(&s->kobj);
73318 kobject_put(&s->kobj);
73319 }
73320+#endif
73321
73322 /*
73323 * Need to buffer aliases during bootup until sysfs becomes
73324@@ -5355,6 +5402,7 @@ struct saved_alias {
73325
73326 static struct saved_alias *alias_list;
73327
73328+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73329 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
73330 {
73331 struct saved_alias *al;
73332@@ -5377,6 +5425,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
73333 alias_list = al;
73334 return 0;
73335 }
73336+#endif
73337
73338 static int __init slab_sysfs_init(void)
73339 {
73340diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
73341index 1b7e22a..3fcd4f3 100644
73342--- a/mm/sparse-vmemmap.c
73343+++ b/mm/sparse-vmemmap.c
73344@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
73345 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
73346 if (!p)
73347 return NULL;
73348- pud_populate(&init_mm, pud, p);
73349+ pud_populate_kernel(&init_mm, pud, p);
73350 }
73351 return pud;
73352 }
73353@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
73354 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
73355 if (!p)
73356 return NULL;
73357- pgd_populate(&init_mm, pgd, p);
73358+ pgd_populate_kernel(&init_mm, pgd, p);
73359 }
73360 return pgd;
73361 }
73362diff --git a/mm/swap.c b/mm/swap.c
73363index 5c13f13..f1cfc13 100644
73364--- a/mm/swap.c
73365+++ b/mm/swap.c
73366@@ -30,6 +30,7 @@
73367 #include <linux/backing-dev.h>
73368 #include <linux/memcontrol.h>
73369 #include <linux/gfp.h>
73370+#include <linux/hugetlb.h>
73371
73372 #include "internal.h"
73373
73374@@ -70,6 +71,8 @@ static void __put_compound_page(struct page *page)
73375
73376 __page_cache_release(page);
73377 dtor = get_compound_page_dtor(page);
73378+ if (!PageHuge(page))
73379+ BUG_ON(dtor != free_compound_page);
73380 (*dtor)(page);
73381 }
73382
73383diff --git a/mm/swapfile.c b/mm/swapfile.c
73384index fafc26d..1b7493e 100644
73385--- a/mm/swapfile.c
73386+++ b/mm/swapfile.c
73387@@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
73388
73389 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
73390 /* Activity counter to indicate that a swapon or swapoff has occurred */
73391-static atomic_t proc_poll_event = ATOMIC_INIT(0);
73392+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
73393
73394 static inline unsigned char swap_count(unsigned char ent)
73395 {
73396@@ -1671,7 +1671,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
73397 }
73398 filp_close(swap_file, NULL);
73399 err = 0;
73400- atomic_inc(&proc_poll_event);
73401+ atomic_inc_unchecked(&proc_poll_event);
73402 wake_up_interruptible(&proc_poll_wait);
73403
73404 out_dput:
73405@@ -1687,8 +1687,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
73406
73407 poll_wait(file, &proc_poll_wait, wait);
73408
73409- if (seq->poll_event != atomic_read(&proc_poll_event)) {
73410- seq->poll_event = atomic_read(&proc_poll_event);
73411+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
73412+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
73413 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
73414 }
73415
73416@@ -1786,7 +1786,7 @@ static int swaps_open(struct inode *inode, struct file *file)
73417 return ret;
73418
73419 seq = file->private_data;
73420- seq->poll_event = atomic_read(&proc_poll_event);
73421+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
73422 return 0;
73423 }
73424
73425@@ -2127,7 +2127,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
73426 (p->flags & SWP_DISCARDABLE) ? "D" : "");
73427
73428 mutex_unlock(&swapon_mutex);
73429- atomic_inc(&proc_poll_event);
73430+ atomic_inc_unchecked(&proc_poll_event);
73431 wake_up_interruptible(&proc_poll_wait);
73432
73433 if (S_ISREG(inode->i_mode))
73434diff --git a/mm/util.c b/mm/util.c
73435index ae962b3..0bba886 100644
73436--- a/mm/util.c
73437+++ b/mm/util.c
73438@@ -284,6 +284,12 @@ done:
73439 void arch_pick_mmap_layout(struct mm_struct *mm)
73440 {
73441 mm->mmap_base = TASK_UNMAPPED_BASE;
73442+
73443+#ifdef CONFIG_PAX_RANDMMAP
73444+ if (mm->pax_flags & MF_PAX_RANDMMAP)
73445+ mm->mmap_base += mm->delta_mmap;
73446+#endif
73447+
73448 mm->get_unmapped_area = arch_get_unmapped_area;
73449 mm->unmap_area = arch_unmap_area;
73450 }
73451diff --git a/mm/vmalloc.c b/mm/vmalloc.c
73452index 1196c77..2e608e8 100644
73453--- a/mm/vmalloc.c
73454+++ b/mm/vmalloc.c
73455@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
73456
73457 pte = pte_offset_kernel(pmd, addr);
73458 do {
73459- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
73460- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
73461+
73462+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73463+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
73464+ BUG_ON(!pte_exec(*pte));
73465+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
73466+ continue;
73467+ }
73468+#endif
73469+
73470+ {
73471+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
73472+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
73473+ }
73474 } while (pte++, addr += PAGE_SIZE, addr != end);
73475 }
73476
73477@@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
73478 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
73479 {
73480 pte_t *pte;
73481+ int ret = -ENOMEM;
73482
73483 /*
73484 * nr is a running index into the array which helps higher level
73485@@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
73486 pte = pte_alloc_kernel(pmd, addr);
73487 if (!pte)
73488 return -ENOMEM;
73489+
73490+ pax_open_kernel();
73491 do {
73492 struct page *page = pages[*nr];
73493
73494- if (WARN_ON(!pte_none(*pte)))
73495- return -EBUSY;
73496- if (WARN_ON(!page))
73497- return -ENOMEM;
73498+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73499+ if (pgprot_val(prot) & _PAGE_NX)
73500+#endif
73501+
73502+ if (WARN_ON(!pte_none(*pte))) {
73503+ ret = -EBUSY;
73504+ goto out;
73505+ }
73506+ if (WARN_ON(!page)) {
73507+ ret = -ENOMEM;
73508+ goto out;
73509+ }
73510 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
73511 (*nr)++;
73512 } while (pte++, addr += PAGE_SIZE, addr != end);
73513- return 0;
73514+ ret = 0;
73515+out:
73516+ pax_close_kernel();
73517+ return ret;
73518 }
73519
73520 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
73521@@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
73522 pmd_t *pmd;
73523 unsigned long next;
73524
73525- pmd = pmd_alloc(&init_mm, pud, addr);
73526+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
73527 if (!pmd)
73528 return -ENOMEM;
73529 do {
73530@@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
73531 pud_t *pud;
73532 unsigned long next;
73533
73534- pud = pud_alloc(&init_mm, pgd, addr);
73535+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
73536 if (!pud)
73537 return -ENOMEM;
73538 do {
73539@@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
73540 * and fall back on vmalloc() if that fails. Others
73541 * just put it in the vmalloc space.
73542 */
73543-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
73544+#ifdef CONFIG_MODULES
73545+#ifdef MODULES_VADDR
73546 unsigned long addr = (unsigned long)x;
73547 if (addr >= MODULES_VADDR && addr < MODULES_END)
73548 return 1;
73549 #endif
73550+
73551+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73552+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
73553+ return 1;
73554+#endif
73555+
73556+#endif
73557+
73558 return is_vmalloc_addr(x);
73559 }
73560
73561@@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
73562
73563 if (!pgd_none(*pgd)) {
73564 pud_t *pud = pud_offset(pgd, addr);
73565+#ifdef CONFIG_X86
73566+ if (!pud_large(*pud))
73567+#endif
73568 if (!pud_none(*pud)) {
73569 pmd_t *pmd = pmd_offset(pud, addr);
73570+#ifdef CONFIG_X86
73571+ if (!pmd_large(*pmd))
73572+#endif
73573 if (!pmd_none(*pmd)) {
73574 pte_t *ptep, pte;
73575
73576@@ -332,6 +372,10 @@ static void purge_vmap_area_lazy(void);
73577 static struct vmap_area *alloc_vmap_area(unsigned long size,
73578 unsigned long align,
73579 unsigned long vstart, unsigned long vend,
73580+ int node, gfp_t gfp_mask) __size_overflow(1);
73581+static struct vmap_area *alloc_vmap_area(unsigned long size,
73582+ unsigned long align,
73583+ unsigned long vstart, unsigned long vend,
73584 int node, gfp_t gfp_mask)
73585 {
73586 struct vmap_area *va;
73587@@ -1320,6 +1364,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
73588 struct vm_struct *area;
73589
73590 BUG_ON(in_interrupt());
73591+
73592+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73593+ if (flags & VM_KERNEXEC) {
73594+ if (start != VMALLOC_START || end != VMALLOC_END)
73595+ return NULL;
73596+ start = (unsigned long)MODULES_EXEC_VADDR;
73597+ end = (unsigned long)MODULES_EXEC_END;
73598+ }
73599+#endif
73600+
73601 if (flags & VM_IOREMAP) {
73602 int bit = fls(size);
73603
73604@@ -1552,6 +1606,11 @@ void *vmap(struct page **pages, unsigned int count,
73605 if (count > totalram_pages)
73606 return NULL;
73607
73608+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73609+ if (!(pgprot_val(prot) & _PAGE_NX))
73610+ flags |= VM_KERNEXEC;
73611+#endif
73612+
73613 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
73614 __builtin_return_address(0));
73615 if (!area)
73616@@ -1653,6 +1712,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
73617 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
73618 goto fail;
73619
73620+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73621+ if (!(pgprot_val(prot) & _PAGE_NX))
73622+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
73623+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
73624+ else
73625+#endif
73626+
73627 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
73628 start, end, node, gfp_mask, caller);
73629 if (!area)
73630@@ -1826,10 +1892,9 @@ EXPORT_SYMBOL(vzalloc_node);
73631 * For tight control over page level allocator and protection flags
73632 * use __vmalloc() instead.
73633 */
73634-
73635 void *vmalloc_exec(unsigned long size)
73636 {
73637- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
73638+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
73639 -1, __builtin_return_address(0));
73640 }
73641
73642@@ -2124,6 +2189,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
73643 unsigned long uaddr = vma->vm_start;
73644 unsigned long usize = vma->vm_end - vma->vm_start;
73645
73646+ BUG_ON(vma->vm_mirror);
73647+
73648 if ((PAGE_SIZE-1) & (unsigned long)addr)
73649 return -EINVAL;
73650
73651@@ -2376,8 +2443,8 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
73652 return NULL;
73653 }
73654
73655- vms = kzalloc(sizeof(vms[0]) * nr_vms, GFP_KERNEL);
73656- vas = kzalloc(sizeof(vas[0]) * nr_vms, GFP_KERNEL);
73657+ vms = kcalloc(nr_vms, sizeof(vms[0]), GFP_KERNEL);
73658+ vas = kcalloc(nr_vms, sizeof(vas[0]), GFP_KERNEL);
73659 if (!vas || !vms)
73660 goto err_free2;
73661
73662diff --git a/mm/vmstat.c b/mm/vmstat.c
73663index 7db1b9b..e9f6b07 100644
73664--- a/mm/vmstat.c
73665+++ b/mm/vmstat.c
73666@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
73667 *
73668 * vm_stat contains the global counters
73669 */
73670-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
73671+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
73672 EXPORT_SYMBOL(vm_stat);
73673
73674 #ifdef CONFIG_SMP
73675@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
73676 v = p->vm_stat_diff[i];
73677 p->vm_stat_diff[i] = 0;
73678 local_irq_restore(flags);
73679- atomic_long_add(v, &zone->vm_stat[i]);
73680+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
73681 global_diff[i] += v;
73682 #ifdef CONFIG_NUMA
73683 /* 3 seconds idle till flush */
73684@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
73685
73686 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
73687 if (global_diff[i])
73688- atomic_long_add(global_diff[i], &vm_stat[i]);
73689+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
73690 }
73691
73692 #endif
73693@@ -1208,10 +1208,20 @@ static int __init setup_vmstat(void)
73694 start_cpu_timer(cpu);
73695 #endif
73696 #ifdef CONFIG_PROC_FS
73697- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
73698- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
73699- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
73700- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
73701+ {
73702+ mode_t gr_mode = S_IRUGO;
73703+#ifdef CONFIG_GRKERNSEC_PROC_ADD
73704+ gr_mode = S_IRUSR;
73705+#endif
73706+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
73707+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
73708+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
73709+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
73710+#else
73711+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
73712+#endif
73713+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
73714+ }
73715 #endif
73716 return 0;
73717 }
73718diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
73719index efea35b..9c8dd0b 100644
73720--- a/net/8021q/vlan.c
73721+++ b/net/8021q/vlan.c
73722@@ -554,8 +554,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
73723 err = -EPERM;
73724 if (!capable(CAP_NET_ADMIN))
73725 break;
73726- if ((args.u.name_type >= 0) &&
73727- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
73728+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
73729 struct vlan_net *vn;
73730
73731 vn = net_generic(net, vlan_net_id);
73732diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
73733index fccae26..e7ece2f 100644
73734--- a/net/9p/trans_fd.c
73735+++ b/net/9p/trans_fd.c
73736@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
73737 oldfs = get_fs();
73738 set_fs(get_ds());
73739 /* The cast to a user pointer is valid due to the set_fs() */
73740- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
73741+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
73742 set_fs(oldfs);
73743
73744 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
73745diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
73746index 876fbe8..8bbea9f 100644
73747--- a/net/atm/atm_misc.c
73748+++ b/net/atm/atm_misc.c
73749@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
73750 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
73751 return 1;
73752 atm_return(vcc, truesize);
73753- atomic_inc(&vcc->stats->rx_drop);
73754+ atomic_inc_unchecked(&vcc->stats->rx_drop);
73755 return 0;
73756 }
73757 EXPORT_SYMBOL(atm_charge);
73758@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
73759 }
73760 }
73761 atm_return(vcc, guess);
73762- atomic_inc(&vcc->stats->rx_drop);
73763+ atomic_inc_unchecked(&vcc->stats->rx_drop);
73764 return NULL;
73765 }
73766 EXPORT_SYMBOL(atm_alloc_charge);
73767@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
73768
73769 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
73770 {
73771-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
73772+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
73773 __SONET_ITEMS
73774 #undef __HANDLE_ITEM
73775 }
73776@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
73777
73778 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
73779 {
73780-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
73781+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
73782 __SONET_ITEMS
73783 #undef __HANDLE_ITEM
73784 }
73785diff --git a/net/atm/lec.h b/net/atm/lec.h
73786index dfc0719..47c5322 100644
73787--- a/net/atm/lec.h
73788+++ b/net/atm/lec.h
73789@@ -48,7 +48,7 @@ struct lane2_ops {
73790 const u8 *tlvs, u32 sizeoftlvs);
73791 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
73792 const u8 *tlvs, u32 sizeoftlvs);
73793-};
73794+} __no_const;
73795
73796 /*
73797 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
73798diff --git a/net/atm/mpc.h b/net/atm/mpc.h
73799index 0919a88..a23d54e 100644
73800--- a/net/atm/mpc.h
73801+++ b/net/atm/mpc.h
73802@@ -33,7 +33,7 @@ struct mpoa_client {
73803 struct mpc_parameters parameters; /* parameters for this client */
73804
73805 const struct net_device_ops *old_ops;
73806- struct net_device_ops new_ops;
73807+ net_device_ops_no_const new_ops;
73808 };
73809
73810
73811diff --git a/net/atm/proc.c b/net/atm/proc.c
73812index 0d020de..011c7bb 100644
73813--- a/net/atm/proc.c
73814+++ b/net/atm/proc.c
73815@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
73816 const struct k_atm_aal_stats *stats)
73817 {
73818 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
73819- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
73820- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
73821- atomic_read(&stats->rx_drop));
73822+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
73823+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
73824+ atomic_read_unchecked(&stats->rx_drop));
73825 }
73826
73827 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
73828diff --git a/net/atm/resources.c b/net/atm/resources.c
73829index 23f45ce..c748f1a 100644
73830--- a/net/atm/resources.c
73831+++ b/net/atm/resources.c
73832@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
73833 static void copy_aal_stats(struct k_atm_aal_stats *from,
73834 struct atm_aal_stats *to)
73835 {
73836-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
73837+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
73838 __AAL_STAT_ITEMS
73839 #undef __HANDLE_ITEM
73840 }
73841@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
73842 static void subtract_aal_stats(struct k_atm_aal_stats *from,
73843 struct atm_aal_stats *to)
73844 {
73845-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
73846+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
73847 __AAL_STAT_ITEMS
73848 #undef __HANDLE_ITEM
73849 }
73850diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
73851index a6d5d63..1cc6c2b 100644
73852--- a/net/batman-adv/bat_iv_ogm.c
73853+++ b/net/batman-adv/bat_iv_ogm.c
73854@@ -539,7 +539,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
73855
73856 /* change sequence number to network order */
73857 batman_ogm_packet->seqno =
73858- htonl((uint32_t)atomic_read(&hard_iface->seqno));
73859+ htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
73860
73861 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
73862 batman_ogm_packet->tt_crc = htons((uint16_t)
73863@@ -559,7 +559,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
73864 else
73865 batman_ogm_packet->gw_flags = NO_FLAGS;
73866
73867- atomic_inc(&hard_iface->seqno);
73868+ atomic_inc_unchecked(&hard_iface->seqno);
73869
73870 slide_own_bcast_window(hard_iface);
73871 bat_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff,
73872@@ -917,7 +917,7 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
73873 return;
73874
73875 /* could be changed by schedule_own_packet() */
73876- if_incoming_seqno = atomic_read(&if_incoming->seqno);
73877+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
73878
73879 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
73880
73881diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
73882index 3778977..f6a9450 100644
73883--- a/net/batman-adv/hard-interface.c
73884+++ b/net/batman-adv/hard-interface.c
73885@@ -328,8 +328,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
73886 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
73887 dev_add_pack(&hard_iface->batman_adv_ptype);
73888
73889- atomic_set(&hard_iface->seqno, 1);
73890- atomic_set(&hard_iface->frag_seqno, 1);
73891+ atomic_set_unchecked(&hard_iface->seqno, 1);
73892+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
73893 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
73894 hard_iface->net_dev->name);
73895
73896diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
73897index a5590f4..8d31969 100644
73898--- a/net/batman-adv/soft-interface.c
73899+++ b/net/batman-adv/soft-interface.c
73900@@ -645,7 +645,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
73901
73902 /* set broadcast sequence number */
73903 bcast_packet->seqno =
73904- htonl(atomic_inc_return(&bat_priv->bcast_seqno));
73905+ htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
73906
73907 add_bcast_packet_to_list(bat_priv, skb, 1);
73908
73909@@ -841,7 +841,7 @@ struct net_device *softif_create(const char *name)
73910 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
73911
73912 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
73913- atomic_set(&bat_priv->bcast_seqno, 1);
73914+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
73915 atomic_set(&bat_priv->ttvn, 0);
73916 atomic_set(&bat_priv->tt_local_changes, 0);
73917 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
73918diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
73919index 302efb5..1590365 100644
73920--- a/net/batman-adv/types.h
73921+++ b/net/batman-adv/types.h
73922@@ -38,8 +38,8 @@ struct hard_iface {
73923 int16_t if_num;
73924 char if_status;
73925 struct net_device *net_dev;
73926- atomic_t seqno;
73927- atomic_t frag_seqno;
73928+ atomic_unchecked_t seqno;
73929+ atomic_unchecked_t frag_seqno;
73930 unsigned char *packet_buff;
73931 int packet_len;
73932 struct kobject *hardif_obj;
73933@@ -155,7 +155,7 @@ struct bat_priv {
73934 atomic_t orig_interval; /* uint */
73935 atomic_t hop_penalty; /* uint */
73936 atomic_t log_level; /* uint */
73937- atomic_t bcast_seqno;
73938+ atomic_unchecked_t bcast_seqno;
73939 atomic_t bcast_queue_left;
73940 atomic_t batman_queue_left;
73941 atomic_t ttvn; /* translation table version number */
73942diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
73943index 676f6a6..3b4e668 100644
73944--- a/net/batman-adv/unicast.c
73945+++ b/net/batman-adv/unicast.c
73946@@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
73947 frag1->flags = UNI_FRAG_HEAD | large_tail;
73948 frag2->flags = large_tail;
73949
73950- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
73951+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
73952 frag1->seqno = htons(seqno - 1);
73953 frag2->seqno = htons(seqno);
73954
73955diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
73956index 5238b6b..c9798ce 100644
73957--- a/net/bluetooth/hci_conn.c
73958+++ b/net/bluetooth/hci_conn.c
73959@@ -233,7 +233,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
73960 memset(&cp, 0, sizeof(cp));
73961
73962 cp.handle = cpu_to_le16(conn->handle);
73963- memcpy(cp.ltk, ltk, sizeof(ltk));
73964+ memcpy(cp.ltk, ltk, sizeof(cp.ltk));
73965
73966 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
73967 }
73968diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
73969index 6f9c25b..d19fd66 100644
73970--- a/net/bluetooth/l2cap_core.c
73971+++ b/net/bluetooth/l2cap_core.c
73972@@ -2466,8 +2466,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
73973 break;
73974
73975 case L2CAP_CONF_RFC:
73976- if (olen == sizeof(rfc))
73977- memcpy(&rfc, (void *)val, olen);
73978+ if (olen != sizeof(rfc))
73979+ break;
73980+
73981+ memcpy(&rfc, (void *)val, olen);
73982
73983 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
73984 rfc.mode != chan->mode)
73985@@ -2585,8 +2587,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
73986
73987 switch (type) {
73988 case L2CAP_CONF_RFC:
73989- if (olen == sizeof(rfc))
73990- memcpy(&rfc, (void *)val, olen);
73991+ if (olen != sizeof(rfc))
73992+ break;
73993+
73994+ memcpy(&rfc, (void *)val, olen);
73995 goto done;
73996 }
73997 }
73998diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
73999index 5fe2ff3..10968b5 100644
74000--- a/net/bridge/netfilter/ebtables.c
74001+++ b/net/bridge/netfilter/ebtables.c
74002@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
74003 tmp.valid_hooks = t->table->valid_hooks;
74004 }
74005 mutex_unlock(&ebt_mutex);
74006- if (copy_to_user(user, &tmp, *len) != 0){
74007+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
74008 BUGPRINT("c2u Didn't work\n");
74009 ret = -EFAULT;
74010 break;
74011diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
74012index 5cf5222..6f704ad 100644
74013--- a/net/caif/cfctrl.c
74014+++ b/net/caif/cfctrl.c
74015@@ -9,6 +9,7 @@
74016 #include <linux/stddef.h>
74017 #include <linux/spinlock.h>
74018 #include <linux/slab.h>
74019+#include <linux/sched.h>
74020 #include <net/caif/caif_layer.h>
74021 #include <net/caif/cfpkt.h>
74022 #include <net/caif/cfctrl.h>
74023@@ -42,8 +43,8 @@ struct cflayer *cfctrl_create(void)
74024 memset(&dev_info, 0, sizeof(dev_info));
74025 dev_info.id = 0xff;
74026 cfsrvl_init(&this->serv, 0, &dev_info, false);
74027- atomic_set(&this->req_seq_no, 1);
74028- atomic_set(&this->rsp_seq_no, 1);
74029+ atomic_set_unchecked(&this->req_seq_no, 1);
74030+ atomic_set_unchecked(&this->rsp_seq_no, 1);
74031 this->serv.layer.receive = cfctrl_recv;
74032 sprintf(this->serv.layer.name, "ctrl");
74033 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
74034@@ -129,8 +130,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
74035 struct cfctrl_request_info *req)
74036 {
74037 spin_lock_bh(&ctrl->info_list_lock);
74038- atomic_inc(&ctrl->req_seq_no);
74039- req->sequence_no = atomic_read(&ctrl->req_seq_no);
74040+ atomic_inc_unchecked(&ctrl->req_seq_no);
74041+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
74042 list_add_tail(&req->list, &ctrl->list);
74043 spin_unlock_bh(&ctrl->info_list_lock);
74044 }
74045@@ -148,7 +149,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
74046 if (p != first)
74047 pr_warn("Requests are not received in order\n");
74048
74049- atomic_set(&ctrl->rsp_seq_no,
74050+ atomic_set_unchecked(&ctrl->rsp_seq_no,
74051 p->sequence_no);
74052 list_del(&p->list);
74053 goto out;
74054diff --git a/net/can/gw.c b/net/can/gw.c
74055index 3d79b12..8de85fa 100644
74056--- a/net/can/gw.c
74057+++ b/net/can/gw.c
74058@@ -96,7 +96,7 @@ struct cf_mod {
74059 struct {
74060 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
74061 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
74062- } csumfunc;
74063+ } __no_const csumfunc;
74064 };
74065
74066
74067diff --git a/net/compat.c b/net/compat.c
74068index e055708..3f80795 100644
74069--- a/net/compat.c
74070+++ b/net/compat.c
74071@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
74072 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
74073 __get_user(kmsg->msg_flags, &umsg->msg_flags))
74074 return -EFAULT;
74075- kmsg->msg_name = compat_ptr(tmp1);
74076- kmsg->msg_iov = compat_ptr(tmp2);
74077- kmsg->msg_control = compat_ptr(tmp3);
74078+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
74079+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
74080+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
74081 return 0;
74082 }
74083
74084@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74085
74086 if (kern_msg->msg_namelen) {
74087 if (mode == VERIFY_READ) {
74088- int err = move_addr_to_kernel(kern_msg->msg_name,
74089+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
74090 kern_msg->msg_namelen,
74091 kern_address);
74092 if (err < 0)
74093@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74094 kern_msg->msg_name = NULL;
74095
74096 tot_len = iov_from_user_compat_to_kern(kern_iov,
74097- (struct compat_iovec __user *)kern_msg->msg_iov,
74098+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
74099 kern_msg->msg_iovlen);
74100 if (tot_len >= 0)
74101 kern_msg->msg_iov = kern_iov;
74102@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74103
74104 #define CMSG_COMPAT_FIRSTHDR(msg) \
74105 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
74106- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
74107+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
74108 (struct compat_cmsghdr __user *)NULL)
74109
74110 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
74111 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
74112 (ucmlen) <= (unsigned long) \
74113 ((mhdr)->msg_controllen - \
74114- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
74115+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
74116
74117 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
74118 struct compat_cmsghdr __user *cmsg, int cmsg_len)
74119 {
74120 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
74121- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
74122+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
74123 msg->msg_controllen)
74124 return NULL;
74125 return (struct compat_cmsghdr __user *)ptr;
74126@@ -219,7 +219,7 @@ Efault:
74127
74128 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
74129 {
74130- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74131+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74132 struct compat_cmsghdr cmhdr;
74133 int cmlen;
74134
74135@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
74136
74137 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
74138 {
74139- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74140+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74141 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
74142 int fdnum = scm->fp->count;
74143 struct file **fp = scm->fp->fp;
74144@@ -372,7 +372,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
74145 return -EFAULT;
74146 old_fs = get_fs();
74147 set_fs(KERNEL_DS);
74148- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
74149+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
74150 set_fs(old_fs);
74151
74152 return err;
74153@@ -433,7 +433,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
74154 len = sizeof(ktime);
74155 old_fs = get_fs();
74156 set_fs(KERNEL_DS);
74157- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
74158+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
74159 set_fs(old_fs);
74160
74161 if (!err) {
74162@@ -576,7 +576,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74163 case MCAST_JOIN_GROUP:
74164 case MCAST_LEAVE_GROUP:
74165 {
74166- struct compat_group_req __user *gr32 = (void *)optval;
74167+ struct compat_group_req __user *gr32 = (void __user *)optval;
74168 struct group_req __user *kgr =
74169 compat_alloc_user_space(sizeof(struct group_req));
74170 u32 interface;
74171@@ -597,7 +597,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74172 case MCAST_BLOCK_SOURCE:
74173 case MCAST_UNBLOCK_SOURCE:
74174 {
74175- struct compat_group_source_req __user *gsr32 = (void *)optval;
74176+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
74177 struct group_source_req __user *kgsr = compat_alloc_user_space(
74178 sizeof(struct group_source_req));
74179 u32 interface;
74180@@ -618,7 +618,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74181 }
74182 case MCAST_MSFILTER:
74183 {
74184- struct compat_group_filter __user *gf32 = (void *)optval;
74185+ struct compat_group_filter __user *gf32 = (void __user *)optval;
74186 struct group_filter __user *kgf;
74187 u32 interface, fmode, numsrc;
74188
74189@@ -656,7 +656,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
74190 char __user *optval, int __user *optlen,
74191 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
74192 {
74193- struct compat_group_filter __user *gf32 = (void *)optval;
74194+ struct compat_group_filter __user *gf32 = (void __user *)optval;
74195 struct group_filter __user *kgf;
74196 int __user *koptlen;
74197 u32 interface, fmode, numsrc;
74198diff --git a/net/core/datagram.c b/net/core/datagram.c
74199index e4fbfd6..6a6ac94 100644
74200--- a/net/core/datagram.c
74201+++ b/net/core/datagram.c
74202@@ -290,7 +290,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
74203 }
74204
74205 kfree_skb(skb);
74206- atomic_inc(&sk->sk_drops);
74207+ atomic_inc_unchecked(&sk->sk_drops);
74208 sk_mem_reclaim_partial(sk);
74209
74210 return err;
74211diff --git a/net/core/dev.c b/net/core/dev.c
74212index 99e1d75..adf968a 100644
74213--- a/net/core/dev.c
74214+++ b/net/core/dev.c
74215@@ -1136,9 +1136,13 @@ void dev_load(struct net *net, const char *name)
74216 if (no_module && capable(CAP_NET_ADMIN))
74217 no_module = request_module("netdev-%s", name);
74218 if (no_module && capable(CAP_SYS_MODULE)) {
74219+#ifdef CONFIG_GRKERNSEC_MODHARDEN
74220+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
74221+#else
74222 if (!request_module("%s", name))
74223 pr_err("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
74224 name);
74225+#endif
74226 }
74227 }
74228 EXPORT_SYMBOL(dev_load);
74229@@ -1602,7 +1606,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
74230 {
74231 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
74232 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
74233- atomic_long_inc(&dev->rx_dropped);
74234+ atomic_long_inc_unchecked(&dev->rx_dropped);
74235 kfree_skb(skb);
74236 return NET_RX_DROP;
74237 }
74238@@ -1612,7 +1616,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
74239 nf_reset(skb);
74240
74241 if (unlikely(!is_skb_forwardable(dev, skb))) {
74242- atomic_long_inc(&dev->rx_dropped);
74243+ atomic_long_inc_unchecked(&dev->rx_dropped);
74244 kfree_skb(skb);
74245 return NET_RX_DROP;
74246 }
74247@@ -2042,7 +2046,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
74248
74249 struct dev_gso_cb {
74250 void (*destructor)(struct sk_buff *skb);
74251-};
74252+} __no_const;
74253
74254 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
74255
74256@@ -2898,7 +2902,7 @@ enqueue:
74257
74258 local_irq_restore(flags);
74259
74260- atomic_long_inc(&skb->dev->rx_dropped);
74261+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
74262 kfree_skb(skb);
74263 return NET_RX_DROP;
74264 }
74265@@ -2970,7 +2974,7 @@ int netif_rx_ni(struct sk_buff *skb)
74266 }
74267 EXPORT_SYMBOL(netif_rx_ni);
74268
74269-static void net_tx_action(struct softirq_action *h)
74270+static void net_tx_action(void)
74271 {
74272 struct softnet_data *sd = &__get_cpu_var(softnet_data);
74273
74274@@ -3258,7 +3262,7 @@ ncls:
74275 if (pt_prev) {
74276 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
74277 } else {
74278- atomic_long_inc(&skb->dev->rx_dropped);
74279+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
74280 kfree_skb(skb);
74281 /* Jamal, now you will not able to escape explaining
74282 * me how you were going to use this. :-)
74283@@ -3818,7 +3822,7 @@ void netif_napi_del(struct napi_struct *napi)
74284 }
74285 EXPORT_SYMBOL(netif_napi_del);
74286
74287-static void net_rx_action(struct softirq_action *h)
74288+static void net_rx_action(void)
74289 {
74290 struct softnet_data *sd = &__get_cpu_var(softnet_data);
74291 unsigned long time_limit = jiffies + 2;
74292@@ -4288,8 +4292,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
74293 else
74294 seq_printf(seq, "%04x", ntohs(pt->type));
74295
74296+#ifdef CONFIG_GRKERNSEC_HIDESYM
74297+ seq_printf(seq, " %-8s %p\n",
74298+ pt->dev ? pt->dev->name : "", NULL);
74299+#else
74300 seq_printf(seq, " %-8s %pF\n",
74301 pt->dev ? pt->dev->name : "", pt->func);
74302+#endif
74303 }
74304
74305 return 0;
74306@@ -5839,7 +5848,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
74307 } else {
74308 netdev_stats_to_stats64(storage, &dev->stats);
74309 }
74310- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
74311+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
74312 return storage;
74313 }
74314 EXPORT_SYMBOL(dev_get_stats);
74315diff --git a/net/core/flow.c b/net/core/flow.c
74316index e318c7e..168b1d0 100644
74317--- a/net/core/flow.c
74318+++ b/net/core/flow.c
74319@@ -61,7 +61,7 @@ struct flow_cache {
74320 struct timer_list rnd_timer;
74321 };
74322
74323-atomic_t flow_cache_genid = ATOMIC_INIT(0);
74324+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
74325 EXPORT_SYMBOL(flow_cache_genid);
74326 static struct flow_cache flow_cache_global;
74327 static struct kmem_cache *flow_cachep __read_mostly;
74328@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
74329
74330 static int flow_entry_valid(struct flow_cache_entry *fle)
74331 {
74332- if (atomic_read(&flow_cache_genid) != fle->genid)
74333+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
74334 return 0;
74335 if (fle->object && !fle->object->ops->check(fle->object))
74336 return 0;
74337@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
74338 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
74339 fcp->hash_count++;
74340 }
74341- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
74342+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
74343 flo = fle->object;
74344 if (!flo)
74345 goto ret_object;
74346@@ -280,7 +280,7 @@ nocache:
74347 }
74348 flo = resolver(net, key, family, dir, flo, ctx);
74349 if (fle) {
74350- fle->genid = atomic_read(&flow_cache_genid);
74351+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
74352 if (!IS_ERR(flo))
74353 fle->object = flo;
74354 else
74355diff --git a/net/core/iovec.c b/net/core/iovec.c
74356index 7e7aeb0..2a998cb 100644
74357--- a/net/core/iovec.c
74358+++ b/net/core/iovec.c
74359@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
74360 if (m->msg_namelen) {
74361 if (mode == VERIFY_READ) {
74362 void __user *namep;
74363- namep = (void __user __force *) m->msg_name;
74364+ namep = (void __force_user *) m->msg_name;
74365 err = move_addr_to_kernel(namep, m->msg_namelen,
74366 address);
74367 if (err < 0)
74368@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
74369 }
74370
74371 size = m->msg_iovlen * sizeof(struct iovec);
74372- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
74373+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
74374 return -EFAULT;
74375
74376 m->msg_iov = iov;
74377diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
74378index 90430b7..0032ec0 100644
74379--- a/net/core/rtnetlink.c
74380+++ b/net/core/rtnetlink.c
74381@@ -56,7 +56,7 @@ struct rtnl_link {
74382 rtnl_doit_func doit;
74383 rtnl_dumpit_func dumpit;
74384 rtnl_calcit_func calcit;
74385-};
74386+} __no_const;
74387
74388 static DEFINE_MUTEX(rtnl_mutex);
74389
74390diff --git a/net/core/scm.c b/net/core/scm.c
74391index 611c5ef..88f6d6d 100644
74392--- a/net/core/scm.c
74393+++ b/net/core/scm.c
74394@@ -219,7 +219,7 @@ EXPORT_SYMBOL(__scm_send);
74395 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
74396 {
74397 struct cmsghdr __user *cm
74398- = (__force struct cmsghdr __user *)msg->msg_control;
74399+ = (struct cmsghdr __force_user *)msg->msg_control;
74400 struct cmsghdr cmhdr;
74401 int cmlen = CMSG_LEN(len);
74402 int err;
74403@@ -242,7 +242,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
74404 err = -EFAULT;
74405 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
74406 goto out;
74407- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
74408+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
74409 goto out;
74410 cmlen = CMSG_SPACE(len);
74411 if (msg->msg_controllen < cmlen)
74412@@ -258,7 +258,7 @@ EXPORT_SYMBOL(put_cmsg);
74413 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
74414 {
74415 struct cmsghdr __user *cm
74416- = (__force struct cmsghdr __user*)msg->msg_control;
74417+ = (struct cmsghdr __force_user *)msg->msg_control;
74418
74419 int fdmax = 0;
74420 int fdnum = scm->fp->count;
74421@@ -278,7 +278,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
74422 if (fdnum < fdmax)
74423 fdmax = fdnum;
74424
74425- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
74426+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
74427 i++, cmfptr++)
74428 {
74429 int new_fd;
74430diff --git a/net/core/sock.c b/net/core/sock.c
74431index b2e14c0..6651b32 100644
74432--- a/net/core/sock.c
74433+++ b/net/core/sock.c
74434@@ -340,7 +340,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74435 struct sk_buff_head *list = &sk->sk_receive_queue;
74436
74437 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
74438- atomic_inc(&sk->sk_drops);
74439+ atomic_inc_unchecked(&sk->sk_drops);
74440 trace_sock_rcvqueue_full(sk, skb);
74441 return -ENOMEM;
74442 }
74443@@ -350,7 +350,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74444 return err;
74445
74446 if (!sk_rmem_schedule(sk, skb->truesize)) {
74447- atomic_inc(&sk->sk_drops);
74448+ atomic_inc_unchecked(&sk->sk_drops);
74449 return -ENOBUFS;
74450 }
74451
74452@@ -370,7 +370,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74453 skb_dst_force(skb);
74454
74455 spin_lock_irqsave(&list->lock, flags);
74456- skb->dropcount = atomic_read(&sk->sk_drops);
74457+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
74458 __skb_queue_tail(list, skb);
74459 spin_unlock_irqrestore(&list->lock, flags);
74460
74461@@ -390,7 +390,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
74462 skb->dev = NULL;
74463
74464 if (sk_rcvqueues_full(sk, skb)) {
74465- atomic_inc(&sk->sk_drops);
74466+ atomic_inc_unchecked(&sk->sk_drops);
74467 goto discard_and_relse;
74468 }
74469 if (nested)
74470@@ -408,7 +408,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
74471 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
74472 } else if (sk_add_backlog(sk, skb)) {
74473 bh_unlock_sock(sk);
74474- atomic_inc(&sk->sk_drops);
74475+ atomic_inc_unchecked(&sk->sk_drops);
74476 goto discard_and_relse;
74477 }
74478
74479@@ -984,7 +984,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74480 if (len > sizeof(peercred))
74481 len = sizeof(peercred);
74482 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
74483- if (copy_to_user(optval, &peercred, len))
74484+ if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
74485 return -EFAULT;
74486 goto lenout;
74487 }
74488@@ -997,7 +997,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74489 return -ENOTCONN;
74490 if (lv < len)
74491 return -EINVAL;
74492- if (copy_to_user(optval, address, len))
74493+ if (len > sizeof(address) || copy_to_user(optval, address, len))
74494 return -EFAULT;
74495 goto lenout;
74496 }
74497@@ -1043,7 +1043,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74498
74499 if (len > lv)
74500 len = lv;
74501- if (copy_to_user(optval, &v, len))
74502+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
74503 return -EFAULT;
74504 lenout:
74505 if (put_user(len, optlen))
74506@@ -2128,7 +2128,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
74507 */
74508 smp_wmb();
74509 atomic_set(&sk->sk_refcnt, 1);
74510- atomic_set(&sk->sk_drops, 0);
74511+ atomic_set_unchecked(&sk->sk_drops, 0);
74512 }
74513 EXPORT_SYMBOL(sock_init_data);
74514
74515diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
74516index b9868e1..849f809 100644
74517--- a/net/core/sock_diag.c
74518+++ b/net/core/sock_diag.c
74519@@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
74520
74521 int sock_diag_check_cookie(void *sk, __u32 *cookie)
74522 {
74523+#ifndef CONFIG_GRKERNSEC_HIDESYM
74524 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
74525 cookie[1] != INET_DIAG_NOCOOKIE) &&
74526 ((u32)(unsigned long)sk != cookie[0] ||
74527 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
74528 return -ESTALE;
74529 else
74530+#endif
74531 return 0;
74532 }
74533 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
74534
74535 void sock_diag_save_cookie(void *sk, __u32 *cookie)
74536 {
74537+#ifdef CONFIG_GRKERNSEC_HIDESYM
74538+ cookie[0] = 0;
74539+ cookie[1] = 0;
74540+#else
74541 cookie[0] = (u32)(unsigned long)sk;
74542 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
74543+#endif
74544 }
74545 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
74546
74547diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
74548index 02e75d1..9a57a7c 100644
74549--- a/net/decnet/sysctl_net_decnet.c
74550+++ b/net/decnet/sysctl_net_decnet.c
74551@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
74552
74553 if (len > *lenp) len = *lenp;
74554
74555- if (copy_to_user(buffer, addr, len))
74556+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
74557 return -EFAULT;
74558
74559 *lenp = len;
74560@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
74561
74562 if (len > *lenp) len = *lenp;
74563
74564- if (copy_to_user(buffer, devname, len))
74565+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
74566 return -EFAULT;
74567
74568 *lenp = len;
74569diff --git a/net/econet/Kconfig b/net/econet/Kconfig
74570index 39a2d29..f39c0fe 100644
74571--- a/net/econet/Kconfig
74572+++ b/net/econet/Kconfig
74573@@ -4,7 +4,7 @@
74574
74575 config ECONET
74576 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
74577- depends on EXPERIMENTAL && INET
74578+ depends on EXPERIMENTAL && INET && BROKEN
74579 ---help---
74580 Econet is a fairly old and slow networking protocol mainly used by
74581 Acorn computers to access file and print servers. It uses native
74582diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
74583index cbe3a68..a879b75 100644
74584--- a/net/ipv4/fib_frontend.c
74585+++ b/net/ipv4/fib_frontend.c
74586@@ -969,12 +969,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
74587 #ifdef CONFIG_IP_ROUTE_MULTIPATH
74588 fib_sync_up(dev);
74589 #endif
74590- atomic_inc(&net->ipv4.dev_addr_genid);
74591+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74592 rt_cache_flush(dev_net(dev), -1);
74593 break;
74594 case NETDEV_DOWN:
74595 fib_del_ifaddr(ifa, NULL);
74596- atomic_inc(&net->ipv4.dev_addr_genid);
74597+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74598 if (ifa->ifa_dev->ifa_list == NULL) {
74599 /* Last address was deleted from this interface.
74600 * Disable IP.
74601@@ -1010,7 +1010,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
74602 #ifdef CONFIG_IP_ROUTE_MULTIPATH
74603 fib_sync_up(dev);
74604 #endif
74605- atomic_inc(&net->ipv4.dev_addr_genid);
74606+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74607 rt_cache_flush(dev_net(dev), -1);
74608 break;
74609 case NETDEV_DOWN:
74610diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
74611index 8861f91..ab1e3c1 100644
74612--- a/net/ipv4/fib_semantics.c
74613+++ b/net/ipv4/fib_semantics.c
74614@@ -698,7 +698,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
74615 nh->nh_saddr = inet_select_addr(nh->nh_dev,
74616 nh->nh_gw,
74617 nh->nh_parent->fib_scope);
74618- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
74619+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
74620
74621 return nh->nh_saddr;
74622 }
74623diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
74624index 984ec65..97ac518 100644
74625--- a/net/ipv4/inet_hashtables.c
74626+++ b/net/ipv4/inet_hashtables.c
74627@@ -18,12 +18,15 @@
74628 #include <linux/sched.h>
74629 #include <linux/slab.h>
74630 #include <linux/wait.h>
74631+#include <linux/security.h>
74632
74633 #include <net/inet_connection_sock.h>
74634 #include <net/inet_hashtables.h>
74635 #include <net/secure_seq.h>
74636 #include <net/ip.h>
74637
74638+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
74639+
74640 /*
74641 * Allocate and initialize a new local port bind bucket.
74642 * The bindhash mutex for snum's hash chain must be held here.
74643@@ -530,6 +533,8 @@ ok:
74644 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
74645 spin_unlock(&head->lock);
74646
74647+ gr_update_task_in_ip_table(current, inet_sk(sk));
74648+
74649 if (tw) {
74650 inet_twsk_deschedule(tw, death_row);
74651 while (twrefcnt) {
74652diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
74653index d4d61b6..b81aec8 100644
74654--- a/net/ipv4/inetpeer.c
74655+++ b/net/ipv4/inetpeer.c
74656@@ -487,8 +487,8 @@ relookup:
74657 if (p) {
74658 p->daddr = *daddr;
74659 atomic_set(&p->refcnt, 1);
74660- atomic_set(&p->rid, 0);
74661- atomic_set(&p->ip_id_count,
74662+ atomic_set_unchecked(&p->rid, 0);
74663+ atomic_set_unchecked(&p->ip_id_count,
74664 (daddr->family == AF_INET) ?
74665 secure_ip_id(daddr->addr.a4) :
74666 secure_ipv6_id(daddr->addr.a6));
74667diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
74668index 3727e23..517f5df 100644
74669--- a/net/ipv4/ip_fragment.c
74670+++ b/net/ipv4/ip_fragment.c
74671@@ -318,7 +318,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
74672 return 0;
74673
74674 start = qp->rid;
74675- end = atomic_inc_return(&peer->rid);
74676+ end = atomic_inc_return_unchecked(&peer->rid);
74677 qp->rid = end;
74678
74679 rc = qp->q.fragments && (end - start) > max;
74680diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
74681index 2fd0fba..83fac99 100644
74682--- a/net/ipv4/ip_sockglue.c
74683+++ b/net/ipv4/ip_sockglue.c
74684@@ -1137,7 +1137,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
74685 len = min_t(unsigned int, len, opt->optlen);
74686 if (put_user(len, optlen))
74687 return -EFAULT;
74688- if (copy_to_user(optval, opt->__data, len))
74689+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
74690+ copy_to_user(optval, opt->__data, len))
74691 return -EFAULT;
74692 return 0;
74693 }
74694@@ -1268,7 +1269,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
74695 if (sk->sk_type != SOCK_STREAM)
74696 return -ENOPROTOOPT;
74697
74698- msg.msg_control = optval;
74699+ msg.msg_control = (void __force_kernel *)optval;
74700 msg.msg_controllen = len;
74701 msg.msg_flags = flags;
74702
74703diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
74704index 92ac7e7..13f93d9 100644
74705--- a/net/ipv4/ipconfig.c
74706+++ b/net/ipv4/ipconfig.c
74707@@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
74708
74709 mm_segment_t oldfs = get_fs();
74710 set_fs(get_ds());
74711- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
74712+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
74713 set_fs(oldfs);
74714 return res;
74715 }
74716@@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
74717
74718 mm_segment_t oldfs = get_fs();
74719 set_fs(get_ds());
74720- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
74721+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
74722 set_fs(oldfs);
74723 return res;
74724 }
74725@@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
74726
74727 mm_segment_t oldfs = get_fs();
74728 set_fs(get_ds());
74729- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
74730+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
74731 set_fs(oldfs);
74732 return res;
74733 }
74734diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
74735index 50009c7..5996a9f 100644
74736--- a/net/ipv4/ping.c
74737+++ b/net/ipv4/ping.c
74738@@ -838,7 +838,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
74739 sk_rmem_alloc_get(sp),
74740 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
74741 atomic_read(&sp->sk_refcnt), sp,
74742- atomic_read(&sp->sk_drops), len);
74743+ atomic_read_unchecked(&sp->sk_drops), len);
74744 }
74745
74746 static int ping_seq_show(struct seq_file *seq, void *v)
74747diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
74748index bbd604c..4d5469c 100644
74749--- a/net/ipv4/raw.c
74750+++ b/net/ipv4/raw.c
74751@@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
74752 int raw_rcv(struct sock *sk, struct sk_buff *skb)
74753 {
74754 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
74755- atomic_inc(&sk->sk_drops);
74756+ atomic_inc_unchecked(&sk->sk_drops);
74757 kfree_skb(skb);
74758 return NET_RX_DROP;
74759 }
74760@@ -740,16 +740,20 @@ static int raw_init(struct sock *sk)
74761
74762 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
74763 {
74764+ struct icmp_filter filter;
74765+
74766 if (optlen > sizeof(struct icmp_filter))
74767 optlen = sizeof(struct icmp_filter);
74768- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
74769+ if (copy_from_user(&filter, optval, optlen))
74770 return -EFAULT;
74771+ raw_sk(sk)->filter = filter;
74772 return 0;
74773 }
74774
74775 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
74776 {
74777 int len, ret = -EFAULT;
74778+ struct icmp_filter filter;
74779
74780 if (get_user(len, optlen))
74781 goto out;
74782@@ -759,8 +763,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
74783 if (len > sizeof(struct icmp_filter))
74784 len = sizeof(struct icmp_filter);
74785 ret = -EFAULT;
74786- if (put_user(len, optlen) ||
74787- copy_to_user(optval, &raw_sk(sk)->filter, len))
74788+ filter = raw_sk(sk)->filter;
74789+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
74790 goto out;
74791 ret = 0;
74792 out: return ret;
74793@@ -988,7 +992,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
74794 sk_wmem_alloc_get(sp),
74795 sk_rmem_alloc_get(sp),
74796 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
74797- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
74798+ atomic_read(&sp->sk_refcnt),
74799+#ifdef CONFIG_GRKERNSEC_HIDESYM
74800+ NULL,
74801+#else
74802+ sp,
74803+#endif
74804+ atomic_read_unchecked(&sp->sk_drops));
74805 }
74806
74807 static int raw_seq_show(struct seq_file *seq, void *v)
74808diff --git a/net/ipv4/route.c b/net/ipv4/route.c
74809index 167ea10..4b15883 100644
74810--- a/net/ipv4/route.c
74811+++ b/net/ipv4/route.c
74812@@ -312,7 +312,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
74813
74814 static inline int rt_genid(struct net *net)
74815 {
74816- return atomic_read(&net->ipv4.rt_genid);
74817+ return atomic_read_unchecked(&net->ipv4.rt_genid);
74818 }
74819
74820 #ifdef CONFIG_PROC_FS
74821@@ -936,7 +936,7 @@ static void rt_cache_invalidate(struct net *net)
74822 unsigned char shuffle;
74823
74824 get_random_bytes(&shuffle, sizeof(shuffle));
74825- atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
74826+ atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
74827 inetpeer_invalidate_tree(AF_INET);
74828 }
74829
74830@@ -3009,7 +3009,7 @@ static int rt_fill_info(struct net *net,
74831 error = rt->dst.error;
74832 if (peer) {
74833 inet_peer_refcheck(rt->peer);
74834- id = atomic_read(&peer->ip_id_count) & 0xffff;
74835+ id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
74836 if (peer->tcp_ts_stamp) {
74837 ts = peer->tcp_ts;
74838 tsage = get_seconds() - peer->tcp_ts_stamp;
74839diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
74840index 0cb86ce..8e7fda8 100644
74841--- a/net/ipv4/tcp_ipv4.c
74842+++ b/net/ipv4/tcp_ipv4.c
74843@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
74844 EXPORT_SYMBOL(sysctl_tcp_low_latency);
74845
74846
74847+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74848+extern int grsec_enable_blackhole;
74849+#endif
74850+
74851 #ifdef CONFIG_TCP_MD5SIG
74852 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
74853 __be32 daddr, __be32 saddr, const struct tcphdr *th);
74854@@ -1641,6 +1645,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
74855 return 0;
74856
74857 reset:
74858+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74859+ if (!grsec_enable_blackhole)
74860+#endif
74861 tcp_v4_send_reset(rsk, skb);
74862 discard:
74863 kfree_skb(skb);
74864@@ -1703,12 +1710,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
74865 TCP_SKB_CB(skb)->sacked = 0;
74866
74867 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
74868- if (!sk)
74869+ if (!sk) {
74870+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74871+ ret = 1;
74872+#endif
74873 goto no_tcp_socket;
74874-
74875+ }
74876 process:
74877- if (sk->sk_state == TCP_TIME_WAIT)
74878+ if (sk->sk_state == TCP_TIME_WAIT) {
74879+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74880+ ret = 2;
74881+#endif
74882 goto do_time_wait;
74883+ }
74884
74885 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
74886 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
74887@@ -1758,6 +1772,10 @@ no_tcp_socket:
74888 bad_packet:
74889 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
74890 } else {
74891+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74892+ if (!grsec_enable_blackhole || (ret == 1 &&
74893+ (skb->dev->flags & IFF_LOOPBACK)))
74894+#endif
74895 tcp_v4_send_reset(NULL, skb);
74896 }
74897
74898@@ -2419,7 +2437,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
74899 0, /* non standard timer */
74900 0, /* open_requests have no inode */
74901 atomic_read(&sk->sk_refcnt),
74902+#ifdef CONFIG_GRKERNSEC_HIDESYM
74903+ NULL,
74904+#else
74905 req,
74906+#endif
74907 len);
74908 }
74909
74910@@ -2469,7 +2491,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
74911 sock_i_uid(sk),
74912 icsk->icsk_probes_out,
74913 sock_i_ino(sk),
74914- atomic_read(&sk->sk_refcnt), sk,
74915+ atomic_read(&sk->sk_refcnt),
74916+#ifdef CONFIG_GRKERNSEC_HIDESYM
74917+ NULL,
74918+#else
74919+ sk,
74920+#endif
74921 jiffies_to_clock_t(icsk->icsk_rto),
74922 jiffies_to_clock_t(icsk->icsk_ack.ato),
74923 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
74924@@ -2497,7 +2524,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
74925 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
74926 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
74927 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
74928- atomic_read(&tw->tw_refcnt), tw, len);
74929+ atomic_read(&tw->tw_refcnt),
74930+#ifdef CONFIG_GRKERNSEC_HIDESYM
74931+ NULL,
74932+#else
74933+ tw,
74934+#endif
74935+ len);
74936 }
74937
74938 #define TMPSZ 150
74939diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
74940index 3cabafb..640525b 100644
74941--- a/net/ipv4/tcp_minisocks.c
74942+++ b/net/ipv4/tcp_minisocks.c
74943@@ -27,6 +27,10 @@
74944 #include <net/inet_common.h>
74945 #include <net/xfrm.h>
74946
74947+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74948+extern int grsec_enable_blackhole;
74949+#endif
74950+
74951 int sysctl_tcp_syncookies __read_mostly = 1;
74952 EXPORT_SYMBOL(sysctl_tcp_syncookies);
74953
74954@@ -753,6 +757,10 @@ listen_overflow:
74955
74956 embryonic_reset:
74957 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
74958+
74959+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74960+ if (!grsec_enable_blackhole)
74961+#endif
74962 if (!(flg & TCP_FLAG_RST))
74963 req->rsk_ops->send_reset(sk, skb);
74964
74965diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
74966index a981cdc..48f4c3a 100644
74967--- a/net/ipv4/tcp_probe.c
74968+++ b/net/ipv4/tcp_probe.c
74969@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
74970 if (cnt + width >= len)
74971 break;
74972
74973- if (copy_to_user(buf + cnt, tbuf, width))
74974+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
74975 return -EFAULT;
74976 cnt += width;
74977 }
74978diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
74979index 34d4a02..3b57f86 100644
74980--- a/net/ipv4/tcp_timer.c
74981+++ b/net/ipv4/tcp_timer.c
74982@@ -22,6 +22,10 @@
74983 #include <linux/gfp.h>
74984 #include <net/tcp.h>
74985
74986+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74987+extern int grsec_lastack_retries;
74988+#endif
74989+
74990 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
74991 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
74992 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
74993@@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
74994 }
74995 }
74996
74997+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74998+ if ((sk->sk_state == TCP_LAST_ACK) &&
74999+ (grsec_lastack_retries > 0) &&
75000+ (grsec_lastack_retries < retry_until))
75001+ retry_until = grsec_lastack_retries;
75002+#endif
75003+
75004 if (retransmits_timed_out(sk, retry_until,
75005 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
75006 /* Has it gone just too far? */
75007diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
75008index fe14105..0618260 100644
75009--- a/net/ipv4/udp.c
75010+++ b/net/ipv4/udp.c
75011@@ -87,6 +87,7 @@
75012 #include <linux/types.h>
75013 #include <linux/fcntl.h>
75014 #include <linux/module.h>
75015+#include <linux/security.h>
75016 #include <linux/socket.h>
75017 #include <linux/sockios.h>
75018 #include <linux/igmp.h>
75019@@ -109,6 +110,10 @@
75020 #include <trace/events/udp.h>
75021 #include "udp_impl.h"
75022
75023+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75024+extern int grsec_enable_blackhole;
75025+#endif
75026+
75027 struct udp_table udp_table __read_mostly;
75028 EXPORT_SYMBOL(udp_table);
75029
75030@@ -567,6 +572,9 @@ found:
75031 return s;
75032 }
75033
75034+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
75035+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
75036+
75037 /*
75038 * This routine is called by the ICMP module when it gets some
75039 * sort of error condition. If err < 0 then the socket should
75040@@ -858,9 +866,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
75041 dport = usin->sin_port;
75042 if (dport == 0)
75043 return -EINVAL;
75044+
75045+ err = gr_search_udp_sendmsg(sk, usin);
75046+ if (err)
75047+ return err;
75048 } else {
75049 if (sk->sk_state != TCP_ESTABLISHED)
75050 return -EDESTADDRREQ;
75051+
75052+ err = gr_search_udp_sendmsg(sk, NULL);
75053+ if (err)
75054+ return err;
75055+
75056 daddr = inet->inet_daddr;
75057 dport = inet->inet_dport;
75058 /* Open fast path for connected socket.
75059@@ -1102,7 +1119,7 @@ static unsigned int first_packet_length(struct sock *sk)
75060 udp_lib_checksum_complete(skb)) {
75061 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75062 IS_UDPLITE(sk));
75063- atomic_inc(&sk->sk_drops);
75064+ atomic_inc_unchecked(&sk->sk_drops);
75065 __skb_unlink(skb, rcvq);
75066 __skb_queue_tail(&list_kill, skb);
75067 }
75068@@ -1188,6 +1205,10 @@ try_again:
75069 if (!skb)
75070 goto out;
75071
75072+ err = gr_search_udp_recvmsg(sk, skb);
75073+ if (err)
75074+ goto out_free;
75075+
75076 ulen = skb->len - sizeof(struct udphdr);
75077 copied = len;
75078 if (copied > ulen)
75079@@ -1489,7 +1510,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75080
75081 drop:
75082 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
75083- atomic_inc(&sk->sk_drops);
75084+ atomic_inc_unchecked(&sk->sk_drops);
75085 kfree_skb(skb);
75086 return -1;
75087 }
75088@@ -1508,7 +1529,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
75089 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
75090
75091 if (!skb1) {
75092- atomic_inc(&sk->sk_drops);
75093+ atomic_inc_unchecked(&sk->sk_drops);
75094 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
75095 IS_UDPLITE(sk));
75096 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75097@@ -1677,6 +1698,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75098 goto csum_error;
75099
75100 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
75101+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75102+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
75103+#endif
75104 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
75105
75106 /*
75107@@ -2094,8 +2118,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
75108 sk_wmem_alloc_get(sp),
75109 sk_rmem_alloc_get(sp),
75110 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75111- atomic_read(&sp->sk_refcnt), sp,
75112- atomic_read(&sp->sk_drops), len);
75113+ atomic_read(&sp->sk_refcnt),
75114+#ifdef CONFIG_GRKERNSEC_HIDESYM
75115+ NULL,
75116+#else
75117+ sp,
75118+#endif
75119+ atomic_read_unchecked(&sp->sk_drops), len);
75120 }
75121
75122 int udp4_seq_show(struct seq_file *seq, void *v)
75123diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
75124index 7d5cb97..c56564f 100644
75125--- a/net/ipv6/addrconf.c
75126+++ b/net/ipv6/addrconf.c
75127@@ -2142,7 +2142,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
75128 p.iph.ihl = 5;
75129 p.iph.protocol = IPPROTO_IPV6;
75130 p.iph.ttl = 64;
75131- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
75132+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
75133
75134 if (ops->ndo_do_ioctl) {
75135 mm_segment_t oldfs = get_fs();
75136diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
75137index 02dd203..e03fcc9 100644
75138--- a/net/ipv6/inet6_connection_sock.c
75139+++ b/net/ipv6/inet6_connection_sock.c
75140@@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
75141 #ifdef CONFIG_XFRM
75142 {
75143 struct rt6_info *rt = (struct rt6_info *)dst;
75144- rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
75145+ rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
75146 }
75147 #endif
75148 }
75149@@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
75150 #ifdef CONFIG_XFRM
75151 if (dst) {
75152 struct rt6_info *rt = (struct rt6_info *)dst;
75153- if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
75154+ if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
75155 __sk_dst_reset(sk);
75156 dst = NULL;
75157 }
75158diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
75159index 63dd1f8..e7f53ca 100644
75160--- a/net/ipv6/ipv6_sockglue.c
75161+++ b/net/ipv6/ipv6_sockglue.c
75162@@ -990,7 +990,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
75163 if (sk->sk_type != SOCK_STREAM)
75164 return -ENOPROTOOPT;
75165
75166- msg.msg_control = optval;
75167+ msg.msg_control = (void __force_kernel *)optval;
75168 msg.msg_controllen = len;
75169 msg.msg_flags = flags;
75170
75171diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
75172index 5bddea7..82d9d67 100644
75173--- a/net/ipv6/raw.c
75174+++ b/net/ipv6/raw.c
75175@@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
75176 {
75177 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
75178 skb_checksum_complete(skb)) {
75179- atomic_inc(&sk->sk_drops);
75180+ atomic_inc_unchecked(&sk->sk_drops);
75181 kfree_skb(skb);
75182 return NET_RX_DROP;
75183 }
75184@@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
75185 struct raw6_sock *rp = raw6_sk(sk);
75186
75187 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
75188- atomic_inc(&sk->sk_drops);
75189+ atomic_inc_unchecked(&sk->sk_drops);
75190 kfree_skb(skb);
75191 return NET_RX_DROP;
75192 }
75193@@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
75194
75195 if (inet->hdrincl) {
75196 if (skb_checksum_complete(skb)) {
75197- atomic_inc(&sk->sk_drops);
75198+ atomic_inc_unchecked(&sk->sk_drops);
75199 kfree_skb(skb);
75200 return NET_RX_DROP;
75201 }
75202@@ -602,7 +602,7 @@ out:
75203 return err;
75204 }
75205
75206-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
75207+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
75208 struct flowi6 *fl6, struct dst_entry **dstp,
75209 unsigned int flags)
75210 {
75211@@ -914,12 +914,15 @@ do_confirm:
75212 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
75213 char __user *optval, int optlen)
75214 {
75215+ struct icmp6_filter filter;
75216+
75217 switch (optname) {
75218 case ICMPV6_FILTER:
75219 if (optlen > sizeof(struct icmp6_filter))
75220 optlen = sizeof(struct icmp6_filter);
75221- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
75222+ if (copy_from_user(&filter, optval, optlen))
75223 return -EFAULT;
75224+ raw6_sk(sk)->filter = filter;
75225 return 0;
75226 default:
75227 return -ENOPROTOOPT;
75228@@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
75229 char __user *optval, int __user *optlen)
75230 {
75231 int len;
75232+ struct icmp6_filter filter;
75233
75234 switch (optname) {
75235 case ICMPV6_FILTER:
75236@@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
75237 len = sizeof(struct icmp6_filter);
75238 if (put_user(len, optlen))
75239 return -EFAULT;
75240- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
75241+ filter = raw6_sk(sk)->filter;
75242+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
75243 return -EFAULT;
75244 return 0;
75245 default:
75246@@ -1250,7 +1255,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
75247 0, 0L, 0,
75248 sock_i_uid(sp), 0,
75249 sock_i_ino(sp),
75250- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
75251+ atomic_read(&sp->sk_refcnt),
75252+#ifdef CONFIG_GRKERNSEC_HIDESYM
75253+ NULL,
75254+#else
75255+ sp,
75256+#endif
75257+ atomic_read_unchecked(&sp->sk_drops));
75258 }
75259
75260 static int raw6_seq_show(struct seq_file *seq, void *v)
75261diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
75262index 98256cf..7f16dbd 100644
75263--- a/net/ipv6/tcp_ipv6.c
75264+++ b/net/ipv6/tcp_ipv6.c
75265@@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
75266 }
75267 #endif
75268
75269+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75270+extern int grsec_enable_blackhole;
75271+#endif
75272+
75273 static void tcp_v6_hash(struct sock *sk)
75274 {
75275 if (sk->sk_state != TCP_CLOSE) {
75276@@ -1542,6 +1546,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
75277 return 0;
75278
75279 reset:
75280+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75281+ if (!grsec_enable_blackhole)
75282+#endif
75283 tcp_v6_send_reset(sk, skb);
75284 discard:
75285 if (opt_skb)
75286@@ -1623,12 +1630,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
75287 TCP_SKB_CB(skb)->sacked = 0;
75288
75289 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
75290- if (!sk)
75291+ if (!sk) {
75292+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75293+ ret = 1;
75294+#endif
75295 goto no_tcp_socket;
75296+ }
75297
75298 process:
75299- if (sk->sk_state == TCP_TIME_WAIT)
75300+ if (sk->sk_state == TCP_TIME_WAIT) {
75301+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75302+ ret = 2;
75303+#endif
75304 goto do_time_wait;
75305+ }
75306
75307 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
75308 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
75309@@ -1676,6 +1691,10 @@ no_tcp_socket:
75310 bad_packet:
75311 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
75312 } else {
75313+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75314+ if (!grsec_enable_blackhole || (ret == 1 &&
75315+ (skb->dev->flags & IFF_LOOPBACK)))
75316+#endif
75317 tcp_v6_send_reset(NULL, skb);
75318 }
75319
75320@@ -1930,7 +1949,13 @@ static void get_openreq6(struct seq_file *seq,
75321 uid,
75322 0, /* non standard timer */
75323 0, /* open_requests have no inode */
75324- 0, req);
75325+ 0,
75326+#ifdef CONFIG_GRKERNSEC_HIDESYM
75327+ NULL
75328+#else
75329+ req
75330+#endif
75331+ );
75332 }
75333
75334 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
75335@@ -1980,7 +2005,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
75336 sock_i_uid(sp),
75337 icsk->icsk_probes_out,
75338 sock_i_ino(sp),
75339- atomic_read(&sp->sk_refcnt), sp,
75340+ atomic_read(&sp->sk_refcnt),
75341+#ifdef CONFIG_GRKERNSEC_HIDESYM
75342+ NULL,
75343+#else
75344+ sp,
75345+#endif
75346 jiffies_to_clock_t(icsk->icsk_rto),
75347 jiffies_to_clock_t(icsk->icsk_ack.ato),
75348 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
75349@@ -2015,7 +2045,13 @@ static void get_timewait6_sock(struct seq_file *seq,
75350 dest->s6_addr32[2], dest->s6_addr32[3], destp,
75351 tw->tw_substate, 0, 0,
75352 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
75353- atomic_read(&tw->tw_refcnt), tw);
75354+ atomic_read(&tw->tw_refcnt),
75355+#ifdef CONFIG_GRKERNSEC_HIDESYM
75356+ NULL
75357+#else
75358+ tw
75359+#endif
75360+ );
75361 }
75362
75363 static int tcp6_seq_show(struct seq_file *seq, void *v)
75364diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
75365index 37b0699..d323408 100644
75366--- a/net/ipv6/udp.c
75367+++ b/net/ipv6/udp.c
75368@@ -50,6 +50,10 @@
75369 #include <linux/seq_file.h>
75370 #include "udp_impl.h"
75371
75372+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75373+extern int grsec_enable_blackhole;
75374+#endif
75375+
75376 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
75377 {
75378 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
75379@@ -551,7 +555,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
75380
75381 return 0;
75382 drop:
75383- atomic_inc(&sk->sk_drops);
75384+ atomic_inc_unchecked(&sk->sk_drops);
75385 drop_no_sk_drops_inc:
75386 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
75387 kfree_skb(skb);
75388@@ -627,7 +631,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
75389 continue;
75390 }
75391 drop:
75392- atomic_inc(&sk->sk_drops);
75393+ atomic_inc_unchecked(&sk->sk_drops);
75394 UDP6_INC_STATS_BH(sock_net(sk),
75395 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
75396 UDP6_INC_STATS_BH(sock_net(sk),
75397@@ -782,6 +786,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75398 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
75399 proto == IPPROTO_UDPLITE);
75400
75401+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75402+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
75403+#endif
75404 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
75405
75406 kfree_skb(skb);
75407@@ -798,7 +805,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75408 if (!sock_owned_by_user(sk))
75409 udpv6_queue_rcv_skb(sk, skb);
75410 else if (sk_add_backlog(sk, skb)) {
75411- atomic_inc(&sk->sk_drops);
75412+ atomic_inc_unchecked(&sk->sk_drops);
75413 bh_unlock_sock(sk);
75414 sock_put(sk);
75415 goto discard;
75416@@ -1411,8 +1418,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
75417 0, 0L, 0,
75418 sock_i_uid(sp), 0,
75419 sock_i_ino(sp),
75420- atomic_read(&sp->sk_refcnt), sp,
75421- atomic_read(&sp->sk_drops));
75422+ atomic_read(&sp->sk_refcnt),
75423+#ifdef CONFIG_GRKERNSEC_HIDESYM
75424+ NULL,
75425+#else
75426+ sp,
75427+#endif
75428+ atomic_read_unchecked(&sp->sk_drops));
75429 }
75430
75431 int udp6_seq_show(struct seq_file *seq, void *v)
75432diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
75433index 6b9d5a0..4dffaf1 100644
75434--- a/net/irda/ircomm/ircomm_tty.c
75435+++ b/net/irda/ircomm/ircomm_tty.c
75436@@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75437 add_wait_queue(&self->open_wait, &wait);
75438
75439 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
75440- __FILE__,__LINE__, tty->driver->name, self->open_count );
75441+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
75442
75443 /* As far as I can see, we protect open_count - Jean II */
75444 spin_lock_irqsave(&self->spinlock, flags);
75445 if (!tty_hung_up_p(filp)) {
75446 extra_count = 1;
75447- self->open_count--;
75448+ local_dec(&self->open_count);
75449 }
75450 spin_unlock_irqrestore(&self->spinlock, flags);
75451- self->blocked_open++;
75452+ local_inc(&self->blocked_open);
75453
75454 while (1) {
75455 if (tty->termios->c_cflag & CBAUD) {
75456@@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75457 }
75458
75459 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
75460- __FILE__,__LINE__, tty->driver->name, self->open_count );
75461+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
75462
75463 schedule();
75464 }
75465@@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75466 if (extra_count) {
75467 /* ++ is not atomic, so this should be protected - Jean II */
75468 spin_lock_irqsave(&self->spinlock, flags);
75469- self->open_count++;
75470+ local_inc(&self->open_count);
75471 spin_unlock_irqrestore(&self->spinlock, flags);
75472 }
75473- self->blocked_open--;
75474+ local_dec(&self->blocked_open);
75475
75476 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
75477- __FILE__,__LINE__, tty->driver->name, self->open_count);
75478+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
75479
75480 if (!retval)
75481 self->flags |= ASYNC_NORMAL_ACTIVE;
75482@@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
75483 }
75484 /* ++ is not atomic, so this should be protected - Jean II */
75485 spin_lock_irqsave(&self->spinlock, flags);
75486- self->open_count++;
75487+ local_inc(&self->open_count);
75488
75489 tty->driver_data = self;
75490 self->tty = tty;
75491 spin_unlock_irqrestore(&self->spinlock, flags);
75492
75493 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
75494- self->line, self->open_count);
75495+ self->line, local_read(&self->open_count));
75496
75497 /* Not really used by us, but lets do it anyway */
75498 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
75499@@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75500 return;
75501 }
75502
75503- if ((tty->count == 1) && (self->open_count != 1)) {
75504+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
75505 /*
75506 * Uh, oh. tty->count is 1, which means that the tty
75507 * structure will be freed. state->count should always
75508@@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75509 */
75510 IRDA_DEBUG(0, "%s(), bad serial port count; "
75511 "tty->count is 1, state->count is %d\n", __func__ ,
75512- self->open_count);
75513- self->open_count = 1;
75514+ local_read(&self->open_count));
75515+ local_set(&self->open_count, 1);
75516 }
75517
75518- if (--self->open_count < 0) {
75519+ if (local_dec_return(&self->open_count) < 0) {
75520 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
75521- __func__, self->line, self->open_count);
75522- self->open_count = 0;
75523+ __func__, self->line, local_read(&self->open_count));
75524+ local_set(&self->open_count, 0);
75525 }
75526- if (self->open_count) {
75527+ if (local_read(&self->open_count)) {
75528 spin_unlock_irqrestore(&self->spinlock, flags);
75529
75530 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
75531@@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75532 tty->closing = 0;
75533 self->tty = NULL;
75534
75535- if (self->blocked_open) {
75536+ if (local_read(&self->blocked_open)) {
75537 if (self->close_delay)
75538 schedule_timeout_interruptible(self->close_delay);
75539 wake_up_interruptible(&self->open_wait);
75540@@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
75541 spin_lock_irqsave(&self->spinlock, flags);
75542 self->flags &= ~ASYNC_NORMAL_ACTIVE;
75543 self->tty = NULL;
75544- self->open_count = 0;
75545+ local_set(&self->open_count, 0);
75546 spin_unlock_irqrestore(&self->spinlock, flags);
75547
75548 wake_up_interruptible(&self->open_wait);
75549@@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
75550 seq_putc(m, '\n');
75551
75552 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
75553- seq_printf(m, "Open count: %d\n", self->open_count);
75554+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
75555 seq_printf(m, "Max data size: %d\n", self->max_data_size);
75556 seq_printf(m, "Max header size: %d\n", self->max_header_size);
75557
75558diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
75559index 07d7d55..541de95 100644
75560--- a/net/iucv/af_iucv.c
75561+++ b/net/iucv/af_iucv.c
75562@@ -783,10 +783,10 @@ static int iucv_sock_autobind(struct sock *sk)
75563
75564 write_lock_bh(&iucv_sk_list.lock);
75565
75566- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
75567+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
75568 while (__iucv_get_sock_by_name(name)) {
75569 sprintf(name, "%08x",
75570- atomic_inc_return(&iucv_sk_list.autobind_name));
75571+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
75572 }
75573
75574 write_unlock_bh(&iucv_sk_list.lock);
75575diff --git a/net/key/af_key.c b/net/key/af_key.c
75576index 7e5d927..cdbb54e 100644
75577--- a/net/key/af_key.c
75578+++ b/net/key/af_key.c
75579@@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
75580 static u32 get_acqseq(void)
75581 {
75582 u32 res;
75583- static atomic_t acqseq;
75584+ static atomic_unchecked_t acqseq;
75585
75586 do {
75587- res = atomic_inc_return(&acqseq);
75588+ res = atomic_inc_return_unchecked(&acqseq);
75589 } while (!res);
75590 return res;
75591 }
75592diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
75593index db8fae5..ff070cd 100644
75594--- a/net/mac80211/ieee80211_i.h
75595+++ b/net/mac80211/ieee80211_i.h
75596@@ -28,6 +28,7 @@
75597 #include <net/ieee80211_radiotap.h>
75598 #include <net/cfg80211.h>
75599 #include <net/mac80211.h>
75600+#include <asm/local.h>
75601 #include "key.h"
75602 #include "sta_info.h"
75603
75604@@ -842,7 +843,7 @@ struct ieee80211_local {
75605 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
75606 spinlock_t queue_stop_reason_lock;
75607
75608- int open_count;
75609+ local_t open_count;
75610 int monitors, cooked_mntrs;
75611 /* number of interfaces with corresponding FIF_ flags */
75612 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
75613diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
75614index 48f937e..4ccd7b8 100644
75615--- a/net/mac80211/iface.c
75616+++ b/net/mac80211/iface.c
75617@@ -222,7 +222,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75618 break;
75619 }
75620
75621- if (local->open_count == 0) {
75622+ if (local_read(&local->open_count) == 0) {
75623 res = drv_start(local);
75624 if (res)
75625 goto err_del_bss;
75626@@ -246,7 +246,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75627 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
75628
75629 if (!is_valid_ether_addr(dev->dev_addr)) {
75630- if (!local->open_count)
75631+ if (!local_read(&local->open_count))
75632 drv_stop(local);
75633 return -EADDRNOTAVAIL;
75634 }
75635@@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75636 mutex_unlock(&local->mtx);
75637
75638 if (coming_up)
75639- local->open_count++;
75640+ local_inc(&local->open_count);
75641
75642 if (hw_reconf_flags)
75643 ieee80211_hw_config(local, hw_reconf_flags);
75644@@ -360,7 +360,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75645 err_del_interface:
75646 drv_remove_interface(local, sdata);
75647 err_stop:
75648- if (!local->open_count)
75649+ if (!local_read(&local->open_count))
75650 drv_stop(local);
75651 err_del_bss:
75652 sdata->bss = NULL;
75653@@ -491,7 +491,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
75654 }
75655
75656 if (going_down)
75657- local->open_count--;
75658+ local_dec(&local->open_count);
75659
75660 switch (sdata->vif.type) {
75661 case NL80211_IFTYPE_AP_VLAN:
75662@@ -562,7 +562,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
75663
75664 ieee80211_recalc_ps(local, -1);
75665
75666- if (local->open_count == 0) {
75667+ if (local_read(&local->open_count) == 0) {
75668 if (local->ops->napi_poll)
75669 napi_disable(&local->napi);
75670 ieee80211_clear_tx_pending(local);
75671diff --git a/net/mac80211/main.c b/net/mac80211/main.c
75672index 1633648..d45ebfa 100644
75673--- a/net/mac80211/main.c
75674+++ b/net/mac80211/main.c
75675@@ -164,7 +164,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
75676 local->hw.conf.power_level = power;
75677 }
75678
75679- if (changed && local->open_count) {
75680+ if (changed && local_read(&local->open_count)) {
75681 ret = drv_config(local, changed);
75682 /*
75683 * Goal:
75684diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
75685index ef8eba1..5c63952 100644
75686--- a/net/mac80211/pm.c
75687+++ b/net/mac80211/pm.c
75688@@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75689 struct ieee80211_sub_if_data *sdata;
75690 struct sta_info *sta;
75691
75692- if (!local->open_count)
75693+ if (!local_read(&local->open_count))
75694 goto suspend;
75695
75696 ieee80211_scan_cancel(local);
75697@@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75698 cancel_work_sync(&local->dynamic_ps_enable_work);
75699 del_timer_sync(&local->dynamic_ps_timer);
75700
75701- local->wowlan = wowlan && local->open_count;
75702+ local->wowlan = wowlan && local_read(&local->open_count);
75703 if (local->wowlan) {
75704 int err = drv_suspend(local, wowlan);
75705 if (err < 0) {
75706@@ -128,7 +128,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75707 }
75708
75709 /* stop hardware - this must stop RX */
75710- if (local->open_count)
75711+ if (local_read(&local->open_count))
75712 ieee80211_stop_device(local);
75713
75714 suspend:
75715diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
75716index 3313c11..bec9f17 100644
75717--- a/net/mac80211/rate.c
75718+++ b/net/mac80211/rate.c
75719@@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
75720
75721 ASSERT_RTNL();
75722
75723- if (local->open_count)
75724+ if (local_read(&local->open_count))
75725 return -EBUSY;
75726
75727 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
75728diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
75729index c97a065..ff61928 100644
75730--- a/net/mac80211/rc80211_pid_debugfs.c
75731+++ b/net/mac80211/rc80211_pid_debugfs.c
75732@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
75733
75734 spin_unlock_irqrestore(&events->lock, status);
75735
75736- if (copy_to_user(buf, pb, p))
75737+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
75738 return -EFAULT;
75739
75740 return p;
75741diff --git a/net/mac80211/util.c b/net/mac80211/util.c
75742index eb9d7c0..d34b832 100644
75743--- a/net/mac80211/util.c
75744+++ b/net/mac80211/util.c
75745@@ -1179,7 +1179,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
75746 }
75747 #endif
75748 /* everything else happens only if HW was up & running */
75749- if (!local->open_count)
75750+ if (!local_read(&local->open_count))
75751 goto wake_up;
75752
75753 /*
75754diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
75755index 0c6f67e..d02cdfc 100644
75756--- a/net/netfilter/Kconfig
75757+++ b/net/netfilter/Kconfig
75758@@ -836,6 +836,16 @@ config NETFILTER_XT_MATCH_ESP
75759
75760 To compile it as a module, choose M here. If unsure, say N.
75761
75762+config NETFILTER_XT_MATCH_GRADM
75763+ tristate '"gradm" match support'
75764+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
75765+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
75766+ ---help---
75767+ The gradm match allows to match on grsecurity RBAC being enabled.
75768+ It is useful when iptables rules are applied early on bootup to
75769+ prevent connections to the machine (except from a trusted host)
75770+ while the RBAC system is disabled.
75771+
75772 config NETFILTER_XT_MATCH_HASHLIMIT
75773 tristate '"hashlimit" match support'
75774 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
75775diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
75776index ca36765..0882e7c 100644
75777--- a/net/netfilter/Makefile
75778+++ b/net/netfilter/Makefile
75779@@ -86,6 +86,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
75780 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
75781 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
75782 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
75783+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
75784 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
75785 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
75786 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
75787diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
75788index 29fa5ba..8debc79 100644
75789--- a/net/netfilter/ipvs/ip_vs_conn.c
75790+++ b/net/netfilter/ipvs/ip_vs_conn.c
75791@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
75792 /* Increase the refcnt counter of the dest */
75793 atomic_inc(&dest->refcnt);
75794
75795- conn_flags = atomic_read(&dest->conn_flags);
75796+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
75797 if (cp->protocol != IPPROTO_UDP)
75798 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
75799 /* Bind with the destination and its corresponding transmitter */
75800@@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
75801 atomic_set(&cp->refcnt, 1);
75802
75803 atomic_set(&cp->n_control, 0);
75804- atomic_set(&cp->in_pkts, 0);
75805+ atomic_set_unchecked(&cp->in_pkts, 0);
75806
75807 atomic_inc(&ipvs->conn_count);
75808 if (flags & IP_VS_CONN_F_NO_CPORT)
75809@@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
75810
75811 /* Don't drop the entry if its number of incoming packets is not
75812 located in [0, 8] */
75813- i = atomic_read(&cp->in_pkts);
75814+ i = atomic_read_unchecked(&cp->in_pkts);
75815 if (i > 8 || i < 0) return 0;
75816
75817 if (!todrop_rate[i]) return 0;
75818diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
75819index 00bdb1d..6725a48 100644
75820--- a/net/netfilter/ipvs/ip_vs_core.c
75821+++ b/net/netfilter/ipvs/ip_vs_core.c
75822@@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
75823 ret = cp->packet_xmit(skb, cp, pd->pp);
75824 /* do not touch skb anymore */
75825
75826- atomic_inc(&cp->in_pkts);
75827+ atomic_inc_unchecked(&cp->in_pkts);
75828 ip_vs_conn_put(cp);
75829 return ret;
75830 }
75831@@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
75832 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
75833 pkts = sysctl_sync_threshold(ipvs);
75834 else
75835- pkts = atomic_add_return(1, &cp->in_pkts);
75836+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
75837
75838 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
75839 cp->protocol == IPPROTO_SCTP) {
75840diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
75841index f558998..9cdff60 100644
75842--- a/net/netfilter/ipvs/ip_vs_ctl.c
75843+++ b/net/netfilter/ipvs/ip_vs_ctl.c
75844@@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
75845 ip_vs_rs_hash(ipvs, dest);
75846 write_unlock_bh(&ipvs->rs_lock);
75847 }
75848- atomic_set(&dest->conn_flags, conn_flags);
75849+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
75850
75851 /* bind the service */
75852 if (!dest->svc) {
75853@@ -2028,7 +2028,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
75854 " %-7s %-6d %-10d %-10d\n",
75855 &dest->addr.in6,
75856 ntohs(dest->port),
75857- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
75858+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
75859 atomic_read(&dest->weight),
75860 atomic_read(&dest->activeconns),
75861 atomic_read(&dest->inactconns));
75862@@ -2039,7 +2039,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
75863 "%-7s %-6d %-10d %-10d\n",
75864 ntohl(dest->addr.ip),
75865 ntohs(dest->port),
75866- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
75867+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
75868 atomic_read(&dest->weight),
75869 atomic_read(&dest->activeconns),
75870 atomic_read(&dest->inactconns));
75871@@ -2509,7 +2509,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
75872
75873 entry.addr = dest->addr.ip;
75874 entry.port = dest->port;
75875- entry.conn_flags = atomic_read(&dest->conn_flags);
75876+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
75877 entry.weight = atomic_read(&dest->weight);
75878 entry.u_threshold = dest->u_threshold;
75879 entry.l_threshold = dest->l_threshold;
75880@@ -3042,7 +3042,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
75881 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
75882
75883 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
75884- atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
75885+ atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
75886 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
75887 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
75888 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
75889diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
75890index 8a0d6d6..90ec197 100644
75891--- a/net/netfilter/ipvs/ip_vs_sync.c
75892+++ b/net/netfilter/ipvs/ip_vs_sync.c
75893@@ -649,7 +649,7 @@ control:
75894 * i.e only increment in_pkts for Templates.
75895 */
75896 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
75897- int pkts = atomic_add_return(1, &cp->in_pkts);
75898+ int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
75899
75900 if (pkts % sysctl_sync_period(ipvs) != 1)
75901 return;
75902@@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
75903
75904 if (opt)
75905 memcpy(&cp->in_seq, opt, sizeof(*opt));
75906- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
75907+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
75908 cp->state = state;
75909 cp->old_state = cp->state;
75910 /*
75911diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
75912index 7fd66de..e6fb361 100644
75913--- a/net/netfilter/ipvs/ip_vs_xmit.c
75914+++ b/net/netfilter/ipvs/ip_vs_xmit.c
75915@@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
75916 else
75917 rc = NF_ACCEPT;
75918 /* do not touch skb anymore */
75919- atomic_inc(&cp->in_pkts);
75920+ atomic_inc_unchecked(&cp->in_pkts);
75921 goto out;
75922 }
75923
75924@@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
75925 else
75926 rc = NF_ACCEPT;
75927 /* do not touch skb anymore */
75928- atomic_inc(&cp->in_pkts);
75929+ atomic_inc_unchecked(&cp->in_pkts);
75930 goto out;
75931 }
75932
75933diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
75934index 66b2c54..c7884e3 100644
75935--- a/net/netfilter/nfnetlink_log.c
75936+++ b/net/netfilter/nfnetlink_log.c
75937@@ -70,7 +70,7 @@ struct nfulnl_instance {
75938 };
75939
75940 static DEFINE_SPINLOCK(instances_lock);
75941-static atomic_t global_seq;
75942+static atomic_unchecked_t global_seq;
75943
75944 #define INSTANCE_BUCKETS 16
75945 static struct hlist_head instance_table[INSTANCE_BUCKETS];
75946@@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,
75947 /* global sequence number */
75948 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
75949 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
75950- htonl(atomic_inc_return(&global_seq)));
75951+ htonl(atomic_inc_return_unchecked(&global_seq)));
75952
75953 if (data_len) {
75954 struct nlattr *nla;
75955diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
75956new file mode 100644
75957index 0000000..6905327
75958--- /dev/null
75959+++ b/net/netfilter/xt_gradm.c
75960@@ -0,0 +1,51 @@
75961+/*
75962+ * gradm match for netfilter
75963