]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.9.5-201306111850.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.9.5-201306111850.patch
CommitLineData
7c4ecf64
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index b89a739..b47493f 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,14 +51,17 @@
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 *.9
38-.*
39+.[^g]*
40+.gen*
41 .*.d
42 .mm
43 53c700_d.h
44@@ -69,6 +75,7 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48+PERF*
49 SCCS
50 System.map*
51 TAGS
52@@ -80,6 +87,7 @@ aic7*seq.h*
53 aicasm
54 aicdb.h*
55 altivec*.c
56+ashldi3.S
57 asm-offsets.h
58 asm_offsets.h
59 autoconf.h*
60@@ -92,19 +100,24 @@ bounds.h
61 bsetup
62 btfixupprep
63 build
64+builtin-policy.h
65 bvmlinux
66 bzImage*
67 capability_names.h
68 capflags.c
69 classlist.h*
70+clut_vga16.c
71+common-cmds.h
72 comp*.log
73 compile.h*
74 conf
75 config
76 config-*
77 config_data.h*
78+config.c
79 config.mak
80 config.mak.autogen
81+config.tmp
82 conmakehash
83 consolemap_deftbl.c*
84 cpustr.h
85@@ -115,9 +128,11 @@ devlist.h*
86 dnotify_test
87 docproc
88 dslm
89+dtc-lexer.lex.c
90 elf2ecoff
91 elfconfig.h*
92 evergreen_reg_safe.h
93+exception_policy.conf
94 fixdep
95 flask.h
96 fore200e_mkfirm
97@@ -125,12 +140,15 @@ fore200e_pca_fw.c*
98 gconf
99 gconf.glade.h
100 gen-devlist
101+gen-kdb_cmds.c
102 gen_crc32table
103 gen_init_cpio
104 generated
105 genheaders
106 genksyms
107 *_gray256.c
108+hash
109+hid-example
110 hpet_example
111 hugepage-mmap
112 hugepage-shm
113@@ -145,14 +163,14 @@ int32.c
114 int4.c
115 int8.c
116 kallsyms
117-kconfig
118+kern_constants.h
119 keywords.c
120 ksym.c*
121 ksym.h*
122 kxgettext
123 lex.c
124 lex.*.c
125-linux
126+lib1funcs.S
127 logo_*.c
128 logo_*_clut224.c
129 logo_*_mono.c
130@@ -162,14 +180,15 @@ mach-types.h
131 machtypes.h
132 map
133 map_hugetlb
134-media
135 mconf
136+mdp
137 miboot*
138 mk_elfconfig
139 mkboot
140 mkbugboot
141 mkcpustr
142 mkdep
143+mkpiggy
144 mkprep
145 mkregtable
146 mktables
147@@ -185,6 +204,8 @@ oui.c*
148 page-types
149 parse.c
150 parse.h
151+parse-events*
152+pasyms.h
153 patches*
154 pca200e.bin
155 pca200e_ecd.bin2
156@@ -194,6 +215,7 @@ perf-archive
157 piggyback
158 piggy.gzip
159 piggy.S
160+pmu-*
161 pnmtologo
162 ppc_defs.h*
163 pss_boot.h
164@@ -203,7 +225,10 @@ r200_reg_safe.h
165 r300_reg_safe.h
166 r420_reg_safe.h
167 r600_reg_safe.h
168+realmode.lds
169+realmode.relocs
170 recordmcount
171+regdb.c
172 relocs
173 rlim_names.h
174 rn50_reg_safe.h
175@@ -213,8 +238,12 @@ series
176 setup
177 setup.bin
178 setup.elf
179+signing_key*
180+size_overflow_hash.h
181 sImage
182+slabinfo
183 sm_tbl*
184+sortextable
185 split-include
186 syscalltab.h
187 tables.c
188@@ -224,6 +253,7 @@ tftpboot.img
189 timeconst.h
190 times.h*
191 trix_boot.h
192+user_constants.h
193 utsrelease.h*
194 vdso-syms.lds
195 vdso.lds
196@@ -235,13 +265,17 @@ vdso32.lds
197 vdso32.so.dbg
198 vdso64.lds
199 vdso64.so.dbg
200+vdsox32.lds
201+vdsox32-syms.lds
202 version.h*
203 vmImage
204 vmlinux
205 vmlinux-*
206 vmlinux.aout
207 vmlinux.bin.all
208+vmlinux.bin.bz2
209 vmlinux.lds
210+vmlinux.relocs
211 vmlinuz
212 voffset.h
213 vsyscall.lds
214@@ -249,9 +283,12 @@ vsyscall_32.lds
215 wanxlfw.inc
216 uImage
217 unifdef
218+utsrelease.h
219 wakeup.bin
220 wakeup.elf
221 wakeup.lds
222+x509*
223 zImage*
224 zconf.hash.c
225+zconf.lex.c
226 zoffset.h
227diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
228index 8ccbf27..afffeb4 100644
229--- a/Documentation/kernel-parameters.txt
230+++ b/Documentation/kernel-parameters.txt
231@@ -948,6 +948,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
232 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
233 Default: 1024
234
235+ grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
236+ ignore grsecurity's /proc restrictions
237+
238+
239 hashdist= [KNL,NUMA] Large hashes allocated during boot
240 are distributed across NUMA nodes. Defaults on
241 for 64-bit NUMA, off otherwise.
242@@ -2147,6 +2151,18 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
243 the specified number of seconds. This is to be used if
244 your oopses keep scrolling off the screen.
245
246+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
247+ virtualization environments that don't cope well with the
248+ expand down segment used by UDEREF on X86-32 or the frequent
249+ page table updates on X86-64.
250+
251+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
252+
253+ pax_extra_latent_entropy
254+ Enable a very simple form of latent entropy extraction
255+ from the first 4GB of memory as the bootmem allocator
256+ passes the memory pages to the buddy allocator.
257+
258 pcbit= [HW,ISDN]
259
260 pcd. [PARIDE]
261diff --git a/Makefile b/Makefile
262index 8818c95..ced0bb1 100644
263--- a/Makefile
264+++ b/Makefile
265@@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
266
267 HOSTCC = gcc
268 HOSTCXX = g++
269-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
270-HOSTCXXFLAGS = -O2
271+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
272+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
273+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
274
275 # Decide whether to build built-in, modular, or both.
276 # Normally, just do built-in.
277@@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
278 # Rules shared between *config targets and build targets
279
280 # Basic helpers built in scripts/
281-PHONY += scripts_basic
282-scripts_basic:
283+PHONY += scripts_basic gcc-plugins
284+scripts_basic: gcc-plugins
285 $(Q)$(MAKE) $(build)=scripts/basic
286 $(Q)rm -f .tmp_quiet_recordmcount
287
288@@ -576,6 +577,65 @@ else
289 KBUILD_CFLAGS += -O2
290 endif
291
292+ifndef DISABLE_PAX_PLUGINS
293+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
294+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
295+else
296+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
297+endif
298+ifneq ($(PLUGINCC),)
299+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
300+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
301+endif
302+ifdef CONFIG_PAX_MEMORY_STACKLEAK
303+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
304+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
305+endif
306+ifdef CONFIG_KALLOCSTAT_PLUGIN
307+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
308+endif
309+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
310+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
311+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
312+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
313+endif
314+ifdef CONFIG_CHECKER_PLUGIN
315+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
316+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
317+endif
318+endif
319+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
320+ifdef CONFIG_PAX_SIZE_OVERFLOW
321+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
322+endif
323+ifdef CONFIG_PAX_LATENT_ENTROPY
324+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
325+endif
326+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
327+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
328+endif
329+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
330+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
331+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
332+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
333+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
334+ifeq ($(KBUILD_EXTMOD),)
335+gcc-plugins:
336+ $(Q)$(MAKE) $(build)=tools/gcc
337+else
338+gcc-plugins: ;
339+endif
340+else
341+gcc-plugins:
342+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
343+ $(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.))
344+else
345+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
346+endif
347+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
348+endif
349+endif
350+
351 include $(srctree)/arch/$(SRCARCH)/Makefile
352
353 ifdef CONFIG_READABLE_ASM
354@@ -733,7 +793,7 @@ export mod_sign_cmd
355
356
357 ifeq ($(KBUILD_EXTMOD),)
358-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
359+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
360
361 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
362 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
363@@ -780,6 +840,8 @@ endif
364
365 # The actual objects are generated when descending,
366 # make sure no implicit rule kicks in
367+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
368+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
369 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
370
371 # Handle descending into subdirectories listed in $(vmlinux-dirs)
372@@ -789,7 +851,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
373 # Error messages still appears in the original language
374
375 PHONY += $(vmlinux-dirs)
376-$(vmlinux-dirs): prepare scripts
377+$(vmlinux-dirs): gcc-plugins prepare scripts
378 $(Q)$(MAKE) $(build)=$@
379
380 # Store (new) KERNELRELASE string in include/config/kernel.release
381@@ -833,6 +895,7 @@ prepare0: archprepare FORCE
382 $(Q)$(MAKE) $(build)=.
383
384 # All the preparing..
385+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
386 prepare: prepare0
387
388 # Generate some files
389@@ -940,6 +1003,8 @@ all: modules
390 # using awk while concatenating to the final file.
391
392 PHONY += modules
393+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
394+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
395 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
396 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
397 @$(kecho) ' Building modules, stage 2.';
398@@ -955,7 +1020,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
399
400 # Target to prepare building external modules
401 PHONY += modules_prepare
402-modules_prepare: prepare scripts
403+modules_prepare: gcc-plugins prepare scripts
404
405 # Target to install modules
406 PHONY += modules_install
407@@ -1021,7 +1086,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
408 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
409 signing_key.priv signing_key.x509 x509.genkey \
410 extra_certificates signing_key.x509.keyid \
411- signing_key.x509.signer
412+ signing_key.x509.signer tools/gcc/size_overflow_hash.h
413
414 # clean - Delete most, but leave enough to build external modules
415 #
416@@ -1061,6 +1126,7 @@ distclean: mrproper
417 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
418 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
419 -o -name '.*.rej' \
420+ -o -name '.*.rej' -o -name '*.so' \
421 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
422 -type f -print | xargs rm -f
423
424@@ -1221,6 +1287,8 @@ PHONY += $(module-dirs) modules
425 $(module-dirs): crmodverdir $(objtree)/Module.symvers
426 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
427
428+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
429+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
430 modules: $(module-dirs)
431 @$(kecho) ' Building modules, stage 2.';
432 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
433@@ -1357,17 +1425,21 @@ else
434 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
435 endif
436
437-%.s: %.c prepare scripts FORCE
438+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
439+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
440+%.s: %.c gcc-plugins prepare scripts FORCE
441 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
442 %.i: %.c prepare scripts FORCE
443 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
444-%.o: %.c prepare scripts FORCE
445+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
446+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
447+%.o: %.c gcc-plugins prepare scripts FORCE
448 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
449 %.lst: %.c prepare scripts FORCE
450 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
451-%.s: %.S prepare scripts FORCE
452+%.s: %.S gcc-plugins prepare scripts FORCE
453 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
454-%.o: %.S prepare scripts FORCE
455+%.o: %.S gcc-plugins prepare scripts FORCE
456 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
457 %.symtypes: %.c prepare scripts FORCE
458 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
459@@ -1377,11 +1449,15 @@ endif
460 $(cmd_crmodverdir)
461 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
462 $(build)=$(build-dir)
463-%/: prepare scripts FORCE
464+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
465+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
466+%/: gcc-plugins prepare scripts FORCE
467 $(cmd_crmodverdir)
468 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
469 $(build)=$(build-dir)
470-%.ko: prepare scripts FORCE
471+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
472+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
473+%.ko: gcc-plugins prepare scripts FORCE
474 $(cmd_crmodverdir)
475 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
476 $(build)=$(build-dir) $(@:.ko=.o)
477diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
478index c2cbe4f..f7264b4 100644
479--- a/arch/alpha/include/asm/atomic.h
480+++ b/arch/alpha/include/asm/atomic.h
481@@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
482 #define atomic_dec(v) atomic_sub(1,(v))
483 #define atomic64_dec(v) atomic64_sub(1,(v))
484
485+#define atomic64_read_unchecked(v) atomic64_read(v)
486+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
487+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
488+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
489+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
490+#define atomic64_inc_unchecked(v) atomic64_inc(v)
491+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
492+#define atomic64_dec_unchecked(v) atomic64_dec(v)
493+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
494+
495 #define smp_mb__before_atomic_dec() smp_mb()
496 #define smp_mb__after_atomic_dec() smp_mb()
497 #define smp_mb__before_atomic_inc() smp_mb()
498diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
499index ad368a9..fbe0f25 100644
500--- a/arch/alpha/include/asm/cache.h
501+++ b/arch/alpha/include/asm/cache.h
502@@ -4,19 +4,19 @@
503 #ifndef __ARCH_ALPHA_CACHE_H
504 #define __ARCH_ALPHA_CACHE_H
505
506+#include <linux/const.h>
507
508 /* Bytes per L1 (data) cache line. */
509 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
510-# define L1_CACHE_BYTES 64
511 # define L1_CACHE_SHIFT 6
512 #else
513 /* Both EV4 and EV5 are write-through, read-allocate,
514 direct-mapped, physical.
515 */
516-# define L1_CACHE_BYTES 32
517 # define L1_CACHE_SHIFT 5
518 #endif
519
520+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
521 #define SMP_CACHE_BYTES L1_CACHE_BYTES
522
523 #endif
524diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
525index 968d999..d36b2df 100644
526--- a/arch/alpha/include/asm/elf.h
527+++ b/arch/alpha/include/asm/elf.h
528@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
529
530 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
531
532+#ifdef CONFIG_PAX_ASLR
533+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
534+
535+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
536+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
537+#endif
538+
539 /* $0 is set by ld.so to a pointer to a function which might be
540 registered using atexit. This provides a mean for the dynamic
541 linker to call DT_FINI functions for shared libraries that have
542diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
543index bc2a0da..8ad11ee 100644
544--- a/arch/alpha/include/asm/pgalloc.h
545+++ b/arch/alpha/include/asm/pgalloc.h
546@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
547 pgd_set(pgd, pmd);
548 }
549
550+static inline void
551+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
552+{
553+ pgd_populate(mm, pgd, pmd);
554+}
555+
556 extern pgd_t *pgd_alloc(struct mm_struct *mm);
557
558 static inline void
559diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
560index 81a4342..348b927 100644
561--- a/arch/alpha/include/asm/pgtable.h
562+++ b/arch/alpha/include/asm/pgtable.h
563@@ -102,6 +102,17 @@ struct vm_area_struct;
564 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
565 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
566 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
567+
568+#ifdef CONFIG_PAX_PAGEEXEC
569+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
570+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
571+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
572+#else
573+# define PAGE_SHARED_NOEXEC PAGE_SHARED
574+# define PAGE_COPY_NOEXEC PAGE_COPY
575+# define PAGE_READONLY_NOEXEC PAGE_READONLY
576+#endif
577+
578 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
579
580 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
581diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
582index 2fd00b7..cfd5069 100644
583--- a/arch/alpha/kernel/module.c
584+++ b/arch/alpha/kernel/module.c
585@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
586
587 /* The small sections were sorted to the end of the segment.
588 The following should definitely cover them. */
589- gp = (u64)me->module_core + me->core_size - 0x8000;
590+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
591 got = sechdrs[me->arch.gotsecindex].sh_addr;
592
593 for (i = 0; i < n; i++) {
594diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
595index b9e37ad..44c24e7 100644
596--- a/arch/alpha/kernel/osf_sys.c
597+++ b/arch/alpha/kernel/osf_sys.c
598@@ -1297,10 +1297,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
599 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
600
601 static unsigned long
602-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
603- unsigned long limit)
604+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
605+ unsigned long limit, unsigned long flags)
606 {
607 struct vm_unmapped_area_info info;
608+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
609
610 info.flags = 0;
611 info.length = len;
612@@ -1308,6 +1309,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
613 info.high_limit = limit;
614 info.align_mask = 0;
615 info.align_offset = 0;
616+ info.threadstack_offset = offset;
617 return vm_unmapped_area(&info);
618 }
619
620@@ -1340,20 +1342,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
621 merely specific addresses, but regions of memory -- perhaps
622 this feature should be incorporated into all ports? */
623
624+#ifdef CONFIG_PAX_RANDMMAP
625+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
626+#endif
627+
628 if (addr) {
629- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
630+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
631 if (addr != (unsigned long) -ENOMEM)
632 return addr;
633 }
634
635 /* Next, try allocating at TASK_UNMAPPED_BASE. */
636- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
637- len, limit);
638+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
639+
640 if (addr != (unsigned long) -ENOMEM)
641 return addr;
642
643 /* Finally, try allocating in low memory. */
644- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
645+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
646
647 return addr;
648 }
649diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
650index 0c4132d..88f0d53 100644
651--- a/arch/alpha/mm/fault.c
652+++ b/arch/alpha/mm/fault.c
653@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
654 __reload_thread(pcb);
655 }
656
657+#ifdef CONFIG_PAX_PAGEEXEC
658+/*
659+ * PaX: decide what to do with offenders (regs->pc = fault address)
660+ *
661+ * returns 1 when task should be killed
662+ * 2 when patched PLT trampoline was detected
663+ * 3 when unpatched PLT trampoline was detected
664+ */
665+static int pax_handle_fetch_fault(struct pt_regs *regs)
666+{
667+
668+#ifdef CONFIG_PAX_EMUPLT
669+ int err;
670+
671+ do { /* PaX: patched PLT emulation #1 */
672+ unsigned int ldah, ldq, jmp;
673+
674+ err = get_user(ldah, (unsigned int *)regs->pc);
675+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
676+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
677+
678+ if (err)
679+ break;
680+
681+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
682+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
683+ jmp == 0x6BFB0000U)
684+ {
685+ unsigned long r27, addr;
686+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
687+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
688+
689+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
690+ err = get_user(r27, (unsigned long *)addr);
691+ if (err)
692+ break;
693+
694+ regs->r27 = r27;
695+ regs->pc = r27;
696+ return 2;
697+ }
698+ } while (0);
699+
700+ do { /* PaX: patched PLT emulation #2 */
701+ unsigned int ldah, lda, br;
702+
703+ err = get_user(ldah, (unsigned int *)regs->pc);
704+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
705+ err |= get_user(br, (unsigned int *)(regs->pc+8));
706+
707+ if (err)
708+ break;
709+
710+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
711+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
712+ (br & 0xFFE00000U) == 0xC3E00000U)
713+ {
714+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
715+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
716+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
717+
718+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
719+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
720+ return 2;
721+ }
722+ } while (0);
723+
724+ do { /* PaX: unpatched PLT emulation */
725+ unsigned int br;
726+
727+ err = get_user(br, (unsigned int *)regs->pc);
728+
729+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
730+ unsigned int br2, ldq, nop, jmp;
731+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
732+
733+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
734+ err = get_user(br2, (unsigned int *)addr);
735+ err |= get_user(ldq, (unsigned int *)(addr+4));
736+ err |= get_user(nop, (unsigned int *)(addr+8));
737+ err |= get_user(jmp, (unsigned int *)(addr+12));
738+ err |= get_user(resolver, (unsigned long *)(addr+16));
739+
740+ if (err)
741+ break;
742+
743+ if (br2 == 0xC3600000U &&
744+ ldq == 0xA77B000CU &&
745+ nop == 0x47FF041FU &&
746+ jmp == 0x6B7B0000U)
747+ {
748+ regs->r28 = regs->pc+4;
749+ regs->r27 = addr+16;
750+ regs->pc = resolver;
751+ return 3;
752+ }
753+ }
754+ } while (0);
755+#endif
756+
757+ return 1;
758+}
759+
760+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
761+{
762+ unsigned long i;
763+
764+ printk(KERN_ERR "PAX: bytes at PC: ");
765+ for (i = 0; i < 5; i++) {
766+ unsigned int c;
767+ if (get_user(c, (unsigned int *)pc+i))
768+ printk(KERN_CONT "???????? ");
769+ else
770+ printk(KERN_CONT "%08x ", c);
771+ }
772+ printk("\n");
773+}
774+#endif
775
776 /*
777 * This routine handles page faults. It determines the address,
778@@ -133,8 +251,29 @@ retry:
779 good_area:
780 si_code = SEGV_ACCERR;
781 if (cause < 0) {
782- if (!(vma->vm_flags & VM_EXEC))
783+ if (!(vma->vm_flags & VM_EXEC)) {
784+
785+#ifdef CONFIG_PAX_PAGEEXEC
786+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
787+ goto bad_area;
788+
789+ up_read(&mm->mmap_sem);
790+ switch (pax_handle_fetch_fault(regs)) {
791+
792+#ifdef CONFIG_PAX_EMUPLT
793+ case 2:
794+ case 3:
795+ return;
796+#endif
797+
798+ }
799+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
800+ do_group_exit(SIGKILL);
801+#else
802 goto bad_area;
803+#endif
804+
805+ }
806 } else if (!cause) {
807 /* Allow reads even for write-only mappings */
808 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
809diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
810index 1cacda4..2cef624 100644
811--- a/arch/arm/Kconfig
812+++ b/arch/arm/Kconfig
813@@ -1850,7 +1850,7 @@ config ALIGNMENT_TRAP
814
815 config UACCESS_WITH_MEMCPY
816 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
817- depends on MMU
818+ depends on MMU && !PAX_MEMORY_UDEREF
819 default y if CPU_FEROCEON
820 help
821 Implement faster copy_to_user and clear_user methods for CPU
822diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
823index c79f61f..9ac0642 100644
824--- a/arch/arm/include/asm/atomic.h
825+++ b/arch/arm/include/asm/atomic.h
826@@ -17,17 +17,35 @@
827 #include <asm/barrier.h>
828 #include <asm/cmpxchg.h>
829
830+#ifdef CONFIG_GENERIC_ATOMIC64
831+#include <asm-generic/atomic64.h>
832+#endif
833+
834 #define ATOMIC_INIT(i) { (i) }
835
836 #ifdef __KERNEL__
837
838+#define _ASM_EXTABLE(from, to) \
839+" .pushsection __ex_table,\"a\"\n"\
840+" .align 3\n" \
841+" .long " #from ", " #to"\n" \
842+" .popsection"
843+
844 /*
845 * On ARM, ordinary assignment (str instruction) doesn't clear the local
846 * strex/ldrex monitor on some implementations. The reason we can use it for
847 * atomic_set() is the clrex or dummy strex done on every exception return.
848 */
849 #define atomic_read(v) (*(volatile int *)&(v)->counter)
850+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
851+{
852+ return v->counter;
853+}
854 #define atomic_set(v,i) (((v)->counter) = (i))
855+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
856+{
857+ v->counter = i;
858+}
859
860 #if __LINUX_ARM_ARCH__ >= 6
861
862@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
863 int result;
864
865 __asm__ __volatile__("@ atomic_add\n"
866+"1: ldrex %1, [%3]\n"
867+" adds %0, %1, %4\n"
868+
869+#ifdef CONFIG_PAX_REFCOUNT
870+" bvc 3f\n"
871+"2: bkpt 0xf103\n"
872+"3:\n"
873+#endif
874+
875+" strex %1, %0, [%3]\n"
876+" teq %1, #0\n"
877+" bne 1b"
878+
879+#ifdef CONFIG_PAX_REFCOUNT
880+"\n4:\n"
881+ _ASM_EXTABLE(2b, 4b)
882+#endif
883+
884+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
885+ : "r" (&v->counter), "Ir" (i)
886+ : "cc");
887+}
888+
889+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
890+{
891+ unsigned long tmp;
892+ int result;
893+
894+ __asm__ __volatile__("@ atomic_add_unchecked\n"
895 "1: ldrex %0, [%3]\n"
896 " add %0, %0, %4\n"
897 " strex %1, %0, [%3]\n"
898@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
899 smp_mb();
900
901 __asm__ __volatile__("@ atomic_add_return\n"
902+"1: ldrex %1, [%3]\n"
903+" adds %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+
925+ smp_mb();
926+
927+ return result;
928+}
929+
930+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
931+{
932+ unsigned long tmp;
933+ int result;
934+
935+ smp_mb();
936+
937+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
938 "1: ldrex %0, [%3]\n"
939 " add %0, %0, %4\n"
940 " strex %1, %0, [%3]\n"
941@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
942 int result;
943
944 __asm__ __volatile__("@ atomic_sub\n"
945+"1: ldrex %1, [%3]\n"
946+" subs %0, %1, %4\n"
947+
948+#ifdef CONFIG_PAX_REFCOUNT
949+" bvc 3f\n"
950+"2: bkpt 0xf103\n"
951+"3:\n"
952+#endif
953+
954+" strex %1, %0, [%3]\n"
955+" teq %1, #0\n"
956+" bne 1b"
957+
958+#ifdef CONFIG_PAX_REFCOUNT
959+"\n4:\n"
960+ _ASM_EXTABLE(2b, 4b)
961+#endif
962+
963+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
964+ : "r" (&v->counter), "Ir" (i)
965+ : "cc");
966+}
967+
968+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
969+{
970+ unsigned long tmp;
971+ int result;
972+
973+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
974 "1: ldrex %0, [%3]\n"
975 " sub %0, %0, %4\n"
976 " strex %1, %0, [%3]\n"
977@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
978 smp_mb();
979
980 __asm__ __volatile__("@ atomic_sub_return\n"
981-"1: ldrex %0, [%3]\n"
982-" sub %0, %0, %4\n"
983+"1: ldrex %1, [%3]\n"
984+" subs %0, %1, %4\n"
985+
986+#ifdef CONFIG_PAX_REFCOUNT
987+" bvc 3f\n"
988+" mov %0, %1\n"
989+"2: bkpt 0xf103\n"
990+"3:\n"
991+#endif
992+
993 " strex %1, %0, [%3]\n"
994 " teq %1, #0\n"
995 " bne 1b"
996+
997+#ifdef CONFIG_PAX_REFCOUNT
998+"\n4:\n"
999+ _ASM_EXTABLE(2b, 4b)
1000+#endif
1001+
1002 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1003 : "r" (&v->counter), "Ir" (i)
1004 : "cc");
1005@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1006 return oldval;
1007 }
1008
1009+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1010+{
1011+ unsigned long oldval, res;
1012+
1013+ smp_mb();
1014+
1015+ do {
1016+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1017+ "ldrex %1, [%3]\n"
1018+ "mov %0, #0\n"
1019+ "teq %1, %4\n"
1020+ "strexeq %0, %5, [%3]\n"
1021+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1022+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1023+ : "cc");
1024+ } while (res);
1025+
1026+ smp_mb();
1027+
1028+ return oldval;
1029+}
1030+
1031 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1032 {
1033 unsigned long tmp, tmp2;
1034@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1035
1036 return val;
1037 }
1038+
1039+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1040+{
1041+ return atomic_add_return(i, v);
1042+}
1043+
1044 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1045+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1046+{
1047+ (void) atomic_add_return(i, v);
1048+}
1049
1050 static inline int atomic_sub_return(int i, atomic_t *v)
1051 {
1052@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1053 return val;
1054 }
1055 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1056+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1057+{
1058+ (void) atomic_sub_return(i, v);
1059+}
1060
1061 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1062 {
1063@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1064 return ret;
1065 }
1066
1067+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1068+{
1069+ return atomic_cmpxchg(v, old, new);
1070+}
1071+
1072 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1073 {
1074 unsigned long flags;
1075@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1076 #endif /* __LINUX_ARM_ARCH__ */
1077
1078 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1079+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1080+{
1081+ return xchg(&v->counter, new);
1082+}
1083
1084 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1085 {
1086@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1087 }
1088
1089 #define atomic_inc(v) atomic_add(1, v)
1090+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1091+{
1092+ atomic_add_unchecked(1, v);
1093+}
1094 #define atomic_dec(v) atomic_sub(1, v)
1095+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1096+{
1097+ atomic_sub_unchecked(1, v);
1098+}
1099
1100 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1101+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1102+{
1103+ return atomic_add_return_unchecked(1, v) == 0;
1104+}
1105 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1106 #define atomic_inc_return(v) (atomic_add_return(1, v))
1107+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1108+{
1109+ return atomic_add_return_unchecked(1, v);
1110+}
1111 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1112 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1113
1114@@ -241,6 +428,14 @@ typedef struct {
1115 u64 __aligned(8) counter;
1116 } atomic64_t;
1117
1118+#ifdef CONFIG_PAX_REFCOUNT
1119+typedef struct {
1120+ u64 __aligned(8) counter;
1121+} atomic64_unchecked_t;
1122+#else
1123+typedef atomic64_t atomic64_unchecked_t;
1124+#endif
1125+
1126 #define ATOMIC64_INIT(i) { (i) }
1127
1128 static inline u64 atomic64_read(const atomic64_t *v)
1129@@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1130 return result;
1131 }
1132
1133+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1134+{
1135+ u64 result;
1136+
1137+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1138+" ldrexd %0, %H0, [%1]"
1139+ : "=&r" (result)
1140+ : "r" (&v->counter), "Qo" (v->counter)
1141+ );
1142+
1143+ return result;
1144+}
1145+
1146 static inline void atomic64_set(atomic64_t *v, u64 i)
1147 {
1148 u64 tmp;
1149@@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1150 : "cc");
1151 }
1152
1153+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1154+{
1155+ u64 tmp;
1156+
1157+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1158+"1: ldrexd %0, %H0, [%2]\n"
1159+" strexd %0, %3, %H3, [%2]\n"
1160+" teq %0, #0\n"
1161+" bne 1b"
1162+ : "=&r" (tmp), "=Qo" (v->counter)
1163+ : "r" (&v->counter), "r" (i)
1164+ : "cc");
1165+}
1166+
1167 static inline void atomic64_add(u64 i, atomic64_t *v)
1168 {
1169 u64 result;
1170@@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1171 __asm__ __volatile__("@ atomic64_add\n"
1172 "1: ldrexd %0, %H0, [%3]\n"
1173 " adds %0, %0, %4\n"
1174+" adcs %H0, %H0, %H4\n"
1175+
1176+#ifdef CONFIG_PAX_REFCOUNT
1177+" bvc 3f\n"
1178+"2: bkpt 0xf103\n"
1179+"3:\n"
1180+#endif
1181+
1182+" strexd %1, %0, %H0, [%3]\n"
1183+" teq %1, #0\n"
1184+" bne 1b"
1185+
1186+#ifdef CONFIG_PAX_REFCOUNT
1187+"\n4:\n"
1188+ _ASM_EXTABLE(2b, 4b)
1189+#endif
1190+
1191+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1192+ : "r" (&v->counter), "r" (i)
1193+ : "cc");
1194+}
1195+
1196+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1197+{
1198+ u64 result;
1199+ unsigned long tmp;
1200+
1201+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1202+"1: ldrexd %0, %H0, [%3]\n"
1203+" adds %0, %0, %4\n"
1204 " adc %H0, %H0, %H4\n"
1205 " strexd %1, %0, %H0, [%3]\n"
1206 " teq %1, #0\n"
1207@@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1208
1209 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1210 {
1211- u64 result;
1212- unsigned long tmp;
1213+ u64 result, tmp;
1214
1215 smp_mb();
1216
1217 __asm__ __volatile__("@ atomic64_add_return\n"
1218+"1: ldrexd %1, %H1, [%3]\n"
1219+" adds %0, %1, %4\n"
1220+" adcs %H0, %H1, %H4\n"
1221+
1222+#ifdef CONFIG_PAX_REFCOUNT
1223+" bvc 3f\n"
1224+" mov %0, %1\n"
1225+" mov %H0, %H1\n"
1226+"2: bkpt 0xf103\n"
1227+"3:\n"
1228+#endif
1229+
1230+" strexd %1, %0, %H0, [%3]\n"
1231+" teq %1, #0\n"
1232+" bne 1b"
1233+
1234+#ifdef CONFIG_PAX_REFCOUNT
1235+"\n4:\n"
1236+ _ASM_EXTABLE(2b, 4b)
1237+#endif
1238+
1239+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1240+ : "r" (&v->counter), "r" (i)
1241+ : "cc");
1242+
1243+ smp_mb();
1244+
1245+ return result;
1246+}
1247+
1248+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1249+{
1250+ u64 result;
1251+ unsigned long tmp;
1252+
1253+ smp_mb();
1254+
1255+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1256 "1: ldrexd %0, %H0, [%3]\n"
1257 " adds %0, %0, %4\n"
1258 " adc %H0, %H0, %H4\n"
1259@@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1260 __asm__ __volatile__("@ atomic64_sub\n"
1261 "1: ldrexd %0, %H0, [%3]\n"
1262 " subs %0, %0, %4\n"
1263+" sbcs %H0, %H0, %H4\n"
1264+
1265+#ifdef CONFIG_PAX_REFCOUNT
1266+" bvc 3f\n"
1267+"2: bkpt 0xf103\n"
1268+"3:\n"
1269+#endif
1270+
1271+" strexd %1, %0, %H0, [%3]\n"
1272+" teq %1, #0\n"
1273+" bne 1b"
1274+
1275+#ifdef CONFIG_PAX_REFCOUNT
1276+"\n4:\n"
1277+ _ASM_EXTABLE(2b, 4b)
1278+#endif
1279+
1280+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1281+ : "r" (&v->counter), "r" (i)
1282+ : "cc");
1283+}
1284+
1285+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1286+{
1287+ u64 result;
1288+ unsigned long tmp;
1289+
1290+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1291+"1: ldrexd %0, %H0, [%3]\n"
1292+" subs %0, %0, %4\n"
1293 " sbc %H0, %H0, %H4\n"
1294 " strexd %1, %0, %H0, [%3]\n"
1295 " teq %1, #0\n"
1296@@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1297
1298 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1299 {
1300- u64 result;
1301- unsigned long tmp;
1302+ u64 result, tmp;
1303
1304 smp_mb();
1305
1306 __asm__ __volatile__("@ atomic64_sub_return\n"
1307-"1: ldrexd %0, %H0, [%3]\n"
1308-" subs %0, %0, %4\n"
1309-" sbc %H0, %H0, %H4\n"
1310+"1: ldrexd %1, %H1, [%3]\n"
1311+" subs %0, %1, %4\n"
1312+" sbcs %H0, %H1, %H4\n"
1313+
1314+#ifdef CONFIG_PAX_REFCOUNT
1315+" bvc 3f\n"
1316+" mov %0, %1\n"
1317+" mov %H0, %H1\n"
1318+"2: bkpt 0xf103\n"
1319+"3:\n"
1320+#endif
1321+
1322 " strexd %1, %0, %H0, [%3]\n"
1323 " teq %1, #0\n"
1324 " bne 1b"
1325+
1326+#ifdef CONFIG_PAX_REFCOUNT
1327+"\n4:\n"
1328+ _ASM_EXTABLE(2b, 4b)
1329+#endif
1330+
1331 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1332 : "r" (&v->counter), "r" (i)
1333 : "cc");
1334@@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1335 return oldval;
1336 }
1337
1338+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1339+{
1340+ u64 oldval;
1341+ unsigned long res;
1342+
1343+ smp_mb();
1344+
1345+ do {
1346+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1347+ "ldrexd %1, %H1, [%3]\n"
1348+ "mov %0, #0\n"
1349+ "teq %1, %4\n"
1350+ "teqeq %H1, %H4\n"
1351+ "strexdeq %0, %5, %H5, [%3]"
1352+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1353+ : "r" (&ptr->counter), "r" (old), "r" (new)
1354+ : "cc");
1355+ } while (res);
1356+
1357+ smp_mb();
1358+
1359+ return oldval;
1360+}
1361+
1362 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1363 {
1364 u64 result;
1365@@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1366
1367 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1368 {
1369- u64 result;
1370- unsigned long tmp;
1371+ u64 result, tmp;
1372
1373 smp_mb();
1374
1375 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1376-"1: ldrexd %0, %H0, [%3]\n"
1377-" subs %0, %0, #1\n"
1378-" sbc %H0, %H0, #0\n"
1379+"1: ldrexd %1, %H1, [%3]\n"
1380+" subs %0, %1, #1\n"
1381+" sbcs %H0, %H1, #0\n"
1382+
1383+#ifdef CONFIG_PAX_REFCOUNT
1384+" bvc 3f\n"
1385+" mov %0, %1\n"
1386+" mov %H0, %H1\n"
1387+"2: bkpt 0xf103\n"
1388+"3:\n"
1389+#endif
1390+
1391 " teq %H0, #0\n"
1392-" bmi 2f\n"
1393+" bmi 4f\n"
1394 " strexd %1, %0, %H0, [%3]\n"
1395 " teq %1, #0\n"
1396 " bne 1b\n"
1397-"2:"
1398+"4:\n"
1399+
1400+#ifdef CONFIG_PAX_REFCOUNT
1401+ _ASM_EXTABLE(2b, 4b)
1402+#endif
1403+
1404 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1405 : "r" (&v->counter)
1406 : "cc");
1407@@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1408 " teq %0, %5\n"
1409 " teqeq %H0, %H5\n"
1410 " moveq %1, #0\n"
1411-" beq 2f\n"
1412+" beq 4f\n"
1413 " adds %0, %0, %6\n"
1414-" adc %H0, %H0, %H6\n"
1415+" adcs %H0, %H0, %H6\n"
1416+
1417+#ifdef CONFIG_PAX_REFCOUNT
1418+" bvc 3f\n"
1419+"2: bkpt 0xf103\n"
1420+"3:\n"
1421+#endif
1422+
1423 " strexd %2, %0, %H0, [%4]\n"
1424 " teq %2, #0\n"
1425 " bne 1b\n"
1426-"2:"
1427+"4:\n"
1428+
1429+#ifdef CONFIG_PAX_REFCOUNT
1430+ _ASM_EXTABLE(2b, 4b)
1431+#endif
1432+
1433 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1434 : "r" (&v->counter), "r" (u), "r" (a)
1435 : "cc");
1436@@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1437
1438 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1439 #define atomic64_inc(v) atomic64_add(1LL, (v))
1440+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1441 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1442+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1443 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1444 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1445 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1446+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1447 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1448 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1449 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1450diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1451index 75fe66b..ba3dee4 100644
1452--- a/arch/arm/include/asm/cache.h
1453+++ b/arch/arm/include/asm/cache.h
1454@@ -4,8 +4,10 @@
1455 #ifndef __ASMARM_CACHE_H
1456 #define __ASMARM_CACHE_H
1457
1458+#include <linux/const.h>
1459+
1460 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1461-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1462+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1463
1464 /*
1465 * Memory returned by kmalloc() may be used for DMA, so we must make
1466@@ -24,5 +26,6 @@
1467 #endif
1468
1469 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1470+#define __read_only __attribute__ ((__section__(".data..read_only")))
1471
1472 #endif
1473diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1474index e1489c5..d418304 100644
1475--- a/arch/arm/include/asm/cacheflush.h
1476+++ b/arch/arm/include/asm/cacheflush.h
1477@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1478 void (*dma_unmap_area)(const void *, size_t, int);
1479
1480 void (*dma_flush_range)(const void *, const void *);
1481-};
1482+} __no_const;
1483
1484 /*
1485 * Select the calling method
1486diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1487index 6dcc164..b14d917 100644
1488--- a/arch/arm/include/asm/checksum.h
1489+++ b/arch/arm/include/asm/checksum.h
1490@@ -37,7 +37,19 @@ __wsum
1491 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1492
1493 __wsum
1494-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1495+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1496+
1497+static inline __wsum
1498+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1499+{
1500+ __wsum ret;
1501+ pax_open_userland();
1502+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1503+ pax_close_userland();
1504+ return ret;
1505+}
1506+
1507+
1508
1509 /*
1510 * Fold a partial checksum without adding pseudo headers
1511diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1512index 4f009c1..466c59b 100644
1513--- a/arch/arm/include/asm/cmpxchg.h
1514+++ b/arch/arm/include/asm/cmpxchg.h
1515@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1516
1517 #define xchg(ptr,x) \
1518 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1519+#define xchg_unchecked(ptr,x) \
1520+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1521
1522 #include <asm-generic/cmpxchg-local.h>
1523
1524diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1525index 6ddbe44..b5e38b1 100644
1526--- a/arch/arm/include/asm/domain.h
1527+++ b/arch/arm/include/asm/domain.h
1528@@ -48,18 +48,37 @@
1529 * Domain types
1530 */
1531 #define DOMAIN_NOACCESS 0
1532-#define DOMAIN_CLIENT 1
1533 #ifdef CONFIG_CPU_USE_DOMAINS
1534+#define DOMAIN_USERCLIENT 1
1535+#define DOMAIN_KERNELCLIENT 1
1536 #define DOMAIN_MANAGER 3
1537+#define DOMAIN_VECTORS DOMAIN_USER
1538 #else
1539+
1540+#ifdef CONFIG_PAX_KERNEXEC
1541 #define DOMAIN_MANAGER 1
1542+#define DOMAIN_KERNEXEC 3
1543+#else
1544+#define DOMAIN_MANAGER 1
1545+#endif
1546+
1547+#ifdef CONFIG_PAX_MEMORY_UDEREF
1548+#define DOMAIN_USERCLIENT 0
1549+#define DOMAIN_UDEREF 1
1550+#define DOMAIN_VECTORS DOMAIN_KERNEL
1551+#else
1552+#define DOMAIN_USERCLIENT 1
1553+#define DOMAIN_VECTORS DOMAIN_USER
1554+#endif
1555+#define DOMAIN_KERNELCLIENT 1
1556+
1557 #endif
1558
1559 #define domain_val(dom,type) ((type) << (2*(dom)))
1560
1561 #ifndef __ASSEMBLY__
1562
1563-#ifdef CONFIG_CPU_USE_DOMAINS
1564+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1565 static inline void set_domain(unsigned val)
1566 {
1567 asm volatile(
1568@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1569 isb();
1570 }
1571
1572-#define modify_domain(dom,type) \
1573- do { \
1574- struct thread_info *thread = current_thread_info(); \
1575- unsigned int domain = thread->cpu_domain; \
1576- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1577- thread->cpu_domain = domain | domain_val(dom, type); \
1578- set_domain(thread->cpu_domain); \
1579- } while (0)
1580-
1581+extern void modify_domain(unsigned int dom, unsigned int type);
1582 #else
1583 static inline void set_domain(unsigned val) { }
1584 static inline void modify_domain(unsigned dom, unsigned type) { }
1585diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1586index 38050b1..9d90e8b 100644
1587--- a/arch/arm/include/asm/elf.h
1588+++ b/arch/arm/include/asm/elf.h
1589@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1590 the loader. We need to make sure that it is out of the way of the program
1591 that it will "exec", and that there is sufficient room for the brk. */
1592
1593-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1594+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1595+
1596+#ifdef CONFIG_PAX_ASLR
1597+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1598+
1599+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1600+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1601+#endif
1602
1603 /* When the program starts, a1 contains a pointer to a function to be
1604 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1605@@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1606 extern void elf_set_personality(const struct elf32_hdr *);
1607 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1608
1609-struct mm_struct;
1610-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1611-#define arch_randomize_brk arch_randomize_brk
1612-
1613 #endif
1614diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1615index de53547..52b9a28 100644
1616--- a/arch/arm/include/asm/fncpy.h
1617+++ b/arch/arm/include/asm/fncpy.h
1618@@ -81,7 +81,9 @@
1619 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1620 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1621 \
1622+ pax_open_kernel(); \
1623 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1624+ pax_close_kernel(); \
1625 flush_icache_range((unsigned long)(dest_buf), \
1626 (unsigned long)(dest_buf) + (size)); \
1627 \
1628diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1629index e42cf59..7b94b8f 100644
1630--- a/arch/arm/include/asm/futex.h
1631+++ b/arch/arm/include/asm/futex.h
1632@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1633 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1634 return -EFAULT;
1635
1636+ pax_open_userland();
1637+
1638 smp_mb();
1639 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1640 "1: ldrex %1, [%4]\n"
1641@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1642 : "cc", "memory");
1643 smp_mb();
1644
1645+ pax_close_userland();
1646+
1647 *uval = val;
1648 return ret;
1649 }
1650@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1651 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1652 return -EFAULT;
1653
1654+ pax_open_userland();
1655+
1656 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1657 "1: " TUSER(ldr) " %1, [%4]\n"
1658 " teq %1, %2\n"
1659@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1660 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1661 : "cc", "memory");
1662
1663+ pax_close_userland();
1664+
1665 *uval = val;
1666 return ret;
1667 }
1668@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1669 return -EFAULT;
1670
1671 pagefault_disable(); /* implies preempt_disable() */
1672+ pax_open_userland();
1673
1674 switch (op) {
1675 case FUTEX_OP_SET:
1676@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1677 ret = -ENOSYS;
1678 }
1679
1680+ pax_close_userland();
1681 pagefault_enable(); /* subsumes preempt_enable() */
1682
1683 if (!ret) {
1684diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1685index 83eb2f7..ed77159 100644
1686--- a/arch/arm/include/asm/kmap_types.h
1687+++ b/arch/arm/include/asm/kmap_types.h
1688@@ -4,6 +4,6 @@
1689 /*
1690 * This is the "bare minimum". AIO seems to require this.
1691 */
1692-#define KM_TYPE_NR 16
1693+#define KM_TYPE_NR 17
1694
1695 #endif
1696diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1697index 9e614a1..3302cca 100644
1698--- a/arch/arm/include/asm/mach/dma.h
1699+++ b/arch/arm/include/asm/mach/dma.h
1700@@ -22,7 +22,7 @@ struct dma_ops {
1701 int (*residue)(unsigned int, dma_t *); /* optional */
1702 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1703 const char *type;
1704-};
1705+} __do_const;
1706
1707 struct dma_struct {
1708 void *addr; /* single DMA address */
1709diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1710index 2fe141f..192dc01 100644
1711--- a/arch/arm/include/asm/mach/map.h
1712+++ b/arch/arm/include/asm/mach/map.h
1713@@ -27,13 +27,16 @@ struct map_desc {
1714 #define MT_MINICLEAN 6
1715 #define MT_LOW_VECTORS 7
1716 #define MT_HIGH_VECTORS 8
1717-#define MT_MEMORY 9
1718+#define MT_MEMORY_RWX 9
1719 #define MT_ROM 10
1720-#define MT_MEMORY_NONCACHED 11
1721+#define MT_MEMORY_NONCACHED_RX 11
1722 #define MT_MEMORY_DTCM 12
1723 #define MT_MEMORY_ITCM 13
1724 #define MT_MEMORY_SO 14
1725 #define MT_MEMORY_DMA_READY 15
1726+#define MT_MEMORY_RW 16
1727+#define MT_MEMORY_RX 17
1728+#define MT_MEMORY_NONCACHED_RW 18
1729
1730 #ifdef CONFIG_MMU
1731 extern void iotable_init(struct map_desc *, int);
1732diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1733index 12f71a1..04e063c 100644
1734--- a/arch/arm/include/asm/outercache.h
1735+++ b/arch/arm/include/asm/outercache.h
1736@@ -35,7 +35,7 @@ struct outer_cache_fns {
1737 #endif
1738 void (*set_debug)(unsigned long);
1739 void (*resume)(void);
1740-};
1741+} __no_const;
1742
1743 #ifdef CONFIG_OUTER_CACHE
1744
1745diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1746index 812a494..71fc0b6 100644
1747--- a/arch/arm/include/asm/page.h
1748+++ b/arch/arm/include/asm/page.h
1749@@ -114,7 +114,7 @@ struct cpu_user_fns {
1750 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1751 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1752 unsigned long vaddr, struct vm_area_struct *vma);
1753-};
1754+} __no_const;
1755
1756 #ifdef MULTI_USER
1757 extern struct cpu_user_fns cpu_user;
1758diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1759index 943504f..c37a730 100644
1760--- a/arch/arm/include/asm/pgalloc.h
1761+++ b/arch/arm/include/asm/pgalloc.h
1762@@ -17,6 +17,7 @@
1763 #include <asm/processor.h>
1764 #include <asm/cacheflush.h>
1765 #include <asm/tlbflush.h>
1766+#include <asm/system_info.h>
1767
1768 #define check_pgt_cache() do { } while (0)
1769
1770@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1771 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1772 }
1773
1774+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1775+{
1776+ pud_populate(mm, pud, pmd);
1777+}
1778+
1779 #else /* !CONFIG_ARM_LPAE */
1780
1781 /*
1782@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1783 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1784 #define pmd_free(mm, pmd) do { } while (0)
1785 #define pud_populate(mm,pmd,pte) BUG()
1786+#define pud_populate_kernel(mm,pmd,pte) BUG()
1787
1788 #endif /* CONFIG_ARM_LPAE */
1789
1790@@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1791 __free_page(pte);
1792 }
1793
1794+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1795+{
1796+#ifdef CONFIG_ARM_LPAE
1797+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1798+#else
1799+ if (addr & SECTION_SIZE)
1800+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1801+ else
1802+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1803+#endif
1804+ flush_pmd_entry(pmdp);
1805+}
1806+
1807 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1808 pmdval_t prot)
1809 {
1810@@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1811 static inline void
1812 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1813 {
1814- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1815+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1816 }
1817 #define pmd_pgtable(pmd) pmd_page(pmd)
1818
1819diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1820index 5cfba15..f415e1a 100644
1821--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1822+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1823@@ -20,12 +20,15 @@
1824 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1825 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1826 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1827+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1828 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1829 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1830 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1831+
1832 /*
1833 * - section
1834 */
1835+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1836 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1837 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1838 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1839@@ -37,6 +40,7 @@
1840 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1841 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1842 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1843+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1844
1845 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1846 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1847@@ -66,6 +70,7 @@
1848 * - extended small page/tiny page
1849 */
1850 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1851+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1852 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1853 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1854 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1855diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1856index f97ee02..07f1be5 100644
1857--- a/arch/arm/include/asm/pgtable-2level.h
1858+++ b/arch/arm/include/asm/pgtable-2level.h
1859@@ -125,6 +125,7 @@
1860 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1861 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1862 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1863+#define L_PTE_PXN (_AT(pteval_t, 1) << 12) /* v7*/
1864
1865 /*
1866 * These are the memory types, defined to be compatible with
1867diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1868index 18f5cef..25b8f43 100644
1869--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1870+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1871@@ -41,6 +41,7 @@
1872 */
1873 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1874 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1875+#define PMD_SECT_RDONLY (_AT(pmdval_t, 1) << 7)
1876 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1877 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1878 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1879@@ -71,6 +72,7 @@
1880 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1881 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1882 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1883+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1884 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1885
1886 /*
1887diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1888index 86b8fe3..e25f975 100644
1889--- a/arch/arm/include/asm/pgtable-3level.h
1890+++ b/arch/arm/include/asm/pgtable-3level.h
1891@@ -74,6 +74,7 @@
1892 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1893 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1894 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1895+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1896 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1897 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1898 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1899@@ -82,6 +83,7 @@
1900 /*
1901 * To be used in assembly code with the upper page attributes.
1902 */
1903+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1904 #define L_PTE_XN_HIGH (1 << (54 - 32))
1905 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1906
1907diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1908index 9bcd262..fba731c 100644
1909--- a/arch/arm/include/asm/pgtable.h
1910+++ b/arch/arm/include/asm/pgtable.h
1911@@ -30,6 +30,9 @@
1912 #include <asm/pgtable-2level.h>
1913 #endif
1914
1915+#define ktla_ktva(addr) (addr)
1916+#define ktva_ktla(addr) (addr)
1917+
1918 /*
1919 * Just any arbitrary offset to the start of the vmalloc VM area: the
1920 * current 8MB value just means that there will be a 8MB "hole" after the
1921@@ -45,6 +48,9 @@
1922 #define LIBRARY_TEXT_START 0x0c000000
1923
1924 #ifndef __ASSEMBLY__
1925+extern pteval_t __supported_pte_mask;
1926+extern pmdval_t __supported_pmd_mask;
1927+
1928 extern void __pte_error(const char *file, int line, pte_t);
1929 extern void __pmd_error(const char *file, int line, pmd_t);
1930 extern void __pgd_error(const char *file, int line, pgd_t);
1931@@ -53,6 +59,50 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1932 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1933 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1934
1935+#define __HAVE_ARCH_PAX_OPEN_KERNEL
1936+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1937+
1938+#ifdef CONFIG_PAX_KERNEXEC
1939+#include <asm/domain.h>
1940+#include <linux/thread_info.h>
1941+#include <linux/preempt.h>
1942+#endif
1943+
1944+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1945+static inline int test_domain(int domain, int domaintype)
1946+{
1947+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
1948+}
1949+#endif
1950+
1951+#ifdef CONFIG_PAX_KERNEXEC
1952+static inline unsigned long pax_open_kernel(void) {
1953+#ifdef CONFIG_ARM_LPAE
1954+ /* TODO */
1955+#else
1956+ preempt_disable();
1957+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
1958+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
1959+#endif
1960+ return 0;
1961+}
1962+
1963+static inline unsigned long pax_close_kernel(void) {
1964+#ifdef CONFIG_ARM_LPAE
1965+ /* TODO */
1966+#else
1967+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
1968+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
1969+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
1970+ preempt_enable_no_resched();
1971+#endif
1972+ return 0;
1973+}
1974+#else
1975+static inline unsigned long pax_open_kernel(void) { return 0; }
1976+static inline unsigned long pax_close_kernel(void) { return 0; }
1977+#endif
1978+
1979 /*
1980 * This is the lowest virtual address we can permit any user space
1981 * mapping to be mapped at. This is particularly important for
1982@@ -72,8 +122,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1983 /*
1984 * The pgprot_* and protection_map entries will be fixed up in runtime
1985 * to include the cachable and bufferable bits based on memory policy,
1986- * as well as any architecture dependent bits like global/ASID and SMP
1987- * shared mapping bits.
1988+ * as well as any architecture dependent bits like global/ASID, PXN,
1989+ * and SMP shared mapping bits.
1990 */
1991 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
1992
1993@@ -257,7 +307,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
1994 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
1995 {
1996 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
1997- L_PTE_NONE | L_PTE_VALID;
1998+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
1999 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2000 return pte;
2001 }
2002diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2003index f3628fb..a0672dd 100644
2004--- a/arch/arm/include/asm/proc-fns.h
2005+++ b/arch/arm/include/asm/proc-fns.h
2006@@ -75,7 +75,7 @@ extern struct processor {
2007 unsigned int suspend_size;
2008 void (*do_suspend)(void *);
2009 void (*do_resume)(void *);
2010-} processor;
2011+} __do_const processor;
2012
2013 #ifndef MULTI_CPU
2014 extern void cpu_proc_init(void);
2015diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h
2016index 06e7d50..8a8e251 100644
2017--- a/arch/arm/include/asm/processor.h
2018+++ b/arch/arm/include/asm/processor.h
2019@@ -65,9 +65,8 @@ struct thread_struct {
2020 regs->ARM_cpsr |= PSR_ENDSTATE; \
2021 regs->ARM_pc = pc & ~1; /* pc */ \
2022 regs->ARM_sp = sp; /* sp */ \
2023- regs->ARM_r2 = stack[2]; /* r2 (envp) */ \
2024- regs->ARM_r1 = stack[1]; /* r1 (argv) */ \
2025- regs->ARM_r0 = stack[0]; /* r0 (argc) */ \
2026+ /* r2 (envp), r1 (argv), r0 (argc) */ \
2027+ (void)copy_from_user(&regs->ARM_r0, (const char __user *)stack, 3 * sizeof(unsigned long)); \
2028 nommu_start_thread(regs); \
2029 })
2030
2031diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2032index ce0dbe7..c085b6f 100644
2033--- a/arch/arm/include/asm/psci.h
2034+++ b/arch/arm/include/asm/psci.h
2035@@ -29,7 +29,7 @@ struct psci_operations {
2036 int (*cpu_off)(struct psci_power_state state);
2037 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2038 int (*migrate)(unsigned long cpuid);
2039-};
2040+} __no_const;
2041
2042 extern struct psci_operations psci_ops;
2043
2044diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2045index d3a22be..3a69ad5 100644
2046--- a/arch/arm/include/asm/smp.h
2047+++ b/arch/arm/include/asm/smp.h
2048@@ -107,7 +107,7 @@ struct smp_operations {
2049 int (*cpu_disable)(unsigned int cpu);
2050 #endif
2051 #endif
2052-};
2053+} __no_const;
2054
2055 /*
2056 * set platform specific SMP operations
2057diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2058index cddda1f..ff357f7 100644
2059--- a/arch/arm/include/asm/thread_info.h
2060+++ b/arch/arm/include/asm/thread_info.h
2061@@ -77,9 +77,9 @@ struct thread_info {
2062 .flags = 0, \
2063 .preempt_count = INIT_PREEMPT_COUNT, \
2064 .addr_limit = KERNEL_DS, \
2065- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2066- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2067- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2068+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2069+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2070+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2071 .restart_block = { \
2072 .fn = do_no_restart_syscall, \
2073 }, \
2074@@ -152,6 +152,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2075 #define TIF_SYSCALL_AUDIT 9
2076 #define TIF_SYSCALL_TRACEPOINT 10
2077 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2078+
2079+/* within 8 bits of TIF_SYSCALL_TRACE
2080+ * to meet flexible second operand requirements
2081+ */
2082+#define TIF_GRSEC_SETXID 12
2083+
2084 #define TIF_USING_IWMMXT 17
2085 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2086 #define TIF_RESTORE_SIGMASK 20
2087@@ -165,10 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2088 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2089 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2090 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2091+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2092
2093 /* Checks for any syscall work in entry-common.S */
2094 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2095- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2096+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2097
2098 /*
2099 * Change these and you break ASM code in entry-common.S
2100diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2101index 7e1f760..752fcb7 100644
2102--- a/arch/arm/include/asm/uaccess.h
2103+++ b/arch/arm/include/asm/uaccess.h
2104@@ -18,6 +18,7 @@
2105 #include <asm/domain.h>
2106 #include <asm/unified.h>
2107 #include <asm/compiler.h>
2108+#include <asm/pgtable.h>
2109
2110 #define VERIFY_READ 0
2111 #define VERIFY_WRITE 1
2112@@ -60,10 +61,34 @@ extern int __put_user_bad(void);
2113 #define USER_DS TASK_SIZE
2114 #define get_fs() (current_thread_info()->addr_limit)
2115
2116+static inline void pax_open_userland(void)
2117+{
2118+
2119+#ifdef CONFIG_PAX_MEMORY_UDEREF
2120+ if (get_fs() == USER_DS) {
2121+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2122+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2123+ }
2124+#endif
2125+
2126+}
2127+
2128+static inline void pax_close_userland(void)
2129+{
2130+
2131+#ifdef CONFIG_PAX_MEMORY_UDEREF
2132+ if (get_fs() == USER_DS) {
2133+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2134+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2135+ }
2136+#endif
2137+
2138+}
2139+
2140 static inline void set_fs(mm_segment_t fs)
2141 {
2142 current_thread_info()->addr_limit = fs;
2143- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2144+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2145 }
2146
2147 #define segment_eq(a,b) ((a) == (b))
2148@@ -143,8 +168,12 @@ extern int __get_user_4(void *);
2149
2150 #define get_user(x,p) \
2151 ({ \
2152+ int __e; \
2153 might_fault(); \
2154- __get_user_check(x,p); \
2155+ pax_open_userland(); \
2156+ __e = __get_user_check(x,p); \
2157+ pax_close_userland(); \
2158+ __e; \
2159 })
2160
2161 extern int __put_user_1(void *, unsigned int);
2162@@ -188,8 +217,12 @@ extern int __put_user_8(void *, unsigned long long);
2163
2164 #define put_user(x,p) \
2165 ({ \
2166+ int __e; \
2167 might_fault(); \
2168- __put_user_check(x,p); \
2169+ pax_open_userland(); \
2170+ __e = __put_user_check(x,p); \
2171+ pax_close_userland(); \
2172+ __e; \
2173 })
2174
2175 #else /* CONFIG_MMU */
2176@@ -230,13 +263,17 @@ static inline void set_fs(mm_segment_t fs)
2177 #define __get_user(x,ptr) \
2178 ({ \
2179 long __gu_err = 0; \
2180+ pax_open_userland(); \
2181 __get_user_err((x),(ptr),__gu_err); \
2182+ pax_close_userland(); \
2183 __gu_err; \
2184 })
2185
2186 #define __get_user_error(x,ptr,err) \
2187 ({ \
2188+ pax_open_userland(); \
2189 __get_user_err((x),(ptr),err); \
2190+ pax_close_userland(); \
2191 (void) 0; \
2192 })
2193
2194@@ -312,13 +349,17 @@ do { \
2195 #define __put_user(x,ptr) \
2196 ({ \
2197 long __pu_err = 0; \
2198+ pax_open_userland(); \
2199 __put_user_err((x),(ptr),__pu_err); \
2200+ pax_close_userland(); \
2201 __pu_err; \
2202 })
2203
2204 #define __put_user_error(x,ptr,err) \
2205 ({ \
2206+ pax_open_userland(); \
2207 __put_user_err((x),(ptr),err); \
2208+ pax_close_userland(); \
2209 (void) 0; \
2210 })
2211
2212@@ -418,11 +459,44 @@ do { \
2213
2214
2215 #ifdef CONFIG_MMU
2216-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2217-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2218+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2219+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2220+
2221+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2222+{
2223+ unsigned long ret;
2224+
2225+ check_object_size(to, n, false);
2226+ pax_open_userland();
2227+ ret = ___copy_from_user(to, from, n);
2228+ pax_close_userland();
2229+ return ret;
2230+}
2231+
2232+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2233+{
2234+ unsigned long ret;
2235+
2236+ check_object_size(from, n, true);
2237+ pax_open_userland();
2238+ ret = ___copy_to_user(to, from, n);
2239+ pax_close_userland();
2240+ return ret;
2241+}
2242+
2243 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2244-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2245+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2246 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2247+
2248+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2249+{
2250+ unsigned long ret;
2251+ pax_open_userland();
2252+ ret = ___clear_user(addr, n);
2253+ pax_close_userland();
2254+ return ret;
2255+}
2256+
2257 #else
2258 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2259 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2260@@ -431,6 +505,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2261
2262 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2263 {
2264+ if ((long)n < 0)
2265+ return n;
2266+
2267 if (access_ok(VERIFY_READ, from, n))
2268 n = __copy_from_user(to, from, n);
2269 else /* security hole - plug it */
2270@@ -440,6 +517,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2271
2272 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2273 {
2274+ if ((long)n < 0)
2275+ return n;
2276+
2277 if (access_ok(VERIFY_WRITE, to, n))
2278 n = __copy_to_user(to, from, n);
2279 return n;
2280diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2281index 96ee092..37f1844 100644
2282--- a/arch/arm/include/uapi/asm/ptrace.h
2283+++ b/arch/arm/include/uapi/asm/ptrace.h
2284@@ -73,7 +73,7 @@
2285 * ARMv7 groups of PSR bits
2286 */
2287 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2288-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2289+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2290 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2291 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2292
2293diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2294index 60d3b73..d27ee09 100644
2295--- a/arch/arm/kernel/armksyms.c
2296+++ b/arch/arm/kernel/armksyms.c
2297@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2298 #ifdef CONFIG_MMU
2299 EXPORT_SYMBOL(copy_page);
2300
2301-EXPORT_SYMBOL(__copy_from_user);
2302-EXPORT_SYMBOL(__copy_to_user);
2303-EXPORT_SYMBOL(__clear_user);
2304+EXPORT_SYMBOL(___copy_from_user);
2305+EXPORT_SYMBOL(___copy_to_user);
2306+EXPORT_SYMBOL(___clear_user);
2307
2308 EXPORT_SYMBOL(__get_user_1);
2309 EXPORT_SYMBOL(__get_user_2);
2310diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2311index 0f82098..3dbd3ee 100644
2312--- a/arch/arm/kernel/entry-armv.S
2313+++ b/arch/arm/kernel/entry-armv.S
2314@@ -47,6 +47,87 @@
2315 9997:
2316 .endm
2317
2318+ .macro pax_enter_kernel
2319+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2320+ @ make aligned space for saved DACR
2321+ sub sp, sp, #8
2322+ @ save regs
2323+ stmdb sp!, {r1, r2}
2324+ @ read DACR from cpu_domain into r1
2325+ mov r2, sp
2326+ @ assume 8K pages, since we have to split the immediate in two
2327+ bic r2, r2, #(0x1fc0)
2328+ bic r2, r2, #(0x3f)
2329+ ldr r1, [r2, #TI_CPU_DOMAIN]
2330+ @ store old DACR on stack
2331+ str r1, [sp, #8]
2332+#ifdef CONFIG_PAX_KERNEXEC
2333+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2334+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2335+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2336+#endif
2337+#ifdef CONFIG_PAX_MEMORY_UDEREF
2338+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2339+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2340+#endif
2341+ @ write r1 to current_thread_info()->cpu_domain
2342+ str r1, [r2, #TI_CPU_DOMAIN]
2343+ @ write r1 to DACR
2344+ mcr p15, 0, r1, c3, c0, 0
2345+ @ instruction sync
2346+ instr_sync
2347+ @ restore regs
2348+ ldmia sp!, {r1, r2}
2349+#endif
2350+ .endm
2351+
2352+ .macro pax_open_userland
2353+#ifdef CONFIG_PAX_MEMORY_UDEREF
2354+ @ save regs
2355+ stmdb sp!, {r0, r1}
2356+ @ read DACR from cpu_domain into r1
2357+ mov r0, sp
2358+ @ assume 8K pages, since we have to split the immediate in two
2359+ bic r0, r0, #(0x1fc0)
2360+ bic r0, r0, #(0x3f)
2361+ ldr r1, [r0, #TI_CPU_DOMAIN]
2362+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2363+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2364+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2365+ @ write r1 to current_thread_info()->cpu_domain
2366+ str r1, [r0, #TI_CPU_DOMAIN]
2367+ @ write r1 to DACR
2368+ mcr p15, 0, r1, c3, c0, 0
2369+ @ instruction sync
2370+ instr_sync
2371+ @ restore regs
2372+ ldmia sp!, {r0, r1}
2373+#endif
2374+ .endm
2375+
2376+ .macro pax_close_userland
2377+#ifdef CONFIG_PAX_MEMORY_UDEREF
2378+ @ save regs
2379+ stmdb sp!, {r0, r1}
2380+ @ read DACR from cpu_domain into r1
2381+ mov r0, sp
2382+ @ assume 8K pages, since we have to split the immediate in two
2383+ bic r0, r0, #(0x1fc0)
2384+ bic r0, r0, #(0x3f)
2385+ ldr r1, [r0, #TI_CPU_DOMAIN]
2386+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2387+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2388+ @ write r1 to current_thread_info()->cpu_domain
2389+ str r1, [r0, #TI_CPU_DOMAIN]
2390+ @ write r1 to DACR
2391+ mcr p15, 0, r1, c3, c0, 0
2392+ @ instruction sync
2393+ instr_sync
2394+ @ restore regs
2395+ ldmia sp!, {r0, r1}
2396+#endif
2397+ .endm
2398+
2399 .macro pabt_helper
2400 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2401 #ifdef MULTI_PABORT
2402@@ -89,11 +170,15 @@
2403 * Invalid mode handlers
2404 */
2405 .macro inv_entry, reason
2406+
2407+ pax_enter_kernel
2408+
2409 sub sp, sp, #S_FRAME_SIZE
2410 ARM( stmib sp, {r1 - lr} )
2411 THUMB( stmia sp, {r0 - r12} )
2412 THUMB( str sp, [sp, #S_SP] )
2413 THUMB( str lr, [sp, #S_LR] )
2414+
2415 mov r1, #\reason
2416 .endm
2417
2418@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2419 .macro svc_entry, stack_hole=0
2420 UNWIND(.fnstart )
2421 UNWIND(.save {r0 - pc} )
2422+
2423+ pax_enter_kernel
2424+
2425 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2426+
2427 #ifdef CONFIG_THUMB2_KERNEL
2428 SPFIX( str r0, [sp] ) @ temporarily saved
2429 SPFIX( mov r0, sp )
2430@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2431 ldmia r0, {r3 - r5}
2432 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2433 mov r6, #-1 @ "" "" "" ""
2434+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2435+ @ offset sp by 8 as done in pax_enter_kernel
2436+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2437+#else
2438 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2439+#endif
2440 SPFIX( addeq r2, r2, #4 )
2441 str r3, [sp, #-4]! @ save the "real" r0 copied
2442 @ from the exception stack
2443@@ -359,6 +453,9 @@ ENDPROC(__pabt_svc)
2444 .macro usr_entry
2445 UNWIND(.fnstart )
2446 UNWIND(.cantunwind ) @ don't unwind the user space
2447+
2448+ pax_enter_kernel_user
2449+
2450 sub sp, sp, #S_FRAME_SIZE
2451 ARM( stmib sp, {r1 - r12} )
2452 THUMB( stmia sp, {r0 - r12} )
2453@@ -456,7 +553,9 @@ __und_usr:
2454 tst r3, #PSR_T_BIT @ Thumb mode?
2455 bne __und_usr_thumb
2456 sub r4, r2, #4 @ ARM instr at LR - 4
2457+ pax_open_userland
2458 1: ldrt r0, [r4]
2459+ pax_close_userland
2460 #ifdef CONFIG_CPU_ENDIAN_BE8
2461 rev r0, r0 @ little endian instruction
2462 #endif
2463@@ -491,10 +590,14 @@ __und_usr_thumb:
2464 */
2465 .arch armv6t2
2466 #endif
2467+ pax_open_userland
2468 2: ldrht r5, [r4]
2469+ pax_close_userland
2470 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2471 blo __und_usr_fault_16 @ 16bit undefined instruction
2472+ pax_open_userland
2473 3: ldrht r0, [r2]
2474+ pax_close_userland
2475 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2476 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2477 orr r0, r0, r5, lsl #16
2478@@ -733,7 +836,7 @@ ENTRY(__switch_to)
2479 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
2480 THUMB( str sp, [ip], #4 )
2481 THUMB( str lr, [ip], #4 )
2482-#ifdef CONFIG_CPU_USE_DOMAINS
2483+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2484 ldr r6, [r2, #TI_CPU_DOMAIN]
2485 #endif
2486 set_tls r3, r4, r5
2487@@ -742,7 +845,7 @@ ENTRY(__switch_to)
2488 ldr r8, =__stack_chk_guard
2489 ldr r7, [r7, #TSK_STACK_CANARY]
2490 #endif
2491-#ifdef CONFIG_CPU_USE_DOMAINS
2492+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2493 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2494 #endif
2495 mov r5, r0
2496diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2497index fefd7f9..e6f250e 100644
2498--- a/arch/arm/kernel/entry-common.S
2499+++ b/arch/arm/kernel/entry-common.S
2500@@ -10,18 +10,46 @@
2501
2502 #include <asm/unistd.h>
2503 #include <asm/ftrace.h>
2504+#include <asm/domain.h>
2505 #include <asm/unwind.h>
2506
2507+#include "entry-header.S"
2508+
2509 #ifdef CONFIG_NEED_RET_TO_USER
2510 #include <mach/entry-macro.S>
2511 #else
2512 .macro arch_ret_to_user, tmp1, tmp2
2513+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2514+ @ save regs
2515+ stmdb sp!, {r1, r2}
2516+ @ read DACR from cpu_domain into r1
2517+ mov r2, sp
2518+ @ assume 8K pages, since we have to split the immediate in two
2519+ bic r2, r2, #(0x1fc0)
2520+ bic r2, r2, #(0x3f)
2521+ ldr r1, [r2, #TI_CPU_DOMAIN]
2522+#ifdef CONFIG_PAX_KERNEXEC
2523+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2524+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2525+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2526+#endif
2527+#ifdef CONFIG_PAX_MEMORY_UDEREF
2528+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2529+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2530+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2531+#endif
2532+ @ write r1 to current_thread_info()->cpu_domain
2533+ str r1, [r2, #TI_CPU_DOMAIN]
2534+ @ write r1 to DACR
2535+ mcr p15, 0, r1, c3, c0, 0
2536+ @ instruction sync
2537+ instr_sync
2538+ @ restore regs
2539+ ldmia sp!, {r1, r2}
2540+#endif
2541 .endm
2542 #endif
2543
2544-#include "entry-header.S"
2545-
2546-
2547 .align 5
2548 /*
2549 * This is the fast syscall return path. We do as little as
2550@@ -351,6 +379,7 @@ ENDPROC(ftrace_stub)
2551
2552 .align 5
2553 ENTRY(vector_swi)
2554+
2555 sub sp, sp, #S_FRAME_SIZE
2556 stmia sp, {r0 - r12} @ Calling r0 - r12
2557 ARM( add r8, sp, #S_PC )
2558@@ -400,6 +429,12 @@ ENTRY(vector_swi)
2559 ldr scno, [lr, #-4] @ get SWI instruction
2560 #endif
2561
2562+ /*
2563+ * do this here to avoid a performance hit of wrapping the code above
2564+ * that directly dereferences userland to parse the SWI instruction
2565+ */
2566+ pax_enter_kernel_user
2567+
2568 #ifdef CONFIG_ALIGNMENT_TRAP
2569 ldr ip, __cr_alignment
2570 ldr ip, [ip]
2571diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2572index 9a8531e..812e287 100644
2573--- a/arch/arm/kernel/entry-header.S
2574+++ b/arch/arm/kernel/entry-header.S
2575@@ -73,9 +73,66 @@
2576 msr cpsr_c, \rtemp @ switch back to the SVC mode
2577 .endm
2578
2579+ .macro pax_enter_kernel_user
2580+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2581+ @ save regs
2582+ stmdb sp!, {r0, r1}
2583+ @ read DACR from cpu_domain into r1
2584+ mov r0, sp
2585+ @ assume 8K pages, since we have to split the immediate in two
2586+ bic r0, r0, #(0x1fc0)
2587+ bic r0, r0, #(0x3f)
2588+ ldr r1, [r0, #TI_CPU_DOMAIN]
2589+#ifdef CONFIG_PAX_MEMORY_UDEREF
2590+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2591+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2592+#endif
2593+#ifdef CONFIG_PAX_KERNEXEC
2594+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2595+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2596+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2597+#endif
2598+ @ write r1 to current_thread_info()->cpu_domain
2599+ str r1, [r0, #TI_CPU_DOMAIN]
2600+ @ write r1 to DACR
2601+ mcr p15, 0, r1, c3, c0, 0
2602+ @ instruction sync
2603+ instr_sync
2604+ @ restore regs
2605+ ldmia sp!, {r0, r1}
2606+#endif
2607+ .endm
2608+
2609+ .macro pax_exit_kernel
2610+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2611+ @ save regs
2612+ stmdb sp!, {r0, r1}
2613+ @ read old DACR from stack into r1
2614+ ldr r1, [sp, #(8 + S_SP)]
2615+ sub r1, r1, #8
2616+ ldr r1, [r1]
2617+
2618+ @ write r1 to current_thread_info()->cpu_domain
2619+ mov r0, sp
2620+ @ assume 8K pages, since we have to split the immediate in two
2621+ bic r0, r0, #(0x1fc0)
2622+ bic r0, r0, #(0x3f)
2623+ str r1, [r0, #TI_CPU_DOMAIN]
2624+ @ write r1 to DACR
2625+ mcr p15, 0, r1, c3, c0, 0
2626+ @ instruction sync
2627+ instr_sync
2628+ @ restore regs
2629+ ldmia sp!, {r0, r1}
2630+#endif
2631+ .endm
2632+
2633 #ifndef CONFIG_THUMB2_KERNEL
2634 .macro svc_exit, rpsr
2635 msr spsr_cxsf, \rpsr
2636+
2637+ pax_exit_kernel
2638+
2639 #if defined(CONFIG_CPU_V6)
2640 ldr r0, [sp]
2641 strex r1, r2, [sp] @ clear the exclusive monitor
2642@@ -121,6 +178,9 @@
2643 .endm
2644 #else /* CONFIG_THUMB2_KERNEL */
2645 .macro svc_exit, rpsr
2646+
2647+ pax_exit_kernel
2648+
2649 ldr lr, [sp, #S_SP] @ top of the stack
2650 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2651 clrex @ clear the exclusive monitor
2652diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2653index 2adda11..7fbe958 100644
2654--- a/arch/arm/kernel/fiq.c
2655+++ b/arch/arm/kernel/fiq.c
2656@@ -82,7 +82,9 @@ void set_fiq_handler(void *start, unsigned int length)
2657 #if defined(CONFIG_CPU_USE_DOMAINS)
2658 memcpy((void *)0xffff001c, start, length);
2659 #else
2660+ pax_open_kernel();
2661 memcpy(vectors_page + 0x1c, start, length);
2662+ pax_close_kernel();
2663 #endif
2664 flush_icache_range(0xffff001c, 0xffff001c + length);
2665 if (!vectors_high())
2666diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2667index 8bac553..caee108 100644
2668--- a/arch/arm/kernel/head.S
2669+++ b/arch/arm/kernel/head.S
2670@@ -52,7 +52,9 @@
2671 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2672
2673 .macro pgtbl, rd, phys
2674- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2675+ mov \rd, #TEXT_OFFSET
2676+ sub \rd, #PG_DIR_SIZE
2677+ add \rd, \rd, \phys
2678 .endm
2679
2680 /*
2681@@ -434,7 +436,7 @@ __enable_mmu:
2682 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2683 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2684 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2685- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2686+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2687 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2688 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2689 #endif
2690diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
2691index 1fd749e..47adb08 100644
2692--- a/arch/arm/kernel/hw_breakpoint.c
2693+++ b/arch/arm/kernel/hw_breakpoint.c
2694@@ -1029,7 +1029,7 @@ static int __cpuinit dbg_reset_notify(struct notifier_block *self,
2695 return NOTIFY_OK;
2696 }
2697
2698-static struct notifier_block __cpuinitdata dbg_reset_nb = {
2699+static struct notifier_block dbg_reset_nb = {
2700 .notifier_call = dbg_reset_notify,
2701 };
2702
2703diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2704index 1e9be5d..03edbc2 100644
2705--- a/arch/arm/kernel/module.c
2706+++ b/arch/arm/kernel/module.c
2707@@ -37,12 +37,37 @@
2708 #endif
2709
2710 #ifdef CONFIG_MMU
2711-void *module_alloc(unsigned long size)
2712+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2713 {
2714+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2715+ return NULL;
2716 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2717- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2718+ GFP_KERNEL, prot, -1,
2719 __builtin_return_address(0));
2720 }
2721+
2722+void *module_alloc(unsigned long size)
2723+{
2724+
2725+#ifdef CONFIG_PAX_KERNEXEC
2726+ return __module_alloc(size, PAGE_KERNEL);
2727+#else
2728+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2729+#endif
2730+
2731+}
2732+
2733+#ifdef CONFIG_PAX_KERNEXEC
2734+void module_free_exec(struct module *mod, void *module_region)
2735+{
2736+ module_free(mod, module_region);
2737+}
2738+
2739+void *module_alloc_exec(unsigned long size)
2740+{
2741+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2742+}
2743+#endif
2744 #endif
2745
2746 int
2747diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2748index 07314af..c46655c 100644
2749--- a/arch/arm/kernel/patch.c
2750+++ b/arch/arm/kernel/patch.c
2751@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2752 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2753 int size;
2754
2755+ pax_open_kernel();
2756 if (thumb2 && __opcode_is_thumb16(insn)) {
2757 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2758 size = sizeof(u16);
2759@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2760 *(u32 *)addr = insn;
2761 size = sizeof(u32);
2762 }
2763+ pax_close_kernel();
2764
2765 flush_icache_range((uintptr_t)(addr),
2766 (uintptr_t)(addr) + size);
2767diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
2768index 1f2740e..b36e225 100644
2769--- a/arch/arm/kernel/perf_event_cpu.c
2770+++ b/arch/arm/kernel/perf_event_cpu.c
2771@@ -171,7 +171,7 @@ static int __cpuinit cpu_pmu_notify(struct notifier_block *b,
2772 return NOTIFY_OK;
2773 }
2774
2775-static struct notifier_block __cpuinitdata cpu_pmu_hotplug_notifier = {
2776+static struct notifier_block cpu_pmu_hotplug_notifier = {
2777 .notifier_call = cpu_pmu_notify,
2778 };
2779
2780diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2781index 047d3e4..7e96107 100644
2782--- a/arch/arm/kernel/process.c
2783+++ b/arch/arm/kernel/process.c
2784@@ -28,7 +28,6 @@
2785 #include <linux/tick.h>
2786 #include <linux/utsname.h>
2787 #include <linux/uaccess.h>
2788-#include <linux/random.h>
2789 #include <linux/hw_breakpoint.h>
2790 #include <linux/cpuidle.h>
2791 #include <linux/leds.h>
2792@@ -251,9 +250,10 @@ void machine_power_off(void)
2793 machine_shutdown();
2794 if (pm_power_off)
2795 pm_power_off();
2796+ BUG();
2797 }
2798
2799-void machine_restart(char *cmd)
2800+__noreturn void machine_restart(char *cmd)
2801 {
2802 machine_shutdown();
2803
2804@@ -278,8 +278,8 @@ void __show_regs(struct pt_regs *regs)
2805 init_utsname()->release,
2806 (int)strcspn(init_utsname()->version, " "),
2807 init_utsname()->version);
2808- print_symbol("PC is at %s\n", instruction_pointer(regs));
2809- print_symbol("LR is at %s\n", regs->ARM_lr);
2810+ printk("PC is at %pA\n", instruction_pointer(regs));
2811+ printk("LR is at %pA\n", regs->ARM_lr);
2812 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2813 "sp : %08lx ip : %08lx fp : %08lx\n",
2814 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2815@@ -447,12 +447,6 @@ unsigned long get_wchan(struct task_struct *p)
2816 return 0;
2817 }
2818
2819-unsigned long arch_randomize_brk(struct mm_struct *mm)
2820-{
2821- unsigned long range_end = mm->brk + 0x02000000;
2822- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2823-}
2824-
2825 #ifdef CONFIG_MMU
2826 /*
2827 * The vectors page is always readable from user space for the
2828@@ -465,9 +459,8 @@ static int __init gate_vma_init(void)
2829 {
2830 gate_vma.vm_start = 0xffff0000;
2831 gate_vma.vm_end = 0xffff0000 + PAGE_SIZE;
2832- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2833- gate_vma.vm_flags = VM_READ | VM_EXEC |
2834- VM_MAYREAD | VM_MAYEXEC;
2835+ gate_vma.vm_flags = VM_NONE;
2836+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2837 return 0;
2838 }
2839 arch_initcall(gate_vma_init);
2840diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2841index 3653164..d83e55d 100644
2842--- a/arch/arm/kernel/psci.c
2843+++ b/arch/arm/kernel/psci.c
2844@@ -24,7 +24,7 @@
2845 #include <asm/opcodes-virt.h>
2846 #include <asm/psci.h>
2847
2848-struct psci_operations psci_ops;
2849+struct psci_operations psci_ops __read_only;
2850
2851 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2852
2853diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2854index 03deeff..741ce88 100644
2855--- a/arch/arm/kernel/ptrace.c
2856+++ b/arch/arm/kernel/ptrace.c
2857@@ -937,10 +937,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2858 return current_thread_info()->syscall;
2859 }
2860
2861+#ifdef CONFIG_GRKERNSEC_SETXID
2862+extern void gr_delayed_cred_worker(void);
2863+#endif
2864+
2865 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2866 {
2867 current_thread_info()->syscall = scno;
2868
2869+#ifdef CONFIG_GRKERNSEC_SETXID
2870+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2871+ gr_delayed_cred_worker();
2872+#endif
2873+
2874 /* Do the secure computing check first; failures should be fast. */
2875 if (secure_computing(scno) == -1)
2876 return -1;
2877diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2878index 234e339..81264a1 100644
2879--- a/arch/arm/kernel/setup.c
2880+++ b/arch/arm/kernel/setup.c
2881@@ -96,21 +96,23 @@ EXPORT_SYMBOL(system_serial_high);
2882 unsigned int elf_hwcap __read_mostly;
2883 EXPORT_SYMBOL(elf_hwcap);
2884
2885+pteval_t __supported_pte_mask __read_only;
2886+pmdval_t __supported_pmd_mask __read_only;
2887
2888 #ifdef MULTI_CPU
2889-struct processor processor __read_mostly;
2890+struct processor processor;
2891 #endif
2892 #ifdef MULTI_TLB
2893-struct cpu_tlb_fns cpu_tlb __read_mostly;
2894+struct cpu_tlb_fns cpu_tlb __read_only;
2895 #endif
2896 #ifdef MULTI_USER
2897-struct cpu_user_fns cpu_user __read_mostly;
2898+struct cpu_user_fns cpu_user __read_only;
2899 #endif
2900 #ifdef MULTI_CACHE
2901-struct cpu_cache_fns cpu_cache __read_mostly;
2902+struct cpu_cache_fns cpu_cache __read_only;
2903 #endif
2904 #ifdef CONFIG_OUTER_CACHE
2905-struct outer_cache_fns outer_cache __read_mostly;
2906+struct outer_cache_fns outer_cache __read_only;
2907 EXPORT_SYMBOL(outer_cache);
2908 #endif
2909
2910@@ -235,9 +237,13 @@ static int __get_cpu_architecture(void)
2911 asm("mrc p15, 0, %0, c0, c1, 4"
2912 : "=r" (mmfr0));
2913 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2914- (mmfr0 & 0x000000f0) >= 0x00000030)
2915+ (mmfr0 & 0x000000f0) >= 0x00000030) {
2916 cpu_arch = CPU_ARCH_ARMv7;
2917- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2918+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2919+ __supported_pte_mask |= L_PTE_PXN;
2920+ __supported_pmd_mask |= PMD_PXNTABLE;
2921+ }
2922+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2923 (mmfr0 & 0x000000f0) == 0x00000020)
2924 cpu_arch = CPU_ARCH_ARMv6;
2925 else
2926@@ -478,7 +484,7 @@ static void __init setup_processor(void)
2927 __cpu_architecture = __get_cpu_architecture();
2928
2929 #ifdef MULTI_CPU
2930- processor = *list->proc;
2931+ memcpy((void *)&processor, list->proc, sizeof processor);
2932 #endif
2933 #ifdef MULTI_TLB
2934 cpu_tlb = *list->tlb;
2935diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
2936index 296786b..a8d4dd5 100644
2937--- a/arch/arm/kernel/signal.c
2938+++ b/arch/arm/kernel/signal.c
2939@@ -396,22 +396,14 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
2940 __put_user(sigreturn_codes[idx+1], rc+1))
2941 return 1;
2942
2943- if (cpsr & MODE32_BIT) {
2944- /*
2945- * 32-bit code can use the new high-page
2946- * signal return code support.
2947- */
2948- retcode = KERN_SIGRETURN_CODE + (idx << 2) + thumb;
2949- } else {
2950- /*
2951- * Ensure that the instruction cache sees
2952- * the return code written onto the stack.
2953- */
2954- flush_icache_range((unsigned long)rc,
2955- (unsigned long)(rc + 2));
2956+ /*
2957+ * Ensure that the instruction cache sees
2958+ * the return code written onto the stack.
2959+ */
2960+ flush_icache_range((unsigned long)rc,
2961+ (unsigned long)(rc + 2));
2962
2963- retcode = ((unsigned long)rc) + thumb;
2964- }
2965+ retcode = ((unsigned long)rc) + thumb;
2966 }
2967
2968 regs->ARM_r0 = map_sig(ksig->sig);
2969diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
2970index 1f2cccc..f40c02e 100644
2971--- a/arch/arm/kernel/smp.c
2972+++ b/arch/arm/kernel/smp.c
2973@@ -70,7 +70,7 @@ enum ipi_msg_type {
2974
2975 static DECLARE_COMPLETION(cpu_running);
2976
2977-static struct smp_operations smp_ops;
2978+static struct smp_operations smp_ops __read_only;
2979
2980 void __init smp_set_ops(struct smp_operations *ops)
2981 {
2982diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
2983index 1c08911..264f009 100644
2984--- a/arch/arm/kernel/traps.c
2985+++ b/arch/arm/kernel/traps.c
2986@@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
2987 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
2988 {
2989 #ifdef CONFIG_KALLSYMS
2990- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
2991+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
2992 #else
2993 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
2994 #endif
2995@@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
2996 static int die_owner = -1;
2997 static unsigned int die_nest_count;
2998
2999+extern void gr_handle_kernel_exploit(void);
3000+
3001 static unsigned long oops_begin(void)
3002 {
3003 int cpu;
3004@@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3005 panic("Fatal exception in interrupt");
3006 if (panic_on_oops)
3007 panic("Fatal exception");
3008+
3009+ gr_handle_kernel_exploit();
3010+
3011 if (signr)
3012 do_exit(signr);
3013 }
3014@@ -601,7 +606,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3015 * The user helper at 0xffff0fe0 must be used instead.
3016 * (see entry-armv.S for details)
3017 */
3018+ pax_open_kernel();
3019 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3020+ pax_close_kernel();
3021 }
3022 return 0;
3023
3024@@ -841,13 +848,10 @@ void __init early_trap_init(void *vectors_base)
3025 */
3026 kuser_get_tls_init(vectors);
3027
3028- /*
3029- * Copy signal return handlers into the vector page, and
3030- * set sigreturn to be a pointer to these.
3031- */
3032- memcpy((void *)(vectors + KERN_SIGRETURN_CODE - CONFIG_VECTORS_BASE),
3033- sigreturn_codes, sizeof(sigreturn_codes));
3034-
3035 flush_icache_range(vectors, vectors + PAGE_SIZE);
3036- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3037+
3038+#ifndef CONFIG_PAX_MEMORY_UDEREF
3039+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3040+#endif
3041+
3042 }
3043diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3044index b571484..4b2fc9b 100644
3045--- a/arch/arm/kernel/vmlinux.lds.S
3046+++ b/arch/arm/kernel/vmlinux.lds.S
3047@@ -8,7 +8,11 @@
3048 #include <asm/thread_info.h>
3049 #include <asm/memory.h>
3050 #include <asm/page.h>
3051-
3052+
3053+#ifdef CONFIG_PAX_KERNEXEC
3054+#include <asm/pgtable.h>
3055+#endif
3056+
3057 #define PROC_INFO \
3058 . = ALIGN(4); \
3059 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3060@@ -94,6 +98,11 @@ SECTIONS
3061 _text = .;
3062 HEAD_TEXT
3063 }
3064+
3065+#ifdef CONFIG_PAX_KERNEXEC
3066+ . = ALIGN(1<<SECTION_SHIFT);
3067+#endif
3068+
3069 .text : { /* Real text segment */
3070 _stext = .; /* Text and read-only data */
3071 __exception_text_start = .;
3072@@ -116,6 +125,8 @@ SECTIONS
3073 ARM_CPU_KEEP(PROC_INFO)
3074 }
3075
3076+ _etext = .; /* End of text section */
3077+
3078 RO_DATA(PAGE_SIZE)
3079
3080 . = ALIGN(4);
3081@@ -146,7 +157,9 @@ SECTIONS
3082
3083 NOTES
3084
3085- _etext = .; /* End of text and rodata section */
3086+#ifdef CONFIG_PAX_KERNEXEC
3087+ . = ALIGN(1<<SECTION_SHIFT);
3088+#endif
3089
3090 #ifndef CONFIG_XIP_KERNEL
3091 . = ALIGN(PAGE_SIZE);
3092@@ -207,6 +220,11 @@ SECTIONS
3093 . = PAGE_OFFSET + TEXT_OFFSET;
3094 #else
3095 __init_end = .;
3096+
3097+#ifdef CONFIG_PAX_KERNEXEC
3098+ . = ALIGN(1<<SECTION_SHIFT);
3099+#endif
3100+
3101 . = ALIGN(THREAD_SIZE);
3102 __data_loc = .;
3103 #endif
3104diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3105index 14a0d98..7771a7d 100644
3106--- a/arch/arm/lib/clear_user.S
3107+++ b/arch/arm/lib/clear_user.S
3108@@ -12,14 +12,14 @@
3109
3110 .text
3111
3112-/* Prototype: int __clear_user(void *addr, size_t sz)
3113+/* Prototype: int ___clear_user(void *addr, size_t sz)
3114 * Purpose : clear some user memory
3115 * Params : addr - user memory address to clear
3116 * : sz - number of bytes to clear
3117 * Returns : number of bytes NOT cleared
3118 */
3119 ENTRY(__clear_user_std)
3120-WEAK(__clear_user)
3121+WEAK(___clear_user)
3122 stmfd sp!, {r1, lr}
3123 mov r2, #0
3124 cmp r1, #4
3125@@ -44,7 +44,7 @@ WEAK(__clear_user)
3126 USER( strnebt r2, [r0])
3127 mov r0, #0
3128 ldmfd sp!, {r1, pc}
3129-ENDPROC(__clear_user)
3130+ENDPROC(___clear_user)
3131 ENDPROC(__clear_user_std)
3132
3133 .pushsection .fixup,"ax"
3134diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3135index 66a477a..bee61d3 100644
3136--- a/arch/arm/lib/copy_from_user.S
3137+++ b/arch/arm/lib/copy_from_user.S
3138@@ -16,7 +16,7 @@
3139 /*
3140 * Prototype:
3141 *
3142- * size_t __copy_from_user(void *to, const void *from, size_t n)
3143+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3144 *
3145 * Purpose:
3146 *
3147@@ -84,11 +84,11 @@
3148
3149 .text
3150
3151-ENTRY(__copy_from_user)
3152+ENTRY(___copy_from_user)
3153
3154 #include "copy_template.S"
3155
3156-ENDPROC(__copy_from_user)
3157+ENDPROC(___copy_from_user)
3158
3159 .pushsection .fixup,"ax"
3160 .align 0
3161diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3162index 6ee2f67..d1cce76 100644
3163--- a/arch/arm/lib/copy_page.S
3164+++ b/arch/arm/lib/copy_page.S
3165@@ -10,6 +10,7 @@
3166 * ASM optimised string functions
3167 */
3168 #include <linux/linkage.h>
3169+#include <linux/const.h>
3170 #include <asm/assembler.h>
3171 #include <asm/asm-offsets.h>
3172 #include <asm/cache.h>
3173diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3174index d066df6..df28194 100644
3175--- a/arch/arm/lib/copy_to_user.S
3176+++ b/arch/arm/lib/copy_to_user.S
3177@@ -16,7 +16,7 @@
3178 /*
3179 * Prototype:
3180 *
3181- * size_t __copy_to_user(void *to, const void *from, size_t n)
3182+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3183 *
3184 * Purpose:
3185 *
3186@@ -88,11 +88,11 @@
3187 .text
3188
3189 ENTRY(__copy_to_user_std)
3190-WEAK(__copy_to_user)
3191+WEAK(___copy_to_user)
3192
3193 #include "copy_template.S"
3194
3195-ENDPROC(__copy_to_user)
3196+ENDPROC(___copy_to_user)
3197 ENDPROC(__copy_to_user_std)
3198
3199 .pushsection .fixup,"ax"
3200diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3201index 7d08b43..f7ca7ea 100644
3202--- a/arch/arm/lib/csumpartialcopyuser.S
3203+++ b/arch/arm/lib/csumpartialcopyuser.S
3204@@ -57,8 +57,8 @@
3205 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3206 */
3207
3208-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3209-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3210+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3211+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3212
3213 #include "csumpartialcopygeneric.S"
3214
3215diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3216index 64dbfa5..84a3fd9 100644
3217--- a/arch/arm/lib/delay.c
3218+++ b/arch/arm/lib/delay.c
3219@@ -28,7 +28,7 @@
3220 /*
3221 * Default to the loop-based delay implementation.
3222 */
3223-struct arm_delay_ops arm_delay_ops = {
3224+struct arm_delay_ops arm_delay_ops __read_only = {
3225 .delay = __loop_delay,
3226 .const_udelay = __loop_const_udelay,
3227 .udelay = __loop_udelay,
3228diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3229index 025f742..8432b08 100644
3230--- a/arch/arm/lib/uaccess_with_memcpy.c
3231+++ b/arch/arm/lib/uaccess_with_memcpy.c
3232@@ -104,7 +104,7 @@ out:
3233 }
3234
3235 unsigned long
3236-__copy_to_user(void __user *to, const void *from, unsigned long n)
3237+___copy_to_user(void __user *to, const void *from, unsigned long n)
3238 {
3239 /*
3240 * This test is stubbed out of the main function above to keep
3241diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3242index 49792a0..f192052 100644
3243--- a/arch/arm/mach-kirkwood/common.c
3244+++ b/arch/arm/mach-kirkwood/common.c
3245@@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3246 clk_gate_ops.disable(hw);
3247 }
3248
3249-static struct clk_ops clk_gate_fn_ops;
3250+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3251+{
3252+ return clk_gate_ops.is_enabled(hw);
3253+}
3254+
3255+static struct clk_ops clk_gate_fn_ops = {
3256+ .enable = clk_gate_fn_enable,
3257+ .disable = clk_gate_fn_disable,
3258+ .is_enabled = clk_gate_fn_is_enabled,
3259+};
3260
3261 static struct clk __init *clk_register_gate_fn(struct device *dev,
3262 const char *name,
3263@@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3264 gate_fn->fn_en = fn_en;
3265 gate_fn->fn_dis = fn_dis;
3266
3267- /* ops is the gate ops, but with our enable/disable functions */
3268- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3269- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3270- clk_gate_fn_ops = clk_gate_ops;
3271- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3272- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3273- }
3274-
3275 clk = clk_register(dev, &gate_fn->gate.hw);
3276
3277 if (IS_ERR(clk))
3278diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3279index f6eeb87..cc90868 100644
3280--- a/arch/arm/mach-omap2/board-n8x0.c
3281+++ b/arch/arm/mach-omap2/board-n8x0.c
3282@@ -631,7 +631,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3283 }
3284 #endif
3285
3286-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3287+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3288 .late_init = n8x0_menelaus_late_init,
3289 };
3290
3291diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3292index 410e1ba..1d2dd59 100644
3293--- a/arch/arm/mach-omap2/gpmc.c
3294+++ b/arch/arm/mach-omap2/gpmc.c
3295@@ -145,7 +145,6 @@ struct omap3_gpmc_regs {
3296 };
3297
3298 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3299-static struct irq_chip gpmc_irq_chip;
3300 static unsigned gpmc_irq_start;
3301
3302 static struct resource gpmc_mem_root;
3303@@ -707,6 +706,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3304
3305 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3306
3307+static struct irq_chip gpmc_irq_chip = {
3308+ .name = "gpmc",
3309+ .irq_startup = gpmc_irq_noop_ret,
3310+ .irq_enable = gpmc_irq_enable,
3311+ .irq_disable = gpmc_irq_disable,
3312+ .irq_shutdown = gpmc_irq_noop,
3313+ .irq_ack = gpmc_irq_noop,
3314+ .irq_mask = gpmc_irq_noop,
3315+ .irq_unmask = gpmc_irq_noop,
3316+
3317+};
3318+
3319 static int gpmc_setup_irq(void)
3320 {
3321 int i;
3322@@ -721,15 +732,6 @@ static int gpmc_setup_irq(void)
3323 return gpmc_irq_start;
3324 }
3325
3326- gpmc_irq_chip.name = "gpmc";
3327- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3328- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3329- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3330- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3331- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3332- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3333- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3334-
3335 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3336 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3337
3338diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3339index f8bb3b9..831e7b8 100644
3340--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3341+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3342@@ -339,7 +339,7 @@ static int __cpuinit irq_cpu_hotplug_notify(struct notifier_block *self,
3343 return NOTIFY_OK;
3344 }
3345
3346-static struct notifier_block __refdata irq_hotplug_notifier = {
3347+static struct notifier_block irq_hotplug_notifier = {
3348 .notifier_call = irq_cpu_hotplug_notify,
3349 };
3350
3351diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3352index 381be7a..89b9c7e 100644
3353--- a/arch/arm/mach-omap2/omap_device.c
3354+++ b/arch/arm/mach-omap2/omap_device.c
3355@@ -499,7 +499,7 @@ void omap_device_delete(struct omap_device *od)
3356 struct platform_device __init *omap_device_build(const char *pdev_name,
3357 int pdev_id,
3358 struct omap_hwmod *oh,
3359- void *pdata, int pdata_len)
3360+ const void *pdata, int pdata_len)
3361 {
3362 struct omap_hwmod *ohs[] = { oh };
3363
3364@@ -527,7 +527,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3365 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3366 int pdev_id,
3367 struct omap_hwmod **ohs,
3368- int oh_cnt, void *pdata,
3369+ int oh_cnt, const void *pdata,
3370 int pdata_len)
3371 {
3372 int ret = -ENOMEM;
3373diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3374index 044c31d..2ee0861 100644
3375--- a/arch/arm/mach-omap2/omap_device.h
3376+++ b/arch/arm/mach-omap2/omap_device.h
3377@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3378 /* Core code interface */
3379
3380 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3381- struct omap_hwmod *oh, void *pdata,
3382+ struct omap_hwmod *oh, const void *pdata,
3383 int pdata_len);
3384
3385 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3386 struct omap_hwmod **oh, int oh_cnt,
3387- void *pdata, int pdata_len);
3388+ const void *pdata, int pdata_len);
3389
3390 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3391 struct omap_hwmod **ohs, int oh_cnt);
3392diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3393index 3a750de..4c9b88f 100644
3394--- a/arch/arm/mach-omap2/omap_hwmod.c
3395+++ b/arch/arm/mach-omap2/omap_hwmod.c
3396@@ -191,10 +191,10 @@ struct omap_hwmod_soc_ops {
3397 int (*init_clkdm)(struct omap_hwmod *oh);
3398 void (*update_context_lost)(struct omap_hwmod *oh);
3399 int (*get_context_lost)(struct omap_hwmod *oh);
3400-};
3401+} __no_const;
3402
3403 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3404-static struct omap_hwmod_soc_ops soc_ops;
3405+static struct omap_hwmod_soc_ops soc_ops __read_only;
3406
3407 /* omap_hwmod_list contains all registered struct omap_hwmods */
3408 static LIST_HEAD(omap_hwmod_list);
3409diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3410index d15c7bb..b2d1f0c 100644
3411--- a/arch/arm/mach-omap2/wd_timer.c
3412+++ b/arch/arm/mach-omap2/wd_timer.c
3413@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3414 struct omap_hwmod *oh;
3415 char *oh_name = "wd_timer2";
3416 char *dev_name = "omap_wdt";
3417- struct omap_wd_timer_platform_data pdata;
3418+ static struct omap_wd_timer_platform_data pdata = {
3419+ .read_reset_sources = prm_read_reset_sources
3420+ };
3421
3422 if (!cpu_class_is_omap2() || of_have_populated_dt())
3423 return 0;
3424@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3425 return -EINVAL;
3426 }
3427
3428- pdata.read_reset_sources = prm_read_reset_sources;
3429-
3430 pdev = omap_device_build(dev_name, id, oh, &pdata,
3431 sizeof(struct omap_wd_timer_platform_data));
3432 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3433diff --git a/arch/arm/mach-ux500/include/mach/setup.h b/arch/arm/mach-ux500/include/mach/setup.h
3434index bddce2b..3eb04e2 100644
3435--- a/arch/arm/mach-ux500/include/mach/setup.h
3436+++ b/arch/arm/mach-ux500/include/mach/setup.h
3437@@ -37,13 +37,6 @@ extern void ux500_timer_init(void);
3438 .type = MT_DEVICE, \
3439 }
3440
3441-#define __MEM_DEV_DESC(x, sz) { \
3442- .virtual = IO_ADDRESS(x), \
3443- .pfn = __phys_to_pfn(x), \
3444- .length = sz, \
3445- .type = MT_MEMORY, \
3446-}
3447-
3448 extern struct smp_operations ux500_smp_ops;
3449 extern void ux500_cpu_die(unsigned int cpu);
3450
3451diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3452index 4045c49..4e26c79 100644
3453--- a/arch/arm/mm/Kconfig
3454+++ b/arch/arm/mm/Kconfig
3455@@ -425,7 +425,7 @@ config CPU_32v5
3456
3457 config CPU_32v6
3458 bool
3459- select CPU_USE_DOMAINS if CPU_V6 && MMU
3460+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC
3461 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3462
3463 config CPU_32v6K
3464@@ -574,6 +574,7 @@ config CPU_CP15_MPU
3465
3466 config CPU_USE_DOMAINS
3467 bool
3468+ depends on !ARM_LPAE && !PAX_KERNEXEC
3469 help
3470 This option enables or disables the use of domain switching
3471 via the set_fs() function.
3472diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3473index db26e2e..ee44569 100644
3474--- a/arch/arm/mm/alignment.c
3475+++ b/arch/arm/mm/alignment.c
3476@@ -211,10 +211,12 @@ union offset_union {
3477 #define __get16_unaligned_check(ins,val,addr) \
3478 do { \
3479 unsigned int err = 0, v, a = addr; \
3480+ pax_open_userland(); \
3481 __get8_unaligned_check(ins,v,a,err); \
3482 val = v << ((BE) ? 8 : 0); \
3483 __get8_unaligned_check(ins,v,a,err); \
3484 val |= v << ((BE) ? 0 : 8); \
3485+ pax_close_userland(); \
3486 if (err) \
3487 goto fault; \
3488 } while (0)
3489@@ -228,6 +230,7 @@ union offset_union {
3490 #define __get32_unaligned_check(ins,val,addr) \
3491 do { \
3492 unsigned int err = 0, v, a = addr; \
3493+ pax_open_userland(); \
3494 __get8_unaligned_check(ins,v,a,err); \
3495 val = v << ((BE) ? 24 : 0); \
3496 __get8_unaligned_check(ins,v,a,err); \
3497@@ -236,6 +239,7 @@ union offset_union {
3498 val |= v << ((BE) ? 8 : 16); \
3499 __get8_unaligned_check(ins,v,a,err); \
3500 val |= v << ((BE) ? 0 : 24); \
3501+ pax_close_userland(); \
3502 if (err) \
3503 goto fault; \
3504 } while (0)
3505@@ -249,6 +253,7 @@ union offset_union {
3506 #define __put16_unaligned_check(ins,val,addr) \
3507 do { \
3508 unsigned int err = 0, v = val, a = addr; \
3509+ pax_open_userland(); \
3510 __asm__( FIRST_BYTE_16 \
3511 ARM( "1: "ins" %1, [%2], #1\n" ) \
3512 THUMB( "1: "ins" %1, [%2]\n" ) \
3513@@ -268,6 +273,7 @@ union offset_union {
3514 " .popsection\n" \
3515 : "=r" (err), "=&r" (v), "=&r" (a) \
3516 : "0" (err), "1" (v), "2" (a)); \
3517+ pax_close_userland(); \
3518 if (err) \
3519 goto fault; \
3520 } while (0)
3521@@ -281,6 +287,7 @@ union offset_union {
3522 #define __put32_unaligned_check(ins,val,addr) \
3523 do { \
3524 unsigned int err = 0, v = val, a = addr; \
3525+ pax_open_userland(); \
3526 __asm__( FIRST_BYTE_32 \
3527 ARM( "1: "ins" %1, [%2], #1\n" ) \
3528 THUMB( "1: "ins" %1, [%2]\n" ) \
3529@@ -310,6 +317,7 @@ union offset_union {
3530 " .popsection\n" \
3531 : "=r" (err), "=&r" (v), "=&r" (a) \
3532 : "0" (err), "1" (v), "2" (a)); \
3533+ pax_close_userland(); \
3534 if (err) \
3535 goto fault; \
3536 } while (0)
3537diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3538index 5dbf13f..1a60561 100644
3539--- a/arch/arm/mm/fault.c
3540+++ b/arch/arm/mm/fault.c
3541@@ -25,6 +25,7 @@
3542 #include <asm/system_misc.h>
3543 #include <asm/system_info.h>
3544 #include <asm/tlbflush.h>
3545+#include <asm/sections.h>
3546
3547 #include "fault.h"
3548
3549@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3550 if (fixup_exception(regs))
3551 return;
3552
3553+#ifdef CONFIG_PAX_KERNEXEC
3554+ if ((fsr & FSR_WRITE) &&
3555+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3556+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3557+ {
3558+ if (current->signal->curr_ip)
3559+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3560+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3561+ else
3562+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3563+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3564+ }
3565+#endif
3566+
3567 /*
3568 * No handler, we'll have to terminate things with extreme prejudice.
3569 */
3570@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3571 }
3572 #endif
3573
3574+#ifdef CONFIG_PAX_PAGEEXEC
3575+ if (fsr & FSR_LNX_PF) {
3576+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3577+ do_group_exit(SIGKILL);
3578+ }
3579+#endif
3580+
3581 tsk->thread.address = addr;
3582 tsk->thread.error_code = fsr;
3583 tsk->thread.trap_no = 14;
3584@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3585 }
3586 #endif /* CONFIG_MMU */
3587
3588+#ifdef CONFIG_PAX_PAGEEXEC
3589+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3590+{
3591+ long i;
3592+
3593+ printk(KERN_ERR "PAX: bytes at PC: ");
3594+ for (i = 0; i < 20; i++) {
3595+ unsigned char c;
3596+ if (get_user(c, (__force unsigned char __user *)pc+i))
3597+ printk(KERN_CONT "?? ");
3598+ else
3599+ printk(KERN_CONT "%02x ", c);
3600+ }
3601+ printk("\n");
3602+
3603+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3604+ for (i = -1; i < 20; i++) {
3605+ unsigned long c;
3606+ if (get_user(c, (__force unsigned long __user *)sp+i))
3607+ printk(KERN_CONT "???????? ");
3608+ else
3609+ printk(KERN_CONT "%08lx ", c);
3610+ }
3611+ printk("\n");
3612+}
3613+#endif
3614+
3615 /*
3616 * First Level Translation Fault Handler
3617 *
3618@@ -543,9 +592,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3619 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3620 struct siginfo info;
3621
3622+#ifdef CONFIG_PAX_MEMORY_UDEREF
3623+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3624+ if (current->signal->curr_ip)
3625+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3626+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3627+ else
3628+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3629+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3630+ goto die;
3631+ }
3632+#endif
3633+
3634 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3635 return;
3636
3637+die:
3638 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3639 inf->name, fsr, addr);
3640
3641@@ -575,9 +637,49 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3642 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3643 struct siginfo info;
3644
3645+ if (user_mode(regs)) {
3646+ if (addr == 0xffff0fe0UL) {
3647+ /*
3648+ * PaX: __kuser_get_tls emulation
3649+ */
3650+ regs->ARM_r0 = current_thread_info()->tp_value;
3651+ regs->ARM_pc = regs->ARM_lr;
3652+ return;
3653+ }
3654+ }
3655+
3656+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3657+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3658+ if (current->signal->curr_ip)
3659+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3660+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3661+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3662+ else
3663+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3664+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3665+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3666+ goto die;
3667+ }
3668+#endif
3669+
3670+#ifdef CONFIG_PAX_REFCOUNT
3671+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3672+ unsigned int bkpt;
3673+
3674+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
3675+ current->thread.error_code = ifsr;
3676+ current->thread.trap_no = 0;
3677+ pax_report_refcount_overflow(regs);
3678+ fixup_exception(regs);
3679+ return;
3680+ }
3681+ }
3682+#endif
3683+
3684 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3685 return;
3686
3687+die:
3688 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3689 inf->name, ifsr, addr);
3690
3691diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3692index cf08bdf..772656c 100644
3693--- a/arch/arm/mm/fault.h
3694+++ b/arch/arm/mm/fault.h
3695@@ -3,6 +3,7 @@
3696
3697 /*
3698 * Fault status register encodings. We steal bit 31 for our own purposes.
3699+ * Set when the FSR value is from an instruction fault.
3700 */
3701 #define FSR_LNX_PF (1 << 31)
3702 #define FSR_WRITE (1 << 11)
3703@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3704 }
3705 #endif
3706
3707+/* valid for LPAE and !LPAE */
3708+static inline int is_xn_fault(unsigned int fsr)
3709+{
3710+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
3711+}
3712+
3713+static inline int is_domain_fault(unsigned int fsr)
3714+{
3715+ return ((fsr_fs(fsr) & 0xD) == 0x9);
3716+}
3717+
3718 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3719 unsigned long search_exception_table(unsigned long addr);
3720
3721diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
3722index ad722f1..763fdd3 100644
3723--- a/arch/arm/mm/init.c
3724+++ b/arch/arm/mm/init.c
3725@@ -30,6 +30,8 @@
3726 #include <asm/setup.h>
3727 #include <asm/tlb.h>
3728 #include <asm/fixmap.h>
3729+#include <asm/system_info.h>
3730+#include <asm/cp15.h>
3731
3732 #include <asm/mach/arch.h>
3733 #include <asm/mach/map.h>
3734@@ -736,7 +738,46 @@ void free_initmem(void)
3735 {
3736 #ifdef CONFIG_HAVE_TCM
3737 extern char __tcm_start, __tcm_end;
3738+#endif
3739
3740+#ifdef CONFIG_PAX_KERNEXEC
3741+ unsigned long addr;
3742+ pgd_t *pgd;
3743+ pud_t *pud;
3744+ pmd_t *pmd;
3745+ int cpu_arch = cpu_architecture();
3746+ unsigned int cr = get_cr();
3747+
3748+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
3749+ /* make pages tables, etc before .text NX */
3750+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
3751+ pgd = pgd_offset_k(addr);
3752+ pud = pud_offset(pgd, addr);
3753+ pmd = pmd_offset(pud, addr);
3754+ __section_update(pmd, addr, PMD_SECT_XN);
3755+ }
3756+ /* make init NX */
3757+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
3758+ pgd = pgd_offset_k(addr);
3759+ pud = pud_offset(pgd, addr);
3760+ pmd = pmd_offset(pud, addr);
3761+ __section_update(pmd, addr, PMD_SECT_XN);
3762+ }
3763+ /* make kernel code/rodata RX */
3764+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
3765+ pgd = pgd_offset_k(addr);
3766+ pud = pud_offset(pgd, addr);
3767+ pmd = pmd_offset(pud, addr);
3768+#ifdef CONFIG_ARM_LPAE
3769+ __section_update(pmd, addr, PMD_SECT_RDONLY);
3770+#else
3771+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
3772+#endif
3773+ }
3774+ }
3775+#endif
3776+
3777+#ifdef CONFIG_HAVE_TCM
3778 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
3779 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
3780 __phys_to_pfn(__pa(&__tcm_end)),
3781diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
3782index 04d9006..c547d85 100644
3783--- a/arch/arm/mm/ioremap.c
3784+++ b/arch/arm/mm/ioremap.c
3785@@ -392,9 +392,9 @@ __arm_ioremap_exec(unsigned long phys_addr, size_t size, bool cached)
3786 unsigned int mtype;
3787
3788 if (cached)
3789- mtype = MT_MEMORY;
3790+ mtype = MT_MEMORY_RX;
3791 else
3792- mtype = MT_MEMORY_NONCACHED;
3793+ mtype = MT_MEMORY_NONCACHED_RX;
3794
3795 return __arm_ioremap_caller(phys_addr, size, mtype,
3796 __builtin_return_address(0));
3797diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
3798index 10062ce..cd34fb9 100644
3799--- a/arch/arm/mm/mmap.c
3800+++ b/arch/arm/mm/mmap.c
3801@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3802 struct vm_area_struct *vma;
3803 int do_align = 0;
3804 int aliasing = cache_is_vipt_aliasing();
3805+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3806 struct vm_unmapped_area_info info;
3807
3808 /*
3809@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3810 if (len > TASK_SIZE)
3811 return -ENOMEM;
3812
3813+#ifdef CONFIG_PAX_RANDMMAP
3814+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3815+#endif
3816+
3817 if (addr) {
3818 if (do_align)
3819 addr = COLOUR_ALIGN(addr, pgoff);
3820@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3821 addr = PAGE_ALIGN(addr);
3822
3823 vma = find_vma(mm, addr);
3824- if (TASK_SIZE - len >= addr &&
3825- (!vma || addr + len <= vma->vm_start))
3826+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3827 return addr;
3828 }
3829
3830@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3831 info.high_limit = TASK_SIZE;
3832 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
3833 info.align_offset = pgoff << PAGE_SHIFT;
3834+ info.threadstack_offset = offset;
3835 return vm_unmapped_area(&info);
3836 }
3837
3838@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3839 unsigned long addr = addr0;
3840 int do_align = 0;
3841 int aliasing = cache_is_vipt_aliasing();
3842+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3843 struct vm_unmapped_area_info info;
3844
3845 /*
3846@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3847 return addr;
3848 }
3849
3850+#ifdef CONFIG_PAX_RANDMMAP
3851+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3852+#endif
3853+
3854 /* requesting a specific address */
3855 if (addr) {
3856 if (do_align)
3857@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3858 else
3859 addr = PAGE_ALIGN(addr);
3860 vma = find_vma(mm, addr);
3861- if (TASK_SIZE - len >= addr &&
3862- (!vma || addr + len <= vma->vm_start))
3863+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3864 return addr;
3865 }
3866
3867@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3868 info.high_limit = mm->mmap_base;
3869 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
3870 info.align_offset = pgoff << PAGE_SHIFT;
3871+ info.threadstack_offset = offset;
3872 addr = vm_unmapped_area(&info);
3873
3874 /*
3875@@ -162,6 +172,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3876 VM_BUG_ON(addr != -ENOMEM);
3877 info.flags = 0;
3878 info.low_limit = mm->mmap_base;
3879+
3880+#ifdef CONFIG_PAX_RANDMMAP
3881+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3882+ info.low_limit += mm->delta_mmap;
3883+#endif
3884+
3885 info.high_limit = TASK_SIZE;
3886 addr = vm_unmapped_area(&info);
3887 }
3888@@ -173,6 +189,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3889 {
3890 unsigned long random_factor = 0UL;
3891
3892+#ifdef CONFIG_PAX_RANDMMAP
3893+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3894+#endif
3895+
3896 /* 8 bits of randomness in 20 address space bits */
3897 if ((current->flags & PF_RANDOMIZE) &&
3898 !(current->personality & ADDR_NO_RANDOMIZE))
3899@@ -180,10 +200,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3900
3901 if (mmap_is_legacy()) {
3902 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
3903+
3904+#ifdef CONFIG_PAX_RANDMMAP
3905+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3906+ mm->mmap_base += mm->delta_mmap;
3907+#endif
3908+
3909 mm->get_unmapped_area = arch_get_unmapped_area;
3910 mm->unmap_area = arch_unmap_area;
3911 } else {
3912 mm->mmap_base = mmap_base(random_factor);
3913+
3914+#ifdef CONFIG_PAX_RANDMMAP
3915+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3916+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3917+#endif
3918+
3919 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3920 mm->unmap_area = arch_unmap_area_topdown;
3921 }
3922diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
3923index a84ff76..f221c1d 100644
3924--- a/arch/arm/mm/mmu.c
3925+++ b/arch/arm/mm/mmu.c
3926@@ -36,6 +36,22 @@
3927 #include "mm.h"
3928 #include "tcm.h"
3929
3930+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3931+void modify_domain(unsigned int dom, unsigned int type)
3932+{
3933+ struct thread_info *thread = current_thread_info();
3934+ unsigned int domain = thread->cpu_domain;
3935+ /*
3936+ * DOMAIN_MANAGER might be defined to some other value,
3937+ * use the arch-defined constant
3938+ */
3939+ domain &= ~domain_val(dom, 3);
3940+ thread->cpu_domain = domain | domain_val(dom, type);
3941+ set_domain(thread->cpu_domain);
3942+}
3943+EXPORT_SYMBOL(modify_domain);
3944+#endif
3945+
3946 /*
3947 * empty_zero_page is a special page that is used for
3948 * zero-initialized data and COW.
3949@@ -211,10 +227,18 @@ void adjust_cr(unsigned long mask, unsigned long set)
3950 }
3951 #endif
3952
3953-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
3954+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
3955 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
3956
3957-static struct mem_type mem_types[] = {
3958+#ifdef CONFIG_PAX_KERNEXEC
3959+#define L_PTE_KERNEXEC L_PTE_RDONLY
3960+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
3961+#else
3962+#define L_PTE_KERNEXEC L_PTE_DIRTY
3963+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
3964+#endif
3965+
3966+static struct mem_type mem_types[] __read_only = {
3967 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
3968 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
3969 L_PTE_SHARED,
3970@@ -243,16 +267,16 @@ static struct mem_type mem_types[] = {
3971 [MT_UNCACHED] = {
3972 .prot_pte = PROT_PTE_DEVICE,
3973 .prot_l1 = PMD_TYPE_TABLE,
3974- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3975+ .prot_sect = PROT_SECT_DEVICE,
3976 .domain = DOMAIN_IO,
3977 },
3978 [MT_CACHECLEAN] = {
3979- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3980+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3981 .domain = DOMAIN_KERNEL,
3982 },
3983 #ifndef CONFIG_ARM_LPAE
3984 [MT_MINICLEAN] = {
3985- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
3986+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
3987 .domain = DOMAIN_KERNEL,
3988 },
3989 #endif
3990@@ -260,36 +284,54 @@ static struct mem_type mem_types[] = {
3991 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3992 L_PTE_RDONLY,
3993 .prot_l1 = PMD_TYPE_TABLE,
3994- .domain = DOMAIN_USER,
3995+ .domain = DOMAIN_VECTORS,
3996 },
3997 [MT_HIGH_VECTORS] = {
3998 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3999- L_PTE_USER | L_PTE_RDONLY,
4000+ L_PTE_RDONLY,
4001 .prot_l1 = PMD_TYPE_TABLE,
4002- .domain = DOMAIN_USER,
4003+ .domain = DOMAIN_VECTORS,
4004 },
4005- [MT_MEMORY] = {
4006+ [MT_MEMORY_RWX] = {
4007 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4008 .prot_l1 = PMD_TYPE_TABLE,
4009 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4010 .domain = DOMAIN_KERNEL,
4011 },
4012+ [MT_MEMORY_RW] = {
4013+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4014+ .prot_l1 = PMD_TYPE_TABLE,
4015+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4016+ .domain = DOMAIN_KERNEL,
4017+ },
4018+ [MT_MEMORY_RX] = {
4019+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4020+ .prot_l1 = PMD_TYPE_TABLE,
4021+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4022+ .domain = DOMAIN_KERNEL,
4023+ },
4024 [MT_ROM] = {
4025- .prot_sect = PMD_TYPE_SECT,
4026+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4027 .domain = DOMAIN_KERNEL,
4028 },
4029- [MT_MEMORY_NONCACHED] = {
4030+ [MT_MEMORY_NONCACHED_RW] = {
4031 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4032 L_PTE_MT_BUFFERABLE,
4033 .prot_l1 = PMD_TYPE_TABLE,
4034 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4035 .domain = DOMAIN_KERNEL,
4036 },
4037+ [MT_MEMORY_NONCACHED_RX] = {
4038+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4039+ L_PTE_MT_BUFFERABLE,
4040+ .prot_l1 = PMD_TYPE_TABLE,
4041+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4042+ .domain = DOMAIN_KERNEL,
4043+ },
4044 [MT_MEMORY_DTCM] = {
4045- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4046- L_PTE_XN,
4047+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4048 .prot_l1 = PMD_TYPE_TABLE,
4049- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4050+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4051 .domain = DOMAIN_KERNEL,
4052 },
4053 [MT_MEMORY_ITCM] = {
4054@@ -299,10 +341,10 @@ static struct mem_type mem_types[] = {
4055 },
4056 [MT_MEMORY_SO] = {
4057 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4058- L_PTE_MT_UNCACHED | L_PTE_XN,
4059+ L_PTE_MT_UNCACHED,
4060 .prot_l1 = PMD_TYPE_TABLE,
4061 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4062- PMD_SECT_UNCACHED | PMD_SECT_XN,
4063+ PMD_SECT_UNCACHED,
4064 .domain = DOMAIN_KERNEL,
4065 },
4066 [MT_MEMORY_DMA_READY] = {
4067@@ -388,9 +430,35 @@ static void __init build_mem_type_table(void)
4068 * to prevent speculative instruction fetches.
4069 */
4070 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4071+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4072 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4073+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4074 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4075+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4076 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4077+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4078+
4079+ /* Mark other regions on ARMv6+ as execute-never */
4080+
4081+#ifdef CONFIG_PAX_KERNEXEC
4082+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4083+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4084+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4085+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4086+#ifndef CONFIG_ARM_LPAE
4087+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4088+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4089+#endif
4090+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4091+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4092+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4093+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4094+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4095+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4096+#endif
4097+
4098+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4099+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4100 }
4101 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4102 /*
4103@@ -451,6 +519,9 @@ static void __init build_mem_type_table(void)
4104 * from SVC mode and no access from userspace.
4105 */
4106 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4107+#ifdef CONFIG_PAX_KERNEXEC
4108+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4109+#endif
4110 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4111 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4112 #endif
4113@@ -468,11 +539,17 @@ static void __init build_mem_type_table(void)
4114 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4115 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4116 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4117- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4118- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4119+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4120+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4121+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4122+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4123+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4124+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4125 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4126- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4127- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4128+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4129+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4130+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4131+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4132 }
4133 }
4134
4135@@ -483,15 +560,20 @@ static void __init build_mem_type_table(void)
4136 if (cpu_arch >= CPU_ARCH_ARMv6) {
4137 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4138 /* Non-cacheable Normal is XCB = 001 */
4139- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4140+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4141+ PMD_SECT_BUFFERED;
4142+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4143 PMD_SECT_BUFFERED;
4144 } else {
4145 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4146- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4147+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4148+ PMD_SECT_TEX(1);
4149+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4150 PMD_SECT_TEX(1);
4151 }
4152 } else {
4153- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4154+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4155+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4156 }
4157
4158 #ifdef CONFIG_ARM_LPAE
4159@@ -507,6 +589,8 @@ static void __init build_mem_type_table(void)
4160 vecs_pgprot |= PTE_EXT_AF;
4161 #endif
4162
4163+ user_pgprot |= __supported_pte_mask;
4164+
4165 for (i = 0; i < 16; i++) {
4166 pteval_t v = pgprot_val(protection_map[i]);
4167 protection_map[i] = __pgprot(v | user_pgprot);
4168@@ -524,10 +608,15 @@ static void __init build_mem_type_table(void)
4169
4170 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4171 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4172- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4173- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4174+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4175+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4176+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4177+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4178+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4179+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4180 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4181- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4182+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4183+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4184 mem_types[MT_ROM].prot_sect |= cp->pmd;
4185
4186 switch (cp->pmd) {
4187@@ -1147,18 +1236,15 @@ void __init arm_mm_memblock_reserve(void)
4188 * called function. This means you can't use any function or debugging
4189 * method which may touch any device, otherwise the kernel _will_ crash.
4190 */
4191+
4192+static char vectors[PAGE_SIZE] __read_only __aligned(PAGE_SIZE);
4193+
4194 static void __init devicemaps_init(struct machine_desc *mdesc)
4195 {
4196 struct map_desc map;
4197 unsigned long addr;
4198- void *vectors;
4199
4200- /*
4201- * Allocate the vector page early.
4202- */
4203- vectors = early_alloc(PAGE_SIZE);
4204-
4205- early_trap_init(vectors);
4206+ early_trap_init(&vectors);
4207
4208 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4209 pmd_clear(pmd_off_k(addr));
4210@@ -1198,7 +1284,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4211 * location (0xffff0000). If we aren't using high-vectors, also
4212 * create a mapping at the low-vectors virtual address.
4213 */
4214- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4215+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4216 map.virtual = 0xffff0000;
4217 map.length = PAGE_SIZE;
4218 map.type = MT_HIGH_VECTORS;
4219@@ -1256,8 +1342,39 @@ static void __init map_lowmem(void)
4220 map.pfn = __phys_to_pfn(start);
4221 map.virtual = __phys_to_virt(start);
4222 map.length = end - start;
4223- map.type = MT_MEMORY;
4224
4225+#ifdef CONFIG_PAX_KERNEXEC
4226+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4227+ struct map_desc kernel;
4228+ struct map_desc initmap;
4229+
4230+ /* when freeing initmem we will make this RW */
4231+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4232+ initmap.virtual = (unsigned long)__init_begin;
4233+ initmap.length = _sdata - __init_begin;
4234+ initmap.type = MT_MEMORY_RWX;
4235+ create_mapping(&initmap);
4236+
4237+ /* when freeing initmem we will make this RX */
4238+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4239+ kernel.virtual = (unsigned long)_stext;
4240+ kernel.length = __init_begin - _stext;
4241+ kernel.type = MT_MEMORY_RWX;
4242+ create_mapping(&kernel);
4243+
4244+ if (map.virtual < (unsigned long)_stext) {
4245+ map.length = (unsigned long)_stext - map.virtual;
4246+ map.type = MT_MEMORY_RWX;
4247+ create_mapping(&map);
4248+ }
4249+
4250+ map.pfn = __phys_to_pfn(__pa(_sdata));
4251+ map.virtual = (unsigned long)_sdata;
4252+ map.length = end - __pa(_sdata);
4253+ }
4254+#endif
4255+
4256+ map.type = MT_MEMORY_RW;
4257 create_mapping(&map);
4258 }
4259 }
4260diff --git a/arch/arm/mm/proc-v7-2level.S b/arch/arm/mm/proc-v7-2level.S
4261index 78f520b..31f0cb6 100644
4262--- a/arch/arm/mm/proc-v7-2level.S
4263+++ b/arch/arm/mm/proc-v7-2level.S
4264@@ -99,6 +99,9 @@ ENTRY(cpu_v7_set_pte_ext)
4265 tst r1, #L_PTE_XN
4266 orrne r3, r3, #PTE_EXT_XN
4267
4268+ tst r1, #L_PTE_PXN
4269+ orrne r3, r3, #PTE_EXT_PXN
4270+
4271 tst r1, #L_PTE_YOUNG
4272 tstne r1, #L_PTE_VALID
4273 #ifndef CONFIG_CPU_USE_DOMAINS
4274diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4275index a5bc92d..0bb4730 100644
4276--- a/arch/arm/plat-omap/sram.c
4277+++ b/arch/arm/plat-omap/sram.c
4278@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4279 * Looks like we need to preserve some bootloader code at the
4280 * beginning of SRAM for jumping to flash for reboot to work...
4281 */
4282+ pax_open_kernel();
4283 memset_io(omap_sram_base + omap_sram_skip, 0,
4284 omap_sram_size - omap_sram_skip);
4285+ pax_close_kernel();
4286 }
4287diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4288index 1141782..0959d64 100644
4289--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4290+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4291@@ -48,7 +48,7 @@ struct samsung_dma_ops {
4292 int (*started)(unsigned ch);
4293 int (*flush)(unsigned ch);
4294 int (*stop)(unsigned ch);
4295-};
4296+} __no_const;
4297
4298 extern void *samsung_dmadev_get_ops(void);
4299 extern void *s3c_dma_get_ops(void);
4300diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
4301index f4726dc..39ed646 100644
4302--- a/arch/arm64/kernel/debug-monitors.c
4303+++ b/arch/arm64/kernel/debug-monitors.c
4304@@ -149,7 +149,7 @@ static int __cpuinit os_lock_notify(struct notifier_block *self,
4305 return NOTIFY_OK;
4306 }
4307
4308-static struct notifier_block __cpuinitdata os_lock_nb = {
4309+static struct notifier_block os_lock_nb = {
4310 .notifier_call = os_lock_notify,
4311 };
4312
4313diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
4314index 5ab825c..96aaec8 100644
4315--- a/arch/arm64/kernel/hw_breakpoint.c
4316+++ b/arch/arm64/kernel/hw_breakpoint.c
4317@@ -831,7 +831,7 @@ static int __cpuinit hw_breakpoint_reset_notify(struct notifier_block *self,
4318 return NOTIFY_OK;
4319 }
4320
4321-static struct notifier_block __cpuinitdata hw_breakpoint_reset_nb = {
4322+static struct notifier_block hw_breakpoint_reset_nb = {
4323 .notifier_call = hw_breakpoint_reset_notify,
4324 };
4325
4326diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4327index c3a58a1..78fbf54 100644
4328--- a/arch/avr32/include/asm/cache.h
4329+++ b/arch/avr32/include/asm/cache.h
4330@@ -1,8 +1,10 @@
4331 #ifndef __ASM_AVR32_CACHE_H
4332 #define __ASM_AVR32_CACHE_H
4333
4334+#include <linux/const.h>
4335+
4336 #define L1_CACHE_SHIFT 5
4337-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4338+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4339
4340 /*
4341 * Memory returned by kmalloc() may be used for DMA, so we must make
4342diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4343index d232888..87c8df1 100644
4344--- a/arch/avr32/include/asm/elf.h
4345+++ b/arch/avr32/include/asm/elf.h
4346@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4347 the loader. We need to make sure that it is out of the way of the program
4348 that it will "exec", and that there is sufficient room for the brk. */
4349
4350-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4351+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4352
4353+#ifdef CONFIG_PAX_ASLR
4354+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4355+
4356+#define PAX_DELTA_MMAP_LEN 15
4357+#define PAX_DELTA_STACK_LEN 15
4358+#endif
4359
4360 /* This yields a mask that user programs can use to figure out what
4361 instruction set this CPU supports. This could be done in user space,
4362diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4363index 479330b..53717a8 100644
4364--- a/arch/avr32/include/asm/kmap_types.h
4365+++ b/arch/avr32/include/asm/kmap_types.h
4366@@ -2,9 +2,9 @@
4367 #define __ASM_AVR32_KMAP_TYPES_H
4368
4369 #ifdef CONFIG_DEBUG_HIGHMEM
4370-# define KM_TYPE_NR 29
4371+# define KM_TYPE_NR 30
4372 #else
4373-# define KM_TYPE_NR 14
4374+# define KM_TYPE_NR 15
4375 #endif
4376
4377 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4378diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4379index b2f2d2d..d1c85cb 100644
4380--- a/arch/avr32/mm/fault.c
4381+++ b/arch/avr32/mm/fault.c
4382@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4383
4384 int exception_trace = 1;
4385
4386+#ifdef CONFIG_PAX_PAGEEXEC
4387+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4388+{
4389+ unsigned long i;
4390+
4391+ printk(KERN_ERR "PAX: bytes at PC: ");
4392+ for (i = 0; i < 20; i++) {
4393+ unsigned char c;
4394+ if (get_user(c, (unsigned char *)pc+i))
4395+ printk(KERN_CONT "???????? ");
4396+ else
4397+ printk(KERN_CONT "%02x ", c);
4398+ }
4399+ printk("\n");
4400+}
4401+#endif
4402+
4403 /*
4404 * This routine handles page faults. It determines the address and the
4405 * problem, and then passes it off to one of the appropriate routines.
4406@@ -174,6 +191,16 @@ bad_area:
4407 up_read(&mm->mmap_sem);
4408
4409 if (user_mode(regs)) {
4410+
4411+#ifdef CONFIG_PAX_PAGEEXEC
4412+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4413+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4414+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4415+ do_group_exit(SIGKILL);
4416+ }
4417+ }
4418+#endif
4419+
4420 if (exception_trace && printk_ratelimit())
4421 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4422 "sp %08lx ecr %lu\n",
4423diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4424index 568885a..f8008df 100644
4425--- a/arch/blackfin/include/asm/cache.h
4426+++ b/arch/blackfin/include/asm/cache.h
4427@@ -7,6 +7,7 @@
4428 #ifndef __ARCH_BLACKFIN_CACHE_H
4429 #define __ARCH_BLACKFIN_CACHE_H
4430
4431+#include <linux/const.h>
4432 #include <linux/linkage.h> /* for asmlinkage */
4433
4434 /*
4435@@ -14,7 +15,7 @@
4436 * Blackfin loads 32 bytes for cache
4437 */
4438 #define L1_CACHE_SHIFT 5
4439-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4440+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4441 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4442
4443 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4444diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4445index aea2718..3639a60 100644
4446--- a/arch/cris/include/arch-v10/arch/cache.h
4447+++ b/arch/cris/include/arch-v10/arch/cache.h
4448@@ -1,8 +1,9 @@
4449 #ifndef _ASM_ARCH_CACHE_H
4450 #define _ASM_ARCH_CACHE_H
4451
4452+#include <linux/const.h>
4453 /* Etrax 100LX have 32-byte cache-lines. */
4454-#define L1_CACHE_BYTES 32
4455 #define L1_CACHE_SHIFT 5
4456+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4457
4458 #endif /* _ASM_ARCH_CACHE_H */
4459diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4460index 7caf25d..ee65ac5 100644
4461--- a/arch/cris/include/arch-v32/arch/cache.h
4462+++ b/arch/cris/include/arch-v32/arch/cache.h
4463@@ -1,11 +1,12 @@
4464 #ifndef _ASM_CRIS_ARCH_CACHE_H
4465 #define _ASM_CRIS_ARCH_CACHE_H
4466
4467+#include <linux/const.h>
4468 #include <arch/hwregs/dma.h>
4469
4470 /* A cache-line is 32 bytes. */
4471-#define L1_CACHE_BYTES 32
4472 #define L1_CACHE_SHIFT 5
4473+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4474
4475 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4476
4477diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4478index b86329d..6709906 100644
4479--- a/arch/frv/include/asm/atomic.h
4480+++ b/arch/frv/include/asm/atomic.h
4481@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4482 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4483 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4484
4485+#define atomic64_read_unchecked(v) atomic64_read(v)
4486+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4487+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4488+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4489+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4490+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4491+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4492+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4493+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4494+
4495 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4496 {
4497 int c, old;
4498diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4499index 2797163..c2a401d 100644
4500--- a/arch/frv/include/asm/cache.h
4501+++ b/arch/frv/include/asm/cache.h
4502@@ -12,10 +12,11 @@
4503 #ifndef __ASM_CACHE_H
4504 #define __ASM_CACHE_H
4505
4506+#include <linux/const.h>
4507
4508 /* bytes per L1 cache line */
4509 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4510-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4511+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4512
4513 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4514 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4515diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4516index 43901f2..0d8b865 100644
4517--- a/arch/frv/include/asm/kmap_types.h
4518+++ b/arch/frv/include/asm/kmap_types.h
4519@@ -2,6 +2,6 @@
4520 #ifndef _ASM_KMAP_TYPES_H
4521 #define _ASM_KMAP_TYPES_H
4522
4523-#define KM_TYPE_NR 17
4524+#define KM_TYPE_NR 18
4525
4526 #endif
4527diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4528index 836f147..4cf23f5 100644
4529--- a/arch/frv/mm/elf-fdpic.c
4530+++ b/arch/frv/mm/elf-fdpic.c
4531@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4532 {
4533 struct vm_area_struct *vma;
4534 struct vm_unmapped_area_info info;
4535+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4536
4537 if (len > TASK_SIZE)
4538 return -ENOMEM;
4539@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4540 if (addr) {
4541 addr = PAGE_ALIGN(addr);
4542 vma = find_vma(current->mm, addr);
4543- if (TASK_SIZE - len >= addr &&
4544- (!vma || addr + len <= vma->vm_start))
4545+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4546 goto success;
4547 }
4548
4549@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4550 info.high_limit = (current->mm->start_stack - 0x00200000);
4551 info.align_mask = 0;
4552 info.align_offset = 0;
4553+ info.threadstack_offset = offset;
4554 addr = vm_unmapped_area(&info);
4555 if (!(addr & ~PAGE_MASK))
4556 goto success;
4557diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4558index f4ca594..adc72fd6 100644
4559--- a/arch/hexagon/include/asm/cache.h
4560+++ b/arch/hexagon/include/asm/cache.h
4561@@ -21,9 +21,11 @@
4562 #ifndef __ASM_CACHE_H
4563 #define __ASM_CACHE_H
4564
4565+#include <linux/const.h>
4566+
4567 /* Bytes per L1 cache line */
4568-#define L1_CACHE_SHIFT (5)
4569-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4570+#define L1_CACHE_SHIFT 5
4571+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4572
4573 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4574 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4575diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4576index 6e6fe18..a6ae668 100644
4577--- a/arch/ia64/include/asm/atomic.h
4578+++ b/arch/ia64/include/asm/atomic.h
4579@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4580 #define atomic64_inc(v) atomic64_add(1, (v))
4581 #define atomic64_dec(v) atomic64_sub(1, (v))
4582
4583+#define atomic64_read_unchecked(v) atomic64_read(v)
4584+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4585+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4586+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4587+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4588+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4589+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4590+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4591+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4592+
4593 /* Atomic operations are already serializing */
4594 #define smp_mb__before_atomic_dec() barrier()
4595 #define smp_mb__after_atomic_dec() barrier()
4596diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4597index 988254a..e1ee885 100644
4598--- a/arch/ia64/include/asm/cache.h
4599+++ b/arch/ia64/include/asm/cache.h
4600@@ -1,6 +1,7 @@
4601 #ifndef _ASM_IA64_CACHE_H
4602 #define _ASM_IA64_CACHE_H
4603
4604+#include <linux/const.h>
4605
4606 /*
4607 * Copyright (C) 1998-2000 Hewlett-Packard Co
4608@@ -9,7 +10,7 @@
4609
4610 /* Bytes per L1 (data) cache line. */
4611 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4612-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4613+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4614
4615 #ifdef CONFIG_SMP
4616 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4617diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4618index 5a83c5c..4d7f553 100644
4619--- a/arch/ia64/include/asm/elf.h
4620+++ b/arch/ia64/include/asm/elf.h
4621@@ -42,6 +42,13 @@
4622 */
4623 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4624
4625+#ifdef CONFIG_PAX_ASLR
4626+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4627+
4628+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4629+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4630+#endif
4631+
4632 #define PT_IA_64_UNWIND 0x70000001
4633
4634 /* IA-64 relocations: */
4635diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4636index 96a8d92..617a1cf 100644
4637--- a/arch/ia64/include/asm/pgalloc.h
4638+++ b/arch/ia64/include/asm/pgalloc.h
4639@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4640 pgd_val(*pgd_entry) = __pa(pud);
4641 }
4642
4643+static inline void
4644+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4645+{
4646+ pgd_populate(mm, pgd_entry, pud);
4647+}
4648+
4649 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4650 {
4651 return quicklist_alloc(0, GFP_KERNEL, NULL);
4652@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4653 pud_val(*pud_entry) = __pa(pmd);
4654 }
4655
4656+static inline void
4657+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4658+{
4659+ pud_populate(mm, pud_entry, pmd);
4660+}
4661+
4662 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4663 {
4664 return quicklist_alloc(0, GFP_KERNEL, NULL);
4665diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4666index 815810c..d60bd4c 100644
4667--- a/arch/ia64/include/asm/pgtable.h
4668+++ b/arch/ia64/include/asm/pgtable.h
4669@@ -12,7 +12,7 @@
4670 * David Mosberger-Tang <davidm@hpl.hp.com>
4671 */
4672
4673-
4674+#include <linux/const.h>
4675 #include <asm/mman.h>
4676 #include <asm/page.h>
4677 #include <asm/processor.h>
4678@@ -142,6 +142,17 @@
4679 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4680 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4681 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4682+
4683+#ifdef CONFIG_PAX_PAGEEXEC
4684+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4685+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4686+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4687+#else
4688+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4689+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4690+# define PAGE_COPY_NOEXEC PAGE_COPY
4691+#endif
4692+
4693 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4694 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4695 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4696diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4697index 54ff557..70c88b7 100644
4698--- a/arch/ia64/include/asm/spinlock.h
4699+++ b/arch/ia64/include/asm/spinlock.h
4700@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4701 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4702
4703 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4704- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4705+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4706 }
4707
4708 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4709diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4710index 449c8c0..18965fb 100644
4711--- a/arch/ia64/include/asm/uaccess.h
4712+++ b/arch/ia64/include/asm/uaccess.h
4713@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4714 static inline unsigned long
4715 __copy_to_user (void __user *to, const void *from, unsigned long count)
4716 {
4717+ if (count > INT_MAX)
4718+ return count;
4719+
4720+ if (!__builtin_constant_p(count))
4721+ check_object_size(from, count, true);
4722+
4723 return __copy_user(to, (__force void __user *) from, count);
4724 }
4725
4726 static inline unsigned long
4727 __copy_from_user (void *to, const void __user *from, unsigned long count)
4728 {
4729+ if (count > INT_MAX)
4730+ return count;
4731+
4732+ if (!__builtin_constant_p(count))
4733+ check_object_size(to, count, false);
4734+
4735 return __copy_user((__force void __user *) to, from, count);
4736 }
4737
4738@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4739 ({ \
4740 void __user *__cu_to = (to); \
4741 const void *__cu_from = (from); \
4742- long __cu_len = (n); \
4743+ unsigned long __cu_len = (n); \
4744 \
4745- if (__access_ok(__cu_to, __cu_len, get_fs())) \
4746+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4747+ if (!__builtin_constant_p(n)) \
4748+ check_object_size(__cu_from, __cu_len, true); \
4749 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4750+ } \
4751 __cu_len; \
4752 })
4753
4754@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4755 ({ \
4756 void *__cu_to = (to); \
4757 const void __user *__cu_from = (from); \
4758- long __cu_len = (n); \
4759+ unsigned long __cu_len = (n); \
4760 \
4761 __chk_user_ptr(__cu_from); \
4762- if (__access_ok(__cu_from, __cu_len, get_fs())) \
4763+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4764+ if (!__builtin_constant_p(n)) \
4765+ check_object_size(__cu_to, __cu_len, false); \
4766 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
4767+ } \
4768 __cu_len; \
4769 })
4770
4771diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
4772index 2d67317..07d8bfa 100644
4773--- a/arch/ia64/kernel/err_inject.c
4774+++ b/arch/ia64/kernel/err_inject.c
4775@@ -256,7 +256,7 @@ static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
4776 return NOTIFY_OK;
4777 }
4778
4779-static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
4780+static struct notifier_block err_inject_cpu_notifier =
4781 {
4782 .notifier_call = err_inject_cpu_callback,
4783 };
4784diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
4785index d7396db..b33e873 100644
4786--- a/arch/ia64/kernel/mca.c
4787+++ b/arch/ia64/kernel/mca.c
4788@@ -1922,7 +1922,7 @@ static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
4789 return NOTIFY_OK;
4790 }
4791
4792-static struct notifier_block mca_cpu_notifier __cpuinitdata = {
4793+static struct notifier_block mca_cpu_notifier = {
4794 .notifier_call = mca_cpu_callback
4795 };
4796
4797diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
4798index 24603be..948052d 100644
4799--- a/arch/ia64/kernel/module.c
4800+++ b/arch/ia64/kernel/module.c
4801@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
4802 void
4803 module_free (struct module *mod, void *module_region)
4804 {
4805- if (mod && mod->arch.init_unw_table &&
4806- module_region == mod->module_init) {
4807+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
4808 unw_remove_unwind_table(mod->arch.init_unw_table);
4809 mod->arch.init_unw_table = NULL;
4810 }
4811@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
4812 }
4813
4814 static inline int
4815+in_init_rx (const struct module *mod, uint64_t addr)
4816+{
4817+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
4818+}
4819+
4820+static inline int
4821+in_init_rw (const struct module *mod, uint64_t addr)
4822+{
4823+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
4824+}
4825+
4826+static inline int
4827 in_init (const struct module *mod, uint64_t addr)
4828 {
4829- return addr - (uint64_t) mod->module_init < mod->init_size;
4830+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
4831+}
4832+
4833+static inline int
4834+in_core_rx (const struct module *mod, uint64_t addr)
4835+{
4836+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
4837+}
4838+
4839+static inline int
4840+in_core_rw (const struct module *mod, uint64_t addr)
4841+{
4842+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
4843 }
4844
4845 static inline int
4846 in_core (const struct module *mod, uint64_t addr)
4847 {
4848- return addr - (uint64_t) mod->module_core < mod->core_size;
4849+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
4850 }
4851
4852 static inline int
4853@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
4854 break;
4855
4856 case RV_BDREL:
4857- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
4858+ if (in_init_rx(mod, val))
4859+ val -= (uint64_t) mod->module_init_rx;
4860+ else if (in_init_rw(mod, val))
4861+ val -= (uint64_t) mod->module_init_rw;
4862+ else if (in_core_rx(mod, val))
4863+ val -= (uint64_t) mod->module_core_rx;
4864+ else if (in_core_rw(mod, val))
4865+ val -= (uint64_t) mod->module_core_rw;
4866 break;
4867
4868 case RV_LTV:
4869@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
4870 * addresses have been selected...
4871 */
4872 uint64_t gp;
4873- if (mod->core_size > MAX_LTOFF)
4874+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
4875 /*
4876 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
4877 * at the end of the module.
4878 */
4879- gp = mod->core_size - MAX_LTOFF / 2;
4880+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
4881 else
4882- gp = mod->core_size / 2;
4883- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
4884+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
4885+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
4886 mod->arch.gp = gp;
4887 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
4888 }
4889diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
4890index 79521d5..43dddff 100644
4891--- a/arch/ia64/kernel/palinfo.c
4892+++ b/arch/ia64/kernel/palinfo.c
4893@@ -1006,7 +1006,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
4894 return NOTIFY_OK;
4895 }
4896
4897-static struct notifier_block __refdata palinfo_cpu_notifier =
4898+static struct notifier_block palinfo_cpu_notifier =
4899 {
4900 .notifier_call = palinfo_cpu_callback,
4901 .priority = 0,
4902diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
4903index aa527d7..f237752 100644
4904--- a/arch/ia64/kernel/salinfo.c
4905+++ b/arch/ia64/kernel/salinfo.c
4906@@ -616,7 +616,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
4907 return NOTIFY_OK;
4908 }
4909
4910-static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
4911+static struct notifier_block salinfo_cpu_notifier =
4912 {
4913 .notifier_call = salinfo_cpu_callback,
4914 .priority = 0,
4915diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
4916index 41e33f8..65180b2 100644
4917--- a/arch/ia64/kernel/sys_ia64.c
4918+++ b/arch/ia64/kernel/sys_ia64.c
4919@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4920 unsigned long align_mask = 0;
4921 struct mm_struct *mm = current->mm;
4922 struct vm_unmapped_area_info info;
4923+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4924
4925 if (len > RGN_MAP_LIMIT)
4926 return -ENOMEM;
4927@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4928 if (REGION_NUMBER(addr) == RGN_HPAGE)
4929 addr = 0;
4930 #endif
4931+
4932+#ifdef CONFIG_PAX_RANDMMAP
4933+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4934+ addr = mm->free_area_cache;
4935+ else
4936+#endif
4937+
4938 if (!addr)
4939 addr = TASK_UNMAPPED_BASE;
4940
4941@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4942 info.high_limit = TASK_SIZE;
4943 info.align_mask = align_mask;
4944 info.align_offset = 0;
4945+ info.threadstack_offset = offset;
4946 return vm_unmapped_area(&info);
4947 }
4948
4949diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
4950index dc00b2c..cce53c2 100644
4951--- a/arch/ia64/kernel/topology.c
4952+++ b/arch/ia64/kernel/topology.c
4953@@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
4954 return NOTIFY_OK;
4955 }
4956
4957-static struct notifier_block __cpuinitdata cache_cpu_notifier =
4958+static struct notifier_block cache_cpu_notifier =
4959 {
4960 .notifier_call = cache_cpu_callback
4961 };
4962diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
4963index 0ccb28f..8992469 100644
4964--- a/arch/ia64/kernel/vmlinux.lds.S
4965+++ b/arch/ia64/kernel/vmlinux.lds.S
4966@@ -198,7 +198,7 @@ SECTIONS {
4967 /* Per-cpu data: */
4968 . = ALIGN(PERCPU_PAGE_SIZE);
4969 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
4970- __phys_per_cpu_start = __per_cpu_load;
4971+ __phys_per_cpu_start = per_cpu_load;
4972 /*
4973 * ensure percpu data fits
4974 * into percpu page size
4975diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
4976index 6cf0341..d352594 100644
4977--- a/arch/ia64/mm/fault.c
4978+++ b/arch/ia64/mm/fault.c
4979@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
4980 return pte_present(pte);
4981 }
4982
4983+#ifdef CONFIG_PAX_PAGEEXEC
4984+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4985+{
4986+ unsigned long i;
4987+
4988+ printk(KERN_ERR "PAX: bytes at PC: ");
4989+ for (i = 0; i < 8; i++) {
4990+ unsigned int c;
4991+ if (get_user(c, (unsigned int *)pc+i))
4992+ printk(KERN_CONT "???????? ");
4993+ else
4994+ printk(KERN_CONT "%08x ", c);
4995+ }
4996+ printk("\n");
4997+}
4998+#endif
4999+
5000 # define VM_READ_BIT 0
5001 # define VM_WRITE_BIT 1
5002 # define VM_EXEC_BIT 2
5003@@ -149,8 +166,21 @@ retry:
5004 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5005 goto bad_area;
5006
5007- if ((vma->vm_flags & mask) != mask)
5008+ if ((vma->vm_flags & mask) != mask) {
5009+
5010+#ifdef CONFIG_PAX_PAGEEXEC
5011+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5012+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5013+ goto bad_area;
5014+
5015+ up_read(&mm->mmap_sem);
5016+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5017+ do_group_exit(SIGKILL);
5018+ }
5019+#endif
5020+
5021 goto bad_area;
5022+ }
5023
5024 /*
5025 * If for any reason at all we couldn't handle the fault, make
5026diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5027index 76069c1..c2aa816 100644
5028--- a/arch/ia64/mm/hugetlbpage.c
5029+++ b/arch/ia64/mm/hugetlbpage.c
5030@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5031 unsigned long pgoff, unsigned long flags)
5032 {
5033 struct vm_unmapped_area_info info;
5034+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5035
5036 if (len > RGN_MAP_LIMIT)
5037 return -ENOMEM;
5038@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5039 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5040 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5041 info.align_offset = 0;
5042+ info.threadstack_offset = offset;
5043 return vm_unmapped_area(&info);
5044 }
5045
5046diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5047index 20bc967..a26993e 100644
5048--- a/arch/ia64/mm/init.c
5049+++ b/arch/ia64/mm/init.c
5050@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5051 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5052 vma->vm_end = vma->vm_start + PAGE_SIZE;
5053 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5054+
5055+#ifdef CONFIG_PAX_PAGEEXEC
5056+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5057+ vma->vm_flags &= ~VM_EXEC;
5058+
5059+#ifdef CONFIG_PAX_MPROTECT
5060+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5061+ vma->vm_flags &= ~VM_MAYEXEC;
5062+#endif
5063+
5064+ }
5065+#endif
5066+
5067 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5068 down_write(&current->mm->mmap_sem);
5069 if (insert_vm_struct(current->mm, vma)) {
5070diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5071index 40b3ee9..8c2c112 100644
5072--- a/arch/m32r/include/asm/cache.h
5073+++ b/arch/m32r/include/asm/cache.h
5074@@ -1,8 +1,10 @@
5075 #ifndef _ASM_M32R_CACHE_H
5076 #define _ASM_M32R_CACHE_H
5077
5078+#include <linux/const.h>
5079+
5080 /* L1 cache line size */
5081 #define L1_CACHE_SHIFT 4
5082-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5083+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5084
5085 #endif /* _ASM_M32R_CACHE_H */
5086diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5087index 82abd15..d95ae5d 100644
5088--- a/arch/m32r/lib/usercopy.c
5089+++ b/arch/m32r/lib/usercopy.c
5090@@ -14,6 +14,9 @@
5091 unsigned long
5092 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5093 {
5094+ if ((long)n < 0)
5095+ return n;
5096+
5097 prefetch(from);
5098 if (access_ok(VERIFY_WRITE, to, n))
5099 __copy_user(to,from,n);
5100@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5101 unsigned long
5102 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5103 {
5104+ if ((long)n < 0)
5105+ return n;
5106+
5107 prefetchw(to);
5108 if (access_ok(VERIFY_READ, from, n))
5109 __copy_user_zeroing(to,from,n);
5110diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5111index 0395c51..5f26031 100644
5112--- a/arch/m68k/include/asm/cache.h
5113+++ b/arch/m68k/include/asm/cache.h
5114@@ -4,9 +4,11 @@
5115 #ifndef __ARCH_M68K_CACHE_H
5116 #define __ARCH_M68K_CACHE_H
5117
5118+#include <linux/const.h>
5119+
5120 /* bytes per L1 cache line */
5121 #define L1_CACHE_SHIFT 4
5122-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5123+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5124
5125 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5126
5127diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5128index 3c52fa6..11b2ad8 100644
5129--- a/arch/metag/mm/hugetlbpage.c
5130+++ b/arch/metag/mm/hugetlbpage.c
5131@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5132 info.high_limit = TASK_SIZE;
5133 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5134 info.align_offset = 0;
5135+ info.threadstack_offset = 0;
5136 return vm_unmapped_area(&info);
5137 }
5138
5139diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5140index 4efe96a..60e8699 100644
5141--- a/arch/microblaze/include/asm/cache.h
5142+++ b/arch/microblaze/include/asm/cache.h
5143@@ -13,11 +13,12 @@
5144 #ifndef _ASM_MICROBLAZE_CACHE_H
5145 #define _ASM_MICROBLAZE_CACHE_H
5146
5147+#include <linux/const.h>
5148 #include <asm/registers.h>
5149
5150 #define L1_CACHE_SHIFT 5
5151 /* word-granular cache in microblaze */
5152-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5153+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5154
5155 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5156
5157diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5158index 08b6079..eb272cf 100644
5159--- a/arch/mips/include/asm/atomic.h
5160+++ b/arch/mips/include/asm/atomic.h
5161@@ -21,6 +21,10 @@
5162 #include <asm/cmpxchg.h>
5163 #include <asm/war.h>
5164
5165+#ifdef CONFIG_GENERIC_ATOMIC64
5166+#include <asm-generic/atomic64.h>
5167+#endif
5168+
5169 #define ATOMIC_INIT(i) { (i) }
5170
5171 /*
5172@@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5173 */
5174 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
5175
5176+#define atomic64_read_unchecked(v) atomic64_read(v)
5177+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5178+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5179+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5180+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5181+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5182+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5183+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5184+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5185+
5186 #endif /* CONFIG_64BIT */
5187
5188 /*
5189diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
5190index b4db69f..8f3b093 100644
5191--- a/arch/mips/include/asm/cache.h
5192+++ b/arch/mips/include/asm/cache.h
5193@@ -9,10 +9,11 @@
5194 #ifndef _ASM_CACHE_H
5195 #define _ASM_CACHE_H
5196
5197+#include <linux/const.h>
5198 #include <kmalloc.h>
5199
5200 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
5201-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5202+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5203
5204 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5205 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5206diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
5207index cf3ae24..238d22f 100644
5208--- a/arch/mips/include/asm/elf.h
5209+++ b/arch/mips/include/asm/elf.h
5210@@ -372,13 +372,16 @@ extern const char *__elf_platform;
5211 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
5212 #endif
5213
5214+#ifdef CONFIG_PAX_ASLR
5215+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5216+
5217+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5218+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5219+#endif
5220+
5221 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5222 struct linux_binprm;
5223 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5224 int uses_interp);
5225
5226-struct mm_struct;
5227-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5228-#define arch_randomize_brk arch_randomize_brk
5229-
5230 #endif /* _ASM_ELF_H */
5231diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
5232index c1f6afa..38cc6e9 100644
5233--- a/arch/mips/include/asm/exec.h
5234+++ b/arch/mips/include/asm/exec.h
5235@@ -12,6 +12,6 @@
5236 #ifndef _ASM_EXEC_H
5237 #define _ASM_EXEC_H
5238
5239-extern unsigned long arch_align_stack(unsigned long sp);
5240+#define arch_align_stack(x) ((x) & ~0xfUL)
5241
5242 #endif /* _ASM_EXEC_H */
5243diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
5244index eab99e5..607c98e 100644
5245--- a/arch/mips/include/asm/page.h
5246+++ b/arch/mips/include/asm/page.h
5247@@ -96,7 +96,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
5248 #ifdef CONFIG_CPU_MIPS32
5249 typedef struct { unsigned long pte_low, pte_high; } pte_t;
5250 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
5251- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
5252+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
5253 #else
5254 typedef struct { unsigned long long pte; } pte_t;
5255 #define pte_val(x) ((x).pte)
5256diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
5257index 881d18b..cea38bc 100644
5258--- a/arch/mips/include/asm/pgalloc.h
5259+++ b/arch/mips/include/asm/pgalloc.h
5260@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5261 {
5262 set_pud(pud, __pud((unsigned long)pmd));
5263 }
5264+
5265+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5266+{
5267+ pud_populate(mm, pud, pmd);
5268+}
5269 #endif
5270
5271 /*
5272diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
5273index 178f792..8ebc510 100644
5274--- a/arch/mips/include/asm/thread_info.h
5275+++ b/arch/mips/include/asm/thread_info.h
5276@@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
5277 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
5278 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
5279 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
5280+/* li takes a 32bit immediate */
5281+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
5282 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
5283
5284 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5285@@ -126,15 +128,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
5286 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
5287 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
5288 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
5289+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5290+
5291+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5292
5293 /* work to do in syscall_trace_leave() */
5294-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
5295+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5296
5297 /* work to do on interrupt/exception return */
5298 #define _TIF_WORK_MASK \
5299 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
5300 /* work to do on any return to u-space */
5301-#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
5302+#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
5303
5304 #endif /* __KERNEL__ */
5305
5306diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
5307index e06f777..3244284 100644
5308--- a/arch/mips/kernel/binfmt_elfn32.c
5309+++ b/arch/mips/kernel/binfmt_elfn32.c
5310@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5311 #undef ELF_ET_DYN_BASE
5312 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5313
5314+#ifdef CONFIG_PAX_ASLR
5315+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5316+
5317+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5318+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5319+#endif
5320+
5321 #include <asm/processor.h>
5322 #include <linux/module.h>
5323 #include <linux/elfcore.h>
5324diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
5325index 556a435..b4fd2e3 100644
5326--- a/arch/mips/kernel/binfmt_elfo32.c
5327+++ b/arch/mips/kernel/binfmt_elfo32.c
5328@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5329 #undef ELF_ET_DYN_BASE
5330 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5331
5332+#ifdef CONFIG_PAX_ASLR
5333+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5334+
5335+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5336+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5337+#endif
5338+
5339 #include <asm/processor.h>
5340
5341 /*
5342diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
5343index 3be4405..a799827 100644
5344--- a/arch/mips/kernel/process.c
5345+++ b/arch/mips/kernel/process.c
5346@@ -461,15 +461,3 @@ unsigned long get_wchan(struct task_struct *task)
5347 out:
5348 return pc;
5349 }
5350-
5351-/*
5352- * Don't forget that the stack pointer must be aligned on a 8 bytes
5353- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
5354- */
5355-unsigned long arch_align_stack(unsigned long sp)
5356-{
5357- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5358- sp -= get_random_int() & ~PAGE_MASK;
5359-
5360- return sp & ALMASK;
5361-}
5362diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
5363index 9c6299c..2fb4c22 100644
5364--- a/arch/mips/kernel/ptrace.c
5365+++ b/arch/mips/kernel/ptrace.c
5366@@ -528,6 +528,10 @@ static inline int audit_arch(void)
5367 return arch;
5368 }
5369
5370+#ifdef CONFIG_GRKERNSEC_SETXID
5371+extern void gr_delayed_cred_worker(void);
5372+#endif
5373+
5374 /*
5375 * Notification of system call entry/exit
5376 * - triggered by current->work.syscall_trace
5377@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
5378 /* do the secure computing check first */
5379 secure_computing_strict(regs->regs[2]);
5380
5381+#ifdef CONFIG_GRKERNSEC_SETXID
5382+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5383+ gr_delayed_cred_worker();
5384+#endif
5385+
5386 if (!(current->ptrace & PT_PTRACED))
5387 goto out;
5388
5389diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
5390index 9ea2964..c4329c3 100644
5391--- a/arch/mips/kernel/scall32-o32.S
5392+++ b/arch/mips/kernel/scall32-o32.S
5393@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5394
5395 stack_done:
5396 lw t0, TI_FLAGS($28) # syscall tracing enabled?
5397- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5398+ li t1, _TIF_SYSCALL_WORK
5399 and t0, t1
5400 bnez t0, syscall_trace_entry # -> yes
5401
5402diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
5403index 36cfd40..b1436e0 100644
5404--- a/arch/mips/kernel/scall64-64.S
5405+++ b/arch/mips/kernel/scall64-64.S
5406@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
5407
5408 sd a3, PT_R26(sp) # save a3 for syscall restarting
5409
5410- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5411+ li t1, _TIF_SYSCALL_WORK
5412 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5413 and t0, t1, t0
5414 bnez t0, syscall_trace_entry
5415diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
5416index 693d60b..ae0ba75 100644
5417--- a/arch/mips/kernel/scall64-n32.S
5418+++ b/arch/mips/kernel/scall64-n32.S
5419@@ -47,7 +47,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
5420
5421 sd a3, PT_R26(sp) # save a3 for syscall restarting
5422
5423- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5424+ li t1, _TIF_SYSCALL_WORK
5425 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5426 and t0, t1, t0
5427 bnez t0, n32_syscall_trace_entry
5428diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
5429index af8887f..611ccb6 100644
5430--- a/arch/mips/kernel/scall64-o32.S
5431+++ b/arch/mips/kernel/scall64-o32.S
5432@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5433 PTR 4b, bad_stack
5434 .previous
5435
5436- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5437+ li t1, _TIF_SYSCALL_WORK
5438 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5439 and t0, t1, t0
5440 bnez t0, trace_a_syscall
5441diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
5442index 0fead53..a2c0fb5 100644
5443--- a/arch/mips/mm/fault.c
5444+++ b/arch/mips/mm/fault.c
5445@@ -27,6 +27,23 @@
5446 #include <asm/highmem.h> /* For VMALLOC_END */
5447 #include <linux/kdebug.h>
5448
5449+#ifdef CONFIG_PAX_PAGEEXEC
5450+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5451+{
5452+ unsigned long i;
5453+
5454+ printk(KERN_ERR "PAX: bytes at PC: ");
5455+ for (i = 0; i < 5; i++) {
5456+ unsigned int c;
5457+ if (get_user(c, (unsigned int *)pc+i))
5458+ printk(KERN_CONT "???????? ");
5459+ else
5460+ printk(KERN_CONT "%08x ", c);
5461+ }
5462+ printk("\n");
5463+}
5464+#endif
5465+
5466 /*
5467 * This routine handles page faults. It determines the address,
5468 * and the problem, and then passes it off to one of the appropriate
5469diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
5470index 7e5fe27..9656513 100644
5471--- a/arch/mips/mm/mmap.c
5472+++ b/arch/mips/mm/mmap.c
5473@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5474 struct vm_area_struct *vma;
5475 unsigned long addr = addr0;
5476 int do_color_align;
5477+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5478 struct vm_unmapped_area_info info;
5479
5480 if (unlikely(len > TASK_SIZE))
5481@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5482 do_color_align = 1;
5483
5484 /* requesting a specific address */
5485+
5486+#ifdef CONFIG_PAX_RANDMMAP
5487+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5488+#endif
5489+
5490 if (addr) {
5491 if (do_color_align)
5492 addr = COLOUR_ALIGN(addr, pgoff);
5493@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5494 addr = PAGE_ALIGN(addr);
5495
5496 vma = find_vma(mm, addr);
5497- if (TASK_SIZE - len >= addr &&
5498- (!vma || addr + len <= vma->vm_start))
5499+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
5500 return addr;
5501 }
5502
5503 info.length = len;
5504 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
5505 info.align_offset = pgoff << PAGE_SHIFT;
5506+ info.threadstack_offset = offset;
5507
5508 if (dir == DOWN) {
5509 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
5510@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5511 {
5512 unsigned long random_factor = 0UL;
5513
5514+#ifdef CONFIG_PAX_RANDMMAP
5515+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5516+#endif
5517+
5518 if (current->flags & PF_RANDOMIZE) {
5519 random_factor = get_random_int();
5520 random_factor = random_factor << PAGE_SHIFT;
5521@@ -157,42 +167,27 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5522
5523 if (mmap_is_legacy()) {
5524 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5525+
5526+#ifdef CONFIG_PAX_RANDMMAP
5527+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5528+ mm->mmap_base += mm->delta_mmap;
5529+#endif
5530+
5531 mm->get_unmapped_area = arch_get_unmapped_area;
5532 mm->unmap_area = arch_unmap_area;
5533 } else {
5534 mm->mmap_base = mmap_base(random_factor);
5535+
5536+#ifdef CONFIG_PAX_RANDMMAP
5537+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5538+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5539+#endif
5540+
5541 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5542 mm->unmap_area = arch_unmap_area_topdown;
5543 }
5544 }
5545
5546-static inline unsigned long brk_rnd(void)
5547-{
5548- unsigned long rnd = get_random_int();
5549-
5550- rnd = rnd << PAGE_SHIFT;
5551- /* 8MB for 32bit, 256MB for 64bit */
5552- if (TASK_IS_32BIT_ADDR)
5553- rnd = rnd & 0x7ffffful;
5554- else
5555- rnd = rnd & 0xffffffful;
5556-
5557- return rnd;
5558-}
5559-
5560-unsigned long arch_randomize_brk(struct mm_struct *mm)
5561-{
5562- unsigned long base = mm->brk;
5563- unsigned long ret;
5564-
5565- ret = PAGE_ALIGN(base + brk_rnd());
5566-
5567- if (ret < mm->brk)
5568- return mm->brk;
5569-
5570- return ret;
5571-}
5572-
5573 int __virt_addr_valid(const volatile void *kaddr)
5574 {
5575 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
5576diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5577index 967d144..db12197 100644
5578--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
5579+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5580@@ -11,12 +11,14 @@
5581 #ifndef _ASM_PROC_CACHE_H
5582 #define _ASM_PROC_CACHE_H
5583
5584+#include <linux/const.h>
5585+
5586 /* L1 cache */
5587
5588 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5589 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
5590-#define L1_CACHE_BYTES 16 /* bytes per entry */
5591 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
5592+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5593 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
5594
5595 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5596diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5597index bcb5df2..84fabd2 100644
5598--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5599+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5600@@ -16,13 +16,15 @@
5601 #ifndef _ASM_PROC_CACHE_H
5602 #define _ASM_PROC_CACHE_H
5603
5604+#include <linux/const.h>
5605+
5606 /*
5607 * L1 cache
5608 */
5609 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5610 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
5611-#define L1_CACHE_BYTES 32 /* bytes per entry */
5612 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
5613+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5614 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
5615
5616 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5617diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
5618index 4ce7a01..449202a 100644
5619--- a/arch/openrisc/include/asm/cache.h
5620+++ b/arch/openrisc/include/asm/cache.h
5621@@ -19,11 +19,13 @@
5622 #ifndef __ASM_OPENRISC_CACHE_H
5623 #define __ASM_OPENRISC_CACHE_H
5624
5625+#include <linux/const.h>
5626+
5627 /* FIXME: How can we replace these with values from the CPU...
5628 * they shouldn't be hard-coded!
5629 */
5630
5631-#define L1_CACHE_BYTES 16
5632 #define L1_CACHE_SHIFT 4
5633+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5634
5635 #endif /* __ASM_OPENRISC_CACHE_H */
5636diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
5637index f38e198..4179e38 100644
5638--- a/arch/parisc/include/asm/atomic.h
5639+++ b/arch/parisc/include/asm/atomic.h
5640@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5641
5642 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5643
5644+#define atomic64_read_unchecked(v) atomic64_read(v)
5645+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5646+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5647+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5648+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5649+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5650+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5651+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5652+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5653+
5654 #endif /* !CONFIG_64BIT */
5655
5656
5657diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
5658index 47f11c7..3420df2 100644
5659--- a/arch/parisc/include/asm/cache.h
5660+++ b/arch/parisc/include/asm/cache.h
5661@@ -5,6 +5,7 @@
5662 #ifndef __ARCH_PARISC_CACHE_H
5663 #define __ARCH_PARISC_CACHE_H
5664
5665+#include <linux/const.h>
5666
5667 /*
5668 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
5669@@ -15,13 +16,13 @@
5670 * just ruin performance.
5671 */
5672 #ifdef CONFIG_PA20
5673-#define L1_CACHE_BYTES 64
5674 #define L1_CACHE_SHIFT 6
5675 #else
5676-#define L1_CACHE_BYTES 32
5677 #define L1_CACHE_SHIFT 5
5678 #endif
5679
5680+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5681+
5682 #ifndef __ASSEMBLY__
5683
5684 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5685diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
5686index ad2b503..bdf1651 100644
5687--- a/arch/parisc/include/asm/elf.h
5688+++ b/arch/parisc/include/asm/elf.h
5689@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
5690
5691 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
5692
5693+#ifdef CONFIG_PAX_ASLR
5694+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5695+
5696+#define PAX_DELTA_MMAP_LEN 16
5697+#define PAX_DELTA_STACK_LEN 16
5698+#endif
5699+
5700 /* This yields a mask that user programs can use to figure out what
5701 instruction set this CPU supports. This could be done in user space,
5702 but it's not easy, and we've already done it here. */
5703diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
5704index fc987a1..6e068ef 100644
5705--- a/arch/parisc/include/asm/pgalloc.h
5706+++ b/arch/parisc/include/asm/pgalloc.h
5707@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5708 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
5709 }
5710
5711+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5712+{
5713+ pgd_populate(mm, pgd, pmd);
5714+}
5715+
5716 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
5717 {
5718 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
5719@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
5720 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
5721 #define pmd_free(mm, x) do { } while (0)
5722 #define pgd_populate(mm, pmd, pte) BUG()
5723+#define pgd_populate_kernel(mm, pmd, pte) BUG()
5724
5725 #endif
5726
5727diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
5728index 1e40d7f..a3eb445 100644
5729--- a/arch/parisc/include/asm/pgtable.h
5730+++ b/arch/parisc/include/asm/pgtable.h
5731@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
5732 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
5733 #define PAGE_COPY PAGE_EXECREAD
5734 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
5735+
5736+#ifdef CONFIG_PAX_PAGEEXEC
5737+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
5738+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5739+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5740+#else
5741+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5742+# define PAGE_COPY_NOEXEC PAGE_COPY
5743+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5744+#endif
5745+
5746 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
5747 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
5748 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
5749diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
5750index e0a8235..ce2f1e1 100644
5751--- a/arch/parisc/include/asm/uaccess.h
5752+++ b/arch/parisc/include/asm/uaccess.h
5753@@ -245,10 +245,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
5754 const void __user *from,
5755 unsigned long n)
5756 {
5757- int sz = __compiletime_object_size(to);
5758+ size_t sz = __compiletime_object_size(to);
5759 int ret = -EFAULT;
5760
5761- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
5762+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
5763 ret = __copy_from_user(to, from, n);
5764 else
5765 copy_from_user_overflow();
5766diff --git a/arch/parisc/kernel/drivers.c b/arch/parisc/kernel/drivers.c
5767index 5709c5e..14285ca 100644
5768--- a/arch/parisc/kernel/drivers.c
5769+++ b/arch/parisc/kernel/drivers.c
5770@@ -394,7 +394,7 @@ EXPORT_SYMBOL(print_pci_hwpath);
5771 static void setup_bus_id(struct parisc_device *padev)
5772 {
5773 struct hardware_path path;
5774- char name[20];
5775+ char name[28];
5776 char *output = name;
5777 int i;
5778
5779diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
5780index 2a625fb..9908930 100644
5781--- a/arch/parisc/kernel/module.c
5782+++ b/arch/parisc/kernel/module.c
5783@@ -98,16 +98,38 @@
5784
5785 /* three functions to determine where in the module core
5786 * or init pieces the location is */
5787+static inline int in_init_rx(struct module *me, void *loc)
5788+{
5789+ return (loc >= me->module_init_rx &&
5790+ loc < (me->module_init_rx + me->init_size_rx));
5791+}
5792+
5793+static inline int in_init_rw(struct module *me, void *loc)
5794+{
5795+ return (loc >= me->module_init_rw &&
5796+ loc < (me->module_init_rw + me->init_size_rw));
5797+}
5798+
5799 static inline int in_init(struct module *me, void *loc)
5800 {
5801- return (loc >= me->module_init &&
5802- loc <= (me->module_init + me->init_size));
5803+ return in_init_rx(me, loc) || in_init_rw(me, loc);
5804+}
5805+
5806+static inline int in_core_rx(struct module *me, void *loc)
5807+{
5808+ return (loc >= me->module_core_rx &&
5809+ loc < (me->module_core_rx + me->core_size_rx));
5810+}
5811+
5812+static inline int in_core_rw(struct module *me, void *loc)
5813+{
5814+ return (loc >= me->module_core_rw &&
5815+ loc < (me->module_core_rw + me->core_size_rw));
5816 }
5817
5818 static inline int in_core(struct module *me, void *loc)
5819 {
5820- return (loc >= me->module_core &&
5821- loc <= (me->module_core + me->core_size));
5822+ return in_core_rx(me, loc) || in_core_rw(me, loc);
5823 }
5824
5825 static inline int in_local(struct module *me, void *loc)
5826@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
5827 }
5828
5829 /* align things a bit */
5830- me->core_size = ALIGN(me->core_size, 16);
5831- me->arch.got_offset = me->core_size;
5832- me->core_size += gots * sizeof(struct got_entry);
5833+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5834+ me->arch.got_offset = me->core_size_rw;
5835+ me->core_size_rw += gots * sizeof(struct got_entry);
5836
5837- me->core_size = ALIGN(me->core_size, 16);
5838- me->arch.fdesc_offset = me->core_size;
5839- me->core_size += fdescs * sizeof(Elf_Fdesc);
5840+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5841+ me->arch.fdesc_offset = me->core_size_rw;
5842+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
5843
5844 me->arch.got_max = gots;
5845 me->arch.fdesc_max = fdescs;
5846@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5847
5848 BUG_ON(value == 0);
5849
5850- got = me->module_core + me->arch.got_offset;
5851+ got = me->module_core_rw + me->arch.got_offset;
5852 for (i = 0; got[i].addr; i++)
5853 if (got[i].addr == value)
5854 goto out;
5855@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5856 #ifdef CONFIG_64BIT
5857 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5858 {
5859- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
5860+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
5861
5862 if (!value) {
5863 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
5864@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5865
5866 /* Create new one */
5867 fdesc->addr = value;
5868- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5869+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5870 return (Elf_Addr)fdesc;
5871 }
5872 #endif /* CONFIG_64BIT */
5873@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
5874
5875 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
5876 end = table + sechdrs[me->arch.unwind_section].sh_size;
5877- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5878+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5879
5880 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
5881 me->arch.unwind_section, table, end, gp);
5882diff --git a/arch/parisc/kernel/setup.c b/arch/parisc/kernel/setup.c
5883index a3328c2..3b812eb 100644
5884--- a/arch/parisc/kernel/setup.c
5885+++ b/arch/parisc/kernel/setup.c
5886@@ -69,7 +69,8 @@ void __init setup_cmdline(char **cmdline_p)
5887 /* called from hpux boot loader */
5888 boot_command_line[0] = '\0';
5889 } else {
5890- strcpy(boot_command_line, (char *)__va(boot_args[1]));
5891+ strlcpy(boot_command_line, (char *)__va(boot_args[1]),
5892+ COMMAND_LINE_SIZE);
5893
5894 #ifdef CONFIG_BLK_DEV_INITRD
5895 if (boot_args[2] != 0) /* did palo pass us a ramdisk? */
5896diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
5897index 5dfd248..64914ac 100644
5898--- a/arch/parisc/kernel/sys_parisc.c
5899+++ b/arch/parisc/kernel/sys_parisc.c
5900@@ -33,9 +33,11 @@
5901 #include <linux/utsname.h>
5902 #include <linux/personality.h>
5903
5904-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5905+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
5906+ unsigned long flags)
5907 {
5908 struct vm_unmapped_area_info info;
5909+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5910
5911 info.flags = 0;
5912 info.length = len;
5913@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5914 info.high_limit = TASK_SIZE;
5915 info.align_mask = 0;
5916 info.align_offset = 0;
5917+ info.threadstack_offset = offset;
5918 return vm_unmapped_area(&info);
5919 }
5920
5921@@ -61,10 +64,11 @@ static int get_offset(struct address_space *mapping)
5922 return (unsigned long) mapping >> 8;
5923 }
5924
5925-static unsigned long get_shared_area(struct address_space *mapping,
5926- unsigned long addr, unsigned long len, unsigned long pgoff)
5927+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
5928+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
5929 {
5930 struct vm_unmapped_area_info info;
5931+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5932
5933 info.flags = 0;
5934 info.length = len;
5935@@ -72,6 +76,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
5936 info.high_limit = TASK_SIZE;
5937 info.align_mask = PAGE_MASK & (SHMLBA - 1);
5938 info.align_offset = (get_offset(mapping) + pgoff) << PAGE_SHIFT;
5939+ info.threadstack_offset = offset;
5940 return vm_unmapped_area(&info);
5941 }
5942
5943@@ -86,15 +91,22 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5944 return -EINVAL;
5945 return addr;
5946 }
5947- if (!addr)
5948+ if (!addr) {
5949 addr = TASK_UNMAPPED_BASE;
5950
5951+#ifdef CONFIG_PAX_RANDMMAP
5952+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
5953+ addr += current->mm->delta_mmap;
5954+#endif
5955+
5956+ }
5957+
5958 if (filp) {
5959- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
5960+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
5961 } else if(flags & MAP_SHARED) {
5962- addr = get_shared_area(NULL, addr, len, pgoff);
5963+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
5964 } else {
5965- addr = get_unshared_area(addr, len);
5966+ addr = get_unshared_area(filp, addr, len, flags);
5967 }
5968 return addr;
5969 }
5970diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
5971index aeb8f8f..27a6c2f 100644
5972--- a/arch/parisc/kernel/traps.c
5973+++ b/arch/parisc/kernel/traps.c
5974@@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
5975
5976 down_read(&current->mm->mmap_sem);
5977 vma = find_vma(current->mm,regs->iaoq[0]);
5978- if (vma && (regs->iaoq[0] >= vma->vm_start)
5979- && (vma->vm_flags & VM_EXEC)) {
5980-
5981+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
5982 fault_address = regs->iaoq[0];
5983 fault_space = regs->iasq[0];
5984
5985diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
5986index f247a34..dc0f219 100644
5987--- a/arch/parisc/mm/fault.c
5988+++ b/arch/parisc/mm/fault.c
5989@@ -15,6 +15,7 @@
5990 #include <linux/sched.h>
5991 #include <linux/interrupt.h>
5992 #include <linux/module.h>
5993+#include <linux/unistd.h>
5994
5995 #include <asm/uaccess.h>
5996 #include <asm/traps.h>
5997@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
5998 static unsigned long
5999 parisc_acctyp(unsigned long code, unsigned int inst)
6000 {
6001- if (code == 6 || code == 16)
6002+ if (code == 6 || code == 7 || code == 16)
6003 return VM_EXEC;
6004
6005 switch (inst & 0xf0000000) {
6006@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
6007 }
6008 #endif
6009
6010+#ifdef CONFIG_PAX_PAGEEXEC
6011+/*
6012+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
6013+ *
6014+ * returns 1 when task should be killed
6015+ * 2 when rt_sigreturn trampoline was detected
6016+ * 3 when unpatched PLT trampoline was detected
6017+ */
6018+static int pax_handle_fetch_fault(struct pt_regs *regs)
6019+{
6020+
6021+#ifdef CONFIG_PAX_EMUPLT
6022+ int err;
6023+
6024+ do { /* PaX: unpatched PLT emulation */
6025+ unsigned int bl, depwi;
6026+
6027+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
6028+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
6029+
6030+ if (err)
6031+ break;
6032+
6033+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
6034+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
6035+
6036+ err = get_user(ldw, (unsigned int *)addr);
6037+ err |= get_user(bv, (unsigned int *)(addr+4));
6038+ err |= get_user(ldw2, (unsigned int *)(addr+8));
6039+
6040+ if (err)
6041+ break;
6042+
6043+ if (ldw == 0x0E801096U &&
6044+ bv == 0xEAC0C000U &&
6045+ ldw2 == 0x0E881095U)
6046+ {
6047+ unsigned int resolver, map;
6048+
6049+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
6050+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
6051+ if (err)
6052+ break;
6053+
6054+ regs->gr[20] = instruction_pointer(regs)+8;
6055+ regs->gr[21] = map;
6056+ regs->gr[22] = resolver;
6057+ regs->iaoq[0] = resolver | 3UL;
6058+ regs->iaoq[1] = regs->iaoq[0] + 4;
6059+ return 3;
6060+ }
6061+ }
6062+ } while (0);
6063+#endif
6064+
6065+#ifdef CONFIG_PAX_EMUTRAMP
6066+
6067+#ifndef CONFIG_PAX_EMUSIGRT
6068+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
6069+ return 1;
6070+#endif
6071+
6072+ do { /* PaX: rt_sigreturn emulation */
6073+ unsigned int ldi1, ldi2, bel, nop;
6074+
6075+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
6076+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
6077+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
6078+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
6079+
6080+ if (err)
6081+ break;
6082+
6083+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
6084+ ldi2 == 0x3414015AU &&
6085+ bel == 0xE4008200U &&
6086+ nop == 0x08000240U)
6087+ {
6088+ regs->gr[25] = (ldi1 & 2) >> 1;
6089+ regs->gr[20] = __NR_rt_sigreturn;
6090+ regs->gr[31] = regs->iaoq[1] + 16;
6091+ regs->sr[0] = regs->iasq[1];
6092+ regs->iaoq[0] = 0x100UL;
6093+ regs->iaoq[1] = regs->iaoq[0] + 4;
6094+ regs->iasq[0] = regs->sr[2];
6095+ regs->iasq[1] = regs->sr[2];
6096+ return 2;
6097+ }
6098+ } while (0);
6099+#endif
6100+
6101+ return 1;
6102+}
6103+
6104+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6105+{
6106+ unsigned long i;
6107+
6108+ printk(KERN_ERR "PAX: bytes at PC: ");
6109+ for (i = 0; i < 5; i++) {
6110+ unsigned int c;
6111+ if (get_user(c, (unsigned int *)pc+i))
6112+ printk(KERN_CONT "???????? ");
6113+ else
6114+ printk(KERN_CONT "%08x ", c);
6115+ }
6116+ printk("\n");
6117+}
6118+#endif
6119+
6120 int fixup_exception(struct pt_regs *regs)
6121 {
6122 const struct exception_table_entry *fix;
6123@@ -194,8 +305,33 @@ good_area:
6124
6125 acc_type = parisc_acctyp(code,regs->iir);
6126
6127- if ((vma->vm_flags & acc_type) != acc_type)
6128+ if ((vma->vm_flags & acc_type) != acc_type) {
6129+
6130+#ifdef CONFIG_PAX_PAGEEXEC
6131+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
6132+ (address & ~3UL) == instruction_pointer(regs))
6133+ {
6134+ up_read(&mm->mmap_sem);
6135+ switch (pax_handle_fetch_fault(regs)) {
6136+
6137+#ifdef CONFIG_PAX_EMUPLT
6138+ case 3:
6139+ return;
6140+#endif
6141+
6142+#ifdef CONFIG_PAX_EMUTRAMP
6143+ case 2:
6144+ return;
6145+#endif
6146+
6147+ }
6148+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
6149+ do_group_exit(SIGKILL);
6150+ }
6151+#endif
6152+
6153 goto bad_area;
6154+ }
6155
6156 /*
6157 * If for any reason at all we couldn't handle the fault, make
6158diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
6159index e3b1d41..8e81edf 100644
6160--- a/arch/powerpc/include/asm/atomic.h
6161+++ b/arch/powerpc/include/asm/atomic.h
6162@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
6163 return t1;
6164 }
6165
6166+#define atomic64_read_unchecked(v) atomic64_read(v)
6167+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6168+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6169+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6170+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6171+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6172+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6173+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6174+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6175+
6176 #endif /* __powerpc64__ */
6177
6178 #endif /* __KERNEL__ */
6179diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
6180index 9e495c9..b6878e5 100644
6181--- a/arch/powerpc/include/asm/cache.h
6182+++ b/arch/powerpc/include/asm/cache.h
6183@@ -3,6 +3,7 @@
6184
6185 #ifdef __KERNEL__
6186
6187+#include <linux/const.h>
6188
6189 /* bytes per L1 cache line */
6190 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
6191@@ -22,7 +23,7 @@
6192 #define L1_CACHE_SHIFT 7
6193 #endif
6194
6195-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6196+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6197
6198 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6199
6200diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
6201index ac9790f..6d30741 100644
6202--- a/arch/powerpc/include/asm/elf.h
6203+++ b/arch/powerpc/include/asm/elf.h
6204@@ -28,8 +28,19 @@
6205 the loader. We need to make sure that it is out of the way of the program
6206 that it will "exec", and that there is sufficient room for the brk. */
6207
6208-extern unsigned long randomize_et_dyn(unsigned long base);
6209-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
6210+#define ELF_ET_DYN_BASE (0x20000000)
6211+
6212+#ifdef CONFIG_PAX_ASLR
6213+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
6214+
6215+#ifdef __powerpc64__
6216+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
6217+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
6218+#else
6219+#define PAX_DELTA_MMAP_LEN 15
6220+#define PAX_DELTA_STACK_LEN 15
6221+#endif
6222+#endif
6223
6224 /*
6225 * Our registers are always unsigned longs, whether we're a 32 bit
6226@@ -122,10 +133,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6227 (0x7ff >> (PAGE_SHIFT - 12)) : \
6228 (0x3ffff >> (PAGE_SHIFT - 12)))
6229
6230-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6231-#define arch_randomize_brk arch_randomize_brk
6232-
6233-
6234 #ifdef CONFIG_SPU_BASE
6235 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
6236 #define NT_SPU 1
6237diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
6238index 8196e9c..d83a9f3 100644
6239--- a/arch/powerpc/include/asm/exec.h
6240+++ b/arch/powerpc/include/asm/exec.h
6241@@ -4,6 +4,6 @@
6242 #ifndef _ASM_POWERPC_EXEC_H
6243 #define _ASM_POWERPC_EXEC_H
6244
6245-extern unsigned long arch_align_stack(unsigned long sp);
6246+#define arch_align_stack(x) ((x) & ~0xfUL)
6247
6248 #endif /* _ASM_POWERPC_EXEC_H */
6249diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
6250index 5acabbd..7ea14fa 100644
6251--- a/arch/powerpc/include/asm/kmap_types.h
6252+++ b/arch/powerpc/include/asm/kmap_types.h
6253@@ -10,7 +10,7 @@
6254 * 2 of the License, or (at your option) any later version.
6255 */
6256
6257-#define KM_TYPE_NR 16
6258+#define KM_TYPE_NR 17
6259
6260 #endif /* __KERNEL__ */
6261 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
6262diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
6263index 8565c25..2865190 100644
6264--- a/arch/powerpc/include/asm/mman.h
6265+++ b/arch/powerpc/include/asm/mman.h
6266@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
6267 }
6268 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
6269
6270-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
6271+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
6272 {
6273 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
6274 }
6275diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
6276index f072e97..b436dee 100644
6277--- a/arch/powerpc/include/asm/page.h
6278+++ b/arch/powerpc/include/asm/page.h
6279@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
6280 * and needs to be executable. This means the whole heap ends
6281 * up being executable.
6282 */
6283-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6284- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6285+#define VM_DATA_DEFAULT_FLAGS32 \
6286+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6287+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6288
6289 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6290 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6291@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
6292 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
6293 #endif
6294
6295+#define ktla_ktva(addr) (addr)
6296+#define ktva_ktla(addr) (addr)
6297+
6298 /*
6299 * Use the top bit of the higher-level page table entries to indicate whether
6300 * the entries we point to contain hugepages. This works because we know that
6301diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
6302index cd915d6..c10cee8 100644
6303--- a/arch/powerpc/include/asm/page_64.h
6304+++ b/arch/powerpc/include/asm/page_64.h
6305@@ -154,15 +154,18 @@ do { \
6306 * stack by default, so in the absence of a PT_GNU_STACK program header
6307 * we turn execute permission off.
6308 */
6309-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6310- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6311+#define VM_STACK_DEFAULT_FLAGS32 \
6312+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6313+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6314
6315 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6316 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6317
6318+#ifndef CONFIG_PAX_PAGEEXEC
6319 #define VM_STACK_DEFAULT_FLAGS \
6320 (is_32bit_task() ? \
6321 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
6322+#endif
6323
6324 #include <asm-generic/getorder.h>
6325
6326diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
6327index 292725c..f87ae14 100644
6328--- a/arch/powerpc/include/asm/pgalloc-64.h
6329+++ b/arch/powerpc/include/asm/pgalloc-64.h
6330@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6331 #ifndef CONFIG_PPC_64K_PAGES
6332
6333 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
6334+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
6335
6336 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
6337 {
6338@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6339 pud_set(pud, (unsigned long)pmd);
6340 }
6341
6342+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6343+{
6344+ pud_populate(mm, pud, pmd);
6345+}
6346+
6347 #define pmd_populate(mm, pmd, pte_page) \
6348 pmd_populate_kernel(mm, pmd, page_address(pte_page))
6349 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
6350@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6351 #else /* CONFIG_PPC_64K_PAGES */
6352
6353 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
6354+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
6355
6356 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
6357 pte_t *pte)
6358diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
6359index a9cbd3b..3b67efa 100644
6360--- a/arch/powerpc/include/asm/pgtable.h
6361+++ b/arch/powerpc/include/asm/pgtable.h
6362@@ -2,6 +2,7 @@
6363 #define _ASM_POWERPC_PGTABLE_H
6364 #ifdef __KERNEL__
6365
6366+#include <linux/const.h>
6367 #ifndef __ASSEMBLY__
6368 #include <asm/processor.h> /* For TASK_SIZE */
6369 #include <asm/mmu.h>
6370diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
6371index 4aad413..85d86bf 100644
6372--- a/arch/powerpc/include/asm/pte-hash32.h
6373+++ b/arch/powerpc/include/asm/pte-hash32.h
6374@@ -21,6 +21,7 @@
6375 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
6376 #define _PAGE_USER 0x004 /* usermode access allowed */
6377 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
6378+#define _PAGE_EXEC _PAGE_GUARDED
6379 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
6380 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
6381 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
6382diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
6383index 3b097a8..8f8c774 100644
6384--- a/arch/powerpc/include/asm/reg.h
6385+++ b/arch/powerpc/include/asm/reg.h
6386@@ -234,6 +234,7 @@
6387 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
6388 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
6389 #define DSISR_NOHPTE 0x40000000 /* no translation found */
6390+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
6391 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
6392 #define DSISR_ISSTORE 0x02000000 /* access was a store */
6393 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
6394diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
6395index 195ce2a..ab5c614 100644
6396--- a/arch/powerpc/include/asm/smp.h
6397+++ b/arch/powerpc/include/asm/smp.h
6398@@ -50,7 +50,7 @@ struct smp_ops_t {
6399 int (*cpu_disable)(void);
6400 void (*cpu_die)(unsigned int nr);
6401 int (*cpu_bootable)(unsigned int nr);
6402-};
6403+} __no_const;
6404
6405 extern void smp_send_debugger_break(void);
6406 extern void start_secondary_resume(void);
6407diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
6408index 406b7b9..af63426 100644
6409--- a/arch/powerpc/include/asm/thread_info.h
6410+++ b/arch/powerpc/include/asm/thread_info.h
6411@@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
6412 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
6413 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
6414 #define TIF_SINGLESTEP 8 /* singlestepping active */
6415-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
6416 #define TIF_SECCOMP 10 /* secure computing */
6417 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
6418 #define TIF_NOERROR 12 /* Force successful syscall return */
6419@@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6420 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
6421 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
6422 for stack store? */
6423+#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
6424+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
6425+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
6426
6427 /* as above, but as bit values */
6428 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6429@@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
6430 #define _TIF_UPROBE (1<<TIF_UPROBE)
6431 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6432 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
6433+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6434 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
6435- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
6436+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
6437+ _TIF_GRSEC_SETXID)
6438
6439 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
6440 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
6441diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
6442index 4db4959..aba5c41 100644
6443--- a/arch/powerpc/include/asm/uaccess.h
6444+++ b/arch/powerpc/include/asm/uaccess.h
6445@@ -318,52 +318,6 @@ do { \
6446 extern unsigned long __copy_tofrom_user(void __user *to,
6447 const void __user *from, unsigned long size);
6448
6449-#ifndef __powerpc64__
6450-
6451-static inline unsigned long copy_from_user(void *to,
6452- const void __user *from, unsigned long n)
6453-{
6454- unsigned long over;
6455-
6456- if (access_ok(VERIFY_READ, from, n))
6457- return __copy_tofrom_user((__force void __user *)to, from, n);
6458- if ((unsigned long)from < TASK_SIZE) {
6459- over = (unsigned long)from + n - TASK_SIZE;
6460- return __copy_tofrom_user((__force void __user *)to, from,
6461- n - over) + over;
6462- }
6463- return n;
6464-}
6465-
6466-static inline unsigned long copy_to_user(void __user *to,
6467- const void *from, unsigned long n)
6468-{
6469- unsigned long over;
6470-
6471- if (access_ok(VERIFY_WRITE, to, n))
6472- return __copy_tofrom_user(to, (__force void __user *)from, n);
6473- if ((unsigned long)to < TASK_SIZE) {
6474- over = (unsigned long)to + n - TASK_SIZE;
6475- return __copy_tofrom_user(to, (__force void __user *)from,
6476- n - over) + over;
6477- }
6478- return n;
6479-}
6480-
6481-#else /* __powerpc64__ */
6482-
6483-#define __copy_in_user(to, from, size) \
6484- __copy_tofrom_user((to), (from), (size))
6485-
6486-extern unsigned long copy_from_user(void *to, const void __user *from,
6487- unsigned long n);
6488-extern unsigned long copy_to_user(void __user *to, const void *from,
6489- unsigned long n);
6490-extern unsigned long copy_in_user(void __user *to, const void __user *from,
6491- unsigned long n);
6492-
6493-#endif /* __powerpc64__ */
6494-
6495 static inline unsigned long __copy_from_user_inatomic(void *to,
6496 const void __user *from, unsigned long n)
6497 {
6498@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
6499 if (ret == 0)
6500 return 0;
6501 }
6502+
6503+ if (!__builtin_constant_p(n))
6504+ check_object_size(to, n, false);
6505+
6506 return __copy_tofrom_user((__force void __user *)to, from, n);
6507 }
6508
6509@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
6510 if (ret == 0)
6511 return 0;
6512 }
6513+
6514+ if (!__builtin_constant_p(n))
6515+ check_object_size(from, n, true);
6516+
6517 return __copy_tofrom_user(to, (__force const void __user *)from, n);
6518 }
6519
6520@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
6521 return __copy_to_user_inatomic(to, from, size);
6522 }
6523
6524+#ifndef __powerpc64__
6525+
6526+static inline unsigned long __must_check copy_from_user(void *to,
6527+ const void __user *from, unsigned long n)
6528+{
6529+ unsigned long over;
6530+
6531+ if ((long)n < 0)
6532+ return n;
6533+
6534+ if (access_ok(VERIFY_READ, from, n)) {
6535+ if (!__builtin_constant_p(n))
6536+ check_object_size(to, n, false);
6537+ return __copy_tofrom_user((__force void __user *)to, from, n);
6538+ }
6539+ if ((unsigned long)from < TASK_SIZE) {
6540+ over = (unsigned long)from + n - TASK_SIZE;
6541+ if (!__builtin_constant_p(n - over))
6542+ check_object_size(to, n - over, false);
6543+ return __copy_tofrom_user((__force void __user *)to, from,
6544+ n - over) + over;
6545+ }
6546+ return n;
6547+}
6548+
6549+static inline unsigned long __must_check copy_to_user(void __user *to,
6550+ const void *from, unsigned long n)
6551+{
6552+ unsigned long over;
6553+
6554+ if ((long)n < 0)
6555+ return n;
6556+
6557+ if (access_ok(VERIFY_WRITE, to, n)) {
6558+ if (!__builtin_constant_p(n))
6559+ check_object_size(from, n, true);
6560+ return __copy_tofrom_user(to, (__force void __user *)from, n);
6561+ }
6562+ if ((unsigned long)to < TASK_SIZE) {
6563+ over = (unsigned long)to + n - TASK_SIZE;
6564+ if (!__builtin_constant_p(n))
6565+ check_object_size(from, n - over, true);
6566+ return __copy_tofrom_user(to, (__force void __user *)from,
6567+ n - over) + over;
6568+ }
6569+ return n;
6570+}
6571+
6572+#else /* __powerpc64__ */
6573+
6574+#define __copy_in_user(to, from, size) \
6575+ __copy_tofrom_user((to), (from), (size))
6576+
6577+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
6578+{
6579+ if ((long)n < 0 || n > INT_MAX)
6580+ return n;
6581+
6582+ if (!__builtin_constant_p(n))
6583+ check_object_size(to, n, false);
6584+
6585+ if (likely(access_ok(VERIFY_READ, from, n)))
6586+ n = __copy_from_user(to, from, n);
6587+ else
6588+ memset(to, 0, n);
6589+ return n;
6590+}
6591+
6592+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
6593+{
6594+ if ((long)n < 0 || n > INT_MAX)
6595+ return n;
6596+
6597+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
6598+ if (!__builtin_constant_p(n))
6599+ check_object_size(from, n, true);
6600+ n = __copy_to_user(to, from, n);
6601+ }
6602+ return n;
6603+}
6604+
6605+extern unsigned long copy_in_user(void __user *to, const void __user *from,
6606+ unsigned long n);
6607+
6608+#endif /* __powerpc64__ */
6609+
6610 extern unsigned long __clear_user(void __user *addr, unsigned long size);
6611
6612 static inline unsigned long clear_user(void __user *addr, unsigned long size)
6613diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
6614index ae54553..cf2184d 100644
6615--- a/arch/powerpc/kernel/exceptions-64e.S
6616+++ b/arch/powerpc/kernel/exceptions-64e.S
6617@@ -716,6 +716,7 @@ storage_fault_common:
6618 std r14,_DAR(r1)
6619 std r15,_DSISR(r1)
6620 addi r3,r1,STACK_FRAME_OVERHEAD
6621+ bl .save_nvgprs
6622 mr r4,r14
6623 mr r5,r15
6624 ld r14,PACA_EXGEN+EX_R14(r13)
6625@@ -724,8 +725,7 @@ storage_fault_common:
6626 cmpdi r3,0
6627 bne- 1f
6628 b .ret_from_except_lite
6629-1: bl .save_nvgprs
6630- mr r5,r3
6631+1: mr r5,r3
6632 addi r3,r1,STACK_FRAME_OVERHEAD
6633 ld r4,_DAR(r1)
6634 bl .bad_page_fault
6635diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
6636index 3bbe7ed..14ec3eb 100644
6637--- a/arch/powerpc/kernel/exceptions-64s.S
6638+++ b/arch/powerpc/kernel/exceptions-64s.S
6639@@ -1390,10 +1390,10 @@ handle_page_fault:
6640 11: ld r4,_DAR(r1)
6641 ld r5,_DSISR(r1)
6642 addi r3,r1,STACK_FRAME_OVERHEAD
6643+ bl .save_nvgprs
6644 bl .do_page_fault
6645 cmpdi r3,0
6646 beq+ 12f
6647- bl .save_nvgprs
6648 mr r5,r3
6649 addi r3,r1,STACK_FRAME_OVERHEAD
6650 lwz r4,_DAR(r1)
6651diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
6652index 2e3200c..72095ce 100644
6653--- a/arch/powerpc/kernel/module_32.c
6654+++ b/arch/powerpc/kernel/module_32.c
6655@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
6656 me->arch.core_plt_section = i;
6657 }
6658 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
6659- printk("Module doesn't contain .plt or .init.plt sections.\n");
6660+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
6661 return -ENOEXEC;
6662 }
6663
6664@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
6665
6666 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
6667 /* Init, or core PLT? */
6668- if (location >= mod->module_core
6669- && location < mod->module_core + mod->core_size)
6670+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
6671+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
6672 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
6673- else
6674+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
6675+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
6676 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
6677+ else {
6678+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
6679+ return ~0UL;
6680+ }
6681
6682 /* Find this entry, or if that fails, the next avail. entry */
6683 while (entry->jump[0]) {
6684diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
6685index 16e77a8..4501b41 100644
6686--- a/arch/powerpc/kernel/process.c
6687+++ b/arch/powerpc/kernel/process.c
6688@@ -870,8 +870,8 @@ void show_regs(struct pt_regs * regs)
6689 * Lookup NIP late so we have the best change of getting the
6690 * above info out without failing
6691 */
6692- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
6693- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
6694+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
6695+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
6696 #endif
6697 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
6698 printk("PACATMSCRATCH [%llx]\n", get_paca()->tm_scratch);
6699@@ -1330,10 +1330,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6700 newsp = stack[0];
6701 ip = stack[STACK_FRAME_LR_SAVE];
6702 if (!firstframe || ip != lr) {
6703- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
6704+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
6705 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6706 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
6707- printk(" (%pS)",
6708+ printk(" (%pA)",
6709 (void *)current->ret_stack[curr_frame].ret);
6710 curr_frame--;
6711 }
6712@@ -1353,7 +1353,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6713 struct pt_regs *regs = (struct pt_regs *)
6714 (sp + STACK_FRAME_OVERHEAD);
6715 lr = regs->link;
6716- printk("--- Exception: %lx at %pS\n LR = %pS\n",
6717+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
6718 regs->trap, (void *)regs->nip, (void *)lr);
6719 firstframe = 1;
6720 }
6721@@ -1395,58 +1395,3 @@ void __ppc64_runlatch_off(void)
6722 mtspr(SPRN_CTRLT, ctrl);
6723 }
6724 #endif /* CONFIG_PPC64 */
6725-
6726-unsigned long arch_align_stack(unsigned long sp)
6727-{
6728- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6729- sp -= get_random_int() & ~PAGE_MASK;
6730- return sp & ~0xf;
6731-}
6732-
6733-static inline unsigned long brk_rnd(void)
6734-{
6735- unsigned long rnd = 0;
6736-
6737- /* 8MB for 32bit, 1GB for 64bit */
6738- if (is_32bit_task())
6739- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
6740- else
6741- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
6742-
6743- return rnd << PAGE_SHIFT;
6744-}
6745-
6746-unsigned long arch_randomize_brk(struct mm_struct *mm)
6747-{
6748- unsigned long base = mm->brk;
6749- unsigned long ret;
6750-
6751-#ifdef CONFIG_PPC_STD_MMU_64
6752- /*
6753- * If we are using 1TB segments and we are allowed to randomise
6754- * the heap, we can put it above 1TB so it is backed by a 1TB
6755- * segment. Otherwise the heap will be in the bottom 1TB
6756- * which always uses 256MB segments and this may result in a
6757- * performance penalty.
6758- */
6759- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
6760- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
6761-#endif
6762-
6763- ret = PAGE_ALIGN(base + brk_rnd());
6764-
6765- if (ret < mm->brk)
6766- return mm->brk;
6767-
6768- return ret;
6769-}
6770-
6771-unsigned long randomize_et_dyn(unsigned long base)
6772-{
6773- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
6774-
6775- if (ret < base)
6776- return base;
6777-
6778- return ret;
6779-}
6780diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
6781index f9b30c6..d72e7a3 100644
6782--- a/arch/powerpc/kernel/ptrace.c
6783+++ b/arch/powerpc/kernel/ptrace.c
6784@@ -1771,6 +1771,10 @@ long arch_ptrace(struct task_struct *child, long request,
6785 return ret;
6786 }
6787
6788+#ifdef CONFIG_GRKERNSEC_SETXID
6789+extern void gr_delayed_cred_worker(void);
6790+#endif
6791+
6792 /*
6793 * We must return the syscall number to actually look up in the table.
6794 * This can be -1L to skip running any syscall at all.
6795@@ -1781,6 +1785,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
6796
6797 secure_computing_strict(regs->gpr[0]);
6798
6799+#ifdef CONFIG_GRKERNSEC_SETXID
6800+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6801+ gr_delayed_cred_worker();
6802+#endif
6803+
6804 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
6805 tracehook_report_syscall_entry(regs))
6806 /*
6807@@ -1815,6 +1824,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
6808 {
6809 int step;
6810
6811+#ifdef CONFIG_GRKERNSEC_SETXID
6812+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6813+ gr_delayed_cred_worker();
6814+#endif
6815+
6816 audit_syscall_exit(regs);
6817
6818 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6819diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
6820index 201385c..0f01828 100644
6821--- a/arch/powerpc/kernel/signal_32.c
6822+++ b/arch/powerpc/kernel/signal_32.c
6823@@ -976,7 +976,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
6824 /* Save user registers on the stack */
6825 frame = &rt_sf->uc.uc_mcontext;
6826 addr = frame;
6827- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
6828+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6829 sigret = 0;
6830 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
6831 } else {
6832diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
6833index 3459473..2d40783 100644
6834--- a/arch/powerpc/kernel/signal_64.c
6835+++ b/arch/powerpc/kernel/signal_64.c
6836@@ -749,7 +749,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
6837 #endif
6838
6839 /* Set up to return from userspace. */
6840- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
6841+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6842 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
6843 } else {
6844 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
6845diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
6846index 3ce1f86..c30e629 100644
6847--- a/arch/powerpc/kernel/sysfs.c
6848+++ b/arch/powerpc/kernel/sysfs.c
6849@@ -522,7 +522,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
6850 return NOTIFY_OK;
6851 }
6852
6853-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
6854+static struct notifier_block sysfs_cpu_nb = {
6855 .notifier_call = sysfs_cpu_notify,
6856 };
6857
6858diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
6859index 1c22b2d..3b56e67 100644
6860--- a/arch/powerpc/kernel/traps.c
6861+++ b/arch/powerpc/kernel/traps.c
6862@@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
6863 return flags;
6864 }
6865
6866+extern void gr_handle_kernel_exploit(void);
6867+
6868 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6869 int signr)
6870 {
6871@@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6872 panic("Fatal exception in interrupt");
6873 if (panic_on_oops)
6874 panic("Fatal exception");
6875+
6876+ gr_handle_kernel_exploit();
6877+
6878 do_exit(signr);
6879 }
6880
6881diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
6882index 1b2076f..835e4be 100644
6883--- a/arch/powerpc/kernel/vdso.c
6884+++ b/arch/powerpc/kernel/vdso.c
6885@@ -34,6 +34,7 @@
6886 #include <asm/firmware.h>
6887 #include <asm/vdso.h>
6888 #include <asm/vdso_datapage.h>
6889+#include <asm/mman.h>
6890
6891 #include "setup.h"
6892
6893@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6894 vdso_base = VDSO32_MBASE;
6895 #endif
6896
6897- current->mm->context.vdso_base = 0;
6898+ current->mm->context.vdso_base = ~0UL;
6899
6900 /* vDSO has a problem and was disabled, just don't "enable" it for the
6901 * process
6902@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6903 vdso_base = get_unmapped_area(NULL, vdso_base,
6904 (vdso_pages << PAGE_SHIFT) +
6905 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
6906- 0, 0);
6907+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
6908 if (IS_ERR_VALUE(vdso_base)) {
6909 rc = vdso_base;
6910 goto fail_mmapsem;
6911diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
6912index 5eea6f3..5d10396 100644
6913--- a/arch/powerpc/lib/usercopy_64.c
6914+++ b/arch/powerpc/lib/usercopy_64.c
6915@@ -9,22 +9,6 @@
6916 #include <linux/module.h>
6917 #include <asm/uaccess.h>
6918
6919-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6920-{
6921- if (likely(access_ok(VERIFY_READ, from, n)))
6922- n = __copy_from_user(to, from, n);
6923- else
6924- memset(to, 0, n);
6925- return n;
6926-}
6927-
6928-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6929-{
6930- if (likely(access_ok(VERIFY_WRITE, to, n)))
6931- n = __copy_to_user(to, from, n);
6932- return n;
6933-}
6934-
6935 unsigned long copy_in_user(void __user *to, const void __user *from,
6936 unsigned long n)
6937 {
6938@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
6939 return n;
6940 }
6941
6942-EXPORT_SYMBOL(copy_from_user);
6943-EXPORT_SYMBOL(copy_to_user);
6944 EXPORT_SYMBOL(copy_in_user);
6945
6946diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
6947index 229951f..cdeca42 100644
6948--- a/arch/powerpc/mm/fault.c
6949+++ b/arch/powerpc/mm/fault.c
6950@@ -32,6 +32,10 @@
6951 #include <linux/perf_event.h>
6952 #include <linux/magic.h>
6953 #include <linux/ratelimit.h>
6954+#include <linux/slab.h>
6955+#include <linux/pagemap.h>
6956+#include <linux/compiler.h>
6957+#include <linux/unistd.h>
6958
6959 #include <asm/firmware.h>
6960 #include <asm/page.h>
6961@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
6962 }
6963 #endif
6964
6965+#ifdef CONFIG_PAX_PAGEEXEC
6966+/*
6967+ * PaX: decide what to do with offenders (regs->nip = fault address)
6968+ *
6969+ * returns 1 when task should be killed
6970+ */
6971+static int pax_handle_fetch_fault(struct pt_regs *regs)
6972+{
6973+ return 1;
6974+}
6975+
6976+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6977+{
6978+ unsigned long i;
6979+
6980+ printk(KERN_ERR "PAX: bytes at PC: ");
6981+ for (i = 0; i < 5; i++) {
6982+ unsigned int c;
6983+ if (get_user(c, (unsigned int __user *)pc+i))
6984+ printk(KERN_CONT "???????? ");
6985+ else
6986+ printk(KERN_CONT "%08x ", c);
6987+ }
6988+ printk("\n");
6989+}
6990+#endif
6991+
6992 /*
6993 * Check whether the instruction at regs->nip is a store using
6994 * an update addressing form which will update r1.
6995@@ -213,7 +244,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
6996 * indicate errors in DSISR but can validly be set in SRR1.
6997 */
6998 if (trap == 0x400)
6999- error_code &= 0x48200000;
7000+ error_code &= 0x58200000;
7001 else
7002 is_write = error_code & DSISR_ISSTORE;
7003 #else
7004@@ -364,7 +395,7 @@ good_area:
7005 * "undefined". Of those that can be set, this is the only
7006 * one which seems bad.
7007 */
7008- if (error_code & 0x10000000)
7009+ if (error_code & DSISR_GUARDED)
7010 /* Guarded storage error. */
7011 goto bad_area;
7012 #endif /* CONFIG_8xx */
7013@@ -379,7 +410,7 @@ good_area:
7014 * processors use the same I/D cache coherency mechanism
7015 * as embedded.
7016 */
7017- if (error_code & DSISR_PROTFAULT)
7018+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
7019 goto bad_area;
7020 #endif /* CONFIG_PPC_STD_MMU */
7021
7022@@ -462,6 +493,23 @@ bad_area:
7023 bad_area_nosemaphore:
7024 /* User mode accesses cause a SIGSEGV */
7025 if (user_mode(regs)) {
7026+
7027+#ifdef CONFIG_PAX_PAGEEXEC
7028+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
7029+#ifdef CONFIG_PPC_STD_MMU
7030+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
7031+#else
7032+ if (is_exec && regs->nip == address) {
7033+#endif
7034+ switch (pax_handle_fetch_fault(regs)) {
7035+ }
7036+
7037+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
7038+ do_group_exit(SIGKILL);
7039+ }
7040+ }
7041+#endif
7042+
7043 _exception(SIGSEGV, regs, code, address);
7044 return 0;
7045 }
7046diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
7047index 67a42ed..cd463e0 100644
7048--- a/arch/powerpc/mm/mmap_64.c
7049+++ b/arch/powerpc/mm/mmap_64.c
7050@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
7051 {
7052 unsigned long rnd = 0;
7053
7054+#ifdef CONFIG_PAX_RANDMMAP
7055+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7056+#endif
7057+
7058 if (current->flags & PF_RANDOMIZE) {
7059 /* 8MB for 32bit, 1GB for 64bit */
7060 if (is_32bit_task())
7061@@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7062 */
7063 if (mmap_is_legacy()) {
7064 mm->mmap_base = TASK_UNMAPPED_BASE;
7065+
7066+#ifdef CONFIG_PAX_RANDMMAP
7067+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7068+ mm->mmap_base += mm->delta_mmap;
7069+#endif
7070+
7071 mm->get_unmapped_area = arch_get_unmapped_area;
7072 mm->unmap_area = arch_unmap_area;
7073 } else {
7074 mm->mmap_base = mmap_base();
7075+
7076+#ifdef CONFIG_PAX_RANDMMAP
7077+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7078+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7079+#endif
7080+
7081 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7082 mm->unmap_area = arch_unmap_area_topdown;
7083 }
7084diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
7085index e779642..e5bb889 100644
7086--- a/arch/powerpc/mm/mmu_context_nohash.c
7087+++ b/arch/powerpc/mm/mmu_context_nohash.c
7088@@ -363,7 +363,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
7089 return NOTIFY_OK;
7090 }
7091
7092-static struct notifier_block __cpuinitdata mmu_context_cpu_nb = {
7093+static struct notifier_block mmu_context_cpu_nb = {
7094 .notifier_call = mmu_context_cpu_notify,
7095 };
7096
7097diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
7098index 6a252c4..3024d81 100644
7099--- a/arch/powerpc/mm/numa.c
7100+++ b/arch/powerpc/mm/numa.c
7101@@ -932,7 +932,7 @@ static void __init *careful_zallocation(int nid, unsigned long size,
7102 return ret;
7103 }
7104
7105-static struct notifier_block __cpuinitdata ppc64_numa_nb = {
7106+static struct notifier_block ppc64_numa_nb = {
7107 .notifier_call = cpu_numa_callback,
7108 .priority = 1 /* Must run before sched domains notifier. */
7109 };
7110diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
7111index cf9dada..241529f 100644
7112--- a/arch/powerpc/mm/slice.c
7113+++ b/arch/powerpc/mm/slice.c
7114@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
7115 if ((mm->task_size - len) < addr)
7116 return 0;
7117 vma = find_vma(mm, addr);
7118- return (!vma || (addr + len) <= vma->vm_start);
7119+ return check_heap_stack_gap(vma, addr, len, 0);
7120 }
7121
7122 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
7123@@ -272,7 +272,7 @@ full_search:
7124 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
7125 continue;
7126 }
7127- if (!vma || addr + len <= vma->vm_start) {
7128+ if (check_heap_stack_gap(vma, addr, len, 0)) {
7129 /*
7130 * Remember the place where we stopped the search:
7131 */
7132@@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7133 }
7134 }
7135
7136- addr = mm->mmap_base;
7137- while (addr > len) {
7138+ if (mm->mmap_base < len)
7139+ addr = -ENOMEM;
7140+ else
7141+ addr = mm->mmap_base - len;
7142+
7143+ while (!IS_ERR_VALUE(addr)) {
7144 /* Go down by chunk size */
7145- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
7146+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
7147
7148 /* Check for hit with different page size */
7149 mask = slice_range_to_mask(addr, len);
7150@@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7151 * return with success:
7152 */
7153 vma = find_vma(mm, addr);
7154- if (!vma || (addr + len) <= vma->vm_start) {
7155+ if (check_heap_stack_gap(vma, addr, len, 0)) {
7156 /* remember the address as a hint for next time */
7157 if (use_cache)
7158 mm->free_area_cache = addr;
7159@@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7160 mm->cached_hole_size = vma->vm_start - addr;
7161
7162 /* try just below the current vma->vm_start */
7163- addr = vma->vm_start;
7164+ addr = skip_heap_stack_gap(vma, len, 0);
7165 }
7166
7167 /*
7168@@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
7169 if (fixed && addr > (mm->task_size - len))
7170 return -EINVAL;
7171
7172+#ifdef CONFIG_PAX_RANDMMAP
7173+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
7174+ addr = 0;
7175+#endif
7176+
7177 /* If hint, make sure it matches our alignment restrictions */
7178 if (!fixed && addr) {
7179 addr = _ALIGN_UP(addr, 1ul << pshift);
7180diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
7181index 68c57d3..1fdcfb2 100644
7182--- a/arch/powerpc/platforms/cell/spufs/file.c
7183+++ b/arch/powerpc/platforms/cell/spufs/file.c
7184@@ -281,9 +281,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7185 return VM_FAULT_NOPAGE;
7186 }
7187
7188-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
7189+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
7190 unsigned long address,
7191- void *buf, int len, int write)
7192+ void *buf, size_t len, int write)
7193 {
7194 struct spu_context *ctx = vma->vm_file->private_data;
7195 unsigned long offset = address - vma->vm_start;
7196diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
7197index bdb738a..49c9f95 100644
7198--- a/arch/powerpc/platforms/powermac/smp.c
7199+++ b/arch/powerpc/platforms/powermac/smp.c
7200@@ -885,7 +885,7 @@ static int smp_core99_cpu_notify(struct notifier_block *self,
7201 return NOTIFY_OK;
7202 }
7203
7204-static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
7205+static struct notifier_block smp_core99_cpu_nb = {
7206 .notifier_call = smp_core99_cpu_notify,
7207 };
7208 #endif /* CONFIG_HOTPLUG_CPU */
7209diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
7210index c797832..ce575c8 100644
7211--- a/arch/s390/include/asm/atomic.h
7212+++ b/arch/s390/include/asm/atomic.h
7213@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
7214 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
7215 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7216
7217+#define atomic64_read_unchecked(v) atomic64_read(v)
7218+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7219+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7220+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7221+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7222+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7223+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7224+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7225+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7226+
7227 #define smp_mb__before_atomic_dec() smp_mb()
7228 #define smp_mb__after_atomic_dec() smp_mb()
7229 #define smp_mb__before_atomic_inc() smp_mb()
7230diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
7231index 4d7ccac..d03d0ad 100644
7232--- a/arch/s390/include/asm/cache.h
7233+++ b/arch/s390/include/asm/cache.h
7234@@ -9,8 +9,10 @@
7235 #ifndef __ARCH_S390_CACHE_H
7236 #define __ARCH_S390_CACHE_H
7237
7238-#define L1_CACHE_BYTES 256
7239+#include <linux/const.h>
7240+
7241 #define L1_CACHE_SHIFT 8
7242+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7243 #define NET_SKB_PAD 32
7244
7245 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7246diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
7247index 1bfdf24..9c9ab2e 100644
7248--- a/arch/s390/include/asm/elf.h
7249+++ b/arch/s390/include/asm/elf.h
7250@@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
7251 the loader. We need to make sure that it is out of the way of the program
7252 that it will "exec", and that there is sufficient room for the brk. */
7253
7254-extern unsigned long randomize_et_dyn(unsigned long base);
7255-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
7256+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
7257+
7258+#ifdef CONFIG_PAX_ASLR
7259+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
7260+
7261+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7262+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7263+#endif
7264
7265 /* This yields a mask that user programs can use to figure out what
7266 instruction set this CPU supports. */
7267@@ -207,9 +213,6 @@ struct linux_binprm;
7268 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
7269 int arch_setup_additional_pages(struct linux_binprm *, int);
7270
7271-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7272-#define arch_randomize_brk arch_randomize_brk
7273-
7274 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
7275
7276 #endif
7277diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
7278index c4a93d6..4d2a9b4 100644
7279--- a/arch/s390/include/asm/exec.h
7280+++ b/arch/s390/include/asm/exec.h
7281@@ -7,6 +7,6 @@
7282 #ifndef __ASM_EXEC_H
7283 #define __ASM_EXEC_H
7284
7285-extern unsigned long arch_align_stack(unsigned long sp);
7286+#define arch_align_stack(x) ((x) & ~0xfUL)
7287
7288 #endif /* __ASM_EXEC_H */
7289diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
7290index 9c33ed4..e40cbef 100644
7291--- a/arch/s390/include/asm/uaccess.h
7292+++ b/arch/s390/include/asm/uaccess.h
7293@@ -252,6 +252,10 @@ static inline unsigned long __must_check
7294 copy_to_user(void __user *to, const void *from, unsigned long n)
7295 {
7296 might_fault();
7297+
7298+ if ((long)n < 0)
7299+ return n;
7300+
7301 return __copy_to_user(to, from, n);
7302 }
7303
7304@@ -275,6 +279,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
7305 static inline unsigned long __must_check
7306 __copy_from_user(void *to, const void __user *from, unsigned long n)
7307 {
7308+ if ((long)n < 0)
7309+ return n;
7310+
7311 if (__builtin_constant_p(n) && (n <= 256))
7312 return uaccess.copy_from_user_small(n, from, to);
7313 else
7314@@ -306,10 +313,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
7315 static inline unsigned long __must_check
7316 copy_from_user(void *to, const void __user *from, unsigned long n)
7317 {
7318- unsigned int sz = __compiletime_object_size(to);
7319+ size_t sz = __compiletime_object_size(to);
7320
7321 might_fault();
7322- if (unlikely(sz != -1 && sz < n)) {
7323+
7324+ if ((long)n < 0)
7325+ return n;
7326+
7327+ if (unlikely(sz != (size_t)-1 && sz < n)) {
7328 copy_from_user_overflow();
7329 return n;
7330 }
7331diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
7332index 7845e15..59c4353 100644
7333--- a/arch/s390/kernel/module.c
7334+++ b/arch/s390/kernel/module.c
7335@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
7336
7337 /* Increase core size by size of got & plt and set start
7338 offsets for got and plt. */
7339- me->core_size = ALIGN(me->core_size, 4);
7340- me->arch.got_offset = me->core_size;
7341- me->core_size += me->arch.got_size;
7342- me->arch.plt_offset = me->core_size;
7343- me->core_size += me->arch.plt_size;
7344+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
7345+ me->arch.got_offset = me->core_size_rw;
7346+ me->core_size_rw += me->arch.got_size;
7347+ me->arch.plt_offset = me->core_size_rx;
7348+ me->core_size_rx += me->arch.plt_size;
7349 return 0;
7350 }
7351
7352@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7353 if (info->got_initialized == 0) {
7354 Elf_Addr *gotent;
7355
7356- gotent = me->module_core + me->arch.got_offset +
7357+ gotent = me->module_core_rw + me->arch.got_offset +
7358 info->got_offset;
7359 *gotent = val;
7360 info->got_initialized = 1;
7361@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7362 rc = apply_rela_bits(loc, val, 0, 64, 0);
7363 else if (r_type == R_390_GOTENT ||
7364 r_type == R_390_GOTPLTENT) {
7365- val += (Elf_Addr) me->module_core - loc;
7366+ val += (Elf_Addr) me->module_core_rw - loc;
7367 rc = apply_rela_bits(loc, val, 1, 32, 1);
7368 }
7369 break;
7370@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7371 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
7372 if (info->plt_initialized == 0) {
7373 unsigned int *ip;
7374- ip = me->module_core + me->arch.plt_offset +
7375+ ip = me->module_core_rx + me->arch.plt_offset +
7376 info->plt_offset;
7377 #ifndef CONFIG_64BIT
7378 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
7379@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7380 val - loc + 0xffffUL < 0x1ffffeUL) ||
7381 (r_type == R_390_PLT32DBL &&
7382 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
7383- val = (Elf_Addr) me->module_core +
7384+ val = (Elf_Addr) me->module_core_rx +
7385 me->arch.plt_offset +
7386 info->plt_offset;
7387 val += rela->r_addend - loc;
7388@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7389 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
7390 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
7391 val = val + rela->r_addend -
7392- ((Elf_Addr) me->module_core + me->arch.got_offset);
7393+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
7394 if (r_type == R_390_GOTOFF16)
7395 rc = apply_rela_bits(loc, val, 0, 16, 0);
7396 else if (r_type == R_390_GOTOFF32)
7397@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7398 break;
7399 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
7400 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
7401- val = (Elf_Addr) me->module_core + me->arch.got_offset +
7402+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
7403 rela->r_addend - loc;
7404 if (r_type == R_390_GOTPC)
7405 rc = apply_rela_bits(loc, val, 1, 32, 0);
7406diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
7407index 536d645..4a5bd9e 100644
7408--- a/arch/s390/kernel/process.c
7409+++ b/arch/s390/kernel/process.c
7410@@ -250,39 +250,3 @@ unsigned long get_wchan(struct task_struct *p)
7411 }
7412 return 0;
7413 }
7414-
7415-unsigned long arch_align_stack(unsigned long sp)
7416-{
7417- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7418- sp -= get_random_int() & ~PAGE_MASK;
7419- return sp & ~0xf;
7420-}
7421-
7422-static inline unsigned long brk_rnd(void)
7423-{
7424- /* 8MB for 32bit, 1GB for 64bit */
7425- if (is_32bit_task())
7426- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
7427- else
7428- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
7429-}
7430-
7431-unsigned long arch_randomize_brk(struct mm_struct *mm)
7432-{
7433- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
7434-
7435- if (ret < mm->brk)
7436- return mm->brk;
7437- return ret;
7438-}
7439-
7440-unsigned long randomize_et_dyn(unsigned long base)
7441-{
7442- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7443-
7444- if (!(current->flags & PF_RANDOMIZE))
7445- return base;
7446- if (ret < base)
7447- return base;
7448- return ret;
7449-}
7450diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
7451index 06bafec..2bca531 100644
7452--- a/arch/s390/mm/mmap.c
7453+++ b/arch/s390/mm/mmap.c
7454@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7455 */
7456 if (mmap_is_legacy()) {
7457 mm->mmap_base = TASK_UNMAPPED_BASE;
7458+
7459+#ifdef CONFIG_PAX_RANDMMAP
7460+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7461+ mm->mmap_base += mm->delta_mmap;
7462+#endif
7463+
7464 mm->get_unmapped_area = arch_get_unmapped_area;
7465 mm->unmap_area = arch_unmap_area;
7466 } else {
7467 mm->mmap_base = mmap_base();
7468+
7469+#ifdef CONFIG_PAX_RANDMMAP
7470+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7471+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7472+#endif
7473+
7474 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7475 mm->unmap_area = arch_unmap_area_topdown;
7476 }
7477@@ -175,10 +187,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7478 */
7479 if (mmap_is_legacy()) {
7480 mm->mmap_base = TASK_UNMAPPED_BASE;
7481+
7482+#ifdef CONFIG_PAX_RANDMMAP
7483+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7484+ mm->mmap_base += mm->delta_mmap;
7485+#endif
7486+
7487 mm->get_unmapped_area = s390_get_unmapped_area;
7488 mm->unmap_area = arch_unmap_area;
7489 } else {
7490 mm->mmap_base = mmap_base();
7491+
7492+#ifdef CONFIG_PAX_RANDMMAP
7493+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7494+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7495+#endif
7496+
7497 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
7498 mm->unmap_area = arch_unmap_area_topdown;
7499 }
7500diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
7501index ae3d59f..f65f075 100644
7502--- a/arch/score/include/asm/cache.h
7503+++ b/arch/score/include/asm/cache.h
7504@@ -1,7 +1,9 @@
7505 #ifndef _ASM_SCORE_CACHE_H
7506 #define _ASM_SCORE_CACHE_H
7507
7508+#include <linux/const.h>
7509+
7510 #define L1_CACHE_SHIFT 4
7511-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7512+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7513
7514 #endif /* _ASM_SCORE_CACHE_H */
7515diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
7516index f9f3cd5..58ff438 100644
7517--- a/arch/score/include/asm/exec.h
7518+++ b/arch/score/include/asm/exec.h
7519@@ -1,6 +1,6 @@
7520 #ifndef _ASM_SCORE_EXEC_H
7521 #define _ASM_SCORE_EXEC_H
7522
7523-extern unsigned long arch_align_stack(unsigned long sp);
7524+#define arch_align_stack(x) (x)
7525
7526 #endif /* _ASM_SCORE_EXEC_H */
7527diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
7528index 7956846..5f37677 100644
7529--- a/arch/score/kernel/process.c
7530+++ b/arch/score/kernel/process.c
7531@@ -134,8 +134,3 @@ unsigned long get_wchan(struct task_struct *task)
7532
7533 return task_pt_regs(task)->cp0_epc;
7534 }
7535-
7536-unsigned long arch_align_stack(unsigned long sp)
7537-{
7538- return sp;
7539-}
7540diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
7541index ef9e555..331bd29 100644
7542--- a/arch/sh/include/asm/cache.h
7543+++ b/arch/sh/include/asm/cache.h
7544@@ -9,10 +9,11 @@
7545 #define __ASM_SH_CACHE_H
7546 #ifdef __KERNEL__
7547
7548+#include <linux/const.h>
7549 #include <linux/init.h>
7550 #include <cpu/cache.h>
7551
7552-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7553+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7554
7555 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7556
7557diff --git a/arch/sh/kernel/cpu/sh4a/smp-shx3.c b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7558index 03f2b55..b0270327 100644
7559--- a/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7560+++ b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7561@@ -143,7 +143,7 @@ shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
7562 return NOTIFY_OK;
7563 }
7564
7565-static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
7566+static struct notifier_block shx3_cpu_notifier = {
7567 .notifier_call = shx3_cpu_callback,
7568 };
7569
7570diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
7571index 6777177..cb5e44f 100644
7572--- a/arch/sh/mm/mmap.c
7573+++ b/arch/sh/mm/mmap.c
7574@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7575 struct mm_struct *mm = current->mm;
7576 struct vm_area_struct *vma;
7577 int do_colour_align;
7578+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7579 struct vm_unmapped_area_info info;
7580
7581 if (flags & MAP_FIXED) {
7582@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7583 if (filp || (flags & MAP_SHARED))
7584 do_colour_align = 1;
7585
7586+#ifdef CONFIG_PAX_RANDMMAP
7587+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7588+#endif
7589+
7590 if (addr) {
7591 if (do_colour_align)
7592 addr = COLOUR_ALIGN(addr, pgoff);
7593@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7594 addr = PAGE_ALIGN(addr);
7595
7596 vma = find_vma(mm, addr);
7597- if (TASK_SIZE - len >= addr &&
7598- (!vma || addr + len <= vma->vm_start))
7599+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7600 return addr;
7601 }
7602
7603 info.flags = 0;
7604 info.length = len;
7605- info.low_limit = TASK_UNMAPPED_BASE;
7606+ info.low_limit = mm->mmap_base;
7607 info.high_limit = TASK_SIZE;
7608 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
7609 info.align_offset = pgoff << PAGE_SHIFT;
7610@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7611 struct mm_struct *mm = current->mm;
7612 unsigned long addr = addr0;
7613 int do_colour_align;
7614+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7615 struct vm_unmapped_area_info info;
7616
7617 if (flags & MAP_FIXED) {
7618@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7619 if (filp || (flags & MAP_SHARED))
7620 do_colour_align = 1;
7621
7622+#ifdef CONFIG_PAX_RANDMMAP
7623+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7624+#endif
7625+
7626 /* requesting a specific address */
7627 if (addr) {
7628 if (do_colour_align)
7629@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7630 addr = PAGE_ALIGN(addr);
7631
7632 vma = find_vma(mm, addr);
7633- if (TASK_SIZE - len >= addr &&
7634- (!vma || addr + len <= vma->vm_start))
7635+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7636 return addr;
7637 }
7638
7639@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7640 VM_BUG_ON(addr != -ENOMEM);
7641 info.flags = 0;
7642 info.low_limit = TASK_UNMAPPED_BASE;
7643+
7644+#ifdef CONFIG_PAX_RANDMMAP
7645+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7646+ info.low_limit += mm->delta_mmap;
7647+#endif
7648+
7649 info.high_limit = TASK_SIZE;
7650 addr = vm_unmapped_area(&info);
7651 }
7652diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
7653index be56a24..443328f 100644
7654--- a/arch/sparc/include/asm/atomic_64.h
7655+++ b/arch/sparc/include/asm/atomic_64.h
7656@@ -14,18 +14,40 @@
7657 #define ATOMIC64_INIT(i) { (i) }
7658
7659 #define atomic_read(v) (*(volatile int *)&(v)->counter)
7660+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7661+{
7662+ return v->counter;
7663+}
7664 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
7665+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7666+{
7667+ return v->counter;
7668+}
7669
7670 #define atomic_set(v, i) (((v)->counter) = i)
7671+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7672+{
7673+ v->counter = i;
7674+}
7675 #define atomic64_set(v, i) (((v)->counter) = i)
7676+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7677+{
7678+ v->counter = i;
7679+}
7680
7681 extern void atomic_add(int, atomic_t *);
7682+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
7683 extern void atomic64_add(long, atomic64_t *);
7684+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
7685 extern void atomic_sub(int, atomic_t *);
7686+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
7687 extern void atomic64_sub(long, atomic64_t *);
7688+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
7689
7690 extern int atomic_add_ret(int, atomic_t *);
7691+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
7692 extern long atomic64_add_ret(long, atomic64_t *);
7693+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
7694 extern int atomic_sub_ret(int, atomic_t *);
7695 extern long atomic64_sub_ret(long, atomic64_t *);
7696
7697@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7698 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
7699
7700 #define atomic_inc_return(v) atomic_add_ret(1, v)
7701+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7702+{
7703+ return atomic_add_ret_unchecked(1, v);
7704+}
7705 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
7706+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7707+{
7708+ return atomic64_add_ret_unchecked(1, v);
7709+}
7710
7711 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
7712 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
7713
7714 #define atomic_add_return(i, v) atomic_add_ret(i, v)
7715+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7716+{
7717+ return atomic_add_ret_unchecked(i, v);
7718+}
7719 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
7720+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7721+{
7722+ return atomic64_add_ret_unchecked(i, v);
7723+}
7724
7725 /*
7726 * atomic_inc_and_test - increment and test
7727@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7728 * other cases.
7729 */
7730 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7731+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7732+{
7733+ return atomic_inc_return_unchecked(v) == 0;
7734+}
7735 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
7736
7737 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
7738@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7739 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
7740
7741 #define atomic_inc(v) atomic_add(1, v)
7742+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7743+{
7744+ atomic_add_unchecked(1, v);
7745+}
7746 #define atomic64_inc(v) atomic64_add(1, v)
7747+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7748+{
7749+ atomic64_add_unchecked(1, v);
7750+}
7751
7752 #define atomic_dec(v) atomic_sub(1, v)
7753+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7754+{
7755+ atomic_sub_unchecked(1, v);
7756+}
7757 #define atomic64_dec(v) atomic64_sub(1, v)
7758+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7759+{
7760+ atomic64_sub_unchecked(1, v);
7761+}
7762
7763 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
7764 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
7765
7766 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7767+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7768+{
7769+ return cmpxchg(&v->counter, old, new);
7770+}
7771 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7772+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7773+{
7774+ return xchg(&v->counter, new);
7775+}
7776
7777 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7778 {
7779- int c, old;
7780+ int c, old, new;
7781 c = atomic_read(v);
7782 for (;;) {
7783- if (unlikely(c == (u)))
7784+ if (unlikely(c == u))
7785 break;
7786- old = atomic_cmpxchg((v), c, c + (a));
7787+
7788+ asm volatile("addcc %2, %0, %0\n"
7789+
7790+#ifdef CONFIG_PAX_REFCOUNT
7791+ "tvs %%icc, 6\n"
7792+#endif
7793+
7794+ : "=r" (new)
7795+ : "0" (c), "ir" (a)
7796+ : "cc");
7797+
7798+ old = atomic_cmpxchg(v, c, new);
7799 if (likely(old == c))
7800 break;
7801 c = old;
7802@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7803 #define atomic64_cmpxchg(v, o, n) \
7804 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
7805 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
7806+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7807+{
7808+ return xchg(&v->counter, new);
7809+}
7810
7811 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7812 {
7813- long c, old;
7814+ long c, old, new;
7815 c = atomic64_read(v);
7816 for (;;) {
7817- if (unlikely(c == (u)))
7818+ if (unlikely(c == u))
7819 break;
7820- old = atomic64_cmpxchg((v), c, c + (a));
7821+
7822+ asm volatile("addcc %2, %0, %0\n"
7823+
7824+#ifdef CONFIG_PAX_REFCOUNT
7825+ "tvs %%xcc, 6\n"
7826+#endif
7827+
7828+ : "=r" (new)
7829+ : "0" (c), "ir" (a)
7830+ : "cc");
7831+
7832+ old = atomic64_cmpxchg(v, c, new);
7833 if (likely(old == c))
7834 break;
7835 c = old;
7836 }
7837- return c != (u);
7838+ return c != u;
7839 }
7840
7841 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7842diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
7843index 5bb6991..5c2132e 100644
7844--- a/arch/sparc/include/asm/cache.h
7845+++ b/arch/sparc/include/asm/cache.h
7846@@ -7,10 +7,12 @@
7847 #ifndef _SPARC_CACHE_H
7848 #define _SPARC_CACHE_H
7849
7850+#include <linux/const.h>
7851+
7852 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
7853
7854 #define L1_CACHE_SHIFT 5
7855-#define L1_CACHE_BYTES 32
7856+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7857
7858 #ifdef CONFIG_SPARC32
7859 #define SMP_CACHE_BYTES_SHIFT 5
7860diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
7861index a24e41f..47677ff 100644
7862--- a/arch/sparc/include/asm/elf_32.h
7863+++ b/arch/sparc/include/asm/elf_32.h
7864@@ -114,6 +114,13 @@ typedef struct {
7865
7866 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
7867
7868+#ifdef CONFIG_PAX_ASLR
7869+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7870+
7871+#define PAX_DELTA_MMAP_LEN 16
7872+#define PAX_DELTA_STACK_LEN 16
7873+#endif
7874+
7875 /* This yields a mask that user programs can use to figure out what
7876 instruction set this cpu supports. This can NOT be done in userspace
7877 on Sparc. */
7878diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
7879index 370ca1e..d4f4a98 100644
7880--- a/arch/sparc/include/asm/elf_64.h
7881+++ b/arch/sparc/include/asm/elf_64.h
7882@@ -189,6 +189,13 @@ typedef struct {
7883 #define ELF_ET_DYN_BASE 0x0000010000000000UL
7884 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
7885
7886+#ifdef CONFIG_PAX_ASLR
7887+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
7888+
7889+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
7890+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
7891+#endif
7892+
7893 extern unsigned long sparc64_elf_hwcap;
7894 #define ELF_HWCAP sparc64_elf_hwcap
7895
7896diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
7897index 9b1c36d..209298b 100644
7898--- a/arch/sparc/include/asm/pgalloc_32.h
7899+++ b/arch/sparc/include/asm/pgalloc_32.h
7900@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
7901 }
7902
7903 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
7904+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
7905
7906 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
7907 unsigned long address)
7908diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
7909index bcfe063..b333142 100644
7910--- a/arch/sparc/include/asm/pgalloc_64.h
7911+++ b/arch/sparc/include/asm/pgalloc_64.h
7912@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7913 }
7914
7915 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
7916+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
7917
7918 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
7919 {
7920diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
7921index 6fc1348..390c50a 100644
7922--- a/arch/sparc/include/asm/pgtable_32.h
7923+++ b/arch/sparc/include/asm/pgtable_32.h
7924@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
7925 #define PAGE_SHARED SRMMU_PAGE_SHARED
7926 #define PAGE_COPY SRMMU_PAGE_COPY
7927 #define PAGE_READONLY SRMMU_PAGE_RDONLY
7928+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
7929+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
7930+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
7931 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
7932
7933 /* Top-level page directory - dummy used by init-mm.
7934@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
7935
7936 /* xwr */
7937 #define __P000 PAGE_NONE
7938-#define __P001 PAGE_READONLY
7939-#define __P010 PAGE_COPY
7940-#define __P011 PAGE_COPY
7941+#define __P001 PAGE_READONLY_NOEXEC
7942+#define __P010 PAGE_COPY_NOEXEC
7943+#define __P011 PAGE_COPY_NOEXEC
7944 #define __P100 PAGE_READONLY
7945 #define __P101 PAGE_READONLY
7946 #define __P110 PAGE_COPY
7947 #define __P111 PAGE_COPY
7948
7949 #define __S000 PAGE_NONE
7950-#define __S001 PAGE_READONLY
7951-#define __S010 PAGE_SHARED
7952-#define __S011 PAGE_SHARED
7953+#define __S001 PAGE_READONLY_NOEXEC
7954+#define __S010 PAGE_SHARED_NOEXEC
7955+#define __S011 PAGE_SHARED_NOEXEC
7956 #define __S100 PAGE_READONLY
7957 #define __S101 PAGE_READONLY
7958 #define __S110 PAGE_SHARED
7959diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
7960index 79da178..c2eede8 100644
7961--- a/arch/sparc/include/asm/pgtsrmmu.h
7962+++ b/arch/sparc/include/asm/pgtsrmmu.h
7963@@ -115,6 +115,11 @@
7964 SRMMU_EXEC | SRMMU_REF)
7965 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
7966 SRMMU_EXEC | SRMMU_REF)
7967+
7968+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
7969+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7970+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7971+
7972 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
7973 SRMMU_DIRTY | SRMMU_REF)
7974
7975diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
7976index 9689176..63c18ea 100644
7977--- a/arch/sparc/include/asm/spinlock_64.h
7978+++ b/arch/sparc/include/asm/spinlock_64.h
7979@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
7980
7981 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
7982
7983-static void inline arch_read_lock(arch_rwlock_t *lock)
7984+static inline void arch_read_lock(arch_rwlock_t *lock)
7985 {
7986 unsigned long tmp1, tmp2;
7987
7988 __asm__ __volatile__ (
7989 "1: ldsw [%2], %0\n"
7990 " brlz,pn %0, 2f\n"
7991-"4: add %0, 1, %1\n"
7992+"4: addcc %0, 1, %1\n"
7993+
7994+#ifdef CONFIG_PAX_REFCOUNT
7995+" tvs %%icc, 6\n"
7996+#endif
7997+
7998 " cas [%2], %0, %1\n"
7999 " cmp %0, %1\n"
8000 " bne,pn %%icc, 1b\n"
8001@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
8002 " .previous"
8003 : "=&r" (tmp1), "=&r" (tmp2)
8004 : "r" (lock)
8005- : "memory");
8006+ : "memory", "cc");
8007 }
8008
8009-static int inline arch_read_trylock(arch_rwlock_t *lock)
8010+static inline int arch_read_trylock(arch_rwlock_t *lock)
8011 {
8012 int tmp1, tmp2;
8013
8014@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8015 "1: ldsw [%2], %0\n"
8016 " brlz,a,pn %0, 2f\n"
8017 " mov 0, %0\n"
8018-" add %0, 1, %1\n"
8019+" addcc %0, 1, %1\n"
8020+
8021+#ifdef CONFIG_PAX_REFCOUNT
8022+" tvs %%icc, 6\n"
8023+#endif
8024+
8025 " cas [%2], %0, %1\n"
8026 " cmp %0, %1\n"
8027 " bne,pn %%icc, 1b\n"
8028@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8029 return tmp1;
8030 }
8031
8032-static void inline arch_read_unlock(arch_rwlock_t *lock)
8033+static inline void arch_read_unlock(arch_rwlock_t *lock)
8034 {
8035 unsigned long tmp1, tmp2;
8036
8037 __asm__ __volatile__(
8038 "1: lduw [%2], %0\n"
8039-" sub %0, 1, %1\n"
8040+" subcc %0, 1, %1\n"
8041+
8042+#ifdef CONFIG_PAX_REFCOUNT
8043+" tvs %%icc, 6\n"
8044+#endif
8045+
8046 " cas [%2], %0, %1\n"
8047 " cmp %0, %1\n"
8048 " bne,pn %%xcc, 1b\n"
8049@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
8050 : "memory");
8051 }
8052
8053-static void inline arch_write_lock(arch_rwlock_t *lock)
8054+static inline void arch_write_lock(arch_rwlock_t *lock)
8055 {
8056 unsigned long mask, tmp1, tmp2;
8057
8058@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
8059 : "memory");
8060 }
8061
8062-static void inline arch_write_unlock(arch_rwlock_t *lock)
8063+static inline void arch_write_unlock(arch_rwlock_t *lock)
8064 {
8065 __asm__ __volatile__(
8066 " stw %%g0, [%0]"
8067@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
8068 : "memory");
8069 }
8070
8071-static int inline arch_write_trylock(arch_rwlock_t *lock)
8072+static inline int arch_write_trylock(arch_rwlock_t *lock)
8073 {
8074 unsigned long mask, tmp1, tmp2, result;
8075
8076diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
8077index 25849ae..924c54b 100644
8078--- a/arch/sparc/include/asm/thread_info_32.h
8079+++ b/arch/sparc/include/asm/thread_info_32.h
8080@@ -49,6 +49,8 @@ struct thread_info {
8081 unsigned long w_saved;
8082
8083 struct restart_block restart_block;
8084+
8085+ unsigned long lowest_stack;
8086 };
8087
8088 /*
8089diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
8090index 269bd92..e46a9b8 100644
8091--- a/arch/sparc/include/asm/thread_info_64.h
8092+++ b/arch/sparc/include/asm/thread_info_64.h
8093@@ -63,6 +63,8 @@ struct thread_info {
8094 struct pt_regs *kern_una_regs;
8095 unsigned int kern_una_insn;
8096
8097+ unsigned long lowest_stack;
8098+
8099 unsigned long fpregs[0] __attribute__ ((aligned(64)));
8100 };
8101
8102@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
8103 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
8104 /* flag bit 6 is available */
8105 #define TIF_32BIT 7 /* 32-bit binary */
8106-/* flag bit 8 is available */
8107+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
8108 #define TIF_SECCOMP 9 /* secure computing */
8109 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
8110 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
8111+
8112 /* NOTE: Thread flags >= 12 should be ones we have no interest
8113 * in using in assembly, else we can't use the mask as
8114 * an immediate value in instructions such as andcc.
8115@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
8116 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
8117 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8118 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
8119+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8120
8121 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
8122 _TIF_DO_NOTIFY_RESUME_MASK | \
8123 _TIF_NEED_RESCHED)
8124 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
8125
8126+#define _TIF_WORK_SYSCALL \
8127+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
8128+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
8129+
8130+
8131 /*
8132 * Thread-synchronous status.
8133 *
8134diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
8135index 0167d26..767bb0c 100644
8136--- a/arch/sparc/include/asm/uaccess.h
8137+++ b/arch/sparc/include/asm/uaccess.h
8138@@ -1,5 +1,6 @@
8139 #ifndef ___ASM_SPARC_UACCESS_H
8140 #define ___ASM_SPARC_UACCESS_H
8141+
8142 #if defined(__sparc__) && defined(__arch64__)
8143 #include <asm/uaccess_64.h>
8144 #else
8145diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
8146index 53a28dd..50c38c3 100644
8147--- a/arch/sparc/include/asm/uaccess_32.h
8148+++ b/arch/sparc/include/asm/uaccess_32.h
8149@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
8150
8151 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8152 {
8153- if (n && __access_ok((unsigned long) to, n))
8154+ if ((long)n < 0)
8155+ return n;
8156+
8157+ if (n && __access_ok((unsigned long) to, n)) {
8158+ if (!__builtin_constant_p(n))
8159+ check_object_size(from, n, true);
8160 return __copy_user(to, (__force void __user *) from, n);
8161- else
8162+ } else
8163 return n;
8164 }
8165
8166 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
8167 {
8168+ if ((long)n < 0)
8169+ return n;
8170+
8171+ if (!__builtin_constant_p(n))
8172+ check_object_size(from, n, true);
8173+
8174 return __copy_user(to, (__force void __user *) from, n);
8175 }
8176
8177 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8178 {
8179- if (n && __access_ok((unsigned long) from, n))
8180+ if ((long)n < 0)
8181+ return n;
8182+
8183+ if (n && __access_ok((unsigned long) from, n)) {
8184+ if (!__builtin_constant_p(n))
8185+ check_object_size(to, n, false);
8186 return __copy_user((__force void __user *) to, from, n);
8187- else
8188+ } else
8189 return n;
8190 }
8191
8192 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
8193 {
8194+ if ((long)n < 0)
8195+ return n;
8196+
8197 return __copy_user((__force void __user *) to, from, n);
8198 }
8199
8200diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
8201index e562d3c..191f176 100644
8202--- a/arch/sparc/include/asm/uaccess_64.h
8203+++ b/arch/sparc/include/asm/uaccess_64.h
8204@@ -10,6 +10,7 @@
8205 #include <linux/compiler.h>
8206 #include <linux/string.h>
8207 #include <linux/thread_info.h>
8208+#include <linux/kernel.h>
8209 #include <asm/asi.h>
8210 #include <asm/spitfire.h>
8211 #include <asm-generic/uaccess-unaligned.h>
8212@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
8213 static inline unsigned long __must_check
8214 copy_from_user(void *to, const void __user *from, unsigned long size)
8215 {
8216- unsigned long ret = ___copy_from_user(to, from, size);
8217+ unsigned long ret;
8218
8219+ if ((long)size < 0 || size > INT_MAX)
8220+ return size;
8221+
8222+ if (!__builtin_constant_p(size))
8223+ check_object_size(to, size, false);
8224+
8225+ ret = ___copy_from_user(to, from, size);
8226 if (unlikely(ret))
8227 ret = copy_from_user_fixup(to, from, size);
8228
8229@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
8230 static inline unsigned long __must_check
8231 copy_to_user(void __user *to, const void *from, unsigned long size)
8232 {
8233- unsigned long ret = ___copy_to_user(to, from, size);
8234+ unsigned long ret;
8235
8236+ if ((long)size < 0 || size > INT_MAX)
8237+ return size;
8238+
8239+ if (!__builtin_constant_p(size))
8240+ check_object_size(from, size, true);
8241+
8242+ ret = ___copy_to_user(to, from, size);
8243 if (unlikely(ret))
8244 ret = copy_to_user_fixup(to, from, size);
8245 return ret;
8246diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
8247index 6cf591b..b49e65a 100644
8248--- a/arch/sparc/kernel/Makefile
8249+++ b/arch/sparc/kernel/Makefile
8250@@ -3,7 +3,7 @@
8251 #
8252
8253 asflags-y := -ansi
8254-ccflags-y := -Werror
8255+#ccflags-y := -Werror
8256
8257 extra-y := head_$(BITS).o
8258
8259diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
8260index 62eede1..9c5b904 100644
8261--- a/arch/sparc/kernel/process_32.c
8262+++ b/arch/sparc/kernel/process_32.c
8263@@ -125,14 +125,14 @@ void show_regs(struct pt_regs *r)
8264
8265 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
8266 r->psr, r->pc, r->npc, r->y, print_tainted());
8267- printk("PC: <%pS>\n", (void *) r->pc);
8268+ printk("PC: <%pA>\n", (void *) r->pc);
8269 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8270 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
8271 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
8272 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8273 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
8274 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
8275- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
8276+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
8277
8278 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8279 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
8280@@ -167,7 +167,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8281 rw = (struct reg_window32 *) fp;
8282 pc = rw->ins[7];
8283 printk("[%08lx : ", pc);
8284- printk("%pS ] ", (void *) pc);
8285+ printk("%pA ] ", (void *) pc);
8286 fp = rw->ins[6];
8287 } while (++count < 16);
8288 printk("\n");
8289diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
8290index cdb80b2..5ca141d 100644
8291--- a/arch/sparc/kernel/process_64.c
8292+++ b/arch/sparc/kernel/process_64.c
8293@@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
8294 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
8295 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
8296 if (regs->tstate & TSTATE_PRIV)
8297- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
8298+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
8299 }
8300
8301 void show_regs(struct pt_regs *regs)
8302 {
8303 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
8304 regs->tpc, regs->tnpc, regs->y, print_tainted());
8305- printk("TPC: <%pS>\n", (void *) regs->tpc);
8306+ printk("TPC: <%pA>\n", (void *) regs->tpc);
8307 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
8308 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
8309 regs->u_regs[3]);
8310@@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
8311 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
8312 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
8313 regs->u_regs[15]);
8314- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
8315+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
8316 show_regwindow(regs);
8317 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
8318 }
8319@@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
8320 ((tp && tp->task) ? tp->task->pid : -1));
8321
8322 if (gp->tstate & TSTATE_PRIV) {
8323- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
8324+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
8325 (void *) gp->tpc,
8326 (void *) gp->o7,
8327 (void *) gp->i7,
8328diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
8329index 9f20566..67eb41b 100644
8330--- a/arch/sparc/kernel/prom_common.c
8331+++ b/arch/sparc/kernel/prom_common.c
8332@@ -143,7 +143,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
8333
8334 unsigned int prom_early_allocated __initdata;
8335
8336-static struct of_pdt_ops prom_sparc_ops __initdata = {
8337+static struct of_pdt_ops prom_sparc_ops __initconst = {
8338 .nextprop = prom_common_nextprop,
8339 .getproplen = prom_getproplen,
8340 .getproperty = prom_getproperty,
8341diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
8342index 7ff45e4..a58f271 100644
8343--- a/arch/sparc/kernel/ptrace_64.c
8344+++ b/arch/sparc/kernel/ptrace_64.c
8345@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
8346 return ret;
8347 }
8348
8349+#ifdef CONFIG_GRKERNSEC_SETXID
8350+extern void gr_delayed_cred_worker(void);
8351+#endif
8352+
8353 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8354 {
8355 int ret = 0;
8356@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8357 /* do the secure computing check first */
8358 secure_computing_strict(regs->u_regs[UREG_G1]);
8359
8360+#ifdef CONFIG_GRKERNSEC_SETXID
8361+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8362+ gr_delayed_cred_worker();
8363+#endif
8364+
8365 if (test_thread_flag(TIF_SYSCALL_TRACE))
8366 ret = tracehook_report_syscall_entry(regs);
8367
8368@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8369
8370 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
8371 {
8372+#ifdef CONFIG_GRKERNSEC_SETXID
8373+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8374+ gr_delayed_cred_worker();
8375+#endif
8376+
8377 audit_syscall_exit(regs);
8378
8379 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8380diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
8381index 3a8d184..49498a8 100644
8382--- a/arch/sparc/kernel/sys_sparc_32.c
8383+++ b/arch/sparc/kernel/sys_sparc_32.c
8384@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8385 if (len > TASK_SIZE - PAGE_SIZE)
8386 return -ENOMEM;
8387 if (!addr)
8388- addr = TASK_UNMAPPED_BASE;
8389+ addr = current->mm->mmap_base;
8390
8391 info.flags = 0;
8392 info.length = len;
8393diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
8394index 708bc29..6bfdfad 100644
8395--- a/arch/sparc/kernel/sys_sparc_64.c
8396+++ b/arch/sparc/kernel/sys_sparc_64.c
8397@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8398 struct vm_area_struct * vma;
8399 unsigned long task_size = TASK_SIZE;
8400 int do_color_align;
8401+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8402 struct vm_unmapped_area_info info;
8403
8404 if (flags & MAP_FIXED) {
8405 /* We do not accept a shared mapping if it would violate
8406 * cache aliasing constraints.
8407 */
8408- if ((flags & MAP_SHARED) &&
8409+ if ((filp || (flags & MAP_SHARED)) &&
8410 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8411 return -EINVAL;
8412 return addr;
8413@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8414 if (filp || (flags & MAP_SHARED))
8415 do_color_align = 1;
8416
8417+#ifdef CONFIG_PAX_RANDMMAP
8418+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8419+#endif
8420+
8421 if (addr) {
8422 if (do_color_align)
8423 addr = COLOR_ALIGN(addr, pgoff);
8424@@ -118,22 +123,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8425 addr = PAGE_ALIGN(addr);
8426
8427 vma = find_vma(mm, addr);
8428- if (task_size - len >= addr &&
8429- (!vma || addr + len <= vma->vm_start))
8430+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8431 return addr;
8432 }
8433
8434 info.flags = 0;
8435 info.length = len;
8436- info.low_limit = TASK_UNMAPPED_BASE;
8437+ info.low_limit = mm->mmap_base;
8438 info.high_limit = min(task_size, VA_EXCLUDE_START);
8439 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8440 info.align_offset = pgoff << PAGE_SHIFT;
8441+ info.threadstack_offset = offset;
8442 addr = vm_unmapped_area(&info);
8443
8444 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
8445 VM_BUG_ON(addr != -ENOMEM);
8446 info.low_limit = VA_EXCLUDE_END;
8447+
8448+#ifdef CONFIG_PAX_RANDMMAP
8449+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8450+ info.low_limit += mm->delta_mmap;
8451+#endif
8452+
8453 info.high_limit = task_size;
8454 addr = vm_unmapped_area(&info);
8455 }
8456@@ -151,6 +162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8457 unsigned long task_size = STACK_TOP32;
8458 unsigned long addr = addr0;
8459 int do_color_align;
8460+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8461 struct vm_unmapped_area_info info;
8462
8463 /* This should only ever run for 32-bit processes. */
8464@@ -160,7 +172,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8465 /* We do not accept a shared mapping if it would violate
8466 * cache aliasing constraints.
8467 */
8468- if ((flags & MAP_SHARED) &&
8469+ if ((filp || (flags & MAP_SHARED)) &&
8470 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8471 return -EINVAL;
8472 return addr;
8473@@ -173,6 +185,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8474 if (filp || (flags & MAP_SHARED))
8475 do_color_align = 1;
8476
8477+#ifdef CONFIG_PAX_RANDMMAP
8478+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8479+#endif
8480+
8481 /* requesting a specific address */
8482 if (addr) {
8483 if (do_color_align)
8484@@ -181,8 +197,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8485 addr = PAGE_ALIGN(addr);
8486
8487 vma = find_vma(mm, addr);
8488- if (task_size - len >= addr &&
8489- (!vma || addr + len <= vma->vm_start))
8490+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8491 return addr;
8492 }
8493
8494@@ -192,6 +207,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8495 info.high_limit = mm->mmap_base;
8496 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8497 info.align_offset = pgoff << PAGE_SHIFT;
8498+ info.threadstack_offset = offset;
8499 addr = vm_unmapped_area(&info);
8500
8501 /*
8502@@ -204,6 +220,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8503 VM_BUG_ON(addr != -ENOMEM);
8504 info.flags = 0;
8505 info.low_limit = TASK_UNMAPPED_BASE;
8506+
8507+#ifdef CONFIG_PAX_RANDMMAP
8508+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8509+ info.low_limit += mm->delta_mmap;
8510+#endif
8511+
8512 info.high_limit = STACK_TOP32;
8513 addr = vm_unmapped_area(&info);
8514 }
8515@@ -264,6 +286,10 @@ static unsigned long mmap_rnd(void)
8516 {
8517 unsigned long rnd = 0UL;
8518
8519+#ifdef CONFIG_PAX_RANDMMAP
8520+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8521+#endif
8522+
8523 if (current->flags & PF_RANDOMIZE) {
8524 unsigned long val = get_random_int();
8525 if (test_thread_flag(TIF_32BIT))
8526@@ -289,6 +315,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8527 gap == RLIM_INFINITY ||
8528 sysctl_legacy_va_layout) {
8529 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
8530+
8531+#ifdef CONFIG_PAX_RANDMMAP
8532+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8533+ mm->mmap_base += mm->delta_mmap;
8534+#endif
8535+
8536 mm->get_unmapped_area = arch_get_unmapped_area;
8537 mm->unmap_area = arch_unmap_area;
8538 } else {
8539@@ -301,6 +333,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8540 gap = (task_size / 6 * 5);
8541
8542 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
8543+
8544+#ifdef CONFIG_PAX_RANDMMAP
8545+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8546+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8547+#endif
8548+
8549 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8550 mm->unmap_area = arch_unmap_area_topdown;
8551 }
8552diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
8553index 22a1098..6255eb9 100644
8554--- a/arch/sparc/kernel/syscalls.S
8555+++ b/arch/sparc/kernel/syscalls.S
8556@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
8557 #endif
8558 .align 32
8559 1: ldx [%g6 + TI_FLAGS], %l5
8560- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8561+ andcc %l5, _TIF_WORK_SYSCALL, %g0
8562 be,pt %icc, rtrap
8563 nop
8564 call syscall_trace_leave
8565@@ -184,7 +184,7 @@ linux_sparc_syscall32:
8566
8567 srl %i5, 0, %o5 ! IEU1
8568 srl %i2, 0, %o2 ! IEU0 Group
8569- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8570+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8571 bne,pn %icc, linux_syscall_trace32 ! CTI
8572 mov %i0, %l5 ! IEU1
8573 call %l7 ! CTI Group brk forced
8574@@ -207,7 +207,7 @@ linux_sparc_syscall:
8575
8576 mov %i3, %o3 ! IEU1
8577 mov %i4, %o4 ! IEU0 Group
8578- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8579+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8580 bne,pn %icc, linux_syscall_trace ! CTI Group
8581 mov %i0, %l5 ! IEU0
8582 2: call %l7 ! CTI Group brk forced
8583@@ -223,7 +223,7 @@ ret_sys_call:
8584
8585 cmp %o0, -ERESTART_RESTARTBLOCK
8586 bgeu,pn %xcc, 1f
8587- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8588+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8589 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
8590
8591 2:
8592diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
8593index 654e8aa..45f431b 100644
8594--- a/arch/sparc/kernel/sysfs.c
8595+++ b/arch/sparc/kernel/sysfs.c
8596@@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
8597 return NOTIFY_OK;
8598 }
8599
8600-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
8601+static struct notifier_block sysfs_cpu_nb = {
8602 .notifier_call = sysfs_cpu_notify,
8603 };
8604
8605diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
8606index 6629829..036032d 100644
8607--- a/arch/sparc/kernel/traps_32.c
8608+++ b/arch/sparc/kernel/traps_32.c
8609@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
8610 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
8611 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
8612
8613+extern void gr_handle_kernel_exploit(void);
8614+
8615 void die_if_kernel(char *str, struct pt_regs *regs)
8616 {
8617 static int die_counter;
8618@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8619 count++ < 30 &&
8620 (((unsigned long) rw) >= PAGE_OFFSET) &&
8621 !(((unsigned long) rw) & 0x7)) {
8622- printk("Caller[%08lx]: %pS\n", rw->ins[7],
8623+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
8624 (void *) rw->ins[7]);
8625 rw = (struct reg_window32 *)rw->ins[6];
8626 }
8627 }
8628 printk("Instruction DUMP:");
8629 instruction_dump ((unsigned long *) regs->pc);
8630- if(regs->psr & PSR_PS)
8631+ if(regs->psr & PSR_PS) {
8632+ gr_handle_kernel_exploit();
8633 do_exit(SIGKILL);
8634+ }
8635 do_exit(SIGSEGV);
8636 }
8637
8638diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
8639index 8d38ca9..845b1d6 100644
8640--- a/arch/sparc/kernel/traps_64.c
8641+++ b/arch/sparc/kernel/traps_64.c
8642@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
8643 i + 1,
8644 p->trapstack[i].tstate, p->trapstack[i].tpc,
8645 p->trapstack[i].tnpc, p->trapstack[i].tt);
8646- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
8647+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
8648 }
8649 }
8650
8651@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
8652
8653 lvl -= 0x100;
8654 if (regs->tstate & TSTATE_PRIV) {
8655+
8656+#ifdef CONFIG_PAX_REFCOUNT
8657+ if (lvl == 6)
8658+ pax_report_refcount_overflow(regs);
8659+#endif
8660+
8661 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
8662 die_if_kernel(buffer, regs);
8663 }
8664@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
8665 void bad_trap_tl1(struct pt_regs *regs, long lvl)
8666 {
8667 char buffer[32];
8668-
8669+
8670 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
8671 0, lvl, SIGTRAP) == NOTIFY_STOP)
8672 return;
8673
8674+#ifdef CONFIG_PAX_REFCOUNT
8675+ if (lvl == 6)
8676+ pax_report_refcount_overflow(regs);
8677+#endif
8678+
8679 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
8680
8681 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
8682@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
8683 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
8684 printk("%s" "ERROR(%d): ",
8685 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
8686- printk("TPC<%pS>\n", (void *) regs->tpc);
8687+ printk("TPC<%pA>\n", (void *) regs->tpc);
8688 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
8689 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
8690 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
8691@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8692 smp_processor_id(),
8693 (type & 0x1) ? 'I' : 'D',
8694 regs->tpc);
8695- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
8696+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
8697 panic("Irrecoverable Cheetah+ parity error.");
8698 }
8699
8700@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8701 smp_processor_id(),
8702 (type & 0x1) ? 'I' : 'D',
8703 regs->tpc);
8704- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
8705+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
8706 }
8707
8708 struct sun4v_error_entry {
8709@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
8710
8711 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
8712 regs->tpc, tl);
8713- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
8714+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
8715 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8716- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
8717+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
8718 (void *) regs->u_regs[UREG_I7]);
8719 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
8720 "pte[%lx] error[%lx]\n",
8721@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
8722
8723 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
8724 regs->tpc, tl);
8725- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
8726+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
8727 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8728- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
8729+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
8730 (void *) regs->u_regs[UREG_I7]);
8731 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
8732 "pte[%lx] error[%lx]\n",
8733@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8734 fp = (unsigned long)sf->fp + STACK_BIAS;
8735 }
8736
8737- printk(" [%016lx] %pS\n", pc, (void *) pc);
8738+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8739 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8740 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
8741 int index = tsk->curr_ret_stack;
8742 if (tsk->ret_stack && index >= graph) {
8743 pc = tsk->ret_stack[index - graph].ret;
8744- printk(" [%016lx] %pS\n", pc, (void *) pc);
8745+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8746 graph++;
8747 }
8748 }
8749@@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
8750 return (struct reg_window *) (fp + STACK_BIAS);
8751 }
8752
8753+extern void gr_handle_kernel_exploit(void);
8754+
8755 void die_if_kernel(char *str, struct pt_regs *regs)
8756 {
8757 static int die_counter;
8758@@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8759 while (rw &&
8760 count++ < 30 &&
8761 kstack_valid(tp, (unsigned long) rw)) {
8762- printk("Caller[%016lx]: %pS\n", rw->ins[7],
8763+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
8764 (void *) rw->ins[7]);
8765
8766 rw = kernel_stack_up(rw);
8767@@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8768 }
8769 user_instruction_dump ((unsigned int __user *) regs->tpc);
8770 }
8771- if (regs->tstate & TSTATE_PRIV)
8772+ if (regs->tstate & TSTATE_PRIV) {
8773+ gr_handle_kernel_exploit();
8774 do_exit(SIGKILL);
8775+ }
8776 do_exit(SIGSEGV);
8777 }
8778 EXPORT_SYMBOL(die_if_kernel);
8779diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
8780index 8201c25e..072a2a7 100644
8781--- a/arch/sparc/kernel/unaligned_64.c
8782+++ b/arch/sparc/kernel/unaligned_64.c
8783@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
8784 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
8785
8786 if (__ratelimit(&ratelimit)) {
8787- printk("Kernel unaligned access at TPC[%lx] %pS\n",
8788+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
8789 regs->tpc, (void *) regs->tpc);
8790 }
8791 }
8792diff --git a/arch/sparc/kernel/us3_cpufreq.c b/arch/sparc/kernel/us3_cpufreq.c
8793index eb1624b..55100de 100644
8794--- a/arch/sparc/kernel/us3_cpufreq.c
8795+++ b/arch/sparc/kernel/us3_cpufreq.c
8796@@ -18,14 +18,12 @@
8797 #include <asm/head.h>
8798 #include <asm/timer.h>
8799
8800-static struct cpufreq_driver *cpufreq_us3_driver;
8801-
8802 struct us3_freq_percpu_info {
8803 struct cpufreq_frequency_table table[4];
8804 };
8805
8806 /* Indexed by cpu number. */
8807-static struct us3_freq_percpu_info *us3_freq_table;
8808+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
8809
8810 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
8811 * in the Safari config register.
8812@@ -191,12 +189,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
8813
8814 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
8815 {
8816- if (cpufreq_us3_driver)
8817- us3_set_cpu_divider_index(policy->cpu, 0);
8818+ us3_set_cpu_divider_index(policy->cpu, 0);
8819
8820 return 0;
8821 }
8822
8823+static int __init us3_freq_init(void);
8824+static void __exit us3_freq_exit(void);
8825+
8826+static struct cpufreq_driver cpufreq_us3_driver = {
8827+ .init = us3_freq_cpu_init,
8828+ .verify = us3_freq_verify,
8829+ .target = us3_freq_target,
8830+ .get = us3_freq_get,
8831+ .exit = us3_freq_cpu_exit,
8832+ .owner = THIS_MODULE,
8833+ .name = "UltraSPARC-III",
8834+
8835+};
8836+
8837 static int __init us3_freq_init(void)
8838 {
8839 unsigned long manuf, impl, ver;
8840@@ -213,57 +224,15 @@ static int __init us3_freq_init(void)
8841 (impl == CHEETAH_IMPL ||
8842 impl == CHEETAH_PLUS_IMPL ||
8843 impl == JAGUAR_IMPL ||
8844- impl == PANTHER_IMPL)) {
8845- struct cpufreq_driver *driver;
8846-
8847- ret = -ENOMEM;
8848- driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL);
8849- if (!driver)
8850- goto err_out;
8851-
8852- us3_freq_table = kzalloc(
8853- (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
8854- GFP_KERNEL);
8855- if (!us3_freq_table)
8856- goto err_out;
8857-
8858- driver->init = us3_freq_cpu_init;
8859- driver->verify = us3_freq_verify;
8860- driver->target = us3_freq_target;
8861- driver->get = us3_freq_get;
8862- driver->exit = us3_freq_cpu_exit;
8863- driver->owner = THIS_MODULE,
8864- strcpy(driver->name, "UltraSPARC-III");
8865-
8866- cpufreq_us3_driver = driver;
8867- ret = cpufreq_register_driver(driver);
8868- if (ret)
8869- goto err_out;
8870-
8871- return 0;
8872-
8873-err_out:
8874- if (driver) {
8875- kfree(driver);
8876- cpufreq_us3_driver = NULL;
8877- }
8878- kfree(us3_freq_table);
8879- us3_freq_table = NULL;
8880- return ret;
8881- }
8882+ impl == PANTHER_IMPL))
8883+ return cpufreq_register_driver(&cpufreq_us3_driver);
8884
8885 return -ENODEV;
8886 }
8887
8888 static void __exit us3_freq_exit(void)
8889 {
8890- if (cpufreq_us3_driver) {
8891- cpufreq_unregister_driver(cpufreq_us3_driver);
8892- kfree(cpufreq_us3_driver);
8893- cpufreq_us3_driver = NULL;
8894- kfree(us3_freq_table);
8895- us3_freq_table = NULL;
8896- }
8897+ cpufreq_unregister_driver(&cpufreq_us3_driver);
8898 }
8899
8900 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
8901diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
8902index 8410065f2..4fd4ca22 100644
8903--- a/arch/sparc/lib/Makefile
8904+++ b/arch/sparc/lib/Makefile
8905@@ -2,7 +2,7 @@
8906 #
8907
8908 asflags-y := -ansi -DST_DIV0=0x02
8909-ccflags-y := -Werror
8910+#ccflags-y := -Werror
8911
8912 lib-$(CONFIG_SPARC32) += ashrdi3.o
8913 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
8914diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
8915index 85c233d..68500e0 100644
8916--- a/arch/sparc/lib/atomic_64.S
8917+++ b/arch/sparc/lib/atomic_64.S
8918@@ -17,7 +17,12 @@
8919 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8920 BACKOFF_SETUP(%o2)
8921 1: lduw [%o1], %g1
8922- add %g1, %o0, %g7
8923+ addcc %g1, %o0, %g7
8924+
8925+#ifdef CONFIG_PAX_REFCOUNT
8926+ tvs %icc, 6
8927+#endif
8928+
8929 cas [%o1], %g1, %g7
8930 cmp %g1, %g7
8931 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8932@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8933 2: BACKOFF_SPIN(%o2, %o3, 1b)
8934 ENDPROC(atomic_add)
8935
8936+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8937+ BACKOFF_SETUP(%o2)
8938+1: lduw [%o1], %g1
8939+ add %g1, %o0, %g7
8940+ cas [%o1], %g1, %g7
8941+ cmp %g1, %g7
8942+ bne,pn %icc, 2f
8943+ nop
8944+ retl
8945+ nop
8946+2: BACKOFF_SPIN(%o2, %o3, 1b)
8947+ENDPROC(atomic_add_unchecked)
8948+
8949 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8950 BACKOFF_SETUP(%o2)
8951 1: lduw [%o1], %g1
8952- sub %g1, %o0, %g7
8953+ subcc %g1, %o0, %g7
8954+
8955+#ifdef CONFIG_PAX_REFCOUNT
8956+ tvs %icc, 6
8957+#endif
8958+
8959 cas [%o1], %g1, %g7
8960 cmp %g1, %g7
8961 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8962@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8963 2: BACKOFF_SPIN(%o2, %o3, 1b)
8964 ENDPROC(atomic_sub)
8965
8966+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8967+ BACKOFF_SETUP(%o2)
8968+1: lduw [%o1], %g1
8969+ sub %g1, %o0, %g7
8970+ cas [%o1], %g1, %g7
8971+ cmp %g1, %g7
8972+ bne,pn %icc, 2f
8973+ nop
8974+ retl
8975+ nop
8976+2: BACKOFF_SPIN(%o2, %o3, 1b)
8977+ENDPROC(atomic_sub_unchecked)
8978+
8979 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8980 BACKOFF_SETUP(%o2)
8981 1: lduw [%o1], %g1
8982- add %g1, %o0, %g7
8983+ addcc %g1, %o0, %g7
8984+
8985+#ifdef CONFIG_PAX_REFCOUNT
8986+ tvs %icc, 6
8987+#endif
8988+
8989 cas [%o1], %g1, %g7
8990 cmp %g1, %g7
8991 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8992@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8993 2: BACKOFF_SPIN(%o2, %o3, 1b)
8994 ENDPROC(atomic_add_ret)
8995
8996+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8997+ BACKOFF_SETUP(%o2)
8998+1: lduw [%o1], %g1
8999+ addcc %g1, %o0, %g7
9000+ cas [%o1], %g1, %g7
9001+ cmp %g1, %g7
9002+ bne,pn %icc, 2f
9003+ add %g7, %o0, %g7
9004+ sra %g7, 0, %o0
9005+ retl
9006+ nop
9007+2: BACKOFF_SPIN(%o2, %o3, 1b)
9008+ENDPROC(atomic_add_ret_unchecked)
9009+
9010 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
9011 BACKOFF_SETUP(%o2)
9012 1: lduw [%o1], %g1
9013- sub %g1, %o0, %g7
9014+ subcc %g1, %o0, %g7
9015+
9016+#ifdef CONFIG_PAX_REFCOUNT
9017+ tvs %icc, 6
9018+#endif
9019+
9020 cas [%o1], %g1, %g7
9021 cmp %g1, %g7
9022 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
9023@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
9024 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
9025 BACKOFF_SETUP(%o2)
9026 1: ldx [%o1], %g1
9027- add %g1, %o0, %g7
9028+ addcc %g1, %o0, %g7
9029+
9030+#ifdef CONFIG_PAX_REFCOUNT
9031+ tvs %xcc, 6
9032+#endif
9033+
9034 casx [%o1], %g1, %g7
9035 cmp %g1, %g7
9036 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9037@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
9038 2: BACKOFF_SPIN(%o2, %o3, 1b)
9039 ENDPROC(atomic64_add)
9040
9041+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9042+ BACKOFF_SETUP(%o2)
9043+1: ldx [%o1], %g1
9044+ addcc %g1, %o0, %g7
9045+ casx [%o1], %g1, %g7
9046+ cmp %g1, %g7
9047+ bne,pn %xcc, 2f
9048+ nop
9049+ retl
9050+ nop
9051+2: BACKOFF_SPIN(%o2, %o3, 1b)
9052+ENDPROC(atomic64_add_unchecked)
9053+
9054 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9055 BACKOFF_SETUP(%o2)
9056 1: ldx [%o1], %g1
9057- sub %g1, %o0, %g7
9058+ subcc %g1, %o0, %g7
9059+
9060+#ifdef CONFIG_PAX_REFCOUNT
9061+ tvs %xcc, 6
9062+#endif
9063+
9064 casx [%o1], %g1, %g7
9065 cmp %g1, %g7
9066 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9067@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9068 2: BACKOFF_SPIN(%o2, %o3, 1b)
9069 ENDPROC(atomic64_sub)
9070
9071+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
9072+ BACKOFF_SETUP(%o2)
9073+1: ldx [%o1], %g1
9074+ subcc %g1, %o0, %g7
9075+ casx [%o1], %g1, %g7
9076+ cmp %g1, %g7
9077+ bne,pn %xcc, 2f
9078+ nop
9079+ retl
9080+ nop
9081+2: BACKOFF_SPIN(%o2, %o3, 1b)
9082+ENDPROC(atomic64_sub_unchecked)
9083+
9084 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9085 BACKOFF_SETUP(%o2)
9086 1: ldx [%o1], %g1
9087- add %g1, %o0, %g7
9088+ addcc %g1, %o0, %g7
9089+
9090+#ifdef CONFIG_PAX_REFCOUNT
9091+ tvs %xcc, 6
9092+#endif
9093+
9094 casx [%o1], %g1, %g7
9095 cmp %g1, %g7
9096 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9097@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9098 2: BACKOFF_SPIN(%o2, %o3, 1b)
9099 ENDPROC(atomic64_add_ret)
9100
9101+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9102+ BACKOFF_SETUP(%o2)
9103+1: ldx [%o1], %g1
9104+ addcc %g1, %o0, %g7
9105+ casx [%o1], %g1, %g7
9106+ cmp %g1, %g7
9107+ bne,pn %xcc, 2f
9108+ add %g7, %o0, %g7
9109+ mov %g7, %o0
9110+ retl
9111+ nop
9112+2: BACKOFF_SPIN(%o2, %o3, 1b)
9113+ENDPROC(atomic64_add_ret_unchecked)
9114+
9115 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
9116 BACKOFF_SETUP(%o2)
9117 1: ldx [%o1], %g1
9118- sub %g1, %o0, %g7
9119+ subcc %g1, %o0, %g7
9120+
9121+#ifdef CONFIG_PAX_REFCOUNT
9122+ tvs %xcc, 6
9123+#endif
9124+
9125 casx [%o1], %g1, %g7
9126 cmp %g1, %g7
9127 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9128diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
9129index 0c4e35e..745d3e4 100644
9130--- a/arch/sparc/lib/ksyms.c
9131+++ b/arch/sparc/lib/ksyms.c
9132@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
9133
9134 /* Atomic counter implementation. */
9135 EXPORT_SYMBOL(atomic_add);
9136+EXPORT_SYMBOL(atomic_add_unchecked);
9137 EXPORT_SYMBOL(atomic_add_ret);
9138+EXPORT_SYMBOL(atomic_add_ret_unchecked);
9139 EXPORT_SYMBOL(atomic_sub);
9140+EXPORT_SYMBOL(atomic_sub_unchecked);
9141 EXPORT_SYMBOL(atomic_sub_ret);
9142 EXPORT_SYMBOL(atomic64_add);
9143+EXPORT_SYMBOL(atomic64_add_unchecked);
9144 EXPORT_SYMBOL(atomic64_add_ret);
9145+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
9146 EXPORT_SYMBOL(atomic64_sub);
9147+EXPORT_SYMBOL(atomic64_sub_unchecked);
9148 EXPORT_SYMBOL(atomic64_sub_ret);
9149 EXPORT_SYMBOL(atomic64_dec_if_positive);
9150
9151diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
9152index 30c3ecc..736f015 100644
9153--- a/arch/sparc/mm/Makefile
9154+++ b/arch/sparc/mm/Makefile
9155@@ -2,7 +2,7 @@
9156 #
9157
9158 asflags-y := -ansi
9159-ccflags-y := -Werror
9160+#ccflags-y := -Werror
9161
9162 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
9163 obj-y += fault_$(BITS).o
9164diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
9165index e98bfda..ea8d221 100644
9166--- a/arch/sparc/mm/fault_32.c
9167+++ b/arch/sparc/mm/fault_32.c
9168@@ -21,6 +21,9 @@
9169 #include <linux/perf_event.h>
9170 #include <linux/interrupt.h>
9171 #include <linux/kdebug.h>
9172+#include <linux/slab.h>
9173+#include <linux/pagemap.h>
9174+#include <linux/compiler.h>
9175
9176 #include <asm/page.h>
9177 #include <asm/pgtable.h>
9178@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
9179 return safe_compute_effective_address(regs, insn);
9180 }
9181
9182+#ifdef CONFIG_PAX_PAGEEXEC
9183+#ifdef CONFIG_PAX_DLRESOLVE
9184+static void pax_emuplt_close(struct vm_area_struct *vma)
9185+{
9186+ vma->vm_mm->call_dl_resolve = 0UL;
9187+}
9188+
9189+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9190+{
9191+ unsigned int *kaddr;
9192+
9193+ vmf->page = alloc_page(GFP_HIGHUSER);
9194+ if (!vmf->page)
9195+ return VM_FAULT_OOM;
9196+
9197+ kaddr = kmap(vmf->page);
9198+ memset(kaddr, 0, PAGE_SIZE);
9199+ kaddr[0] = 0x9DE3BFA8U; /* save */
9200+ flush_dcache_page(vmf->page);
9201+ kunmap(vmf->page);
9202+ return VM_FAULT_MAJOR;
9203+}
9204+
9205+static const struct vm_operations_struct pax_vm_ops = {
9206+ .close = pax_emuplt_close,
9207+ .fault = pax_emuplt_fault
9208+};
9209+
9210+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9211+{
9212+ int ret;
9213+
9214+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9215+ vma->vm_mm = current->mm;
9216+ vma->vm_start = addr;
9217+ vma->vm_end = addr + PAGE_SIZE;
9218+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9219+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9220+ vma->vm_ops = &pax_vm_ops;
9221+
9222+ ret = insert_vm_struct(current->mm, vma);
9223+ if (ret)
9224+ return ret;
9225+
9226+ ++current->mm->total_vm;
9227+ return 0;
9228+}
9229+#endif
9230+
9231+/*
9232+ * PaX: decide what to do with offenders (regs->pc = fault address)
9233+ *
9234+ * returns 1 when task should be killed
9235+ * 2 when patched PLT trampoline was detected
9236+ * 3 when unpatched PLT trampoline was detected
9237+ */
9238+static int pax_handle_fetch_fault(struct pt_regs *regs)
9239+{
9240+
9241+#ifdef CONFIG_PAX_EMUPLT
9242+ int err;
9243+
9244+ do { /* PaX: patched PLT emulation #1 */
9245+ unsigned int sethi1, sethi2, jmpl;
9246+
9247+ err = get_user(sethi1, (unsigned int *)regs->pc);
9248+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
9249+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
9250+
9251+ if (err)
9252+ break;
9253+
9254+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9255+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9256+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9257+ {
9258+ unsigned int addr;
9259+
9260+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9261+ addr = regs->u_regs[UREG_G1];
9262+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9263+ regs->pc = addr;
9264+ regs->npc = addr+4;
9265+ return 2;
9266+ }
9267+ } while (0);
9268+
9269+ do { /* PaX: patched PLT emulation #2 */
9270+ unsigned int ba;
9271+
9272+ err = get_user(ba, (unsigned int *)regs->pc);
9273+
9274+ if (err)
9275+ break;
9276+
9277+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9278+ unsigned int addr;
9279+
9280+ if ((ba & 0xFFC00000U) == 0x30800000U)
9281+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9282+ else
9283+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9284+ regs->pc = addr;
9285+ regs->npc = addr+4;
9286+ return 2;
9287+ }
9288+ } while (0);
9289+
9290+ do { /* PaX: patched PLT emulation #3 */
9291+ unsigned int sethi, bajmpl, nop;
9292+
9293+ err = get_user(sethi, (unsigned int *)regs->pc);
9294+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
9295+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9296+
9297+ if (err)
9298+ break;
9299+
9300+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9301+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9302+ nop == 0x01000000U)
9303+ {
9304+ unsigned int addr;
9305+
9306+ addr = (sethi & 0x003FFFFFU) << 10;
9307+ regs->u_regs[UREG_G1] = addr;
9308+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9309+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9310+ else
9311+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9312+ regs->pc = addr;
9313+ regs->npc = addr+4;
9314+ return 2;
9315+ }
9316+ } while (0);
9317+
9318+ do { /* PaX: unpatched PLT emulation step 1 */
9319+ unsigned int sethi, ba, nop;
9320+
9321+ err = get_user(sethi, (unsigned int *)regs->pc);
9322+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
9323+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9324+
9325+ if (err)
9326+ break;
9327+
9328+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9329+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9330+ nop == 0x01000000U)
9331+ {
9332+ unsigned int addr, save, call;
9333+
9334+ if ((ba & 0xFFC00000U) == 0x30800000U)
9335+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9336+ else
9337+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9338+
9339+ err = get_user(save, (unsigned int *)addr);
9340+ err |= get_user(call, (unsigned int *)(addr+4));
9341+ err |= get_user(nop, (unsigned int *)(addr+8));
9342+ if (err)
9343+ break;
9344+
9345+#ifdef CONFIG_PAX_DLRESOLVE
9346+ if (save == 0x9DE3BFA8U &&
9347+ (call & 0xC0000000U) == 0x40000000U &&
9348+ nop == 0x01000000U)
9349+ {
9350+ struct vm_area_struct *vma;
9351+ unsigned long call_dl_resolve;
9352+
9353+ down_read(&current->mm->mmap_sem);
9354+ call_dl_resolve = current->mm->call_dl_resolve;
9355+ up_read(&current->mm->mmap_sem);
9356+ if (likely(call_dl_resolve))
9357+ goto emulate;
9358+
9359+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9360+
9361+ down_write(&current->mm->mmap_sem);
9362+ if (current->mm->call_dl_resolve) {
9363+ call_dl_resolve = current->mm->call_dl_resolve;
9364+ up_write(&current->mm->mmap_sem);
9365+ if (vma)
9366+ kmem_cache_free(vm_area_cachep, vma);
9367+ goto emulate;
9368+ }
9369+
9370+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9371+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9372+ up_write(&current->mm->mmap_sem);
9373+ if (vma)
9374+ kmem_cache_free(vm_area_cachep, vma);
9375+ return 1;
9376+ }
9377+
9378+ if (pax_insert_vma(vma, call_dl_resolve)) {
9379+ up_write(&current->mm->mmap_sem);
9380+ kmem_cache_free(vm_area_cachep, vma);
9381+ return 1;
9382+ }
9383+
9384+ current->mm->call_dl_resolve = call_dl_resolve;
9385+ up_write(&current->mm->mmap_sem);
9386+
9387+emulate:
9388+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9389+ regs->pc = call_dl_resolve;
9390+ regs->npc = addr+4;
9391+ return 3;
9392+ }
9393+#endif
9394+
9395+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9396+ if ((save & 0xFFC00000U) == 0x05000000U &&
9397+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9398+ nop == 0x01000000U)
9399+ {
9400+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9401+ regs->u_regs[UREG_G2] = addr + 4;
9402+ addr = (save & 0x003FFFFFU) << 10;
9403+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9404+ regs->pc = addr;
9405+ regs->npc = addr+4;
9406+ return 3;
9407+ }
9408+ }
9409+ } while (0);
9410+
9411+ do { /* PaX: unpatched PLT emulation step 2 */
9412+ unsigned int save, call, nop;
9413+
9414+ err = get_user(save, (unsigned int *)(regs->pc-4));
9415+ err |= get_user(call, (unsigned int *)regs->pc);
9416+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
9417+ if (err)
9418+ break;
9419+
9420+ if (save == 0x9DE3BFA8U &&
9421+ (call & 0xC0000000U) == 0x40000000U &&
9422+ nop == 0x01000000U)
9423+ {
9424+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
9425+
9426+ regs->u_regs[UREG_RETPC] = regs->pc;
9427+ regs->pc = dl_resolve;
9428+ regs->npc = dl_resolve+4;
9429+ return 3;
9430+ }
9431+ } while (0);
9432+#endif
9433+
9434+ return 1;
9435+}
9436+
9437+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9438+{
9439+ unsigned long i;
9440+
9441+ printk(KERN_ERR "PAX: bytes at PC: ");
9442+ for (i = 0; i < 8; i++) {
9443+ unsigned int c;
9444+ if (get_user(c, (unsigned int *)pc+i))
9445+ printk(KERN_CONT "???????? ");
9446+ else
9447+ printk(KERN_CONT "%08x ", c);
9448+ }
9449+ printk("\n");
9450+}
9451+#endif
9452+
9453 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
9454 int text_fault)
9455 {
9456@@ -230,6 +504,24 @@ good_area:
9457 if (!(vma->vm_flags & VM_WRITE))
9458 goto bad_area;
9459 } else {
9460+
9461+#ifdef CONFIG_PAX_PAGEEXEC
9462+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
9463+ up_read(&mm->mmap_sem);
9464+ switch (pax_handle_fetch_fault(regs)) {
9465+
9466+#ifdef CONFIG_PAX_EMUPLT
9467+ case 2:
9468+ case 3:
9469+ return;
9470+#endif
9471+
9472+ }
9473+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
9474+ do_group_exit(SIGKILL);
9475+ }
9476+#endif
9477+
9478 /* Allow reads even for write-only mappings */
9479 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
9480 goto bad_area;
9481diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
9482index 5062ff3..e0b75f3 100644
9483--- a/arch/sparc/mm/fault_64.c
9484+++ b/arch/sparc/mm/fault_64.c
9485@@ -21,6 +21,9 @@
9486 #include <linux/kprobes.h>
9487 #include <linux/kdebug.h>
9488 #include <linux/percpu.h>
9489+#include <linux/slab.h>
9490+#include <linux/pagemap.h>
9491+#include <linux/compiler.h>
9492
9493 #include <asm/page.h>
9494 #include <asm/pgtable.h>
9495@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
9496 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
9497 regs->tpc);
9498 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
9499- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
9500+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
9501 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
9502 dump_stack();
9503 unhandled_fault(regs->tpc, current, regs);
9504@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
9505 show_regs(regs);
9506 }
9507
9508+#ifdef CONFIG_PAX_PAGEEXEC
9509+#ifdef CONFIG_PAX_DLRESOLVE
9510+static void pax_emuplt_close(struct vm_area_struct *vma)
9511+{
9512+ vma->vm_mm->call_dl_resolve = 0UL;
9513+}
9514+
9515+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9516+{
9517+ unsigned int *kaddr;
9518+
9519+ vmf->page = alloc_page(GFP_HIGHUSER);
9520+ if (!vmf->page)
9521+ return VM_FAULT_OOM;
9522+
9523+ kaddr = kmap(vmf->page);
9524+ memset(kaddr, 0, PAGE_SIZE);
9525+ kaddr[0] = 0x9DE3BFA8U; /* save */
9526+ flush_dcache_page(vmf->page);
9527+ kunmap(vmf->page);
9528+ return VM_FAULT_MAJOR;
9529+}
9530+
9531+static const struct vm_operations_struct pax_vm_ops = {
9532+ .close = pax_emuplt_close,
9533+ .fault = pax_emuplt_fault
9534+};
9535+
9536+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9537+{
9538+ int ret;
9539+
9540+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9541+ vma->vm_mm = current->mm;
9542+ vma->vm_start = addr;
9543+ vma->vm_end = addr + PAGE_SIZE;
9544+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9545+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9546+ vma->vm_ops = &pax_vm_ops;
9547+
9548+ ret = insert_vm_struct(current->mm, vma);
9549+ if (ret)
9550+ return ret;
9551+
9552+ ++current->mm->total_vm;
9553+ return 0;
9554+}
9555+#endif
9556+
9557+/*
9558+ * PaX: decide what to do with offenders (regs->tpc = fault address)
9559+ *
9560+ * returns 1 when task should be killed
9561+ * 2 when patched PLT trampoline was detected
9562+ * 3 when unpatched PLT trampoline was detected
9563+ */
9564+static int pax_handle_fetch_fault(struct pt_regs *regs)
9565+{
9566+
9567+#ifdef CONFIG_PAX_EMUPLT
9568+ int err;
9569+
9570+ do { /* PaX: patched PLT emulation #1 */
9571+ unsigned int sethi1, sethi2, jmpl;
9572+
9573+ err = get_user(sethi1, (unsigned int *)regs->tpc);
9574+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
9575+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
9576+
9577+ if (err)
9578+ break;
9579+
9580+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9581+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9582+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9583+ {
9584+ unsigned long addr;
9585+
9586+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9587+ addr = regs->u_regs[UREG_G1];
9588+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9589+
9590+ if (test_thread_flag(TIF_32BIT))
9591+ addr &= 0xFFFFFFFFUL;
9592+
9593+ regs->tpc = addr;
9594+ regs->tnpc = addr+4;
9595+ return 2;
9596+ }
9597+ } while (0);
9598+
9599+ do { /* PaX: patched PLT emulation #2 */
9600+ unsigned int ba;
9601+
9602+ err = get_user(ba, (unsigned int *)regs->tpc);
9603+
9604+ if (err)
9605+ break;
9606+
9607+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9608+ unsigned long addr;
9609+
9610+ if ((ba & 0xFFC00000U) == 0x30800000U)
9611+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9612+ else
9613+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9614+
9615+ if (test_thread_flag(TIF_32BIT))
9616+ addr &= 0xFFFFFFFFUL;
9617+
9618+ regs->tpc = addr;
9619+ regs->tnpc = addr+4;
9620+ return 2;
9621+ }
9622+ } while (0);
9623+
9624+ do { /* PaX: patched PLT emulation #3 */
9625+ unsigned int sethi, bajmpl, nop;
9626+
9627+ err = get_user(sethi, (unsigned int *)regs->tpc);
9628+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
9629+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9630+
9631+ if (err)
9632+ break;
9633+
9634+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9635+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9636+ nop == 0x01000000U)
9637+ {
9638+ unsigned long addr;
9639+
9640+ addr = (sethi & 0x003FFFFFU) << 10;
9641+ regs->u_regs[UREG_G1] = addr;
9642+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9643+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9644+ else
9645+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9646+
9647+ if (test_thread_flag(TIF_32BIT))
9648+ addr &= 0xFFFFFFFFUL;
9649+
9650+ regs->tpc = addr;
9651+ regs->tnpc = addr+4;
9652+ return 2;
9653+ }
9654+ } while (0);
9655+
9656+ do { /* PaX: patched PLT emulation #4 */
9657+ unsigned int sethi, mov1, call, mov2;
9658+
9659+ err = get_user(sethi, (unsigned int *)regs->tpc);
9660+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
9661+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
9662+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
9663+
9664+ if (err)
9665+ break;
9666+
9667+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9668+ mov1 == 0x8210000FU &&
9669+ (call & 0xC0000000U) == 0x40000000U &&
9670+ mov2 == 0x9E100001U)
9671+ {
9672+ unsigned long addr;
9673+
9674+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
9675+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9676+
9677+ if (test_thread_flag(TIF_32BIT))
9678+ addr &= 0xFFFFFFFFUL;
9679+
9680+ regs->tpc = addr;
9681+ regs->tnpc = addr+4;
9682+ return 2;
9683+ }
9684+ } while (0);
9685+
9686+ do { /* PaX: patched PLT emulation #5 */
9687+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
9688+
9689+ err = get_user(sethi, (unsigned int *)regs->tpc);
9690+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9691+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9692+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
9693+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
9694+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
9695+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
9696+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
9697+
9698+ if (err)
9699+ break;
9700+
9701+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9702+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9703+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9704+ (or1 & 0xFFFFE000U) == 0x82106000U &&
9705+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9706+ sllx == 0x83287020U &&
9707+ jmpl == 0x81C04005U &&
9708+ nop == 0x01000000U)
9709+ {
9710+ unsigned long addr;
9711+
9712+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9713+ regs->u_regs[UREG_G1] <<= 32;
9714+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9715+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9716+ regs->tpc = addr;
9717+ regs->tnpc = addr+4;
9718+ return 2;
9719+ }
9720+ } while (0);
9721+
9722+ do { /* PaX: patched PLT emulation #6 */
9723+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
9724+
9725+ err = get_user(sethi, (unsigned int *)regs->tpc);
9726+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9727+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9728+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
9729+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
9730+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
9731+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
9732+
9733+ if (err)
9734+ break;
9735+
9736+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9737+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9738+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9739+ sllx == 0x83287020U &&
9740+ (or & 0xFFFFE000U) == 0x8A116000U &&
9741+ jmpl == 0x81C04005U &&
9742+ nop == 0x01000000U)
9743+ {
9744+ unsigned long addr;
9745+
9746+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
9747+ regs->u_regs[UREG_G1] <<= 32;
9748+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
9749+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9750+ regs->tpc = addr;
9751+ regs->tnpc = addr+4;
9752+ return 2;
9753+ }
9754+ } while (0);
9755+
9756+ do { /* PaX: unpatched PLT emulation step 1 */
9757+ unsigned int sethi, ba, nop;
9758+
9759+ err = get_user(sethi, (unsigned int *)regs->tpc);
9760+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9761+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9762+
9763+ if (err)
9764+ break;
9765+
9766+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9767+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9768+ nop == 0x01000000U)
9769+ {
9770+ unsigned long addr;
9771+ unsigned int save, call;
9772+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
9773+
9774+ if ((ba & 0xFFC00000U) == 0x30800000U)
9775+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9776+ else
9777+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9778+
9779+ if (test_thread_flag(TIF_32BIT))
9780+ addr &= 0xFFFFFFFFUL;
9781+
9782+ err = get_user(save, (unsigned int *)addr);
9783+ err |= get_user(call, (unsigned int *)(addr+4));
9784+ err |= get_user(nop, (unsigned int *)(addr+8));
9785+ if (err)
9786+ break;
9787+
9788+#ifdef CONFIG_PAX_DLRESOLVE
9789+ if (save == 0x9DE3BFA8U &&
9790+ (call & 0xC0000000U) == 0x40000000U &&
9791+ nop == 0x01000000U)
9792+ {
9793+ struct vm_area_struct *vma;
9794+ unsigned long call_dl_resolve;
9795+
9796+ down_read(&current->mm->mmap_sem);
9797+ call_dl_resolve = current->mm->call_dl_resolve;
9798+ up_read(&current->mm->mmap_sem);
9799+ if (likely(call_dl_resolve))
9800+ goto emulate;
9801+
9802+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9803+
9804+ down_write(&current->mm->mmap_sem);
9805+ if (current->mm->call_dl_resolve) {
9806+ call_dl_resolve = current->mm->call_dl_resolve;
9807+ up_write(&current->mm->mmap_sem);
9808+ if (vma)
9809+ kmem_cache_free(vm_area_cachep, vma);
9810+ goto emulate;
9811+ }
9812+
9813+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9814+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9815+ up_write(&current->mm->mmap_sem);
9816+ if (vma)
9817+ kmem_cache_free(vm_area_cachep, vma);
9818+ return 1;
9819+ }
9820+
9821+ if (pax_insert_vma(vma, call_dl_resolve)) {
9822+ up_write(&current->mm->mmap_sem);
9823+ kmem_cache_free(vm_area_cachep, vma);
9824+ return 1;
9825+ }
9826+
9827+ current->mm->call_dl_resolve = call_dl_resolve;
9828+ up_write(&current->mm->mmap_sem);
9829+
9830+emulate:
9831+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9832+ regs->tpc = call_dl_resolve;
9833+ regs->tnpc = addr+4;
9834+ return 3;
9835+ }
9836+#endif
9837+
9838+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9839+ if ((save & 0xFFC00000U) == 0x05000000U &&
9840+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9841+ nop == 0x01000000U)
9842+ {
9843+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9844+ regs->u_regs[UREG_G2] = addr + 4;
9845+ addr = (save & 0x003FFFFFU) << 10;
9846+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9847+
9848+ if (test_thread_flag(TIF_32BIT))
9849+ addr &= 0xFFFFFFFFUL;
9850+
9851+ regs->tpc = addr;
9852+ regs->tnpc = addr+4;
9853+ return 3;
9854+ }
9855+
9856+ /* PaX: 64-bit PLT stub */
9857+ err = get_user(sethi1, (unsigned int *)addr);
9858+ err |= get_user(sethi2, (unsigned int *)(addr+4));
9859+ err |= get_user(or1, (unsigned int *)(addr+8));
9860+ err |= get_user(or2, (unsigned int *)(addr+12));
9861+ err |= get_user(sllx, (unsigned int *)(addr+16));
9862+ err |= get_user(add, (unsigned int *)(addr+20));
9863+ err |= get_user(jmpl, (unsigned int *)(addr+24));
9864+ err |= get_user(nop, (unsigned int *)(addr+28));
9865+ if (err)
9866+ break;
9867+
9868+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
9869+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9870+ (or1 & 0xFFFFE000U) == 0x88112000U &&
9871+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9872+ sllx == 0x89293020U &&
9873+ add == 0x8A010005U &&
9874+ jmpl == 0x89C14000U &&
9875+ nop == 0x01000000U)
9876+ {
9877+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9878+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9879+ regs->u_regs[UREG_G4] <<= 32;
9880+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9881+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
9882+ regs->u_regs[UREG_G4] = addr + 24;
9883+ addr = regs->u_regs[UREG_G5];
9884+ regs->tpc = addr;
9885+ regs->tnpc = addr+4;
9886+ return 3;
9887+ }
9888+ }
9889+ } while (0);
9890+
9891+#ifdef CONFIG_PAX_DLRESOLVE
9892+ do { /* PaX: unpatched PLT emulation step 2 */
9893+ unsigned int save, call, nop;
9894+
9895+ err = get_user(save, (unsigned int *)(regs->tpc-4));
9896+ err |= get_user(call, (unsigned int *)regs->tpc);
9897+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
9898+ if (err)
9899+ break;
9900+
9901+ if (save == 0x9DE3BFA8U &&
9902+ (call & 0xC0000000U) == 0x40000000U &&
9903+ nop == 0x01000000U)
9904+ {
9905+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9906+
9907+ if (test_thread_flag(TIF_32BIT))
9908+ dl_resolve &= 0xFFFFFFFFUL;
9909+
9910+ regs->u_regs[UREG_RETPC] = regs->tpc;
9911+ regs->tpc = dl_resolve;
9912+ regs->tnpc = dl_resolve+4;
9913+ return 3;
9914+ }
9915+ } while (0);
9916+#endif
9917+
9918+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
9919+ unsigned int sethi, ba, nop;
9920+
9921+ err = get_user(sethi, (unsigned int *)regs->tpc);
9922+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9923+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9924+
9925+ if (err)
9926+ break;
9927+
9928+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9929+ (ba & 0xFFF00000U) == 0x30600000U &&
9930+ nop == 0x01000000U)
9931+ {
9932+ unsigned long addr;
9933+
9934+ addr = (sethi & 0x003FFFFFU) << 10;
9935+ regs->u_regs[UREG_G1] = addr;
9936+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9937+
9938+ if (test_thread_flag(TIF_32BIT))
9939+ addr &= 0xFFFFFFFFUL;
9940+
9941+ regs->tpc = addr;
9942+ regs->tnpc = addr+4;
9943+ return 2;
9944+ }
9945+ } while (0);
9946+
9947+#endif
9948+
9949+ return 1;
9950+}
9951+
9952+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9953+{
9954+ unsigned long i;
9955+
9956+ printk(KERN_ERR "PAX: bytes at PC: ");
9957+ for (i = 0; i < 8; i++) {
9958+ unsigned int c;
9959+ if (get_user(c, (unsigned int *)pc+i))
9960+ printk(KERN_CONT "???????? ");
9961+ else
9962+ printk(KERN_CONT "%08x ", c);
9963+ }
9964+ printk("\n");
9965+}
9966+#endif
9967+
9968 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
9969 {
9970 struct mm_struct *mm = current->mm;
9971@@ -341,6 +804,29 @@ retry:
9972 if (!vma)
9973 goto bad_area;
9974
9975+#ifdef CONFIG_PAX_PAGEEXEC
9976+ /* PaX: detect ITLB misses on non-exec pages */
9977+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
9978+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
9979+ {
9980+ if (address != regs->tpc)
9981+ goto good_area;
9982+
9983+ up_read(&mm->mmap_sem);
9984+ switch (pax_handle_fetch_fault(regs)) {
9985+
9986+#ifdef CONFIG_PAX_EMUPLT
9987+ case 2:
9988+ case 3:
9989+ return;
9990+#endif
9991+
9992+ }
9993+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
9994+ do_group_exit(SIGKILL);
9995+ }
9996+#endif
9997+
9998 /* Pure DTLB misses do not tell us whether the fault causing
9999 * load/store/atomic was a write or not, it only says that there
10000 * was no match. So in such a case we (carefully) read the
10001diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
10002index d2b5944..bd813f2 100644
10003--- a/arch/sparc/mm/hugetlbpage.c
10004+++ b/arch/sparc/mm/hugetlbpage.c
10005@@ -38,7 +38,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
10006
10007 info.flags = 0;
10008 info.length = len;
10009- info.low_limit = TASK_UNMAPPED_BASE;
10010+ info.low_limit = mm->mmap_base;
10011 info.high_limit = min(task_size, VA_EXCLUDE_START);
10012 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
10013 info.align_offset = 0;
10014@@ -47,6 +47,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
10015 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10016 VM_BUG_ON(addr != -ENOMEM);
10017 info.low_limit = VA_EXCLUDE_END;
10018+
10019+#ifdef CONFIG_PAX_RANDMMAP
10020+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10021+ info.low_limit += mm->delta_mmap;
10022+#endif
10023+
10024 info.high_limit = task_size;
10025 addr = vm_unmapped_area(&info);
10026 }
10027@@ -85,6 +91,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10028 VM_BUG_ON(addr != -ENOMEM);
10029 info.flags = 0;
10030 info.low_limit = TASK_UNMAPPED_BASE;
10031+
10032+#ifdef CONFIG_PAX_RANDMMAP
10033+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10034+ info.low_limit += mm->delta_mmap;
10035+#endif
10036+
10037 info.high_limit = STACK_TOP32;
10038 addr = vm_unmapped_area(&info);
10039 }
10040@@ -99,6 +111,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
10041 struct mm_struct *mm = current->mm;
10042 struct vm_area_struct *vma;
10043 unsigned long task_size = TASK_SIZE;
10044+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
10045
10046 if (test_thread_flag(TIF_32BIT))
10047 task_size = STACK_TOP32;
10048@@ -114,11 +127,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
10049 return addr;
10050 }
10051
10052+#ifdef CONFIG_PAX_RANDMMAP
10053+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10054+#endif
10055+
10056 if (addr) {
10057 addr = ALIGN(addr, HPAGE_SIZE);
10058 vma = find_vma(mm, addr);
10059- if (task_size - len >= addr &&
10060- (!vma || addr + len <= vma->vm_start))
10061+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10062 return addr;
10063 }
10064 if (mm->get_unmapped_area == arch_get_unmapped_area)
10065diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
10066index f4500c6..889656c 100644
10067--- a/arch/tile/include/asm/atomic_64.h
10068+++ b/arch/tile/include/asm/atomic_64.h
10069@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10070
10071 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10072
10073+#define atomic64_read_unchecked(v) atomic64_read(v)
10074+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
10075+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
10076+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
10077+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
10078+#define atomic64_inc_unchecked(v) atomic64_inc(v)
10079+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
10080+#define atomic64_dec_unchecked(v) atomic64_dec(v)
10081+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
10082+
10083 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
10084 #define smp_mb__before_atomic_dec() smp_mb()
10085 #define smp_mb__after_atomic_dec() smp_mb()
10086diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
10087index a9a5299..0fce79e 100644
10088--- a/arch/tile/include/asm/cache.h
10089+++ b/arch/tile/include/asm/cache.h
10090@@ -15,11 +15,12 @@
10091 #ifndef _ASM_TILE_CACHE_H
10092 #define _ASM_TILE_CACHE_H
10093
10094+#include <linux/const.h>
10095 #include <arch/chip.h>
10096
10097 /* bytes per L1 data cache line */
10098 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
10099-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10100+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10101
10102 /* bytes per L2 cache line */
10103 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
10104diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
10105index 9ab078a..d6635c2 100644
10106--- a/arch/tile/include/asm/uaccess.h
10107+++ b/arch/tile/include/asm/uaccess.h
10108@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
10109 const void __user *from,
10110 unsigned long n)
10111 {
10112- int sz = __compiletime_object_size(to);
10113+ size_t sz = __compiletime_object_size(to);
10114
10115- if (likely(sz == -1 || sz >= n))
10116+ if (likely(sz == (size_t)-1 || sz >= n))
10117 n = _copy_from_user(to, from, n);
10118 else
10119 copy_from_user_overflow();
10120diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
10121index 650ccff..45fe2d6 100644
10122--- a/arch/tile/mm/hugetlbpage.c
10123+++ b/arch/tile/mm/hugetlbpage.c
10124@@ -239,6 +239,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
10125 info.high_limit = TASK_SIZE;
10126 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
10127 info.align_offset = 0;
10128+ info.threadstack_offset = 0;
10129 return vm_unmapped_area(&info);
10130 }
10131
10132@@ -256,6 +257,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
10133 info.high_limit = current->mm->mmap_base;
10134 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
10135 info.align_offset = 0;
10136+ info.threadstack_offset = 0;
10137 addr = vm_unmapped_area(&info);
10138
10139 /*
10140diff --git a/arch/um/Makefile b/arch/um/Makefile
10141index 133f7de..1d6f2f1 100644
10142--- a/arch/um/Makefile
10143+++ b/arch/um/Makefile
10144@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
10145 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
10146 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
10147
10148+ifdef CONSTIFY_PLUGIN
10149+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10150+endif
10151+
10152 #This will adjust *FLAGS accordingly to the platform.
10153 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
10154
10155diff --git a/arch/um/defconfig b/arch/um/defconfig
10156index 08107a7..ab22afe 100644
10157--- a/arch/um/defconfig
10158+++ b/arch/um/defconfig
10159@@ -51,7 +51,6 @@ CONFIG_X86_CMPXCHG=y
10160 CONFIG_X86_L1_CACHE_SHIFT=5
10161 CONFIG_X86_XADD=y
10162 CONFIG_X86_PPRO_FENCE=y
10163-CONFIG_X86_WP_WORKS_OK=y
10164 CONFIG_X86_INVLPG=y
10165 CONFIG_X86_BSWAP=y
10166 CONFIG_X86_POPAD_OK=y
10167diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
10168index 19e1bdd..3665b77 100644
10169--- a/arch/um/include/asm/cache.h
10170+++ b/arch/um/include/asm/cache.h
10171@@ -1,6 +1,7 @@
10172 #ifndef __UM_CACHE_H
10173 #define __UM_CACHE_H
10174
10175+#include <linux/const.h>
10176
10177 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
10178 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10179@@ -12,6 +13,6 @@
10180 # define L1_CACHE_SHIFT 5
10181 #endif
10182
10183-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10184+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10185
10186 #endif
10187diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
10188index 2e0a6b1..a64d0f5 100644
10189--- a/arch/um/include/asm/kmap_types.h
10190+++ b/arch/um/include/asm/kmap_types.h
10191@@ -8,6 +8,6 @@
10192
10193 /* No more #include "asm/arch/kmap_types.h" ! */
10194
10195-#define KM_TYPE_NR 14
10196+#define KM_TYPE_NR 15
10197
10198 #endif
10199diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
10200index 5ff53d9..5850cdf 100644
10201--- a/arch/um/include/asm/page.h
10202+++ b/arch/um/include/asm/page.h
10203@@ -14,6 +14,9 @@
10204 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
10205 #define PAGE_MASK (~(PAGE_SIZE-1))
10206
10207+#define ktla_ktva(addr) (addr)
10208+#define ktva_ktla(addr) (addr)
10209+
10210 #ifndef __ASSEMBLY__
10211
10212 struct page;
10213diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
10214index 0032f92..cd151e0 100644
10215--- a/arch/um/include/asm/pgtable-3level.h
10216+++ b/arch/um/include/asm/pgtable-3level.h
10217@@ -58,6 +58,7 @@
10218 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
10219 #define pud_populate(mm, pud, pmd) \
10220 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
10221+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
10222
10223 #ifdef CONFIG_64BIT
10224 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
10225diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
10226index b462b13..e7a19aa 100644
10227--- a/arch/um/kernel/process.c
10228+++ b/arch/um/kernel/process.c
10229@@ -386,22 +386,6 @@ int singlestepping(void * t)
10230 return 2;
10231 }
10232
10233-/*
10234- * Only x86 and x86_64 have an arch_align_stack().
10235- * All other arches have "#define arch_align_stack(x) (x)"
10236- * in their asm/system.h
10237- * As this is included in UML from asm-um/system-generic.h,
10238- * we can use it to behave as the subarch does.
10239- */
10240-#ifndef arch_align_stack
10241-unsigned long arch_align_stack(unsigned long sp)
10242-{
10243- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
10244- sp -= get_random_int() % 8192;
10245- return sp & ~0xf;
10246-}
10247-#endif
10248-
10249 unsigned long get_wchan(struct task_struct *p)
10250 {
10251 unsigned long stack_page, sp, ip;
10252diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
10253index ad8f795..2c7eec6 100644
10254--- a/arch/unicore32/include/asm/cache.h
10255+++ b/arch/unicore32/include/asm/cache.h
10256@@ -12,8 +12,10 @@
10257 #ifndef __UNICORE_CACHE_H__
10258 #define __UNICORE_CACHE_H__
10259
10260-#define L1_CACHE_SHIFT (5)
10261-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10262+#include <linux/const.h>
10263+
10264+#define L1_CACHE_SHIFT 5
10265+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10266
10267 /*
10268 * Memory returned by kmalloc() may be used for DMA, so we must make
10269diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
10270index 6ef2a37..74ad6ad 100644
10271--- a/arch/x86/Kconfig
10272+++ b/arch/x86/Kconfig
10273@@ -243,7 +243,7 @@ config X86_HT
10274
10275 config X86_32_LAZY_GS
10276 def_bool y
10277- depends on X86_32 && !CC_STACKPROTECTOR
10278+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
10279
10280 config ARCH_HWEIGHT_CFLAGS
10281 string
10282@@ -1076,6 +1076,7 @@ config MICROCODE_EARLY
10283
10284 config X86_MSR
10285 tristate "/dev/cpu/*/msr - Model-specific register support"
10286+ depends on !GRKERNSEC_KMEM
10287 ---help---
10288 This device gives privileged processes access to the x86
10289 Model-Specific Registers (MSRs). It is a character device with
10290@@ -1099,7 +1100,7 @@ choice
10291
10292 config NOHIGHMEM
10293 bool "off"
10294- depends on !X86_NUMAQ
10295+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10296 ---help---
10297 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
10298 However, the address space of 32-bit x86 processors is only 4
10299@@ -1136,7 +1137,7 @@ config NOHIGHMEM
10300
10301 config HIGHMEM4G
10302 bool "4GB"
10303- depends on !X86_NUMAQ
10304+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10305 ---help---
10306 Select this if you have a 32-bit processor and between 1 and 4
10307 gigabytes of physical RAM.
10308@@ -1189,7 +1190,7 @@ config PAGE_OFFSET
10309 hex
10310 default 0xB0000000 if VMSPLIT_3G_OPT
10311 default 0x80000000 if VMSPLIT_2G
10312- default 0x78000000 if VMSPLIT_2G_OPT
10313+ default 0x70000000 if VMSPLIT_2G_OPT
10314 default 0x40000000 if VMSPLIT_1G
10315 default 0xC0000000
10316 depends on X86_32
10317@@ -1587,6 +1588,7 @@ config SECCOMP
10318
10319 config CC_STACKPROTECTOR
10320 bool "Enable -fstack-protector buffer overflow detection"
10321+ depends on X86_64 || !PAX_MEMORY_UDEREF
10322 ---help---
10323 This option turns on the -fstack-protector GCC feature. This
10324 feature puts, at the beginning of functions, a canary value on
10325@@ -1706,6 +1708,8 @@ config X86_NEED_RELOCS
10326 config PHYSICAL_ALIGN
10327 hex "Alignment value to which kernel should be aligned" if X86_32
10328 default "0x1000000"
10329+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
10330+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
10331 range 0x2000 0x1000000
10332 ---help---
10333 This value puts the alignment restrictions on physical address
10334@@ -1781,9 +1785,10 @@ config DEBUG_HOTPLUG_CPU0
10335 If unsure, say N.
10336
10337 config COMPAT_VDSO
10338- def_bool y
10339+ def_bool n
10340 prompt "Compat VDSO support"
10341 depends on X86_32 || IA32_EMULATION
10342+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
10343 ---help---
10344 Map the 32-bit VDSO to the predictable old-style address too.
10345
10346diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
10347index c026cca..14657ae 100644
10348--- a/arch/x86/Kconfig.cpu
10349+++ b/arch/x86/Kconfig.cpu
10350@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
10351
10352 config X86_F00F_BUG
10353 def_bool y
10354- depends on M586MMX || M586TSC || M586 || M486
10355+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
10356
10357 config X86_INVD_BUG
10358 def_bool y
10359@@ -327,7 +327,7 @@ config X86_INVD_BUG
10360
10361 config X86_ALIGNMENT_16
10362 def_bool y
10363- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10364+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10365
10366 config X86_INTEL_USERCOPY
10367 def_bool y
10368@@ -373,7 +373,7 @@ config X86_CMPXCHG64
10369 # generates cmov.
10370 config X86_CMOV
10371 def_bool y
10372- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10373+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10374
10375 config X86_MINIMUM_CPU_FAMILY
10376 int
10377diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
10378index b322f12..652d0d9 100644
10379--- a/arch/x86/Kconfig.debug
10380+++ b/arch/x86/Kconfig.debug
10381@@ -84,7 +84,7 @@ config X86_PTDUMP
10382 config DEBUG_RODATA
10383 bool "Write protect kernel read-only data structures"
10384 default y
10385- depends on DEBUG_KERNEL
10386+ depends on DEBUG_KERNEL && BROKEN
10387 ---help---
10388 Mark the kernel read-only data as write-protected in the pagetables,
10389 in order to catch accidental (and incorrect) writes to such const
10390@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
10391
10392 config DEBUG_SET_MODULE_RONX
10393 bool "Set loadable kernel module data as NX and text as RO"
10394- depends on MODULES
10395+ depends on MODULES && BROKEN
10396 ---help---
10397 This option helps catch unintended modifications to loadable
10398 kernel module's text and read-only data. It also prevents execution
10399@@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
10400
10401 config DEBUG_STRICT_USER_COPY_CHECKS
10402 bool "Strict copy size checks"
10403- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
10404+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
10405 ---help---
10406 Enabling this option turns a certain set of sanity checks for user
10407 copy operations into compile time failures.
10408diff --git a/arch/x86/Makefile b/arch/x86/Makefile
10409index 5c47726..8c4fa67 100644
10410--- a/arch/x86/Makefile
10411+++ b/arch/x86/Makefile
10412@@ -54,6 +54,7 @@ else
10413 UTS_MACHINE := x86_64
10414 CHECKFLAGS += -D__x86_64__ -m64
10415
10416+ biarch := $(call cc-option,-m64)
10417 KBUILD_AFLAGS += -m64
10418 KBUILD_CFLAGS += -m64
10419
10420@@ -234,3 +235,12 @@ define archhelp
10421 echo ' FDARGS="..." arguments for the booted kernel'
10422 echo ' FDINITRD=file initrd for the booted kernel'
10423 endef
10424+
10425+define OLD_LD
10426+
10427+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
10428+*** Please upgrade your binutils to 2.18 or newer
10429+endef
10430+
10431+archprepare:
10432+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
10433diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
10434index 379814b..add62ce 100644
10435--- a/arch/x86/boot/Makefile
10436+++ b/arch/x86/boot/Makefile
10437@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
10438 $(call cc-option, -fno-stack-protector) \
10439 $(call cc-option, -mpreferred-stack-boundary=2)
10440 KBUILD_CFLAGS += $(call cc-option, -m32)
10441+ifdef CONSTIFY_PLUGIN
10442+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10443+endif
10444 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10445 GCOV_PROFILE := n
10446
10447diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
10448index 878e4b9..20537ab 100644
10449--- a/arch/x86/boot/bitops.h
10450+++ b/arch/x86/boot/bitops.h
10451@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10452 u8 v;
10453 const u32 *p = (const u32 *)addr;
10454
10455- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10456+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10457 return v;
10458 }
10459
10460@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10461
10462 static inline void set_bit(int nr, void *addr)
10463 {
10464- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10465+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10466 }
10467
10468 #endif /* BOOT_BITOPS_H */
10469diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
10470index 5b75319..331a4ca 100644
10471--- a/arch/x86/boot/boot.h
10472+++ b/arch/x86/boot/boot.h
10473@@ -85,7 +85,7 @@ static inline void io_delay(void)
10474 static inline u16 ds(void)
10475 {
10476 u16 seg;
10477- asm("movw %%ds,%0" : "=rm" (seg));
10478+ asm volatile("movw %%ds,%0" : "=rm" (seg));
10479 return seg;
10480 }
10481
10482@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
10483 static inline int memcmp(const void *s1, const void *s2, size_t len)
10484 {
10485 u8 diff;
10486- asm("repe; cmpsb; setnz %0"
10487+ asm volatile("repe; cmpsb; setnz %0"
10488 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
10489 return diff;
10490 }
10491diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
10492index 5ef205c..342191d 100644
10493--- a/arch/x86/boot/compressed/Makefile
10494+++ b/arch/x86/boot/compressed/Makefile
10495@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
10496 KBUILD_CFLAGS += $(cflags-y)
10497 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
10498 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
10499+ifdef CONSTIFY_PLUGIN
10500+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10501+endif
10502
10503 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10504 GCOV_PROFILE := n
10505diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
10506index 35ee62f..b6609b6 100644
10507--- a/arch/x86/boot/compressed/eboot.c
10508+++ b/arch/x86/boot/compressed/eboot.c
10509@@ -150,7 +150,6 @@ again:
10510 *addr = max_addr;
10511 }
10512
10513-free_pool:
10514 efi_call_phys1(sys_table->boottime->free_pool, map);
10515
10516 fail:
10517@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
10518 if (i == map_size / desc_size)
10519 status = EFI_NOT_FOUND;
10520
10521-free_pool:
10522 efi_call_phys1(sys_table->boottime->free_pool, map);
10523 fail:
10524 return status;
10525diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
10526index 1e3184f..0d11e2e 100644
10527--- a/arch/x86/boot/compressed/head_32.S
10528+++ b/arch/x86/boot/compressed/head_32.S
10529@@ -118,7 +118,7 @@ preferred_addr:
10530 notl %eax
10531 andl %eax, %ebx
10532 #else
10533- movl $LOAD_PHYSICAL_ADDR, %ebx
10534+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10535 #endif
10536
10537 /* Target address to relocate to for decompression */
10538@@ -204,7 +204,7 @@ relocated:
10539 * and where it was actually loaded.
10540 */
10541 movl %ebp, %ebx
10542- subl $LOAD_PHYSICAL_ADDR, %ebx
10543+ subl $____LOAD_PHYSICAL_ADDR, %ebx
10544 jz 2f /* Nothing to be done if loaded at compiled addr. */
10545 /*
10546 * Process relocations.
10547@@ -212,8 +212,7 @@ relocated:
10548
10549 1: subl $4, %edi
10550 movl (%edi), %ecx
10551- testl %ecx, %ecx
10552- jz 2f
10553+ jecxz 2f
10554 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
10555 jmp 1b
10556 2:
10557diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
10558index c1d383d..57ab51c 100644
10559--- a/arch/x86/boot/compressed/head_64.S
10560+++ b/arch/x86/boot/compressed/head_64.S
10561@@ -97,7 +97,7 @@ ENTRY(startup_32)
10562 notl %eax
10563 andl %eax, %ebx
10564 #else
10565- movl $LOAD_PHYSICAL_ADDR, %ebx
10566+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10567 #endif
10568
10569 /* Target address to relocate to for decompression */
10570@@ -272,7 +272,7 @@ preferred_addr:
10571 notq %rax
10572 andq %rax, %rbp
10573 #else
10574- movq $LOAD_PHYSICAL_ADDR, %rbp
10575+ movq $____LOAD_PHYSICAL_ADDR, %rbp
10576 #endif
10577
10578 /* Target address to relocate to for decompression */
10579@@ -363,8 +363,8 @@ gdt:
10580 .long gdt
10581 .word 0
10582 .quad 0x0000000000000000 /* NULL descriptor */
10583- .quad 0x00af9a000000ffff /* __KERNEL_CS */
10584- .quad 0x00cf92000000ffff /* __KERNEL_DS */
10585+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
10586+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
10587 .quad 0x0080890000000000 /* TS descriptor */
10588 .quad 0x0000000000000000 /* TS continued */
10589 gdt_end:
10590diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
10591index 7cb56c6..d382d84 100644
10592--- a/arch/x86/boot/compressed/misc.c
10593+++ b/arch/x86/boot/compressed/misc.c
10594@@ -303,7 +303,7 @@ static void parse_elf(void *output)
10595 case PT_LOAD:
10596 #ifdef CONFIG_RELOCATABLE
10597 dest = output;
10598- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
10599+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
10600 #else
10601 dest = (void *)(phdr->p_paddr);
10602 #endif
10603@@ -354,7 +354,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
10604 error("Destination address too large");
10605 #endif
10606 #ifndef CONFIG_RELOCATABLE
10607- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
10608+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
10609 error("Wrong destination address");
10610 #endif
10611
10612diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
10613index 4d3ff03..e4972ff 100644
10614--- a/arch/x86/boot/cpucheck.c
10615+++ b/arch/x86/boot/cpucheck.c
10616@@ -74,7 +74,7 @@ static int has_fpu(void)
10617 u16 fcw = -1, fsw = -1;
10618 u32 cr0;
10619
10620- asm("movl %%cr0,%0" : "=r" (cr0));
10621+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
10622 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
10623 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
10624 asm volatile("movl %0,%%cr0" : : "r" (cr0));
10625@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
10626 {
10627 u32 f0, f1;
10628
10629- asm("pushfl ; "
10630+ asm volatile("pushfl ; "
10631 "pushfl ; "
10632 "popl %0 ; "
10633 "movl %0,%1 ; "
10634@@ -115,7 +115,7 @@ static void get_flags(void)
10635 set_bit(X86_FEATURE_FPU, cpu.flags);
10636
10637 if (has_eflag(X86_EFLAGS_ID)) {
10638- asm("cpuid"
10639+ asm volatile("cpuid"
10640 : "=a" (max_intel_level),
10641 "=b" (cpu_vendor[0]),
10642 "=d" (cpu_vendor[1]),
10643@@ -124,7 +124,7 @@ static void get_flags(void)
10644
10645 if (max_intel_level >= 0x00000001 &&
10646 max_intel_level <= 0x0000ffff) {
10647- asm("cpuid"
10648+ asm volatile("cpuid"
10649 : "=a" (tfms),
10650 "=c" (cpu.flags[4]),
10651 "=d" (cpu.flags[0])
10652@@ -136,7 +136,7 @@ static void get_flags(void)
10653 cpu.model += ((tfms >> 16) & 0xf) << 4;
10654 }
10655
10656- asm("cpuid"
10657+ asm volatile("cpuid"
10658 : "=a" (max_amd_level)
10659 : "a" (0x80000000)
10660 : "ebx", "ecx", "edx");
10661@@ -144,7 +144,7 @@ static void get_flags(void)
10662 if (max_amd_level >= 0x80000001 &&
10663 max_amd_level <= 0x8000ffff) {
10664 u32 eax = 0x80000001;
10665- asm("cpuid"
10666+ asm volatile("cpuid"
10667 : "+a" (eax),
10668 "=c" (cpu.flags[6]),
10669 "=d" (cpu.flags[1])
10670@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10671 u32 ecx = MSR_K7_HWCR;
10672 u32 eax, edx;
10673
10674- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10675+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10676 eax &= ~(1 << 15);
10677- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10678+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10679
10680 get_flags(); /* Make sure it really did something */
10681 err = check_flags();
10682@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10683 u32 ecx = MSR_VIA_FCR;
10684 u32 eax, edx;
10685
10686- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10687+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10688 eax |= (1<<1)|(1<<7);
10689- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10690+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10691
10692 set_bit(X86_FEATURE_CX8, cpu.flags);
10693 err = check_flags();
10694@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10695 u32 eax, edx;
10696 u32 level = 1;
10697
10698- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10699- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10700- asm("cpuid"
10701+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10702+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10703+ asm volatile("cpuid"
10704 : "+a" (level), "=d" (cpu.flags[0])
10705 : : "ecx", "ebx");
10706- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10707+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10708
10709 err = check_flags();
10710 }
10711diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
10712index 9ec06a1..2c25e79 100644
10713--- a/arch/x86/boot/header.S
10714+++ b/arch/x86/boot/header.S
10715@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
10716 # single linked list of
10717 # struct setup_data
10718
10719-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
10720+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
10721
10722 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
10723+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
10724+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
10725+#else
10726 #define VO_INIT_SIZE (VO__end - VO__text)
10727+#endif
10728 #if ZO_INIT_SIZE > VO_INIT_SIZE
10729 #define INIT_SIZE ZO_INIT_SIZE
10730 #else
10731diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
10732index db75d07..8e6d0af 100644
10733--- a/arch/x86/boot/memory.c
10734+++ b/arch/x86/boot/memory.c
10735@@ -19,7 +19,7 @@
10736
10737 static int detect_memory_e820(void)
10738 {
10739- int count = 0;
10740+ unsigned int count = 0;
10741 struct biosregs ireg, oreg;
10742 struct e820entry *desc = boot_params.e820_map;
10743 static struct e820entry buf; /* static so it is zeroed */
10744diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
10745index 11e8c6e..fdbb1ed 100644
10746--- a/arch/x86/boot/video-vesa.c
10747+++ b/arch/x86/boot/video-vesa.c
10748@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
10749
10750 boot_params.screen_info.vesapm_seg = oreg.es;
10751 boot_params.screen_info.vesapm_off = oreg.di;
10752+ boot_params.screen_info.vesapm_size = oreg.cx;
10753 }
10754
10755 /*
10756diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
10757index 43eda28..5ab5fdb 100644
10758--- a/arch/x86/boot/video.c
10759+++ b/arch/x86/boot/video.c
10760@@ -96,7 +96,7 @@ static void store_mode_params(void)
10761 static unsigned int get_entry(void)
10762 {
10763 char entry_buf[4];
10764- int i, len = 0;
10765+ unsigned int i, len = 0;
10766 int key;
10767 unsigned int v;
10768
10769diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
10770index 9105655..5e37f27 100644
10771--- a/arch/x86/crypto/aes-x86_64-asm_64.S
10772+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
10773@@ -8,6 +8,8 @@
10774 * including this sentence is retained in full.
10775 */
10776
10777+#include <asm/alternative-asm.h>
10778+
10779 .extern crypto_ft_tab
10780 .extern crypto_it_tab
10781 .extern crypto_fl_tab
10782@@ -70,6 +72,8 @@
10783 je B192; \
10784 leaq 32(r9),r9;
10785
10786+#define ret pax_force_retaddr 0, 1; ret
10787+
10788 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
10789 movq r1,r2; \
10790 movq r3,r4; \
10791diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
10792index 04b7977..402f223 100644
10793--- a/arch/x86/crypto/aesni-intel_asm.S
10794+++ b/arch/x86/crypto/aesni-intel_asm.S
10795@@ -31,6 +31,7 @@
10796
10797 #include <linux/linkage.h>
10798 #include <asm/inst.h>
10799+#include <asm/alternative-asm.h>
10800
10801 #ifdef __x86_64__
10802 .data
10803@@ -1435,6 +1436,7 @@ _return_T_done_decrypt:
10804 pop %r14
10805 pop %r13
10806 pop %r12
10807+ pax_force_retaddr 0, 1
10808 ret
10809 ENDPROC(aesni_gcm_dec)
10810
10811@@ -1699,6 +1701,7 @@ _return_T_done_encrypt:
10812 pop %r14
10813 pop %r13
10814 pop %r12
10815+ pax_force_retaddr 0, 1
10816 ret
10817 ENDPROC(aesni_gcm_enc)
10818
10819@@ -1716,6 +1719,7 @@ _key_expansion_256a:
10820 pxor %xmm1, %xmm0
10821 movaps %xmm0, (TKEYP)
10822 add $0x10, TKEYP
10823+ pax_force_retaddr_bts
10824 ret
10825 ENDPROC(_key_expansion_128)
10826 ENDPROC(_key_expansion_256a)
10827@@ -1742,6 +1746,7 @@ _key_expansion_192a:
10828 shufps $0b01001110, %xmm2, %xmm1
10829 movaps %xmm1, 0x10(TKEYP)
10830 add $0x20, TKEYP
10831+ pax_force_retaddr_bts
10832 ret
10833 ENDPROC(_key_expansion_192a)
10834
10835@@ -1762,6 +1767,7 @@ _key_expansion_192b:
10836
10837 movaps %xmm0, (TKEYP)
10838 add $0x10, TKEYP
10839+ pax_force_retaddr_bts
10840 ret
10841 ENDPROC(_key_expansion_192b)
10842
10843@@ -1775,6 +1781,7 @@ _key_expansion_256b:
10844 pxor %xmm1, %xmm2
10845 movaps %xmm2, (TKEYP)
10846 add $0x10, TKEYP
10847+ pax_force_retaddr_bts
10848 ret
10849 ENDPROC(_key_expansion_256b)
10850
10851@@ -1888,6 +1895,7 @@ ENTRY(aesni_set_key)
10852 #ifndef __x86_64__
10853 popl KEYP
10854 #endif
10855+ pax_force_retaddr 0, 1
10856 ret
10857 ENDPROC(aesni_set_key)
10858
10859@@ -1910,6 +1918,7 @@ ENTRY(aesni_enc)
10860 popl KLEN
10861 popl KEYP
10862 #endif
10863+ pax_force_retaddr 0, 1
10864 ret
10865 ENDPROC(aesni_enc)
10866
10867@@ -1968,6 +1977,7 @@ _aesni_enc1:
10868 AESENC KEY STATE
10869 movaps 0x70(TKEYP), KEY
10870 AESENCLAST KEY STATE
10871+ pax_force_retaddr_bts
10872 ret
10873 ENDPROC(_aesni_enc1)
10874
10875@@ -2077,6 +2087,7 @@ _aesni_enc4:
10876 AESENCLAST KEY STATE2
10877 AESENCLAST KEY STATE3
10878 AESENCLAST KEY STATE4
10879+ pax_force_retaddr_bts
10880 ret
10881 ENDPROC(_aesni_enc4)
10882
10883@@ -2100,6 +2111,7 @@ ENTRY(aesni_dec)
10884 popl KLEN
10885 popl KEYP
10886 #endif
10887+ pax_force_retaddr 0, 1
10888 ret
10889 ENDPROC(aesni_dec)
10890
10891@@ -2158,6 +2170,7 @@ _aesni_dec1:
10892 AESDEC KEY STATE
10893 movaps 0x70(TKEYP), KEY
10894 AESDECLAST KEY STATE
10895+ pax_force_retaddr_bts
10896 ret
10897 ENDPROC(_aesni_dec1)
10898
10899@@ -2267,6 +2280,7 @@ _aesni_dec4:
10900 AESDECLAST KEY STATE2
10901 AESDECLAST KEY STATE3
10902 AESDECLAST KEY STATE4
10903+ pax_force_retaddr_bts
10904 ret
10905 ENDPROC(_aesni_dec4)
10906
10907@@ -2325,6 +2339,7 @@ ENTRY(aesni_ecb_enc)
10908 popl KEYP
10909 popl LEN
10910 #endif
10911+ pax_force_retaddr 0, 1
10912 ret
10913 ENDPROC(aesni_ecb_enc)
10914
10915@@ -2384,6 +2399,7 @@ ENTRY(aesni_ecb_dec)
10916 popl KEYP
10917 popl LEN
10918 #endif
10919+ pax_force_retaddr 0, 1
10920 ret
10921 ENDPROC(aesni_ecb_dec)
10922
10923@@ -2426,6 +2442,7 @@ ENTRY(aesni_cbc_enc)
10924 popl LEN
10925 popl IVP
10926 #endif
10927+ pax_force_retaddr 0, 1
10928 ret
10929 ENDPROC(aesni_cbc_enc)
10930
10931@@ -2517,6 +2534,7 @@ ENTRY(aesni_cbc_dec)
10932 popl LEN
10933 popl IVP
10934 #endif
10935+ pax_force_retaddr 0, 1
10936 ret
10937 ENDPROC(aesni_cbc_dec)
10938
10939@@ -2544,6 +2562,7 @@ _aesni_inc_init:
10940 mov $1, TCTR_LOW
10941 MOVQ_R64_XMM TCTR_LOW INC
10942 MOVQ_R64_XMM CTR TCTR_LOW
10943+ pax_force_retaddr_bts
10944 ret
10945 ENDPROC(_aesni_inc_init)
10946
10947@@ -2573,6 +2592,7 @@ _aesni_inc:
10948 .Linc_low:
10949 movaps CTR, IV
10950 PSHUFB_XMM BSWAP_MASK IV
10951+ pax_force_retaddr_bts
10952 ret
10953 ENDPROC(_aesni_inc)
10954
10955@@ -2634,6 +2654,7 @@ ENTRY(aesni_ctr_enc)
10956 .Lctr_enc_ret:
10957 movups IV, (IVP)
10958 .Lctr_enc_just_ret:
10959+ pax_force_retaddr 0, 1
10960 ret
10961 ENDPROC(aesni_ctr_enc)
10962 #endif
10963diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10964index 246c670..4d1ed00 100644
10965--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
10966+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10967@@ -21,6 +21,7 @@
10968 */
10969
10970 #include <linux/linkage.h>
10971+#include <asm/alternative-asm.h>
10972
10973 .file "blowfish-x86_64-asm.S"
10974 .text
10975@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
10976 jnz .L__enc_xor;
10977
10978 write_block();
10979+ pax_force_retaddr 0, 1
10980 ret;
10981 .L__enc_xor:
10982 xor_block();
10983+ pax_force_retaddr 0, 1
10984 ret;
10985 ENDPROC(__blowfish_enc_blk)
10986
10987@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
10988
10989 movq %r11, %rbp;
10990
10991+ pax_force_retaddr 0, 1
10992 ret;
10993 ENDPROC(blowfish_dec_blk)
10994
10995@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
10996
10997 popq %rbx;
10998 popq %rbp;
10999+ pax_force_retaddr 0, 1
11000 ret;
11001
11002 .L__enc_xor4:
11003@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
11004
11005 popq %rbx;
11006 popq %rbp;
11007+ pax_force_retaddr 0, 1
11008 ret;
11009 ENDPROC(__blowfish_enc_blk_4way)
11010
11011@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
11012 popq %rbx;
11013 popq %rbp;
11014
11015+ pax_force_retaddr 0, 1
11016 ret;
11017 ENDPROC(blowfish_dec_blk_4way)
11018diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
11019index 310319c..ce174a4 100644
11020--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
11021+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
11022@@ -21,6 +21,7 @@
11023 */
11024
11025 #include <linux/linkage.h>
11026+#include <asm/alternative-asm.h>
11027
11028 .file "camellia-x86_64-asm_64.S"
11029 .text
11030@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
11031 enc_outunpack(mov, RT1);
11032
11033 movq RRBP, %rbp;
11034+ pax_force_retaddr 0, 1
11035 ret;
11036
11037 .L__enc_xor:
11038 enc_outunpack(xor, RT1);
11039
11040 movq RRBP, %rbp;
11041+ pax_force_retaddr 0, 1
11042 ret;
11043 ENDPROC(__camellia_enc_blk)
11044
11045@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
11046 dec_outunpack();
11047
11048 movq RRBP, %rbp;
11049+ pax_force_retaddr 0, 1
11050 ret;
11051 ENDPROC(camellia_dec_blk)
11052
11053@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
11054
11055 movq RRBP, %rbp;
11056 popq %rbx;
11057+ pax_force_retaddr 0, 1
11058 ret;
11059
11060 .L__enc2_xor:
11061@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
11062
11063 movq RRBP, %rbp;
11064 popq %rbx;
11065+ pax_force_retaddr 0, 1
11066 ret;
11067 ENDPROC(__camellia_enc_blk_2way)
11068
11069@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
11070
11071 movq RRBP, %rbp;
11072 movq RXOR, %rbx;
11073+ pax_force_retaddr 0, 1
11074 ret;
11075 ENDPROC(camellia_dec_blk_2way)
11076diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11077index c35fd5d..c1ee236 100644
11078--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11079+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11080@@ -24,6 +24,7 @@
11081 */
11082
11083 #include <linux/linkage.h>
11084+#include <asm/alternative-asm.h>
11085
11086 .file "cast5-avx-x86_64-asm_64.S"
11087
11088@@ -281,6 +282,7 @@ __cast5_enc_blk16:
11089 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
11090 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
11091
11092+ pax_force_retaddr 0, 1
11093 ret;
11094 ENDPROC(__cast5_enc_blk16)
11095
11096@@ -352,6 +354,7 @@ __cast5_dec_blk16:
11097 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
11098 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
11099
11100+ pax_force_retaddr 0, 1
11101 ret;
11102
11103 .L__skip_dec:
11104@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
11105 vmovdqu RR4, (6*4*4)(%r11);
11106 vmovdqu RL4, (7*4*4)(%r11);
11107
11108+ pax_force_retaddr
11109 ret;
11110 ENDPROC(cast5_ecb_enc_16way)
11111
11112@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
11113 vmovdqu RR4, (6*4*4)(%r11);
11114 vmovdqu RL4, (7*4*4)(%r11);
11115
11116+ pax_force_retaddr
11117 ret;
11118 ENDPROC(cast5_ecb_dec_16way)
11119
11120@@ -469,6 +474,7 @@ ENTRY(cast5_cbc_dec_16way)
11121
11122 popq %r12;
11123
11124+ pax_force_retaddr
11125 ret;
11126 ENDPROC(cast5_cbc_dec_16way)
11127
11128@@ -542,5 +548,6 @@ ENTRY(cast5_ctr_16way)
11129
11130 popq %r12;
11131
11132+ pax_force_retaddr
11133 ret;
11134 ENDPROC(cast5_ctr_16way)
11135diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11136index f93b610..c09bf40 100644
11137--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11138+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11139@@ -24,6 +24,7 @@
11140 */
11141
11142 #include <linux/linkage.h>
11143+#include <asm/alternative-asm.h>
11144 #include "glue_helper-asm-avx.S"
11145
11146 .file "cast6-avx-x86_64-asm_64.S"
11147@@ -293,6 +294,7 @@ __cast6_enc_blk8:
11148 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11149 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11150
11151+ pax_force_retaddr 0, 1
11152 ret;
11153 ENDPROC(__cast6_enc_blk8)
11154
11155@@ -338,6 +340,7 @@ __cast6_dec_blk8:
11156 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11157 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11158
11159+ pax_force_retaddr 0, 1
11160 ret;
11161 ENDPROC(__cast6_dec_blk8)
11162
11163@@ -356,6 +359,7 @@ ENTRY(cast6_ecb_enc_8way)
11164
11165 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11166
11167+ pax_force_retaddr
11168 ret;
11169 ENDPROC(cast6_ecb_enc_8way)
11170
11171@@ -374,6 +378,7 @@ ENTRY(cast6_ecb_dec_8way)
11172
11173 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11174
11175+ pax_force_retaddr
11176 ret;
11177 ENDPROC(cast6_ecb_dec_8way)
11178
11179@@ -397,6 +402,7 @@ ENTRY(cast6_cbc_dec_8way)
11180
11181 popq %r12;
11182
11183+ pax_force_retaddr
11184 ret;
11185 ENDPROC(cast6_cbc_dec_8way)
11186
11187@@ -422,5 +428,6 @@ ENTRY(cast6_ctr_8way)
11188
11189 popq %r12;
11190
11191+ pax_force_retaddr
11192 ret;
11193 ENDPROC(cast6_ctr_8way)
11194diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11195index 9279e0b..9270820 100644
11196--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
11197+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11198@@ -1,4 +1,5 @@
11199 #include <linux/linkage.h>
11200+#include <asm/alternative-asm.h>
11201
11202 # enter salsa20_encrypt_bytes
11203 ENTRY(salsa20_encrypt_bytes)
11204@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
11205 add %r11,%rsp
11206 mov %rdi,%rax
11207 mov %rsi,%rdx
11208+ pax_force_retaddr 0, 1
11209 ret
11210 # bytesatleast65:
11211 ._bytesatleast65:
11212@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
11213 add %r11,%rsp
11214 mov %rdi,%rax
11215 mov %rsi,%rdx
11216+ pax_force_retaddr
11217 ret
11218 ENDPROC(salsa20_keysetup)
11219
11220@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
11221 add %r11,%rsp
11222 mov %rdi,%rax
11223 mov %rsi,%rdx
11224+ pax_force_retaddr
11225 ret
11226 ENDPROC(salsa20_ivsetup)
11227diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11228index 43c9386..a0e2d60 100644
11229--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11230+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11231@@ -25,6 +25,7 @@
11232 */
11233
11234 #include <linux/linkage.h>
11235+#include <asm/alternative-asm.h>
11236 #include "glue_helper-asm-avx.S"
11237
11238 .file "serpent-avx-x86_64-asm_64.S"
11239@@ -617,6 +618,7 @@ __serpent_enc_blk8_avx:
11240 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11241 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11242
11243+ pax_force_retaddr
11244 ret;
11245 ENDPROC(__serpent_enc_blk8_avx)
11246
11247@@ -671,6 +673,7 @@ __serpent_dec_blk8_avx:
11248 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11249 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11250
11251+ pax_force_retaddr
11252 ret;
11253 ENDPROC(__serpent_dec_blk8_avx)
11254
11255@@ -687,6 +690,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
11256
11257 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11258
11259+ pax_force_retaddr
11260 ret;
11261 ENDPROC(serpent_ecb_enc_8way_avx)
11262
11263@@ -703,6 +707,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
11264
11265 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11266
11267+ pax_force_retaddr
11268 ret;
11269 ENDPROC(serpent_ecb_dec_8way_avx)
11270
11271@@ -719,6 +724,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
11272
11273 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11274
11275+ pax_force_retaddr
11276 ret;
11277 ENDPROC(serpent_cbc_dec_8way_avx)
11278
11279@@ -737,5 +743,6 @@ ENTRY(serpent_ctr_8way_avx)
11280
11281 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11282
11283+ pax_force_retaddr
11284 ret;
11285 ENDPROC(serpent_ctr_8way_avx)
11286diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11287index acc066c..1559cc4 100644
11288--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11289+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11290@@ -25,6 +25,7 @@
11291 */
11292
11293 #include <linux/linkage.h>
11294+#include <asm/alternative-asm.h>
11295
11296 .file "serpent-sse2-x86_64-asm_64.S"
11297 .text
11298@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
11299 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11300 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11301
11302+ pax_force_retaddr
11303 ret;
11304
11305 .L__enc_xor8:
11306 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11307 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11308
11309+ pax_force_retaddr
11310 ret;
11311 ENDPROC(__serpent_enc_blk_8way)
11312
11313@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
11314 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11315 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11316
11317+ pax_force_retaddr
11318 ret;
11319 ENDPROC(serpent_dec_blk_8way)
11320diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
11321index a410950..3356d42 100644
11322--- a/arch/x86/crypto/sha1_ssse3_asm.S
11323+++ b/arch/x86/crypto/sha1_ssse3_asm.S
11324@@ -29,6 +29,7 @@
11325 */
11326
11327 #include <linux/linkage.h>
11328+#include <asm/alternative-asm.h>
11329
11330 #define CTX %rdi // arg1
11331 #define BUF %rsi // arg2
11332@@ -104,6 +105,7 @@
11333 pop %r12
11334 pop %rbp
11335 pop %rbx
11336+ pax_force_retaddr 0, 1
11337 ret
11338
11339 ENDPROC(\name)
11340diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11341index 8d3e113..898b161 100644
11342--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11343+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11344@@ -24,6 +24,7 @@
11345 */
11346
11347 #include <linux/linkage.h>
11348+#include <asm/alternative-asm.h>
11349 #include "glue_helper-asm-avx.S"
11350
11351 .file "twofish-avx-x86_64-asm_64.S"
11352@@ -282,6 +283,7 @@ __twofish_enc_blk8:
11353 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
11354 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
11355
11356+ pax_force_retaddr 0, 1
11357 ret;
11358 ENDPROC(__twofish_enc_blk8)
11359
11360@@ -322,6 +324,7 @@ __twofish_dec_blk8:
11361 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
11362 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
11363
11364+ pax_force_retaddr 0, 1
11365 ret;
11366 ENDPROC(__twofish_dec_blk8)
11367
11368@@ -340,6 +343,7 @@ ENTRY(twofish_ecb_enc_8way)
11369
11370 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
11371
11372+ pax_force_retaddr 0, 1
11373 ret;
11374 ENDPROC(twofish_ecb_enc_8way)
11375
11376@@ -358,6 +362,7 @@ ENTRY(twofish_ecb_dec_8way)
11377
11378 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11379
11380+ pax_force_retaddr 0, 1
11381 ret;
11382 ENDPROC(twofish_ecb_dec_8way)
11383
11384@@ -381,6 +386,7 @@ ENTRY(twofish_cbc_dec_8way)
11385
11386 popq %r12;
11387
11388+ pax_force_retaddr 0, 1
11389 ret;
11390 ENDPROC(twofish_cbc_dec_8way)
11391
11392@@ -406,5 +412,6 @@ ENTRY(twofish_ctr_8way)
11393
11394 popq %r12;
11395
11396+ pax_force_retaddr 0, 1
11397 ret;
11398 ENDPROC(twofish_ctr_8way)
11399diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11400index 1c3b7ce..b365c5e 100644
11401--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11402+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11403@@ -21,6 +21,7 @@
11404 */
11405
11406 #include <linux/linkage.h>
11407+#include <asm/alternative-asm.h>
11408
11409 .file "twofish-x86_64-asm-3way.S"
11410 .text
11411@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
11412 popq %r13;
11413 popq %r14;
11414 popq %r15;
11415+ pax_force_retaddr 0, 1
11416 ret;
11417
11418 .L__enc_xor3:
11419@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
11420 popq %r13;
11421 popq %r14;
11422 popq %r15;
11423+ pax_force_retaddr 0, 1
11424 ret;
11425 ENDPROC(__twofish_enc_blk_3way)
11426
11427@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
11428 popq %r13;
11429 popq %r14;
11430 popq %r15;
11431+ pax_force_retaddr 0, 1
11432 ret;
11433 ENDPROC(twofish_dec_blk_3way)
11434diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
11435index a039d21..29e7615 100644
11436--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
11437+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
11438@@ -22,6 +22,7 @@
11439
11440 #include <linux/linkage.h>
11441 #include <asm/asm-offsets.h>
11442+#include <asm/alternative-asm.h>
11443
11444 #define a_offset 0
11445 #define b_offset 4
11446@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
11447
11448 popq R1
11449 movq $1,%rax
11450+ pax_force_retaddr 0, 1
11451 ret
11452 ENDPROC(twofish_enc_blk)
11453
11454@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
11455
11456 popq R1
11457 movq $1,%rax
11458+ pax_force_retaddr 0, 1
11459 ret
11460 ENDPROC(twofish_dec_blk)
11461diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
11462index 03abf9b..a42ba29 100644
11463--- a/arch/x86/ia32/ia32_aout.c
11464+++ b/arch/x86/ia32/ia32_aout.c
11465@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
11466 unsigned long dump_start, dump_size;
11467 struct user32 dump;
11468
11469+ memset(&dump, 0, sizeof(dump));
11470+
11471 fs = get_fs();
11472 set_fs(KERNEL_DS);
11473 has_dumped = 1;
11474diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
11475index cf1a471..3bc4cf8 100644
11476--- a/arch/x86/ia32/ia32_signal.c
11477+++ b/arch/x86/ia32/ia32_signal.c
11478@@ -340,7 +340,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
11479 sp -= frame_size;
11480 /* Align the stack pointer according to the i386 ABI,
11481 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
11482- sp = ((sp + 4) & -16ul) - 4;
11483+ sp = ((sp - 12) & -16ul) - 4;
11484 return (void __user *) sp;
11485 }
11486
11487@@ -398,7 +398,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
11488 * These are actually not used anymore, but left because some
11489 * gdb versions depend on them as a marker.
11490 */
11491- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11492+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11493 } put_user_catch(err);
11494
11495 if (err)
11496@@ -440,7 +440,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
11497 0xb8,
11498 __NR_ia32_rt_sigreturn,
11499 0x80cd,
11500- 0,
11501+ 0
11502 };
11503
11504 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
11505@@ -463,16 +463,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
11506
11507 if (ksig->ka.sa.sa_flags & SA_RESTORER)
11508 restorer = ksig->ka.sa.sa_restorer;
11509+ else if (current->mm->context.vdso)
11510+ /* Return stub is in 32bit vsyscall page */
11511+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
11512 else
11513- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
11514- rt_sigreturn);
11515+ restorer = &frame->retcode;
11516 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
11517
11518 /*
11519 * Not actually used anymore, but left because some gdb
11520 * versions need it.
11521 */
11522- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11523+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11524 } put_user_catch(err);
11525
11526 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
11527diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
11528index 474dc1b..be7bff5 100644
11529--- a/arch/x86/ia32/ia32entry.S
11530+++ b/arch/x86/ia32/ia32entry.S
11531@@ -15,8 +15,10 @@
11532 #include <asm/irqflags.h>
11533 #include <asm/asm.h>
11534 #include <asm/smap.h>
11535+#include <asm/pgtable.h>
11536 #include <linux/linkage.h>
11537 #include <linux/err.h>
11538+#include <asm/alternative-asm.h>
11539
11540 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
11541 #include <linux/elf-em.h>
11542@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
11543 ENDPROC(native_irq_enable_sysexit)
11544 #endif
11545
11546+ .macro pax_enter_kernel_user
11547+ pax_set_fptr_mask
11548+#ifdef CONFIG_PAX_MEMORY_UDEREF
11549+ call pax_enter_kernel_user
11550+#endif
11551+ .endm
11552+
11553+ .macro pax_exit_kernel_user
11554+#ifdef CONFIG_PAX_MEMORY_UDEREF
11555+ call pax_exit_kernel_user
11556+#endif
11557+#ifdef CONFIG_PAX_RANDKSTACK
11558+ pushq %rax
11559+ pushq %r11
11560+ call pax_randomize_kstack
11561+ popq %r11
11562+ popq %rax
11563+#endif
11564+ .endm
11565+
11566+.macro pax_erase_kstack
11567+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11568+ call pax_erase_kstack
11569+#endif
11570+.endm
11571+
11572 /*
11573 * 32bit SYSENTER instruction entry.
11574 *
11575@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
11576 CFI_REGISTER rsp,rbp
11577 SWAPGS_UNSAFE_STACK
11578 movq PER_CPU_VAR(kernel_stack), %rsp
11579- addq $(KERNEL_STACK_OFFSET),%rsp
11580- /*
11581- * No need to follow this irqs on/off section: the syscall
11582- * disabled irqs, here we enable it straight after entry:
11583- */
11584- ENABLE_INTERRUPTS(CLBR_NONE)
11585 movl %ebp,%ebp /* zero extension */
11586 pushq_cfi $__USER32_DS
11587 /*CFI_REL_OFFSET ss,0*/
11588@@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
11589 CFI_REL_OFFSET rsp,0
11590 pushfq_cfi
11591 /*CFI_REL_OFFSET rflags,0*/
11592- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
11593- CFI_REGISTER rip,r10
11594+ orl $X86_EFLAGS_IF,(%rsp)
11595+ GET_THREAD_INFO(%r11)
11596+ movl TI_sysenter_return(%r11), %r11d
11597+ CFI_REGISTER rip,r11
11598 pushq_cfi $__USER32_CS
11599 /*CFI_REL_OFFSET cs,0*/
11600 movl %eax, %eax
11601- pushq_cfi %r10
11602+ pushq_cfi %r11
11603 CFI_REL_OFFSET rip,0
11604 pushq_cfi %rax
11605 cld
11606 SAVE_ARGS 0,1,0
11607+ pax_enter_kernel_user
11608+
11609+#ifdef CONFIG_PAX_RANDKSTACK
11610+ pax_erase_kstack
11611+#endif
11612+
11613+ /*
11614+ * No need to follow this irqs on/off section: the syscall
11615+ * disabled irqs, here we enable it straight after entry:
11616+ */
11617+ ENABLE_INTERRUPTS(CLBR_NONE)
11618 /* no need to do an access_ok check here because rbp has been
11619 32bit zero extended */
11620+
11621+#ifdef CONFIG_PAX_MEMORY_UDEREF
11622+ mov pax_user_shadow_base,%r11
11623+ add %r11,%rbp
11624+#endif
11625+
11626 ASM_STAC
11627 1: movl (%rbp),%ebp
11628 _ASM_EXTABLE(1b,ia32_badarg)
11629 ASM_CLAC
11630- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11631- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11632+ GET_THREAD_INFO(%r11)
11633+ orl $TS_COMPAT,TI_status(%r11)
11634+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11635 CFI_REMEMBER_STATE
11636 jnz sysenter_tracesys
11637 cmpq $(IA32_NR_syscalls-1),%rax
11638@@ -162,12 +204,15 @@ sysenter_do_call:
11639 sysenter_dispatch:
11640 call *ia32_sys_call_table(,%rax,8)
11641 movq %rax,RAX-ARGOFFSET(%rsp)
11642+ GET_THREAD_INFO(%r11)
11643 DISABLE_INTERRUPTS(CLBR_NONE)
11644 TRACE_IRQS_OFF
11645- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11646+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11647 jnz sysexit_audit
11648 sysexit_from_sys_call:
11649- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11650+ pax_exit_kernel_user
11651+ pax_erase_kstack
11652+ andl $~TS_COMPAT,TI_status(%r11)
11653 /* clear IF, that popfq doesn't enable interrupts early */
11654 andl $~0x200,EFLAGS-R11(%rsp)
11655 movl RIP-R11(%rsp),%edx /* User %eip */
11656@@ -193,6 +238,9 @@ sysexit_from_sys_call:
11657 movl %eax,%esi /* 2nd arg: syscall number */
11658 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
11659 call __audit_syscall_entry
11660+
11661+ pax_erase_kstack
11662+
11663 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
11664 cmpq $(IA32_NR_syscalls-1),%rax
11665 ja ia32_badsys
11666@@ -204,7 +252,7 @@ sysexit_from_sys_call:
11667 .endm
11668
11669 .macro auditsys_exit exit
11670- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11671+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11672 jnz ia32_ret_from_sys_call
11673 TRACE_IRQS_ON
11674 ENABLE_INTERRUPTS(CLBR_NONE)
11675@@ -215,11 +263,12 @@ sysexit_from_sys_call:
11676 1: setbe %al /* 1 if error, 0 if not */
11677 movzbl %al,%edi /* zero-extend that into %edi */
11678 call __audit_syscall_exit
11679+ GET_THREAD_INFO(%r11)
11680 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
11681 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
11682 DISABLE_INTERRUPTS(CLBR_NONE)
11683 TRACE_IRQS_OFF
11684- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11685+ testl %edi,TI_flags(%r11)
11686 jz \exit
11687 CLEAR_RREGS -ARGOFFSET
11688 jmp int_with_check
11689@@ -237,7 +286,7 @@ sysexit_audit:
11690
11691 sysenter_tracesys:
11692 #ifdef CONFIG_AUDITSYSCALL
11693- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11694+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11695 jz sysenter_auditsys
11696 #endif
11697 SAVE_REST
11698@@ -249,6 +298,9 @@ sysenter_tracesys:
11699 RESTORE_REST
11700 cmpq $(IA32_NR_syscalls-1),%rax
11701 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
11702+
11703+ pax_erase_kstack
11704+
11705 jmp sysenter_do_call
11706 CFI_ENDPROC
11707 ENDPROC(ia32_sysenter_target)
11708@@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
11709 ENTRY(ia32_cstar_target)
11710 CFI_STARTPROC32 simple
11711 CFI_SIGNAL_FRAME
11712- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
11713+ CFI_DEF_CFA rsp,0
11714 CFI_REGISTER rip,rcx
11715 /*CFI_REGISTER rflags,r11*/
11716 SWAPGS_UNSAFE_STACK
11717 movl %esp,%r8d
11718 CFI_REGISTER rsp,r8
11719 movq PER_CPU_VAR(kernel_stack),%rsp
11720+ SAVE_ARGS 8*6,0,0
11721+ pax_enter_kernel_user
11722+
11723+#ifdef CONFIG_PAX_RANDKSTACK
11724+ pax_erase_kstack
11725+#endif
11726+
11727 /*
11728 * No need to follow this irqs on/off section: the syscall
11729 * disabled irqs and here we enable it straight after entry:
11730 */
11731 ENABLE_INTERRUPTS(CLBR_NONE)
11732- SAVE_ARGS 8,0,0
11733 movl %eax,%eax /* zero extension */
11734 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
11735 movq %rcx,RIP-ARGOFFSET(%rsp)
11736@@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
11737 /* no need to do an access_ok check here because r8 has been
11738 32bit zero extended */
11739 /* hardware stack frame is complete now */
11740+
11741+#ifdef CONFIG_PAX_MEMORY_UDEREF
11742+ mov pax_user_shadow_base,%r11
11743+ add %r11,%r8
11744+#endif
11745+
11746 ASM_STAC
11747 1: movl (%r8),%r9d
11748 _ASM_EXTABLE(1b,ia32_badarg)
11749 ASM_CLAC
11750- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11751- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11752+ GET_THREAD_INFO(%r11)
11753+ orl $TS_COMPAT,TI_status(%r11)
11754+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11755 CFI_REMEMBER_STATE
11756 jnz cstar_tracesys
11757 cmpq $IA32_NR_syscalls-1,%rax
11758@@ -319,12 +384,15 @@ cstar_do_call:
11759 cstar_dispatch:
11760 call *ia32_sys_call_table(,%rax,8)
11761 movq %rax,RAX-ARGOFFSET(%rsp)
11762+ GET_THREAD_INFO(%r11)
11763 DISABLE_INTERRUPTS(CLBR_NONE)
11764 TRACE_IRQS_OFF
11765- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11766+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11767 jnz sysretl_audit
11768 sysretl_from_sys_call:
11769- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11770+ pax_exit_kernel_user
11771+ pax_erase_kstack
11772+ andl $~TS_COMPAT,TI_status(%r11)
11773 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
11774 movl RIP-ARGOFFSET(%rsp),%ecx
11775 CFI_REGISTER rip,rcx
11776@@ -352,7 +420,7 @@ sysretl_audit:
11777
11778 cstar_tracesys:
11779 #ifdef CONFIG_AUDITSYSCALL
11780- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11781+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11782 jz cstar_auditsys
11783 #endif
11784 xchgl %r9d,%ebp
11785@@ -366,6 +434,9 @@ cstar_tracesys:
11786 xchgl %ebp,%r9d
11787 cmpq $(IA32_NR_syscalls-1),%rax
11788 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
11789+
11790+ pax_erase_kstack
11791+
11792 jmp cstar_do_call
11793 END(ia32_cstar_target)
11794
11795@@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
11796 CFI_REL_OFFSET rip,RIP-RIP
11797 PARAVIRT_ADJUST_EXCEPTION_FRAME
11798 SWAPGS
11799- /*
11800- * No need to follow this irqs on/off section: the syscall
11801- * disabled irqs and here we enable it straight after entry:
11802- */
11803- ENABLE_INTERRUPTS(CLBR_NONE)
11804 movl %eax,%eax
11805 pushq_cfi %rax
11806 cld
11807 /* note the registers are not zero extended to the sf.
11808 this could be a problem. */
11809 SAVE_ARGS 0,1,0
11810- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11811- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11812+ pax_enter_kernel_user
11813+
11814+#ifdef CONFIG_PAX_RANDKSTACK
11815+ pax_erase_kstack
11816+#endif
11817+
11818+ /*
11819+ * No need to follow this irqs on/off section: the syscall
11820+ * disabled irqs and here we enable it straight after entry:
11821+ */
11822+ ENABLE_INTERRUPTS(CLBR_NONE)
11823+ GET_THREAD_INFO(%r11)
11824+ orl $TS_COMPAT,TI_status(%r11)
11825+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11826 jnz ia32_tracesys
11827 cmpq $(IA32_NR_syscalls-1),%rax
11828 ja ia32_badsys
11829@@ -442,6 +520,9 @@ ia32_tracesys:
11830 RESTORE_REST
11831 cmpq $(IA32_NR_syscalls-1),%rax
11832 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
11833+
11834+ pax_erase_kstack
11835+
11836 jmp ia32_do_call
11837 END(ia32_syscall)
11838
11839diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
11840index ad7a20c..1ffa3c1 100644
11841--- a/arch/x86/ia32/sys_ia32.c
11842+++ b/arch/x86/ia32/sys_ia32.c
11843@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
11844 */
11845 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
11846 {
11847- typeof(ubuf->st_uid) uid = 0;
11848- typeof(ubuf->st_gid) gid = 0;
11849+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
11850+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
11851 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
11852 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
11853 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
11854@@ -205,7 +205,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
11855 return -EFAULT;
11856
11857 set_fs(KERNEL_DS);
11858- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
11859+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
11860 count);
11861 set_fs(old_fs);
11862
11863diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
11864index 372231c..a5aa1a1 100644
11865--- a/arch/x86/include/asm/alternative-asm.h
11866+++ b/arch/x86/include/asm/alternative-asm.h
11867@@ -18,6 +18,45 @@
11868 .endm
11869 #endif
11870
11871+#ifdef KERNEXEC_PLUGIN
11872+ .macro pax_force_retaddr_bts rip=0
11873+ btsq $63,\rip(%rsp)
11874+ .endm
11875+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11876+ .macro pax_force_retaddr rip=0, reload=0
11877+ btsq $63,\rip(%rsp)
11878+ .endm
11879+ .macro pax_force_fptr ptr
11880+ btsq $63,\ptr
11881+ .endm
11882+ .macro pax_set_fptr_mask
11883+ .endm
11884+#endif
11885+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
11886+ .macro pax_force_retaddr rip=0, reload=0
11887+ .if \reload
11888+ pax_set_fptr_mask
11889+ .endif
11890+ orq %r10,\rip(%rsp)
11891+ .endm
11892+ .macro pax_force_fptr ptr
11893+ orq %r10,\ptr
11894+ .endm
11895+ .macro pax_set_fptr_mask
11896+ movabs $0x8000000000000000,%r10
11897+ .endm
11898+#endif
11899+#else
11900+ .macro pax_force_retaddr rip=0, reload=0
11901+ .endm
11902+ .macro pax_force_fptr ptr
11903+ .endm
11904+ .macro pax_force_retaddr_bts rip=0
11905+ .endm
11906+ .macro pax_set_fptr_mask
11907+ .endm
11908+#endif
11909+
11910 .macro altinstruction_entry orig alt feature orig_len alt_len
11911 .long \orig - .
11912 .long \alt - .
11913diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
11914index 58ed6d9..f1cbe58 100644
11915--- a/arch/x86/include/asm/alternative.h
11916+++ b/arch/x86/include/asm/alternative.h
11917@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11918 ".pushsection .discard,\"aw\",@progbits\n" \
11919 DISCARD_ENTRY(1) \
11920 ".popsection\n" \
11921- ".pushsection .altinstr_replacement, \"ax\"\n" \
11922+ ".pushsection .altinstr_replacement, \"a\"\n" \
11923 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
11924 ".popsection"
11925
11926@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11927 DISCARD_ENTRY(1) \
11928 DISCARD_ENTRY(2) \
11929 ".popsection\n" \
11930- ".pushsection .altinstr_replacement, \"ax\"\n" \
11931+ ".pushsection .altinstr_replacement, \"a\"\n" \
11932 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
11933 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
11934 ".popsection"
11935diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
11936index 3388034..050f0b9 100644
11937--- a/arch/x86/include/asm/apic.h
11938+++ b/arch/x86/include/asm/apic.h
11939@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
11940
11941 #ifdef CONFIG_X86_LOCAL_APIC
11942
11943-extern unsigned int apic_verbosity;
11944+extern int apic_verbosity;
11945 extern int local_apic_timer_c2_ok;
11946
11947 extern int disable_apic;
11948diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
11949index 20370c6..a2eb9b0 100644
11950--- a/arch/x86/include/asm/apm.h
11951+++ b/arch/x86/include/asm/apm.h
11952@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
11953 __asm__ __volatile__(APM_DO_ZERO_SEGS
11954 "pushl %%edi\n\t"
11955 "pushl %%ebp\n\t"
11956- "lcall *%%cs:apm_bios_entry\n\t"
11957+ "lcall *%%ss:apm_bios_entry\n\t"
11958 "setc %%al\n\t"
11959 "popl %%ebp\n\t"
11960 "popl %%edi\n\t"
11961@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
11962 __asm__ __volatile__(APM_DO_ZERO_SEGS
11963 "pushl %%edi\n\t"
11964 "pushl %%ebp\n\t"
11965- "lcall *%%cs:apm_bios_entry\n\t"
11966+ "lcall *%%ss:apm_bios_entry\n\t"
11967 "setc %%bl\n\t"
11968 "popl %%ebp\n\t"
11969 "popl %%edi\n\t"
11970diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
11971index 722aa3b..3a0bb27 100644
11972--- a/arch/x86/include/asm/atomic.h
11973+++ b/arch/x86/include/asm/atomic.h
11974@@ -22,7 +22,18 @@
11975 */
11976 static inline int atomic_read(const atomic_t *v)
11977 {
11978- return (*(volatile int *)&(v)->counter);
11979+ return (*(volatile const int *)&(v)->counter);
11980+}
11981+
11982+/**
11983+ * atomic_read_unchecked - read atomic variable
11984+ * @v: pointer of type atomic_unchecked_t
11985+ *
11986+ * Atomically reads the value of @v.
11987+ */
11988+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
11989+{
11990+ return (*(volatile const int *)&(v)->counter);
11991 }
11992
11993 /**
11994@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
11995 }
11996
11997 /**
11998+ * atomic_set_unchecked - set atomic variable
11999+ * @v: pointer of type atomic_unchecked_t
12000+ * @i: required value
12001+ *
12002+ * Atomically sets the value of @v to @i.
12003+ */
12004+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
12005+{
12006+ v->counter = i;
12007+}
12008+
12009+/**
12010 * atomic_add - add integer to atomic variable
12011 * @i: integer value to add
12012 * @v: pointer of type atomic_t
12013@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
12014 */
12015 static inline void atomic_add(int i, atomic_t *v)
12016 {
12017- asm volatile(LOCK_PREFIX "addl %1,%0"
12018+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
12019+
12020+#ifdef CONFIG_PAX_REFCOUNT
12021+ "jno 0f\n"
12022+ LOCK_PREFIX "subl %1,%0\n"
12023+ "int $4\n0:\n"
12024+ _ASM_EXTABLE(0b, 0b)
12025+#endif
12026+
12027+ : "+m" (v->counter)
12028+ : "ir" (i));
12029+}
12030+
12031+/**
12032+ * atomic_add_unchecked - add integer to atomic variable
12033+ * @i: integer value to add
12034+ * @v: pointer of type atomic_unchecked_t
12035+ *
12036+ * Atomically adds @i to @v.
12037+ */
12038+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
12039+{
12040+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
12041 : "+m" (v->counter)
12042 : "ir" (i));
12043 }
12044@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
12045 */
12046 static inline void atomic_sub(int i, atomic_t *v)
12047 {
12048- asm volatile(LOCK_PREFIX "subl %1,%0"
12049+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
12050+
12051+#ifdef CONFIG_PAX_REFCOUNT
12052+ "jno 0f\n"
12053+ LOCK_PREFIX "addl %1,%0\n"
12054+ "int $4\n0:\n"
12055+ _ASM_EXTABLE(0b, 0b)
12056+#endif
12057+
12058+ : "+m" (v->counter)
12059+ : "ir" (i));
12060+}
12061+
12062+/**
12063+ * atomic_sub_unchecked - subtract integer from atomic variable
12064+ * @i: integer value to subtract
12065+ * @v: pointer of type atomic_unchecked_t
12066+ *
12067+ * Atomically subtracts @i from @v.
12068+ */
12069+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
12070+{
12071+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
12072 : "+m" (v->counter)
12073 : "ir" (i));
12074 }
12075@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
12076 {
12077 unsigned char c;
12078
12079- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
12080+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
12081+
12082+#ifdef CONFIG_PAX_REFCOUNT
12083+ "jno 0f\n"
12084+ LOCK_PREFIX "addl %2,%0\n"
12085+ "int $4\n0:\n"
12086+ _ASM_EXTABLE(0b, 0b)
12087+#endif
12088+
12089+ "sete %1\n"
12090 : "+m" (v->counter), "=qm" (c)
12091 : "ir" (i) : "memory");
12092 return c;
12093@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
12094 */
12095 static inline void atomic_inc(atomic_t *v)
12096 {
12097- asm volatile(LOCK_PREFIX "incl %0"
12098+ asm volatile(LOCK_PREFIX "incl %0\n"
12099+
12100+#ifdef CONFIG_PAX_REFCOUNT
12101+ "jno 0f\n"
12102+ LOCK_PREFIX "decl %0\n"
12103+ "int $4\n0:\n"
12104+ _ASM_EXTABLE(0b, 0b)
12105+#endif
12106+
12107+ : "+m" (v->counter));
12108+}
12109+
12110+/**
12111+ * atomic_inc_unchecked - increment atomic variable
12112+ * @v: pointer of type atomic_unchecked_t
12113+ *
12114+ * Atomically increments @v by 1.
12115+ */
12116+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
12117+{
12118+ asm volatile(LOCK_PREFIX "incl %0\n"
12119 : "+m" (v->counter));
12120 }
12121
12122@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
12123 */
12124 static inline void atomic_dec(atomic_t *v)
12125 {
12126- asm volatile(LOCK_PREFIX "decl %0"
12127+ asm volatile(LOCK_PREFIX "decl %0\n"
12128+
12129+#ifdef CONFIG_PAX_REFCOUNT
12130+ "jno 0f\n"
12131+ LOCK_PREFIX "incl %0\n"
12132+ "int $4\n0:\n"
12133+ _ASM_EXTABLE(0b, 0b)
12134+#endif
12135+
12136+ : "+m" (v->counter));
12137+}
12138+
12139+/**
12140+ * atomic_dec_unchecked - decrement atomic variable
12141+ * @v: pointer of type atomic_unchecked_t
12142+ *
12143+ * Atomically decrements @v by 1.
12144+ */
12145+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
12146+{
12147+ asm volatile(LOCK_PREFIX "decl %0\n"
12148 : "+m" (v->counter));
12149 }
12150
12151@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
12152 {
12153 unsigned char c;
12154
12155- asm volatile(LOCK_PREFIX "decl %0; sete %1"
12156+ asm volatile(LOCK_PREFIX "decl %0\n"
12157+
12158+#ifdef CONFIG_PAX_REFCOUNT
12159+ "jno 0f\n"
12160+ LOCK_PREFIX "incl %0\n"
12161+ "int $4\n0:\n"
12162+ _ASM_EXTABLE(0b, 0b)
12163+#endif
12164+
12165+ "sete %1\n"
12166 : "+m" (v->counter), "=qm" (c)
12167 : : "memory");
12168 return c != 0;
12169@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
12170 {
12171 unsigned char c;
12172
12173- asm volatile(LOCK_PREFIX "incl %0; sete %1"
12174+ asm volatile(LOCK_PREFIX "incl %0\n"
12175+
12176+#ifdef CONFIG_PAX_REFCOUNT
12177+ "jno 0f\n"
12178+ LOCK_PREFIX "decl %0\n"
12179+ "int $4\n0:\n"
12180+ _ASM_EXTABLE(0b, 0b)
12181+#endif
12182+
12183+ "sete %1\n"
12184+ : "+m" (v->counter), "=qm" (c)
12185+ : : "memory");
12186+ return c != 0;
12187+}
12188+
12189+/**
12190+ * atomic_inc_and_test_unchecked - increment and test
12191+ * @v: pointer of type atomic_unchecked_t
12192+ *
12193+ * Atomically increments @v by 1
12194+ * and returns true if the result is zero, or false for all
12195+ * other cases.
12196+ */
12197+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
12198+{
12199+ unsigned char c;
12200+
12201+ asm volatile(LOCK_PREFIX "incl %0\n"
12202+ "sete %1\n"
12203 : "+m" (v->counter), "=qm" (c)
12204 : : "memory");
12205 return c != 0;
12206@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12207 {
12208 unsigned char c;
12209
12210- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
12211+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
12212+
12213+#ifdef CONFIG_PAX_REFCOUNT
12214+ "jno 0f\n"
12215+ LOCK_PREFIX "subl %2,%0\n"
12216+ "int $4\n0:\n"
12217+ _ASM_EXTABLE(0b, 0b)
12218+#endif
12219+
12220+ "sets %1\n"
12221 : "+m" (v->counter), "=qm" (c)
12222 : "ir" (i) : "memory");
12223 return c;
12224@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12225 */
12226 static inline int atomic_add_return(int i, atomic_t *v)
12227 {
12228+ return i + xadd_check_overflow(&v->counter, i);
12229+}
12230+
12231+/**
12232+ * atomic_add_return_unchecked - add integer and return
12233+ * @i: integer value to add
12234+ * @v: pointer of type atomic_unchecked_t
12235+ *
12236+ * Atomically adds @i to @v and returns @i + @v
12237+ */
12238+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
12239+{
12240 return i + xadd(&v->counter, i);
12241 }
12242
12243@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
12244 }
12245
12246 #define atomic_inc_return(v) (atomic_add_return(1, v))
12247+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
12248+{
12249+ return atomic_add_return_unchecked(1, v);
12250+}
12251 #define atomic_dec_return(v) (atomic_sub_return(1, v))
12252
12253 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12254@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12255 return cmpxchg(&v->counter, old, new);
12256 }
12257
12258+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
12259+{
12260+ return cmpxchg(&v->counter, old, new);
12261+}
12262+
12263 static inline int atomic_xchg(atomic_t *v, int new)
12264 {
12265 return xchg(&v->counter, new);
12266 }
12267
12268+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
12269+{
12270+ return xchg(&v->counter, new);
12271+}
12272+
12273 /**
12274 * __atomic_add_unless - add unless the number is already a given value
12275 * @v: pointer of type atomic_t
12276@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
12277 */
12278 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12279 {
12280- int c, old;
12281+ int c, old, new;
12282 c = atomic_read(v);
12283 for (;;) {
12284- if (unlikely(c == (u)))
12285+ if (unlikely(c == u))
12286 break;
12287- old = atomic_cmpxchg((v), c, c + (a));
12288+
12289+ asm volatile("addl %2,%0\n"
12290+
12291+#ifdef CONFIG_PAX_REFCOUNT
12292+ "jno 0f\n"
12293+ "subl %2,%0\n"
12294+ "int $4\n0:\n"
12295+ _ASM_EXTABLE(0b, 0b)
12296+#endif
12297+
12298+ : "=r" (new)
12299+ : "0" (c), "ir" (a));
12300+
12301+ old = atomic_cmpxchg(v, c, new);
12302 if (likely(old == c))
12303 break;
12304 c = old;
12305@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12306 }
12307
12308 /**
12309+ * atomic_inc_not_zero_hint - increment if not null
12310+ * @v: pointer of type atomic_t
12311+ * @hint: probable value of the atomic before the increment
12312+ *
12313+ * This version of atomic_inc_not_zero() gives a hint of probable
12314+ * value of the atomic. This helps processor to not read the memory
12315+ * before doing the atomic read/modify/write cycle, lowering
12316+ * number of bus transactions on some arches.
12317+ *
12318+ * Returns: 0 if increment was not done, 1 otherwise.
12319+ */
12320+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
12321+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
12322+{
12323+ int val, c = hint, new;
12324+
12325+ /* sanity test, should be removed by compiler if hint is a constant */
12326+ if (!hint)
12327+ return __atomic_add_unless(v, 1, 0);
12328+
12329+ do {
12330+ asm volatile("incl %0\n"
12331+
12332+#ifdef CONFIG_PAX_REFCOUNT
12333+ "jno 0f\n"
12334+ "decl %0\n"
12335+ "int $4\n0:\n"
12336+ _ASM_EXTABLE(0b, 0b)
12337+#endif
12338+
12339+ : "=r" (new)
12340+ : "0" (c));
12341+
12342+ val = atomic_cmpxchg(v, c, new);
12343+ if (val == c)
12344+ return 1;
12345+ c = val;
12346+ } while (c);
12347+
12348+ return 0;
12349+}
12350+
12351+/**
12352 * atomic_inc_short - increment of a short integer
12353 * @v: pointer to type int
12354 *
12355@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
12356 #endif
12357
12358 /* These are x86-specific, used by some header files */
12359-#define atomic_clear_mask(mask, addr) \
12360- asm volatile(LOCK_PREFIX "andl %0,%1" \
12361- : : "r" (~(mask)), "m" (*(addr)) : "memory")
12362+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
12363+{
12364+ asm volatile(LOCK_PREFIX "andl %1,%0"
12365+ : "+m" (v->counter)
12366+ : "r" (~(mask))
12367+ : "memory");
12368+}
12369
12370-#define atomic_set_mask(mask, addr) \
12371- asm volatile(LOCK_PREFIX "orl %0,%1" \
12372- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
12373- : "memory")
12374+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12375+{
12376+ asm volatile(LOCK_PREFIX "andl %1,%0"
12377+ : "+m" (v->counter)
12378+ : "r" (~(mask))
12379+ : "memory");
12380+}
12381+
12382+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
12383+{
12384+ asm volatile(LOCK_PREFIX "orl %1,%0"
12385+ : "+m" (v->counter)
12386+ : "r" (mask)
12387+ : "memory");
12388+}
12389+
12390+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12391+{
12392+ asm volatile(LOCK_PREFIX "orl %1,%0"
12393+ : "+m" (v->counter)
12394+ : "r" (mask)
12395+ : "memory");
12396+}
12397
12398 /* Atomic operations are already serializing on x86 */
12399 #define smp_mb__before_atomic_dec() barrier()
12400diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
12401index b154de7..aadebd8 100644
12402--- a/arch/x86/include/asm/atomic64_32.h
12403+++ b/arch/x86/include/asm/atomic64_32.h
12404@@ -12,6 +12,14 @@ typedef struct {
12405 u64 __aligned(8) counter;
12406 } atomic64_t;
12407
12408+#ifdef CONFIG_PAX_REFCOUNT
12409+typedef struct {
12410+ u64 __aligned(8) counter;
12411+} atomic64_unchecked_t;
12412+#else
12413+typedef atomic64_t atomic64_unchecked_t;
12414+#endif
12415+
12416 #define ATOMIC64_INIT(val) { (val) }
12417
12418 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
12419@@ -37,21 +45,31 @@ typedef struct {
12420 ATOMIC64_DECL_ONE(sym##_386)
12421
12422 ATOMIC64_DECL_ONE(add_386);
12423+ATOMIC64_DECL_ONE(add_unchecked_386);
12424 ATOMIC64_DECL_ONE(sub_386);
12425+ATOMIC64_DECL_ONE(sub_unchecked_386);
12426 ATOMIC64_DECL_ONE(inc_386);
12427+ATOMIC64_DECL_ONE(inc_unchecked_386);
12428 ATOMIC64_DECL_ONE(dec_386);
12429+ATOMIC64_DECL_ONE(dec_unchecked_386);
12430 #endif
12431
12432 #define alternative_atomic64(f, out, in...) \
12433 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
12434
12435 ATOMIC64_DECL(read);
12436+ATOMIC64_DECL(read_unchecked);
12437 ATOMIC64_DECL(set);
12438+ATOMIC64_DECL(set_unchecked);
12439 ATOMIC64_DECL(xchg);
12440 ATOMIC64_DECL(add_return);
12441+ATOMIC64_DECL(add_return_unchecked);
12442 ATOMIC64_DECL(sub_return);
12443+ATOMIC64_DECL(sub_return_unchecked);
12444 ATOMIC64_DECL(inc_return);
12445+ATOMIC64_DECL(inc_return_unchecked);
12446 ATOMIC64_DECL(dec_return);
12447+ATOMIC64_DECL(dec_return_unchecked);
12448 ATOMIC64_DECL(dec_if_positive);
12449 ATOMIC64_DECL(inc_not_zero);
12450 ATOMIC64_DECL(add_unless);
12451@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
12452 }
12453
12454 /**
12455+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
12456+ * @p: pointer to type atomic64_unchecked_t
12457+ * @o: expected value
12458+ * @n: new value
12459+ *
12460+ * Atomically sets @v to @n if it was equal to @o and returns
12461+ * the old value.
12462+ */
12463+
12464+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
12465+{
12466+ return cmpxchg64(&v->counter, o, n);
12467+}
12468+
12469+/**
12470 * atomic64_xchg - xchg atomic64 variable
12471 * @v: pointer to type atomic64_t
12472 * @n: value to assign
12473@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
12474 }
12475
12476 /**
12477+ * atomic64_set_unchecked - set atomic64 variable
12478+ * @v: pointer to type atomic64_unchecked_t
12479+ * @n: value to assign
12480+ *
12481+ * Atomically sets the value of @v to @n.
12482+ */
12483+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
12484+{
12485+ unsigned high = (unsigned)(i >> 32);
12486+ unsigned low = (unsigned)i;
12487+ alternative_atomic64(set, /* no output */,
12488+ "S" (v), "b" (low), "c" (high)
12489+ : "eax", "edx", "memory");
12490+}
12491+
12492+/**
12493 * atomic64_read - read atomic64 variable
12494 * @v: pointer to type atomic64_t
12495 *
12496@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
12497 }
12498
12499 /**
12500+ * atomic64_read_unchecked - read atomic64 variable
12501+ * @v: pointer to type atomic64_unchecked_t
12502+ *
12503+ * Atomically reads the value of @v and returns it.
12504+ */
12505+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
12506+{
12507+ long long r;
12508+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
12509+ return r;
12510+ }
12511+
12512+/**
12513 * atomic64_add_return - add and return
12514 * @i: integer value to add
12515 * @v: pointer to type atomic64_t
12516@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
12517 return i;
12518 }
12519
12520+/**
12521+ * atomic64_add_return_unchecked - add and return
12522+ * @i: integer value to add
12523+ * @v: pointer to type atomic64_unchecked_t
12524+ *
12525+ * Atomically adds @i to @v and returns @i + *@v
12526+ */
12527+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
12528+{
12529+ alternative_atomic64(add_return_unchecked,
12530+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12531+ ASM_NO_INPUT_CLOBBER("memory"));
12532+ return i;
12533+}
12534+
12535 /*
12536 * Other variants with different arithmetic operators:
12537 */
12538@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
12539 return a;
12540 }
12541
12542+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12543+{
12544+ long long a;
12545+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
12546+ "S" (v) : "memory", "ecx");
12547+ return a;
12548+}
12549+
12550 static inline long long atomic64_dec_return(atomic64_t *v)
12551 {
12552 long long a;
12553@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
12554 }
12555
12556 /**
12557+ * atomic64_add_unchecked - add integer to atomic64 variable
12558+ * @i: integer value to add
12559+ * @v: pointer to type atomic64_unchecked_t
12560+ *
12561+ * Atomically adds @i to @v.
12562+ */
12563+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
12564+{
12565+ __alternative_atomic64(add_unchecked, add_return_unchecked,
12566+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12567+ ASM_NO_INPUT_CLOBBER("memory"));
12568+ return i;
12569+}
12570+
12571+/**
12572 * atomic64_sub - subtract the atomic64 variable
12573 * @i: integer value to subtract
12574 * @v: pointer to type atomic64_t
12575diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
12576index 0e1cbfc..5623683 100644
12577--- a/arch/x86/include/asm/atomic64_64.h
12578+++ b/arch/x86/include/asm/atomic64_64.h
12579@@ -18,7 +18,19 @@
12580 */
12581 static inline long atomic64_read(const atomic64_t *v)
12582 {
12583- return (*(volatile long *)&(v)->counter);
12584+ return (*(volatile const long *)&(v)->counter);
12585+}
12586+
12587+/**
12588+ * atomic64_read_unchecked - read atomic64 variable
12589+ * @v: pointer of type atomic64_unchecked_t
12590+ *
12591+ * Atomically reads the value of @v.
12592+ * Doesn't imply a read memory barrier.
12593+ */
12594+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
12595+{
12596+ return (*(volatile const long *)&(v)->counter);
12597 }
12598
12599 /**
12600@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
12601 }
12602
12603 /**
12604+ * atomic64_set_unchecked - set atomic64 variable
12605+ * @v: pointer to type atomic64_unchecked_t
12606+ * @i: required value
12607+ *
12608+ * Atomically sets the value of @v to @i.
12609+ */
12610+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
12611+{
12612+ v->counter = i;
12613+}
12614+
12615+/**
12616 * atomic64_add - add integer to atomic64 variable
12617 * @i: integer value to add
12618 * @v: pointer to type atomic64_t
12619@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
12620 */
12621 static inline void atomic64_add(long i, atomic64_t *v)
12622 {
12623+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
12624+
12625+#ifdef CONFIG_PAX_REFCOUNT
12626+ "jno 0f\n"
12627+ LOCK_PREFIX "subq %1,%0\n"
12628+ "int $4\n0:\n"
12629+ _ASM_EXTABLE(0b, 0b)
12630+#endif
12631+
12632+ : "=m" (v->counter)
12633+ : "er" (i), "m" (v->counter));
12634+}
12635+
12636+/**
12637+ * atomic64_add_unchecked - add integer to atomic64 variable
12638+ * @i: integer value to add
12639+ * @v: pointer to type atomic64_unchecked_t
12640+ *
12641+ * Atomically adds @i to @v.
12642+ */
12643+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
12644+{
12645 asm volatile(LOCK_PREFIX "addq %1,%0"
12646 : "=m" (v->counter)
12647 : "er" (i), "m" (v->counter));
12648@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
12649 */
12650 static inline void atomic64_sub(long i, atomic64_t *v)
12651 {
12652- asm volatile(LOCK_PREFIX "subq %1,%0"
12653+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12654+
12655+#ifdef CONFIG_PAX_REFCOUNT
12656+ "jno 0f\n"
12657+ LOCK_PREFIX "addq %1,%0\n"
12658+ "int $4\n0:\n"
12659+ _ASM_EXTABLE(0b, 0b)
12660+#endif
12661+
12662+ : "=m" (v->counter)
12663+ : "er" (i), "m" (v->counter));
12664+}
12665+
12666+/**
12667+ * atomic64_sub_unchecked - subtract the atomic64 variable
12668+ * @i: integer value to subtract
12669+ * @v: pointer to type atomic64_unchecked_t
12670+ *
12671+ * Atomically subtracts @i from @v.
12672+ */
12673+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
12674+{
12675+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12676 : "=m" (v->counter)
12677 : "er" (i), "m" (v->counter));
12678 }
12679@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12680 {
12681 unsigned char c;
12682
12683- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
12684+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
12685+
12686+#ifdef CONFIG_PAX_REFCOUNT
12687+ "jno 0f\n"
12688+ LOCK_PREFIX "addq %2,%0\n"
12689+ "int $4\n0:\n"
12690+ _ASM_EXTABLE(0b, 0b)
12691+#endif
12692+
12693+ "sete %1\n"
12694 : "=m" (v->counter), "=qm" (c)
12695 : "er" (i), "m" (v->counter) : "memory");
12696 return c;
12697@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12698 */
12699 static inline void atomic64_inc(atomic64_t *v)
12700 {
12701+ asm volatile(LOCK_PREFIX "incq %0\n"
12702+
12703+#ifdef CONFIG_PAX_REFCOUNT
12704+ "jno 0f\n"
12705+ LOCK_PREFIX "decq %0\n"
12706+ "int $4\n0:\n"
12707+ _ASM_EXTABLE(0b, 0b)
12708+#endif
12709+
12710+ : "=m" (v->counter)
12711+ : "m" (v->counter));
12712+}
12713+
12714+/**
12715+ * atomic64_inc_unchecked - increment atomic64 variable
12716+ * @v: pointer to type atomic64_unchecked_t
12717+ *
12718+ * Atomically increments @v by 1.
12719+ */
12720+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
12721+{
12722 asm volatile(LOCK_PREFIX "incq %0"
12723 : "=m" (v->counter)
12724 : "m" (v->counter));
12725@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
12726 */
12727 static inline void atomic64_dec(atomic64_t *v)
12728 {
12729- asm volatile(LOCK_PREFIX "decq %0"
12730+ asm volatile(LOCK_PREFIX "decq %0\n"
12731+
12732+#ifdef CONFIG_PAX_REFCOUNT
12733+ "jno 0f\n"
12734+ LOCK_PREFIX "incq %0\n"
12735+ "int $4\n0:\n"
12736+ _ASM_EXTABLE(0b, 0b)
12737+#endif
12738+
12739+ : "=m" (v->counter)
12740+ : "m" (v->counter));
12741+}
12742+
12743+/**
12744+ * atomic64_dec_unchecked - decrement atomic64 variable
12745+ * @v: pointer to type atomic64_t
12746+ *
12747+ * Atomically decrements @v by 1.
12748+ */
12749+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
12750+{
12751+ asm volatile(LOCK_PREFIX "decq %0\n"
12752 : "=m" (v->counter)
12753 : "m" (v->counter));
12754 }
12755@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
12756 {
12757 unsigned char c;
12758
12759- asm volatile(LOCK_PREFIX "decq %0; sete %1"
12760+ asm volatile(LOCK_PREFIX "decq %0\n"
12761+
12762+#ifdef CONFIG_PAX_REFCOUNT
12763+ "jno 0f\n"
12764+ LOCK_PREFIX "incq %0\n"
12765+ "int $4\n0:\n"
12766+ _ASM_EXTABLE(0b, 0b)
12767+#endif
12768+
12769+ "sete %1\n"
12770 : "=m" (v->counter), "=qm" (c)
12771 : "m" (v->counter) : "memory");
12772 return c != 0;
12773@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
12774 {
12775 unsigned char c;
12776
12777- asm volatile(LOCK_PREFIX "incq %0; sete %1"
12778+ asm volatile(LOCK_PREFIX "incq %0\n"
12779+
12780+#ifdef CONFIG_PAX_REFCOUNT
12781+ "jno 0f\n"
12782+ LOCK_PREFIX "decq %0\n"
12783+ "int $4\n0:\n"
12784+ _ASM_EXTABLE(0b, 0b)
12785+#endif
12786+
12787+ "sete %1\n"
12788 : "=m" (v->counter), "=qm" (c)
12789 : "m" (v->counter) : "memory");
12790 return c != 0;
12791@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12792 {
12793 unsigned char c;
12794
12795- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
12796+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
12797+
12798+#ifdef CONFIG_PAX_REFCOUNT
12799+ "jno 0f\n"
12800+ LOCK_PREFIX "subq %2,%0\n"
12801+ "int $4\n0:\n"
12802+ _ASM_EXTABLE(0b, 0b)
12803+#endif
12804+
12805+ "sets %1\n"
12806 : "=m" (v->counter), "=qm" (c)
12807 : "er" (i), "m" (v->counter) : "memory");
12808 return c;
12809@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12810 */
12811 static inline long atomic64_add_return(long i, atomic64_t *v)
12812 {
12813+ return i + xadd_check_overflow(&v->counter, i);
12814+}
12815+
12816+/**
12817+ * atomic64_add_return_unchecked - add and return
12818+ * @i: integer value to add
12819+ * @v: pointer to type atomic64_unchecked_t
12820+ *
12821+ * Atomically adds @i to @v and returns @i + @v
12822+ */
12823+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
12824+{
12825 return i + xadd(&v->counter, i);
12826 }
12827
12828@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
12829 }
12830
12831 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
12832+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12833+{
12834+ return atomic64_add_return_unchecked(1, v);
12835+}
12836 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
12837
12838 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12839@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12840 return cmpxchg(&v->counter, old, new);
12841 }
12842
12843+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
12844+{
12845+ return cmpxchg(&v->counter, old, new);
12846+}
12847+
12848 static inline long atomic64_xchg(atomic64_t *v, long new)
12849 {
12850 return xchg(&v->counter, new);
12851@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
12852 */
12853 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
12854 {
12855- long c, old;
12856+ long c, old, new;
12857 c = atomic64_read(v);
12858 for (;;) {
12859- if (unlikely(c == (u)))
12860+ if (unlikely(c == u))
12861 break;
12862- old = atomic64_cmpxchg((v), c, c + (a));
12863+
12864+ asm volatile("add %2,%0\n"
12865+
12866+#ifdef CONFIG_PAX_REFCOUNT
12867+ "jno 0f\n"
12868+ "sub %2,%0\n"
12869+ "int $4\n0:\n"
12870+ _ASM_EXTABLE(0b, 0b)
12871+#endif
12872+
12873+ : "=r" (new)
12874+ : "0" (c), "ir" (a));
12875+
12876+ old = atomic64_cmpxchg(v, c, new);
12877 if (likely(old == c))
12878 break;
12879 c = old;
12880 }
12881- return c != (u);
12882+ return c != u;
12883 }
12884
12885 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12886diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
12887index 6dfd019..28e188d 100644
12888--- a/arch/x86/include/asm/bitops.h
12889+++ b/arch/x86/include/asm/bitops.h
12890@@ -40,7 +40,7 @@
12891 * a mask operation on a byte.
12892 */
12893 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
12894-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
12895+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
12896 #define CONST_MASK(nr) (1 << ((nr) & 7))
12897
12898 /**
12899@@ -486,7 +486,7 @@ static inline int fls(int x)
12900 * at position 64.
12901 */
12902 #ifdef CONFIG_X86_64
12903-static __always_inline int fls64(__u64 x)
12904+static __always_inline long fls64(__u64 x)
12905 {
12906 int bitpos = -1;
12907 /*
12908diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
12909index 4fa687a..60f2d39 100644
12910--- a/arch/x86/include/asm/boot.h
12911+++ b/arch/x86/include/asm/boot.h
12912@@ -6,10 +6,15 @@
12913 #include <uapi/asm/boot.h>
12914
12915 /* Physical address where kernel should be loaded. */
12916-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12917+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12918 + (CONFIG_PHYSICAL_ALIGN - 1)) \
12919 & ~(CONFIG_PHYSICAL_ALIGN - 1))
12920
12921+#ifndef __ASSEMBLY__
12922+extern unsigned char __LOAD_PHYSICAL_ADDR[];
12923+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
12924+#endif
12925+
12926 /* Minimum kernel alignment, as a power of two */
12927 #ifdef CONFIG_X86_64
12928 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
12929diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
12930index 48f99f1..d78ebf9 100644
12931--- a/arch/x86/include/asm/cache.h
12932+++ b/arch/x86/include/asm/cache.h
12933@@ -5,12 +5,13 @@
12934
12935 /* L1 cache line size */
12936 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12937-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12938+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12939
12940 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
12941+#define __read_only __attribute__((__section__(".data..read_only")))
12942
12943 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
12944-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
12945+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
12946
12947 #ifdef CONFIG_X86_VSMP
12948 #ifdef CONFIG_SMP
12949diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
12950index 9863ee3..4a1f8e1 100644
12951--- a/arch/x86/include/asm/cacheflush.h
12952+++ b/arch/x86/include/asm/cacheflush.h
12953@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
12954 unsigned long pg_flags = pg->flags & _PGMT_MASK;
12955
12956 if (pg_flags == _PGMT_DEFAULT)
12957- return -1;
12958+ return ~0UL;
12959 else if (pg_flags == _PGMT_WC)
12960 return _PAGE_CACHE_WC;
12961 else if (pg_flags == _PGMT_UC_MINUS)
12962diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
12963index 46fc474..b02b0f9 100644
12964--- a/arch/x86/include/asm/checksum_32.h
12965+++ b/arch/x86/include/asm/checksum_32.h
12966@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
12967 int len, __wsum sum,
12968 int *src_err_ptr, int *dst_err_ptr);
12969
12970+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
12971+ int len, __wsum sum,
12972+ int *src_err_ptr, int *dst_err_ptr);
12973+
12974+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
12975+ int len, __wsum sum,
12976+ int *src_err_ptr, int *dst_err_ptr);
12977+
12978 /*
12979 * Note: when you get a NULL pointer exception here this means someone
12980 * passed in an incorrect kernel address to one of these functions.
12981@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
12982 int *err_ptr)
12983 {
12984 might_sleep();
12985- return csum_partial_copy_generic((__force void *)src, dst,
12986+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
12987 len, sum, err_ptr, NULL);
12988 }
12989
12990@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
12991 {
12992 might_sleep();
12993 if (access_ok(VERIFY_WRITE, dst, len))
12994- return csum_partial_copy_generic(src, (__force void *)dst,
12995+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
12996 len, sum, NULL, err_ptr);
12997
12998 if (len)
12999diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
13000index 8d871ea..c1a0dc9 100644
13001--- a/arch/x86/include/asm/cmpxchg.h
13002+++ b/arch/x86/include/asm/cmpxchg.h
13003@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
13004 __compiletime_error("Bad argument size for cmpxchg");
13005 extern void __xadd_wrong_size(void)
13006 __compiletime_error("Bad argument size for xadd");
13007+extern void __xadd_check_overflow_wrong_size(void)
13008+ __compiletime_error("Bad argument size for xadd_check_overflow");
13009 extern void __add_wrong_size(void)
13010 __compiletime_error("Bad argument size for add");
13011+extern void __add_check_overflow_wrong_size(void)
13012+ __compiletime_error("Bad argument size for add_check_overflow");
13013
13014 /*
13015 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
13016@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
13017 __ret; \
13018 })
13019
13020+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
13021+ ({ \
13022+ __typeof__ (*(ptr)) __ret = (arg); \
13023+ switch (sizeof(*(ptr))) { \
13024+ case __X86_CASE_L: \
13025+ asm volatile (lock #op "l %0, %1\n" \
13026+ "jno 0f\n" \
13027+ "mov %0,%1\n" \
13028+ "int $4\n0:\n" \
13029+ _ASM_EXTABLE(0b, 0b) \
13030+ : "+r" (__ret), "+m" (*(ptr)) \
13031+ : : "memory", "cc"); \
13032+ break; \
13033+ case __X86_CASE_Q: \
13034+ asm volatile (lock #op "q %q0, %1\n" \
13035+ "jno 0f\n" \
13036+ "mov %0,%1\n" \
13037+ "int $4\n0:\n" \
13038+ _ASM_EXTABLE(0b, 0b) \
13039+ : "+r" (__ret), "+m" (*(ptr)) \
13040+ : : "memory", "cc"); \
13041+ break; \
13042+ default: \
13043+ __ ## op ## _check_overflow_wrong_size(); \
13044+ } \
13045+ __ret; \
13046+ })
13047+
13048 /*
13049 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
13050 * Since this is generally used to protect other memory information, we
13051@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
13052 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
13053 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
13054
13055+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
13056+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
13057+
13058 #define __add(ptr, inc, lock) \
13059 ({ \
13060 __typeof__ (*(ptr)) __ret = (inc); \
13061diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
13062index 59c6c40..5e0b22c 100644
13063--- a/arch/x86/include/asm/compat.h
13064+++ b/arch/x86/include/asm/compat.h
13065@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
13066 typedef u32 compat_uint_t;
13067 typedef u32 compat_ulong_t;
13068 typedef u64 __attribute__((aligned(4))) compat_u64;
13069-typedef u32 compat_uptr_t;
13070+typedef u32 __user compat_uptr_t;
13071
13072 struct compat_timespec {
13073 compat_time_t tv_sec;
13074diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
13075index 93fe929..90858b7 100644
13076--- a/arch/x86/include/asm/cpufeature.h
13077+++ b/arch/x86/include/asm/cpufeature.h
13078@@ -207,7 +207,7 @@
13079 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
13080 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
13081 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
13082-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
13083+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
13084 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
13085 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
13086 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
13087@@ -377,7 +377,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
13088 ".section .discard,\"aw\",@progbits\n"
13089 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
13090 ".previous\n"
13091- ".section .altinstr_replacement,\"ax\"\n"
13092+ ".section .altinstr_replacement,\"a\"\n"
13093 "3: movb $1,%0\n"
13094 "4:\n"
13095 ".previous\n"
13096diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
13097index 8bf1c06..b6ae785 100644
13098--- a/arch/x86/include/asm/desc.h
13099+++ b/arch/x86/include/asm/desc.h
13100@@ -4,6 +4,7 @@
13101 #include <asm/desc_defs.h>
13102 #include <asm/ldt.h>
13103 #include <asm/mmu.h>
13104+#include <asm/pgtable.h>
13105
13106 #include <linux/smp.h>
13107 #include <linux/percpu.h>
13108@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13109
13110 desc->type = (info->read_exec_only ^ 1) << 1;
13111 desc->type |= info->contents << 2;
13112+ desc->type |= info->seg_not_present ^ 1;
13113
13114 desc->s = 1;
13115 desc->dpl = 0x3;
13116@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13117 }
13118
13119 extern struct desc_ptr idt_descr;
13120-extern gate_desc idt_table[];
13121 extern struct desc_ptr nmi_idt_descr;
13122-extern gate_desc nmi_idt_table[];
13123-
13124-struct gdt_page {
13125- struct desc_struct gdt[GDT_ENTRIES];
13126-} __attribute__((aligned(PAGE_SIZE)));
13127-
13128-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
13129+extern gate_desc idt_table[256];
13130+extern gate_desc nmi_idt_table[256];
13131
13132+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
13133 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
13134 {
13135- return per_cpu(gdt_page, cpu).gdt;
13136+ return cpu_gdt_table[cpu];
13137 }
13138
13139 #ifdef CONFIG_X86_64
13140@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
13141 unsigned long base, unsigned dpl, unsigned flags,
13142 unsigned short seg)
13143 {
13144- gate->a = (seg << 16) | (base & 0xffff);
13145- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
13146+ gate->gate.offset_low = base;
13147+ gate->gate.seg = seg;
13148+ gate->gate.reserved = 0;
13149+ gate->gate.type = type;
13150+ gate->gate.s = 0;
13151+ gate->gate.dpl = dpl;
13152+ gate->gate.p = 1;
13153+ gate->gate.offset_high = base >> 16;
13154 }
13155
13156 #endif
13157@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
13158
13159 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
13160 {
13161+ pax_open_kernel();
13162 memcpy(&idt[entry], gate, sizeof(*gate));
13163+ pax_close_kernel();
13164 }
13165
13166 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
13167 {
13168+ pax_open_kernel();
13169 memcpy(&ldt[entry], desc, 8);
13170+ pax_close_kernel();
13171 }
13172
13173 static inline void
13174@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
13175 default: size = sizeof(*gdt); break;
13176 }
13177
13178+ pax_open_kernel();
13179 memcpy(&gdt[entry], desc, size);
13180+ pax_close_kernel();
13181 }
13182
13183 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
13184@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
13185
13186 static inline void native_load_tr_desc(void)
13187 {
13188+ pax_open_kernel();
13189 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
13190+ pax_close_kernel();
13191 }
13192
13193 static inline void native_load_gdt(const struct desc_ptr *dtr)
13194@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
13195 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
13196 unsigned int i;
13197
13198+ pax_open_kernel();
13199 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
13200 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
13201+ pax_close_kernel();
13202 }
13203
13204 #define _LDT_empty(info) \
13205@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
13206 preempt_enable();
13207 }
13208
13209-static inline unsigned long get_desc_base(const struct desc_struct *desc)
13210+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
13211 {
13212 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
13213 }
13214@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
13215 }
13216
13217 #ifdef CONFIG_X86_64
13218-static inline void set_nmi_gate(int gate, void *addr)
13219+static inline void set_nmi_gate(int gate, const void *addr)
13220 {
13221 gate_desc s;
13222
13223@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
13224 }
13225 #endif
13226
13227-static inline void _set_gate(int gate, unsigned type, void *addr,
13228+static inline void _set_gate(int gate, unsigned type, const void *addr,
13229 unsigned dpl, unsigned ist, unsigned seg)
13230 {
13231 gate_desc s;
13232@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
13233 * Pentium F0 0F bugfix can have resulted in the mapped
13234 * IDT being write-protected.
13235 */
13236-static inline void set_intr_gate(unsigned int n, void *addr)
13237+static inline void set_intr_gate(unsigned int n, const void *addr)
13238 {
13239 BUG_ON((unsigned)n > 0xFF);
13240 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
13241@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
13242 /*
13243 * This routine sets up an interrupt gate at directory privilege level 3.
13244 */
13245-static inline void set_system_intr_gate(unsigned int n, void *addr)
13246+static inline void set_system_intr_gate(unsigned int n, const void *addr)
13247 {
13248 BUG_ON((unsigned)n > 0xFF);
13249 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
13250 }
13251
13252-static inline void set_system_trap_gate(unsigned int n, void *addr)
13253+static inline void set_system_trap_gate(unsigned int n, const void *addr)
13254 {
13255 BUG_ON((unsigned)n > 0xFF);
13256 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
13257 }
13258
13259-static inline void set_trap_gate(unsigned int n, void *addr)
13260+static inline void set_trap_gate(unsigned int n, const void *addr)
13261 {
13262 BUG_ON((unsigned)n > 0xFF);
13263 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
13264@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
13265 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
13266 {
13267 BUG_ON((unsigned)n > 0xFF);
13268- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
13269+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
13270 }
13271
13272-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
13273+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
13274 {
13275 BUG_ON((unsigned)n > 0xFF);
13276 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
13277 }
13278
13279-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
13280+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
13281 {
13282 BUG_ON((unsigned)n > 0xFF);
13283 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
13284 }
13285
13286+#ifdef CONFIG_X86_32
13287+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
13288+{
13289+ struct desc_struct d;
13290+
13291+ if (likely(limit))
13292+ limit = (limit - 1UL) >> PAGE_SHIFT;
13293+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
13294+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
13295+}
13296+#endif
13297+
13298 #endif /* _ASM_X86_DESC_H */
13299diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
13300index 278441f..b95a174 100644
13301--- a/arch/x86/include/asm/desc_defs.h
13302+++ b/arch/x86/include/asm/desc_defs.h
13303@@ -31,6 +31,12 @@ struct desc_struct {
13304 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
13305 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
13306 };
13307+ struct {
13308+ u16 offset_low;
13309+ u16 seg;
13310+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
13311+ unsigned offset_high: 16;
13312+ } gate;
13313 };
13314 } __attribute__((packed));
13315
13316diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
13317index ced283a..ffe04cc 100644
13318--- a/arch/x86/include/asm/div64.h
13319+++ b/arch/x86/include/asm/div64.h
13320@@ -39,7 +39,7 @@
13321 __mod; \
13322 })
13323
13324-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13325+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13326 {
13327 union {
13328 u64 v64;
13329diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
13330index 9c999c1..3860cb8 100644
13331--- a/arch/x86/include/asm/elf.h
13332+++ b/arch/x86/include/asm/elf.h
13333@@ -243,7 +243,25 @@ extern int force_personality32;
13334 the loader. We need to make sure that it is out of the way of the program
13335 that it will "exec", and that there is sufficient room for the brk. */
13336
13337+#ifdef CONFIG_PAX_SEGMEXEC
13338+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
13339+#else
13340 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
13341+#endif
13342+
13343+#ifdef CONFIG_PAX_ASLR
13344+#ifdef CONFIG_X86_32
13345+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
13346+
13347+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13348+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13349+#else
13350+#define PAX_ELF_ET_DYN_BASE 0x400000UL
13351+
13352+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13353+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13354+#endif
13355+#endif
13356
13357 /* This yields a mask that user programs can use to figure out what
13358 instruction set this CPU supports. This could be done in user space,
13359@@ -296,16 +314,12 @@ do { \
13360
13361 #define ARCH_DLINFO \
13362 do { \
13363- if (vdso_enabled) \
13364- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13365- (unsigned long)current->mm->context.vdso); \
13366+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13367 } while (0)
13368
13369 #define ARCH_DLINFO_X32 \
13370 do { \
13371- if (vdso_enabled) \
13372- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13373- (unsigned long)current->mm->context.vdso); \
13374+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13375 } while (0)
13376
13377 #define AT_SYSINFO 32
13378@@ -320,7 +334,7 @@ else \
13379
13380 #endif /* !CONFIG_X86_32 */
13381
13382-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
13383+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
13384
13385 #define VDSO_ENTRY \
13386 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
13387@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
13388 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
13389 #define compat_arch_setup_additional_pages syscall32_setup_pages
13390
13391-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
13392-#define arch_randomize_brk arch_randomize_brk
13393-
13394 /*
13395 * True on X86_32 or when emulating IA32 on X86_64
13396 */
13397diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
13398index 75ce3f4..882e801 100644
13399--- a/arch/x86/include/asm/emergency-restart.h
13400+++ b/arch/x86/include/asm/emergency-restart.h
13401@@ -13,6 +13,6 @@ enum reboot_type {
13402
13403 extern enum reboot_type reboot_type;
13404
13405-extern void machine_emergency_restart(void);
13406+extern void machine_emergency_restart(void) __noreturn;
13407
13408 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
13409diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
13410index e25cc33..425d099 100644
13411--- a/arch/x86/include/asm/fpu-internal.h
13412+++ b/arch/x86/include/asm/fpu-internal.h
13413@@ -127,7 +127,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
13414 ({ \
13415 int err; \
13416 asm volatile(ASM_STAC "\n" \
13417- "1:" #insn "\n\t" \
13418+ "1:" \
13419+ __copyuser_seg \
13420+ #insn "\n\t" \
13421 "2: " ASM_CLAC "\n" \
13422 ".section .fixup,\"ax\"\n" \
13423 "3: movl $-1,%[err]\n" \
13424@@ -300,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
13425 "emms\n\t" /* clear stack tags */
13426 "fildl %P[addr]", /* set F?P to defined value */
13427 X86_FEATURE_FXSAVE_LEAK,
13428- [addr] "m" (tsk->thread.fpu.has_fpu));
13429+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
13430
13431 return fpu_restore_checking(&tsk->thread.fpu);
13432 }
13433diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
13434index be27ba1..8f13ff9 100644
13435--- a/arch/x86/include/asm/futex.h
13436+++ b/arch/x86/include/asm/futex.h
13437@@ -12,6 +12,7 @@
13438 #include <asm/smap.h>
13439
13440 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
13441+ typecheck(u32 __user *, uaddr); \
13442 asm volatile("\t" ASM_STAC "\n" \
13443 "1:\t" insn "\n" \
13444 "2:\t" ASM_CLAC "\n" \
13445@@ -20,15 +21,16 @@
13446 "\tjmp\t2b\n" \
13447 "\t.previous\n" \
13448 _ASM_EXTABLE(1b, 3b) \
13449- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
13450+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
13451 : "i" (-EFAULT), "0" (oparg), "1" (0))
13452
13453 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
13454+ typecheck(u32 __user *, uaddr); \
13455 asm volatile("\t" ASM_STAC "\n" \
13456 "1:\tmovl %2, %0\n" \
13457 "\tmovl\t%0, %3\n" \
13458 "\t" insn "\n" \
13459- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
13460+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
13461 "\tjnz\t1b\n" \
13462 "3:\t" ASM_CLAC "\n" \
13463 "\t.section .fixup,\"ax\"\n" \
13464@@ -38,7 +40,7 @@
13465 _ASM_EXTABLE(1b, 4b) \
13466 _ASM_EXTABLE(2b, 4b) \
13467 : "=&a" (oldval), "=&r" (ret), \
13468- "+m" (*uaddr), "=&r" (tem) \
13469+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
13470 : "r" (oparg), "i" (-EFAULT), "1" (0))
13471
13472 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13473@@ -59,10 +61,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13474
13475 switch (op) {
13476 case FUTEX_OP_SET:
13477- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
13478+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
13479 break;
13480 case FUTEX_OP_ADD:
13481- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
13482+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
13483 uaddr, oparg);
13484 break;
13485 case FUTEX_OP_OR:
13486@@ -116,14 +118,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
13487 return -EFAULT;
13488
13489 asm volatile("\t" ASM_STAC "\n"
13490- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
13491+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
13492 "2:\t" ASM_CLAC "\n"
13493 "\t.section .fixup, \"ax\"\n"
13494 "3:\tmov %3, %0\n"
13495 "\tjmp 2b\n"
13496 "\t.previous\n"
13497 _ASM_EXTABLE(1b, 3b)
13498- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
13499+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
13500 : "i" (-EFAULT), "r" (newval), "1" (oldval)
13501 : "memory"
13502 );
13503diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
13504index 10a78c3..cc77143 100644
13505--- a/arch/x86/include/asm/hw_irq.h
13506+++ b/arch/x86/include/asm/hw_irq.h
13507@@ -147,8 +147,8 @@ extern void setup_ioapic_dest(void);
13508 extern void enable_IO_APIC(void);
13509
13510 /* Statistics */
13511-extern atomic_t irq_err_count;
13512-extern atomic_t irq_mis_count;
13513+extern atomic_unchecked_t irq_err_count;
13514+extern atomic_unchecked_t irq_mis_count;
13515
13516 /* EISA */
13517 extern void eisa_set_level_irq(unsigned int irq);
13518diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
13519index a203659..9889f1c 100644
13520--- a/arch/x86/include/asm/i8259.h
13521+++ b/arch/x86/include/asm/i8259.h
13522@@ -62,7 +62,7 @@ struct legacy_pic {
13523 void (*init)(int auto_eoi);
13524 int (*irq_pending)(unsigned int irq);
13525 void (*make_irq)(unsigned int irq);
13526-};
13527+} __do_const;
13528
13529 extern struct legacy_pic *legacy_pic;
13530 extern struct legacy_pic null_legacy_pic;
13531diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
13532index d8e8eef..1765f78 100644
13533--- a/arch/x86/include/asm/io.h
13534+++ b/arch/x86/include/asm/io.h
13535@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
13536 "m" (*(volatile type __force *)addr) barrier); }
13537
13538 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
13539-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
13540-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
13541+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
13542+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
13543
13544 build_mmio_read(__readb, "b", unsigned char, "=q", )
13545-build_mmio_read(__readw, "w", unsigned short, "=r", )
13546-build_mmio_read(__readl, "l", unsigned int, "=r", )
13547+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
13548+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
13549
13550 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
13551 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
13552@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
13553 return ioremap_nocache(offset, size);
13554 }
13555
13556-extern void iounmap(volatile void __iomem *addr);
13557+extern void iounmap(const volatile void __iomem *addr);
13558
13559 extern void set_iounmap_nonlazy(void);
13560
13561@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
13562
13563 #include <linux/vmalloc.h>
13564
13565+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
13566+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
13567+{
13568+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13569+}
13570+
13571+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
13572+{
13573+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13574+}
13575+
13576 /*
13577 * Convert a virtual cached pointer to an uncached pointer
13578 */
13579diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
13580index bba3cf8..06bc8da 100644
13581--- a/arch/x86/include/asm/irqflags.h
13582+++ b/arch/x86/include/asm/irqflags.h
13583@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
13584 sti; \
13585 sysexit
13586
13587+#define GET_CR0_INTO_RDI mov %cr0, %rdi
13588+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
13589+#define GET_CR3_INTO_RDI mov %cr3, %rdi
13590+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
13591+
13592 #else
13593 #define INTERRUPT_RETURN iret
13594 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
13595diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
13596index 5a6d287..f815789 100644
13597--- a/arch/x86/include/asm/kprobes.h
13598+++ b/arch/x86/include/asm/kprobes.h
13599@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
13600 #define RELATIVEJUMP_SIZE 5
13601 #define RELATIVECALL_OPCODE 0xe8
13602 #define RELATIVE_ADDR_SIZE 4
13603-#define MAX_STACK_SIZE 64
13604-#define MIN_STACK_SIZE(ADDR) \
13605- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
13606- THREAD_SIZE - (unsigned long)(ADDR))) \
13607- ? (MAX_STACK_SIZE) \
13608- : (((unsigned long)current_thread_info()) + \
13609- THREAD_SIZE - (unsigned long)(ADDR)))
13610+#define MAX_STACK_SIZE 64UL
13611+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
13612
13613 #define flush_insn_slot(p) do { } while (0)
13614
13615diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
13616index 2d89e39..baee879 100644
13617--- a/arch/x86/include/asm/local.h
13618+++ b/arch/x86/include/asm/local.h
13619@@ -10,33 +10,97 @@ typedef struct {
13620 atomic_long_t a;
13621 } local_t;
13622
13623+typedef struct {
13624+ atomic_long_unchecked_t a;
13625+} local_unchecked_t;
13626+
13627 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
13628
13629 #define local_read(l) atomic_long_read(&(l)->a)
13630+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
13631 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
13632+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
13633
13634 static inline void local_inc(local_t *l)
13635 {
13636- asm volatile(_ASM_INC "%0"
13637+ asm volatile(_ASM_INC "%0\n"
13638+
13639+#ifdef CONFIG_PAX_REFCOUNT
13640+ "jno 0f\n"
13641+ _ASM_DEC "%0\n"
13642+ "int $4\n0:\n"
13643+ _ASM_EXTABLE(0b, 0b)
13644+#endif
13645+
13646+ : "+m" (l->a.counter));
13647+}
13648+
13649+static inline void local_inc_unchecked(local_unchecked_t *l)
13650+{
13651+ asm volatile(_ASM_INC "%0\n"
13652 : "+m" (l->a.counter));
13653 }
13654
13655 static inline void local_dec(local_t *l)
13656 {
13657- asm volatile(_ASM_DEC "%0"
13658+ asm volatile(_ASM_DEC "%0\n"
13659+
13660+#ifdef CONFIG_PAX_REFCOUNT
13661+ "jno 0f\n"
13662+ _ASM_INC "%0\n"
13663+ "int $4\n0:\n"
13664+ _ASM_EXTABLE(0b, 0b)
13665+#endif
13666+
13667+ : "+m" (l->a.counter));
13668+}
13669+
13670+static inline void local_dec_unchecked(local_unchecked_t *l)
13671+{
13672+ asm volatile(_ASM_DEC "%0\n"
13673 : "+m" (l->a.counter));
13674 }
13675
13676 static inline void local_add(long i, local_t *l)
13677 {
13678- asm volatile(_ASM_ADD "%1,%0"
13679+ asm volatile(_ASM_ADD "%1,%0\n"
13680+
13681+#ifdef CONFIG_PAX_REFCOUNT
13682+ "jno 0f\n"
13683+ _ASM_SUB "%1,%0\n"
13684+ "int $4\n0:\n"
13685+ _ASM_EXTABLE(0b, 0b)
13686+#endif
13687+
13688+ : "+m" (l->a.counter)
13689+ : "ir" (i));
13690+}
13691+
13692+static inline void local_add_unchecked(long i, local_unchecked_t *l)
13693+{
13694+ asm volatile(_ASM_ADD "%1,%0\n"
13695 : "+m" (l->a.counter)
13696 : "ir" (i));
13697 }
13698
13699 static inline void local_sub(long i, local_t *l)
13700 {
13701- asm volatile(_ASM_SUB "%1,%0"
13702+ asm volatile(_ASM_SUB "%1,%0\n"
13703+
13704+#ifdef CONFIG_PAX_REFCOUNT
13705+ "jno 0f\n"
13706+ _ASM_ADD "%1,%0\n"
13707+ "int $4\n0:\n"
13708+ _ASM_EXTABLE(0b, 0b)
13709+#endif
13710+
13711+ : "+m" (l->a.counter)
13712+ : "ir" (i));
13713+}
13714+
13715+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
13716+{
13717+ asm volatile(_ASM_SUB "%1,%0\n"
13718 : "+m" (l->a.counter)
13719 : "ir" (i));
13720 }
13721@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
13722 {
13723 unsigned char c;
13724
13725- asm volatile(_ASM_SUB "%2,%0; sete %1"
13726+ asm volatile(_ASM_SUB "%2,%0\n"
13727+
13728+#ifdef CONFIG_PAX_REFCOUNT
13729+ "jno 0f\n"
13730+ _ASM_ADD "%2,%0\n"
13731+ "int $4\n0:\n"
13732+ _ASM_EXTABLE(0b, 0b)
13733+#endif
13734+
13735+ "sete %1\n"
13736 : "+m" (l->a.counter), "=qm" (c)
13737 : "ir" (i) : "memory");
13738 return c;
13739@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
13740 {
13741 unsigned char c;
13742
13743- asm volatile(_ASM_DEC "%0; sete %1"
13744+ asm volatile(_ASM_DEC "%0\n"
13745+
13746+#ifdef CONFIG_PAX_REFCOUNT
13747+ "jno 0f\n"
13748+ _ASM_INC "%0\n"
13749+ "int $4\n0:\n"
13750+ _ASM_EXTABLE(0b, 0b)
13751+#endif
13752+
13753+ "sete %1\n"
13754 : "+m" (l->a.counter), "=qm" (c)
13755 : : "memory");
13756 return c != 0;
13757@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
13758 {
13759 unsigned char c;
13760
13761- asm volatile(_ASM_INC "%0; sete %1"
13762+ asm volatile(_ASM_INC "%0\n"
13763+
13764+#ifdef CONFIG_PAX_REFCOUNT
13765+ "jno 0f\n"
13766+ _ASM_DEC "%0\n"
13767+ "int $4\n0:\n"
13768+ _ASM_EXTABLE(0b, 0b)
13769+#endif
13770+
13771+ "sete %1\n"
13772 : "+m" (l->a.counter), "=qm" (c)
13773 : : "memory");
13774 return c != 0;
13775@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
13776 {
13777 unsigned char c;
13778
13779- asm volatile(_ASM_ADD "%2,%0; sets %1"
13780+ asm volatile(_ASM_ADD "%2,%0\n"
13781+
13782+#ifdef CONFIG_PAX_REFCOUNT
13783+ "jno 0f\n"
13784+ _ASM_SUB "%2,%0\n"
13785+ "int $4\n0:\n"
13786+ _ASM_EXTABLE(0b, 0b)
13787+#endif
13788+
13789+ "sets %1\n"
13790 : "+m" (l->a.counter), "=qm" (c)
13791 : "ir" (i) : "memory");
13792 return c;
13793@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
13794 static inline long local_add_return(long i, local_t *l)
13795 {
13796 long __i = i;
13797+ asm volatile(_ASM_XADD "%0, %1\n"
13798+
13799+#ifdef CONFIG_PAX_REFCOUNT
13800+ "jno 0f\n"
13801+ _ASM_MOV "%0,%1\n"
13802+ "int $4\n0:\n"
13803+ _ASM_EXTABLE(0b, 0b)
13804+#endif
13805+
13806+ : "+r" (i), "+m" (l->a.counter)
13807+ : : "memory");
13808+ return i + __i;
13809+}
13810+
13811+/**
13812+ * local_add_return_unchecked - add and return
13813+ * @i: integer value to add
13814+ * @l: pointer to type local_unchecked_t
13815+ *
13816+ * Atomically adds @i to @l and returns @i + @l
13817+ */
13818+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
13819+{
13820+ long __i = i;
13821 asm volatile(_ASM_XADD "%0, %1;"
13822 : "+r" (i), "+m" (l->a.counter)
13823 : : "memory");
13824@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
13825
13826 #define local_cmpxchg(l, o, n) \
13827 (cmpxchg_local(&((l)->a.counter), (o), (n)))
13828+#define local_cmpxchg_unchecked(l, o, n) \
13829+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
13830 /* Always has a lock prefix */
13831 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
13832
13833diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
13834new file mode 100644
13835index 0000000..2bfd3ba
13836--- /dev/null
13837+++ b/arch/x86/include/asm/mman.h
13838@@ -0,0 +1,15 @@
13839+#ifndef _X86_MMAN_H
13840+#define _X86_MMAN_H
13841+
13842+#include <uapi/asm/mman.h>
13843+
13844+#ifdef __KERNEL__
13845+#ifndef __ASSEMBLY__
13846+#ifdef CONFIG_X86_32
13847+#define arch_mmap_check i386_mmap_check
13848+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
13849+#endif
13850+#endif
13851+#endif
13852+
13853+#endif /* X86_MMAN_H */
13854diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
13855index 5f55e69..e20bfb1 100644
13856--- a/arch/x86/include/asm/mmu.h
13857+++ b/arch/x86/include/asm/mmu.h
13858@@ -9,7 +9,7 @@
13859 * we put the segment information here.
13860 */
13861 typedef struct {
13862- void *ldt;
13863+ struct desc_struct *ldt;
13864 int size;
13865
13866 #ifdef CONFIG_X86_64
13867@@ -18,7 +18,19 @@ typedef struct {
13868 #endif
13869
13870 struct mutex lock;
13871- void *vdso;
13872+ unsigned long vdso;
13873+
13874+#ifdef CONFIG_X86_32
13875+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
13876+ unsigned long user_cs_base;
13877+ unsigned long user_cs_limit;
13878+
13879+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13880+ cpumask_t cpu_user_cs_mask;
13881+#endif
13882+
13883+#endif
13884+#endif
13885 } mm_context_t;
13886
13887 #ifdef CONFIG_SMP
13888diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
13889index cdbf367..adb37ac 100644
13890--- a/arch/x86/include/asm/mmu_context.h
13891+++ b/arch/x86/include/asm/mmu_context.h
13892@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
13893
13894 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
13895 {
13896+
13897+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13898+ unsigned int i;
13899+ pgd_t *pgd;
13900+
13901+ pax_open_kernel();
13902+ pgd = get_cpu_pgd(smp_processor_id());
13903+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
13904+ set_pgd_batched(pgd+i, native_make_pgd(0));
13905+ pax_close_kernel();
13906+#endif
13907+
13908 #ifdef CONFIG_SMP
13909 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
13910 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
13911@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13912 struct task_struct *tsk)
13913 {
13914 unsigned cpu = smp_processor_id();
13915+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13916+ int tlbstate = TLBSTATE_OK;
13917+#endif
13918
13919 if (likely(prev != next)) {
13920 #ifdef CONFIG_SMP
13921+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13922+ tlbstate = this_cpu_read(cpu_tlbstate.state);
13923+#endif
13924 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13925 this_cpu_write(cpu_tlbstate.active_mm, next);
13926 #endif
13927 cpumask_set_cpu(cpu, mm_cpumask(next));
13928
13929 /* Re-load page tables */
13930+#ifdef CONFIG_PAX_PER_CPU_PGD
13931+ pax_open_kernel();
13932+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13933+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13934+ pax_close_kernel();
13935+ load_cr3(get_cpu_pgd(cpu));
13936+#else
13937 load_cr3(next->pgd);
13938+#endif
13939
13940 /* stop flush ipis for the previous mm */
13941 cpumask_clear_cpu(cpu, mm_cpumask(prev));
13942@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13943 */
13944 if (unlikely(prev->context.ldt != next->context.ldt))
13945 load_LDT_nolock(&next->context);
13946- }
13947+
13948+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13949+ if (!(__supported_pte_mask & _PAGE_NX)) {
13950+ smp_mb__before_clear_bit();
13951+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
13952+ smp_mb__after_clear_bit();
13953+ cpu_set(cpu, next->context.cpu_user_cs_mask);
13954+ }
13955+#endif
13956+
13957+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13958+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
13959+ prev->context.user_cs_limit != next->context.user_cs_limit))
13960+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13961 #ifdef CONFIG_SMP
13962+ else if (unlikely(tlbstate != TLBSTATE_OK))
13963+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13964+#endif
13965+#endif
13966+
13967+ }
13968 else {
13969+
13970+#ifdef CONFIG_PAX_PER_CPU_PGD
13971+ pax_open_kernel();
13972+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13973+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13974+ pax_close_kernel();
13975+ load_cr3(get_cpu_pgd(cpu));
13976+#endif
13977+
13978+#ifdef CONFIG_SMP
13979 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13980 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
13981
13982@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13983 * tlb flush IPI delivery. We must reload CR3
13984 * to make sure to use no freed page tables.
13985 */
13986+
13987+#ifndef CONFIG_PAX_PER_CPU_PGD
13988 load_cr3(next->pgd);
13989+#endif
13990+
13991 load_LDT_nolock(&next->context);
13992+
13993+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
13994+ if (!(__supported_pte_mask & _PAGE_NX))
13995+ cpu_set(cpu, next->context.cpu_user_cs_mask);
13996+#endif
13997+
13998+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13999+#ifdef CONFIG_PAX_PAGEEXEC
14000+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
14001+#endif
14002+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
14003+#endif
14004+
14005 }
14006+#endif
14007 }
14008-#endif
14009 }
14010
14011 #define activate_mm(prev, next) \
14012diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
14013index e3b7819..b257c64 100644
14014--- a/arch/x86/include/asm/module.h
14015+++ b/arch/x86/include/asm/module.h
14016@@ -5,6 +5,7 @@
14017
14018 #ifdef CONFIG_X86_64
14019 /* X86_64 does not define MODULE_PROC_FAMILY */
14020+#define MODULE_PROC_FAMILY ""
14021 #elif defined CONFIG_M486
14022 #define MODULE_PROC_FAMILY "486 "
14023 #elif defined CONFIG_M586
14024@@ -57,8 +58,20 @@
14025 #error unknown processor family
14026 #endif
14027
14028-#ifdef CONFIG_X86_32
14029-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
14030+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14031+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
14032+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
14033+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
14034+#else
14035+#define MODULE_PAX_KERNEXEC ""
14036 #endif
14037
14038+#ifdef CONFIG_PAX_MEMORY_UDEREF
14039+#define MODULE_PAX_UDEREF "UDEREF "
14040+#else
14041+#define MODULE_PAX_UDEREF ""
14042+#endif
14043+
14044+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
14045+
14046 #endif /* _ASM_X86_MODULE_H */
14047diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
14048index c0fa356..07a498a 100644
14049--- a/arch/x86/include/asm/nmi.h
14050+++ b/arch/x86/include/asm/nmi.h
14051@@ -42,11 +42,11 @@ struct nmiaction {
14052 nmi_handler_t handler;
14053 unsigned long flags;
14054 const char *name;
14055-};
14056+} __do_const;
14057
14058 #define register_nmi_handler(t, fn, fg, n, init...) \
14059 ({ \
14060- static struct nmiaction init fn##_na = { \
14061+ static const struct nmiaction init fn##_na = { \
14062 .handler = (fn), \
14063 .name = (n), \
14064 .flags = (fg), \
14065@@ -54,7 +54,7 @@ struct nmiaction {
14066 __register_nmi_handler((t), &fn##_na); \
14067 })
14068
14069-int __register_nmi_handler(unsigned int, struct nmiaction *);
14070+int __register_nmi_handler(unsigned int, const struct nmiaction *);
14071
14072 void unregister_nmi_handler(unsigned int, const char *);
14073
14074diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
14075index 0f1ddee..e2fc3d1 100644
14076--- a/arch/x86/include/asm/page_64.h
14077+++ b/arch/x86/include/asm/page_64.h
14078@@ -7,9 +7,9 @@
14079
14080 /* duplicated to the one in bootmem.h */
14081 extern unsigned long max_pfn;
14082-extern unsigned long phys_base;
14083+extern const unsigned long phys_base;
14084
14085-static inline unsigned long __phys_addr_nodebug(unsigned long x)
14086+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
14087 {
14088 unsigned long y = x - __START_KERNEL_map;
14089
14090diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
14091index 7361e47..16dc226 100644
14092--- a/arch/x86/include/asm/paravirt.h
14093+++ b/arch/x86/include/asm/paravirt.h
14094@@ -564,7 +564,7 @@ static inline pmd_t __pmd(pmdval_t val)
14095 return (pmd_t) { ret };
14096 }
14097
14098-static inline pmdval_t pmd_val(pmd_t pmd)
14099+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
14100 {
14101 pmdval_t ret;
14102
14103@@ -630,6 +630,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
14104 val);
14105 }
14106
14107+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14108+{
14109+ pgdval_t val = native_pgd_val(pgd);
14110+
14111+ if (sizeof(pgdval_t) > sizeof(long))
14112+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
14113+ val, (u64)val >> 32);
14114+ else
14115+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
14116+ val);
14117+}
14118+
14119 static inline void pgd_clear(pgd_t *pgdp)
14120 {
14121 set_pgd(pgdp, __pgd(0));
14122@@ -714,6 +726,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
14123 pv_mmu_ops.set_fixmap(idx, phys, flags);
14124 }
14125
14126+#ifdef CONFIG_PAX_KERNEXEC
14127+static inline unsigned long pax_open_kernel(void)
14128+{
14129+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
14130+}
14131+
14132+static inline unsigned long pax_close_kernel(void)
14133+{
14134+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
14135+}
14136+#else
14137+static inline unsigned long pax_open_kernel(void) { return 0; }
14138+static inline unsigned long pax_close_kernel(void) { return 0; }
14139+#endif
14140+
14141 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
14142
14143 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
14144@@ -930,7 +957,7 @@ extern void default_banner(void);
14145
14146 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
14147 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
14148-#define PARA_INDIRECT(addr) *%cs:addr
14149+#define PARA_INDIRECT(addr) *%ss:addr
14150 #endif
14151
14152 #define INTERRUPT_RETURN \
14153@@ -1005,6 +1032,21 @@ extern void default_banner(void);
14154 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
14155 CLBR_NONE, \
14156 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
14157+
14158+#define GET_CR0_INTO_RDI \
14159+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
14160+ mov %rax,%rdi
14161+
14162+#define SET_RDI_INTO_CR0 \
14163+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14164+
14165+#define GET_CR3_INTO_RDI \
14166+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
14167+ mov %rax,%rdi
14168+
14169+#define SET_RDI_INTO_CR3 \
14170+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
14171+
14172 #endif /* CONFIG_X86_32 */
14173
14174 #endif /* __ASSEMBLY__ */
14175diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
14176index b3b0ec1..b1cd3eb 100644
14177--- a/arch/x86/include/asm/paravirt_types.h
14178+++ b/arch/x86/include/asm/paravirt_types.h
14179@@ -84,7 +84,7 @@ struct pv_init_ops {
14180 */
14181 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
14182 unsigned long addr, unsigned len);
14183-};
14184+} __no_const;
14185
14186
14187 struct pv_lazy_ops {
14188@@ -98,7 +98,7 @@ struct pv_time_ops {
14189 unsigned long long (*sched_clock)(void);
14190 unsigned long long (*steal_clock)(int cpu);
14191 unsigned long (*get_tsc_khz)(void);
14192-};
14193+} __no_const;
14194
14195 struct pv_cpu_ops {
14196 /* hooks for various privileged instructions */
14197@@ -192,7 +192,7 @@ struct pv_cpu_ops {
14198
14199 void (*start_context_switch)(struct task_struct *prev);
14200 void (*end_context_switch)(struct task_struct *next);
14201-};
14202+} __no_const;
14203
14204 struct pv_irq_ops {
14205 /*
14206@@ -223,7 +223,7 @@ struct pv_apic_ops {
14207 unsigned long start_eip,
14208 unsigned long start_esp);
14209 #endif
14210-};
14211+} __no_const;
14212
14213 struct pv_mmu_ops {
14214 unsigned long (*read_cr2)(void);
14215@@ -313,6 +313,7 @@ struct pv_mmu_ops {
14216 struct paravirt_callee_save make_pud;
14217
14218 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
14219+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
14220 #endif /* PAGETABLE_LEVELS == 4 */
14221 #endif /* PAGETABLE_LEVELS >= 3 */
14222
14223@@ -324,6 +325,12 @@ struct pv_mmu_ops {
14224 an mfn. We can tell which is which from the index. */
14225 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
14226 phys_addr_t phys, pgprot_t flags);
14227+
14228+#ifdef CONFIG_PAX_KERNEXEC
14229+ unsigned long (*pax_open_kernel)(void);
14230+ unsigned long (*pax_close_kernel)(void);
14231+#endif
14232+
14233 };
14234
14235 struct arch_spinlock;
14236@@ -334,7 +341,7 @@ struct pv_lock_ops {
14237 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
14238 int (*spin_trylock)(struct arch_spinlock *lock);
14239 void (*spin_unlock)(struct arch_spinlock *lock);
14240-};
14241+} __no_const;
14242
14243 /* This contains all the paravirt structures: we get a convenient
14244 * number for each function using the offset which we use to indicate
14245diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
14246index b4389a4..7024269 100644
14247--- a/arch/x86/include/asm/pgalloc.h
14248+++ b/arch/x86/include/asm/pgalloc.h
14249@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
14250 pmd_t *pmd, pte_t *pte)
14251 {
14252 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14253+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
14254+}
14255+
14256+static inline void pmd_populate_user(struct mm_struct *mm,
14257+ pmd_t *pmd, pte_t *pte)
14258+{
14259+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14260 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
14261 }
14262
14263@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
14264
14265 #ifdef CONFIG_X86_PAE
14266 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
14267+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
14268+{
14269+ pud_populate(mm, pudp, pmd);
14270+}
14271 #else /* !CONFIG_X86_PAE */
14272 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14273 {
14274 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14275 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
14276 }
14277+
14278+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14279+{
14280+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14281+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
14282+}
14283 #endif /* CONFIG_X86_PAE */
14284
14285 #if PAGETABLE_LEVELS > 3
14286@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14287 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
14288 }
14289
14290+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14291+{
14292+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
14293+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
14294+}
14295+
14296 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
14297 {
14298 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
14299diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
14300index f2b489c..4f7e2e5 100644
14301--- a/arch/x86/include/asm/pgtable-2level.h
14302+++ b/arch/x86/include/asm/pgtable-2level.h
14303@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
14304
14305 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14306 {
14307+ pax_open_kernel();
14308 *pmdp = pmd;
14309+ pax_close_kernel();
14310 }
14311
14312 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14313diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
14314index 4cc9f2b..5fd9226 100644
14315--- a/arch/x86/include/asm/pgtable-3level.h
14316+++ b/arch/x86/include/asm/pgtable-3level.h
14317@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14318
14319 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14320 {
14321+ pax_open_kernel();
14322 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
14323+ pax_close_kernel();
14324 }
14325
14326 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14327 {
14328+ pax_open_kernel();
14329 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
14330+ pax_close_kernel();
14331 }
14332
14333 /*
14334diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
14335index 1e67223..dd6e7ea 100644
14336--- a/arch/x86/include/asm/pgtable.h
14337+++ b/arch/x86/include/asm/pgtable.h
14338@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14339
14340 #ifndef __PAGETABLE_PUD_FOLDED
14341 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
14342+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
14343 #define pgd_clear(pgd) native_pgd_clear(pgd)
14344 #endif
14345
14346@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14347
14348 #define arch_end_context_switch(prev) do {} while(0)
14349
14350+#define pax_open_kernel() native_pax_open_kernel()
14351+#define pax_close_kernel() native_pax_close_kernel()
14352 #endif /* CONFIG_PARAVIRT */
14353
14354+#define __HAVE_ARCH_PAX_OPEN_KERNEL
14355+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
14356+
14357+#ifdef CONFIG_PAX_KERNEXEC
14358+static inline unsigned long native_pax_open_kernel(void)
14359+{
14360+ unsigned long cr0;
14361+
14362+ preempt_disable();
14363+ barrier();
14364+ cr0 = read_cr0() ^ X86_CR0_WP;
14365+ BUG_ON(cr0 & X86_CR0_WP);
14366+ write_cr0(cr0);
14367+ return cr0 ^ X86_CR0_WP;
14368+}
14369+
14370+static inline unsigned long native_pax_close_kernel(void)
14371+{
14372+ unsigned long cr0;
14373+
14374+ cr0 = read_cr0() ^ X86_CR0_WP;
14375+ BUG_ON(!(cr0 & X86_CR0_WP));
14376+ write_cr0(cr0);
14377+ barrier();
14378+ preempt_enable_no_resched();
14379+ return cr0 ^ X86_CR0_WP;
14380+}
14381+#else
14382+static inline unsigned long native_pax_open_kernel(void) { return 0; }
14383+static inline unsigned long native_pax_close_kernel(void) { return 0; }
14384+#endif
14385+
14386 /*
14387 * The following only work if pte_present() is true.
14388 * Undefined behaviour if not..
14389 */
14390+static inline int pte_user(pte_t pte)
14391+{
14392+ return pte_val(pte) & _PAGE_USER;
14393+}
14394+
14395 static inline int pte_dirty(pte_t pte)
14396 {
14397 return pte_flags(pte) & _PAGE_DIRTY;
14398@@ -147,6 +187,11 @@ static inline unsigned long pud_pfn(pud_t pud)
14399 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
14400 }
14401
14402+static inline unsigned long pgd_pfn(pgd_t pgd)
14403+{
14404+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
14405+}
14406+
14407 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
14408
14409 static inline int pmd_large(pmd_t pte)
14410@@ -200,9 +245,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
14411 return pte_clear_flags(pte, _PAGE_RW);
14412 }
14413
14414+static inline pte_t pte_mkread(pte_t pte)
14415+{
14416+ return __pte(pte_val(pte) | _PAGE_USER);
14417+}
14418+
14419 static inline pte_t pte_mkexec(pte_t pte)
14420 {
14421- return pte_clear_flags(pte, _PAGE_NX);
14422+#ifdef CONFIG_X86_PAE
14423+ if (__supported_pte_mask & _PAGE_NX)
14424+ return pte_clear_flags(pte, _PAGE_NX);
14425+ else
14426+#endif
14427+ return pte_set_flags(pte, _PAGE_USER);
14428+}
14429+
14430+static inline pte_t pte_exprotect(pte_t pte)
14431+{
14432+#ifdef CONFIG_X86_PAE
14433+ if (__supported_pte_mask & _PAGE_NX)
14434+ return pte_set_flags(pte, _PAGE_NX);
14435+ else
14436+#endif
14437+ return pte_clear_flags(pte, _PAGE_USER);
14438 }
14439
14440 static inline pte_t pte_mkdirty(pte_t pte)
14441@@ -394,6 +459,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
14442 #endif
14443
14444 #ifndef __ASSEMBLY__
14445+
14446+#ifdef CONFIG_PAX_PER_CPU_PGD
14447+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
14448+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
14449+{
14450+ return cpu_pgd[cpu];
14451+}
14452+#endif
14453+
14454 #include <linux/mm_types.h>
14455 #include <linux/log2.h>
14456
14457@@ -529,7 +603,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
14458 * Currently stuck as a macro due to indirect forward reference to
14459 * linux/mmzone.h's __section_mem_map_addr() definition:
14460 */
14461-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
14462+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
14463
14464 /* Find an entry in the second-level page table.. */
14465 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
14466@@ -569,7 +643,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
14467 * Currently stuck as a macro due to indirect forward reference to
14468 * linux/mmzone.h's __section_mem_map_addr() definition:
14469 */
14470-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
14471+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
14472
14473 /* to find an entry in a page-table-directory. */
14474 static inline unsigned long pud_index(unsigned long address)
14475@@ -584,7 +658,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
14476
14477 static inline int pgd_bad(pgd_t pgd)
14478 {
14479- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
14480+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
14481 }
14482
14483 static inline int pgd_none(pgd_t pgd)
14484@@ -607,7 +681,12 @@ static inline int pgd_none(pgd_t pgd)
14485 * pgd_offset() returns a (pgd_t *)
14486 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
14487 */
14488-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
14489+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
14490+
14491+#ifdef CONFIG_PAX_PER_CPU_PGD
14492+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
14493+#endif
14494+
14495 /*
14496 * a shortcut which implies the use of the kernel's pgd, instead
14497 * of a process's
14498@@ -618,6 +697,22 @@ static inline int pgd_none(pgd_t pgd)
14499 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
14500 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
14501
14502+#ifdef CONFIG_X86_32
14503+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
14504+#else
14505+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
14506+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
14507+
14508+#ifdef CONFIG_PAX_MEMORY_UDEREF
14509+#ifdef __ASSEMBLY__
14510+#define pax_user_shadow_base pax_user_shadow_base(%rip)
14511+#else
14512+extern unsigned long pax_user_shadow_base;
14513+#endif
14514+#endif
14515+
14516+#endif
14517+
14518 #ifndef __ASSEMBLY__
14519
14520 extern int direct_gbpages;
14521@@ -784,11 +879,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
14522 * dst and src can be on the same page, but the range must not overlap,
14523 * and must not cross a page boundary.
14524 */
14525-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
14526+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
14527 {
14528- memcpy(dst, src, count * sizeof(pgd_t));
14529+ pax_open_kernel();
14530+ while (count--)
14531+ *dst++ = *src++;
14532+ pax_close_kernel();
14533 }
14534
14535+#ifdef CONFIG_PAX_PER_CPU_PGD
14536+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
14537+#endif
14538+
14539+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14540+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
14541+#else
14542+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
14543+#endif
14544+
14545 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
14546 static inline int page_level_shift(enum pg_level level)
14547 {
14548diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
14549index 9ee3221..b979c6b 100644
14550--- a/arch/x86/include/asm/pgtable_32.h
14551+++ b/arch/x86/include/asm/pgtable_32.h
14552@@ -25,9 +25,6 @@
14553 struct mm_struct;
14554 struct vm_area_struct;
14555
14556-extern pgd_t swapper_pg_dir[1024];
14557-extern pgd_t initial_page_table[1024];
14558-
14559 static inline void pgtable_cache_init(void) { }
14560 static inline void check_pgt_cache(void) { }
14561 void paging_init(void);
14562@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14563 # include <asm/pgtable-2level.h>
14564 #endif
14565
14566+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
14567+extern pgd_t initial_page_table[PTRS_PER_PGD];
14568+#ifdef CONFIG_X86_PAE
14569+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
14570+#endif
14571+
14572 #if defined(CONFIG_HIGHPTE)
14573 #define pte_offset_map(dir, address) \
14574 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
14575@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14576 /* Clear a kernel PTE and flush it from the TLB */
14577 #define kpte_clear_flush(ptep, vaddr) \
14578 do { \
14579+ pax_open_kernel(); \
14580 pte_clear(&init_mm, (vaddr), (ptep)); \
14581+ pax_close_kernel(); \
14582 __flush_tlb_one((vaddr)); \
14583 } while (0)
14584
14585 #endif /* !__ASSEMBLY__ */
14586
14587+#define HAVE_ARCH_UNMAPPED_AREA
14588+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
14589+
14590 /*
14591 * kern_addr_valid() is (1) for FLATMEM and (0) for
14592 * SPARSEMEM and DISCONTIGMEM
14593diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
14594index ed5903b..c7fe163 100644
14595--- a/arch/x86/include/asm/pgtable_32_types.h
14596+++ b/arch/x86/include/asm/pgtable_32_types.h
14597@@ -8,7 +8,7 @@
14598 */
14599 #ifdef CONFIG_X86_PAE
14600 # include <asm/pgtable-3level_types.h>
14601-# define PMD_SIZE (1UL << PMD_SHIFT)
14602+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
14603 # define PMD_MASK (~(PMD_SIZE - 1))
14604 #else
14605 # include <asm/pgtable-2level_types.h>
14606@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
14607 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
14608 #endif
14609
14610+#ifdef CONFIG_PAX_KERNEXEC
14611+#ifndef __ASSEMBLY__
14612+extern unsigned char MODULES_EXEC_VADDR[];
14613+extern unsigned char MODULES_EXEC_END[];
14614+#endif
14615+#include <asm/boot.h>
14616+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
14617+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
14618+#else
14619+#define ktla_ktva(addr) (addr)
14620+#define ktva_ktla(addr) (addr)
14621+#endif
14622+
14623 #define MODULES_VADDR VMALLOC_START
14624 #define MODULES_END VMALLOC_END
14625 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
14626diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
14627index e22c1db..23a625a 100644
14628--- a/arch/x86/include/asm/pgtable_64.h
14629+++ b/arch/x86/include/asm/pgtable_64.h
14630@@ -16,10 +16,14 @@
14631
14632 extern pud_t level3_kernel_pgt[512];
14633 extern pud_t level3_ident_pgt[512];
14634+extern pud_t level3_vmalloc_start_pgt[512];
14635+extern pud_t level3_vmalloc_end_pgt[512];
14636+extern pud_t level3_vmemmap_pgt[512];
14637+extern pud_t level2_vmemmap_pgt[512];
14638 extern pmd_t level2_kernel_pgt[512];
14639 extern pmd_t level2_fixmap_pgt[512];
14640-extern pmd_t level2_ident_pgt[512];
14641-extern pgd_t init_level4_pgt[];
14642+extern pmd_t level2_ident_pgt[512*2];
14643+extern pgd_t init_level4_pgt[512];
14644
14645 #define swapper_pg_dir init_level4_pgt
14646
14647@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14648
14649 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14650 {
14651+ pax_open_kernel();
14652 *pmdp = pmd;
14653+ pax_close_kernel();
14654 }
14655
14656 static inline void native_pmd_clear(pmd_t *pmd)
14657@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
14658
14659 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14660 {
14661+ pax_open_kernel();
14662 *pudp = pud;
14663+ pax_close_kernel();
14664 }
14665
14666 static inline void native_pud_clear(pud_t *pud)
14667@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
14668
14669 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
14670 {
14671+ pax_open_kernel();
14672+ *pgdp = pgd;
14673+ pax_close_kernel();
14674+}
14675+
14676+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14677+{
14678 *pgdp = pgd;
14679 }
14680
14681diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
14682index 2d88344..4679fc3 100644
14683--- a/arch/x86/include/asm/pgtable_64_types.h
14684+++ b/arch/x86/include/asm/pgtable_64_types.h
14685@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
14686 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
14687 #define MODULES_END _AC(0xffffffffff000000, UL)
14688 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
14689+#define MODULES_EXEC_VADDR MODULES_VADDR
14690+#define MODULES_EXEC_END MODULES_END
14691+
14692+#define ktla_ktva(addr) (addr)
14693+#define ktva_ktla(addr) (addr)
14694
14695 #define EARLY_DYNAMIC_PAGE_TABLES 64
14696
14697diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
14698index 567b5d0..bd91d64 100644
14699--- a/arch/x86/include/asm/pgtable_types.h
14700+++ b/arch/x86/include/asm/pgtable_types.h
14701@@ -16,13 +16,12 @@
14702 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
14703 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
14704 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
14705-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
14706+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
14707 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
14708 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
14709 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
14710-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
14711-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
14712-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
14713+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
14714+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
14715 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
14716
14717 /* If _PAGE_BIT_PRESENT is clear, we use these: */
14718@@ -40,7 +39,6 @@
14719 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
14720 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
14721 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
14722-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
14723 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
14724 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
14725 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
14726@@ -57,8 +55,10 @@
14727
14728 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
14729 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
14730-#else
14731+#elif defined(CONFIG_KMEMCHECK)
14732 #define _PAGE_NX (_AT(pteval_t, 0))
14733+#else
14734+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
14735 #endif
14736
14737 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
14738@@ -116,6 +116,9 @@
14739 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
14740 _PAGE_ACCESSED)
14741
14742+#define PAGE_READONLY_NOEXEC PAGE_READONLY
14743+#define PAGE_SHARED_NOEXEC PAGE_SHARED
14744+
14745 #define __PAGE_KERNEL_EXEC \
14746 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
14747 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
14748@@ -126,7 +129,7 @@
14749 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
14750 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
14751 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
14752-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
14753+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
14754 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
14755 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
14756 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
14757@@ -188,8 +191,8 @@
14758 * bits are combined, this will alow user to access the high address mapped
14759 * VDSO in the presence of CONFIG_COMPAT_VDSO
14760 */
14761-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
14762-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
14763+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14764+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14765 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
14766 #endif
14767
14768@@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
14769 {
14770 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
14771 }
14772+#endif
14773
14774+#if PAGETABLE_LEVELS == 3
14775+#include <asm-generic/pgtable-nopud.h>
14776+#endif
14777+
14778+#if PAGETABLE_LEVELS == 2
14779+#include <asm-generic/pgtable-nopmd.h>
14780+#endif
14781+
14782+#ifndef __ASSEMBLY__
14783 #if PAGETABLE_LEVELS > 3
14784 typedef struct { pudval_t pud; } pud_t;
14785
14786@@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
14787 return pud.pud;
14788 }
14789 #else
14790-#include <asm-generic/pgtable-nopud.h>
14791-
14792 static inline pudval_t native_pud_val(pud_t pud)
14793 {
14794 return native_pgd_val(pud.pgd);
14795@@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
14796 return pmd.pmd;
14797 }
14798 #else
14799-#include <asm-generic/pgtable-nopmd.h>
14800-
14801 static inline pmdval_t native_pmd_val(pmd_t pmd)
14802 {
14803 return native_pgd_val(pmd.pud.pgd);
14804@@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
14805
14806 extern pteval_t __supported_pte_mask;
14807 extern void set_nx(void);
14808-extern int nx_enabled;
14809
14810 #define pgprot_writecombine pgprot_writecombine
14811 extern pgprot_t pgprot_writecombine(pgprot_t prot);
14812diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
14813index 3270116..8d99d82 100644
14814--- a/arch/x86/include/asm/processor.h
14815+++ b/arch/x86/include/asm/processor.h
14816@@ -285,7 +285,7 @@ struct tss_struct {
14817
14818 } ____cacheline_aligned;
14819
14820-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
14821+extern struct tss_struct init_tss[NR_CPUS];
14822
14823 /*
14824 * Save the original ist values for checking stack pointers during debugging
14825@@ -826,11 +826,18 @@ static inline void spin_lock_prefetch(const void *x)
14826 */
14827 #define TASK_SIZE PAGE_OFFSET
14828 #define TASK_SIZE_MAX TASK_SIZE
14829+
14830+#ifdef CONFIG_PAX_SEGMEXEC
14831+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
14832+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
14833+#else
14834 #define STACK_TOP TASK_SIZE
14835-#define STACK_TOP_MAX STACK_TOP
14836+#endif
14837+
14838+#define STACK_TOP_MAX TASK_SIZE
14839
14840 #define INIT_THREAD { \
14841- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14842+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14843 .vm86_info = NULL, \
14844 .sysenter_cs = __KERNEL_CS, \
14845 .io_bitmap_ptr = NULL, \
14846@@ -844,7 +851,7 @@ static inline void spin_lock_prefetch(const void *x)
14847 */
14848 #define INIT_TSS { \
14849 .x86_tss = { \
14850- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14851+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14852 .ss0 = __KERNEL_DS, \
14853 .ss1 = __KERNEL_CS, \
14854 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
14855@@ -855,11 +862,7 @@ static inline void spin_lock_prefetch(const void *x)
14856 extern unsigned long thread_saved_pc(struct task_struct *tsk);
14857
14858 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
14859-#define KSTK_TOP(info) \
14860-({ \
14861- unsigned long *__ptr = (unsigned long *)(info); \
14862- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
14863-})
14864+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
14865
14866 /*
14867 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
14868@@ -874,7 +877,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14869 #define task_pt_regs(task) \
14870 ({ \
14871 struct pt_regs *__regs__; \
14872- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
14873+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
14874 __regs__ - 1; \
14875 })
14876
14877@@ -884,13 +887,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14878 /*
14879 * User space process size. 47bits minus one guard page.
14880 */
14881-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
14882+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
14883
14884 /* This decides where the kernel will search for a free chunk of vm
14885 * space during mmap's.
14886 */
14887 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
14888- 0xc0000000 : 0xFFFFe000)
14889+ 0xc0000000 : 0xFFFFf000)
14890
14891 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
14892 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
14893@@ -901,11 +904,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14894 #define STACK_TOP_MAX TASK_SIZE_MAX
14895
14896 #define INIT_THREAD { \
14897- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14898+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14899 }
14900
14901 #define INIT_TSS { \
14902- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14903+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14904 }
14905
14906 /*
14907@@ -933,6 +936,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
14908 */
14909 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
14910
14911+#ifdef CONFIG_PAX_SEGMEXEC
14912+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
14913+#endif
14914+
14915 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
14916
14917 /* Get/set a process' ability to use the timestamp counter instruction */
14918@@ -993,7 +1000,7 @@ extern bool cpu_has_amd_erratum(const int *);
14919 #define cpu_has_amd_erratum(x) (false)
14920 #endif /* CONFIG_CPU_SUP_AMD */
14921
14922-extern unsigned long arch_align_stack(unsigned long sp);
14923+#define arch_align_stack(x) ((x) & ~0xfUL)
14924 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
14925
14926 void default_idle(void);
14927@@ -1003,6 +1010,6 @@ bool xen_set_default_idle(void);
14928 #define xen_set_default_idle 0
14929 #endif
14930
14931-void stop_this_cpu(void *dummy);
14932+void stop_this_cpu(void *dummy) __noreturn;
14933
14934 #endif /* _ASM_X86_PROCESSOR_H */
14935diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
14936index 942a086..6c26446 100644
14937--- a/arch/x86/include/asm/ptrace.h
14938+++ b/arch/x86/include/asm/ptrace.h
14939@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
14940 }
14941
14942 /*
14943- * user_mode_vm(regs) determines whether a register set came from user mode.
14944+ * user_mode(regs) determines whether a register set came from user mode.
14945 * This is true if V8086 mode was enabled OR if the register set was from
14946 * protected mode with RPL-3 CS value. This tricky test checks that with
14947 * one comparison. Many places in the kernel can bypass this full check
14948- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
14949+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
14950+ * be used.
14951 */
14952-static inline int user_mode(struct pt_regs *regs)
14953+static inline int user_mode_novm(struct pt_regs *regs)
14954 {
14955 #ifdef CONFIG_X86_32
14956 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
14957 #else
14958- return !!(regs->cs & 3);
14959+ return !!(regs->cs & SEGMENT_RPL_MASK);
14960 #endif
14961 }
14962
14963-static inline int user_mode_vm(struct pt_regs *regs)
14964+static inline int user_mode(struct pt_regs *regs)
14965 {
14966 #ifdef CONFIG_X86_32
14967 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
14968 USER_RPL;
14969 #else
14970- return user_mode(regs);
14971+ return user_mode_novm(regs);
14972 #endif
14973 }
14974
14975@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
14976 #ifdef CONFIG_X86_64
14977 static inline bool user_64bit_mode(struct pt_regs *regs)
14978 {
14979+ unsigned long cs = regs->cs & 0xffff;
14980 #ifndef CONFIG_PARAVIRT
14981 /*
14982 * On non-paravirt systems, this is the only long mode CPL 3
14983 * selector. We do not allow long mode selectors in the LDT.
14984 */
14985- return regs->cs == __USER_CS;
14986+ return cs == __USER_CS;
14987 #else
14988 /* Headers are too twisted for this to go in paravirt.h. */
14989- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
14990+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
14991 #endif
14992 }
14993
14994@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
14995 * Traps from the kernel do not save sp and ss.
14996 * Use the helper function to retrieve sp.
14997 */
14998- if (offset == offsetof(struct pt_regs, sp) &&
14999- regs->cs == __KERNEL_CS)
15000- return kernel_stack_pointer(regs);
15001+ if (offset == offsetof(struct pt_regs, sp)) {
15002+ unsigned long cs = regs->cs & 0xffff;
15003+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
15004+ return kernel_stack_pointer(regs);
15005+ }
15006 #endif
15007 return *(unsigned long *)((unsigned long)regs + offset);
15008 }
15009diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
15010index 9c6b890..5305f53 100644
15011--- a/arch/x86/include/asm/realmode.h
15012+++ b/arch/x86/include/asm/realmode.h
15013@@ -22,16 +22,14 @@ struct real_mode_header {
15014 #endif
15015 /* APM/BIOS reboot */
15016 u32 machine_real_restart_asm;
15017-#ifdef CONFIG_X86_64
15018 u32 machine_real_restart_seg;
15019-#endif
15020 };
15021
15022 /* This must match data at trampoline_32/64.S */
15023 struct trampoline_header {
15024 #ifdef CONFIG_X86_32
15025 u32 start;
15026- u16 gdt_pad;
15027+ u16 boot_cs;
15028 u16 gdt_limit;
15029 u32 gdt_base;
15030 #else
15031diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
15032index a82c4f1..ac45053 100644
15033--- a/arch/x86/include/asm/reboot.h
15034+++ b/arch/x86/include/asm/reboot.h
15035@@ -6,13 +6,13 @@
15036 struct pt_regs;
15037
15038 struct machine_ops {
15039- void (*restart)(char *cmd);
15040- void (*halt)(void);
15041- void (*power_off)(void);
15042+ void (* __noreturn restart)(char *cmd);
15043+ void (* __noreturn halt)(void);
15044+ void (* __noreturn power_off)(void);
15045 void (*shutdown)(void);
15046 void (*crash_shutdown)(struct pt_regs *);
15047- void (*emergency_restart)(void);
15048-};
15049+ void (* __noreturn emergency_restart)(void);
15050+} __no_const;
15051
15052 extern struct machine_ops machine_ops;
15053
15054diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
15055index 2dbe4a7..ce1db00 100644
15056--- a/arch/x86/include/asm/rwsem.h
15057+++ b/arch/x86/include/asm/rwsem.h
15058@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
15059 {
15060 asm volatile("# beginning down_read\n\t"
15061 LOCK_PREFIX _ASM_INC "(%1)\n\t"
15062+
15063+#ifdef CONFIG_PAX_REFCOUNT
15064+ "jno 0f\n"
15065+ LOCK_PREFIX _ASM_DEC "(%1)\n"
15066+ "int $4\n0:\n"
15067+ _ASM_EXTABLE(0b, 0b)
15068+#endif
15069+
15070 /* adds 0x00000001 */
15071 " jns 1f\n"
15072 " call call_rwsem_down_read_failed\n"
15073@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
15074 "1:\n\t"
15075 " mov %1,%2\n\t"
15076 " add %3,%2\n\t"
15077+
15078+#ifdef CONFIG_PAX_REFCOUNT
15079+ "jno 0f\n"
15080+ "sub %3,%2\n"
15081+ "int $4\n0:\n"
15082+ _ASM_EXTABLE(0b, 0b)
15083+#endif
15084+
15085 " jle 2f\n\t"
15086 LOCK_PREFIX " cmpxchg %2,%0\n\t"
15087 " jnz 1b\n\t"
15088@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
15089 long tmp;
15090 asm volatile("# beginning down_write\n\t"
15091 LOCK_PREFIX " xadd %1,(%2)\n\t"
15092+
15093+#ifdef CONFIG_PAX_REFCOUNT
15094+ "jno 0f\n"
15095+ "mov %1,(%2)\n"
15096+ "int $4\n0:\n"
15097+ _ASM_EXTABLE(0b, 0b)
15098+#endif
15099+
15100 /* adds 0xffff0001, returns the old value */
15101 " test %1,%1\n\t"
15102 /* was the count 0 before? */
15103@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
15104 long tmp;
15105 asm volatile("# beginning __up_read\n\t"
15106 LOCK_PREFIX " xadd %1,(%2)\n\t"
15107+
15108+#ifdef CONFIG_PAX_REFCOUNT
15109+ "jno 0f\n"
15110+ "mov %1,(%2)\n"
15111+ "int $4\n0:\n"
15112+ _ASM_EXTABLE(0b, 0b)
15113+#endif
15114+
15115 /* subtracts 1, returns the old value */
15116 " jns 1f\n\t"
15117 " call call_rwsem_wake\n" /* expects old value in %edx */
15118@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
15119 long tmp;
15120 asm volatile("# beginning __up_write\n\t"
15121 LOCK_PREFIX " xadd %1,(%2)\n\t"
15122+
15123+#ifdef CONFIG_PAX_REFCOUNT
15124+ "jno 0f\n"
15125+ "mov %1,(%2)\n"
15126+ "int $4\n0:\n"
15127+ _ASM_EXTABLE(0b, 0b)
15128+#endif
15129+
15130 /* subtracts 0xffff0001, returns the old value */
15131 " jns 1f\n\t"
15132 " call call_rwsem_wake\n" /* expects old value in %edx */
15133@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15134 {
15135 asm volatile("# beginning __downgrade_write\n\t"
15136 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
15137+
15138+#ifdef CONFIG_PAX_REFCOUNT
15139+ "jno 0f\n"
15140+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
15141+ "int $4\n0:\n"
15142+ _ASM_EXTABLE(0b, 0b)
15143+#endif
15144+
15145 /*
15146 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
15147 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
15148@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15149 */
15150 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15151 {
15152- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
15153+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
15154+
15155+#ifdef CONFIG_PAX_REFCOUNT
15156+ "jno 0f\n"
15157+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
15158+ "int $4\n0:\n"
15159+ _ASM_EXTABLE(0b, 0b)
15160+#endif
15161+
15162 : "+m" (sem->count)
15163 : "er" (delta));
15164 }
15165@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15166 */
15167 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
15168 {
15169- return delta + xadd(&sem->count, delta);
15170+ return delta + xadd_check_overflow(&sem->count, delta);
15171 }
15172
15173 #endif /* __KERNEL__ */
15174diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
15175index c48a950..c6d7468 100644
15176--- a/arch/x86/include/asm/segment.h
15177+++ b/arch/x86/include/asm/segment.h
15178@@ -64,10 +64,15 @@
15179 * 26 - ESPFIX small SS
15180 * 27 - per-cpu [ offset to per-cpu data area ]
15181 * 28 - stack_canary-20 [ for stack protector ]
15182- * 29 - unused
15183- * 30 - unused
15184+ * 29 - PCI BIOS CS
15185+ * 30 - PCI BIOS DS
15186 * 31 - TSS for double fault handler
15187 */
15188+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
15189+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
15190+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
15191+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
15192+
15193 #define GDT_ENTRY_TLS_MIN 6
15194 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
15195
15196@@ -79,6 +84,8 @@
15197
15198 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
15199
15200+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
15201+
15202 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
15203
15204 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
15205@@ -104,6 +111,12 @@
15206 #define __KERNEL_STACK_CANARY 0
15207 #endif
15208
15209+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
15210+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
15211+
15212+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
15213+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
15214+
15215 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
15216
15217 /*
15218@@ -141,7 +154,7 @@
15219 */
15220
15221 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
15222-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
15223+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
15224
15225
15226 #else
15227@@ -165,6 +178,8 @@
15228 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
15229 #define __USER32_DS __USER_DS
15230
15231+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
15232+
15233 #define GDT_ENTRY_TSS 8 /* needs two entries */
15234 #define GDT_ENTRY_LDT 10 /* needs two entries */
15235 #define GDT_ENTRY_TLS_MIN 12
15236@@ -185,6 +200,7 @@
15237 #endif
15238
15239 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
15240+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
15241 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
15242 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
15243 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
15244@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
15245 {
15246 unsigned long __limit;
15247 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
15248- return __limit + 1;
15249+ return __limit;
15250 }
15251
15252 #endif /* !__ASSEMBLY__ */
15253diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
15254index b073aae..39f9bdd 100644
15255--- a/arch/x86/include/asm/smp.h
15256+++ b/arch/x86/include/asm/smp.h
15257@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
15258 /* cpus sharing the last level cache: */
15259 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
15260 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
15261-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
15262+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
15263
15264 static inline struct cpumask *cpu_sibling_mask(int cpu)
15265 {
15266@@ -79,7 +79,7 @@ struct smp_ops {
15267
15268 void (*send_call_func_ipi)(const struct cpumask *mask);
15269 void (*send_call_func_single_ipi)(int cpu);
15270-};
15271+} __no_const;
15272
15273 /* Globals due to paravirt */
15274 extern void set_cpu_sibling_map(int cpu);
15275@@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
15276 extern int safe_smp_processor_id(void);
15277
15278 #elif defined(CONFIG_X86_64_SMP)
15279-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15280-
15281-#define stack_smp_processor_id() \
15282-({ \
15283- struct thread_info *ti; \
15284- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
15285- ti->cpu; \
15286-})
15287+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15288+#define stack_smp_processor_id() raw_smp_processor_id()
15289 #define safe_smp_processor_id() smp_processor_id()
15290
15291 #endif
15292diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
15293index 33692ea..350a534 100644
15294--- a/arch/x86/include/asm/spinlock.h
15295+++ b/arch/x86/include/asm/spinlock.h
15296@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
15297 static inline void arch_read_lock(arch_rwlock_t *rw)
15298 {
15299 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
15300+
15301+#ifdef CONFIG_PAX_REFCOUNT
15302+ "jno 0f\n"
15303+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
15304+ "int $4\n0:\n"
15305+ _ASM_EXTABLE(0b, 0b)
15306+#endif
15307+
15308 "jns 1f\n"
15309 "call __read_lock_failed\n\t"
15310 "1:\n"
15311@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
15312 static inline void arch_write_lock(arch_rwlock_t *rw)
15313 {
15314 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
15315+
15316+#ifdef CONFIG_PAX_REFCOUNT
15317+ "jno 0f\n"
15318+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
15319+ "int $4\n0:\n"
15320+ _ASM_EXTABLE(0b, 0b)
15321+#endif
15322+
15323 "jz 1f\n"
15324 "call __write_lock_failed\n\t"
15325 "1:\n"
15326@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
15327
15328 static inline void arch_read_unlock(arch_rwlock_t *rw)
15329 {
15330- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
15331+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
15332+
15333+#ifdef CONFIG_PAX_REFCOUNT
15334+ "jno 0f\n"
15335+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
15336+ "int $4\n0:\n"
15337+ _ASM_EXTABLE(0b, 0b)
15338+#endif
15339+
15340 :"+m" (rw->lock) : : "memory");
15341 }
15342
15343 static inline void arch_write_unlock(arch_rwlock_t *rw)
15344 {
15345- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
15346+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
15347+
15348+#ifdef CONFIG_PAX_REFCOUNT
15349+ "jno 0f\n"
15350+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
15351+ "int $4\n0:\n"
15352+ _ASM_EXTABLE(0b, 0b)
15353+#endif
15354+
15355 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
15356 }
15357
15358diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
15359index 6a99859..03cb807 100644
15360--- a/arch/x86/include/asm/stackprotector.h
15361+++ b/arch/x86/include/asm/stackprotector.h
15362@@ -47,7 +47,7 @@
15363 * head_32 for boot CPU and setup_per_cpu_areas() for others.
15364 */
15365 #define GDT_STACK_CANARY_INIT \
15366- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
15367+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
15368
15369 /*
15370 * Initialize the stackprotector canary value.
15371@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
15372
15373 static inline void load_stack_canary_segment(void)
15374 {
15375-#ifdef CONFIG_X86_32
15376+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
15377 asm volatile ("mov %0, %%gs" : : "r" (0));
15378 #endif
15379 }
15380diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
15381index 70bbe39..4ae2bd4 100644
15382--- a/arch/x86/include/asm/stacktrace.h
15383+++ b/arch/x86/include/asm/stacktrace.h
15384@@ -11,28 +11,20 @@
15385
15386 extern int kstack_depth_to_print;
15387
15388-struct thread_info;
15389+struct task_struct;
15390 struct stacktrace_ops;
15391
15392-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
15393- unsigned long *stack,
15394- unsigned long bp,
15395- const struct stacktrace_ops *ops,
15396- void *data,
15397- unsigned long *end,
15398- int *graph);
15399+typedef unsigned long walk_stack_t(struct task_struct *task,
15400+ void *stack_start,
15401+ unsigned long *stack,
15402+ unsigned long bp,
15403+ const struct stacktrace_ops *ops,
15404+ void *data,
15405+ unsigned long *end,
15406+ int *graph);
15407
15408-extern unsigned long
15409-print_context_stack(struct thread_info *tinfo,
15410- unsigned long *stack, unsigned long bp,
15411- const struct stacktrace_ops *ops, void *data,
15412- unsigned long *end, int *graph);
15413-
15414-extern unsigned long
15415-print_context_stack_bp(struct thread_info *tinfo,
15416- unsigned long *stack, unsigned long bp,
15417- const struct stacktrace_ops *ops, void *data,
15418- unsigned long *end, int *graph);
15419+extern walk_stack_t print_context_stack;
15420+extern walk_stack_t print_context_stack_bp;
15421
15422 /* Generic stack tracer with callbacks */
15423
15424@@ -40,7 +32,7 @@ struct stacktrace_ops {
15425 void (*address)(void *data, unsigned long address, int reliable);
15426 /* On negative return stop dumping */
15427 int (*stack)(void *data, char *name);
15428- walk_stack_t walk_stack;
15429+ walk_stack_t *walk_stack;
15430 };
15431
15432 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
15433diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
15434index 4ec45b3..a4f0a8a 100644
15435--- a/arch/x86/include/asm/switch_to.h
15436+++ b/arch/x86/include/asm/switch_to.h
15437@@ -108,7 +108,7 @@ do { \
15438 "call __switch_to\n\t" \
15439 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
15440 __switch_canary \
15441- "movq %P[thread_info](%%rsi),%%r8\n\t" \
15442+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
15443 "movq %%rax,%%rdi\n\t" \
15444 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
15445 "jnz ret_from_fork\n\t" \
15446@@ -119,7 +119,7 @@ do { \
15447 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
15448 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
15449 [_tif_fork] "i" (_TIF_FORK), \
15450- [thread_info] "i" (offsetof(struct task_struct, stack)), \
15451+ [thread_info] "m" (current_tinfo), \
15452 [current_task] "m" (current_task) \
15453 __switch_canary_iparam \
15454 : "memory", "cc" __EXTRA_CLOBBER)
15455diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
15456index 2cd056e..0224df8 100644
15457--- a/arch/x86/include/asm/thread_info.h
15458+++ b/arch/x86/include/asm/thread_info.h
15459@@ -10,6 +10,7 @@
15460 #include <linux/compiler.h>
15461 #include <asm/page.h>
15462 #include <asm/types.h>
15463+#include <asm/percpu.h>
15464
15465 /*
15466 * low level task data that entry.S needs immediate access to
15467@@ -23,7 +24,6 @@ struct exec_domain;
15468 #include <linux/atomic.h>
15469
15470 struct thread_info {
15471- struct task_struct *task; /* main task structure */
15472 struct exec_domain *exec_domain; /* execution domain */
15473 __u32 flags; /* low level flags */
15474 __u32 status; /* thread synchronous flags */
15475@@ -33,19 +33,13 @@ struct thread_info {
15476 mm_segment_t addr_limit;
15477 struct restart_block restart_block;
15478 void __user *sysenter_return;
15479-#ifdef CONFIG_X86_32
15480- unsigned long previous_esp; /* ESP of the previous stack in
15481- case of nested (IRQ) stacks
15482- */
15483- __u8 supervisor_stack[0];
15484-#endif
15485+ unsigned long lowest_stack;
15486 unsigned int sig_on_uaccess_error:1;
15487 unsigned int uaccess_err:1; /* uaccess failed */
15488 };
15489
15490-#define INIT_THREAD_INFO(tsk) \
15491+#define INIT_THREAD_INFO \
15492 { \
15493- .task = &tsk, \
15494 .exec_domain = &default_exec_domain, \
15495 .flags = 0, \
15496 .cpu = 0, \
15497@@ -56,7 +50,7 @@ struct thread_info {
15498 }, \
15499 }
15500
15501-#define init_thread_info (init_thread_union.thread_info)
15502+#define init_thread_info (init_thread_union.stack)
15503 #define init_stack (init_thread_union.stack)
15504
15505 #else /* !__ASSEMBLY__ */
15506@@ -97,6 +91,7 @@ struct thread_info {
15507 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
15508 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
15509 #define TIF_X32 30 /* 32-bit native x86-64 binary */
15510+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
15511
15512 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
15513 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
15514@@ -121,17 +116,18 @@ struct thread_info {
15515 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
15516 #define _TIF_ADDR32 (1 << TIF_ADDR32)
15517 #define _TIF_X32 (1 << TIF_X32)
15518+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
15519
15520 /* work to do in syscall_trace_enter() */
15521 #define _TIF_WORK_SYSCALL_ENTRY \
15522 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
15523 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
15524- _TIF_NOHZ)
15525+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15526
15527 /* work to do in syscall_trace_leave() */
15528 #define _TIF_WORK_SYSCALL_EXIT \
15529 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
15530- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
15531+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
15532
15533 /* work to do on interrupt/exception return */
15534 #define _TIF_WORK_MASK \
15535@@ -142,7 +138,7 @@ struct thread_info {
15536 /* work to do on any return to user space */
15537 #define _TIF_ALLWORK_MASK \
15538 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
15539- _TIF_NOHZ)
15540+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15541
15542 /* Only used for 64 bit */
15543 #define _TIF_DO_NOTIFY_MASK \
15544@@ -158,45 +154,40 @@ struct thread_info {
15545
15546 #define PREEMPT_ACTIVE 0x10000000
15547
15548-#ifdef CONFIG_X86_32
15549-
15550-#define STACK_WARN (THREAD_SIZE/8)
15551-/*
15552- * macros/functions for gaining access to the thread information structure
15553- *
15554- * preempt_count needs to be 1 initially, until the scheduler is functional.
15555- */
15556-#ifndef __ASSEMBLY__
15557-
15558-
15559-/* how to get the current stack pointer from C */
15560-register unsigned long current_stack_pointer asm("esp") __used;
15561-
15562-/* how to get the thread information struct from C */
15563-static inline struct thread_info *current_thread_info(void)
15564-{
15565- return (struct thread_info *)
15566- (current_stack_pointer & ~(THREAD_SIZE - 1));
15567-}
15568-
15569-#else /* !__ASSEMBLY__ */
15570-
15571+#ifdef __ASSEMBLY__
15572 /* how to get the thread information struct from ASM */
15573 #define GET_THREAD_INFO(reg) \
15574- movl $-THREAD_SIZE, reg; \
15575- andl %esp, reg
15576+ mov PER_CPU_VAR(current_tinfo), reg
15577
15578 /* use this one if reg already contains %esp */
15579-#define GET_THREAD_INFO_WITH_ESP(reg) \
15580- andl $-THREAD_SIZE, reg
15581+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
15582+#else
15583+/* how to get the thread information struct from C */
15584+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
15585+
15586+static __always_inline struct thread_info *current_thread_info(void)
15587+{
15588+ return this_cpu_read_stable(current_tinfo);
15589+}
15590+#endif
15591+
15592+#ifdef CONFIG_X86_32
15593+
15594+#define STACK_WARN (THREAD_SIZE/8)
15595+/*
15596+ * macros/functions for gaining access to the thread information structure
15597+ *
15598+ * preempt_count needs to be 1 initially, until the scheduler is functional.
15599+ */
15600+#ifndef __ASSEMBLY__
15601+
15602+/* how to get the current stack pointer from C */
15603+register unsigned long current_stack_pointer asm("esp") __used;
15604
15605 #endif
15606
15607 #else /* X86_32 */
15608
15609-#include <asm/percpu.h>
15610-#define KERNEL_STACK_OFFSET (5*8)
15611-
15612 /*
15613 * macros/functions for gaining access to the thread information structure
15614 * preempt_count needs to be 1 initially, until the scheduler is functional.
15615@@ -204,27 +195,8 @@ static inline struct thread_info *current_thread_info(void)
15616 #ifndef __ASSEMBLY__
15617 DECLARE_PER_CPU(unsigned long, kernel_stack);
15618
15619-static inline struct thread_info *current_thread_info(void)
15620-{
15621- struct thread_info *ti;
15622- ti = (void *)(this_cpu_read_stable(kernel_stack) +
15623- KERNEL_STACK_OFFSET - THREAD_SIZE);
15624- return ti;
15625-}
15626-
15627-#else /* !__ASSEMBLY__ */
15628-
15629-/* how to get the thread information struct from ASM */
15630-#define GET_THREAD_INFO(reg) \
15631- movq PER_CPU_VAR(kernel_stack),reg ; \
15632- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
15633-
15634-/*
15635- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
15636- * a certain register (to be used in assembler memory operands).
15637- */
15638-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
15639-
15640+/* how to get the current stack pointer from C */
15641+register unsigned long current_stack_pointer asm("rsp") __used;
15642 #endif
15643
15644 #endif /* !X86_32 */
15645@@ -285,5 +257,12 @@ static inline bool is_ia32_task(void)
15646 extern void arch_task_cache_init(void);
15647 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
15648 extern void arch_release_task_struct(struct task_struct *tsk);
15649+
15650+#define __HAVE_THREAD_FUNCTIONS
15651+#define task_thread_info(task) (&(task)->tinfo)
15652+#define task_stack_page(task) ((task)->stack)
15653+#define setup_thread_stack(p, org) do {} while (0)
15654+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
15655+
15656 #endif
15657 #endif /* _ASM_X86_THREAD_INFO_H */
15658diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
15659index 5ee2687..70d5895 100644
15660--- a/arch/x86/include/asm/uaccess.h
15661+++ b/arch/x86/include/asm/uaccess.h
15662@@ -7,6 +7,7 @@
15663 #include <linux/compiler.h>
15664 #include <linux/thread_info.h>
15665 #include <linux/string.h>
15666+#include <linux/sched.h>
15667 #include <asm/asm.h>
15668 #include <asm/page.h>
15669 #include <asm/smap.h>
15670@@ -29,7 +30,12 @@
15671
15672 #define get_ds() (KERNEL_DS)
15673 #define get_fs() (current_thread_info()->addr_limit)
15674+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15675+void __set_fs(mm_segment_t x);
15676+void set_fs(mm_segment_t x);
15677+#else
15678 #define set_fs(x) (current_thread_info()->addr_limit = (x))
15679+#endif
15680
15681 #define segment_eq(a, b) ((a).seg == (b).seg)
15682
15683@@ -77,8 +83,33 @@
15684 * checks that the pointer is in the user space range - after calling
15685 * this function, memory access functions may still return -EFAULT.
15686 */
15687-#define access_ok(type, addr, size) \
15688- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15689+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15690+#define access_ok(type, addr, size) \
15691+({ \
15692+ long __size = size; \
15693+ unsigned long __addr = (unsigned long)addr; \
15694+ unsigned long __addr_ao = __addr & PAGE_MASK; \
15695+ unsigned long __end_ao = __addr + __size - 1; \
15696+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
15697+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
15698+ while(__addr_ao <= __end_ao) { \
15699+ char __c_ao; \
15700+ __addr_ao += PAGE_SIZE; \
15701+ if (__size > PAGE_SIZE) \
15702+ cond_resched(); \
15703+ if (__get_user(__c_ao, (char __user *)__addr)) \
15704+ break; \
15705+ if (type != VERIFY_WRITE) { \
15706+ __addr = __addr_ao; \
15707+ continue; \
15708+ } \
15709+ if (__put_user(__c_ao, (char __user *)__addr)) \
15710+ break; \
15711+ __addr = __addr_ao; \
15712+ } \
15713+ } \
15714+ __ret_ao; \
15715+})
15716
15717 /*
15718 * The exception table consists of pairs of addresses relative to the
15719@@ -176,13 +207,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
15720 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
15721 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
15722
15723-
15724+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15725+#define __copyuser_seg "gs;"
15726+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
15727+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
15728+#else
15729+#define __copyuser_seg
15730+#define __COPYUSER_SET_ES
15731+#define __COPYUSER_RESTORE_ES
15732+#endif
15733
15734 #ifdef CONFIG_X86_32
15735 #define __put_user_asm_u64(x, addr, err, errret) \
15736 asm volatile(ASM_STAC "\n" \
15737- "1: movl %%eax,0(%2)\n" \
15738- "2: movl %%edx,4(%2)\n" \
15739+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
15740+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
15741 "3: " ASM_CLAC "\n" \
15742 ".section .fixup,\"ax\"\n" \
15743 "4: movl %3,%0\n" \
15744@@ -195,8 +234,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
15745
15746 #define __put_user_asm_ex_u64(x, addr) \
15747 asm volatile(ASM_STAC "\n" \
15748- "1: movl %%eax,0(%1)\n" \
15749- "2: movl %%edx,4(%1)\n" \
15750+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
15751+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
15752 "3: " ASM_CLAC "\n" \
15753 _ASM_EXTABLE_EX(1b, 2b) \
15754 _ASM_EXTABLE_EX(2b, 3b) \
15755@@ -246,7 +285,7 @@ extern void __put_user_8(void);
15756 __typeof__(*(ptr)) __pu_val; \
15757 __chk_user_ptr(ptr); \
15758 might_fault(); \
15759- __pu_val = x; \
15760+ __pu_val = (x); \
15761 switch (sizeof(*(ptr))) { \
15762 case 1: \
15763 __put_user_x(1, __pu_val, ptr, __ret_pu); \
15764@@ -345,7 +384,7 @@ do { \
15765
15766 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15767 asm volatile(ASM_STAC "\n" \
15768- "1: mov"itype" %2,%"rtype"1\n" \
15769+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
15770 "2: " ASM_CLAC "\n" \
15771 ".section .fixup,\"ax\"\n" \
15772 "3: mov %3,%0\n" \
15773@@ -353,7 +392,7 @@ do { \
15774 " jmp 2b\n" \
15775 ".previous\n" \
15776 _ASM_EXTABLE(1b, 3b) \
15777- : "=r" (err), ltype(x) \
15778+ : "=r" (err), ltype (x) \
15779 : "m" (__m(addr)), "i" (errret), "0" (err))
15780
15781 #define __get_user_size_ex(x, ptr, size) \
15782@@ -378,7 +417,7 @@ do { \
15783 } while (0)
15784
15785 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
15786- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
15787+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
15788 "2:\n" \
15789 _ASM_EXTABLE_EX(1b, 2b) \
15790 : ltype(x) : "m" (__m(addr)))
15791@@ -395,13 +434,24 @@ do { \
15792 int __gu_err; \
15793 unsigned long __gu_val; \
15794 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
15795- (x) = (__force __typeof__(*(ptr)))__gu_val; \
15796+ (x) = (__typeof__(*(ptr)))__gu_val; \
15797 __gu_err; \
15798 })
15799
15800 /* FIXME: this hack is definitely wrong -AK */
15801 struct __large_struct { unsigned long buf[100]; };
15802-#define __m(x) (*(struct __large_struct __user *)(x))
15803+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15804+#define ____m(x) \
15805+({ \
15806+ unsigned long ____x = (unsigned long)(x); \
15807+ if (____x < pax_user_shadow_base) \
15808+ ____x += pax_user_shadow_base; \
15809+ (typeof(x))____x; \
15810+})
15811+#else
15812+#define ____m(x) (x)
15813+#endif
15814+#define __m(x) (*(struct __large_struct __user *)____m(x))
15815
15816 /*
15817 * Tell gcc we read from memory instead of writing: this is because
15818@@ -410,7 +460,7 @@ struct __large_struct { unsigned long buf[100]; };
15819 */
15820 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15821 asm volatile(ASM_STAC "\n" \
15822- "1: mov"itype" %"rtype"1,%2\n" \
15823+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
15824 "2: " ASM_CLAC "\n" \
15825 ".section .fixup,\"ax\"\n" \
15826 "3: mov %3,%0\n" \
15827@@ -418,10 +468,10 @@ struct __large_struct { unsigned long buf[100]; };
15828 ".previous\n" \
15829 _ASM_EXTABLE(1b, 3b) \
15830 : "=r"(err) \
15831- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
15832+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
15833
15834 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
15835- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
15836+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
15837 "2:\n" \
15838 _ASM_EXTABLE_EX(1b, 2b) \
15839 : : ltype(x), "m" (__m(addr)))
15840@@ -460,8 +510,12 @@ struct __large_struct { unsigned long buf[100]; };
15841 * On error, the variable @x is set to zero.
15842 */
15843
15844+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15845+#define __get_user(x, ptr) get_user((x), (ptr))
15846+#else
15847 #define __get_user(x, ptr) \
15848 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
15849+#endif
15850
15851 /**
15852 * __put_user: - Write a simple value into user space, with less checking.
15853@@ -483,8 +537,12 @@ struct __large_struct { unsigned long buf[100]; };
15854 * Returns zero on success, or -EFAULT on error.
15855 */
15856
15857+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15858+#define __put_user(x, ptr) put_user((x), (ptr))
15859+#else
15860 #define __put_user(x, ptr) \
15861 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
15862+#endif
15863
15864 #define __get_user_unaligned __get_user
15865 #define __put_user_unaligned __put_user
15866@@ -502,7 +560,7 @@ struct __large_struct { unsigned long buf[100]; };
15867 #define get_user_ex(x, ptr) do { \
15868 unsigned long __gue_val; \
15869 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
15870- (x) = (__force __typeof__(*(ptr)))__gue_val; \
15871+ (x) = (__typeof__(*(ptr)))__gue_val; \
15872 } while (0)
15873
15874 #define put_user_try uaccess_try
15875@@ -519,8 +577,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
15876 extern __must_check long strlen_user(const char __user *str);
15877 extern __must_check long strnlen_user(const char __user *str, long n);
15878
15879-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
15880-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
15881+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15882+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15883
15884 /*
15885 * movsl can be slow when source and dest are not both 8-byte aligned
15886diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
15887index 7f760a9..04b1c65 100644
15888--- a/arch/x86/include/asm/uaccess_32.h
15889+++ b/arch/x86/include/asm/uaccess_32.h
15890@@ -11,15 +11,15 @@
15891 #include <asm/page.h>
15892
15893 unsigned long __must_check __copy_to_user_ll
15894- (void __user *to, const void *from, unsigned long n);
15895+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
15896 unsigned long __must_check __copy_from_user_ll
15897- (void *to, const void __user *from, unsigned long n);
15898+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15899 unsigned long __must_check __copy_from_user_ll_nozero
15900- (void *to, const void __user *from, unsigned long n);
15901+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15902 unsigned long __must_check __copy_from_user_ll_nocache
15903- (void *to, const void __user *from, unsigned long n);
15904+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15905 unsigned long __must_check __copy_from_user_ll_nocache_nozero
15906- (void *to, const void __user *from, unsigned long n);
15907+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15908
15909 /**
15910 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
15911@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
15912 static __always_inline unsigned long __must_check
15913 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
15914 {
15915+ if ((long)n < 0)
15916+ return n;
15917+
15918+ check_object_size(from, n, true);
15919+
15920 if (__builtin_constant_p(n)) {
15921 unsigned long ret;
15922
15923@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
15924 __copy_to_user(void __user *to, const void *from, unsigned long n)
15925 {
15926 might_fault();
15927+
15928 return __copy_to_user_inatomic(to, from, n);
15929 }
15930
15931 static __always_inline unsigned long
15932 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
15933 {
15934+ if ((long)n < 0)
15935+ return n;
15936+
15937 /* Avoid zeroing the tail if the copy fails..
15938 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
15939 * but as the zeroing behaviour is only significant when n is not
15940@@ -137,6 +146,12 @@ static __always_inline unsigned long
15941 __copy_from_user(void *to, const void __user *from, unsigned long n)
15942 {
15943 might_fault();
15944+
15945+ if ((long)n < 0)
15946+ return n;
15947+
15948+ check_object_size(to, n, false);
15949+
15950 if (__builtin_constant_p(n)) {
15951 unsigned long ret;
15952
15953@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
15954 const void __user *from, unsigned long n)
15955 {
15956 might_fault();
15957+
15958+ if ((long)n < 0)
15959+ return n;
15960+
15961 if (__builtin_constant_p(n)) {
15962 unsigned long ret;
15963
15964@@ -181,15 +200,19 @@ static __always_inline unsigned long
15965 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
15966 unsigned long n)
15967 {
15968- return __copy_from_user_ll_nocache_nozero(to, from, n);
15969+ if ((long)n < 0)
15970+ return n;
15971+
15972+ return __copy_from_user_ll_nocache_nozero(to, from, n);
15973 }
15974
15975-unsigned long __must_check copy_to_user(void __user *to,
15976- const void *from, unsigned long n);
15977-unsigned long __must_check _copy_from_user(void *to,
15978- const void __user *from,
15979- unsigned long n);
15980-
15981+extern void copy_to_user_overflow(void)
15982+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15983+ __compiletime_error("copy_to_user() buffer size is not provably correct")
15984+#else
15985+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
15986+#endif
15987+;
15988
15989 extern void copy_from_user_overflow(void)
15990 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15991@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
15992 #endif
15993 ;
15994
15995-static inline unsigned long __must_check copy_from_user(void *to,
15996- const void __user *from,
15997- unsigned long n)
15998+/**
15999+ * copy_to_user: - Copy a block of data into user space.
16000+ * @to: Destination address, in user space.
16001+ * @from: Source address, in kernel space.
16002+ * @n: Number of bytes to copy.
16003+ *
16004+ * Context: User context only. This function may sleep.
16005+ *
16006+ * Copy data from kernel space to user space.
16007+ *
16008+ * Returns number of bytes that could not be copied.
16009+ * On success, this will be zero.
16010+ */
16011+static inline unsigned long __must_check
16012+copy_to_user(void __user *to, const void *from, unsigned long n)
16013 {
16014- int sz = __compiletime_object_size(to);
16015+ size_t sz = __compiletime_object_size(from);
16016
16017- if (likely(sz == -1 || sz >= n))
16018- n = _copy_from_user(to, from, n);
16019- else
16020+ if (unlikely(sz != (size_t)-1 && sz < n))
16021+ copy_to_user_overflow();
16022+ else if (access_ok(VERIFY_WRITE, to, n))
16023+ n = __copy_to_user(to, from, n);
16024+ return n;
16025+}
16026+
16027+/**
16028+ * copy_from_user: - Copy a block of data from user space.
16029+ * @to: Destination address, in kernel space.
16030+ * @from: Source address, in user space.
16031+ * @n: Number of bytes to copy.
16032+ *
16033+ * Context: User context only. This function may sleep.
16034+ *
16035+ * Copy data from user space to kernel space.
16036+ *
16037+ * Returns number of bytes that could not be copied.
16038+ * On success, this will be zero.
16039+ *
16040+ * If some data could not be copied, this function will pad the copied
16041+ * data to the requested size using zero bytes.
16042+ */
16043+static inline unsigned long __must_check
16044+copy_from_user(void *to, const void __user *from, unsigned long n)
16045+{
16046+ size_t sz = __compiletime_object_size(to);
16047+
16048+ check_object_size(to, n, false);
16049+
16050+ if (unlikely(sz != (size_t)-1 && sz < n))
16051 copy_from_user_overflow();
16052-
16053+ else if (access_ok(VERIFY_READ, from, n))
16054+ n = __copy_from_user(to, from, n);
16055+ else if ((long)n > 0)
16056+ memset(to, 0, n);
16057 return n;
16058 }
16059
16060diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
16061index 142810c..1f2a0a7 100644
16062--- a/arch/x86/include/asm/uaccess_64.h
16063+++ b/arch/x86/include/asm/uaccess_64.h
16064@@ -10,6 +10,9 @@
16065 #include <asm/alternative.h>
16066 #include <asm/cpufeature.h>
16067 #include <asm/page.h>
16068+#include <asm/pgtable.h>
16069+
16070+#define set_fs(x) (current_thread_info()->addr_limit = (x))
16071
16072 /*
16073 * Copy To/From Userspace
16074@@ -17,13 +20,13 @@
16075
16076 /* Handles exceptions in both to and from, but doesn't do access_ok */
16077 __must_check unsigned long
16078-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
16079+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
16080 __must_check unsigned long
16081-copy_user_generic_string(void *to, const void *from, unsigned len);
16082+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
16083 __must_check unsigned long
16084-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
16085+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
16086
16087-static __always_inline __must_check unsigned long
16088+static __always_inline __must_check __size_overflow(3) unsigned long
16089 copy_user_generic(void *to, const void *from, unsigned len)
16090 {
16091 unsigned ret;
16092@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
16093 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
16094 "=d" (len)),
16095 "1" (to), "2" (from), "3" (len)
16096- : "memory", "rcx", "r8", "r9", "r10", "r11");
16097+ : "memory", "rcx", "r8", "r9", "r11");
16098 return ret;
16099 }
16100
16101+static __always_inline __must_check unsigned long
16102+__copy_to_user(void __user *to, const void *from, unsigned long len);
16103+static __always_inline __must_check unsigned long
16104+__copy_from_user(void *to, const void __user *from, unsigned long len);
16105 __must_check unsigned long
16106-_copy_to_user(void __user *to, const void *from, unsigned len);
16107-__must_check unsigned long
16108-_copy_from_user(void *to, const void __user *from, unsigned len);
16109-__must_check unsigned long
16110-copy_in_user(void __user *to, const void __user *from, unsigned len);
16111+copy_in_user(void __user *to, const void __user *from, unsigned long len);
16112+
16113+extern void copy_to_user_overflow(void)
16114+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16115+ __compiletime_error("copy_to_user() buffer size is not provably correct")
16116+#else
16117+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
16118+#endif
16119+;
16120+
16121+extern void copy_from_user_overflow(void)
16122+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16123+ __compiletime_error("copy_from_user() buffer size is not provably correct")
16124+#else
16125+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
16126+#endif
16127+;
16128
16129 static inline unsigned long __must_check copy_from_user(void *to,
16130 const void __user *from,
16131 unsigned long n)
16132 {
16133- int sz = __compiletime_object_size(to);
16134-
16135 might_fault();
16136- if (likely(sz == -1 || sz >= n))
16137- n = _copy_from_user(to, from, n);
16138-#ifdef CONFIG_DEBUG_VM
16139- else
16140- WARN(1, "Buffer overflow detected!\n");
16141-#endif
16142+
16143+ check_object_size(to, n, false);
16144+
16145+ if (access_ok(VERIFY_READ, from, n))
16146+ n = __copy_from_user(to, from, n);
16147+ else if (n < INT_MAX)
16148+ memset(to, 0, n);
16149 return n;
16150 }
16151
16152 static __always_inline __must_check
16153-int copy_to_user(void __user *dst, const void *src, unsigned size)
16154+int copy_to_user(void __user *dst, const void *src, unsigned long size)
16155 {
16156 might_fault();
16157
16158- return _copy_to_user(dst, src, size);
16159+ if (access_ok(VERIFY_WRITE, dst, size))
16160+ size = __copy_to_user(dst, src, size);
16161+ return size;
16162 }
16163
16164 static __always_inline __must_check
16165-int __copy_from_user(void *dst, const void __user *src, unsigned size)
16166+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
16167 {
16168- int ret = 0;
16169+ size_t sz = __compiletime_object_size(dst);
16170+ unsigned ret = 0;
16171
16172 might_fault();
16173+
16174+ if (size > INT_MAX)
16175+ return size;
16176+
16177+ check_object_size(dst, size, false);
16178+
16179+#ifdef CONFIG_PAX_MEMORY_UDEREF
16180+ if (!__access_ok(VERIFY_READ, src, size))
16181+ return size;
16182+#endif
16183+
16184+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16185+ copy_from_user_overflow();
16186+ return size;
16187+ }
16188+
16189 if (!__builtin_constant_p(size))
16190- return copy_user_generic(dst, (__force void *)src, size);
16191+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16192 switch (size) {
16193- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
16194+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
16195 ret, "b", "b", "=q", 1);
16196 return ret;
16197- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
16198+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
16199 ret, "w", "w", "=r", 2);
16200 return ret;
16201- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
16202+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
16203 ret, "l", "k", "=r", 4);
16204 return ret;
16205- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
16206+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16207 ret, "q", "", "=r", 8);
16208 return ret;
16209 case 10:
16210- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16211+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16212 ret, "q", "", "=r", 10);
16213 if (unlikely(ret))
16214 return ret;
16215 __get_user_asm(*(u16 *)(8 + (char *)dst),
16216- (u16 __user *)(8 + (char __user *)src),
16217+ (const u16 __user *)(8 + (const char __user *)src),
16218 ret, "w", "w", "=r", 2);
16219 return ret;
16220 case 16:
16221- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16222+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16223 ret, "q", "", "=r", 16);
16224 if (unlikely(ret))
16225 return ret;
16226 __get_user_asm(*(u64 *)(8 + (char *)dst),
16227- (u64 __user *)(8 + (char __user *)src),
16228+ (const u64 __user *)(8 + (const char __user *)src),
16229 ret, "q", "", "=r", 8);
16230 return ret;
16231 default:
16232- return copy_user_generic(dst, (__force void *)src, size);
16233+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16234 }
16235 }
16236
16237 static __always_inline __must_check
16238-int __copy_to_user(void __user *dst, const void *src, unsigned size)
16239+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
16240 {
16241- int ret = 0;
16242+ size_t sz = __compiletime_object_size(src);
16243+ unsigned ret = 0;
16244
16245 might_fault();
16246+
16247+ if (size > INT_MAX)
16248+ return size;
16249+
16250+ check_object_size(src, size, true);
16251+
16252+#ifdef CONFIG_PAX_MEMORY_UDEREF
16253+ if (!__access_ok(VERIFY_WRITE, dst, size))
16254+ return size;
16255+#endif
16256+
16257+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16258+ copy_to_user_overflow();
16259+ return size;
16260+ }
16261+
16262 if (!__builtin_constant_p(size))
16263- return copy_user_generic((__force void *)dst, src, size);
16264+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16265 switch (size) {
16266- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
16267+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
16268 ret, "b", "b", "iq", 1);
16269 return ret;
16270- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
16271+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
16272 ret, "w", "w", "ir", 2);
16273 return ret;
16274- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
16275+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
16276 ret, "l", "k", "ir", 4);
16277 return ret;
16278- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
16279+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16280 ret, "q", "", "er", 8);
16281 return ret;
16282 case 10:
16283- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16284+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16285 ret, "q", "", "er", 10);
16286 if (unlikely(ret))
16287 return ret;
16288 asm("":::"memory");
16289- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
16290+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
16291 ret, "w", "w", "ir", 2);
16292 return ret;
16293 case 16:
16294- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16295+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16296 ret, "q", "", "er", 16);
16297 if (unlikely(ret))
16298 return ret;
16299 asm("":::"memory");
16300- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
16301+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
16302 ret, "q", "", "er", 8);
16303 return ret;
16304 default:
16305- return copy_user_generic((__force void *)dst, src, size);
16306+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16307 }
16308 }
16309
16310 static __always_inline __must_check
16311-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16312+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
16313 {
16314- int ret = 0;
16315+ unsigned ret = 0;
16316
16317 might_fault();
16318+
16319+ if (size > INT_MAX)
16320+ return size;
16321+
16322+#ifdef CONFIG_PAX_MEMORY_UDEREF
16323+ if (!__access_ok(VERIFY_READ, src, size))
16324+ return size;
16325+ if (!__access_ok(VERIFY_WRITE, dst, size))
16326+ return size;
16327+#endif
16328+
16329 if (!__builtin_constant_p(size))
16330- return copy_user_generic((__force void *)dst,
16331- (__force void *)src, size);
16332+ return copy_user_generic((__force_kernel void *)____m(dst),
16333+ (__force_kernel const void *)____m(src), size);
16334 switch (size) {
16335 case 1: {
16336 u8 tmp;
16337- __get_user_asm(tmp, (u8 __user *)src,
16338+ __get_user_asm(tmp, (const u8 __user *)src,
16339 ret, "b", "b", "=q", 1);
16340 if (likely(!ret))
16341 __put_user_asm(tmp, (u8 __user *)dst,
16342@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16343 }
16344 case 2: {
16345 u16 tmp;
16346- __get_user_asm(tmp, (u16 __user *)src,
16347+ __get_user_asm(tmp, (const u16 __user *)src,
16348 ret, "w", "w", "=r", 2);
16349 if (likely(!ret))
16350 __put_user_asm(tmp, (u16 __user *)dst,
16351@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16352
16353 case 4: {
16354 u32 tmp;
16355- __get_user_asm(tmp, (u32 __user *)src,
16356+ __get_user_asm(tmp, (const u32 __user *)src,
16357 ret, "l", "k", "=r", 4);
16358 if (likely(!ret))
16359 __put_user_asm(tmp, (u32 __user *)dst,
16360@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16361 }
16362 case 8: {
16363 u64 tmp;
16364- __get_user_asm(tmp, (u64 __user *)src,
16365+ __get_user_asm(tmp, (const u64 __user *)src,
16366 ret, "q", "", "=r", 8);
16367 if (likely(!ret))
16368 __put_user_asm(tmp, (u64 __user *)dst,
16369@@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16370 return ret;
16371 }
16372 default:
16373- return copy_user_generic((__force void *)dst,
16374- (__force void *)src, size);
16375+ return copy_user_generic((__force_kernel void *)____m(dst),
16376+ (__force_kernel const void *)____m(src), size);
16377 }
16378 }
16379
16380 static __must_check __always_inline int
16381-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
16382+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
16383 {
16384- return copy_user_generic(dst, (__force const void *)src, size);
16385+ if (size > INT_MAX)
16386+ return size;
16387+
16388+#ifdef CONFIG_PAX_MEMORY_UDEREF
16389+ if (!__access_ok(VERIFY_READ, src, size))
16390+ return size;
16391+#endif
16392+
16393+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16394 }
16395
16396-static __must_check __always_inline int
16397-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
16398+static __must_check __always_inline unsigned long
16399+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
16400 {
16401- return copy_user_generic((__force void *)dst, src, size);
16402+ if (size > INT_MAX)
16403+ return size;
16404+
16405+#ifdef CONFIG_PAX_MEMORY_UDEREF
16406+ if (!__access_ok(VERIFY_WRITE, dst, size))
16407+ return size;
16408+#endif
16409+
16410+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16411 }
16412
16413-extern long __copy_user_nocache(void *dst, const void __user *src,
16414- unsigned size, int zerorest);
16415+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
16416+ unsigned long size, int zerorest) __size_overflow(3);
16417
16418-static inline int
16419-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
16420+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
16421 {
16422 might_sleep();
16423+
16424+ if (size > INT_MAX)
16425+ return size;
16426+
16427+#ifdef CONFIG_PAX_MEMORY_UDEREF
16428+ if (!__access_ok(VERIFY_READ, src, size))
16429+ return size;
16430+#endif
16431+
16432 return __copy_user_nocache(dst, src, size, 1);
16433 }
16434
16435-static inline int
16436-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16437- unsigned size)
16438+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16439+ unsigned long size)
16440 {
16441+ if (size > INT_MAX)
16442+ return size;
16443+
16444+#ifdef CONFIG_PAX_MEMORY_UDEREF
16445+ if (!__access_ok(VERIFY_READ, src, size))
16446+ return size;
16447+#endif
16448+
16449 return __copy_user_nocache(dst, src, size, 0);
16450 }
16451
16452-unsigned long
16453-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
16454+extern unsigned long
16455+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
16456
16457 #endif /* _ASM_X86_UACCESS_64_H */
16458diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
16459index 5b238981..77fdd78 100644
16460--- a/arch/x86/include/asm/word-at-a-time.h
16461+++ b/arch/x86/include/asm/word-at-a-time.h
16462@@ -11,7 +11,7 @@
16463 * and shift, for example.
16464 */
16465 struct word_at_a_time {
16466- const unsigned long one_bits, high_bits;
16467+ unsigned long one_bits, high_bits;
16468 };
16469
16470 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
16471diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
16472index d8d9922..bf6cecb 100644
16473--- a/arch/x86/include/asm/x86_init.h
16474+++ b/arch/x86/include/asm/x86_init.h
16475@@ -129,7 +129,7 @@ struct x86_init_ops {
16476 struct x86_init_timers timers;
16477 struct x86_init_iommu iommu;
16478 struct x86_init_pci pci;
16479-};
16480+} __no_const;
16481
16482 /**
16483 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
16484@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
16485 void (*setup_percpu_clockev)(void);
16486 void (*early_percpu_clock_init)(void);
16487 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
16488-};
16489+} __no_const;
16490
16491 /**
16492 * struct x86_platform_ops - platform specific runtime functions
16493@@ -166,7 +166,7 @@ struct x86_platform_ops {
16494 void (*save_sched_clock_state)(void);
16495 void (*restore_sched_clock_state)(void);
16496 void (*apic_post_init)(void);
16497-};
16498+} __no_const;
16499
16500 struct pci_dev;
16501 struct msi_msg;
16502@@ -180,7 +180,7 @@ struct x86_msi_ops {
16503 void (*teardown_msi_irqs)(struct pci_dev *dev);
16504 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
16505 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
16506-};
16507+} __no_const;
16508
16509 struct IO_APIC_route_entry;
16510 struct io_apic_irq_attr;
16511@@ -201,7 +201,7 @@ struct x86_io_apic_ops {
16512 unsigned int destination, int vector,
16513 struct io_apic_irq_attr *attr);
16514 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
16515-};
16516+} __no_const;
16517
16518 extern struct x86_init_ops x86_init;
16519 extern struct x86_cpuinit_ops x86_cpuinit;
16520diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
16521index 0415cda..b43d877 100644
16522--- a/arch/x86/include/asm/xsave.h
16523+++ b/arch/x86/include/asm/xsave.h
16524@@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16525 return -EFAULT;
16526
16527 __asm__ __volatile__(ASM_STAC "\n"
16528- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
16529+ "1:"
16530+ __copyuser_seg
16531+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
16532 "2: " ASM_CLAC "\n"
16533 ".section .fixup,\"ax\"\n"
16534 "3: movl $-1,%[err]\n"
16535@@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16536 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
16537 {
16538 int err;
16539- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
16540+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
16541 u32 lmask = mask;
16542 u32 hmask = mask >> 32;
16543
16544 __asm__ __volatile__(ASM_STAC "\n"
16545- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16546+ "1:"
16547+ __copyuser_seg
16548+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16549 "2: " ASM_CLAC "\n"
16550 ".section .fixup,\"ax\"\n"
16551 "3: movl $-1,%[err]\n"
16552diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
16553index bbae024..e1528f9 100644
16554--- a/arch/x86/include/uapi/asm/e820.h
16555+++ b/arch/x86/include/uapi/asm/e820.h
16556@@ -63,7 +63,7 @@ struct e820map {
16557 #define ISA_START_ADDRESS 0xa0000
16558 #define ISA_END_ADDRESS 0x100000
16559
16560-#define BIOS_BEGIN 0x000a0000
16561+#define BIOS_BEGIN 0x000c0000
16562 #define BIOS_END 0x00100000
16563
16564 #define BIOS_ROM_BASE 0xffe00000
16565diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
16566index 7bd3bd3..5dac791 100644
16567--- a/arch/x86/kernel/Makefile
16568+++ b/arch/x86/kernel/Makefile
16569@@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
16570 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
16571 obj-$(CONFIG_IRQ_WORK) += irq_work.o
16572 obj-y += probe_roms.o
16573-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
16574+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
16575 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
16576 obj-y += syscall_$(BITS).o
16577 obj-$(CONFIG_X86_64) += vsyscall_64.o
16578diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
16579index 230c8ea..f915130 100644
16580--- a/arch/x86/kernel/acpi/boot.c
16581+++ b/arch/x86/kernel/acpi/boot.c
16582@@ -1361,7 +1361,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
16583 * If your system is blacklisted here, but you find that acpi=force
16584 * works for you, please contact linux-acpi@vger.kernel.org
16585 */
16586-static struct dmi_system_id __initdata acpi_dmi_table[] = {
16587+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
16588 /*
16589 * Boxes that need ACPI disabled
16590 */
16591@@ -1436,7 +1436,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
16592 };
16593
16594 /* second table for DMI checks that should run after early-quirks */
16595-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
16596+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
16597 /*
16598 * HP laptops which use a DSDT reporting as HP/SB400/10000,
16599 * which includes some code which overrides all temperature
16600diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
16601index 0532f5d..36afc0a 100644
16602--- a/arch/x86/kernel/acpi/sleep.c
16603+++ b/arch/x86/kernel/acpi/sleep.c
16604@@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
16605 #else /* CONFIG_64BIT */
16606 #ifdef CONFIG_SMP
16607 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
16608+
16609+ pax_open_kernel();
16610 early_gdt_descr.address =
16611 (unsigned long)get_cpu_gdt_table(smp_processor_id());
16612+ pax_close_kernel();
16613+
16614 initial_gs = per_cpu_offset(smp_processor_id());
16615 #endif
16616 initial_code = (unsigned long)wakeup_long64;
16617diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
16618index 13ab720..95d5442 100644
16619--- a/arch/x86/kernel/acpi/wakeup_32.S
16620+++ b/arch/x86/kernel/acpi/wakeup_32.S
16621@@ -30,13 +30,11 @@ wakeup_pmode_return:
16622 # and restore the stack ... but you need gdt for this to work
16623 movl saved_context_esp, %esp
16624
16625- movl %cs:saved_magic, %eax
16626- cmpl $0x12345678, %eax
16627+ cmpl $0x12345678, saved_magic
16628 jne bogus_magic
16629
16630 # jump to place where we left off
16631- movl saved_eip, %eax
16632- jmp *%eax
16633+ jmp *(saved_eip)
16634
16635 bogus_magic:
16636 jmp bogus_magic
16637diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
16638index ef5ccca..bd83949 100644
16639--- a/arch/x86/kernel/alternative.c
16640+++ b/arch/x86/kernel/alternative.c
16641@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
16642 */
16643 for (a = start; a < end; a++) {
16644 instr = (u8 *)&a->instr_offset + a->instr_offset;
16645+
16646+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16647+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16648+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
16649+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16650+#endif
16651+
16652 replacement = (u8 *)&a->repl_offset + a->repl_offset;
16653 BUG_ON(a->replacementlen > a->instrlen);
16654 BUG_ON(a->instrlen > sizeof(insnbuf));
16655@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
16656 for (poff = start; poff < end; poff++) {
16657 u8 *ptr = (u8 *)poff + *poff;
16658
16659+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16660+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16661+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16662+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16663+#endif
16664+
16665 if (!*poff || ptr < text || ptr >= text_end)
16666 continue;
16667 /* turn DS segment override prefix into lock prefix */
16668- if (*ptr == 0x3e)
16669+ if (*ktla_ktva(ptr) == 0x3e)
16670 text_poke(ptr, ((unsigned char []){0xf0}), 1);
16671 }
16672 mutex_unlock(&text_mutex);
16673@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
16674 for (poff = start; poff < end; poff++) {
16675 u8 *ptr = (u8 *)poff + *poff;
16676
16677+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16678+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16679+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16680+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16681+#endif
16682+
16683 if (!*poff || ptr < text || ptr >= text_end)
16684 continue;
16685 /* turn lock prefix into DS segment override prefix */
16686- if (*ptr == 0xf0)
16687+ if (*ktla_ktva(ptr) == 0xf0)
16688 text_poke(ptr, ((unsigned char []){0x3E}), 1);
16689 }
16690 mutex_unlock(&text_mutex);
16691@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
16692
16693 BUG_ON(p->len > MAX_PATCH_LEN);
16694 /* prep the buffer with the original instructions */
16695- memcpy(insnbuf, p->instr, p->len);
16696+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
16697 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
16698 (unsigned long)p->instr, p->len);
16699
16700@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
16701 if (!uniproc_patched || num_possible_cpus() == 1)
16702 free_init_pages("SMP alternatives",
16703 (unsigned long)__smp_locks,
16704- (unsigned long)__smp_locks_end);
16705+ PAGE_ALIGN((unsigned long)__smp_locks_end));
16706 #endif
16707
16708 apply_paravirt(__parainstructions, __parainstructions_end);
16709@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
16710 * instructions. And on the local CPU you need to be protected again NMI or MCE
16711 * handlers seeing an inconsistent instruction while you patch.
16712 */
16713-void *__init_or_module text_poke_early(void *addr, const void *opcode,
16714+void *__kprobes text_poke_early(void *addr, const void *opcode,
16715 size_t len)
16716 {
16717 unsigned long flags;
16718 local_irq_save(flags);
16719- memcpy(addr, opcode, len);
16720+
16721+ pax_open_kernel();
16722+ memcpy(ktla_ktva(addr), opcode, len);
16723 sync_core();
16724+ pax_close_kernel();
16725+
16726 local_irq_restore(flags);
16727 /* Could also do a CLFLUSH here to speed up CPU recovery; but
16728 that causes hangs on some VIA CPUs. */
16729@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
16730 */
16731 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
16732 {
16733- unsigned long flags;
16734- char *vaddr;
16735+ unsigned char *vaddr = ktla_ktva(addr);
16736 struct page *pages[2];
16737- int i;
16738+ size_t i;
16739
16740 if (!core_kernel_text((unsigned long)addr)) {
16741- pages[0] = vmalloc_to_page(addr);
16742- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
16743+ pages[0] = vmalloc_to_page(vaddr);
16744+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
16745 } else {
16746- pages[0] = virt_to_page(addr);
16747+ pages[0] = virt_to_page(vaddr);
16748 WARN_ON(!PageReserved(pages[0]));
16749- pages[1] = virt_to_page(addr + PAGE_SIZE);
16750+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
16751 }
16752 BUG_ON(!pages[0]);
16753- local_irq_save(flags);
16754- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
16755- if (pages[1])
16756- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
16757- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
16758- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
16759- clear_fixmap(FIX_TEXT_POKE0);
16760- if (pages[1])
16761- clear_fixmap(FIX_TEXT_POKE1);
16762- local_flush_tlb();
16763- sync_core();
16764- /* Could also do a CLFLUSH here to speed up CPU recovery; but
16765- that causes hangs on some VIA CPUs. */
16766+ text_poke_early(addr, opcode, len);
16767 for (i = 0; i < len; i++)
16768- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
16769- local_irq_restore(flags);
16770+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
16771 return addr;
16772 }
16773
16774diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
16775index 904611b..004dde6 100644
16776--- a/arch/x86/kernel/apic/apic.c
16777+++ b/arch/x86/kernel/apic/apic.c
16778@@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
16779 /*
16780 * Debug level, exported for io_apic.c
16781 */
16782-unsigned int apic_verbosity;
16783+int apic_verbosity;
16784
16785 int pic_mode;
16786
16787@@ -1955,7 +1955,7 @@ void smp_error_interrupt(struct pt_regs *regs)
16788 apic_write(APIC_ESR, 0);
16789 v1 = apic_read(APIC_ESR);
16790 ack_APIC_irq();
16791- atomic_inc(&irq_err_count);
16792+ atomic_inc_unchecked(&irq_err_count);
16793
16794 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
16795 smp_processor_id(), v0 , v1);
16796diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
16797index 00c77cf..2dc6a2d 100644
16798--- a/arch/x86/kernel/apic/apic_flat_64.c
16799+++ b/arch/x86/kernel/apic/apic_flat_64.c
16800@@ -157,7 +157,7 @@ static int flat_probe(void)
16801 return 1;
16802 }
16803
16804-static struct apic apic_flat = {
16805+static struct apic apic_flat __read_only = {
16806 .name = "flat",
16807 .probe = flat_probe,
16808 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
16809@@ -271,7 +271,7 @@ static int physflat_probe(void)
16810 return 0;
16811 }
16812
16813-static struct apic apic_physflat = {
16814+static struct apic apic_physflat __read_only = {
16815
16816 .name = "physical flat",
16817 .probe = physflat_probe,
16818diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
16819index e145f28..2752888 100644
16820--- a/arch/x86/kernel/apic/apic_noop.c
16821+++ b/arch/x86/kernel/apic/apic_noop.c
16822@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
16823 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
16824 }
16825
16826-struct apic apic_noop = {
16827+struct apic apic_noop __read_only = {
16828 .name = "noop",
16829 .probe = noop_probe,
16830 .acpi_madt_oem_check = NULL,
16831diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
16832index d50e364..543bee3 100644
16833--- a/arch/x86/kernel/apic/bigsmp_32.c
16834+++ b/arch/x86/kernel/apic/bigsmp_32.c
16835@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
16836 return dmi_bigsmp;
16837 }
16838
16839-static struct apic apic_bigsmp = {
16840+static struct apic apic_bigsmp __read_only = {
16841
16842 .name = "bigsmp",
16843 .probe = probe_bigsmp,
16844diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
16845index 0874799..a7a7892 100644
16846--- a/arch/x86/kernel/apic/es7000_32.c
16847+++ b/arch/x86/kernel/apic/es7000_32.c
16848@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
16849 return ret && es7000_apic_is_cluster();
16850 }
16851
16852-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
16853-static struct apic __refdata apic_es7000_cluster = {
16854+static struct apic apic_es7000_cluster __read_only = {
16855
16856 .name = "es7000",
16857 .probe = probe_es7000,
16858@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
16859 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
16860 };
16861
16862-static struct apic __refdata apic_es7000 = {
16863+static struct apic apic_es7000 __read_only = {
16864
16865 .name = "es7000",
16866 .probe = probe_es7000,
16867diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
16868index 9ed796c..e930fe4 100644
16869--- a/arch/x86/kernel/apic/io_apic.c
16870+++ b/arch/x86/kernel/apic/io_apic.c
16871@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
16872 }
16873 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
16874
16875-void lock_vector_lock(void)
16876+void lock_vector_lock(void) __acquires(vector_lock)
16877 {
16878 /* Used to the online set of cpus does not change
16879 * during assign_irq_vector.
16880@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
16881 raw_spin_lock(&vector_lock);
16882 }
16883
16884-void unlock_vector_lock(void)
16885+void unlock_vector_lock(void) __releases(vector_lock)
16886 {
16887 raw_spin_unlock(&vector_lock);
16888 }
16889@@ -2362,7 +2362,7 @@ static void ack_apic_edge(struct irq_data *data)
16890 ack_APIC_irq();
16891 }
16892
16893-atomic_t irq_mis_count;
16894+atomic_unchecked_t irq_mis_count;
16895
16896 #ifdef CONFIG_GENERIC_PENDING_IRQ
16897 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
16898@@ -2503,7 +2503,7 @@ static void ack_apic_level(struct irq_data *data)
16899 * at the cpu.
16900 */
16901 if (!(v & (1 << (i & 0x1f)))) {
16902- atomic_inc(&irq_mis_count);
16903+ atomic_inc_unchecked(&irq_mis_count);
16904
16905 eoi_ioapic_irq(irq, cfg);
16906 }
16907diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
16908index d661ee9..791fd33 100644
16909--- a/arch/x86/kernel/apic/numaq_32.c
16910+++ b/arch/x86/kernel/apic/numaq_32.c
16911@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
16912 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
16913 }
16914
16915-/* Use __refdata to keep false positive warning calm. */
16916-static struct apic __refdata apic_numaq = {
16917+static struct apic apic_numaq __read_only = {
16918
16919 .name = "NUMAQ",
16920 .probe = probe_numaq,
16921diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
16922index eb35ef9..f184a21 100644
16923--- a/arch/x86/kernel/apic/probe_32.c
16924+++ b/arch/x86/kernel/apic/probe_32.c
16925@@ -72,7 +72,7 @@ static int probe_default(void)
16926 return 1;
16927 }
16928
16929-static struct apic apic_default = {
16930+static struct apic apic_default __read_only = {
16931
16932 .name = "default",
16933 .probe = probe_default,
16934diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
16935index 77c95c0..434f8a4 100644
16936--- a/arch/x86/kernel/apic/summit_32.c
16937+++ b/arch/x86/kernel/apic/summit_32.c
16938@@ -486,7 +486,7 @@ void setup_summit(void)
16939 }
16940 #endif
16941
16942-static struct apic apic_summit = {
16943+static struct apic apic_summit __read_only = {
16944
16945 .name = "summit",
16946 .probe = probe_summit,
16947diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
16948index c88baa4..757aee1 100644
16949--- a/arch/x86/kernel/apic/x2apic_cluster.c
16950+++ b/arch/x86/kernel/apic/x2apic_cluster.c
16951@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
16952 return notifier_from_errno(err);
16953 }
16954
16955-static struct notifier_block __refdata x2apic_cpu_notifier = {
16956+static struct notifier_block x2apic_cpu_notifier = {
16957 .notifier_call = update_clusterinfo,
16958 };
16959
16960@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
16961 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
16962 }
16963
16964-static struct apic apic_x2apic_cluster = {
16965+static struct apic apic_x2apic_cluster __read_only = {
16966
16967 .name = "cluster x2apic",
16968 .probe = x2apic_cluster_probe,
16969diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
16970index 562a76d..a003c0f 100644
16971--- a/arch/x86/kernel/apic/x2apic_phys.c
16972+++ b/arch/x86/kernel/apic/x2apic_phys.c
16973@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
16974 return apic == &apic_x2apic_phys;
16975 }
16976
16977-static struct apic apic_x2apic_phys = {
16978+static struct apic apic_x2apic_phys __read_only = {
16979
16980 .name = "physical x2apic",
16981 .probe = x2apic_phys_probe,
16982diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
16983index 794f6eb..67e1db2 100644
16984--- a/arch/x86/kernel/apic/x2apic_uv_x.c
16985+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
16986@@ -342,7 +342,7 @@ static int uv_probe(void)
16987 return apic == &apic_x2apic_uv_x;
16988 }
16989
16990-static struct apic __refdata apic_x2apic_uv_x = {
16991+static struct apic apic_x2apic_uv_x __read_only = {
16992
16993 .name = "UV large system",
16994 .probe = uv_probe,
16995diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
16996index 66b5faf..3442423 100644
16997--- a/arch/x86/kernel/apm_32.c
16998+++ b/arch/x86/kernel/apm_32.c
16999@@ -434,7 +434,7 @@ static DEFINE_MUTEX(apm_mutex);
17000 * This is for buggy BIOS's that refer to (real mode) segment 0x40
17001 * even though they are called in protected mode.
17002 */
17003-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
17004+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
17005 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
17006
17007 static const char driver_version[] = "1.16ac"; /* no spaces */
17008@@ -612,7 +612,10 @@ static long __apm_bios_call(void *_call)
17009 BUG_ON(cpu != 0);
17010 gdt = get_cpu_gdt_table(cpu);
17011 save_desc_40 = gdt[0x40 / 8];
17012+
17013+ pax_open_kernel();
17014 gdt[0x40 / 8] = bad_bios_desc;
17015+ pax_close_kernel();
17016
17017 apm_irq_save(flags);
17018 APM_DO_SAVE_SEGS;
17019@@ -621,7 +624,11 @@ static long __apm_bios_call(void *_call)
17020 &call->esi);
17021 APM_DO_RESTORE_SEGS;
17022 apm_irq_restore(flags);
17023+
17024+ pax_open_kernel();
17025 gdt[0x40 / 8] = save_desc_40;
17026+ pax_close_kernel();
17027+
17028 put_cpu();
17029
17030 return call->eax & 0xff;
17031@@ -688,7 +695,10 @@ static long __apm_bios_call_simple(void *_call)
17032 BUG_ON(cpu != 0);
17033 gdt = get_cpu_gdt_table(cpu);
17034 save_desc_40 = gdt[0x40 / 8];
17035+
17036+ pax_open_kernel();
17037 gdt[0x40 / 8] = bad_bios_desc;
17038+ pax_close_kernel();
17039
17040 apm_irq_save(flags);
17041 APM_DO_SAVE_SEGS;
17042@@ -696,7 +706,11 @@ static long __apm_bios_call_simple(void *_call)
17043 &call->eax);
17044 APM_DO_RESTORE_SEGS;
17045 apm_irq_restore(flags);
17046+
17047+ pax_open_kernel();
17048 gdt[0x40 / 8] = save_desc_40;
17049+ pax_close_kernel();
17050+
17051 put_cpu();
17052 return error;
17053 }
17054@@ -2363,12 +2377,15 @@ static int __init apm_init(void)
17055 * code to that CPU.
17056 */
17057 gdt = get_cpu_gdt_table(0);
17058+
17059+ pax_open_kernel();
17060 set_desc_base(&gdt[APM_CS >> 3],
17061 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
17062 set_desc_base(&gdt[APM_CS_16 >> 3],
17063 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
17064 set_desc_base(&gdt[APM_DS >> 3],
17065 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
17066+ pax_close_kernel();
17067
17068 proc_create("apm", 0, NULL, &apm_file_ops);
17069
17070diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
17071index 2861082..6d4718e 100644
17072--- a/arch/x86/kernel/asm-offsets.c
17073+++ b/arch/x86/kernel/asm-offsets.c
17074@@ -33,6 +33,8 @@ void common(void) {
17075 OFFSET(TI_status, thread_info, status);
17076 OFFSET(TI_addr_limit, thread_info, addr_limit);
17077 OFFSET(TI_preempt_count, thread_info, preempt_count);
17078+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
17079+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
17080
17081 BLANK();
17082 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
17083@@ -53,8 +55,26 @@ void common(void) {
17084 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
17085 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
17086 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
17087+
17088+#ifdef CONFIG_PAX_KERNEXEC
17089+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
17090 #endif
17091
17092+#ifdef CONFIG_PAX_MEMORY_UDEREF
17093+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
17094+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
17095+#ifdef CONFIG_X86_64
17096+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
17097+#endif
17098+#endif
17099+
17100+#endif
17101+
17102+ BLANK();
17103+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
17104+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
17105+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
17106+
17107 #ifdef CONFIG_XEN
17108 BLANK();
17109 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
17110diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
17111index 1b4754f..fbb4227 100644
17112--- a/arch/x86/kernel/asm-offsets_64.c
17113+++ b/arch/x86/kernel/asm-offsets_64.c
17114@@ -76,6 +76,7 @@ int main(void)
17115 BLANK();
17116 #undef ENTRY
17117
17118+ DEFINE(TSS_size, sizeof(struct tss_struct));
17119 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
17120 BLANK();
17121
17122diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
17123index a0e067d..9c7db16 100644
17124--- a/arch/x86/kernel/cpu/Makefile
17125+++ b/arch/x86/kernel/cpu/Makefile
17126@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
17127 CFLAGS_REMOVE_perf_event.o = -pg
17128 endif
17129
17130-# Make sure load_percpu_segment has no stackprotector
17131-nostackp := $(call cc-option, -fno-stack-protector)
17132-CFLAGS_common.o := $(nostackp)
17133-
17134 obj-y := intel_cacheinfo.o scattered.o topology.o
17135 obj-y += proc.o capflags.o powerflags.o common.o
17136 obj-y += vmware.o hypervisor.o mshyperv.o
17137diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
17138index fa96eb0..03efe73 100644
17139--- a/arch/x86/kernel/cpu/amd.c
17140+++ b/arch/x86/kernel/cpu/amd.c
17141@@ -737,7 +737,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
17142 unsigned int size)
17143 {
17144 /* AMD errata T13 (order #21922) */
17145- if ((c->x86 == 6)) {
17146+ if (c->x86 == 6) {
17147 /* Duron Rev A0 */
17148 if (c->x86_model == 3 && c->x86_mask == 0)
17149 size = 64;
17150diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
17151index d814772..c615653 100644
17152--- a/arch/x86/kernel/cpu/common.c
17153+++ b/arch/x86/kernel/cpu/common.c
17154@@ -88,60 +88,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
17155
17156 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
17157
17158-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
17159-#ifdef CONFIG_X86_64
17160- /*
17161- * We need valid kernel segments for data and code in long mode too
17162- * IRET will check the segment types kkeil 2000/10/28
17163- * Also sysret mandates a special GDT layout
17164- *
17165- * TLS descriptors are currently at a different place compared to i386.
17166- * Hopefully nobody expects them at a fixed place (Wine?)
17167- */
17168- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
17169- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
17170- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
17171- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
17172- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
17173- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
17174-#else
17175- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
17176- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17177- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
17178- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
17179- /*
17180- * Segments used for calling PnP BIOS have byte granularity.
17181- * They code segments and data segments have fixed 64k limits,
17182- * the transfer segment sizes are set at run time.
17183- */
17184- /* 32-bit code */
17185- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17186- /* 16-bit code */
17187- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17188- /* 16-bit data */
17189- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
17190- /* 16-bit data */
17191- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
17192- /* 16-bit data */
17193- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
17194- /*
17195- * The APM segments have byte granularity and their bases
17196- * are set at run time. All have 64k limits.
17197- */
17198- /* 32-bit code */
17199- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17200- /* 16-bit code */
17201- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17202- /* data */
17203- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
17204-
17205- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17206- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17207- GDT_STACK_CANARY_INIT
17208-#endif
17209-} };
17210-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
17211-
17212 static int __init x86_xsave_setup(char *s)
17213 {
17214 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
17215@@ -386,7 +332,7 @@ void switch_to_new_gdt(int cpu)
17216 {
17217 struct desc_ptr gdt_descr;
17218
17219- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
17220+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
17221 gdt_descr.size = GDT_SIZE - 1;
17222 load_gdt(&gdt_descr);
17223 /* Reload the per-cpu base */
17224@@ -882,6 +828,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
17225 /* Filter out anything that depends on CPUID levels we don't have */
17226 filter_cpuid_features(c, true);
17227
17228+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
17229+ setup_clear_cpu_cap(X86_FEATURE_SEP);
17230+#endif
17231+
17232 /* If the model name is still unset, do table lookup. */
17233 if (!c->x86_model_id[0]) {
17234 const char *p;
17235@@ -1065,10 +1015,12 @@ static __init int setup_disablecpuid(char *arg)
17236 }
17237 __setup("clearcpuid=", setup_disablecpuid);
17238
17239+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
17240+EXPORT_PER_CPU_SYMBOL(current_tinfo);
17241+
17242 #ifdef CONFIG_X86_64
17243 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
17244-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
17245- (unsigned long) nmi_idt_table };
17246+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
17247
17248 DEFINE_PER_CPU_FIRST(union irq_stack_union,
17249 irq_stack_union) __aligned(PAGE_SIZE);
17250@@ -1082,7 +1034,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
17251 EXPORT_PER_CPU_SYMBOL(current_task);
17252
17253 DEFINE_PER_CPU(unsigned long, kernel_stack) =
17254- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
17255+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
17256 EXPORT_PER_CPU_SYMBOL(kernel_stack);
17257
17258 DEFINE_PER_CPU(char *, irq_stack_ptr) =
17259@@ -1227,7 +1179,7 @@ void __cpuinit cpu_init(void)
17260 load_ucode_ap();
17261
17262 cpu = stack_smp_processor_id();
17263- t = &per_cpu(init_tss, cpu);
17264+ t = init_tss + cpu;
17265 oist = &per_cpu(orig_ist, cpu);
17266
17267 #ifdef CONFIG_NUMA
17268@@ -1253,7 +1205,7 @@ void __cpuinit cpu_init(void)
17269 switch_to_new_gdt(cpu);
17270 loadsegment(fs, 0);
17271
17272- load_idt((const struct desc_ptr *)&idt_descr);
17273+ load_idt(&idt_descr);
17274
17275 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
17276 syscall_init();
17277@@ -1262,7 +1214,6 @@ void __cpuinit cpu_init(void)
17278 wrmsrl(MSR_KERNEL_GS_BASE, 0);
17279 barrier();
17280
17281- x86_configure_nx();
17282 enable_x2apic();
17283
17284 /*
17285@@ -1314,7 +1265,7 @@ void __cpuinit cpu_init(void)
17286 {
17287 int cpu = smp_processor_id();
17288 struct task_struct *curr = current;
17289- struct tss_struct *t = &per_cpu(init_tss, cpu);
17290+ struct tss_struct *t = init_tss + cpu;
17291 struct thread_struct *thread = &curr->thread;
17292
17293 show_ucode_info_early();
17294diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
17295index 1905ce9..a7ac587 100644
17296--- a/arch/x86/kernel/cpu/intel.c
17297+++ b/arch/x86/kernel/cpu/intel.c
17298@@ -173,7 +173,7 @@ static void __cpuinit trap_init_f00f_bug(void)
17299 * Update the IDT descriptor and reload the IDT so that
17300 * it uses the read-only mapped virtual address.
17301 */
17302- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
17303+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
17304 load_idt(&idt_descr);
17305 }
17306 #endif
17307diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
17308index 7c6f7d5..8cac382 100644
17309--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
17310+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
17311@@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
17312 };
17313
17314 #ifdef CONFIG_AMD_NB
17315+static struct attribute *default_attrs_amd_nb[] = {
17316+ &type.attr,
17317+ &level.attr,
17318+ &coherency_line_size.attr,
17319+ &physical_line_partition.attr,
17320+ &ways_of_associativity.attr,
17321+ &number_of_sets.attr,
17322+ &size.attr,
17323+ &shared_cpu_map.attr,
17324+ &shared_cpu_list.attr,
17325+ NULL,
17326+ NULL,
17327+ NULL,
17328+ NULL
17329+};
17330+
17331 static struct attribute ** __cpuinit amd_l3_attrs(void)
17332 {
17333 static struct attribute **attrs;
17334@@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
17335
17336 n = ARRAY_SIZE(default_attrs);
17337
17338- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
17339- n += 2;
17340-
17341- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
17342- n += 1;
17343-
17344- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
17345- if (attrs == NULL)
17346- return attrs = default_attrs;
17347-
17348- for (n = 0; default_attrs[n]; n++)
17349- attrs[n] = default_attrs[n];
17350+ attrs = default_attrs_amd_nb;
17351
17352 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
17353 attrs[n++] = &cache_disable_0.attr;
17354@@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
17355 .default_attrs = default_attrs,
17356 };
17357
17358+#ifdef CONFIG_AMD_NB
17359+static struct kobj_type ktype_cache_amd_nb = {
17360+ .sysfs_ops = &sysfs_ops,
17361+ .default_attrs = default_attrs_amd_nb,
17362+};
17363+#endif
17364+
17365 static struct kobj_type ktype_percpu_entry = {
17366 .sysfs_ops = &sysfs_ops,
17367 };
17368@@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
17369 return retval;
17370 }
17371
17372+#ifdef CONFIG_AMD_NB
17373+ amd_l3_attrs();
17374+#endif
17375+
17376 for (i = 0; i < num_cache_leaves; i++) {
17377+ struct kobj_type *ktype;
17378+
17379 this_object = INDEX_KOBJECT_PTR(cpu, i);
17380 this_object->cpu = cpu;
17381 this_object->index = i;
17382
17383 this_leaf = CPUID4_INFO_IDX(cpu, i);
17384
17385- ktype_cache.default_attrs = default_attrs;
17386+ ktype = &ktype_cache;
17387 #ifdef CONFIG_AMD_NB
17388 if (this_leaf->base.nb)
17389- ktype_cache.default_attrs = amd_l3_attrs();
17390+ ktype = &ktype_cache_amd_nb;
17391 #endif
17392 retval = kobject_init_and_add(&(this_object->kobj),
17393- &ktype_cache,
17394+ ktype,
17395 per_cpu(ici_cache_kobject, cpu),
17396 "index%1lu", i);
17397 if (unlikely(retval)) {
17398@@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
17399 return NOTIFY_OK;
17400 }
17401
17402-static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
17403+static struct notifier_block cacheinfo_cpu_notifier = {
17404 .notifier_call = cacheinfo_cpu_callback,
17405 };
17406
17407diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
17408index 7bc1263..ce2cbfb 100644
17409--- a/arch/x86/kernel/cpu/mcheck/mce.c
17410+++ b/arch/x86/kernel/cpu/mcheck/mce.c
17411@@ -45,6 +45,7 @@
17412 #include <asm/processor.h>
17413 #include <asm/mce.h>
17414 #include <asm/msr.h>
17415+#include <asm/local.h>
17416
17417 #include "mce-internal.h"
17418
17419@@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
17420 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
17421 m->cs, m->ip);
17422
17423- if (m->cs == __KERNEL_CS)
17424+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
17425 print_symbol("{%s}", m->ip);
17426 pr_cont("\n");
17427 }
17428@@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
17429
17430 #define PANIC_TIMEOUT 5 /* 5 seconds */
17431
17432-static atomic_t mce_paniced;
17433+static atomic_unchecked_t mce_paniced;
17434
17435 static int fake_panic;
17436-static atomic_t mce_fake_paniced;
17437+static atomic_unchecked_t mce_fake_paniced;
17438
17439 /* Panic in progress. Enable interrupts and wait for final IPI */
17440 static void wait_for_panic(void)
17441@@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17442 /*
17443 * Make sure only one CPU runs in machine check panic
17444 */
17445- if (atomic_inc_return(&mce_paniced) > 1)
17446+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
17447 wait_for_panic();
17448 barrier();
17449
17450@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17451 console_verbose();
17452 } else {
17453 /* Don't log too much for fake panic */
17454- if (atomic_inc_return(&mce_fake_paniced) > 1)
17455+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
17456 return;
17457 }
17458 /* First print corrected ones that are still unlogged */
17459@@ -683,7 +684,7 @@ static int mce_timed_out(u64 *t)
17460 * might have been modified by someone else.
17461 */
17462 rmb();
17463- if (atomic_read(&mce_paniced))
17464+ if (atomic_read_unchecked(&mce_paniced))
17465 wait_for_panic();
17466 if (!mca_cfg.monarch_timeout)
17467 goto out;
17468@@ -1654,7 +1655,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
17469 }
17470
17471 /* Call the installed machine check handler for this CPU setup. */
17472-void (*machine_check_vector)(struct pt_regs *, long error_code) =
17473+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
17474 unexpected_machine_check;
17475
17476 /*
17477@@ -1677,7 +1678,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17478 return;
17479 }
17480
17481+ pax_open_kernel();
17482 machine_check_vector = do_machine_check;
17483+ pax_close_kernel();
17484
17485 __mcheck_cpu_init_generic();
17486 __mcheck_cpu_init_vendor(c);
17487@@ -1691,7 +1694,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17488 */
17489
17490 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
17491-static int mce_chrdev_open_count; /* #times opened */
17492+static local_t mce_chrdev_open_count; /* #times opened */
17493 static int mce_chrdev_open_exclu; /* already open exclusive? */
17494
17495 static int mce_chrdev_open(struct inode *inode, struct file *file)
17496@@ -1699,7 +1702,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17497 spin_lock(&mce_chrdev_state_lock);
17498
17499 if (mce_chrdev_open_exclu ||
17500- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
17501+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
17502 spin_unlock(&mce_chrdev_state_lock);
17503
17504 return -EBUSY;
17505@@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17506
17507 if (file->f_flags & O_EXCL)
17508 mce_chrdev_open_exclu = 1;
17509- mce_chrdev_open_count++;
17510+ local_inc(&mce_chrdev_open_count);
17511
17512 spin_unlock(&mce_chrdev_state_lock);
17513
17514@@ -1718,7 +1721,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
17515 {
17516 spin_lock(&mce_chrdev_state_lock);
17517
17518- mce_chrdev_open_count--;
17519+ local_dec(&mce_chrdev_open_count);
17520 mce_chrdev_open_exclu = 0;
17521
17522 spin_unlock(&mce_chrdev_state_lock);
17523@@ -2364,7 +2367,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
17524 return NOTIFY_OK;
17525 }
17526
17527-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
17528+static struct notifier_block mce_cpu_notifier = {
17529 .notifier_call = mce_cpu_callback,
17530 };
17531
17532@@ -2374,7 +2377,7 @@ static __init void mce_init_banks(void)
17533
17534 for (i = 0; i < mca_cfg.banks; i++) {
17535 struct mce_bank *b = &mce_banks[i];
17536- struct device_attribute *a = &b->attr;
17537+ device_attribute_no_const *a = &b->attr;
17538
17539 sysfs_attr_init(&a->attr);
17540 a->attr.name = b->attrname;
17541@@ -2442,7 +2445,7 @@ struct dentry *mce_get_debugfs_dir(void)
17542 static void mce_reset(void)
17543 {
17544 cpu_missing = 0;
17545- atomic_set(&mce_fake_paniced, 0);
17546+ atomic_set_unchecked(&mce_fake_paniced, 0);
17547 atomic_set(&mce_executing, 0);
17548 atomic_set(&mce_callin, 0);
17549 atomic_set(&global_nwo, 0);
17550diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
17551index 1c044b1..37a2a43 100644
17552--- a/arch/x86/kernel/cpu/mcheck/p5.c
17553+++ b/arch/x86/kernel/cpu/mcheck/p5.c
17554@@ -11,6 +11,7 @@
17555 #include <asm/processor.h>
17556 #include <asm/mce.h>
17557 #include <asm/msr.h>
17558+#include <asm/pgtable.h>
17559
17560 /* By default disabled */
17561 int mce_p5_enabled __read_mostly;
17562@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
17563 if (!cpu_has(c, X86_FEATURE_MCE))
17564 return;
17565
17566+ pax_open_kernel();
17567 machine_check_vector = pentium_machine_check;
17568+ pax_close_kernel();
17569 /* Make sure the vector pointer is visible before we enable MCEs: */
17570 wmb();
17571
17572diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17573index 47a1870..8c019a7 100644
17574--- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
17575+++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17576@@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
17577 return notifier_from_errno(err);
17578 }
17579
17580-static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
17581+static struct notifier_block thermal_throttle_cpu_notifier =
17582 {
17583 .notifier_call = thermal_throttle_cpu_callback,
17584 };
17585diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
17586index e9a701a..35317d6 100644
17587--- a/arch/x86/kernel/cpu/mcheck/winchip.c
17588+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
17589@@ -10,6 +10,7 @@
17590 #include <asm/processor.h>
17591 #include <asm/mce.h>
17592 #include <asm/msr.h>
17593+#include <asm/pgtable.h>
17594
17595 /* Machine check handler for WinChip C6: */
17596 static void winchip_machine_check(struct pt_regs *regs, long error_code)
17597@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
17598 {
17599 u32 lo, hi;
17600
17601+ pax_open_kernel();
17602 machine_check_vector = winchip_machine_check;
17603+ pax_close_kernel();
17604 /* Make sure the vector pointer is visible before we enable MCEs: */
17605 wmb();
17606
17607diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
17608index 726bf96..81f0526 100644
17609--- a/arch/x86/kernel/cpu/mtrr/main.c
17610+++ b/arch/x86/kernel/cpu/mtrr/main.c
17611@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
17612 u64 size_or_mask, size_and_mask;
17613 static bool mtrr_aps_delayed_init;
17614
17615-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
17616+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
17617
17618 const struct mtrr_ops *mtrr_if;
17619
17620diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
17621index df5e41f..816c719 100644
17622--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
17623+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
17624@@ -25,7 +25,7 @@ struct mtrr_ops {
17625 int (*validate_add_page)(unsigned long base, unsigned long size,
17626 unsigned int type);
17627 int (*have_wrcomb)(void);
17628-};
17629+} __do_const;
17630
17631 extern int generic_get_free_region(unsigned long base, unsigned long size,
17632 int replace_reg);
17633diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
17634index bf0f01a..9adfee1 100644
17635--- a/arch/x86/kernel/cpu/perf_event.c
17636+++ b/arch/x86/kernel/cpu/perf_event.c
17637@@ -1305,7 +1305,7 @@ static void __init pmu_check_apic(void)
17638 pr_info("no hardware sampling interrupt available.\n");
17639 }
17640
17641-static struct attribute_group x86_pmu_format_group = {
17642+static attribute_group_no_const x86_pmu_format_group = {
17643 .name = "format",
17644 .attrs = NULL,
17645 };
17646@@ -1374,7 +1374,7 @@ static struct attribute *events_attr[] = {
17647 NULL,
17648 };
17649
17650-static struct attribute_group x86_pmu_events_group = {
17651+static attribute_group_no_const x86_pmu_events_group = {
17652 .name = "events",
17653 .attrs = events_attr,
17654 };
17655@@ -1873,7 +1873,7 @@ static unsigned long get_segment_base(unsigned int segment)
17656 if (idx > GDT_ENTRIES)
17657 return 0;
17658
17659- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
17660+ desc = get_cpu_gdt_table(smp_processor_id());
17661 }
17662
17663 return get_desc_base(desc + idx);
17664@@ -1963,7 +1963,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
17665 break;
17666
17667 perf_callchain_store(entry, frame.return_address);
17668- fp = frame.next_frame;
17669+ fp = (const void __force_user *)frame.next_frame;
17670 }
17671 }
17672
17673diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
17674index 4a0a462..be3b204 100644
17675--- a/arch/x86/kernel/cpu/perf_event_intel.c
17676+++ b/arch/x86/kernel/cpu/perf_event_intel.c
17677@@ -1994,10 +1994,10 @@ __init int intel_pmu_init(void)
17678 * v2 and above have a perf capabilities MSR
17679 */
17680 if (version > 1) {
17681- u64 capabilities;
17682+ u64 capabilities = x86_pmu.intel_cap.capabilities;
17683
17684- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
17685- x86_pmu.intel_cap.capabilities = capabilities;
17686+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
17687+ x86_pmu.intel_cap.capabilities = capabilities;
17688 }
17689
17690 intel_ds_init();
17691diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17692index 3e091f0..d2dc8d6 100644
17693--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17694+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17695@@ -2428,7 +2428,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
17696 static int __init uncore_type_init(struct intel_uncore_type *type)
17697 {
17698 struct intel_uncore_pmu *pmus;
17699- struct attribute_group *attr_group;
17700+ attribute_group_no_const *attr_group;
17701 struct attribute **attrs;
17702 int i, j;
17703
17704@@ -2826,7 +2826,7 @@ static int
17705 return NOTIFY_OK;
17706 }
17707
17708-static struct notifier_block uncore_cpu_nb __cpuinitdata = {
17709+static struct notifier_block uncore_cpu_nb = {
17710 .notifier_call = uncore_cpu_notifier,
17711 /*
17712 * to migrate uncore events, our notifier should be executed
17713diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17714index e68a455..975a932 100644
17715--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17716+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17717@@ -428,7 +428,7 @@ struct intel_uncore_box {
17718 struct uncore_event_desc {
17719 struct kobj_attribute attr;
17720 const char *config;
17721-};
17722+} __do_const;
17723
17724 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
17725 { \
17726diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
17727index 1e4dbcf..b9a34c2 100644
17728--- a/arch/x86/kernel/cpuid.c
17729+++ b/arch/x86/kernel/cpuid.c
17730@@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
17731 return notifier_from_errno(err);
17732 }
17733
17734-static struct notifier_block __refdata cpuid_class_cpu_notifier =
17735+static struct notifier_block cpuid_class_cpu_notifier =
17736 {
17737 .notifier_call = cpuid_class_cpu_callback,
17738 };
17739diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
17740index 74467fe..18793d5 100644
17741--- a/arch/x86/kernel/crash.c
17742+++ b/arch/x86/kernel/crash.c
17743@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
17744 {
17745 #ifdef CONFIG_X86_32
17746 struct pt_regs fixed_regs;
17747-#endif
17748
17749-#ifdef CONFIG_X86_32
17750- if (!user_mode_vm(regs)) {
17751+ if (!user_mode(regs)) {
17752 crash_fixup_ss_esp(&fixed_regs, regs);
17753 regs = &fixed_regs;
17754 }
17755diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
17756index afa64ad..dce67dd 100644
17757--- a/arch/x86/kernel/crash_dump_64.c
17758+++ b/arch/x86/kernel/crash_dump_64.c
17759@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
17760 return -ENOMEM;
17761
17762 if (userbuf) {
17763- if (copy_to_user(buf, vaddr + offset, csize)) {
17764+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
17765 iounmap(vaddr);
17766 return -EFAULT;
17767 }
17768diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
17769index 37250fe..bf2ec74 100644
17770--- a/arch/x86/kernel/doublefault_32.c
17771+++ b/arch/x86/kernel/doublefault_32.c
17772@@ -11,7 +11,7 @@
17773
17774 #define DOUBLEFAULT_STACKSIZE (1024)
17775 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
17776-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
17777+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
17778
17779 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
17780
17781@@ -21,7 +21,7 @@ static void doublefault_fn(void)
17782 unsigned long gdt, tss;
17783
17784 store_gdt(&gdt_desc);
17785- gdt = gdt_desc.address;
17786+ gdt = (unsigned long)gdt_desc.address;
17787
17788 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
17789
17790@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
17791 /* 0x2 bit is always set */
17792 .flags = X86_EFLAGS_SF | 0x2,
17793 .sp = STACK_START,
17794- .es = __USER_DS,
17795+ .es = __KERNEL_DS,
17796 .cs = __KERNEL_CS,
17797 .ss = __KERNEL_DS,
17798- .ds = __USER_DS,
17799+ .ds = __KERNEL_DS,
17800 .fs = __KERNEL_PERCPU,
17801
17802 .__cr3 = __pa_nodebug(swapper_pg_dir),
17803diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
17804index c8797d5..c605e53 100644
17805--- a/arch/x86/kernel/dumpstack.c
17806+++ b/arch/x86/kernel/dumpstack.c
17807@@ -2,6 +2,9 @@
17808 * Copyright (C) 1991, 1992 Linus Torvalds
17809 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
17810 */
17811+#ifdef CONFIG_GRKERNSEC_HIDESYM
17812+#define __INCLUDED_BY_HIDESYM 1
17813+#endif
17814 #include <linux/kallsyms.h>
17815 #include <linux/kprobes.h>
17816 #include <linux/uaccess.h>
17817@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
17818 static void
17819 print_ftrace_graph_addr(unsigned long addr, void *data,
17820 const struct stacktrace_ops *ops,
17821- struct thread_info *tinfo, int *graph)
17822+ struct task_struct *task, int *graph)
17823 {
17824- struct task_struct *task;
17825 unsigned long ret_addr;
17826 int index;
17827
17828 if (addr != (unsigned long)return_to_handler)
17829 return;
17830
17831- task = tinfo->task;
17832 index = task->curr_ret_stack;
17833
17834 if (!task->ret_stack || index < *graph)
17835@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17836 static inline void
17837 print_ftrace_graph_addr(unsigned long addr, void *data,
17838 const struct stacktrace_ops *ops,
17839- struct thread_info *tinfo, int *graph)
17840+ struct task_struct *task, int *graph)
17841 { }
17842 #endif
17843
17844@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17845 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
17846 */
17847
17848-static inline int valid_stack_ptr(struct thread_info *tinfo,
17849- void *p, unsigned int size, void *end)
17850+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
17851 {
17852- void *t = tinfo;
17853 if (end) {
17854 if (p < end && p >= (end-THREAD_SIZE))
17855 return 1;
17856@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
17857 }
17858
17859 unsigned long
17860-print_context_stack(struct thread_info *tinfo,
17861+print_context_stack(struct task_struct *task, void *stack_start,
17862 unsigned long *stack, unsigned long bp,
17863 const struct stacktrace_ops *ops, void *data,
17864 unsigned long *end, int *graph)
17865 {
17866 struct stack_frame *frame = (struct stack_frame *)bp;
17867
17868- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
17869+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
17870 unsigned long addr;
17871
17872 addr = *stack;
17873@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
17874 } else {
17875 ops->address(data, addr, 0);
17876 }
17877- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17878+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17879 }
17880 stack++;
17881 }
17882@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
17883 EXPORT_SYMBOL_GPL(print_context_stack);
17884
17885 unsigned long
17886-print_context_stack_bp(struct thread_info *tinfo,
17887+print_context_stack_bp(struct task_struct *task, void *stack_start,
17888 unsigned long *stack, unsigned long bp,
17889 const struct stacktrace_ops *ops, void *data,
17890 unsigned long *end, int *graph)
17891@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17892 struct stack_frame *frame = (struct stack_frame *)bp;
17893 unsigned long *ret_addr = &frame->return_address;
17894
17895- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
17896+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
17897 unsigned long addr = *ret_addr;
17898
17899 if (!__kernel_text_address(addr))
17900@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17901 ops->address(data, addr, 1);
17902 frame = frame->next_frame;
17903 ret_addr = &frame->return_address;
17904- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17905+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17906 }
17907
17908 return (unsigned long)frame;
17909@@ -189,7 +188,7 @@ void dump_stack(void)
17910
17911 bp = stack_frame(current, NULL);
17912 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
17913- current->pid, current->comm, print_tainted(),
17914+ task_pid_nr(current), current->comm, print_tainted(),
17915 init_utsname()->release,
17916 (int)strcspn(init_utsname()->version, " "),
17917 init_utsname()->version);
17918@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
17919 }
17920 EXPORT_SYMBOL_GPL(oops_begin);
17921
17922+extern void gr_handle_kernel_exploit(void);
17923+
17924 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17925 {
17926 if (regs && kexec_should_crash(current))
17927@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17928 panic("Fatal exception in interrupt");
17929 if (panic_on_oops)
17930 panic("Fatal exception");
17931- do_exit(signr);
17932+
17933+ gr_handle_kernel_exploit();
17934+
17935+ do_group_exit(signr);
17936 }
17937
17938 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17939@@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17940 print_modules();
17941 show_regs(regs);
17942 #ifdef CONFIG_X86_32
17943- if (user_mode_vm(regs)) {
17944+ if (user_mode(regs)) {
17945 sp = regs->sp;
17946 ss = regs->ss & 0xffff;
17947 } else {
17948@@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
17949 unsigned long flags = oops_begin();
17950 int sig = SIGSEGV;
17951
17952- if (!user_mode_vm(regs))
17953+ if (!user_mode(regs))
17954 report_bug(regs->ip, regs);
17955
17956 if (__die(str, regs, err))
17957diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
17958index 1038a41..db2c12b 100644
17959--- a/arch/x86/kernel/dumpstack_32.c
17960+++ b/arch/x86/kernel/dumpstack_32.c
17961@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17962 bp = stack_frame(task, regs);
17963
17964 for (;;) {
17965- struct thread_info *context;
17966+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17967
17968- context = (struct thread_info *)
17969- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
17970- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
17971+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17972
17973- stack = (unsigned long *)context->previous_esp;
17974- if (!stack)
17975+ if (stack_start == task_stack_page(task))
17976 break;
17977+ stack = *(unsigned long **)stack_start;
17978 if (ops->stack(data, "IRQ") < 0)
17979 break;
17980 touch_nmi_watchdog();
17981@@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
17982 {
17983 int i;
17984
17985- __show_regs(regs, !user_mode_vm(regs));
17986+ __show_regs(regs, !user_mode(regs));
17987
17988 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
17989 TASK_COMM_LEN, current->comm, task_pid_nr(current),
17990@@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
17991 * When in-kernel, we also print out the stack and code at the
17992 * time of the fault..
17993 */
17994- if (!user_mode_vm(regs)) {
17995+ if (!user_mode(regs)) {
17996 unsigned int code_prologue = code_bytes * 43 / 64;
17997 unsigned int code_len = code_bytes;
17998 unsigned char c;
17999 u8 *ip;
18000+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
18001
18002 pr_emerg("Stack:\n");
18003 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
18004
18005 pr_emerg("Code:");
18006
18007- ip = (u8 *)regs->ip - code_prologue;
18008+ ip = (u8 *)regs->ip - code_prologue + cs_base;
18009 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
18010 /* try starting at IP */
18011- ip = (u8 *)regs->ip;
18012+ ip = (u8 *)regs->ip + cs_base;
18013 code_len = code_len - code_prologue + 1;
18014 }
18015 for (i = 0; i < code_len; i++, ip++) {
18016@@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
18017 pr_cont(" Bad EIP value.");
18018 break;
18019 }
18020- if (ip == (u8 *)regs->ip)
18021+ if (ip == (u8 *)regs->ip + cs_base)
18022 pr_cont(" <%02x>", c);
18023 else
18024 pr_cont(" %02x", c);
18025@@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
18026 {
18027 unsigned short ud2;
18028
18029+ ip = ktla_ktva(ip);
18030 if (ip < PAGE_OFFSET)
18031 return 0;
18032 if (probe_kernel_address((unsigned short *)ip, ud2))
18033@@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
18034
18035 return ud2 == 0x0b0f;
18036 }
18037+
18038+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18039+void pax_check_alloca(unsigned long size)
18040+{
18041+ unsigned long sp = (unsigned long)&sp, stack_left;
18042+
18043+ /* all kernel stacks are of the same size */
18044+ stack_left = sp & (THREAD_SIZE - 1);
18045+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18046+}
18047+EXPORT_SYMBOL(pax_check_alloca);
18048+#endif
18049diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
18050index b653675..51cc8c0 100644
18051--- a/arch/x86/kernel/dumpstack_64.c
18052+++ b/arch/x86/kernel/dumpstack_64.c
18053@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18054 unsigned long *irq_stack_end =
18055 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
18056 unsigned used = 0;
18057- struct thread_info *tinfo;
18058 int graph = 0;
18059 unsigned long dummy;
18060+ void *stack_start;
18061
18062 if (!task)
18063 task = current;
18064@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18065 * current stack address. If the stacks consist of nested
18066 * exceptions
18067 */
18068- tinfo = task_thread_info(task);
18069 for (;;) {
18070 char *id;
18071 unsigned long *estack_end;
18072+
18073 estack_end = in_exception_stack(cpu, (unsigned long)stack,
18074 &used, &id);
18075
18076@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18077 if (ops->stack(data, id) < 0)
18078 break;
18079
18080- bp = ops->walk_stack(tinfo, stack, bp, ops,
18081+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
18082 data, estack_end, &graph);
18083 ops->stack(data, "<EOE>");
18084 /*
18085@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18086 * second-to-last pointer (index -2 to end) in the
18087 * exception stack:
18088 */
18089+ if ((u16)estack_end[-1] != __KERNEL_DS)
18090+ goto out;
18091 stack = (unsigned long *) estack_end[-2];
18092 continue;
18093 }
18094@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18095 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
18096 if (ops->stack(data, "IRQ") < 0)
18097 break;
18098- bp = ops->walk_stack(tinfo, stack, bp,
18099+ bp = ops->walk_stack(task, irq_stack, stack, bp,
18100 ops, data, irq_stack_end, &graph);
18101 /*
18102 * We link to the next stack (which would be
18103@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18104 /*
18105 * This handles the process stack:
18106 */
18107- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
18108+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
18109+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
18110+out:
18111 put_cpu();
18112 }
18113 EXPORT_SYMBOL(dump_trace);
18114@@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
18115 {
18116 int i;
18117 unsigned long sp;
18118- const int cpu = smp_processor_id();
18119+ const int cpu = raw_smp_processor_id();
18120 struct task_struct *cur = current;
18121
18122 sp = regs->sp;
18123@@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
18124
18125 return ud2 == 0x0b0f;
18126 }
18127+
18128+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18129+void pax_check_alloca(unsigned long size)
18130+{
18131+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
18132+ unsigned cpu, used;
18133+ char *id;
18134+
18135+ /* check the process stack first */
18136+ stack_start = (unsigned long)task_stack_page(current);
18137+ stack_end = stack_start + THREAD_SIZE;
18138+ if (likely(stack_start <= sp && sp < stack_end)) {
18139+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
18140+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18141+ return;
18142+ }
18143+
18144+ cpu = get_cpu();
18145+
18146+ /* check the irq stacks */
18147+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
18148+ stack_start = stack_end - IRQ_STACK_SIZE;
18149+ if (stack_start <= sp && sp < stack_end) {
18150+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
18151+ put_cpu();
18152+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18153+ return;
18154+ }
18155+
18156+ /* check the exception stacks */
18157+ used = 0;
18158+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
18159+ stack_start = stack_end - EXCEPTION_STKSZ;
18160+ if (stack_end && stack_start <= sp && sp < stack_end) {
18161+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
18162+ put_cpu();
18163+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18164+ return;
18165+ }
18166+
18167+ put_cpu();
18168+
18169+ /* unknown stack */
18170+ BUG();
18171+}
18172+EXPORT_SYMBOL(pax_check_alloca);
18173+#endif
18174diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
18175index 9b9f18b..9fcaa04 100644
18176--- a/arch/x86/kernel/early_printk.c
18177+++ b/arch/x86/kernel/early_printk.c
18178@@ -7,6 +7,7 @@
18179 #include <linux/pci_regs.h>
18180 #include <linux/pci_ids.h>
18181 #include <linux/errno.h>
18182+#include <linux/sched.h>
18183 #include <asm/io.h>
18184 #include <asm/processor.h>
18185 #include <asm/fcntl.h>
18186diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
18187index 8f3e2de..934870f 100644
18188--- a/arch/x86/kernel/entry_32.S
18189+++ b/arch/x86/kernel/entry_32.S
18190@@ -177,13 +177,153 @@
18191 /*CFI_REL_OFFSET gs, PT_GS*/
18192 .endm
18193 .macro SET_KERNEL_GS reg
18194+
18195+#ifdef CONFIG_CC_STACKPROTECTOR
18196 movl $(__KERNEL_STACK_CANARY), \reg
18197+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
18198+ movl $(__USER_DS), \reg
18199+#else
18200+ xorl \reg, \reg
18201+#endif
18202+
18203 movl \reg, %gs
18204 .endm
18205
18206 #endif /* CONFIG_X86_32_LAZY_GS */
18207
18208-.macro SAVE_ALL
18209+.macro pax_enter_kernel
18210+#ifdef CONFIG_PAX_KERNEXEC
18211+ call pax_enter_kernel
18212+#endif
18213+.endm
18214+
18215+.macro pax_exit_kernel
18216+#ifdef CONFIG_PAX_KERNEXEC
18217+ call pax_exit_kernel
18218+#endif
18219+.endm
18220+
18221+#ifdef CONFIG_PAX_KERNEXEC
18222+ENTRY(pax_enter_kernel)
18223+#ifdef CONFIG_PARAVIRT
18224+ pushl %eax
18225+ pushl %ecx
18226+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
18227+ mov %eax, %esi
18228+#else
18229+ mov %cr0, %esi
18230+#endif
18231+ bts $16, %esi
18232+ jnc 1f
18233+ mov %cs, %esi
18234+ cmp $__KERNEL_CS, %esi
18235+ jz 3f
18236+ ljmp $__KERNEL_CS, $3f
18237+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
18238+2:
18239+#ifdef CONFIG_PARAVIRT
18240+ mov %esi, %eax
18241+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
18242+#else
18243+ mov %esi, %cr0
18244+#endif
18245+3:
18246+#ifdef CONFIG_PARAVIRT
18247+ popl %ecx
18248+ popl %eax
18249+#endif
18250+ ret
18251+ENDPROC(pax_enter_kernel)
18252+
18253+ENTRY(pax_exit_kernel)
18254+#ifdef CONFIG_PARAVIRT
18255+ pushl %eax
18256+ pushl %ecx
18257+#endif
18258+ mov %cs, %esi
18259+ cmp $__KERNEXEC_KERNEL_CS, %esi
18260+ jnz 2f
18261+#ifdef CONFIG_PARAVIRT
18262+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
18263+ mov %eax, %esi
18264+#else
18265+ mov %cr0, %esi
18266+#endif
18267+ btr $16, %esi
18268+ ljmp $__KERNEL_CS, $1f
18269+1:
18270+#ifdef CONFIG_PARAVIRT
18271+ mov %esi, %eax
18272+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
18273+#else
18274+ mov %esi, %cr0
18275+#endif
18276+2:
18277+#ifdef CONFIG_PARAVIRT
18278+ popl %ecx
18279+ popl %eax
18280+#endif
18281+ ret
18282+ENDPROC(pax_exit_kernel)
18283+#endif
18284+
18285+.macro pax_erase_kstack
18286+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18287+ call pax_erase_kstack
18288+#endif
18289+.endm
18290+
18291+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18292+/*
18293+ * ebp: thread_info
18294+ */
18295+ENTRY(pax_erase_kstack)
18296+ pushl %edi
18297+ pushl %ecx
18298+ pushl %eax
18299+
18300+ mov TI_lowest_stack(%ebp), %edi
18301+ mov $-0xBEEF, %eax
18302+ std
18303+
18304+1: mov %edi, %ecx
18305+ and $THREAD_SIZE_asm - 1, %ecx
18306+ shr $2, %ecx
18307+ repne scasl
18308+ jecxz 2f
18309+
18310+ cmp $2*16, %ecx
18311+ jc 2f
18312+
18313+ mov $2*16, %ecx
18314+ repe scasl
18315+ jecxz 2f
18316+ jne 1b
18317+
18318+2: cld
18319+ mov %esp, %ecx
18320+ sub %edi, %ecx
18321+
18322+ cmp $THREAD_SIZE_asm, %ecx
18323+ jb 3f
18324+ ud2
18325+3:
18326+
18327+ shr $2, %ecx
18328+ rep stosl
18329+
18330+ mov TI_task_thread_sp0(%ebp), %edi
18331+ sub $128, %edi
18332+ mov %edi, TI_lowest_stack(%ebp)
18333+
18334+ popl %eax
18335+ popl %ecx
18336+ popl %edi
18337+ ret
18338+ENDPROC(pax_erase_kstack)
18339+#endif
18340+
18341+.macro __SAVE_ALL _DS
18342 cld
18343 PUSH_GS
18344 pushl_cfi %fs
18345@@ -206,7 +346,7 @@
18346 CFI_REL_OFFSET ecx, 0
18347 pushl_cfi %ebx
18348 CFI_REL_OFFSET ebx, 0
18349- movl $(__USER_DS), %edx
18350+ movl $\_DS, %edx
18351 movl %edx, %ds
18352 movl %edx, %es
18353 movl $(__KERNEL_PERCPU), %edx
18354@@ -214,6 +354,15 @@
18355 SET_KERNEL_GS %edx
18356 .endm
18357
18358+.macro SAVE_ALL
18359+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18360+ __SAVE_ALL __KERNEL_DS
18361+ pax_enter_kernel
18362+#else
18363+ __SAVE_ALL __USER_DS
18364+#endif
18365+.endm
18366+
18367 .macro RESTORE_INT_REGS
18368 popl_cfi %ebx
18369 CFI_RESTORE ebx
18370@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
18371 popfl_cfi
18372 jmp syscall_exit
18373 CFI_ENDPROC
18374-END(ret_from_fork)
18375+ENDPROC(ret_from_fork)
18376
18377 ENTRY(ret_from_kernel_thread)
18378 CFI_STARTPROC
18379@@ -344,7 +493,15 @@ ret_from_intr:
18380 andl $SEGMENT_RPL_MASK, %eax
18381 #endif
18382 cmpl $USER_RPL, %eax
18383+
18384+#ifdef CONFIG_PAX_KERNEXEC
18385+ jae resume_userspace
18386+
18387+ pax_exit_kernel
18388+ jmp resume_kernel
18389+#else
18390 jb resume_kernel # not returning to v8086 or userspace
18391+#endif
18392
18393 ENTRY(resume_userspace)
18394 LOCKDEP_SYS_EXIT
18395@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
18396 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
18397 # int/exception return?
18398 jne work_pending
18399- jmp restore_all
18400-END(ret_from_exception)
18401+ jmp restore_all_pax
18402+ENDPROC(ret_from_exception)
18403
18404 #ifdef CONFIG_PREEMPT
18405 ENTRY(resume_kernel)
18406@@ -372,7 +529,7 @@ need_resched:
18407 jz restore_all
18408 call preempt_schedule_irq
18409 jmp need_resched
18410-END(resume_kernel)
18411+ENDPROC(resume_kernel)
18412 #endif
18413 CFI_ENDPROC
18414 /*
18415@@ -406,30 +563,45 @@ sysenter_past_esp:
18416 /*CFI_REL_OFFSET cs, 0*/
18417 /*
18418 * Push current_thread_info()->sysenter_return to the stack.
18419- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
18420- * pushed above; +8 corresponds to copy_thread's esp0 setting.
18421 */
18422- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
18423+ pushl_cfi $0
18424 CFI_REL_OFFSET eip, 0
18425
18426 pushl_cfi %eax
18427 SAVE_ALL
18428+ GET_THREAD_INFO(%ebp)
18429+ movl TI_sysenter_return(%ebp),%ebp
18430+ movl %ebp,PT_EIP(%esp)
18431 ENABLE_INTERRUPTS(CLBR_NONE)
18432
18433 /*
18434 * Load the potential sixth argument from user stack.
18435 * Careful about security.
18436 */
18437+ movl PT_OLDESP(%esp),%ebp
18438+
18439+#ifdef CONFIG_PAX_MEMORY_UDEREF
18440+ mov PT_OLDSS(%esp),%ds
18441+1: movl %ds:(%ebp),%ebp
18442+ push %ss
18443+ pop %ds
18444+#else
18445 cmpl $__PAGE_OFFSET-3,%ebp
18446 jae syscall_fault
18447 ASM_STAC
18448 1: movl (%ebp),%ebp
18449 ASM_CLAC
18450+#endif
18451+
18452 movl %ebp,PT_EBP(%esp)
18453 _ASM_EXTABLE(1b,syscall_fault)
18454
18455 GET_THREAD_INFO(%ebp)
18456
18457+#ifdef CONFIG_PAX_RANDKSTACK
18458+ pax_erase_kstack
18459+#endif
18460+
18461 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18462 jnz sysenter_audit
18463 sysenter_do_call:
18464@@ -444,12 +616,24 @@ sysenter_do_call:
18465 testl $_TIF_ALLWORK_MASK, %ecx
18466 jne sysexit_audit
18467 sysenter_exit:
18468+
18469+#ifdef CONFIG_PAX_RANDKSTACK
18470+ pushl_cfi %eax
18471+ movl %esp, %eax
18472+ call pax_randomize_kstack
18473+ popl_cfi %eax
18474+#endif
18475+
18476+ pax_erase_kstack
18477+
18478 /* if something modifies registers it must also disable sysexit */
18479 movl PT_EIP(%esp), %edx
18480 movl PT_OLDESP(%esp), %ecx
18481 xorl %ebp,%ebp
18482 TRACE_IRQS_ON
18483 1: mov PT_FS(%esp), %fs
18484+2: mov PT_DS(%esp), %ds
18485+3: mov PT_ES(%esp), %es
18486 PTGS_TO_GS
18487 ENABLE_INTERRUPTS_SYSEXIT
18488
18489@@ -466,6 +650,9 @@ sysenter_audit:
18490 movl %eax,%edx /* 2nd arg: syscall number */
18491 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
18492 call __audit_syscall_entry
18493+
18494+ pax_erase_kstack
18495+
18496 pushl_cfi %ebx
18497 movl PT_EAX(%esp),%eax /* reload syscall number */
18498 jmp sysenter_do_call
18499@@ -491,10 +678,16 @@ sysexit_audit:
18500
18501 CFI_ENDPROC
18502 .pushsection .fixup,"ax"
18503-2: movl $0,PT_FS(%esp)
18504+4: movl $0,PT_FS(%esp)
18505+ jmp 1b
18506+5: movl $0,PT_DS(%esp)
18507+ jmp 1b
18508+6: movl $0,PT_ES(%esp)
18509 jmp 1b
18510 .popsection
18511- _ASM_EXTABLE(1b,2b)
18512+ _ASM_EXTABLE(1b,4b)
18513+ _ASM_EXTABLE(2b,5b)
18514+ _ASM_EXTABLE(3b,6b)
18515 PTGS_TO_GS_EX
18516 ENDPROC(ia32_sysenter_target)
18517
18518@@ -509,6 +702,11 @@ ENTRY(system_call)
18519 pushl_cfi %eax # save orig_eax
18520 SAVE_ALL
18521 GET_THREAD_INFO(%ebp)
18522+
18523+#ifdef CONFIG_PAX_RANDKSTACK
18524+ pax_erase_kstack
18525+#endif
18526+
18527 # system call tracing in operation / emulation
18528 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18529 jnz syscall_trace_entry
18530@@ -527,6 +725,15 @@ syscall_exit:
18531 testl $_TIF_ALLWORK_MASK, %ecx # current->work
18532 jne syscall_exit_work
18533
18534+restore_all_pax:
18535+
18536+#ifdef CONFIG_PAX_RANDKSTACK
18537+ movl %esp, %eax
18538+ call pax_randomize_kstack
18539+#endif
18540+
18541+ pax_erase_kstack
18542+
18543 restore_all:
18544 TRACE_IRQS_IRET
18545 restore_all_notrace:
18546@@ -583,14 +790,34 @@ ldt_ss:
18547 * compensating for the offset by changing to the ESPFIX segment with
18548 * a base address that matches for the difference.
18549 */
18550-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
18551+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
18552 mov %esp, %edx /* load kernel esp */
18553 mov PT_OLDESP(%esp), %eax /* load userspace esp */
18554 mov %dx, %ax /* eax: new kernel esp */
18555 sub %eax, %edx /* offset (low word is 0) */
18556+#ifdef CONFIG_SMP
18557+ movl PER_CPU_VAR(cpu_number), %ebx
18558+ shll $PAGE_SHIFT_asm, %ebx
18559+ addl $cpu_gdt_table, %ebx
18560+#else
18561+ movl $cpu_gdt_table, %ebx
18562+#endif
18563 shr $16, %edx
18564- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
18565- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
18566+
18567+#ifdef CONFIG_PAX_KERNEXEC
18568+ mov %cr0, %esi
18569+ btr $16, %esi
18570+ mov %esi, %cr0
18571+#endif
18572+
18573+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
18574+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
18575+
18576+#ifdef CONFIG_PAX_KERNEXEC
18577+ bts $16, %esi
18578+ mov %esi, %cr0
18579+#endif
18580+
18581 pushl_cfi $__ESPFIX_SS
18582 pushl_cfi %eax /* new kernel esp */
18583 /* Disable interrupts, but do not irqtrace this section: we
18584@@ -619,20 +846,18 @@ work_resched:
18585 movl TI_flags(%ebp), %ecx
18586 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
18587 # than syscall tracing?
18588- jz restore_all
18589+ jz restore_all_pax
18590 testb $_TIF_NEED_RESCHED, %cl
18591 jnz work_resched
18592
18593 work_notifysig: # deal with pending signals and
18594 # notify-resume requests
18595+ movl %esp, %eax
18596 #ifdef CONFIG_VM86
18597 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
18598- movl %esp, %eax
18599 jne work_notifysig_v86 # returning to kernel-space or
18600 # vm86-space
18601 1:
18602-#else
18603- movl %esp, %eax
18604 #endif
18605 TRACE_IRQS_ON
18606 ENABLE_INTERRUPTS(CLBR_NONE)
18607@@ -653,7 +878,7 @@ work_notifysig_v86:
18608 movl %eax, %esp
18609 jmp 1b
18610 #endif
18611-END(work_pending)
18612+ENDPROC(work_pending)
18613
18614 # perform syscall exit tracing
18615 ALIGN
18616@@ -661,11 +886,14 @@ syscall_trace_entry:
18617 movl $-ENOSYS,PT_EAX(%esp)
18618 movl %esp, %eax
18619 call syscall_trace_enter
18620+
18621+ pax_erase_kstack
18622+
18623 /* What it returned is what we'll actually use. */
18624 cmpl $(NR_syscalls), %eax
18625 jnae syscall_call
18626 jmp syscall_exit
18627-END(syscall_trace_entry)
18628+ENDPROC(syscall_trace_entry)
18629
18630 # perform syscall exit tracing
18631 ALIGN
18632@@ -678,21 +906,25 @@ syscall_exit_work:
18633 movl %esp, %eax
18634 call syscall_trace_leave
18635 jmp resume_userspace
18636-END(syscall_exit_work)
18637+ENDPROC(syscall_exit_work)
18638 CFI_ENDPROC
18639
18640 RING0_INT_FRAME # can't unwind into user space anyway
18641 syscall_fault:
18642+#ifdef CONFIG_PAX_MEMORY_UDEREF
18643+ push %ss
18644+ pop %ds
18645+#endif
18646 ASM_CLAC
18647 GET_THREAD_INFO(%ebp)
18648 movl $-EFAULT,PT_EAX(%esp)
18649 jmp resume_userspace
18650-END(syscall_fault)
18651+ENDPROC(syscall_fault)
18652
18653 syscall_badsys:
18654 movl $-ENOSYS,PT_EAX(%esp)
18655 jmp resume_userspace
18656-END(syscall_badsys)
18657+ENDPROC(syscall_badsys)
18658 CFI_ENDPROC
18659 /*
18660 * End of kprobes section
18661@@ -708,8 +940,15 @@ END(syscall_badsys)
18662 * normal stack and adjusts ESP with the matching offset.
18663 */
18664 /* fixup the stack */
18665- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
18666- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
18667+#ifdef CONFIG_SMP
18668+ movl PER_CPU_VAR(cpu_number), %ebx
18669+ shll $PAGE_SHIFT_asm, %ebx
18670+ addl $cpu_gdt_table, %ebx
18671+#else
18672+ movl $cpu_gdt_table, %ebx
18673+#endif
18674+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
18675+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
18676 shl $16, %eax
18677 addl %esp, %eax /* the adjusted stack pointer */
18678 pushl_cfi $__KERNEL_DS
18679@@ -762,7 +1001,7 @@ vector=vector+1
18680 .endr
18681 2: jmp common_interrupt
18682 .endr
18683-END(irq_entries_start)
18684+ENDPROC(irq_entries_start)
18685
18686 .previous
18687 END(interrupt)
18688@@ -813,7 +1052,7 @@ ENTRY(coprocessor_error)
18689 pushl_cfi $do_coprocessor_error
18690 jmp error_code
18691 CFI_ENDPROC
18692-END(coprocessor_error)
18693+ENDPROC(coprocessor_error)
18694
18695 ENTRY(simd_coprocessor_error)
18696 RING0_INT_FRAME
18697@@ -835,7 +1074,7 @@ ENTRY(simd_coprocessor_error)
18698 #endif
18699 jmp error_code
18700 CFI_ENDPROC
18701-END(simd_coprocessor_error)
18702+ENDPROC(simd_coprocessor_error)
18703
18704 ENTRY(device_not_available)
18705 RING0_INT_FRAME
18706@@ -844,18 +1083,18 @@ ENTRY(device_not_available)
18707 pushl_cfi $do_device_not_available
18708 jmp error_code
18709 CFI_ENDPROC
18710-END(device_not_available)
18711+ENDPROC(device_not_available)
18712
18713 #ifdef CONFIG_PARAVIRT
18714 ENTRY(native_iret)
18715 iret
18716 _ASM_EXTABLE(native_iret, iret_exc)
18717-END(native_iret)
18718+ENDPROC(native_iret)
18719
18720 ENTRY(native_irq_enable_sysexit)
18721 sti
18722 sysexit
18723-END(native_irq_enable_sysexit)
18724+ENDPROC(native_irq_enable_sysexit)
18725 #endif
18726
18727 ENTRY(overflow)
18728@@ -865,7 +1104,7 @@ ENTRY(overflow)
18729 pushl_cfi $do_overflow
18730 jmp error_code
18731 CFI_ENDPROC
18732-END(overflow)
18733+ENDPROC(overflow)
18734
18735 ENTRY(bounds)
18736 RING0_INT_FRAME
18737@@ -874,7 +1113,7 @@ ENTRY(bounds)
18738 pushl_cfi $do_bounds
18739 jmp error_code
18740 CFI_ENDPROC
18741-END(bounds)
18742+ENDPROC(bounds)
18743
18744 ENTRY(invalid_op)
18745 RING0_INT_FRAME
18746@@ -883,7 +1122,7 @@ ENTRY(invalid_op)
18747 pushl_cfi $do_invalid_op
18748 jmp error_code
18749 CFI_ENDPROC
18750-END(invalid_op)
18751+ENDPROC(invalid_op)
18752
18753 ENTRY(coprocessor_segment_overrun)
18754 RING0_INT_FRAME
18755@@ -892,7 +1131,7 @@ ENTRY(coprocessor_segment_overrun)
18756 pushl_cfi $do_coprocessor_segment_overrun
18757 jmp error_code
18758 CFI_ENDPROC
18759-END(coprocessor_segment_overrun)
18760+ENDPROC(coprocessor_segment_overrun)
18761
18762 ENTRY(invalid_TSS)
18763 RING0_EC_FRAME
18764@@ -900,7 +1139,7 @@ ENTRY(invalid_TSS)
18765 pushl_cfi $do_invalid_TSS
18766 jmp error_code
18767 CFI_ENDPROC
18768-END(invalid_TSS)
18769+ENDPROC(invalid_TSS)
18770
18771 ENTRY(segment_not_present)
18772 RING0_EC_FRAME
18773@@ -908,7 +1147,7 @@ ENTRY(segment_not_present)
18774 pushl_cfi $do_segment_not_present
18775 jmp error_code
18776 CFI_ENDPROC
18777-END(segment_not_present)
18778+ENDPROC(segment_not_present)
18779
18780 ENTRY(stack_segment)
18781 RING0_EC_FRAME
18782@@ -916,7 +1155,7 @@ ENTRY(stack_segment)
18783 pushl_cfi $do_stack_segment
18784 jmp error_code
18785 CFI_ENDPROC
18786-END(stack_segment)
18787+ENDPROC(stack_segment)
18788
18789 ENTRY(alignment_check)
18790 RING0_EC_FRAME
18791@@ -924,7 +1163,7 @@ ENTRY(alignment_check)
18792 pushl_cfi $do_alignment_check
18793 jmp error_code
18794 CFI_ENDPROC
18795-END(alignment_check)
18796+ENDPROC(alignment_check)
18797
18798 ENTRY(divide_error)
18799 RING0_INT_FRAME
18800@@ -933,7 +1172,7 @@ ENTRY(divide_error)
18801 pushl_cfi $do_divide_error
18802 jmp error_code
18803 CFI_ENDPROC
18804-END(divide_error)
18805+ENDPROC(divide_error)
18806
18807 #ifdef CONFIG_X86_MCE
18808 ENTRY(machine_check)
18809@@ -943,7 +1182,7 @@ ENTRY(machine_check)
18810 pushl_cfi machine_check_vector
18811 jmp error_code
18812 CFI_ENDPROC
18813-END(machine_check)
18814+ENDPROC(machine_check)
18815 #endif
18816
18817 ENTRY(spurious_interrupt_bug)
18818@@ -953,7 +1192,7 @@ ENTRY(spurious_interrupt_bug)
18819 pushl_cfi $do_spurious_interrupt_bug
18820 jmp error_code
18821 CFI_ENDPROC
18822-END(spurious_interrupt_bug)
18823+ENDPROC(spurious_interrupt_bug)
18824 /*
18825 * End of kprobes section
18826 */
18827@@ -1063,7 +1302,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
18828
18829 ENTRY(mcount)
18830 ret
18831-END(mcount)
18832+ENDPROC(mcount)
18833
18834 ENTRY(ftrace_caller)
18835 cmpl $0, function_trace_stop
18836@@ -1096,7 +1335,7 @@ ftrace_graph_call:
18837 .globl ftrace_stub
18838 ftrace_stub:
18839 ret
18840-END(ftrace_caller)
18841+ENDPROC(ftrace_caller)
18842
18843 ENTRY(ftrace_regs_caller)
18844 pushf /* push flags before compare (in cs location) */
18845@@ -1197,7 +1436,7 @@ trace:
18846 popl %ecx
18847 popl %eax
18848 jmp ftrace_stub
18849-END(mcount)
18850+ENDPROC(mcount)
18851 #endif /* CONFIG_DYNAMIC_FTRACE */
18852 #endif /* CONFIG_FUNCTION_TRACER */
18853
18854@@ -1215,7 +1454,7 @@ ENTRY(ftrace_graph_caller)
18855 popl %ecx
18856 popl %eax
18857 ret
18858-END(ftrace_graph_caller)
18859+ENDPROC(ftrace_graph_caller)
18860
18861 .globl return_to_handler
18862 return_to_handler:
18863@@ -1271,15 +1510,18 @@ error_code:
18864 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
18865 REG_TO_PTGS %ecx
18866 SET_KERNEL_GS %ecx
18867- movl $(__USER_DS), %ecx
18868+ movl $(__KERNEL_DS), %ecx
18869 movl %ecx, %ds
18870 movl %ecx, %es
18871+
18872+ pax_enter_kernel
18873+
18874 TRACE_IRQS_OFF
18875 movl %esp,%eax # pt_regs pointer
18876 call *%edi
18877 jmp ret_from_exception
18878 CFI_ENDPROC
18879-END(page_fault)
18880+ENDPROC(page_fault)
18881
18882 /*
18883 * Debug traps and NMI can happen at the one SYSENTER instruction
18884@@ -1322,7 +1564,7 @@ debug_stack_correct:
18885 call do_debug
18886 jmp ret_from_exception
18887 CFI_ENDPROC
18888-END(debug)
18889+ENDPROC(debug)
18890
18891 /*
18892 * NMI is doubly nasty. It can happen _while_ we're handling
18893@@ -1360,6 +1602,9 @@ nmi_stack_correct:
18894 xorl %edx,%edx # zero error code
18895 movl %esp,%eax # pt_regs pointer
18896 call do_nmi
18897+
18898+ pax_exit_kernel
18899+
18900 jmp restore_all_notrace
18901 CFI_ENDPROC
18902
18903@@ -1396,12 +1641,15 @@ nmi_espfix_stack:
18904 FIXUP_ESPFIX_STACK # %eax == %esp
18905 xorl %edx,%edx # zero error code
18906 call do_nmi
18907+
18908+ pax_exit_kernel
18909+
18910 RESTORE_REGS
18911 lss 12+4(%esp), %esp # back to espfix stack
18912 CFI_ADJUST_CFA_OFFSET -24
18913 jmp irq_return
18914 CFI_ENDPROC
18915-END(nmi)
18916+ENDPROC(nmi)
18917
18918 ENTRY(int3)
18919 RING0_INT_FRAME
18920@@ -1414,14 +1662,14 @@ ENTRY(int3)
18921 call do_int3
18922 jmp ret_from_exception
18923 CFI_ENDPROC
18924-END(int3)
18925+ENDPROC(int3)
18926
18927 ENTRY(general_protection)
18928 RING0_EC_FRAME
18929 pushl_cfi $do_general_protection
18930 jmp error_code
18931 CFI_ENDPROC
18932-END(general_protection)
18933+ENDPROC(general_protection)
18934
18935 #ifdef CONFIG_KVM_GUEST
18936 ENTRY(async_page_fault)
18937@@ -1430,7 +1678,7 @@ ENTRY(async_page_fault)
18938 pushl_cfi $do_async_page_fault
18939 jmp error_code
18940 CFI_ENDPROC
18941-END(async_page_fault)
18942+ENDPROC(async_page_fault)
18943 #endif
18944
18945 /*
18946diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
18947index c1d01e6..5625dce 100644
18948--- a/arch/x86/kernel/entry_64.S
18949+++ b/arch/x86/kernel/entry_64.S
18950@@ -59,6 +59,8 @@
18951 #include <asm/context_tracking.h>
18952 #include <asm/smap.h>
18953 #include <linux/err.h>
18954+#include <asm/pgtable.h>
18955+#include <asm/alternative-asm.h>
18956
18957 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
18958 #include <linux/elf-em.h>
18959@@ -80,8 +82,9 @@
18960 #ifdef CONFIG_DYNAMIC_FTRACE
18961
18962 ENTRY(function_hook)
18963+ pax_force_retaddr
18964 retq
18965-END(function_hook)
18966+ENDPROC(function_hook)
18967
18968 /* skip is set if stack has been adjusted */
18969 .macro ftrace_caller_setup skip=0
18970@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
18971 #endif
18972
18973 GLOBAL(ftrace_stub)
18974+ pax_force_retaddr
18975 retq
18976-END(ftrace_caller)
18977+ENDPROC(ftrace_caller)
18978
18979 ENTRY(ftrace_regs_caller)
18980 /* Save the current flags before compare (in SS location)*/
18981@@ -191,7 +195,7 @@ ftrace_restore_flags:
18982 popfq
18983 jmp ftrace_stub
18984
18985-END(ftrace_regs_caller)
18986+ENDPROC(ftrace_regs_caller)
18987
18988
18989 #else /* ! CONFIG_DYNAMIC_FTRACE */
18990@@ -212,6 +216,7 @@ ENTRY(function_hook)
18991 #endif
18992
18993 GLOBAL(ftrace_stub)
18994+ pax_force_retaddr
18995 retq
18996
18997 trace:
18998@@ -225,12 +230,13 @@ trace:
18999 #endif
19000 subq $MCOUNT_INSN_SIZE, %rdi
19001
19002+ pax_force_fptr ftrace_trace_function
19003 call *ftrace_trace_function
19004
19005 MCOUNT_RESTORE_FRAME
19006
19007 jmp ftrace_stub
19008-END(function_hook)
19009+ENDPROC(function_hook)
19010 #endif /* CONFIG_DYNAMIC_FTRACE */
19011 #endif /* CONFIG_FUNCTION_TRACER */
19012
19013@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
19014
19015 MCOUNT_RESTORE_FRAME
19016
19017+ pax_force_retaddr
19018 retq
19019-END(ftrace_graph_caller)
19020+ENDPROC(ftrace_graph_caller)
19021
19022 GLOBAL(return_to_handler)
19023 subq $24, %rsp
19024@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
19025 movq 8(%rsp), %rdx
19026 movq (%rsp), %rax
19027 addq $24, %rsp
19028+ pax_force_fptr %rdi
19029 jmp *%rdi
19030+ENDPROC(return_to_handler)
19031 #endif
19032
19033
19034@@ -284,6 +293,282 @@ ENTRY(native_usergs_sysret64)
19035 ENDPROC(native_usergs_sysret64)
19036 #endif /* CONFIG_PARAVIRT */
19037
19038+ .macro ljmpq sel, off
19039+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
19040+ .byte 0x48; ljmp *1234f(%rip)
19041+ .pushsection .rodata
19042+ .align 16
19043+ 1234: .quad \off; .word \sel
19044+ .popsection
19045+#else
19046+ pushq $\sel
19047+ pushq $\off
19048+ lretq
19049+#endif
19050+ .endm
19051+
19052+ .macro pax_enter_kernel
19053+ pax_set_fptr_mask
19054+#ifdef CONFIG_PAX_KERNEXEC
19055+ call pax_enter_kernel
19056+#endif
19057+ .endm
19058+
19059+ .macro pax_exit_kernel
19060+#ifdef CONFIG_PAX_KERNEXEC
19061+ call pax_exit_kernel
19062+#endif
19063+ .endm
19064+
19065+#ifdef CONFIG_PAX_KERNEXEC
19066+ENTRY(pax_enter_kernel)
19067+ pushq %rdi
19068+
19069+#ifdef CONFIG_PARAVIRT
19070+ PV_SAVE_REGS(CLBR_RDI)
19071+#endif
19072+
19073+ GET_CR0_INTO_RDI
19074+ bts $16,%rdi
19075+ jnc 3f
19076+ mov %cs,%edi
19077+ cmp $__KERNEL_CS,%edi
19078+ jnz 2f
19079+1:
19080+
19081+#ifdef CONFIG_PARAVIRT
19082+ PV_RESTORE_REGS(CLBR_RDI)
19083+#endif
19084+
19085+ popq %rdi
19086+ pax_force_retaddr
19087+ retq
19088+
19089+2: ljmpq __KERNEL_CS,1b
19090+3: ljmpq __KERNEXEC_KERNEL_CS,4f
19091+4: SET_RDI_INTO_CR0
19092+ jmp 1b
19093+ENDPROC(pax_enter_kernel)
19094+
19095+ENTRY(pax_exit_kernel)
19096+ pushq %rdi
19097+
19098+#ifdef CONFIG_PARAVIRT
19099+ PV_SAVE_REGS(CLBR_RDI)
19100+#endif
19101+
19102+ mov %cs,%rdi
19103+ cmp $__KERNEXEC_KERNEL_CS,%edi
19104+ jz 2f
19105+ GET_CR0_INTO_RDI
19106+ bts $16,%rdi
19107+ jnc 4f
19108+1:
19109+
19110+#ifdef CONFIG_PARAVIRT
19111+ PV_RESTORE_REGS(CLBR_RDI);
19112+#endif
19113+
19114+ popq %rdi
19115+ pax_force_retaddr
19116+ retq
19117+
19118+2: GET_CR0_INTO_RDI
19119+ btr $16,%rdi
19120+ jnc 4f
19121+ ljmpq __KERNEL_CS,3f
19122+3: SET_RDI_INTO_CR0
19123+ jmp 1b
19124+4: ud2
19125+ jmp 4b
19126+ENDPROC(pax_exit_kernel)
19127+#endif
19128+
19129+ .macro pax_enter_kernel_user
19130+ pax_set_fptr_mask
19131+#ifdef CONFIG_PAX_MEMORY_UDEREF
19132+ call pax_enter_kernel_user
19133+#endif
19134+ .endm
19135+
19136+ .macro pax_exit_kernel_user
19137+#ifdef CONFIG_PAX_MEMORY_UDEREF
19138+ call pax_exit_kernel_user
19139+#endif
19140+#ifdef CONFIG_PAX_RANDKSTACK
19141+ pushq %rax
19142+ call pax_randomize_kstack
19143+ popq %rax
19144+#endif
19145+ .endm
19146+
19147+#ifdef CONFIG_PAX_MEMORY_UDEREF
19148+ENTRY(pax_enter_kernel_user)
19149+ pushq %rdi
19150+ pushq %rbx
19151+
19152+#ifdef CONFIG_PARAVIRT
19153+ PV_SAVE_REGS(CLBR_RDI)
19154+#endif
19155+
19156+ GET_CR3_INTO_RDI
19157+ mov %rdi,%rbx
19158+ add $__START_KERNEL_map,%rbx
19159+ sub phys_base(%rip),%rbx
19160+
19161+#ifdef CONFIG_PARAVIRT
19162+ pushq %rdi
19163+ cmpl $0, pv_info+PARAVIRT_enabled
19164+ jz 1f
19165+ i = 0
19166+ .rept USER_PGD_PTRS
19167+ mov i*8(%rbx),%rsi
19168+ mov $0,%sil
19169+ lea i*8(%rbx),%rdi
19170+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19171+ i = i + 1
19172+ .endr
19173+ jmp 2f
19174+1:
19175+#endif
19176+
19177+ i = 0
19178+ .rept USER_PGD_PTRS
19179+ movb $0,i*8(%rbx)
19180+ i = i + 1
19181+ .endr
19182+
19183+#ifdef CONFIG_PARAVIRT
19184+2: popq %rdi
19185+#endif
19186+ SET_RDI_INTO_CR3
19187+
19188+#ifdef CONFIG_PAX_KERNEXEC
19189+ GET_CR0_INTO_RDI
19190+ bts $16,%rdi
19191+ SET_RDI_INTO_CR0
19192+#endif
19193+
19194+#ifdef CONFIG_PARAVIRT
19195+ PV_RESTORE_REGS(CLBR_RDI)
19196+#endif
19197+
19198+ popq %rbx
19199+ popq %rdi
19200+ pax_force_retaddr
19201+ retq
19202+ENDPROC(pax_enter_kernel_user)
19203+
19204+ENTRY(pax_exit_kernel_user)
19205+ push %rdi
19206+
19207+#ifdef CONFIG_PARAVIRT
19208+ pushq %rbx
19209+ PV_SAVE_REGS(CLBR_RDI)
19210+#endif
19211+
19212+#ifdef CONFIG_PAX_KERNEXEC
19213+ GET_CR0_INTO_RDI
19214+ btr $16,%rdi
19215+ jnc 3f
19216+ SET_RDI_INTO_CR0
19217+#endif
19218+
19219+ GET_CR3_INTO_RDI
19220+ add $__START_KERNEL_map,%rdi
19221+ sub phys_base(%rip),%rdi
19222+
19223+#ifdef CONFIG_PARAVIRT
19224+ cmpl $0, pv_info+PARAVIRT_enabled
19225+ jz 1f
19226+ mov %rdi,%rbx
19227+ i = 0
19228+ .rept USER_PGD_PTRS
19229+ mov i*8(%rbx),%rsi
19230+ mov $0x67,%sil
19231+ lea i*8(%rbx),%rdi
19232+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19233+ i = i + 1
19234+ .endr
19235+ jmp 2f
19236+1:
19237+#endif
19238+
19239+ i = 0
19240+ .rept USER_PGD_PTRS
19241+ movb $0x67,i*8(%rdi)
19242+ i = i + 1
19243+ .endr
19244+
19245+#ifdef CONFIG_PARAVIRT
19246+2: PV_RESTORE_REGS(CLBR_RDI)
19247+ popq %rbx
19248+#endif
19249+
19250+ popq %rdi
19251+ pax_force_retaddr
19252+ retq
19253+3: ud2
19254+ jmp 3b
19255+ENDPROC(pax_exit_kernel_user)
19256+#endif
19257+
19258+.macro pax_erase_kstack
19259+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19260+ call pax_erase_kstack
19261+#endif
19262+.endm
19263+
19264+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19265+ENTRY(pax_erase_kstack)
19266+ pushq %rdi
19267+ pushq %rcx
19268+ pushq %rax
19269+ pushq %r11
19270+
19271+ GET_THREAD_INFO(%r11)
19272+ mov TI_lowest_stack(%r11), %rdi
19273+ mov $-0xBEEF, %rax
19274+ std
19275+
19276+1: mov %edi, %ecx
19277+ and $THREAD_SIZE_asm - 1, %ecx
19278+ shr $3, %ecx
19279+ repne scasq
19280+ jecxz 2f
19281+
19282+ cmp $2*8, %ecx
19283+ jc 2f
19284+
19285+ mov $2*8, %ecx
19286+ repe scasq
19287+ jecxz 2f
19288+ jne 1b
19289+
19290+2: cld
19291+ mov %esp, %ecx
19292+ sub %edi, %ecx
19293+
19294+ cmp $THREAD_SIZE_asm, %rcx
19295+ jb 3f
19296+ ud2
19297+3:
19298+
19299+ shr $3, %ecx
19300+ rep stosq
19301+
19302+ mov TI_task_thread_sp0(%r11), %rdi
19303+ sub $256, %rdi
19304+ mov %rdi, TI_lowest_stack(%r11)
19305+
19306+ popq %r11
19307+ popq %rax
19308+ popq %rcx
19309+ popq %rdi
19310+ pax_force_retaddr
19311+ ret
19312+ENDPROC(pax_erase_kstack)
19313+#endif
19314
19315 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
19316 #ifdef CONFIG_TRACE_IRQFLAGS
19317@@ -375,8 +660,8 @@ ENDPROC(native_usergs_sysret64)
19318 .endm
19319
19320 .macro UNFAKE_STACK_FRAME
19321- addq $8*6, %rsp
19322- CFI_ADJUST_CFA_OFFSET -(6*8)
19323+ addq $8*6 + ARG_SKIP, %rsp
19324+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
19325 .endm
19326
19327 /*
19328@@ -463,7 +748,7 @@ ENDPROC(native_usergs_sysret64)
19329 movq %rsp, %rsi
19330
19331 leaq -RBP(%rsp),%rdi /* arg1 for handler */
19332- testl $3, CS-RBP(%rsi)
19333+ testb $3, CS-RBP(%rsi)
19334 je 1f
19335 SWAPGS
19336 /*
19337@@ -498,9 +783,10 @@ ENTRY(save_rest)
19338 movq_cfi r15, R15+16
19339 movq %r11, 8(%rsp) /* return address */
19340 FIXUP_TOP_OF_STACK %r11, 16
19341+ pax_force_retaddr
19342 ret
19343 CFI_ENDPROC
19344-END(save_rest)
19345+ENDPROC(save_rest)
19346
19347 /* save complete stack frame */
19348 .pushsection .kprobes.text, "ax"
19349@@ -529,9 +815,10 @@ ENTRY(save_paranoid)
19350 js 1f /* negative -> in kernel */
19351 SWAPGS
19352 xorl %ebx,%ebx
19353-1: ret
19354+1: pax_force_retaddr_bts
19355+ ret
19356 CFI_ENDPROC
19357-END(save_paranoid)
19358+ENDPROC(save_paranoid)
19359 .popsection
19360
19361 /*
19362@@ -553,7 +840,7 @@ ENTRY(ret_from_fork)
19363
19364 RESTORE_REST
19365
19366- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19367+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19368 jz 1f
19369
19370 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
19371@@ -571,7 +858,7 @@ ENTRY(ret_from_fork)
19372 RESTORE_REST
19373 jmp int_ret_from_sys_call
19374 CFI_ENDPROC
19375-END(ret_from_fork)
19376+ENDPROC(ret_from_fork)
19377
19378 /*
19379 * System call entry. Up to 6 arguments in registers are supported.
19380@@ -608,7 +895,7 @@ END(ret_from_fork)
19381 ENTRY(system_call)
19382 CFI_STARTPROC simple
19383 CFI_SIGNAL_FRAME
19384- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
19385+ CFI_DEF_CFA rsp,0
19386 CFI_REGISTER rip,rcx
19387 /*CFI_REGISTER rflags,r11*/
19388 SWAPGS_UNSAFE_STACK
19389@@ -621,16 +908,23 @@ GLOBAL(system_call_after_swapgs)
19390
19391 movq %rsp,PER_CPU_VAR(old_rsp)
19392 movq PER_CPU_VAR(kernel_stack),%rsp
19393+ SAVE_ARGS 8*6,0
19394+ pax_enter_kernel_user
19395+
19396+#ifdef CONFIG_PAX_RANDKSTACK
19397+ pax_erase_kstack
19398+#endif
19399+
19400 /*
19401 * No need to follow this irqs off/on section - it's straight
19402 * and short:
19403 */
19404 ENABLE_INTERRUPTS(CLBR_NONE)
19405- SAVE_ARGS 8,0
19406 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
19407 movq %rcx,RIP-ARGOFFSET(%rsp)
19408 CFI_REL_OFFSET rip,RIP-ARGOFFSET
19409- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19410+ GET_THREAD_INFO(%rcx)
19411+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
19412 jnz tracesys
19413 system_call_fastpath:
19414 #if __SYSCALL_MASK == ~0
19415@@ -640,7 +934,7 @@ system_call_fastpath:
19416 cmpl $__NR_syscall_max,%eax
19417 #endif
19418 ja badsys
19419- movq %r10,%rcx
19420+ movq R10-ARGOFFSET(%rsp),%rcx
19421 call *sys_call_table(,%rax,8) # XXX: rip relative
19422 movq %rax,RAX-ARGOFFSET(%rsp)
19423 /*
19424@@ -654,10 +948,13 @@ sysret_check:
19425 LOCKDEP_SYS_EXIT
19426 DISABLE_INTERRUPTS(CLBR_NONE)
19427 TRACE_IRQS_OFF
19428- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
19429+ GET_THREAD_INFO(%rcx)
19430+ movl TI_flags(%rcx),%edx
19431 andl %edi,%edx
19432 jnz sysret_careful
19433 CFI_REMEMBER_STATE
19434+ pax_exit_kernel_user
19435+ pax_erase_kstack
19436 /*
19437 * sysretq will re-enable interrupts:
19438 */
19439@@ -709,14 +1006,18 @@ badsys:
19440 * jump back to the normal fast path.
19441 */
19442 auditsys:
19443- movq %r10,%r9 /* 6th arg: 4th syscall arg */
19444+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
19445 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
19446 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
19447 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
19448 movq %rax,%rsi /* 2nd arg: syscall number */
19449 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
19450 call __audit_syscall_entry
19451+
19452+ pax_erase_kstack
19453+
19454 LOAD_ARGS 0 /* reload call-clobbered registers */
19455+ pax_set_fptr_mask
19456 jmp system_call_fastpath
19457
19458 /*
19459@@ -737,7 +1038,7 @@ sysret_audit:
19460 /* Do syscall tracing */
19461 tracesys:
19462 #ifdef CONFIG_AUDITSYSCALL
19463- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19464+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
19465 jz auditsys
19466 #endif
19467 SAVE_REST
19468@@ -745,12 +1046,16 @@ tracesys:
19469 FIXUP_TOP_OF_STACK %rdi
19470 movq %rsp,%rdi
19471 call syscall_trace_enter
19472+
19473+ pax_erase_kstack
19474+
19475 /*
19476 * Reload arg registers from stack in case ptrace changed them.
19477 * We don't reload %rax because syscall_trace_enter() returned
19478 * the value it wants us to use in the table lookup.
19479 */
19480 LOAD_ARGS ARGOFFSET, 1
19481+ pax_set_fptr_mask
19482 RESTORE_REST
19483 #if __SYSCALL_MASK == ~0
19484 cmpq $__NR_syscall_max,%rax
19485@@ -759,7 +1064,7 @@ tracesys:
19486 cmpl $__NR_syscall_max,%eax
19487 #endif
19488 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
19489- movq %r10,%rcx /* fixup for C */
19490+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
19491 call *sys_call_table(,%rax,8)
19492 movq %rax,RAX-ARGOFFSET(%rsp)
19493 /* Use IRET because user could have changed frame */
19494@@ -780,7 +1085,9 @@ GLOBAL(int_with_check)
19495 andl %edi,%edx
19496 jnz int_careful
19497 andl $~TS_COMPAT,TI_status(%rcx)
19498- jmp retint_swapgs
19499+ pax_exit_kernel_user
19500+ pax_erase_kstack
19501+ jmp retint_swapgs_pax
19502
19503 /* Either reschedule or signal or syscall exit tracking needed. */
19504 /* First do a reschedule test. */
19505@@ -826,7 +1133,7 @@ int_restore_rest:
19506 TRACE_IRQS_OFF
19507 jmp int_with_check
19508 CFI_ENDPROC
19509-END(system_call)
19510+ENDPROC(system_call)
19511
19512 .macro FORK_LIKE func
19513 ENTRY(stub_\func)
19514@@ -839,9 +1146,10 @@ ENTRY(stub_\func)
19515 DEFAULT_FRAME 0 8 /* offset 8: return address */
19516 call sys_\func
19517 RESTORE_TOP_OF_STACK %r11, 8
19518+ pax_force_retaddr
19519 ret $REST_SKIP /* pop extended registers */
19520 CFI_ENDPROC
19521-END(stub_\func)
19522+ENDPROC(stub_\func)
19523 .endm
19524
19525 .macro FIXED_FRAME label,func
19526@@ -851,9 +1159,10 @@ ENTRY(\label)
19527 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
19528 call \func
19529 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
19530+ pax_force_retaddr
19531 ret
19532 CFI_ENDPROC
19533-END(\label)
19534+ENDPROC(\label)
19535 .endm
19536
19537 FORK_LIKE clone
19538@@ -870,9 +1179,10 @@ ENTRY(ptregscall_common)
19539 movq_cfi_restore R12+8, r12
19540 movq_cfi_restore RBP+8, rbp
19541 movq_cfi_restore RBX+8, rbx
19542+ pax_force_retaddr
19543 ret $REST_SKIP /* pop extended registers */
19544 CFI_ENDPROC
19545-END(ptregscall_common)
19546+ENDPROC(ptregscall_common)
19547
19548 ENTRY(stub_execve)
19549 CFI_STARTPROC
19550@@ -885,7 +1195,7 @@ ENTRY(stub_execve)
19551 RESTORE_REST
19552 jmp int_ret_from_sys_call
19553 CFI_ENDPROC
19554-END(stub_execve)
19555+ENDPROC(stub_execve)
19556
19557 /*
19558 * sigreturn is special because it needs to restore all registers on return.
19559@@ -902,7 +1212,7 @@ ENTRY(stub_rt_sigreturn)
19560 RESTORE_REST
19561 jmp int_ret_from_sys_call
19562 CFI_ENDPROC
19563-END(stub_rt_sigreturn)
19564+ENDPROC(stub_rt_sigreturn)
19565
19566 #ifdef CONFIG_X86_X32_ABI
19567 ENTRY(stub_x32_rt_sigreturn)
19568@@ -916,7 +1226,7 @@ ENTRY(stub_x32_rt_sigreturn)
19569 RESTORE_REST
19570 jmp int_ret_from_sys_call
19571 CFI_ENDPROC
19572-END(stub_x32_rt_sigreturn)
19573+ENDPROC(stub_x32_rt_sigreturn)
19574
19575 ENTRY(stub_x32_execve)
19576 CFI_STARTPROC
19577@@ -930,7 +1240,7 @@ ENTRY(stub_x32_execve)
19578 RESTORE_REST
19579 jmp int_ret_from_sys_call
19580 CFI_ENDPROC
19581-END(stub_x32_execve)
19582+ENDPROC(stub_x32_execve)
19583
19584 #endif
19585
19586@@ -967,7 +1277,7 @@ vector=vector+1
19587 2: jmp common_interrupt
19588 .endr
19589 CFI_ENDPROC
19590-END(irq_entries_start)
19591+ENDPROC(irq_entries_start)
19592
19593 .previous
19594 END(interrupt)
19595@@ -987,6 +1297,16 @@ END(interrupt)
19596 subq $ORIG_RAX-RBP, %rsp
19597 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
19598 SAVE_ARGS_IRQ
19599+#ifdef CONFIG_PAX_MEMORY_UDEREF
19600+ testb $3, CS(%rdi)
19601+ jnz 1f
19602+ pax_enter_kernel
19603+ jmp 2f
19604+1: pax_enter_kernel_user
19605+2:
19606+#else
19607+ pax_enter_kernel
19608+#endif
19609 call \func
19610 .endm
19611
19612@@ -1019,7 +1339,7 @@ ret_from_intr:
19613
19614 exit_intr:
19615 GET_THREAD_INFO(%rcx)
19616- testl $3,CS-ARGOFFSET(%rsp)
19617+ testb $3,CS-ARGOFFSET(%rsp)
19618 je retint_kernel
19619
19620 /* Interrupt came from user space */
19621@@ -1041,12 +1361,16 @@ retint_swapgs: /* return to user-space */
19622 * The iretq could re-enable interrupts:
19623 */
19624 DISABLE_INTERRUPTS(CLBR_ANY)
19625+ pax_exit_kernel_user
19626+retint_swapgs_pax:
19627 TRACE_IRQS_IRETQ
19628 SWAPGS
19629 jmp restore_args
19630
19631 retint_restore_args: /* return to kernel space */
19632 DISABLE_INTERRUPTS(CLBR_ANY)
19633+ pax_exit_kernel
19634+ pax_force_retaddr (RIP-ARGOFFSET)
19635 /*
19636 * The iretq could re-enable interrupts:
19637 */
19638@@ -1129,7 +1453,7 @@ ENTRY(retint_kernel)
19639 #endif
19640
19641 CFI_ENDPROC
19642-END(common_interrupt)
19643+ENDPROC(common_interrupt)
19644 /*
19645 * End of kprobes section
19646 */
19647@@ -1147,7 +1471,7 @@ ENTRY(\sym)
19648 interrupt \do_sym
19649 jmp ret_from_intr
19650 CFI_ENDPROC
19651-END(\sym)
19652+ENDPROC(\sym)
19653 .endm
19654
19655 #ifdef CONFIG_SMP
19656@@ -1203,12 +1527,22 @@ ENTRY(\sym)
19657 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19658 call error_entry
19659 DEFAULT_FRAME 0
19660+#ifdef CONFIG_PAX_MEMORY_UDEREF
19661+ testb $3, CS(%rsp)
19662+ jnz 1f
19663+ pax_enter_kernel
19664+ jmp 2f
19665+1: pax_enter_kernel_user
19666+2:
19667+#else
19668+ pax_enter_kernel
19669+#endif
19670 movq %rsp,%rdi /* pt_regs pointer */
19671 xorl %esi,%esi /* no error code */
19672 call \do_sym
19673 jmp error_exit /* %ebx: no swapgs flag */
19674 CFI_ENDPROC
19675-END(\sym)
19676+ENDPROC(\sym)
19677 .endm
19678
19679 .macro paranoidzeroentry sym do_sym
19680@@ -1221,15 +1555,25 @@ ENTRY(\sym)
19681 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19682 call save_paranoid
19683 TRACE_IRQS_OFF
19684+#ifdef CONFIG_PAX_MEMORY_UDEREF
19685+ testb $3, CS(%rsp)
19686+ jnz 1f
19687+ pax_enter_kernel
19688+ jmp 2f
19689+1: pax_enter_kernel_user
19690+2:
19691+#else
19692+ pax_enter_kernel
19693+#endif
19694 movq %rsp,%rdi /* pt_regs pointer */
19695 xorl %esi,%esi /* no error code */
19696 call \do_sym
19697 jmp paranoid_exit /* %ebx: no swapgs flag */
19698 CFI_ENDPROC
19699-END(\sym)
19700+ENDPROC(\sym)
19701 .endm
19702
19703-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
19704+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
19705 .macro paranoidzeroentry_ist sym do_sym ist
19706 ENTRY(\sym)
19707 INTR_FRAME
19708@@ -1240,14 +1584,30 @@ ENTRY(\sym)
19709 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19710 call save_paranoid
19711 TRACE_IRQS_OFF_DEBUG
19712+#ifdef CONFIG_PAX_MEMORY_UDEREF
19713+ testb $3, CS(%rsp)
19714+ jnz 1f
19715+ pax_enter_kernel
19716+ jmp 2f
19717+1: pax_enter_kernel_user
19718+2:
19719+#else
19720+ pax_enter_kernel
19721+#endif
19722 movq %rsp,%rdi /* pt_regs pointer */
19723 xorl %esi,%esi /* no error code */
19724+#ifdef CONFIG_SMP
19725+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
19726+ lea init_tss(%r12), %r12
19727+#else
19728+ lea init_tss(%rip), %r12
19729+#endif
19730 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19731 call \do_sym
19732 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19733 jmp paranoid_exit /* %ebx: no swapgs flag */
19734 CFI_ENDPROC
19735-END(\sym)
19736+ENDPROC(\sym)
19737 .endm
19738
19739 .macro errorentry sym do_sym
19740@@ -1259,13 +1619,23 @@ ENTRY(\sym)
19741 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19742 call error_entry
19743 DEFAULT_FRAME 0
19744+#ifdef CONFIG_PAX_MEMORY_UDEREF
19745+ testb $3, CS(%rsp)
19746+ jnz 1f
19747+ pax_enter_kernel
19748+ jmp 2f
19749+1: pax_enter_kernel_user
19750+2:
19751+#else
19752+ pax_enter_kernel
19753+#endif
19754 movq %rsp,%rdi /* pt_regs pointer */
19755 movq ORIG_RAX(%rsp),%rsi /* get error code */
19756 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19757 call \do_sym
19758 jmp error_exit /* %ebx: no swapgs flag */
19759 CFI_ENDPROC
19760-END(\sym)
19761+ENDPROC(\sym)
19762 .endm
19763
19764 /* error code is on the stack already */
19765@@ -1279,13 +1649,23 @@ ENTRY(\sym)
19766 call save_paranoid
19767 DEFAULT_FRAME 0
19768 TRACE_IRQS_OFF
19769+#ifdef CONFIG_PAX_MEMORY_UDEREF
19770+ testb $3, CS(%rsp)
19771+ jnz 1f
19772+ pax_enter_kernel
19773+ jmp 2f
19774+1: pax_enter_kernel_user
19775+2:
19776+#else
19777+ pax_enter_kernel
19778+#endif
19779 movq %rsp,%rdi /* pt_regs pointer */
19780 movq ORIG_RAX(%rsp),%rsi /* get error code */
19781 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19782 call \do_sym
19783 jmp paranoid_exit /* %ebx: no swapgs flag */
19784 CFI_ENDPROC
19785-END(\sym)
19786+ENDPROC(\sym)
19787 .endm
19788
19789 zeroentry divide_error do_divide_error
19790@@ -1315,9 +1695,10 @@ gs_change:
19791 2: mfence /* workaround */
19792 SWAPGS
19793 popfq_cfi
19794+ pax_force_retaddr
19795 ret
19796 CFI_ENDPROC
19797-END(native_load_gs_index)
19798+ENDPROC(native_load_gs_index)
19799
19800 _ASM_EXTABLE(gs_change,bad_gs)
19801 .section .fixup,"ax"
19802@@ -1345,9 +1726,10 @@ ENTRY(call_softirq)
19803 CFI_DEF_CFA_REGISTER rsp
19804 CFI_ADJUST_CFA_OFFSET -8
19805 decl PER_CPU_VAR(irq_count)
19806+ pax_force_retaddr
19807 ret
19808 CFI_ENDPROC
19809-END(call_softirq)
19810+ENDPROC(call_softirq)
19811
19812 #ifdef CONFIG_XEN
19813 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
19814@@ -1385,7 +1767,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
19815 decl PER_CPU_VAR(irq_count)
19816 jmp error_exit
19817 CFI_ENDPROC
19818-END(xen_do_hypervisor_callback)
19819+ENDPROC(xen_do_hypervisor_callback)
19820
19821 /*
19822 * Hypervisor uses this for application faults while it executes.
19823@@ -1444,7 +1826,7 @@ ENTRY(xen_failsafe_callback)
19824 SAVE_ALL
19825 jmp error_exit
19826 CFI_ENDPROC
19827-END(xen_failsafe_callback)
19828+ENDPROC(xen_failsafe_callback)
19829
19830 apicinterrupt HYPERVISOR_CALLBACK_VECTOR \
19831 xen_hvm_callback_vector xen_evtchn_do_upcall
19832@@ -1498,16 +1880,31 @@ ENTRY(paranoid_exit)
19833 TRACE_IRQS_OFF_DEBUG
19834 testl %ebx,%ebx /* swapgs needed? */
19835 jnz paranoid_restore
19836- testl $3,CS(%rsp)
19837+ testb $3,CS(%rsp)
19838 jnz paranoid_userspace
19839+#ifdef CONFIG_PAX_MEMORY_UDEREF
19840+ pax_exit_kernel
19841+ TRACE_IRQS_IRETQ 0
19842+ SWAPGS_UNSAFE_STACK
19843+ RESTORE_ALL 8
19844+ pax_force_retaddr_bts
19845+ jmp irq_return
19846+#endif
19847 paranoid_swapgs:
19848+#ifdef CONFIG_PAX_MEMORY_UDEREF
19849+ pax_exit_kernel_user
19850+#else
19851+ pax_exit_kernel
19852+#endif
19853 TRACE_IRQS_IRETQ 0
19854 SWAPGS_UNSAFE_STACK
19855 RESTORE_ALL 8
19856 jmp irq_return
19857 paranoid_restore:
19858+ pax_exit_kernel
19859 TRACE_IRQS_IRETQ_DEBUG 0
19860 RESTORE_ALL 8
19861+ pax_force_retaddr_bts
19862 jmp irq_return
19863 paranoid_userspace:
19864 GET_THREAD_INFO(%rcx)
19865@@ -1536,7 +1933,7 @@ paranoid_schedule:
19866 TRACE_IRQS_OFF
19867 jmp paranoid_userspace
19868 CFI_ENDPROC
19869-END(paranoid_exit)
19870+ENDPROC(paranoid_exit)
19871
19872 /*
19873 * Exception entry point. This expects an error code/orig_rax on the stack.
19874@@ -1563,12 +1960,13 @@ ENTRY(error_entry)
19875 movq_cfi r14, R14+8
19876 movq_cfi r15, R15+8
19877 xorl %ebx,%ebx
19878- testl $3,CS+8(%rsp)
19879+ testb $3,CS+8(%rsp)
19880 je error_kernelspace
19881 error_swapgs:
19882 SWAPGS
19883 error_sti:
19884 TRACE_IRQS_OFF
19885+ pax_force_retaddr_bts
19886 ret
19887
19888 /*
19889@@ -1595,7 +1993,7 @@ bstep_iret:
19890 movq %rcx,RIP+8(%rsp)
19891 jmp error_swapgs
19892 CFI_ENDPROC
19893-END(error_entry)
19894+ENDPROC(error_entry)
19895
19896
19897 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
19898@@ -1615,7 +2013,7 @@ ENTRY(error_exit)
19899 jnz retint_careful
19900 jmp retint_swapgs
19901 CFI_ENDPROC
19902-END(error_exit)
19903+ENDPROC(error_exit)
19904
19905 /*
19906 * Test if a given stack is an NMI stack or not.
19907@@ -1673,9 +2071,11 @@ ENTRY(nmi)
19908 * If %cs was not the kernel segment, then the NMI triggered in user
19909 * space, which means it is definitely not nested.
19910 */
19911+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
19912+ je 1f
19913 cmpl $__KERNEL_CS, 16(%rsp)
19914 jne first_nmi
19915-
19916+1:
19917 /*
19918 * Check the special variable on the stack to see if NMIs are
19919 * executing.
19920@@ -1709,8 +2109,7 @@ nested_nmi:
19921
19922 1:
19923 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
19924- leaq -1*8(%rsp), %rdx
19925- movq %rdx, %rsp
19926+ subq $8, %rsp
19927 CFI_ADJUST_CFA_OFFSET 1*8
19928 leaq -10*8(%rsp), %rdx
19929 pushq_cfi $__KERNEL_DS
19930@@ -1728,6 +2127,7 @@ nested_nmi_out:
19931 CFI_RESTORE rdx
19932
19933 /* No need to check faults here */
19934+ pax_force_retaddr_bts
19935 INTERRUPT_RETURN
19936
19937 CFI_RESTORE_STATE
19938@@ -1844,6 +2244,17 @@ end_repeat_nmi:
19939 */
19940 movq %cr2, %r12
19941
19942+#ifdef CONFIG_PAX_MEMORY_UDEREF
19943+ testb $3, CS(%rsp)
19944+ jnz 1f
19945+ pax_enter_kernel
19946+ jmp 2f
19947+1: pax_enter_kernel_user
19948+2:
19949+#else
19950+ pax_enter_kernel
19951+#endif
19952+
19953 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
19954 movq %rsp,%rdi
19955 movq $-1,%rsi
19956@@ -1859,23 +2270,34 @@ end_repeat_nmi:
19957 testl %ebx,%ebx /* swapgs needed? */
19958 jnz nmi_restore
19959 nmi_swapgs:
19960+#ifdef CONFIG_PAX_MEMORY_UDEREF
19961+ pax_exit_kernel_user
19962+#else
19963+ pax_exit_kernel
19964+#endif
19965 SWAPGS_UNSAFE_STACK
19966+ RESTORE_ALL 6*8
19967+ /* Clear the NMI executing stack variable */
19968+ movq $0, 5*8(%rsp)
19969+ jmp irq_return
19970 nmi_restore:
19971+ pax_exit_kernel
19972 /* Pop the extra iret frame at once */
19973 RESTORE_ALL 6*8
19974+ pax_force_retaddr_bts
19975
19976 /* Clear the NMI executing stack variable */
19977 movq $0, 5*8(%rsp)
19978 jmp irq_return
19979 CFI_ENDPROC
19980-END(nmi)
19981+ENDPROC(nmi)
19982
19983 ENTRY(ignore_sysret)
19984 CFI_STARTPROC
19985 mov $-ENOSYS,%eax
19986 sysret
19987 CFI_ENDPROC
19988-END(ignore_sysret)
19989+ENDPROC(ignore_sysret)
19990
19991 /*
19992 * End of kprobes section
19993diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
19994index 42a392a..fbbd930 100644
19995--- a/arch/x86/kernel/ftrace.c
19996+++ b/arch/x86/kernel/ftrace.c
19997@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
19998 {
19999 unsigned char replaced[MCOUNT_INSN_SIZE];
20000
20001+ ip = ktla_ktva(ip);
20002+
20003 /*
20004 * Note: Due to modules and __init, code can
20005 * disappear and change, we need to protect against faulting
20006@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
20007 unsigned char old[MCOUNT_INSN_SIZE], *new;
20008 int ret;
20009
20010- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
20011+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
20012 new = ftrace_call_replace(ip, (unsigned long)func);
20013
20014 /* See comment above by declaration of modifying_ftrace_code */
20015@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
20016 /* Also update the regs callback function */
20017 if (!ret) {
20018 ip = (unsigned long)(&ftrace_regs_call);
20019- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
20020+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
20021 new = ftrace_call_replace(ip, (unsigned long)func);
20022 ret = ftrace_modify_code(ip, old, new);
20023 }
20024@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
20025 * kernel identity mapping to modify code.
20026 */
20027 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
20028- ip = (unsigned long)__va(__pa_symbol(ip));
20029+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
20030
20031 return probe_kernel_write((void *)ip, val, size);
20032 }
20033@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
20034 unsigned char replaced[MCOUNT_INSN_SIZE];
20035 unsigned char brk = BREAKPOINT_INSTRUCTION;
20036
20037- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
20038+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
20039 return -EFAULT;
20040
20041 /* Make sure it is what we expect it to be */
20042@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
20043 return ret;
20044
20045 fail_update:
20046- probe_kernel_write((void *)ip, &old_code[0], 1);
20047+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
20048 goto out;
20049 }
20050
20051@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
20052 {
20053 unsigned char code[MCOUNT_INSN_SIZE];
20054
20055+ ip = ktla_ktva(ip);
20056+
20057 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
20058 return -EFAULT;
20059
20060diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
20061index 8f3201d..aa860bf 100644
20062--- a/arch/x86/kernel/head64.c
20063+++ b/arch/x86/kernel/head64.c
20064@@ -175,7 +175,6 @@ void __init x86_64_start_kernel(char * real_mode_data)
20065 if (console_loglevel == 10)
20066 early_printk("Kernel alive\n");
20067
20068- clear_page(init_level4_pgt);
20069 /* set init_level4_pgt kernel high mapping*/
20070 init_level4_pgt[511] = early_level4_pgt[511];
20071
20072diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
20073index 73afd11..d1670f5 100644
20074--- a/arch/x86/kernel/head_32.S
20075+++ b/arch/x86/kernel/head_32.S
20076@@ -26,6 +26,12 @@
20077 /* Physical address */
20078 #define pa(X) ((X) - __PAGE_OFFSET)
20079
20080+#ifdef CONFIG_PAX_KERNEXEC
20081+#define ta(X) (X)
20082+#else
20083+#define ta(X) ((X) - __PAGE_OFFSET)
20084+#endif
20085+
20086 /*
20087 * References to members of the new_cpu_data structure.
20088 */
20089@@ -55,11 +61,7 @@
20090 * and small than max_low_pfn, otherwise will waste some page table entries
20091 */
20092
20093-#if PTRS_PER_PMD > 1
20094-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
20095-#else
20096-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
20097-#endif
20098+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
20099
20100 /* Number of possible pages in the lowmem region */
20101 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
20102@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
20103 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
20104
20105 /*
20106+ * Real beginning of normal "text" segment
20107+ */
20108+ENTRY(stext)
20109+ENTRY(_stext)
20110+
20111+/*
20112 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
20113 * %esi points to the real-mode code as a 32-bit pointer.
20114 * CS and DS must be 4 GB flat segments, but we don't depend on
20115@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
20116 * can.
20117 */
20118 __HEAD
20119+
20120+#ifdef CONFIG_PAX_KERNEXEC
20121+ jmp startup_32
20122+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
20123+.fill PAGE_SIZE-5,1,0xcc
20124+#endif
20125+
20126 ENTRY(startup_32)
20127 movl pa(stack_start),%ecx
20128
20129@@ -106,6 +121,59 @@ ENTRY(startup_32)
20130 2:
20131 leal -__PAGE_OFFSET(%ecx),%esp
20132
20133+#ifdef CONFIG_SMP
20134+ movl $pa(cpu_gdt_table),%edi
20135+ movl $__per_cpu_load,%eax
20136+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
20137+ rorl $16,%eax
20138+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
20139+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
20140+ movl $__per_cpu_end - 1,%eax
20141+ subl $__per_cpu_start,%eax
20142+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
20143+#endif
20144+
20145+#ifdef CONFIG_PAX_MEMORY_UDEREF
20146+ movl $NR_CPUS,%ecx
20147+ movl $pa(cpu_gdt_table),%edi
20148+1:
20149+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
20150+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
20151+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
20152+ addl $PAGE_SIZE_asm,%edi
20153+ loop 1b
20154+#endif
20155+
20156+#ifdef CONFIG_PAX_KERNEXEC
20157+ movl $pa(boot_gdt),%edi
20158+ movl $__LOAD_PHYSICAL_ADDR,%eax
20159+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
20160+ rorl $16,%eax
20161+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
20162+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
20163+ rorl $16,%eax
20164+
20165+ ljmp $(__BOOT_CS),$1f
20166+1:
20167+
20168+ movl $NR_CPUS,%ecx
20169+ movl $pa(cpu_gdt_table),%edi
20170+ addl $__PAGE_OFFSET,%eax
20171+1:
20172+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
20173+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
20174+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
20175+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
20176+ rorl $16,%eax
20177+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
20178+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
20179+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
20180+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
20181+ rorl $16,%eax
20182+ addl $PAGE_SIZE_asm,%edi
20183+ loop 1b
20184+#endif
20185+
20186 /*
20187 * Clear BSS first so that there are no surprises...
20188 */
20189@@ -201,8 +269,11 @@ ENTRY(startup_32)
20190 movl %eax, pa(max_pfn_mapped)
20191
20192 /* Do early initialization of the fixmap area */
20193- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20194- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
20195+#ifdef CONFIG_COMPAT_VDSO
20196+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
20197+#else
20198+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
20199+#endif
20200 #else /* Not PAE */
20201
20202 page_pde_offset = (__PAGE_OFFSET >> 20);
20203@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20204 movl %eax, pa(max_pfn_mapped)
20205
20206 /* Do early initialization of the fixmap area */
20207- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20208- movl %eax,pa(initial_page_table+0xffc)
20209+#ifdef CONFIG_COMPAT_VDSO
20210+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
20211+#else
20212+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
20213+#endif
20214 #endif
20215
20216 #ifdef CONFIG_PARAVIRT
20217@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20218 cmpl $num_subarch_entries, %eax
20219 jae bad_subarch
20220
20221- movl pa(subarch_entries)(,%eax,4), %eax
20222- subl $__PAGE_OFFSET, %eax
20223- jmp *%eax
20224+ jmp *pa(subarch_entries)(,%eax,4)
20225
20226 bad_subarch:
20227 WEAK(lguest_entry)
20228@@ -261,10 +333,10 @@ WEAK(xen_entry)
20229 __INITDATA
20230
20231 subarch_entries:
20232- .long default_entry /* normal x86/PC */
20233- .long lguest_entry /* lguest hypervisor */
20234- .long xen_entry /* Xen hypervisor */
20235- .long default_entry /* Moorestown MID */
20236+ .long ta(default_entry) /* normal x86/PC */
20237+ .long ta(lguest_entry) /* lguest hypervisor */
20238+ .long ta(xen_entry) /* Xen hypervisor */
20239+ .long ta(default_entry) /* Moorestown MID */
20240 num_subarch_entries = (. - subarch_entries) / 4
20241 .previous
20242 #else
20243@@ -355,6 +427,7 @@ default_entry:
20244 movl pa(mmu_cr4_features),%eax
20245 movl %eax,%cr4
20246
20247+#ifdef CONFIG_X86_PAE
20248 testb $X86_CR4_PAE, %al # check if PAE is enabled
20249 jz enable_paging
20250
20251@@ -383,6 +456,9 @@ default_entry:
20252 /* Make changes effective */
20253 wrmsr
20254
20255+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
20256+#endif
20257+
20258 enable_paging:
20259
20260 /*
20261@@ -451,14 +527,20 @@ is486:
20262 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
20263 movl %eax,%ss # after changing gdt.
20264
20265- movl $(__USER_DS),%eax # DS/ES contains default USER segment
20266+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
20267 movl %eax,%ds
20268 movl %eax,%es
20269
20270 movl $(__KERNEL_PERCPU), %eax
20271 movl %eax,%fs # set this cpu's percpu
20272
20273+#ifdef CONFIG_CC_STACKPROTECTOR
20274 movl $(__KERNEL_STACK_CANARY),%eax
20275+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20276+ movl $(__USER_DS),%eax
20277+#else
20278+ xorl %eax,%eax
20279+#endif
20280 movl %eax,%gs
20281
20282 xorl %eax,%eax # Clear LDT
20283@@ -534,8 +616,11 @@ setup_once:
20284 * relocation. Manually set base address in stack canary
20285 * segment descriptor.
20286 */
20287- movl $gdt_page,%eax
20288+ movl $cpu_gdt_table,%eax
20289 movl $stack_canary,%ecx
20290+#ifdef CONFIG_SMP
20291+ addl $__per_cpu_load,%ecx
20292+#endif
20293 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
20294 shrl $16, %ecx
20295 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
20296@@ -566,7 +651,7 @@ ENDPROC(early_idt_handlers)
20297 /* This is global to keep gas from relaxing the jumps */
20298 ENTRY(early_idt_handler)
20299 cld
20300- cmpl $2,%ss:early_recursion_flag
20301+ cmpl $1,%ss:early_recursion_flag
20302 je hlt_loop
20303 incl %ss:early_recursion_flag
20304
20305@@ -604,8 +689,8 @@ ENTRY(early_idt_handler)
20306 pushl (20+6*4)(%esp) /* trapno */
20307 pushl $fault_msg
20308 call printk
20309-#endif
20310 call dump_stack
20311+#endif
20312 hlt_loop:
20313 hlt
20314 jmp hlt_loop
20315@@ -624,8 +709,11 @@ ENDPROC(early_idt_handler)
20316 /* This is the default interrupt "handler" :-) */
20317 ALIGN
20318 ignore_int:
20319- cld
20320 #ifdef CONFIG_PRINTK
20321+ cmpl $2,%ss:early_recursion_flag
20322+ je hlt_loop
20323+ incl %ss:early_recursion_flag
20324+ cld
20325 pushl %eax
20326 pushl %ecx
20327 pushl %edx
20328@@ -634,9 +722,6 @@ ignore_int:
20329 movl $(__KERNEL_DS),%eax
20330 movl %eax,%ds
20331 movl %eax,%es
20332- cmpl $2,early_recursion_flag
20333- je hlt_loop
20334- incl early_recursion_flag
20335 pushl 16(%esp)
20336 pushl 24(%esp)
20337 pushl 32(%esp)
20338@@ -670,29 +755,43 @@ ENTRY(setup_once_ref)
20339 /*
20340 * BSS section
20341 */
20342-__PAGE_ALIGNED_BSS
20343- .align PAGE_SIZE
20344 #ifdef CONFIG_X86_PAE
20345+.section .initial_pg_pmd,"a",@progbits
20346 initial_pg_pmd:
20347 .fill 1024*KPMDS,4,0
20348 #else
20349+.section .initial_page_table,"a",@progbits
20350 ENTRY(initial_page_table)
20351 .fill 1024,4,0
20352 #endif
20353+.section .initial_pg_fixmap,"a",@progbits
20354 initial_pg_fixmap:
20355 .fill 1024,4,0
20356+.section .empty_zero_page,"a",@progbits
20357 ENTRY(empty_zero_page)
20358 .fill 4096,1,0
20359+.section .swapper_pg_dir,"a",@progbits
20360 ENTRY(swapper_pg_dir)
20361+#ifdef CONFIG_X86_PAE
20362+ .fill 4,8,0
20363+#else
20364 .fill 1024,4,0
20365+#endif
20366+
20367+/*
20368+ * The IDT has to be page-aligned to simplify the Pentium
20369+ * F0 0F bug workaround.. We have a special link segment
20370+ * for this.
20371+ */
20372+.section .idt,"a",@progbits
20373+ENTRY(idt_table)
20374+ .fill 256,8,0
20375
20376 /*
20377 * This starts the data section.
20378 */
20379 #ifdef CONFIG_X86_PAE
20380-__PAGE_ALIGNED_DATA
20381- /* Page-aligned for the benefit of paravirt? */
20382- .align PAGE_SIZE
20383+.section .initial_page_table,"a",@progbits
20384 ENTRY(initial_page_table)
20385 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
20386 # if KPMDS == 3
20387@@ -711,12 +810,20 @@ ENTRY(initial_page_table)
20388 # error "Kernel PMDs should be 1, 2 or 3"
20389 # endif
20390 .align PAGE_SIZE /* needs to be page-sized too */
20391+
20392+#ifdef CONFIG_PAX_PER_CPU_PGD
20393+ENTRY(cpu_pgd)
20394+ .rept NR_CPUS
20395+ .fill 4,8,0
20396+ .endr
20397+#endif
20398+
20399 #endif
20400
20401 .data
20402 .balign 4
20403 ENTRY(stack_start)
20404- .long init_thread_union+THREAD_SIZE
20405+ .long init_thread_union+THREAD_SIZE-8
20406
20407 __INITRODATA
20408 int_msg:
20409@@ -744,7 +851,7 @@ fault_msg:
20410 * segment size, and 32-bit linear address value:
20411 */
20412
20413- .data
20414+.section .rodata,"a",@progbits
20415 .globl boot_gdt_descr
20416 .globl idt_descr
20417
20418@@ -753,7 +860,7 @@ fault_msg:
20419 .word 0 # 32 bit align gdt_desc.address
20420 boot_gdt_descr:
20421 .word __BOOT_DS+7
20422- .long boot_gdt - __PAGE_OFFSET
20423+ .long pa(boot_gdt)
20424
20425 .word 0 # 32-bit align idt_desc.address
20426 idt_descr:
20427@@ -764,7 +871,7 @@ idt_descr:
20428 .word 0 # 32 bit align gdt_desc.address
20429 ENTRY(early_gdt_descr)
20430 .word GDT_ENTRIES*8-1
20431- .long gdt_page /* Overwritten for secondary CPUs */
20432+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
20433
20434 /*
20435 * The boot_gdt must mirror the equivalent in setup.S and is
20436@@ -773,5 +880,65 @@ ENTRY(early_gdt_descr)
20437 .align L1_CACHE_BYTES
20438 ENTRY(boot_gdt)
20439 .fill GDT_ENTRY_BOOT_CS,8,0
20440- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
20441- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
20442+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
20443+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
20444+
20445+ .align PAGE_SIZE_asm
20446+ENTRY(cpu_gdt_table)
20447+ .rept NR_CPUS
20448+ .quad 0x0000000000000000 /* NULL descriptor */
20449+ .quad 0x0000000000000000 /* 0x0b reserved */
20450+ .quad 0x0000000000000000 /* 0x13 reserved */
20451+ .quad 0x0000000000000000 /* 0x1b reserved */
20452+
20453+#ifdef CONFIG_PAX_KERNEXEC
20454+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
20455+#else
20456+ .quad 0x0000000000000000 /* 0x20 unused */
20457+#endif
20458+
20459+ .quad 0x0000000000000000 /* 0x28 unused */
20460+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
20461+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
20462+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
20463+ .quad 0x0000000000000000 /* 0x4b reserved */
20464+ .quad 0x0000000000000000 /* 0x53 reserved */
20465+ .quad 0x0000000000000000 /* 0x5b reserved */
20466+
20467+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
20468+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
20469+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
20470+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
20471+
20472+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
20473+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
20474+
20475+ /*
20476+ * Segments used for calling PnP BIOS have byte granularity.
20477+ * The code segments and data segments have fixed 64k limits,
20478+ * the transfer segment sizes are set at run time.
20479+ */
20480+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
20481+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
20482+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
20483+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
20484+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
20485+
20486+ /*
20487+ * The APM segments have byte granularity and their bases
20488+ * are set at run time. All have 64k limits.
20489+ */
20490+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
20491+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
20492+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
20493+
20494+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
20495+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
20496+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
20497+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
20498+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
20499+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
20500+
20501+ /* Be sure this is zeroed to avoid false validations in Xen */
20502+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
20503+ .endr
20504diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
20505index 321d65e..e9437f7 100644
20506--- a/arch/x86/kernel/head_64.S
20507+++ b/arch/x86/kernel/head_64.S
20508@@ -20,6 +20,8 @@
20509 #include <asm/processor-flags.h>
20510 #include <asm/percpu.h>
20511 #include <asm/nops.h>
20512+#include <asm/cpufeature.h>
20513+#include <asm/alternative-asm.h>
20514
20515 #ifdef CONFIG_PARAVIRT
20516 #include <asm/asm-offsets.h>
20517@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
20518 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
20519 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
20520 L3_START_KERNEL = pud_index(__START_KERNEL_map)
20521+L4_VMALLOC_START = pgd_index(VMALLOC_START)
20522+L3_VMALLOC_START = pud_index(VMALLOC_START)
20523+L4_VMALLOC_END = pgd_index(VMALLOC_END)
20524+L3_VMALLOC_END = pud_index(VMALLOC_END)
20525+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
20526+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
20527
20528 .text
20529 __HEAD
20530@@ -89,11 +97,15 @@ startup_64:
20531 * Fixup the physical addresses in the page table
20532 */
20533 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
20534+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
20535+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
20536+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
20537
20538 addq %rbp, level3_kernel_pgt + (510*8)(%rip)
20539 addq %rbp, level3_kernel_pgt + (511*8)(%rip)
20540
20541 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
20542+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
20543
20544 /*
20545 * Set up the identity mapping for the switchover. These
20546@@ -177,8 +189,8 @@ ENTRY(secondary_startup_64)
20547 movq $(init_level4_pgt - __START_KERNEL_map), %rax
20548 1:
20549
20550- /* Enable PAE mode and PGE */
20551- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
20552+ /* Enable PAE mode and PSE/PGE */
20553+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
20554 movq %rcx, %cr4
20555
20556 /* Setup early boot stage 4 level pagetables. */
20557@@ -199,10 +211,18 @@ ENTRY(secondary_startup_64)
20558 movl $MSR_EFER, %ecx
20559 rdmsr
20560 btsl $_EFER_SCE, %eax /* Enable System Call */
20561- btl $20,%edi /* No Execute supported? */
20562+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
20563 jnc 1f
20564 btsl $_EFER_NX, %eax
20565 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
20566+ leaq init_level4_pgt(%rip), %rdi
20567+#ifndef CONFIG_EFI
20568+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
20569+#endif
20570+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
20571+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
20572+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
20573+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
20574 1: wrmsr /* Make changes effective */
20575
20576 /* Setup cr0 */
20577@@ -282,6 +302,7 @@ ENTRY(secondary_startup_64)
20578 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
20579 * address given in m16:64.
20580 */
20581+ pax_set_fptr_mask
20582 movq initial_code(%rip),%rax
20583 pushq $0 # fake return address to stop unwinder
20584 pushq $__KERNEL_CS # set correct cs
20585@@ -388,7 +409,7 @@ ENTRY(early_idt_handler)
20586 call dump_stack
20587 #ifdef CONFIG_KALLSYMS
20588 leaq early_idt_ripmsg(%rip),%rdi
20589- movq 40(%rsp),%rsi # %rip again
20590+ movq 88(%rsp),%rsi # %rip again
20591 call __print_symbol
20592 #endif
20593 #endif /* EARLY_PRINTK */
20594@@ -416,6 +437,7 @@ ENDPROC(early_idt_handler)
20595 early_recursion_flag:
20596 .long 0
20597
20598+ .section .rodata,"a",@progbits
20599 #ifdef CONFIG_EARLY_PRINTK
20600 early_idt_msg:
20601 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
20602@@ -445,27 +467,50 @@ NEXT_PAGE(early_dynamic_pgts)
20603
20604 .data
20605
20606-#ifndef CONFIG_XEN
20607 NEXT_PAGE(init_level4_pgt)
20608- .fill 512,8,0
20609-#else
20610-NEXT_PAGE(init_level4_pgt)
20611- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20612 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
20613 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20614+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
20615+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
20616+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
20617+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
20618+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
20619+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20620 .org init_level4_pgt + L4_START_KERNEL*8, 0
20621 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
20622 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
20623
20624+#ifdef CONFIG_PAX_PER_CPU_PGD
20625+NEXT_PAGE(cpu_pgd)
20626+ .rept NR_CPUS
20627+ .fill 512,8,0
20628+ .endr
20629+#endif
20630+
20631 NEXT_PAGE(level3_ident_pgt)
20632 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20633+#ifdef CONFIG_XEN
20634 .fill 511, 8, 0
20635+#else
20636+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
20637+ .fill 510,8,0
20638+#endif
20639+
20640+NEXT_PAGE(level3_vmalloc_start_pgt)
20641+ .fill 512,8,0
20642+
20643+NEXT_PAGE(level3_vmalloc_end_pgt)
20644+ .fill 512,8,0
20645+
20646+NEXT_PAGE(level3_vmemmap_pgt)
20647+ .fill L3_VMEMMAP_START,8,0
20648+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20649+
20650 NEXT_PAGE(level2_ident_pgt)
20651- /* Since I easily can, map the first 1G.
20652+ /* Since I easily can, map the first 2G.
20653 * Don't set NX because code runs from these pages.
20654 */
20655- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
20656-#endif
20657+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
20658
20659 NEXT_PAGE(level3_kernel_pgt)
20660 .fill L3_START_KERNEL,8,0
20661@@ -473,6 +518,9 @@ NEXT_PAGE(level3_kernel_pgt)
20662 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
20663 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20664
20665+NEXT_PAGE(level2_vmemmap_pgt)
20666+ .fill 512,8,0
20667+
20668 NEXT_PAGE(level2_kernel_pgt)
20669 /*
20670 * 512 MB kernel mapping. We spend a full page on this pagetable
20671@@ -488,38 +536,64 @@ NEXT_PAGE(level2_kernel_pgt)
20672 KERNEL_IMAGE_SIZE/PMD_SIZE)
20673
20674 NEXT_PAGE(level2_fixmap_pgt)
20675- .fill 506,8,0
20676- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20677- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
20678- .fill 5,8,0
20679+ .fill 507,8,0
20680+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
20681+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
20682+ .fill 4,8,0
20683
20684-NEXT_PAGE(level1_fixmap_pgt)
20685+NEXT_PAGE(level1_vsyscall_pgt)
20686 .fill 512,8,0
20687
20688 #undef PMDS
20689
20690- .data
20691+ .align PAGE_SIZE
20692+ENTRY(cpu_gdt_table)
20693+ .rept NR_CPUS
20694+ .quad 0x0000000000000000 /* NULL descriptor */
20695+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
20696+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
20697+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
20698+ .quad 0x00cffb000000ffff /* __USER32_CS */
20699+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
20700+ .quad 0x00affb000000ffff /* __USER_CS */
20701+
20702+#ifdef CONFIG_PAX_KERNEXEC
20703+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
20704+#else
20705+ .quad 0x0 /* unused */
20706+#endif
20707+
20708+ .quad 0,0 /* TSS */
20709+ .quad 0,0 /* LDT */
20710+ .quad 0,0,0 /* three TLS descriptors */
20711+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
20712+ /* asm/segment.h:GDT_ENTRIES must match this */
20713+
20714+ /* zero the remaining page */
20715+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
20716+ .endr
20717+
20718 .align 16
20719 .globl early_gdt_descr
20720 early_gdt_descr:
20721 .word GDT_ENTRIES*8-1
20722 early_gdt_descr_base:
20723- .quad INIT_PER_CPU_VAR(gdt_page)
20724+ .quad cpu_gdt_table
20725
20726 ENTRY(phys_base)
20727 /* This must match the first entry in level2_kernel_pgt */
20728 .quad 0x0000000000000000
20729
20730 #include "../../x86/xen/xen-head.S"
20731-
20732- .section .bss, "aw", @nobits
20733+
20734+ .section .rodata,"a",@progbits
20735 .align L1_CACHE_BYTES
20736 ENTRY(idt_table)
20737- .skip IDT_ENTRIES * 16
20738+ .fill 512,8,0
20739
20740 .align L1_CACHE_BYTES
20741 ENTRY(nmi_idt_table)
20742- .skip IDT_ENTRIES * 16
20743+ .fill 512,8,0
20744
20745 __PAGE_ALIGNED_BSS
20746 NEXT_PAGE(empty_zero_page)
20747diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
20748index 0fa6912..37fce70 100644
20749--- a/arch/x86/kernel/i386_ksyms_32.c
20750+++ b/arch/x86/kernel/i386_ksyms_32.c
20751@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
20752 EXPORT_SYMBOL(cmpxchg8b_emu);
20753 #endif
20754
20755+EXPORT_SYMBOL_GPL(cpu_gdt_table);
20756+
20757 /* Networking helper routines. */
20758 EXPORT_SYMBOL(csum_partial_copy_generic);
20759+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
20760+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
20761
20762 EXPORT_SYMBOL(__get_user_1);
20763 EXPORT_SYMBOL(__get_user_2);
20764@@ -37,3 +41,7 @@ EXPORT_SYMBOL(strstr);
20765
20766 EXPORT_SYMBOL(csum_partial);
20767 EXPORT_SYMBOL(empty_zero_page);
20768+
20769+#ifdef CONFIG_PAX_KERNEXEC
20770+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
20771+#endif
20772diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
20773index cb33909..1163b40 100644
20774--- a/arch/x86/kernel/i387.c
20775+++ b/arch/x86/kernel/i387.c
20776@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
20777 static inline bool interrupted_user_mode(void)
20778 {
20779 struct pt_regs *regs = get_irq_regs();
20780- return regs && user_mode_vm(regs);
20781+ return regs && user_mode(regs);
20782 }
20783
20784 /*
20785diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
20786index 9a5c460..84868423 100644
20787--- a/arch/x86/kernel/i8259.c
20788+++ b/arch/x86/kernel/i8259.c
20789@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
20790 static void make_8259A_irq(unsigned int irq)
20791 {
20792 disable_irq_nosync(irq);
20793- io_apic_irqs &= ~(1<<irq);
20794+ io_apic_irqs &= ~(1UL<<irq);
20795 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
20796 i8259A_chip.name);
20797 enable_irq(irq);
20798@@ -209,7 +209,7 @@ spurious_8259A_irq:
20799 "spurious 8259A interrupt: IRQ%d.\n", irq);
20800 spurious_irq_mask |= irqmask;
20801 }
20802- atomic_inc(&irq_err_count);
20803+ atomic_inc_unchecked(&irq_err_count);
20804 /*
20805 * Theoretically we do not have to handle this IRQ,
20806 * but in Linux this does not cause problems and is
20807@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
20808 /* (slave's support for AEOI in flat mode is to be investigated) */
20809 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
20810
20811+ pax_open_kernel();
20812 if (auto_eoi)
20813 /*
20814 * In AEOI mode we just have to mask the interrupt
20815 * when acking.
20816 */
20817- i8259A_chip.irq_mask_ack = disable_8259A_irq;
20818+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
20819 else
20820- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20821+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20822+ pax_close_kernel();
20823
20824 udelay(100); /* wait for 8259A to initialize */
20825
20826diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
20827index a979b5b..1d6db75 100644
20828--- a/arch/x86/kernel/io_delay.c
20829+++ b/arch/x86/kernel/io_delay.c
20830@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
20831 * Quirk table for systems that misbehave (lock up, etc.) if port
20832 * 0x80 is used:
20833 */
20834-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
20835+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
20836 {
20837 .callback = dmi_io_delay_0xed_port,
20838 .ident = "Compaq Presario V6000",
20839diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
20840index 4ddaf66..6292f4e 100644
20841--- a/arch/x86/kernel/ioport.c
20842+++ b/arch/x86/kernel/ioport.c
20843@@ -6,6 +6,7 @@
20844 #include <linux/sched.h>
20845 #include <linux/kernel.h>
20846 #include <linux/capability.h>
20847+#include <linux/security.h>
20848 #include <linux/errno.h>
20849 #include <linux/types.h>
20850 #include <linux/ioport.h>
20851@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20852
20853 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
20854 return -EINVAL;
20855+#ifdef CONFIG_GRKERNSEC_IO
20856+ if (turn_on && grsec_disable_privio) {
20857+ gr_handle_ioperm();
20858+ return -EPERM;
20859+ }
20860+#endif
20861 if (turn_on && !capable(CAP_SYS_RAWIO))
20862 return -EPERM;
20863
20864@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20865 * because the ->io_bitmap_max value must match the bitmap
20866 * contents:
20867 */
20868- tss = &per_cpu(init_tss, get_cpu());
20869+ tss = init_tss + get_cpu();
20870
20871 if (turn_on)
20872 bitmap_clear(t->io_bitmap_ptr, from, num);
20873@@ -103,6 +110,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
20874 return -EINVAL;
20875 /* Trying to gain more privileges? */
20876 if (level > old) {
20877+#ifdef CONFIG_GRKERNSEC_IO
20878+ if (grsec_disable_privio) {
20879+ gr_handle_iopl();
20880+ return -EPERM;
20881+ }
20882+#endif
20883 if (!capable(CAP_SYS_RAWIO))
20884 return -EPERM;
20885 }
20886diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
20887index 84b7789..e65e8be 100644
20888--- a/arch/x86/kernel/irq.c
20889+++ b/arch/x86/kernel/irq.c
20890@@ -18,7 +18,7 @@
20891 #include <asm/mce.h>
20892 #include <asm/hw_irq.h>
20893
20894-atomic_t irq_err_count;
20895+atomic_unchecked_t irq_err_count;
20896
20897 /* Function pointer for generic interrupt vector handling */
20898 void (*x86_platform_ipi_callback)(void) = NULL;
20899@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
20900 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
20901 seq_printf(p, " Machine check polls\n");
20902 #endif
20903- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
20904+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
20905 #if defined(CONFIG_X86_IO_APIC)
20906- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
20907+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
20908 #endif
20909 return 0;
20910 }
20911@@ -164,7 +164,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
20912
20913 u64 arch_irq_stat(void)
20914 {
20915- u64 sum = atomic_read(&irq_err_count);
20916+ u64 sum = atomic_read_unchecked(&irq_err_count);
20917 return sum;
20918 }
20919
20920diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
20921index 344faf8..355f60d 100644
20922--- a/arch/x86/kernel/irq_32.c
20923+++ b/arch/x86/kernel/irq_32.c
20924@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
20925 __asm__ __volatile__("andl %%esp,%0" :
20926 "=r" (sp) : "0" (THREAD_SIZE - 1));
20927
20928- return sp < (sizeof(struct thread_info) + STACK_WARN);
20929+ return sp < STACK_WARN;
20930 }
20931
20932 static void print_stack_overflow(void)
20933@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
20934 * per-CPU IRQ handling contexts (thread information and stack)
20935 */
20936 union irq_ctx {
20937- struct thread_info tinfo;
20938- u32 stack[THREAD_SIZE/sizeof(u32)];
20939+ unsigned long previous_esp;
20940+ u32 stack[THREAD_SIZE/sizeof(u32)];
20941 } __attribute__((aligned(THREAD_SIZE)));
20942
20943 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
20944@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
20945 static inline int
20946 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20947 {
20948- union irq_ctx *curctx, *irqctx;
20949+ union irq_ctx *irqctx;
20950 u32 *isp, arg1, arg2;
20951
20952- curctx = (union irq_ctx *) current_thread_info();
20953 irqctx = __this_cpu_read(hardirq_ctx);
20954
20955 /*
20956@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20957 * handler) we can't do that and just have to keep using the
20958 * current stack (which is the irq stack already after all)
20959 */
20960- if (unlikely(curctx == irqctx))
20961+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
20962 return 0;
20963
20964 /* build the stack frame on the IRQ stack */
20965- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20966- irqctx->tinfo.task = curctx->tinfo.task;
20967- irqctx->tinfo.previous_esp = current_stack_pointer;
20968+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20969+ irqctx->previous_esp = current_stack_pointer;
20970
20971- /* Copy the preempt_count so that the [soft]irq checks work. */
20972- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
20973+#ifdef CONFIG_PAX_MEMORY_UDEREF
20974+ __set_fs(MAKE_MM_SEG(0));
20975+#endif
20976
20977 if (unlikely(overflow))
20978 call_on_stack(print_stack_overflow, isp);
20979@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20980 : "0" (irq), "1" (desc), "2" (isp),
20981 "D" (desc->handle_irq)
20982 : "memory", "cc", "ecx");
20983+
20984+#ifdef CONFIG_PAX_MEMORY_UDEREF
20985+ __set_fs(current_thread_info()->addr_limit);
20986+#endif
20987+
20988 return 1;
20989 }
20990
20991@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20992 */
20993 void __cpuinit irq_ctx_init(int cpu)
20994 {
20995- union irq_ctx *irqctx;
20996-
20997 if (per_cpu(hardirq_ctx, cpu))
20998 return;
20999
21000- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
21001- THREADINFO_GFP,
21002- THREAD_SIZE_ORDER));
21003- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
21004- irqctx->tinfo.cpu = cpu;
21005- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
21006- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
21007-
21008- per_cpu(hardirq_ctx, cpu) = irqctx;
21009-
21010- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
21011- THREADINFO_GFP,
21012- THREAD_SIZE_ORDER));
21013- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
21014- irqctx->tinfo.cpu = cpu;
21015- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
21016-
21017- per_cpu(softirq_ctx, cpu) = irqctx;
21018+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
21019+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
21020+
21021+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
21022+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
21023
21024 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
21025 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
21026@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
21027 asmlinkage void do_softirq(void)
21028 {
21029 unsigned long flags;
21030- struct thread_info *curctx;
21031 union irq_ctx *irqctx;
21032 u32 *isp;
21033
21034@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
21035 local_irq_save(flags);
21036
21037 if (local_softirq_pending()) {
21038- curctx = current_thread_info();
21039 irqctx = __this_cpu_read(softirq_ctx);
21040- irqctx->tinfo.task = curctx->task;
21041- irqctx->tinfo.previous_esp = current_stack_pointer;
21042+ irqctx->previous_esp = current_stack_pointer;
21043
21044 /* build the stack frame on the softirq stack */
21045- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
21046+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
21047+
21048+#ifdef CONFIG_PAX_MEMORY_UDEREF
21049+ __set_fs(MAKE_MM_SEG(0));
21050+#endif
21051
21052 call_on_stack(__do_softirq, isp);
21053+
21054+#ifdef CONFIG_PAX_MEMORY_UDEREF
21055+ __set_fs(current_thread_info()->addr_limit);
21056+#endif
21057+
21058 /*
21059 * Shouldn't happen, we returned above if in_interrupt():
21060 */
21061@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
21062 if (unlikely(!desc))
21063 return false;
21064
21065- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21066+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21067 if (unlikely(overflow))
21068 print_stack_overflow();
21069 desc->handle_irq(irq, desc);
21070diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
21071index d04d3ec..ea4b374 100644
21072--- a/arch/x86/kernel/irq_64.c
21073+++ b/arch/x86/kernel/irq_64.c
21074@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
21075 u64 estack_top, estack_bottom;
21076 u64 curbase = (u64)task_stack_page(current);
21077
21078- if (user_mode_vm(regs))
21079+ if (user_mode(regs))
21080 return;
21081
21082 if (regs->sp >= curbase + sizeof(struct thread_info) +
21083diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
21084index dc1404b..bbc43e7 100644
21085--- a/arch/x86/kernel/kdebugfs.c
21086+++ b/arch/x86/kernel/kdebugfs.c
21087@@ -27,7 +27,7 @@ struct setup_data_node {
21088 u32 len;
21089 };
21090
21091-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
21092+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
21093 size_t count, loff_t *ppos)
21094 {
21095 struct setup_data_node *node = file->private_data;
21096diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
21097index 836f832..a8bda67 100644
21098--- a/arch/x86/kernel/kgdb.c
21099+++ b/arch/x86/kernel/kgdb.c
21100@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
21101 #ifdef CONFIG_X86_32
21102 switch (regno) {
21103 case GDB_SS:
21104- if (!user_mode_vm(regs))
21105+ if (!user_mode(regs))
21106 *(unsigned long *)mem = __KERNEL_DS;
21107 break;
21108 case GDB_SP:
21109- if (!user_mode_vm(regs))
21110+ if (!user_mode(regs))
21111 *(unsigned long *)mem = kernel_stack_pointer(regs);
21112 break;
21113 case GDB_GS:
21114@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
21115 bp->attr.bp_addr = breakinfo[breakno].addr;
21116 bp->attr.bp_len = breakinfo[breakno].len;
21117 bp->attr.bp_type = breakinfo[breakno].type;
21118- info->address = breakinfo[breakno].addr;
21119+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
21120+ info->address = ktla_ktva(breakinfo[breakno].addr);
21121+ else
21122+ info->address = breakinfo[breakno].addr;
21123 info->len = breakinfo[breakno].len;
21124 info->type = breakinfo[breakno].type;
21125 val = arch_install_hw_breakpoint(bp);
21126@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
21127 case 'k':
21128 /* clear the trace bit */
21129 linux_regs->flags &= ~X86_EFLAGS_TF;
21130- atomic_set(&kgdb_cpu_doing_single_step, -1);
21131+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
21132
21133 /* set the trace bit if we're stepping */
21134 if (remcomInBuffer[0] == 's') {
21135 linux_regs->flags |= X86_EFLAGS_TF;
21136- atomic_set(&kgdb_cpu_doing_single_step,
21137+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
21138 raw_smp_processor_id());
21139 }
21140
21141@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
21142
21143 switch (cmd) {
21144 case DIE_DEBUG:
21145- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
21146+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
21147 if (user_mode(regs))
21148 return single_step_cont(regs, args);
21149 break;
21150@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21151 #endif /* CONFIG_DEBUG_RODATA */
21152
21153 bpt->type = BP_BREAKPOINT;
21154- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
21155+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
21156 BREAK_INSTR_SIZE);
21157 if (err)
21158 return err;
21159- err = probe_kernel_write((char *)bpt->bpt_addr,
21160+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21161 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
21162 #ifdef CONFIG_DEBUG_RODATA
21163 if (!err)
21164@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21165 return -EBUSY;
21166 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
21167 BREAK_INSTR_SIZE);
21168- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21169+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21170 if (err)
21171 return err;
21172 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
21173@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
21174 if (mutex_is_locked(&text_mutex))
21175 goto knl_write;
21176 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
21177- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21178+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21179 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
21180 goto knl_write;
21181 return err;
21182 knl_write:
21183 #endif /* CONFIG_DEBUG_RODATA */
21184- return probe_kernel_write((char *)bpt->bpt_addr,
21185+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21186 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
21187 }
21188
21189diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
21190index 7bfe318..383d238 100644
21191--- a/arch/x86/kernel/kprobes/core.c
21192+++ b/arch/x86/kernel/kprobes/core.c
21193@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
21194 s32 raddr;
21195 } __packed *insn;
21196
21197- insn = (struct __arch_relative_insn *)from;
21198+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
21199+
21200+ pax_open_kernel();
21201 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
21202 insn->op = op;
21203+ pax_close_kernel();
21204 }
21205
21206 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
21207@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
21208 kprobe_opcode_t opcode;
21209 kprobe_opcode_t *orig_opcodes = opcodes;
21210
21211- if (search_exception_tables((unsigned long)opcodes))
21212+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
21213 return 0; /* Page fault may occur on this address. */
21214
21215 retry:
21216@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
21217 * for the first byte, we can recover the original instruction
21218 * from it and kp->opcode.
21219 */
21220- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21221+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21222 buf[0] = kp->opcode;
21223- return (unsigned long)buf;
21224+ return ktva_ktla((unsigned long)buf);
21225 }
21226
21227 /*
21228@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21229 /* Another subsystem puts a breakpoint, failed to recover */
21230 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
21231 return 0;
21232+ pax_open_kernel();
21233 memcpy(dest, insn.kaddr, insn.length);
21234+ pax_close_kernel();
21235
21236 #ifdef CONFIG_X86_64
21237 if (insn_rip_relative(&insn)) {
21238@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21239 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
21240 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
21241 disp = (u8 *) dest + insn_offset_displacement(&insn);
21242+ pax_open_kernel();
21243 *(s32 *) disp = (s32) newdisp;
21244+ pax_close_kernel();
21245 }
21246 #endif
21247 return insn.length;
21248@@ -488,7 +495,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21249 * nor set current_kprobe, because it doesn't use single
21250 * stepping.
21251 */
21252- regs->ip = (unsigned long)p->ainsn.insn;
21253+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21254 preempt_enable_no_resched();
21255 return;
21256 }
21257@@ -505,9 +512,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21258 regs->flags &= ~X86_EFLAGS_IF;
21259 /* single step inline if the instruction is an int3 */
21260 if (p->opcode == BREAKPOINT_INSTRUCTION)
21261- regs->ip = (unsigned long)p->addr;
21262+ regs->ip = ktla_ktva((unsigned long)p->addr);
21263 else
21264- regs->ip = (unsigned long)p->ainsn.insn;
21265+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21266 }
21267
21268 /*
21269@@ -586,7 +593,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
21270 setup_singlestep(p, regs, kcb, 0);
21271 return 1;
21272 }
21273- } else if (*addr != BREAKPOINT_INSTRUCTION) {
21274+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
21275 /*
21276 * The breakpoint instruction was removed right
21277 * after we hit it. Another cpu has removed
21278@@ -632,6 +639,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
21279 " movq %rax, 152(%rsp)\n"
21280 RESTORE_REGS_STRING
21281 " popfq\n"
21282+#ifdef KERNEXEC_PLUGIN
21283+ " btsq $63,(%rsp)\n"
21284+#endif
21285 #else
21286 " pushf\n"
21287 SAVE_REGS_STRING
21288@@ -769,7 +779,7 @@ static void __kprobes
21289 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
21290 {
21291 unsigned long *tos = stack_addr(regs);
21292- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
21293+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
21294 unsigned long orig_ip = (unsigned long)p->addr;
21295 kprobe_opcode_t *insn = p->ainsn.insn;
21296
21297@@ -951,7 +961,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
21298 struct die_args *args = data;
21299 int ret = NOTIFY_DONE;
21300
21301- if (args->regs && user_mode_vm(args->regs))
21302+ if (args->regs && user_mode(args->regs))
21303 return ret;
21304
21305 switch (val) {
21306diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
21307index 76dc6f0..66bdfc3 100644
21308--- a/arch/x86/kernel/kprobes/opt.c
21309+++ b/arch/x86/kernel/kprobes/opt.c
21310@@ -79,6 +79,7 @@ found:
21311 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
21312 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
21313 {
21314+ pax_open_kernel();
21315 #ifdef CONFIG_X86_64
21316 *addr++ = 0x48;
21317 *addr++ = 0xbf;
21318@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
21319 *addr++ = 0xb8;
21320 #endif
21321 *(unsigned long *)addr = val;
21322+ pax_close_kernel();
21323 }
21324
21325 static void __used __kprobes kprobes_optinsn_template_holder(void)
21326@@ -338,7 +340,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21327 * Verify if the address gap is in 2GB range, because this uses
21328 * a relative jump.
21329 */
21330- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
21331+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
21332 if (abs(rel) > 0x7fffffff)
21333 return -ERANGE;
21334
21335@@ -353,16 +355,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21336 op->optinsn.size = ret;
21337
21338 /* Copy arch-dep-instance from template */
21339- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
21340+ pax_open_kernel();
21341+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
21342+ pax_close_kernel();
21343
21344 /* Set probe information */
21345 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
21346
21347 /* Set probe function call */
21348- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
21349+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
21350
21351 /* Set returning jmp instruction at the tail of out-of-line buffer */
21352- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
21353+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
21354 (u8 *)op->kp.addr + op->optinsn.size);
21355
21356 flush_icache_range((unsigned long) buf,
21357@@ -385,7 +389,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
21358 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
21359
21360 /* Backup instructions which will be replaced by jump address */
21361- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
21362+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
21363 RELATIVE_ADDR_SIZE);
21364
21365 insn_buf[0] = RELATIVEJUMP_OPCODE;
21366@@ -483,7 +487,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
21367 /* This kprobe is really able to run optimized path. */
21368 op = container_of(p, struct optimized_kprobe, kp);
21369 /* Detour through copied instructions */
21370- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
21371+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
21372 if (!reenter)
21373 reset_current_kprobe();
21374 preempt_enable_no_resched();
21375diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
21376index b686a90..60d36fb 100644
21377--- a/arch/x86/kernel/kvm.c
21378+++ b/arch/x86/kernel/kvm.c
21379@@ -453,7 +453,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
21380 return NOTIFY_OK;
21381 }
21382
21383-static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
21384+static struct notifier_block kvm_cpu_notifier = {
21385 .notifier_call = kvm_cpu_notify,
21386 };
21387 #endif
21388diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
21389index ebc9873..1b9724b 100644
21390--- a/arch/x86/kernel/ldt.c
21391+++ b/arch/x86/kernel/ldt.c
21392@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
21393 if (reload) {
21394 #ifdef CONFIG_SMP
21395 preempt_disable();
21396- load_LDT(pc);
21397+ load_LDT_nolock(pc);
21398 if (!cpumask_equal(mm_cpumask(current->mm),
21399 cpumask_of(smp_processor_id())))
21400 smp_call_function(flush_ldt, current->mm, 1);
21401 preempt_enable();
21402 #else
21403- load_LDT(pc);
21404+ load_LDT_nolock(pc);
21405 #endif
21406 }
21407 if (oldsize) {
21408@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
21409 return err;
21410
21411 for (i = 0; i < old->size; i++)
21412- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
21413+ write_ldt_entry(new->ldt, i, old->ldt + i);
21414 return 0;
21415 }
21416
21417@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
21418 retval = copy_ldt(&mm->context, &old_mm->context);
21419 mutex_unlock(&old_mm->context.lock);
21420 }
21421+
21422+ if (tsk == current) {
21423+ mm->context.vdso = 0;
21424+
21425+#ifdef CONFIG_X86_32
21426+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21427+ mm->context.user_cs_base = 0UL;
21428+ mm->context.user_cs_limit = ~0UL;
21429+
21430+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
21431+ cpus_clear(mm->context.cpu_user_cs_mask);
21432+#endif
21433+
21434+#endif
21435+#endif
21436+
21437+ }
21438+
21439 return retval;
21440 }
21441
21442@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
21443 }
21444 }
21445
21446+#ifdef CONFIG_PAX_SEGMEXEC
21447+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
21448+ error = -EINVAL;
21449+ goto out_unlock;
21450+ }
21451+#endif
21452+
21453 fill_ldt(&ldt, &ldt_info);
21454 if (oldmode)
21455 ldt.avl = 0;
21456diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
21457index 5b19e4d..6476a76 100644
21458--- a/arch/x86/kernel/machine_kexec_32.c
21459+++ b/arch/x86/kernel/machine_kexec_32.c
21460@@ -26,7 +26,7 @@
21461 #include <asm/cacheflush.h>
21462 #include <asm/debugreg.h>
21463
21464-static void set_idt(void *newidt, __u16 limit)
21465+static void set_idt(struct desc_struct *newidt, __u16 limit)
21466 {
21467 struct desc_ptr curidt;
21468
21469@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
21470 }
21471
21472
21473-static void set_gdt(void *newgdt, __u16 limit)
21474+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
21475 {
21476 struct desc_ptr curgdt;
21477
21478@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
21479 }
21480
21481 control_page = page_address(image->control_code_page);
21482- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
21483+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
21484
21485 relocate_kernel_ptr = control_page;
21486 page_list[PA_CONTROL_PAGE] = __pa(control_page);
21487diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
21488index 22db92b..d546bec 100644
21489--- a/arch/x86/kernel/microcode_core.c
21490+++ b/arch/x86/kernel/microcode_core.c
21491@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21492 return NOTIFY_OK;
21493 }
21494
21495-static struct notifier_block __refdata mc_cpu_notifier = {
21496+static struct notifier_block mc_cpu_notifier = {
21497 .notifier_call = mc_cpu_callback,
21498 };
21499
21500diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
21501index 5fb2ceb..3ae90bb 100644
21502--- a/arch/x86/kernel/microcode_intel.c
21503+++ b/arch/x86/kernel/microcode_intel.c
21504@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21505
21506 static int get_ucode_user(void *to, const void *from, size_t n)
21507 {
21508- return copy_from_user(to, from, n);
21509+ return copy_from_user(to, (const void __force_user *)from, n);
21510 }
21511
21512 static enum ucode_state
21513 request_microcode_user(int cpu, const void __user *buf, size_t size)
21514 {
21515- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21516+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21517 }
21518
21519 static void microcode_fini_cpu(int cpu)
21520diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
21521index 216a4d7..228255a 100644
21522--- a/arch/x86/kernel/module.c
21523+++ b/arch/x86/kernel/module.c
21524@@ -43,15 +43,60 @@ do { \
21525 } while (0)
21526 #endif
21527
21528-void *module_alloc(unsigned long size)
21529+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
21530 {
21531- if (PAGE_ALIGN(size) > MODULES_LEN)
21532+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
21533 return NULL;
21534 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
21535- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
21536+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
21537 -1, __builtin_return_address(0));
21538 }
21539
21540+void *module_alloc(unsigned long size)
21541+{
21542+
21543+#ifdef CONFIG_PAX_KERNEXEC
21544+ return __module_alloc(size, PAGE_KERNEL);
21545+#else
21546+ return __module_alloc(size, PAGE_KERNEL_EXEC);
21547+#endif
21548+
21549+}
21550+
21551+#ifdef CONFIG_PAX_KERNEXEC
21552+#ifdef CONFIG_X86_32
21553+void *module_alloc_exec(unsigned long size)
21554+{
21555+ struct vm_struct *area;
21556+
21557+ if (size == 0)
21558+ return NULL;
21559+
21560+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
21561+ return area ? area->addr : NULL;
21562+}
21563+EXPORT_SYMBOL(module_alloc_exec);
21564+
21565+void module_free_exec(struct module *mod, void *module_region)
21566+{
21567+ vunmap(module_region);
21568+}
21569+EXPORT_SYMBOL(module_free_exec);
21570+#else
21571+void module_free_exec(struct module *mod, void *module_region)
21572+{
21573+ module_free(mod, module_region);
21574+}
21575+EXPORT_SYMBOL(module_free_exec);
21576+
21577+void *module_alloc_exec(unsigned long size)
21578+{
21579+ return __module_alloc(size, PAGE_KERNEL_RX);
21580+}
21581+EXPORT_SYMBOL(module_alloc_exec);
21582+#endif
21583+#endif
21584+
21585 #ifdef CONFIG_X86_32
21586 int apply_relocate(Elf32_Shdr *sechdrs,
21587 const char *strtab,
21588@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21589 unsigned int i;
21590 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
21591 Elf32_Sym *sym;
21592- uint32_t *location;
21593+ uint32_t *plocation, location;
21594
21595 DEBUGP("Applying relocate section %u to %u\n",
21596 relsec, sechdrs[relsec].sh_info);
21597 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
21598 /* This is where to make the change */
21599- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
21600- + rel[i].r_offset;
21601+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
21602+ location = (uint32_t)plocation;
21603+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
21604+ plocation = ktla_ktva((void *)plocation);
21605 /* This is the symbol it is referring to. Note that all
21606 undefined symbols have been resolved. */
21607 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
21608@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21609 switch (ELF32_R_TYPE(rel[i].r_info)) {
21610 case R_386_32:
21611 /* We add the value into the location given */
21612- *location += sym->st_value;
21613+ pax_open_kernel();
21614+ *plocation += sym->st_value;
21615+ pax_close_kernel();
21616 break;
21617 case R_386_PC32:
21618 /* Add the value, subtract its position */
21619- *location += sym->st_value - (uint32_t)location;
21620+ pax_open_kernel();
21621+ *plocation += sym->st_value - location;
21622+ pax_close_kernel();
21623 break;
21624 default:
21625 pr_err("%s: Unknown relocation: %u\n",
21626@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
21627 case R_X86_64_NONE:
21628 break;
21629 case R_X86_64_64:
21630+ pax_open_kernel();
21631 *(u64 *)loc = val;
21632+ pax_close_kernel();
21633 break;
21634 case R_X86_64_32:
21635+ pax_open_kernel();
21636 *(u32 *)loc = val;
21637+ pax_close_kernel();
21638 if (val != *(u32 *)loc)
21639 goto overflow;
21640 break;
21641 case R_X86_64_32S:
21642+ pax_open_kernel();
21643 *(s32 *)loc = val;
21644+ pax_close_kernel();
21645 if ((s64)val != *(s32 *)loc)
21646 goto overflow;
21647 break;
21648 case R_X86_64_PC32:
21649 val -= (u64)loc;
21650+ pax_open_kernel();
21651 *(u32 *)loc = val;
21652+ pax_close_kernel();
21653+
21654 #if 0
21655 if ((s64)val != *(s32 *)loc)
21656 goto overflow;
21657diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
21658index ce13049..e2e9c3c 100644
21659--- a/arch/x86/kernel/msr.c
21660+++ b/arch/x86/kernel/msr.c
21661@@ -233,7 +233,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
21662 return notifier_from_errno(err);
21663 }
21664
21665-static struct notifier_block __refdata msr_class_cpu_notifier = {
21666+static struct notifier_block msr_class_cpu_notifier = {
21667 .notifier_call = msr_class_cpu_callback,
21668 };
21669
21670diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
21671index 6030805..2d33f21 100644
21672--- a/arch/x86/kernel/nmi.c
21673+++ b/arch/x86/kernel/nmi.c
21674@@ -105,7 +105,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
21675 return handled;
21676 }
21677
21678-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21679+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
21680 {
21681 struct nmi_desc *desc = nmi_to_desc(type);
21682 unsigned long flags;
21683@@ -129,9 +129,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21684 * event confuses some handlers (kdump uses this flag)
21685 */
21686 if (action->flags & NMI_FLAG_FIRST)
21687- list_add_rcu(&action->list, &desc->head);
21688+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
21689 else
21690- list_add_tail_rcu(&action->list, &desc->head);
21691+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
21692
21693 spin_unlock_irqrestore(&desc->lock, flags);
21694 return 0;
21695@@ -154,7 +154,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
21696 if (!strcmp(n->name, name)) {
21697 WARN(in_nmi(),
21698 "Trying to free NMI (%s) from NMI context!\n", n->name);
21699- list_del_rcu(&n->list);
21700+ pax_list_del_rcu((struct list_head *)&n->list);
21701 break;
21702 }
21703 }
21704@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
21705 dotraplinkage notrace __kprobes void
21706 do_nmi(struct pt_regs *regs, long error_code)
21707 {
21708+
21709+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21710+ if (!user_mode(regs)) {
21711+ unsigned long cs = regs->cs & 0xFFFF;
21712+ unsigned long ip = ktva_ktla(regs->ip);
21713+
21714+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
21715+ regs->ip = ip;
21716+ }
21717+#endif
21718+
21719 nmi_nesting_preprocess(regs);
21720
21721 nmi_enter();
21722diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
21723index 6d9582e..f746287 100644
21724--- a/arch/x86/kernel/nmi_selftest.c
21725+++ b/arch/x86/kernel/nmi_selftest.c
21726@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
21727 {
21728 /* trap all the unknown NMIs we may generate */
21729 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
21730- __initdata);
21731+ __initconst);
21732 }
21733
21734 static void __init cleanup_nmi_testsuite(void)
21735@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
21736 unsigned long timeout;
21737
21738 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
21739- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
21740+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
21741 nmi_fail = FAILURE;
21742 return;
21743 }
21744diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
21745index 676b8c7..870ba04 100644
21746--- a/arch/x86/kernel/paravirt-spinlocks.c
21747+++ b/arch/x86/kernel/paravirt-spinlocks.c
21748@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
21749 arch_spin_lock(lock);
21750 }
21751
21752-struct pv_lock_ops pv_lock_ops = {
21753+struct pv_lock_ops pv_lock_ops __read_only = {
21754 #ifdef CONFIG_SMP
21755 .spin_is_locked = __ticket_spin_is_locked,
21756 .spin_is_contended = __ticket_spin_is_contended,
21757diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
21758index 8bfb335..c1463c6 100644
21759--- a/arch/x86/kernel/paravirt.c
21760+++ b/arch/x86/kernel/paravirt.c
21761@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
21762 {
21763 return x;
21764 }
21765+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21766+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
21767+#endif
21768
21769 void __init default_banner(void)
21770 {
21771@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
21772 if (opfunc == NULL)
21773 /* If there's no function, patch it with a ud2a (BUG) */
21774 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
21775- else if (opfunc == _paravirt_nop)
21776+ else if (opfunc == (void *)_paravirt_nop)
21777 /* If the operation is a nop, then nop the callsite */
21778 ret = paravirt_patch_nop();
21779
21780 /* identity functions just return their single argument */
21781- else if (opfunc == _paravirt_ident_32)
21782+ else if (opfunc == (void *)_paravirt_ident_32)
21783 ret = paravirt_patch_ident_32(insnbuf, len);
21784- else if (opfunc == _paravirt_ident_64)
21785+ else if (opfunc == (void *)_paravirt_ident_64)
21786 ret = paravirt_patch_ident_64(insnbuf, len);
21787+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21788+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
21789+ ret = paravirt_patch_ident_64(insnbuf, len);
21790+#endif
21791
21792 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
21793 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
21794@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
21795 if (insn_len > len || start == NULL)
21796 insn_len = len;
21797 else
21798- memcpy(insnbuf, start, insn_len);
21799+ memcpy(insnbuf, ktla_ktva(start), insn_len);
21800
21801 return insn_len;
21802 }
21803@@ -304,7 +311,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
21804 return this_cpu_read(paravirt_lazy_mode);
21805 }
21806
21807-struct pv_info pv_info = {
21808+struct pv_info pv_info __read_only = {
21809 .name = "bare hardware",
21810 .paravirt_enabled = 0,
21811 .kernel_rpl = 0,
21812@@ -315,16 +322,16 @@ struct pv_info pv_info = {
21813 #endif
21814 };
21815
21816-struct pv_init_ops pv_init_ops = {
21817+struct pv_init_ops pv_init_ops __read_only = {
21818 .patch = native_patch,
21819 };
21820
21821-struct pv_time_ops pv_time_ops = {
21822+struct pv_time_ops pv_time_ops __read_only = {
21823 .sched_clock = native_sched_clock,
21824 .steal_clock = native_steal_clock,
21825 };
21826
21827-struct pv_irq_ops pv_irq_ops = {
21828+struct pv_irq_ops pv_irq_ops __read_only = {
21829 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
21830 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
21831 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
21832@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
21833 #endif
21834 };
21835
21836-struct pv_cpu_ops pv_cpu_ops = {
21837+struct pv_cpu_ops pv_cpu_ops __read_only = {
21838 .cpuid = native_cpuid,
21839 .get_debugreg = native_get_debugreg,
21840 .set_debugreg = native_set_debugreg,
21841@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
21842 .end_context_switch = paravirt_nop,
21843 };
21844
21845-struct pv_apic_ops pv_apic_ops = {
21846+struct pv_apic_ops pv_apic_ops __read_only= {
21847 #ifdef CONFIG_X86_LOCAL_APIC
21848 .startup_ipi_hook = paravirt_nop,
21849 #endif
21850 };
21851
21852-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
21853+#ifdef CONFIG_X86_32
21854+#ifdef CONFIG_X86_PAE
21855+/* 64-bit pagetable entries */
21856+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
21857+#else
21858 /* 32-bit pagetable entries */
21859 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
21860+#endif
21861 #else
21862 /* 64-bit pagetable entries */
21863 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
21864 #endif
21865
21866-struct pv_mmu_ops pv_mmu_ops = {
21867+struct pv_mmu_ops pv_mmu_ops __read_only = {
21868
21869 .read_cr2 = native_read_cr2,
21870 .write_cr2 = native_write_cr2,
21871@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
21872 .make_pud = PTE_IDENT,
21873
21874 .set_pgd = native_set_pgd,
21875+ .set_pgd_batched = native_set_pgd_batched,
21876 #endif
21877 #endif /* PAGETABLE_LEVELS >= 3 */
21878
21879@@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
21880 },
21881
21882 .set_fixmap = native_set_fixmap,
21883+
21884+#ifdef CONFIG_PAX_KERNEXEC
21885+ .pax_open_kernel = native_pax_open_kernel,
21886+ .pax_close_kernel = native_pax_close_kernel,
21887+#endif
21888+
21889 };
21890
21891 EXPORT_SYMBOL_GPL(pv_time_ops);
21892diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
21893index 299d493..2ccb0ee 100644
21894--- a/arch/x86/kernel/pci-calgary_64.c
21895+++ b/arch/x86/kernel/pci-calgary_64.c
21896@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
21897 tce_space = be64_to_cpu(readq(target));
21898 tce_space = tce_space & TAR_SW_BITS;
21899
21900- tce_space = tce_space & (~specified_table_size);
21901+ tce_space = tce_space & (~(unsigned long)specified_table_size);
21902 info->tce_space = (u64 *)__va(tce_space);
21903 }
21904 }
21905diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
21906index 35ccf75..7a15747 100644
21907--- a/arch/x86/kernel/pci-iommu_table.c
21908+++ b/arch/x86/kernel/pci-iommu_table.c
21909@@ -2,7 +2,7 @@
21910 #include <asm/iommu_table.h>
21911 #include <linux/string.h>
21912 #include <linux/kallsyms.h>
21913-
21914+#include <linux/sched.h>
21915
21916 #define DEBUG 1
21917
21918diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
21919index 6c483ba..d10ce2f 100644
21920--- a/arch/x86/kernel/pci-swiotlb.c
21921+++ b/arch/x86/kernel/pci-swiotlb.c
21922@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
21923 void *vaddr, dma_addr_t dma_addr,
21924 struct dma_attrs *attrs)
21925 {
21926- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
21927+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
21928 }
21929
21930 static struct dma_map_ops swiotlb_dma_ops = {
21931diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
21932index 14ae100..752a4f6 100644
21933--- a/arch/x86/kernel/process.c
21934+++ b/arch/x86/kernel/process.c
21935@@ -36,7 +36,8 @@
21936 * section. Since TSS's are completely CPU-local, we want them
21937 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
21938 */
21939-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
21940+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
21941+EXPORT_SYMBOL(init_tss);
21942
21943 #ifdef CONFIG_X86_64
21944 static DEFINE_PER_CPU(unsigned char, is_idle);
21945@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
21946 task_xstate_cachep =
21947 kmem_cache_create("task_xstate", xstate_size,
21948 __alignof__(union thread_xstate),
21949- SLAB_PANIC | SLAB_NOTRACK, NULL);
21950+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
21951 }
21952
21953 /*
21954@@ -105,7 +106,7 @@ void exit_thread(void)
21955 unsigned long *bp = t->io_bitmap_ptr;
21956
21957 if (bp) {
21958- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
21959+ struct tss_struct *tss = init_tss + get_cpu();
21960
21961 t->io_bitmap_ptr = NULL;
21962 clear_thread_flag(TIF_IO_BITMAP);
21963@@ -136,7 +137,7 @@ void show_regs_common(void)
21964 board = dmi_get_system_info(DMI_BOARD_NAME);
21965
21966 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
21967- current->pid, current->comm, print_tainted(),
21968+ task_pid_nr(current), current->comm, print_tainted(),
21969 init_utsname()->release,
21970 (int)strcspn(init_utsname()->version, " "),
21971 init_utsname()->version,
21972@@ -149,6 +150,9 @@ void flush_thread(void)
21973 {
21974 struct task_struct *tsk = current;
21975
21976+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
21977+ loadsegment(gs, 0);
21978+#endif
21979 flush_ptrace_hw_breakpoint(tsk);
21980 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
21981 drop_init_fpu(tsk);
21982@@ -295,7 +299,7 @@ static void __exit_idle(void)
21983 void exit_idle(void)
21984 {
21985 /* idle loop has pid 0 */
21986- if (current->pid)
21987+ if (task_pid_nr(current))
21988 return;
21989 __exit_idle();
21990 }
21991@@ -398,7 +402,7 @@ bool xen_set_default_idle(void)
21992 return ret;
21993 }
21994 #endif
21995-void stop_this_cpu(void *dummy)
21996+__noreturn void stop_this_cpu(void *dummy)
21997 {
21998 local_irq_disable();
21999 /*
22000@@ -544,16 +548,37 @@ static int __init idle_setup(char *str)
22001 }
22002 early_param("idle", idle_setup);
22003
22004-unsigned long arch_align_stack(unsigned long sp)
22005+#ifdef CONFIG_PAX_RANDKSTACK
22006+void pax_randomize_kstack(struct pt_regs *regs)
22007 {
22008- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
22009- sp -= get_random_int() % 8192;
22010- return sp & ~0xf;
22011-}
22012+ struct thread_struct *thread = &current->thread;
22013+ unsigned long time;
22014
22015-unsigned long arch_randomize_brk(struct mm_struct *mm)
22016-{
22017- unsigned long range_end = mm->brk + 0x02000000;
22018- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
22019-}
22020+ if (!randomize_va_space)
22021+ return;
22022+
22023+ if (v8086_mode(regs))
22024+ return;
22025
22026+ rdtscl(time);
22027+
22028+ /* P4 seems to return a 0 LSB, ignore it */
22029+#ifdef CONFIG_MPENTIUM4
22030+ time &= 0x3EUL;
22031+ time <<= 2;
22032+#elif defined(CONFIG_X86_64)
22033+ time &= 0xFUL;
22034+ time <<= 4;
22035+#else
22036+ time &= 0x1FUL;
22037+ time <<= 3;
22038+#endif
22039+
22040+ thread->sp0 ^= time;
22041+ load_sp0(init_tss + smp_processor_id(), thread);
22042+
22043+#ifdef CONFIG_X86_64
22044+ this_cpu_write(kernel_stack, thread->sp0);
22045+#endif
22046+}
22047+#endif
22048diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
22049index b5a8905..d9cacac 100644
22050--- a/arch/x86/kernel/process_32.c
22051+++ b/arch/x86/kernel/process_32.c
22052@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
22053 unsigned long thread_saved_pc(struct task_struct *tsk)
22054 {
22055 return ((unsigned long *)tsk->thread.sp)[3];
22056+//XXX return tsk->thread.eip;
22057 }
22058
22059 void __show_regs(struct pt_regs *regs, int all)
22060@@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
22061 unsigned long sp;
22062 unsigned short ss, gs;
22063
22064- if (user_mode_vm(regs)) {
22065+ if (user_mode(regs)) {
22066 sp = regs->sp;
22067 ss = regs->ss & 0xffff;
22068- gs = get_user_gs(regs);
22069 } else {
22070 sp = kernel_stack_pointer(regs);
22071 savesegment(ss, ss);
22072- savesegment(gs, gs);
22073 }
22074+ gs = get_user_gs(regs);
22075
22076 show_regs_common();
22077
22078 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
22079 (u16)regs->cs, regs->ip, regs->flags,
22080- smp_processor_id());
22081+ raw_smp_processor_id());
22082 print_symbol("EIP is at %s\n", regs->ip);
22083
22084 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
22085@@ -130,20 +130,21 @@ void release_thread(struct task_struct *dead_task)
22086 int copy_thread(unsigned long clone_flags, unsigned long sp,
22087 unsigned long arg, struct task_struct *p)
22088 {
22089- struct pt_regs *childregs = task_pt_regs(p);
22090+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
22091 struct task_struct *tsk;
22092 int err;
22093
22094 p->thread.sp = (unsigned long) childregs;
22095 p->thread.sp0 = (unsigned long) (childregs+1);
22096+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22097
22098 if (unlikely(p->flags & PF_KTHREAD)) {
22099 /* kernel thread */
22100 memset(childregs, 0, sizeof(struct pt_regs));
22101 p->thread.ip = (unsigned long) ret_from_kernel_thread;
22102- task_user_gs(p) = __KERNEL_STACK_CANARY;
22103- childregs->ds = __USER_DS;
22104- childregs->es = __USER_DS;
22105+ savesegment(gs, childregs->gs);
22106+ childregs->ds = __KERNEL_DS;
22107+ childregs->es = __KERNEL_DS;
22108 childregs->fs = __KERNEL_PERCPU;
22109 childregs->bx = sp; /* function */
22110 childregs->bp = arg;
22111@@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22112 struct thread_struct *prev = &prev_p->thread,
22113 *next = &next_p->thread;
22114 int cpu = smp_processor_id();
22115- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22116+ struct tss_struct *tss = init_tss + cpu;
22117 fpu_switch_t fpu;
22118
22119 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
22120@@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22121 */
22122 lazy_save_gs(prev->gs);
22123
22124+#ifdef CONFIG_PAX_MEMORY_UDEREF
22125+ __set_fs(task_thread_info(next_p)->addr_limit);
22126+#endif
22127+
22128 /*
22129 * Load the per-thread Thread-Local Storage descriptor.
22130 */
22131@@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22132 */
22133 arch_end_context_switch(next_p);
22134
22135+ this_cpu_write(current_task, next_p);
22136+ this_cpu_write(current_tinfo, &next_p->tinfo);
22137+
22138 /*
22139 * Restore %gs if needed (which is common)
22140 */
22141@@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22142
22143 switch_fpu_finish(next_p, fpu);
22144
22145- this_cpu_write(current_task, next_p);
22146-
22147 return prev_p;
22148 }
22149
22150@@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
22151 } while (count++ < 16);
22152 return 0;
22153 }
22154-
22155diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
22156index 0f49677..fcbf88c 100644
22157--- a/arch/x86/kernel/process_64.c
22158+++ b/arch/x86/kernel/process_64.c
22159@@ -152,10 +152,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
22160 struct pt_regs *childregs;
22161 struct task_struct *me = current;
22162
22163- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
22164+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
22165 childregs = task_pt_regs(p);
22166 p->thread.sp = (unsigned long) childregs;
22167 p->thread.usersp = me->thread.usersp;
22168+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22169 set_tsk_thread_flag(p, TIF_FORK);
22170 p->fpu_counter = 0;
22171 p->thread.io_bitmap_ptr = NULL;
22172@@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22173 struct thread_struct *prev = &prev_p->thread;
22174 struct thread_struct *next = &next_p->thread;
22175 int cpu = smp_processor_id();
22176- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22177+ struct tss_struct *tss = init_tss + cpu;
22178 unsigned fsindex, gsindex;
22179 fpu_switch_t fpu;
22180
22181@@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22182 prev->usersp = this_cpu_read(old_rsp);
22183 this_cpu_write(old_rsp, next->usersp);
22184 this_cpu_write(current_task, next_p);
22185+ this_cpu_write(current_tinfo, &next_p->tinfo);
22186
22187- this_cpu_write(kernel_stack,
22188- (unsigned long)task_stack_page(next_p) +
22189- THREAD_SIZE - KERNEL_STACK_OFFSET);
22190+ this_cpu_write(kernel_stack, next->sp0);
22191
22192 /*
22193 * Now maybe reload the debug registers and handle I/O bitmaps
22194@@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
22195 if (!p || p == current || p->state == TASK_RUNNING)
22196 return 0;
22197 stack = (unsigned long)task_stack_page(p);
22198- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
22199+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
22200 return 0;
22201 fp = *(u64 *)(p->thread.sp);
22202 do {
22203- if (fp < (unsigned long)stack ||
22204- fp >= (unsigned long)stack+THREAD_SIZE)
22205+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
22206 return 0;
22207 ip = *(u64 *)(fp+8);
22208 if (!in_sched_functions(ip))
22209diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
22210index 29a8120..a50b5ee 100644
22211--- a/arch/x86/kernel/ptrace.c
22212+++ b/arch/x86/kernel/ptrace.c
22213@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
22214 {
22215 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
22216 unsigned long sp = (unsigned long)&regs->sp;
22217- struct thread_info *tinfo;
22218
22219- if (context == (sp & ~(THREAD_SIZE - 1)))
22220+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
22221 return sp;
22222
22223- tinfo = (struct thread_info *)context;
22224- if (tinfo->previous_esp)
22225- return tinfo->previous_esp;
22226+ sp = *(unsigned long *)context;
22227+ if (sp)
22228+ return sp;
22229
22230 return (unsigned long)regs;
22231 }
22232@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
22233 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
22234 {
22235 int i;
22236- int dr7 = 0;
22237+ unsigned long dr7 = 0;
22238 struct arch_hw_breakpoint *info;
22239
22240 for (i = 0; i < HBP_NUM; i++) {
22241@@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
22242 unsigned long addr, unsigned long data)
22243 {
22244 int ret;
22245- unsigned long __user *datap = (unsigned long __user *)data;
22246+ unsigned long __user *datap = (__force unsigned long __user *)data;
22247
22248 switch (request) {
22249 /* read the word at location addr in the USER area. */
22250@@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
22251 if ((int) addr < 0)
22252 return -EIO;
22253 ret = do_get_thread_area(child, addr,
22254- (struct user_desc __user *)data);
22255+ (__force struct user_desc __user *) data);
22256 break;
22257
22258 case PTRACE_SET_THREAD_AREA:
22259 if ((int) addr < 0)
22260 return -EIO;
22261 ret = do_set_thread_area(child, addr,
22262- (struct user_desc __user *)data, 0);
22263+ (__force struct user_desc __user *) data, 0);
22264 break;
22265 #endif
22266
22267@@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
22268
22269 #ifdef CONFIG_X86_64
22270
22271-static struct user_regset x86_64_regsets[] __read_mostly = {
22272+static user_regset_no_const x86_64_regsets[] __read_only = {
22273 [REGSET_GENERAL] = {
22274 .core_note_type = NT_PRSTATUS,
22275 .n = sizeof(struct user_regs_struct) / sizeof(long),
22276@@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
22277 #endif /* CONFIG_X86_64 */
22278
22279 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
22280-static struct user_regset x86_32_regsets[] __read_mostly = {
22281+static user_regset_no_const x86_32_regsets[] __read_only = {
22282 [REGSET_GENERAL] = {
22283 .core_note_type = NT_PRSTATUS,
22284 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
22285@@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
22286 */
22287 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
22288
22289-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22290+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22291 {
22292 #ifdef CONFIG_X86_64
22293 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
22294@@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
22295 memset(info, 0, sizeof(*info));
22296 info->si_signo = SIGTRAP;
22297 info->si_code = si_code;
22298- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
22299+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
22300 }
22301
22302 void user_single_step_siginfo(struct task_struct *tsk,
22303@@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
22304 # define IS_IA32 0
22305 #endif
22306
22307+#ifdef CONFIG_GRKERNSEC_SETXID
22308+extern void gr_delayed_cred_worker(void);
22309+#endif
22310+
22311 /*
22312 * We must return the syscall number to actually look up in the table.
22313 * This can be -1L to skip running any syscall at all.
22314@@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
22315
22316 user_exit();
22317
22318+#ifdef CONFIG_GRKERNSEC_SETXID
22319+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22320+ gr_delayed_cred_worker();
22321+#endif
22322+
22323 /*
22324 * If we stepped into a sysenter/syscall insn, it trapped in
22325 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
22326@@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
22327 */
22328 user_exit();
22329
22330+#ifdef CONFIG_GRKERNSEC_SETXID
22331+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22332+ gr_delayed_cred_worker();
22333+#endif
22334+
22335 audit_syscall_exit(regs);
22336
22337 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
22338diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
22339index 2cb9470..ff1fd80 100644
22340--- a/arch/x86/kernel/pvclock.c
22341+++ b/arch/x86/kernel/pvclock.c
22342@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
22343 return pv_tsc_khz;
22344 }
22345
22346-static atomic64_t last_value = ATOMIC64_INIT(0);
22347+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
22348
22349 void pvclock_resume(void)
22350 {
22351- atomic64_set(&last_value, 0);
22352+ atomic64_set_unchecked(&last_value, 0);
22353 }
22354
22355 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
22356@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
22357 * updating at the same time, and one of them could be slightly behind,
22358 * making the assumption that last_value always go forward fail to hold.
22359 */
22360- last = atomic64_read(&last_value);
22361+ last = atomic64_read_unchecked(&last_value);
22362 do {
22363 if (ret < last)
22364 return last;
22365- last = atomic64_cmpxchg(&last_value, last, ret);
22366+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
22367 } while (unlikely(last != ret));
22368
22369 return ret;
22370diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
22371index 76fa1e9..abf09ea 100644
22372--- a/arch/x86/kernel/reboot.c
22373+++ b/arch/x86/kernel/reboot.c
22374@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
22375 EXPORT_SYMBOL(pm_power_off);
22376
22377 static const struct desc_ptr no_idt = {};
22378-static int reboot_mode;
22379+static unsigned short reboot_mode;
22380 enum reboot_type reboot_type = BOOT_ACPI;
22381 int reboot_force;
22382
22383@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
22384
22385 void __noreturn machine_real_restart(unsigned int type)
22386 {
22387+
22388+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
22389+ struct desc_struct *gdt;
22390+#endif
22391+
22392 local_irq_disable();
22393
22394 /*
22395@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
22396
22397 /* Jump to the identity-mapped low memory code */
22398 #ifdef CONFIG_X86_32
22399- asm volatile("jmpl *%0" : :
22400+
22401+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22402+ gdt = get_cpu_gdt_table(smp_processor_id());
22403+ pax_open_kernel();
22404+#ifdef CONFIG_PAX_MEMORY_UDEREF
22405+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
22406+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
22407+ loadsegment(ds, __KERNEL_DS);
22408+ loadsegment(es, __KERNEL_DS);
22409+ loadsegment(ss, __KERNEL_DS);
22410+#endif
22411+#ifdef CONFIG_PAX_KERNEXEC
22412+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
22413+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
22414+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
22415+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
22416+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
22417+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
22418+#endif
22419+ pax_close_kernel();
22420+#endif
22421+
22422+ asm volatile("ljmpl *%0" : :
22423 "rm" (real_mode_header->machine_real_restart_asm),
22424 "a" (type));
22425 #else
22426@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
22427 * try to force a triple fault and then cycle between hitting the keyboard
22428 * controller and doing that
22429 */
22430-static void native_machine_emergency_restart(void)
22431+static void __noreturn native_machine_emergency_restart(void)
22432 {
22433 int i;
22434 int attempt = 0;
22435@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
22436 #endif
22437 }
22438
22439-static void __machine_emergency_restart(int emergency)
22440+static void __noreturn __machine_emergency_restart(int emergency)
22441 {
22442 reboot_emergency = emergency;
22443 machine_ops.emergency_restart();
22444 }
22445
22446-static void native_machine_restart(char *__unused)
22447+static void __noreturn native_machine_restart(char *__unused)
22448 {
22449 pr_notice("machine restart\n");
22450
22451@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
22452 __machine_emergency_restart(0);
22453 }
22454
22455-static void native_machine_halt(void)
22456+static void __noreturn native_machine_halt(void)
22457 {
22458 /* Stop other cpus and apics */
22459 machine_shutdown();
22460@@ -679,7 +706,7 @@ static void native_machine_halt(void)
22461 stop_this_cpu(NULL);
22462 }
22463
22464-static void native_machine_power_off(void)
22465+static void __noreturn native_machine_power_off(void)
22466 {
22467 if (pm_power_off) {
22468 if (!reboot_force)
22469@@ -688,9 +715,10 @@ static void native_machine_power_off(void)
22470 }
22471 /* A fallback in case there is no PM info available */
22472 tboot_shutdown(TB_SHUTDOWN_HALT);
22473+ unreachable();
22474 }
22475
22476-struct machine_ops machine_ops = {
22477+struct machine_ops machine_ops __read_only = {
22478 .power_off = native_machine_power_off,
22479 .shutdown = native_machine_shutdown,
22480 .emergency_restart = native_machine_emergency_restart,
22481diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
22482index 7a6f3b3..bed145d7 100644
22483--- a/arch/x86/kernel/relocate_kernel_64.S
22484+++ b/arch/x86/kernel/relocate_kernel_64.S
22485@@ -11,6 +11,7 @@
22486 #include <asm/kexec.h>
22487 #include <asm/processor-flags.h>
22488 #include <asm/pgtable_types.h>
22489+#include <asm/alternative-asm.h>
22490
22491 /*
22492 * Must be relocatable PIC code callable as a C function
22493@@ -160,13 +161,14 @@ identity_mapped:
22494 xorq %rbp, %rbp
22495 xorq %r8, %r8
22496 xorq %r9, %r9
22497- xorq %r10, %r9
22498+ xorq %r10, %r10
22499 xorq %r11, %r11
22500 xorq %r12, %r12
22501 xorq %r13, %r13
22502 xorq %r14, %r14
22503 xorq %r15, %r15
22504
22505+ pax_force_retaddr 0, 1
22506 ret
22507
22508 1:
22509diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
22510index fae9134..f8e4a47 100644
22511--- a/arch/x86/kernel/setup.c
22512+++ b/arch/x86/kernel/setup.c
22513@@ -111,6 +111,7 @@
22514 #include <asm/mce.h>
22515 #include <asm/alternative.h>
22516 #include <asm/prom.h>
22517+#include <asm/boot.h>
22518
22519 /*
22520 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
22521@@ -447,7 +448,7 @@ static void __init parse_setup_data(void)
22522
22523 switch (data->type) {
22524 case SETUP_E820_EXT:
22525- parse_e820_ext(data);
22526+ parse_e820_ext((struct setup_data __force_kernel *)data);
22527 break;
22528 case SETUP_DTB:
22529 add_dtb(pa_data);
22530@@ -774,7 +775,7 @@ static void __init trim_bios_range(void)
22531 * area (640->1Mb) as ram even though it is not.
22532 * take them out.
22533 */
22534- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
22535+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
22536
22537 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
22538 }
22539@@ -782,7 +783,7 @@ static void __init trim_bios_range(void)
22540 /* called before trim_bios_range() to spare extra sanitize */
22541 static void __init e820_add_kernel_range(void)
22542 {
22543- u64 start = __pa_symbol(_text);
22544+ u64 start = __pa_symbol(ktla_ktva(_text));
22545 u64 size = __pa_symbol(_end) - start;
22546
22547 /*
22548@@ -844,8 +845,12 @@ static void __init trim_low_memory_range(void)
22549
22550 void __init setup_arch(char **cmdline_p)
22551 {
22552+#ifdef CONFIG_X86_32
22553+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - ____LOAD_PHYSICAL_ADDR);
22554+#else
22555 memblock_reserve(__pa_symbol(_text),
22556 (unsigned long)__bss_stop - (unsigned long)_text);
22557+#endif
22558
22559 early_reserve_initrd();
22560
22561@@ -937,14 +942,14 @@ void __init setup_arch(char **cmdline_p)
22562
22563 if (!boot_params.hdr.root_flags)
22564 root_mountflags &= ~MS_RDONLY;
22565- init_mm.start_code = (unsigned long) _text;
22566- init_mm.end_code = (unsigned long) _etext;
22567+ init_mm.start_code = ktla_ktva((unsigned long) _text);
22568+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
22569 init_mm.end_data = (unsigned long) _edata;
22570 init_mm.brk = _brk_end;
22571
22572- code_resource.start = __pa_symbol(_text);
22573- code_resource.end = __pa_symbol(_etext)-1;
22574- data_resource.start = __pa_symbol(_etext);
22575+ code_resource.start = __pa_symbol(ktla_ktva(_text));
22576+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
22577+ data_resource.start = __pa_symbol(_sdata);
22578 data_resource.end = __pa_symbol(_edata)-1;
22579 bss_resource.start = __pa_symbol(__bss_start);
22580 bss_resource.end = __pa_symbol(__bss_stop)-1;
22581diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
22582index 5cdff03..80fa283 100644
22583--- a/arch/x86/kernel/setup_percpu.c
22584+++ b/arch/x86/kernel/setup_percpu.c
22585@@ -21,19 +21,17 @@
22586 #include <asm/cpu.h>
22587 #include <asm/stackprotector.h>
22588
22589-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
22590+#ifdef CONFIG_SMP
22591+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
22592 EXPORT_PER_CPU_SYMBOL(cpu_number);
22593+#endif
22594
22595-#ifdef CONFIG_X86_64
22596 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
22597-#else
22598-#define BOOT_PERCPU_OFFSET 0
22599-#endif
22600
22601 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
22602 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
22603
22604-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
22605+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
22606 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
22607 };
22608 EXPORT_SYMBOL(__per_cpu_offset);
22609@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
22610 {
22611 #ifdef CONFIG_NEED_MULTIPLE_NODES
22612 pg_data_t *last = NULL;
22613- unsigned int cpu;
22614+ int cpu;
22615
22616 for_each_possible_cpu(cpu) {
22617 int node = early_cpu_to_node(cpu);
22618@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
22619 {
22620 #ifdef CONFIG_X86_32
22621 struct desc_struct gdt;
22622+ unsigned long base = per_cpu_offset(cpu);
22623
22624- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
22625- 0x2 | DESCTYPE_S, 0x8);
22626- gdt.s = 1;
22627+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
22628+ 0x83 | DESCTYPE_S, 0xC);
22629 write_gdt_entry(get_cpu_gdt_table(cpu),
22630 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
22631 #endif
22632@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
22633 /* alrighty, percpu areas up and running */
22634 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
22635 for_each_possible_cpu(cpu) {
22636+#ifdef CONFIG_CC_STACKPROTECTOR
22637+#ifdef CONFIG_X86_32
22638+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
22639+#endif
22640+#endif
22641 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
22642 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
22643 per_cpu(cpu_number, cpu) = cpu;
22644@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
22645 */
22646 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
22647 #endif
22648+#ifdef CONFIG_CC_STACKPROTECTOR
22649+#ifdef CONFIG_X86_32
22650+ if (!cpu)
22651+ per_cpu(stack_canary.canary, cpu) = canary;
22652+#endif
22653+#endif
22654 /*
22655 * Up to this point, the boot CPU has been using .init.data
22656 * area. Reload any changed state for the boot CPU.
22657diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
22658index 6956299..f20beae 100644
22659--- a/arch/x86/kernel/signal.c
22660+++ b/arch/x86/kernel/signal.c
22661@@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
22662 * Align the stack pointer according to the i386 ABI,
22663 * i.e. so that on function entry ((sp + 4) & 15) == 0.
22664 */
22665- sp = ((sp + 4) & -16ul) - 4;
22666+ sp = ((sp - 12) & -16ul) - 4;
22667 #else /* !CONFIG_X86_32 */
22668 sp = round_down(sp, 16) - 8;
22669 #endif
22670@@ -304,9 +304,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
22671 }
22672
22673 if (current->mm->context.vdso)
22674- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22675+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22676 else
22677- restorer = &frame->retcode;
22678+ restorer = (void __user *)&frame->retcode;
22679 if (ksig->ka.sa.sa_flags & SA_RESTORER)
22680 restorer = ksig->ka.sa.sa_restorer;
22681
22682@@ -320,7 +320,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
22683 * reasons and because gdb uses it as a signature to notice
22684 * signal handler stack frames.
22685 */
22686- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
22687+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
22688
22689 if (err)
22690 return -EFAULT;
22691@@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
22692 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
22693
22694 /* Set up to return from userspace. */
22695- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22696+ if (current->mm->context.vdso)
22697+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22698+ else
22699+ restorer = (void __user *)&frame->retcode;
22700 if (ksig->ka.sa.sa_flags & SA_RESTORER)
22701 restorer = ksig->ka.sa.sa_restorer;
22702 put_user_ex(restorer, &frame->pretcode);
22703@@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
22704 * reasons and because gdb uses it as a signature to notice
22705 * signal handler stack frames.
22706 */
22707- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
22708+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
22709 } put_user_catch(err);
22710
22711 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
22712@@ -615,7 +618,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
22713 {
22714 int usig = signr_convert(ksig->sig);
22715 sigset_t *set = sigmask_to_save();
22716- compat_sigset_t *cset = (compat_sigset_t *) set;
22717+ sigset_t sigcopy;
22718+ compat_sigset_t *cset;
22719+
22720+ sigcopy = *set;
22721+
22722+ cset = (compat_sigset_t *) &sigcopy;
22723
22724 /* Set up the stack frame */
22725 if (is_ia32_frame()) {
22726@@ -626,7 +634,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
22727 } else if (is_x32_frame()) {
22728 return x32_setup_rt_frame(ksig, cset, regs);
22729 } else {
22730- return __setup_rt_frame(ksig->sig, ksig, set, regs);
22731+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
22732 }
22733 }
22734
22735diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
22736index 48d2b7d..90d328a 100644
22737--- a/arch/x86/kernel/smp.c
22738+++ b/arch/x86/kernel/smp.c
22739@@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
22740
22741 __setup("nonmi_ipi", nonmi_ipi_setup);
22742
22743-struct smp_ops smp_ops = {
22744+struct smp_ops smp_ops __read_only = {
22745 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
22746 .smp_prepare_cpus = native_smp_prepare_cpus,
22747 .smp_cpus_done = native_smp_cpus_done,
22748diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
22749index 9f190a2..90a0688 100644
22750--- a/arch/x86/kernel/smpboot.c
22751+++ b/arch/x86/kernel/smpboot.c
22752@@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22753 idle->thread.sp = (unsigned long) (((struct pt_regs *)
22754 (THREAD_SIZE + task_stack_page(idle))) - 1);
22755 per_cpu(current_task, cpu) = idle;
22756+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
22757
22758 #ifdef CONFIG_X86_32
22759 /* Stack for startup_32 can be just as for start_secondary onwards */
22760@@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22761 #else
22762 clear_tsk_thread_flag(idle, TIF_FORK);
22763 initial_gs = per_cpu_offset(cpu);
22764- per_cpu(kernel_stack, cpu) =
22765- (unsigned long)task_stack_page(idle) -
22766- KERNEL_STACK_OFFSET + THREAD_SIZE;
22767+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
22768 #endif
22769+
22770+ pax_open_kernel();
22771 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
22772+ pax_close_kernel();
22773+
22774 initial_code = (unsigned long)start_secondary;
22775 stack_start = idle->thread.sp;
22776
22777@@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
22778 /* the FPU context is blank, nobody can own it */
22779 __cpu_disable_lazy_restore(cpu);
22780
22781+#ifdef CONFIG_PAX_PER_CPU_PGD
22782+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
22783+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22784+ KERNEL_PGD_PTRS);
22785+#endif
22786+
22787+ /* the FPU context is blank, nobody can own it */
22788+ __cpu_disable_lazy_restore(cpu);
22789+
22790 err = do_boot_cpu(apicid, cpu, tidle);
22791 if (err) {
22792 pr_debug("do_boot_cpu failed %d\n", err);
22793diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
22794index 9b4d51d..5d28b58 100644
22795--- a/arch/x86/kernel/step.c
22796+++ b/arch/x86/kernel/step.c
22797@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22798 struct desc_struct *desc;
22799 unsigned long base;
22800
22801- seg &= ~7UL;
22802+ seg >>= 3;
22803
22804 mutex_lock(&child->mm->context.lock);
22805- if (unlikely((seg >> 3) >= child->mm->context.size))
22806+ if (unlikely(seg >= child->mm->context.size))
22807 addr = -1L; /* bogus selector, access would fault */
22808 else {
22809 desc = child->mm->context.ldt + seg;
22810@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22811 addr += base;
22812 }
22813 mutex_unlock(&child->mm->context.lock);
22814- }
22815+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
22816+ addr = ktla_ktva(addr);
22817
22818 return addr;
22819 }
22820@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
22821 unsigned char opcode[15];
22822 unsigned long addr = convert_ip_to_linear(child, regs);
22823
22824+ if (addr == -EINVAL)
22825+ return 0;
22826+
22827 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
22828 for (i = 0; i < copied; i++) {
22829 switch (opcode[i]) {
22830diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
22831new file mode 100644
22832index 0000000..207bec6
22833--- /dev/null
22834+++ b/arch/x86/kernel/sys_i386_32.c
22835@@ -0,0 +1,250 @@
22836+/*
22837+ * This file contains various random system calls that
22838+ * have a non-standard calling sequence on the Linux/i386
22839+ * platform.
22840+ */
22841+
22842+#include <linux/errno.h>
22843+#include <linux/sched.h>
22844+#include <linux/mm.h>
22845+#include <linux/fs.h>
22846+#include <linux/smp.h>
22847+#include <linux/sem.h>
22848+#include <linux/msg.h>
22849+#include <linux/shm.h>
22850+#include <linux/stat.h>
22851+#include <linux/syscalls.h>
22852+#include <linux/mman.h>
22853+#include <linux/file.h>
22854+#include <linux/utsname.h>
22855+#include <linux/ipc.h>
22856+
22857+#include <linux/uaccess.h>
22858+#include <linux/unistd.h>
22859+
22860+#include <asm/syscalls.h>
22861+
22862+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
22863+{
22864+ unsigned long pax_task_size = TASK_SIZE;
22865+
22866+#ifdef CONFIG_PAX_SEGMEXEC
22867+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
22868+ pax_task_size = SEGMEXEC_TASK_SIZE;
22869+#endif
22870+
22871+ if (flags & MAP_FIXED)
22872+ if (len > pax_task_size || addr > pax_task_size - len)
22873+ return -EINVAL;
22874+
22875+ return 0;
22876+}
22877+
22878+unsigned long
22879+arch_get_unmapped_area(struct file *filp, unsigned long addr,
22880+ unsigned long len, unsigned long pgoff, unsigned long flags)
22881+{
22882+ struct mm_struct *mm = current->mm;
22883+ struct vm_area_struct *vma;
22884+ unsigned long start_addr, pax_task_size = TASK_SIZE;
22885+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22886+
22887+#ifdef CONFIG_PAX_SEGMEXEC
22888+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22889+ pax_task_size = SEGMEXEC_TASK_SIZE;
22890+#endif
22891+
22892+ pax_task_size -= PAGE_SIZE;
22893+
22894+ if (len > pax_task_size)
22895+ return -ENOMEM;
22896+
22897+ if (flags & MAP_FIXED)
22898+ return addr;
22899+
22900+#ifdef CONFIG_PAX_RANDMMAP
22901+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22902+#endif
22903+
22904+ if (addr) {
22905+ addr = PAGE_ALIGN(addr);
22906+ if (pax_task_size - len >= addr) {
22907+ vma = find_vma(mm, addr);
22908+ if (check_heap_stack_gap(vma, addr, len, offset))
22909+ return addr;
22910+ }
22911+ }
22912+ if (len > mm->cached_hole_size) {
22913+ start_addr = addr = mm->free_area_cache;
22914+ } else {
22915+ start_addr = addr = mm->mmap_base;
22916+ mm->cached_hole_size = 0;
22917+ }
22918+
22919+#ifdef CONFIG_PAX_PAGEEXEC
22920+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
22921+ start_addr = 0x00110000UL;
22922+
22923+#ifdef CONFIG_PAX_RANDMMAP
22924+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22925+ start_addr += mm->delta_mmap & 0x03FFF000UL;
22926+#endif
22927+
22928+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
22929+ start_addr = addr = mm->mmap_base;
22930+ else
22931+ addr = start_addr;
22932+ }
22933+#endif
22934+
22935+full_search:
22936+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
22937+ /* At this point: (!vma || addr < vma->vm_end). */
22938+ if (pax_task_size - len < addr) {
22939+ /*
22940+ * Start a new search - just in case we missed
22941+ * some holes.
22942+ */
22943+ if (start_addr != mm->mmap_base) {
22944+ start_addr = addr = mm->mmap_base;
22945+ mm->cached_hole_size = 0;
22946+ goto full_search;
22947+ }
22948+ return -ENOMEM;
22949+ }
22950+ if (check_heap_stack_gap(vma, addr, len, offset))
22951+ break;
22952+ if (addr + mm->cached_hole_size < vma->vm_start)
22953+ mm->cached_hole_size = vma->vm_start - addr;
22954+ addr = vma->vm_end;
22955+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
22956+ start_addr = addr = mm->mmap_base;
22957+ mm->cached_hole_size = 0;
22958+ goto full_search;
22959+ }
22960+ }
22961+
22962+ /*
22963+ * Remember the place where we stopped the search:
22964+ */
22965+ mm->free_area_cache = addr + len;
22966+ return addr;
22967+}
22968+
22969+unsigned long
22970+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22971+ const unsigned long len, const unsigned long pgoff,
22972+ const unsigned long flags)
22973+{
22974+ struct vm_area_struct *vma;
22975+ struct mm_struct *mm = current->mm;
22976+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
22977+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22978+
22979+#ifdef CONFIG_PAX_SEGMEXEC
22980+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22981+ pax_task_size = SEGMEXEC_TASK_SIZE;
22982+#endif
22983+
22984+ pax_task_size -= PAGE_SIZE;
22985+
22986+ /* requested length too big for entire address space */
22987+ if (len > pax_task_size)
22988+ return -ENOMEM;
22989+
22990+ if (flags & MAP_FIXED)
22991+ return addr;
22992+
22993+#ifdef CONFIG_PAX_PAGEEXEC
22994+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
22995+ goto bottomup;
22996+#endif
22997+
22998+#ifdef CONFIG_PAX_RANDMMAP
22999+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23000+#endif
23001+
23002+ /* requesting a specific address */
23003+ if (addr) {
23004+ addr = PAGE_ALIGN(addr);
23005+ if (pax_task_size - len >= addr) {
23006+ vma = find_vma(mm, addr);
23007+ if (check_heap_stack_gap(vma, addr, len, offset))
23008+ return addr;
23009+ }
23010+ }
23011+
23012+ /* check if free_area_cache is useful for us */
23013+ if (len <= mm->cached_hole_size) {
23014+ mm->cached_hole_size = 0;
23015+ mm->free_area_cache = mm->mmap_base;
23016+ }
23017+
23018+ /* either no address requested or can't fit in requested address hole */
23019+ addr = mm->free_area_cache;
23020+
23021+ /* make sure it can fit in the remaining address space */
23022+ if (addr > len) {
23023+ vma = find_vma(mm, addr-len);
23024+ if (check_heap_stack_gap(vma, addr - len, len, offset))
23025+ /* remember the address as a hint for next time */
23026+ return (mm->free_area_cache = addr-len);
23027+ }
23028+
23029+ if (mm->mmap_base < len)
23030+ goto bottomup;
23031+
23032+ addr = mm->mmap_base-len;
23033+
23034+ do {
23035+ /*
23036+ * Lookup failure means no vma is above this address,
23037+ * else if new region fits below vma->vm_start,
23038+ * return with success:
23039+ */
23040+ vma = find_vma(mm, addr);
23041+ if (check_heap_stack_gap(vma, addr, len, offset))
23042+ /* remember the address as a hint for next time */
23043+ return (mm->free_area_cache = addr);
23044+
23045+ /* remember the largest hole we saw so far */
23046+ if (addr + mm->cached_hole_size < vma->vm_start)
23047+ mm->cached_hole_size = vma->vm_start - addr;
23048+
23049+ /* try just below the current vma->vm_start */
23050+ addr = skip_heap_stack_gap(vma, len, offset);
23051+ } while (!IS_ERR_VALUE(addr));
23052+
23053+bottomup:
23054+ /*
23055+ * A failed mmap() very likely causes application failure,
23056+ * so fall back to the bottom-up function here. This scenario
23057+ * can happen with large stack limits and large mmap()
23058+ * allocations.
23059+ */
23060+
23061+#ifdef CONFIG_PAX_SEGMEXEC
23062+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23063+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
23064+ else
23065+#endif
23066+
23067+ mm->mmap_base = TASK_UNMAPPED_BASE;
23068+
23069+#ifdef CONFIG_PAX_RANDMMAP
23070+ if (mm->pax_flags & MF_PAX_RANDMMAP)
23071+ mm->mmap_base += mm->delta_mmap;
23072+#endif
23073+
23074+ mm->free_area_cache = mm->mmap_base;
23075+ mm->cached_hole_size = ~0UL;
23076+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
23077+ /*
23078+ * Restore the topdown base:
23079+ */
23080+ mm->mmap_base = base;
23081+ mm->free_area_cache = base;
23082+ mm->cached_hole_size = ~0UL;
23083+
23084+ return addr;
23085+}
23086diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
23087index dbded5a..ace2781 100644
23088--- a/arch/x86/kernel/sys_x86_64.c
23089+++ b/arch/x86/kernel/sys_x86_64.c
23090@@ -81,8 +81,8 @@ out:
23091 return error;
23092 }
23093
23094-static void find_start_end(unsigned long flags, unsigned long *begin,
23095- unsigned long *end)
23096+static void find_start_end(struct mm_struct *mm, unsigned long flags,
23097+ unsigned long *begin, unsigned long *end)
23098 {
23099 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
23100 unsigned long new_begin;
23101@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
23102 *begin = new_begin;
23103 }
23104 } else {
23105- *begin = TASK_UNMAPPED_BASE;
23106+ *begin = mm->mmap_base;
23107 *end = TASK_SIZE;
23108 }
23109 }
23110@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
23111 struct vm_area_struct *vma;
23112 struct vm_unmapped_area_info info;
23113 unsigned long begin, end;
23114+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23115
23116 if (flags & MAP_FIXED)
23117 return addr;
23118
23119- find_start_end(flags, &begin, &end);
23120+ find_start_end(mm, flags, &begin, &end);
23121
23122 if (len > end)
23123 return -ENOMEM;
23124
23125+#ifdef CONFIG_PAX_RANDMMAP
23126+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23127+#endif
23128+
23129 if (addr) {
23130 addr = PAGE_ALIGN(addr);
23131 vma = find_vma(mm, addr);
23132- if (end - len >= addr &&
23133- (!vma || addr + len <= vma->vm_start))
23134+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
23135 return addr;
23136 }
23137
23138@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
23139 info.high_limit = end;
23140 info.align_mask = filp ? get_align_mask() : 0;
23141 info.align_offset = pgoff << PAGE_SHIFT;
23142+ info.threadstack_offset = offset;
23143 return vm_unmapped_area(&info);
23144 }
23145
23146@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23147 struct mm_struct *mm = current->mm;
23148 unsigned long addr = addr0;
23149 struct vm_unmapped_area_info info;
23150+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23151
23152 /* requested length too big for entire address space */
23153 if (len > TASK_SIZE)
23154@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23155 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
23156 goto bottomup;
23157
23158+#ifdef CONFIG_PAX_RANDMMAP
23159+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23160+#endif
23161+
23162 /* requesting a specific address */
23163 if (addr) {
23164 addr = PAGE_ALIGN(addr);
23165 vma = find_vma(mm, addr);
23166- if (TASK_SIZE - len >= addr &&
23167- (!vma || addr + len <= vma->vm_start))
23168+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
23169 return addr;
23170 }
23171
23172@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23173 info.high_limit = mm->mmap_base;
23174 info.align_mask = filp ? get_align_mask() : 0;
23175 info.align_offset = pgoff << PAGE_SHIFT;
23176+ info.threadstack_offset = offset;
23177 addr = vm_unmapped_area(&info);
23178 if (!(addr & ~PAGE_MASK))
23179 return addr;
23180diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
23181index f84fe00..f41d9f1 100644
23182--- a/arch/x86/kernel/tboot.c
23183+++ b/arch/x86/kernel/tboot.c
23184@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
23185
23186 void tboot_shutdown(u32 shutdown_type)
23187 {
23188- void (*shutdown)(void);
23189+ void (* __noreturn shutdown)(void);
23190
23191 if (!tboot_enabled())
23192 return;
23193@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
23194
23195 switch_to_tboot_pt();
23196
23197- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
23198+ shutdown = (void *)tboot->shutdown_entry;
23199 shutdown();
23200
23201 /* should not reach here */
23202@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
23203 return 0;
23204 }
23205
23206-static atomic_t ap_wfs_count;
23207+static atomic_unchecked_t ap_wfs_count;
23208
23209 static int tboot_wait_for_aps(int num_aps)
23210 {
23211@@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
23212 {
23213 switch (action) {
23214 case CPU_DYING:
23215- atomic_inc(&ap_wfs_count);
23216+ atomic_inc_unchecked(&ap_wfs_count);
23217 if (num_online_cpus() == 1)
23218- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
23219+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
23220 return NOTIFY_BAD;
23221 break;
23222 }
23223 return NOTIFY_OK;
23224 }
23225
23226-static struct notifier_block tboot_cpu_notifier __cpuinitdata =
23227+static struct notifier_block tboot_cpu_notifier =
23228 {
23229 .notifier_call = tboot_cpu_callback,
23230 };
23231@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
23232
23233 tboot_create_trampoline();
23234
23235- atomic_set(&ap_wfs_count, 0);
23236+ atomic_set_unchecked(&ap_wfs_count, 0);
23237 register_hotcpu_notifier(&tboot_cpu_notifier);
23238
23239 acpi_os_set_prepare_sleep(&tboot_sleep);
23240diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
23241index 24d3c91..d06b473 100644
23242--- a/arch/x86/kernel/time.c
23243+++ b/arch/x86/kernel/time.c
23244@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
23245 {
23246 unsigned long pc = instruction_pointer(regs);
23247
23248- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
23249+ if (!user_mode(regs) && in_lock_functions(pc)) {
23250 #ifdef CONFIG_FRAME_POINTER
23251- return *(unsigned long *)(regs->bp + sizeof(long));
23252+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
23253 #else
23254 unsigned long *sp =
23255 (unsigned long *)kernel_stack_pointer(regs);
23256@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
23257 * or above a saved flags. Eflags has bits 22-31 zero,
23258 * kernel addresses don't.
23259 */
23260+
23261+#ifdef CONFIG_PAX_KERNEXEC
23262+ return ktla_ktva(sp[0]);
23263+#else
23264 if (sp[0] >> 22)
23265 return sp[0];
23266 if (sp[1] >> 22)
23267 return sp[1];
23268 #endif
23269+
23270+#endif
23271 }
23272 return pc;
23273 }
23274diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
23275index 9d9d2f9..cad418a 100644
23276--- a/arch/x86/kernel/tls.c
23277+++ b/arch/x86/kernel/tls.c
23278@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
23279 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
23280 return -EINVAL;
23281
23282+#ifdef CONFIG_PAX_SEGMEXEC
23283+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
23284+ return -EINVAL;
23285+#endif
23286+
23287 set_tls_desc(p, idx, &info, 1);
23288
23289 return 0;
23290@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
23291
23292 if (kbuf)
23293 info = kbuf;
23294- else if (__copy_from_user(infobuf, ubuf, count))
23295+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
23296 return -EFAULT;
23297 else
23298 info = infobuf;
23299diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
23300index 68bda7a..3ec7bb7 100644
23301--- a/arch/x86/kernel/traps.c
23302+++ b/arch/x86/kernel/traps.c
23303@@ -68,12 +68,6 @@
23304 #include <asm/setup.h>
23305
23306 asmlinkage int system_call(void);
23307-
23308-/*
23309- * The IDT has to be page-aligned to simplify the Pentium
23310- * F0 0F bug workaround.
23311- */
23312-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
23313 #endif
23314
23315 DECLARE_BITMAP(used_vectors, NR_VECTORS);
23316@@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
23317 }
23318
23319 static int __kprobes
23320-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23321+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
23322 struct pt_regs *regs, long error_code)
23323 {
23324 #ifdef CONFIG_X86_32
23325- if (regs->flags & X86_VM_MASK) {
23326+ if (v8086_mode(regs)) {
23327 /*
23328 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
23329 * On nmi (interrupt 2), do_trap should not be called.
23330@@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23331 return -1;
23332 }
23333 #endif
23334- if (!user_mode(regs)) {
23335+ if (!user_mode_novm(regs)) {
23336 if (!fixup_exception(regs)) {
23337 tsk->thread.error_code = error_code;
23338 tsk->thread.trap_nr = trapnr;
23339+
23340+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23341+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
23342+ str = "PAX: suspicious stack segment fault";
23343+#endif
23344+
23345 die(str, regs, error_code);
23346 }
23347+
23348+#ifdef CONFIG_PAX_REFCOUNT
23349+ if (trapnr == 4)
23350+ pax_report_refcount_overflow(regs);
23351+#endif
23352+
23353 return 0;
23354 }
23355
23356@@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23357 }
23358
23359 static void __kprobes
23360-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23361+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
23362 long error_code, siginfo_t *info)
23363 {
23364 struct task_struct *tsk = current;
23365@@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23366 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
23367 printk_ratelimit()) {
23368 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
23369- tsk->comm, tsk->pid, str,
23370+ tsk->comm, task_pid_nr(tsk), str,
23371 regs->ip, regs->sp, error_code);
23372 print_vma_addr(" in ", regs->ip);
23373 pr_cont("\n");
23374@@ -266,7 +272,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
23375 conditional_sti(regs);
23376
23377 #ifdef CONFIG_X86_32
23378- if (regs->flags & X86_VM_MASK) {
23379+ if (v8086_mode(regs)) {
23380 local_irq_enable();
23381 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
23382 goto exit;
23383@@ -274,18 +280,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
23384 #endif
23385
23386 tsk = current;
23387- if (!user_mode(regs)) {
23388+ if (!user_mode_novm(regs)) {
23389 if (fixup_exception(regs))
23390 goto exit;
23391
23392 tsk->thread.error_code = error_code;
23393 tsk->thread.trap_nr = X86_TRAP_GP;
23394 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
23395- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
23396+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
23397+
23398+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23399+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
23400+ die("PAX: suspicious general protection fault", regs, error_code);
23401+ else
23402+#endif
23403+
23404 die("general protection fault", regs, error_code);
23405+ }
23406 goto exit;
23407 }
23408
23409+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23410+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
23411+ struct mm_struct *mm = tsk->mm;
23412+ unsigned long limit;
23413+
23414+ down_write(&mm->mmap_sem);
23415+ limit = mm->context.user_cs_limit;
23416+ if (limit < TASK_SIZE) {
23417+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
23418+ up_write(&mm->mmap_sem);
23419+ return;
23420+ }
23421+ up_write(&mm->mmap_sem);
23422+ }
23423+#endif
23424+
23425 tsk->thread.error_code = error_code;
23426 tsk->thread.trap_nr = X86_TRAP_GP;
23427
23428@@ -440,7 +470,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23429 /* It's safe to allow irq's after DR6 has been saved */
23430 preempt_conditional_sti(regs);
23431
23432- if (regs->flags & X86_VM_MASK) {
23433+ if (v8086_mode(regs)) {
23434 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
23435 X86_TRAP_DB);
23436 preempt_conditional_cli(regs);
23437@@ -455,7 +485,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23438 * We already checked v86 mode above, so we can check for kernel mode
23439 * by just checking the CPL of CS.
23440 */
23441- if ((dr6 & DR_STEP) && !user_mode(regs)) {
23442+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
23443 tsk->thread.debugreg6 &= ~DR_STEP;
23444 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
23445 regs->flags &= ~X86_EFLAGS_TF;
23446@@ -487,7 +517,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
23447 return;
23448 conditional_sti(regs);
23449
23450- if (!user_mode_vm(regs))
23451+ if (!user_mode(regs))
23452 {
23453 if (!fixup_exception(regs)) {
23454 task->thread.error_code = error_code;
23455diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
23456index 0ba4cfb..4596bec 100644
23457--- a/arch/x86/kernel/uprobes.c
23458+++ b/arch/x86/kernel/uprobes.c
23459@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
23460 int ret = NOTIFY_DONE;
23461
23462 /* We are only interested in userspace traps */
23463- if (regs && !user_mode_vm(regs))
23464+ if (regs && !user_mode(regs))
23465 return NOTIFY_DONE;
23466
23467 switch (val) {
23468diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
23469index b9242ba..50c5edd 100644
23470--- a/arch/x86/kernel/verify_cpu.S
23471+++ b/arch/x86/kernel/verify_cpu.S
23472@@ -20,6 +20,7 @@
23473 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
23474 * arch/x86/kernel/trampoline_64.S: secondary processor verification
23475 * arch/x86/kernel/head_32.S: processor startup
23476+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
23477 *
23478 * verify_cpu, returns the status of longmode and SSE in register %eax.
23479 * 0: Success 1: Failure
23480diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
23481index 3dbdd9c..888b14e 100644
23482--- a/arch/x86/kernel/vm86_32.c
23483+++ b/arch/x86/kernel/vm86_32.c
23484@@ -44,6 +44,7 @@
23485 #include <linux/ptrace.h>
23486 #include <linux/audit.h>
23487 #include <linux/stddef.h>
23488+#include <linux/grsecurity.h>
23489
23490 #include <asm/uaccess.h>
23491 #include <asm/io.h>
23492@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
23493 do_exit(SIGSEGV);
23494 }
23495
23496- tss = &per_cpu(init_tss, get_cpu());
23497+ tss = init_tss + get_cpu();
23498 current->thread.sp0 = current->thread.saved_sp0;
23499 current->thread.sysenter_cs = __KERNEL_CS;
23500 load_sp0(tss, &current->thread);
23501@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
23502
23503 if (tsk->thread.saved_sp0)
23504 goto out;
23505+
23506+#ifdef CONFIG_GRKERNSEC_VM86
23507+ if (!capable(CAP_SYS_RAWIO)) {
23508+ gr_handle_vm86();
23509+ goto out;
23510+ }
23511+#endif
23512+
23513 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
23514 offsetof(struct kernel_vm86_struct, vm86plus) -
23515 sizeof(info.regs));
23516@@ -242,6 +251,14 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
23517 int tmp, ret;
23518 struct vm86plus_struct __user *v86;
23519
23520+#ifdef CONFIG_GRKERNSEC_VM86
23521+ if (!capable(CAP_SYS_RAWIO)) {
23522+ gr_handle_vm86();
23523+ ret = -EPERM;
23524+ goto out;
23525+ }
23526+#endif
23527+
23528 tsk = current;
23529 switch (cmd) {
23530 case VM86_REQUEST_IRQ:
23531@@ -329,7 +346,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
23532 tsk->thread.saved_fs = info->regs32->fs;
23533 tsk->thread.saved_gs = get_user_gs(info->regs32);
23534
23535- tss = &per_cpu(init_tss, get_cpu());
23536+ tss = init_tss + get_cpu();
23537 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
23538 if (cpu_has_sep)
23539 tsk->thread.sysenter_cs = 0;
23540@@ -536,7 +553,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
23541 goto cannot_handle;
23542 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
23543 goto cannot_handle;
23544- intr_ptr = (unsigned long __user *) (i << 2);
23545+ intr_ptr = (__force unsigned long __user *) (i << 2);
23546 if (get_user(segoffs, intr_ptr))
23547 goto cannot_handle;
23548 if ((segoffs >> 16) == BIOSSEG)
23549diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
23550index 22a1530..8fbaaad 100644
23551--- a/arch/x86/kernel/vmlinux.lds.S
23552+++ b/arch/x86/kernel/vmlinux.lds.S
23553@@ -26,6 +26,13 @@
23554 #include <asm/page_types.h>
23555 #include <asm/cache.h>
23556 #include <asm/boot.h>
23557+#include <asm/segment.h>
23558+
23559+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23560+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
23561+#else
23562+#define __KERNEL_TEXT_OFFSET 0
23563+#endif
23564
23565 #undef i386 /* in case the preprocessor is a 32bit one */
23566
23567@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
23568
23569 PHDRS {
23570 text PT_LOAD FLAGS(5); /* R_E */
23571+#ifdef CONFIG_X86_32
23572+ module PT_LOAD FLAGS(5); /* R_E */
23573+#endif
23574+#ifdef CONFIG_XEN
23575+ rodata PT_LOAD FLAGS(5); /* R_E */
23576+#else
23577+ rodata PT_LOAD FLAGS(4); /* R__ */
23578+#endif
23579 data PT_LOAD FLAGS(6); /* RW_ */
23580-#ifdef CONFIG_X86_64
23581+ init.begin PT_LOAD FLAGS(6); /* RW_ */
23582 #ifdef CONFIG_SMP
23583 percpu PT_LOAD FLAGS(6); /* RW_ */
23584 #endif
23585+ text.init PT_LOAD FLAGS(5); /* R_E */
23586+ text.exit PT_LOAD FLAGS(5); /* R_E */
23587 init PT_LOAD FLAGS(7); /* RWE */
23588-#endif
23589 note PT_NOTE FLAGS(0); /* ___ */
23590 }
23591
23592 SECTIONS
23593 {
23594 #ifdef CONFIG_X86_32
23595- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
23596- phys_startup_32 = startup_32 - LOAD_OFFSET;
23597+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
23598 #else
23599- . = __START_KERNEL;
23600- phys_startup_64 = startup_64 - LOAD_OFFSET;
23601+ . = __START_KERNEL;
23602 #endif
23603
23604 /* Text and read-only data */
23605- .text : AT(ADDR(.text) - LOAD_OFFSET) {
23606- _text = .;
23607+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23608 /* bootstrapping code */
23609+#ifdef CONFIG_X86_32
23610+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23611+#else
23612+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23613+#endif
23614+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23615+ _text = .;
23616 HEAD_TEXT
23617 #ifdef CONFIG_X86_32
23618 . = ALIGN(PAGE_SIZE);
23619@@ -108,13 +128,48 @@ SECTIONS
23620 IRQENTRY_TEXT
23621 *(.fixup)
23622 *(.gnu.warning)
23623- /* End of text section */
23624- _etext = .;
23625 } :text = 0x9090
23626
23627- NOTES :text :note
23628+ . += __KERNEL_TEXT_OFFSET;
23629
23630- EXCEPTION_TABLE(16) :text = 0x9090
23631+#ifdef CONFIG_X86_32
23632+ . = ALIGN(PAGE_SIZE);
23633+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
23634+
23635+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
23636+ MODULES_EXEC_VADDR = .;
23637+ BYTE(0)
23638+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
23639+ . = ALIGN(HPAGE_SIZE) - 1;
23640+ MODULES_EXEC_END = .;
23641+#endif
23642+
23643+ } :module
23644+#endif
23645+
23646+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
23647+ /* End of text section */
23648+ BYTE(0)
23649+ _etext = . - __KERNEL_TEXT_OFFSET;
23650+ }
23651+
23652+#ifdef CONFIG_X86_32
23653+ . = ALIGN(PAGE_SIZE);
23654+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
23655+ *(.idt)
23656+ . = ALIGN(PAGE_SIZE);
23657+ *(.empty_zero_page)
23658+ *(.initial_pg_fixmap)
23659+ *(.initial_pg_pmd)
23660+ *(.initial_page_table)
23661+ *(.swapper_pg_dir)
23662+ } :rodata
23663+#endif
23664+
23665+ . = ALIGN(PAGE_SIZE);
23666+ NOTES :rodata :note
23667+
23668+ EXCEPTION_TABLE(16) :rodata
23669
23670 #if defined(CONFIG_DEBUG_RODATA)
23671 /* .text should occupy whole number of pages */
23672@@ -126,16 +181,20 @@ SECTIONS
23673
23674 /* Data */
23675 .data : AT(ADDR(.data) - LOAD_OFFSET) {
23676+
23677+#ifdef CONFIG_PAX_KERNEXEC
23678+ . = ALIGN(HPAGE_SIZE);
23679+#else
23680+ . = ALIGN(PAGE_SIZE);
23681+#endif
23682+
23683 /* Start of data section */
23684 _sdata = .;
23685
23686 /* init_task */
23687 INIT_TASK_DATA(THREAD_SIZE)
23688
23689-#ifdef CONFIG_X86_32
23690- /* 32 bit has nosave before _edata */
23691 NOSAVE_DATA
23692-#endif
23693
23694 PAGE_ALIGNED_DATA(PAGE_SIZE)
23695
23696@@ -176,12 +235,19 @@ SECTIONS
23697 #endif /* CONFIG_X86_64 */
23698
23699 /* Init code and data - will be freed after init */
23700- . = ALIGN(PAGE_SIZE);
23701 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
23702+ BYTE(0)
23703+
23704+#ifdef CONFIG_PAX_KERNEXEC
23705+ . = ALIGN(HPAGE_SIZE);
23706+#else
23707+ . = ALIGN(PAGE_SIZE);
23708+#endif
23709+
23710 __init_begin = .; /* paired with __init_end */
23711- }
23712+ } :init.begin
23713
23714-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
23715+#ifdef CONFIG_SMP
23716 /*
23717 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
23718 * output PHDR, so the next output section - .init.text - should
23719@@ -190,12 +256,27 @@ SECTIONS
23720 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
23721 #endif
23722
23723- INIT_TEXT_SECTION(PAGE_SIZE)
23724-#ifdef CONFIG_X86_64
23725- :init
23726-#endif
23727+ . = ALIGN(PAGE_SIZE);
23728+ init_begin = .;
23729+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
23730+ VMLINUX_SYMBOL(_sinittext) = .;
23731+ INIT_TEXT
23732+ VMLINUX_SYMBOL(_einittext) = .;
23733+ . = ALIGN(PAGE_SIZE);
23734+ } :text.init
23735
23736- INIT_DATA_SECTION(16)
23737+ /*
23738+ * .exit.text is discard at runtime, not link time, to deal with
23739+ * references from .altinstructions and .eh_frame
23740+ */
23741+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23742+ EXIT_TEXT
23743+ . = ALIGN(16);
23744+ } :text.exit
23745+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
23746+
23747+ . = ALIGN(PAGE_SIZE);
23748+ INIT_DATA_SECTION(16) :init
23749
23750 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
23751 __x86_cpu_dev_start = .;
23752@@ -257,19 +338,12 @@ SECTIONS
23753 }
23754
23755 . = ALIGN(8);
23756- /*
23757- * .exit.text is discard at runtime, not link time, to deal with
23758- * references from .altinstructions and .eh_frame
23759- */
23760- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
23761- EXIT_TEXT
23762- }
23763
23764 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
23765 EXIT_DATA
23766 }
23767
23768-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
23769+#ifndef CONFIG_SMP
23770 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
23771 #endif
23772
23773@@ -288,16 +362,10 @@ SECTIONS
23774 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
23775 __smp_locks = .;
23776 *(.smp_locks)
23777- . = ALIGN(PAGE_SIZE);
23778 __smp_locks_end = .;
23779+ . = ALIGN(PAGE_SIZE);
23780 }
23781
23782-#ifdef CONFIG_X86_64
23783- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
23784- NOSAVE_DATA
23785- }
23786-#endif
23787-
23788 /* BSS */
23789 . = ALIGN(PAGE_SIZE);
23790 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
23791@@ -313,6 +381,7 @@ SECTIONS
23792 __brk_base = .;
23793 . += 64 * 1024; /* 64k alignment slop space */
23794 *(.brk_reservation) /* areas brk users have reserved */
23795+ . = ALIGN(HPAGE_SIZE);
23796 __brk_limit = .;
23797 }
23798
23799@@ -339,13 +408,12 @@ SECTIONS
23800 * for the boot processor.
23801 */
23802 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
23803-INIT_PER_CPU(gdt_page);
23804 INIT_PER_CPU(irq_stack_union);
23805
23806 /*
23807 * Build-time check on the image size:
23808 */
23809-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
23810+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
23811 "kernel image bigger than KERNEL_IMAGE_SIZE");
23812
23813 #ifdef CONFIG_SMP
23814diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
23815index 9a907a6..f83f921 100644
23816--- a/arch/x86/kernel/vsyscall_64.c
23817+++ b/arch/x86/kernel/vsyscall_64.c
23818@@ -56,15 +56,13 @@
23819 DEFINE_VVAR(int, vgetcpu_mode);
23820 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
23821
23822-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
23823+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
23824
23825 static int __init vsyscall_setup(char *str)
23826 {
23827 if (str) {
23828 if (!strcmp("emulate", str))
23829 vsyscall_mode = EMULATE;
23830- else if (!strcmp("native", str))
23831- vsyscall_mode = NATIVE;
23832 else if (!strcmp("none", str))
23833 vsyscall_mode = NONE;
23834 else
23835@@ -323,8 +321,7 @@ do_ret:
23836 return true;
23837
23838 sigsegv:
23839- force_sig(SIGSEGV, current);
23840- return true;
23841+ do_group_exit(SIGKILL);
23842 }
23843
23844 /*
23845@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
23846 extern char __vvar_page;
23847 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
23848
23849- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
23850- vsyscall_mode == NATIVE
23851- ? PAGE_KERNEL_VSYSCALL
23852- : PAGE_KERNEL_VVAR);
23853+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
23854 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
23855 (unsigned long)VSYSCALL_START);
23856
23857diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
23858index b014d94..6d6ca7b 100644
23859--- a/arch/x86/kernel/x8664_ksyms_64.c
23860+++ b/arch/x86/kernel/x8664_ksyms_64.c
23861@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
23862 EXPORT_SYMBOL(copy_user_generic_unrolled);
23863 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
23864 EXPORT_SYMBOL(__copy_user_nocache);
23865-EXPORT_SYMBOL(_copy_from_user);
23866-EXPORT_SYMBOL(_copy_to_user);
23867
23868 EXPORT_SYMBOL(copy_page);
23869 EXPORT_SYMBOL(clear_page);
23870diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
23871index 45a14db..075bb9b 100644
23872--- a/arch/x86/kernel/x86_init.c
23873+++ b/arch/x86/kernel/x86_init.c
23874@@ -85,7 +85,7 @@ struct x86_init_ops x86_init __initdata = {
23875 },
23876 };
23877
23878-struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23879+struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
23880 .early_percpu_clock_init = x86_init_noop,
23881 .setup_percpu_clockev = setup_secondary_APIC_clock,
23882 };
23883@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23884 static void default_nmi_init(void) { };
23885 static int default_i8042_detect(void) { return 1; };
23886
23887-struct x86_platform_ops x86_platform = {
23888+struct x86_platform_ops x86_platform __read_only = {
23889 .calibrate_tsc = native_calibrate_tsc,
23890 .get_wallclock = mach_get_cmos_time,
23891 .set_wallclock = mach_set_rtc_mmss,
23892@@ -107,7 +107,7 @@ struct x86_platform_ops x86_platform = {
23893 };
23894
23895 EXPORT_SYMBOL_GPL(x86_platform);
23896-struct x86_msi_ops x86_msi = {
23897+struct x86_msi_ops x86_msi __read_only = {
23898 .setup_msi_irqs = native_setup_msi_irqs,
23899 .compose_msi_msg = native_compose_msi_msg,
23900 .teardown_msi_irq = native_teardown_msi_irq,
23901@@ -116,7 +116,7 @@ struct x86_msi_ops x86_msi = {
23902 .setup_hpet_msi = default_setup_hpet_msi,
23903 };
23904
23905-struct x86_io_apic_ops x86_io_apic_ops = {
23906+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
23907 .init = native_io_apic_init_mappings,
23908 .read = native_io_apic_read,
23909 .write = native_io_apic_write,
23910diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
23911index ada87a3..afea76d 100644
23912--- a/arch/x86/kernel/xsave.c
23913+++ b/arch/x86/kernel/xsave.c
23914@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
23915 {
23916 int err;
23917
23918+ buf = (struct xsave_struct __user *)____m(buf);
23919 if (use_xsave())
23920 err = xsave_user(buf);
23921 else if (use_fxsr())
23922@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
23923 */
23924 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
23925 {
23926+ buf = (void __user *)____m(buf);
23927 if (use_xsave()) {
23928 if ((unsigned long)buf % 64 || fx_only) {
23929 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
23930diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
23931index a20ecb5..d0e2194 100644
23932--- a/arch/x86/kvm/cpuid.c
23933+++ b/arch/x86/kvm/cpuid.c
23934@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
23935 struct kvm_cpuid2 *cpuid,
23936 struct kvm_cpuid_entry2 __user *entries)
23937 {
23938- int r;
23939+ int r, i;
23940
23941 r = -E2BIG;
23942 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
23943 goto out;
23944 r = -EFAULT;
23945- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
23946- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23947+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23948 goto out;
23949+ for (i = 0; i < cpuid->nent; ++i) {
23950+ struct kvm_cpuid_entry2 cpuid_entry;
23951+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
23952+ goto out;
23953+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
23954+ }
23955 vcpu->arch.cpuid_nent = cpuid->nent;
23956 kvm_apic_set_version(vcpu);
23957 kvm_x86_ops->cpuid_update(vcpu);
23958@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
23959 struct kvm_cpuid2 *cpuid,
23960 struct kvm_cpuid_entry2 __user *entries)
23961 {
23962- int r;
23963+ int r, i;
23964
23965 r = -E2BIG;
23966 if (cpuid->nent < vcpu->arch.cpuid_nent)
23967 goto out;
23968 r = -EFAULT;
23969- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
23970- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23971+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23972 goto out;
23973+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
23974+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
23975+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
23976+ goto out;
23977+ }
23978 return 0;
23979
23980 out:
23981diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
23982index 698eece..776b682 100644
23983--- a/arch/x86/kvm/emulate.c
23984+++ b/arch/x86/kvm/emulate.c
23985@@ -328,6 +328,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23986
23987 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
23988 do { \
23989+ unsigned long _tmp; \
23990 __asm__ __volatile__ ( \
23991 _PRE_EFLAGS("0", "4", "2") \
23992 _op _suffix " %"_x"3,%1; " \
23993@@ -342,8 +343,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23994 /* Raw emulation: instruction has two explicit operands. */
23995 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
23996 do { \
23997- unsigned long _tmp; \
23998- \
23999 switch ((ctxt)->dst.bytes) { \
24000 case 2: \
24001 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
24002@@ -359,7 +358,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24003
24004 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
24005 do { \
24006- unsigned long _tmp; \
24007 switch ((ctxt)->dst.bytes) { \
24008 case 1: \
24009 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
24010diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
24011index f77df1c..6f20690 100644
24012--- a/arch/x86/kvm/lapic.c
24013+++ b/arch/x86/kvm/lapic.c
24014@@ -55,7 +55,7 @@
24015 #define APIC_BUS_CYCLE_NS 1
24016
24017 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
24018-#define apic_debug(fmt, arg...)
24019+#define apic_debug(fmt, arg...) do {} while (0)
24020
24021 #define APIC_LVT_NUM 6
24022 /* 14 is the version for Xeon and Pentium 8.4.8*/
24023diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
24024index 105dd5b..1b0ccc2 100644
24025--- a/arch/x86/kvm/paging_tmpl.h
24026+++ b/arch/x86/kvm/paging_tmpl.h
24027@@ -208,7 +208,7 @@ retry_walk:
24028 if (unlikely(kvm_is_error_hva(host_addr)))
24029 goto error;
24030
24031- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
24032+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
24033 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
24034 goto error;
24035 walker->ptep_user[walker->level - 1] = ptep_user;
24036diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
24037index e1b1ce2..f7b4b43 100644
24038--- a/arch/x86/kvm/svm.c
24039+++ b/arch/x86/kvm/svm.c
24040@@ -3507,7 +3507,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
24041 int cpu = raw_smp_processor_id();
24042
24043 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
24044+
24045+ pax_open_kernel();
24046 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
24047+ pax_close_kernel();
24048+
24049 load_TR_desc();
24050 }
24051
24052@@ -3901,6 +3905,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
24053 #endif
24054 #endif
24055
24056+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24057+ __set_fs(current_thread_info()->addr_limit);
24058+#endif
24059+
24060 reload_tss(vcpu);
24061
24062 local_irq_disable();
24063diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
24064index 0af1807..06912bb 100644
24065--- a/arch/x86/kvm/vmx.c
24066+++ b/arch/x86/kvm/vmx.c
24067@@ -1184,12 +1184,12 @@ static void vmcs_write64(unsigned long field, u64 value)
24068 #endif
24069 }
24070
24071-static void vmcs_clear_bits(unsigned long field, u32 mask)
24072+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
24073 {
24074 vmcs_writel(field, vmcs_readl(field) & ~mask);
24075 }
24076
24077-static void vmcs_set_bits(unsigned long field, u32 mask)
24078+static void vmcs_set_bits(unsigned long field, unsigned long mask)
24079 {
24080 vmcs_writel(field, vmcs_readl(field) | mask);
24081 }
24082@@ -1390,7 +1390,11 @@ static void reload_tss(void)
24083 struct desc_struct *descs;
24084
24085 descs = (void *)gdt->address;
24086+
24087+ pax_open_kernel();
24088 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
24089+ pax_close_kernel();
24090+
24091 load_TR_desc();
24092 }
24093
24094@@ -1614,6 +1618,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
24095 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
24096 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
24097
24098+#ifdef CONFIG_PAX_PER_CPU_PGD
24099+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
24100+#endif
24101+
24102 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
24103 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
24104 vmx->loaded_vmcs->cpu = cpu;
24105@@ -2779,8 +2787,11 @@ static __init int hardware_setup(void)
24106 if (!cpu_has_vmx_flexpriority())
24107 flexpriority_enabled = 0;
24108
24109- if (!cpu_has_vmx_tpr_shadow())
24110- kvm_x86_ops->update_cr8_intercept = NULL;
24111+ if (!cpu_has_vmx_tpr_shadow()) {
24112+ pax_open_kernel();
24113+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
24114+ pax_close_kernel();
24115+ }
24116
24117 if (enable_ept && !cpu_has_vmx_ept_2m_page())
24118 kvm_disable_largepages();
24119@@ -2792,10 +2803,12 @@ static __init int hardware_setup(void)
24120 !cpu_has_vmx_virtual_intr_delivery())
24121 enable_apicv_reg_vid = 0;
24122
24123+ pax_open_kernel();
24124 if (enable_apicv_reg_vid)
24125- kvm_x86_ops->update_cr8_intercept = NULL;
24126+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
24127 else
24128- kvm_x86_ops->hwapic_irr_update = NULL;
24129+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
24130+ pax_close_kernel();
24131
24132 if (nested)
24133 nested_vmx_setup_ctls_msrs();
24134@@ -3883,7 +3896,10 @@ static void vmx_set_constant_host_state(void)
24135
24136 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
24137 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
24138+
24139+#ifndef CONFIG_PAX_PER_CPU_PGD
24140 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
24141+#endif
24142
24143 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
24144 #ifdef CONFIG_X86_64
24145@@ -3904,7 +3920,7 @@ static void vmx_set_constant_host_state(void)
24146 native_store_idt(&dt);
24147 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
24148
24149- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
24150+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
24151
24152 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
24153 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
24154@@ -6580,6 +6596,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24155 "jmp 2f \n\t"
24156 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
24157 "2: "
24158+
24159+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24160+ "ljmp %[cs],$3f\n\t"
24161+ "3: "
24162+#endif
24163+
24164 /* Save guest registers, load host registers, keep flags */
24165 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
24166 "pop %0 \n\t"
24167@@ -6632,6 +6654,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24168 #endif
24169 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
24170 [wordsize]"i"(sizeof(ulong))
24171+
24172+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24173+ ,[cs]"i"(__KERNEL_CS)
24174+#endif
24175+
24176 : "cc", "memory"
24177 #ifdef CONFIG_X86_64
24178 , "rax", "rbx", "rdi", "rsi"
24179@@ -6645,7 +6672,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24180 if (debugctlmsr)
24181 update_debugctlmsr(debugctlmsr);
24182
24183-#ifndef CONFIG_X86_64
24184+#ifdef CONFIG_X86_32
24185 /*
24186 * The sysexit path does not restore ds/es, so we must set them to
24187 * a reasonable value ourselves.
24188@@ -6654,8 +6681,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24189 * may be executed in interrupt context, which saves and restore segments
24190 * around it, nullifying its effect.
24191 */
24192- loadsegment(ds, __USER_DS);
24193- loadsegment(es, __USER_DS);
24194+ loadsegment(ds, __KERNEL_DS);
24195+ loadsegment(es, __KERNEL_DS);
24196+ loadsegment(ss, __KERNEL_DS);
24197+
24198+#ifdef CONFIG_PAX_KERNEXEC
24199+ loadsegment(fs, __KERNEL_PERCPU);
24200+#endif
24201+
24202+#ifdef CONFIG_PAX_MEMORY_UDEREF
24203+ __set_fs(current_thread_info()->addr_limit);
24204+#endif
24205+
24206 #endif
24207
24208 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
24209diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
24210index e172132..c3d3e27 100644
24211--- a/arch/x86/kvm/x86.c
24212+++ b/arch/x86/kvm/x86.c
24213@@ -1686,8 +1686,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
24214 {
24215 struct kvm *kvm = vcpu->kvm;
24216 int lm = is_long_mode(vcpu);
24217- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24218- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24219+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24220+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24221 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
24222 : kvm->arch.xen_hvm_config.blob_size_32;
24223 u32 page_num = data & ~PAGE_MASK;
24224@@ -2567,6 +2567,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
24225 if (n < msr_list.nmsrs)
24226 goto out;
24227 r = -EFAULT;
24228+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
24229+ goto out;
24230 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
24231 num_msrs_to_save * sizeof(u32)))
24232 goto out;
24233@@ -2696,7 +2698,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
24234 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
24235 struct kvm_interrupt *irq)
24236 {
24237- if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
24238+ if (irq->irq >= KVM_NR_INTERRUPTS)
24239 return -EINVAL;
24240 if (irqchip_in_kernel(vcpu->kvm))
24241 return -ENXIO;
24242@@ -5247,7 +5249,7 @@ static struct notifier_block pvclock_gtod_notifier = {
24243 };
24244 #endif
24245
24246-int kvm_arch_init(void *opaque)
24247+int kvm_arch_init(const void *opaque)
24248 {
24249 int r;
24250 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
24251diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
24252index 7114c63..a1018fc 100644
24253--- a/arch/x86/lguest/boot.c
24254+++ b/arch/x86/lguest/boot.c
24255@@ -1201,9 +1201,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
24256 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
24257 * Launcher to reboot us.
24258 */
24259-static void lguest_restart(char *reason)
24260+static __noreturn void lguest_restart(char *reason)
24261 {
24262 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
24263+ BUG();
24264 }
24265
24266 /*G:050
24267diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
24268index 00933d5..3a64af9 100644
24269--- a/arch/x86/lib/atomic64_386_32.S
24270+++ b/arch/x86/lib/atomic64_386_32.S
24271@@ -48,6 +48,10 @@ BEGIN(read)
24272 movl (v), %eax
24273 movl 4(v), %edx
24274 RET_ENDP
24275+BEGIN(read_unchecked)
24276+ movl (v), %eax
24277+ movl 4(v), %edx
24278+RET_ENDP
24279 #undef v
24280
24281 #define v %esi
24282@@ -55,6 +59,10 @@ BEGIN(set)
24283 movl %ebx, (v)
24284 movl %ecx, 4(v)
24285 RET_ENDP
24286+BEGIN(set_unchecked)
24287+ movl %ebx, (v)
24288+ movl %ecx, 4(v)
24289+RET_ENDP
24290 #undef v
24291
24292 #define v %esi
24293@@ -70,6 +78,20 @@ RET_ENDP
24294 BEGIN(add)
24295 addl %eax, (v)
24296 adcl %edx, 4(v)
24297+
24298+#ifdef CONFIG_PAX_REFCOUNT
24299+ jno 0f
24300+ subl %eax, (v)
24301+ sbbl %edx, 4(v)
24302+ int $4
24303+0:
24304+ _ASM_EXTABLE(0b, 0b)
24305+#endif
24306+
24307+RET_ENDP
24308+BEGIN(add_unchecked)
24309+ addl %eax, (v)
24310+ adcl %edx, 4(v)
24311 RET_ENDP
24312 #undef v
24313
24314@@ -77,6 +99,24 @@ RET_ENDP
24315 BEGIN(add_return)
24316 addl (v), %eax
24317 adcl 4(v), %edx
24318+
24319+#ifdef CONFIG_PAX_REFCOUNT
24320+ into
24321+1234:
24322+ _ASM_EXTABLE(1234b, 2f)
24323+#endif
24324+
24325+ movl %eax, (v)
24326+ movl %edx, 4(v)
24327+
24328+#ifdef CONFIG_PAX_REFCOUNT
24329+2:
24330+#endif
24331+
24332+RET_ENDP
24333+BEGIN(add_return_unchecked)
24334+ addl (v), %eax
24335+ adcl 4(v), %edx
24336 movl %eax, (v)
24337 movl %edx, 4(v)
24338 RET_ENDP
24339@@ -86,6 +126,20 @@ RET_ENDP
24340 BEGIN(sub)
24341 subl %eax, (v)
24342 sbbl %edx, 4(v)
24343+
24344+#ifdef CONFIG_PAX_REFCOUNT
24345+ jno 0f
24346+ addl %eax, (v)
24347+ adcl %edx, 4(v)
24348+ int $4
24349+0:
24350+ _ASM_EXTABLE(0b, 0b)
24351+#endif
24352+
24353+RET_ENDP
24354+BEGIN(sub_unchecked)
24355+ subl %eax, (v)
24356+ sbbl %edx, 4(v)
24357 RET_ENDP
24358 #undef v
24359
24360@@ -96,6 +150,27 @@ BEGIN(sub_return)
24361 sbbl $0, %edx
24362 addl (v), %eax
24363 adcl 4(v), %edx
24364+
24365+#ifdef CONFIG_PAX_REFCOUNT
24366+ into
24367+1234:
24368+ _ASM_EXTABLE(1234b, 2f)
24369+#endif
24370+
24371+ movl %eax, (v)
24372+ movl %edx, 4(v)
24373+
24374+#ifdef CONFIG_PAX_REFCOUNT
24375+2:
24376+#endif
24377+
24378+RET_ENDP
24379+BEGIN(sub_return_unchecked)
24380+ negl %edx
24381+ negl %eax
24382+ sbbl $0, %edx
24383+ addl (v), %eax
24384+ adcl 4(v), %edx
24385 movl %eax, (v)
24386 movl %edx, 4(v)
24387 RET_ENDP
24388@@ -105,6 +180,20 @@ RET_ENDP
24389 BEGIN(inc)
24390 addl $1, (v)
24391 adcl $0, 4(v)
24392+
24393+#ifdef CONFIG_PAX_REFCOUNT
24394+ jno 0f
24395+ subl $1, (v)
24396+ sbbl $0, 4(v)
24397+ int $4
24398+0:
24399+ _ASM_EXTABLE(0b, 0b)
24400+#endif
24401+
24402+RET_ENDP
24403+BEGIN(inc_unchecked)
24404+ addl $1, (v)
24405+ adcl $0, 4(v)
24406 RET_ENDP
24407 #undef v
24408
24409@@ -114,6 +203,26 @@ BEGIN(inc_return)
24410 movl 4(v), %edx
24411 addl $1, %eax
24412 adcl $0, %edx
24413+
24414+#ifdef CONFIG_PAX_REFCOUNT
24415+ into
24416+1234:
24417+ _ASM_EXTABLE(1234b, 2f)
24418+#endif
24419+
24420+ movl %eax, (v)
24421+ movl %edx, 4(v)
24422+
24423+#ifdef CONFIG_PAX_REFCOUNT
24424+2:
24425+#endif
24426+
24427+RET_ENDP
24428+BEGIN(inc_return_unchecked)
24429+ movl (v), %eax
24430+ movl 4(v), %edx
24431+ addl $1, %eax
24432+ adcl $0, %edx
24433 movl %eax, (v)
24434 movl %edx, 4(v)
24435 RET_ENDP
24436@@ -123,6 +232,20 @@ RET_ENDP
24437 BEGIN(dec)
24438 subl $1, (v)
24439 sbbl $0, 4(v)
24440+
24441+#ifdef CONFIG_PAX_REFCOUNT
24442+ jno 0f
24443+ addl $1, (v)
24444+ adcl $0, 4(v)
24445+ int $4
24446+0:
24447+ _ASM_EXTABLE(0b, 0b)
24448+#endif
24449+
24450+RET_ENDP
24451+BEGIN(dec_unchecked)
24452+ subl $1, (v)
24453+ sbbl $0, 4(v)
24454 RET_ENDP
24455 #undef v
24456
24457@@ -132,6 +255,26 @@ BEGIN(dec_return)
24458 movl 4(v), %edx
24459 subl $1, %eax
24460 sbbl $0, %edx
24461+
24462+#ifdef CONFIG_PAX_REFCOUNT
24463+ into
24464+1234:
24465+ _ASM_EXTABLE(1234b, 2f)
24466+#endif
24467+
24468+ movl %eax, (v)
24469+ movl %edx, 4(v)
24470+
24471+#ifdef CONFIG_PAX_REFCOUNT
24472+2:
24473+#endif
24474+
24475+RET_ENDP
24476+BEGIN(dec_return_unchecked)
24477+ movl (v), %eax
24478+ movl 4(v), %edx
24479+ subl $1, %eax
24480+ sbbl $0, %edx
24481 movl %eax, (v)
24482 movl %edx, 4(v)
24483 RET_ENDP
24484@@ -143,6 +286,13 @@ BEGIN(add_unless)
24485 adcl %edx, %edi
24486 addl (v), %eax
24487 adcl 4(v), %edx
24488+
24489+#ifdef CONFIG_PAX_REFCOUNT
24490+ into
24491+1234:
24492+ _ASM_EXTABLE(1234b, 2f)
24493+#endif
24494+
24495 cmpl %eax, %ecx
24496 je 3f
24497 1:
24498@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
24499 1:
24500 addl $1, %eax
24501 adcl $0, %edx
24502+
24503+#ifdef CONFIG_PAX_REFCOUNT
24504+ into
24505+1234:
24506+ _ASM_EXTABLE(1234b, 2f)
24507+#endif
24508+
24509 movl %eax, (v)
24510 movl %edx, 4(v)
24511 movl $1, %eax
24512@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
24513 movl 4(v), %edx
24514 subl $1, %eax
24515 sbbl $0, %edx
24516+
24517+#ifdef CONFIG_PAX_REFCOUNT
24518+ into
24519+1234:
24520+ _ASM_EXTABLE(1234b, 1f)
24521+#endif
24522+
24523 js 1f
24524 movl %eax, (v)
24525 movl %edx, 4(v)
24526diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
24527index f5cc9eb..51fa319 100644
24528--- a/arch/x86/lib/atomic64_cx8_32.S
24529+++ b/arch/x86/lib/atomic64_cx8_32.S
24530@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
24531 CFI_STARTPROC
24532
24533 read64 %ecx
24534+ pax_force_retaddr
24535 ret
24536 CFI_ENDPROC
24537 ENDPROC(atomic64_read_cx8)
24538
24539+ENTRY(atomic64_read_unchecked_cx8)
24540+ CFI_STARTPROC
24541+
24542+ read64 %ecx
24543+ pax_force_retaddr
24544+ ret
24545+ CFI_ENDPROC
24546+ENDPROC(atomic64_read_unchecked_cx8)
24547+
24548 ENTRY(atomic64_set_cx8)
24549 CFI_STARTPROC
24550
24551@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
24552 cmpxchg8b (%esi)
24553 jne 1b
24554
24555+ pax_force_retaddr
24556 ret
24557 CFI_ENDPROC
24558 ENDPROC(atomic64_set_cx8)
24559
24560+ENTRY(atomic64_set_unchecked_cx8)
24561+ CFI_STARTPROC
24562+
24563+1:
24564+/* we don't need LOCK_PREFIX since aligned 64-bit writes
24565+ * are atomic on 586 and newer */
24566+ cmpxchg8b (%esi)
24567+ jne 1b
24568+
24569+ pax_force_retaddr
24570+ ret
24571+ CFI_ENDPROC
24572+ENDPROC(atomic64_set_unchecked_cx8)
24573+
24574 ENTRY(atomic64_xchg_cx8)
24575 CFI_STARTPROC
24576
24577@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
24578 cmpxchg8b (%esi)
24579 jne 1b
24580
24581+ pax_force_retaddr
24582 ret
24583 CFI_ENDPROC
24584 ENDPROC(atomic64_xchg_cx8)
24585
24586-.macro addsub_return func ins insc
24587-ENTRY(atomic64_\func\()_return_cx8)
24588+.macro addsub_return func ins insc unchecked=""
24589+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24590 CFI_STARTPROC
24591 SAVE ebp
24592 SAVE ebx
24593@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
24594 movl %edx, %ecx
24595 \ins\()l %esi, %ebx
24596 \insc\()l %edi, %ecx
24597+
24598+.ifb \unchecked
24599+#ifdef CONFIG_PAX_REFCOUNT
24600+ into
24601+2:
24602+ _ASM_EXTABLE(2b, 3f)
24603+#endif
24604+.endif
24605+
24606 LOCK_PREFIX
24607 cmpxchg8b (%ebp)
24608 jne 1b
24609-
24610-10:
24611 movl %ebx, %eax
24612 movl %ecx, %edx
24613+
24614+.ifb \unchecked
24615+#ifdef CONFIG_PAX_REFCOUNT
24616+3:
24617+#endif
24618+.endif
24619+
24620 RESTORE edi
24621 RESTORE esi
24622 RESTORE ebx
24623 RESTORE ebp
24624+ pax_force_retaddr
24625 ret
24626 CFI_ENDPROC
24627-ENDPROC(atomic64_\func\()_return_cx8)
24628+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24629 .endm
24630
24631 addsub_return add add adc
24632 addsub_return sub sub sbb
24633+addsub_return add add adc _unchecked
24634+addsub_return sub sub sbb _unchecked
24635
24636-.macro incdec_return func ins insc
24637-ENTRY(atomic64_\func\()_return_cx8)
24638+.macro incdec_return func ins insc unchecked=""
24639+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24640 CFI_STARTPROC
24641 SAVE ebx
24642
24643@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
24644 movl %edx, %ecx
24645 \ins\()l $1, %ebx
24646 \insc\()l $0, %ecx
24647+
24648+.ifb \unchecked
24649+#ifdef CONFIG_PAX_REFCOUNT
24650+ into
24651+2:
24652+ _ASM_EXTABLE(2b, 3f)
24653+#endif
24654+.endif
24655+
24656 LOCK_PREFIX
24657 cmpxchg8b (%esi)
24658 jne 1b
24659
24660-10:
24661 movl %ebx, %eax
24662 movl %ecx, %edx
24663+
24664+.ifb \unchecked
24665+#ifdef CONFIG_PAX_REFCOUNT
24666+3:
24667+#endif
24668+.endif
24669+
24670 RESTORE ebx
24671+ pax_force_retaddr
24672 ret
24673 CFI_ENDPROC
24674-ENDPROC(atomic64_\func\()_return_cx8)
24675+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24676 .endm
24677
24678 incdec_return inc add adc
24679 incdec_return dec sub sbb
24680+incdec_return inc add adc _unchecked
24681+incdec_return dec sub sbb _unchecked
24682
24683 ENTRY(atomic64_dec_if_positive_cx8)
24684 CFI_STARTPROC
24685@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
24686 movl %edx, %ecx
24687 subl $1, %ebx
24688 sbb $0, %ecx
24689+
24690+#ifdef CONFIG_PAX_REFCOUNT
24691+ into
24692+1234:
24693+ _ASM_EXTABLE(1234b, 2f)
24694+#endif
24695+
24696 js 2f
24697 LOCK_PREFIX
24698 cmpxchg8b (%esi)
24699@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
24700 movl %ebx, %eax
24701 movl %ecx, %edx
24702 RESTORE ebx
24703+ pax_force_retaddr
24704 ret
24705 CFI_ENDPROC
24706 ENDPROC(atomic64_dec_if_positive_cx8)
24707@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
24708 movl %edx, %ecx
24709 addl %ebp, %ebx
24710 adcl %edi, %ecx
24711+
24712+#ifdef CONFIG_PAX_REFCOUNT
24713+ into
24714+1234:
24715+ _ASM_EXTABLE(1234b, 3f)
24716+#endif
24717+
24718 LOCK_PREFIX
24719 cmpxchg8b (%esi)
24720 jne 1b
24721@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
24722 CFI_ADJUST_CFA_OFFSET -8
24723 RESTORE ebx
24724 RESTORE ebp
24725+ pax_force_retaddr
24726 ret
24727 4:
24728 cmpl %edx, 4(%esp)
24729@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
24730 xorl %ecx, %ecx
24731 addl $1, %ebx
24732 adcl %edx, %ecx
24733+
24734+#ifdef CONFIG_PAX_REFCOUNT
24735+ into
24736+1234:
24737+ _ASM_EXTABLE(1234b, 3f)
24738+#endif
24739+
24740 LOCK_PREFIX
24741 cmpxchg8b (%esi)
24742 jne 1b
24743@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
24744 movl $1, %eax
24745 3:
24746 RESTORE ebx
24747+ pax_force_retaddr
24748 ret
24749 CFI_ENDPROC
24750 ENDPROC(atomic64_inc_not_zero_cx8)
24751diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
24752index 2af5df3..62b1a5a 100644
24753--- a/arch/x86/lib/checksum_32.S
24754+++ b/arch/x86/lib/checksum_32.S
24755@@ -29,7 +29,8 @@
24756 #include <asm/dwarf2.h>
24757 #include <asm/errno.h>
24758 #include <asm/asm.h>
24759-
24760+#include <asm/segment.h>
24761+
24762 /*
24763 * computes a partial checksum, e.g. for TCP/UDP fragments
24764 */
24765@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
24766
24767 #define ARGBASE 16
24768 #define FP 12
24769-
24770-ENTRY(csum_partial_copy_generic)
24771+
24772+ENTRY(csum_partial_copy_generic_to_user)
24773 CFI_STARTPROC
24774+
24775+#ifdef CONFIG_PAX_MEMORY_UDEREF
24776+ pushl_cfi %gs
24777+ popl_cfi %es
24778+ jmp csum_partial_copy_generic
24779+#endif
24780+
24781+ENTRY(csum_partial_copy_generic_from_user)
24782+
24783+#ifdef CONFIG_PAX_MEMORY_UDEREF
24784+ pushl_cfi %gs
24785+ popl_cfi %ds
24786+#endif
24787+
24788+ENTRY(csum_partial_copy_generic)
24789 subl $4,%esp
24790 CFI_ADJUST_CFA_OFFSET 4
24791 pushl_cfi %edi
24792@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
24793 jmp 4f
24794 SRC(1: movw (%esi), %bx )
24795 addl $2, %esi
24796-DST( movw %bx, (%edi) )
24797+DST( movw %bx, %es:(%edi) )
24798 addl $2, %edi
24799 addw %bx, %ax
24800 adcl $0, %eax
24801@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
24802 SRC(1: movl (%esi), %ebx )
24803 SRC( movl 4(%esi), %edx )
24804 adcl %ebx, %eax
24805-DST( movl %ebx, (%edi) )
24806+DST( movl %ebx, %es:(%edi) )
24807 adcl %edx, %eax
24808-DST( movl %edx, 4(%edi) )
24809+DST( movl %edx, %es:4(%edi) )
24810
24811 SRC( movl 8(%esi), %ebx )
24812 SRC( movl 12(%esi), %edx )
24813 adcl %ebx, %eax
24814-DST( movl %ebx, 8(%edi) )
24815+DST( movl %ebx, %es:8(%edi) )
24816 adcl %edx, %eax
24817-DST( movl %edx, 12(%edi) )
24818+DST( movl %edx, %es:12(%edi) )
24819
24820 SRC( movl 16(%esi), %ebx )
24821 SRC( movl 20(%esi), %edx )
24822 adcl %ebx, %eax
24823-DST( movl %ebx, 16(%edi) )
24824+DST( movl %ebx, %es:16(%edi) )
24825 adcl %edx, %eax
24826-DST( movl %edx, 20(%edi) )
24827+DST( movl %edx, %es:20(%edi) )
24828
24829 SRC( movl 24(%esi), %ebx )
24830 SRC( movl 28(%esi), %edx )
24831 adcl %ebx, %eax
24832-DST( movl %ebx, 24(%edi) )
24833+DST( movl %ebx, %es:24(%edi) )
24834 adcl %edx, %eax
24835-DST( movl %edx, 28(%edi) )
24836+DST( movl %edx, %es:28(%edi) )
24837
24838 lea 32(%esi), %esi
24839 lea 32(%edi), %edi
24840@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
24841 shrl $2, %edx # This clears CF
24842 SRC(3: movl (%esi), %ebx )
24843 adcl %ebx, %eax
24844-DST( movl %ebx, (%edi) )
24845+DST( movl %ebx, %es:(%edi) )
24846 lea 4(%esi), %esi
24847 lea 4(%edi), %edi
24848 dec %edx
24849@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
24850 jb 5f
24851 SRC( movw (%esi), %cx )
24852 leal 2(%esi), %esi
24853-DST( movw %cx, (%edi) )
24854+DST( movw %cx, %es:(%edi) )
24855 leal 2(%edi), %edi
24856 je 6f
24857 shll $16,%ecx
24858 SRC(5: movb (%esi), %cl )
24859-DST( movb %cl, (%edi) )
24860+DST( movb %cl, %es:(%edi) )
24861 6: addl %ecx, %eax
24862 adcl $0, %eax
24863 7:
24864@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
24865
24866 6001:
24867 movl ARGBASE+20(%esp), %ebx # src_err_ptr
24868- movl $-EFAULT, (%ebx)
24869+ movl $-EFAULT, %ss:(%ebx)
24870
24871 # zero the complete destination - computing the rest
24872 # is too much work
24873@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
24874
24875 6002:
24876 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24877- movl $-EFAULT,(%ebx)
24878+ movl $-EFAULT,%ss:(%ebx)
24879 jmp 5000b
24880
24881 .previous
24882
24883+ pushl_cfi %ss
24884+ popl_cfi %ds
24885+ pushl_cfi %ss
24886+ popl_cfi %es
24887 popl_cfi %ebx
24888 CFI_RESTORE ebx
24889 popl_cfi %esi
24890@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
24891 popl_cfi %ecx # equivalent to addl $4,%esp
24892 ret
24893 CFI_ENDPROC
24894-ENDPROC(csum_partial_copy_generic)
24895+ENDPROC(csum_partial_copy_generic_to_user)
24896
24897 #else
24898
24899 /* Version for PentiumII/PPro */
24900
24901 #define ROUND1(x) \
24902+ nop; nop; nop; \
24903 SRC(movl x(%esi), %ebx ) ; \
24904 addl %ebx, %eax ; \
24905- DST(movl %ebx, x(%edi) ) ;
24906+ DST(movl %ebx, %es:x(%edi)) ;
24907
24908 #define ROUND(x) \
24909+ nop; nop; nop; \
24910 SRC(movl x(%esi), %ebx ) ; \
24911 adcl %ebx, %eax ; \
24912- DST(movl %ebx, x(%edi) ) ;
24913+ DST(movl %ebx, %es:x(%edi)) ;
24914
24915 #define ARGBASE 12
24916-
24917-ENTRY(csum_partial_copy_generic)
24918+
24919+ENTRY(csum_partial_copy_generic_to_user)
24920 CFI_STARTPROC
24921+
24922+#ifdef CONFIG_PAX_MEMORY_UDEREF
24923+ pushl_cfi %gs
24924+ popl_cfi %es
24925+ jmp csum_partial_copy_generic
24926+#endif
24927+
24928+ENTRY(csum_partial_copy_generic_from_user)
24929+
24930+#ifdef CONFIG_PAX_MEMORY_UDEREF
24931+ pushl_cfi %gs
24932+ popl_cfi %ds
24933+#endif
24934+
24935+ENTRY(csum_partial_copy_generic)
24936 pushl_cfi %ebx
24937 CFI_REL_OFFSET ebx, 0
24938 pushl_cfi %edi
24939@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
24940 subl %ebx, %edi
24941 lea -1(%esi),%edx
24942 andl $-32,%edx
24943- lea 3f(%ebx,%ebx), %ebx
24944+ lea 3f(%ebx,%ebx,2), %ebx
24945 testl %esi, %esi
24946 jmp *%ebx
24947 1: addl $64,%esi
24948@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
24949 jb 5f
24950 SRC( movw (%esi), %dx )
24951 leal 2(%esi), %esi
24952-DST( movw %dx, (%edi) )
24953+DST( movw %dx, %es:(%edi) )
24954 leal 2(%edi), %edi
24955 je 6f
24956 shll $16,%edx
24957 5:
24958 SRC( movb (%esi), %dl )
24959-DST( movb %dl, (%edi) )
24960+DST( movb %dl, %es:(%edi) )
24961 6: addl %edx, %eax
24962 adcl $0, %eax
24963 7:
24964 .section .fixup, "ax"
24965 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
24966- movl $-EFAULT, (%ebx)
24967+ movl $-EFAULT, %ss:(%ebx)
24968 # zero the complete destination (computing the rest is too much work)
24969 movl ARGBASE+8(%esp),%edi # dst
24970 movl ARGBASE+12(%esp),%ecx # len
24971@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
24972 rep; stosb
24973 jmp 7b
24974 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24975- movl $-EFAULT, (%ebx)
24976+ movl $-EFAULT, %ss:(%ebx)
24977 jmp 7b
24978 .previous
24979
24980+#ifdef CONFIG_PAX_MEMORY_UDEREF
24981+ pushl_cfi %ss
24982+ popl_cfi %ds
24983+ pushl_cfi %ss
24984+ popl_cfi %es
24985+#endif
24986+
24987 popl_cfi %esi
24988 CFI_RESTORE esi
24989 popl_cfi %edi
24990@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
24991 CFI_RESTORE ebx
24992 ret
24993 CFI_ENDPROC
24994-ENDPROC(csum_partial_copy_generic)
24995+ENDPROC(csum_partial_copy_generic_to_user)
24996
24997 #undef ROUND
24998 #undef ROUND1
24999diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
25000index f2145cf..cea889d 100644
25001--- a/arch/x86/lib/clear_page_64.S
25002+++ b/arch/x86/lib/clear_page_64.S
25003@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
25004 movl $4096/8,%ecx
25005 xorl %eax,%eax
25006 rep stosq
25007+ pax_force_retaddr
25008 ret
25009 CFI_ENDPROC
25010 ENDPROC(clear_page_c)
25011@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
25012 movl $4096,%ecx
25013 xorl %eax,%eax
25014 rep stosb
25015+ pax_force_retaddr
25016 ret
25017 CFI_ENDPROC
25018 ENDPROC(clear_page_c_e)
25019@@ -43,6 +45,7 @@ ENTRY(clear_page)
25020 leaq 64(%rdi),%rdi
25021 jnz .Lloop
25022 nop
25023+ pax_force_retaddr
25024 ret
25025 CFI_ENDPROC
25026 .Lclear_page_end:
25027@@ -58,7 +61,7 @@ ENDPROC(clear_page)
25028
25029 #include <asm/cpufeature.h>
25030
25031- .section .altinstr_replacement,"ax"
25032+ .section .altinstr_replacement,"a"
25033 1: .byte 0xeb /* jmp <disp8> */
25034 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
25035 2: .byte 0xeb /* jmp <disp8> */
25036diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
25037index 1e572c5..2a162cd 100644
25038--- a/arch/x86/lib/cmpxchg16b_emu.S
25039+++ b/arch/x86/lib/cmpxchg16b_emu.S
25040@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
25041
25042 popf
25043 mov $1, %al
25044+ pax_force_retaddr
25045 ret
25046
25047 not_same:
25048 popf
25049 xor %al,%al
25050+ pax_force_retaddr
25051 ret
25052
25053 CFI_ENDPROC
25054diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
25055index 176cca6..1166c50 100644
25056--- a/arch/x86/lib/copy_page_64.S
25057+++ b/arch/x86/lib/copy_page_64.S
25058@@ -9,6 +9,7 @@ copy_page_rep:
25059 CFI_STARTPROC
25060 movl $4096/8, %ecx
25061 rep movsq
25062+ pax_force_retaddr
25063 ret
25064 CFI_ENDPROC
25065 ENDPROC(copy_page_rep)
25066@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
25067
25068 ENTRY(copy_page)
25069 CFI_STARTPROC
25070- subq $2*8, %rsp
25071- CFI_ADJUST_CFA_OFFSET 2*8
25072+ subq $3*8, %rsp
25073+ CFI_ADJUST_CFA_OFFSET 3*8
25074 movq %rbx, (%rsp)
25075 CFI_REL_OFFSET rbx, 0
25076 movq %r12, 1*8(%rsp)
25077 CFI_REL_OFFSET r12, 1*8
25078+ movq %r13, 2*8(%rsp)
25079+ CFI_REL_OFFSET r13, 2*8
25080
25081 movl $(4096/64)-5, %ecx
25082 .p2align 4
25083@@ -36,7 +39,7 @@ ENTRY(copy_page)
25084 movq 0x8*2(%rsi), %rdx
25085 movq 0x8*3(%rsi), %r8
25086 movq 0x8*4(%rsi), %r9
25087- movq 0x8*5(%rsi), %r10
25088+ movq 0x8*5(%rsi), %r13
25089 movq 0x8*6(%rsi), %r11
25090 movq 0x8*7(%rsi), %r12
25091
25092@@ -47,7 +50,7 @@ ENTRY(copy_page)
25093 movq %rdx, 0x8*2(%rdi)
25094 movq %r8, 0x8*3(%rdi)
25095 movq %r9, 0x8*4(%rdi)
25096- movq %r10, 0x8*5(%rdi)
25097+ movq %r13, 0x8*5(%rdi)
25098 movq %r11, 0x8*6(%rdi)
25099 movq %r12, 0x8*7(%rdi)
25100
25101@@ -66,7 +69,7 @@ ENTRY(copy_page)
25102 movq 0x8*2(%rsi), %rdx
25103 movq 0x8*3(%rsi), %r8
25104 movq 0x8*4(%rsi), %r9
25105- movq 0x8*5(%rsi), %r10
25106+ movq 0x8*5(%rsi), %r13
25107 movq 0x8*6(%rsi), %r11
25108 movq 0x8*7(%rsi), %r12
25109
25110@@ -75,7 +78,7 @@ ENTRY(copy_page)
25111 movq %rdx, 0x8*2(%rdi)
25112 movq %r8, 0x8*3(%rdi)
25113 movq %r9, 0x8*4(%rdi)
25114- movq %r10, 0x8*5(%rdi)
25115+ movq %r13, 0x8*5(%rdi)
25116 movq %r11, 0x8*6(%rdi)
25117 movq %r12, 0x8*7(%rdi)
25118
25119@@ -87,8 +90,11 @@ ENTRY(copy_page)
25120 CFI_RESTORE rbx
25121 movq 1*8(%rsp), %r12
25122 CFI_RESTORE r12
25123- addq $2*8, %rsp
25124- CFI_ADJUST_CFA_OFFSET -2*8
25125+ movq 2*8(%rsp), %r13
25126+ CFI_RESTORE r13
25127+ addq $3*8, %rsp
25128+ CFI_ADJUST_CFA_OFFSET -3*8
25129+ pax_force_retaddr
25130 ret
25131 .Lcopy_page_end:
25132 CFI_ENDPROC
25133@@ -99,7 +105,7 @@ ENDPROC(copy_page)
25134
25135 #include <asm/cpufeature.h>
25136
25137- .section .altinstr_replacement,"ax"
25138+ .section .altinstr_replacement,"a"
25139 1: .byte 0xeb /* jmp <disp8> */
25140 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
25141 2:
25142diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
25143index a30ca15..d25fab6 100644
25144--- a/arch/x86/lib/copy_user_64.S
25145+++ b/arch/x86/lib/copy_user_64.S
25146@@ -18,6 +18,7 @@
25147 #include <asm/alternative-asm.h>
25148 #include <asm/asm.h>
25149 #include <asm/smap.h>
25150+#include <asm/pgtable.h>
25151
25152 /*
25153 * By placing feature2 after feature1 in altinstructions section, we logically
25154@@ -31,7 +32,7 @@
25155 .byte 0xe9 /* 32bit jump */
25156 .long \orig-1f /* by default jump to orig */
25157 1:
25158- .section .altinstr_replacement,"ax"
25159+ .section .altinstr_replacement,"a"
25160 2: .byte 0xe9 /* near jump with 32bit immediate */
25161 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
25162 3: .byte 0xe9 /* near jump with 32bit immediate */
25163@@ -70,47 +71,20 @@
25164 #endif
25165 .endm
25166
25167-/* Standard copy_to_user with segment limit checking */
25168-ENTRY(_copy_to_user)
25169- CFI_STARTPROC
25170- GET_THREAD_INFO(%rax)
25171- movq %rdi,%rcx
25172- addq %rdx,%rcx
25173- jc bad_to_user
25174- cmpq TI_addr_limit(%rax),%rcx
25175- ja bad_to_user
25176- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25177- copy_user_generic_unrolled,copy_user_generic_string, \
25178- copy_user_enhanced_fast_string
25179- CFI_ENDPROC
25180-ENDPROC(_copy_to_user)
25181-
25182-/* Standard copy_from_user with segment limit checking */
25183-ENTRY(_copy_from_user)
25184- CFI_STARTPROC
25185- GET_THREAD_INFO(%rax)
25186- movq %rsi,%rcx
25187- addq %rdx,%rcx
25188- jc bad_from_user
25189- cmpq TI_addr_limit(%rax),%rcx
25190- ja bad_from_user
25191- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25192- copy_user_generic_unrolled,copy_user_generic_string, \
25193- copy_user_enhanced_fast_string
25194- CFI_ENDPROC
25195-ENDPROC(_copy_from_user)
25196-
25197 .section .fixup,"ax"
25198 /* must zero dest */
25199 ENTRY(bad_from_user)
25200 bad_from_user:
25201 CFI_STARTPROC
25202+ testl %edx,%edx
25203+ js bad_to_user
25204 movl %edx,%ecx
25205 xorl %eax,%eax
25206 rep
25207 stosb
25208 bad_to_user:
25209 movl %edx,%eax
25210+ pax_force_retaddr
25211 ret
25212 CFI_ENDPROC
25213 ENDPROC(bad_from_user)
25214@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
25215 jz 17f
25216 1: movq (%rsi),%r8
25217 2: movq 1*8(%rsi),%r9
25218-3: movq 2*8(%rsi),%r10
25219+3: movq 2*8(%rsi),%rax
25220 4: movq 3*8(%rsi),%r11
25221 5: movq %r8,(%rdi)
25222 6: movq %r9,1*8(%rdi)
25223-7: movq %r10,2*8(%rdi)
25224+7: movq %rax,2*8(%rdi)
25225 8: movq %r11,3*8(%rdi)
25226 9: movq 4*8(%rsi),%r8
25227 10: movq 5*8(%rsi),%r9
25228-11: movq 6*8(%rsi),%r10
25229+11: movq 6*8(%rsi),%rax
25230 12: movq 7*8(%rsi),%r11
25231 13: movq %r8,4*8(%rdi)
25232 14: movq %r9,5*8(%rdi)
25233-15: movq %r10,6*8(%rdi)
25234+15: movq %rax,6*8(%rdi)
25235 16: movq %r11,7*8(%rdi)
25236 leaq 64(%rsi),%rsi
25237 leaq 64(%rdi),%rdi
25238@@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
25239 jnz 21b
25240 23: xor %eax,%eax
25241 ASM_CLAC
25242+ pax_force_retaddr
25243 ret
25244
25245 .section .fixup,"ax"
25246@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
25247 movsb
25248 4: xorl %eax,%eax
25249 ASM_CLAC
25250+ pax_force_retaddr
25251 ret
25252
25253 .section .fixup,"ax"
25254@@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
25255 movsb
25256 2: xorl %eax,%eax
25257 ASM_CLAC
25258+ pax_force_retaddr
25259 ret
25260
25261 .section .fixup,"ax"
25262diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
25263index 6a4f43c..f08b4a2 100644
25264--- a/arch/x86/lib/copy_user_nocache_64.S
25265+++ b/arch/x86/lib/copy_user_nocache_64.S
25266@@ -8,6 +8,7 @@
25267
25268 #include <linux/linkage.h>
25269 #include <asm/dwarf2.h>
25270+#include <asm/alternative-asm.h>
25271
25272 #define FIX_ALIGNMENT 1
25273
25274@@ -16,6 +17,7 @@
25275 #include <asm/thread_info.h>
25276 #include <asm/asm.h>
25277 #include <asm/smap.h>
25278+#include <asm/pgtable.h>
25279
25280 .macro ALIGN_DESTINATION
25281 #ifdef FIX_ALIGNMENT
25282@@ -49,6 +51,15 @@
25283 */
25284 ENTRY(__copy_user_nocache)
25285 CFI_STARTPROC
25286+
25287+#ifdef CONFIG_PAX_MEMORY_UDEREF
25288+ mov pax_user_shadow_base,%rcx
25289+ cmp %rcx,%rsi
25290+ jae 1f
25291+ add %rcx,%rsi
25292+1:
25293+#endif
25294+
25295 ASM_STAC
25296 cmpl $8,%edx
25297 jb 20f /* less then 8 bytes, go to byte copy loop */
25298@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
25299 jz 17f
25300 1: movq (%rsi),%r8
25301 2: movq 1*8(%rsi),%r9
25302-3: movq 2*8(%rsi),%r10
25303+3: movq 2*8(%rsi),%rax
25304 4: movq 3*8(%rsi),%r11
25305 5: movnti %r8,(%rdi)
25306 6: movnti %r9,1*8(%rdi)
25307-7: movnti %r10,2*8(%rdi)
25308+7: movnti %rax,2*8(%rdi)
25309 8: movnti %r11,3*8(%rdi)
25310 9: movq 4*8(%rsi),%r8
25311 10: movq 5*8(%rsi),%r9
25312-11: movq 6*8(%rsi),%r10
25313+11: movq 6*8(%rsi),%rax
25314 12: movq 7*8(%rsi),%r11
25315 13: movnti %r8,4*8(%rdi)
25316 14: movnti %r9,5*8(%rdi)
25317-15: movnti %r10,6*8(%rdi)
25318+15: movnti %rax,6*8(%rdi)
25319 16: movnti %r11,7*8(%rdi)
25320 leaq 64(%rsi),%rsi
25321 leaq 64(%rdi),%rdi
25322@@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
25323 23: xorl %eax,%eax
25324 ASM_CLAC
25325 sfence
25326+ pax_force_retaddr
25327 ret
25328
25329 .section .fixup,"ax"
25330diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
25331index 2419d5f..953ee51 100644
25332--- a/arch/x86/lib/csum-copy_64.S
25333+++ b/arch/x86/lib/csum-copy_64.S
25334@@ -9,6 +9,7 @@
25335 #include <asm/dwarf2.h>
25336 #include <asm/errno.h>
25337 #include <asm/asm.h>
25338+#include <asm/alternative-asm.h>
25339
25340 /*
25341 * Checksum copy with exception handling.
25342@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
25343 CFI_RESTORE rbp
25344 addq $7*8, %rsp
25345 CFI_ADJUST_CFA_OFFSET -7*8
25346+ pax_force_retaddr 0, 1
25347 ret
25348 CFI_RESTORE_STATE
25349
25350diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
25351index 25b7ae8..169fafc 100644
25352--- a/arch/x86/lib/csum-wrappers_64.c
25353+++ b/arch/x86/lib/csum-wrappers_64.c
25354@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
25355 len -= 2;
25356 }
25357 }
25358- isum = csum_partial_copy_generic((__force const void *)src,
25359+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
25360 dst, len, isum, errp, NULL);
25361 if (unlikely(*errp))
25362 goto out_err;
25363@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
25364 }
25365
25366 *errp = 0;
25367- return csum_partial_copy_generic(src, (void __force *)dst,
25368+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
25369 len, isum, NULL, errp);
25370 }
25371 EXPORT_SYMBOL(csum_partial_copy_to_user);
25372diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
25373index a451235..79fb5cf 100644
25374--- a/arch/x86/lib/getuser.S
25375+++ b/arch/x86/lib/getuser.S
25376@@ -33,17 +33,40 @@
25377 #include <asm/thread_info.h>
25378 #include <asm/asm.h>
25379 #include <asm/smap.h>
25380+#include <asm/segment.h>
25381+#include <asm/pgtable.h>
25382+#include <asm/alternative-asm.h>
25383+
25384+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25385+#define __copyuser_seg gs;
25386+#else
25387+#define __copyuser_seg
25388+#endif
25389
25390 .text
25391 ENTRY(__get_user_1)
25392 CFI_STARTPROC
25393+
25394+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25395 GET_THREAD_INFO(%_ASM_DX)
25396 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25397 jae bad_get_user
25398 ASM_STAC
25399-1: movzbl (%_ASM_AX),%edx
25400+
25401+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25402+ mov pax_user_shadow_base,%_ASM_DX
25403+ cmp %_ASM_DX,%_ASM_AX
25404+ jae 1234f
25405+ add %_ASM_DX,%_ASM_AX
25406+1234:
25407+#endif
25408+
25409+#endif
25410+
25411+1: __copyuser_seg movzbl (%_ASM_AX),%edx
25412 xor %eax,%eax
25413 ASM_CLAC
25414+ pax_force_retaddr
25415 ret
25416 CFI_ENDPROC
25417 ENDPROC(__get_user_1)
25418@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
25419 ENTRY(__get_user_2)
25420 CFI_STARTPROC
25421 add $1,%_ASM_AX
25422+
25423+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25424 jc bad_get_user
25425 GET_THREAD_INFO(%_ASM_DX)
25426 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25427 jae bad_get_user
25428 ASM_STAC
25429-2: movzwl -1(%_ASM_AX),%edx
25430+
25431+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25432+ mov pax_user_shadow_base,%_ASM_DX
25433+ cmp %_ASM_DX,%_ASM_AX
25434+ jae 1234f
25435+ add %_ASM_DX,%_ASM_AX
25436+1234:
25437+#endif
25438+
25439+#endif
25440+
25441+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
25442 xor %eax,%eax
25443 ASM_CLAC
25444+ pax_force_retaddr
25445 ret
25446 CFI_ENDPROC
25447 ENDPROC(__get_user_2)
25448@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
25449 ENTRY(__get_user_4)
25450 CFI_STARTPROC
25451 add $3,%_ASM_AX
25452+
25453+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25454 jc bad_get_user
25455 GET_THREAD_INFO(%_ASM_DX)
25456 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25457 jae bad_get_user
25458 ASM_STAC
25459-3: movl -3(%_ASM_AX),%edx
25460+
25461+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25462+ mov pax_user_shadow_base,%_ASM_DX
25463+ cmp %_ASM_DX,%_ASM_AX
25464+ jae 1234f
25465+ add %_ASM_DX,%_ASM_AX
25466+1234:
25467+#endif
25468+
25469+#endif
25470+
25471+3: __copyuser_seg movl -3(%_ASM_AX),%edx
25472 xor %eax,%eax
25473 ASM_CLAC
25474+ pax_force_retaddr
25475 ret
25476 CFI_ENDPROC
25477 ENDPROC(__get_user_4)
25478@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
25479 GET_THREAD_INFO(%_ASM_DX)
25480 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25481 jae bad_get_user
25482+
25483+#ifdef CONFIG_PAX_MEMORY_UDEREF
25484+ mov pax_user_shadow_base,%_ASM_DX
25485+ cmp %_ASM_DX,%_ASM_AX
25486+ jae 1234f
25487+ add %_ASM_DX,%_ASM_AX
25488+1234:
25489+#endif
25490+
25491 ASM_STAC
25492 4: movq -7(%_ASM_AX),%rdx
25493 xor %eax,%eax
25494 ASM_CLAC
25495+ pax_force_retaddr
25496 ret
25497 #else
25498 add $7,%_ASM_AX
25499@@ -102,6 +163,7 @@ ENTRY(__get_user_8)
25500 5: movl -3(%_ASM_AX),%ecx
25501 xor %eax,%eax
25502 ASM_CLAC
25503+ pax_force_retaddr
25504 ret
25505 #endif
25506 CFI_ENDPROC
25507@@ -113,6 +175,7 @@ bad_get_user:
25508 xor %edx,%edx
25509 mov $(-EFAULT),%_ASM_AX
25510 ASM_CLAC
25511+ pax_force_retaddr
25512 ret
25513 CFI_ENDPROC
25514 END(bad_get_user)
25515@@ -124,6 +187,7 @@ bad_get_user_8:
25516 xor %ecx,%ecx
25517 mov $(-EFAULT),%_ASM_AX
25518 ASM_CLAC
25519+ pax_force_retaddr
25520 ret
25521 CFI_ENDPROC
25522 END(bad_get_user_8)
25523diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
25524index 54fcffe..7be149e 100644
25525--- a/arch/x86/lib/insn.c
25526+++ b/arch/x86/lib/insn.c
25527@@ -20,8 +20,10 @@
25528
25529 #ifdef __KERNEL__
25530 #include <linux/string.h>
25531+#include <asm/pgtable_types.h>
25532 #else
25533 #include <string.h>
25534+#define ktla_ktva(addr) addr
25535 #endif
25536 #include <asm/inat.h>
25537 #include <asm/insn.h>
25538@@ -53,8 +55,8 @@
25539 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
25540 {
25541 memset(insn, 0, sizeof(*insn));
25542- insn->kaddr = kaddr;
25543- insn->next_byte = kaddr;
25544+ insn->kaddr = ktla_ktva(kaddr);
25545+ insn->next_byte = ktla_ktva(kaddr);
25546 insn->x86_64 = x86_64 ? 1 : 0;
25547 insn->opnd_bytes = 4;
25548 if (x86_64)
25549diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
25550index 05a95e7..326f2fa 100644
25551--- a/arch/x86/lib/iomap_copy_64.S
25552+++ b/arch/x86/lib/iomap_copy_64.S
25553@@ -17,6 +17,7 @@
25554
25555 #include <linux/linkage.h>
25556 #include <asm/dwarf2.h>
25557+#include <asm/alternative-asm.h>
25558
25559 /*
25560 * override generic version in lib/iomap_copy.c
25561@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
25562 CFI_STARTPROC
25563 movl %edx,%ecx
25564 rep movsd
25565+ pax_force_retaddr
25566 ret
25567 CFI_ENDPROC
25568 ENDPROC(__iowrite32_copy)
25569diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
25570index 1c273be..da9cc0e 100644
25571--- a/arch/x86/lib/memcpy_64.S
25572+++ b/arch/x86/lib/memcpy_64.S
25573@@ -33,6 +33,7 @@
25574 rep movsq
25575 movl %edx, %ecx
25576 rep movsb
25577+ pax_force_retaddr
25578 ret
25579 .Lmemcpy_e:
25580 .previous
25581@@ -49,6 +50,7 @@
25582 movq %rdi, %rax
25583 movq %rdx, %rcx
25584 rep movsb
25585+ pax_force_retaddr
25586 ret
25587 .Lmemcpy_e_e:
25588 .previous
25589@@ -76,13 +78,13 @@ ENTRY(memcpy)
25590 */
25591 movq 0*8(%rsi), %r8
25592 movq 1*8(%rsi), %r9
25593- movq 2*8(%rsi), %r10
25594+ movq 2*8(%rsi), %rcx
25595 movq 3*8(%rsi), %r11
25596 leaq 4*8(%rsi), %rsi
25597
25598 movq %r8, 0*8(%rdi)
25599 movq %r9, 1*8(%rdi)
25600- movq %r10, 2*8(%rdi)
25601+ movq %rcx, 2*8(%rdi)
25602 movq %r11, 3*8(%rdi)
25603 leaq 4*8(%rdi), %rdi
25604 jae .Lcopy_forward_loop
25605@@ -105,12 +107,12 @@ ENTRY(memcpy)
25606 subq $0x20, %rdx
25607 movq -1*8(%rsi), %r8
25608 movq -2*8(%rsi), %r9
25609- movq -3*8(%rsi), %r10
25610+ movq -3*8(%rsi), %rcx
25611 movq -4*8(%rsi), %r11
25612 leaq -4*8(%rsi), %rsi
25613 movq %r8, -1*8(%rdi)
25614 movq %r9, -2*8(%rdi)
25615- movq %r10, -3*8(%rdi)
25616+ movq %rcx, -3*8(%rdi)
25617 movq %r11, -4*8(%rdi)
25618 leaq -4*8(%rdi), %rdi
25619 jae .Lcopy_backward_loop
25620@@ -130,12 +132,13 @@ ENTRY(memcpy)
25621 */
25622 movq 0*8(%rsi), %r8
25623 movq 1*8(%rsi), %r9
25624- movq -2*8(%rsi, %rdx), %r10
25625+ movq -2*8(%rsi, %rdx), %rcx
25626 movq -1*8(%rsi, %rdx), %r11
25627 movq %r8, 0*8(%rdi)
25628 movq %r9, 1*8(%rdi)
25629- movq %r10, -2*8(%rdi, %rdx)
25630+ movq %rcx, -2*8(%rdi, %rdx)
25631 movq %r11, -1*8(%rdi, %rdx)
25632+ pax_force_retaddr
25633 retq
25634 .p2align 4
25635 .Lless_16bytes:
25636@@ -148,6 +151,7 @@ ENTRY(memcpy)
25637 movq -1*8(%rsi, %rdx), %r9
25638 movq %r8, 0*8(%rdi)
25639 movq %r9, -1*8(%rdi, %rdx)
25640+ pax_force_retaddr
25641 retq
25642 .p2align 4
25643 .Lless_8bytes:
25644@@ -161,6 +165,7 @@ ENTRY(memcpy)
25645 movl -4(%rsi, %rdx), %r8d
25646 movl %ecx, (%rdi)
25647 movl %r8d, -4(%rdi, %rdx)
25648+ pax_force_retaddr
25649 retq
25650 .p2align 4
25651 .Lless_3bytes:
25652@@ -179,6 +184,7 @@ ENTRY(memcpy)
25653 movb %cl, (%rdi)
25654
25655 .Lend:
25656+ pax_force_retaddr
25657 retq
25658 CFI_ENDPROC
25659 ENDPROC(memcpy)
25660diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
25661index ee16461..c39c199 100644
25662--- a/arch/x86/lib/memmove_64.S
25663+++ b/arch/x86/lib/memmove_64.S
25664@@ -61,13 +61,13 @@ ENTRY(memmove)
25665 5:
25666 sub $0x20, %rdx
25667 movq 0*8(%rsi), %r11
25668- movq 1*8(%rsi), %r10
25669+ movq 1*8(%rsi), %rcx
25670 movq 2*8(%rsi), %r9
25671 movq 3*8(%rsi), %r8
25672 leaq 4*8(%rsi), %rsi
25673
25674 movq %r11, 0*8(%rdi)
25675- movq %r10, 1*8(%rdi)
25676+ movq %rcx, 1*8(%rdi)
25677 movq %r9, 2*8(%rdi)
25678 movq %r8, 3*8(%rdi)
25679 leaq 4*8(%rdi), %rdi
25680@@ -81,10 +81,10 @@ ENTRY(memmove)
25681 4:
25682 movq %rdx, %rcx
25683 movq -8(%rsi, %rdx), %r11
25684- lea -8(%rdi, %rdx), %r10
25685+ lea -8(%rdi, %rdx), %r9
25686 shrq $3, %rcx
25687 rep movsq
25688- movq %r11, (%r10)
25689+ movq %r11, (%r9)
25690 jmp 13f
25691 .Lmemmove_end_forward:
25692
25693@@ -95,14 +95,14 @@ ENTRY(memmove)
25694 7:
25695 movq %rdx, %rcx
25696 movq (%rsi), %r11
25697- movq %rdi, %r10
25698+ movq %rdi, %r9
25699 leaq -8(%rsi, %rdx), %rsi
25700 leaq -8(%rdi, %rdx), %rdi
25701 shrq $3, %rcx
25702 std
25703 rep movsq
25704 cld
25705- movq %r11, (%r10)
25706+ movq %r11, (%r9)
25707 jmp 13f
25708
25709 /*
25710@@ -127,13 +127,13 @@ ENTRY(memmove)
25711 8:
25712 subq $0x20, %rdx
25713 movq -1*8(%rsi), %r11
25714- movq -2*8(%rsi), %r10
25715+ movq -2*8(%rsi), %rcx
25716 movq -3*8(%rsi), %r9
25717 movq -4*8(%rsi), %r8
25718 leaq -4*8(%rsi), %rsi
25719
25720 movq %r11, -1*8(%rdi)
25721- movq %r10, -2*8(%rdi)
25722+ movq %rcx, -2*8(%rdi)
25723 movq %r9, -3*8(%rdi)
25724 movq %r8, -4*8(%rdi)
25725 leaq -4*8(%rdi), %rdi
25726@@ -151,11 +151,11 @@ ENTRY(memmove)
25727 * Move data from 16 bytes to 31 bytes.
25728 */
25729 movq 0*8(%rsi), %r11
25730- movq 1*8(%rsi), %r10
25731+ movq 1*8(%rsi), %rcx
25732 movq -2*8(%rsi, %rdx), %r9
25733 movq -1*8(%rsi, %rdx), %r8
25734 movq %r11, 0*8(%rdi)
25735- movq %r10, 1*8(%rdi)
25736+ movq %rcx, 1*8(%rdi)
25737 movq %r9, -2*8(%rdi, %rdx)
25738 movq %r8, -1*8(%rdi, %rdx)
25739 jmp 13f
25740@@ -167,9 +167,9 @@ ENTRY(memmove)
25741 * Move data from 8 bytes to 15 bytes.
25742 */
25743 movq 0*8(%rsi), %r11
25744- movq -1*8(%rsi, %rdx), %r10
25745+ movq -1*8(%rsi, %rdx), %r9
25746 movq %r11, 0*8(%rdi)
25747- movq %r10, -1*8(%rdi, %rdx)
25748+ movq %r9, -1*8(%rdi, %rdx)
25749 jmp 13f
25750 10:
25751 cmpq $4, %rdx
25752@@ -178,9 +178,9 @@ ENTRY(memmove)
25753 * Move data from 4 bytes to 7 bytes.
25754 */
25755 movl (%rsi), %r11d
25756- movl -4(%rsi, %rdx), %r10d
25757+ movl -4(%rsi, %rdx), %r9d
25758 movl %r11d, (%rdi)
25759- movl %r10d, -4(%rdi, %rdx)
25760+ movl %r9d, -4(%rdi, %rdx)
25761 jmp 13f
25762 11:
25763 cmp $2, %rdx
25764@@ -189,9 +189,9 @@ ENTRY(memmove)
25765 * Move data from 2 bytes to 3 bytes.
25766 */
25767 movw (%rsi), %r11w
25768- movw -2(%rsi, %rdx), %r10w
25769+ movw -2(%rsi, %rdx), %r9w
25770 movw %r11w, (%rdi)
25771- movw %r10w, -2(%rdi, %rdx)
25772+ movw %r9w, -2(%rdi, %rdx)
25773 jmp 13f
25774 12:
25775 cmp $1, %rdx
25776@@ -202,6 +202,7 @@ ENTRY(memmove)
25777 movb (%rsi), %r11b
25778 movb %r11b, (%rdi)
25779 13:
25780+ pax_force_retaddr
25781 retq
25782 CFI_ENDPROC
25783
25784@@ -210,6 +211,7 @@ ENTRY(memmove)
25785 /* Forward moving data. */
25786 movq %rdx, %rcx
25787 rep movsb
25788+ pax_force_retaddr
25789 retq
25790 .Lmemmove_end_forward_efs:
25791 .previous
25792diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
25793index 2dcb380..963660a 100644
25794--- a/arch/x86/lib/memset_64.S
25795+++ b/arch/x86/lib/memset_64.S
25796@@ -30,6 +30,7 @@
25797 movl %edx,%ecx
25798 rep stosb
25799 movq %r9,%rax
25800+ pax_force_retaddr
25801 ret
25802 .Lmemset_e:
25803 .previous
25804@@ -52,6 +53,7 @@
25805 movq %rdx,%rcx
25806 rep stosb
25807 movq %r9,%rax
25808+ pax_force_retaddr
25809 ret
25810 .Lmemset_e_e:
25811 .previous
25812@@ -59,7 +61,7 @@
25813 ENTRY(memset)
25814 ENTRY(__memset)
25815 CFI_STARTPROC
25816- movq %rdi,%r10
25817+ movq %rdi,%r11
25818
25819 /* expand byte value */
25820 movzbl %sil,%ecx
25821@@ -117,7 +119,8 @@ ENTRY(__memset)
25822 jnz .Lloop_1
25823
25824 .Lende:
25825- movq %r10,%rax
25826+ movq %r11,%rax
25827+ pax_force_retaddr
25828 ret
25829
25830 CFI_RESTORE_STATE
25831diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
25832index c9f2d9b..e7fd2c0 100644
25833--- a/arch/x86/lib/mmx_32.c
25834+++ b/arch/x86/lib/mmx_32.c
25835@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25836 {
25837 void *p;
25838 int i;
25839+ unsigned long cr0;
25840
25841 if (unlikely(in_interrupt()))
25842 return __memcpy(to, from, len);
25843@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25844 kernel_fpu_begin();
25845
25846 __asm__ __volatile__ (
25847- "1: prefetch (%0)\n" /* This set is 28 bytes */
25848- " prefetch 64(%0)\n"
25849- " prefetch 128(%0)\n"
25850- " prefetch 192(%0)\n"
25851- " prefetch 256(%0)\n"
25852+ "1: prefetch (%1)\n" /* This set is 28 bytes */
25853+ " prefetch 64(%1)\n"
25854+ " prefetch 128(%1)\n"
25855+ " prefetch 192(%1)\n"
25856+ " prefetch 256(%1)\n"
25857 "2: \n"
25858 ".section .fixup, \"ax\"\n"
25859- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25860+ "3: \n"
25861+
25862+#ifdef CONFIG_PAX_KERNEXEC
25863+ " movl %%cr0, %0\n"
25864+ " movl %0, %%eax\n"
25865+ " andl $0xFFFEFFFF, %%eax\n"
25866+ " movl %%eax, %%cr0\n"
25867+#endif
25868+
25869+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25870+
25871+#ifdef CONFIG_PAX_KERNEXEC
25872+ " movl %0, %%cr0\n"
25873+#endif
25874+
25875 " jmp 2b\n"
25876 ".previous\n"
25877 _ASM_EXTABLE(1b, 3b)
25878- : : "r" (from));
25879+ : "=&r" (cr0) : "r" (from) : "ax");
25880
25881 for ( ; i > 5; i--) {
25882 __asm__ __volatile__ (
25883- "1: prefetch 320(%0)\n"
25884- "2: movq (%0), %%mm0\n"
25885- " movq 8(%0), %%mm1\n"
25886- " movq 16(%0), %%mm2\n"
25887- " movq 24(%0), %%mm3\n"
25888- " movq %%mm0, (%1)\n"
25889- " movq %%mm1, 8(%1)\n"
25890- " movq %%mm2, 16(%1)\n"
25891- " movq %%mm3, 24(%1)\n"
25892- " movq 32(%0), %%mm0\n"
25893- " movq 40(%0), %%mm1\n"
25894- " movq 48(%0), %%mm2\n"
25895- " movq 56(%0), %%mm3\n"
25896- " movq %%mm0, 32(%1)\n"
25897- " movq %%mm1, 40(%1)\n"
25898- " movq %%mm2, 48(%1)\n"
25899- " movq %%mm3, 56(%1)\n"
25900+ "1: prefetch 320(%1)\n"
25901+ "2: movq (%1), %%mm0\n"
25902+ " movq 8(%1), %%mm1\n"
25903+ " movq 16(%1), %%mm2\n"
25904+ " movq 24(%1), %%mm3\n"
25905+ " movq %%mm0, (%2)\n"
25906+ " movq %%mm1, 8(%2)\n"
25907+ " movq %%mm2, 16(%2)\n"
25908+ " movq %%mm3, 24(%2)\n"
25909+ " movq 32(%1), %%mm0\n"
25910+ " movq 40(%1), %%mm1\n"
25911+ " movq 48(%1), %%mm2\n"
25912+ " movq 56(%1), %%mm3\n"
25913+ " movq %%mm0, 32(%2)\n"
25914+ " movq %%mm1, 40(%2)\n"
25915+ " movq %%mm2, 48(%2)\n"
25916+ " movq %%mm3, 56(%2)\n"
25917 ".section .fixup, \"ax\"\n"
25918- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25919+ "3:\n"
25920+
25921+#ifdef CONFIG_PAX_KERNEXEC
25922+ " movl %%cr0, %0\n"
25923+ " movl %0, %%eax\n"
25924+ " andl $0xFFFEFFFF, %%eax\n"
25925+ " movl %%eax, %%cr0\n"
25926+#endif
25927+
25928+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25929+
25930+#ifdef CONFIG_PAX_KERNEXEC
25931+ " movl %0, %%cr0\n"
25932+#endif
25933+
25934 " jmp 2b\n"
25935 ".previous\n"
25936 _ASM_EXTABLE(1b, 3b)
25937- : : "r" (from), "r" (to) : "memory");
25938+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25939
25940 from += 64;
25941 to += 64;
25942@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
25943 static void fast_copy_page(void *to, void *from)
25944 {
25945 int i;
25946+ unsigned long cr0;
25947
25948 kernel_fpu_begin();
25949
25950@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
25951 * but that is for later. -AV
25952 */
25953 __asm__ __volatile__(
25954- "1: prefetch (%0)\n"
25955- " prefetch 64(%0)\n"
25956- " prefetch 128(%0)\n"
25957- " prefetch 192(%0)\n"
25958- " prefetch 256(%0)\n"
25959+ "1: prefetch (%1)\n"
25960+ " prefetch 64(%1)\n"
25961+ " prefetch 128(%1)\n"
25962+ " prefetch 192(%1)\n"
25963+ " prefetch 256(%1)\n"
25964 "2: \n"
25965 ".section .fixup, \"ax\"\n"
25966- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25967+ "3: \n"
25968+
25969+#ifdef CONFIG_PAX_KERNEXEC
25970+ " movl %%cr0, %0\n"
25971+ " movl %0, %%eax\n"
25972+ " andl $0xFFFEFFFF, %%eax\n"
25973+ " movl %%eax, %%cr0\n"
25974+#endif
25975+
25976+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25977+
25978+#ifdef CONFIG_PAX_KERNEXEC
25979+ " movl %0, %%cr0\n"
25980+#endif
25981+
25982 " jmp 2b\n"
25983 ".previous\n"
25984- _ASM_EXTABLE(1b, 3b) : : "r" (from));
25985+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25986
25987 for (i = 0; i < (4096-320)/64; i++) {
25988 __asm__ __volatile__ (
25989- "1: prefetch 320(%0)\n"
25990- "2: movq (%0), %%mm0\n"
25991- " movntq %%mm0, (%1)\n"
25992- " movq 8(%0), %%mm1\n"
25993- " movntq %%mm1, 8(%1)\n"
25994- " movq 16(%0), %%mm2\n"
25995- " movntq %%mm2, 16(%1)\n"
25996- " movq 24(%0), %%mm3\n"
25997- " movntq %%mm3, 24(%1)\n"
25998- " movq 32(%0), %%mm4\n"
25999- " movntq %%mm4, 32(%1)\n"
26000- " movq 40(%0), %%mm5\n"
26001- " movntq %%mm5, 40(%1)\n"
26002- " movq 48(%0), %%mm6\n"
26003- " movntq %%mm6, 48(%1)\n"
26004- " movq 56(%0), %%mm7\n"
26005- " movntq %%mm7, 56(%1)\n"
26006+ "1: prefetch 320(%1)\n"
26007+ "2: movq (%1), %%mm0\n"
26008+ " movntq %%mm0, (%2)\n"
26009+ " movq 8(%1), %%mm1\n"
26010+ " movntq %%mm1, 8(%2)\n"
26011+ " movq 16(%1), %%mm2\n"
26012+ " movntq %%mm2, 16(%2)\n"
26013+ " movq 24(%1), %%mm3\n"
26014+ " movntq %%mm3, 24(%2)\n"
26015+ " movq 32(%1), %%mm4\n"
26016+ " movntq %%mm4, 32(%2)\n"
26017+ " movq 40(%1), %%mm5\n"
26018+ " movntq %%mm5, 40(%2)\n"
26019+ " movq 48(%1), %%mm6\n"
26020+ " movntq %%mm6, 48(%2)\n"
26021+ " movq 56(%1), %%mm7\n"
26022+ " movntq %%mm7, 56(%2)\n"
26023 ".section .fixup, \"ax\"\n"
26024- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26025+ "3:\n"
26026+
26027+#ifdef CONFIG_PAX_KERNEXEC
26028+ " movl %%cr0, %0\n"
26029+ " movl %0, %%eax\n"
26030+ " andl $0xFFFEFFFF, %%eax\n"
26031+ " movl %%eax, %%cr0\n"
26032+#endif
26033+
26034+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26035+
26036+#ifdef CONFIG_PAX_KERNEXEC
26037+ " movl %0, %%cr0\n"
26038+#endif
26039+
26040 " jmp 2b\n"
26041 ".previous\n"
26042- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
26043+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26044
26045 from += 64;
26046 to += 64;
26047@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
26048 static void fast_copy_page(void *to, void *from)
26049 {
26050 int i;
26051+ unsigned long cr0;
26052
26053 kernel_fpu_begin();
26054
26055 __asm__ __volatile__ (
26056- "1: prefetch (%0)\n"
26057- " prefetch 64(%0)\n"
26058- " prefetch 128(%0)\n"
26059- " prefetch 192(%0)\n"
26060- " prefetch 256(%0)\n"
26061+ "1: prefetch (%1)\n"
26062+ " prefetch 64(%1)\n"
26063+ " prefetch 128(%1)\n"
26064+ " prefetch 192(%1)\n"
26065+ " prefetch 256(%1)\n"
26066 "2: \n"
26067 ".section .fixup, \"ax\"\n"
26068- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26069+ "3: \n"
26070+
26071+#ifdef CONFIG_PAX_KERNEXEC
26072+ " movl %%cr0, %0\n"
26073+ " movl %0, %%eax\n"
26074+ " andl $0xFFFEFFFF, %%eax\n"
26075+ " movl %%eax, %%cr0\n"
26076+#endif
26077+
26078+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26079+
26080+#ifdef CONFIG_PAX_KERNEXEC
26081+ " movl %0, %%cr0\n"
26082+#endif
26083+
26084 " jmp 2b\n"
26085 ".previous\n"
26086- _ASM_EXTABLE(1b, 3b) : : "r" (from));
26087+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
26088
26089 for (i = 0; i < 4096/64; i++) {
26090 __asm__ __volatile__ (
26091- "1: prefetch 320(%0)\n"
26092- "2: movq (%0), %%mm0\n"
26093- " movq 8(%0), %%mm1\n"
26094- " movq 16(%0), %%mm2\n"
26095- " movq 24(%0), %%mm3\n"
26096- " movq %%mm0, (%1)\n"
26097- " movq %%mm1, 8(%1)\n"
26098- " movq %%mm2, 16(%1)\n"
26099- " movq %%mm3, 24(%1)\n"
26100- " movq 32(%0), %%mm0\n"
26101- " movq 40(%0), %%mm1\n"
26102- " movq 48(%0), %%mm2\n"
26103- " movq 56(%0), %%mm3\n"
26104- " movq %%mm0, 32(%1)\n"
26105- " movq %%mm1, 40(%1)\n"
26106- " movq %%mm2, 48(%1)\n"
26107- " movq %%mm3, 56(%1)\n"
26108+ "1: prefetch 320(%1)\n"
26109+ "2: movq (%1), %%mm0\n"
26110+ " movq 8(%1), %%mm1\n"
26111+ " movq 16(%1), %%mm2\n"
26112+ " movq 24(%1), %%mm3\n"
26113+ " movq %%mm0, (%2)\n"
26114+ " movq %%mm1, 8(%2)\n"
26115+ " movq %%mm2, 16(%2)\n"
26116+ " movq %%mm3, 24(%2)\n"
26117+ " movq 32(%1), %%mm0\n"
26118+ " movq 40(%1), %%mm1\n"
26119+ " movq 48(%1), %%mm2\n"
26120+ " movq 56(%1), %%mm3\n"
26121+ " movq %%mm0, 32(%2)\n"
26122+ " movq %%mm1, 40(%2)\n"
26123+ " movq %%mm2, 48(%2)\n"
26124+ " movq %%mm3, 56(%2)\n"
26125 ".section .fixup, \"ax\"\n"
26126- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26127+ "3:\n"
26128+
26129+#ifdef CONFIG_PAX_KERNEXEC
26130+ " movl %%cr0, %0\n"
26131+ " movl %0, %%eax\n"
26132+ " andl $0xFFFEFFFF, %%eax\n"
26133+ " movl %%eax, %%cr0\n"
26134+#endif
26135+
26136+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26137+
26138+#ifdef CONFIG_PAX_KERNEXEC
26139+ " movl %0, %%cr0\n"
26140+#endif
26141+
26142 " jmp 2b\n"
26143 ".previous\n"
26144 _ASM_EXTABLE(1b, 3b)
26145- : : "r" (from), "r" (to) : "memory");
26146+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26147
26148 from += 64;
26149 to += 64;
26150diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
26151index f6d13ee..aca5f0b 100644
26152--- a/arch/x86/lib/msr-reg.S
26153+++ b/arch/x86/lib/msr-reg.S
26154@@ -3,6 +3,7 @@
26155 #include <asm/dwarf2.h>
26156 #include <asm/asm.h>
26157 #include <asm/msr.h>
26158+#include <asm/alternative-asm.h>
26159
26160 #ifdef CONFIG_X86_64
26161 /*
26162@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
26163 CFI_STARTPROC
26164 pushq_cfi %rbx
26165 pushq_cfi %rbp
26166- movq %rdi, %r10 /* Save pointer */
26167+ movq %rdi, %r9 /* Save pointer */
26168 xorl %r11d, %r11d /* Return value */
26169 movl (%rdi), %eax
26170 movl 4(%rdi), %ecx
26171@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
26172 movl 28(%rdi), %edi
26173 CFI_REMEMBER_STATE
26174 1: \op
26175-2: movl %eax, (%r10)
26176+2: movl %eax, (%r9)
26177 movl %r11d, %eax /* Return value */
26178- movl %ecx, 4(%r10)
26179- movl %edx, 8(%r10)
26180- movl %ebx, 12(%r10)
26181- movl %ebp, 20(%r10)
26182- movl %esi, 24(%r10)
26183- movl %edi, 28(%r10)
26184+ movl %ecx, 4(%r9)
26185+ movl %edx, 8(%r9)
26186+ movl %ebx, 12(%r9)
26187+ movl %ebp, 20(%r9)
26188+ movl %esi, 24(%r9)
26189+ movl %edi, 28(%r9)
26190 popq_cfi %rbp
26191 popq_cfi %rbx
26192+ pax_force_retaddr
26193 ret
26194 3:
26195 CFI_RESTORE_STATE
26196diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
26197index fc6ba17..d4d989d 100644
26198--- a/arch/x86/lib/putuser.S
26199+++ b/arch/x86/lib/putuser.S
26200@@ -16,7 +16,9 @@
26201 #include <asm/errno.h>
26202 #include <asm/asm.h>
26203 #include <asm/smap.h>
26204-
26205+#include <asm/segment.h>
26206+#include <asm/pgtable.h>
26207+#include <asm/alternative-asm.h>
26208
26209 /*
26210 * __put_user_X
26211@@ -30,57 +32,125 @@
26212 * as they get called from within inline assembly.
26213 */
26214
26215-#define ENTER CFI_STARTPROC ; \
26216- GET_THREAD_INFO(%_ASM_BX)
26217-#define EXIT ASM_CLAC ; \
26218- ret ; \
26219+#define ENTER CFI_STARTPROC
26220+#define EXIT ASM_CLAC ; \
26221+ pax_force_retaddr ; \
26222+ ret ; \
26223 CFI_ENDPROC
26224
26225+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26226+#define _DEST %_ASM_CX,%_ASM_BX
26227+#else
26228+#define _DEST %_ASM_CX
26229+#endif
26230+
26231+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26232+#define __copyuser_seg gs;
26233+#else
26234+#define __copyuser_seg
26235+#endif
26236+
26237 .text
26238 ENTRY(__put_user_1)
26239 ENTER
26240+
26241+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26242+ GET_THREAD_INFO(%_ASM_BX)
26243 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
26244 jae bad_put_user
26245 ASM_STAC
26246-1: movb %al,(%_ASM_CX)
26247+
26248+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26249+ mov pax_user_shadow_base,%_ASM_BX
26250+ cmp %_ASM_BX,%_ASM_CX
26251+ jb 1234f
26252+ xor %ebx,%ebx
26253+1234:
26254+#endif
26255+
26256+#endif
26257+
26258+1: __copyuser_seg movb %al,(_DEST)
26259 xor %eax,%eax
26260 EXIT
26261 ENDPROC(__put_user_1)
26262
26263 ENTRY(__put_user_2)
26264 ENTER
26265+
26266+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26267+ GET_THREAD_INFO(%_ASM_BX)
26268 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26269 sub $1,%_ASM_BX
26270 cmp %_ASM_BX,%_ASM_CX
26271 jae bad_put_user
26272 ASM_STAC
26273-2: movw %ax,(%_ASM_CX)
26274+
26275+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26276+ mov pax_user_shadow_base,%_ASM_BX
26277+ cmp %_ASM_BX,%_ASM_CX
26278+ jb 1234f
26279+ xor %ebx,%ebx
26280+1234:
26281+#endif
26282+
26283+#endif
26284+
26285+2: __copyuser_seg movw %ax,(_DEST)
26286 xor %eax,%eax
26287 EXIT
26288 ENDPROC(__put_user_2)
26289
26290 ENTRY(__put_user_4)
26291 ENTER
26292+
26293+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26294+ GET_THREAD_INFO(%_ASM_BX)
26295 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26296 sub $3,%_ASM_BX
26297 cmp %_ASM_BX,%_ASM_CX
26298 jae bad_put_user
26299 ASM_STAC
26300-3: movl %eax,(%_ASM_CX)
26301+
26302+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26303+ mov pax_user_shadow_base,%_ASM_BX
26304+ cmp %_ASM_BX,%_ASM_CX
26305+ jb 1234f
26306+ xor %ebx,%ebx
26307+1234:
26308+#endif
26309+
26310+#endif
26311+
26312+3: __copyuser_seg movl %eax,(_DEST)
26313 xor %eax,%eax
26314 EXIT
26315 ENDPROC(__put_user_4)
26316
26317 ENTRY(__put_user_8)
26318 ENTER
26319+
26320+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26321+ GET_THREAD_INFO(%_ASM_BX)
26322 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26323 sub $7,%_ASM_BX
26324 cmp %_ASM_BX,%_ASM_CX
26325 jae bad_put_user
26326 ASM_STAC
26327-4: mov %_ASM_AX,(%_ASM_CX)
26328+
26329+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26330+ mov pax_user_shadow_base,%_ASM_BX
26331+ cmp %_ASM_BX,%_ASM_CX
26332+ jb 1234f
26333+ xor %ebx,%ebx
26334+1234:
26335+#endif
26336+
26337+#endif
26338+
26339+4: __copyuser_seg mov %_ASM_AX,(_DEST)
26340 #ifdef CONFIG_X86_32
26341-5: movl %edx,4(%_ASM_CX)
26342+5: __copyuser_seg movl %edx,4(_DEST)
26343 #endif
26344 xor %eax,%eax
26345 EXIT
26346diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
26347index 1cad221..de671ee 100644
26348--- a/arch/x86/lib/rwlock.S
26349+++ b/arch/x86/lib/rwlock.S
26350@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
26351 FRAME
26352 0: LOCK_PREFIX
26353 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26354+
26355+#ifdef CONFIG_PAX_REFCOUNT
26356+ jno 1234f
26357+ LOCK_PREFIX
26358+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26359+ int $4
26360+1234:
26361+ _ASM_EXTABLE(1234b, 1234b)
26362+#endif
26363+
26364 1: rep; nop
26365 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
26366 jne 1b
26367 LOCK_PREFIX
26368 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26369+
26370+#ifdef CONFIG_PAX_REFCOUNT
26371+ jno 1234f
26372+ LOCK_PREFIX
26373+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26374+ int $4
26375+1234:
26376+ _ASM_EXTABLE(1234b, 1234b)
26377+#endif
26378+
26379 jnz 0b
26380 ENDFRAME
26381+ pax_force_retaddr
26382 ret
26383 CFI_ENDPROC
26384 END(__write_lock_failed)
26385@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
26386 FRAME
26387 0: LOCK_PREFIX
26388 READ_LOCK_SIZE(inc) (%__lock_ptr)
26389+
26390+#ifdef CONFIG_PAX_REFCOUNT
26391+ jno 1234f
26392+ LOCK_PREFIX
26393+ READ_LOCK_SIZE(dec) (%__lock_ptr)
26394+ int $4
26395+1234:
26396+ _ASM_EXTABLE(1234b, 1234b)
26397+#endif
26398+
26399 1: rep; nop
26400 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
26401 js 1b
26402 LOCK_PREFIX
26403 READ_LOCK_SIZE(dec) (%__lock_ptr)
26404+
26405+#ifdef CONFIG_PAX_REFCOUNT
26406+ jno 1234f
26407+ LOCK_PREFIX
26408+ READ_LOCK_SIZE(inc) (%__lock_ptr)
26409+ int $4
26410+1234:
26411+ _ASM_EXTABLE(1234b, 1234b)
26412+#endif
26413+
26414 js 0b
26415 ENDFRAME
26416+ pax_force_retaddr
26417 ret
26418 CFI_ENDPROC
26419 END(__read_lock_failed)
26420diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
26421index 5dff5f0..cadebf4 100644
26422--- a/arch/x86/lib/rwsem.S
26423+++ b/arch/x86/lib/rwsem.S
26424@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
26425 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26426 CFI_RESTORE __ASM_REG(dx)
26427 restore_common_regs
26428+ pax_force_retaddr
26429 ret
26430 CFI_ENDPROC
26431 ENDPROC(call_rwsem_down_read_failed)
26432@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
26433 movq %rax,%rdi
26434 call rwsem_down_write_failed
26435 restore_common_regs
26436+ pax_force_retaddr
26437 ret
26438 CFI_ENDPROC
26439 ENDPROC(call_rwsem_down_write_failed)
26440@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
26441 movq %rax,%rdi
26442 call rwsem_wake
26443 restore_common_regs
26444-1: ret
26445+1: pax_force_retaddr
26446+ ret
26447 CFI_ENDPROC
26448 ENDPROC(call_rwsem_wake)
26449
26450@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
26451 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26452 CFI_RESTORE __ASM_REG(dx)
26453 restore_common_regs
26454+ pax_force_retaddr
26455 ret
26456 CFI_ENDPROC
26457 ENDPROC(call_rwsem_downgrade_wake)
26458diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
26459index a63efd6..ccecad8 100644
26460--- a/arch/x86/lib/thunk_64.S
26461+++ b/arch/x86/lib/thunk_64.S
26462@@ -8,6 +8,7 @@
26463 #include <linux/linkage.h>
26464 #include <asm/dwarf2.h>
26465 #include <asm/calling.h>
26466+#include <asm/alternative-asm.h>
26467
26468 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
26469 .macro THUNK name, func, put_ret_addr_in_rdi=0
26470@@ -41,5 +42,6 @@
26471 SAVE_ARGS
26472 restore:
26473 RESTORE_ARGS
26474+ pax_force_retaddr
26475 ret
26476 CFI_ENDPROC
26477diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
26478index f0312d7..9c39d63 100644
26479--- a/arch/x86/lib/usercopy_32.c
26480+++ b/arch/x86/lib/usercopy_32.c
26481@@ -42,11 +42,13 @@ do { \
26482 int __d0; \
26483 might_fault(); \
26484 __asm__ __volatile__( \
26485+ __COPYUSER_SET_ES \
26486 ASM_STAC "\n" \
26487 "0: rep; stosl\n" \
26488 " movl %2,%0\n" \
26489 "1: rep; stosb\n" \
26490 "2: " ASM_CLAC "\n" \
26491+ __COPYUSER_RESTORE_ES \
26492 ".section .fixup,\"ax\"\n" \
26493 "3: lea 0(%2,%0,4),%0\n" \
26494 " jmp 2b\n" \
26495@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
26496
26497 #ifdef CONFIG_X86_INTEL_USERCOPY
26498 static unsigned long
26499-__copy_user_intel(void __user *to, const void *from, unsigned long size)
26500+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
26501 {
26502 int d0, d1;
26503 __asm__ __volatile__(
26504@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26505 " .align 2,0x90\n"
26506 "3: movl 0(%4), %%eax\n"
26507 "4: movl 4(%4), %%edx\n"
26508- "5: movl %%eax, 0(%3)\n"
26509- "6: movl %%edx, 4(%3)\n"
26510+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
26511+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
26512 "7: movl 8(%4), %%eax\n"
26513 "8: movl 12(%4),%%edx\n"
26514- "9: movl %%eax, 8(%3)\n"
26515- "10: movl %%edx, 12(%3)\n"
26516+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
26517+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
26518 "11: movl 16(%4), %%eax\n"
26519 "12: movl 20(%4), %%edx\n"
26520- "13: movl %%eax, 16(%3)\n"
26521- "14: movl %%edx, 20(%3)\n"
26522+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
26523+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
26524 "15: movl 24(%4), %%eax\n"
26525 "16: movl 28(%4), %%edx\n"
26526- "17: movl %%eax, 24(%3)\n"
26527- "18: movl %%edx, 28(%3)\n"
26528+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
26529+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
26530 "19: movl 32(%4), %%eax\n"
26531 "20: movl 36(%4), %%edx\n"
26532- "21: movl %%eax, 32(%3)\n"
26533- "22: movl %%edx, 36(%3)\n"
26534+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
26535+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
26536 "23: movl 40(%4), %%eax\n"
26537 "24: movl 44(%4), %%edx\n"
26538- "25: movl %%eax, 40(%3)\n"
26539- "26: movl %%edx, 44(%3)\n"
26540+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
26541+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
26542 "27: movl 48(%4), %%eax\n"
26543 "28: movl 52(%4), %%edx\n"
26544- "29: movl %%eax, 48(%3)\n"
26545- "30: movl %%edx, 52(%3)\n"
26546+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
26547+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
26548 "31: movl 56(%4), %%eax\n"
26549 "32: movl 60(%4), %%edx\n"
26550- "33: movl %%eax, 56(%3)\n"
26551- "34: movl %%edx, 60(%3)\n"
26552+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
26553+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
26554 " addl $-64, %0\n"
26555 " addl $64, %4\n"
26556 " addl $64, %3\n"
26557@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26558 " shrl $2, %0\n"
26559 " andl $3, %%eax\n"
26560 " cld\n"
26561+ __COPYUSER_SET_ES
26562 "99: rep; movsl\n"
26563 "36: movl %%eax, %0\n"
26564 "37: rep; movsb\n"
26565 "100:\n"
26566+ __COPYUSER_RESTORE_ES
26567 ".section .fixup,\"ax\"\n"
26568 "101: lea 0(%%eax,%0,4),%0\n"
26569 " jmp 100b\n"
26570@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26571 }
26572
26573 static unsigned long
26574+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
26575+{
26576+ int d0, d1;
26577+ __asm__ __volatile__(
26578+ " .align 2,0x90\n"
26579+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
26580+ " cmpl $67, %0\n"
26581+ " jbe 3f\n"
26582+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
26583+ " .align 2,0x90\n"
26584+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
26585+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
26586+ "5: movl %%eax, 0(%3)\n"
26587+ "6: movl %%edx, 4(%3)\n"
26588+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
26589+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
26590+ "9: movl %%eax, 8(%3)\n"
26591+ "10: movl %%edx, 12(%3)\n"
26592+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
26593+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
26594+ "13: movl %%eax, 16(%3)\n"
26595+ "14: movl %%edx, 20(%3)\n"
26596+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
26597+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
26598+ "17: movl %%eax, 24(%3)\n"
26599+ "18: movl %%edx, 28(%3)\n"
26600+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
26601+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
26602+ "21: movl %%eax, 32(%3)\n"
26603+ "22: movl %%edx, 36(%3)\n"
26604+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
26605+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
26606+ "25: movl %%eax, 40(%3)\n"
26607+ "26: movl %%edx, 44(%3)\n"
26608+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
26609+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
26610+ "29: movl %%eax, 48(%3)\n"
26611+ "30: movl %%edx, 52(%3)\n"
26612+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
26613+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
26614+ "33: movl %%eax, 56(%3)\n"
26615+ "34: movl %%edx, 60(%3)\n"
26616+ " addl $-64, %0\n"
26617+ " addl $64, %4\n"
26618+ " addl $64, %3\n"
26619+ " cmpl $63, %0\n"
26620+ " ja 1b\n"
26621+ "35: movl %0, %%eax\n"
26622+ " shrl $2, %0\n"
26623+ " andl $3, %%eax\n"
26624+ " cld\n"
26625+ "99: rep; "__copyuser_seg" movsl\n"
26626+ "36: movl %%eax, %0\n"
26627+ "37: rep; "__copyuser_seg" movsb\n"
26628+ "100:\n"
26629+ ".section .fixup,\"ax\"\n"
26630+ "101: lea 0(%%eax,%0,4),%0\n"
26631+ " jmp 100b\n"
26632+ ".previous\n"
26633+ _ASM_EXTABLE(1b,100b)
26634+ _ASM_EXTABLE(2b,100b)
26635+ _ASM_EXTABLE(3b,100b)
26636+ _ASM_EXTABLE(4b,100b)
26637+ _ASM_EXTABLE(5b,100b)
26638+ _ASM_EXTABLE(6b,100b)
26639+ _ASM_EXTABLE(7b,100b)
26640+ _ASM_EXTABLE(8b,100b)
26641+ _ASM_EXTABLE(9b,100b)
26642+ _ASM_EXTABLE(10b,100b)
26643+ _ASM_EXTABLE(11b,100b)
26644+ _ASM_EXTABLE(12b,100b)
26645+ _ASM_EXTABLE(13b,100b)
26646+ _ASM_EXTABLE(14b,100b)
26647+ _ASM_EXTABLE(15b,100b)
26648+ _ASM_EXTABLE(16b,100b)
26649+ _ASM_EXTABLE(17b,100b)
26650+ _ASM_EXTABLE(18b,100b)
26651+ _ASM_EXTABLE(19b,100b)
26652+ _ASM_EXTABLE(20b,100b)
26653+ _ASM_EXTABLE(21b,100b)
26654+ _ASM_EXTABLE(22b,100b)
26655+ _ASM_EXTABLE(23b,100b)
26656+ _ASM_EXTABLE(24b,100b)
26657+ _ASM_EXTABLE(25b,100b)
26658+ _ASM_EXTABLE(26b,100b)
26659+ _ASM_EXTABLE(27b,100b)
26660+ _ASM_EXTABLE(28b,100b)
26661+ _ASM_EXTABLE(29b,100b)
26662+ _ASM_EXTABLE(30b,100b)
26663+ _ASM_EXTABLE(31b,100b)
26664+ _ASM_EXTABLE(32b,100b)
26665+ _ASM_EXTABLE(33b,100b)
26666+ _ASM_EXTABLE(34b,100b)
26667+ _ASM_EXTABLE(35b,100b)
26668+ _ASM_EXTABLE(36b,100b)
26669+ _ASM_EXTABLE(37b,100b)
26670+ _ASM_EXTABLE(99b,101b)
26671+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
26672+ : "1"(to), "2"(from), "0"(size)
26673+ : "eax", "edx", "memory");
26674+ return size;
26675+}
26676+
26677+static unsigned long __size_overflow(3)
26678 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26679 {
26680 int d0, d1;
26681 __asm__ __volatile__(
26682 " .align 2,0x90\n"
26683- "0: movl 32(%4), %%eax\n"
26684+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26685 " cmpl $67, %0\n"
26686 " jbe 2f\n"
26687- "1: movl 64(%4), %%eax\n"
26688+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26689 " .align 2,0x90\n"
26690- "2: movl 0(%4), %%eax\n"
26691- "21: movl 4(%4), %%edx\n"
26692+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26693+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26694 " movl %%eax, 0(%3)\n"
26695 " movl %%edx, 4(%3)\n"
26696- "3: movl 8(%4), %%eax\n"
26697- "31: movl 12(%4),%%edx\n"
26698+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26699+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26700 " movl %%eax, 8(%3)\n"
26701 " movl %%edx, 12(%3)\n"
26702- "4: movl 16(%4), %%eax\n"
26703- "41: movl 20(%4), %%edx\n"
26704+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26705+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26706 " movl %%eax, 16(%3)\n"
26707 " movl %%edx, 20(%3)\n"
26708- "10: movl 24(%4), %%eax\n"
26709- "51: movl 28(%4), %%edx\n"
26710+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26711+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26712 " movl %%eax, 24(%3)\n"
26713 " movl %%edx, 28(%3)\n"
26714- "11: movl 32(%4), %%eax\n"
26715- "61: movl 36(%4), %%edx\n"
26716+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26717+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26718 " movl %%eax, 32(%3)\n"
26719 " movl %%edx, 36(%3)\n"
26720- "12: movl 40(%4), %%eax\n"
26721- "71: movl 44(%4), %%edx\n"
26722+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26723+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26724 " movl %%eax, 40(%3)\n"
26725 " movl %%edx, 44(%3)\n"
26726- "13: movl 48(%4), %%eax\n"
26727- "81: movl 52(%4), %%edx\n"
26728+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26729+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26730 " movl %%eax, 48(%3)\n"
26731 " movl %%edx, 52(%3)\n"
26732- "14: movl 56(%4), %%eax\n"
26733- "91: movl 60(%4), %%edx\n"
26734+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26735+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26736 " movl %%eax, 56(%3)\n"
26737 " movl %%edx, 60(%3)\n"
26738 " addl $-64, %0\n"
26739@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26740 " shrl $2, %0\n"
26741 " andl $3, %%eax\n"
26742 " cld\n"
26743- "6: rep; movsl\n"
26744+ "6: rep; "__copyuser_seg" movsl\n"
26745 " movl %%eax,%0\n"
26746- "7: rep; movsb\n"
26747+ "7: rep; "__copyuser_seg" movsb\n"
26748 "8:\n"
26749 ".section .fixup,\"ax\"\n"
26750 "9: lea 0(%%eax,%0,4),%0\n"
26751@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26752 * hyoshiok@miraclelinux.com
26753 */
26754
26755-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26756+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
26757 const void __user *from, unsigned long size)
26758 {
26759 int d0, d1;
26760
26761 __asm__ __volatile__(
26762 " .align 2,0x90\n"
26763- "0: movl 32(%4), %%eax\n"
26764+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26765 " cmpl $67, %0\n"
26766 " jbe 2f\n"
26767- "1: movl 64(%4), %%eax\n"
26768+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26769 " .align 2,0x90\n"
26770- "2: movl 0(%4), %%eax\n"
26771- "21: movl 4(%4), %%edx\n"
26772+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26773+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26774 " movnti %%eax, 0(%3)\n"
26775 " movnti %%edx, 4(%3)\n"
26776- "3: movl 8(%4), %%eax\n"
26777- "31: movl 12(%4),%%edx\n"
26778+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26779+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26780 " movnti %%eax, 8(%3)\n"
26781 " movnti %%edx, 12(%3)\n"
26782- "4: movl 16(%4), %%eax\n"
26783- "41: movl 20(%4), %%edx\n"
26784+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26785+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26786 " movnti %%eax, 16(%3)\n"
26787 " movnti %%edx, 20(%3)\n"
26788- "10: movl 24(%4), %%eax\n"
26789- "51: movl 28(%4), %%edx\n"
26790+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26791+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26792 " movnti %%eax, 24(%3)\n"
26793 " movnti %%edx, 28(%3)\n"
26794- "11: movl 32(%4), %%eax\n"
26795- "61: movl 36(%4), %%edx\n"
26796+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26797+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26798 " movnti %%eax, 32(%3)\n"
26799 " movnti %%edx, 36(%3)\n"
26800- "12: movl 40(%4), %%eax\n"
26801- "71: movl 44(%4), %%edx\n"
26802+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26803+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26804 " movnti %%eax, 40(%3)\n"
26805 " movnti %%edx, 44(%3)\n"
26806- "13: movl 48(%4), %%eax\n"
26807- "81: movl 52(%4), %%edx\n"
26808+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26809+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26810 " movnti %%eax, 48(%3)\n"
26811 " movnti %%edx, 52(%3)\n"
26812- "14: movl 56(%4), %%eax\n"
26813- "91: movl 60(%4), %%edx\n"
26814+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26815+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26816 " movnti %%eax, 56(%3)\n"
26817 " movnti %%edx, 60(%3)\n"
26818 " addl $-64, %0\n"
26819@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26820 " shrl $2, %0\n"
26821 " andl $3, %%eax\n"
26822 " cld\n"
26823- "6: rep; movsl\n"
26824+ "6: rep; "__copyuser_seg" movsl\n"
26825 " movl %%eax,%0\n"
26826- "7: rep; movsb\n"
26827+ "7: rep; "__copyuser_seg" movsb\n"
26828 "8:\n"
26829 ".section .fixup,\"ax\"\n"
26830 "9: lea 0(%%eax,%0,4),%0\n"
26831@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26832 return size;
26833 }
26834
26835-static unsigned long __copy_user_intel_nocache(void *to,
26836+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
26837 const void __user *from, unsigned long size)
26838 {
26839 int d0, d1;
26840
26841 __asm__ __volatile__(
26842 " .align 2,0x90\n"
26843- "0: movl 32(%4), %%eax\n"
26844+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26845 " cmpl $67, %0\n"
26846 " jbe 2f\n"
26847- "1: movl 64(%4), %%eax\n"
26848+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26849 " .align 2,0x90\n"
26850- "2: movl 0(%4), %%eax\n"
26851- "21: movl 4(%4), %%edx\n"
26852+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26853+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26854 " movnti %%eax, 0(%3)\n"
26855 " movnti %%edx, 4(%3)\n"
26856- "3: movl 8(%4), %%eax\n"
26857- "31: movl 12(%4),%%edx\n"
26858+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26859+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26860 " movnti %%eax, 8(%3)\n"
26861 " movnti %%edx, 12(%3)\n"
26862- "4: movl 16(%4), %%eax\n"
26863- "41: movl 20(%4), %%edx\n"
26864+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26865+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26866 " movnti %%eax, 16(%3)\n"
26867 " movnti %%edx, 20(%3)\n"
26868- "10: movl 24(%4), %%eax\n"
26869- "51: movl 28(%4), %%edx\n"
26870+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26871+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26872 " movnti %%eax, 24(%3)\n"
26873 " movnti %%edx, 28(%3)\n"
26874- "11: movl 32(%4), %%eax\n"
26875- "61: movl 36(%4), %%edx\n"
26876+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26877+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26878 " movnti %%eax, 32(%3)\n"
26879 " movnti %%edx, 36(%3)\n"
26880- "12: movl 40(%4), %%eax\n"
26881- "71: movl 44(%4), %%edx\n"
26882+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26883+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26884 " movnti %%eax, 40(%3)\n"
26885 " movnti %%edx, 44(%3)\n"
26886- "13: movl 48(%4), %%eax\n"
26887- "81: movl 52(%4), %%edx\n"
26888+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26889+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26890 " movnti %%eax, 48(%3)\n"
26891 " movnti %%edx, 52(%3)\n"
26892- "14: movl 56(%4), %%eax\n"
26893- "91: movl 60(%4), %%edx\n"
26894+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26895+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26896 " movnti %%eax, 56(%3)\n"
26897 " movnti %%edx, 60(%3)\n"
26898 " addl $-64, %0\n"
26899@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
26900 " shrl $2, %0\n"
26901 " andl $3, %%eax\n"
26902 " cld\n"
26903- "6: rep; movsl\n"
26904+ "6: rep; "__copyuser_seg" movsl\n"
26905 " movl %%eax,%0\n"
26906- "7: rep; movsb\n"
26907+ "7: rep; "__copyuser_seg" movsb\n"
26908 "8:\n"
26909 ".section .fixup,\"ax\"\n"
26910 "9: lea 0(%%eax,%0,4),%0\n"
26911@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
26912 */
26913 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
26914 unsigned long size);
26915-unsigned long __copy_user_intel(void __user *to, const void *from,
26916+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
26917+ unsigned long size);
26918+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
26919 unsigned long size);
26920 unsigned long __copy_user_zeroing_intel_nocache(void *to,
26921 const void __user *from, unsigned long size);
26922 #endif /* CONFIG_X86_INTEL_USERCOPY */
26923
26924 /* Generic arbitrary sized copy. */
26925-#define __copy_user(to, from, size) \
26926+#define __copy_user(to, from, size, prefix, set, restore) \
26927 do { \
26928 int __d0, __d1, __d2; \
26929 __asm__ __volatile__( \
26930+ set \
26931 " cmp $7,%0\n" \
26932 " jbe 1f\n" \
26933 " movl %1,%0\n" \
26934 " negl %0\n" \
26935 " andl $7,%0\n" \
26936 " subl %0,%3\n" \
26937- "4: rep; movsb\n" \
26938+ "4: rep; "prefix"movsb\n" \
26939 " movl %3,%0\n" \
26940 " shrl $2,%0\n" \
26941 " andl $3,%3\n" \
26942 " .align 2,0x90\n" \
26943- "0: rep; movsl\n" \
26944+ "0: rep; "prefix"movsl\n" \
26945 " movl %3,%0\n" \
26946- "1: rep; movsb\n" \
26947+ "1: rep; "prefix"movsb\n" \
26948 "2:\n" \
26949+ restore \
26950 ".section .fixup,\"ax\"\n" \
26951 "5: addl %3,%0\n" \
26952 " jmp 2b\n" \
26953@@ -538,14 +650,14 @@ do { \
26954 " negl %0\n" \
26955 " andl $7,%0\n" \
26956 " subl %0,%3\n" \
26957- "4: rep; movsb\n" \
26958+ "4: rep; "__copyuser_seg"movsb\n" \
26959 " movl %3,%0\n" \
26960 " shrl $2,%0\n" \
26961 " andl $3,%3\n" \
26962 " .align 2,0x90\n" \
26963- "0: rep; movsl\n" \
26964+ "0: rep; "__copyuser_seg"movsl\n" \
26965 " movl %3,%0\n" \
26966- "1: rep; movsb\n" \
26967+ "1: rep; "__copyuser_seg"movsb\n" \
26968 "2:\n" \
26969 ".section .fixup,\"ax\"\n" \
26970 "5: addl %3,%0\n" \
26971@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
26972 {
26973 stac();
26974 if (movsl_is_ok(to, from, n))
26975- __copy_user(to, from, n);
26976+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
26977 else
26978- n = __copy_user_intel(to, from, n);
26979+ n = __generic_copy_to_user_intel(to, from, n);
26980 clac();
26981 return n;
26982 }
26983@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
26984 {
26985 stac();
26986 if (movsl_is_ok(to, from, n))
26987- __copy_user(to, from, n);
26988+ __copy_user(to, from, n, __copyuser_seg, "", "");
26989 else
26990- n = __copy_user_intel((void __user *)to,
26991- (const void *)from, n);
26992+ n = __generic_copy_from_user_intel(to, from, n);
26993 clac();
26994 return n;
26995 }
26996@@ -632,66 +743,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
26997 if (n > 64 && cpu_has_xmm2)
26998 n = __copy_user_intel_nocache(to, from, n);
26999 else
27000- __copy_user(to, from, n);
27001+ __copy_user(to, from, n, __copyuser_seg, "", "");
27002 #else
27003- __copy_user(to, from, n);
27004+ __copy_user(to, from, n, __copyuser_seg, "", "");
27005 #endif
27006 clac();
27007 return n;
27008 }
27009 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
27010
27011-/**
27012- * copy_to_user: - Copy a block of data into user space.
27013- * @to: Destination address, in user space.
27014- * @from: Source address, in kernel space.
27015- * @n: Number of bytes to copy.
27016- *
27017- * Context: User context only. This function may sleep.
27018- *
27019- * Copy data from kernel space to user space.
27020- *
27021- * Returns number of bytes that could not be copied.
27022- * On success, this will be zero.
27023- */
27024-unsigned long
27025-copy_to_user(void __user *to, const void *from, unsigned long n)
27026-{
27027- if (access_ok(VERIFY_WRITE, to, n))
27028- n = __copy_to_user(to, from, n);
27029- return n;
27030-}
27031-EXPORT_SYMBOL(copy_to_user);
27032-
27033-/**
27034- * copy_from_user: - Copy a block of data from user space.
27035- * @to: Destination address, in kernel space.
27036- * @from: Source address, in user space.
27037- * @n: Number of bytes to copy.
27038- *
27039- * Context: User context only. This function may sleep.
27040- *
27041- * Copy data from user space to kernel space.
27042- *
27043- * Returns number of bytes that could not be copied.
27044- * On success, this will be zero.
27045- *
27046- * If some data could not be copied, this function will pad the copied
27047- * data to the requested size using zero bytes.
27048- */
27049-unsigned long
27050-_copy_from_user(void *to, const void __user *from, unsigned long n)
27051-{
27052- if (access_ok(VERIFY_READ, from, n))
27053- n = __copy_from_user(to, from, n);
27054- else
27055- memset(to, 0, n);
27056- return n;
27057-}
27058-EXPORT_SYMBOL(_copy_from_user);
27059-
27060 void copy_from_user_overflow(void)
27061 {
27062 WARN(1, "Buffer overflow detected!\n");
27063 }
27064 EXPORT_SYMBOL(copy_from_user_overflow);
27065+
27066+void copy_to_user_overflow(void)
27067+{
27068+ WARN(1, "Buffer overflow detected!\n");
27069+}
27070+EXPORT_SYMBOL(copy_to_user_overflow);
27071+
27072+#ifdef CONFIG_PAX_MEMORY_UDEREF
27073+void __set_fs(mm_segment_t x)
27074+{
27075+ switch (x.seg) {
27076+ case 0:
27077+ loadsegment(gs, 0);
27078+ break;
27079+ case TASK_SIZE_MAX:
27080+ loadsegment(gs, __USER_DS);
27081+ break;
27082+ case -1UL:
27083+ loadsegment(gs, __KERNEL_DS);
27084+ break;
27085+ default:
27086+ BUG();
27087+ }
27088+ return;
27089+}
27090+EXPORT_SYMBOL(__set_fs);
27091+
27092+void set_fs(mm_segment_t x)
27093+{
27094+ current_thread_info()->addr_limit = x;
27095+ __set_fs(x);
27096+}
27097+EXPORT_SYMBOL(set_fs);
27098+#endif
27099diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
27100index 906fea3..ee8a097 100644
27101--- a/arch/x86/lib/usercopy_64.c
27102+++ b/arch/x86/lib/usercopy_64.c
27103@@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
27104 _ASM_EXTABLE(0b,3b)
27105 _ASM_EXTABLE(1b,2b)
27106 : [size8] "=&c"(size), [dst] "=&D" (__d0)
27107- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
27108+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
27109 [zero] "r" (0UL), [eight] "r" (8UL));
27110 clac();
27111 return size;
27112@@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
27113 }
27114 EXPORT_SYMBOL(clear_user);
27115
27116-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
27117+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
27118 {
27119- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
27120- return copy_user_generic((__force void *)to, (__force void *)from, len);
27121- }
27122- return len;
27123+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
27124+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
27125+ return len;
27126 }
27127 EXPORT_SYMBOL(copy_in_user);
27128
27129@@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
27130 * it is not necessary to optimize tail handling.
27131 */
27132 unsigned long
27133-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27134+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
27135 {
27136 char c;
27137 unsigned zero_len;
27138@@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27139 clac();
27140 return len;
27141 }
27142+
27143+void copy_from_user_overflow(void)
27144+{
27145+ WARN(1, "Buffer overflow detected!\n");
27146+}
27147+EXPORT_SYMBOL(copy_from_user_overflow);
27148+
27149+void copy_to_user_overflow(void)
27150+{
27151+ WARN(1, "Buffer overflow detected!\n");
27152+}
27153+EXPORT_SYMBOL(copy_to_user_overflow);
27154diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
27155index 903ec1e..c4166b2 100644
27156--- a/arch/x86/mm/extable.c
27157+++ b/arch/x86/mm/extable.c
27158@@ -6,12 +6,24 @@
27159 static inline unsigned long
27160 ex_insn_addr(const struct exception_table_entry *x)
27161 {
27162- return (unsigned long)&x->insn + x->insn;
27163+ unsigned long reloc = 0;
27164+
27165+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27166+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27167+#endif
27168+
27169+ return (unsigned long)&x->insn + x->insn + reloc;
27170 }
27171 static inline unsigned long
27172 ex_fixup_addr(const struct exception_table_entry *x)
27173 {
27174- return (unsigned long)&x->fixup + x->fixup;
27175+ unsigned long reloc = 0;
27176+
27177+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27178+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27179+#endif
27180+
27181+ return (unsigned long)&x->fixup + x->fixup + reloc;
27182 }
27183
27184 int fixup_exception(struct pt_regs *regs)
27185@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
27186 unsigned long new_ip;
27187
27188 #ifdef CONFIG_PNPBIOS
27189- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
27190+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
27191 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
27192 extern u32 pnp_bios_is_utter_crap;
27193 pnp_bios_is_utter_crap = 1;
27194@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
27195 i += 4;
27196 p->fixup -= i;
27197 i += 4;
27198+
27199+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27200+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
27201+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27202+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27203+#endif
27204+
27205 }
27206 }
27207
27208diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
27209index 0e88336..2bb9777 100644
27210--- a/arch/x86/mm/fault.c
27211+++ b/arch/x86/mm/fault.c
27212@@ -13,12 +13,19 @@
27213 #include <linux/perf_event.h> /* perf_sw_event */
27214 #include <linux/hugetlb.h> /* hstate_index_to_shift */
27215 #include <linux/prefetch.h> /* prefetchw */
27216+#include <linux/unistd.h>
27217+#include <linux/compiler.h>
27218
27219 #include <asm/traps.h> /* dotraplinkage, ... */
27220 #include <asm/pgalloc.h> /* pgd_*(), ... */
27221 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
27222 #include <asm/fixmap.h> /* VSYSCALL_START */
27223 #include <asm/context_tracking.h> /* exception_enter(), ... */
27224+#include <asm/tlbflush.h>
27225+
27226+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27227+#include <asm/stacktrace.h>
27228+#endif
27229
27230 /*
27231 * Page fault error code bits:
27232@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
27233 int ret = 0;
27234
27235 /* kprobe_running() needs smp_processor_id() */
27236- if (kprobes_built_in() && !user_mode_vm(regs)) {
27237+ if (kprobes_built_in() && !user_mode(regs)) {
27238 preempt_disable();
27239 if (kprobe_running() && kprobe_fault_handler(regs, 14))
27240 ret = 1;
27241@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
27242 return !instr_lo || (instr_lo>>1) == 1;
27243 case 0x00:
27244 /* Prefetch instruction is 0x0F0D or 0x0F18 */
27245- if (probe_kernel_address(instr, opcode))
27246+ if (user_mode(regs)) {
27247+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27248+ return 0;
27249+ } else if (probe_kernel_address(instr, opcode))
27250 return 0;
27251
27252 *prefetch = (instr_lo == 0xF) &&
27253@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
27254 while (instr < max_instr) {
27255 unsigned char opcode;
27256
27257- if (probe_kernel_address(instr, opcode))
27258+ if (user_mode(regs)) {
27259+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27260+ break;
27261+ } else if (probe_kernel_address(instr, opcode))
27262 break;
27263
27264 instr++;
27265@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
27266 force_sig_info(si_signo, &info, tsk);
27267 }
27268
27269+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27270+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
27271+#endif
27272+
27273+#ifdef CONFIG_PAX_EMUTRAMP
27274+static int pax_handle_fetch_fault(struct pt_regs *regs);
27275+#endif
27276+
27277+#ifdef CONFIG_PAX_PAGEEXEC
27278+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
27279+{
27280+ pgd_t *pgd;
27281+ pud_t *pud;
27282+ pmd_t *pmd;
27283+
27284+ pgd = pgd_offset(mm, address);
27285+ if (!pgd_present(*pgd))
27286+ return NULL;
27287+ pud = pud_offset(pgd, address);
27288+ if (!pud_present(*pud))
27289+ return NULL;
27290+ pmd = pmd_offset(pud, address);
27291+ if (!pmd_present(*pmd))
27292+ return NULL;
27293+ return pmd;
27294+}
27295+#endif
27296+
27297 DEFINE_SPINLOCK(pgd_lock);
27298 LIST_HEAD(pgd_list);
27299
27300@@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
27301 for (address = VMALLOC_START & PMD_MASK;
27302 address >= TASK_SIZE && address < FIXADDR_TOP;
27303 address += PMD_SIZE) {
27304+
27305+#ifdef CONFIG_PAX_PER_CPU_PGD
27306+ unsigned long cpu;
27307+#else
27308 struct page *page;
27309+#endif
27310
27311 spin_lock(&pgd_lock);
27312+
27313+#ifdef CONFIG_PAX_PER_CPU_PGD
27314+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27315+ pgd_t *pgd = get_cpu_pgd(cpu);
27316+ pmd_t *ret;
27317+#else
27318 list_for_each_entry(page, &pgd_list, lru) {
27319+ pgd_t *pgd;
27320 spinlock_t *pgt_lock;
27321 pmd_t *ret;
27322
27323@@ -243,8 +296,14 @@ void vmalloc_sync_all(void)
27324 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
27325
27326 spin_lock(pgt_lock);
27327- ret = vmalloc_sync_one(page_address(page), address);
27328+ pgd = page_address(page);
27329+#endif
27330+
27331+ ret = vmalloc_sync_one(pgd, address);
27332+
27333+#ifndef CONFIG_PAX_PER_CPU_PGD
27334 spin_unlock(pgt_lock);
27335+#endif
27336
27337 if (!ret)
27338 break;
27339@@ -278,6 +337,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27340 * an interrupt in the middle of a task switch..
27341 */
27342 pgd_paddr = read_cr3();
27343+
27344+#ifdef CONFIG_PAX_PER_CPU_PGD
27345+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
27346+#endif
27347+
27348 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
27349 if (!pmd_k)
27350 return -1;
27351@@ -373,7 +437,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27352 * happen within a race in page table update. In the later
27353 * case just flush:
27354 */
27355+
27356+#ifdef CONFIG_PAX_PER_CPU_PGD
27357+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
27358+ pgd = pgd_offset_cpu(smp_processor_id(), address);
27359+#else
27360 pgd = pgd_offset(current->active_mm, address);
27361+#endif
27362+
27363 pgd_ref = pgd_offset_k(address);
27364 if (pgd_none(*pgd_ref))
27365 return -1;
27366@@ -543,7 +614,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
27367 static int is_errata100(struct pt_regs *regs, unsigned long address)
27368 {
27369 #ifdef CONFIG_X86_64
27370- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
27371+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
27372 return 1;
27373 #endif
27374 return 0;
27375@@ -570,7 +641,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
27376 }
27377
27378 static const char nx_warning[] = KERN_CRIT
27379-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
27380+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
27381
27382 static void
27383 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27384@@ -579,15 +650,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27385 if (!oops_may_print())
27386 return;
27387
27388- if (error_code & PF_INSTR) {
27389+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
27390 unsigned int level;
27391
27392 pte_t *pte = lookup_address(address, &level);
27393
27394 if (pte && pte_present(*pte) && !pte_exec(*pte))
27395- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
27396+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
27397 }
27398
27399+#ifdef CONFIG_PAX_KERNEXEC
27400+ if (init_mm.start_code <= address && address < init_mm.end_code) {
27401+ if (current->signal->curr_ip)
27402+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
27403+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
27404+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27405+ else
27406+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
27407+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27408+ }
27409+#endif
27410+
27411 printk(KERN_ALERT "BUG: unable to handle kernel ");
27412 if (address < PAGE_SIZE)
27413 printk(KERN_CONT "NULL pointer dereference");
27414@@ -750,6 +833,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
27415 return;
27416 }
27417 #endif
27418+
27419+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27420+ if (pax_is_fetch_fault(regs, error_code, address)) {
27421+
27422+#ifdef CONFIG_PAX_EMUTRAMP
27423+ switch (pax_handle_fetch_fault(regs)) {
27424+ case 2:
27425+ return;
27426+ }
27427+#endif
27428+
27429+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27430+ do_group_exit(SIGKILL);
27431+ }
27432+#endif
27433+
27434 /* Kernel addresses are always protection faults: */
27435 if (address >= TASK_SIZE)
27436 error_code |= PF_PROT;
27437@@ -835,7 +934,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
27438 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
27439 printk(KERN_ERR
27440 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
27441- tsk->comm, tsk->pid, address);
27442+ tsk->comm, task_pid_nr(tsk), address);
27443 code = BUS_MCEERR_AR;
27444 }
27445 #endif
27446@@ -898,6 +997,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
27447 return 1;
27448 }
27449
27450+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27451+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
27452+{
27453+ pte_t *pte;
27454+ pmd_t *pmd;
27455+ spinlock_t *ptl;
27456+ unsigned char pte_mask;
27457+
27458+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
27459+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
27460+ return 0;
27461+
27462+ /* PaX: it's our fault, let's handle it if we can */
27463+
27464+ /* PaX: take a look at read faults before acquiring any locks */
27465+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
27466+ /* instruction fetch attempt from a protected page in user mode */
27467+ up_read(&mm->mmap_sem);
27468+
27469+#ifdef CONFIG_PAX_EMUTRAMP
27470+ switch (pax_handle_fetch_fault(regs)) {
27471+ case 2:
27472+ return 1;
27473+ }
27474+#endif
27475+
27476+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27477+ do_group_exit(SIGKILL);
27478+ }
27479+
27480+ pmd = pax_get_pmd(mm, address);
27481+ if (unlikely(!pmd))
27482+ return 0;
27483+
27484+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
27485+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
27486+ pte_unmap_unlock(pte, ptl);
27487+ return 0;
27488+ }
27489+
27490+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
27491+ /* write attempt to a protected page in user mode */
27492+ pte_unmap_unlock(pte, ptl);
27493+ return 0;
27494+ }
27495+
27496+#ifdef CONFIG_SMP
27497+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
27498+#else
27499+ if (likely(address > get_limit(regs->cs)))
27500+#endif
27501+ {
27502+ set_pte(pte, pte_mkread(*pte));
27503+ __flush_tlb_one(address);
27504+ pte_unmap_unlock(pte, ptl);
27505+ up_read(&mm->mmap_sem);
27506+ return 1;
27507+ }
27508+
27509+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
27510+
27511+ /*
27512+ * PaX: fill DTLB with user rights and retry
27513+ */
27514+ __asm__ __volatile__ (
27515+ "orb %2,(%1)\n"
27516+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
27517+/*
27518+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
27519+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
27520+ * page fault when examined during a TLB load attempt. this is true not only
27521+ * for PTEs holding a non-present entry but also present entries that will
27522+ * raise a page fault (such as those set up by PaX, or the copy-on-write
27523+ * mechanism). in effect it means that we do *not* need to flush the TLBs
27524+ * for our target pages since their PTEs are simply not in the TLBs at all.
27525+
27526+ * the best thing in omitting it is that we gain around 15-20% speed in the
27527+ * fast path of the page fault handler and can get rid of tracing since we
27528+ * can no longer flush unintended entries.
27529+ */
27530+ "invlpg (%0)\n"
27531+#endif
27532+ __copyuser_seg"testb $0,(%0)\n"
27533+ "xorb %3,(%1)\n"
27534+ :
27535+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
27536+ : "memory", "cc");
27537+ pte_unmap_unlock(pte, ptl);
27538+ up_read(&mm->mmap_sem);
27539+ return 1;
27540+}
27541+#endif
27542+
27543 /*
27544 * Handle a spurious fault caused by a stale TLB entry.
27545 *
27546@@ -964,6 +1156,9 @@ int show_unhandled_signals = 1;
27547 static inline int
27548 access_error(unsigned long error_code, struct vm_area_struct *vma)
27549 {
27550+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
27551+ return 1;
27552+
27553 if (error_code & PF_WRITE) {
27554 /* write, present and write, not present: */
27555 if (unlikely(!(vma->vm_flags & VM_WRITE)))
27556@@ -992,7 +1187,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
27557 if (error_code & PF_USER)
27558 return false;
27559
27560- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
27561+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
27562 return false;
27563
27564 return true;
27565@@ -1008,18 +1203,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27566 {
27567 struct vm_area_struct *vma;
27568 struct task_struct *tsk;
27569- unsigned long address;
27570 struct mm_struct *mm;
27571 int fault;
27572 int write = error_code & PF_WRITE;
27573 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
27574 (write ? FAULT_FLAG_WRITE : 0);
27575
27576- tsk = current;
27577- mm = tsk->mm;
27578-
27579 /* Get the faulting address: */
27580- address = read_cr2();
27581+ unsigned long address = read_cr2();
27582+
27583+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27584+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
27585+ if (!search_exception_tables(regs->ip)) {
27586+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27587+ bad_area_nosemaphore(regs, error_code, address);
27588+ return;
27589+ }
27590+ if (address < pax_user_shadow_base) {
27591+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27592+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
27593+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
27594+ } else
27595+ address -= pax_user_shadow_base;
27596+ }
27597+#endif
27598+
27599+ tsk = current;
27600+ mm = tsk->mm;
27601
27602 /*
27603 * Detect and handle instructions that would cause a page fault for
27604@@ -1080,7 +1290,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27605 * User-mode registers count as a user access even for any
27606 * potential system fault or CPU buglet:
27607 */
27608- if (user_mode_vm(regs)) {
27609+ if (user_mode(regs)) {
27610 local_irq_enable();
27611 error_code |= PF_USER;
27612 } else {
27613@@ -1142,6 +1352,11 @@ retry:
27614 might_sleep();
27615 }
27616
27617+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27618+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
27619+ return;
27620+#endif
27621+
27622 vma = find_vma(mm, address);
27623 if (unlikely(!vma)) {
27624 bad_area(regs, error_code, address);
27625@@ -1153,18 +1368,24 @@ retry:
27626 bad_area(regs, error_code, address);
27627 return;
27628 }
27629- if (error_code & PF_USER) {
27630- /*
27631- * Accessing the stack below %sp is always a bug.
27632- * The large cushion allows instructions like enter
27633- * and pusha to work. ("enter $65535, $31" pushes
27634- * 32 pointers and then decrements %sp by 65535.)
27635- */
27636- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
27637- bad_area(regs, error_code, address);
27638- return;
27639- }
27640+ /*
27641+ * Accessing the stack below %sp is always a bug.
27642+ * The large cushion allows instructions like enter
27643+ * and pusha to work. ("enter $65535, $31" pushes
27644+ * 32 pointers and then decrements %sp by 65535.)
27645+ */
27646+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
27647+ bad_area(regs, error_code, address);
27648+ return;
27649 }
27650+
27651+#ifdef CONFIG_PAX_SEGMEXEC
27652+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
27653+ bad_area(regs, error_code, address);
27654+ return;
27655+ }
27656+#endif
27657+
27658 if (unlikely(expand_stack(vma, address))) {
27659 bad_area(regs, error_code, address);
27660 return;
27661@@ -1228,3 +1449,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
27662 __do_page_fault(regs, error_code);
27663 exception_exit(regs);
27664 }
27665+
27666+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27667+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
27668+{
27669+ struct mm_struct *mm = current->mm;
27670+ unsigned long ip = regs->ip;
27671+
27672+ if (v8086_mode(regs))
27673+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
27674+
27675+#ifdef CONFIG_PAX_PAGEEXEC
27676+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
27677+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
27678+ return true;
27679+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
27680+ return true;
27681+ return false;
27682+ }
27683+#endif
27684+
27685+#ifdef CONFIG_PAX_SEGMEXEC
27686+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
27687+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
27688+ return true;
27689+ return false;
27690+ }
27691+#endif
27692+
27693+ return false;
27694+}
27695+#endif
27696+
27697+#ifdef CONFIG_PAX_EMUTRAMP
27698+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
27699+{
27700+ int err;
27701+
27702+ do { /* PaX: libffi trampoline emulation */
27703+ unsigned char mov, jmp;
27704+ unsigned int addr1, addr2;
27705+
27706+#ifdef CONFIG_X86_64
27707+ if ((regs->ip + 9) >> 32)
27708+ break;
27709+#endif
27710+
27711+ err = get_user(mov, (unsigned char __user *)regs->ip);
27712+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27713+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27714+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27715+
27716+ if (err)
27717+ break;
27718+
27719+ if (mov == 0xB8 && jmp == 0xE9) {
27720+ regs->ax = addr1;
27721+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27722+ return 2;
27723+ }
27724+ } while (0);
27725+
27726+ do { /* PaX: gcc trampoline emulation #1 */
27727+ unsigned char mov1, mov2;
27728+ unsigned short jmp;
27729+ unsigned int addr1, addr2;
27730+
27731+#ifdef CONFIG_X86_64
27732+ if ((regs->ip + 11) >> 32)
27733+ break;
27734+#endif
27735+
27736+ err = get_user(mov1, (unsigned char __user *)regs->ip);
27737+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27738+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
27739+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27740+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
27741+
27742+ if (err)
27743+ break;
27744+
27745+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
27746+ regs->cx = addr1;
27747+ regs->ax = addr2;
27748+ regs->ip = addr2;
27749+ return 2;
27750+ }
27751+ } while (0);
27752+
27753+ do { /* PaX: gcc trampoline emulation #2 */
27754+ unsigned char mov, jmp;
27755+ unsigned int addr1, addr2;
27756+
27757+#ifdef CONFIG_X86_64
27758+ if ((regs->ip + 9) >> 32)
27759+ break;
27760+#endif
27761+
27762+ err = get_user(mov, (unsigned char __user *)regs->ip);
27763+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27764+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27765+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27766+
27767+ if (err)
27768+ break;
27769+
27770+ if (mov == 0xB9 && jmp == 0xE9) {
27771+ regs->cx = addr1;
27772+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27773+ return 2;
27774+ }
27775+ } while (0);
27776+
27777+ return 1; /* PaX in action */
27778+}
27779+
27780+#ifdef CONFIG_X86_64
27781+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
27782+{
27783+ int err;
27784+
27785+ do { /* PaX: libffi trampoline emulation */
27786+ unsigned short mov1, mov2, jmp1;
27787+ unsigned char stcclc, jmp2;
27788+ unsigned long addr1, addr2;
27789+
27790+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27791+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27792+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27793+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27794+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
27795+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
27796+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
27797+
27798+ if (err)
27799+ break;
27800+
27801+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27802+ regs->r11 = addr1;
27803+ regs->r10 = addr2;
27804+ if (stcclc == 0xF8)
27805+ regs->flags &= ~X86_EFLAGS_CF;
27806+ else
27807+ regs->flags |= X86_EFLAGS_CF;
27808+ regs->ip = addr1;
27809+ return 2;
27810+ }
27811+ } while (0);
27812+
27813+ do { /* PaX: gcc trampoline emulation #1 */
27814+ unsigned short mov1, mov2, jmp1;
27815+ unsigned char jmp2;
27816+ unsigned int addr1;
27817+ unsigned long addr2;
27818+
27819+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27820+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
27821+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
27822+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
27823+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
27824+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
27825+
27826+ if (err)
27827+ break;
27828+
27829+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27830+ regs->r11 = addr1;
27831+ regs->r10 = addr2;
27832+ regs->ip = addr1;
27833+ return 2;
27834+ }
27835+ } while (0);
27836+
27837+ do { /* PaX: gcc trampoline emulation #2 */
27838+ unsigned short mov1, mov2, jmp1;
27839+ unsigned char jmp2;
27840+ unsigned long addr1, addr2;
27841+
27842+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27843+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27844+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27845+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27846+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
27847+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
27848+
27849+ if (err)
27850+ break;
27851+
27852+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27853+ regs->r11 = addr1;
27854+ regs->r10 = addr2;
27855+ regs->ip = addr1;
27856+ return 2;
27857+ }
27858+ } while (0);
27859+
27860+ return 1; /* PaX in action */
27861+}
27862+#endif
27863+
27864+/*
27865+ * PaX: decide what to do with offenders (regs->ip = fault address)
27866+ *
27867+ * returns 1 when task should be killed
27868+ * 2 when gcc trampoline was detected
27869+ */
27870+static int pax_handle_fetch_fault(struct pt_regs *regs)
27871+{
27872+ if (v8086_mode(regs))
27873+ return 1;
27874+
27875+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
27876+ return 1;
27877+
27878+#ifdef CONFIG_X86_32
27879+ return pax_handle_fetch_fault_32(regs);
27880+#else
27881+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
27882+ return pax_handle_fetch_fault_32(regs);
27883+ else
27884+ return pax_handle_fetch_fault_64(regs);
27885+#endif
27886+}
27887+#endif
27888+
27889+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27890+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
27891+{
27892+ long i;
27893+
27894+ printk(KERN_ERR "PAX: bytes at PC: ");
27895+ for (i = 0; i < 20; i++) {
27896+ unsigned char c;
27897+ if (get_user(c, (unsigned char __force_user *)pc+i))
27898+ printk(KERN_CONT "?? ");
27899+ else
27900+ printk(KERN_CONT "%02x ", c);
27901+ }
27902+ printk("\n");
27903+
27904+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
27905+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
27906+ unsigned long c;
27907+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
27908+#ifdef CONFIG_X86_32
27909+ printk(KERN_CONT "???????? ");
27910+#else
27911+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
27912+ printk(KERN_CONT "???????? ???????? ");
27913+ else
27914+ printk(KERN_CONT "???????????????? ");
27915+#endif
27916+ } else {
27917+#ifdef CONFIG_X86_64
27918+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
27919+ printk(KERN_CONT "%08x ", (unsigned int)c);
27920+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
27921+ } else
27922+#endif
27923+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
27924+ }
27925+ }
27926+ printk("\n");
27927+}
27928+#endif
27929+
27930+/**
27931+ * probe_kernel_write(): safely attempt to write to a location
27932+ * @dst: address to write to
27933+ * @src: pointer to the data that shall be written
27934+ * @size: size of the data chunk
27935+ *
27936+ * Safely write to address @dst from the buffer at @src. If a kernel fault
27937+ * happens, handle that and return -EFAULT.
27938+ */
27939+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
27940+{
27941+ long ret;
27942+ mm_segment_t old_fs = get_fs();
27943+
27944+ set_fs(KERNEL_DS);
27945+ pagefault_disable();
27946+ pax_open_kernel();
27947+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
27948+ pax_close_kernel();
27949+ pagefault_enable();
27950+ set_fs(old_fs);
27951+
27952+ return ret ? -EFAULT : 0;
27953+}
27954diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
27955index dd74e46..7d26398 100644
27956--- a/arch/x86/mm/gup.c
27957+++ b/arch/x86/mm/gup.c
27958@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
27959 addr = start;
27960 len = (unsigned long) nr_pages << PAGE_SHIFT;
27961 end = start + len;
27962- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27963+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27964 (void __user *)start, len)))
27965 return 0;
27966
27967diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
27968index 6f31ee5..8ee4164 100644
27969--- a/arch/x86/mm/highmem_32.c
27970+++ b/arch/x86/mm/highmem_32.c
27971@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
27972 idx = type + KM_TYPE_NR*smp_processor_id();
27973 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
27974 BUG_ON(!pte_none(*(kmap_pte-idx)));
27975+
27976+ pax_open_kernel();
27977 set_pte(kmap_pte-idx, mk_pte(page, prot));
27978+ pax_close_kernel();
27979+
27980 arch_flush_lazy_mmu_mode();
27981
27982 return (void *)vaddr;
27983diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
27984index ae1aa71..d9bea75 100644
27985--- a/arch/x86/mm/hugetlbpage.c
27986+++ b/arch/x86/mm/hugetlbpage.c
27987@@ -271,23 +271,30 @@ follow_huge_pud(struct mm_struct *mm, unsigned long address,
27988 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
27989 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
27990 unsigned long addr, unsigned long len,
27991- unsigned long pgoff, unsigned long flags)
27992+ unsigned long pgoff, unsigned long flags, unsigned long offset)
27993 {
27994 struct hstate *h = hstate_file(file);
27995 struct vm_unmapped_area_info info;
27996-
27997+
27998 info.flags = 0;
27999 info.length = len;
28000 info.low_limit = TASK_UNMAPPED_BASE;
28001+
28002+#ifdef CONFIG_PAX_RANDMMAP
28003+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
28004+ info.low_limit += current->mm->delta_mmap;
28005+#endif
28006+
28007 info.high_limit = TASK_SIZE;
28008 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
28009 info.align_offset = 0;
28010+ info.threadstack_offset = offset;
28011 return vm_unmapped_area(&info);
28012 }
28013
28014 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28015 unsigned long addr0, unsigned long len,
28016- unsigned long pgoff, unsigned long flags)
28017+ unsigned long pgoff, unsigned long flags, unsigned long offset)
28018 {
28019 struct hstate *h = hstate_file(file);
28020 struct vm_unmapped_area_info info;
28021@@ -299,6 +306,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28022 info.high_limit = current->mm->mmap_base;
28023 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
28024 info.align_offset = 0;
28025+ info.threadstack_offset = offset;
28026 addr = vm_unmapped_area(&info);
28027
28028 /*
28029@@ -311,6 +319,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28030 VM_BUG_ON(addr != -ENOMEM);
28031 info.flags = 0;
28032 info.low_limit = TASK_UNMAPPED_BASE;
28033+
28034+#ifdef CONFIG_PAX_RANDMMAP
28035+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
28036+ info.low_limit += current->mm->delta_mmap;
28037+#endif
28038+
28039 info.high_limit = TASK_SIZE;
28040 addr = vm_unmapped_area(&info);
28041 }
28042@@ -325,10 +339,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
28043 struct hstate *h = hstate_file(file);
28044 struct mm_struct *mm = current->mm;
28045 struct vm_area_struct *vma;
28046+ unsigned long pax_task_size = TASK_SIZE;
28047+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
28048
28049 if (len & ~huge_page_mask(h))
28050 return -EINVAL;
28051- if (len > TASK_SIZE)
28052+
28053+#ifdef CONFIG_PAX_SEGMEXEC
28054+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28055+ pax_task_size = SEGMEXEC_TASK_SIZE;
28056+#endif
28057+
28058+ pax_task_size -= PAGE_SIZE;
28059+
28060+ if (len > pax_task_size)
28061 return -ENOMEM;
28062
28063 if (flags & MAP_FIXED) {
28064@@ -337,19 +361,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
28065 return addr;
28066 }
28067
28068+#ifdef CONFIG_PAX_RANDMMAP
28069+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28070+#endif
28071+
28072 if (addr) {
28073 addr = ALIGN(addr, huge_page_size(h));
28074 vma = find_vma(mm, addr);
28075- if (TASK_SIZE - len >= addr &&
28076- (!vma || addr + len <= vma->vm_start))
28077+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
28078 return addr;
28079 }
28080 if (mm->get_unmapped_area == arch_get_unmapped_area)
28081 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
28082- pgoff, flags);
28083+ pgoff, flags, offset);
28084 else
28085 return hugetlb_get_unmapped_area_topdown(file, addr, len,
28086- pgoff, flags);
28087+ pgoff, flags, offset);
28088 }
28089
28090 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
28091diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
28092index 59b7fc4..b1dd75f 100644
28093--- a/arch/x86/mm/init.c
28094+++ b/arch/x86/mm/init.c
28095@@ -4,6 +4,7 @@
28096 #include <linux/swap.h>
28097 #include <linux/memblock.h>
28098 #include <linux/bootmem.h> /* for max_low_pfn */
28099+#include <linux/tboot.h>
28100
28101 #include <asm/cacheflush.h>
28102 #include <asm/e820.h>
28103@@ -17,6 +18,8 @@
28104 #include <asm/proto.h>
28105 #include <asm/dma.h> /* for MAX_DMA_PFN */
28106 #include <asm/microcode.h>
28107+#include <asm/desc.h>
28108+#include <asm/bios_ebda.h>
28109
28110 #include "mm_internal.h"
28111
28112@@ -464,10 +467,40 @@ void __init init_mem_mapping(void)
28113 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
28114 * mmio resources as well as potential bios/acpi data regions.
28115 */
28116+
28117+#ifdef CONFIG_GRKERNSEC_KMEM
28118+static unsigned int ebda_start __read_only;
28119+static unsigned int ebda_end __read_only;
28120+#endif
28121+
28122 int devmem_is_allowed(unsigned long pagenr)
28123 {
28124- if (pagenr < 256)
28125+#ifdef CONFIG_GRKERNSEC_KMEM
28126+ /* allow BDA */
28127+ if (!pagenr)
28128 return 1;
28129+ /* allow EBDA */
28130+ if (pagenr >= ebda_start && pagenr < ebda_end)
28131+ return 1;
28132+ /* if tboot is in use, allow access to its hardcoded serial log range */
28133+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
28134+ return 1;
28135+#else
28136+ if (!pagenr)
28137+ return 1;
28138+#ifdef CONFIG_VM86
28139+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
28140+ return 1;
28141+#endif
28142+#endif
28143+
28144+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
28145+ return 1;
28146+#ifdef CONFIG_GRKERNSEC_KMEM
28147+ /* throw out everything else below 1MB */
28148+ if (pagenr <= 256)
28149+ return 0;
28150+#endif
28151 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
28152 return 0;
28153 if (!page_is_ram(pagenr))
28154@@ -524,8 +557,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
28155 #endif
28156 }
28157
28158+#ifdef CONFIG_GRKERNSEC_KMEM
28159+static inline void gr_init_ebda(void)
28160+{
28161+ unsigned int ebda_addr;
28162+ unsigned int ebda_size = 0;
28163+
28164+ ebda_addr = get_bios_ebda();
28165+ if (ebda_addr) {
28166+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
28167+ ebda_size <<= 10;
28168+ }
28169+ if (ebda_addr && ebda_size) {
28170+ ebda_start = ebda_addr >> PAGE_SHIFT;
28171+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
28172+ } else {
28173+ ebda_start = 0x9f000 >> PAGE_SHIFT;
28174+ ebda_end = 0xa0000 >> PAGE_SHIFT;
28175+ }
28176+}
28177+#else
28178+static inline void gr_init_ebda(void) { }
28179+#endif
28180+
28181 void free_initmem(void)
28182 {
28183+#ifdef CONFIG_PAX_KERNEXEC
28184+#ifdef CONFIG_X86_32
28185+ /* PaX: limit KERNEL_CS to actual size */
28186+ unsigned long addr, limit;
28187+ struct desc_struct d;
28188+ int cpu;
28189+#else
28190+ pgd_t *pgd;
28191+ pud_t *pud;
28192+ pmd_t *pmd;
28193+ unsigned long addr, end;
28194+#endif
28195+#endif
28196+
28197+ gr_init_ebda();
28198+
28199+#ifdef CONFIG_PAX_KERNEXEC
28200+#ifdef CONFIG_X86_32
28201+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
28202+ limit = (limit - 1UL) >> PAGE_SHIFT;
28203+
28204+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
28205+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
28206+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
28207+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
28208+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
28209+ }
28210+
28211+ /* PaX: make KERNEL_CS read-only */
28212+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
28213+ if (!paravirt_enabled())
28214+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
28215+/*
28216+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
28217+ pgd = pgd_offset_k(addr);
28218+ pud = pud_offset(pgd, addr);
28219+ pmd = pmd_offset(pud, addr);
28220+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28221+ }
28222+*/
28223+#ifdef CONFIG_X86_PAE
28224+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
28225+/*
28226+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
28227+ pgd = pgd_offset_k(addr);
28228+ pud = pud_offset(pgd, addr);
28229+ pmd = pmd_offset(pud, addr);
28230+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28231+ }
28232+*/
28233+#endif
28234+
28235+#ifdef CONFIG_MODULES
28236+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
28237+#endif
28238+
28239+#else
28240+ /* PaX: make kernel code/rodata read-only, rest non-executable */
28241+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
28242+ pgd = pgd_offset_k(addr);
28243+ pud = pud_offset(pgd, addr);
28244+ pmd = pmd_offset(pud, addr);
28245+ if (!pmd_present(*pmd))
28246+ continue;
28247+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
28248+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28249+ else
28250+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28251+ }
28252+
28253+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
28254+ end = addr + KERNEL_IMAGE_SIZE;
28255+ for (; addr < end; addr += PMD_SIZE) {
28256+ pgd = pgd_offset_k(addr);
28257+ pud = pud_offset(pgd, addr);
28258+ pmd = pmd_offset(pud, addr);
28259+ if (!pmd_present(*pmd))
28260+ continue;
28261+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
28262+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28263+ }
28264+#endif
28265+
28266+ flush_tlb_all();
28267+#endif
28268+
28269 free_init_pages("unused kernel memory",
28270 (unsigned long)(&__init_begin),
28271 (unsigned long)(&__init_end));
28272diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
28273index 2d19001..6a1046c 100644
28274--- a/arch/x86/mm/init_32.c
28275+++ b/arch/x86/mm/init_32.c
28276@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
28277 bool __read_mostly __vmalloc_start_set = false;
28278
28279 /*
28280- * Creates a middle page table and puts a pointer to it in the
28281- * given global directory entry. This only returns the gd entry
28282- * in non-PAE compilation mode, since the middle layer is folded.
28283- */
28284-static pmd_t * __init one_md_table_init(pgd_t *pgd)
28285-{
28286- pud_t *pud;
28287- pmd_t *pmd_table;
28288-
28289-#ifdef CONFIG_X86_PAE
28290- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
28291- pmd_table = (pmd_t *)alloc_low_page();
28292- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
28293- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
28294- pud = pud_offset(pgd, 0);
28295- BUG_ON(pmd_table != pmd_offset(pud, 0));
28296-
28297- return pmd_table;
28298- }
28299-#endif
28300- pud = pud_offset(pgd, 0);
28301- pmd_table = pmd_offset(pud, 0);
28302-
28303- return pmd_table;
28304-}
28305-
28306-/*
28307 * Create a page table and place a pointer to it in a middle page
28308 * directory entry:
28309 */
28310@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
28311 pte_t *page_table = (pte_t *)alloc_low_page();
28312
28313 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
28314+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28315+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
28316+#else
28317 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
28318+#endif
28319 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
28320 }
28321
28322 return pte_offset_kernel(pmd, 0);
28323 }
28324
28325+static pmd_t * __init one_md_table_init(pgd_t *pgd)
28326+{
28327+ pud_t *pud;
28328+ pmd_t *pmd_table;
28329+
28330+ pud = pud_offset(pgd, 0);
28331+ pmd_table = pmd_offset(pud, 0);
28332+
28333+ return pmd_table;
28334+}
28335+
28336 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
28337 {
28338 int pgd_idx = pgd_index(vaddr);
28339@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28340 int pgd_idx, pmd_idx;
28341 unsigned long vaddr;
28342 pgd_t *pgd;
28343+ pud_t *pud;
28344 pmd_t *pmd;
28345 pte_t *pte = NULL;
28346 unsigned long count = page_table_range_init_count(start, end);
28347@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28348 pgd = pgd_base + pgd_idx;
28349
28350 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
28351- pmd = one_md_table_init(pgd);
28352- pmd = pmd + pmd_index(vaddr);
28353+ pud = pud_offset(pgd, vaddr);
28354+ pmd = pmd_offset(pud, vaddr);
28355+
28356+#ifdef CONFIG_X86_PAE
28357+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28358+#endif
28359+
28360 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
28361 pmd++, pmd_idx++) {
28362 pte = page_table_kmap_check(one_page_table_init(pmd),
28363@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28364 }
28365 }
28366
28367-static inline int is_kernel_text(unsigned long addr)
28368+static inline int is_kernel_text(unsigned long start, unsigned long end)
28369 {
28370- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
28371- return 1;
28372- return 0;
28373+ if ((start > ktla_ktva((unsigned long)_etext) ||
28374+ end <= ktla_ktva((unsigned long)_stext)) &&
28375+ (start > ktla_ktva((unsigned long)_einittext) ||
28376+ end <= ktla_ktva((unsigned long)_sinittext)) &&
28377+
28378+#ifdef CONFIG_ACPI_SLEEP
28379+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
28380+#endif
28381+
28382+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
28383+ return 0;
28384+ return 1;
28385 }
28386
28387 /*
28388@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
28389 unsigned long last_map_addr = end;
28390 unsigned long start_pfn, end_pfn;
28391 pgd_t *pgd_base = swapper_pg_dir;
28392- int pgd_idx, pmd_idx, pte_ofs;
28393+ unsigned int pgd_idx, pmd_idx, pte_ofs;
28394 unsigned long pfn;
28395 pgd_t *pgd;
28396+ pud_t *pud;
28397 pmd_t *pmd;
28398 pte_t *pte;
28399 unsigned pages_2m, pages_4k;
28400@@ -291,8 +295,13 @@ repeat:
28401 pfn = start_pfn;
28402 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28403 pgd = pgd_base + pgd_idx;
28404- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
28405- pmd = one_md_table_init(pgd);
28406+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
28407+ pud = pud_offset(pgd, 0);
28408+ pmd = pmd_offset(pud, 0);
28409+
28410+#ifdef CONFIG_X86_PAE
28411+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28412+#endif
28413
28414 if (pfn >= end_pfn)
28415 continue;
28416@@ -304,14 +313,13 @@ repeat:
28417 #endif
28418 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
28419 pmd++, pmd_idx++) {
28420- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
28421+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
28422
28423 /*
28424 * Map with big pages if possible, otherwise
28425 * create normal page tables:
28426 */
28427 if (use_pse) {
28428- unsigned int addr2;
28429 pgprot_t prot = PAGE_KERNEL_LARGE;
28430 /*
28431 * first pass will use the same initial
28432@@ -322,11 +330,7 @@ repeat:
28433 _PAGE_PSE);
28434
28435 pfn &= PMD_MASK >> PAGE_SHIFT;
28436- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
28437- PAGE_OFFSET + PAGE_SIZE-1;
28438-
28439- if (is_kernel_text(addr) ||
28440- is_kernel_text(addr2))
28441+ if (is_kernel_text(address, address + PMD_SIZE))
28442 prot = PAGE_KERNEL_LARGE_EXEC;
28443
28444 pages_2m++;
28445@@ -343,7 +347,7 @@ repeat:
28446 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28447 pte += pte_ofs;
28448 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
28449- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
28450+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
28451 pgprot_t prot = PAGE_KERNEL;
28452 /*
28453 * first pass will use the same initial
28454@@ -351,7 +355,7 @@ repeat:
28455 */
28456 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
28457
28458- if (is_kernel_text(addr))
28459+ if (is_kernel_text(address, address + PAGE_SIZE))
28460 prot = PAGE_KERNEL_EXEC;
28461
28462 pages_4k++;
28463@@ -482,7 +486,7 @@ void __init native_pagetable_init(void)
28464
28465 pud = pud_offset(pgd, va);
28466 pmd = pmd_offset(pud, va);
28467- if (!pmd_present(*pmd))
28468+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
28469 break;
28470
28471 /* should not be large page here */
28472@@ -540,12 +544,10 @@ void __init early_ioremap_page_table_range_init(void)
28473
28474 static void __init pagetable_init(void)
28475 {
28476- pgd_t *pgd_base = swapper_pg_dir;
28477-
28478- permanent_kmaps_init(pgd_base);
28479+ permanent_kmaps_init(swapper_pg_dir);
28480 }
28481
28482-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28483+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28484 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28485
28486 /* user-defined highmem size */
28487@@ -752,6 +754,12 @@ void __init mem_init(void)
28488
28489 pci_iommu_alloc();
28490
28491+#ifdef CONFIG_PAX_PER_CPU_PGD
28492+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28493+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28494+ KERNEL_PGD_PTRS);
28495+#endif
28496+
28497 #ifdef CONFIG_FLATMEM
28498 BUG_ON(!mem_map);
28499 #endif
28500@@ -780,7 +788,7 @@ void __init mem_init(void)
28501 after_bootmem = 1;
28502
28503 codesize = (unsigned long) &_etext - (unsigned long) &_text;
28504- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
28505+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
28506 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
28507
28508 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
28509@@ -821,10 +829,10 @@ void __init mem_init(void)
28510 ((unsigned long)&__init_end -
28511 (unsigned long)&__init_begin) >> 10,
28512
28513- (unsigned long)&_etext, (unsigned long)&_edata,
28514- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
28515+ (unsigned long)&_sdata, (unsigned long)&_edata,
28516+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
28517
28518- (unsigned long)&_text, (unsigned long)&_etext,
28519+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
28520 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
28521
28522 /*
28523@@ -914,6 +922,7 @@ void set_kernel_text_rw(void)
28524 if (!kernel_set_to_readonly)
28525 return;
28526
28527+ start = ktla_ktva(start);
28528 pr_debug("Set kernel text: %lx - %lx for read write\n",
28529 start, start+size);
28530
28531@@ -928,6 +937,7 @@ void set_kernel_text_ro(void)
28532 if (!kernel_set_to_readonly)
28533 return;
28534
28535+ start = ktla_ktva(start);
28536 pr_debug("Set kernel text: %lx - %lx for read only\n",
28537 start, start+size);
28538
28539@@ -956,6 +966,7 @@ void mark_rodata_ro(void)
28540 unsigned long start = PFN_ALIGN(_text);
28541 unsigned long size = PFN_ALIGN(_etext) - start;
28542
28543+ start = ktla_ktva(start);
28544 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
28545 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
28546 size >> 10);
28547diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
28548index 474e28f..647dd12 100644
28549--- a/arch/x86/mm/init_64.c
28550+++ b/arch/x86/mm/init_64.c
28551@@ -150,7 +150,7 @@ early_param("gbpages", parse_direct_gbpages_on);
28552 * around without checking the pgd every time.
28553 */
28554
28555-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
28556+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
28557 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28558
28559 int force_personality32;
28560@@ -183,12 +183,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28561
28562 for (address = start; address <= end; address += PGDIR_SIZE) {
28563 const pgd_t *pgd_ref = pgd_offset_k(address);
28564+
28565+#ifdef CONFIG_PAX_PER_CPU_PGD
28566+ unsigned long cpu;
28567+#else
28568 struct page *page;
28569+#endif
28570
28571 if (pgd_none(*pgd_ref))
28572 continue;
28573
28574 spin_lock(&pgd_lock);
28575+
28576+#ifdef CONFIG_PAX_PER_CPU_PGD
28577+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28578+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
28579+#else
28580 list_for_each_entry(page, &pgd_list, lru) {
28581 pgd_t *pgd;
28582 spinlock_t *pgt_lock;
28583@@ -197,6 +207,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28584 /* the pgt_lock only for Xen */
28585 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
28586 spin_lock(pgt_lock);
28587+#endif
28588
28589 if (pgd_none(*pgd))
28590 set_pgd(pgd, *pgd_ref);
28591@@ -204,7 +215,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28592 BUG_ON(pgd_page_vaddr(*pgd)
28593 != pgd_page_vaddr(*pgd_ref));
28594
28595+#ifndef CONFIG_PAX_PER_CPU_PGD
28596 spin_unlock(pgt_lock);
28597+#endif
28598+
28599 }
28600 spin_unlock(&pgd_lock);
28601 }
28602@@ -237,7 +251,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
28603 {
28604 if (pgd_none(*pgd)) {
28605 pud_t *pud = (pud_t *)spp_getpage();
28606- pgd_populate(&init_mm, pgd, pud);
28607+ pgd_populate_kernel(&init_mm, pgd, pud);
28608 if (pud != pud_offset(pgd, 0))
28609 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
28610 pud, pud_offset(pgd, 0));
28611@@ -249,7 +263,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
28612 {
28613 if (pud_none(*pud)) {
28614 pmd_t *pmd = (pmd_t *) spp_getpage();
28615- pud_populate(&init_mm, pud, pmd);
28616+ pud_populate_kernel(&init_mm, pud, pmd);
28617 if (pmd != pmd_offset(pud, 0))
28618 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
28619 pmd, pmd_offset(pud, 0));
28620@@ -278,7 +292,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
28621 pmd = fill_pmd(pud, vaddr);
28622 pte = fill_pte(pmd, vaddr);
28623
28624+ pax_open_kernel();
28625 set_pte(pte, new_pte);
28626+ pax_close_kernel();
28627
28628 /*
28629 * It's enough to flush this one mapping.
28630@@ -337,14 +353,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
28631 pgd = pgd_offset_k((unsigned long)__va(phys));
28632 if (pgd_none(*pgd)) {
28633 pud = (pud_t *) spp_getpage();
28634- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
28635- _PAGE_USER));
28636+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
28637 }
28638 pud = pud_offset(pgd, (unsigned long)__va(phys));
28639 if (pud_none(*pud)) {
28640 pmd = (pmd_t *) spp_getpage();
28641- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
28642- _PAGE_USER));
28643+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
28644 }
28645 pmd = pmd_offset(pud, phys);
28646 BUG_ON(!pmd_none(*pmd));
28647@@ -585,7 +599,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
28648 prot);
28649
28650 spin_lock(&init_mm.page_table_lock);
28651- pud_populate(&init_mm, pud, pmd);
28652+ pud_populate_kernel(&init_mm, pud, pmd);
28653 spin_unlock(&init_mm.page_table_lock);
28654 }
28655 __flush_tlb_all();
28656@@ -626,7 +640,7 @@ kernel_physical_mapping_init(unsigned long start,
28657 page_size_mask);
28658
28659 spin_lock(&init_mm.page_table_lock);
28660- pgd_populate(&init_mm, pgd, pud);
28661+ pgd_populate_kernel(&init_mm, pgd, pud);
28662 spin_unlock(&init_mm.page_table_lock);
28663 pgd_changed = true;
28664 }
28665@@ -1065,6 +1079,12 @@ void __init mem_init(void)
28666
28667 pci_iommu_alloc();
28668
28669+#ifdef CONFIG_PAX_PER_CPU_PGD
28670+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28671+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28672+ KERNEL_PGD_PTRS);
28673+#endif
28674+
28675 /* clear_bss() already clear the empty_zero_page */
28676
28677 reservedpages = 0;
28678@@ -1224,8 +1244,8 @@ int kern_addr_valid(unsigned long addr)
28679 static struct vm_area_struct gate_vma = {
28680 .vm_start = VSYSCALL_START,
28681 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
28682- .vm_page_prot = PAGE_READONLY_EXEC,
28683- .vm_flags = VM_READ | VM_EXEC
28684+ .vm_page_prot = PAGE_READONLY,
28685+ .vm_flags = VM_READ
28686 };
28687
28688 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
28689@@ -1259,7 +1279,7 @@ int in_gate_area_no_mm(unsigned long addr)
28690
28691 const char *arch_vma_name(struct vm_area_struct *vma)
28692 {
28693- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
28694+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
28695 return "[vdso]";
28696 if (vma == &gate_vma)
28697 return "[vsyscall]";
28698diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
28699index 7b179b4..6bd17777 100644
28700--- a/arch/x86/mm/iomap_32.c
28701+++ b/arch/x86/mm/iomap_32.c
28702@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
28703 type = kmap_atomic_idx_push();
28704 idx = type + KM_TYPE_NR * smp_processor_id();
28705 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
28706+
28707+ pax_open_kernel();
28708 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
28709+ pax_close_kernel();
28710+
28711 arch_flush_lazy_mmu_mode();
28712
28713 return (void *)vaddr;
28714diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
28715index 78fe3f1..73b95e2 100644
28716--- a/arch/x86/mm/ioremap.c
28717+++ b/arch/x86/mm/ioremap.c
28718@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
28719 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
28720 int is_ram = page_is_ram(pfn);
28721
28722- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
28723+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
28724 return NULL;
28725 WARN_ON_ONCE(is_ram);
28726 }
28727@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
28728 *
28729 * Caller must ensure there is only one unmapping for the same pointer.
28730 */
28731-void iounmap(volatile void __iomem *addr)
28732+void iounmap(const volatile void __iomem *addr)
28733 {
28734 struct vm_struct *p, *o;
28735
28736@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
28737
28738 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
28739 if (page_is_ram(start >> PAGE_SHIFT))
28740+#ifdef CONFIG_HIGHMEM
28741+ if ((start >> PAGE_SHIFT) < max_low_pfn)
28742+#endif
28743 return __va(phys);
28744
28745 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
28746@@ -327,6 +330,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
28747 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
28748 {
28749 if (page_is_ram(phys >> PAGE_SHIFT))
28750+#ifdef CONFIG_HIGHMEM
28751+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
28752+#endif
28753 return;
28754
28755 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
28756@@ -344,7 +350,7 @@ static int __init early_ioremap_debug_setup(char *str)
28757 early_param("early_ioremap_debug", early_ioremap_debug_setup);
28758
28759 static __initdata int after_paging_init;
28760-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
28761+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
28762
28763 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
28764 {
28765@@ -381,8 +387,7 @@ void __init early_ioremap_init(void)
28766 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
28767
28768 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
28769- memset(bm_pte, 0, sizeof(bm_pte));
28770- pmd_populate_kernel(&init_mm, pmd, bm_pte);
28771+ pmd_populate_user(&init_mm, pmd, bm_pte);
28772
28773 /*
28774 * The boot-ioremap range spans multiple pmds, for which
28775diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
28776index d87dd6d..bf3fa66 100644
28777--- a/arch/x86/mm/kmemcheck/kmemcheck.c
28778+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
28779@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
28780 * memory (e.g. tracked pages)? For now, we need this to avoid
28781 * invoking kmemcheck for PnP BIOS calls.
28782 */
28783- if (regs->flags & X86_VM_MASK)
28784+ if (v8086_mode(regs))
28785 return false;
28786- if (regs->cs != __KERNEL_CS)
28787+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
28788 return false;
28789
28790 pte = kmemcheck_pte_lookup(address);
28791diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
28792index 845df68..1d8d29f 100644
28793--- a/arch/x86/mm/mmap.c
28794+++ b/arch/x86/mm/mmap.c
28795@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
28796 * Leave an at least ~128 MB hole with possible stack randomization.
28797 */
28798 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
28799-#define MAX_GAP (TASK_SIZE/6*5)
28800+#define MAX_GAP (pax_task_size/6*5)
28801
28802 static int mmap_is_legacy(void)
28803 {
28804@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
28805 return rnd << PAGE_SHIFT;
28806 }
28807
28808-static unsigned long mmap_base(void)
28809+static unsigned long mmap_base(struct mm_struct *mm)
28810 {
28811 unsigned long gap = rlimit(RLIMIT_STACK);
28812+ unsigned long pax_task_size = TASK_SIZE;
28813+
28814+#ifdef CONFIG_PAX_SEGMEXEC
28815+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28816+ pax_task_size = SEGMEXEC_TASK_SIZE;
28817+#endif
28818
28819 if (gap < MIN_GAP)
28820 gap = MIN_GAP;
28821 else if (gap > MAX_GAP)
28822 gap = MAX_GAP;
28823
28824- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
28825+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
28826 }
28827
28828 /*
28829 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
28830 * does, but not when emulating X86_32
28831 */
28832-static unsigned long mmap_legacy_base(void)
28833+static unsigned long mmap_legacy_base(struct mm_struct *mm)
28834 {
28835- if (mmap_is_ia32())
28836+ if (mmap_is_ia32()) {
28837+
28838+#ifdef CONFIG_PAX_SEGMEXEC
28839+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28840+ return SEGMEXEC_TASK_UNMAPPED_BASE;
28841+ else
28842+#endif
28843+
28844 return TASK_UNMAPPED_BASE;
28845- else
28846+ } else
28847 return TASK_UNMAPPED_BASE + mmap_rnd();
28848 }
28849
28850@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
28851 void arch_pick_mmap_layout(struct mm_struct *mm)
28852 {
28853 if (mmap_is_legacy()) {
28854- mm->mmap_base = mmap_legacy_base();
28855+ mm->mmap_base = mmap_legacy_base(mm);
28856+
28857+#ifdef CONFIG_PAX_RANDMMAP
28858+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28859+ mm->mmap_base += mm->delta_mmap;
28860+#endif
28861+
28862 mm->get_unmapped_area = arch_get_unmapped_area;
28863 mm->unmap_area = arch_unmap_area;
28864 } else {
28865- mm->mmap_base = mmap_base();
28866+ mm->mmap_base = mmap_base(mm);
28867+
28868+#ifdef CONFIG_PAX_RANDMMAP
28869+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28870+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
28871+#endif
28872+
28873 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
28874 mm->unmap_area = arch_unmap_area_topdown;
28875 }
28876diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
28877index dc0b727..f612039 100644
28878--- a/arch/x86/mm/mmio-mod.c
28879+++ b/arch/x86/mm/mmio-mod.c
28880@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
28881 break;
28882 default:
28883 {
28884- unsigned char *ip = (unsigned char *)instptr;
28885+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
28886 my_trace->opcode = MMIO_UNKNOWN_OP;
28887 my_trace->width = 0;
28888 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
28889@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
28890 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28891 void __iomem *addr)
28892 {
28893- static atomic_t next_id;
28894+ static atomic_unchecked_t next_id;
28895 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
28896 /* These are page-unaligned. */
28897 struct mmiotrace_map map = {
28898@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28899 .private = trace
28900 },
28901 .phys = offset,
28902- .id = atomic_inc_return(&next_id)
28903+ .id = atomic_inc_return_unchecked(&next_id)
28904 };
28905 map.map_id = trace->id;
28906
28907@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
28908 ioremap_trace_core(offset, size, addr);
28909 }
28910
28911-static void iounmap_trace_core(volatile void __iomem *addr)
28912+static void iounmap_trace_core(const volatile void __iomem *addr)
28913 {
28914 struct mmiotrace_map map = {
28915 .phys = 0,
28916@@ -328,7 +328,7 @@ not_enabled:
28917 }
28918 }
28919
28920-void mmiotrace_iounmap(volatile void __iomem *addr)
28921+void mmiotrace_iounmap(const volatile void __iomem *addr)
28922 {
28923 might_sleep();
28924 if (is_enabled()) /* recheck and proper locking in *_core() */
28925diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
28926index 72fe01e..f1a8daa 100644
28927--- a/arch/x86/mm/numa.c
28928+++ b/arch/x86/mm/numa.c
28929@@ -477,7 +477,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
28930 return true;
28931 }
28932
28933-static int __init numa_register_memblks(struct numa_meminfo *mi)
28934+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
28935 {
28936 unsigned long uninitialized_var(pfn_align);
28937 int i, nid;
28938diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
28939index 0e38951..4ca8458 100644
28940--- a/arch/x86/mm/pageattr-test.c
28941+++ b/arch/x86/mm/pageattr-test.c
28942@@ -36,7 +36,7 @@ enum {
28943
28944 static int pte_testbit(pte_t pte)
28945 {
28946- return pte_flags(pte) & _PAGE_UNUSED1;
28947+ return pte_flags(pte) & _PAGE_CPA_TEST;
28948 }
28949
28950 struct split_state {
28951diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
28952index fb4e73e..43f7238 100644
28953--- a/arch/x86/mm/pageattr.c
28954+++ b/arch/x86/mm/pageattr.c
28955@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28956 */
28957 #ifdef CONFIG_PCI_BIOS
28958 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
28959- pgprot_val(forbidden) |= _PAGE_NX;
28960+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28961 #endif
28962
28963 /*
28964@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28965 * Does not cover __inittext since that is gone later on. On
28966 * 64bit we do not enforce !NX on the low mapping
28967 */
28968- if (within(address, (unsigned long)_text, (unsigned long)_etext))
28969- pgprot_val(forbidden) |= _PAGE_NX;
28970+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
28971+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28972
28973+#ifdef CONFIG_DEBUG_RODATA
28974 /*
28975 * The .rodata section needs to be read-only. Using the pfn
28976 * catches all aliases.
28977@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28978 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
28979 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
28980 pgprot_val(forbidden) |= _PAGE_RW;
28981+#endif
28982
28983 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
28984 /*
28985@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28986 }
28987 #endif
28988
28989+#ifdef CONFIG_PAX_KERNEXEC
28990+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
28991+ pgprot_val(forbidden) |= _PAGE_RW;
28992+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28993+ }
28994+#endif
28995+
28996 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
28997
28998 return prot;
28999@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
29000 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
29001 {
29002 /* change init_mm */
29003+ pax_open_kernel();
29004 set_pte_atomic(kpte, pte);
29005+
29006 #ifdef CONFIG_X86_32
29007 if (!SHARED_KERNEL_PMD) {
29008+
29009+#ifdef CONFIG_PAX_PER_CPU_PGD
29010+ unsigned long cpu;
29011+#else
29012 struct page *page;
29013+#endif
29014
29015+#ifdef CONFIG_PAX_PER_CPU_PGD
29016+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
29017+ pgd_t *pgd = get_cpu_pgd(cpu);
29018+#else
29019 list_for_each_entry(page, &pgd_list, lru) {
29020- pgd_t *pgd;
29021+ pgd_t *pgd = (pgd_t *)page_address(page);
29022+#endif
29023+
29024 pud_t *pud;
29025 pmd_t *pmd;
29026
29027- pgd = (pgd_t *)page_address(page) + pgd_index(address);
29028+ pgd += pgd_index(address);
29029 pud = pud_offset(pgd, address);
29030 pmd = pmd_offset(pud, address);
29031 set_pte_atomic((pte_t *)pmd, pte);
29032 }
29033 }
29034 #endif
29035+ pax_close_kernel();
29036 }
29037
29038 static int
29039diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
29040index 6574388..87e9bef 100644
29041--- a/arch/x86/mm/pat.c
29042+++ b/arch/x86/mm/pat.c
29043@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
29044
29045 if (!entry) {
29046 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
29047- current->comm, current->pid, start, end - 1);
29048+ current->comm, task_pid_nr(current), start, end - 1);
29049 return -EINVAL;
29050 }
29051
29052@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29053
29054 while (cursor < to) {
29055 if (!devmem_is_allowed(pfn)) {
29056- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
29057- current->comm, from, to - 1);
29058+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
29059+ current->comm, from, to - 1, cursor);
29060 return 0;
29061 }
29062 cursor += PAGE_SIZE;
29063@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
29064 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
29065 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
29066 "for [mem %#010Lx-%#010Lx]\n",
29067- current->comm, current->pid,
29068+ current->comm, task_pid_nr(current),
29069 cattr_name(flags),
29070 base, (unsigned long long)(base + size-1));
29071 return -EINVAL;
29072@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
29073 flags = lookup_memtype(paddr);
29074 if (want_flags != flags) {
29075 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
29076- current->comm, current->pid,
29077+ current->comm, task_pid_nr(current),
29078 cattr_name(want_flags),
29079 (unsigned long long)paddr,
29080 (unsigned long long)(paddr + size - 1),
29081@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
29082 free_memtype(paddr, paddr + size);
29083 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
29084 " for [mem %#010Lx-%#010Lx], got %s\n",
29085- current->comm, current->pid,
29086+ current->comm, task_pid_nr(current),
29087 cattr_name(want_flags),
29088 (unsigned long long)paddr,
29089 (unsigned long long)(paddr + size - 1),
29090diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
29091index 9f0614d..92ae64a 100644
29092--- a/arch/x86/mm/pf_in.c
29093+++ b/arch/x86/mm/pf_in.c
29094@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
29095 int i;
29096 enum reason_type rv = OTHERS;
29097
29098- p = (unsigned char *)ins_addr;
29099+ p = (unsigned char *)ktla_ktva(ins_addr);
29100 p += skip_prefix(p, &prf);
29101 p += get_opcode(p, &opcode);
29102
29103@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
29104 struct prefix_bits prf;
29105 int i;
29106
29107- p = (unsigned char *)ins_addr;
29108+ p = (unsigned char *)ktla_ktva(ins_addr);
29109 p += skip_prefix(p, &prf);
29110 p += get_opcode(p, &opcode);
29111
29112@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
29113 struct prefix_bits prf;
29114 int i;
29115
29116- p = (unsigned char *)ins_addr;
29117+ p = (unsigned char *)ktla_ktva(ins_addr);
29118 p += skip_prefix(p, &prf);
29119 p += get_opcode(p, &opcode);
29120
29121@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
29122 struct prefix_bits prf;
29123 int i;
29124
29125- p = (unsigned char *)ins_addr;
29126+ p = (unsigned char *)ktla_ktva(ins_addr);
29127 p += skip_prefix(p, &prf);
29128 p += get_opcode(p, &opcode);
29129 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
29130@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
29131 struct prefix_bits prf;
29132 int i;
29133
29134- p = (unsigned char *)ins_addr;
29135+ p = (unsigned char *)ktla_ktva(ins_addr);
29136 p += skip_prefix(p, &prf);
29137 p += get_opcode(p, &opcode);
29138 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
29139diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
29140index 17fda6a..489c74a 100644
29141--- a/arch/x86/mm/pgtable.c
29142+++ b/arch/x86/mm/pgtable.c
29143@@ -91,10 +91,64 @@ static inline void pgd_list_del(pgd_t *pgd)
29144 list_del(&page->lru);
29145 }
29146
29147-#define UNSHARED_PTRS_PER_PGD \
29148- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29149+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29150+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
29151
29152+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
29153+{
29154+ unsigned int count = USER_PGD_PTRS;
29155
29156+ while (count--)
29157+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
29158+}
29159+#endif
29160+
29161+#ifdef CONFIG_PAX_PER_CPU_PGD
29162+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
29163+{
29164+ unsigned int count = USER_PGD_PTRS;
29165+
29166+ while (count--) {
29167+ pgd_t pgd;
29168+
29169+#ifdef CONFIG_X86_64
29170+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
29171+#else
29172+ pgd = *src++;
29173+#endif
29174+
29175+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29176+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
29177+#endif
29178+
29179+ *dst++ = pgd;
29180+ }
29181+
29182+}
29183+#endif
29184+
29185+#ifdef CONFIG_X86_64
29186+#define pxd_t pud_t
29187+#define pyd_t pgd_t
29188+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
29189+#define pxd_free(mm, pud) pud_free((mm), (pud))
29190+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
29191+#define pyd_offset(mm, address) pgd_offset((mm), (address))
29192+#define PYD_SIZE PGDIR_SIZE
29193+#else
29194+#define pxd_t pmd_t
29195+#define pyd_t pud_t
29196+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
29197+#define pxd_free(mm, pud) pmd_free((mm), (pud))
29198+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
29199+#define pyd_offset(mm, address) pud_offset((mm), (address))
29200+#define PYD_SIZE PUD_SIZE
29201+#endif
29202+
29203+#ifdef CONFIG_PAX_PER_CPU_PGD
29204+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
29205+static inline void pgd_dtor(pgd_t *pgd) {}
29206+#else
29207 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
29208 {
29209 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
29210@@ -135,6 +189,7 @@ static void pgd_dtor(pgd_t *pgd)
29211 pgd_list_del(pgd);
29212 spin_unlock(&pgd_lock);
29213 }
29214+#endif
29215
29216 /*
29217 * List of all pgd's needed for non-PAE so it can invalidate entries
29218@@ -147,7 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
29219 * -- nyc
29220 */
29221
29222-#ifdef CONFIG_X86_PAE
29223+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
29224 /*
29225 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
29226 * updating the top-level pagetable entries to guarantee the
29227@@ -159,7 +214,7 @@ static void pgd_dtor(pgd_t *pgd)
29228 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
29229 * and initialize the kernel pmds here.
29230 */
29231-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
29232+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29233
29234 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29235 {
29236@@ -177,36 +232,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29237 */
29238 flush_tlb_mm(mm);
29239 }
29240+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
29241+#define PREALLOCATED_PXDS USER_PGD_PTRS
29242 #else /* !CONFIG_X86_PAE */
29243
29244 /* No need to prepopulate any pagetable entries in non-PAE modes. */
29245-#define PREALLOCATED_PMDS 0
29246+#define PREALLOCATED_PXDS 0
29247
29248 #endif /* CONFIG_X86_PAE */
29249
29250-static void free_pmds(pmd_t *pmds[])
29251+static void free_pxds(pxd_t *pxds[])
29252 {
29253 int i;
29254
29255- for(i = 0; i < PREALLOCATED_PMDS; i++)
29256- if (pmds[i])
29257- free_page((unsigned long)pmds[i]);
29258+ for(i = 0; i < PREALLOCATED_PXDS; i++)
29259+ if (pxds[i])
29260+ free_page((unsigned long)pxds[i]);
29261 }
29262
29263-static int preallocate_pmds(pmd_t *pmds[])
29264+static int preallocate_pxds(pxd_t *pxds[])
29265 {
29266 int i;
29267 bool failed = false;
29268
29269- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29270- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
29271- if (pmd == NULL)
29272+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29273+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
29274+ if (pxd == NULL)
29275 failed = true;
29276- pmds[i] = pmd;
29277+ pxds[i] = pxd;
29278 }
29279
29280 if (failed) {
29281- free_pmds(pmds);
29282+ free_pxds(pxds);
29283 return -ENOMEM;
29284 }
29285
29286@@ -219,51 +276,55 @@ static int preallocate_pmds(pmd_t *pmds[])
29287 * preallocate which never got a corresponding vma will need to be
29288 * freed manually.
29289 */
29290-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
29291+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
29292 {
29293 int i;
29294
29295- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29296+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29297 pgd_t pgd = pgdp[i];
29298
29299 if (pgd_val(pgd) != 0) {
29300- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
29301+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
29302
29303- pgdp[i] = native_make_pgd(0);
29304+ set_pgd(pgdp + i, native_make_pgd(0));
29305
29306- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
29307- pmd_free(mm, pmd);
29308+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
29309+ pxd_free(mm, pxd);
29310 }
29311 }
29312 }
29313
29314-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
29315+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
29316 {
29317- pud_t *pud;
29318+ pyd_t *pyd;
29319 unsigned long addr;
29320 int i;
29321
29322- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
29323+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
29324 return;
29325
29326- pud = pud_offset(pgd, 0);
29327+#ifdef CONFIG_X86_64
29328+ pyd = pyd_offset(mm, 0L);
29329+#else
29330+ pyd = pyd_offset(pgd, 0L);
29331+#endif
29332
29333- for (addr = i = 0; i < PREALLOCATED_PMDS;
29334- i++, pud++, addr += PUD_SIZE) {
29335- pmd_t *pmd = pmds[i];
29336+ for (addr = i = 0; i < PREALLOCATED_PXDS;
29337+ i++, pyd++, addr += PYD_SIZE) {
29338+ pxd_t *pxd = pxds[i];
29339
29340 if (i >= KERNEL_PGD_BOUNDARY)
29341- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29342- sizeof(pmd_t) * PTRS_PER_PMD);
29343+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29344+ sizeof(pxd_t) * PTRS_PER_PMD);
29345
29346- pud_populate(mm, pud, pmd);
29347+ pyd_populate(mm, pyd, pxd);
29348 }
29349 }
29350
29351 pgd_t *pgd_alloc(struct mm_struct *mm)
29352 {
29353 pgd_t *pgd;
29354- pmd_t *pmds[PREALLOCATED_PMDS];
29355+ pxd_t *pxds[PREALLOCATED_PXDS];
29356
29357 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
29358
29359@@ -272,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29360
29361 mm->pgd = pgd;
29362
29363- if (preallocate_pmds(pmds) != 0)
29364+ if (preallocate_pxds(pxds) != 0)
29365 goto out_free_pgd;
29366
29367 if (paravirt_pgd_alloc(mm) != 0)
29368- goto out_free_pmds;
29369+ goto out_free_pxds;
29370
29371 /*
29372 * Make sure that pre-populating the pmds is atomic with
29373@@ -286,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29374 spin_lock(&pgd_lock);
29375
29376 pgd_ctor(mm, pgd);
29377- pgd_prepopulate_pmd(mm, pgd, pmds);
29378+ pgd_prepopulate_pxd(mm, pgd, pxds);
29379
29380 spin_unlock(&pgd_lock);
29381
29382 return pgd;
29383
29384-out_free_pmds:
29385- free_pmds(pmds);
29386+out_free_pxds:
29387+ free_pxds(pxds);
29388 out_free_pgd:
29389 free_page((unsigned long)pgd);
29390 out:
29391@@ -302,7 +363,7 @@ out:
29392
29393 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
29394 {
29395- pgd_mop_up_pmds(mm, pgd);
29396+ pgd_mop_up_pxds(mm, pgd);
29397 pgd_dtor(pgd);
29398 paravirt_pgd_free(mm, pgd);
29399 free_page((unsigned long)pgd);
29400diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
29401index a69bcb8..19068ab 100644
29402--- a/arch/x86/mm/pgtable_32.c
29403+++ b/arch/x86/mm/pgtable_32.c
29404@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
29405 return;
29406 }
29407 pte = pte_offset_kernel(pmd, vaddr);
29408+
29409+ pax_open_kernel();
29410 if (pte_val(pteval))
29411 set_pte_at(&init_mm, vaddr, pte, pteval);
29412 else
29413 pte_clear(&init_mm, vaddr, pte);
29414+ pax_close_kernel();
29415
29416 /*
29417 * It's enough to flush this one mapping.
29418diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
29419index e666cbb..61788c45 100644
29420--- a/arch/x86/mm/physaddr.c
29421+++ b/arch/x86/mm/physaddr.c
29422@@ -10,7 +10,7 @@
29423 #ifdef CONFIG_X86_64
29424
29425 #ifdef CONFIG_DEBUG_VIRTUAL
29426-unsigned long __phys_addr(unsigned long x)
29427+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29428 {
29429 unsigned long y = x - __START_KERNEL_map;
29430
29431@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
29432 #else
29433
29434 #ifdef CONFIG_DEBUG_VIRTUAL
29435-unsigned long __phys_addr(unsigned long x)
29436+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29437 {
29438 unsigned long phys_addr = x - PAGE_OFFSET;
29439 /* VMALLOC_* aren't constants */
29440diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
29441index 410531d..0f16030 100644
29442--- a/arch/x86/mm/setup_nx.c
29443+++ b/arch/x86/mm/setup_nx.c
29444@@ -5,8 +5,10 @@
29445 #include <asm/pgtable.h>
29446 #include <asm/proto.h>
29447
29448+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29449 static int disable_nx __cpuinitdata;
29450
29451+#ifndef CONFIG_PAX_PAGEEXEC
29452 /*
29453 * noexec = on|off
29454 *
29455@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
29456 return 0;
29457 }
29458 early_param("noexec", noexec_setup);
29459+#endif
29460+
29461+#endif
29462
29463 void __cpuinit x86_configure_nx(void)
29464 {
29465+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29466 if (cpu_has_nx && !disable_nx)
29467 __supported_pte_mask |= _PAGE_NX;
29468 else
29469+#endif
29470 __supported_pte_mask &= ~_PAGE_NX;
29471 }
29472
29473diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
29474index 282375f..e03a98f 100644
29475--- a/arch/x86/mm/tlb.c
29476+++ b/arch/x86/mm/tlb.c
29477@@ -48,7 +48,11 @@ void leave_mm(int cpu)
29478 BUG();
29479 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
29480 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
29481+
29482+#ifndef CONFIG_PAX_PER_CPU_PGD
29483 load_cr3(swapper_pg_dir);
29484+#endif
29485+
29486 }
29487 }
29488 EXPORT_SYMBOL_GPL(leave_mm);
29489diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
29490index 877b9a1..a8ecf42 100644
29491--- a/arch/x86/net/bpf_jit.S
29492+++ b/arch/x86/net/bpf_jit.S
29493@@ -9,6 +9,7 @@
29494 */
29495 #include <linux/linkage.h>
29496 #include <asm/dwarf2.h>
29497+#include <asm/alternative-asm.h>
29498
29499 /*
29500 * Calling convention :
29501@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
29502 jle bpf_slow_path_word
29503 mov (SKBDATA,%rsi),%eax
29504 bswap %eax /* ntohl() */
29505+ pax_force_retaddr
29506 ret
29507
29508 sk_load_half:
29509@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
29510 jle bpf_slow_path_half
29511 movzwl (SKBDATA,%rsi),%eax
29512 rol $8,%ax # ntohs()
29513+ pax_force_retaddr
29514 ret
29515
29516 sk_load_byte:
29517@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
29518 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
29519 jle bpf_slow_path_byte
29520 movzbl (SKBDATA,%rsi),%eax
29521+ pax_force_retaddr
29522 ret
29523
29524 /**
29525@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
29526 movzbl (SKBDATA,%rsi),%ebx
29527 and $15,%bl
29528 shl $2,%bl
29529+ pax_force_retaddr
29530 ret
29531
29532 /* rsi contains offset and can be scratched */
29533@@ -109,6 +114,7 @@ bpf_slow_path_word:
29534 js bpf_error
29535 mov -12(%rbp),%eax
29536 bswap %eax
29537+ pax_force_retaddr
29538 ret
29539
29540 bpf_slow_path_half:
29541@@ -117,12 +123,14 @@ bpf_slow_path_half:
29542 mov -12(%rbp),%ax
29543 rol $8,%ax
29544 movzwl %ax,%eax
29545+ pax_force_retaddr
29546 ret
29547
29548 bpf_slow_path_byte:
29549 bpf_slow_path_common(1)
29550 js bpf_error
29551 movzbl -12(%rbp),%eax
29552+ pax_force_retaddr
29553 ret
29554
29555 bpf_slow_path_byte_msh:
29556@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
29557 and $15,%al
29558 shl $2,%al
29559 xchg %eax,%ebx
29560+ pax_force_retaddr
29561 ret
29562
29563 #define sk_negative_common(SIZE) \
29564@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
29565 sk_negative_common(4)
29566 mov (%rax), %eax
29567 bswap %eax
29568+ pax_force_retaddr
29569 ret
29570
29571 bpf_slow_path_half_neg:
29572@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
29573 mov (%rax),%ax
29574 rol $8,%ax
29575 movzwl %ax,%eax
29576+ pax_force_retaddr
29577 ret
29578
29579 bpf_slow_path_byte_neg:
29580@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
29581 .globl sk_load_byte_negative_offset
29582 sk_negative_common(1)
29583 movzbl (%rax), %eax
29584+ pax_force_retaddr
29585 ret
29586
29587 bpf_slow_path_byte_msh_neg:
29588@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
29589 and $15,%al
29590 shl $2,%al
29591 xchg %eax,%ebx
29592+ pax_force_retaddr
29593 ret
29594
29595 bpf_error:
29596@@ -197,4 +210,5 @@ bpf_error:
29597 xor %eax,%eax
29598 mov -8(%rbp),%rbx
29599 leaveq
29600+ pax_force_retaddr
29601 ret
29602diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
29603index 3cbe4538..003d011 100644
29604--- a/arch/x86/net/bpf_jit_comp.c
29605+++ b/arch/x86/net/bpf_jit_comp.c
29606@@ -12,6 +12,7 @@
29607 #include <linux/netdevice.h>
29608 #include <linux/filter.h>
29609 #include <linux/if_vlan.h>
29610+#include <linux/random.h>
29611
29612 /*
29613 * Conventions :
29614@@ -49,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
29615 return ptr + len;
29616 }
29617
29618+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29619+#define MAX_INSTR_CODE_SIZE 96
29620+#else
29621+#define MAX_INSTR_CODE_SIZE 64
29622+#endif
29623+
29624 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
29625
29626 #define EMIT1(b1) EMIT(b1, 1)
29627 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
29628 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
29629 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
29630+
29631+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29632+/* original constant will appear in ecx */
29633+#define DILUTE_CONST_SEQUENCE(_off, _key) \
29634+do { \
29635+ /* mov ecx, randkey */ \
29636+ EMIT1(0xb9); \
29637+ EMIT(_key, 4); \
29638+ /* xor ecx, randkey ^ off */ \
29639+ EMIT2(0x81, 0xf1); \
29640+ EMIT((_key) ^ (_off), 4); \
29641+} while (0)
29642+
29643+#define EMIT1_off32(b1, _off) \
29644+do { \
29645+ switch (b1) { \
29646+ case 0x05: /* add eax, imm32 */ \
29647+ case 0x2d: /* sub eax, imm32 */ \
29648+ case 0x25: /* and eax, imm32 */ \
29649+ case 0x0d: /* or eax, imm32 */ \
29650+ case 0xb8: /* mov eax, imm32 */ \
29651+ case 0x35: /* xor eax, imm32 */ \
29652+ case 0x3d: /* cmp eax, imm32 */ \
29653+ case 0xa9: /* test eax, imm32 */ \
29654+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29655+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
29656+ break; \
29657+ case 0xbb: /* mov ebx, imm32 */ \
29658+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29659+ /* mov ebx, ecx */ \
29660+ EMIT2(0x89, 0xcb); \
29661+ break; \
29662+ case 0xbe: /* mov esi, imm32 */ \
29663+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29664+ /* mov esi, ecx */ \
29665+ EMIT2(0x89, 0xce); \
29666+ break; \
29667+ case 0xe8: /* call rel imm32, always to known funcs */ \
29668+ EMIT1(b1); \
29669+ EMIT(_off, 4); \
29670+ break; \
29671+ case 0xe9: /* jmp rel imm32 */ \
29672+ EMIT1(b1); \
29673+ EMIT(_off, 4); \
29674+ /* prevent fall-through, we're not called if off = 0 */ \
29675+ EMIT(0xcccccccc, 4); \
29676+ EMIT(0xcccccccc, 4); \
29677+ break; \
29678+ default: \
29679+ BUILD_BUG(); \
29680+ } \
29681+} while (0)
29682+
29683+#define EMIT2_off32(b1, b2, _off) \
29684+do { \
29685+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
29686+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
29687+ EMIT(randkey, 4); \
29688+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
29689+ EMIT((_off) - randkey, 4); \
29690+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
29691+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29692+ /* imul eax, ecx */ \
29693+ EMIT3(0x0f, 0xaf, 0xc1); \
29694+ } else { \
29695+ BUILD_BUG(); \
29696+ } \
29697+} while (0)
29698+#else
29699 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
29700+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
29701+#endif
29702
29703 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
29704 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
29705@@ -90,6 +168,24 @@ do { \
29706 #define X86_JBE 0x76
29707 #define X86_JA 0x77
29708
29709+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29710+#define APPEND_FLOW_VERIFY() \
29711+do { \
29712+ /* mov ecx, randkey */ \
29713+ EMIT1(0xb9); \
29714+ EMIT(randkey, 4); \
29715+ /* cmp ecx, randkey */ \
29716+ EMIT2(0x81, 0xf9); \
29717+ EMIT(randkey, 4); \
29718+ /* jz after 8 int 3s */ \
29719+ EMIT2(0x74, 0x08); \
29720+ EMIT(0xcccccccc, 4); \
29721+ EMIT(0xcccccccc, 4); \
29722+} while (0)
29723+#else
29724+#define APPEND_FLOW_VERIFY() do { } while (0)
29725+#endif
29726+
29727 #define EMIT_COND_JMP(op, offset) \
29728 do { \
29729 if (is_near(offset)) \
29730@@ -97,6 +193,7 @@ do { \
29731 else { \
29732 EMIT2(0x0f, op + 0x10); \
29733 EMIT(offset, 4); /* jxx .+off32 */ \
29734+ APPEND_FLOW_VERIFY(); \
29735 } \
29736 } while (0)
29737
29738@@ -121,6 +218,11 @@ static inline void bpf_flush_icache(void *start, void *end)
29739 set_fs(old_fs);
29740 }
29741
29742+struct bpf_jit_work {
29743+ struct work_struct work;
29744+ void *image;
29745+};
29746+
29747 #define CHOOSE_LOAD_FUNC(K, func) \
29748 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
29749
29750@@ -146,7 +248,7 @@ static int pkt_type_offset(void)
29751
29752 void bpf_jit_compile(struct sk_filter *fp)
29753 {
29754- u8 temp[64];
29755+ u8 temp[MAX_INSTR_CODE_SIZE];
29756 u8 *prog;
29757 unsigned int proglen, oldproglen = 0;
29758 int ilen, i;
29759@@ -159,6 +261,9 @@ void bpf_jit_compile(struct sk_filter *fp)
29760 unsigned int *addrs;
29761 const struct sock_filter *filter = fp->insns;
29762 int flen = fp->len;
29763+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29764+ unsigned int randkey;
29765+#endif
29766
29767 if (!bpf_jit_enable)
29768 return;
29769@@ -167,11 +272,19 @@ void bpf_jit_compile(struct sk_filter *fp)
29770 if (addrs == NULL)
29771 return;
29772
29773+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
29774+ if (!fp->work)
29775+ goto out;
29776+
29777+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29778+ randkey = get_random_int();
29779+#endif
29780+
29781 /* Before first pass, make a rough estimation of addrs[]
29782- * each bpf instruction is translated to less than 64 bytes
29783+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
29784 */
29785 for (proglen = 0, i = 0; i < flen; i++) {
29786- proglen += 64;
29787+ proglen += MAX_INSTR_CODE_SIZE;
29788 addrs[i] = proglen;
29789 }
29790 cleanup_addr = proglen; /* epilogue address */
29791@@ -282,10 +395,8 @@ void bpf_jit_compile(struct sk_filter *fp)
29792 case BPF_S_ALU_MUL_K: /* A *= K */
29793 if (is_imm8(K))
29794 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
29795- else {
29796- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
29797- EMIT(K, 4);
29798- }
29799+ else
29800+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
29801 break;
29802 case BPF_S_ALU_DIV_X: /* A /= X; */
29803 seen |= SEEN_XREG;
29804@@ -325,13 +436,23 @@ void bpf_jit_compile(struct sk_filter *fp)
29805 break;
29806 case BPF_S_ALU_MOD_K: /* A %= K; */
29807 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
29808+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29809+ DILUTE_CONST_SEQUENCE(K, randkey);
29810+#else
29811 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
29812+#endif
29813 EMIT2(0xf7, 0xf1); /* div %ecx */
29814 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
29815 break;
29816 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
29817+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29818+ DILUTE_CONST_SEQUENCE(K, randkey);
29819+ // imul rax, rcx
29820+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
29821+#else
29822 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
29823 EMIT(K, 4);
29824+#endif
29825 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
29826 break;
29827 case BPF_S_ALU_AND_X:
29828@@ -602,8 +723,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
29829 if (is_imm8(K)) {
29830 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
29831 } else {
29832- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
29833- EMIT(K, 4);
29834+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
29835 }
29836 } else {
29837 EMIT2(0x89,0xde); /* mov %ebx,%esi */
29838@@ -686,17 +806,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29839 break;
29840 default:
29841 /* hmm, too complex filter, give up with jit compiler */
29842- goto out;
29843+ goto error;
29844 }
29845 ilen = prog - temp;
29846 if (image) {
29847 if (unlikely(proglen + ilen > oldproglen)) {
29848 pr_err("bpb_jit_compile fatal error\n");
29849- kfree(addrs);
29850- module_free(NULL, image);
29851- return;
29852+ module_free_exec(NULL, image);
29853+ goto error;
29854 }
29855+ pax_open_kernel();
29856 memcpy(image + proglen, temp, ilen);
29857+ pax_close_kernel();
29858 }
29859 proglen += ilen;
29860 addrs[i] = proglen;
29861@@ -717,11 +838,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29862 break;
29863 }
29864 if (proglen == oldproglen) {
29865- image = module_alloc(max_t(unsigned int,
29866- proglen,
29867- sizeof(struct work_struct)));
29868+ image = module_alloc_exec(proglen);
29869 if (!image)
29870- goto out;
29871+ goto error;
29872 }
29873 oldproglen = proglen;
29874 }
29875@@ -737,7 +856,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29876 bpf_flush_icache(image, image + proglen);
29877
29878 fp->bpf_func = (void *)image;
29879- }
29880+ } else
29881+error:
29882+ kfree(fp->work);
29883+
29884 out:
29885 kfree(addrs);
29886 return;
29887@@ -745,18 +867,20 @@ out:
29888
29889 static void jit_free_defer(struct work_struct *arg)
29890 {
29891- module_free(NULL, arg);
29892+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
29893+ kfree(arg);
29894 }
29895
29896 /* run from softirq, we must use a work_struct to call
29897- * module_free() from process context
29898+ * module_free_exec() from process context
29899 */
29900 void bpf_jit_free(struct sk_filter *fp)
29901 {
29902 if (fp->bpf_func != sk_run_filter) {
29903- struct work_struct *work = (struct work_struct *)fp->bpf_func;
29904+ struct work_struct *work = &fp->work->work;
29905
29906 INIT_WORK(work, jit_free_defer);
29907+ fp->work->image = fp->bpf_func;
29908 schedule_work(work);
29909 }
29910 }
29911diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
29912index d6aa6e8..266395a 100644
29913--- a/arch/x86/oprofile/backtrace.c
29914+++ b/arch/x86/oprofile/backtrace.c
29915@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
29916 struct stack_frame_ia32 *fp;
29917 unsigned long bytes;
29918
29919- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29920+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29921 if (bytes != sizeof(bufhead))
29922 return NULL;
29923
29924- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
29925+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
29926
29927 oprofile_add_trace(bufhead[0].return_address);
29928
29929@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
29930 struct stack_frame bufhead[2];
29931 unsigned long bytes;
29932
29933- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29934+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29935 if (bytes != sizeof(bufhead))
29936 return NULL;
29937
29938@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
29939 {
29940 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
29941
29942- if (!user_mode_vm(regs)) {
29943+ if (!user_mode(regs)) {
29944 unsigned long stack = kernel_stack_pointer(regs);
29945 if (depth)
29946 dump_trace(NULL, regs, (unsigned long *)stack, 0,
29947diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
29948index 48768df..ba9143c 100644
29949--- a/arch/x86/oprofile/nmi_int.c
29950+++ b/arch/x86/oprofile/nmi_int.c
29951@@ -23,6 +23,7 @@
29952 #include <asm/nmi.h>
29953 #include <asm/msr.h>
29954 #include <asm/apic.h>
29955+#include <asm/pgtable.h>
29956
29957 #include "op_counter.h"
29958 #include "op_x86_model.h"
29959@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
29960 if (ret)
29961 return ret;
29962
29963- if (!model->num_virt_counters)
29964- model->num_virt_counters = model->num_counters;
29965+ if (!model->num_virt_counters) {
29966+ pax_open_kernel();
29967+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
29968+ pax_close_kernel();
29969+ }
29970
29971 mux_init(ops);
29972
29973diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
29974index b2b9443..be58856 100644
29975--- a/arch/x86/oprofile/op_model_amd.c
29976+++ b/arch/x86/oprofile/op_model_amd.c
29977@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
29978 num_counters = AMD64_NUM_COUNTERS;
29979 }
29980
29981- op_amd_spec.num_counters = num_counters;
29982- op_amd_spec.num_controls = num_counters;
29983- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29984+ pax_open_kernel();
29985+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
29986+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
29987+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29988+ pax_close_kernel();
29989
29990 return 0;
29991 }
29992diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
29993index d90528e..0127e2b 100644
29994--- a/arch/x86/oprofile/op_model_ppro.c
29995+++ b/arch/x86/oprofile/op_model_ppro.c
29996@@ -19,6 +19,7 @@
29997 #include <asm/msr.h>
29998 #include <asm/apic.h>
29999 #include <asm/nmi.h>
30000+#include <asm/pgtable.h>
30001
30002 #include "op_x86_model.h"
30003 #include "op_counter.h"
30004@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
30005
30006 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
30007
30008- op_arch_perfmon_spec.num_counters = num_counters;
30009- op_arch_perfmon_spec.num_controls = num_counters;
30010+ pax_open_kernel();
30011+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
30012+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
30013+ pax_close_kernel();
30014 }
30015
30016 static int arch_perfmon_init(struct oprofile_operations *ignore)
30017diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
30018index 71e8a67..6a313bb 100644
30019--- a/arch/x86/oprofile/op_x86_model.h
30020+++ b/arch/x86/oprofile/op_x86_model.h
30021@@ -52,7 +52,7 @@ struct op_x86_model_spec {
30022 void (*switch_ctrl)(struct op_x86_model_spec const *model,
30023 struct op_msrs const * const msrs);
30024 #endif
30025-};
30026+} __do_const;
30027
30028 struct op_counter_config;
30029
30030diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
30031index e9e6ed5..e47ae67 100644
30032--- a/arch/x86/pci/amd_bus.c
30033+++ b/arch/x86/pci/amd_bus.c
30034@@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
30035 return NOTIFY_OK;
30036 }
30037
30038-static struct notifier_block __cpuinitdata amd_cpu_notifier = {
30039+static struct notifier_block amd_cpu_notifier = {
30040 .notifier_call = amd_cpu_notify,
30041 };
30042
30043diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
30044index 372e9b8..e775a6c 100644
30045--- a/arch/x86/pci/irq.c
30046+++ b/arch/x86/pci/irq.c
30047@@ -50,7 +50,7 @@ struct irq_router {
30048 struct irq_router_handler {
30049 u16 vendor;
30050 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
30051-};
30052+} __do_const;
30053
30054 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
30055 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
30056@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
30057 return 0;
30058 }
30059
30060-static __initdata struct irq_router_handler pirq_routers[] = {
30061+static __initconst const struct irq_router_handler pirq_routers[] = {
30062 { PCI_VENDOR_ID_INTEL, intel_router_probe },
30063 { PCI_VENDOR_ID_AL, ali_router_probe },
30064 { PCI_VENDOR_ID_ITE, ite_router_probe },
30065@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
30066 static void __init pirq_find_router(struct irq_router *r)
30067 {
30068 struct irq_routing_table *rt = pirq_table;
30069- struct irq_router_handler *h;
30070+ const struct irq_router_handler *h;
30071
30072 #ifdef CONFIG_PCI_BIOS
30073 if (!rt->signature) {
30074@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
30075 return 0;
30076 }
30077
30078-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
30079+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
30080 {
30081 .callback = fix_broken_hp_bios_irq9,
30082 .ident = "HP Pavilion N5400 Series Laptop",
30083diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
30084index 6eb18c4..20d83de 100644
30085--- a/arch/x86/pci/mrst.c
30086+++ b/arch/x86/pci/mrst.c
30087@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
30088 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
30089 pci_mmcfg_late_init();
30090 pcibios_enable_irq = mrst_pci_irq_enable;
30091- pci_root_ops = pci_mrst_ops;
30092+ pax_open_kernel();
30093+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
30094+ pax_close_kernel();
30095 pci_soc_mode = 1;
30096 /* Continue with standard init */
30097 return 1;
30098diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
30099index c77b24a..c979855 100644
30100--- a/arch/x86/pci/pcbios.c
30101+++ b/arch/x86/pci/pcbios.c
30102@@ -79,7 +79,7 @@ union bios32 {
30103 static struct {
30104 unsigned long address;
30105 unsigned short segment;
30106-} bios32_indirect = { 0, __KERNEL_CS };
30107+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
30108
30109 /*
30110 * Returns the entry point for the given service, NULL on error
30111@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
30112 unsigned long length; /* %ecx */
30113 unsigned long entry; /* %edx */
30114 unsigned long flags;
30115+ struct desc_struct d, *gdt;
30116
30117 local_irq_save(flags);
30118- __asm__("lcall *(%%edi); cld"
30119+
30120+ gdt = get_cpu_gdt_table(smp_processor_id());
30121+
30122+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
30123+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30124+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
30125+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30126+
30127+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
30128 : "=a" (return_code),
30129 "=b" (address),
30130 "=c" (length),
30131 "=d" (entry)
30132 : "0" (service),
30133 "1" (0),
30134- "D" (&bios32_indirect));
30135+ "D" (&bios32_indirect),
30136+ "r"(__PCIBIOS_DS)
30137+ : "memory");
30138+
30139+ pax_open_kernel();
30140+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
30141+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
30142+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
30143+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
30144+ pax_close_kernel();
30145+
30146 local_irq_restore(flags);
30147
30148 switch (return_code) {
30149- case 0:
30150- return address + entry;
30151- case 0x80: /* Not present */
30152- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30153- return 0;
30154- default: /* Shouldn't happen */
30155- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30156- service, return_code);
30157+ case 0: {
30158+ int cpu;
30159+ unsigned char flags;
30160+
30161+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
30162+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
30163+ printk(KERN_WARNING "bios32_service: not valid\n");
30164 return 0;
30165+ }
30166+ address = address + PAGE_OFFSET;
30167+ length += 16UL; /* some BIOSs underreport this... */
30168+ flags = 4;
30169+ if (length >= 64*1024*1024) {
30170+ length >>= PAGE_SHIFT;
30171+ flags |= 8;
30172+ }
30173+
30174+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30175+ gdt = get_cpu_gdt_table(cpu);
30176+ pack_descriptor(&d, address, length, 0x9b, flags);
30177+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30178+ pack_descriptor(&d, address, length, 0x93, flags);
30179+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30180+ }
30181+ return entry;
30182+ }
30183+ case 0x80: /* Not present */
30184+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30185+ return 0;
30186+ default: /* Shouldn't happen */
30187+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30188+ service, return_code);
30189+ return 0;
30190 }
30191 }
30192
30193 static struct {
30194 unsigned long address;
30195 unsigned short segment;
30196-} pci_indirect = { 0, __KERNEL_CS };
30197+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
30198
30199-static int pci_bios_present;
30200+static int pci_bios_present __read_only;
30201
30202 static int check_pcibios(void)
30203 {
30204@@ -131,11 +174,13 @@ static int check_pcibios(void)
30205 unsigned long flags, pcibios_entry;
30206
30207 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
30208- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
30209+ pci_indirect.address = pcibios_entry;
30210
30211 local_irq_save(flags);
30212- __asm__(
30213- "lcall *(%%edi); cld\n\t"
30214+ __asm__("movw %w6, %%ds\n\t"
30215+ "lcall *%%ss:(%%edi); cld\n\t"
30216+ "push %%ss\n\t"
30217+ "pop %%ds\n\t"
30218 "jc 1f\n\t"
30219 "xor %%ah, %%ah\n"
30220 "1:"
30221@@ -144,7 +189,8 @@ static int check_pcibios(void)
30222 "=b" (ebx),
30223 "=c" (ecx)
30224 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
30225- "D" (&pci_indirect)
30226+ "D" (&pci_indirect),
30227+ "r" (__PCIBIOS_DS)
30228 : "memory");
30229 local_irq_restore(flags);
30230
30231@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30232
30233 switch (len) {
30234 case 1:
30235- __asm__("lcall *(%%esi); cld\n\t"
30236+ __asm__("movw %w6, %%ds\n\t"
30237+ "lcall *%%ss:(%%esi); cld\n\t"
30238+ "push %%ss\n\t"
30239+ "pop %%ds\n\t"
30240 "jc 1f\n\t"
30241 "xor %%ah, %%ah\n"
30242 "1:"
30243@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30244 : "1" (PCIBIOS_READ_CONFIG_BYTE),
30245 "b" (bx),
30246 "D" ((long)reg),
30247- "S" (&pci_indirect));
30248+ "S" (&pci_indirect),
30249+ "r" (__PCIBIOS_DS));
30250 /*
30251 * Zero-extend the result beyond 8 bits, do not trust the
30252 * BIOS having done it:
30253@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30254 *value &= 0xff;
30255 break;
30256 case 2:
30257- __asm__("lcall *(%%esi); cld\n\t"
30258+ __asm__("movw %w6, %%ds\n\t"
30259+ "lcall *%%ss:(%%esi); cld\n\t"
30260+ "push %%ss\n\t"
30261+ "pop %%ds\n\t"
30262 "jc 1f\n\t"
30263 "xor %%ah, %%ah\n"
30264 "1:"
30265@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30266 : "1" (PCIBIOS_READ_CONFIG_WORD),
30267 "b" (bx),
30268 "D" ((long)reg),
30269- "S" (&pci_indirect));
30270+ "S" (&pci_indirect),
30271+ "r" (__PCIBIOS_DS));
30272 /*
30273 * Zero-extend the result beyond 16 bits, do not trust the
30274 * BIOS having done it:
30275@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30276 *value &= 0xffff;
30277 break;
30278 case 4:
30279- __asm__("lcall *(%%esi); cld\n\t"
30280+ __asm__("movw %w6, %%ds\n\t"
30281+ "lcall *%%ss:(%%esi); cld\n\t"
30282+ "push %%ss\n\t"
30283+ "pop %%ds\n\t"
30284 "jc 1f\n\t"
30285 "xor %%ah, %%ah\n"
30286 "1:"
30287@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30288 : "1" (PCIBIOS_READ_CONFIG_DWORD),
30289 "b" (bx),
30290 "D" ((long)reg),
30291- "S" (&pci_indirect));
30292+ "S" (&pci_indirect),
30293+ "r" (__PCIBIOS_DS));
30294 break;
30295 }
30296
30297@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30298
30299 switch (len) {
30300 case 1:
30301- __asm__("lcall *(%%esi); cld\n\t"
30302+ __asm__("movw %w6, %%ds\n\t"
30303+ "lcall *%%ss:(%%esi); cld\n\t"
30304+ "push %%ss\n\t"
30305+ "pop %%ds\n\t"
30306 "jc 1f\n\t"
30307 "xor %%ah, %%ah\n"
30308 "1:"
30309@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30310 "c" (value),
30311 "b" (bx),
30312 "D" ((long)reg),
30313- "S" (&pci_indirect));
30314+ "S" (&pci_indirect),
30315+ "r" (__PCIBIOS_DS));
30316 break;
30317 case 2:
30318- __asm__("lcall *(%%esi); cld\n\t"
30319+ __asm__("movw %w6, %%ds\n\t"
30320+ "lcall *%%ss:(%%esi); cld\n\t"
30321+ "push %%ss\n\t"
30322+ "pop %%ds\n\t"
30323 "jc 1f\n\t"
30324 "xor %%ah, %%ah\n"
30325 "1:"
30326@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30327 "c" (value),
30328 "b" (bx),
30329 "D" ((long)reg),
30330- "S" (&pci_indirect));
30331+ "S" (&pci_indirect),
30332+ "r" (__PCIBIOS_DS));
30333 break;
30334 case 4:
30335- __asm__("lcall *(%%esi); cld\n\t"
30336+ __asm__("movw %w6, %%ds\n\t"
30337+ "lcall *%%ss:(%%esi); cld\n\t"
30338+ "push %%ss\n\t"
30339+ "pop %%ds\n\t"
30340 "jc 1f\n\t"
30341 "xor %%ah, %%ah\n"
30342 "1:"
30343@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30344 "c" (value),
30345 "b" (bx),
30346 "D" ((long)reg),
30347- "S" (&pci_indirect));
30348+ "S" (&pci_indirect),
30349+ "r" (__PCIBIOS_DS));
30350 break;
30351 }
30352
30353@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30354
30355 DBG("PCI: Fetching IRQ routing table... ");
30356 __asm__("push %%es\n\t"
30357+ "movw %w8, %%ds\n\t"
30358 "push %%ds\n\t"
30359 "pop %%es\n\t"
30360- "lcall *(%%esi); cld\n\t"
30361+ "lcall *%%ss:(%%esi); cld\n\t"
30362 "pop %%es\n\t"
30363+ "push %%ss\n\t"
30364+ "pop %%ds\n"
30365 "jc 1f\n\t"
30366 "xor %%ah, %%ah\n"
30367 "1:"
30368@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30369 "1" (0),
30370 "D" ((long) &opt),
30371 "S" (&pci_indirect),
30372- "m" (opt)
30373+ "m" (opt),
30374+ "r" (__PCIBIOS_DS)
30375 : "memory");
30376 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
30377 if (ret & 0xff00)
30378@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30379 {
30380 int ret;
30381
30382- __asm__("lcall *(%%esi); cld\n\t"
30383+ __asm__("movw %w5, %%ds\n\t"
30384+ "lcall *%%ss:(%%esi); cld\n\t"
30385+ "push %%ss\n\t"
30386+ "pop %%ds\n"
30387 "jc 1f\n\t"
30388 "xor %%ah, %%ah\n"
30389 "1:"
30390@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30391 : "0" (PCIBIOS_SET_PCI_HW_INT),
30392 "b" ((dev->bus->number << 8) | dev->devfn),
30393 "c" ((irq << 8) | (pin + 10)),
30394- "S" (&pci_indirect));
30395+ "S" (&pci_indirect),
30396+ "r" (__PCIBIOS_DS));
30397 return !(ret & 0xff00);
30398 }
30399 EXPORT_SYMBOL(pcibios_set_irq_routing);
30400diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
30401index 40e4469..1ab536e 100644
30402--- a/arch/x86/platform/efi/efi_32.c
30403+++ b/arch/x86/platform/efi/efi_32.c
30404@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
30405 {
30406 struct desc_ptr gdt_descr;
30407
30408+#ifdef CONFIG_PAX_KERNEXEC
30409+ struct desc_struct d;
30410+#endif
30411+
30412 local_irq_save(efi_rt_eflags);
30413
30414 load_cr3(initial_page_table);
30415 __flush_tlb_all();
30416
30417+#ifdef CONFIG_PAX_KERNEXEC
30418+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
30419+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30420+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
30421+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30422+#endif
30423+
30424 gdt_descr.address = __pa(get_cpu_gdt_table(0));
30425 gdt_descr.size = GDT_SIZE - 1;
30426 load_gdt(&gdt_descr);
30427@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
30428 {
30429 struct desc_ptr gdt_descr;
30430
30431+#ifdef CONFIG_PAX_KERNEXEC
30432+ struct desc_struct d;
30433+
30434+ memset(&d, 0, sizeof d);
30435+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30436+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30437+#endif
30438+
30439 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
30440 gdt_descr.size = GDT_SIZE - 1;
30441 load_gdt(&gdt_descr);
30442diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
30443index fbe66e6..eae5e38 100644
30444--- a/arch/x86/platform/efi/efi_stub_32.S
30445+++ b/arch/x86/platform/efi/efi_stub_32.S
30446@@ -6,7 +6,9 @@
30447 */
30448
30449 #include <linux/linkage.h>
30450+#include <linux/init.h>
30451 #include <asm/page_types.h>
30452+#include <asm/segment.h>
30453
30454 /*
30455 * efi_call_phys(void *, ...) is a function with variable parameters.
30456@@ -20,7 +22,7 @@
30457 * service functions will comply with gcc calling convention, too.
30458 */
30459
30460-.text
30461+__INIT
30462 ENTRY(efi_call_phys)
30463 /*
30464 * 0. The function can only be called in Linux kernel. So CS has been
30465@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
30466 * The mapping of lower virtual memory has been created in prelog and
30467 * epilog.
30468 */
30469- movl $1f, %edx
30470- subl $__PAGE_OFFSET, %edx
30471- jmp *%edx
30472+#ifdef CONFIG_PAX_KERNEXEC
30473+ movl $(__KERNEXEC_EFI_DS), %edx
30474+ mov %edx, %ds
30475+ mov %edx, %es
30476+ mov %edx, %ss
30477+ addl $2f,(1f)
30478+ ljmp *(1f)
30479+
30480+__INITDATA
30481+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
30482+.previous
30483+
30484+2:
30485+ subl $2b,(1b)
30486+#else
30487+ jmp 1f-__PAGE_OFFSET
30488 1:
30489+#endif
30490
30491 /*
30492 * 2. Now on the top of stack is the return
30493@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
30494 * parameter 2, ..., param n. To make things easy, we save the return
30495 * address of efi_call_phys in a global variable.
30496 */
30497- popl %edx
30498- movl %edx, saved_return_addr
30499- /* get the function pointer into ECX*/
30500- popl %ecx
30501- movl %ecx, efi_rt_function_ptr
30502- movl $2f, %edx
30503- subl $__PAGE_OFFSET, %edx
30504- pushl %edx
30505+ popl (saved_return_addr)
30506+ popl (efi_rt_function_ptr)
30507
30508 /*
30509 * 3. Clear PG bit in %CR0.
30510@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
30511 /*
30512 * 5. Call the physical function.
30513 */
30514- jmp *%ecx
30515+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
30516
30517-2:
30518 /*
30519 * 6. After EFI runtime service returns, control will return to
30520 * following instruction. We'd better readjust stack pointer first.
30521@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
30522 movl %cr0, %edx
30523 orl $0x80000000, %edx
30524 movl %edx, %cr0
30525- jmp 1f
30526-1:
30527+
30528 /*
30529 * 8. Now restore the virtual mode from flat mode by
30530 * adding EIP with PAGE_OFFSET.
30531 */
30532- movl $1f, %edx
30533- jmp *%edx
30534+#ifdef CONFIG_PAX_KERNEXEC
30535+ movl $(__KERNEL_DS), %edx
30536+ mov %edx, %ds
30537+ mov %edx, %es
30538+ mov %edx, %ss
30539+ ljmp $(__KERNEL_CS),$1f
30540+#else
30541+ jmp 1f+__PAGE_OFFSET
30542+#endif
30543 1:
30544
30545 /*
30546 * 9. Balance the stack. And because EAX contain the return value,
30547 * we'd better not clobber it.
30548 */
30549- leal efi_rt_function_ptr, %edx
30550- movl (%edx), %ecx
30551- pushl %ecx
30552+ pushl (efi_rt_function_ptr)
30553
30554 /*
30555- * 10. Push the saved return address onto the stack and return.
30556+ * 10. Return to the saved return address.
30557 */
30558- leal saved_return_addr, %edx
30559- movl (%edx), %ecx
30560- pushl %ecx
30561- ret
30562+ jmpl *(saved_return_addr)
30563 ENDPROC(efi_call_phys)
30564 .previous
30565
30566-.data
30567+__INITDATA
30568 saved_return_addr:
30569 .long 0
30570 efi_rt_function_ptr:
30571diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
30572index 4c07cca..2c8427d 100644
30573--- a/arch/x86/platform/efi/efi_stub_64.S
30574+++ b/arch/x86/platform/efi/efi_stub_64.S
30575@@ -7,6 +7,7 @@
30576 */
30577
30578 #include <linux/linkage.h>
30579+#include <asm/alternative-asm.h>
30580
30581 #define SAVE_XMM \
30582 mov %rsp, %rax; \
30583@@ -40,6 +41,7 @@ ENTRY(efi_call0)
30584 call *%rdi
30585 addq $32, %rsp
30586 RESTORE_XMM
30587+ pax_force_retaddr 0, 1
30588 ret
30589 ENDPROC(efi_call0)
30590
30591@@ -50,6 +52,7 @@ ENTRY(efi_call1)
30592 call *%rdi
30593 addq $32, %rsp
30594 RESTORE_XMM
30595+ pax_force_retaddr 0, 1
30596 ret
30597 ENDPROC(efi_call1)
30598
30599@@ -60,6 +63,7 @@ ENTRY(efi_call2)
30600 call *%rdi
30601 addq $32, %rsp
30602 RESTORE_XMM
30603+ pax_force_retaddr 0, 1
30604 ret
30605 ENDPROC(efi_call2)
30606
30607@@ -71,6 +75,7 @@ ENTRY(efi_call3)
30608 call *%rdi
30609 addq $32, %rsp
30610 RESTORE_XMM
30611+ pax_force_retaddr 0, 1
30612 ret
30613 ENDPROC(efi_call3)
30614
30615@@ -83,6 +88,7 @@ ENTRY(efi_call4)
30616 call *%rdi
30617 addq $32, %rsp
30618 RESTORE_XMM
30619+ pax_force_retaddr 0, 1
30620 ret
30621 ENDPROC(efi_call4)
30622
30623@@ -96,6 +102,7 @@ ENTRY(efi_call5)
30624 call *%rdi
30625 addq $48, %rsp
30626 RESTORE_XMM
30627+ pax_force_retaddr 0, 1
30628 ret
30629 ENDPROC(efi_call5)
30630
30631@@ -112,5 +119,6 @@ ENTRY(efi_call6)
30632 call *%rdi
30633 addq $48, %rsp
30634 RESTORE_XMM
30635+ pax_force_retaddr 0, 1
30636 ret
30637 ENDPROC(efi_call6)
30638diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
30639index e31bcd8..f12dc46 100644
30640--- a/arch/x86/platform/mrst/mrst.c
30641+++ b/arch/x86/platform/mrst/mrst.c
30642@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
30643 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
30644 int sfi_mrtc_num;
30645
30646-static void mrst_power_off(void)
30647+static __noreturn void mrst_power_off(void)
30648 {
30649+ BUG();
30650 }
30651
30652-static void mrst_reboot(void)
30653+static __noreturn void mrst_reboot(void)
30654 {
30655 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
30656+ BUG();
30657 }
30658
30659 /* parse all the mtimer info to a static mtimer array */
30660diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
30661index d6ee929..3637cb5 100644
30662--- a/arch/x86/platform/olpc/olpc_dt.c
30663+++ b/arch/x86/platform/olpc/olpc_dt.c
30664@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
30665 return res;
30666 }
30667
30668-static struct of_pdt_ops prom_olpc_ops __initdata = {
30669+static struct of_pdt_ops prom_olpc_ops __initconst = {
30670 .nextprop = olpc_dt_nextprop,
30671 .getproplen = olpc_dt_getproplen,
30672 .getproperty = olpc_dt_getproperty,
30673diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
30674index 3c68768..07e82b8 100644
30675--- a/arch/x86/power/cpu.c
30676+++ b/arch/x86/power/cpu.c
30677@@ -134,7 +134,7 @@ static void do_fpu_end(void)
30678 static void fix_processor_context(void)
30679 {
30680 int cpu = smp_processor_id();
30681- struct tss_struct *t = &per_cpu(init_tss, cpu);
30682+ struct tss_struct *t = init_tss + cpu;
30683
30684 set_tss_desc(cpu, t); /*
30685 * This just modifies memory; should not be
30686@@ -144,8 +144,6 @@ static void fix_processor_context(void)
30687 */
30688
30689 #ifdef CONFIG_X86_64
30690- get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
30691-
30692 syscall_init(); /* This sets MSR_*STAR and related */
30693 #endif
30694 load_TR_desc(); /* This does ltr */
30695diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
30696index a44f457..9140171 100644
30697--- a/arch/x86/realmode/init.c
30698+++ b/arch/x86/realmode/init.c
30699@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
30700 __va(real_mode_header->trampoline_header);
30701
30702 #ifdef CONFIG_X86_32
30703- trampoline_header->start = __pa_symbol(startup_32_smp);
30704+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
30705+
30706+#ifdef CONFIG_PAX_KERNEXEC
30707+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
30708+#endif
30709+
30710+ trampoline_header->boot_cs = __BOOT_CS;
30711 trampoline_header->gdt_limit = __BOOT_DS + 7;
30712 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
30713 #else
30714@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
30715 *trampoline_cr4_features = read_cr4();
30716
30717 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
30718- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
30719+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
30720 trampoline_pgd[511] = init_level4_pgt[511].pgd;
30721 #endif
30722 }
30723diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
30724index 8869287..d577672 100644
30725--- a/arch/x86/realmode/rm/Makefile
30726+++ b/arch/x86/realmode/rm/Makefile
30727@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
30728 $(call cc-option, -fno-unit-at-a-time)) \
30729 $(call cc-option, -fno-stack-protector) \
30730 $(call cc-option, -mpreferred-stack-boundary=2)
30731+ifdef CONSTIFY_PLUGIN
30732+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
30733+endif
30734 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
30735 GCOV_PROFILE := n
30736diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
30737index a28221d..93c40f1 100644
30738--- a/arch/x86/realmode/rm/header.S
30739+++ b/arch/x86/realmode/rm/header.S
30740@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
30741 #endif
30742 /* APM/BIOS reboot */
30743 .long pa_machine_real_restart_asm
30744-#ifdef CONFIG_X86_64
30745+#ifdef CONFIG_X86_32
30746+ .long __KERNEL_CS
30747+#else
30748 .long __KERNEL32_CS
30749 #endif
30750 END(real_mode_header)
30751diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
30752index c1b2791..f9e31c7 100644
30753--- a/arch/x86/realmode/rm/trampoline_32.S
30754+++ b/arch/x86/realmode/rm/trampoline_32.S
30755@@ -25,6 +25,12 @@
30756 #include <asm/page_types.h>
30757 #include "realmode.h"
30758
30759+#ifdef CONFIG_PAX_KERNEXEC
30760+#define ta(X) (X)
30761+#else
30762+#define ta(X) (pa_ ## X)
30763+#endif
30764+
30765 .text
30766 .code16
30767
30768@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
30769
30770 cli # We should be safe anyway
30771
30772- movl tr_start, %eax # where we need to go
30773-
30774 movl $0xA5A5A5A5, trampoline_status
30775 # write marker for master knows we're running
30776
30777@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
30778 movw $1, %dx # protected mode (PE) bit
30779 lmsw %dx # into protected mode
30780
30781- ljmpl $__BOOT_CS, $pa_startup_32
30782+ ljmpl *(trampoline_header)
30783
30784 .section ".text32","ax"
30785 .code32
30786@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
30787 .balign 8
30788 GLOBAL(trampoline_header)
30789 tr_start: .space 4
30790- tr_gdt_pad: .space 2
30791+ tr_boot_cs: .space 2
30792 tr_gdt: .space 6
30793 END(trampoline_header)
30794
30795diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
30796index bb360dc..3e5945f 100644
30797--- a/arch/x86/realmode/rm/trampoline_64.S
30798+++ b/arch/x86/realmode/rm/trampoline_64.S
30799@@ -107,7 +107,7 @@ ENTRY(startup_32)
30800 wrmsr
30801
30802 # Enable paging and in turn activate Long Mode
30803- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
30804+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
30805 movl %eax, %cr0
30806
30807 /*
30808diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
30809index 79d67bd..c7e1b90 100644
30810--- a/arch/x86/tools/relocs.c
30811+++ b/arch/x86/tools/relocs.c
30812@@ -12,10 +12,13 @@
30813 #include <regex.h>
30814 #include <tools/le_byteshift.h>
30815
30816+#include "../../../include/generated/autoconf.h"
30817+
30818 static void die(char *fmt, ...);
30819
30820 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
30821 static Elf32_Ehdr ehdr;
30822+static Elf32_Phdr *phdr;
30823 static unsigned long reloc_count, reloc_idx;
30824 static unsigned long *relocs;
30825 static unsigned long reloc16_count, reloc16_idx;
30826@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
30827 }
30828 }
30829
30830+static void read_phdrs(FILE *fp)
30831+{
30832+ unsigned int i;
30833+
30834+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
30835+ if (!phdr) {
30836+ die("Unable to allocate %d program headers\n",
30837+ ehdr.e_phnum);
30838+ }
30839+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
30840+ die("Seek to %d failed: %s\n",
30841+ ehdr.e_phoff, strerror(errno));
30842+ }
30843+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
30844+ die("Cannot read ELF program headers: %s\n",
30845+ strerror(errno));
30846+ }
30847+ for(i = 0; i < ehdr.e_phnum; i++) {
30848+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
30849+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
30850+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
30851+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
30852+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
30853+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
30854+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
30855+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
30856+ }
30857+
30858+}
30859+
30860 static void read_shdrs(FILE *fp)
30861 {
30862- int i;
30863+ unsigned int i;
30864 Elf32_Shdr shdr;
30865
30866 secs = calloc(ehdr.e_shnum, sizeof(struct section));
30867@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
30868
30869 static void read_strtabs(FILE *fp)
30870 {
30871- int i;
30872+ unsigned int i;
30873 for (i = 0; i < ehdr.e_shnum; i++) {
30874 struct section *sec = &secs[i];
30875 if (sec->shdr.sh_type != SHT_STRTAB) {
30876@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
30877
30878 static void read_symtabs(FILE *fp)
30879 {
30880- int i,j;
30881+ unsigned int i,j;
30882 for (i = 0; i < ehdr.e_shnum; i++) {
30883 struct section *sec = &secs[i];
30884 if (sec->shdr.sh_type != SHT_SYMTAB) {
30885@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
30886 }
30887
30888
30889-static void read_relocs(FILE *fp)
30890+static void read_relocs(FILE *fp, int use_real_mode)
30891 {
30892- int i,j;
30893+ unsigned int i,j;
30894+ uint32_t base;
30895+
30896 for (i = 0; i < ehdr.e_shnum; i++) {
30897 struct section *sec = &secs[i];
30898 if (sec->shdr.sh_type != SHT_REL) {
30899@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
30900 die("Cannot read symbol table: %s\n",
30901 strerror(errno));
30902 }
30903+ base = 0;
30904+
30905+#ifdef CONFIG_X86_32
30906+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
30907+ if (phdr[j].p_type != PT_LOAD )
30908+ continue;
30909+ 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)
30910+ continue;
30911+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
30912+ break;
30913+ }
30914+#endif
30915+
30916 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
30917 Elf32_Rel *rel = &sec->reltab[j];
30918- rel->r_offset = elf32_to_cpu(rel->r_offset);
30919+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
30920 rel->r_info = elf32_to_cpu(rel->r_info);
30921 }
30922 }
30923@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
30924
30925 static void print_absolute_symbols(void)
30926 {
30927- int i;
30928+ unsigned int i;
30929 printf("Absolute symbols\n");
30930 printf(" Num: Value Size Type Bind Visibility Name\n");
30931 for (i = 0; i < ehdr.e_shnum; i++) {
30932 struct section *sec = &secs[i];
30933 char *sym_strtab;
30934- int j;
30935+ unsigned int j;
30936
30937 if (sec->shdr.sh_type != SHT_SYMTAB) {
30938 continue;
30939@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
30940
30941 static void print_absolute_relocs(void)
30942 {
30943- int i, printed = 0;
30944+ unsigned int i, printed = 0;
30945
30946 for (i = 0; i < ehdr.e_shnum; i++) {
30947 struct section *sec = &secs[i];
30948 struct section *sec_applies, *sec_symtab;
30949 char *sym_strtab;
30950 Elf32_Sym *sh_symtab;
30951- int j;
30952+ unsigned int j;
30953 if (sec->shdr.sh_type != SHT_REL) {
30954 continue;
30955 }
30956@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
30957 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
30958 int use_real_mode)
30959 {
30960- int i;
30961+ unsigned int i;
30962 /* Walk through the relocations */
30963 for (i = 0; i < ehdr.e_shnum; i++) {
30964 char *sym_strtab;
30965 Elf32_Sym *sh_symtab;
30966 struct section *sec_applies, *sec_symtab;
30967- int j;
30968+ unsigned int j;
30969 struct section *sec = &secs[i];
30970
30971 if (sec->shdr.sh_type != SHT_REL) {
30972@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
30973 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
30974 r_type = ELF32_R_TYPE(rel->r_info);
30975
30976+ if (!use_real_mode) {
30977+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
30978+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
30979+ continue;
30980+
30981+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
30982+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
30983+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
30984+ continue;
30985+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
30986+ continue;
30987+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
30988+ continue;
30989+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
30990+ continue;
30991+#endif
30992+ }
30993+
30994 shn_abs = sym->st_shndx == SHN_ABS;
30995
30996 switch (r_type) {
30997@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
30998
30999 static void emit_relocs(int as_text, int use_real_mode)
31000 {
31001- int i;
31002+ unsigned int i;
31003 /* Count how many relocations I have and allocate space for them. */
31004 reloc_count = 0;
31005 walk_relocs(count_reloc, use_real_mode);
31006@@ -808,10 +874,11 @@ int main(int argc, char **argv)
31007 fname, strerror(errno));
31008 }
31009 read_ehdr(fp);
31010+ read_phdrs(fp);
31011 read_shdrs(fp);
31012 read_strtabs(fp);
31013 read_symtabs(fp);
31014- read_relocs(fp);
31015+ read_relocs(fp, use_real_mode);
31016 if (show_absolute_syms) {
31017 print_absolute_symbols();
31018 goto out;
31019diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
31020index fd14be1..e3c79c0 100644
31021--- a/arch/x86/vdso/Makefile
31022+++ b/arch/x86/vdso/Makefile
31023@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
31024 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
31025 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
31026
31027-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
31028+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
31029 GCOV_PROFILE := n
31030
31031 #
31032diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
31033index 0faad64..39ef157 100644
31034--- a/arch/x86/vdso/vdso32-setup.c
31035+++ b/arch/x86/vdso/vdso32-setup.c
31036@@ -25,6 +25,7 @@
31037 #include <asm/tlbflush.h>
31038 #include <asm/vdso.h>
31039 #include <asm/proto.h>
31040+#include <asm/mman.h>
31041
31042 enum {
31043 VDSO_DISABLED = 0,
31044@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
31045 void enable_sep_cpu(void)
31046 {
31047 int cpu = get_cpu();
31048- struct tss_struct *tss = &per_cpu(init_tss, cpu);
31049+ struct tss_struct *tss = init_tss + cpu;
31050
31051 if (!boot_cpu_has(X86_FEATURE_SEP)) {
31052 put_cpu();
31053@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
31054 gate_vma.vm_start = FIXADDR_USER_START;
31055 gate_vma.vm_end = FIXADDR_USER_END;
31056 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
31057- gate_vma.vm_page_prot = __P101;
31058+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
31059
31060 return 0;
31061 }
31062@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31063 if (compat)
31064 addr = VDSO_HIGH_BASE;
31065 else {
31066- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
31067+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
31068 if (IS_ERR_VALUE(addr)) {
31069 ret = addr;
31070 goto up_fail;
31071 }
31072 }
31073
31074- current->mm->context.vdso = (void *)addr;
31075+ current->mm->context.vdso = addr;
31076
31077 if (compat_uses_vma || !compat) {
31078 /*
31079@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31080 }
31081
31082 current_thread_info()->sysenter_return =
31083- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
31084+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
31085
31086 up_fail:
31087 if (ret)
31088- current->mm->context.vdso = NULL;
31089+ current->mm->context.vdso = 0;
31090
31091 up_write(&mm->mmap_sem);
31092
31093@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
31094
31095 const char *arch_vma_name(struct vm_area_struct *vma)
31096 {
31097- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31098+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31099 return "[vdso]";
31100+
31101+#ifdef CONFIG_PAX_SEGMEXEC
31102+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
31103+ return "[vdso]";
31104+#endif
31105+
31106 return NULL;
31107 }
31108
31109@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31110 * Check to see if the corresponding task was created in compat vdso
31111 * mode.
31112 */
31113- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
31114+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
31115 return &gate_vma;
31116 return NULL;
31117 }
31118diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
31119index 431e875..cbb23f3 100644
31120--- a/arch/x86/vdso/vma.c
31121+++ b/arch/x86/vdso/vma.c
31122@@ -16,8 +16,6 @@
31123 #include <asm/vdso.h>
31124 #include <asm/page.h>
31125
31126-unsigned int __read_mostly vdso_enabled = 1;
31127-
31128 extern char vdso_start[], vdso_end[];
31129 extern unsigned short vdso_sync_cpuid;
31130
31131@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
31132 * unaligned here as a result of stack start randomization.
31133 */
31134 addr = PAGE_ALIGN(addr);
31135- addr = align_vdso_addr(addr);
31136
31137 return addr;
31138 }
31139@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
31140 unsigned size)
31141 {
31142 struct mm_struct *mm = current->mm;
31143- unsigned long addr;
31144+ unsigned long addr = 0;
31145 int ret;
31146
31147- if (!vdso_enabled)
31148- return 0;
31149-
31150 down_write(&mm->mmap_sem);
31151+
31152+#ifdef CONFIG_PAX_RANDMMAP
31153+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
31154+#endif
31155+
31156 addr = vdso_addr(mm->start_stack, size);
31157+ addr = align_vdso_addr(addr);
31158 addr = get_unmapped_area(NULL, addr, size, 0, 0);
31159 if (IS_ERR_VALUE(addr)) {
31160 ret = addr;
31161 goto up_fail;
31162 }
31163
31164- current->mm->context.vdso = (void *)addr;
31165+ mm->context.vdso = addr;
31166
31167 ret = install_special_mapping(mm, addr, size,
31168 VM_READ|VM_EXEC|
31169 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
31170 pages);
31171- if (ret) {
31172- current->mm->context.vdso = NULL;
31173- goto up_fail;
31174- }
31175+ if (ret)
31176+ mm->context.vdso = 0;
31177
31178 up_fail:
31179 up_write(&mm->mmap_sem);
31180@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31181 vdsox32_size);
31182 }
31183 #endif
31184-
31185-static __init int vdso_setup(char *s)
31186-{
31187- vdso_enabled = simple_strtoul(s, NULL, 0);
31188- return 0;
31189-}
31190-__setup("vdso=", vdso_setup);
31191diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
31192index cf95e19..17e9f50 100644
31193--- a/arch/x86/xen/enlighten.c
31194+++ b/arch/x86/xen/enlighten.c
31195@@ -100,8 +100,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
31196
31197 struct shared_info xen_dummy_shared_info;
31198
31199-void *xen_initial_gdt;
31200-
31201 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
31202 __read_mostly int xen_have_vector_callback;
31203 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
31204@@ -511,8 +509,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
31205 {
31206 unsigned long va = dtr->address;
31207 unsigned int size = dtr->size + 1;
31208- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31209- unsigned long frames[pages];
31210+ unsigned long frames[65536 / PAGE_SIZE];
31211 int f;
31212
31213 /*
31214@@ -560,8 +557,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31215 {
31216 unsigned long va = dtr->address;
31217 unsigned int size = dtr->size + 1;
31218- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31219- unsigned long frames[pages];
31220+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
31221 int f;
31222
31223 /*
31224@@ -569,7 +565,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31225 * 8-byte entries, or 16 4k pages..
31226 */
31227
31228- BUG_ON(size > 65536);
31229+ BUG_ON(size > GDT_SIZE);
31230 BUG_ON(va & ~PAGE_MASK);
31231
31232 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
31233@@ -954,7 +950,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
31234 return 0;
31235 }
31236
31237-static void set_xen_basic_apic_ops(void)
31238+static void __init set_xen_basic_apic_ops(void)
31239 {
31240 apic->read = xen_apic_read;
31241 apic->write = xen_apic_write;
31242@@ -1260,30 +1256,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
31243 #endif
31244 };
31245
31246-static void xen_reboot(int reason)
31247+static __noreturn void xen_reboot(int reason)
31248 {
31249 struct sched_shutdown r = { .reason = reason };
31250
31251- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
31252- BUG();
31253+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
31254+ BUG();
31255 }
31256
31257-static void xen_restart(char *msg)
31258+static __noreturn void xen_restart(char *msg)
31259 {
31260 xen_reboot(SHUTDOWN_reboot);
31261 }
31262
31263-static void xen_emergency_restart(void)
31264+static __noreturn void xen_emergency_restart(void)
31265 {
31266 xen_reboot(SHUTDOWN_reboot);
31267 }
31268
31269-static void xen_machine_halt(void)
31270+static __noreturn void xen_machine_halt(void)
31271 {
31272 xen_reboot(SHUTDOWN_poweroff);
31273 }
31274
31275-static void xen_machine_power_off(void)
31276+static __noreturn void xen_machine_power_off(void)
31277 {
31278 if (pm_power_off)
31279 pm_power_off();
31280@@ -1385,7 +1381,17 @@ asmlinkage void __init xen_start_kernel(void)
31281 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
31282
31283 /* Work out if we support NX */
31284- x86_configure_nx();
31285+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
31286+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
31287+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
31288+ unsigned l, h;
31289+
31290+ __supported_pte_mask |= _PAGE_NX;
31291+ rdmsr(MSR_EFER, l, h);
31292+ l |= EFER_NX;
31293+ wrmsr(MSR_EFER, l, h);
31294+ }
31295+#endif
31296
31297 xen_setup_features();
31298
31299@@ -1416,13 +1422,6 @@ asmlinkage void __init xen_start_kernel(void)
31300
31301 machine_ops = xen_machine_ops;
31302
31303- /*
31304- * The only reliable way to retain the initial address of the
31305- * percpu gdt_page is to remember it here, so we can go and
31306- * mark it RW later, when the initial percpu area is freed.
31307- */
31308- xen_initial_gdt = &per_cpu(gdt_page, 0);
31309-
31310 xen_smp_init();
31311
31312 #ifdef CONFIG_ACPI_NUMA
31313@@ -1616,7 +1615,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
31314 return NOTIFY_OK;
31315 }
31316
31317-static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
31318+static struct notifier_block xen_hvm_cpu_notifier = {
31319 .notifier_call = xen_hvm_cpu_notify,
31320 };
31321
31322diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
31323index e006c18..b9a7d6c 100644
31324--- a/arch/x86/xen/mmu.c
31325+++ b/arch/x86/xen/mmu.c
31326@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31327 /* L3_k[510] -> level2_kernel_pgt
31328 * L3_i[511] -> level2_fixmap_pgt */
31329 convert_pfn_mfn(level3_kernel_pgt);
31330+ convert_pfn_mfn(level3_vmalloc_start_pgt);
31331+ convert_pfn_mfn(level3_vmalloc_end_pgt);
31332+ convert_pfn_mfn(level3_vmemmap_pgt);
31333
31334 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
31335 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
31336@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31337 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
31338 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
31339 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
31340+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
31341+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
31342+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
31343 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
31344 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
31345+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
31346 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
31347 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
31348
31349@@ -2110,6 +2117,7 @@ static void __init xen_post_allocator_init(void)
31350 pv_mmu_ops.set_pud = xen_set_pud;
31351 #if PAGETABLE_LEVELS == 4
31352 pv_mmu_ops.set_pgd = xen_set_pgd;
31353+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
31354 #endif
31355
31356 /* This will work as long as patching hasn't happened yet
31357@@ -2188,6 +2196,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
31358 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
31359 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
31360 .set_pgd = xen_set_pgd_hyper,
31361+ .set_pgd_batched = xen_set_pgd_hyper,
31362
31363 .alloc_pud = xen_alloc_pmd_init,
31364 .release_pud = xen_release_pmd_init,
31365diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
31366index 22c800a..8915f1e 100644
31367--- a/arch/x86/xen/smp.c
31368+++ b/arch/x86/xen/smp.c
31369@@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
31370 {
31371 BUG_ON(smp_processor_id() != 0);
31372 native_smp_prepare_boot_cpu();
31373-
31374- /* We've switched to the "real" per-cpu gdt, so make sure the
31375- old memory can be recycled */
31376- make_lowmem_page_readwrite(xen_initial_gdt);
31377-
31378 xen_filter_cpu_maps();
31379 xen_setup_vcpu_info_placement();
31380 }
31381@@ -303,7 +298,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
31382 ctxt->user_regs.ss = __KERNEL_DS;
31383 #ifdef CONFIG_X86_32
31384 ctxt->user_regs.fs = __KERNEL_PERCPU;
31385- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
31386+ savesegment(gs, ctxt->user_regs.gs);
31387 #else
31388 ctxt->gs_base_kernel = per_cpu_offset(cpu);
31389 #endif
31390@@ -313,8 +308,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
31391
31392 {
31393 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
31394- ctxt->user_regs.ds = __USER_DS;
31395- ctxt->user_regs.es = __USER_DS;
31396+ ctxt->user_regs.ds = __KERNEL_DS;
31397+ ctxt->user_regs.es = __KERNEL_DS;
31398
31399 xen_copy_trap_info(ctxt->trap_ctxt);
31400
31401@@ -359,13 +354,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
31402 int rc;
31403
31404 per_cpu(current_task, cpu) = idle;
31405+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
31406 #ifdef CONFIG_X86_32
31407 irq_ctx_init(cpu);
31408 #else
31409 clear_tsk_thread_flag(idle, TIF_FORK);
31410- per_cpu(kernel_stack, cpu) =
31411- (unsigned long)task_stack_page(idle) -
31412- KERNEL_STACK_OFFSET + THREAD_SIZE;
31413+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
31414 #endif
31415 xen_setup_runstate_info(cpu);
31416 xen_setup_timer(cpu);
31417@@ -634,7 +628,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
31418
31419 void __init xen_smp_init(void)
31420 {
31421- smp_ops = xen_smp_ops;
31422+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
31423 xen_fill_possible_map();
31424 xen_init_spinlocks();
31425 }
31426diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
31427index 33ca6e4..0ded929 100644
31428--- a/arch/x86/xen/xen-asm_32.S
31429+++ b/arch/x86/xen/xen-asm_32.S
31430@@ -84,14 +84,14 @@ ENTRY(xen_iret)
31431 ESP_OFFSET=4 # bytes pushed onto stack
31432
31433 /*
31434- * Store vcpu_info pointer for easy access. Do it this way to
31435- * avoid having to reload %fs
31436+ * Store vcpu_info pointer for easy access.
31437 */
31438 #ifdef CONFIG_SMP
31439- GET_THREAD_INFO(%eax)
31440- movl %ss:TI_cpu(%eax), %eax
31441- movl %ss:__per_cpu_offset(,%eax,4), %eax
31442- mov %ss:xen_vcpu(%eax), %eax
31443+ push %fs
31444+ mov $(__KERNEL_PERCPU), %eax
31445+ mov %eax, %fs
31446+ mov PER_CPU_VAR(xen_vcpu), %eax
31447+ pop %fs
31448 #else
31449 movl %ss:xen_vcpu, %eax
31450 #endif
31451diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
31452index 7faed58..ba4427c 100644
31453--- a/arch/x86/xen/xen-head.S
31454+++ b/arch/x86/xen/xen-head.S
31455@@ -19,6 +19,17 @@ ENTRY(startup_xen)
31456 #ifdef CONFIG_X86_32
31457 mov %esi,xen_start_info
31458 mov $init_thread_union+THREAD_SIZE,%esp
31459+#ifdef CONFIG_SMP
31460+ movl $cpu_gdt_table,%edi
31461+ movl $__per_cpu_load,%eax
31462+ movw %ax,__KERNEL_PERCPU + 2(%edi)
31463+ rorl $16,%eax
31464+ movb %al,__KERNEL_PERCPU + 4(%edi)
31465+ movb %ah,__KERNEL_PERCPU + 7(%edi)
31466+ movl $__per_cpu_end - 1,%eax
31467+ subl $__per_cpu_start,%eax
31468+ movw %ax,__KERNEL_PERCPU + 0(%edi)
31469+#endif
31470 #else
31471 mov %rsi,xen_start_info
31472 mov $init_thread_union+THREAD_SIZE,%rsp
31473diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
31474index a95b417..b6dbd0b 100644
31475--- a/arch/x86/xen/xen-ops.h
31476+++ b/arch/x86/xen/xen-ops.h
31477@@ -10,8 +10,6 @@
31478 extern const char xen_hypervisor_callback[];
31479 extern const char xen_failsafe_callback[];
31480
31481-extern void *xen_initial_gdt;
31482-
31483 struct trap_info;
31484 void xen_copy_trap_info(struct trap_info *traps);
31485
31486diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
31487index 525bd3d..ef888b1 100644
31488--- a/arch/xtensa/variants/dc232b/include/variant/core.h
31489+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
31490@@ -119,9 +119,9 @@
31491 ----------------------------------------------------------------------*/
31492
31493 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
31494-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
31495 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
31496 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
31497+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31498
31499 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
31500 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
31501diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
31502index 2f33760..835e50a 100644
31503--- a/arch/xtensa/variants/fsf/include/variant/core.h
31504+++ b/arch/xtensa/variants/fsf/include/variant/core.h
31505@@ -11,6 +11,7 @@
31506 #ifndef _XTENSA_CORE_H
31507 #define _XTENSA_CORE_H
31508
31509+#include <linux/const.h>
31510
31511 /****************************************************************************
31512 Parameters Useful for Any Code, USER or PRIVILEGED
31513@@ -112,9 +113,9 @@
31514 ----------------------------------------------------------------------*/
31515
31516 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31517-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31518 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31519 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31520+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31521
31522 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
31523 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
31524diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
31525index af00795..2bb8105 100644
31526--- a/arch/xtensa/variants/s6000/include/variant/core.h
31527+++ b/arch/xtensa/variants/s6000/include/variant/core.h
31528@@ -11,6 +11,7 @@
31529 #ifndef _XTENSA_CORE_CONFIGURATION_H
31530 #define _XTENSA_CORE_CONFIGURATION_H
31531
31532+#include <linux/const.h>
31533
31534 /****************************************************************************
31535 Parameters Useful for Any Code, USER or PRIVILEGED
31536@@ -118,9 +119,9 @@
31537 ----------------------------------------------------------------------*/
31538
31539 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31540-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31541 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31542 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31543+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31544
31545 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
31546 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
31547diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
31548index 58916af..eb9dbcf6 100644
31549--- a/block/blk-iopoll.c
31550+++ b/block/blk-iopoll.c
31551@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
31552 }
31553 EXPORT_SYMBOL(blk_iopoll_complete);
31554
31555-static void blk_iopoll_softirq(struct softirq_action *h)
31556+static void blk_iopoll_softirq(void)
31557 {
31558 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
31559 int rearm = 0, budget = blk_iopoll_budget;
31560@@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
31561 return NOTIFY_OK;
31562 }
31563
31564-static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
31565+static struct notifier_block blk_iopoll_cpu_notifier = {
31566 .notifier_call = blk_iopoll_cpu_notify,
31567 };
31568
31569diff --git a/block/blk-map.c b/block/blk-map.c
31570index 623e1cd..ca1e109 100644
31571--- a/block/blk-map.c
31572+++ b/block/blk-map.c
31573@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
31574 if (!len || !kbuf)
31575 return -EINVAL;
31576
31577- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
31578+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
31579 if (do_copy)
31580 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
31581 else
31582diff --git a/block/blk-softirq.c b/block/blk-softirq.c
31583index 467c8de..f3628c5 100644
31584--- a/block/blk-softirq.c
31585+++ b/block/blk-softirq.c
31586@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
31587 * Softirq action handler - move entries to local list and loop over them
31588 * while passing them to the queue registered handler.
31589 */
31590-static void blk_done_softirq(struct softirq_action *h)
31591+static void blk_done_softirq(void)
31592 {
31593 struct list_head *cpu_list, local_list;
31594
31595@@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
31596 return NOTIFY_OK;
31597 }
31598
31599-static struct notifier_block __cpuinitdata blk_cpu_notifier = {
31600+static struct notifier_block blk_cpu_notifier = {
31601 .notifier_call = blk_cpu_notify,
31602 };
31603
31604diff --git a/block/bsg.c b/block/bsg.c
31605index 420a5a9..23834aa 100644
31606--- a/block/bsg.c
31607+++ b/block/bsg.c
31608@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
31609 struct sg_io_v4 *hdr, struct bsg_device *bd,
31610 fmode_t has_write_perm)
31611 {
31612+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31613+ unsigned char *cmdptr;
31614+
31615 if (hdr->request_len > BLK_MAX_CDB) {
31616 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
31617 if (!rq->cmd)
31618 return -ENOMEM;
31619- }
31620+ cmdptr = rq->cmd;
31621+ } else
31622+ cmdptr = tmpcmd;
31623
31624- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
31625+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
31626 hdr->request_len))
31627 return -EFAULT;
31628
31629+ if (cmdptr != rq->cmd)
31630+ memcpy(rq->cmd, cmdptr, hdr->request_len);
31631+
31632 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
31633 if (blk_verify_command(rq->cmd, has_write_perm))
31634 return -EPERM;
31635diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
31636index 7c668c8..db3521c 100644
31637--- a/block/compat_ioctl.c
31638+++ b/block/compat_ioctl.c
31639@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
31640 err |= __get_user(f->spec1, &uf->spec1);
31641 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
31642 err |= __get_user(name, &uf->name);
31643- f->name = compat_ptr(name);
31644+ f->name = (void __force_kernel *)compat_ptr(name);
31645 if (err) {
31646 err = -EFAULT;
31647 goto out;
31648diff --git a/block/partitions/efi.c b/block/partitions/efi.c
31649index ff5804e..a88acad 100644
31650--- a/block/partitions/efi.c
31651+++ b/block/partitions/efi.c
31652@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
31653 if (!gpt)
31654 return NULL;
31655
31656+ if (!le32_to_cpu(gpt->num_partition_entries))
31657+ return NULL;
31658+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
31659+ if (!pte)
31660+ return NULL;
31661+
31662 count = le32_to_cpu(gpt->num_partition_entries) *
31663 le32_to_cpu(gpt->sizeof_partition_entry);
31664- if (!count)
31665- return NULL;
31666- pte = kzalloc(count, GFP_KERNEL);
31667- if (!pte)
31668- return NULL;
31669-
31670 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
31671 (u8 *) pte,
31672 count) < count) {
31673diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
31674index 9a87daa..fb17486 100644
31675--- a/block/scsi_ioctl.c
31676+++ b/block/scsi_ioctl.c
31677@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
31678 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
31679 struct sg_io_hdr *hdr, fmode_t mode)
31680 {
31681- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
31682+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31683+ unsigned char *cmdptr;
31684+
31685+ if (rq->cmd != rq->__cmd)
31686+ cmdptr = rq->cmd;
31687+ else
31688+ cmdptr = tmpcmd;
31689+
31690+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
31691 return -EFAULT;
31692+
31693+ if (cmdptr != rq->cmd)
31694+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
31695+
31696 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
31697 return -EPERM;
31698
31699@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31700 int err;
31701 unsigned int in_len, out_len, bytes, opcode, cmdlen;
31702 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
31703+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31704+ unsigned char *cmdptr;
31705
31706 if (!sic)
31707 return -EINVAL;
31708@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31709 */
31710 err = -EFAULT;
31711 rq->cmd_len = cmdlen;
31712- if (copy_from_user(rq->cmd, sic->data, cmdlen))
31713+
31714+ if (rq->cmd != rq->__cmd)
31715+ cmdptr = rq->cmd;
31716+ else
31717+ cmdptr = tmpcmd;
31718+
31719+ if (copy_from_user(cmdptr, sic->data, cmdlen))
31720 goto error;
31721
31722+ if (rq->cmd != cmdptr)
31723+ memcpy(rq->cmd, cmdptr, cmdlen);
31724+
31725 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
31726 goto error;
31727
31728diff --git a/crypto/cryptd.c b/crypto/cryptd.c
31729index 7bdd61b..afec999 100644
31730--- a/crypto/cryptd.c
31731+++ b/crypto/cryptd.c
31732@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
31733
31734 struct cryptd_blkcipher_request_ctx {
31735 crypto_completion_t complete;
31736-};
31737+} __no_const;
31738
31739 struct cryptd_hash_ctx {
31740 struct crypto_shash *child;
31741@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
31742
31743 struct cryptd_aead_request_ctx {
31744 crypto_completion_t complete;
31745-};
31746+} __no_const;
31747
31748 static void cryptd_queue_worker(struct work_struct *work);
31749
31750diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
31751index f220d64..d359ad6 100644
31752--- a/drivers/acpi/apei/apei-internal.h
31753+++ b/drivers/acpi/apei/apei-internal.h
31754@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
31755 struct apei_exec_ins_type {
31756 u32 flags;
31757 apei_exec_ins_func_t run;
31758-};
31759+} __do_const;
31760
31761 struct apei_exec_context {
31762 u32 ip;
31763diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
31764index fefc2ca..12a535d 100644
31765--- a/drivers/acpi/apei/cper.c
31766+++ b/drivers/acpi/apei/cper.c
31767@@ -39,12 +39,12 @@
31768 */
31769 u64 cper_next_record_id(void)
31770 {
31771- static atomic64_t seq;
31772+ static atomic64_unchecked_t seq;
31773
31774- if (!atomic64_read(&seq))
31775- atomic64_set(&seq, ((u64)get_seconds()) << 32);
31776+ if (!atomic64_read_unchecked(&seq))
31777+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
31778
31779- return atomic64_inc_return(&seq);
31780+ return atomic64_inc_return_unchecked(&seq);
31781 }
31782 EXPORT_SYMBOL_GPL(cper_next_record_id);
31783
31784diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
31785index be60399..778b33e8 100644
31786--- a/drivers/acpi/bgrt.c
31787+++ b/drivers/acpi/bgrt.c
31788@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
31789 return -ENODEV;
31790
31791 sysfs_bin_attr_init(&image_attr);
31792- image_attr.private = bgrt_image;
31793- image_attr.size = bgrt_image_size;
31794+ pax_open_kernel();
31795+ *(void **)&image_attr.private = bgrt_image;
31796+ *(size_t *)&image_attr.size = bgrt_image_size;
31797+ pax_close_kernel();
31798
31799 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
31800 if (!bgrt_kobj)
31801diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
31802index cb96296..b81293b 100644
31803--- a/drivers/acpi/blacklist.c
31804+++ b/drivers/acpi/blacklist.c
31805@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
31806 u32 is_critical_error;
31807 };
31808
31809-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
31810+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
31811
31812 /*
31813 * POLICY: If *anything* doesn't work, put it on the blacklist.
31814@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
31815 return 0;
31816 }
31817
31818-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
31819+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
31820 {
31821 .callback = dmi_disable_osi_vista,
31822 .ident = "Fujitsu Siemens",
31823diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
31824index 7586544..636a2f0 100644
31825--- a/drivers/acpi/ec_sys.c
31826+++ b/drivers/acpi/ec_sys.c
31827@@ -12,6 +12,7 @@
31828 #include <linux/acpi.h>
31829 #include <linux/debugfs.h>
31830 #include <linux/module.h>
31831+#include <linux/uaccess.h>
31832 #include "internal.h"
31833
31834 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
31835@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31836 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
31837 */
31838 unsigned int size = EC_SPACE_SIZE;
31839- u8 *data = (u8 *) buf;
31840+ u8 data;
31841 loff_t init_off = *off;
31842 int err = 0;
31843
31844@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31845 size = count;
31846
31847 while (size) {
31848- err = ec_read(*off, &data[*off - init_off]);
31849+ err = ec_read(*off, &data);
31850 if (err)
31851 return err;
31852+ if (put_user(data, &buf[*off - init_off]))
31853+ return -EFAULT;
31854 *off += 1;
31855 size--;
31856 }
31857@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31858
31859 unsigned int size = count;
31860 loff_t init_off = *off;
31861- u8 *data = (u8 *) buf;
31862 int err = 0;
31863
31864 if (*off >= EC_SPACE_SIZE)
31865@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31866 }
31867
31868 while (size) {
31869- u8 byte_write = data[*off - init_off];
31870+ u8 byte_write;
31871+ if (get_user(byte_write, &buf[*off - init_off]))
31872+ return -EFAULT;
31873 err = ec_write(*off, byte_write);
31874 if (err)
31875 return err;
31876diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
31877index ee255c6..747c68b 100644
31878--- a/drivers/acpi/processor_idle.c
31879+++ b/drivers/acpi/processor_idle.c
31880@@ -986,7 +986,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
31881 {
31882 int i, count = CPUIDLE_DRIVER_STATE_START;
31883 struct acpi_processor_cx *cx;
31884- struct cpuidle_state *state;
31885+ cpuidle_state_no_const *state;
31886 struct cpuidle_driver *drv = &acpi_idle_driver;
31887
31888 if (!pr->flags.power_setup_done)
31889diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
31890index 41c0504..f8c0836 100644
31891--- a/drivers/acpi/sysfs.c
31892+++ b/drivers/acpi/sysfs.c
31893@@ -420,11 +420,11 @@ static u32 num_counters;
31894 static struct attribute **all_attrs;
31895 static u32 acpi_gpe_count;
31896
31897-static struct attribute_group interrupt_stats_attr_group = {
31898+static attribute_group_no_const interrupt_stats_attr_group = {
31899 .name = "interrupts",
31900 };
31901
31902-static struct kobj_attribute *counter_attrs;
31903+static kobj_attribute_no_const *counter_attrs;
31904
31905 static void delete_gpe_attr_array(void)
31906 {
31907diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
31908index 34c8216..f56c828 100644
31909--- a/drivers/ata/libahci.c
31910+++ b/drivers/ata/libahci.c
31911@@ -1230,7 +1230,7 @@ int ahci_kick_engine(struct ata_port *ap)
31912 }
31913 EXPORT_SYMBOL_GPL(ahci_kick_engine);
31914
31915-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
31916+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
31917 struct ata_taskfile *tf, int is_cmd, u16 flags,
31918 unsigned long timeout_msec)
31919 {
31920diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
31921index cf15aee..e0b7078 100644
31922--- a/drivers/ata/libata-core.c
31923+++ b/drivers/ata/libata-core.c
31924@@ -4792,7 +4792,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
31925 struct ata_port *ap;
31926 unsigned int tag;
31927
31928- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31929+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31930 ap = qc->ap;
31931
31932 qc->flags = 0;
31933@@ -4808,7 +4808,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
31934 struct ata_port *ap;
31935 struct ata_link *link;
31936
31937- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31938+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31939 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
31940 ap = qc->ap;
31941 link = qc->dev->link;
31942@@ -5926,6 +5926,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31943 return;
31944
31945 spin_lock(&lock);
31946+ pax_open_kernel();
31947
31948 for (cur = ops->inherits; cur; cur = cur->inherits) {
31949 void **inherit = (void **)cur;
31950@@ -5939,8 +5940,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31951 if (IS_ERR(*pp))
31952 *pp = NULL;
31953
31954- ops->inherits = NULL;
31955+ *(struct ata_port_operations **)&ops->inherits = NULL;
31956
31957+ pax_close_kernel();
31958 spin_unlock(&lock);
31959 }
31960
31961diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
31962index 405022d..fb70e53 100644
31963--- a/drivers/ata/pata_arasan_cf.c
31964+++ b/drivers/ata/pata_arasan_cf.c
31965@@ -864,7 +864,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
31966 /* Handle platform specific quirks */
31967 if (pdata->quirk) {
31968 if (pdata->quirk & CF_BROKEN_PIO) {
31969- ap->ops->set_piomode = NULL;
31970+ pax_open_kernel();
31971+ *(void **)&ap->ops->set_piomode = NULL;
31972+ pax_close_kernel();
31973 ap->pio_mask = 0;
31974 }
31975 if (pdata->quirk & CF_BROKEN_MWDMA)
31976diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
31977index f9b983a..887b9d8 100644
31978--- a/drivers/atm/adummy.c
31979+++ b/drivers/atm/adummy.c
31980@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
31981 vcc->pop(vcc, skb);
31982 else
31983 dev_kfree_skb_any(skb);
31984- atomic_inc(&vcc->stats->tx);
31985+ atomic_inc_unchecked(&vcc->stats->tx);
31986
31987 return 0;
31988 }
31989diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
31990index 77a7480d..05cde58 100644
31991--- a/drivers/atm/ambassador.c
31992+++ b/drivers/atm/ambassador.c
31993@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
31994 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
31995
31996 // VC layer stats
31997- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31998+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31999
32000 // free the descriptor
32001 kfree (tx_descr);
32002@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
32003 dump_skb ("<<<", vc, skb);
32004
32005 // VC layer stats
32006- atomic_inc(&atm_vcc->stats->rx);
32007+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32008 __net_timestamp(skb);
32009 // end of our responsibility
32010 atm_vcc->push (atm_vcc, skb);
32011@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
32012 } else {
32013 PRINTK (KERN_INFO, "dropped over-size frame");
32014 // should we count this?
32015- atomic_inc(&atm_vcc->stats->rx_drop);
32016+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32017 }
32018
32019 } else {
32020@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
32021 }
32022
32023 if (check_area (skb->data, skb->len)) {
32024- atomic_inc(&atm_vcc->stats->tx_err);
32025+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
32026 return -ENOMEM; // ?
32027 }
32028
32029diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
32030index 0e3f8f9..765a7a5 100644
32031--- a/drivers/atm/atmtcp.c
32032+++ b/drivers/atm/atmtcp.c
32033@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32034 if (vcc->pop) vcc->pop(vcc,skb);
32035 else dev_kfree_skb(skb);
32036 if (dev_data) return 0;
32037- atomic_inc(&vcc->stats->tx_err);
32038+ atomic_inc_unchecked(&vcc->stats->tx_err);
32039 return -ENOLINK;
32040 }
32041 size = skb->len+sizeof(struct atmtcp_hdr);
32042@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32043 if (!new_skb) {
32044 if (vcc->pop) vcc->pop(vcc,skb);
32045 else dev_kfree_skb(skb);
32046- atomic_inc(&vcc->stats->tx_err);
32047+ atomic_inc_unchecked(&vcc->stats->tx_err);
32048 return -ENOBUFS;
32049 }
32050 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
32051@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32052 if (vcc->pop) vcc->pop(vcc,skb);
32053 else dev_kfree_skb(skb);
32054 out_vcc->push(out_vcc,new_skb);
32055- atomic_inc(&vcc->stats->tx);
32056- atomic_inc(&out_vcc->stats->rx);
32057+ atomic_inc_unchecked(&vcc->stats->tx);
32058+ atomic_inc_unchecked(&out_vcc->stats->rx);
32059 return 0;
32060 }
32061
32062@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32063 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
32064 read_unlock(&vcc_sklist_lock);
32065 if (!out_vcc) {
32066- atomic_inc(&vcc->stats->tx_err);
32067+ atomic_inc_unchecked(&vcc->stats->tx_err);
32068 goto done;
32069 }
32070 skb_pull(skb,sizeof(struct atmtcp_hdr));
32071@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32072 __net_timestamp(new_skb);
32073 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
32074 out_vcc->push(out_vcc,new_skb);
32075- atomic_inc(&vcc->stats->tx);
32076- atomic_inc(&out_vcc->stats->rx);
32077+ atomic_inc_unchecked(&vcc->stats->tx);
32078+ atomic_inc_unchecked(&out_vcc->stats->rx);
32079 done:
32080 if (vcc->pop) vcc->pop(vcc,skb);
32081 else dev_kfree_skb(skb);
32082diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
32083index b1955ba..b179940 100644
32084--- a/drivers/atm/eni.c
32085+++ b/drivers/atm/eni.c
32086@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
32087 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
32088 vcc->dev->number);
32089 length = 0;
32090- atomic_inc(&vcc->stats->rx_err);
32091+ atomic_inc_unchecked(&vcc->stats->rx_err);
32092 }
32093 else {
32094 length = ATM_CELL_SIZE-1; /* no HEC */
32095@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32096 size);
32097 }
32098 eff = length = 0;
32099- atomic_inc(&vcc->stats->rx_err);
32100+ atomic_inc_unchecked(&vcc->stats->rx_err);
32101 }
32102 else {
32103 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
32104@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32105 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
32106 vcc->dev->number,vcc->vci,length,size << 2,descr);
32107 length = eff = 0;
32108- atomic_inc(&vcc->stats->rx_err);
32109+ atomic_inc_unchecked(&vcc->stats->rx_err);
32110 }
32111 }
32112 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
32113@@ -767,7 +767,7 @@ rx_dequeued++;
32114 vcc->push(vcc,skb);
32115 pushed++;
32116 }
32117- atomic_inc(&vcc->stats->rx);
32118+ atomic_inc_unchecked(&vcc->stats->rx);
32119 }
32120 wake_up(&eni_dev->rx_wait);
32121 }
32122@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
32123 PCI_DMA_TODEVICE);
32124 if (vcc->pop) vcc->pop(vcc,skb);
32125 else dev_kfree_skb_irq(skb);
32126- atomic_inc(&vcc->stats->tx);
32127+ atomic_inc_unchecked(&vcc->stats->tx);
32128 wake_up(&eni_dev->tx_wait);
32129 dma_complete++;
32130 }
32131diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
32132index b41c948..a002b17 100644
32133--- a/drivers/atm/firestream.c
32134+++ b/drivers/atm/firestream.c
32135@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
32136 }
32137 }
32138
32139- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32140+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32141
32142 fs_dprintk (FS_DEBUG_TXMEM, "i");
32143 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
32144@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32145 #endif
32146 skb_put (skb, qe->p1 & 0xffff);
32147 ATM_SKB(skb)->vcc = atm_vcc;
32148- atomic_inc(&atm_vcc->stats->rx);
32149+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32150 __net_timestamp(skb);
32151 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
32152 atm_vcc->push (atm_vcc, skb);
32153@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32154 kfree (pe);
32155 }
32156 if (atm_vcc)
32157- atomic_inc(&atm_vcc->stats->rx_drop);
32158+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32159 break;
32160 case 0x1f: /* Reassembly abort: no buffers. */
32161 /* Silently increment error counter. */
32162 if (atm_vcc)
32163- atomic_inc(&atm_vcc->stats->rx_drop);
32164+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32165 break;
32166 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
32167 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
32168diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
32169index 204814e..cede831 100644
32170--- a/drivers/atm/fore200e.c
32171+++ b/drivers/atm/fore200e.c
32172@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
32173 #endif
32174 /* check error condition */
32175 if (*entry->status & STATUS_ERROR)
32176- atomic_inc(&vcc->stats->tx_err);
32177+ atomic_inc_unchecked(&vcc->stats->tx_err);
32178 else
32179- atomic_inc(&vcc->stats->tx);
32180+ atomic_inc_unchecked(&vcc->stats->tx);
32181 }
32182 }
32183
32184@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32185 if (skb == NULL) {
32186 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
32187
32188- atomic_inc(&vcc->stats->rx_drop);
32189+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32190 return -ENOMEM;
32191 }
32192
32193@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32194
32195 dev_kfree_skb_any(skb);
32196
32197- atomic_inc(&vcc->stats->rx_drop);
32198+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32199 return -ENOMEM;
32200 }
32201
32202 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32203
32204 vcc->push(vcc, skb);
32205- atomic_inc(&vcc->stats->rx);
32206+ atomic_inc_unchecked(&vcc->stats->rx);
32207
32208 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32209
32210@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
32211 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
32212 fore200e->atm_dev->number,
32213 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
32214- atomic_inc(&vcc->stats->rx_err);
32215+ atomic_inc_unchecked(&vcc->stats->rx_err);
32216 }
32217 }
32218
32219@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
32220 goto retry_here;
32221 }
32222
32223- atomic_inc(&vcc->stats->tx_err);
32224+ atomic_inc_unchecked(&vcc->stats->tx_err);
32225
32226 fore200e->tx_sat++;
32227 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
32228diff --git a/drivers/atm/he.c b/drivers/atm/he.c
32229index d689126..e78e412 100644
32230--- a/drivers/atm/he.c
32231+++ b/drivers/atm/he.c
32232@@ -1698,7 +1698,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32233
32234 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
32235 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
32236- atomic_inc(&vcc->stats->rx_drop);
32237+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32238 goto return_host_buffers;
32239 }
32240
32241@@ -1725,7 +1725,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32242 RBRQ_LEN_ERR(he_dev->rbrq_head)
32243 ? "LEN_ERR" : "",
32244 vcc->vpi, vcc->vci);
32245- atomic_inc(&vcc->stats->rx_err);
32246+ atomic_inc_unchecked(&vcc->stats->rx_err);
32247 goto return_host_buffers;
32248 }
32249
32250@@ -1777,7 +1777,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32251 vcc->push(vcc, skb);
32252 spin_lock(&he_dev->global_lock);
32253
32254- atomic_inc(&vcc->stats->rx);
32255+ atomic_inc_unchecked(&vcc->stats->rx);
32256
32257 return_host_buffers:
32258 ++pdus_assembled;
32259@@ -2103,7 +2103,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
32260 tpd->vcc->pop(tpd->vcc, tpd->skb);
32261 else
32262 dev_kfree_skb_any(tpd->skb);
32263- atomic_inc(&tpd->vcc->stats->tx_err);
32264+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
32265 }
32266 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
32267 return;
32268@@ -2515,7 +2515,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32269 vcc->pop(vcc, skb);
32270 else
32271 dev_kfree_skb_any(skb);
32272- atomic_inc(&vcc->stats->tx_err);
32273+ atomic_inc_unchecked(&vcc->stats->tx_err);
32274 return -EINVAL;
32275 }
32276
32277@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32278 vcc->pop(vcc, skb);
32279 else
32280 dev_kfree_skb_any(skb);
32281- atomic_inc(&vcc->stats->tx_err);
32282+ atomic_inc_unchecked(&vcc->stats->tx_err);
32283 return -EINVAL;
32284 }
32285 #endif
32286@@ -2538,7 +2538,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32287 vcc->pop(vcc, skb);
32288 else
32289 dev_kfree_skb_any(skb);
32290- atomic_inc(&vcc->stats->tx_err);
32291+ atomic_inc_unchecked(&vcc->stats->tx_err);
32292 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32293 return -ENOMEM;
32294 }
32295@@ -2580,7 +2580,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32296 vcc->pop(vcc, skb);
32297 else
32298 dev_kfree_skb_any(skb);
32299- atomic_inc(&vcc->stats->tx_err);
32300+ atomic_inc_unchecked(&vcc->stats->tx_err);
32301 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32302 return -ENOMEM;
32303 }
32304@@ -2611,7 +2611,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32305 __enqueue_tpd(he_dev, tpd, cid);
32306 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32307
32308- atomic_inc(&vcc->stats->tx);
32309+ atomic_inc_unchecked(&vcc->stats->tx);
32310
32311 return 0;
32312 }
32313diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
32314index 1dc0519..1aadaf7 100644
32315--- a/drivers/atm/horizon.c
32316+++ b/drivers/atm/horizon.c
32317@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
32318 {
32319 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
32320 // VC layer stats
32321- atomic_inc(&vcc->stats->rx);
32322+ atomic_inc_unchecked(&vcc->stats->rx);
32323 __net_timestamp(skb);
32324 // end of our responsibility
32325 vcc->push (vcc, skb);
32326@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
32327 dev->tx_iovec = NULL;
32328
32329 // VC layer stats
32330- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32331+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32332
32333 // free the skb
32334 hrz_kfree_skb (skb);
32335diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
32336index 272f009..a18ba55 100644
32337--- a/drivers/atm/idt77252.c
32338+++ b/drivers/atm/idt77252.c
32339@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
32340 else
32341 dev_kfree_skb(skb);
32342
32343- atomic_inc(&vcc->stats->tx);
32344+ atomic_inc_unchecked(&vcc->stats->tx);
32345 }
32346
32347 atomic_dec(&scq->used);
32348@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32349 if ((sb = dev_alloc_skb(64)) == NULL) {
32350 printk("%s: Can't allocate buffers for aal0.\n",
32351 card->name);
32352- atomic_add(i, &vcc->stats->rx_drop);
32353+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32354 break;
32355 }
32356 if (!atm_charge(vcc, sb->truesize)) {
32357 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
32358 card->name);
32359- atomic_add(i - 1, &vcc->stats->rx_drop);
32360+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
32361 dev_kfree_skb(sb);
32362 break;
32363 }
32364@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32365 ATM_SKB(sb)->vcc = vcc;
32366 __net_timestamp(sb);
32367 vcc->push(vcc, sb);
32368- atomic_inc(&vcc->stats->rx);
32369+ atomic_inc_unchecked(&vcc->stats->rx);
32370
32371 cell += ATM_CELL_PAYLOAD;
32372 }
32373@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32374 "(CDC: %08x)\n",
32375 card->name, len, rpp->len, readl(SAR_REG_CDC));
32376 recycle_rx_pool_skb(card, rpp);
32377- atomic_inc(&vcc->stats->rx_err);
32378+ atomic_inc_unchecked(&vcc->stats->rx_err);
32379 return;
32380 }
32381 if (stat & SAR_RSQE_CRC) {
32382 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
32383 recycle_rx_pool_skb(card, rpp);
32384- atomic_inc(&vcc->stats->rx_err);
32385+ atomic_inc_unchecked(&vcc->stats->rx_err);
32386 return;
32387 }
32388 if (skb_queue_len(&rpp->queue) > 1) {
32389@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32390 RXPRINTK("%s: Can't alloc RX skb.\n",
32391 card->name);
32392 recycle_rx_pool_skb(card, rpp);
32393- atomic_inc(&vcc->stats->rx_err);
32394+ atomic_inc_unchecked(&vcc->stats->rx_err);
32395 return;
32396 }
32397 if (!atm_charge(vcc, skb->truesize)) {
32398@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32399 __net_timestamp(skb);
32400
32401 vcc->push(vcc, skb);
32402- atomic_inc(&vcc->stats->rx);
32403+ atomic_inc_unchecked(&vcc->stats->rx);
32404
32405 return;
32406 }
32407@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32408 __net_timestamp(skb);
32409
32410 vcc->push(vcc, skb);
32411- atomic_inc(&vcc->stats->rx);
32412+ atomic_inc_unchecked(&vcc->stats->rx);
32413
32414 if (skb->truesize > SAR_FB_SIZE_3)
32415 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
32416@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
32417 if (vcc->qos.aal != ATM_AAL0) {
32418 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
32419 card->name, vpi, vci);
32420- atomic_inc(&vcc->stats->rx_drop);
32421+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32422 goto drop;
32423 }
32424
32425 if ((sb = dev_alloc_skb(64)) == NULL) {
32426 printk("%s: Can't allocate buffers for AAL0.\n",
32427 card->name);
32428- atomic_inc(&vcc->stats->rx_err);
32429+ atomic_inc_unchecked(&vcc->stats->rx_err);
32430 goto drop;
32431 }
32432
32433@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
32434 ATM_SKB(sb)->vcc = vcc;
32435 __net_timestamp(sb);
32436 vcc->push(vcc, sb);
32437- atomic_inc(&vcc->stats->rx);
32438+ atomic_inc_unchecked(&vcc->stats->rx);
32439
32440 drop:
32441 skb_pull(queue, 64);
32442@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32443
32444 if (vc == NULL) {
32445 printk("%s: NULL connection in send().\n", card->name);
32446- atomic_inc(&vcc->stats->tx_err);
32447+ atomic_inc_unchecked(&vcc->stats->tx_err);
32448 dev_kfree_skb(skb);
32449 return -EINVAL;
32450 }
32451 if (!test_bit(VCF_TX, &vc->flags)) {
32452 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
32453- atomic_inc(&vcc->stats->tx_err);
32454+ atomic_inc_unchecked(&vcc->stats->tx_err);
32455 dev_kfree_skb(skb);
32456 return -EINVAL;
32457 }
32458@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32459 break;
32460 default:
32461 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
32462- atomic_inc(&vcc->stats->tx_err);
32463+ atomic_inc_unchecked(&vcc->stats->tx_err);
32464 dev_kfree_skb(skb);
32465 return -EINVAL;
32466 }
32467
32468 if (skb_shinfo(skb)->nr_frags != 0) {
32469 printk("%s: No scatter-gather yet.\n", card->name);
32470- atomic_inc(&vcc->stats->tx_err);
32471+ atomic_inc_unchecked(&vcc->stats->tx_err);
32472 dev_kfree_skb(skb);
32473 return -EINVAL;
32474 }
32475@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32476
32477 err = queue_skb(card, vc, skb, oam);
32478 if (err) {
32479- atomic_inc(&vcc->stats->tx_err);
32480+ atomic_inc_unchecked(&vcc->stats->tx_err);
32481 dev_kfree_skb(skb);
32482 return err;
32483 }
32484@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
32485 skb = dev_alloc_skb(64);
32486 if (!skb) {
32487 printk("%s: Out of memory in send_oam().\n", card->name);
32488- atomic_inc(&vcc->stats->tx_err);
32489+ atomic_inc_unchecked(&vcc->stats->tx_err);
32490 return -ENOMEM;
32491 }
32492 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
32493diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
32494index 4217f29..88f547a 100644
32495--- a/drivers/atm/iphase.c
32496+++ b/drivers/atm/iphase.c
32497@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
32498 status = (u_short) (buf_desc_ptr->desc_mode);
32499 if (status & (RX_CER | RX_PTE | RX_OFL))
32500 {
32501- atomic_inc(&vcc->stats->rx_err);
32502+ atomic_inc_unchecked(&vcc->stats->rx_err);
32503 IF_ERR(printk("IA: bad packet, dropping it");)
32504 if (status & RX_CER) {
32505 IF_ERR(printk(" cause: packet CRC error\n");)
32506@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
32507 len = dma_addr - buf_addr;
32508 if (len > iadev->rx_buf_sz) {
32509 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
32510- atomic_inc(&vcc->stats->rx_err);
32511+ atomic_inc_unchecked(&vcc->stats->rx_err);
32512 goto out_free_desc;
32513 }
32514
32515@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32516 ia_vcc = INPH_IA_VCC(vcc);
32517 if (ia_vcc == NULL)
32518 {
32519- atomic_inc(&vcc->stats->rx_err);
32520+ atomic_inc_unchecked(&vcc->stats->rx_err);
32521 atm_return(vcc, skb->truesize);
32522 dev_kfree_skb_any(skb);
32523 goto INCR_DLE;
32524@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32525 if ((length > iadev->rx_buf_sz) || (length >
32526 (skb->len - sizeof(struct cpcs_trailer))))
32527 {
32528- atomic_inc(&vcc->stats->rx_err);
32529+ atomic_inc_unchecked(&vcc->stats->rx_err);
32530 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
32531 length, skb->len);)
32532 atm_return(vcc, skb->truesize);
32533@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32534
32535 IF_RX(printk("rx_dle_intr: skb push");)
32536 vcc->push(vcc,skb);
32537- atomic_inc(&vcc->stats->rx);
32538+ atomic_inc_unchecked(&vcc->stats->rx);
32539 iadev->rx_pkt_cnt++;
32540 }
32541 INCR_DLE:
32542@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
32543 {
32544 struct k_sonet_stats *stats;
32545 stats = &PRIV(_ia_dev[board])->sonet_stats;
32546- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
32547- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
32548- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
32549- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
32550- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
32551- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
32552- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
32553- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
32554- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
32555+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
32556+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
32557+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
32558+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
32559+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
32560+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
32561+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
32562+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
32563+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
32564 }
32565 ia_cmds.status = 0;
32566 break;
32567@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32568 if ((desc == 0) || (desc > iadev->num_tx_desc))
32569 {
32570 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
32571- atomic_inc(&vcc->stats->tx);
32572+ atomic_inc_unchecked(&vcc->stats->tx);
32573 if (vcc->pop)
32574 vcc->pop(vcc, skb);
32575 else
32576@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32577 ATM_DESC(skb) = vcc->vci;
32578 skb_queue_tail(&iadev->tx_dma_q, skb);
32579
32580- atomic_inc(&vcc->stats->tx);
32581+ atomic_inc_unchecked(&vcc->stats->tx);
32582 iadev->tx_pkt_cnt++;
32583 /* Increment transaction counter */
32584 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
32585
32586 #if 0
32587 /* add flow control logic */
32588- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
32589+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
32590 if (iavcc->vc_desc_cnt > 10) {
32591 vcc->tx_quota = vcc->tx_quota * 3 / 4;
32592 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
32593diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
32594index fa7d701..1e404c7 100644
32595--- a/drivers/atm/lanai.c
32596+++ b/drivers/atm/lanai.c
32597@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
32598 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
32599 lanai_endtx(lanai, lvcc);
32600 lanai_free_skb(lvcc->tx.atmvcc, skb);
32601- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
32602+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
32603 }
32604
32605 /* Try to fill the buffer - don't call unless there is backlog */
32606@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
32607 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
32608 __net_timestamp(skb);
32609 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
32610- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
32611+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
32612 out:
32613 lvcc->rx.buf.ptr = end;
32614 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
32615@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32616 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
32617 "vcc %d\n", lanai->number, (unsigned int) s, vci);
32618 lanai->stats.service_rxnotaal5++;
32619- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32620+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32621 return 0;
32622 }
32623 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
32624@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32625 int bytes;
32626 read_unlock(&vcc_sklist_lock);
32627 DPRINTK("got trashed rx pdu on vci %d\n", vci);
32628- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32629+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32630 lvcc->stats.x.aal5.service_trash++;
32631 bytes = (SERVICE_GET_END(s) * 16) -
32632 (((unsigned long) lvcc->rx.buf.ptr) -
32633@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32634 }
32635 if (s & SERVICE_STREAM) {
32636 read_unlock(&vcc_sklist_lock);
32637- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32638+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32639 lvcc->stats.x.aal5.service_stream++;
32640 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
32641 "PDU on VCI %d!\n", lanai->number, vci);
32642@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32643 return 0;
32644 }
32645 DPRINTK("got rx crc error on vci %d\n", vci);
32646- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32647+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32648 lvcc->stats.x.aal5.service_rxcrc++;
32649 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
32650 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
32651diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
32652index 6587dc2..149833d 100644
32653--- a/drivers/atm/nicstar.c
32654+++ b/drivers/atm/nicstar.c
32655@@ -1641,7 +1641,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32656 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
32657 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
32658 card->index);
32659- atomic_inc(&vcc->stats->tx_err);
32660+ atomic_inc_unchecked(&vcc->stats->tx_err);
32661 dev_kfree_skb_any(skb);
32662 return -EINVAL;
32663 }
32664@@ -1649,7 +1649,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32665 if (!vc->tx) {
32666 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
32667 card->index);
32668- atomic_inc(&vcc->stats->tx_err);
32669+ atomic_inc_unchecked(&vcc->stats->tx_err);
32670 dev_kfree_skb_any(skb);
32671 return -EINVAL;
32672 }
32673@@ -1657,14 +1657,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32674 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
32675 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
32676 card->index);
32677- atomic_inc(&vcc->stats->tx_err);
32678+ atomic_inc_unchecked(&vcc->stats->tx_err);
32679 dev_kfree_skb_any(skb);
32680 return -EINVAL;
32681 }
32682
32683 if (skb_shinfo(skb)->nr_frags != 0) {
32684 printk("nicstar%d: No scatter-gather yet.\n", card->index);
32685- atomic_inc(&vcc->stats->tx_err);
32686+ atomic_inc_unchecked(&vcc->stats->tx_err);
32687 dev_kfree_skb_any(skb);
32688 return -EINVAL;
32689 }
32690@@ -1712,11 +1712,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32691 }
32692
32693 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
32694- atomic_inc(&vcc->stats->tx_err);
32695+ atomic_inc_unchecked(&vcc->stats->tx_err);
32696 dev_kfree_skb_any(skb);
32697 return -EIO;
32698 }
32699- atomic_inc(&vcc->stats->tx);
32700+ atomic_inc_unchecked(&vcc->stats->tx);
32701
32702 return 0;
32703 }
32704@@ -2033,14 +2033,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32705 printk
32706 ("nicstar%d: Can't allocate buffers for aal0.\n",
32707 card->index);
32708- atomic_add(i, &vcc->stats->rx_drop);
32709+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32710 break;
32711 }
32712 if (!atm_charge(vcc, sb->truesize)) {
32713 RXPRINTK
32714 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
32715 card->index);
32716- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32717+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32718 dev_kfree_skb_any(sb);
32719 break;
32720 }
32721@@ -2055,7 +2055,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32722 ATM_SKB(sb)->vcc = vcc;
32723 __net_timestamp(sb);
32724 vcc->push(vcc, sb);
32725- atomic_inc(&vcc->stats->rx);
32726+ atomic_inc_unchecked(&vcc->stats->rx);
32727 cell += ATM_CELL_PAYLOAD;
32728 }
32729
32730@@ -2072,7 +2072,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32731 if (iovb == NULL) {
32732 printk("nicstar%d: Out of iovec buffers.\n",
32733 card->index);
32734- atomic_inc(&vcc->stats->rx_drop);
32735+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32736 recycle_rx_buf(card, skb);
32737 return;
32738 }
32739@@ -2096,7 +2096,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32740 small or large buffer itself. */
32741 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
32742 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
32743- atomic_inc(&vcc->stats->rx_err);
32744+ atomic_inc_unchecked(&vcc->stats->rx_err);
32745 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32746 NS_MAX_IOVECS);
32747 NS_PRV_IOVCNT(iovb) = 0;
32748@@ -2116,7 +2116,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32749 ("nicstar%d: Expected a small buffer, and this is not one.\n",
32750 card->index);
32751 which_list(card, skb);
32752- atomic_inc(&vcc->stats->rx_err);
32753+ atomic_inc_unchecked(&vcc->stats->rx_err);
32754 recycle_rx_buf(card, skb);
32755 vc->rx_iov = NULL;
32756 recycle_iov_buf(card, iovb);
32757@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32758 ("nicstar%d: Expected a large buffer, and this is not one.\n",
32759 card->index);
32760 which_list(card, skb);
32761- atomic_inc(&vcc->stats->rx_err);
32762+ atomic_inc_unchecked(&vcc->stats->rx_err);
32763 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32764 NS_PRV_IOVCNT(iovb));
32765 vc->rx_iov = NULL;
32766@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32767 printk(" - PDU size mismatch.\n");
32768 else
32769 printk(".\n");
32770- atomic_inc(&vcc->stats->rx_err);
32771+ atomic_inc_unchecked(&vcc->stats->rx_err);
32772 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32773 NS_PRV_IOVCNT(iovb));
32774 vc->rx_iov = NULL;
32775@@ -2166,7 +2166,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32776 /* skb points to a small buffer */
32777 if (!atm_charge(vcc, skb->truesize)) {
32778 push_rxbufs(card, skb);
32779- atomic_inc(&vcc->stats->rx_drop);
32780+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32781 } else {
32782 skb_put(skb, len);
32783 dequeue_sm_buf(card, skb);
32784@@ -2176,7 +2176,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32785 ATM_SKB(skb)->vcc = vcc;
32786 __net_timestamp(skb);
32787 vcc->push(vcc, skb);
32788- atomic_inc(&vcc->stats->rx);
32789+ atomic_inc_unchecked(&vcc->stats->rx);
32790 }
32791 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
32792 struct sk_buff *sb;
32793@@ -2187,7 +2187,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32794 if (len <= NS_SMBUFSIZE) {
32795 if (!atm_charge(vcc, sb->truesize)) {
32796 push_rxbufs(card, sb);
32797- atomic_inc(&vcc->stats->rx_drop);
32798+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32799 } else {
32800 skb_put(sb, len);
32801 dequeue_sm_buf(card, sb);
32802@@ -2197,7 +2197,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32803 ATM_SKB(sb)->vcc = vcc;
32804 __net_timestamp(sb);
32805 vcc->push(vcc, sb);
32806- atomic_inc(&vcc->stats->rx);
32807+ atomic_inc_unchecked(&vcc->stats->rx);
32808 }
32809
32810 push_rxbufs(card, skb);
32811@@ -2206,7 +2206,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32812
32813 if (!atm_charge(vcc, skb->truesize)) {
32814 push_rxbufs(card, skb);
32815- atomic_inc(&vcc->stats->rx_drop);
32816+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32817 } else {
32818 dequeue_lg_buf(card, skb);
32819 #ifdef NS_USE_DESTRUCTORS
32820@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32821 ATM_SKB(skb)->vcc = vcc;
32822 __net_timestamp(skb);
32823 vcc->push(vcc, skb);
32824- atomic_inc(&vcc->stats->rx);
32825+ atomic_inc_unchecked(&vcc->stats->rx);
32826 }
32827
32828 push_rxbufs(card, sb);
32829@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32830 printk
32831 ("nicstar%d: Out of huge buffers.\n",
32832 card->index);
32833- atomic_inc(&vcc->stats->rx_drop);
32834+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32835 recycle_iovec_rx_bufs(card,
32836 (struct iovec *)
32837 iovb->data,
32838@@ -2291,7 +2291,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32839 card->hbpool.count++;
32840 } else
32841 dev_kfree_skb_any(hb);
32842- atomic_inc(&vcc->stats->rx_drop);
32843+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32844 } else {
32845 /* Copy the small buffer to the huge buffer */
32846 sb = (struct sk_buff *)iov->iov_base;
32847@@ -2328,7 +2328,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32848 #endif /* NS_USE_DESTRUCTORS */
32849 __net_timestamp(hb);
32850 vcc->push(vcc, hb);
32851- atomic_inc(&vcc->stats->rx);
32852+ atomic_inc_unchecked(&vcc->stats->rx);
32853 }
32854 }
32855
32856diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
32857index 32784d1..4a8434a 100644
32858--- a/drivers/atm/solos-pci.c
32859+++ b/drivers/atm/solos-pci.c
32860@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
32861 }
32862 atm_charge(vcc, skb->truesize);
32863 vcc->push(vcc, skb);
32864- atomic_inc(&vcc->stats->rx);
32865+ atomic_inc_unchecked(&vcc->stats->rx);
32866 break;
32867
32868 case PKT_STATUS:
32869@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
32870 vcc = SKB_CB(oldskb)->vcc;
32871
32872 if (vcc) {
32873- atomic_inc(&vcc->stats->tx);
32874+ atomic_inc_unchecked(&vcc->stats->tx);
32875 solos_pop(vcc, oldskb);
32876 } else {
32877 dev_kfree_skb_irq(oldskb);
32878diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
32879index 0215934..ce9f5b1 100644
32880--- a/drivers/atm/suni.c
32881+++ b/drivers/atm/suni.c
32882@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
32883
32884
32885 #define ADD_LIMITED(s,v) \
32886- atomic_add((v),&stats->s); \
32887- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
32888+ atomic_add_unchecked((v),&stats->s); \
32889+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
32890
32891
32892 static void suni_hz(unsigned long from_timer)
32893diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
32894index 5120a96..e2572bd 100644
32895--- a/drivers/atm/uPD98402.c
32896+++ b/drivers/atm/uPD98402.c
32897@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
32898 struct sonet_stats tmp;
32899 int error = 0;
32900
32901- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
32902+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
32903 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
32904 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
32905 if (zero && !error) {
32906@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
32907
32908
32909 #define ADD_LIMITED(s,v) \
32910- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
32911- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
32912- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
32913+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
32914+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
32915+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
32916
32917
32918 static void stat_event(struct atm_dev *dev)
32919@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
32920 if (reason & uPD98402_INT_PFM) stat_event(dev);
32921 if (reason & uPD98402_INT_PCO) {
32922 (void) GET(PCOCR); /* clear interrupt cause */
32923- atomic_add(GET(HECCT),
32924+ atomic_add_unchecked(GET(HECCT),
32925 &PRIV(dev)->sonet_stats.uncorr_hcs);
32926 }
32927 if ((reason & uPD98402_INT_RFO) &&
32928@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
32929 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
32930 uPD98402_INT_LOS),PIMR); /* enable them */
32931 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
32932- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
32933- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
32934- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
32935+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
32936+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
32937+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
32938 return 0;
32939 }
32940
32941diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
32942index 969c3c2..9b72956 100644
32943--- a/drivers/atm/zatm.c
32944+++ b/drivers/atm/zatm.c
32945@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32946 }
32947 if (!size) {
32948 dev_kfree_skb_irq(skb);
32949- if (vcc) atomic_inc(&vcc->stats->rx_err);
32950+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
32951 continue;
32952 }
32953 if (!atm_charge(vcc,skb->truesize)) {
32954@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32955 skb->len = size;
32956 ATM_SKB(skb)->vcc = vcc;
32957 vcc->push(vcc,skb);
32958- atomic_inc(&vcc->stats->rx);
32959+ atomic_inc_unchecked(&vcc->stats->rx);
32960 }
32961 zout(pos & 0xffff,MTA(mbx));
32962 #if 0 /* probably a stupid idea */
32963@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
32964 skb_queue_head(&zatm_vcc->backlog,skb);
32965 break;
32966 }
32967- atomic_inc(&vcc->stats->tx);
32968+ atomic_inc_unchecked(&vcc->stats->tx);
32969 wake_up(&zatm_vcc->tx_wait);
32970 }
32971
32972diff --git a/drivers/base/bus.c b/drivers/base/bus.c
32973index 519865b..e540db3 100644
32974--- a/drivers/base/bus.c
32975+++ b/drivers/base/bus.c
32976@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
32977 return -EINVAL;
32978
32979 mutex_lock(&subsys->p->mutex);
32980- list_add_tail(&sif->node, &subsys->p->interfaces);
32981+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
32982 if (sif->add_dev) {
32983 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
32984 while ((dev = subsys_dev_iter_next(&iter)))
32985@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
32986 subsys = sif->subsys;
32987
32988 mutex_lock(&subsys->p->mutex);
32989- list_del_init(&sif->node);
32990+ pax_list_del_init((struct list_head *)&sif->node);
32991 if (sif->remove_dev) {
32992 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
32993 while ((dev = subsys_dev_iter_next(&iter)))
32994diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
32995index 01fc5b0..917801f 100644
32996--- a/drivers/base/devtmpfs.c
32997+++ b/drivers/base/devtmpfs.c
32998@@ -348,7 +348,7 @@ int devtmpfs_mount(const char *mntdir)
32999 if (!thread)
33000 return 0;
33001
33002- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
33003+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
33004 if (err)
33005 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
33006 else
33007@@ -373,11 +373,11 @@ static int devtmpfsd(void *p)
33008 *err = sys_unshare(CLONE_NEWNS);
33009 if (*err)
33010 goto out;
33011- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
33012+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
33013 if (*err)
33014 goto out;
33015- sys_chdir("/.."); /* will traverse into overmounted root */
33016- sys_chroot(".");
33017+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
33018+ sys_chroot((char __force_user *)".");
33019 complete(&setup_done);
33020 while (1) {
33021 spin_lock(&req_lock);
33022diff --git a/drivers/base/node.c b/drivers/base/node.c
33023index fac124a..66bd4ab 100644
33024--- a/drivers/base/node.c
33025+++ b/drivers/base/node.c
33026@@ -625,7 +625,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
33027 struct node_attr {
33028 struct device_attribute attr;
33029 enum node_states state;
33030-};
33031+} __do_const;
33032
33033 static ssize_t show_node_state(struct device *dev,
33034 struct device_attribute *attr, char *buf)
33035diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
33036index 9a6b05a..2fc8fb9 100644
33037--- a/drivers/base/power/domain.c
33038+++ b/drivers/base/power/domain.c
33039@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
33040 {
33041 struct cpuidle_driver *cpuidle_drv;
33042 struct gpd_cpu_data *cpu_data;
33043- struct cpuidle_state *idle_state;
33044+ cpuidle_state_no_const *idle_state;
33045 int ret = 0;
33046
33047 if (IS_ERR_OR_NULL(genpd) || state < 0)
33048@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
33049 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
33050 {
33051 struct gpd_cpu_data *cpu_data;
33052- struct cpuidle_state *idle_state;
33053+ cpuidle_state_no_const *idle_state;
33054 int ret = 0;
33055
33056 if (IS_ERR_OR_NULL(genpd))
33057diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
33058index 79715e7..df06b3b 100644
33059--- a/drivers/base/power/wakeup.c
33060+++ b/drivers/base/power/wakeup.c
33061@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
33062 * They need to be modified together atomically, so it's better to use one
33063 * atomic variable to hold them both.
33064 */
33065-static atomic_t combined_event_count = ATOMIC_INIT(0);
33066+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
33067
33068 #define IN_PROGRESS_BITS (sizeof(int) * 4)
33069 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
33070
33071 static void split_counters(unsigned int *cnt, unsigned int *inpr)
33072 {
33073- unsigned int comb = atomic_read(&combined_event_count);
33074+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
33075
33076 *cnt = (comb >> IN_PROGRESS_BITS);
33077 *inpr = comb & MAX_IN_PROGRESS;
33078@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
33079 ws->start_prevent_time = ws->last_time;
33080
33081 /* Increment the counter of events in progress. */
33082- cec = atomic_inc_return(&combined_event_count);
33083+ cec = atomic_inc_return_unchecked(&combined_event_count);
33084
33085 trace_wakeup_source_activate(ws->name, cec);
33086 }
33087@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
33088 * Increment the counter of registered wakeup events and decrement the
33089 * couter of wakeup events in progress simultaneously.
33090 */
33091- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
33092+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
33093 trace_wakeup_source_deactivate(ws->name, cec);
33094
33095 split_counters(&cnt, &inpr);
33096diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
33097index e8d11b6..7b1b36f 100644
33098--- a/drivers/base/syscore.c
33099+++ b/drivers/base/syscore.c
33100@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
33101 void register_syscore_ops(struct syscore_ops *ops)
33102 {
33103 mutex_lock(&syscore_ops_lock);
33104- list_add_tail(&ops->node, &syscore_ops_list);
33105+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
33106 mutex_unlock(&syscore_ops_lock);
33107 }
33108 EXPORT_SYMBOL_GPL(register_syscore_ops);
33109@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
33110 void unregister_syscore_ops(struct syscore_ops *ops)
33111 {
33112 mutex_lock(&syscore_ops_lock);
33113- list_del(&ops->node);
33114+ pax_list_del((struct list_head *)&ops->node);
33115 mutex_unlock(&syscore_ops_lock);
33116 }
33117 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
33118diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
33119index 1c1b8e5..b7fc681 100644
33120--- a/drivers/block/cciss.c
33121+++ b/drivers/block/cciss.c
33122@@ -1196,6 +1196,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
33123 int err;
33124 u32 cp;
33125
33126+ memset(&arg64, 0, sizeof(arg64));
33127+
33128 err = 0;
33129 err |=
33130 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
33131@@ -3005,7 +3007,7 @@ static void start_io(ctlr_info_t *h)
33132 while (!list_empty(&h->reqQ)) {
33133 c = list_entry(h->reqQ.next, CommandList_struct, list);
33134 /* can't do anything if fifo is full */
33135- if ((h->access.fifo_full(h))) {
33136+ if ((h->access->fifo_full(h))) {
33137 dev_warn(&h->pdev->dev, "fifo full\n");
33138 break;
33139 }
33140@@ -3015,7 +3017,7 @@ static void start_io(ctlr_info_t *h)
33141 h->Qdepth--;
33142
33143 /* Tell the controller execute command */
33144- h->access.submit_command(h, c);
33145+ h->access->submit_command(h, c);
33146
33147 /* Put job onto the completed Q */
33148 addQ(&h->cmpQ, c);
33149@@ -3441,17 +3443,17 @@ startio:
33150
33151 static inline unsigned long get_next_completion(ctlr_info_t *h)
33152 {
33153- return h->access.command_completed(h);
33154+ return h->access->command_completed(h);
33155 }
33156
33157 static inline int interrupt_pending(ctlr_info_t *h)
33158 {
33159- return h->access.intr_pending(h);
33160+ return h->access->intr_pending(h);
33161 }
33162
33163 static inline long interrupt_not_for_us(ctlr_info_t *h)
33164 {
33165- return ((h->access.intr_pending(h) == 0) ||
33166+ return ((h->access->intr_pending(h) == 0) ||
33167 (h->interrupts_enabled == 0));
33168 }
33169
33170@@ -3484,7 +3486,7 @@ static inline u32 next_command(ctlr_info_t *h)
33171 u32 a;
33172
33173 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
33174- return h->access.command_completed(h);
33175+ return h->access->command_completed(h);
33176
33177 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
33178 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
33179@@ -4041,7 +4043,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
33180 trans_support & CFGTBL_Trans_use_short_tags);
33181
33182 /* Change the access methods to the performant access methods */
33183- h->access = SA5_performant_access;
33184+ h->access = &SA5_performant_access;
33185 h->transMethod = CFGTBL_Trans_Performant;
33186
33187 return;
33188@@ -4310,7 +4312,7 @@ static int cciss_pci_init(ctlr_info_t *h)
33189 if (prod_index < 0)
33190 return -ENODEV;
33191 h->product_name = products[prod_index].product_name;
33192- h->access = *(products[prod_index].access);
33193+ h->access = products[prod_index].access;
33194
33195 if (cciss_board_disabled(h)) {
33196 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
33197@@ -5032,7 +5034,7 @@ reinit_after_soft_reset:
33198 }
33199
33200 /* make sure the board interrupts are off */
33201- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33202+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33203 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
33204 if (rc)
33205 goto clean2;
33206@@ -5082,7 +5084,7 @@ reinit_after_soft_reset:
33207 * fake ones to scoop up any residual completions.
33208 */
33209 spin_lock_irqsave(&h->lock, flags);
33210- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33211+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33212 spin_unlock_irqrestore(&h->lock, flags);
33213 free_irq(h->intr[h->intr_mode], h);
33214 rc = cciss_request_irq(h, cciss_msix_discard_completions,
33215@@ -5102,9 +5104,9 @@ reinit_after_soft_reset:
33216 dev_info(&h->pdev->dev, "Board READY.\n");
33217 dev_info(&h->pdev->dev,
33218 "Waiting for stale completions to drain.\n");
33219- h->access.set_intr_mask(h, CCISS_INTR_ON);
33220+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33221 msleep(10000);
33222- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33223+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33224
33225 rc = controller_reset_failed(h->cfgtable);
33226 if (rc)
33227@@ -5127,7 +5129,7 @@ reinit_after_soft_reset:
33228 cciss_scsi_setup(h);
33229
33230 /* Turn the interrupts on so we can service requests */
33231- h->access.set_intr_mask(h, CCISS_INTR_ON);
33232+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33233
33234 /* Get the firmware version */
33235 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
33236@@ -5199,7 +5201,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
33237 kfree(flush_buf);
33238 if (return_code != IO_OK)
33239 dev_warn(&h->pdev->dev, "Error flushing cache\n");
33240- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33241+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33242 free_irq(h->intr[h->intr_mode], h);
33243 }
33244
33245diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
33246index 7fda30e..eb5dfe0 100644
33247--- a/drivers/block/cciss.h
33248+++ b/drivers/block/cciss.h
33249@@ -101,7 +101,7 @@ struct ctlr_info
33250 /* information about each logical volume */
33251 drive_info_struct *drv[CISS_MAX_LUN];
33252
33253- struct access_method access;
33254+ struct access_method *access;
33255
33256 /* queue and queue Info */
33257 struct list_head reqQ;
33258diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
33259index 3f08713..87d4b4a 100644
33260--- a/drivers/block/cpqarray.c
33261+++ b/drivers/block/cpqarray.c
33262@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33263 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
33264 goto Enomem4;
33265 }
33266- hba[i]->access.set_intr_mask(hba[i], 0);
33267+ hba[i]->access->set_intr_mask(hba[i], 0);
33268 if (request_irq(hba[i]->intr, do_ida_intr,
33269 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
33270 {
33271@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33272 add_timer(&hba[i]->timer);
33273
33274 /* Enable IRQ now that spinlock and rate limit timer are set up */
33275- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33276+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33277
33278 for(j=0; j<NWD; j++) {
33279 struct gendisk *disk = ida_gendisk[i][j];
33280@@ -694,7 +694,7 @@ DBGINFO(
33281 for(i=0; i<NR_PRODUCTS; i++) {
33282 if (board_id == products[i].board_id) {
33283 c->product_name = products[i].product_name;
33284- c->access = *(products[i].access);
33285+ c->access = products[i].access;
33286 break;
33287 }
33288 }
33289@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
33290 hba[ctlr]->intr = intr;
33291 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
33292 hba[ctlr]->product_name = products[j].product_name;
33293- hba[ctlr]->access = *(products[j].access);
33294+ hba[ctlr]->access = products[j].access;
33295 hba[ctlr]->ctlr = ctlr;
33296 hba[ctlr]->board_id = board_id;
33297 hba[ctlr]->pci_dev = NULL; /* not PCI */
33298@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
33299
33300 while((c = h->reqQ) != NULL) {
33301 /* Can't do anything if we're busy */
33302- if (h->access.fifo_full(h) == 0)
33303+ if (h->access->fifo_full(h) == 0)
33304 return;
33305
33306 /* Get the first entry from the request Q */
33307@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
33308 h->Qdepth--;
33309
33310 /* Tell the controller to do our bidding */
33311- h->access.submit_command(h, c);
33312+ h->access->submit_command(h, c);
33313
33314 /* Get onto the completion Q */
33315 addQ(&h->cmpQ, c);
33316@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33317 unsigned long flags;
33318 __u32 a,a1;
33319
33320- istat = h->access.intr_pending(h);
33321+ istat = h->access->intr_pending(h);
33322 /* Is this interrupt for us? */
33323 if (istat == 0)
33324 return IRQ_NONE;
33325@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33326 */
33327 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
33328 if (istat & FIFO_NOT_EMPTY) {
33329- while((a = h->access.command_completed(h))) {
33330+ while((a = h->access->command_completed(h))) {
33331 a1 = a; a &= ~3;
33332 if ((c = h->cmpQ) == NULL)
33333 {
33334@@ -1195,6 +1195,7 @@ out_passthru:
33335 ida_pci_info_struct pciinfo;
33336
33337 if (!arg) return -EINVAL;
33338+ memset(&pciinfo, 0, sizeof(pciinfo));
33339 pciinfo.bus = host->pci_dev->bus->number;
33340 pciinfo.dev_fn = host->pci_dev->devfn;
33341 pciinfo.board_id = host->board_id;
33342@@ -1449,11 +1450,11 @@ static int sendcmd(
33343 /*
33344 * Disable interrupt
33345 */
33346- info_p->access.set_intr_mask(info_p, 0);
33347+ info_p->access->set_intr_mask(info_p, 0);
33348 /* Make sure there is room in the command FIFO */
33349 /* Actually it should be completely empty at this time. */
33350 for (i = 200000; i > 0; i--) {
33351- temp = info_p->access.fifo_full(info_p);
33352+ temp = info_p->access->fifo_full(info_p);
33353 if (temp != 0) {
33354 break;
33355 }
33356@@ -1466,7 +1467,7 @@ DBG(
33357 /*
33358 * Send the cmd
33359 */
33360- info_p->access.submit_command(info_p, c);
33361+ info_p->access->submit_command(info_p, c);
33362 complete = pollcomplete(ctlr);
33363
33364 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
33365@@ -1549,9 +1550,9 @@ static int revalidate_allvol(ctlr_info_t *host)
33366 * we check the new geometry. Then turn interrupts back on when
33367 * we're done.
33368 */
33369- host->access.set_intr_mask(host, 0);
33370+ host->access->set_intr_mask(host, 0);
33371 getgeometry(ctlr);
33372- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
33373+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
33374
33375 for(i=0; i<NWD; i++) {
33376 struct gendisk *disk = ida_gendisk[ctlr][i];
33377@@ -1591,7 +1592,7 @@ static int pollcomplete(int ctlr)
33378 /* Wait (up to 2 seconds) for a command to complete */
33379
33380 for (i = 200000; i > 0; i--) {
33381- done = hba[ctlr]->access.command_completed(hba[ctlr]);
33382+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
33383 if (done == 0) {
33384 udelay(10); /* a short fixed delay */
33385 } else
33386diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
33387index be73e9d..7fbf140 100644
33388--- a/drivers/block/cpqarray.h
33389+++ b/drivers/block/cpqarray.h
33390@@ -99,7 +99,7 @@ struct ctlr_info {
33391 drv_info_t drv[NWD];
33392 struct proc_dir_entry *proc;
33393
33394- struct access_method access;
33395+ struct access_method *access;
33396
33397 cmdlist_t *reqQ;
33398 cmdlist_t *cmpQ;
33399diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
33400index 6b51afa..17e1191 100644
33401--- a/drivers/block/drbd/drbd_int.h
33402+++ b/drivers/block/drbd/drbd_int.h
33403@@ -582,7 +582,7 @@ struct drbd_epoch {
33404 struct drbd_tconn *tconn;
33405 struct list_head list;
33406 unsigned int barrier_nr;
33407- atomic_t epoch_size; /* increased on every request added. */
33408+ atomic_unchecked_t epoch_size; /* increased on every request added. */
33409 atomic_t active; /* increased on every req. added, and dec on every finished. */
33410 unsigned long flags;
33411 };
33412@@ -1011,7 +1011,7 @@ struct drbd_conf {
33413 int al_tr_cycle;
33414 int al_tr_pos; /* position of the next transaction in the journal */
33415 wait_queue_head_t seq_wait;
33416- atomic_t packet_seq;
33417+ atomic_unchecked_t packet_seq;
33418 unsigned int peer_seq;
33419 spinlock_t peer_seq_lock;
33420 unsigned int minor;
33421@@ -1527,7 +1527,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
33422 char __user *uoptval;
33423 int err;
33424
33425- uoptval = (char __user __force *)optval;
33426+ uoptval = (char __force_user *)optval;
33427
33428 set_fs(KERNEL_DS);
33429 if (level == SOL_SOCKET)
33430diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
33431index 54d03d4..332f311 100644
33432--- a/drivers/block/drbd/drbd_main.c
33433+++ b/drivers/block/drbd/drbd_main.c
33434@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
33435 p->sector = sector;
33436 p->block_id = block_id;
33437 p->blksize = blksize;
33438- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33439+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33440 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
33441 }
33442
33443@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
33444 return -EIO;
33445 p->sector = cpu_to_be64(req->i.sector);
33446 p->block_id = (unsigned long)req;
33447- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33448+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33449 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
33450 if (mdev->state.conn >= C_SYNC_SOURCE &&
33451 mdev->state.conn <= C_PAUSED_SYNC_T)
33452@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
33453 {
33454 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
33455
33456- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
33457- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
33458+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
33459+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
33460 kfree(tconn->current_epoch);
33461
33462 idr_destroy(&tconn->volumes);
33463diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
33464index 2f5fffd..b22a1ae 100644
33465--- a/drivers/block/drbd/drbd_receiver.c
33466+++ b/drivers/block/drbd/drbd_receiver.c
33467@@ -833,7 +833,7 @@ int drbd_connected(struct drbd_conf *mdev)
33468 {
33469 int err;
33470
33471- atomic_set(&mdev->packet_seq, 0);
33472+ atomic_set_unchecked(&mdev->packet_seq, 0);
33473 mdev->peer_seq = 0;
33474
33475 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
33476@@ -1191,7 +1191,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33477 do {
33478 next_epoch = NULL;
33479
33480- epoch_size = atomic_read(&epoch->epoch_size);
33481+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
33482
33483 switch (ev & ~EV_CLEANUP) {
33484 case EV_PUT:
33485@@ -1231,7 +1231,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33486 rv = FE_DESTROYED;
33487 } else {
33488 epoch->flags = 0;
33489- atomic_set(&epoch->epoch_size, 0);
33490+ atomic_set_unchecked(&epoch->epoch_size, 0);
33491 /* atomic_set(&epoch->active, 0); is already zero */
33492 if (rv == FE_STILL_LIVE)
33493 rv = FE_RECYCLED;
33494@@ -1449,7 +1449,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33495 conn_wait_active_ee_empty(tconn);
33496 drbd_flush(tconn);
33497
33498- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33499+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33500 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
33501 if (epoch)
33502 break;
33503@@ -1462,11 +1462,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33504 }
33505
33506 epoch->flags = 0;
33507- atomic_set(&epoch->epoch_size, 0);
33508+ atomic_set_unchecked(&epoch->epoch_size, 0);
33509 atomic_set(&epoch->active, 0);
33510
33511 spin_lock(&tconn->epoch_lock);
33512- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33513+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33514 list_add(&epoch->list, &tconn->current_epoch->list);
33515 tconn->current_epoch = epoch;
33516 tconn->epochs++;
33517@@ -2170,7 +2170,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33518
33519 err = wait_for_and_update_peer_seq(mdev, peer_seq);
33520 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
33521- atomic_inc(&tconn->current_epoch->epoch_size);
33522+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
33523 err2 = drbd_drain_block(mdev, pi->size);
33524 if (!err)
33525 err = err2;
33526@@ -2204,7 +2204,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33527
33528 spin_lock(&tconn->epoch_lock);
33529 peer_req->epoch = tconn->current_epoch;
33530- atomic_inc(&peer_req->epoch->epoch_size);
33531+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
33532 atomic_inc(&peer_req->epoch->active);
33533 spin_unlock(&tconn->epoch_lock);
33534
33535@@ -4345,7 +4345,7 @@ struct data_cmd {
33536 int expect_payload;
33537 size_t pkt_size;
33538 int (*fn)(struct drbd_tconn *, struct packet_info *);
33539-};
33540+} __do_const;
33541
33542 static struct data_cmd drbd_cmd_handler[] = {
33543 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
33544@@ -4465,7 +4465,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
33545 if (!list_empty(&tconn->current_epoch->list))
33546 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
33547 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
33548- atomic_set(&tconn->current_epoch->epoch_size, 0);
33549+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
33550 tconn->send.seen_any_write_yet = false;
33551
33552 conn_info(tconn, "Connection closed\n");
33553@@ -5221,7 +5221,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
33554 struct asender_cmd {
33555 size_t pkt_size;
33556 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
33557-};
33558+} __do_const;
33559
33560 static struct asender_cmd asender_tbl[] = {
33561 [P_PING] = { 0, got_Ping },
33562diff --git a/drivers/block/loop.c b/drivers/block/loop.c
33563index dfe7583..83768bb 100644
33564--- a/drivers/block/loop.c
33565+++ b/drivers/block/loop.c
33566@@ -231,7 +231,7 @@ static int __do_lo_send_write(struct file *file,
33567 mm_segment_t old_fs = get_fs();
33568
33569 set_fs(get_ds());
33570- bw = file->f_op->write(file, buf, len, &pos);
33571+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
33572 set_fs(old_fs);
33573 if (likely(bw == len))
33574 return 0;
33575diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
33576index 2e7de7a..ed86dc0 100644
33577--- a/drivers/block/pktcdvd.c
33578+++ b/drivers/block/pktcdvd.c
33579@@ -83,7 +83,7 @@
33580
33581 #define MAX_SPEED 0xffff
33582
33583-#define ZONE(sector, pd) (((sector) + (pd)->offset) & ~((pd)->settings.size - 1))
33584+#define ZONE(sector, pd) (((sector) + (pd)->offset) & ~((pd)->settings.size - 1UL))
33585
33586 static DEFINE_MUTEX(pktcdvd_mutex);
33587 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
33588diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
33589index d620b44..e9abc80 100644
33590--- a/drivers/cdrom/cdrom.c
33591+++ b/drivers/cdrom/cdrom.c
33592@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
33593 ENSURE(reset, CDC_RESET);
33594 ENSURE(generic_packet, CDC_GENERIC_PACKET);
33595 cdi->mc_flags = 0;
33596- cdo->n_minors = 0;
33597 cdi->options = CDO_USE_FFLAGS;
33598
33599 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
33600@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
33601 else
33602 cdi->cdda_method = CDDA_OLD;
33603
33604- if (!cdo->generic_packet)
33605- cdo->generic_packet = cdrom_dummy_generic_packet;
33606+ if (!cdo->generic_packet) {
33607+ pax_open_kernel();
33608+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
33609+ pax_close_kernel();
33610+ }
33611
33612 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
33613 mutex_lock(&cdrom_mutex);
33614@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
33615 if (cdi->exit)
33616 cdi->exit(cdi);
33617
33618- cdi->ops->n_minors--;
33619 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
33620 }
33621
33622@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
33623 */
33624 nr = nframes;
33625 do {
33626- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
33627+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
33628 if (cgc.buffer)
33629 break;
33630
33631@@ -2882,7 +2883,7 @@ static noinline int mmc_ioctl_cdrom_read_data(struct cdrom_device_info *cdi,
33632 if (lba < 0)
33633 return -EINVAL;
33634
33635- cgc->buffer = kmalloc(blocksize, GFP_KERNEL);
33636+ cgc->buffer = kzalloc(blocksize, GFP_KERNEL);
33637 if (cgc->buffer == NULL)
33638 return -ENOMEM;
33639
33640diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
33641index d59cdcb..11afddf 100644
33642--- a/drivers/cdrom/gdrom.c
33643+++ b/drivers/cdrom/gdrom.c
33644@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
33645 .audio_ioctl = gdrom_audio_ioctl,
33646 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
33647 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
33648- .n_minors = 1,
33649 };
33650
33651 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
33652diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
33653index 3bb6fa3..34013fb 100644
33654--- a/drivers/char/Kconfig
33655+++ b/drivers/char/Kconfig
33656@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
33657
33658 config DEVKMEM
33659 bool "/dev/kmem virtual device support"
33660- default y
33661+ default n
33662+ depends on !GRKERNSEC_KMEM
33663 help
33664 Say Y here if you want to support the /dev/kmem device. The
33665 /dev/kmem device is rarely used, but can be used for certain
33666@@ -582,6 +583,7 @@ config DEVPORT
33667 bool
33668 depends on !M68K
33669 depends on ISA || PCI
33670+ depends on !GRKERNSEC_KMEM
33671 default y
33672
33673 source "drivers/s390/char/Kconfig"
33674diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
33675index a48e05b..6bac831 100644
33676--- a/drivers/char/agp/compat_ioctl.c
33677+++ b/drivers/char/agp/compat_ioctl.c
33678@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
33679 return -ENOMEM;
33680 }
33681
33682- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
33683+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
33684 sizeof(*usegment) * ureserve.seg_count)) {
33685 kfree(usegment);
33686 kfree(ksegment);
33687diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
33688index 2e04433..771f2cc 100644
33689--- a/drivers/char/agp/frontend.c
33690+++ b/drivers/char/agp/frontend.c
33691@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
33692 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
33693 return -EFAULT;
33694
33695- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
33696+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
33697 return -EFAULT;
33698
33699 client = agp_find_client_by_pid(reserve.pid);
33700@@ -847,7 +847,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
33701 if (segment == NULL)
33702 return -ENOMEM;
33703
33704- if (copy_from_user(segment, (void __user *) reserve.seg_list,
33705+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
33706 sizeof(struct agp_segment) * reserve.seg_count)) {
33707 kfree(segment);
33708 return -EFAULT;
33709diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
33710index 21cb980..f15107c 100644
33711--- a/drivers/char/genrtc.c
33712+++ b/drivers/char/genrtc.c
33713@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
33714 switch (cmd) {
33715
33716 case RTC_PLL_GET:
33717+ memset(&pll, 0, sizeof(pll));
33718 if (get_rtc_pll(&pll))
33719 return -EINVAL;
33720 else
33721diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
33722index d784650..e8bfd69 100644
33723--- a/drivers/char/hpet.c
33724+++ b/drivers/char/hpet.c
33725@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
33726 }
33727
33728 static int
33729-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
33730+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
33731 struct hpet_info *info)
33732 {
33733 struct hpet_timer __iomem *timer;
33734diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
33735index 053201b0..8335cce 100644
33736--- a/drivers/char/ipmi/ipmi_msghandler.c
33737+++ b/drivers/char/ipmi/ipmi_msghandler.c
33738@@ -420,7 +420,7 @@ struct ipmi_smi {
33739 struct proc_dir_entry *proc_dir;
33740 char proc_dir_name[10];
33741
33742- atomic_t stats[IPMI_NUM_STATS];
33743+ atomic_unchecked_t stats[IPMI_NUM_STATS];
33744
33745 /*
33746 * run_to_completion duplicate of smb_info, smi_info
33747@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
33748
33749
33750 #define ipmi_inc_stat(intf, stat) \
33751- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
33752+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
33753 #define ipmi_get_stat(intf, stat) \
33754- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
33755+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
33756
33757 static int is_lan_addr(struct ipmi_addr *addr)
33758 {
33759@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
33760 INIT_LIST_HEAD(&intf->cmd_rcvrs);
33761 init_waitqueue_head(&intf->waitq);
33762 for (i = 0; i < IPMI_NUM_STATS; i++)
33763- atomic_set(&intf->stats[i], 0);
33764+ atomic_set_unchecked(&intf->stats[i], 0);
33765
33766 intf->proc_dir = NULL;
33767
33768diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
33769index 0ac9b45..6179fb5 100644
33770--- a/drivers/char/ipmi/ipmi_si_intf.c
33771+++ b/drivers/char/ipmi/ipmi_si_intf.c
33772@@ -275,7 +275,7 @@ struct smi_info {
33773 unsigned char slave_addr;
33774
33775 /* Counters and things for the proc filesystem. */
33776- atomic_t stats[SI_NUM_STATS];
33777+ atomic_unchecked_t stats[SI_NUM_STATS];
33778
33779 struct task_struct *thread;
33780
33781@@ -284,9 +284,9 @@ struct smi_info {
33782 };
33783
33784 #define smi_inc_stat(smi, stat) \
33785- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
33786+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
33787 #define smi_get_stat(smi, stat) \
33788- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
33789+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
33790
33791 #define SI_MAX_PARMS 4
33792
33793@@ -3254,7 +3254,7 @@ static int try_smi_init(struct smi_info *new_smi)
33794 atomic_set(&new_smi->req_events, 0);
33795 new_smi->run_to_completion = 0;
33796 for (i = 0; i < SI_NUM_STATS; i++)
33797- atomic_set(&new_smi->stats[i], 0);
33798+ atomic_set_unchecked(&new_smi->stats[i], 0);
33799
33800 new_smi->interrupt_disabled = 1;
33801 atomic_set(&new_smi->stop_operation, 0);
33802diff --git a/drivers/char/mem.c b/drivers/char/mem.c
33803index 2c644af..d4d7f17 100644
33804--- a/drivers/char/mem.c
33805+++ b/drivers/char/mem.c
33806@@ -18,6 +18,7 @@
33807 #include <linux/raw.h>
33808 #include <linux/tty.h>
33809 #include <linux/capability.h>
33810+#include <linux/security.h>
33811 #include <linux/ptrace.h>
33812 #include <linux/device.h>
33813 #include <linux/highmem.h>
33814@@ -37,6 +38,10 @@
33815
33816 #define DEVPORT_MINOR 4
33817
33818+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
33819+extern const struct file_operations grsec_fops;
33820+#endif
33821+
33822 static inline unsigned long size_inside_page(unsigned long start,
33823 unsigned long size)
33824 {
33825@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33826
33827 while (cursor < to) {
33828 if (!devmem_is_allowed(pfn)) {
33829+#ifdef CONFIG_GRKERNSEC_KMEM
33830+ gr_handle_mem_readwrite(from, to);
33831+#else
33832 printk(KERN_INFO
33833 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
33834 current->comm, from, to);
33835+#endif
33836 return 0;
33837 }
33838 cursor += PAGE_SIZE;
33839@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33840 }
33841 return 1;
33842 }
33843+#elif defined(CONFIG_GRKERNSEC_KMEM)
33844+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33845+{
33846+ return 0;
33847+}
33848 #else
33849 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33850 {
33851@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
33852
33853 while (count > 0) {
33854 unsigned long remaining;
33855+ char *temp;
33856
33857 sz = size_inside_page(p, count);
33858
33859@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
33860 if (!ptr)
33861 return -EFAULT;
33862
33863- remaining = copy_to_user(buf, ptr, sz);
33864+#ifdef CONFIG_PAX_USERCOPY
33865+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
33866+ if (!temp) {
33867+ unxlate_dev_mem_ptr(p, ptr);
33868+ return -ENOMEM;
33869+ }
33870+ memcpy(temp, ptr, sz);
33871+#else
33872+ temp = ptr;
33873+#endif
33874+
33875+ remaining = copy_to_user(buf, temp, sz);
33876+
33877+#ifdef CONFIG_PAX_USERCOPY
33878+ kfree(temp);
33879+#endif
33880+
33881 unxlate_dev_mem_ptr(p, ptr);
33882 if (remaining)
33883 return -EFAULT;
33884@@ -378,7 +409,7 @@ static ssize_t read_oldmem(struct file *file, char __user *buf,
33885 else
33886 csize = count;
33887
33888- rc = copy_oldmem_page(pfn, buf, csize, offset, 1);
33889+ rc = copy_oldmem_page(pfn, (char __force_kernel *)buf, csize, offset, 1);
33890 if (rc < 0)
33891 return rc;
33892 buf += csize;
33893@@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33894 size_t count, loff_t *ppos)
33895 {
33896 unsigned long p = *ppos;
33897- ssize_t low_count, read, sz;
33898+ ssize_t low_count, read, sz, err = 0;
33899 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
33900- int err = 0;
33901
33902 read = 0;
33903 if (p < (unsigned long) high_memory) {
33904@@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33905 }
33906 #endif
33907 while (low_count > 0) {
33908+ char *temp;
33909+
33910 sz = size_inside_page(p, low_count);
33911
33912 /*
33913@@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33914 */
33915 kbuf = xlate_dev_kmem_ptr((char *)p);
33916
33917- if (copy_to_user(buf, kbuf, sz))
33918+#ifdef CONFIG_PAX_USERCOPY
33919+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
33920+ if (!temp)
33921+ return -ENOMEM;
33922+ memcpy(temp, kbuf, sz);
33923+#else
33924+ temp = kbuf;
33925+#endif
33926+
33927+ err = copy_to_user(buf, temp, sz);
33928+
33929+#ifdef CONFIG_PAX_USERCOPY
33930+ kfree(temp);
33931+#endif
33932+
33933+ if (err)
33934 return -EFAULT;
33935 buf += sz;
33936 p += sz;
33937@@ -833,6 +880,9 @@ static const struct memdev {
33938 #ifdef CONFIG_CRASH_DUMP
33939 [12] = { "oldmem", 0, &oldmem_fops, NULL },
33940 #endif
33941+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
33942+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
33943+#endif
33944 };
33945
33946 static int memory_open(struct inode *inode, struct file *filp)
33947diff --git a/drivers/char/mwave/tp3780i.c b/drivers/char/mwave/tp3780i.c
33948index c689697..04e6d6a 100644
33949--- a/drivers/char/mwave/tp3780i.c
33950+++ b/drivers/char/mwave/tp3780i.c
33951@@ -479,6 +479,7 @@ int tp3780I_QueryAbilities(THINKPAD_BD_DATA * pBDData, MW_ABILITIES * pAbilities
33952 PRINTK_2(TRACE_TP3780I,
33953 "tp3780i::tp3780I_QueryAbilities entry pBDData %p\n", pBDData);
33954
33955+ memset(pAbilities, 0, sizeof(*pAbilities));
33956 /* fill out standard constant fields */
33957 pAbilities->instr_per_sec = pBDData->rDspSettings.uIps;
33958 pAbilities->data_size = pBDData->rDspSettings.uDStoreSize;
33959diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
33960index 9df78e2..01ba9ae 100644
33961--- a/drivers/char/nvram.c
33962+++ b/drivers/char/nvram.c
33963@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
33964
33965 spin_unlock_irq(&rtc_lock);
33966
33967- if (copy_to_user(buf, contents, tmp - contents))
33968+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
33969 return -EFAULT;
33970
33971 *ppos = i;
33972diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
33973index 5c5cc00..ac9edb7 100644
33974--- a/drivers/char/pcmcia/synclink_cs.c
33975+++ b/drivers/char/pcmcia/synclink_cs.c
33976@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
33977
33978 if (debug_level >= DEBUG_LEVEL_INFO)
33979 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
33980- __FILE__, __LINE__, info->device_name, port->count);
33981+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
33982
33983- WARN_ON(!port->count);
33984+ WARN_ON(!atomic_read(&port->count));
33985
33986 if (tty_port_close_start(port, tty, filp) == 0)
33987 goto cleanup;
33988@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
33989 cleanup:
33990 if (debug_level >= DEBUG_LEVEL_INFO)
33991 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
33992- tty->driver->name, port->count);
33993+ tty->driver->name, atomic_read(&port->count));
33994 }
33995
33996 /* Wait until the transmitter is empty.
33997@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
33998
33999 if (debug_level >= DEBUG_LEVEL_INFO)
34000 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
34001- __FILE__, __LINE__, tty->driver->name, port->count);
34002+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
34003
34004 /* If port is closing, signal caller to try again */
34005 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
34006@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
34007 goto cleanup;
34008 }
34009 spin_lock(&port->lock);
34010- port->count++;
34011+ atomic_inc(&port->count);
34012 spin_unlock(&port->lock);
34013 spin_unlock_irqrestore(&info->netlock, flags);
34014
34015- if (port->count == 1) {
34016+ if (atomic_read(&port->count) == 1) {
34017 /* 1st open on this device, init hardware */
34018 retval = startup(info, tty);
34019 if (retval < 0)
34020@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
34021 unsigned short new_crctype;
34022
34023 /* return error if TTY interface open */
34024- if (info->port.count)
34025+ if (atomic_read(&info->port.count))
34026 return -EBUSY;
34027
34028 switch (encoding)
34029@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
34030
34031 /* arbitrate between network and tty opens */
34032 spin_lock_irqsave(&info->netlock, flags);
34033- if (info->port.count != 0 || info->netcount != 0) {
34034+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
34035 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
34036 spin_unlock_irqrestore(&info->netlock, flags);
34037 return -EBUSY;
34038@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34039 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
34040
34041 /* return error if TTY interface open */
34042- if (info->port.count)
34043+ if (atomic_read(&info->port.count))
34044 return -EBUSY;
34045
34046 if (cmd != SIOCWANDEV)
34047diff --git a/drivers/char/random.c b/drivers/char/random.c
34048index eccd7cc..98038d5 100644
34049--- a/drivers/char/random.c
34050+++ b/drivers/char/random.c
34051@@ -272,8 +272,13 @@
34052 /*
34053 * Configuration information
34054 */
34055+#ifdef CONFIG_GRKERNSEC_RANDNET
34056+#define INPUT_POOL_WORDS 512
34057+#define OUTPUT_POOL_WORDS 128
34058+#else
34059 #define INPUT_POOL_WORDS 128
34060 #define OUTPUT_POOL_WORDS 32
34061+#endif
34062 #define SEC_XFER_SIZE 512
34063 #define EXTRACT_SIZE 10
34064
34065@@ -313,10 +318,17 @@ static struct poolinfo {
34066 int poolwords;
34067 int tap1, tap2, tap3, tap4, tap5;
34068 } poolinfo_table[] = {
34069+#ifdef CONFIG_GRKERNSEC_RANDNET
34070+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
34071+ { 512, 411, 308, 208, 104, 1 },
34072+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
34073+ { 128, 103, 76, 51, 25, 1 },
34074+#else
34075 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
34076 { 128, 103, 76, 51, 25, 1 },
34077 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
34078 { 32, 26, 20, 14, 7, 1 },
34079+#endif
34080 #if 0
34081 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
34082 { 2048, 1638, 1231, 819, 411, 1 },
34083@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
34084 input_rotate += i ? 7 : 14;
34085 }
34086
34087- ACCESS_ONCE(r->input_rotate) = input_rotate;
34088- ACCESS_ONCE(r->add_ptr) = i;
34089+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
34090+ ACCESS_ONCE_RW(r->add_ptr) = i;
34091 smp_wmb();
34092
34093 if (out)
34094@@ -1032,7 +1044,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
34095
34096 extract_buf(r, tmp);
34097 i = min_t(int, nbytes, EXTRACT_SIZE);
34098- if (copy_to_user(buf, tmp, i)) {
34099+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
34100 ret = -EFAULT;
34101 break;
34102 }
34103@@ -1368,7 +1380,7 @@ EXPORT_SYMBOL(generate_random_uuid);
34104 #include <linux/sysctl.h>
34105
34106 static int min_read_thresh = 8, min_write_thresh;
34107-static int max_read_thresh = INPUT_POOL_WORDS * 32;
34108+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
34109 static int max_write_thresh = INPUT_POOL_WORDS * 32;
34110 static char sysctl_bootid[16];
34111
34112@@ -1384,7 +1396,7 @@ static char sysctl_bootid[16];
34113 static int proc_do_uuid(ctl_table *table, int write,
34114 void __user *buffer, size_t *lenp, loff_t *ppos)
34115 {
34116- ctl_table fake_table;
34117+ ctl_table_no_const fake_table;
34118 unsigned char buf[64], tmp_uuid[16], *uuid;
34119
34120 uuid = table->data;
34121diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
34122index bf2349db..5456d53 100644
34123--- a/drivers/char/sonypi.c
34124+++ b/drivers/char/sonypi.c
34125@@ -54,6 +54,7 @@
34126
34127 #include <asm/uaccess.h>
34128 #include <asm/io.h>
34129+#include <asm/local.h>
34130
34131 #include <linux/sonypi.h>
34132
34133@@ -490,7 +491,7 @@ static struct sonypi_device {
34134 spinlock_t fifo_lock;
34135 wait_queue_head_t fifo_proc_list;
34136 struct fasync_struct *fifo_async;
34137- int open_count;
34138+ local_t open_count;
34139 int model;
34140 struct input_dev *input_jog_dev;
34141 struct input_dev *input_key_dev;
34142@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
34143 static int sonypi_misc_release(struct inode *inode, struct file *file)
34144 {
34145 mutex_lock(&sonypi_device.lock);
34146- sonypi_device.open_count--;
34147+ local_dec(&sonypi_device.open_count);
34148 mutex_unlock(&sonypi_device.lock);
34149 return 0;
34150 }
34151@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
34152 {
34153 mutex_lock(&sonypi_device.lock);
34154 /* Flush input queue on first open */
34155- if (!sonypi_device.open_count)
34156+ if (!local_read(&sonypi_device.open_count))
34157 kfifo_reset(&sonypi_device.fifo);
34158- sonypi_device.open_count++;
34159+ local_inc(&sonypi_device.open_count);
34160 mutex_unlock(&sonypi_device.lock);
34161
34162 return 0;
34163diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
34164index 64420b3..5c40b56 100644
34165--- a/drivers/char/tpm/tpm_acpi.c
34166+++ b/drivers/char/tpm/tpm_acpi.c
34167@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
34168 virt = acpi_os_map_memory(start, len);
34169 if (!virt) {
34170 kfree(log->bios_event_log);
34171+ log->bios_event_log = NULL;
34172 printk("%s: ERROR - Unable to map memory\n", __func__);
34173 return -EIO;
34174 }
34175
34176- memcpy_fromio(log->bios_event_log, virt, len);
34177+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
34178
34179 acpi_os_unmap_memory(virt, len);
34180 return 0;
34181diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
34182index 84ddc55..1d32f1e 100644
34183--- a/drivers/char/tpm/tpm_eventlog.c
34184+++ b/drivers/char/tpm/tpm_eventlog.c
34185@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
34186 event = addr;
34187
34188 if ((event->event_type == 0 && event->event_size == 0) ||
34189- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
34190+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
34191 return NULL;
34192
34193 return addr;
34194@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
34195 return NULL;
34196
34197 if ((event->event_type == 0 && event->event_size == 0) ||
34198- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
34199+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
34200 return NULL;
34201
34202 (*pos)++;
34203@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
34204 int i;
34205
34206 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
34207- seq_putc(m, data[i]);
34208+ if (!seq_putc(m, data[i]))
34209+ return -EFAULT;
34210
34211 return 0;
34212 }
34213diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
34214index ce5f3fc..e2d3e55 100644
34215--- a/drivers/char/virtio_console.c
34216+++ b/drivers/char/virtio_console.c
34217@@ -679,7 +679,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
34218 if (to_user) {
34219 ssize_t ret;
34220
34221- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
34222+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
34223 if (ret)
34224 return -EFAULT;
34225 } else {
34226@@ -778,7 +778,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
34227 if (!port_has_data(port) && !port->host_connected)
34228 return 0;
34229
34230- return fill_readbuf(port, ubuf, count, true);
34231+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
34232 }
34233
34234 static int wait_port_writable(struct port *port, bool nonblock)
34235diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
34236index d7ad425..3e3f81f 100644
34237--- a/drivers/clocksource/arm_arch_timer.c
34238+++ b/drivers/clocksource/arm_arch_timer.c
34239@@ -262,7 +262,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
34240 return NOTIFY_OK;
34241 }
34242
34243-static struct notifier_block arch_timer_cpu_nb __cpuinitdata = {
34244+static struct notifier_block arch_timer_cpu_nb = {
34245 .notifier_call = arch_timer_cpu_notify,
34246 };
34247
34248diff --git a/drivers/clocksource/metag_generic.c b/drivers/clocksource/metag_generic.c
34249index ade7513..069445f 100644
34250--- a/drivers/clocksource/metag_generic.c
34251+++ b/drivers/clocksource/metag_generic.c
34252@@ -169,7 +169,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
34253 return NOTIFY_OK;
34254 }
34255
34256-static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
34257+static struct notifier_block arch_timer_cpu_nb = {
34258 .notifier_call = arch_timer_cpu_notify,
34259 };
34260
34261diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
34262index 57a8774..545e993 100644
34263--- a/drivers/cpufreq/acpi-cpufreq.c
34264+++ b/drivers/cpufreq/acpi-cpufreq.c
34265@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
34266 return sprintf(buf, "%u\n", boost_enabled);
34267 }
34268
34269-static struct global_attr global_boost = __ATTR(boost, 0644,
34270+static global_attr_no_const global_boost = __ATTR(boost, 0644,
34271 show_global_boost,
34272 store_global_boost);
34273
34274@@ -712,8 +712,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34275 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
34276 per_cpu(acfreq_data, cpu) = data;
34277
34278- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
34279- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34280+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
34281+ pax_open_kernel();
34282+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34283+ pax_close_kernel();
34284+ }
34285
34286 result = acpi_processor_register_performance(data->acpi_data, cpu);
34287 if (result)
34288@@ -839,7 +842,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34289 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
34290 break;
34291 case ACPI_ADR_SPACE_FIXED_HARDWARE:
34292- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34293+ pax_open_kernel();
34294+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34295+ pax_close_kernel();
34296 policy->cur = get_cur_freq_on_cpu(cpu);
34297 break;
34298 default:
34299@@ -850,8 +855,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34300 acpi_processor_notify_smm(THIS_MODULE);
34301
34302 /* Check for APERF/MPERF support in hardware */
34303- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
34304- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34305+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
34306+ pax_open_kernel();
34307+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34308+ pax_close_kernel();
34309+ }
34310
34311 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
34312 for (i = 0; i < perf->state_count; i++)
34313diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
34314index b02824d..51e44aa 100644
34315--- a/drivers/cpufreq/cpufreq.c
34316+++ b/drivers/cpufreq/cpufreq.c
34317@@ -1813,7 +1813,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
34318 return NOTIFY_OK;
34319 }
34320
34321-static struct notifier_block __refdata cpufreq_cpu_notifier = {
34322+static struct notifier_block cpufreq_cpu_notifier = {
34323 .notifier_call = cpufreq_cpu_callback,
34324 };
34325
34326@@ -1845,8 +1845,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
34327
34328 pr_debug("trying to register driver %s\n", driver_data->name);
34329
34330- if (driver_data->setpolicy)
34331- driver_data->flags |= CPUFREQ_CONST_LOOPS;
34332+ if (driver_data->setpolicy) {
34333+ pax_open_kernel();
34334+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
34335+ pax_close_kernel();
34336+ }
34337
34338 spin_lock_irqsave(&cpufreq_driver_lock, flags);
34339 if (cpufreq_driver) {
34340diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
34341index 5a76086..0f4d394 100644
34342--- a/drivers/cpufreq/cpufreq_governor.c
34343+++ b/drivers/cpufreq/cpufreq_governor.c
34344@@ -201,8 +201,8 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
34345 {
34346 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
34347 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
34348- struct cs_ops *cs_ops = NULL;
34349- struct od_ops *od_ops = NULL;
34350+ const struct cs_ops *cs_ops = NULL;
34351+ const struct od_ops *od_ops = NULL;
34352 struct od_dbs_tuners *od_tuners = dbs_data->tuners;
34353 struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
34354 struct cpu_dbs_common_info *cpu_cdbs;
34355diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
34356index cc4bd2f..ad142bc 100644
34357--- a/drivers/cpufreq/cpufreq_governor.h
34358+++ b/drivers/cpufreq/cpufreq_governor.h
34359@@ -142,7 +142,7 @@ struct dbs_data {
34360 void (*gov_check_cpu)(int cpu, unsigned int load);
34361
34362 /* Governor specific ops, see below */
34363- void *gov_ops;
34364+ const void *gov_ops;
34365 };
34366
34367 /* Governor specific ops, will be passed to dbs_data->gov_ops */
34368diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
34369index bfd6273..e39dd63 100644
34370--- a/drivers/cpufreq/cpufreq_stats.c
34371+++ b/drivers/cpufreq/cpufreq_stats.c
34372@@ -365,7 +365,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
34373 }
34374
34375 /* priority=1 so this will get called before cpufreq_remove_dev */
34376-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
34377+static struct notifier_block cpufreq_stat_cpu_notifier = {
34378 .notifier_call = cpufreq_stat_cpu_callback,
34379 .priority = 1,
34380 };
34381diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
34382index 827629c9..0bc6a03 100644
34383--- a/drivers/cpufreq/p4-clockmod.c
34384+++ b/drivers/cpufreq/p4-clockmod.c
34385@@ -167,10 +167,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34386 case 0x0F: /* Core Duo */
34387 case 0x16: /* Celeron Core */
34388 case 0x1C: /* Atom */
34389- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34390+ pax_open_kernel();
34391+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34392+ pax_close_kernel();
34393 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
34394 case 0x0D: /* Pentium M (Dothan) */
34395- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34396+ pax_open_kernel();
34397+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34398+ pax_close_kernel();
34399 /* fall through */
34400 case 0x09: /* Pentium M (Banias) */
34401 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
34402@@ -182,7 +186,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34403
34404 /* on P-4s, the TSC runs with constant frequency independent whether
34405 * throttling is active or not. */
34406- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34407+ pax_open_kernel();
34408+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34409+ pax_close_kernel();
34410
34411 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
34412 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
34413diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
34414index 3a953d5..f5993f6 100644
34415--- a/drivers/cpufreq/speedstep-centrino.c
34416+++ b/drivers/cpufreq/speedstep-centrino.c
34417@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
34418 !cpu_has(cpu, X86_FEATURE_EST))
34419 return -ENODEV;
34420
34421- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
34422- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34423+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
34424+ pax_open_kernel();
34425+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34426+ pax_close_kernel();
34427+ }
34428
34429 if (policy->cpu != 0)
34430 return -ENODEV;
34431diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
34432index eba6929..0f53baf 100644
34433--- a/drivers/cpuidle/cpuidle.c
34434+++ b/drivers/cpuidle/cpuidle.c
34435@@ -277,7 +277,7 @@ static int poll_idle(struct cpuidle_device *dev,
34436
34437 static void poll_idle_init(struct cpuidle_driver *drv)
34438 {
34439- struct cpuidle_state *state = &drv->states[0];
34440+ cpuidle_state_no_const *state = &drv->states[0];
34441
34442 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
34443 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
34444diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
34445index ea2f8e7..70ac501 100644
34446--- a/drivers/cpuidle/governor.c
34447+++ b/drivers/cpuidle/governor.c
34448@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
34449 mutex_lock(&cpuidle_lock);
34450 if (__cpuidle_find_governor(gov->name) == NULL) {
34451 ret = 0;
34452- list_add_tail(&gov->governor_list, &cpuidle_governors);
34453+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
34454 if (!cpuidle_curr_governor ||
34455 cpuidle_curr_governor->rating < gov->rating)
34456 cpuidle_switch_governor(gov);
34457@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
34458 new_gov = cpuidle_replace_governor(gov->rating);
34459 cpuidle_switch_governor(new_gov);
34460 }
34461- list_del(&gov->governor_list);
34462+ pax_list_del((struct list_head *)&gov->governor_list);
34463 mutex_unlock(&cpuidle_lock);
34464 }
34465
34466diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
34467index 428754a..8bdf9cc 100644
34468--- a/drivers/cpuidle/sysfs.c
34469+++ b/drivers/cpuidle/sysfs.c
34470@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
34471 NULL
34472 };
34473
34474-static struct attribute_group cpuidle_attr_group = {
34475+static attribute_group_no_const cpuidle_attr_group = {
34476 .attrs = cpuidle_default_attrs,
34477 .name = "cpuidle",
34478 };
34479diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
34480index 3b36797..289c16a 100644
34481--- a/drivers/devfreq/devfreq.c
34482+++ b/drivers/devfreq/devfreq.c
34483@@ -588,7 +588,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
34484 goto err_out;
34485 }
34486
34487- list_add(&governor->node, &devfreq_governor_list);
34488+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
34489
34490 list_for_each_entry(devfreq, &devfreq_list, node) {
34491 int ret = 0;
34492@@ -676,7 +676,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
34493 }
34494 }
34495
34496- list_del(&governor->node);
34497+ pax_list_del((struct list_head *)&governor->node);
34498 err_out:
34499 mutex_unlock(&devfreq_list_lock);
34500
34501diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
34502index b70709b..1d8d02a 100644
34503--- a/drivers/dma/sh/shdma.c
34504+++ b/drivers/dma/sh/shdma.c
34505@@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
34506 return ret;
34507 }
34508
34509-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
34510+static struct notifier_block sh_dmae_nmi_notifier = {
34511 .notifier_call = sh_dmae_nmi_handler,
34512
34513 /* Run before NMI debug handler and KGDB */
34514diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
34515index 769d92e..a3dcc1e 100644
34516--- a/drivers/edac/edac_mc_sysfs.c
34517+++ b/drivers/edac/edac_mc_sysfs.c
34518@@ -148,7 +148,7 @@ static const char *edac_caps[] = {
34519 struct dev_ch_attribute {
34520 struct device_attribute attr;
34521 int channel;
34522-};
34523+} __do_const;
34524
34525 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
34526 struct dev_ch_attribute dev_attr_legacy_##_name = \
34527@@ -1003,14 +1003,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
34528 }
34529
34530 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
34531+ pax_open_kernel();
34532 if (mci->get_sdram_scrub_rate) {
34533- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
34534- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
34535+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
34536+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
34537 }
34538 if (mci->set_sdram_scrub_rate) {
34539- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
34540- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
34541+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
34542+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
34543 }
34544+ pax_close_kernel();
34545 err = device_create_file(&mci->dev,
34546 &dev_attr_sdram_scrub_rate);
34547 if (err) {
34548diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
34549index e8658e4..22746d6 100644
34550--- a/drivers/edac/edac_pci_sysfs.c
34551+++ b/drivers/edac/edac_pci_sysfs.c
34552@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
34553 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
34554 static int edac_pci_poll_msec = 1000; /* one second workq period */
34555
34556-static atomic_t pci_parity_count = ATOMIC_INIT(0);
34557-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
34558+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
34559+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
34560
34561 static struct kobject *edac_pci_top_main_kobj;
34562 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
34563@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
34564 void *value;
34565 ssize_t(*show) (void *, char *);
34566 ssize_t(*store) (void *, const char *, size_t);
34567-};
34568+} __do_const;
34569
34570 /* Set of show/store abstract level functions for PCI Parity object */
34571 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
34572@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34573 edac_printk(KERN_CRIT, EDAC_PCI,
34574 "Signaled System Error on %s\n",
34575 pci_name(dev));
34576- atomic_inc(&pci_nonparity_count);
34577+ atomic_inc_unchecked(&pci_nonparity_count);
34578 }
34579
34580 if (status & (PCI_STATUS_PARITY)) {
34581@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34582 "Master Data Parity Error on %s\n",
34583 pci_name(dev));
34584
34585- atomic_inc(&pci_parity_count);
34586+ atomic_inc_unchecked(&pci_parity_count);
34587 }
34588
34589 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34590@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34591 "Detected Parity Error on %s\n",
34592 pci_name(dev));
34593
34594- atomic_inc(&pci_parity_count);
34595+ atomic_inc_unchecked(&pci_parity_count);
34596 }
34597 }
34598
34599@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34600 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
34601 "Signaled System Error on %s\n",
34602 pci_name(dev));
34603- atomic_inc(&pci_nonparity_count);
34604+ atomic_inc_unchecked(&pci_nonparity_count);
34605 }
34606
34607 if (status & (PCI_STATUS_PARITY)) {
34608@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34609 "Master Data Parity Error on "
34610 "%s\n", pci_name(dev));
34611
34612- atomic_inc(&pci_parity_count);
34613+ atomic_inc_unchecked(&pci_parity_count);
34614 }
34615
34616 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34617@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34618 "Detected Parity Error on %s\n",
34619 pci_name(dev));
34620
34621- atomic_inc(&pci_parity_count);
34622+ atomic_inc_unchecked(&pci_parity_count);
34623 }
34624 }
34625 }
34626@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
34627 if (!check_pci_errors)
34628 return;
34629
34630- before_count = atomic_read(&pci_parity_count);
34631+ before_count = atomic_read_unchecked(&pci_parity_count);
34632
34633 /* scan all PCI devices looking for a Parity Error on devices and
34634 * bridges.
34635@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
34636 /* Only if operator has selected panic on PCI Error */
34637 if (edac_pci_get_panic_on_pe()) {
34638 /* If the count is different 'after' from 'before' */
34639- if (before_count != atomic_read(&pci_parity_count))
34640+ if (before_count != atomic_read_unchecked(&pci_parity_count))
34641 panic("EDAC: PCI Parity Error");
34642 }
34643 }
34644diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
34645index 51b7e3a..aa8a3e8 100644
34646--- a/drivers/edac/mce_amd.h
34647+++ b/drivers/edac/mce_amd.h
34648@@ -77,7 +77,7 @@ struct amd_decoder_ops {
34649 bool (*mc0_mce)(u16, u8);
34650 bool (*mc1_mce)(u16, u8);
34651 bool (*mc2_mce)(u16, u8);
34652-};
34653+} __no_const;
34654
34655 void amd_report_gart_errors(bool);
34656 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
34657diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
34658index 57ea7f4..789e3c3 100644
34659--- a/drivers/firewire/core-card.c
34660+++ b/drivers/firewire/core-card.c
34661@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
34662
34663 void fw_core_remove_card(struct fw_card *card)
34664 {
34665- struct fw_card_driver dummy_driver = dummy_driver_template;
34666+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
34667
34668 card->driver->update_phy_reg(card, 4,
34669 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
34670diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
34671index 27ac423..13573e8 100644
34672--- a/drivers/firewire/core-cdev.c
34673+++ b/drivers/firewire/core-cdev.c
34674@@ -1366,8 +1366,7 @@ static int init_iso_resource(struct client *client,
34675 int ret;
34676
34677 if ((request->channels == 0 && request->bandwidth == 0) ||
34678- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
34679- request->bandwidth < 0)
34680+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
34681 return -EINVAL;
34682
34683 r = kmalloc(sizeof(*r), GFP_KERNEL);
34684diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
34685index 03ce7d9..b70f5da 100644
34686--- a/drivers/firewire/core-device.c
34687+++ b/drivers/firewire/core-device.c
34688@@ -232,7 +232,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
34689 struct config_rom_attribute {
34690 struct device_attribute attr;
34691 u32 key;
34692-};
34693+} __do_const;
34694
34695 static ssize_t show_immediate(struct device *dev,
34696 struct device_attribute *dattr, char *buf)
34697diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
34698index 28a94c7..58da63a 100644
34699--- a/drivers/firewire/core-transaction.c
34700+++ b/drivers/firewire/core-transaction.c
34701@@ -38,6 +38,7 @@
34702 #include <linux/timer.h>
34703 #include <linux/types.h>
34704 #include <linux/workqueue.h>
34705+#include <linux/sched.h>
34706
34707 #include <asm/byteorder.h>
34708
34709diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
34710index 515a42c..5ecf3ba 100644
34711--- a/drivers/firewire/core.h
34712+++ b/drivers/firewire/core.h
34713@@ -111,6 +111,7 @@ struct fw_card_driver {
34714
34715 int (*stop_iso)(struct fw_iso_context *ctx);
34716 };
34717+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
34718
34719 void fw_card_initialize(struct fw_card *card,
34720 const struct fw_card_driver *driver, struct device *device);
34721diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
34722index 94a58a0..f5eba42 100644
34723--- a/drivers/firmware/dmi-id.c
34724+++ b/drivers/firmware/dmi-id.c
34725@@ -16,7 +16,7 @@
34726 struct dmi_device_attribute{
34727 struct device_attribute dev_attr;
34728 int field;
34729-};
34730+} __do_const;
34731 #define to_dmi_dev_attr(_dev_attr) \
34732 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
34733
34734diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
34735index 4cd392d..4b629e1 100644
34736--- a/drivers/firmware/dmi_scan.c
34737+++ b/drivers/firmware/dmi_scan.c
34738@@ -490,11 +490,6 @@ void __init dmi_scan_machine(void)
34739 }
34740 }
34741 else {
34742- /*
34743- * no iounmap() for that ioremap(); it would be a no-op, but
34744- * it's so early in setup that sucker gets confused into doing
34745- * what it shouldn't if we actually call it.
34746- */
34747 p = dmi_ioremap(0xF0000, 0x10000);
34748 if (p == NULL)
34749 goto error;
34750@@ -769,7 +764,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
34751 if (buf == NULL)
34752 return -1;
34753
34754- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
34755+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
34756
34757 iounmap(buf);
34758 return 0;
34759diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
34760index f4baa11..7970c3a 100644
34761--- a/drivers/firmware/efivars.c
34762+++ b/drivers/firmware/efivars.c
34763@@ -139,7 +139,7 @@ struct efivar_attribute {
34764 };
34765
34766 static struct efivars __efivars;
34767-static struct efivar_operations ops;
34768+static efivar_operations_no_const ops __read_only;
34769
34770 #define PSTORE_EFI_ATTRIBUTES \
34771 (EFI_VARIABLE_NON_VOLATILE | \
34772@@ -1844,7 +1844,7 @@ efivar_create_sysfs_entry(struct efivars *efivars,
34773 static int
34774 create_efivars_bin_attributes(struct efivars *efivars)
34775 {
34776- struct bin_attribute *attr;
34777+ bin_attribute_no_const *attr;
34778 int error;
34779
34780 /* new_var */
34781diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
34782index 2a90ba6..07f3733 100644
34783--- a/drivers/firmware/google/memconsole.c
34784+++ b/drivers/firmware/google/memconsole.c
34785@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
34786 if (!found_memconsole())
34787 return -ENODEV;
34788
34789- memconsole_bin_attr.size = memconsole_length;
34790+ pax_open_kernel();
34791+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
34792+ pax_close_kernel();
34793
34794 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
34795
34796diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
34797index de3c317..b7cd029 100644
34798--- a/drivers/gpio/gpio-ich.c
34799+++ b/drivers/gpio/gpio-ich.c
34800@@ -69,7 +69,7 @@ struct ichx_desc {
34801 /* Some chipsets have quirks, let these use their own request/get */
34802 int (*request)(struct gpio_chip *chip, unsigned offset);
34803 int (*get)(struct gpio_chip *chip, unsigned offset);
34804-};
34805+} __do_const;
34806
34807 static struct {
34808 spinlock_t lock;
34809diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
34810index 9902732..64b62dd 100644
34811--- a/drivers/gpio/gpio-vr41xx.c
34812+++ b/drivers/gpio/gpio-vr41xx.c
34813@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
34814 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
34815 maskl, pendl, maskh, pendh);
34816
34817- atomic_inc(&irq_err_count);
34818+ atomic_inc_unchecked(&irq_err_count);
34819
34820 return -EINVAL;
34821 }
34822diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
34823index 7b2d378..cc947ea 100644
34824--- a/drivers/gpu/drm/drm_crtc_helper.c
34825+++ b/drivers/gpu/drm/drm_crtc_helper.c
34826@@ -319,7 +319,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
34827 struct drm_crtc *tmp;
34828 int crtc_mask = 1;
34829
34830- WARN(!crtc, "checking null crtc?\n");
34831+ BUG_ON(!crtc);
34832
34833 dev = crtc->dev;
34834
34835diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
34836index 25f91cd..a376f55 100644
34837--- a/drivers/gpu/drm/drm_drv.c
34838+++ b/drivers/gpu/drm/drm_drv.c
34839@@ -306,7 +306,7 @@ module_exit(drm_core_exit);
34840 /**
34841 * Copy and IOCTL return string to user space
34842 */
34843-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
34844+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
34845 {
34846 int len;
34847
34848@@ -376,7 +376,7 @@ long drm_ioctl(struct file *filp,
34849 struct drm_file *file_priv = filp->private_data;
34850 struct drm_device *dev;
34851 struct drm_ioctl_desc *ioctl;
34852- drm_ioctl_t *func;
34853+ drm_ioctl_no_const_t func;
34854 unsigned int nr = DRM_IOCTL_NR(cmd);
34855 int retcode = -EINVAL;
34856 char stack_kdata[128];
34857@@ -389,7 +389,7 @@ long drm_ioctl(struct file *filp,
34858 return -ENODEV;
34859
34860 atomic_inc(&dev->ioctl_count);
34861- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
34862+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
34863 ++file_priv->ioctl_count;
34864
34865 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
34866diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
34867index 429e07d..e681a2c 100644
34868--- a/drivers/gpu/drm/drm_fops.c
34869+++ b/drivers/gpu/drm/drm_fops.c
34870@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
34871 }
34872
34873 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
34874- atomic_set(&dev->counts[i], 0);
34875+ atomic_set_unchecked(&dev->counts[i], 0);
34876
34877 dev->sigdata.lock = NULL;
34878
34879@@ -135,7 +135,7 @@ int drm_open(struct inode *inode, struct file *filp)
34880 if (drm_device_is_unplugged(dev))
34881 return -ENODEV;
34882
34883- if (!dev->open_count++)
34884+ if (local_inc_return(&dev->open_count) == 1)
34885 need_setup = 1;
34886 mutex_lock(&dev->struct_mutex);
34887 old_imapping = inode->i_mapping;
34888@@ -151,7 +151,7 @@ int drm_open(struct inode *inode, struct file *filp)
34889 retcode = drm_open_helper(inode, filp, dev);
34890 if (retcode)
34891 goto err_undo;
34892- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
34893+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
34894 if (need_setup) {
34895 retcode = drm_setup(dev);
34896 if (retcode)
34897@@ -166,7 +166,7 @@ err_undo:
34898 iput(container_of(dev->dev_mapping, struct inode, i_data));
34899 dev->dev_mapping = old_mapping;
34900 mutex_unlock(&dev->struct_mutex);
34901- dev->open_count--;
34902+ local_dec(&dev->open_count);
34903 return retcode;
34904 }
34905 EXPORT_SYMBOL(drm_open);
34906@@ -441,7 +441,7 @@ int drm_release(struct inode *inode, struct file *filp)
34907
34908 mutex_lock(&drm_global_mutex);
34909
34910- DRM_DEBUG("open_count = %d\n", dev->open_count);
34911+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
34912
34913 if (dev->driver->preclose)
34914 dev->driver->preclose(dev, file_priv);
34915@@ -450,10 +450,10 @@ int drm_release(struct inode *inode, struct file *filp)
34916 * Begin inline drm_release
34917 */
34918
34919- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
34920+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
34921 task_pid_nr(current),
34922 (long)old_encode_dev(file_priv->minor->device),
34923- dev->open_count);
34924+ local_read(&dev->open_count));
34925
34926 /* Release any auth tokens that might point to this file_priv,
34927 (do that under the drm_global_mutex) */
34928@@ -550,8 +550,8 @@ int drm_release(struct inode *inode, struct file *filp)
34929 * End inline drm_release
34930 */
34931
34932- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
34933- if (!--dev->open_count) {
34934+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
34935+ if (local_dec_and_test(&dev->open_count)) {
34936 if (atomic_read(&dev->ioctl_count)) {
34937 DRM_ERROR("Device busy: %d\n",
34938 atomic_read(&dev->ioctl_count));
34939diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
34940index f731116..629842c 100644
34941--- a/drivers/gpu/drm/drm_global.c
34942+++ b/drivers/gpu/drm/drm_global.c
34943@@ -36,7 +36,7 @@
34944 struct drm_global_item {
34945 struct mutex mutex;
34946 void *object;
34947- int refcount;
34948+ atomic_t refcount;
34949 };
34950
34951 static struct drm_global_item glob[DRM_GLOBAL_NUM];
34952@@ -49,7 +49,7 @@ void drm_global_init(void)
34953 struct drm_global_item *item = &glob[i];
34954 mutex_init(&item->mutex);
34955 item->object = NULL;
34956- item->refcount = 0;
34957+ atomic_set(&item->refcount, 0);
34958 }
34959 }
34960
34961@@ -59,7 +59,7 @@ void drm_global_release(void)
34962 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
34963 struct drm_global_item *item = &glob[i];
34964 BUG_ON(item->object != NULL);
34965- BUG_ON(item->refcount != 0);
34966+ BUG_ON(atomic_read(&item->refcount) != 0);
34967 }
34968 }
34969
34970@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
34971 void *object;
34972
34973 mutex_lock(&item->mutex);
34974- if (item->refcount == 0) {
34975+ if (atomic_read(&item->refcount) == 0) {
34976 item->object = kzalloc(ref->size, GFP_KERNEL);
34977 if (unlikely(item->object == NULL)) {
34978 ret = -ENOMEM;
34979@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
34980 goto out_err;
34981
34982 }
34983- ++item->refcount;
34984+ atomic_inc(&item->refcount);
34985 ref->object = item->object;
34986 object = item->object;
34987 mutex_unlock(&item->mutex);
34988@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
34989 struct drm_global_item *item = &glob[ref->global_type];
34990
34991 mutex_lock(&item->mutex);
34992- BUG_ON(item->refcount == 0);
34993+ BUG_ON(atomic_read(&item->refcount) == 0);
34994 BUG_ON(ref->object != item->object);
34995- if (--item->refcount == 0) {
34996+ if (atomic_dec_and_test(&item->refcount)) {
34997 ref->release(ref);
34998 item->object = NULL;
34999 }
35000diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
35001index d4b20ce..77a8d41 100644
35002--- a/drivers/gpu/drm/drm_info.c
35003+++ b/drivers/gpu/drm/drm_info.c
35004@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
35005 struct drm_local_map *map;
35006 struct drm_map_list *r_list;
35007
35008- /* Hardcoded from _DRM_FRAME_BUFFER,
35009- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
35010- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
35011- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
35012+ static const char * const types[] = {
35013+ [_DRM_FRAME_BUFFER] = "FB",
35014+ [_DRM_REGISTERS] = "REG",
35015+ [_DRM_SHM] = "SHM",
35016+ [_DRM_AGP] = "AGP",
35017+ [_DRM_SCATTER_GATHER] = "SG",
35018+ [_DRM_CONSISTENT] = "PCI",
35019+ [_DRM_GEM] = "GEM" };
35020 const char *type;
35021 int i;
35022
35023@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
35024 map = r_list->map;
35025 if (!map)
35026 continue;
35027- if (map->type < 0 || map->type > 5)
35028+ if (map->type >= ARRAY_SIZE(types))
35029 type = "??";
35030 else
35031 type = types[map->type];
35032@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
35033 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
35034 vma->vm_flags & VM_LOCKED ? 'l' : '-',
35035 vma->vm_flags & VM_IO ? 'i' : '-',
35036+#ifdef CONFIG_GRKERNSEC_HIDESYM
35037+ 0);
35038+#else
35039 vma->vm_pgoff);
35040+#endif
35041
35042 #if defined(__i386__)
35043 pgprot = pgprot_val(vma->vm_page_prot);
35044diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
35045index 2f4c434..dd12cd2 100644
35046--- a/drivers/gpu/drm/drm_ioc32.c
35047+++ b/drivers/gpu/drm/drm_ioc32.c
35048@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
35049 request = compat_alloc_user_space(nbytes);
35050 if (!access_ok(VERIFY_WRITE, request, nbytes))
35051 return -EFAULT;
35052- list = (struct drm_buf_desc *) (request + 1);
35053+ list = (struct drm_buf_desc __user *) (request + 1);
35054
35055 if (__put_user(count, &request->count)
35056 || __put_user(list, &request->list))
35057@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
35058 request = compat_alloc_user_space(nbytes);
35059 if (!access_ok(VERIFY_WRITE, request, nbytes))
35060 return -EFAULT;
35061- list = (struct drm_buf_pub *) (request + 1);
35062+ list = (struct drm_buf_pub __user *) (request + 1);
35063
35064 if (__put_user(count, &request->count)
35065 || __put_user(list, &request->list))
35066@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
35067 return 0;
35068 }
35069
35070-drm_ioctl_compat_t *drm_compat_ioctls[] = {
35071+drm_ioctl_compat_t drm_compat_ioctls[] = {
35072 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
35073 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
35074 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
35075@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
35076 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35077 {
35078 unsigned int nr = DRM_IOCTL_NR(cmd);
35079- drm_ioctl_compat_t *fn;
35080 int ret;
35081
35082 /* Assume that ioctls without an explicit compat routine will just
35083@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35084 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
35085 return drm_ioctl(filp, cmd, arg);
35086
35087- fn = drm_compat_ioctls[nr];
35088-
35089- if (fn != NULL)
35090- ret = (*fn) (filp, cmd, arg);
35091+ if (drm_compat_ioctls[nr] != NULL)
35092+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
35093 else
35094 ret = drm_ioctl(filp, cmd, arg);
35095
35096diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
35097index e77bd8b..1571b85 100644
35098--- a/drivers/gpu/drm/drm_ioctl.c
35099+++ b/drivers/gpu/drm/drm_ioctl.c
35100@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
35101 stats->data[i].value =
35102 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
35103 else
35104- stats->data[i].value = atomic_read(&dev->counts[i]);
35105+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
35106 stats->data[i].type = dev->types[i];
35107 }
35108
35109diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
35110index d752c96..fe08455 100644
35111--- a/drivers/gpu/drm/drm_lock.c
35112+++ b/drivers/gpu/drm/drm_lock.c
35113@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
35114 if (drm_lock_take(&master->lock, lock->context)) {
35115 master->lock.file_priv = file_priv;
35116 master->lock.lock_time = jiffies;
35117- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
35118+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
35119 break; /* Got lock */
35120 }
35121
35122@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
35123 return -EINVAL;
35124 }
35125
35126- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
35127+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
35128
35129 if (drm_lock_free(&master->lock, lock->context)) {
35130 /* FIXME: Should really bail out here. */
35131diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
35132index 7d30802..42c6cbb 100644
35133--- a/drivers/gpu/drm/drm_stub.c
35134+++ b/drivers/gpu/drm/drm_stub.c
35135@@ -501,7 +501,7 @@ void drm_unplug_dev(struct drm_device *dev)
35136
35137 drm_device_set_unplugged(dev);
35138
35139- if (dev->open_count == 0) {
35140+ if (local_read(&dev->open_count) == 0) {
35141 drm_put_dev(dev);
35142 }
35143 mutex_unlock(&drm_global_mutex);
35144diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
35145index 004ecdf..db1f6e0 100644
35146--- a/drivers/gpu/drm/i810/i810_dma.c
35147+++ b/drivers/gpu/drm/i810/i810_dma.c
35148@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
35149 dma->buflist[vertex->idx],
35150 vertex->discard, vertex->used);
35151
35152- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
35153- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35154+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
35155+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35156 sarea_priv->last_enqueue = dev_priv->counter - 1;
35157 sarea_priv->last_dispatch = (int)hw_status[5];
35158
35159@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
35160 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
35161 mc->last_render);
35162
35163- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35164- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35165+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35166+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35167 sarea_priv->last_enqueue = dev_priv->counter - 1;
35168 sarea_priv->last_dispatch = (int)hw_status[5];
35169
35170diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
35171index 6e0acad..93c8289 100644
35172--- a/drivers/gpu/drm/i810/i810_drv.h
35173+++ b/drivers/gpu/drm/i810/i810_drv.h
35174@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
35175 int page_flipping;
35176
35177 wait_queue_head_t irq_queue;
35178- atomic_t irq_received;
35179- atomic_t irq_emitted;
35180+ atomic_unchecked_t irq_received;
35181+ atomic_unchecked_t irq_emitted;
35182
35183 int front_offset;
35184 } drm_i810_private_t;
35185diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
35186index 7299ea4..5314487 100644
35187--- a/drivers/gpu/drm/i915/i915_debugfs.c
35188+++ b/drivers/gpu/drm/i915/i915_debugfs.c
35189@@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
35190 I915_READ(GTIMR));
35191 }
35192 seq_printf(m, "Interrupts received: %d\n",
35193- atomic_read(&dev_priv->irq_received));
35194+ atomic_read_unchecked(&dev_priv->irq_received));
35195 for_each_ring(ring, dev_priv, i) {
35196 if (IS_GEN6(dev) || IS_GEN7(dev)) {
35197 seq_printf(m,
35198diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
35199index 4fa6beb..f930fec 100644
35200--- a/drivers/gpu/drm/i915/i915_dma.c
35201+++ b/drivers/gpu/drm/i915/i915_dma.c
35202@@ -1259,7 +1259,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
35203 bool can_switch;
35204
35205 spin_lock(&dev->count_lock);
35206- can_switch = (dev->open_count == 0);
35207+ can_switch = (local_read(&dev->open_count) == 0);
35208 spin_unlock(&dev->count_lock);
35209 return can_switch;
35210 }
35211diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
35212index ef99b1c..09ce7fb 100644
35213--- a/drivers/gpu/drm/i915/i915_drv.h
35214+++ b/drivers/gpu/drm/i915/i915_drv.h
35215@@ -893,7 +893,7 @@ typedef struct drm_i915_private {
35216 drm_dma_handle_t *status_page_dmah;
35217 struct resource mch_res;
35218
35219- atomic_t irq_received;
35220+ atomic_unchecked_t irq_received;
35221
35222 /* protects the irq masks */
35223 spinlock_t irq_lock;
35224@@ -1775,7 +1775,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
35225 struct drm_i915_private *dev_priv, unsigned port);
35226 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
35227 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
35228-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35229+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35230 {
35231 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
35232 }
35233diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35234index 9a48e1a..f0cbc3e 100644
35235--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35236+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35237@@ -729,9 +729,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
35238
35239 static int
35240 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
35241- int count)
35242+ unsigned int count)
35243 {
35244- int i;
35245+ unsigned int i;
35246 int relocs_total = 0;
35247 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
35248
35249@@ -1195,7 +1195,7 @@ i915_gem_execbuffer2(struct drm_device *dev, void *data,
35250 return -ENOMEM;
35251 }
35252 ret = copy_from_user(exec2_list,
35253- (struct drm_i915_relocation_entry __user *)
35254+ (struct drm_i915_gem_exec_object2 __user *)
35255 (uintptr_t) args->buffers_ptr,
35256 sizeof(*exec2_list) * args->buffer_count);
35257 if (ret != 0) {
35258diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
35259index 3c59584..500f2e9 100644
35260--- a/drivers/gpu/drm/i915/i915_ioc32.c
35261+++ b/drivers/gpu/drm/i915/i915_ioc32.c
35262@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
35263 (unsigned long)request);
35264 }
35265
35266-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35267+static drm_ioctl_compat_t i915_compat_ioctls[] = {
35268 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
35269 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
35270 [DRM_I915_GETPARAM] = compat_i915_getparam,
35271@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35272 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35273 {
35274 unsigned int nr = DRM_IOCTL_NR(cmd);
35275- drm_ioctl_compat_t *fn = NULL;
35276 int ret;
35277
35278 if (nr < DRM_COMMAND_BASE)
35279 return drm_compat_ioctl(filp, cmd, arg);
35280
35281- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
35282- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35283-
35284- if (fn != NULL)
35285+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
35286+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35287 ret = (*fn) (filp, cmd, arg);
35288- else
35289+ } else
35290 ret = drm_ioctl(filp, cmd, arg);
35291
35292 return ret;
35293diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
35294index 3c7bb04..182e049 100644
35295--- a/drivers/gpu/drm/i915/i915_irq.c
35296+++ b/drivers/gpu/drm/i915/i915_irq.c
35297@@ -549,7 +549,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
35298 int pipe;
35299 u32 pipe_stats[I915_MAX_PIPES];
35300
35301- atomic_inc(&dev_priv->irq_received);
35302+ atomic_inc_unchecked(&dev_priv->irq_received);
35303
35304 while (true) {
35305 iir = I915_READ(VLV_IIR);
35306@@ -705,7 +705,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
35307 irqreturn_t ret = IRQ_NONE;
35308 int i;
35309
35310- atomic_inc(&dev_priv->irq_received);
35311+ atomic_inc_unchecked(&dev_priv->irq_received);
35312
35313 /* disable master interrupt before clearing iir */
35314 de_ier = I915_READ(DEIER);
35315@@ -791,7 +791,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
35316 int ret = IRQ_NONE;
35317 u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier;
35318
35319- atomic_inc(&dev_priv->irq_received);
35320+ atomic_inc_unchecked(&dev_priv->irq_received);
35321
35322 /* disable master interrupt before clearing iir */
35323 de_ier = I915_READ(DEIER);
35324@@ -1886,7 +1886,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
35325 {
35326 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35327
35328- atomic_set(&dev_priv->irq_received, 0);
35329+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35330
35331 I915_WRITE(HWSTAM, 0xeffe);
35332
35333@@ -1912,7 +1912,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
35334 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35335 int pipe;
35336
35337- atomic_set(&dev_priv->irq_received, 0);
35338+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35339
35340 /* VLV magic */
35341 I915_WRITE(VLV_IMR, 0);
35342@@ -2208,7 +2208,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
35343 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35344 int pipe;
35345
35346- atomic_set(&dev_priv->irq_received, 0);
35347+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35348
35349 for_each_pipe(pipe)
35350 I915_WRITE(PIPESTAT(pipe), 0);
35351@@ -2259,7 +2259,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
35352 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
35353 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
35354
35355- atomic_inc(&dev_priv->irq_received);
35356+ atomic_inc_unchecked(&dev_priv->irq_received);
35357
35358 iir = I915_READ16(IIR);
35359 if (iir == 0)
35360@@ -2344,7 +2344,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
35361 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35362 int pipe;
35363
35364- atomic_set(&dev_priv->irq_received, 0);
35365+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35366
35367 if (I915_HAS_HOTPLUG(dev)) {
35368 I915_WRITE(PORT_HOTPLUG_EN, 0);
35369@@ -2448,7 +2448,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
35370 };
35371 int pipe, ret = IRQ_NONE;
35372
35373- atomic_inc(&dev_priv->irq_received);
35374+ atomic_inc_unchecked(&dev_priv->irq_received);
35375
35376 iir = I915_READ(IIR);
35377 do {
35378@@ -2574,7 +2574,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
35379 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35380 int pipe;
35381
35382- atomic_set(&dev_priv->irq_received, 0);
35383+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35384
35385 I915_WRITE(PORT_HOTPLUG_EN, 0);
35386 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
35387@@ -2690,7 +2690,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
35388 int irq_received;
35389 int ret = IRQ_NONE, pipe;
35390
35391- atomic_inc(&dev_priv->irq_received);
35392+ atomic_inc_unchecked(&dev_priv->irq_received);
35393
35394 iir = I915_READ(IIR);
35395
35396diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
35397index c2d173a..f4357cc 100644
35398--- a/drivers/gpu/drm/i915/intel_display.c
35399+++ b/drivers/gpu/drm/i915/intel_display.c
35400@@ -8722,13 +8722,13 @@ struct intel_quirk {
35401 int subsystem_vendor;
35402 int subsystem_device;
35403 void (*hook)(struct drm_device *dev);
35404-};
35405+} __do_const;
35406
35407 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
35408 struct intel_dmi_quirk {
35409 void (*hook)(struct drm_device *dev);
35410 const struct dmi_system_id (*dmi_id_list)[];
35411-};
35412+} __do_const;
35413
35414 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35415 {
35416@@ -8736,18 +8736,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35417 return 1;
35418 }
35419
35420-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35421+static const struct dmi_system_id intel_dmi_quirks_table[] = {
35422 {
35423- .dmi_id_list = &(const struct dmi_system_id[]) {
35424- {
35425- .callback = intel_dmi_reverse_brightness,
35426- .ident = "NCR Corporation",
35427- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35428- DMI_MATCH(DMI_PRODUCT_NAME, ""),
35429- },
35430- },
35431- { } /* terminating entry */
35432+ .callback = intel_dmi_reverse_brightness,
35433+ .ident = "NCR Corporation",
35434+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35435+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
35436 },
35437+ },
35438+ { } /* terminating entry */
35439+};
35440+
35441+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35442+ {
35443+ .dmi_id_list = &intel_dmi_quirks_table,
35444 .hook = quirk_invert_brightness,
35445 },
35446 };
35447diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
35448index 54558a0..2d97005 100644
35449--- a/drivers/gpu/drm/mga/mga_drv.h
35450+++ b/drivers/gpu/drm/mga/mga_drv.h
35451@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
35452 u32 clear_cmd;
35453 u32 maccess;
35454
35455- atomic_t vbl_received; /**< Number of vblanks received. */
35456+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
35457 wait_queue_head_t fence_queue;
35458- atomic_t last_fence_retired;
35459+ atomic_unchecked_t last_fence_retired;
35460 u32 next_fence_to_post;
35461
35462 unsigned int fb_cpp;
35463diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
35464index 709e90d..89a1c0d 100644
35465--- a/drivers/gpu/drm/mga/mga_ioc32.c
35466+++ b/drivers/gpu/drm/mga/mga_ioc32.c
35467@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
35468 return 0;
35469 }
35470
35471-drm_ioctl_compat_t *mga_compat_ioctls[] = {
35472+drm_ioctl_compat_t mga_compat_ioctls[] = {
35473 [DRM_MGA_INIT] = compat_mga_init,
35474 [DRM_MGA_GETPARAM] = compat_mga_getparam,
35475 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
35476@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
35477 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35478 {
35479 unsigned int nr = DRM_IOCTL_NR(cmd);
35480- drm_ioctl_compat_t *fn = NULL;
35481 int ret;
35482
35483 if (nr < DRM_COMMAND_BASE)
35484 return drm_compat_ioctl(filp, cmd, arg);
35485
35486- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
35487- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35488-
35489- if (fn != NULL)
35490+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
35491+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35492 ret = (*fn) (filp, cmd, arg);
35493- else
35494+ } else
35495 ret = drm_ioctl(filp, cmd, arg);
35496
35497 return ret;
35498diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
35499index 598c281..60d590e 100644
35500--- a/drivers/gpu/drm/mga/mga_irq.c
35501+++ b/drivers/gpu/drm/mga/mga_irq.c
35502@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
35503 if (crtc != 0)
35504 return 0;
35505
35506- return atomic_read(&dev_priv->vbl_received);
35507+ return atomic_read_unchecked(&dev_priv->vbl_received);
35508 }
35509
35510
35511@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35512 /* VBLANK interrupt */
35513 if (status & MGA_VLINEPEN) {
35514 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
35515- atomic_inc(&dev_priv->vbl_received);
35516+ atomic_inc_unchecked(&dev_priv->vbl_received);
35517 drm_handle_vblank(dev, 0);
35518 handled = 1;
35519 }
35520@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35521 if ((prim_start & ~0x03) != (prim_end & ~0x03))
35522 MGA_WRITE(MGA_PRIMEND, prim_end);
35523
35524- atomic_inc(&dev_priv->last_fence_retired);
35525+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
35526 DRM_WAKEUP(&dev_priv->fence_queue);
35527 handled = 1;
35528 }
35529@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
35530 * using fences.
35531 */
35532 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
35533- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
35534+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
35535 - *sequence) <= (1 << 23)));
35536
35537 *sequence = cur_fence;
35538diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
35539index 50a6dd0..ea66ed8 100644
35540--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
35541+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
35542@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
35543 struct bit_table {
35544 const char id;
35545 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
35546-};
35547+} __no_const;
35548
35549 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
35550
35551diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
35552index 9c39baf..30a22be 100644
35553--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
35554+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
35555@@ -81,7 +81,7 @@ struct nouveau_drm {
35556 struct drm_global_reference mem_global_ref;
35557 struct ttm_bo_global_ref bo_global_ref;
35558 struct ttm_bo_device bdev;
35559- atomic_t validate_sequence;
35560+ atomic_unchecked_t validate_sequence;
35561 int (*move)(struct nouveau_channel *,
35562 struct ttm_buffer_object *,
35563 struct ttm_mem_reg *, struct ttm_mem_reg *);
35564diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
35565index b4b4d0c..b7edc15 100644
35566--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
35567+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
35568@@ -322,7 +322,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
35569 int ret, i;
35570 struct nouveau_bo *res_bo = NULL;
35571
35572- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35573+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35574 retry:
35575 if (++trycnt > 100000) {
35576 NV_ERROR(cli, "%s failed and gave up.\n", __func__);
35577@@ -359,7 +359,7 @@ retry:
35578 if (ret) {
35579 validate_fini(op, NULL);
35580 if (unlikely(ret == -EAGAIN)) {
35581- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35582+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35583 ret = ttm_bo_reserve_slowpath(&nvbo->bo, true,
35584 sequence);
35585 if (!ret)
35586diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35587index 08214bc..9208577 100644
35588--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35589+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35590@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
35591 unsigned long arg)
35592 {
35593 unsigned int nr = DRM_IOCTL_NR(cmd);
35594- drm_ioctl_compat_t *fn = NULL;
35595+ drm_ioctl_compat_t fn = NULL;
35596 int ret;
35597
35598 if (nr < DRM_COMMAND_BASE)
35599diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
35600index 25d3495..d81aaf6 100644
35601--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
35602+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
35603@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
35604 bool can_switch;
35605
35606 spin_lock(&dev->count_lock);
35607- can_switch = (dev->open_count == 0);
35608+ can_switch = (local_read(&dev->open_count) == 0);
35609 spin_unlock(&dev->count_lock);
35610 return can_switch;
35611 }
35612diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
35613index d4660cf..70dbe65 100644
35614--- a/drivers/gpu/drm/r128/r128_cce.c
35615+++ b/drivers/gpu/drm/r128/r128_cce.c
35616@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
35617
35618 /* GH: Simple idle check.
35619 */
35620- atomic_set(&dev_priv->idle_count, 0);
35621+ atomic_set_unchecked(&dev_priv->idle_count, 0);
35622
35623 /* We don't support anything other than bus-mastering ring mode,
35624 * but the ring can be in either AGP or PCI space for the ring
35625diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
35626index 930c71b..499aded 100644
35627--- a/drivers/gpu/drm/r128/r128_drv.h
35628+++ b/drivers/gpu/drm/r128/r128_drv.h
35629@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
35630 int is_pci;
35631 unsigned long cce_buffers_offset;
35632
35633- atomic_t idle_count;
35634+ atomic_unchecked_t idle_count;
35635
35636 int page_flipping;
35637 int current_page;
35638 u32 crtc_offset;
35639 u32 crtc_offset_cntl;
35640
35641- atomic_t vbl_received;
35642+ atomic_unchecked_t vbl_received;
35643
35644 u32 color_fmt;
35645 unsigned int front_offset;
35646diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
35647index a954c54..9cc595c 100644
35648--- a/drivers/gpu/drm/r128/r128_ioc32.c
35649+++ b/drivers/gpu/drm/r128/r128_ioc32.c
35650@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
35651 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
35652 }
35653
35654-drm_ioctl_compat_t *r128_compat_ioctls[] = {
35655+drm_ioctl_compat_t r128_compat_ioctls[] = {
35656 [DRM_R128_INIT] = compat_r128_init,
35657 [DRM_R128_DEPTH] = compat_r128_depth,
35658 [DRM_R128_STIPPLE] = compat_r128_stipple,
35659@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
35660 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35661 {
35662 unsigned int nr = DRM_IOCTL_NR(cmd);
35663- drm_ioctl_compat_t *fn = NULL;
35664 int ret;
35665
35666 if (nr < DRM_COMMAND_BASE)
35667 return drm_compat_ioctl(filp, cmd, arg);
35668
35669- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
35670- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35671-
35672- if (fn != NULL)
35673+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
35674+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35675 ret = (*fn) (filp, cmd, arg);
35676- else
35677+ } else
35678 ret = drm_ioctl(filp, cmd, arg);
35679
35680 return ret;
35681diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
35682index 2ea4f09..d391371 100644
35683--- a/drivers/gpu/drm/r128/r128_irq.c
35684+++ b/drivers/gpu/drm/r128/r128_irq.c
35685@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
35686 if (crtc != 0)
35687 return 0;
35688
35689- return atomic_read(&dev_priv->vbl_received);
35690+ return atomic_read_unchecked(&dev_priv->vbl_received);
35691 }
35692
35693 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
35694@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
35695 /* VBLANK interrupt */
35696 if (status & R128_CRTC_VBLANK_INT) {
35697 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
35698- atomic_inc(&dev_priv->vbl_received);
35699+ atomic_inc_unchecked(&dev_priv->vbl_received);
35700 drm_handle_vblank(dev, 0);
35701 return IRQ_HANDLED;
35702 }
35703diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
35704index 19bb7e6..de7e2a2 100644
35705--- a/drivers/gpu/drm/r128/r128_state.c
35706+++ b/drivers/gpu/drm/r128/r128_state.c
35707@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
35708
35709 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
35710 {
35711- if (atomic_read(&dev_priv->idle_count) == 0)
35712+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
35713 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
35714 else
35715- atomic_set(&dev_priv->idle_count, 0);
35716+ atomic_set_unchecked(&dev_priv->idle_count, 0);
35717 }
35718
35719 #endif
35720diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
35721index 5a82b6b..9e69c73 100644
35722--- a/drivers/gpu/drm/radeon/mkregtable.c
35723+++ b/drivers/gpu/drm/radeon/mkregtable.c
35724@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
35725 regex_t mask_rex;
35726 regmatch_t match[4];
35727 char buf[1024];
35728- size_t end;
35729+ long end;
35730 int len;
35731 int done = 0;
35732 int r;
35733 unsigned o;
35734 struct offset *offset;
35735 char last_reg_s[10];
35736- int last_reg;
35737+ unsigned long last_reg;
35738
35739 if (regcomp
35740 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
35741diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
35742index 5073665..31d15a6 100644
35743--- a/drivers/gpu/drm/radeon/radeon_device.c
35744+++ b/drivers/gpu/drm/radeon/radeon_device.c
35745@@ -976,7 +976,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
35746 bool can_switch;
35747
35748 spin_lock(&dev->count_lock);
35749- can_switch = (dev->open_count == 0);
35750+ can_switch = (local_read(&dev->open_count) == 0);
35751 spin_unlock(&dev->count_lock);
35752 return can_switch;
35753 }
35754diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
35755index b369d42..8dd04eb 100644
35756--- a/drivers/gpu/drm/radeon/radeon_drv.h
35757+++ b/drivers/gpu/drm/radeon/radeon_drv.h
35758@@ -258,7 +258,7 @@ typedef struct drm_radeon_private {
35759
35760 /* SW interrupt */
35761 wait_queue_head_t swi_queue;
35762- atomic_t swi_emitted;
35763+ atomic_unchecked_t swi_emitted;
35764 int vblank_crtc;
35765 uint32_t irq_enable_reg;
35766 uint32_t r500_disp_irq_reg;
35767diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
35768index c180df8..5fd8186 100644
35769--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
35770+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
35771@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
35772 request = compat_alloc_user_space(sizeof(*request));
35773 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
35774 || __put_user(req32.param, &request->param)
35775- || __put_user((void __user *)(unsigned long)req32.value,
35776+ || __put_user((unsigned long)req32.value,
35777 &request->value))
35778 return -EFAULT;
35779
35780@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
35781 #define compat_radeon_cp_setparam NULL
35782 #endif /* X86_64 || IA64 */
35783
35784-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
35785+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
35786 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
35787 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
35788 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
35789@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
35790 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35791 {
35792 unsigned int nr = DRM_IOCTL_NR(cmd);
35793- drm_ioctl_compat_t *fn = NULL;
35794 int ret;
35795
35796 if (nr < DRM_COMMAND_BASE)
35797 return drm_compat_ioctl(filp, cmd, arg);
35798
35799- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
35800- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
35801-
35802- if (fn != NULL)
35803+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
35804+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
35805 ret = (*fn) (filp, cmd, arg);
35806- else
35807+ } else
35808 ret = drm_ioctl(filp, cmd, arg);
35809
35810 return ret;
35811diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
35812index 8d68e97..9dcfed8 100644
35813--- a/drivers/gpu/drm/radeon/radeon_irq.c
35814+++ b/drivers/gpu/drm/radeon/radeon_irq.c
35815@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
35816 unsigned int ret;
35817 RING_LOCALS;
35818
35819- atomic_inc(&dev_priv->swi_emitted);
35820- ret = atomic_read(&dev_priv->swi_emitted);
35821+ atomic_inc_unchecked(&dev_priv->swi_emitted);
35822+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
35823
35824 BEGIN_RING(4);
35825 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
35826@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
35827 drm_radeon_private_t *dev_priv =
35828 (drm_radeon_private_t *) dev->dev_private;
35829
35830- atomic_set(&dev_priv->swi_emitted, 0);
35831+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
35832 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
35833
35834 dev->max_vblank_count = 0x001fffff;
35835diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
35836index 4d20910..6726b6d 100644
35837--- a/drivers/gpu/drm/radeon/radeon_state.c
35838+++ b/drivers/gpu/drm/radeon/radeon_state.c
35839@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
35840 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
35841 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
35842
35843- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
35844+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
35845 sarea_priv->nbox * sizeof(depth_boxes[0])))
35846 return -EFAULT;
35847
35848@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
35849 {
35850 drm_radeon_private_t *dev_priv = dev->dev_private;
35851 drm_radeon_getparam_t *param = data;
35852- int value;
35853+ int value = 0;
35854
35855 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
35856
35857diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
35858index 6c0ce89..66f6d65 100644
35859--- a/drivers/gpu/drm/radeon/radeon_ttm.c
35860+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
35861@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
35862 man->size = size >> PAGE_SHIFT;
35863 }
35864
35865-static struct vm_operations_struct radeon_ttm_vm_ops;
35866+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
35867 static const struct vm_operations_struct *ttm_vm_ops = NULL;
35868
35869 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
35870@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
35871 }
35872 if (unlikely(ttm_vm_ops == NULL)) {
35873 ttm_vm_ops = vma->vm_ops;
35874+ pax_open_kernel();
35875 radeon_ttm_vm_ops = *ttm_vm_ops;
35876 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
35877+ pax_close_kernel();
35878 }
35879 vma->vm_ops = &radeon_ttm_vm_ops;
35880 return 0;
35881@@ -862,28 +864,33 @@ static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
35882 sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
35883 else
35884 sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
35885- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35886- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
35887- radeon_mem_types_list[i].driver_features = 0;
35888+ pax_open_kernel();
35889+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35890+ *(void **)&radeon_mem_types_list[i].show = &radeon_mm_dump_table;
35891+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35892 if (i == 0)
35893- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
35894+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
35895 else
35896- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
35897-
35898+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
35899+ pax_close_kernel();
35900 }
35901 /* Add ttm page pool to debugfs */
35902 sprintf(radeon_mem_types_names[i], "ttm_page_pool");
35903- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35904- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
35905- radeon_mem_types_list[i].driver_features = 0;
35906- radeon_mem_types_list[i++].data = NULL;
35907+ pax_open_kernel();
35908+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35909+ *(void **)&radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
35910+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35911+ *(void **)&radeon_mem_types_list[i++].data = NULL;
35912+ pax_close_kernel();
35913 #ifdef CONFIG_SWIOTLB
35914 if (swiotlb_nr_tbl()) {
35915 sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
35916- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35917- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
35918- radeon_mem_types_list[i].driver_features = 0;
35919- radeon_mem_types_list[i++].data = NULL;
35920+ pax_open_kernel();
35921+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35922+ *(void **)&radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
35923+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35924+ *(void **)&radeon_mem_types_list[i++].data = NULL;
35925+ pax_close_kernel();
35926 }
35927 #endif
35928 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
35929diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
35930index 5706d2a..17aedaa 100644
35931--- a/drivers/gpu/drm/radeon/rs690.c
35932+++ b/drivers/gpu/drm/radeon/rs690.c
35933@@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
35934 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
35935 rdev->pm.sideport_bandwidth.full)
35936 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
35937- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
35938+ read_delay_latency.full = dfixed_const(800 * 1000);
35939 read_delay_latency.full = dfixed_div(read_delay_latency,
35940 rdev->pm.igp_sideport_mclk);
35941+ a.full = dfixed_const(370);
35942+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
35943 } else {
35944 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
35945 rdev->pm.k8_bandwidth.full)
35946diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
35947index bd2a3b4..122d9ad 100644
35948--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
35949+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
35950@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
35951 static int ttm_pool_mm_shrink(struct shrinker *shrink,
35952 struct shrink_control *sc)
35953 {
35954- static atomic_t start_pool = ATOMIC_INIT(0);
35955+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
35956 unsigned i;
35957- unsigned pool_offset = atomic_add_return(1, &start_pool);
35958+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
35959 struct ttm_page_pool *pool;
35960 int shrink_pages = sc->nr_to_scan;
35961
35962diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
35963index 9f4be3d..cbc9fcc 100644
35964--- a/drivers/gpu/drm/udl/udl_fb.c
35965+++ b/drivers/gpu/drm/udl/udl_fb.c
35966@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
35967 fb_deferred_io_cleanup(info);
35968 kfree(info->fbdefio);
35969 info->fbdefio = NULL;
35970- info->fbops->fb_mmap = udl_fb_mmap;
35971 }
35972
35973 pr_warn("released /dev/fb%d user=%d count=%d\n",
35974diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
35975index 893a650..6190d3b 100644
35976--- a/drivers/gpu/drm/via/via_drv.h
35977+++ b/drivers/gpu/drm/via/via_drv.h
35978@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
35979 typedef uint32_t maskarray_t[5];
35980
35981 typedef struct drm_via_irq {
35982- atomic_t irq_received;
35983+ atomic_unchecked_t irq_received;
35984 uint32_t pending_mask;
35985 uint32_t enable_mask;
35986 wait_queue_head_t irq_queue;
35987@@ -75,7 +75,7 @@ typedef struct drm_via_private {
35988 struct timeval last_vblank;
35989 int last_vblank_valid;
35990 unsigned usec_per_vblank;
35991- atomic_t vbl_received;
35992+ atomic_unchecked_t vbl_received;
35993 drm_via_state_t hc_state;
35994 char pci_buf[VIA_PCI_BUF_SIZE];
35995 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
35996diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
35997index ac98964..5dbf512 100644
35998--- a/drivers/gpu/drm/via/via_irq.c
35999+++ b/drivers/gpu/drm/via/via_irq.c
36000@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
36001 if (crtc != 0)
36002 return 0;
36003
36004- return atomic_read(&dev_priv->vbl_received);
36005+ return atomic_read_unchecked(&dev_priv->vbl_received);
36006 }
36007
36008 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36009@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36010
36011 status = VIA_READ(VIA_REG_INTERRUPT);
36012 if (status & VIA_IRQ_VBLANK_PENDING) {
36013- atomic_inc(&dev_priv->vbl_received);
36014- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
36015+ atomic_inc_unchecked(&dev_priv->vbl_received);
36016+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
36017 do_gettimeofday(&cur_vblank);
36018 if (dev_priv->last_vblank_valid) {
36019 dev_priv->usec_per_vblank =
36020@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36021 dev_priv->last_vblank = cur_vblank;
36022 dev_priv->last_vblank_valid = 1;
36023 }
36024- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
36025+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
36026 DRM_DEBUG("US per vblank is: %u\n",
36027 dev_priv->usec_per_vblank);
36028 }
36029@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36030
36031 for (i = 0; i < dev_priv->num_irqs; ++i) {
36032 if (status & cur_irq->pending_mask) {
36033- atomic_inc(&cur_irq->irq_received);
36034+ atomic_inc_unchecked(&cur_irq->irq_received);
36035 DRM_WAKEUP(&cur_irq->irq_queue);
36036 handled = 1;
36037 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
36038@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
36039 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
36040 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
36041 masks[irq][4]));
36042- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
36043+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
36044 } else {
36045 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
36046 (((cur_irq_sequence =
36047- atomic_read(&cur_irq->irq_received)) -
36048+ atomic_read_unchecked(&cur_irq->irq_received)) -
36049 *sequence) <= (1 << 23)));
36050 }
36051 *sequence = cur_irq_sequence;
36052@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
36053 }
36054
36055 for (i = 0; i < dev_priv->num_irqs; ++i) {
36056- atomic_set(&cur_irq->irq_received, 0);
36057+ atomic_set_unchecked(&cur_irq->irq_received, 0);
36058 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
36059 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
36060 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
36061@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
36062 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
36063 case VIA_IRQ_RELATIVE:
36064 irqwait->request.sequence +=
36065- atomic_read(&cur_irq->irq_received);
36066+ atomic_read_unchecked(&cur_irq->irq_received);
36067 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
36068 case VIA_IRQ_ABSOLUTE:
36069 break;
36070diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36071index 13aeda7..4a952d1 100644
36072--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36073+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36074@@ -290,7 +290,7 @@ struct vmw_private {
36075 * Fencing and IRQs.
36076 */
36077
36078- atomic_t marker_seq;
36079+ atomic_unchecked_t marker_seq;
36080 wait_queue_head_t fence_queue;
36081 wait_queue_head_t fifo_queue;
36082 int fence_queue_waiters; /* Protected by hw_mutex */
36083diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36084index 3eb1486..0a47ee9 100644
36085--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36086+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36087@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
36088 (unsigned int) min,
36089 (unsigned int) fifo->capabilities);
36090
36091- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
36092+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
36093 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
36094 vmw_marker_queue_init(&fifo->marker_queue);
36095 return vmw_fifo_send_fence(dev_priv, &dummy);
36096@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
36097 if (reserveable)
36098 iowrite32(bytes, fifo_mem +
36099 SVGA_FIFO_RESERVED);
36100- return fifo_mem + (next_cmd >> 2);
36101+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
36102 } else {
36103 need_bounce = true;
36104 }
36105@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36106
36107 fm = vmw_fifo_reserve(dev_priv, bytes);
36108 if (unlikely(fm == NULL)) {
36109- *seqno = atomic_read(&dev_priv->marker_seq);
36110+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36111 ret = -ENOMEM;
36112 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
36113 false, 3*HZ);
36114@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36115 }
36116
36117 do {
36118- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
36119+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
36120 } while (*seqno == 0);
36121
36122 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
36123diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
36124index c509d40..3b640c3 100644
36125--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
36126+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
36127@@ -138,7 +138,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
36128 int ret;
36129
36130 num_clips = arg->num_clips;
36131- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
36132+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
36133
36134 if (unlikely(num_clips == 0))
36135 return 0;
36136@@ -222,7 +222,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
36137 int ret;
36138
36139 num_clips = arg->num_clips;
36140- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
36141+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
36142
36143 if (unlikely(num_clips == 0))
36144 return 0;
36145diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36146index 4640adb..e1384ed 100644
36147--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36148+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36149@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
36150 * emitted. Then the fence is stale and signaled.
36151 */
36152
36153- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
36154+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
36155 > VMW_FENCE_WRAP);
36156
36157 return ret;
36158@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
36159
36160 if (fifo_idle)
36161 down_read(&fifo_state->rwsem);
36162- signal_seq = atomic_read(&dev_priv->marker_seq);
36163+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
36164 ret = 0;
36165
36166 for (;;) {
36167diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36168index 8a8725c2..afed796 100644
36169--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36170+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36171@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
36172 while (!vmw_lag_lt(queue, us)) {
36173 spin_lock(&queue->lock);
36174 if (list_empty(&queue->head))
36175- seqno = atomic_read(&dev_priv->marker_seq);
36176+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36177 else {
36178 marker = list_first_entry(&queue->head,
36179 struct vmw_marker, head);
36180diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
36181index e6dbf09..3dd2540 100644
36182--- a/drivers/hid/hid-core.c
36183+++ b/drivers/hid/hid-core.c
36184@@ -2268,7 +2268,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
36185
36186 int hid_add_device(struct hid_device *hdev)
36187 {
36188- static atomic_t id = ATOMIC_INIT(0);
36189+ static atomic_unchecked_t id = ATOMIC_INIT(0);
36190 int ret;
36191
36192 if (WARN_ON(hdev->status & HID_STAT_ADDED))
36193@@ -2302,7 +2302,7 @@ int hid_add_device(struct hid_device *hdev)
36194 /* XXX hack, any other cleaner solution after the driver core
36195 * is converted to allow more than 20 bytes as the device name? */
36196 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
36197- hdev->vendor, hdev->product, atomic_inc_return(&id));
36198+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
36199
36200 hid_debug_register(hdev, dev_name(&hdev->dev));
36201 ret = device_add(&hdev->dev);
36202diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
36203index 90124ff..3761764 100644
36204--- a/drivers/hid/hid-wiimote-debug.c
36205+++ b/drivers/hid/hid-wiimote-debug.c
36206@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
36207 else if (size == 0)
36208 return -EIO;
36209
36210- if (copy_to_user(u, buf, size))
36211+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
36212 return -EFAULT;
36213
36214 *off += size;
36215diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
36216index 0b122f8..b1d8160 100644
36217--- a/drivers/hv/channel.c
36218+++ b/drivers/hv/channel.c
36219@@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
36220 int ret = 0;
36221 int t;
36222
36223- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
36224- atomic_inc(&vmbus_connection.next_gpadl_handle);
36225+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
36226+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
36227
36228 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
36229 if (ret)
36230diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
36231index 7311589..861e9ef 100644
36232--- a/drivers/hv/hv.c
36233+++ b/drivers/hv/hv.c
36234@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
36235 u64 output_address = (output) ? virt_to_phys(output) : 0;
36236 u32 output_address_hi = output_address >> 32;
36237 u32 output_address_lo = output_address & 0xFFFFFFFF;
36238- void *hypercall_page = hv_context.hypercall_page;
36239+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
36240
36241 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
36242 "=a"(hv_status_lo) : "d" (control_hi),
36243diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
36244index 12f2f9e..679603c 100644
36245--- a/drivers/hv/hyperv_vmbus.h
36246+++ b/drivers/hv/hyperv_vmbus.h
36247@@ -591,7 +591,7 @@ enum vmbus_connect_state {
36248 struct vmbus_connection {
36249 enum vmbus_connect_state conn_state;
36250
36251- atomic_t next_gpadl_handle;
36252+ atomic_unchecked_t next_gpadl_handle;
36253
36254 /*
36255 * Represents channel interrupts. Each bit position represents a
36256diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
36257index bf421e0..ce2c897 100644
36258--- a/drivers/hv/vmbus_drv.c
36259+++ b/drivers/hv/vmbus_drv.c
36260@@ -668,10 +668,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
36261 {
36262 int ret = 0;
36263
36264- static atomic_t device_num = ATOMIC_INIT(0);
36265+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
36266
36267 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
36268- atomic_inc_return(&device_num));
36269+ atomic_inc_return_unchecked(&device_num));
36270
36271 child_device_obj->device.bus = &hv_bus;
36272 child_device_obj->device.parent = &hv_acpi_dev->dev;
36273diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
36274index 6351aba..dc4aaf4 100644
36275--- a/drivers/hwmon/acpi_power_meter.c
36276+++ b/drivers/hwmon/acpi_power_meter.c
36277@@ -117,7 +117,7 @@ struct sensor_template {
36278 struct device_attribute *devattr,
36279 const char *buf, size_t count);
36280 int index;
36281-};
36282+} __do_const;
36283
36284 /* Averaging interval */
36285 static int update_avg_interval(struct acpi_power_meter_resource *resource)
36286@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
36287 struct sensor_template *attrs)
36288 {
36289 struct device *dev = &resource->acpi_dev->dev;
36290- struct sensor_device_attribute *sensors =
36291+ sensor_device_attribute_no_const *sensors =
36292 &resource->sensors[resource->num_sensors];
36293 int res = 0;
36294
36295diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
36296index b41baff..4953e4d 100644
36297--- a/drivers/hwmon/applesmc.c
36298+++ b/drivers/hwmon/applesmc.c
36299@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
36300 {
36301 struct applesmc_node_group *grp;
36302 struct applesmc_dev_attr *node;
36303- struct attribute *attr;
36304+ attribute_no_const *attr;
36305 int ret, i;
36306
36307 for (grp = groups; grp->format; grp++) {
36308diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
36309index b25c643..a13460d 100644
36310--- a/drivers/hwmon/asus_atk0110.c
36311+++ b/drivers/hwmon/asus_atk0110.c
36312@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
36313 struct atk_sensor_data {
36314 struct list_head list;
36315 struct atk_data *data;
36316- struct device_attribute label_attr;
36317- struct device_attribute input_attr;
36318- struct device_attribute limit1_attr;
36319- struct device_attribute limit2_attr;
36320+ device_attribute_no_const label_attr;
36321+ device_attribute_no_const input_attr;
36322+ device_attribute_no_const limit1_attr;
36323+ device_attribute_no_const limit2_attr;
36324 char label_attr_name[ATTR_NAME_SIZE];
36325 char input_attr_name[ATTR_NAME_SIZE];
36326 char limit1_attr_name[ATTR_NAME_SIZE];
36327@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
36328 static struct device_attribute atk_name_attr =
36329 __ATTR(name, 0444, atk_name_show, NULL);
36330
36331-static void atk_init_attribute(struct device_attribute *attr, char *name,
36332+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
36333 sysfs_show_func show)
36334 {
36335 sysfs_attr_init(&attr->attr);
36336diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
36337index 3f1e297..a6cafb5 100644
36338--- a/drivers/hwmon/coretemp.c
36339+++ b/drivers/hwmon/coretemp.c
36340@@ -791,7 +791,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
36341 return NOTIFY_OK;
36342 }
36343
36344-static struct notifier_block coretemp_cpu_notifier __refdata = {
36345+static struct notifier_block coretemp_cpu_notifier = {
36346 .notifier_call = coretemp_cpu_callback,
36347 };
36348
36349diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
36350index a14f634..2916ee2 100644
36351--- a/drivers/hwmon/ibmaem.c
36352+++ b/drivers/hwmon/ibmaem.c
36353@@ -925,7 +925,7 @@ static int aem_register_sensors(struct aem_data *data,
36354 struct aem_rw_sensor_template *rw)
36355 {
36356 struct device *dev = &data->pdev->dev;
36357- struct sensor_device_attribute *sensors = data->sensors;
36358+ sensor_device_attribute_no_const *sensors = data->sensors;
36359 int err;
36360
36361 /* Set up read-only sensors */
36362diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
36363index 9add6092..ee7ba3f 100644
36364--- a/drivers/hwmon/pmbus/pmbus_core.c
36365+++ b/drivers/hwmon/pmbus/pmbus_core.c
36366@@ -781,7 +781,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
36367 return 0;
36368 }
36369
36370-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
36371+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
36372 const char *name,
36373 umode_t mode,
36374 ssize_t (*show)(struct device *dev,
36375@@ -798,7 +798,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
36376 dev_attr->store = store;
36377 }
36378
36379-static void pmbus_attr_init(struct sensor_device_attribute *a,
36380+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
36381 const char *name,
36382 umode_t mode,
36383 ssize_t (*show)(struct device *dev,
36384@@ -820,7 +820,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
36385 u16 reg, u8 mask)
36386 {
36387 struct pmbus_boolean *boolean;
36388- struct sensor_device_attribute *a;
36389+ sensor_device_attribute_no_const *a;
36390
36391 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
36392 if (!boolean)
36393@@ -845,7 +845,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
36394 bool update, bool readonly)
36395 {
36396 struct pmbus_sensor *sensor;
36397- struct device_attribute *a;
36398+ device_attribute_no_const *a;
36399
36400 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
36401 if (!sensor)
36402@@ -876,7 +876,7 @@ static int pmbus_add_label(struct pmbus_data *data,
36403 const char *lstring, int index)
36404 {
36405 struct pmbus_label *label;
36406- struct device_attribute *a;
36407+ device_attribute_no_const *a;
36408
36409 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
36410 if (!label)
36411diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
36412index 2507f90..1645765 100644
36413--- a/drivers/hwmon/sht15.c
36414+++ b/drivers/hwmon/sht15.c
36415@@ -169,7 +169,7 @@ struct sht15_data {
36416 int supply_uv;
36417 bool supply_uv_valid;
36418 struct work_struct update_supply_work;
36419- atomic_t interrupt_handled;
36420+ atomic_unchecked_t interrupt_handled;
36421 };
36422
36423 /**
36424@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
36425 ret = gpio_direction_input(data->pdata->gpio_data);
36426 if (ret)
36427 return ret;
36428- atomic_set(&data->interrupt_handled, 0);
36429+ atomic_set_unchecked(&data->interrupt_handled, 0);
36430
36431 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36432 if (gpio_get_value(data->pdata->gpio_data) == 0) {
36433 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
36434 /* Only relevant if the interrupt hasn't occurred. */
36435- if (!atomic_read(&data->interrupt_handled))
36436+ if (!atomic_read_unchecked(&data->interrupt_handled))
36437 schedule_work(&data->read_work);
36438 }
36439 ret = wait_event_timeout(data->wait_queue,
36440@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
36441
36442 /* First disable the interrupt */
36443 disable_irq_nosync(irq);
36444- atomic_inc(&data->interrupt_handled);
36445+ atomic_inc_unchecked(&data->interrupt_handled);
36446 /* Then schedule a reading work struct */
36447 if (data->state != SHT15_READING_NOTHING)
36448 schedule_work(&data->read_work);
36449@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
36450 * If not, then start the interrupt again - care here as could
36451 * have gone low in meantime so verify it hasn't!
36452 */
36453- atomic_set(&data->interrupt_handled, 0);
36454+ atomic_set_unchecked(&data->interrupt_handled, 0);
36455 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36456 /* If still not occurred or another handler was scheduled */
36457 if (gpio_get_value(data->pdata->gpio_data)
36458- || atomic_read(&data->interrupt_handled))
36459+ || atomic_read_unchecked(&data->interrupt_handled))
36460 return;
36461 }
36462
36463diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
36464index 76f157b..9c0db1b 100644
36465--- a/drivers/hwmon/via-cputemp.c
36466+++ b/drivers/hwmon/via-cputemp.c
36467@@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
36468 return NOTIFY_OK;
36469 }
36470
36471-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
36472+static struct notifier_block via_cputemp_cpu_notifier = {
36473 .notifier_call = via_cputemp_cpu_callback,
36474 };
36475
36476diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
36477index 378fcb5..5e91fa8 100644
36478--- a/drivers/i2c/busses/i2c-amd756-s4882.c
36479+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
36480@@ -43,7 +43,7 @@
36481 extern struct i2c_adapter amd756_smbus;
36482
36483 static struct i2c_adapter *s4882_adapter;
36484-static struct i2c_algorithm *s4882_algo;
36485+static i2c_algorithm_no_const *s4882_algo;
36486
36487 /* Wrapper access functions for multiplexed SMBus */
36488 static DEFINE_MUTEX(amd756_lock);
36489diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
36490index 29015eb..af2d8e9 100644
36491--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
36492+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
36493@@ -41,7 +41,7 @@
36494 extern struct i2c_adapter *nforce2_smbus;
36495
36496 static struct i2c_adapter *s4985_adapter;
36497-static struct i2c_algorithm *s4985_algo;
36498+static i2c_algorithm_no_const *s4985_algo;
36499
36500 /* Wrapper access functions for multiplexed SMBus */
36501 static DEFINE_MUTEX(nforce2_lock);
36502diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
36503index c3ccdea..5b3dc1a 100644
36504--- a/drivers/i2c/i2c-dev.c
36505+++ b/drivers/i2c/i2c-dev.c
36506@@ -271,7 +271,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
36507 break;
36508 }
36509
36510- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
36511+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
36512 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
36513 if (IS_ERR(rdwr_pa[i].buf)) {
36514 res = PTR_ERR(rdwr_pa[i].buf);
36515diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
36516index 8126824..55a2798 100644
36517--- a/drivers/ide/ide-cd.c
36518+++ b/drivers/ide/ide-cd.c
36519@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
36520 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
36521 if ((unsigned long)buf & alignment
36522 || blk_rq_bytes(rq) & q->dma_pad_mask
36523- || object_is_on_stack(buf))
36524+ || object_starts_on_stack(buf))
36525 drive->dma = 0;
36526 }
36527 }
36528diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
36529index 8848f16..f8e6dd8 100644
36530--- a/drivers/iio/industrialio-core.c
36531+++ b/drivers/iio/industrialio-core.c
36532@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
36533 }
36534
36535 static
36536-int __iio_device_attr_init(struct device_attribute *dev_attr,
36537+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
36538 const char *postfix,
36539 struct iio_chan_spec const *chan,
36540 ssize_t (*readfunc)(struct device *dev,
36541diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
36542index 784b97c..c9ceadf 100644
36543--- a/drivers/infiniband/core/cm.c
36544+++ b/drivers/infiniband/core/cm.c
36545@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
36546
36547 struct cm_counter_group {
36548 struct kobject obj;
36549- atomic_long_t counter[CM_ATTR_COUNT];
36550+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
36551 };
36552
36553 struct cm_counter_attribute {
36554@@ -1395,7 +1395,7 @@ static void cm_dup_req_handler(struct cm_work *work,
36555 struct ib_mad_send_buf *msg = NULL;
36556 int ret;
36557
36558- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36559+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36560 counter[CM_REQ_COUNTER]);
36561
36562 /* Quick state check to discard duplicate REQs. */
36563@@ -1779,7 +1779,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
36564 if (!cm_id_priv)
36565 return;
36566
36567- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36568+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36569 counter[CM_REP_COUNTER]);
36570 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
36571 if (ret)
36572@@ -1946,7 +1946,7 @@ static int cm_rtu_handler(struct cm_work *work)
36573 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
36574 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
36575 spin_unlock_irq(&cm_id_priv->lock);
36576- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36577+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36578 counter[CM_RTU_COUNTER]);
36579 goto out;
36580 }
36581@@ -2129,7 +2129,7 @@ static int cm_dreq_handler(struct cm_work *work)
36582 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
36583 dreq_msg->local_comm_id);
36584 if (!cm_id_priv) {
36585- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36586+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36587 counter[CM_DREQ_COUNTER]);
36588 cm_issue_drep(work->port, work->mad_recv_wc);
36589 return -EINVAL;
36590@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
36591 case IB_CM_MRA_REP_RCVD:
36592 break;
36593 case IB_CM_TIMEWAIT:
36594- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36595+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36596 counter[CM_DREQ_COUNTER]);
36597 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36598 goto unlock;
36599@@ -2168,7 +2168,7 @@ static int cm_dreq_handler(struct cm_work *work)
36600 cm_free_msg(msg);
36601 goto deref;
36602 case IB_CM_DREQ_RCVD:
36603- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36604+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36605 counter[CM_DREQ_COUNTER]);
36606 goto unlock;
36607 default:
36608@@ -2535,7 +2535,7 @@ static int cm_mra_handler(struct cm_work *work)
36609 ib_modify_mad(cm_id_priv->av.port->mad_agent,
36610 cm_id_priv->msg, timeout)) {
36611 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
36612- atomic_long_inc(&work->port->
36613+ atomic_long_inc_unchecked(&work->port->
36614 counter_group[CM_RECV_DUPLICATES].
36615 counter[CM_MRA_COUNTER]);
36616 goto out;
36617@@ -2544,7 +2544,7 @@ static int cm_mra_handler(struct cm_work *work)
36618 break;
36619 case IB_CM_MRA_REQ_RCVD:
36620 case IB_CM_MRA_REP_RCVD:
36621- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36622+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36623 counter[CM_MRA_COUNTER]);
36624 /* fall through */
36625 default:
36626@@ -2706,7 +2706,7 @@ static int cm_lap_handler(struct cm_work *work)
36627 case IB_CM_LAP_IDLE:
36628 break;
36629 case IB_CM_MRA_LAP_SENT:
36630- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36631+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36632 counter[CM_LAP_COUNTER]);
36633 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36634 goto unlock;
36635@@ -2722,7 +2722,7 @@ static int cm_lap_handler(struct cm_work *work)
36636 cm_free_msg(msg);
36637 goto deref;
36638 case IB_CM_LAP_RCVD:
36639- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36640+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36641 counter[CM_LAP_COUNTER]);
36642 goto unlock;
36643 default:
36644@@ -3006,7 +3006,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
36645 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
36646 if (cur_cm_id_priv) {
36647 spin_unlock_irq(&cm.lock);
36648- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36649+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36650 counter[CM_SIDR_REQ_COUNTER]);
36651 goto out; /* Duplicate message. */
36652 }
36653@@ -3218,10 +3218,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
36654 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
36655 msg->retries = 1;
36656
36657- atomic_long_add(1 + msg->retries,
36658+ atomic_long_add_unchecked(1 + msg->retries,
36659 &port->counter_group[CM_XMIT].counter[attr_index]);
36660 if (msg->retries)
36661- atomic_long_add(msg->retries,
36662+ atomic_long_add_unchecked(msg->retries,
36663 &port->counter_group[CM_XMIT_RETRIES].
36664 counter[attr_index]);
36665
36666@@ -3431,7 +3431,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
36667 }
36668
36669 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
36670- atomic_long_inc(&port->counter_group[CM_RECV].
36671+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
36672 counter[attr_id - CM_ATTR_ID_OFFSET]);
36673
36674 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
36675@@ -3636,7 +3636,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
36676 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
36677
36678 return sprintf(buf, "%ld\n",
36679- atomic_long_read(&group->counter[cm_attr->index]));
36680+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
36681 }
36682
36683 static const struct sysfs_ops cm_counter_ops = {
36684diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
36685index 9f5ad7c..588cd84 100644
36686--- a/drivers/infiniband/core/fmr_pool.c
36687+++ b/drivers/infiniband/core/fmr_pool.c
36688@@ -98,8 +98,8 @@ struct ib_fmr_pool {
36689
36690 struct task_struct *thread;
36691
36692- atomic_t req_ser;
36693- atomic_t flush_ser;
36694+ atomic_unchecked_t req_ser;
36695+ atomic_unchecked_t flush_ser;
36696
36697 wait_queue_head_t force_wait;
36698 };
36699@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36700 struct ib_fmr_pool *pool = pool_ptr;
36701
36702 do {
36703- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
36704+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
36705 ib_fmr_batch_release(pool);
36706
36707- atomic_inc(&pool->flush_ser);
36708+ atomic_inc_unchecked(&pool->flush_ser);
36709 wake_up_interruptible(&pool->force_wait);
36710
36711 if (pool->flush_function)
36712@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36713 }
36714
36715 set_current_state(TASK_INTERRUPTIBLE);
36716- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
36717+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
36718 !kthread_should_stop())
36719 schedule();
36720 __set_current_state(TASK_RUNNING);
36721@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
36722 pool->dirty_watermark = params->dirty_watermark;
36723 pool->dirty_len = 0;
36724 spin_lock_init(&pool->pool_lock);
36725- atomic_set(&pool->req_ser, 0);
36726- atomic_set(&pool->flush_ser, 0);
36727+ atomic_set_unchecked(&pool->req_ser, 0);
36728+ atomic_set_unchecked(&pool->flush_ser, 0);
36729 init_waitqueue_head(&pool->force_wait);
36730
36731 pool->thread = kthread_run(ib_fmr_cleanup_thread,
36732@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
36733 }
36734 spin_unlock_irq(&pool->pool_lock);
36735
36736- serial = atomic_inc_return(&pool->req_ser);
36737+ serial = atomic_inc_return_unchecked(&pool->req_ser);
36738 wake_up_process(pool->thread);
36739
36740 if (wait_event_interruptible(pool->force_wait,
36741- atomic_read(&pool->flush_ser) - serial >= 0))
36742+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
36743 return -EINTR;
36744
36745 return 0;
36746@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
36747 } else {
36748 list_add_tail(&fmr->list, &pool->dirty_list);
36749 if (++pool->dirty_len >= pool->dirty_watermark) {
36750- atomic_inc(&pool->req_ser);
36751+ atomic_inc_unchecked(&pool->req_ser);
36752 wake_up_process(pool->thread);
36753 }
36754 }
36755diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
36756index 903a92d..9262548 100644
36757--- a/drivers/infiniband/hw/cxgb4/mem.c
36758+++ b/drivers/infiniband/hw/cxgb4/mem.c
36759@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
36760 int err;
36761 struct fw_ri_tpte tpt;
36762 u32 stag_idx;
36763- static atomic_t key;
36764+ static atomic_unchecked_t key;
36765
36766 if (c4iw_fatal_error(rdev))
36767 return -EIO;
36768@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
36769 if (rdev->stats.stag.cur > rdev->stats.stag.max)
36770 rdev->stats.stag.max = rdev->stats.stag.cur;
36771 mutex_unlock(&rdev->stats.lock);
36772- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
36773+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
36774 }
36775 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
36776 __func__, stag_state, type, pdid, stag_idx);
36777diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
36778index 79b3dbc..96e5fcc 100644
36779--- a/drivers/infiniband/hw/ipath/ipath_rc.c
36780+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
36781@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
36782 struct ib_atomic_eth *ateth;
36783 struct ipath_ack_entry *e;
36784 u64 vaddr;
36785- atomic64_t *maddr;
36786+ atomic64_unchecked_t *maddr;
36787 u64 sdata;
36788 u32 rkey;
36789 u8 next;
36790@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
36791 IB_ACCESS_REMOTE_ATOMIC)))
36792 goto nack_acc_unlck;
36793 /* Perform atomic OP and save result. */
36794- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
36795+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
36796 sdata = be64_to_cpu(ateth->swap_data);
36797 e = &qp->s_ack_queue[qp->r_head_ack_queue];
36798 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
36799- (u64) atomic64_add_return(sdata, maddr) - sdata :
36800+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
36801 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
36802 be64_to_cpu(ateth->compare_data),
36803 sdata);
36804diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
36805index 1f95bba..9530f87 100644
36806--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
36807+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
36808@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
36809 unsigned long flags;
36810 struct ib_wc wc;
36811 u64 sdata;
36812- atomic64_t *maddr;
36813+ atomic64_unchecked_t *maddr;
36814 enum ib_wc_status send_status;
36815
36816 /*
36817@@ -382,11 +382,11 @@ again:
36818 IB_ACCESS_REMOTE_ATOMIC)))
36819 goto acc_err;
36820 /* Perform atomic OP and save result. */
36821- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
36822+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
36823 sdata = wqe->wr.wr.atomic.compare_add;
36824 *(u64 *) sqp->s_sge.sge.vaddr =
36825 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
36826- (u64) atomic64_add_return(sdata, maddr) - sdata :
36827+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
36828 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
36829 sdata, wqe->wr.wr.atomic.swap);
36830 goto send_comp;
36831diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
36832index 9d3e5c1..d9afe4a 100644
36833--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
36834+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
36835@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
36836 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
36837 }
36838
36839-int mthca_QUERY_FW(struct mthca_dev *dev)
36840+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
36841 {
36842 struct mthca_mailbox *mailbox;
36843 u32 *outbox;
36844diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
36845index ed9a989..e0c5871 100644
36846--- a/drivers/infiniband/hw/mthca/mthca_mr.c
36847+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
36848@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
36849 return key;
36850 }
36851
36852-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
36853+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
36854 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
36855 {
36856 struct mthca_mailbox *mailbox;
36857diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
36858index 4291410..d2ab1fb 100644
36859--- a/drivers/infiniband/hw/nes/nes.c
36860+++ b/drivers/infiniband/hw/nes/nes.c
36861@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
36862 LIST_HEAD(nes_adapter_list);
36863 static LIST_HEAD(nes_dev_list);
36864
36865-atomic_t qps_destroyed;
36866+atomic_unchecked_t qps_destroyed;
36867
36868 static unsigned int ee_flsh_adapter;
36869 static unsigned int sysfs_nonidx_addr;
36870@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
36871 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
36872 struct nes_adapter *nesadapter = nesdev->nesadapter;
36873
36874- atomic_inc(&qps_destroyed);
36875+ atomic_inc_unchecked(&qps_destroyed);
36876
36877 /* Free the control structures */
36878
36879diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
36880index 33cc589..3bd6538 100644
36881--- a/drivers/infiniband/hw/nes/nes.h
36882+++ b/drivers/infiniband/hw/nes/nes.h
36883@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
36884 extern unsigned int wqm_quanta;
36885 extern struct list_head nes_adapter_list;
36886
36887-extern atomic_t cm_connects;
36888-extern atomic_t cm_accepts;
36889-extern atomic_t cm_disconnects;
36890-extern atomic_t cm_closes;
36891-extern atomic_t cm_connecteds;
36892-extern atomic_t cm_connect_reqs;
36893-extern atomic_t cm_rejects;
36894-extern atomic_t mod_qp_timouts;
36895-extern atomic_t qps_created;
36896-extern atomic_t qps_destroyed;
36897-extern atomic_t sw_qps_destroyed;
36898+extern atomic_unchecked_t cm_connects;
36899+extern atomic_unchecked_t cm_accepts;
36900+extern atomic_unchecked_t cm_disconnects;
36901+extern atomic_unchecked_t cm_closes;
36902+extern atomic_unchecked_t cm_connecteds;
36903+extern atomic_unchecked_t cm_connect_reqs;
36904+extern atomic_unchecked_t cm_rejects;
36905+extern atomic_unchecked_t mod_qp_timouts;
36906+extern atomic_unchecked_t qps_created;
36907+extern atomic_unchecked_t qps_destroyed;
36908+extern atomic_unchecked_t sw_qps_destroyed;
36909 extern u32 mh_detected;
36910 extern u32 mh_pauses_sent;
36911 extern u32 cm_packets_sent;
36912@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
36913 extern u32 cm_packets_received;
36914 extern u32 cm_packets_dropped;
36915 extern u32 cm_packets_retrans;
36916-extern atomic_t cm_listens_created;
36917-extern atomic_t cm_listens_destroyed;
36918+extern atomic_unchecked_t cm_listens_created;
36919+extern atomic_unchecked_t cm_listens_destroyed;
36920 extern u32 cm_backlog_drops;
36921-extern atomic_t cm_loopbacks;
36922-extern atomic_t cm_nodes_created;
36923-extern atomic_t cm_nodes_destroyed;
36924-extern atomic_t cm_accel_dropped_pkts;
36925-extern atomic_t cm_resets_recvd;
36926-extern atomic_t pau_qps_created;
36927-extern atomic_t pau_qps_destroyed;
36928+extern atomic_unchecked_t cm_loopbacks;
36929+extern atomic_unchecked_t cm_nodes_created;
36930+extern atomic_unchecked_t cm_nodes_destroyed;
36931+extern atomic_unchecked_t cm_accel_dropped_pkts;
36932+extern atomic_unchecked_t cm_resets_recvd;
36933+extern atomic_unchecked_t pau_qps_created;
36934+extern atomic_unchecked_t pau_qps_destroyed;
36935
36936 extern u32 int_mod_timer_init;
36937 extern u32 int_mod_cq_depth_256;
36938diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
36939index 24b9f1a..00fd004 100644
36940--- a/drivers/infiniband/hw/nes/nes_cm.c
36941+++ b/drivers/infiniband/hw/nes/nes_cm.c
36942@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
36943 u32 cm_packets_retrans;
36944 u32 cm_packets_created;
36945 u32 cm_packets_received;
36946-atomic_t cm_listens_created;
36947-atomic_t cm_listens_destroyed;
36948+atomic_unchecked_t cm_listens_created;
36949+atomic_unchecked_t cm_listens_destroyed;
36950 u32 cm_backlog_drops;
36951-atomic_t cm_loopbacks;
36952-atomic_t cm_nodes_created;
36953-atomic_t cm_nodes_destroyed;
36954-atomic_t cm_accel_dropped_pkts;
36955-atomic_t cm_resets_recvd;
36956+atomic_unchecked_t cm_loopbacks;
36957+atomic_unchecked_t cm_nodes_created;
36958+atomic_unchecked_t cm_nodes_destroyed;
36959+atomic_unchecked_t cm_accel_dropped_pkts;
36960+atomic_unchecked_t cm_resets_recvd;
36961
36962 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
36963 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
36964@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
36965
36966 static struct nes_cm_core *g_cm_core;
36967
36968-atomic_t cm_connects;
36969-atomic_t cm_accepts;
36970-atomic_t cm_disconnects;
36971-atomic_t cm_closes;
36972-atomic_t cm_connecteds;
36973-atomic_t cm_connect_reqs;
36974-atomic_t cm_rejects;
36975+atomic_unchecked_t cm_connects;
36976+atomic_unchecked_t cm_accepts;
36977+atomic_unchecked_t cm_disconnects;
36978+atomic_unchecked_t cm_closes;
36979+atomic_unchecked_t cm_connecteds;
36980+atomic_unchecked_t cm_connect_reqs;
36981+atomic_unchecked_t cm_rejects;
36982
36983 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
36984 {
36985@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
36986 kfree(listener);
36987 listener = NULL;
36988 ret = 0;
36989- atomic_inc(&cm_listens_destroyed);
36990+ atomic_inc_unchecked(&cm_listens_destroyed);
36991 } else {
36992 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
36993 }
36994@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
36995 cm_node->rem_mac);
36996
36997 add_hte_node(cm_core, cm_node);
36998- atomic_inc(&cm_nodes_created);
36999+ atomic_inc_unchecked(&cm_nodes_created);
37000
37001 return cm_node;
37002 }
37003@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
37004 }
37005
37006 atomic_dec(&cm_core->node_cnt);
37007- atomic_inc(&cm_nodes_destroyed);
37008+ atomic_inc_unchecked(&cm_nodes_destroyed);
37009 nesqp = cm_node->nesqp;
37010 if (nesqp) {
37011 nesqp->cm_node = NULL;
37012@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
37013
37014 static void drop_packet(struct sk_buff *skb)
37015 {
37016- atomic_inc(&cm_accel_dropped_pkts);
37017+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
37018 dev_kfree_skb_any(skb);
37019 }
37020
37021@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
37022 {
37023
37024 int reset = 0; /* whether to send reset in case of err.. */
37025- atomic_inc(&cm_resets_recvd);
37026+ atomic_inc_unchecked(&cm_resets_recvd);
37027 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
37028 " refcnt=%d\n", cm_node, cm_node->state,
37029 atomic_read(&cm_node->ref_count));
37030@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
37031 rem_ref_cm_node(cm_node->cm_core, cm_node);
37032 return NULL;
37033 }
37034- atomic_inc(&cm_loopbacks);
37035+ atomic_inc_unchecked(&cm_loopbacks);
37036 loopbackremotenode->loopbackpartner = cm_node;
37037 loopbackremotenode->tcp_cntxt.rcv_wscale =
37038 NES_CM_DEFAULT_RCV_WND_SCALE;
37039@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
37040 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
37041 else {
37042 rem_ref_cm_node(cm_core, cm_node);
37043- atomic_inc(&cm_accel_dropped_pkts);
37044+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
37045 dev_kfree_skb_any(skb);
37046 }
37047 break;
37048@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
37049
37050 if ((cm_id) && (cm_id->event_handler)) {
37051 if (issue_disconn) {
37052- atomic_inc(&cm_disconnects);
37053+ atomic_inc_unchecked(&cm_disconnects);
37054 cm_event.event = IW_CM_EVENT_DISCONNECT;
37055 cm_event.status = disconn_status;
37056 cm_event.local_addr = cm_id->local_addr;
37057@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
37058 }
37059
37060 if (issue_close) {
37061- atomic_inc(&cm_closes);
37062+ atomic_inc_unchecked(&cm_closes);
37063 nes_disconnect(nesqp, 1);
37064
37065 cm_id->provider_data = nesqp;
37066@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37067
37068 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
37069 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
37070- atomic_inc(&cm_accepts);
37071+ atomic_inc_unchecked(&cm_accepts);
37072
37073 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
37074 netdev_refcnt_read(nesvnic->netdev));
37075@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
37076 struct nes_cm_core *cm_core;
37077 u8 *start_buff;
37078
37079- atomic_inc(&cm_rejects);
37080+ atomic_inc_unchecked(&cm_rejects);
37081 cm_node = (struct nes_cm_node *)cm_id->provider_data;
37082 loopback = cm_node->loopbackpartner;
37083 cm_core = cm_node->cm_core;
37084@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37085 ntohl(cm_id->local_addr.sin_addr.s_addr),
37086 ntohs(cm_id->local_addr.sin_port));
37087
37088- atomic_inc(&cm_connects);
37089+ atomic_inc_unchecked(&cm_connects);
37090 nesqp->active_conn = 1;
37091
37092 /* cache the cm_id in the qp */
37093@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
37094 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
37095 return err;
37096 }
37097- atomic_inc(&cm_listens_created);
37098+ atomic_inc_unchecked(&cm_listens_created);
37099 }
37100
37101 cm_id->add_ref(cm_id);
37102@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
37103
37104 if (nesqp->destroyed)
37105 return;
37106- atomic_inc(&cm_connecteds);
37107+ atomic_inc_unchecked(&cm_connecteds);
37108 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
37109 " local port 0x%04X. jiffies = %lu.\n",
37110 nesqp->hwqp.qp_id,
37111@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
37112
37113 cm_id->add_ref(cm_id);
37114 ret = cm_id->event_handler(cm_id, &cm_event);
37115- atomic_inc(&cm_closes);
37116+ atomic_inc_unchecked(&cm_closes);
37117 cm_event.event = IW_CM_EVENT_CLOSE;
37118 cm_event.status = 0;
37119 cm_event.provider_data = cm_id->provider_data;
37120@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
37121 return;
37122 cm_id = cm_node->cm_id;
37123
37124- atomic_inc(&cm_connect_reqs);
37125+ atomic_inc_unchecked(&cm_connect_reqs);
37126 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
37127 cm_node, cm_id, jiffies);
37128
37129@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
37130 return;
37131 cm_id = cm_node->cm_id;
37132
37133- atomic_inc(&cm_connect_reqs);
37134+ atomic_inc_unchecked(&cm_connect_reqs);
37135 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
37136 cm_node, cm_id, jiffies);
37137
37138diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
37139index 4166452..fc952c3 100644
37140--- a/drivers/infiniband/hw/nes/nes_mgt.c
37141+++ b/drivers/infiniband/hw/nes/nes_mgt.c
37142@@ -40,8 +40,8 @@
37143 #include "nes.h"
37144 #include "nes_mgt.h"
37145
37146-atomic_t pau_qps_created;
37147-atomic_t pau_qps_destroyed;
37148+atomic_unchecked_t pau_qps_created;
37149+atomic_unchecked_t pau_qps_destroyed;
37150
37151 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
37152 {
37153@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
37154 {
37155 struct sk_buff *skb;
37156 unsigned long flags;
37157- atomic_inc(&pau_qps_destroyed);
37158+ atomic_inc_unchecked(&pau_qps_destroyed);
37159
37160 /* Free packets that have not yet been forwarded */
37161 /* Lock is acquired by skb_dequeue when removing the skb */
37162@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
37163 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
37164 skb_queue_head_init(&nesqp->pau_list);
37165 spin_lock_init(&nesqp->pau_lock);
37166- atomic_inc(&pau_qps_created);
37167+ atomic_inc_unchecked(&pau_qps_created);
37168 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
37169 }
37170
37171diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
37172index 85cf4d1..05d8e71 100644
37173--- a/drivers/infiniband/hw/nes/nes_nic.c
37174+++ b/drivers/infiniband/hw/nes/nes_nic.c
37175@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
37176 target_stat_values[++index] = mh_detected;
37177 target_stat_values[++index] = mh_pauses_sent;
37178 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
37179- target_stat_values[++index] = atomic_read(&cm_connects);
37180- target_stat_values[++index] = atomic_read(&cm_accepts);
37181- target_stat_values[++index] = atomic_read(&cm_disconnects);
37182- target_stat_values[++index] = atomic_read(&cm_connecteds);
37183- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
37184- target_stat_values[++index] = atomic_read(&cm_rejects);
37185- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
37186- target_stat_values[++index] = atomic_read(&qps_created);
37187- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
37188- target_stat_values[++index] = atomic_read(&qps_destroyed);
37189- target_stat_values[++index] = atomic_read(&cm_closes);
37190+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
37191+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
37192+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
37193+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
37194+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
37195+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
37196+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
37197+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
37198+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
37199+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
37200+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
37201 target_stat_values[++index] = cm_packets_sent;
37202 target_stat_values[++index] = cm_packets_bounced;
37203 target_stat_values[++index] = cm_packets_created;
37204 target_stat_values[++index] = cm_packets_received;
37205 target_stat_values[++index] = cm_packets_dropped;
37206 target_stat_values[++index] = cm_packets_retrans;
37207- target_stat_values[++index] = atomic_read(&cm_listens_created);
37208- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
37209+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
37210+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
37211 target_stat_values[++index] = cm_backlog_drops;
37212- target_stat_values[++index] = atomic_read(&cm_loopbacks);
37213- target_stat_values[++index] = atomic_read(&cm_nodes_created);
37214- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
37215- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
37216- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
37217+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
37218+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
37219+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
37220+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
37221+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
37222 target_stat_values[++index] = nesadapter->free_4kpbl;
37223 target_stat_values[++index] = nesadapter->free_256pbl;
37224 target_stat_values[++index] = int_mod_timer_init;
37225 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
37226 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
37227 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
37228- target_stat_values[++index] = atomic_read(&pau_qps_created);
37229- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
37230+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
37231+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
37232 }
37233
37234 /**
37235diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
37236index 8f67fe2..8960859 100644
37237--- a/drivers/infiniband/hw/nes/nes_verbs.c
37238+++ b/drivers/infiniband/hw/nes/nes_verbs.c
37239@@ -46,9 +46,9 @@
37240
37241 #include <rdma/ib_umem.h>
37242
37243-atomic_t mod_qp_timouts;
37244-atomic_t qps_created;
37245-atomic_t sw_qps_destroyed;
37246+atomic_unchecked_t mod_qp_timouts;
37247+atomic_unchecked_t qps_created;
37248+atomic_unchecked_t sw_qps_destroyed;
37249
37250 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
37251
37252@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
37253 if (init_attr->create_flags)
37254 return ERR_PTR(-EINVAL);
37255
37256- atomic_inc(&qps_created);
37257+ atomic_inc_unchecked(&qps_created);
37258 switch (init_attr->qp_type) {
37259 case IB_QPT_RC:
37260 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
37261@@ -1465,7 +1465,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
37262 struct iw_cm_event cm_event;
37263 int ret = 0;
37264
37265- atomic_inc(&sw_qps_destroyed);
37266+ atomic_inc_unchecked(&sw_qps_destroyed);
37267 nesqp->destroyed = 1;
37268
37269 /* Blow away the connection if it exists. */
37270diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
37271index 4d11575..3e890e5 100644
37272--- a/drivers/infiniband/hw/qib/qib.h
37273+++ b/drivers/infiniband/hw/qib/qib.h
37274@@ -51,6 +51,7 @@
37275 #include <linux/completion.h>
37276 #include <linux/kref.h>
37277 #include <linux/sched.h>
37278+#include <linux/slab.h>
37279
37280 #include "qib_common.h"
37281 #include "qib_verbs.h"
37282diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
37283index da739d9..da1c7f4 100644
37284--- a/drivers/input/gameport/gameport.c
37285+++ b/drivers/input/gameport/gameport.c
37286@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
37287 */
37288 static void gameport_init_port(struct gameport *gameport)
37289 {
37290- static atomic_t gameport_no = ATOMIC_INIT(0);
37291+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
37292
37293 __module_get(THIS_MODULE);
37294
37295 mutex_init(&gameport->drv_mutex);
37296 device_initialize(&gameport->dev);
37297 dev_set_name(&gameport->dev, "gameport%lu",
37298- (unsigned long)atomic_inc_return(&gameport_no) - 1);
37299+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
37300 gameport->dev.bus = &gameport_bus;
37301 gameport->dev.release = gameport_release_port;
37302 if (gameport->parent)
37303diff --git a/drivers/input/input.c b/drivers/input/input.c
37304index c044699..174d71a 100644
37305--- a/drivers/input/input.c
37306+++ b/drivers/input/input.c
37307@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
37308 */
37309 int input_register_device(struct input_dev *dev)
37310 {
37311- static atomic_t input_no = ATOMIC_INIT(0);
37312+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
37313 struct input_devres *devres = NULL;
37314 struct input_handler *handler;
37315 unsigned int packet_size;
37316@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
37317 dev->setkeycode = input_default_setkeycode;
37318
37319 dev_set_name(&dev->dev, "input%ld",
37320- (unsigned long) atomic_inc_return(&input_no) - 1);
37321+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
37322
37323 error = device_add(&dev->dev);
37324 if (error)
37325diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
37326index 04c69af..5f92d00 100644
37327--- a/drivers/input/joystick/sidewinder.c
37328+++ b/drivers/input/joystick/sidewinder.c
37329@@ -30,6 +30,7 @@
37330 #include <linux/kernel.h>
37331 #include <linux/module.h>
37332 #include <linux/slab.h>
37333+#include <linux/sched.h>
37334 #include <linux/init.h>
37335 #include <linux/input.h>
37336 #include <linux/gameport.h>
37337diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
37338index d6cbfe9..6225402 100644
37339--- a/drivers/input/joystick/xpad.c
37340+++ b/drivers/input/joystick/xpad.c
37341@@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
37342
37343 static int xpad_led_probe(struct usb_xpad *xpad)
37344 {
37345- static atomic_t led_seq = ATOMIC_INIT(0);
37346+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
37347 long led_no;
37348 struct xpad_led *led;
37349 struct led_classdev *led_cdev;
37350@@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
37351 if (!led)
37352 return -ENOMEM;
37353
37354- led_no = (long)atomic_inc_return(&led_seq) - 1;
37355+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
37356
37357 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
37358 led->xpad = xpad;
37359diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
37360index 2f0b39d..7370f13 100644
37361--- a/drivers/input/mouse/psmouse.h
37362+++ b/drivers/input/mouse/psmouse.h
37363@@ -116,7 +116,7 @@ struct psmouse_attribute {
37364 ssize_t (*set)(struct psmouse *psmouse, void *data,
37365 const char *buf, size_t count);
37366 bool protect;
37367-};
37368+} __do_const;
37369 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
37370
37371 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
37372diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
37373index 4c842c3..590b0bf 100644
37374--- a/drivers/input/mousedev.c
37375+++ b/drivers/input/mousedev.c
37376@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
37377
37378 spin_unlock_irq(&client->packet_lock);
37379
37380- if (copy_to_user(buffer, data, count))
37381+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
37382 return -EFAULT;
37383
37384 return count;
37385diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
37386index 25fc597..558bf3b3 100644
37387--- a/drivers/input/serio/serio.c
37388+++ b/drivers/input/serio/serio.c
37389@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
37390 */
37391 static void serio_init_port(struct serio *serio)
37392 {
37393- static atomic_t serio_no = ATOMIC_INIT(0);
37394+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
37395
37396 __module_get(THIS_MODULE);
37397
37398@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
37399 mutex_init(&serio->drv_mutex);
37400 device_initialize(&serio->dev);
37401 dev_set_name(&serio->dev, "serio%ld",
37402- (long)atomic_inc_return(&serio_no) - 1);
37403+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
37404 serio->dev.bus = &serio_bus;
37405 serio->dev.release = serio_release_port;
37406 serio->dev.groups = serio_device_attr_groups;
37407diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
37408index b972d43..8943713 100644
37409--- a/drivers/iommu/iommu.c
37410+++ b/drivers/iommu/iommu.c
37411@@ -554,7 +554,7 @@ static struct notifier_block iommu_bus_nb = {
37412 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
37413 {
37414 bus_register_notifier(bus, &iommu_bus_nb);
37415- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
37416+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
37417 }
37418
37419 /**
37420diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
37421index 7c11ff3..5b2d7a7 100644
37422--- a/drivers/iommu/irq_remapping.c
37423+++ b/drivers/iommu/irq_remapping.c
37424@@ -369,10 +369,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
37425
37426 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
37427 {
37428- chip->irq_print_chip = ir_print_prefix;
37429- chip->irq_ack = ir_ack_apic_edge;
37430- chip->irq_eoi = ir_ack_apic_level;
37431- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
37432+ pax_open_kernel();
37433+ *(void **)&chip->irq_print_chip = ir_print_prefix;
37434+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
37435+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
37436+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
37437+ pax_close_kernel();
37438 }
37439
37440 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
37441diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
37442index fc6aebf..762c5f5 100644
37443--- a/drivers/irqchip/irq-gic.c
37444+++ b/drivers/irqchip/irq-gic.c
37445@@ -83,7 +83,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
37446 * Supported arch specific GIC irq extension.
37447 * Default make them NULL.
37448 */
37449-struct irq_chip gic_arch_extn = {
37450+irq_chip_no_const gic_arch_extn = {
37451 .irq_eoi = NULL,
37452 .irq_mask = NULL,
37453 .irq_unmask = NULL,
37454@@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
37455 chained_irq_exit(chip, desc);
37456 }
37457
37458-static struct irq_chip gic_chip = {
37459+static irq_chip_no_const gic_chip __read_only = {
37460 .name = "GIC",
37461 .irq_mask = gic_mask_irq,
37462 .irq_unmask = gic_unmask_irq,
37463diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
37464index 89562a8..218999b 100644
37465--- a/drivers/isdn/capi/capi.c
37466+++ b/drivers/isdn/capi/capi.c
37467@@ -81,8 +81,8 @@ struct capiminor {
37468
37469 struct capi20_appl *ap;
37470 u32 ncci;
37471- atomic_t datahandle;
37472- atomic_t msgid;
37473+ atomic_unchecked_t datahandle;
37474+ atomic_unchecked_t msgid;
37475
37476 struct tty_port port;
37477 int ttyinstop;
37478@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
37479 capimsg_setu16(s, 2, mp->ap->applid);
37480 capimsg_setu8 (s, 4, CAPI_DATA_B3);
37481 capimsg_setu8 (s, 5, CAPI_RESP);
37482- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
37483+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
37484 capimsg_setu32(s, 8, mp->ncci);
37485 capimsg_setu16(s, 12, datahandle);
37486 }
37487@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
37488 mp->outbytes -= len;
37489 spin_unlock_bh(&mp->outlock);
37490
37491- datahandle = atomic_inc_return(&mp->datahandle);
37492+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
37493 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
37494 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37495 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37496 capimsg_setu16(skb->data, 2, mp->ap->applid);
37497 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
37498 capimsg_setu8 (skb->data, 5, CAPI_REQ);
37499- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
37500+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
37501 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
37502 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
37503 capimsg_setu16(skb->data, 16, len); /* Data length */
37504diff --git a/drivers/isdn/capi/kcapi.c b/drivers/isdn/capi/kcapi.c
37505index 9b1b274..c123709 100644
37506--- a/drivers/isdn/capi/kcapi.c
37507+++ b/drivers/isdn/capi/kcapi.c
37508@@ -93,7 +93,7 @@ capi_ctr_put(struct capi_ctr *ctr)
37509
37510 static inline struct capi_ctr *get_capi_ctr_by_nr(u16 contr)
37511 {
37512- if (contr - 1 >= CAPI_MAXCONTR)
37513+ if (contr < 1 || contr - 1 >= CAPI_MAXCONTR)
37514 return NULL;
37515
37516 return capi_controller[contr - 1];
37517@@ -103,7 +103,7 @@ static inline struct capi20_appl *__get_capi_appl_by_nr(u16 applid)
37518 {
37519 lockdep_assert_held(&capi_controller_lock);
37520
37521- if (applid - 1 >= CAPI_MAXAPPL)
37522+ if (applid < 1 || applid - 1 >= CAPI_MAXAPPL)
37523 return NULL;
37524
37525 return capi_applications[applid - 1];
37526@@ -111,7 +111,7 @@ static inline struct capi20_appl *__get_capi_appl_by_nr(u16 applid)
37527
37528 static inline struct capi20_appl *get_capi_appl_by_nr(u16 applid)
37529 {
37530- if (applid - 1 >= CAPI_MAXAPPL)
37531+ if (applid < 1 || applid - 1 >= CAPI_MAXAPPL)
37532 return NULL;
37533
37534 return rcu_dereference(capi_applications[applid - 1]);
37535diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
37536index e2b5396..c5486dc 100644
37537--- a/drivers/isdn/gigaset/interface.c
37538+++ b/drivers/isdn/gigaset/interface.c
37539@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
37540 }
37541 tty->driver_data = cs;
37542
37543- ++cs->port.count;
37544+ atomic_inc(&cs->port.count);
37545
37546- if (cs->port.count == 1) {
37547+ if (atomic_read(&cs->port.count) == 1) {
37548 tty_port_tty_set(&cs->port, tty);
37549 cs->port.low_latency = 1;
37550 }
37551@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
37552
37553 if (!cs->connected)
37554 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
37555- else if (!cs->port.count)
37556+ else if (!atomic_read(&cs->port.count))
37557 dev_warn(cs->dev, "%s: device not opened\n", __func__);
37558- else if (!--cs->port.count)
37559+ else if (!atomic_dec_return(&cs->port.count))
37560 tty_port_tty_set(&cs->port, NULL);
37561
37562 mutex_unlock(&cs->mutex);
37563diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
37564index 821f7ac..28d4030 100644
37565--- a/drivers/isdn/hardware/avm/b1.c
37566+++ b/drivers/isdn/hardware/avm/b1.c
37567@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
37568 }
37569 if (left) {
37570 if (t4file->user) {
37571- if (copy_from_user(buf, dp, left))
37572+ if (left > sizeof buf || copy_from_user(buf, dp, left))
37573 return -EFAULT;
37574 } else {
37575 memcpy(buf, dp, left);
37576@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
37577 }
37578 if (left) {
37579 if (config->user) {
37580- if (copy_from_user(buf, dp, left))
37581+ if (left > sizeof buf || copy_from_user(buf, dp, left))
37582 return -EFAULT;
37583 } else {
37584 memcpy(buf, dp, left);
37585diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
37586index ebaebdf..acd4405 100644
37587--- a/drivers/isdn/i4l/isdn_tty.c
37588+++ b/drivers/isdn/i4l/isdn_tty.c
37589@@ -1511,9 +1511,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
37590
37591 #ifdef ISDN_DEBUG_MODEM_OPEN
37592 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
37593- port->count);
37594+ atomic_read(&port->count));
37595 #endif
37596- port->count++;
37597+ atomic_inc(&port->count);
37598 port->tty = tty;
37599 /*
37600 * Start up serial port
37601@@ -1557,7 +1557,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37602 #endif
37603 return;
37604 }
37605- if ((tty->count == 1) && (port->count != 1)) {
37606+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
37607 /*
37608 * Uh, oh. tty->count is 1, which means that the tty
37609 * structure will be freed. Info->count should always
37610@@ -1566,15 +1566,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37611 * serial port won't be shutdown.
37612 */
37613 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
37614- "info->count is %d\n", port->count);
37615- port->count = 1;
37616+ "info->count is %d\n", atomic_read(&port->count));
37617+ atomic_set(&port->count, 1);
37618 }
37619- if (--port->count < 0) {
37620+ if (atomic_dec_return(&port->count) < 0) {
37621 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
37622- info->line, port->count);
37623- port->count = 0;
37624+ info->line, atomic_read(&port->count));
37625+ atomic_set(&port->count, 0);
37626 }
37627- if (port->count) {
37628+ if (atomic_read(&port->count)) {
37629 #ifdef ISDN_DEBUG_MODEM_OPEN
37630 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
37631 #endif
37632@@ -1628,7 +1628,7 @@ isdn_tty_hangup(struct tty_struct *tty)
37633 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
37634 return;
37635 isdn_tty_shutdown(info);
37636- port->count = 0;
37637+ atomic_set(&port->count, 0);
37638 port->flags &= ~ASYNC_NORMAL_ACTIVE;
37639 port->tty = NULL;
37640 wake_up_interruptible(&port->open_wait);
37641@@ -1973,7 +1973,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
37642 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
37643 modem_info *info = &dev->mdm.info[i];
37644
37645- if (info->port.count == 0)
37646+ if (atomic_read(&info->port.count) == 0)
37647 continue;
37648 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
37649 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
37650diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
37651index e74df7c..03a03ba 100644
37652--- a/drivers/isdn/icn/icn.c
37653+++ b/drivers/isdn/icn/icn.c
37654@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
37655 if (count > len)
37656 count = len;
37657 if (user) {
37658- if (copy_from_user(msg, buf, count))
37659+ if (count > sizeof msg || copy_from_user(msg, buf, count))
37660 return -EFAULT;
37661 } else
37662 memcpy(msg, buf, count);
37663diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
37664index 6a8405d..0bd1c7e 100644
37665--- a/drivers/leds/leds-clevo-mail.c
37666+++ b/drivers/leds/leds-clevo-mail.c
37667@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
37668 * detected as working, but in reality it is not) as low as
37669 * possible.
37670 */
37671-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
37672+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
37673 {
37674 .callback = clevo_mail_led_dmi_callback,
37675 .ident = "Clevo D410J",
37676diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
37677index 64e204e..c6bf189 100644
37678--- a/drivers/leds/leds-ss4200.c
37679+++ b/drivers/leds/leds-ss4200.c
37680@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
37681 * detected as working, but in reality it is not) as low as
37682 * possible.
37683 */
37684-static struct dmi_system_id __initdata nas_led_whitelist[] = {
37685+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
37686 {
37687 .callback = ss4200_led_dmi_callback,
37688 .ident = "Intel SS4200-E",
37689diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
37690index a5ebc00..982886f 100644
37691--- a/drivers/lguest/core.c
37692+++ b/drivers/lguest/core.c
37693@@ -92,9 +92,17 @@ static __init int map_switcher(void)
37694 * it's worked so far. The end address needs +1 because __get_vm_area
37695 * allocates an extra guard page, so we need space for that.
37696 */
37697+
37698+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
37699+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37700+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
37701+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37702+#else
37703 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37704 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
37705 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37706+#endif
37707+
37708 if (!switcher_vma) {
37709 err = -ENOMEM;
37710 printk("lguest: could not map switcher pages high\n");
37711@@ -119,7 +127,7 @@ static __init int map_switcher(void)
37712 * Now the Switcher is mapped at the right address, we can't fail!
37713 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
37714 */
37715- memcpy(switcher_vma->addr, start_switcher_text,
37716+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
37717 end_switcher_text - start_switcher_text);
37718
37719 printk(KERN_INFO "lguest: mapped switcher at %p\n",
37720diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
37721index 3b62be16..e33134a 100644
37722--- a/drivers/lguest/page_tables.c
37723+++ b/drivers/lguest/page_tables.c
37724@@ -532,7 +532,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
37725 /*:*/
37726
37727 #ifdef CONFIG_X86_PAE
37728-static void release_pmd(pmd_t *spmd)
37729+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
37730 {
37731 /* If the entry's not present, there's nothing to release. */
37732 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
37733diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
37734index 4af12e1..0e89afe 100644
37735--- a/drivers/lguest/x86/core.c
37736+++ b/drivers/lguest/x86/core.c
37737@@ -59,7 +59,7 @@ static struct {
37738 /* Offset from where switcher.S was compiled to where we've copied it */
37739 static unsigned long switcher_offset(void)
37740 {
37741- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
37742+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
37743 }
37744
37745 /* This cpu's struct lguest_pages. */
37746@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
37747 * These copies are pretty cheap, so we do them unconditionally: */
37748 /* Save the current Host top-level page directory.
37749 */
37750+
37751+#ifdef CONFIG_PAX_PER_CPU_PGD
37752+ pages->state.host_cr3 = read_cr3();
37753+#else
37754 pages->state.host_cr3 = __pa(current->mm->pgd);
37755+#endif
37756+
37757 /*
37758 * Set up the Guest's page tables to see this CPU's pages (and no
37759 * other CPU's pages).
37760@@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
37761 * compiled-in switcher code and the high-mapped copy we just made.
37762 */
37763 for (i = 0; i < IDT_ENTRIES; i++)
37764- default_idt_entries[i] += switcher_offset();
37765+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
37766
37767 /*
37768 * Set up the Switcher's per-cpu areas.
37769@@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
37770 * it will be undisturbed when we switch. To change %cs and jump we
37771 * need this structure to feed to Intel's "lcall" instruction.
37772 */
37773- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
37774+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
37775 lguest_entry.segment = LGUEST_CS;
37776
37777 /*
37778diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
37779index 40634b0..4f5855e 100644
37780--- a/drivers/lguest/x86/switcher_32.S
37781+++ b/drivers/lguest/x86/switcher_32.S
37782@@ -87,6 +87,7 @@
37783 #include <asm/page.h>
37784 #include <asm/segment.h>
37785 #include <asm/lguest.h>
37786+#include <asm/processor-flags.h>
37787
37788 // We mark the start of the code to copy
37789 // It's placed in .text tho it's never run here
37790@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
37791 // Changes type when we load it: damn Intel!
37792 // For after we switch over our page tables
37793 // That entry will be read-only: we'd crash.
37794+
37795+#ifdef CONFIG_PAX_KERNEXEC
37796+ mov %cr0, %edx
37797+ xor $X86_CR0_WP, %edx
37798+ mov %edx, %cr0
37799+#endif
37800+
37801 movl $(GDT_ENTRY_TSS*8), %edx
37802 ltr %dx
37803
37804@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
37805 // Let's clear it again for our return.
37806 // The GDT descriptor of the Host
37807 // Points to the table after two "size" bytes
37808- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
37809+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
37810 // Clear "used" from type field (byte 5, bit 2)
37811- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
37812+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
37813+
37814+#ifdef CONFIG_PAX_KERNEXEC
37815+ mov %cr0, %eax
37816+ xor $X86_CR0_WP, %eax
37817+ mov %eax, %cr0
37818+#endif
37819
37820 // Once our page table's switched, the Guest is live!
37821 // The Host fades as we run this final step.
37822@@ -295,13 +309,12 @@ deliver_to_host:
37823 // I consulted gcc, and it gave
37824 // These instructions, which I gladly credit:
37825 leal (%edx,%ebx,8), %eax
37826- movzwl (%eax),%edx
37827- movl 4(%eax), %eax
37828- xorw %ax, %ax
37829- orl %eax, %edx
37830+ movl 4(%eax), %edx
37831+ movw (%eax), %dx
37832 // Now the address of the handler's in %edx
37833 // We call it now: its "iret" drops us home.
37834- jmp *%edx
37835+ ljmp $__KERNEL_CS, $1f
37836+1: jmp *%edx
37837
37838 // Every interrupt can come to us here
37839 // But we must truly tell each apart.
37840diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
37841index 4fd9d6a..834fa03 100644
37842--- a/drivers/md/bitmap.c
37843+++ b/drivers/md/bitmap.c
37844@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
37845 chunk_kb ? "KB" : "B");
37846 if (bitmap->storage.file) {
37847 seq_printf(seq, ", file: ");
37848- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
37849+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
37850 }
37851
37852 seq_printf(seq, "\n");
37853diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
37854index aa04f02..2a1309e 100644
37855--- a/drivers/md/dm-ioctl.c
37856+++ b/drivers/md/dm-ioctl.c
37857@@ -1694,7 +1694,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
37858 cmd == DM_LIST_VERSIONS_CMD)
37859 return 0;
37860
37861- if ((cmd == DM_DEV_CREATE_CMD)) {
37862+ if (cmd == DM_DEV_CREATE_CMD) {
37863 if (!*param->name) {
37864 DMWARN("name not supplied when creating device");
37865 return -EINVAL;
37866diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
37867index d053098..05cc375 100644
37868--- a/drivers/md/dm-raid1.c
37869+++ b/drivers/md/dm-raid1.c
37870@@ -40,7 +40,7 @@ enum dm_raid1_error {
37871
37872 struct mirror {
37873 struct mirror_set *ms;
37874- atomic_t error_count;
37875+ atomic_unchecked_t error_count;
37876 unsigned long error_type;
37877 struct dm_dev *dev;
37878 sector_t offset;
37879@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
37880 struct mirror *m;
37881
37882 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
37883- if (!atomic_read(&m->error_count))
37884+ if (!atomic_read_unchecked(&m->error_count))
37885 return m;
37886
37887 return NULL;
37888@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
37889 * simple way to tell if a device has encountered
37890 * errors.
37891 */
37892- atomic_inc(&m->error_count);
37893+ atomic_inc_unchecked(&m->error_count);
37894
37895 if (test_and_set_bit(error_type, &m->error_type))
37896 return;
37897@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
37898 struct mirror *m = get_default_mirror(ms);
37899
37900 do {
37901- if (likely(!atomic_read(&m->error_count)))
37902+ if (likely(!atomic_read_unchecked(&m->error_count)))
37903 return m;
37904
37905 if (m-- == ms->mirror)
37906@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
37907 {
37908 struct mirror *default_mirror = get_default_mirror(m->ms);
37909
37910- return !atomic_read(&default_mirror->error_count);
37911+ return !atomic_read_unchecked(&default_mirror->error_count);
37912 }
37913
37914 static int mirror_available(struct mirror_set *ms, struct bio *bio)
37915@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
37916 */
37917 if (likely(region_in_sync(ms, region, 1)))
37918 m = choose_mirror(ms, bio->bi_sector);
37919- else if (m && atomic_read(&m->error_count))
37920+ else if (m && atomic_read_unchecked(&m->error_count))
37921 m = NULL;
37922
37923 if (likely(m))
37924@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
37925 }
37926
37927 ms->mirror[mirror].ms = ms;
37928- atomic_set(&(ms->mirror[mirror].error_count), 0);
37929+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
37930 ms->mirror[mirror].error_type = 0;
37931 ms->mirror[mirror].offset = offset;
37932
37933@@ -1340,7 +1340,7 @@ static void mirror_resume(struct dm_target *ti)
37934 */
37935 static char device_status_char(struct mirror *m)
37936 {
37937- if (!atomic_read(&(m->error_count)))
37938+ if (!atomic_read_unchecked(&(m->error_count)))
37939 return 'A';
37940
37941 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
37942diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
37943index 7b8b2b9..9c7d145 100644
37944--- a/drivers/md/dm-stripe.c
37945+++ b/drivers/md/dm-stripe.c
37946@@ -20,7 +20,7 @@ struct stripe {
37947 struct dm_dev *dev;
37948 sector_t physical_start;
37949
37950- atomic_t error_count;
37951+ atomic_unchecked_t error_count;
37952 };
37953
37954 struct stripe_c {
37955@@ -185,7 +185,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
37956 kfree(sc);
37957 return r;
37958 }
37959- atomic_set(&(sc->stripe[i].error_count), 0);
37960+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
37961 }
37962
37963 ti->private = sc;
37964@@ -326,7 +326,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
37965 DMEMIT("%d ", sc->stripes);
37966 for (i = 0; i < sc->stripes; i++) {
37967 DMEMIT("%s ", sc->stripe[i].dev->name);
37968- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
37969+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
37970 'D' : 'A';
37971 }
37972 buffer[i] = '\0';
37973@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
37974 */
37975 for (i = 0; i < sc->stripes; i++)
37976 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
37977- atomic_inc(&(sc->stripe[i].error_count));
37978- if (atomic_read(&(sc->stripe[i].error_count)) <
37979+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
37980+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
37981 DM_IO_ERROR_THRESHOLD)
37982 schedule_work(&sc->trigger_event);
37983 }
37984diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
37985index 1ff252a..ee384c1 100644
37986--- a/drivers/md/dm-table.c
37987+++ b/drivers/md/dm-table.c
37988@@ -389,7 +389,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
37989 if (!dev_size)
37990 return 0;
37991
37992- if ((start >= dev_size) || (start + len > dev_size)) {
37993+ if ((start >= dev_size) || (len > dev_size - start)) {
37994 DMWARN("%s: %s too small for target: "
37995 "start=%llu, len=%llu, dev_size=%llu",
37996 dm_device_name(ti->table->md), bdevname(bdev, b),
37997diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
37998index 00cee02..b89a29d 100644
37999--- a/drivers/md/dm-thin-metadata.c
38000+++ b/drivers/md/dm-thin-metadata.c
38001@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
38002 {
38003 pmd->info.tm = pmd->tm;
38004 pmd->info.levels = 2;
38005- pmd->info.value_type.context = pmd->data_sm;
38006+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
38007 pmd->info.value_type.size = sizeof(__le64);
38008 pmd->info.value_type.inc = data_block_inc;
38009 pmd->info.value_type.dec = data_block_dec;
38010@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
38011
38012 pmd->bl_info.tm = pmd->tm;
38013 pmd->bl_info.levels = 1;
38014- pmd->bl_info.value_type.context = pmd->data_sm;
38015+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
38016 pmd->bl_info.value_type.size = sizeof(__le64);
38017 pmd->bl_info.value_type.inc = data_block_inc;
38018 pmd->bl_info.value_type.dec = data_block_dec;
38019diff --git a/drivers/md/dm.c b/drivers/md/dm.c
38020index 9a0bdad..4df9543 100644
38021--- a/drivers/md/dm.c
38022+++ b/drivers/md/dm.c
38023@@ -169,9 +169,9 @@ struct mapped_device {
38024 /*
38025 * Event handling.
38026 */
38027- atomic_t event_nr;
38028+ atomic_unchecked_t event_nr;
38029 wait_queue_head_t eventq;
38030- atomic_t uevent_seq;
38031+ atomic_unchecked_t uevent_seq;
38032 struct list_head uevent_list;
38033 spinlock_t uevent_lock; /* Protect access to uevent_list */
38034
38035@@ -1879,8 +1879,8 @@ static struct mapped_device *alloc_dev(int minor)
38036 rwlock_init(&md->map_lock);
38037 atomic_set(&md->holders, 1);
38038 atomic_set(&md->open_count, 0);
38039- atomic_set(&md->event_nr, 0);
38040- atomic_set(&md->uevent_seq, 0);
38041+ atomic_set_unchecked(&md->event_nr, 0);
38042+ atomic_set_unchecked(&md->uevent_seq, 0);
38043 INIT_LIST_HEAD(&md->uevent_list);
38044 spin_lock_init(&md->uevent_lock);
38045
38046@@ -2028,7 +2028,7 @@ static void event_callback(void *context)
38047
38048 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
38049
38050- atomic_inc(&md->event_nr);
38051+ atomic_inc_unchecked(&md->event_nr);
38052 wake_up(&md->eventq);
38053 }
38054
38055@@ -2685,18 +2685,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
38056
38057 uint32_t dm_next_uevent_seq(struct mapped_device *md)
38058 {
38059- return atomic_add_return(1, &md->uevent_seq);
38060+ return atomic_add_return_unchecked(1, &md->uevent_seq);
38061 }
38062
38063 uint32_t dm_get_event_nr(struct mapped_device *md)
38064 {
38065- return atomic_read(&md->event_nr);
38066+ return atomic_read_unchecked(&md->event_nr);
38067 }
38068
38069 int dm_wait_event(struct mapped_device *md, int event_nr)
38070 {
38071 return wait_event_interruptible(md->eventq,
38072- (event_nr != atomic_read(&md->event_nr)));
38073+ (event_nr != atomic_read_unchecked(&md->event_nr)));
38074 }
38075
38076 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
38077diff --git a/drivers/md/md.c b/drivers/md/md.c
38078index a4a93b9..4747b63 100644
38079--- a/drivers/md/md.c
38080+++ b/drivers/md/md.c
38081@@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
38082 * start build, activate spare
38083 */
38084 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
38085-static atomic_t md_event_count;
38086+static atomic_unchecked_t md_event_count;
38087 void md_new_event(struct mddev *mddev)
38088 {
38089- atomic_inc(&md_event_count);
38090+ atomic_inc_unchecked(&md_event_count);
38091 wake_up(&md_event_waiters);
38092 }
38093 EXPORT_SYMBOL_GPL(md_new_event);
38094@@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
38095 */
38096 static void md_new_event_inintr(struct mddev *mddev)
38097 {
38098- atomic_inc(&md_event_count);
38099+ atomic_inc_unchecked(&md_event_count);
38100 wake_up(&md_event_waiters);
38101 }
38102
38103@@ -1507,7 +1507,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
38104 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
38105 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
38106 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
38107- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
38108+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
38109
38110 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
38111 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
38112@@ -1751,7 +1751,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
38113 else
38114 sb->resync_offset = cpu_to_le64(0);
38115
38116- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
38117+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
38118
38119 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
38120 sb->size = cpu_to_le64(mddev->dev_sectors);
38121@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
38122 static ssize_t
38123 errors_show(struct md_rdev *rdev, char *page)
38124 {
38125- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
38126+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
38127 }
38128
38129 static ssize_t
38130@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
38131 char *e;
38132 unsigned long n = simple_strtoul(buf, &e, 10);
38133 if (*buf && (*e == 0 || *e == '\n')) {
38134- atomic_set(&rdev->corrected_errors, n);
38135+ atomic_set_unchecked(&rdev->corrected_errors, n);
38136 return len;
38137 }
38138 return -EINVAL;
38139@@ -3210,8 +3210,8 @@ int md_rdev_init(struct md_rdev *rdev)
38140 rdev->sb_loaded = 0;
38141 rdev->bb_page = NULL;
38142 atomic_set(&rdev->nr_pending, 0);
38143- atomic_set(&rdev->read_errors, 0);
38144- atomic_set(&rdev->corrected_errors, 0);
38145+ atomic_set_unchecked(&rdev->read_errors, 0);
38146+ atomic_set_unchecked(&rdev->corrected_errors, 0);
38147
38148 INIT_LIST_HEAD(&rdev->same_set);
38149 init_waitqueue_head(&rdev->blocked_wait);
38150@@ -6994,7 +6994,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
38151
38152 spin_unlock(&pers_lock);
38153 seq_printf(seq, "\n");
38154- seq->poll_event = atomic_read(&md_event_count);
38155+ seq->poll_event = atomic_read_unchecked(&md_event_count);
38156 return 0;
38157 }
38158 if (v == (void*)2) {
38159@@ -7097,7 +7097,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
38160 return error;
38161
38162 seq = file->private_data;
38163- seq->poll_event = atomic_read(&md_event_count);
38164+ seq->poll_event = atomic_read_unchecked(&md_event_count);
38165 return error;
38166 }
38167
38168@@ -7111,7 +7111,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
38169 /* always allow read */
38170 mask = POLLIN | POLLRDNORM;
38171
38172- if (seq->poll_event != atomic_read(&md_event_count))
38173+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
38174 mask |= POLLERR | POLLPRI;
38175 return mask;
38176 }
38177@@ -7155,7 +7155,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
38178 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
38179 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
38180 (int)part_stat_read(&disk->part0, sectors[1]) -
38181- atomic_read(&disk->sync_io);
38182+ atomic_read_unchecked(&disk->sync_io);
38183 /* sync IO will cause sync_io to increase before the disk_stats
38184 * as sync_io is counted when a request starts, and
38185 * disk_stats is counted when it completes.
38186diff --git a/drivers/md/md.h b/drivers/md/md.h
38187index d90fb1a..4174a2b 100644
38188--- a/drivers/md/md.h
38189+++ b/drivers/md/md.h
38190@@ -94,13 +94,13 @@ struct md_rdev {
38191 * only maintained for arrays that
38192 * support hot removal
38193 */
38194- atomic_t read_errors; /* number of consecutive read errors that
38195+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
38196 * we have tried to ignore.
38197 */
38198 struct timespec last_read_error; /* monotonic time since our
38199 * last read error
38200 */
38201- atomic_t corrected_errors; /* number of corrected read errors,
38202+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
38203 * for reporting to userspace and storing
38204 * in superblock.
38205 */
38206@@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
38207
38208 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
38209 {
38210- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
38211+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
38212 }
38213
38214 struct md_personality
38215diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
38216index 1cbfc6b..56e1dbb 100644
38217--- a/drivers/md/persistent-data/dm-space-map.h
38218+++ b/drivers/md/persistent-data/dm-space-map.h
38219@@ -60,6 +60,7 @@ struct dm_space_map {
38220 int (*root_size)(struct dm_space_map *sm, size_t *result);
38221 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
38222 };
38223+typedef struct dm_space_map __no_const dm_space_map_no_const;
38224
38225 /*----------------------------------------------------------------*/
38226
38227diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
38228index 6af167f..40c25a1 100644
38229--- a/drivers/md/raid1.c
38230+++ b/drivers/md/raid1.c
38231@@ -1826,7 +1826,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
38232 if (r1_sync_page_io(rdev, sect, s,
38233 bio->bi_io_vec[idx].bv_page,
38234 READ) != 0)
38235- atomic_add(s, &rdev->corrected_errors);
38236+ atomic_add_unchecked(s, &rdev->corrected_errors);
38237 }
38238 sectors -= s;
38239 sect += s;
38240@@ -2048,7 +2048,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
38241 test_bit(In_sync, &rdev->flags)) {
38242 if (r1_sync_page_io(rdev, sect, s,
38243 conf->tmppage, READ)) {
38244- atomic_add(s, &rdev->corrected_errors);
38245+ atomic_add_unchecked(s, &rdev->corrected_errors);
38246 printk(KERN_INFO
38247 "md/raid1:%s: read error corrected "
38248 "(%d sectors at %llu on %s)\n",
38249diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
38250index 46c14e5..4db5966 100644
38251--- a/drivers/md/raid10.c
38252+++ b/drivers/md/raid10.c
38253@@ -1932,7 +1932,7 @@ static void end_sync_read(struct bio *bio, int error)
38254 /* The write handler will notice the lack of
38255 * R10BIO_Uptodate and record any errors etc
38256 */
38257- atomic_add(r10_bio->sectors,
38258+ atomic_add_unchecked(r10_bio->sectors,
38259 &conf->mirrors[d].rdev->corrected_errors);
38260
38261 /* for reconstruct, we always reschedule after a read.
38262@@ -2281,7 +2281,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38263 {
38264 struct timespec cur_time_mon;
38265 unsigned long hours_since_last;
38266- unsigned int read_errors = atomic_read(&rdev->read_errors);
38267+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
38268
38269 ktime_get_ts(&cur_time_mon);
38270
38271@@ -2303,9 +2303,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38272 * overflowing the shift of read_errors by hours_since_last.
38273 */
38274 if (hours_since_last >= 8 * sizeof(read_errors))
38275- atomic_set(&rdev->read_errors, 0);
38276+ atomic_set_unchecked(&rdev->read_errors, 0);
38277 else
38278- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
38279+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
38280 }
38281
38282 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
38283@@ -2359,8 +2359,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38284 return;
38285
38286 check_decay_read_errors(mddev, rdev);
38287- atomic_inc(&rdev->read_errors);
38288- if (atomic_read(&rdev->read_errors) > max_read_errors) {
38289+ atomic_inc_unchecked(&rdev->read_errors);
38290+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
38291 char b[BDEVNAME_SIZE];
38292 bdevname(rdev->bdev, b);
38293
38294@@ -2368,7 +2368,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38295 "md/raid10:%s: %s: Raid device exceeded "
38296 "read_error threshold [cur %d:max %d]\n",
38297 mdname(mddev), b,
38298- atomic_read(&rdev->read_errors), max_read_errors);
38299+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
38300 printk(KERN_NOTICE
38301 "md/raid10:%s: %s: Failing raid device\n",
38302 mdname(mddev), b);
38303@@ -2523,7 +2523,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38304 sect +
38305 choose_data_offset(r10_bio, rdev)),
38306 bdevname(rdev->bdev, b));
38307- atomic_add(s, &rdev->corrected_errors);
38308+ atomic_add_unchecked(s, &rdev->corrected_errors);
38309 }
38310
38311 rdev_dec_pending(rdev, mddev);
38312diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
38313index f4e87bf..0d4ad3f 100644
38314--- a/drivers/md/raid5.c
38315+++ b/drivers/md/raid5.c
38316@@ -1763,21 +1763,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
38317 mdname(conf->mddev), STRIPE_SECTORS,
38318 (unsigned long long)s,
38319 bdevname(rdev->bdev, b));
38320- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
38321+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
38322 clear_bit(R5_ReadError, &sh->dev[i].flags);
38323 clear_bit(R5_ReWrite, &sh->dev[i].flags);
38324 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
38325 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
38326
38327- if (atomic_read(&rdev->read_errors))
38328- atomic_set(&rdev->read_errors, 0);
38329+ if (atomic_read_unchecked(&rdev->read_errors))
38330+ atomic_set_unchecked(&rdev->read_errors, 0);
38331 } else {
38332 const char *bdn = bdevname(rdev->bdev, b);
38333 int retry = 0;
38334 int set_bad = 0;
38335
38336 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
38337- atomic_inc(&rdev->read_errors);
38338+ atomic_inc_unchecked(&rdev->read_errors);
38339 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
38340 printk_ratelimited(
38341 KERN_WARNING
38342@@ -1805,7 +1805,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
38343 mdname(conf->mddev),
38344 (unsigned long long)s,
38345 bdn);
38346- } else if (atomic_read(&rdev->read_errors)
38347+ } else if (atomic_read_unchecked(&rdev->read_errors)
38348 > conf->max_nr_stripes)
38349 printk(KERN_WARNING
38350 "md/raid:%s: Too many read errors, failing device %s.\n",
38351diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
38352index 401ef64..836e563 100644
38353--- a/drivers/media/dvb-core/dvbdev.c
38354+++ b/drivers/media/dvb-core/dvbdev.c
38355@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
38356 const struct dvb_device *template, void *priv, int type)
38357 {
38358 struct dvb_device *dvbdev;
38359- struct file_operations *dvbdevfops;
38360+ file_operations_no_const *dvbdevfops;
38361 struct device *clsdev;
38362 int minor;
38363 int id;
38364diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
38365index 9b6c3bb..baeb5c7 100644
38366--- a/drivers/media/dvb-frontends/dib3000.h
38367+++ b/drivers/media/dvb-frontends/dib3000.h
38368@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
38369 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
38370 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
38371 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
38372-};
38373+} __no_const;
38374
38375 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
38376 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
38377diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
38378index bc78354..42c9459 100644
38379--- a/drivers/media/pci/cx88/cx88-video.c
38380+++ b/drivers/media/pci/cx88/cx88-video.c
38381@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
38382
38383 /* ------------------------------------------------------------------ */
38384
38385-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38386-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38387-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38388+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38389+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38390+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38391
38392 module_param_array(video_nr, int, NULL, 0444);
38393 module_param_array(vbi_nr, int, NULL, 0444);
38394diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
38395index 96c4a17..1305a79 100644
38396--- a/drivers/media/platform/omap/omap_vout.c
38397+++ b/drivers/media/platform/omap/omap_vout.c
38398@@ -63,7 +63,6 @@ enum omap_vout_channels {
38399 OMAP_VIDEO2,
38400 };
38401
38402-static struct videobuf_queue_ops video_vbq_ops;
38403 /* Variables configurable through module params*/
38404 static u32 video1_numbuffers = 3;
38405 static u32 video2_numbuffers = 3;
38406@@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
38407 {
38408 struct videobuf_queue *q;
38409 struct omap_vout_device *vout = NULL;
38410+ static struct videobuf_queue_ops video_vbq_ops = {
38411+ .buf_setup = omap_vout_buffer_setup,
38412+ .buf_prepare = omap_vout_buffer_prepare,
38413+ .buf_release = omap_vout_buffer_release,
38414+ .buf_queue = omap_vout_buffer_queue,
38415+ };
38416
38417 vout = video_drvdata(file);
38418 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
38419@@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
38420 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
38421
38422 q = &vout->vbq;
38423- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
38424- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
38425- video_vbq_ops.buf_release = omap_vout_buffer_release;
38426- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
38427 spin_lock_init(&vout->vbq_lock);
38428
38429 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
38430diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
38431index 04e6490..2df65bf 100644
38432--- a/drivers/media/platform/s5p-tv/mixer.h
38433+++ b/drivers/media/platform/s5p-tv/mixer.h
38434@@ -156,7 +156,7 @@ struct mxr_layer {
38435 /** layer index (unique identifier) */
38436 int idx;
38437 /** callbacks for layer methods */
38438- struct mxr_layer_ops ops;
38439+ struct mxr_layer_ops *ops;
38440 /** format array */
38441 const struct mxr_format **fmt_array;
38442 /** size of format array */
38443diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38444index b93a21f..2535195 100644
38445--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38446+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38447@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
38448 {
38449 struct mxr_layer *layer;
38450 int ret;
38451- struct mxr_layer_ops ops = {
38452+ static struct mxr_layer_ops ops = {
38453 .release = mxr_graph_layer_release,
38454 .buffer_set = mxr_graph_buffer_set,
38455 .stream_set = mxr_graph_stream_set,
38456diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
38457index b713403..53cb5ad 100644
38458--- a/drivers/media/platform/s5p-tv/mixer_reg.c
38459+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
38460@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
38461 layer->update_buf = next;
38462 }
38463
38464- layer->ops.buffer_set(layer, layer->update_buf);
38465+ layer->ops->buffer_set(layer, layer->update_buf);
38466
38467 if (done && done != layer->shadow_buf)
38468 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
38469diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
38470index 82142a2..6de47e8 100644
38471--- a/drivers/media/platform/s5p-tv/mixer_video.c
38472+++ b/drivers/media/platform/s5p-tv/mixer_video.c
38473@@ -209,7 +209,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
38474 layer->geo.src.height = layer->geo.src.full_height;
38475
38476 mxr_geometry_dump(mdev, &layer->geo);
38477- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38478+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38479 mxr_geometry_dump(mdev, &layer->geo);
38480 }
38481
38482@@ -227,7 +227,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
38483 layer->geo.dst.full_width = mbus_fmt.width;
38484 layer->geo.dst.full_height = mbus_fmt.height;
38485 layer->geo.dst.field = mbus_fmt.field;
38486- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38487+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38488
38489 mxr_geometry_dump(mdev, &layer->geo);
38490 }
38491@@ -333,7 +333,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
38492 /* set source size to highest accepted value */
38493 geo->src.full_width = max(geo->dst.full_width, pix->width);
38494 geo->src.full_height = max(geo->dst.full_height, pix->height);
38495- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38496+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38497 mxr_geometry_dump(mdev, &layer->geo);
38498 /* set cropping to total visible screen */
38499 geo->src.width = pix->width;
38500@@ -341,12 +341,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
38501 geo->src.x_offset = 0;
38502 geo->src.y_offset = 0;
38503 /* assure consistency of geometry */
38504- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38505+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38506 mxr_geometry_dump(mdev, &layer->geo);
38507 /* set full size to lowest possible value */
38508 geo->src.full_width = 0;
38509 geo->src.full_height = 0;
38510- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38511+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38512 mxr_geometry_dump(mdev, &layer->geo);
38513
38514 /* returning results */
38515@@ -473,7 +473,7 @@ static int mxr_s_selection(struct file *file, void *fh,
38516 target->width = s->r.width;
38517 target->height = s->r.height;
38518
38519- layer->ops.fix_geometry(layer, stage, s->flags);
38520+ layer->ops->fix_geometry(layer, stage, s->flags);
38521
38522 /* retrieve update selection rectangle */
38523 res.left = target->x_offset;
38524@@ -938,13 +938,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
38525 mxr_output_get(mdev);
38526
38527 mxr_layer_update_output(layer);
38528- layer->ops.format_set(layer);
38529+ layer->ops->format_set(layer);
38530 /* enabling layer in hardware */
38531 spin_lock_irqsave(&layer->enq_slock, flags);
38532 layer->state = MXR_LAYER_STREAMING;
38533 spin_unlock_irqrestore(&layer->enq_slock, flags);
38534
38535- layer->ops.stream_set(layer, MXR_ENABLE);
38536+ layer->ops->stream_set(layer, MXR_ENABLE);
38537 mxr_streamer_get(mdev);
38538
38539 return 0;
38540@@ -1014,7 +1014,7 @@ static int stop_streaming(struct vb2_queue *vq)
38541 spin_unlock_irqrestore(&layer->enq_slock, flags);
38542
38543 /* disabling layer in hardware */
38544- layer->ops.stream_set(layer, MXR_DISABLE);
38545+ layer->ops->stream_set(layer, MXR_DISABLE);
38546 /* remove one streamer */
38547 mxr_streamer_put(mdev);
38548 /* allow changes in output configuration */
38549@@ -1053,8 +1053,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
38550
38551 void mxr_layer_release(struct mxr_layer *layer)
38552 {
38553- if (layer->ops.release)
38554- layer->ops.release(layer);
38555+ if (layer->ops->release)
38556+ layer->ops->release(layer);
38557 }
38558
38559 void mxr_base_layer_release(struct mxr_layer *layer)
38560@@ -1080,7 +1080,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
38561
38562 layer->mdev = mdev;
38563 layer->idx = idx;
38564- layer->ops = *ops;
38565+ layer->ops = ops;
38566
38567 spin_lock_init(&layer->enq_slock);
38568 INIT_LIST_HEAD(&layer->enq_list);
38569diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38570index 3d13a63..da31bf1 100644
38571--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38572+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38573@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
38574 {
38575 struct mxr_layer *layer;
38576 int ret;
38577- struct mxr_layer_ops ops = {
38578+ static struct mxr_layer_ops ops = {
38579 .release = mxr_vp_layer_release,
38580 .buffer_set = mxr_vp_buffer_set,
38581 .stream_set = mxr_vp_stream_set,
38582diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
38583index 643d80a..56bb96b 100644
38584--- a/drivers/media/radio/radio-cadet.c
38585+++ b/drivers/media/radio/radio-cadet.c
38586@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
38587 unsigned char readbuf[RDS_BUFFER];
38588 int i = 0;
38589
38590+ if (count > RDS_BUFFER)
38591+ return -EFAULT;
38592 mutex_lock(&dev->lock);
38593 if (dev->rdsstat == 0)
38594 cadet_start_rds(dev);
38595@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
38596 while (i < count && dev->rdsin != dev->rdsout)
38597 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
38598
38599- if (i && copy_to_user(data, readbuf, i))
38600+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
38601 i = -EFAULT;
38602 unlock:
38603 mutex_unlock(&dev->lock);
38604diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
38605index 3940bb0..fb3952a 100644
38606--- a/drivers/media/usb/dvb-usb/cxusb.c
38607+++ b/drivers/media/usb/dvb-usb/cxusb.c
38608@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
38609
38610 struct dib0700_adapter_state {
38611 int (*set_param_save) (struct dvb_frontend *);
38612-};
38613+} __no_const;
38614
38615 static int dib7070_set_param_override(struct dvb_frontend *fe)
38616 {
38617diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
38618index 9578a67..31aa652 100644
38619--- a/drivers/media/usb/dvb-usb/dw2102.c
38620+++ b/drivers/media/usb/dvb-usb/dw2102.c
38621@@ -115,7 +115,7 @@ struct su3000_state {
38622
38623 struct s6x0_state {
38624 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
38625-};
38626+} __no_const;
38627
38628 /* debug */
38629 static int dvb_usb_dw2102_debug;
38630diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
38631index 7157af3..139e91a 100644
38632--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
38633+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
38634@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
38635 __u32 reserved;
38636 };
38637
38638-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
38639+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
38640 enum v4l2_memory memory)
38641 {
38642 void __user *up_pln;
38643@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
38644 return 0;
38645 }
38646
38647-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
38648+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
38649 enum v4l2_memory memory)
38650 {
38651 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
38652@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
38653 put_user(kp->start_block, &up->start_block) ||
38654 put_user(kp->blocks, &up->blocks) ||
38655 put_user(tmp, &up->edid) ||
38656- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
38657+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
38658 return -EFAULT;
38659 return 0;
38660 }
38661diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
38662index aa6e7c7..cb5de87 100644
38663--- a/drivers/media/v4l2-core/v4l2-ioctl.c
38664+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
38665@@ -236,7 +236,7 @@ static void v4l_print_format(const void *arg, bool write_only)
38666 const struct v4l2_vbi_format *vbi;
38667 const struct v4l2_sliced_vbi_format *sliced;
38668 const struct v4l2_window *win;
38669- const struct v4l2_clip *clip;
38670+ const struct v4l2_clip __user *pclip;
38671 unsigned i;
38672
38673 pr_cont("type=%s", prt_names(p->type, v4l2_type_names));
38674@@ -284,12 +284,16 @@ static void v4l_print_format(const void *arg, bool write_only)
38675 win->w.left, win->w.top,
38676 prt_names(win->field, v4l2_field_names),
38677 win->chromakey, win->bitmap, win->global_alpha);
38678- clip = win->clips;
38679+ pclip = win->clips;
38680 for (i = 0; i < win->clipcount; i++) {
38681+ struct v4l2_clip clip;
38682+
38683+ if (copy_from_user(&clip, pclip, sizeof clip))
38684+ break;
38685 printk(KERN_DEBUG "clip %u: wxh=%dx%d, x,y=%d,%d\n",
38686- i, clip->c.width, clip->c.height,
38687- clip->c.left, clip->c.top);
38688- clip = clip->next;
38689+ i, clip.c.width, clip.c.height,
38690+ clip.c.left, clip.c.top);
38691+ pclip = clip.next;
38692 }
38693 break;
38694 case V4L2_BUF_TYPE_VBI_CAPTURE:
38695@@ -1923,7 +1927,8 @@ struct v4l2_ioctl_info {
38696 struct file *file, void *fh, void *p);
38697 } u;
38698 void (*debug)(const void *arg, bool write_only);
38699-};
38700+} __do_const;
38701+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
38702
38703 /* This control needs a priority check */
38704 #define INFO_FL_PRIO (1 << 0)
38705@@ -2108,7 +2113,7 @@ static long __video_do_ioctl(struct file *file,
38706 struct video_device *vfd = video_devdata(file);
38707 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
38708 bool write_only = false;
38709- struct v4l2_ioctl_info default_info;
38710+ v4l2_ioctl_info_no_const default_info;
38711 const struct v4l2_ioctl_info *info;
38712 void *fh = file->private_data;
38713 struct v4l2_fh *vfh = NULL;
38714@@ -2193,7 +2198,7 @@ done:
38715 }
38716
38717 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
38718- void * __user *user_ptr, void ***kernel_ptr)
38719+ void __user **user_ptr, void ***kernel_ptr)
38720 {
38721 int ret = 0;
38722
38723@@ -2209,7 +2214,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
38724 ret = -EINVAL;
38725 break;
38726 }
38727- *user_ptr = (void __user *)buf->m.planes;
38728+ *user_ptr = (void __force_user *)buf->m.planes;
38729 *kernel_ptr = (void *)&buf->m.planes;
38730 *array_size = sizeof(struct v4l2_plane) * buf->length;
38731 ret = 1;
38732@@ -2244,7 +2249,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
38733 ret = -EINVAL;
38734 break;
38735 }
38736- *user_ptr = (void __user *)ctrls->controls;
38737+ *user_ptr = (void __force_user *)ctrls->controls;
38738 *kernel_ptr = (void *)&ctrls->controls;
38739 *array_size = sizeof(struct v4l2_ext_control)
38740 * ctrls->count;
38741diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
38742index fb69baa..3aeea2e 100644
38743--- a/drivers/message/fusion/mptbase.c
38744+++ b/drivers/message/fusion/mptbase.c
38745@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
38746 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
38747 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
38748
38749+#ifdef CONFIG_GRKERNSEC_HIDESYM
38750+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
38751+#else
38752 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
38753 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
38754+#endif
38755+
38756 /*
38757 * Rounding UP to nearest 4-kB boundary here...
38758 */
38759@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
38760 ioc->facts.GlobalCredits);
38761
38762 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
38763+#ifdef CONFIG_GRKERNSEC_HIDESYM
38764+ NULL, NULL);
38765+#else
38766 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
38767+#endif
38768 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
38769 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
38770 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
38771diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
38772index fa43c39..daeb158 100644
38773--- a/drivers/message/fusion/mptsas.c
38774+++ b/drivers/message/fusion/mptsas.c
38775@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
38776 return 0;
38777 }
38778
38779+static inline void
38780+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38781+{
38782+ if (phy_info->port_details) {
38783+ phy_info->port_details->rphy = rphy;
38784+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
38785+ ioc->name, rphy));
38786+ }
38787+
38788+ if (rphy) {
38789+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
38790+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
38791+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
38792+ ioc->name, rphy, rphy->dev.release));
38793+ }
38794+}
38795+
38796 /* no mutex */
38797 static void
38798 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
38799@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
38800 return NULL;
38801 }
38802
38803-static inline void
38804-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38805-{
38806- if (phy_info->port_details) {
38807- phy_info->port_details->rphy = rphy;
38808- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
38809- ioc->name, rphy));
38810- }
38811-
38812- if (rphy) {
38813- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
38814- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
38815- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
38816- ioc->name, rphy, rphy->dev.release));
38817- }
38818-}
38819-
38820 static inline struct sas_port *
38821 mptsas_get_port(struct mptsas_phyinfo *phy_info)
38822 {
38823diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
38824index 164afa7..b6b2e74 100644
38825--- a/drivers/message/fusion/mptscsih.c
38826+++ b/drivers/message/fusion/mptscsih.c
38827@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
38828
38829 h = shost_priv(SChost);
38830
38831- if (h) {
38832- if (h->info_kbuf == NULL)
38833- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38834- return h->info_kbuf;
38835- h->info_kbuf[0] = '\0';
38836+ if (!h)
38837+ return NULL;
38838
38839- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
38840- h->info_kbuf[size-1] = '\0';
38841- }
38842+ if (h->info_kbuf == NULL)
38843+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38844+ return h->info_kbuf;
38845+ h->info_kbuf[0] = '\0';
38846+
38847+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
38848+ h->info_kbuf[size-1] = '\0';
38849
38850 return h->info_kbuf;
38851 }
38852diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
38853index 8001aa6..b137580 100644
38854--- a/drivers/message/i2o/i2o_proc.c
38855+++ b/drivers/message/i2o/i2o_proc.c
38856@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
38857 "Array Controller Device"
38858 };
38859
38860-static char *chtostr(char *tmp, u8 *chars, int n)
38861-{
38862- tmp[0] = 0;
38863- return strncat(tmp, (char *)chars, n);
38864-}
38865-
38866 static int i2o_report_query_status(struct seq_file *seq, int block_status,
38867 char *group)
38868 {
38869@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
38870 } *result;
38871
38872 i2o_exec_execute_ddm_table ddm_table;
38873- char tmp[28 + 1];
38874
38875 result = kmalloc(sizeof(*result), GFP_KERNEL);
38876 if (!result)
38877@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
38878
38879 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
38880 seq_printf(seq, "%-#8x", ddm_table.module_id);
38881- seq_printf(seq, "%-29s",
38882- chtostr(tmp, ddm_table.module_name_version, 28));
38883+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
38884 seq_printf(seq, "%9d ", ddm_table.data_size);
38885 seq_printf(seq, "%8d", ddm_table.code_size);
38886
38887@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
38888
38889 i2o_driver_result_table *result;
38890 i2o_driver_store_table *dst;
38891- char tmp[28 + 1];
38892
38893 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
38894 if (result == NULL)
38895@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
38896
38897 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
38898 seq_printf(seq, "%-#8x", dst->module_id);
38899- seq_printf(seq, "%-29s",
38900- chtostr(tmp, dst->module_name_version, 28));
38901- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
38902+ seq_printf(seq, "%-.28s", dst->module_name_version);
38903+ seq_printf(seq, "%-.8s", dst->date);
38904 seq_printf(seq, "%8d ", dst->module_size);
38905 seq_printf(seq, "%8d ", dst->mpb_size);
38906 seq_printf(seq, "0x%04x", dst->module_flags);
38907@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
38908 // == (allow) 512d bytes (max)
38909 static u16 *work16 = (u16 *) work32;
38910 int token;
38911- char tmp[16 + 1];
38912
38913 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
38914
38915@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
38916 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
38917 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
38918 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
38919- seq_printf(seq, "Vendor info : %s\n",
38920- chtostr(tmp, (u8 *) (work32 + 2), 16));
38921- seq_printf(seq, "Product info : %s\n",
38922- chtostr(tmp, (u8 *) (work32 + 6), 16));
38923- seq_printf(seq, "Description : %s\n",
38924- chtostr(tmp, (u8 *) (work32 + 10), 16));
38925- seq_printf(seq, "Product rev. : %s\n",
38926- chtostr(tmp, (u8 *) (work32 + 14), 8));
38927+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
38928+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
38929+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
38930+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
38931
38932 seq_printf(seq, "Serial number : ");
38933 print_serial_number(seq, (u8 *) (work32 + 16),
38934@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
38935 u8 pad[256]; // allow up to 256 byte (max) serial number
38936 } result;
38937
38938- char tmp[24 + 1];
38939-
38940 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
38941
38942 if (token < 0) {
38943@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
38944 }
38945
38946 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
38947- seq_printf(seq, "Module name : %s\n",
38948- chtostr(tmp, result.module_name, 24));
38949- seq_printf(seq, "Module revision : %s\n",
38950- chtostr(tmp, result.module_rev, 8));
38951+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
38952+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
38953
38954 seq_printf(seq, "Serial number : ");
38955 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
38956@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
38957 u8 instance_number[4];
38958 } result;
38959
38960- char tmp[64 + 1];
38961-
38962 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
38963
38964 if (token < 0) {
38965@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
38966 return 0;
38967 }
38968
38969- seq_printf(seq, "Device name : %s\n",
38970- chtostr(tmp, result.device_name, 64));
38971- seq_printf(seq, "Service name : %s\n",
38972- chtostr(tmp, result.service_name, 64));
38973- seq_printf(seq, "Physical name : %s\n",
38974- chtostr(tmp, result.physical_location, 64));
38975- seq_printf(seq, "Instance number : %s\n",
38976- chtostr(tmp, result.instance_number, 4));
38977+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
38978+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
38979+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
38980+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
38981
38982 return 0;
38983 }
38984diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
38985index a8c08f3..155fe3d 100644
38986--- a/drivers/message/i2o/iop.c
38987+++ b/drivers/message/i2o/iop.c
38988@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
38989
38990 spin_lock_irqsave(&c->context_list_lock, flags);
38991
38992- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
38993- atomic_inc(&c->context_list_counter);
38994+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
38995+ atomic_inc_unchecked(&c->context_list_counter);
38996
38997- entry->context = atomic_read(&c->context_list_counter);
38998+ entry->context = atomic_read_unchecked(&c->context_list_counter);
38999
39000 list_add(&entry->list, &c->context_list);
39001
39002@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
39003
39004 #if BITS_PER_LONG == 64
39005 spin_lock_init(&c->context_list_lock);
39006- atomic_set(&c->context_list_counter, 0);
39007+ atomic_set_unchecked(&c->context_list_counter, 0);
39008 INIT_LIST_HEAD(&c->context_list);
39009 #endif
39010
39011diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
39012index 45ece11..8efa218 100644
39013--- a/drivers/mfd/janz-cmodio.c
39014+++ b/drivers/mfd/janz-cmodio.c
39015@@ -13,6 +13,7 @@
39016
39017 #include <linux/kernel.h>
39018 #include <linux/module.h>
39019+#include <linux/slab.h>
39020 #include <linux/init.h>
39021 #include <linux/pci.h>
39022 #include <linux/interrupt.h>
39023diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
39024index a5f9888..1c0ed56 100644
39025--- a/drivers/mfd/twl4030-irq.c
39026+++ b/drivers/mfd/twl4030-irq.c
39027@@ -35,6 +35,7 @@
39028 #include <linux/of.h>
39029 #include <linux/irqdomain.h>
39030 #include <linux/i2c/twl.h>
39031+#include <asm/pgtable.h>
39032
39033 #include "twl-core.h"
39034
39035@@ -728,10 +729,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
39036 * Install an irq handler for each of the SIH modules;
39037 * clone dummy irq_chip since PIH can't *do* anything
39038 */
39039- twl4030_irq_chip = dummy_irq_chip;
39040- twl4030_irq_chip.name = "twl4030";
39041+ pax_open_kernel();
39042+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
39043+ *(const char **)&twl4030_irq_chip.name = "twl4030";
39044
39045- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
39046+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
39047+ pax_close_kernel();
39048
39049 for (i = irq_base; i < irq_end; i++) {
39050 irq_set_chip_and_handler(i, &twl4030_irq_chip,
39051diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
39052index 277a8db..0e0b754 100644
39053--- a/drivers/mfd/twl6030-irq.c
39054+++ b/drivers/mfd/twl6030-irq.c
39055@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
39056 * install an irq handler for each of the modules;
39057 * clone dummy irq_chip since PIH can't *do* anything
39058 */
39059- twl6030_irq_chip = dummy_irq_chip;
39060- twl6030_irq_chip.name = "twl6030";
39061- twl6030_irq_chip.irq_set_type = NULL;
39062- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
39063+ pax_open_kernel();
39064+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
39065+ *(const char **)&twl6030_irq_chip.name = "twl6030";
39066+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
39067+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
39068+ pax_close_kernel();
39069
39070 for (i = irq_base; i < irq_end; i++) {
39071 irq_set_chip_and_handler(i, &twl6030_irq_chip,
39072diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
39073index f32550a..e3e52a2 100644
39074--- a/drivers/misc/c2port/core.c
39075+++ b/drivers/misc/c2port/core.c
39076@@ -920,7 +920,9 @@ struct c2port_device *c2port_device_register(char *name,
39077 mutex_init(&c2dev->mutex);
39078
39079 /* Create binary file */
39080- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
39081+ pax_open_kernel();
39082+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
39083+ pax_close_kernel();
39084 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
39085 if (unlikely(ret))
39086 goto error_device_create_bin_file;
39087diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
39088index 36f5d52..32311c3 100644
39089--- a/drivers/misc/kgdbts.c
39090+++ b/drivers/misc/kgdbts.c
39091@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
39092 char before[BREAK_INSTR_SIZE];
39093 char after[BREAK_INSTR_SIZE];
39094
39095- probe_kernel_read(before, (char *)kgdbts_break_test,
39096+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
39097 BREAK_INSTR_SIZE);
39098 init_simple_test();
39099 ts.tst = plant_and_detach_test;
39100@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
39101 /* Activate test with initial breakpoint */
39102 if (!is_early)
39103 kgdb_breakpoint();
39104- probe_kernel_read(after, (char *)kgdbts_break_test,
39105+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
39106 BREAK_INSTR_SIZE);
39107 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
39108 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
39109diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
39110index 4a87e5c..76bdf5c 100644
39111--- a/drivers/misc/lis3lv02d/lis3lv02d.c
39112+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
39113@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
39114 * the lid is closed. This leads to interrupts as soon as a little move
39115 * is done.
39116 */
39117- atomic_inc(&lis3->count);
39118+ atomic_inc_unchecked(&lis3->count);
39119
39120 wake_up_interruptible(&lis3->misc_wait);
39121 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
39122@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
39123 if (lis3->pm_dev)
39124 pm_runtime_get_sync(lis3->pm_dev);
39125
39126- atomic_set(&lis3->count, 0);
39127+ atomic_set_unchecked(&lis3->count, 0);
39128 return 0;
39129 }
39130
39131@@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
39132 add_wait_queue(&lis3->misc_wait, &wait);
39133 while (true) {
39134 set_current_state(TASK_INTERRUPTIBLE);
39135- data = atomic_xchg(&lis3->count, 0);
39136+ data = atomic_xchg_unchecked(&lis3->count, 0);
39137 if (data)
39138 break;
39139
39140@@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
39141 struct lis3lv02d, miscdev);
39142
39143 poll_wait(file, &lis3->misc_wait, wait);
39144- if (atomic_read(&lis3->count))
39145+ if (atomic_read_unchecked(&lis3->count))
39146 return POLLIN | POLLRDNORM;
39147 return 0;
39148 }
39149diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
39150index c439c82..1f20f57 100644
39151--- a/drivers/misc/lis3lv02d/lis3lv02d.h
39152+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
39153@@ -297,7 +297,7 @@ struct lis3lv02d {
39154 struct input_polled_dev *idev; /* input device */
39155 struct platform_device *pdev; /* platform device */
39156 struct regulator_bulk_data regulators[2];
39157- atomic_t count; /* interrupt count after last read */
39158+ atomic_unchecked_t count; /* interrupt count after last read */
39159 union axis_conversion ac; /* hw -> logical axis */
39160 int mapped_btns[3];
39161
39162diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
39163index 2f30bad..c4c13d0 100644
39164--- a/drivers/misc/sgi-gru/gruhandles.c
39165+++ b/drivers/misc/sgi-gru/gruhandles.c
39166@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
39167 unsigned long nsec;
39168
39169 nsec = CLKS2NSEC(clks);
39170- atomic_long_inc(&mcs_op_statistics[op].count);
39171- atomic_long_add(nsec, &mcs_op_statistics[op].total);
39172+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
39173+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
39174 if (mcs_op_statistics[op].max < nsec)
39175 mcs_op_statistics[op].max = nsec;
39176 }
39177diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
39178index 950dbe9..eeef0f8 100644
39179--- a/drivers/misc/sgi-gru/gruprocfs.c
39180+++ b/drivers/misc/sgi-gru/gruprocfs.c
39181@@ -32,9 +32,9 @@
39182
39183 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
39184
39185-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
39186+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
39187 {
39188- unsigned long val = atomic_long_read(v);
39189+ unsigned long val = atomic_long_read_unchecked(v);
39190
39191 seq_printf(s, "%16lu %s\n", val, id);
39192 }
39193@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
39194
39195 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
39196 for (op = 0; op < mcsop_last; op++) {
39197- count = atomic_long_read(&mcs_op_statistics[op].count);
39198- total = atomic_long_read(&mcs_op_statistics[op].total);
39199+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
39200+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
39201 max = mcs_op_statistics[op].max;
39202 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
39203 count ? total / count : 0, max);
39204diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
39205index 5c3ce24..4915ccb 100644
39206--- a/drivers/misc/sgi-gru/grutables.h
39207+++ b/drivers/misc/sgi-gru/grutables.h
39208@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
39209 * GRU statistics.
39210 */
39211 struct gru_stats_s {
39212- atomic_long_t vdata_alloc;
39213- atomic_long_t vdata_free;
39214- atomic_long_t gts_alloc;
39215- atomic_long_t gts_free;
39216- atomic_long_t gms_alloc;
39217- atomic_long_t gms_free;
39218- atomic_long_t gts_double_allocate;
39219- atomic_long_t assign_context;
39220- atomic_long_t assign_context_failed;
39221- atomic_long_t free_context;
39222- atomic_long_t load_user_context;
39223- atomic_long_t load_kernel_context;
39224- atomic_long_t lock_kernel_context;
39225- atomic_long_t unlock_kernel_context;
39226- atomic_long_t steal_user_context;
39227- atomic_long_t steal_kernel_context;
39228- atomic_long_t steal_context_failed;
39229- atomic_long_t nopfn;
39230- atomic_long_t asid_new;
39231- atomic_long_t asid_next;
39232- atomic_long_t asid_wrap;
39233- atomic_long_t asid_reuse;
39234- atomic_long_t intr;
39235- atomic_long_t intr_cbr;
39236- atomic_long_t intr_tfh;
39237- atomic_long_t intr_spurious;
39238- atomic_long_t intr_mm_lock_failed;
39239- atomic_long_t call_os;
39240- atomic_long_t call_os_wait_queue;
39241- atomic_long_t user_flush_tlb;
39242- atomic_long_t user_unload_context;
39243- atomic_long_t user_exception;
39244- atomic_long_t set_context_option;
39245- atomic_long_t check_context_retarget_intr;
39246- atomic_long_t check_context_unload;
39247- atomic_long_t tlb_dropin;
39248- atomic_long_t tlb_preload_page;
39249- atomic_long_t tlb_dropin_fail_no_asid;
39250- atomic_long_t tlb_dropin_fail_upm;
39251- atomic_long_t tlb_dropin_fail_invalid;
39252- atomic_long_t tlb_dropin_fail_range_active;
39253- atomic_long_t tlb_dropin_fail_idle;
39254- atomic_long_t tlb_dropin_fail_fmm;
39255- atomic_long_t tlb_dropin_fail_no_exception;
39256- atomic_long_t tfh_stale_on_fault;
39257- atomic_long_t mmu_invalidate_range;
39258- atomic_long_t mmu_invalidate_page;
39259- atomic_long_t flush_tlb;
39260- atomic_long_t flush_tlb_gru;
39261- atomic_long_t flush_tlb_gru_tgh;
39262- atomic_long_t flush_tlb_gru_zero_asid;
39263+ atomic_long_unchecked_t vdata_alloc;
39264+ atomic_long_unchecked_t vdata_free;
39265+ atomic_long_unchecked_t gts_alloc;
39266+ atomic_long_unchecked_t gts_free;
39267+ atomic_long_unchecked_t gms_alloc;
39268+ atomic_long_unchecked_t gms_free;
39269+ atomic_long_unchecked_t gts_double_allocate;
39270+ atomic_long_unchecked_t assign_context;
39271+ atomic_long_unchecked_t assign_context_failed;
39272+ atomic_long_unchecked_t free_context;
39273+ atomic_long_unchecked_t load_user_context;
39274+ atomic_long_unchecked_t load_kernel_context;
39275+ atomic_long_unchecked_t lock_kernel_context;
39276+ atomic_long_unchecked_t unlock_kernel_context;
39277+ atomic_long_unchecked_t steal_user_context;
39278+ atomic_long_unchecked_t steal_kernel_context;
39279+ atomic_long_unchecked_t steal_context_failed;
39280+ atomic_long_unchecked_t nopfn;
39281+ atomic_long_unchecked_t asid_new;
39282+ atomic_long_unchecked_t asid_next;
39283+ atomic_long_unchecked_t asid_wrap;
39284+ atomic_long_unchecked_t asid_reuse;
39285+ atomic_long_unchecked_t intr;
39286+ atomic_long_unchecked_t intr_cbr;
39287+ atomic_long_unchecked_t intr_tfh;
39288+ atomic_long_unchecked_t intr_spurious;
39289+ atomic_long_unchecked_t intr_mm_lock_failed;
39290+ atomic_long_unchecked_t call_os;
39291+ atomic_long_unchecked_t call_os_wait_queue;
39292+ atomic_long_unchecked_t user_flush_tlb;
39293+ atomic_long_unchecked_t user_unload_context;
39294+ atomic_long_unchecked_t user_exception;
39295+ atomic_long_unchecked_t set_context_option;
39296+ atomic_long_unchecked_t check_context_retarget_intr;
39297+ atomic_long_unchecked_t check_context_unload;
39298+ atomic_long_unchecked_t tlb_dropin;
39299+ atomic_long_unchecked_t tlb_preload_page;
39300+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
39301+ atomic_long_unchecked_t tlb_dropin_fail_upm;
39302+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
39303+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
39304+ atomic_long_unchecked_t tlb_dropin_fail_idle;
39305+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
39306+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
39307+ atomic_long_unchecked_t tfh_stale_on_fault;
39308+ atomic_long_unchecked_t mmu_invalidate_range;
39309+ atomic_long_unchecked_t mmu_invalidate_page;
39310+ atomic_long_unchecked_t flush_tlb;
39311+ atomic_long_unchecked_t flush_tlb_gru;
39312+ atomic_long_unchecked_t flush_tlb_gru_tgh;
39313+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
39314
39315- atomic_long_t copy_gpa;
39316- atomic_long_t read_gpa;
39317+ atomic_long_unchecked_t copy_gpa;
39318+ atomic_long_unchecked_t read_gpa;
39319
39320- atomic_long_t mesq_receive;
39321- atomic_long_t mesq_receive_none;
39322- atomic_long_t mesq_send;
39323- atomic_long_t mesq_send_failed;
39324- atomic_long_t mesq_noop;
39325- atomic_long_t mesq_send_unexpected_error;
39326- atomic_long_t mesq_send_lb_overflow;
39327- atomic_long_t mesq_send_qlimit_reached;
39328- atomic_long_t mesq_send_amo_nacked;
39329- atomic_long_t mesq_send_put_nacked;
39330- atomic_long_t mesq_page_overflow;
39331- atomic_long_t mesq_qf_locked;
39332- atomic_long_t mesq_qf_noop_not_full;
39333- atomic_long_t mesq_qf_switch_head_failed;
39334- atomic_long_t mesq_qf_unexpected_error;
39335- atomic_long_t mesq_noop_unexpected_error;
39336- atomic_long_t mesq_noop_lb_overflow;
39337- atomic_long_t mesq_noop_qlimit_reached;
39338- atomic_long_t mesq_noop_amo_nacked;
39339- atomic_long_t mesq_noop_put_nacked;
39340- atomic_long_t mesq_noop_page_overflow;
39341+ atomic_long_unchecked_t mesq_receive;
39342+ atomic_long_unchecked_t mesq_receive_none;
39343+ atomic_long_unchecked_t mesq_send;
39344+ atomic_long_unchecked_t mesq_send_failed;
39345+ atomic_long_unchecked_t mesq_noop;
39346+ atomic_long_unchecked_t mesq_send_unexpected_error;
39347+ atomic_long_unchecked_t mesq_send_lb_overflow;
39348+ atomic_long_unchecked_t mesq_send_qlimit_reached;
39349+ atomic_long_unchecked_t mesq_send_amo_nacked;
39350+ atomic_long_unchecked_t mesq_send_put_nacked;
39351+ atomic_long_unchecked_t mesq_page_overflow;
39352+ atomic_long_unchecked_t mesq_qf_locked;
39353+ atomic_long_unchecked_t mesq_qf_noop_not_full;
39354+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
39355+ atomic_long_unchecked_t mesq_qf_unexpected_error;
39356+ atomic_long_unchecked_t mesq_noop_unexpected_error;
39357+ atomic_long_unchecked_t mesq_noop_lb_overflow;
39358+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
39359+ atomic_long_unchecked_t mesq_noop_amo_nacked;
39360+ atomic_long_unchecked_t mesq_noop_put_nacked;
39361+ atomic_long_unchecked_t mesq_noop_page_overflow;
39362
39363 };
39364
39365@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
39366 tghop_invalidate, mcsop_last};
39367
39368 struct mcs_op_statistic {
39369- atomic_long_t count;
39370- atomic_long_t total;
39371+ atomic_long_unchecked_t count;
39372+ atomic_long_unchecked_t total;
39373 unsigned long max;
39374 };
39375
39376@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
39377
39378 #define STAT(id) do { \
39379 if (gru_options & OPT_STATS) \
39380- atomic_long_inc(&gru_stats.id); \
39381+ atomic_long_inc_unchecked(&gru_stats.id); \
39382 } while (0)
39383
39384 #ifdef CONFIG_SGI_GRU_DEBUG
39385diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
39386index c862cd4..0d176fe 100644
39387--- a/drivers/misc/sgi-xp/xp.h
39388+++ b/drivers/misc/sgi-xp/xp.h
39389@@ -288,7 +288,7 @@ struct xpc_interface {
39390 xpc_notify_func, void *);
39391 void (*received) (short, int, void *);
39392 enum xp_retval (*partid_to_nasids) (short, void *);
39393-};
39394+} __no_const;
39395
39396 extern struct xpc_interface xpc_interface;
39397
39398diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
39399index b94d5f7..7f494c5 100644
39400--- a/drivers/misc/sgi-xp/xpc.h
39401+++ b/drivers/misc/sgi-xp/xpc.h
39402@@ -835,6 +835,7 @@ struct xpc_arch_operations {
39403 void (*received_payload) (struct xpc_channel *, void *);
39404 void (*notify_senders_of_disconnect) (struct xpc_channel *);
39405 };
39406+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
39407
39408 /* struct xpc_partition act_state values (for XPC HB) */
39409
39410@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
39411 /* found in xpc_main.c */
39412 extern struct device *xpc_part;
39413 extern struct device *xpc_chan;
39414-extern struct xpc_arch_operations xpc_arch_ops;
39415+extern xpc_arch_operations_no_const xpc_arch_ops;
39416 extern int xpc_disengage_timelimit;
39417 extern int xpc_disengage_timedout;
39418 extern int xpc_activate_IRQ_rcvd;
39419diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
39420index d971817..33bdca5 100644
39421--- a/drivers/misc/sgi-xp/xpc_main.c
39422+++ b/drivers/misc/sgi-xp/xpc_main.c
39423@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
39424 .notifier_call = xpc_system_die,
39425 };
39426
39427-struct xpc_arch_operations xpc_arch_ops;
39428+xpc_arch_operations_no_const xpc_arch_ops;
39429
39430 /*
39431 * Timer function to enforce the timelimit on the partition disengage.
39432@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
39433
39434 if (((die_args->trapnr == X86_TRAP_MF) ||
39435 (die_args->trapnr == X86_TRAP_XF)) &&
39436- !user_mode_vm(die_args->regs))
39437+ !user_mode(die_args->regs))
39438 xpc_die_deactivate();
39439
39440 break;
39441diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
39442index 49f04bc..65660c2 100644
39443--- a/drivers/mmc/core/mmc_ops.c
39444+++ b/drivers/mmc/core/mmc_ops.c
39445@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
39446 void *data_buf;
39447 int is_on_stack;
39448
39449- is_on_stack = object_is_on_stack(buf);
39450+ is_on_stack = object_starts_on_stack(buf);
39451 if (is_on_stack) {
39452 /*
39453 * dma onto stack is unsafe/nonportable, but callers to this
39454diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
39455index 53b8fd9..615b462 100644
39456--- a/drivers/mmc/host/dw_mmc.h
39457+++ b/drivers/mmc/host/dw_mmc.h
39458@@ -205,5 +205,5 @@ struct dw_mci_drv_data {
39459 int (*parse_dt)(struct dw_mci *host);
39460 int (*setup_bus)(struct dw_mci *host,
39461 struct device_node *slot_np, u8 bus_width);
39462-};
39463+} __do_const;
39464 #endif /* _DW_MMC_H_ */
39465diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
39466index 7363efe..681558e 100644
39467--- a/drivers/mmc/host/sdhci-s3c.c
39468+++ b/drivers/mmc/host/sdhci-s3c.c
39469@@ -720,9 +720,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
39470 * we can use overriding functions instead of default.
39471 */
39472 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
39473- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39474- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39475- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39476+ pax_open_kernel();
39477+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39478+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39479+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39480+ pax_close_kernel();
39481 }
39482
39483 /* It supports additional host capabilities if needed */
39484diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
39485index a4eb8b5..8c0628f 100644
39486--- a/drivers/mtd/devices/doc2000.c
39487+++ b/drivers/mtd/devices/doc2000.c
39488@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
39489
39490 /* The ECC will not be calculated correctly if less than 512 is written */
39491 /* DBB-
39492- if (len != 0x200 && eccbuf)
39493+ if (len != 0x200)
39494 printk(KERN_WARNING
39495 "ECC needs a full sector write (adr: %lx size %lx)\n",
39496 (long) to, (long) len);
39497diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
39498index 0c8bb6b..6f35deb 100644
39499--- a/drivers/mtd/nand/denali.c
39500+++ b/drivers/mtd/nand/denali.c
39501@@ -24,6 +24,7 @@
39502 #include <linux/slab.h>
39503 #include <linux/mtd/mtd.h>
39504 #include <linux/module.h>
39505+#include <linux/slab.h>
39506
39507 #include "denali.h"
39508
39509diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
39510index 51b9d6a..52af9a7 100644
39511--- a/drivers/mtd/nftlmount.c
39512+++ b/drivers/mtd/nftlmount.c
39513@@ -24,6 +24,7 @@
39514 #include <asm/errno.h>
39515 #include <linux/delay.h>
39516 #include <linux/slab.h>
39517+#include <linux/sched.h>
39518 #include <linux/mtd/mtd.h>
39519 #include <linux/mtd/nand.h>
39520 #include <linux/mtd/nftl.h>
39521diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
39522index 8dd6ba5..419cc1d 100644
39523--- a/drivers/mtd/sm_ftl.c
39524+++ b/drivers/mtd/sm_ftl.c
39525@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
39526 #define SM_CIS_VENDOR_OFFSET 0x59
39527 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
39528 {
39529- struct attribute_group *attr_group;
39530+ attribute_group_no_const *attr_group;
39531 struct attribute **attributes;
39532 struct sm_sysfs_attribute *vendor_attribute;
39533
39534diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
39535index dbbea0e..3f4a0b1 100644
39536--- a/drivers/net/bonding/bond_main.c
39537+++ b/drivers/net/bonding/bond_main.c
39538@@ -4822,7 +4822,7 @@ static unsigned int bond_get_num_tx_queues(void)
39539 return tx_queues;
39540 }
39541
39542-static struct rtnl_link_ops bond_link_ops __read_mostly = {
39543+static struct rtnl_link_ops bond_link_ops = {
39544 .kind = "bond",
39545 .priv_size = sizeof(struct bonding),
39546 .setup = bond_setup,
39547@@ -4947,8 +4947,8 @@ static void __exit bonding_exit(void)
39548
39549 bond_destroy_debugfs();
39550
39551- rtnl_link_unregister(&bond_link_ops);
39552 unregister_pernet_subsys(&bond_net_ops);
39553+ rtnl_link_unregister(&bond_link_ops);
39554
39555 #ifdef CONFIG_NET_POLL_CONTROLLER
39556 /*
39557diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
39558index e1d2643..7f4133b 100644
39559--- a/drivers/net/ethernet/8390/ax88796.c
39560+++ b/drivers/net/ethernet/8390/ax88796.c
39561@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
39562 if (ax->plat->reg_offsets)
39563 ei_local->reg_offset = ax->plat->reg_offsets;
39564 else {
39565+ resource_size_t _mem_size = mem_size;
39566+ do_div(_mem_size, 0x18);
39567 ei_local->reg_offset = ax->reg_offsets;
39568 for (ret = 0; ret < 0x18; ret++)
39569- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
39570+ ax->reg_offsets[ret] = _mem_size * ret;
39571 }
39572
39573 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
39574diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39575index aee7671..3ca2651 100644
39576--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39577+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39578@@ -1093,7 +1093,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
39579 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
39580 {
39581 /* RX_MODE controlling object */
39582- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
39583+ bnx2x_init_rx_mode_obj(bp);
39584
39585 /* multicast configuration controlling object */
39586 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
39587diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39588index 7306416..5fb7fb5 100644
39589--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39590+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39591@@ -2381,15 +2381,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
39592 return rc;
39593 }
39594
39595-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
39596- struct bnx2x_rx_mode_obj *o)
39597+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
39598 {
39599 if (CHIP_IS_E1x(bp)) {
39600- o->wait_comp = bnx2x_empty_rx_mode_wait;
39601- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
39602+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
39603+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
39604 } else {
39605- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
39606- o->config_rx_mode = bnx2x_set_rx_mode_e2;
39607+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
39608+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
39609 }
39610 }
39611
39612diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39613index ff90760..08d8aed 100644
39614--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39615+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39616@@ -1306,8 +1306,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
39617
39618 /********************* RX MODE ****************/
39619
39620-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
39621- struct bnx2x_rx_mode_obj *o);
39622+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
39623
39624 /**
39625 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
39626diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
39627index 25309bf..fcfd54c 100644
39628--- a/drivers/net/ethernet/broadcom/tg3.h
39629+++ b/drivers/net/ethernet/broadcom/tg3.h
39630@@ -147,6 +147,7 @@
39631 #define CHIPREV_ID_5750_A0 0x4000
39632 #define CHIPREV_ID_5750_A1 0x4001
39633 #define CHIPREV_ID_5750_A3 0x4003
39634+#define CHIPREV_ID_5750_C1 0x4201
39635 #define CHIPREV_ID_5750_C2 0x4202
39636 #define CHIPREV_ID_5752_A0_HW 0x5000
39637 #define CHIPREV_ID_5752_A0 0x6000
39638diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39639index 8cffcdf..aadf043 100644
39640--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39641+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39642@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
39643 */
39644 struct l2t_skb_cb {
39645 arp_failure_handler_func arp_failure_handler;
39646-};
39647+} __no_const;
39648
39649 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
39650
39651diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
39652index 4c83003..2a2a5b9 100644
39653--- a/drivers/net/ethernet/dec/tulip/de4x5.c
39654+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
39655@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39656 for (i=0; i<ETH_ALEN; i++) {
39657 tmp.addr[i] = dev->dev_addr[i];
39658 }
39659- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39660+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39661 break;
39662
39663 case DE4X5_SET_HWADDR: /* Set the hardware address */
39664@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39665 spin_lock_irqsave(&lp->lock, flags);
39666 memcpy(&statbuf, &lp->pktStats, ioc->len);
39667 spin_unlock_irqrestore(&lp->lock, flags);
39668- if (copy_to_user(ioc->data, &statbuf, ioc->len))
39669+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
39670 return -EFAULT;
39671 break;
39672 }
39673diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
39674index 2886c9b..db71673 100644
39675--- a/drivers/net/ethernet/emulex/benet/be_main.c
39676+++ b/drivers/net/ethernet/emulex/benet/be_main.c
39677@@ -455,7 +455,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
39678
39679 if (wrapped)
39680 newacc += 65536;
39681- ACCESS_ONCE(*acc) = newacc;
39682+ ACCESS_ONCE_RW(*acc) = newacc;
39683 }
39684
39685 void be_parse_stats(struct be_adapter *adapter)
39686diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
39687index 7c361d1..57e3ff1 100644
39688--- a/drivers/net/ethernet/faraday/ftgmac100.c
39689+++ b/drivers/net/ethernet/faraday/ftgmac100.c
39690@@ -31,6 +31,8 @@
39691 #include <linux/netdevice.h>
39692 #include <linux/phy.h>
39693 #include <linux/platform_device.h>
39694+#include <linux/interrupt.h>
39695+#include <linux/irqreturn.h>
39696 #include <net/ip.h>
39697
39698 #include "ftgmac100.h"
39699diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
39700index b5ea8fb..bd25e9a 100644
39701--- a/drivers/net/ethernet/faraday/ftmac100.c
39702+++ b/drivers/net/ethernet/faraday/ftmac100.c
39703@@ -31,6 +31,8 @@
39704 #include <linux/module.h>
39705 #include <linux/netdevice.h>
39706 #include <linux/platform_device.h>
39707+#include <linux/interrupt.h>
39708+#include <linux/irqreturn.h>
39709
39710 #include "ftmac100.h"
39711
39712diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39713index 331987d..3be1135 100644
39714--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39715+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39716@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
39717 }
39718
39719 /* update the base incval used to calculate frequency adjustment */
39720- ACCESS_ONCE(adapter->base_incval) = incval;
39721+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
39722 smp_mb();
39723
39724 /* need lock to prevent incorrect read while modifying cyclecounter */
39725diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
39726index fbe5363..266b4e3 100644
39727--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
39728+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
39729@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
39730 struct __vxge_hw_fifo *fifo;
39731 struct vxge_hw_fifo_config *config;
39732 u32 txdl_size, txdl_per_memblock;
39733- struct vxge_hw_mempool_cbs fifo_mp_callback;
39734+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
39735+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
39736+ };
39737+
39738 struct __vxge_hw_virtualpath *vpath;
39739
39740 if ((vp == NULL) || (attr == NULL)) {
39741@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
39742 goto exit;
39743 }
39744
39745- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
39746-
39747 fifo->mempool =
39748 __vxge_hw_mempool_create(vpath->hldev,
39749 fifo->config->memblock_size,
39750diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
39751index 5c033f2..7bbb0d8 100644
39752--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
39753+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
39754@@ -1894,7 +1894,9 @@ int qlcnic_83xx_config_default_opmode(struct qlcnic_adapter *adapter)
39755 op_mode = QLCRDX(ahw, QLC_83XX_DRV_OP_MODE);
39756
39757 if (op_mode == QLC_83XX_DEFAULT_OPMODE) {
39758- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
39759+ pax_open_kernel();
39760+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
39761+ pax_close_kernel();
39762 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
39763 } else {
39764 return -EIO;
39765diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
39766index b0c3de9..fc5857e 100644
39767--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
39768+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
39769@@ -200,15 +200,21 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
39770 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
39771 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
39772 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
39773- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
39774+ pax_open_kernel();
39775+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
39776+ pax_close_kernel();
39777 } else if (priv_level == QLCNIC_PRIV_FUNC) {
39778 ahw->op_mode = QLCNIC_PRIV_FUNC;
39779 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
39780- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
39781+ pax_open_kernel();
39782+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
39783+ pax_close_kernel();
39784 } else if (priv_level == QLCNIC_MGMT_FUNC) {
39785 ahw->op_mode = QLCNIC_MGMT_FUNC;
39786 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
39787- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
39788+ pax_open_kernel();
39789+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
39790+ pax_close_kernel();
39791 } else {
39792 return -EIO;
39793 }
39794diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
39795index 15ba8c4..3f56838 100644
39796--- a/drivers/net/ethernet/realtek/r8169.c
39797+++ b/drivers/net/ethernet/realtek/r8169.c
39798@@ -740,22 +740,22 @@ struct rtl8169_private {
39799 struct mdio_ops {
39800 void (*write)(struct rtl8169_private *, int, int);
39801 int (*read)(struct rtl8169_private *, int);
39802- } mdio_ops;
39803+ } __no_const mdio_ops;
39804
39805 struct pll_power_ops {
39806 void (*down)(struct rtl8169_private *);
39807 void (*up)(struct rtl8169_private *);
39808- } pll_power_ops;
39809+ } __no_const pll_power_ops;
39810
39811 struct jumbo_ops {
39812 void (*enable)(struct rtl8169_private *);
39813 void (*disable)(struct rtl8169_private *);
39814- } jumbo_ops;
39815+ } __no_const jumbo_ops;
39816
39817 struct csi_ops {
39818 void (*write)(struct rtl8169_private *, int, int);
39819 u32 (*read)(struct rtl8169_private *, int);
39820- } csi_ops;
39821+ } __no_const csi_ops;
39822
39823 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
39824 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
39825diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
39826index 3f93624..cf01144 100644
39827--- a/drivers/net/ethernet/sfc/ptp.c
39828+++ b/drivers/net/ethernet/sfc/ptp.c
39829@@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
39830 (u32)((u64)ptp->start.dma_addr >> 32));
39831
39832 /* Clear flag that signals MC ready */
39833- ACCESS_ONCE(*start) = 0;
39834+ ACCESS_ONCE_RW(*start) = 0;
39835 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
39836 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
39837
39838diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39839index 50617c5..b13724c 100644
39840--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39841+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39842@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
39843
39844 writel(value, ioaddr + MMC_CNTRL);
39845
39846- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
39847- MMC_CNTRL, value);
39848+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
39849+// MMC_CNTRL, value);
39850 }
39851
39852 /* To mask all all interrupts.*/
39853diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
39854index e6fe0d8..2b7d752 100644
39855--- a/drivers/net/hyperv/hyperv_net.h
39856+++ b/drivers/net/hyperv/hyperv_net.h
39857@@ -101,7 +101,7 @@ struct rndis_device {
39858
39859 enum rndis_device_state state;
39860 bool link_state;
39861- atomic_t new_req_id;
39862+ atomic_unchecked_t new_req_id;
39863
39864 spinlock_t request_lock;
39865 struct list_head req_list;
39866diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
39867index 0775f0a..d4fb316 100644
39868--- a/drivers/net/hyperv/rndis_filter.c
39869+++ b/drivers/net/hyperv/rndis_filter.c
39870@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
39871 * template
39872 */
39873 set = &rndis_msg->msg.set_req;
39874- set->req_id = atomic_inc_return(&dev->new_req_id);
39875+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39876
39877 /* Add to the request list */
39878 spin_lock_irqsave(&dev->request_lock, flags);
39879@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
39880
39881 /* Setup the rndis set */
39882 halt = &request->request_msg.msg.halt_req;
39883- halt->req_id = atomic_inc_return(&dev->new_req_id);
39884+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39885
39886 /* Ignore return since this msg is optional. */
39887 rndis_filter_send_request(dev, request);
39888diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
39889index 8f1c256..a2991d1 100644
39890--- a/drivers/net/ieee802154/fakehard.c
39891+++ b/drivers/net/ieee802154/fakehard.c
39892@@ -385,7 +385,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
39893 phy->transmit_power = 0xbf;
39894
39895 dev->netdev_ops = &fake_ops;
39896- dev->ml_priv = &fake_mlme;
39897+ dev->ml_priv = (void *)&fake_mlme;
39898
39899 priv = netdev_priv(dev);
39900 priv->phy = phy;
39901diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
39902index 011062e..ada88e9 100644
39903--- a/drivers/net/macvlan.c
39904+++ b/drivers/net/macvlan.c
39905@@ -892,13 +892,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
39906 int macvlan_link_register(struct rtnl_link_ops *ops)
39907 {
39908 /* common fields */
39909- ops->priv_size = sizeof(struct macvlan_dev);
39910- ops->validate = macvlan_validate;
39911- ops->maxtype = IFLA_MACVLAN_MAX;
39912- ops->policy = macvlan_policy;
39913- ops->changelink = macvlan_changelink;
39914- ops->get_size = macvlan_get_size;
39915- ops->fill_info = macvlan_fill_info;
39916+ pax_open_kernel();
39917+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
39918+ *(void **)&ops->validate = macvlan_validate;
39919+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
39920+ *(const void **)&ops->policy = macvlan_policy;
39921+ *(void **)&ops->changelink = macvlan_changelink;
39922+ *(void **)&ops->get_size = macvlan_get_size;
39923+ *(void **)&ops->fill_info = macvlan_fill_info;
39924+ pax_close_kernel();
39925
39926 return rtnl_link_register(ops);
39927 };
39928@@ -954,7 +956,7 @@ static int macvlan_device_event(struct notifier_block *unused,
39929 return NOTIFY_DONE;
39930 }
39931
39932-static struct notifier_block macvlan_notifier_block __read_mostly = {
39933+static struct notifier_block macvlan_notifier_block = {
39934 .notifier_call = macvlan_device_event,
39935 };
39936
39937diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
39938index a449439..1e468fe 100644
39939--- a/drivers/net/macvtap.c
39940+++ b/drivers/net/macvtap.c
39941@@ -1090,7 +1090,7 @@ static int macvtap_device_event(struct notifier_block *unused,
39942 return NOTIFY_DONE;
39943 }
39944
39945-static struct notifier_block macvtap_notifier_block __read_mostly = {
39946+static struct notifier_block macvtap_notifier_block = {
39947 .notifier_call = macvtap_device_event,
39948 };
39949
39950diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
39951index daec9b0..6428fcb 100644
39952--- a/drivers/net/phy/mdio-bitbang.c
39953+++ b/drivers/net/phy/mdio-bitbang.c
39954@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
39955 struct mdiobb_ctrl *ctrl = bus->priv;
39956
39957 module_put(ctrl->ops->owner);
39958+ mdiobus_unregister(bus);
39959 mdiobus_free(bus);
39960 }
39961 EXPORT_SYMBOL(free_mdio_bitbang);
39962diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
39963index 72ff14b..11d442d 100644
39964--- a/drivers/net/ppp/ppp_generic.c
39965+++ b/drivers/net/ppp/ppp_generic.c
39966@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39967 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
39968 struct ppp_stats stats;
39969 struct ppp_comp_stats cstats;
39970- char *vers;
39971
39972 switch (cmd) {
39973 case SIOCGPPPSTATS:
39974@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39975 break;
39976
39977 case SIOCGPPPVER:
39978- vers = PPP_VERSION;
39979- if (copy_to_user(addr, vers, strlen(vers) + 1))
39980+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
39981 break;
39982 err = 0;
39983 break;
39984diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
39985index 1252d9c..80e660b 100644
39986--- a/drivers/net/slip/slhc.c
39987+++ b/drivers/net/slip/slhc.c
39988@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
39989 register struct tcphdr *thp;
39990 register struct iphdr *ip;
39991 register struct cstate *cs;
39992- int len, hdrlen;
39993+ long len, hdrlen;
39994 unsigned char *cp = icp;
39995
39996 /* We've got a compressed packet; read the change byte */
39997diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
39998index bf34192..fba3500 100644
39999--- a/drivers/net/team/team.c
40000+++ b/drivers/net/team/team.c
40001@@ -2668,7 +2668,7 @@ static int team_device_event(struct notifier_block *unused,
40002 return NOTIFY_DONE;
40003 }
40004
40005-static struct notifier_block team_notifier_block __read_mostly = {
40006+static struct notifier_block team_notifier_block = {
40007 .notifier_call = team_device_event,
40008 };
40009
40010diff --git a/drivers/net/tun.c b/drivers/net/tun.c
40011index 755fa9e..631fdce 100644
40012--- a/drivers/net/tun.c
40013+++ b/drivers/net/tun.c
40014@@ -1841,7 +1841,7 @@ unlock:
40015 }
40016
40017 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40018- unsigned long arg, int ifreq_len)
40019+ unsigned long arg, size_t ifreq_len)
40020 {
40021 struct tun_file *tfile = file->private_data;
40022 struct tun_struct *tun;
40023@@ -1853,6 +1853,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40024 int vnet_hdr_sz;
40025 int ret;
40026
40027+ if (ifreq_len > sizeof ifr)
40028+ return -EFAULT;
40029+
40030 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
40031 if (copy_from_user(&ifr, argp, ifreq_len))
40032 return -EFAULT;
40033diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
40034index e2dd324..be92fcf 100644
40035--- a/drivers/net/usb/hso.c
40036+++ b/drivers/net/usb/hso.c
40037@@ -71,7 +71,7 @@
40038 #include <asm/byteorder.h>
40039 #include <linux/serial_core.h>
40040 #include <linux/serial.h>
40041-
40042+#include <asm/local.h>
40043
40044 #define MOD_AUTHOR "Option Wireless"
40045 #define MOD_DESCRIPTION "USB High Speed Option driver"
40046@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
40047 struct urb *urb;
40048
40049 urb = serial->rx_urb[0];
40050- if (serial->port.count > 0) {
40051+ if (atomic_read(&serial->port.count) > 0) {
40052 count = put_rxbuf_data(urb, serial);
40053 if (count == -1)
40054 return;
40055@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
40056 DUMP1(urb->transfer_buffer, urb->actual_length);
40057
40058 /* Anyone listening? */
40059- if (serial->port.count == 0)
40060+ if (atomic_read(&serial->port.count) == 0)
40061 return;
40062
40063 if (status == 0) {
40064@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40065 tty_port_tty_set(&serial->port, tty);
40066
40067 /* check for port already opened, if not set the termios */
40068- serial->port.count++;
40069- if (serial->port.count == 1) {
40070+ if (atomic_inc_return(&serial->port.count) == 1) {
40071 serial->rx_state = RX_IDLE;
40072 /* Force default termio settings */
40073 _hso_serial_set_termios(tty, NULL);
40074@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40075 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
40076 if (result) {
40077 hso_stop_serial_device(serial->parent);
40078- serial->port.count--;
40079+ atomic_dec(&serial->port.count);
40080 kref_put(&serial->parent->ref, hso_serial_ref_free);
40081 }
40082 } else {
40083@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
40084
40085 /* reset the rts and dtr */
40086 /* do the actual close */
40087- serial->port.count--;
40088+ atomic_dec(&serial->port.count);
40089
40090- if (serial->port.count <= 0) {
40091- serial->port.count = 0;
40092+ if (atomic_read(&serial->port.count) <= 0) {
40093+ atomic_set(&serial->port.count, 0);
40094 tty_port_tty_set(&serial->port, NULL);
40095 if (!usb_gone)
40096 hso_stop_serial_device(serial->parent);
40097@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
40098
40099 /* the actual setup */
40100 spin_lock_irqsave(&serial->serial_lock, flags);
40101- if (serial->port.count)
40102+ if (atomic_read(&serial->port.count))
40103 _hso_serial_set_termios(tty, old);
40104 else
40105 tty->termios = *old;
40106@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
40107 D1("Pending read interrupt on port %d\n", i);
40108 spin_lock(&serial->serial_lock);
40109 if (serial->rx_state == RX_IDLE &&
40110- serial->port.count > 0) {
40111+ atomic_read(&serial->port.count) > 0) {
40112 /* Setup and send a ctrl req read on
40113 * port i */
40114 if (!serial->rx_urb_filled[0]) {
40115@@ -3066,7 +3065,7 @@ static int hso_resume(struct usb_interface *iface)
40116 /* Start all serial ports */
40117 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
40118 if (serial_table[i] && (serial_table[i]->interface == iface)) {
40119- if (dev2ser(serial_table[i])->port.count) {
40120+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
40121 result =
40122 hso_start_serial_device(serial_table[i], GFP_NOIO);
40123 hso_kick_transmit(dev2ser(serial_table[i]));
40124diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
40125index 7cee7a3..1eb9f3b 100644
40126--- a/drivers/net/vxlan.c
40127+++ b/drivers/net/vxlan.c
40128@@ -1443,7 +1443,7 @@ nla_put_failure:
40129 return -EMSGSIZE;
40130 }
40131
40132-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
40133+static struct rtnl_link_ops vxlan_link_ops = {
40134 .kind = "vxlan",
40135 .maxtype = IFLA_VXLAN_MAX,
40136 .policy = vxlan_policy,
40137diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
40138index 5ac5f7a..5f82012 100644
40139--- a/drivers/net/wireless/at76c50x-usb.c
40140+++ b/drivers/net/wireless/at76c50x-usb.c
40141@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
40142 }
40143
40144 /* Convert timeout from the DFU status to jiffies */
40145-static inline unsigned long at76_get_timeout(struct dfu_status *s)
40146+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
40147 {
40148 return msecs_to_jiffies((s->poll_timeout[2] << 16)
40149 | (s->poll_timeout[1] << 8)
40150diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40151index 8d78253..bebbb68 100644
40152--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40153+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40154@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40155 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
40156 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
40157
40158- ACCESS_ONCE(ads->ds_link) = i->link;
40159- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
40160+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
40161+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
40162
40163 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
40164 ctl6 = SM(i->keytype, AR_EncrType);
40165@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40166
40167 if ((i->is_first || i->is_last) &&
40168 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
40169- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
40170+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
40171 | set11nTries(i->rates, 1)
40172 | set11nTries(i->rates, 2)
40173 | set11nTries(i->rates, 3)
40174 | (i->dur_update ? AR_DurUpdateEna : 0)
40175 | SM(0, AR_BurstDur);
40176
40177- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
40178+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
40179 | set11nRate(i->rates, 1)
40180 | set11nRate(i->rates, 2)
40181 | set11nRate(i->rates, 3);
40182 } else {
40183- ACCESS_ONCE(ads->ds_ctl2) = 0;
40184- ACCESS_ONCE(ads->ds_ctl3) = 0;
40185+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
40186+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
40187 }
40188
40189 if (!i->is_first) {
40190- ACCESS_ONCE(ads->ds_ctl0) = 0;
40191- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
40192- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
40193+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
40194+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
40195+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
40196 return;
40197 }
40198
40199@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40200 break;
40201 }
40202
40203- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
40204+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
40205 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
40206 | SM(i->txpower, AR_XmitPower)
40207 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
40208@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40209 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
40210 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
40211
40212- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
40213- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
40214+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
40215+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
40216
40217 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
40218 return;
40219
40220- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
40221+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
40222 | set11nPktDurRTSCTS(i->rates, 1);
40223
40224- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
40225+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
40226 | set11nPktDurRTSCTS(i->rates, 3);
40227
40228- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
40229+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
40230 | set11nRateFlags(i->rates, 1)
40231 | set11nRateFlags(i->rates, 2)
40232 | set11nRateFlags(i->rates, 3)
40233diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40234index 301bf72..3f5654f 100644
40235--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40236+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40237@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40238 (i->qcu << AR_TxQcuNum_S) | desc_len;
40239
40240 checksum += val;
40241- ACCESS_ONCE(ads->info) = val;
40242+ ACCESS_ONCE_RW(ads->info) = val;
40243
40244 checksum += i->link;
40245- ACCESS_ONCE(ads->link) = i->link;
40246+ ACCESS_ONCE_RW(ads->link) = i->link;
40247
40248 checksum += i->buf_addr[0];
40249- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
40250+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
40251 checksum += i->buf_addr[1];
40252- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
40253+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
40254 checksum += i->buf_addr[2];
40255- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
40256+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
40257 checksum += i->buf_addr[3];
40258- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
40259+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
40260
40261 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
40262- ACCESS_ONCE(ads->ctl3) = val;
40263+ ACCESS_ONCE_RW(ads->ctl3) = val;
40264 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
40265- ACCESS_ONCE(ads->ctl5) = val;
40266+ ACCESS_ONCE_RW(ads->ctl5) = val;
40267 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
40268- ACCESS_ONCE(ads->ctl7) = val;
40269+ ACCESS_ONCE_RW(ads->ctl7) = val;
40270 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
40271- ACCESS_ONCE(ads->ctl9) = val;
40272+ ACCESS_ONCE_RW(ads->ctl9) = val;
40273
40274 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
40275- ACCESS_ONCE(ads->ctl10) = checksum;
40276+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
40277
40278 if (i->is_first || i->is_last) {
40279- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
40280+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
40281 | set11nTries(i->rates, 1)
40282 | set11nTries(i->rates, 2)
40283 | set11nTries(i->rates, 3)
40284 | (i->dur_update ? AR_DurUpdateEna : 0)
40285 | SM(0, AR_BurstDur);
40286
40287- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
40288+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
40289 | set11nRate(i->rates, 1)
40290 | set11nRate(i->rates, 2)
40291 | set11nRate(i->rates, 3);
40292 } else {
40293- ACCESS_ONCE(ads->ctl13) = 0;
40294- ACCESS_ONCE(ads->ctl14) = 0;
40295+ ACCESS_ONCE_RW(ads->ctl13) = 0;
40296+ ACCESS_ONCE_RW(ads->ctl14) = 0;
40297 }
40298
40299 ads->ctl20 = 0;
40300@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40301
40302 ctl17 = SM(i->keytype, AR_EncrType);
40303 if (!i->is_first) {
40304- ACCESS_ONCE(ads->ctl11) = 0;
40305- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
40306- ACCESS_ONCE(ads->ctl15) = 0;
40307- ACCESS_ONCE(ads->ctl16) = 0;
40308- ACCESS_ONCE(ads->ctl17) = ctl17;
40309- ACCESS_ONCE(ads->ctl18) = 0;
40310- ACCESS_ONCE(ads->ctl19) = 0;
40311+ ACCESS_ONCE_RW(ads->ctl11) = 0;
40312+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
40313+ ACCESS_ONCE_RW(ads->ctl15) = 0;
40314+ ACCESS_ONCE_RW(ads->ctl16) = 0;
40315+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
40316+ ACCESS_ONCE_RW(ads->ctl18) = 0;
40317+ ACCESS_ONCE_RW(ads->ctl19) = 0;
40318 return;
40319 }
40320
40321- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
40322+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
40323 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
40324 | SM(i->txpower, AR_XmitPower)
40325 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
40326@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40327 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
40328 ctl12 |= SM(val, AR_PAPRDChainMask);
40329
40330- ACCESS_ONCE(ads->ctl12) = ctl12;
40331- ACCESS_ONCE(ads->ctl17) = ctl17;
40332+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
40333+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
40334
40335- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
40336+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
40337 | set11nPktDurRTSCTS(i->rates, 1);
40338
40339- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
40340+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
40341 | set11nPktDurRTSCTS(i->rates, 3);
40342
40343- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
40344+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
40345 | set11nRateFlags(i->rates, 1)
40346 | set11nRateFlags(i->rates, 2)
40347 | set11nRateFlags(i->rates, 3)
40348 | SM(i->rtscts_rate, AR_RTSCTSRate);
40349
40350- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
40351+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
40352 }
40353
40354 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
40355diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
40356index 784e81c..349e01e 100644
40357--- a/drivers/net/wireless/ath/ath9k/hw.h
40358+++ b/drivers/net/wireless/ath/ath9k/hw.h
40359@@ -653,7 +653,7 @@ struct ath_hw_private_ops {
40360
40361 /* ANI */
40362 void (*ani_cache_ini_regs)(struct ath_hw *ah);
40363-};
40364+} __no_const;
40365
40366 /**
40367 * struct ath_spec_scan - parameters for Atheros spectral scan
40368@@ -722,7 +722,7 @@ struct ath_hw_ops {
40369 struct ath_spec_scan *param);
40370 void (*spectral_scan_trigger)(struct ath_hw *ah);
40371 void (*spectral_scan_wait)(struct ath_hw *ah);
40372-};
40373+} __no_const;
40374
40375 struct ath_nf_limits {
40376 s16 max;
40377diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
40378index c353b5f..62aaca2 100644
40379--- a/drivers/net/wireless/iwlegacy/3945-mac.c
40380+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
40381@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
40382 */
40383 if (il3945_mod_params.disable_hw_scan) {
40384 D_INFO("Disabling hw_scan\n");
40385- il3945_mac_ops.hw_scan = NULL;
40386+ pax_open_kernel();
40387+ *(void **)&il3945_mac_ops.hw_scan = NULL;
40388+ pax_close_kernel();
40389 }
40390
40391 D_INFO("*** LOAD DRIVER ***\n");
40392diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40393index 81d4071..f2071ea 100644
40394--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40395+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40396@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
40397 {
40398 struct iwl_priv *priv = file->private_data;
40399 char buf[64];
40400- int buf_size;
40401+ size_t buf_size;
40402 u32 offset, len;
40403
40404 memset(buf, 0, sizeof(buf));
40405@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
40406 struct iwl_priv *priv = file->private_data;
40407
40408 char buf[8];
40409- int buf_size;
40410+ size_t buf_size;
40411 u32 reset_flag;
40412
40413 memset(buf, 0, sizeof(buf));
40414@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
40415 {
40416 struct iwl_priv *priv = file->private_data;
40417 char buf[8];
40418- int buf_size;
40419+ size_t buf_size;
40420 int ht40;
40421
40422 memset(buf, 0, sizeof(buf));
40423@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
40424 {
40425 struct iwl_priv *priv = file->private_data;
40426 char buf[8];
40427- int buf_size;
40428+ size_t buf_size;
40429 int value;
40430
40431 memset(buf, 0, sizeof(buf));
40432@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
40433 {
40434 struct iwl_priv *priv = file->private_data;
40435 char buf[8];
40436- int buf_size;
40437+ size_t buf_size;
40438 int clear;
40439
40440 memset(buf, 0, sizeof(buf));
40441@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
40442 {
40443 struct iwl_priv *priv = file->private_data;
40444 char buf[8];
40445- int buf_size;
40446+ size_t buf_size;
40447 int trace;
40448
40449 memset(buf, 0, sizeof(buf));
40450@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
40451 {
40452 struct iwl_priv *priv = file->private_data;
40453 char buf[8];
40454- int buf_size;
40455+ size_t buf_size;
40456 int missed;
40457
40458 memset(buf, 0, sizeof(buf));
40459@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
40460
40461 struct iwl_priv *priv = file->private_data;
40462 char buf[8];
40463- int buf_size;
40464+ size_t buf_size;
40465 int plcp;
40466
40467 memset(buf, 0, sizeof(buf));
40468@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
40469
40470 struct iwl_priv *priv = file->private_data;
40471 char buf[8];
40472- int buf_size;
40473+ size_t buf_size;
40474 int flush;
40475
40476 memset(buf, 0, sizeof(buf));
40477@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
40478
40479 struct iwl_priv *priv = file->private_data;
40480 char buf[8];
40481- int buf_size;
40482+ size_t buf_size;
40483 int rts;
40484
40485 if (!priv->cfg->ht_params)
40486@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
40487 {
40488 struct iwl_priv *priv = file->private_data;
40489 char buf[8];
40490- int buf_size;
40491+ size_t buf_size;
40492
40493 memset(buf, 0, sizeof(buf));
40494 buf_size = min(count, sizeof(buf) - 1);
40495@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
40496 struct iwl_priv *priv = file->private_data;
40497 u32 event_log_flag;
40498 char buf[8];
40499- int buf_size;
40500+ size_t buf_size;
40501
40502 /* check that the interface is up */
40503 if (!iwl_is_ready(priv))
40504@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
40505 struct iwl_priv *priv = file->private_data;
40506 char buf[8];
40507 u32 calib_disabled;
40508- int buf_size;
40509+ size_t buf_size;
40510
40511 memset(buf, 0, sizeof(buf));
40512 buf_size = min(count, sizeof(buf) - 1);
40513diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
40514index 12c4f31..484d948 100644
40515--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
40516+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
40517@@ -1328,7 +1328,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
40518 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
40519
40520 char buf[8];
40521- int buf_size;
40522+ size_t buf_size;
40523 u32 reset_flag;
40524
40525 memset(buf, 0, sizeof(buf));
40526@@ -1349,7 +1349,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
40527 {
40528 struct iwl_trans *trans = file->private_data;
40529 char buf[8];
40530- int buf_size;
40531+ size_t buf_size;
40532 int csr;
40533
40534 memset(buf, 0, sizeof(buf));
40535diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
40536index 2b49f48..14fc244 100644
40537--- a/drivers/net/wireless/mac80211_hwsim.c
40538+++ b/drivers/net/wireless/mac80211_hwsim.c
40539@@ -2143,25 +2143,19 @@ static int __init init_mac80211_hwsim(void)
40540
40541 if (channels > 1) {
40542 hwsim_if_comb.num_different_channels = channels;
40543- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40544- mac80211_hwsim_ops.cancel_hw_scan =
40545- mac80211_hwsim_cancel_hw_scan;
40546- mac80211_hwsim_ops.sw_scan_start = NULL;
40547- mac80211_hwsim_ops.sw_scan_complete = NULL;
40548- mac80211_hwsim_ops.remain_on_channel =
40549- mac80211_hwsim_roc;
40550- mac80211_hwsim_ops.cancel_remain_on_channel =
40551- mac80211_hwsim_croc;
40552- mac80211_hwsim_ops.add_chanctx =
40553- mac80211_hwsim_add_chanctx;
40554- mac80211_hwsim_ops.remove_chanctx =
40555- mac80211_hwsim_remove_chanctx;
40556- mac80211_hwsim_ops.change_chanctx =
40557- mac80211_hwsim_change_chanctx;
40558- mac80211_hwsim_ops.assign_vif_chanctx =
40559- mac80211_hwsim_assign_vif_chanctx;
40560- mac80211_hwsim_ops.unassign_vif_chanctx =
40561- mac80211_hwsim_unassign_vif_chanctx;
40562+ pax_open_kernel();
40563+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40564+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
40565+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
40566+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
40567+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
40568+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
40569+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
40570+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
40571+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
40572+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
40573+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
40574+ pax_close_kernel();
40575 }
40576
40577 spin_lock_init(&hwsim_radio_lock);
40578diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
40579index 525fd75..6c9f791 100644
40580--- a/drivers/net/wireless/rndis_wlan.c
40581+++ b/drivers/net/wireless/rndis_wlan.c
40582@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
40583
40584 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
40585
40586- if (rts_threshold < 0 || rts_threshold > 2347)
40587+ if (rts_threshold > 2347)
40588 rts_threshold = 2347;
40589
40590 tmp = cpu_to_le32(rts_threshold);
40591diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
40592index 086abb4..8279c30 100644
40593--- a/drivers/net/wireless/rt2x00/rt2x00.h
40594+++ b/drivers/net/wireless/rt2x00/rt2x00.h
40595@@ -396,7 +396,7 @@ struct rt2x00_intf {
40596 * for hardware which doesn't support hardware
40597 * sequence counting.
40598 */
40599- atomic_t seqno;
40600+ atomic_unchecked_t seqno;
40601 };
40602
40603 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
40604diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
40605index 4d91795..62fccff 100644
40606--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
40607+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
40608@@ -251,9 +251,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
40609 * sequence counter given by mac80211.
40610 */
40611 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
40612- seqno = atomic_add_return(0x10, &intf->seqno);
40613+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
40614 else
40615- seqno = atomic_read(&intf->seqno);
40616+ seqno = atomic_read_unchecked(&intf->seqno);
40617
40618 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
40619 hdr->seq_ctrl |= cpu_to_le16(seqno);
40620diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
40621index e57ee48..541cf6c 100644
40622--- a/drivers/net/wireless/ti/wl1251/sdio.c
40623+++ b/drivers/net/wireless/ti/wl1251/sdio.c
40624@@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
40625
40626 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
40627
40628- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
40629- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
40630+ pax_open_kernel();
40631+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
40632+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
40633+ pax_close_kernel();
40634
40635 wl1251_info("using dedicated interrupt line");
40636 } else {
40637- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
40638- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
40639+ pax_open_kernel();
40640+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
40641+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
40642+ pax_close_kernel();
40643
40644 wl1251_info("using SDIO interrupt");
40645 }
40646diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
40647index 09694e3..24ccec7 100644
40648--- a/drivers/net/wireless/ti/wl12xx/main.c
40649+++ b/drivers/net/wireless/ti/wl12xx/main.c
40650@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
40651 sizeof(wl->conf.mem));
40652
40653 /* read data preparation is only needed by wl127x */
40654- wl->ops->prepare_read = wl127x_prepare_read;
40655+ pax_open_kernel();
40656+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
40657+ pax_close_kernel();
40658
40659 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
40660 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
40661@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
40662 sizeof(wl->conf.mem));
40663
40664 /* read data preparation is only needed by wl127x */
40665- wl->ops->prepare_read = wl127x_prepare_read;
40666+ pax_open_kernel();
40667+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
40668+ pax_close_kernel();
40669
40670 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
40671 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
40672diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
40673index da3ef1b..4790b95 100644
40674--- a/drivers/net/wireless/ti/wl18xx/main.c
40675+++ b/drivers/net/wireless/ti/wl18xx/main.c
40676@@ -1664,8 +1664,10 @@ static int wl18xx_setup(struct wl1271 *wl)
40677 }
40678
40679 if (!checksum_param) {
40680- wl18xx_ops.set_rx_csum = NULL;
40681- wl18xx_ops.init_vif = NULL;
40682+ pax_open_kernel();
40683+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
40684+ *(void **)&wl18xx_ops.init_vif = NULL;
40685+ pax_close_kernel();
40686 }
40687
40688 /* Enable 11a Band only if we have 5G antennas */
40689diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
40690index 7ef0b4a..ff65c28 100644
40691--- a/drivers/net/wireless/zd1211rw/zd_usb.c
40692+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
40693@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
40694 {
40695 struct zd_usb *usb = urb->context;
40696 struct zd_usb_interrupt *intr = &usb->intr;
40697- int len;
40698+ unsigned int len;
40699 u16 int_num;
40700
40701 ZD_ASSERT(in_interrupt());
40702diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
40703index d93b2b6..ae50401 100644
40704--- a/drivers/oprofile/buffer_sync.c
40705+++ b/drivers/oprofile/buffer_sync.c
40706@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
40707 if (cookie == NO_COOKIE)
40708 offset = pc;
40709 if (cookie == INVALID_COOKIE) {
40710- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
40711+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
40712 offset = pc;
40713 }
40714 if (cookie != last_cookie) {
40715@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
40716 /* add userspace sample */
40717
40718 if (!mm) {
40719- atomic_inc(&oprofile_stats.sample_lost_no_mm);
40720+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
40721 return 0;
40722 }
40723
40724 cookie = lookup_dcookie(mm, s->eip, &offset);
40725
40726 if (cookie == INVALID_COOKIE) {
40727- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
40728+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
40729 return 0;
40730 }
40731
40732@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
40733 /* ignore backtraces if failed to add a sample */
40734 if (state == sb_bt_start) {
40735 state = sb_bt_ignore;
40736- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
40737+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
40738 }
40739 }
40740 release_mm(mm);
40741diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
40742index c0cc4e7..44d4e54 100644
40743--- a/drivers/oprofile/event_buffer.c
40744+++ b/drivers/oprofile/event_buffer.c
40745@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
40746 }
40747
40748 if (buffer_pos == buffer_size) {
40749- atomic_inc(&oprofile_stats.event_lost_overflow);
40750+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
40751 return;
40752 }
40753
40754diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
40755index ed2c3ec..deda85a 100644
40756--- a/drivers/oprofile/oprof.c
40757+++ b/drivers/oprofile/oprof.c
40758@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
40759 if (oprofile_ops.switch_events())
40760 return;
40761
40762- atomic_inc(&oprofile_stats.multiplex_counter);
40763+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
40764 start_switch_worker();
40765 }
40766
40767diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
40768index 84a208d..d61b0a1 100644
40769--- a/drivers/oprofile/oprofile_files.c
40770+++ b/drivers/oprofile/oprofile_files.c
40771@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
40772
40773 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
40774
40775-static ssize_t timeout_read(struct file *file, char __user *buf,
40776+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
40777 size_t count, loff_t *offset)
40778 {
40779 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
40780diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
40781index 917d28e..d62d981 100644
40782--- a/drivers/oprofile/oprofile_stats.c
40783+++ b/drivers/oprofile/oprofile_stats.c
40784@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
40785 cpu_buf->sample_invalid_eip = 0;
40786 }
40787
40788- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
40789- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
40790- atomic_set(&oprofile_stats.event_lost_overflow, 0);
40791- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
40792- atomic_set(&oprofile_stats.multiplex_counter, 0);
40793+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
40794+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
40795+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
40796+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
40797+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
40798 }
40799
40800
40801diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
40802index 38b6fc0..b5cbfce 100644
40803--- a/drivers/oprofile/oprofile_stats.h
40804+++ b/drivers/oprofile/oprofile_stats.h
40805@@ -13,11 +13,11 @@
40806 #include <linux/atomic.h>
40807
40808 struct oprofile_stat_struct {
40809- atomic_t sample_lost_no_mm;
40810- atomic_t sample_lost_no_mapping;
40811- atomic_t bt_lost_no_mapping;
40812- atomic_t event_lost_overflow;
40813- atomic_t multiplex_counter;
40814+ atomic_unchecked_t sample_lost_no_mm;
40815+ atomic_unchecked_t sample_lost_no_mapping;
40816+ atomic_unchecked_t bt_lost_no_mapping;
40817+ atomic_unchecked_t event_lost_overflow;
40818+ atomic_unchecked_t multiplex_counter;
40819 };
40820
40821 extern struct oprofile_stat_struct oprofile_stats;
40822diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
40823index 7c12d9c..558bf3bb 100644
40824--- a/drivers/oprofile/oprofilefs.c
40825+++ b/drivers/oprofile/oprofilefs.c
40826@@ -190,7 +190,7 @@ static const struct file_operations atomic_ro_fops = {
40827
40828
40829 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
40830- char const *name, atomic_t *val)
40831+ char const *name, atomic_unchecked_t *val)
40832 {
40833 return __oprofilefs_create_file(sb, root, name,
40834 &atomic_ro_fops, 0444, val);
40835diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
40836index 93404f7..4a313d8 100644
40837--- a/drivers/oprofile/timer_int.c
40838+++ b/drivers/oprofile/timer_int.c
40839@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
40840 return NOTIFY_OK;
40841 }
40842
40843-static struct notifier_block __refdata oprofile_cpu_notifier = {
40844+static struct notifier_block oprofile_cpu_notifier = {
40845 .notifier_call = oprofile_cpu_notify,
40846 };
40847
40848diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
40849index 3f56bc0..707d642 100644
40850--- a/drivers/parport/procfs.c
40851+++ b/drivers/parport/procfs.c
40852@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
40853
40854 *ppos += len;
40855
40856- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
40857+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
40858 }
40859
40860 #ifdef CONFIG_PARPORT_1284
40861@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
40862
40863 *ppos += len;
40864
40865- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
40866+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
40867 }
40868 #endif /* IEEE1284.3 support. */
40869
40870diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
40871index c35e8ad..fc33beb 100644
40872--- a/drivers/pci/hotplug/acpiphp_ibm.c
40873+++ b/drivers/pci/hotplug/acpiphp_ibm.c
40874@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
40875 goto init_cleanup;
40876 }
40877
40878- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
40879+ pax_open_kernel();
40880+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
40881+ pax_close_kernel();
40882 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
40883
40884 return retval;
40885diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
40886index a6a71c4..c91097b 100644
40887--- a/drivers/pci/hotplug/cpcihp_generic.c
40888+++ b/drivers/pci/hotplug/cpcihp_generic.c
40889@@ -73,7 +73,6 @@ static u16 port;
40890 static unsigned int enum_bit;
40891 static u8 enum_mask;
40892
40893-static struct cpci_hp_controller_ops generic_hpc_ops;
40894 static struct cpci_hp_controller generic_hpc;
40895
40896 static int __init validate_parameters(void)
40897@@ -139,6 +138,10 @@ static int query_enum(void)
40898 return ((value & enum_mask) == enum_mask);
40899 }
40900
40901+static struct cpci_hp_controller_ops generic_hpc_ops = {
40902+ .query_enum = query_enum,
40903+};
40904+
40905 static int __init cpcihp_generic_init(void)
40906 {
40907 int status;
40908@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
40909 pci_dev_put(dev);
40910
40911 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
40912- generic_hpc_ops.query_enum = query_enum;
40913 generic_hpc.ops = &generic_hpc_ops;
40914
40915 status = cpci_hp_register_controller(&generic_hpc);
40916diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
40917index 449b4bb..257e2e8 100644
40918--- a/drivers/pci/hotplug/cpcihp_zt5550.c
40919+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
40920@@ -59,7 +59,6 @@
40921 /* local variables */
40922 static bool debug;
40923 static bool poll;
40924-static struct cpci_hp_controller_ops zt5550_hpc_ops;
40925 static struct cpci_hp_controller zt5550_hpc;
40926
40927 /* Primary cPCI bus bridge device */
40928@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
40929 return 0;
40930 }
40931
40932+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
40933+ .query_enum = zt5550_hc_query_enum,
40934+};
40935+
40936 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
40937 {
40938 int status;
40939@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
40940 dbg("returned from zt5550_hc_config");
40941
40942 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
40943- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
40944 zt5550_hpc.ops = &zt5550_hpc_ops;
40945 if(!poll) {
40946 zt5550_hpc.irq = hc_dev->irq;
40947 zt5550_hpc.irq_flags = IRQF_SHARED;
40948 zt5550_hpc.dev_id = hc_dev;
40949
40950- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
40951- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
40952- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
40953+ pax_open_kernel();
40954+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
40955+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
40956+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
40957+ pax_open_kernel();
40958 } else {
40959 info("using ENUM# polling mode");
40960 }
40961diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
40962index 76ba8a1..20ca857 100644
40963--- a/drivers/pci/hotplug/cpqphp_nvram.c
40964+++ b/drivers/pci/hotplug/cpqphp_nvram.c
40965@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
40966
40967 void compaq_nvram_init (void __iomem *rom_start)
40968 {
40969+
40970+#ifndef CONFIG_PAX_KERNEXEC
40971 if (rom_start) {
40972 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
40973 }
40974+#endif
40975+
40976 dbg("int15 entry = %p\n", compaq_int15_entry_point);
40977
40978 /* initialize our int15 lock */
40979diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
40980index 202f4a9..8ee47d0 100644
40981--- a/drivers/pci/hotplug/pci_hotplug_core.c
40982+++ b/drivers/pci/hotplug/pci_hotplug_core.c
40983@@ -448,8 +448,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
40984 return -EINVAL;
40985 }
40986
40987- slot->ops->owner = owner;
40988- slot->ops->mod_name = mod_name;
40989+ pax_open_kernel();
40990+ *(struct module **)&slot->ops->owner = owner;
40991+ *(const char **)&slot->ops->mod_name = mod_name;
40992+ pax_close_kernel();
40993
40994 mutex_lock(&pci_hp_mutex);
40995 /*
40996diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
40997index 7d72c5e..edce02c 100644
40998--- a/drivers/pci/hotplug/pciehp_core.c
40999+++ b/drivers/pci/hotplug/pciehp_core.c
41000@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
41001 struct slot *slot = ctrl->slot;
41002 struct hotplug_slot *hotplug = NULL;
41003 struct hotplug_slot_info *info = NULL;
41004- struct hotplug_slot_ops *ops = NULL;
41005+ hotplug_slot_ops_no_const *ops = NULL;
41006 char name[SLOT_NAME_SIZE];
41007 int retval = -ENOMEM;
41008
41009diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
41010index 9c6e9bb..2916736 100644
41011--- a/drivers/pci/pci-sysfs.c
41012+++ b/drivers/pci/pci-sysfs.c
41013@@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
41014 {
41015 /* allocate attribute structure, piggyback attribute name */
41016 int name_len = write_combine ? 13 : 10;
41017- struct bin_attribute *res_attr;
41018+ bin_attribute_no_const *res_attr;
41019 int retval;
41020
41021 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
41022@@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
41023 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
41024 {
41025 int retval;
41026- struct bin_attribute *attr;
41027+ bin_attribute_no_const *attr;
41028
41029 /* If the device has VPD, try to expose it in sysfs. */
41030 if (dev->vpd) {
41031@@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
41032 {
41033 int retval;
41034 int rom_size = 0;
41035- struct bin_attribute *attr;
41036+ bin_attribute_no_const *attr;
41037
41038 if (!sysfs_initialized)
41039 return -EACCES;
41040diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
41041index 7346ee6..41520eb 100644
41042--- a/drivers/pci/pci.h
41043+++ b/drivers/pci/pci.h
41044@@ -93,7 +93,7 @@ struct pci_vpd_ops {
41045 struct pci_vpd {
41046 unsigned int len;
41047 const struct pci_vpd_ops *ops;
41048- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
41049+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
41050 };
41051
41052 extern int pci_vpd_pci22_init(struct pci_dev *dev);
41053diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
41054index d320df6..ca9a8f6 100644
41055--- a/drivers/pci/pcie/aspm.c
41056+++ b/drivers/pci/pcie/aspm.c
41057@@ -27,9 +27,9 @@
41058 #define MODULE_PARAM_PREFIX "pcie_aspm."
41059
41060 /* Note: those are not register definitions */
41061-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
41062-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
41063-#define ASPM_STATE_L1 (4) /* L1 state */
41064+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
41065+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
41066+#define ASPM_STATE_L1 (4U) /* L1 state */
41067 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
41068 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
41069
41070diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
41071index 5427787..8df273b 100644
41072--- a/drivers/pci/probe.c
41073+++ b/drivers/pci/probe.c
41074@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
41075 struct pci_bus_region region;
41076 bool bar_too_big = false, bar_disabled = false;
41077
41078- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
41079+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
41080
41081 /* No printks while decoding is disabled! */
41082 if (!dev->mmio_always_on) {
41083diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
41084index 0b00947..64f7c0a 100644
41085--- a/drivers/pci/proc.c
41086+++ b/drivers/pci/proc.c
41087@@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
41088 static int __init pci_proc_init(void)
41089 {
41090 struct pci_dev *dev = NULL;
41091+
41092+#ifdef CONFIG_GRKERNSEC_PROC_ADD
41093+#ifdef CONFIG_GRKERNSEC_PROC_USER
41094+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
41095+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
41096+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
41097+#endif
41098+#else
41099 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
41100+#endif
41101 proc_create("devices", 0, proc_bus_pci_dir,
41102 &proc_bus_pci_dev_operations);
41103 proc_initialized = 1;
41104diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
41105index 3e5b4497..dcdfb70 100644
41106--- a/drivers/platform/x86/chromeos_laptop.c
41107+++ b/drivers/platform/x86/chromeos_laptop.c
41108@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
41109 return 0;
41110 }
41111
41112-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
41113+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
41114 {
41115 .ident = "Samsung Series 5 550 - Touchpad",
41116 .matches = {
41117diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
41118index 6b22938..bc9700e 100644
41119--- a/drivers/platform/x86/msi-laptop.c
41120+++ b/drivers/platform/x86/msi-laptop.c
41121@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
41122
41123 if (!quirks->ec_read_only) {
41124 /* allow userland write sysfs file */
41125- dev_attr_bluetooth.store = store_bluetooth;
41126- dev_attr_wlan.store = store_wlan;
41127- dev_attr_threeg.store = store_threeg;
41128- dev_attr_bluetooth.attr.mode |= S_IWUSR;
41129- dev_attr_wlan.attr.mode |= S_IWUSR;
41130- dev_attr_threeg.attr.mode |= S_IWUSR;
41131+ pax_open_kernel();
41132+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
41133+ *(void **)&dev_attr_wlan.store = store_wlan;
41134+ *(void **)&dev_attr_threeg.store = store_threeg;
41135+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
41136+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
41137+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
41138+ pax_close_kernel();
41139 }
41140
41141 /* disable hardware control by fn key */
41142diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
41143index 14d4dce..b129917 100644
41144--- a/drivers/platform/x86/sony-laptop.c
41145+++ b/drivers/platform/x86/sony-laptop.c
41146@@ -2465,7 +2465,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
41147 }
41148
41149 /* High speed charging function */
41150-static struct device_attribute *hsc_handle;
41151+static device_attribute_no_const *hsc_handle;
41152
41153 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
41154 struct device_attribute *attr,
41155diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
41156index edec135..59a24a3 100644
41157--- a/drivers/platform/x86/thinkpad_acpi.c
41158+++ b/drivers/platform/x86/thinkpad_acpi.c
41159@@ -2093,7 +2093,7 @@ static int hotkey_mask_get(void)
41160 return 0;
41161 }
41162
41163-void static hotkey_mask_warn_incomplete_mask(void)
41164+static void hotkey_mask_warn_incomplete_mask(void)
41165 {
41166 /* log only what the user can fix... */
41167 const u32 wantedmask = hotkey_driver_mask &
41168@@ -2324,11 +2324,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
41169 }
41170 }
41171
41172-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41173- struct tp_nvram_state *newn,
41174- const u32 event_mask)
41175-{
41176-
41177 #define TPACPI_COMPARE_KEY(__scancode, __member) \
41178 do { \
41179 if ((event_mask & (1 << __scancode)) && \
41180@@ -2342,36 +2337,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41181 tpacpi_hotkey_send_key(__scancode); \
41182 } while (0)
41183
41184- void issue_volchange(const unsigned int oldvol,
41185- const unsigned int newvol)
41186- {
41187- unsigned int i = oldvol;
41188+static void issue_volchange(const unsigned int oldvol,
41189+ const unsigned int newvol,
41190+ const u32 event_mask)
41191+{
41192+ unsigned int i = oldvol;
41193
41194- while (i > newvol) {
41195- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
41196- i--;
41197- }
41198- while (i < newvol) {
41199- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41200- i++;
41201- }
41202+ while (i > newvol) {
41203+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
41204+ i--;
41205 }
41206+ while (i < newvol) {
41207+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41208+ i++;
41209+ }
41210+}
41211
41212- void issue_brightnesschange(const unsigned int oldbrt,
41213- const unsigned int newbrt)
41214- {
41215- unsigned int i = oldbrt;
41216+static void issue_brightnesschange(const unsigned int oldbrt,
41217+ const unsigned int newbrt,
41218+ const u32 event_mask)
41219+{
41220+ unsigned int i = oldbrt;
41221
41222- while (i > newbrt) {
41223- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
41224- i--;
41225- }
41226- while (i < newbrt) {
41227- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41228- i++;
41229- }
41230+ while (i > newbrt) {
41231+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
41232+ i--;
41233+ }
41234+ while (i < newbrt) {
41235+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41236+ i++;
41237 }
41238+}
41239
41240+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41241+ struct tp_nvram_state *newn,
41242+ const u32 event_mask)
41243+{
41244 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
41245 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
41246 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
41247@@ -2405,7 +2406,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41248 oldn->volume_level != newn->volume_level) {
41249 /* recently muted, or repeated mute keypress, or
41250 * multiple presses ending in mute */
41251- issue_volchange(oldn->volume_level, newn->volume_level);
41252+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
41253 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
41254 }
41255 } else {
41256@@ -2415,7 +2416,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41257 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41258 }
41259 if (oldn->volume_level != newn->volume_level) {
41260- issue_volchange(oldn->volume_level, newn->volume_level);
41261+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
41262 } else if (oldn->volume_toggle != newn->volume_toggle) {
41263 /* repeated vol up/down keypress at end of scale ? */
41264 if (newn->volume_level == 0)
41265@@ -2428,7 +2429,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41266 /* handle brightness */
41267 if (oldn->brightness_level != newn->brightness_level) {
41268 issue_brightnesschange(oldn->brightness_level,
41269- newn->brightness_level);
41270+ newn->brightness_level,
41271+ event_mask);
41272 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
41273 /* repeated key presses that didn't change state */
41274 if (newn->brightness_level == 0)
41275@@ -2437,10 +2439,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41276 && !tp_features.bright_unkfw)
41277 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41278 }
41279+}
41280
41281 #undef TPACPI_COMPARE_KEY
41282 #undef TPACPI_MAY_SEND_KEY
41283-}
41284
41285 /*
41286 * Polling driver
41287diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
41288index 769d265..a3a05ca 100644
41289--- a/drivers/pnp/pnpbios/bioscalls.c
41290+++ b/drivers/pnp/pnpbios/bioscalls.c
41291@@ -58,7 +58,7 @@ do { \
41292 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
41293 } while(0)
41294
41295-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
41296+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
41297 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
41298
41299 /*
41300@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
41301
41302 cpu = get_cpu();
41303 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
41304+
41305+ pax_open_kernel();
41306 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
41307+ pax_close_kernel();
41308
41309 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
41310 spin_lock_irqsave(&pnp_bios_lock, flags);
41311@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
41312 :"memory");
41313 spin_unlock_irqrestore(&pnp_bios_lock, flags);
41314
41315+ pax_open_kernel();
41316 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
41317+ pax_close_kernel();
41318+
41319 put_cpu();
41320
41321 /* If we get here and this is set then the PnP BIOS faulted on us. */
41322@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
41323 return status;
41324 }
41325
41326-void pnpbios_calls_init(union pnp_bios_install_struct *header)
41327+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
41328 {
41329 int i;
41330
41331@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
41332 pnp_bios_callpoint.offset = header->fields.pm16offset;
41333 pnp_bios_callpoint.segment = PNP_CS16;
41334
41335+ pax_open_kernel();
41336+
41337 for_each_possible_cpu(i) {
41338 struct desc_struct *gdt = get_cpu_gdt_table(i);
41339 if (!gdt)
41340@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
41341 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
41342 (unsigned long)__va(header->fields.pm16dseg));
41343 }
41344+
41345+ pax_close_kernel();
41346 }
41347diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
41348index 3e6db1c..1fbbdae 100644
41349--- a/drivers/pnp/resource.c
41350+++ b/drivers/pnp/resource.c
41351@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
41352 return 1;
41353
41354 /* check if the resource is valid */
41355- if (*irq < 0 || *irq > 15)
41356+ if (*irq > 15)
41357 return 0;
41358
41359 /* check if the resource is reserved */
41360@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
41361 return 1;
41362
41363 /* check if the resource is valid */
41364- if (*dma < 0 || *dma == 4 || *dma > 7)
41365+ if (*dma == 4 || *dma > 7)
41366 return 0;
41367
41368 /* check if the resource is reserved */
41369diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
41370index 7df7c5f..bd48c47 100644
41371--- a/drivers/power/pda_power.c
41372+++ b/drivers/power/pda_power.c
41373@@ -37,7 +37,11 @@ static int polling;
41374
41375 #ifdef CONFIG_USB_OTG_UTILS
41376 static struct usb_phy *transceiver;
41377-static struct notifier_block otg_nb;
41378+static int otg_handle_notification(struct notifier_block *nb,
41379+ unsigned long event, void *unused);
41380+static struct notifier_block otg_nb = {
41381+ .notifier_call = otg_handle_notification
41382+};
41383 #endif
41384
41385 static struct regulator *ac_draw;
41386@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
41387
41388 #ifdef CONFIG_USB_OTG_UTILS
41389 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
41390- otg_nb.notifier_call = otg_handle_notification;
41391 ret = usb_register_notifier(transceiver, &otg_nb);
41392 if (ret) {
41393 dev_err(dev, "failure to register otg notifier\n");
41394diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
41395index cc439fd..8fa30df 100644
41396--- a/drivers/power/power_supply.h
41397+++ b/drivers/power/power_supply.h
41398@@ -16,12 +16,12 @@ struct power_supply;
41399
41400 #ifdef CONFIG_SYSFS
41401
41402-extern void power_supply_init_attrs(struct device_type *dev_type);
41403+extern void power_supply_init_attrs(void);
41404 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
41405
41406 #else
41407
41408-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
41409+static inline void power_supply_init_attrs(void) {}
41410 #define power_supply_uevent NULL
41411
41412 #endif /* CONFIG_SYSFS */
41413diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
41414index 5deac43..608c5ff 100644
41415--- a/drivers/power/power_supply_core.c
41416+++ b/drivers/power/power_supply_core.c
41417@@ -24,7 +24,10 @@
41418 struct class *power_supply_class;
41419 EXPORT_SYMBOL_GPL(power_supply_class);
41420
41421-static struct device_type power_supply_dev_type;
41422+extern const struct attribute_group *power_supply_attr_groups[];
41423+static struct device_type power_supply_dev_type = {
41424+ .groups = power_supply_attr_groups,
41425+};
41426
41427 static int __power_supply_changed_work(struct device *dev, void *data)
41428 {
41429@@ -393,7 +396,7 @@ static int __init power_supply_class_init(void)
41430 return PTR_ERR(power_supply_class);
41431
41432 power_supply_class->dev_uevent = power_supply_uevent;
41433- power_supply_init_attrs(&power_supply_dev_type);
41434+ power_supply_init_attrs();
41435
41436 return 0;
41437 }
41438diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
41439index 29178f7..c65f324 100644
41440--- a/drivers/power/power_supply_sysfs.c
41441+++ b/drivers/power/power_supply_sysfs.c
41442@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
41443 .is_visible = power_supply_attr_is_visible,
41444 };
41445
41446-static const struct attribute_group *power_supply_attr_groups[] = {
41447+const struct attribute_group *power_supply_attr_groups[] = {
41448 &power_supply_attr_group,
41449 NULL,
41450 };
41451
41452-void power_supply_init_attrs(struct device_type *dev_type)
41453+void power_supply_init_attrs(void)
41454 {
41455 int i;
41456
41457- dev_type->groups = power_supply_attr_groups;
41458-
41459 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
41460 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
41461 }
41462diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
41463index 4d7c635..9860196 100644
41464--- a/drivers/regulator/max8660.c
41465+++ b/drivers/regulator/max8660.c
41466@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
41467 max8660->shadow_regs[MAX8660_OVER1] = 5;
41468 } else {
41469 /* Otherwise devices can be toggled via software */
41470- max8660_dcdc_ops.enable = max8660_dcdc_enable;
41471- max8660_dcdc_ops.disable = max8660_dcdc_disable;
41472+ pax_open_kernel();
41473+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
41474+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
41475+ pax_close_kernel();
41476 }
41477
41478 /*
41479diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
41480index 9a8ea91..c483dd9 100644
41481--- a/drivers/regulator/max8973-regulator.c
41482+++ b/drivers/regulator/max8973-regulator.c
41483@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
41484 if (!pdata->enable_ext_control) {
41485 max->desc.enable_reg = MAX8973_VOUT;
41486 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
41487- max8973_dcdc_ops.enable = regulator_enable_regmap;
41488- max8973_dcdc_ops.disable = regulator_disable_regmap;
41489- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41490+ pax_open_kernel();
41491+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
41492+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
41493+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41494+ pax_close_kernel();
41495 }
41496
41497 max->enable_external_control = pdata->enable_ext_control;
41498diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
41499index 9891aec..beb3083 100644
41500--- a/drivers/regulator/mc13892-regulator.c
41501+++ b/drivers/regulator/mc13892-regulator.c
41502@@ -583,10 +583,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
41503 }
41504 mc13xxx_unlock(mc13892);
41505
41506- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41507+ pax_open_kernel();
41508+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41509 = mc13892_vcam_set_mode;
41510- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41511+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41512 = mc13892_vcam_get_mode;
41513+ pax_close_kernel();
41514
41515 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
41516 ARRAY_SIZE(mc13892_regulators),
41517diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
41518index cc5bea9..689f7d9 100644
41519--- a/drivers/rtc/rtc-cmos.c
41520+++ b/drivers/rtc/rtc-cmos.c
41521@@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
41522 hpet_rtc_timer_init();
41523
41524 /* export at least the first block of NVRAM */
41525- nvram.size = address_space - NVRAM_OFFSET;
41526+ pax_open_kernel();
41527+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
41528+ pax_close_kernel();
41529 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
41530 if (retval < 0) {
41531 dev_dbg(dev, "can't create nvram file? %d\n", retval);
41532diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
41533index d049393..bb20be0 100644
41534--- a/drivers/rtc/rtc-dev.c
41535+++ b/drivers/rtc/rtc-dev.c
41536@@ -16,6 +16,7 @@
41537 #include <linux/module.h>
41538 #include <linux/rtc.h>
41539 #include <linux/sched.h>
41540+#include <linux/grsecurity.h>
41541 #include "rtc-core.h"
41542
41543 static dev_t rtc_devt;
41544@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
41545 if (copy_from_user(&tm, uarg, sizeof(tm)))
41546 return -EFAULT;
41547
41548+ gr_log_timechange();
41549+
41550 return rtc_set_time(rtc, &tm);
41551
41552 case RTC_PIE_ON:
41553diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
41554index 970a236..3613169 100644
41555--- a/drivers/rtc/rtc-ds1307.c
41556+++ b/drivers/rtc/rtc-ds1307.c
41557@@ -106,7 +106,7 @@ struct ds1307 {
41558 u8 offset; /* register's offset */
41559 u8 regs[11];
41560 u16 nvram_offset;
41561- struct bin_attribute *nvram;
41562+ bin_attribute_no_const *nvram;
41563 enum ds_type type;
41564 unsigned long flags;
41565 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
41566diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
41567index 130f29a..6179d03 100644
41568--- a/drivers/rtc/rtc-m48t59.c
41569+++ b/drivers/rtc/rtc-m48t59.c
41570@@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
41571 goto out;
41572 }
41573
41574- m48t59_nvram_attr.size = pdata->offset;
41575+ pax_open_kernel();
41576+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
41577+ pax_close_kernel();
41578
41579 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
41580 if (ret) {
41581diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
41582index e693af6..2e525b6 100644
41583--- a/drivers/scsi/bfa/bfa_fcpim.h
41584+++ b/drivers/scsi/bfa/bfa_fcpim.h
41585@@ -36,7 +36,7 @@ struct bfa_iotag_s {
41586
41587 struct bfa_itn_s {
41588 bfa_isr_func_t isr;
41589-};
41590+} __no_const;
41591
41592 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
41593 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
41594diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
41595index 23a90e7..9cf04ee 100644
41596--- a/drivers/scsi/bfa/bfa_ioc.h
41597+++ b/drivers/scsi/bfa/bfa_ioc.h
41598@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
41599 bfa_ioc_disable_cbfn_t disable_cbfn;
41600 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
41601 bfa_ioc_reset_cbfn_t reset_cbfn;
41602-};
41603+} __no_const;
41604
41605 /*
41606 * IOC event notification mechanism.
41607@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
41608 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
41609 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
41610 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
41611-};
41612+} __no_const;
41613
41614 /*
41615 * Queue element to wait for room in request queue. FIFO order is
41616diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
41617index df0c3c7..b00e1d0 100644
41618--- a/drivers/scsi/hosts.c
41619+++ b/drivers/scsi/hosts.c
41620@@ -42,7 +42,7 @@
41621 #include "scsi_logging.h"
41622
41623
41624-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
41625+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
41626
41627
41628 static void scsi_host_cls_release(struct device *dev)
41629@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
41630 * subtract one because we increment first then return, but we need to
41631 * know what the next host number was before increment
41632 */
41633- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
41634+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
41635 shost->dma_channel = 0xff;
41636
41637 /* These three are default values which can be overridden */
41638diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
41639index 7f4f790..b75b92a 100644
41640--- a/drivers/scsi/hpsa.c
41641+++ b/drivers/scsi/hpsa.c
41642@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
41643 unsigned long flags;
41644
41645 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
41646- return h->access.command_completed(h, q);
41647+ return h->access->command_completed(h, q);
41648
41649 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
41650 a = rq->head[rq->current_entry];
41651@@ -3422,7 +3422,7 @@ static void start_io(struct ctlr_info *h)
41652 while (!list_empty(&h->reqQ)) {
41653 c = list_entry(h->reqQ.next, struct CommandList, list);
41654 /* can't do anything if fifo is full */
41655- if ((h->access.fifo_full(h))) {
41656+ if ((h->access->fifo_full(h))) {
41657 dev_warn(&h->pdev->dev, "fifo full\n");
41658 break;
41659 }
41660@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
41661
41662 /* Tell the controller execute command */
41663 spin_unlock_irqrestore(&h->lock, flags);
41664- h->access.submit_command(h, c);
41665+ h->access->submit_command(h, c);
41666 spin_lock_irqsave(&h->lock, flags);
41667 }
41668 spin_unlock_irqrestore(&h->lock, flags);
41669@@ -3452,17 +3452,17 @@ static void start_io(struct ctlr_info *h)
41670
41671 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
41672 {
41673- return h->access.command_completed(h, q);
41674+ return h->access->command_completed(h, q);
41675 }
41676
41677 static inline bool interrupt_pending(struct ctlr_info *h)
41678 {
41679- return h->access.intr_pending(h);
41680+ return h->access->intr_pending(h);
41681 }
41682
41683 static inline long interrupt_not_for_us(struct ctlr_info *h)
41684 {
41685- return (h->access.intr_pending(h) == 0) ||
41686+ return (h->access->intr_pending(h) == 0) ||
41687 (h->interrupts_enabled == 0);
41688 }
41689
41690@@ -4364,7 +4364,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
41691 if (prod_index < 0)
41692 return -ENODEV;
41693 h->product_name = products[prod_index].product_name;
41694- h->access = *(products[prod_index].access);
41695+ h->access = products[prod_index].access;
41696
41697 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
41698 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
41699@@ -4646,7 +4646,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
41700
41701 assert_spin_locked(&lockup_detector_lock);
41702 remove_ctlr_from_lockup_detector_list(h);
41703- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41704+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41705 spin_lock_irqsave(&h->lock, flags);
41706 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
41707 spin_unlock_irqrestore(&h->lock, flags);
41708@@ -4823,7 +4823,7 @@ reinit_after_soft_reset:
41709 }
41710
41711 /* make sure the board interrupts are off */
41712- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41713+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41714
41715 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
41716 goto clean2;
41717@@ -4857,7 +4857,7 @@ reinit_after_soft_reset:
41718 * fake ones to scoop up any residual completions.
41719 */
41720 spin_lock_irqsave(&h->lock, flags);
41721- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41722+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41723 spin_unlock_irqrestore(&h->lock, flags);
41724 free_irqs(h);
41725 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
41726@@ -4876,9 +4876,9 @@ reinit_after_soft_reset:
41727 dev_info(&h->pdev->dev, "Board READY.\n");
41728 dev_info(&h->pdev->dev,
41729 "Waiting for stale completions to drain.\n");
41730- h->access.set_intr_mask(h, HPSA_INTR_ON);
41731+ h->access->set_intr_mask(h, HPSA_INTR_ON);
41732 msleep(10000);
41733- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41734+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41735
41736 rc = controller_reset_failed(h->cfgtable);
41737 if (rc)
41738@@ -4899,7 +4899,7 @@ reinit_after_soft_reset:
41739 }
41740
41741 /* Turn the interrupts on so we can service requests */
41742- h->access.set_intr_mask(h, HPSA_INTR_ON);
41743+ h->access->set_intr_mask(h, HPSA_INTR_ON);
41744
41745 hpsa_hba_inquiry(h);
41746 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
41747@@ -4954,7 +4954,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
41748 * To write all data in the battery backed cache to disks
41749 */
41750 hpsa_flush_cache(h);
41751- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41752+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41753 hpsa_free_irqs_and_disable_msix(h);
41754 }
41755
41756@@ -5122,7 +5122,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
41757 return;
41758 }
41759 /* Change the access methods to the performant access methods */
41760- h->access = SA5_performant_access;
41761+ h->access = &SA5_performant_access;
41762 h->transMethod = CFGTBL_Trans_Performant;
41763 }
41764
41765diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
41766index 9816479..c5d4e97 100644
41767--- a/drivers/scsi/hpsa.h
41768+++ b/drivers/scsi/hpsa.h
41769@@ -79,7 +79,7 @@ struct ctlr_info {
41770 unsigned int msix_vector;
41771 unsigned int msi_vector;
41772 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
41773- struct access_method access;
41774+ struct access_method *access;
41775
41776 /* queue and queue Info */
41777 struct list_head reqQ;
41778diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
41779index c772d8d..35c362c 100644
41780--- a/drivers/scsi/libfc/fc_exch.c
41781+++ b/drivers/scsi/libfc/fc_exch.c
41782@@ -100,12 +100,12 @@ struct fc_exch_mgr {
41783 u16 pool_max_index;
41784
41785 struct {
41786- atomic_t no_free_exch;
41787- atomic_t no_free_exch_xid;
41788- atomic_t xid_not_found;
41789- atomic_t xid_busy;
41790- atomic_t seq_not_found;
41791- atomic_t non_bls_resp;
41792+ atomic_unchecked_t no_free_exch;
41793+ atomic_unchecked_t no_free_exch_xid;
41794+ atomic_unchecked_t xid_not_found;
41795+ atomic_unchecked_t xid_busy;
41796+ atomic_unchecked_t seq_not_found;
41797+ atomic_unchecked_t non_bls_resp;
41798 } stats;
41799 };
41800
41801@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
41802 /* allocate memory for exchange */
41803 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
41804 if (!ep) {
41805- atomic_inc(&mp->stats.no_free_exch);
41806+ atomic_inc_unchecked(&mp->stats.no_free_exch);
41807 goto out;
41808 }
41809 memset(ep, 0, sizeof(*ep));
41810@@ -786,7 +786,7 @@ out:
41811 return ep;
41812 err:
41813 spin_unlock_bh(&pool->lock);
41814- atomic_inc(&mp->stats.no_free_exch_xid);
41815+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
41816 mempool_free(ep, mp->ep_pool);
41817 return NULL;
41818 }
41819@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41820 xid = ntohs(fh->fh_ox_id); /* we originated exch */
41821 ep = fc_exch_find(mp, xid);
41822 if (!ep) {
41823- atomic_inc(&mp->stats.xid_not_found);
41824+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41825 reject = FC_RJT_OX_ID;
41826 goto out;
41827 }
41828@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41829 ep = fc_exch_find(mp, xid);
41830 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
41831 if (ep) {
41832- atomic_inc(&mp->stats.xid_busy);
41833+ atomic_inc_unchecked(&mp->stats.xid_busy);
41834 reject = FC_RJT_RX_ID;
41835 goto rel;
41836 }
41837@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41838 }
41839 xid = ep->xid; /* get our XID */
41840 } else if (!ep) {
41841- atomic_inc(&mp->stats.xid_not_found);
41842+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41843 reject = FC_RJT_RX_ID; /* XID not found */
41844 goto out;
41845 }
41846@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41847 } else {
41848 sp = &ep->seq;
41849 if (sp->id != fh->fh_seq_id) {
41850- atomic_inc(&mp->stats.seq_not_found);
41851+ atomic_inc_unchecked(&mp->stats.seq_not_found);
41852 if (f_ctl & FC_FC_END_SEQ) {
41853 /*
41854 * Update sequence_id based on incoming last
41855@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41856
41857 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
41858 if (!ep) {
41859- atomic_inc(&mp->stats.xid_not_found);
41860+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41861 goto out;
41862 }
41863 if (ep->esb_stat & ESB_ST_COMPLETE) {
41864- atomic_inc(&mp->stats.xid_not_found);
41865+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41866 goto rel;
41867 }
41868 if (ep->rxid == FC_XID_UNKNOWN)
41869 ep->rxid = ntohs(fh->fh_rx_id);
41870 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
41871- atomic_inc(&mp->stats.xid_not_found);
41872+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41873 goto rel;
41874 }
41875 if (ep->did != ntoh24(fh->fh_s_id) &&
41876 ep->did != FC_FID_FLOGI) {
41877- atomic_inc(&mp->stats.xid_not_found);
41878+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41879 goto rel;
41880 }
41881 sof = fr_sof(fp);
41882@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41883 sp->ssb_stat |= SSB_ST_RESP;
41884 sp->id = fh->fh_seq_id;
41885 } else if (sp->id != fh->fh_seq_id) {
41886- atomic_inc(&mp->stats.seq_not_found);
41887+ atomic_inc_unchecked(&mp->stats.seq_not_found);
41888 goto rel;
41889 }
41890
41891@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41892 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
41893
41894 if (!sp)
41895- atomic_inc(&mp->stats.xid_not_found);
41896+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41897 else
41898- atomic_inc(&mp->stats.non_bls_resp);
41899+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
41900
41901 fc_frame_free(fp);
41902 }
41903@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
41904
41905 list_for_each_entry(ema, &lport->ema_list, ema_list) {
41906 mp = ema->mp;
41907- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
41908+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
41909 st->fc_no_free_exch_xid +=
41910- atomic_read(&mp->stats.no_free_exch_xid);
41911- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
41912- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
41913- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
41914- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
41915+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
41916+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
41917+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
41918+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
41919+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
41920 }
41921 }
41922 EXPORT_SYMBOL(fc_exch_update_stats);
41923diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
41924index bdb81cd..d3c7c2c 100644
41925--- a/drivers/scsi/libsas/sas_ata.c
41926+++ b/drivers/scsi/libsas/sas_ata.c
41927@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
41928 .postreset = ata_std_postreset,
41929 .error_handler = ata_std_error_handler,
41930 .post_internal_cmd = sas_ata_post_internal,
41931- .qc_defer = ata_std_qc_defer,
41932+ .qc_defer = ata_std_qc_defer,
41933 .qc_prep = ata_noop_qc_prep,
41934 .qc_issue = sas_ata_qc_issue,
41935 .qc_fill_rtf = sas_ata_qc_fill_rtf,
41936diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
41937index 7706c99..3b4fc0c 100644
41938--- a/drivers/scsi/lpfc/lpfc.h
41939+++ b/drivers/scsi/lpfc/lpfc.h
41940@@ -424,7 +424,7 @@ struct lpfc_vport {
41941 struct dentry *debug_nodelist;
41942 struct dentry *vport_debugfs_root;
41943 struct lpfc_debugfs_trc *disc_trc;
41944- atomic_t disc_trc_cnt;
41945+ atomic_unchecked_t disc_trc_cnt;
41946 #endif
41947 uint8_t stat_data_enabled;
41948 uint8_t stat_data_blocked;
41949@@ -853,8 +853,8 @@ struct lpfc_hba {
41950 struct timer_list fabric_block_timer;
41951 unsigned long bit_flags;
41952 #define FABRIC_COMANDS_BLOCKED 0
41953- atomic_t num_rsrc_err;
41954- atomic_t num_cmd_success;
41955+ atomic_unchecked_t num_rsrc_err;
41956+ atomic_unchecked_t num_cmd_success;
41957 unsigned long last_rsrc_error_time;
41958 unsigned long last_ramp_down_time;
41959 unsigned long last_ramp_up_time;
41960@@ -890,7 +890,7 @@ struct lpfc_hba {
41961
41962 struct dentry *debug_slow_ring_trc;
41963 struct lpfc_debugfs_trc *slow_ring_trc;
41964- atomic_t slow_ring_trc_cnt;
41965+ atomic_unchecked_t slow_ring_trc_cnt;
41966 /* iDiag debugfs sub-directory */
41967 struct dentry *idiag_root;
41968 struct dentry *idiag_pci_cfg;
41969diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
41970index f63f5ff..de29189 100644
41971--- a/drivers/scsi/lpfc/lpfc_debugfs.c
41972+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
41973@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
41974
41975 #include <linux/debugfs.h>
41976
41977-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
41978+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
41979 static unsigned long lpfc_debugfs_start_time = 0L;
41980
41981 /* iDiag */
41982@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
41983 lpfc_debugfs_enable = 0;
41984
41985 len = 0;
41986- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
41987+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
41988 (lpfc_debugfs_max_disc_trc - 1);
41989 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
41990 dtp = vport->disc_trc + i;
41991@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
41992 lpfc_debugfs_enable = 0;
41993
41994 len = 0;
41995- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
41996+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
41997 (lpfc_debugfs_max_slow_ring_trc - 1);
41998 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
41999 dtp = phba->slow_ring_trc + i;
42000@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
42001 !vport || !vport->disc_trc)
42002 return;
42003
42004- index = atomic_inc_return(&vport->disc_trc_cnt) &
42005+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
42006 (lpfc_debugfs_max_disc_trc - 1);
42007 dtp = vport->disc_trc + index;
42008 dtp->fmt = fmt;
42009 dtp->data1 = data1;
42010 dtp->data2 = data2;
42011 dtp->data3 = data3;
42012- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42013+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42014 dtp->jif = jiffies;
42015 #endif
42016 return;
42017@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
42018 !phba || !phba->slow_ring_trc)
42019 return;
42020
42021- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
42022+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
42023 (lpfc_debugfs_max_slow_ring_trc - 1);
42024 dtp = phba->slow_ring_trc + index;
42025 dtp->fmt = fmt;
42026 dtp->data1 = data1;
42027 dtp->data2 = data2;
42028 dtp->data3 = data3;
42029- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42030+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42031 dtp->jif = jiffies;
42032 #endif
42033 return;
42034@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42035 "slow_ring buffer\n");
42036 goto debug_failed;
42037 }
42038- atomic_set(&phba->slow_ring_trc_cnt, 0);
42039+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
42040 memset(phba->slow_ring_trc, 0,
42041 (sizeof(struct lpfc_debugfs_trc) *
42042 lpfc_debugfs_max_slow_ring_trc));
42043@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42044 "buffer\n");
42045 goto debug_failed;
42046 }
42047- atomic_set(&vport->disc_trc_cnt, 0);
42048+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
42049
42050 snprintf(name, sizeof(name), "discovery_trace");
42051 vport->debug_disc_trc =
42052diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
42053index 314b4f6..7005d10 100644
42054--- a/drivers/scsi/lpfc/lpfc_init.c
42055+++ b/drivers/scsi/lpfc/lpfc_init.c
42056@@ -10551,8 +10551,10 @@ lpfc_init(void)
42057 "misc_register returned with status %d", error);
42058
42059 if (lpfc_enable_npiv) {
42060- lpfc_transport_functions.vport_create = lpfc_vport_create;
42061- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42062+ pax_open_kernel();
42063+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
42064+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42065+ pax_close_kernel();
42066 }
42067 lpfc_transport_template =
42068 fc_attach_transport(&lpfc_transport_functions);
42069diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
42070index 98af07c..7625fb5 100644
42071--- a/drivers/scsi/lpfc/lpfc_scsi.c
42072+++ b/drivers/scsi/lpfc/lpfc_scsi.c
42073@@ -325,7 +325,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
42074 uint32_t evt_posted;
42075
42076 spin_lock_irqsave(&phba->hbalock, flags);
42077- atomic_inc(&phba->num_rsrc_err);
42078+ atomic_inc_unchecked(&phba->num_rsrc_err);
42079 phba->last_rsrc_error_time = jiffies;
42080
42081 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
42082@@ -366,7 +366,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
42083 unsigned long flags;
42084 struct lpfc_hba *phba = vport->phba;
42085 uint32_t evt_posted;
42086- atomic_inc(&phba->num_cmd_success);
42087+ atomic_inc_unchecked(&phba->num_cmd_success);
42088
42089 if (vport->cfg_lun_queue_depth <= queue_depth)
42090 return;
42091@@ -410,8 +410,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42092 unsigned long num_rsrc_err, num_cmd_success;
42093 int i;
42094
42095- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
42096- num_cmd_success = atomic_read(&phba->num_cmd_success);
42097+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
42098+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
42099
42100 /*
42101 * The error and success command counters are global per
42102@@ -439,8 +439,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42103 }
42104 }
42105 lpfc_destroy_vport_work_array(phba, vports);
42106- atomic_set(&phba->num_rsrc_err, 0);
42107- atomic_set(&phba->num_cmd_success, 0);
42108+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42109+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42110 }
42111
42112 /**
42113@@ -474,8 +474,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
42114 }
42115 }
42116 lpfc_destroy_vport_work_array(phba, vports);
42117- atomic_set(&phba->num_rsrc_err, 0);
42118- atomic_set(&phba->num_cmd_success, 0);
42119+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42120+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42121 }
42122
42123 /**
42124diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
42125index b46f5e9..c4c4ccb 100644
42126--- a/drivers/scsi/pmcraid.c
42127+++ b/drivers/scsi/pmcraid.c
42128@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
42129 res->scsi_dev = scsi_dev;
42130 scsi_dev->hostdata = res;
42131 res->change_detected = 0;
42132- atomic_set(&res->read_failures, 0);
42133- atomic_set(&res->write_failures, 0);
42134+ atomic_set_unchecked(&res->read_failures, 0);
42135+ atomic_set_unchecked(&res->write_failures, 0);
42136 rc = 0;
42137 }
42138 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
42139@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
42140
42141 /* If this was a SCSI read/write command keep count of errors */
42142 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
42143- atomic_inc(&res->read_failures);
42144+ atomic_inc_unchecked(&res->read_failures);
42145 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
42146- atomic_inc(&res->write_failures);
42147+ atomic_inc_unchecked(&res->write_failures);
42148
42149 if (!RES_IS_GSCSI(res->cfg_entry) &&
42150 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
42151@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
42152 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
42153 * hrrq_id assigned here in queuecommand
42154 */
42155- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
42156+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
42157 pinstance->num_hrrq;
42158 cmd->cmd_done = pmcraid_io_done;
42159
42160@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
42161 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
42162 * hrrq_id assigned here in queuecommand
42163 */
42164- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
42165+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
42166 pinstance->num_hrrq;
42167
42168 if (request_size) {
42169@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
42170
42171 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
42172 /* add resources only after host is added into system */
42173- if (!atomic_read(&pinstance->expose_resources))
42174+ if (!atomic_read_unchecked(&pinstance->expose_resources))
42175 return;
42176
42177 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
42178@@ -5324,8 +5324,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
42179 init_waitqueue_head(&pinstance->reset_wait_q);
42180
42181 atomic_set(&pinstance->outstanding_cmds, 0);
42182- atomic_set(&pinstance->last_message_id, 0);
42183- atomic_set(&pinstance->expose_resources, 0);
42184+ atomic_set_unchecked(&pinstance->last_message_id, 0);
42185+ atomic_set_unchecked(&pinstance->expose_resources, 0);
42186
42187 INIT_LIST_HEAD(&pinstance->free_res_q);
42188 INIT_LIST_HEAD(&pinstance->used_res_q);
42189@@ -6038,7 +6038,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
42190 /* Schedule worker thread to handle CCN and take care of adding and
42191 * removing devices to OS
42192 */
42193- atomic_set(&pinstance->expose_resources, 1);
42194+ atomic_set_unchecked(&pinstance->expose_resources, 1);
42195 schedule_work(&pinstance->worker_q);
42196 return rc;
42197
42198diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
42199index e1d150f..6c6df44 100644
42200--- a/drivers/scsi/pmcraid.h
42201+++ b/drivers/scsi/pmcraid.h
42202@@ -748,7 +748,7 @@ struct pmcraid_instance {
42203 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
42204
42205 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
42206- atomic_t last_message_id;
42207+ atomic_unchecked_t last_message_id;
42208
42209 /* configuration table */
42210 struct pmcraid_config_table *cfg_table;
42211@@ -777,7 +777,7 @@ struct pmcraid_instance {
42212 atomic_t outstanding_cmds;
42213
42214 /* should add/delete resources to mid-layer now ?*/
42215- atomic_t expose_resources;
42216+ atomic_unchecked_t expose_resources;
42217
42218
42219
42220@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
42221 struct pmcraid_config_table_entry_ext cfg_entry_ext;
42222 };
42223 struct scsi_device *scsi_dev; /* Link scsi_device structure */
42224- atomic_t read_failures; /* count of failed READ commands */
42225- atomic_t write_failures; /* count of failed WRITE commands */
42226+ atomic_unchecked_t read_failures; /* count of failed READ commands */
42227+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
42228
42229 /* To indicate add/delete/modify during CCN */
42230 u8 change_detected;
42231diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
42232index b3db9dc..c3b1756 100644
42233--- a/drivers/scsi/qla2xxx/qla_attr.c
42234+++ b/drivers/scsi/qla2xxx/qla_attr.c
42235@@ -1971,7 +1971,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
42236 return 0;
42237 }
42238
42239-struct fc_function_template qla2xxx_transport_functions = {
42240+fc_function_template_no_const qla2xxx_transport_functions = {
42241
42242 .show_host_node_name = 1,
42243 .show_host_port_name = 1,
42244@@ -2018,7 +2018,7 @@ struct fc_function_template qla2xxx_transport_functions = {
42245 .bsg_timeout = qla24xx_bsg_timeout,
42246 };
42247
42248-struct fc_function_template qla2xxx_transport_vport_functions = {
42249+fc_function_template_no_const qla2xxx_transport_vport_functions = {
42250
42251 .show_host_node_name = 1,
42252 .show_host_port_name = 1,
42253diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
42254index b310fa9..b9b3944 100644
42255--- a/drivers/scsi/qla2xxx/qla_gbl.h
42256+++ b/drivers/scsi/qla2xxx/qla_gbl.h
42257@@ -523,8 +523,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
42258 struct device_attribute;
42259 extern struct device_attribute *qla2x00_host_attrs[];
42260 struct fc_function_template;
42261-extern struct fc_function_template qla2xxx_transport_functions;
42262-extern struct fc_function_template qla2xxx_transport_vport_functions;
42263+extern fc_function_template_no_const qla2xxx_transport_functions;
42264+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
42265 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
42266 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
42267 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
42268diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
42269index 2c6dd3d..e5ecd82 100644
42270--- a/drivers/scsi/qla2xxx/qla_os.c
42271+++ b/drivers/scsi/qla2xxx/qla_os.c
42272@@ -1554,8 +1554,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
42273 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
42274 /* Ok, a 64bit DMA mask is applicable. */
42275 ha->flags.enable_64bit_addressing = 1;
42276- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
42277- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
42278+ pax_open_kernel();
42279+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
42280+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
42281+ pax_close_kernel();
42282 return;
42283 }
42284 }
42285diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
42286index 129f5dd..ade53e8 100644
42287--- a/drivers/scsi/qla4xxx/ql4_def.h
42288+++ b/drivers/scsi/qla4xxx/ql4_def.h
42289@@ -275,7 +275,7 @@ struct ddb_entry {
42290 * (4000 only) */
42291 atomic_t relogin_timer; /* Max Time to wait for
42292 * relogin to complete */
42293- atomic_t relogin_retry_count; /* Num of times relogin has been
42294+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
42295 * retried */
42296 uint32_t default_time2wait; /* Default Min time between
42297 * relogins (+aens) */
42298diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
42299index 6142729..b6a85c9 100644
42300--- a/drivers/scsi/qla4xxx/ql4_os.c
42301+++ b/drivers/scsi/qla4xxx/ql4_os.c
42302@@ -2622,12 +2622,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
42303 */
42304 if (!iscsi_is_session_online(cls_sess)) {
42305 /* Reset retry relogin timer */
42306- atomic_inc(&ddb_entry->relogin_retry_count);
42307+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
42308 DEBUG2(ql4_printk(KERN_INFO, ha,
42309 "%s: index[%d] relogin timed out-retrying"
42310 " relogin (%d), retry (%d)\n", __func__,
42311 ddb_entry->fw_ddb_index,
42312- atomic_read(&ddb_entry->relogin_retry_count),
42313+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
42314 ddb_entry->default_time2wait + 4));
42315 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
42316 atomic_set(&ddb_entry->retry_relogin_timer,
42317@@ -4742,7 +4742,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
42318
42319 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
42320 atomic_set(&ddb_entry->relogin_timer, 0);
42321- atomic_set(&ddb_entry->relogin_retry_count, 0);
42322+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
42323 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
42324 ddb_entry->default_relogin_timeout =
42325 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
42326diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
42327index 2c0d0ec..4e8681a 100644
42328--- a/drivers/scsi/scsi.c
42329+++ b/drivers/scsi/scsi.c
42330@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
42331 unsigned long timeout;
42332 int rtn = 0;
42333
42334- atomic_inc(&cmd->device->iorequest_cnt);
42335+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
42336
42337 /* check if the device is still usable */
42338 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
42339diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
42340index c31187d..0ead8c3 100644
42341--- a/drivers/scsi/scsi_lib.c
42342+++ b/drivers/scsi/scsi_lib.c
42343@@ -1459,7 +1459,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
42344 shost = sdev->host;
42345 scsi_init_cmd_errh(cmd);
42346 cmd->result = DID_NO_CONNECT << 16;
42347- atomic_inc(&cmd->device->iorequest_cnt);
42348+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
42349
42350 /*
42351 * SCSI request completion path will do scsi_device_unbusy(),
42352@@ -1485,9 +1485,9 @@ static void scsi_softirq_done(struct request *rq)
42353
42354 INIT_LIST_HEAD(&cmd->eh_entry);
42355
42356- atomic_inc(&cmd->device->iodone_cnt);
42357+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
42358 if (cmd->result)
42359- atomic_inc(&cmd->device->ioerr_cnt);
42360+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
42361
42362 disposition = scsi_decide_disposition(cmd);
42363 if (disposition != SUCCESS &&
42364diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
42365index 931a7d9..0c2a754 100644
42366--- a/drivers/scsi/scsi_sysfs.c
42367+++ b/drivers/scsi/scsi_sysfs.c
42368@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
42369 char *buf) \
42370 { \
42371 struct scsi_device *sdev = to_scsi_device(dev); \
42372- unsigned long long count = atomic_read(&sdev->field); \
42373+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
42374 return snprintf(buf, 20, "0x%llx\n", count); \
42375 } \
42376 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
42377diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
42378index 84a1fdf..693b0d6 100644
42379--- a/drivers/scsi/scsi_tgt_lib.c
42380+++ b/drivers/scsi/scsi_tgt_lib.c
42381@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
42382 int err;
42383
42384 dprintk("%lx %u\n", uaddr, len);
42385- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
42386+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
42387 if (err) {
42388 /*
42389 * TODO: need to fixup sg_tablesize, max_segment_size,
42390diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
42391index e894ca7..de9d7660 100644
42392--- a/drivers/scsi/scsi_transport_fc.c
42393+++ b/drivers/scsi/scsi_transport_fc.c
42394@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
42395 * Netlink Infrastructure
42396 */
42397
42398-static atomic_t fc_event_seq;
42399+static atomic_unchecked_t fc_event_seq;
42400
42401 /**
42402 * fc_get_event_number - Obtain the next sequential FC event number
42403@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
42404 u32
42405 fc_get_event_number(void)
42406 {
42407- return atomic_add_return(1, &fc_event_seq);
42408+ return atomic_add_return_unchecked(1, &fc_event_seq);
42409 }
42410 EXPORT_SYMBOL(fc_get_event_number);
42411
42412@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
42413 {
42414 int error;
42415
42416- atomic_set(&fc_event_seq, 0);
42417+ atomic_set_unchecked(&fc_event_seq, 0);
42418
42419 error = transport_class_register(&fc_host_class);
42420 if (error)
42421@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
42422 char *cp;
42423
42424 *val = simple_strtoul(buf, &cp, 0);
42425- if ((*cp && (*cp != '\n')) || (*val < 0))
42426+ if (*cp && (*cp != '\n'))
42427 return -EINVAL;
42428 /*
42429 * Check for overflow; dev_loss_tmo is u32
42430diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
42431index 0a74b97..fa8d648 100644
42432--- a/drivers/scsi/scsi_transport_iscsi.c
42433+++ b/drivers/scsi/scsi_transport_iscsi.c
42434@@ -79,7 +79,7 @@ struct iscsi_internal {
42435 struct transport_container session_cont;
42436 };
42437
42438-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
42439+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
42440 static struct workqueue_struct *iscsi_eh_timer_workq;
42441
42442 static DEFINE_IDA(iscsi_sess_ida);
42443@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
42444 int err;
42445
42446 ihost = shost->shost_data;
42447- session->sid = atomic_add_return(1, &iscsi_session_nr);
42448+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
42449
42450 if (target_id == ISCSI_MAX_TARGET) {
42451 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
42452@@ -2955,7 +2955,7 @@ static __init int iscsi_transport_init(void)
42453 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
42454 ISCSI_TRANSPORT_VERSION);
42455
42456- atomic_set(&iscsi_session_nr, 0);
42457+ atomic_set_unchecked(&iscsi_session_nr, 0);
42458
42459 err = class_register(&iscsi_transport_class);
42460 if (err)
42461diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
42462index f379c7f..e8fc69c 100644
42463--- a/drivers/scsi/scsi_transport_srp.c
42464+++ b/drivers/scsi/scsi_transport_srp.c
42465@@ -33,7 +33,7 @@
42466 #include "scsi_transport_srp_internal.h"
42467
42468 struct srp_host_attrs {
42469- atomic_t next_port_id;
42470+ atomic_unchecked_t next_port_id;
42471 };
42472 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
42473
42474@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
42475 struct Scsi_Host *shost = dev_to_shost(dev);
42476 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
42477
42478- atomic_set(&srp_host->next_port_id, 0);
42479+ atomic_set_unchecked(&srp_host->next_port_id, 0);
42480 return 0;
42481 }
42482
42483@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
42484 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
42485 rport->roles = ids->roles;
42486
42487- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
42488+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
42489 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
42490
42491 transport_setup_device(&rport->dev);
42492diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
42493index 82910cc..7c350ad 100644
42494--- a/drivers/scsi/sd.c
42495+++ b/drivers/scsi/sd.c
42496@@ -2929,7 +2929,7 @@ static int sd_probe(struct device *dev)
42497 sdkp->disk = gd;
42498 sdkp->index = index;
42499 atomic_set(&sdkp->openers, 0);
42500- atomic_set(&sdkp->device->ioerr_cnt, 0);
42501+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
42502
42503 if (!sdp->request_queue->rq_timeout) {
42504 if (sdp->type != TYPE_MOD)
42505diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
42506index 9f0c465..47194ee 100644
42507--- a/drivers/scsi/sg.c
42508+++ b/drivers/scsi/sg.c
42509@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
42510 sdp->disk->disk_name,
42511 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
42512 NULL,
42513- (char *)arg);
42514+ (char __user *)arg);
42515 case BLKTRACESTART:
42516 return blk_trace_startstop(sdp->device->request_queue, 1);
42517 case BLKTRACESTOP:
42518diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
42519index 004b10f..7c98d51 100644
42520--- a/drivers/spi/spi.c
42521+++ b/drivers/spi/spi.c
42522@@ -1620,7 +1620,7 @@ int spi_bus_unlock(struct spi_master *master)
42523 EXPORT_SYMBOL_GPL(spi_bus_unlock);
42524
42525 /* portable code must never pass more than 32 bytes */
42526-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
42527+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
42528
42529 static u8 *buf;
42530
42531diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c
42532index 93af756..a4bc5bf 100644
42533--- a/drivers/staging/iio/iio_hwmon.c
42534+++ b/drivers/staging/iio/iio_hwmon.c
42535@@ -67,7 +67,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
42536 {
42537 struct device *dev = &pdev->dev;
42538 struct iio_hwmon_state *st;
42539- struct sensor_device_attribute *a;
42540+ sensor_device_attribute_no_const *a;
42541 int ret, i;
42542 int in_i = 1, temp_i = 1, curr_i = 1;
42543 enum iio_chan_type type;
42544diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
42545index 34afc16..ffe44dd 100644
42546--- a/drivers/staging/octeon/ethernet-rx.c
42547+++ b/drivers/staging/octeon/ethernet-rx.c
42548@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
42549 /* Increment RX stats for virtual ports */
42550 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
42551 #ifdef CONFIG_64BIT
42552- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
42553- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
42554+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
42555+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
42556 #else
42557- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
42558- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
42559+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
42560+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
42561 #endif
42562 }
42563 netif_receive_skb(skb);
42564@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
42565 dev->name);
42566 */
42567 #ifdef CONFIG_64BIT
42568- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
42569+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
42570 #else
42571- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
42572+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
42573 #endif
42574 dev_kfree_skb_irq(skb);
42575 }
42576diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
42577index c3a90e7..023619a 100644
42578--- a/drivers/staging/octeon/ethernet.c
42579+++ b/drivers/staging/octeon/ethernet.c
42580@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
42581 * since the RX tasklet also increments it.
42582 */
42583 #ifdef CONFIG_64BIT
42584- atomic64_add(rx_status.dropped_packets,
42585- (atomic64_t *)&priv->stats.rx_dropped);
42586+ atomic64_add_unchecked(rx_status.dropped_packets,
42587+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
42588 #else
42589- atomic_add(rx_status.dropped_packets,
42590- (atomic_t *)&priv->stats.rx_dropped);
42591+ atomic_add_unchecked(rx_status.dropped_packets,
42592+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
42593 #endif
42594 }
42595
42596diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
42597index dc23395..cf7e9b1 100644
42598--- a/drivers/staging/rtl8712/rtl871x_io.h
42599+++ b/drivers/staging/rtl8712/rtl871x_io.h
42600@@ -108,7 +108,7 @@ struct _io_ops {
42601 u8 *pmem);
42602 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
42603 u8 *pmem);
42604-};
42605+} __no_const;
42606
42607 struct io_req {
42608 struct list_head list;
42609diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
42610index 1f5088b..0e59820 100644
42611--- a/drivers/staging/sbe-2t3e3/netdev.c
42612+++ b/drivers/staging/sbe-2t3e3/netdev.c
42613@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
42614 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
42615
42616 if (rlen)
42617- if (copy_to_user(data, &resp, rlen))
42618+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
42619 return -EFAULT;
42620
42621 return 0;
42622diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
42623index 5dddc4d..34fcb2f 100644
42624--- a/drivers/staging/usbip/vhci.h
42625+++ b/drivers/staging/usbip/vhci.h
42626@@ -83,7 +83,7 @@ struct vhci_hcd {
42627 unsigned resuming:1;
42628 unsigned long re_timeout;
42629
42630- atomic_t seqnum;
42631+ atomic_unchecked_t seqnum;
42632
42633 /*
42634 * NOTE:
42635diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
42636index f1ca084..7b5c0c3 100644
42637--- a/drivers/staging/usbip/vhci_hcd.c
42638+++ b/drivers/staging/usbip/vhci_hcd.c
42639@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
42640
42641 spin_lock(&vdev->priv_lock);
42642
42643- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
42644+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42645 if (priv->seqnum == 0xffff)
42646 dev_info(&urb->dev->dev, "seqnum max\n");
42647
42648@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
42649 return -ENOMEM;
42650 }
42651
42652- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
42653+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42654 if (unlink->seqnum == 0xffff)
42655 pr_info("seqnum max\n");
42656
42657@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
42658 vdev->rhport = rhport;
42659 }
42660
42661- atomic_set(&vhci->seqnum, 0);
42662+ atomic_set_unchecked(&vhci->seqnum, 0);
42663 spin_lock_init(&vhci->lock);
42664
42665 hcd->power_budget = 0; /* no limit */
42666diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
42667index faf8e60..c46f8ab 100644
42668--- a/drivers/staging/usbip/vhci_rx.c
42669+++ b/drivers/staging/usbip/vhci_rx.c
42670@@ -76,7 +76,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
42671 if (!urb) {
42672 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
42673 pr_info("max seqnum %d\n",
42674- atomic_read(&the_controller->seqnum));
42675+ atomic_read_unchecked(&the_controller->seqnum));
42676 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
42677 return;
42678 }
42679diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
42680index 5f13890..36a044b 100644
42681--- a/drivers/staging/vt6655/hostap.c
42682+++ b/drivers/staging/vt6655/hostap.c
42683@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
42684 *
42685 */
42686
42687+static net_device_ops_no_const apdev_netdev_ops;
42688+
42689 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42690 {
42691 PSDevice apdev_priv;
42692 struct net_device *dev = pDevice->dev;
42693 int ret;
42694- const struct net_device_ops apdev_netdev_ops = {
42695- .ndo_start_xmit = pDevice->tx_80211,
42696- };
42697
42698 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
42699
42700@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42701 *apdev_priv = *pDevice;
42702 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
42703
42704+ /* only half broken now */
42705+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
42706 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
42707
42708 pDevice->apdev->type = ARPHRD_IEEE80211;
42709diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
42710index a94e66f..31984d0 100644
42711--- a/drivers/staging/vt6656/hostap.c
42712+++ b/drivers/staging/vt6656/hostap.c
42713@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
42714 *
42715 */
42716
42717+static net_device_ops_no_const apdev_netdev_ops;
42718+
42719 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
42720 {
42721 struct vnt_private *apdev_priv;
42722 struct net_device *dev = pDevice->dev;
42723 int ret;
42724- const struct net_device_ops apdev_netdev_ops = {
42725- .ndo_start_xmit = pDevice->tx_80211,
42726- };
42727
42728 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
42729
42730@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
42731 *apdev_priv = *pDevice;
42732 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
42733
42734+ /* only half broken now */
42735+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
42736 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
42737
42738 pDevice->apdev->type = ARPHRD_IEEE80211;
42739diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
42740index a2b7e03..9ff4bbd 100644
42741--- a/drivers/staging/zcache/tmem.c
42742+++ b/drivers/staging/zcache/tmem.c
42743@@ -50,7 +50,7 @@
42744 * A tmem host implementation must use this function to register callbacks
42745 * for memory allocation.
42746 */
42747-static struct tmem_hostops tmem_hostops;
42748+static tmem_hostops_no_const tmem_hostops;
42749
42750 static void tmem_objnode_tree_init(void);
42751
42752@@ -64,7 +64,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
42753 * A tmem host implementation must use this function to register
42754 * callbacks for a page-accessible memory (PAM) implementation.
42755 */
42756-static struct tmem_pamops tmem_pamops;
42757+static tmem_pamops_no_const tmem_pamops;
42758
42759 void tmem_register_pamops(struct tmem_pamops *m)
42760 {
42761diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
42762index adbe5a8..d387359 100644
42763--- a/drivers/staging/zcache/tmem.h
42764+++ b/drivers/staging/zcache/tmem.h
42765@@ -226,6 +226,7 @@ struct tmem_pamops {
42766 int (*replace_in_obj)(void *, struct tmem_obj *);
42767 #endif
42768 };
42769+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
42770 extern void tmem_register_pamops(struct tmem_pamops *m);
42771
42772 /* memory allocation methods provided by the host implementation */
42773@@ -235,6 +236,7 @@ struct tmem_hostops {
42774 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
42775 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
42776 };
42777+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
42778 extern void tmem_register_hostops(struct tmem_hostops *m);
42779
42780 /* core tmem accessor functions */
42781diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
42782index 2e4d655..fd72e68 100644
42783--- a/drivers/target/target_core_device.c
42784+++ b/drivers/target/target_core_device.c
42785@@ -1414,7 +1414,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
42786 spin_lock_init(&dev->se_port_lock);
42787 spin_lock_init(&dev->se_tmr_lock);
42788 spin_lock_init(&dev->qf_cmd_lock);
42789- atomic_set(&dev->dev_ordered_id, 0);
42790+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
42791 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
42792 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
42793 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
42794diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
42795index fc9a5a0..1d5975e 100644
42796--- a/drivers/target/target_core_transport.c
42797+++ b/drivers/target/target_core_transport.c
42798@@ -1081,7 +1081,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
42799 * Used to determine when ORDERED commands should go from
42800 * Dormant to Active status.
42801 */
42802- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
42803+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
42804 smp_mb__after_atomic_inc();
42805 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
42806 cmd->se_ordered_id, cmd->sam_task_attr,
42807diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
42808index 345bd0e..61d5375 100644
42809--- a/drivers/tty/cyclades.c
42810+++ b/drivers/tty/cyclades.c
42811@@ -1576,10 +1576,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
42812 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
42813 info->port.count);
42814 #endif
42815- info->port.count++;
42816+ atomic_inc(&info->port.count);
42817 #ifdef CY_DEBUG_COUNT
42818 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
42819- current->pid, info->port.count);
42820+ current->pid, atomic_read(&info->port.count));
42821 #endif
42822
42823 /*
42824@@ -3978,7 +3978,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
42825 for (j = 0; j < cy_card[i].nports; j++) {
42826 info = &cy_card[i].ports[j];
42827
42828- if (info->port.count) {
42829+ if (atomic_read(&info->port.count)) {
42830 /* XXX is the ldisc num worth this? */
42831 struct tty_struct *tty;
42832 struct tty_ldisc *ld;
42833diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
42834index eb255e8..f637a57 100644
42835--- a/drivers/tty/hvc/hvc_console.c
42836+++ b/drivers/tty/hvc/hvc_console.c
42837@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
42838
42839 spin_lock_irqsave(&hp->port.lock, flags);
42840 /* Check and then increment for fast path open. */
42841- if (hp->port.count++ > 0) {
42842+ if (atomic_inc_return(&hp->port.count) > 1) {
42843 spin_unlock_irqrestore(&hp->port.lock, flags);
42844 hvc_kick();
42845 return 0;
42846@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
42847
42848 spin_lock_irqsave(&hp->port.lock, flags);
42849
42850- if (--hp->port.count == 0) {
42851+ if (atomic_dec_return(&hp->port.count) == 0) {
42852 spin_unlock_irqrestore(&hp->port.lock, flags);
42853 /* We are done with the tty pointer now. */
42854 tty_port_tty_set(&hp->port, NULL);
42855@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
42856 */
42857 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
42858 } else {
42859- if (hp->port.count < 0)
42860+ if (atomic_read(&hp->port.count) < 0)
42861 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
42862- hp->vtermno, hp->port.count);
42863+ hp->vtermno, atomic_read(&hp->port.count));
42864 spin_unlock_irqrestore(&hp->port.lock, flags);
42865 }
42866 }
42867@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
42868 * open->hangup case this can be called after the final close so prevent
42869 * that from happening for now.
42870 */
42871- if (hp->port.count <= 0) {
42872+ if (atomic_read(&hp->port.count) <= 0) {
42873 spin_unlock_irqrestore(&hp->port.lock, flags);
42874 return;
42875 }
42876
42877- hp->port.count = 0;
42878+ atomic_set(&hp->port.count, 0);
42879 spin_unlock_irqrestore(&hp->port.lock, flags);
42880 tty_port_tty_set(&hp->port, NULL);
42881
42882@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
42883 return -EPIPE;
42884
42885 /* FIXME what's this (unprotected) check for? */
42886- if (hp->port.count <= 0)
42887+ if (atomic_read(&hp->port.count) <= 0)
42888 return -EIO;
42889
42890 spin_lock_irqsave(&hp->lock, flags);
42891diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
42892index 81e939e..95ead10 100644
42893--- a/drivers/tty/hvc/hvcs.c
42894+++ b/drivers/tty/hvc/hvcs.c
42895@@ -83,6 +83,7 @@
42896 #include <asm/hvcserver.h>
42897 #include <asm/uaccess.h>
42898 #include <asm/vio.h>
42899+#include <asm/local.h>
42900
42901 /*
42902 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
42903@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
42904
42905 spin_lock_irqsave(&hvcsd->lock, flags);
42906
42907- if (hvcsd->port.count > 0) {
42908+ if (atomic_read(&hvcsd->port.count) > 0) {
42909 spin_unlock_irqrestore(&hvcsd->lock, flags);
42910 printk(KERN_INFO "HVCS: vterm state unchanged. "
42911 "The hvcs device node is still in use.\n");
42912@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
42913 }
42914 }
42915
42916- hvcsd->port.count = 0;
42917+ atomic_set(&hvcsd->port.count, 0);
42918 hvcsd->port.tty = tty;
42919 tty->driver_data = hvcsd;
42920
42921@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
42922 unsigned long flags;
42923
42924 spin_lock_irqsave(&hvcsd->lock, flags);
42925- hvcsd->port.count++;
42926+ atomic_inc(&hvcsd->port.count);
42927 hvcsd->todo_mask |= HVCS_SCHED_READ;
42928 spin_unlock_irqrestore(&hvcsd->lock, flags);
42929
42930@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
42931 hvcsd = tty->driver_data;
42932
42933 spin_lock_irqsave(&hvcsd->lock, flags);
42934- if (--hvcsd->port.count == 0) {
42935+ if (atomic_dec_and_test(&hvcsd->port.count)) {
42936
42937 vio_disable_interrupts(hvcsd->vdev);
42938
42939@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
42940
42941 free_irq(irq, hvcsd);
42942 return;
42943- } else if (hvcsd->port.count < 0) {
42944+ } else if (atomic_read(&hvcsd->port.count) < 0) {
42945 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
42946 " is missmanaged.\n",
42947- hvcsd->vdev->unit_address, hvcsd->port.count);
42948+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
42949 }
42950
42951 spin_unlock_irqrestore(&hvcsd->lock, flags);
42952@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
42953
42954 spin_lock_irqsave(&hvcsd->lock, flags);
42955 /* Preserve this so that we know how many kref refs to put */
42956- temp_open_count = hvcsd->port.count;
42957+ temp_open_count = atomic_read(&hvcsd->port.count);
42958
42959 /*
42960 * Don't kref put inside the spinlock because the destruction
42961@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
42962 tty->driver_data = NULL;
42963 hvcsd->port.tty = NULL;
42964
42965- hvcsd->port.count = 0;
42966+ atomic_set(&hvcsd->port.count, 0);
42967
42968 /* This will drop any buffered data on the floor which is OK in a hangup
42969 * scenario. */
42970@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
42971 * the middle of a write operation? This is a crummy place to do this
42972 * but we want to keep it all in the spinlock.
42973 */
42974- if (hvcsd->port.count <= 0) {
42975+ if (atomic_read(&hvcsd->port.count) <= 0) {
42976 spin_unlock_irqrestore(&hvcsd->lock, flags);
42977 return -ENODEV;
42978 }
42979@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
42980 {
42981 struct hvcs_struct *hvcsd = tty->driver_data;
42982
42983- if (!hvcsd || hvcsd->port.count <= 0)
42984+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
42985 return 0;
42986
42987 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
42988diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
42989index 8fd72ff..34a0bed 100644
42990--- a/drivers/tty/ipwireless/tty.c
42991+++ b/drivers/tty/ipwireless/tty.c
42992@@ -29,6 +29,7 @@
42993 #include <linux/tty_driver.h>
42994 #include <linux/tty_flip.h>
42995 #include <linux/uaccess.h>
42996+#include <asm/local.h>
42997
42998 #include "tty.h"
42999 #include "network.h"
43000@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
43001 mutex_unlock(&tty->ipw_tty_mutex);
43002 return -ENODEV;
43003 }
43004- if (tty->port.count == 0)
43005+ if (atomic_read(&tty->port.count) == 0)
43006 tty->tx_bytes_queued = 0;
43007
43008- tty->port.count++;
43009+ atomic_inc(&tty->port.count);
43010
43011 tty->port.tty = linux_tty;
43012 linux_tty->driver_data = tty;
43013@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
43014
43015 static void do_ipw_close(struct ipw_tty *tty)
43016 {
43017- tty->port.count--;
43018-
43019- if (tty->port.count == 0) {
43020+ if (atomic_dec_return(&tty->port.count) == 0) {
43021 struct tty_struct *linux_tty = tty->port.tty;
43022
43023 if (linux_tty != NULL) {
43024@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
43025 return;
43026
43027 mutex_lock(&tty->ipw_tty_mutex);
43028- if (tty->port.count == 0) {
43029+ if (atomic_read(&tty->port.count) == 0) {
43030 mutex_unlock(&tty->ipw_tty_mutex);
43031 return;
43032 }
43033@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
43034
43035 mutex_lock(&tty->ipw_tty_mutex);
43036
43037- if (!tty->port.count) {
43038+ if (!atomic_read(&tty->port.count)) {
43039 mutex_unlock(&tty->ipw_tty_mutex);
43040 return;
43041 }
43042@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
43043 return -ENODEV;
43044
43045 mutex_lock(&tty->ipw_tty_mutex);
43046- if (!tty->port.count) {
43047+ if (!atomic_read(&tty->port.count)) {
43048 mutex_unlock(&tty->ipw_tty_mutex);
43049 return -EINVAL;
43050 }
43051@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
43052 if (!tty)
43053 return -ENODEV;
43054
43055- if (!tty->port.count)
43056+ if (!atomic_read(&tty->port.count))
43057 return -EINVAL;
43058
43059 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
43060@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
43061 if (!tty)
43062 return 0;
43063
43064- if (!tty->port.count)
43065+ if (!atomic_read(&tty->port.count))
43066 return 0;
43067
43068 return tty->tx_bytes_queued;
43069@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
43070 if (!tty)
43071 return -ENODEV;
43072
43073- if (!tty->port.count)
43074+ if (!atomic_read(&tty->port.count))
43075 return -EINVAL;
43076
43077 return get_control_lines(tty);
43078@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
43079 if (!tty)
43080 return -ENODEV;
43081
43082- if (!tty->port.count)
43083+ if (!atomic_read(&tty->port.count))
43084 return -EINVAL;
43085
43086 return set_control_lines(tty, set, clear);
43087@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
43088 if (!tty)
43089 return -ENODEV;
43090
43091- if (!tty->port.count)
43092+ if (!atomic_read(&tty->port.count))
43093 return -EINVAL;
43094
43095 /* FIXME: Exactly how is the tty object locked here .. */
43096@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
43097 * are gone */
43098 mutex_lock(&ttyj->ipw_tty_mutex);
43099 }
43100- while (ttyj->port.count)
43101+ while (atomic_read(&ttyj->port.count))
43102 do_ipw_close(ttyj);
43103 ipwireless_disassociate_network_ttys(network,
43104 ttyj->channel_idx);
43105diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
43106index adeac25..787a0a1 100644
43107--- a/drivers/tty/moxa.c
43108+++ b/drivers/tty/moxa.c
43109@@ -1193,7 +1193,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
43110 }
43111
43112 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
43113- ch->port.count++;
43114+ atomic_inc(&ch->port.count);
43115 tty->driver_data = ch;
43116 tty_port_tty_set(&ch->port, tty);
43117 mutex_lock(&ch->port.mutex);
43118diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
43119index 4a43ef5d7..aa71f27 100644
43120--- a/drivers/tty/n_gsm.c
43121+++ b/drivers/tty/n_gsm.c
43122@@ -1636,7 +1636,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
43123 spin_lock_init(&dlci->lock);
43124 mutex_init(&dlci->mutex);
43125 dlci->fifo = &dlci->_fifo;
43126- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
43127+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
43128 kfree(dlci);
43129 return NULL;
43130 }
43131@@ -2936,7 +2936,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
43132 struct gsm_dlci *dlci = tty->driver_data;
43133 struct tty_port *port = &dlci->port;
43134
43135- port->count++;
43136+ atomic_inc(&port->count);
43137 dlci_get(dlci);
43138 dlci_get(dlci->gsm->dlci[0]);
43139 mux_get(dlci->gsm);
43140diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
43141index 1f8cba6..47b06c2 100644
43142--- a/drivers/tty/n_tty.c
43143+++ b/drivers/tty/n_tty.c
43144@@ -2205,6 +2205,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
43145 {
43146 *ops = tty_ldisc_N_TTY;
43147 ops->owner = NULL;
43148- ops->refcount = ops->flags = 0;
43149+ atomic_set(&ops->refcount, 0);
43150+ ops->flags = 0;
43151 }
43152 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
43153diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
43154index 125e0fd..8c50690 100644
43155--- a/drivers/tty/pty.c
43156+++ b/drivers/tty/pty.c
43157@@ -800,8 +800,10 @@ static void __init unix98_pty_init(void)
43158 panic("Couldn't register Unix98 pts driver");
43159
43160 /* Now create the /dev/ptmx special device */
43161+ pax_open_kernel();
43162 tty_default_fops(&ptmx_fops);
43163- ptmx_fops.open = ptmx_open;
43164+ *(void **)&ptmx_fops.open = ptmx_open;
43165+ pax_close_kernel();
43166
43167 cdev_init(&ptmx_cdev, &ptmx_fops);
43168 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
43169diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
43170index 1d27003..959f452 100644
43171--- a/drivers/tty/rocket.c
43172+++ b/drivers/tty/rocket.c
43173@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43174 tty->driver_data = info;
43175 tty_port_tty_set(port, tty);
43176
43177- if (port->count++ == 0) {
43178+ if (atomic_inc_return(&port->count) == 1) {
43179 atomic_inc(&rp_num_ports_open);
43180
43181 #ifdef ROCKET_DEBUG_OPEN
43182@@ -932,7 +932,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43183 #endif
43184 }
43185 #ifdef ROCKET_DEBUG_OPEN
43186- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
43187+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
43188 #endif
43189
43190 /*
43191@@ -1527,7 +1527,7 @@ static void rp_hangup(struct tty_struct *tty)
43192 spin_unlock_irqrestore(&info->port.lock, flags);
43193 return;
43194 }
43195- if (info->port.count)
43196+ if (atomic_read(&info->port.count))
43197 atomic_dec(&rp_num_ports_open);
43198 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
43199 spin_unlock_irqrestore(&info->port.lock, flags);
43200diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
43201index 1002054..dd644a8 100644
43202--- a/drivers/tty/serial/kgdboc.c
43203+++ b/drivers/tty/serial/kgdboc.c
43204@@ -24,8 +24,9 @@
43205 #define MAX_CONFIG_LEN 40
43206
43207 static struct kgdb_io kgdboc_io_ops;
43208+static struct kgdb_io kgdboc_io_ops_console;
43209
43210-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
43211+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
43212 static int configured = -1;
43213
43214 static char config[MAX_CONFIG_LEN];
43215@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
43216 kgdboc_unregister_kbd();
43217 if (configured == 1)
43218 kgdb_unregister_io_module(&kgdboc_io_ops);
43219+ else if (configured == 2)
43220+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
43221 }
43222
43223 static int configure_kgdboc(void)
43224@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
43225 int err;
43226 char *cptr = config;
43227 struct console *cons;
43228+ int is_console = 0;
43229
43230 err = kgdboc_option_setup(config);
43231 if (err || !strlen(config) || isspace(config[0]))
43232 goto noconfig;
43233
43234 err = -ENODEV;
43235- kgdboc_io_ops.is_console = 0;
43236 kgdb_tty_driver = NULL;
43237
43238 kgdboc_use_kms = 0;
43239@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
43240 int idx;
43241 if (cons->device && cons->device(cons, &idx) == p &&
43242 idx == tty_line) {
43243- kgdboc_io_ops.is_console = 1;
43244+ is_console = 1;
43245 break;
43246 }
43247 cons = cons->next;
43248@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
43249 kgdb_tty_line = tty_line;
43250
43251 do_register:
43252- err = kgdb_register_io_module(&kgdboc_io_ops);
43253+ if (is_console) {
43254+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
43255+ configured = 2;
43256+ } else {
43257+ err = kgdb_register_io_module(&kgdboc_io_ops);
43258+ configured = 1;
43259+ }
43260 if (err)
43261 goto noconfig;
43262
43263@@ -205,8 +214,6 @@ do_register:
43264 if (err)
43265 goto nmi_con_failed;
43266
43267- configured = 1;
43268-
43269 return 0;
43270
43271 nmi_con_failed:
43272@@ -223,7 +230,7 @@ noconfig:
43273 static int __init init_kgdboc(void)
43274 {
43275 /* Already configured? */
43276- if (configured == 1)
43277+ if (configured >= 1)
43278 return 0;
43279
43280 return configure_kgdboc();
43281@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
43282 if (config[len - 1] == '\n')
43283 config[len - 1] = '\0';
43284
43285- if (configured == 1)
43286+ if (configured >= 1)
43287 cleanup_kgdboc();
43288
43289 /* Go and configure with the new params. */
43290@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
43291 .post_exception = kgdboc_post_exp_handler,
43292 };
43293
43294+static struct kgdb_io kgdboc_io_ops_console = {
43295+ .name = "kgdboc",
43296+ .read_char = kgdboc_get_char,
43297+ .write_char = kgdboc_put_char,
43298+ .pre_exception = kgdboc_pre_exp_handler,
43299+ .post_exception = kgdboc_post_exp_handler,
43300+ .is_console = 1
43301+};
43302+
43303 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
43304 /* This is only available if kgdboc is a built in for early debugging */
43305 static int __init kgdboc_early_init(char *opt)
43306diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
43307index 2769a38..f3dbe48 100644
43308--- a/drivers/tty/serial/samsung.c
43309+++ b/drivers/tty/serial/samsung.c
43310@@ -451,11 +451,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
43311 }
43312 }
43313
43314+static int s3c64xx_serial_startup(struct uart_port *port);
43315 static int s3c24xx_serial_startup(struct uart_port *port)
43316 {
43317 struct s3c24xx_uart_port *ourport = to_ourport(port);
43318 int ret;
43319
43320+ /* Startup sequence is different for s3c64xx and higher SoC's */
43321+ if (s3c24xx_serial_has_interrupt_mask(port))
43322+ return s3c64xx_serial_startup(port);
43323+
43324 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
43325 port->mapbase, port->membase);
43326
43327@@ -1120,10 +1125,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
43328 /* setup info for port */
43329 port->dev = &platdev->dev;
43330
43331- /* Startup sequence is different for s3c64xx and higher SoC's */
43332- if (s3c24xx_serial_has_interrupt_mask(port))
43333- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
43334-
43335 port->uartclk = 1;
43336
43337 if (cfg->uart_flags & UPF_CONS_FLOW) {
43338diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
43339index 8fbb6d2..822a9e6 100644
43340--- a/drivers/tty/serial/serial_core.c
43341+++ b/drivers/tty/serial/serial_core.c
43342@@ -1454,7 +1454,7 @@ static void uart_hangup(struct tty_struct *tty)
43343 uart_flush_buffer(tty);
43344 uart_shutdown(tty, state);
43345 spin_lock_irqsave(&port->lock, flags);
43346- port->count = 0;
43347+ atomic_set(&port->count, 0);
43348 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
43349 spin_unlock_irqrestore(&port->lock, flags);
43350 tty_port_tty_set(port, NULL);
43351@@ -1550,7 +1550,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43352 goto end;
43353 }
43354
43355- port->count++;
43356+ atomic_inc(&port->count);
43357 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
43358 retval = -ENXIO;
43359 goto err_dec_count;
43360@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43361 /*
43362 * Make sure the device is in D0 state.
43363 */
43364- if (port->count == 1)
43365+ if (atomic_read(&port->count) == 1)
43366 uart_change_pm(state, UART_PM_STATE_ON);
43367
43368 /*
43369@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43370 end:
43371 return retval;
43372 err_dec_count:
43373- port->count--;
43374+ atomic_inc(&port->count);
43375 mutex_unlock(&port->mutex);
43376 goto end;
43377 }
43378diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
43379index 8983276..72a4090 100644
43380--- a/drivers/tty/synclink.c
43381+++ b/drivers/tty/synclink.c
43382@@ -3093,7 +3093,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43383
43384 if (debug_level >= DEBUG_LEVEL_INFO)
43385 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
43386- __FILE__,__LINE__, info->device_name, info->port.count);
43387+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43388
43389 if (tty_port_close_start(&info->port, tty, filp) == 0)
43390 goto cleanup;
43391@@ -3111,7 +3111,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43392 cleanup:
43393 if (debug_level >= DEBUG_LEVEL_INFO)
43394 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
43395- tty->driver->name, info->port.count);
43396+ tty->driver->name, atomic_read(&info->port.count));
43397
43398 } /* end of mgsl_close() */
43399
43400@@ -3210,8 +3210,8 @@ static void mgsl_hangup(struct tty_struct *tty)
43401
43402 mgsl_flush_buffer(tty);
43403 shutdown(info);
43404-
43405- info->port.count = 0;
43406+
43407+ atomic_set(&info->port.count, 0);
43408 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43409 info->port.tty = NULL;
43410
43411@@ -3300,12 +3300,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43412
43413 if (debug_level >= DEBUG_LEVEL_INFO)
43414 printk("%s(%d):block_til_ready before block on %s count=%d\n",
43415- __FILE__,__LINE__, tty->driver->name, port->count );
43416+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43417
43418 spin_lock_irqsave(&info->irq_spinlock, flags);
43419 if (!tty_hung_up_p(filp)) {
43420 extra_count = true;
43421- port->count--;
43422+ atomic_dec(&port->count);
43423 }
43424 spin_unlock_irqrestore(&info->irq_spinlock, flags);
43425 port->blocked_open++;
43426@@ -3334,7 +3334,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43427
43428 if (debug_level >= DEBUG_LEVEL_INFO)
43429 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
43430- __FILE__,__LINE__, tty->driver->name, port->count );
43431+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43432
43433 tty_unlock(tty);
43434 schedule();
43435@@ -3346,12 +3346,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43436
43437 /* FIXME: Racy on hangup during close wait */
43438 if (extra_count)
43439- port->count++;
43440+ atomic_inc(&port->count);
43441 port->blocked_open--;
43442
43443 if (debug_level >= DEBUG_LEVEL_INFO)
43444 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
43445- __FILE__,__LINE__, tty->driver->name, port->count );
43446+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43447
43448 if (!retval)
43449 port->flags |= ASYNC_NORMAL_ACTIVE;
43450@@ -3403,7 +3403,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
43451
43452 if (debug_level >= DEBUG_LEVEL_INFO)
43453 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
43454- __FILE__,__LINE__,tty->driver->name, info->port.count);
43455+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
43456
43457 /* If port is closing, signal caller to try again */
43458 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43459@@ -3422,10 +3422,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
43460 spin_unlock_irqrestore(&info->netlock, flags);
43461 goto cleanup;
43462 }
43463- info->port.count++;
43464+ atomic_inc(&info->port.count);
43465 spin_unlock_irqrestore(&info->netlock, flags);
43466
43467- if (info->port.count == 1) {
43468+ if (atomic_read(&info->port.count) == 1) {
43469 /* 1st open on this device, init hardware */
43470 retval = startup(info);
43471 if (retval < 0)
43472@@ -3449,8 +3449,8 @@ cleanup:
43473 if (retval) {
43474 if (tty->count == 1)
43475 info->port.tty = NULL; /* tty layer will release tty struct */
43476- if(info->port.count)
43477- info->port.count--;
43478+ if (atomic_read(&info->port.count))
43479+ atomic_dec(&info->port.count);
43480 }
43481
43482 return retval;
43483@@ -7668,7 +7668,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43484 unsigned short new_crctype;
43485
43486 /* return error if TTY interface open */
43487- if (info->port.count)
43488+ if (atomic_read(&info->port.count))
43489 return -EBUSY;
43490
43491 switch (encoding)
43492@@ -7763,7 +7763,7 @@ static int hdlcdev_open(struct net_device *dev)
43493
43494 /* arbitrate between network and tty opens */
43495 spin_lock_irqsave(&info->netlock, flags);
43496- if (info->port.count != 0 || info->netcount != 0) {
43497+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43498 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
43499 spin_unlock_irqrestore(&info->netlock, flags);
43500 return -EBUSY;
43501@@ -7849,7 +7849,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43502 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
43503
43504 /* return error if TTY interface open */
43505- if (info->port.count)
43506+ if (atomic_read(&info->port.count))
43507 return -EBUSY;
43508
43509 if (cmd != SIOCWANDEV)
43510diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
43511index aa9eece..d8baaec 100644
43512--- a/drivers/tty/synclink_gt.c
43513+++ b/drivers/tty/synclink_gt.c
43514@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
43515 tty->driver_data = info;
43516 info->port.tty = tty;
43517
43518- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
43519+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
43520
43521 /* If port is closing, signal caller to try again */
43522 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43523@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
43524 mutex_unlock(&info->port.mutex);
43525 goto cleanup;
43526 }
43527- info->port.count++;
43528+ atomic_inc(&info->port.count);
43529 spin_unlock_irqrestore(&info->netlock, flags);
43530
43531- if (info->port.count == 1) {
43532+ if (atomic_read(&info->port.count) == 1) {
43533 /* 1st open on this device, init hardware */
43534 retval = startup(info);
43535 if (retval < 0) {
43536@@ -715,8 +715,8 @@ cleanup:
43537 if (retval) {
43538 if (tty->count == 1)
43539 info->port.tty = NULL; /* tty layer will release tty struct */
43540- if(info->port.count)
43541- info->port.count--;
43542+ if(atomic_read(&info->port.count))
43543+ atomic_dec(&info->port.count);
43544 }
43545
43546 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
43547@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43548
43549 if (sanity_check(info, tty->name, "close"))
43550 return;
43551- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
43552+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
43553
43554 if (tty_port_close_start(&info->port, tty, filp) == 0)
43555 goto cleanup;
43556@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43557 tty_port_close_end(&info->port, tty);
43558 info->port.tty = NULL;
43559 cleanup:
43560- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
43561+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
43562 }
43563
43564 static void hangup(struct tty_struct *tty)
43565@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
43566 shutdown(info);
43567
43568 spin_lock_irqsave(&info->port.lock, flags);
43569- info->port.count = 0;
43570+ atomic_set(&info->port.count, 0);
43571 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43572 info->port.tty = NULL;
43573 spin_unlock_irqrestore(&info->port.lock, flags);
43574@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43575 unsigned short new_crctype;
43576
43577 /* return error if TTY interface open */
43578- if (info->port.count)
43579+ if (atomic_read(&info->port.count))
43580 return -EBUSY;
43581
43582 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
43583@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
43584
43585 /* arbitrate between network and tty opens */
43586 spin_lock_irqsave(&info->netlock, flags);
43587- if (info->port.count != 0 || info->netcount != 0) {
43588+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43589 DBGINFO(("%s hdlc_open busy\n", dev->name));
43590 spin_unlock_irqrestore(&info->netlock, flags);
43591 return -EBUSY;
43592@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43593 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
43594
43595 /* return error if TTY interface open */
43596- if (info->port.count)
43597+ if (atomic_read(&info->port.count))
43598 return -EBUSY;
43599
43600 if (cmd != SIOCWANDEV)
43601@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
43602 if (port == NULL)
43603 continue;
43604 spin_lock(&port->lock);
43605- if ((port->port.count || port->netcount) &&
43606+ if ((atomic_read(&port->port.count) || port->netcount) &&
43607 port->pending_bh && !port->bh_running &&
43608 !port->bh_requested) {
43609 DBGISR(("%s bh queued\n", port->device_name));
43610@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43611 spin_lock_irqsave(&info->lock, flags);
43612 if (!tty_hung_up_p(filp)) {
43613 extra_count = true;
43614- port->count--;
43615+ atomic_dec(&port->count);
43616 }
43617 spin_unlock_irqrestore(&info->lock, flags);
43618 port->blocked_open++;
43619@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43620 remove_wait_queue(&port->open_wait, &wait);
43621
43622 if (extra_count)
43623- port->count++;
43624+ atomic_inc(&port->count);
43625 port->blocked_open--;
43626
43627 if (!retval)
43628diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
43629index 6d5780c..aa4d8cd 100644
43630--- a/drivers/tty/synclinkmp.c
43631+++ b/drivers/tty/synclinkmp.c
43632@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
43633
43634 if (debug_level >= DEBUG_LEVEL_INFO)
43635 printk("%s(%d):%s open(), old ref count = %d\n",
43636- __FILE__,__LINE__,tty->driver->name, info->port.count);
43637+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
43638
43639 /* If port is closing, signal caller to try again */
43640 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43641@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
43642 spin_unlock_irqrestore(&info->netlock, flags);
43643 goto cleanup;
43644 }
43645- info->port.count++;
43646+ atomic_inc(&info->port.count);
43647 spin_unlock_irqrestore(&info->netlock, flags);
43648
43649- if (info->port.count == 1) {
43650+ if (atomic_read(&info->port.count) == 1) {
43651 /* 1st open on this device, init hardware */
43652 retval = startup(info);
43653 if (retval < 0)
43654@@ -796,8 +796,8 @@ cleanup:
43655 if (retval) {
43656 if (tty->count == 1)
43657 info->port.tty = NULL; /* tty layer will release tty struct */
43658- if(info->port.count)
43659- info->port.count--;
43660+ if(atomic_read(&info->port.count))
43661+ atomic_dec(&info->port.count);
43662 }
43663
43664 return retval;
43665@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43666
43667 if (debug_level >= DEBUG_LEVEL_INFO)
43668 printk("%s(%d):%s close() entry, count=%d\n",
43669- __FILE__,__LINE__, info->device_name, info->port.count);
43670+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43671
43672 if (tty_port_close_start(&info->port, tty, filp) == 0)
43673 goto cleanup;
43674@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43675 cleanup:
43676 if (debug_level >= DEBUG_LEVEL_INFO)
43677 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
43678- tty->driver->name, info->port.count);
43679+ tty->driver->name, atomic_read(&info->port.count));
43680 }
43681
43682 /* Called by tty_hangup() when a hangup is signaled.
43683@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
43684 shutdown(info);
43685
43686 spin_lock_irqsave(&info->port.lock, flags);
43687- info->port.count = 0;
43688+ atomic_set(&info->port.count, 0);
43689 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43690 info->port.tty = NULL;
43691 spin_unlock_irqrestore(&info->port.lock, flags);
43692@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43693 unsigned short new_crctype;
43694
43695 /* return error if TTY interface open */
43696- if (info->port.count)
43697+ if (atomic_read(&info->port.count))
43698 return -EBUSY;
43699
43700 switch (encoding)
43701@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
43702
43703 /* arbitrate between network and tty opens */
43704 spin_lock_irqsave(&info->netlock, flags);
43705- if (info->port.count != 0 || info->netcount != 0) {
43706+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43707 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
43708 spin_unlock_irqrestore(&info->netlock, flags);
43709 return -EBUSY;
43710@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43711 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
43712
43713 /* return error if TTY interface open */
43714- if (info->port.count)
43715+ if (atomic_read(&info->port.count))
43716 return -EBUSY;
43717
43718 if (cmd != SIOCWANDEV)
43719@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
43720 * do not request bottom half processing if the
43721 * device is not open in a normal mode.
43722 */
43723- if ( port && (port->port.count || port->netcount) &&
43724+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
43725 port->pending_bh && !port->bh_running &&
43726 !port->bh_requested ) {
43727 if ( debug_level >= DEBUG_LEVEL_ISR )
43728@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43729
43730 if (debug_level >= DEBUG_LEVEL_INFO)
43731 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
43732- __FILE__,__LINE__, tty->driver->name, port->count );
43733+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43734
43735 spin_lock_irqsave(&info->lock, flags);
43736 if (!tty_hung_up_p(filp)) {
43737 extra_count = true;
43738- port->count--;
43739+ atomic_dec(&port->count);
43740 }
43741 spin_unlock_irqrestore(&info->lock, flags);
43742 port->blocked_open++;
43743@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43744
43745 if (debug_level >= DEBUG_LEVEL_INFO)
43746 printk("%s(%d):%s block_til_ready() count=%d\n",
43747- __FILE__,__LINE__, tty->driver->name, port->count );
43748+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43749
43750 tty_unlock(tty);
43751 schedule();
43752@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43753 remove_wait_queue(&port->open_wait, &wait);
43754
43755 if (extra_count)
43756- port->count++;
43757+ atomic_inc(&port->count);
43758 port->blocked_open--;
43759
43760 if (debug_level >= DEBUG_LEVEL_INFO)
43761 printk("%s(%d):%s block_til_ready() after, count=%d\n",
43762- __FILE__,__LINE__, tty->driver->name, port->count );
43763+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43764
43765 if (!retval)
43766 port->flags |= ASYNC_NORMAL_ACTIVE;
43767diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
43768index 3687f0c..6b9b808 100644
43769--- a/drivers/tty/sysrq.c
43770+++ b/drivers/tty/sysrq.c
43771@@ -995,7 +995,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
43772 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
43773 size_t count, loff_t *ppos)
43774 {
43775- if (count) {
43776+ if (count && capable(CAP_SYS_ADMIN)) {
43777 char c;
43778
43779 if (get_user(c, buf))
43780diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
43781index a9cd0b9..47b9336 100644
43782--- a/drivers/tty/tty_io.c
43783+++ b/drivers/tty/tty_io.c
43784@@ -3398,7 +3398,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
43785
43786 void tty_default_fops(struct file_operations *fops)
43787 {
43788- *fops = tty_fops;
43789+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
43790 }
43791
43792 /*
43793diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
43794index d794087..e4f49e5 100644
43795--- a/drivers/tty/tty_ldisc.c
43796+++ b/drivers/tty/tty_ldisc.c
43797@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
43798 if (atomic_dec_and_test(&ld->users)) {
43799 struct tty_ldisc_ops *ldo = ld->ops;
43800
43801- ldo->refcount--;
43802+ atomic_dec(&ldo->refcount);
43803 module_put(ldo->owner);
43804 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43805
43806@@ -93,7 +93,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
43807 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43808 tty_ldiscs[disc] = new_ldisc;
43809 new_ldisc->num = disc;
43810- new_ldisc->refcount = 0;
43811+ atomic_set(&new_ldisc->refcount, 0);
43812 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43813
43814 return ret;
43815@@ -121,7 +121,7 @@ int tty_unregister_ldisc(int disc)
43816 return -EINVAL;
43817
43818 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43819- if (tty_ldiscs[disc]->refcount)
43820+ if (atomic_read(&tty_ldiscs[disc]->refcount))
43821 ret = -EBUSY;
43822 else
43823 tty_ldiscs[disc] = NULL;
43824@@ -142,7 +142,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
43825 if (ldops) {
43826 ret = ERR_PTR(-EAGAIN);
43827 if (try_module_get(ldops->owner)) {
43828- ldops->refcount++;
43829+ atomic_inc(&ldops->refcount);
43830 ret = ldops;
43831 }
43832 }
43833@@ -155,7 +155,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
43834 unsigned long flags;
43835
43836 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43837- ldops->refcount--;
43838+ atomic_dec(&ldops->refcount);
43839 module_put(ldops->owner);
43840 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43841 }
43842diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
43843index b7ff59d..7c6105e 100644
43844--- a/drivers/tty/tty_port.c
43845+++ b/drivers/tty/tty_port.c
43846@@ -218,7 +218,7 @@ void tty_port_hangup(struct tty_port *port)
43847 unsigned long flags;
43848
43849 spin_lock_irqsave(&port->lock, flags);
43850- port->count = 0;
43851+ atomic_set(&port->count, 0);
43852 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43853 if (port->tty) {
43854 set_bit(TTY_IO_ERROR, &port->tty->flags);
43855@@ -344,7 +344,7 @@ int tty_port_block_til_ready(struct tty_port *port,
43856 /* The port lock protects the port counts */
43857 spin_lock_irqsave(&port->lock, flags);
43858 if (!tty_hung_up_p(filp))
43859- port->count--;
43860+ atomic_dec(&port->count);
43861 port->blocked_open++;
43862 spin_unlock_irqrestore(&port->lock, flags);
43863
43864@@ -386,7 +386,7 @@ int tty_port_block_til_ready(struct tty_port *port,
43865 we must not mess that up further */
43866 spin_lock_irqsave(&port->lock, flags);
43867 if (!tty_hung_up_p(filp))
43868- port->count++;
43869+ atomic_inc(&port->count);
43870 port->blocked_open--;
43871 if (retval == 0)
43872 port->flags |= ASYNC_NORMAL_ACTIVE;
43873@@ -406,19 +406,19 @@ int tty_port_close_start(struct tty_port *port,
43874 return 0;
43875 }
43876
43877- if (tty->count == 1 && port->count != 1) {
43878+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
43879 printk(KERN_WARNING
43880 "tty_port_close_start: tty->count = 1 port count = %d.\n",
43881- port->count);
43882- port->count = 1;
43883+ atomic_read(&port->count));
43884+ atomic_set(&port->count, 1);
43885 }
43886- if (--port->count < 0) {
43887+ if (atomic_dec_return(&port->count) < 0) {
43888 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
43889- port->count);
43890- port->count = 0;
43891+ atomic_read(&port->count));
43892+ atomic_set(&port->count, 0);
43893 }
43894
43895- if (port->count) {
43896+ if (atomic_read(&port->count)) {
43897 spin_unlock_irqrestore(&port->lock, flags);
43898 if (port->ops->drop)
43899 port->ops->drop(port);
43900@@ -516,7 +516,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
43901 {
43902 spin_lock_irq(&port->lock);
43903 if (!tty_hung_up_p(filp))
43904- ++port->count;
43905+ atomic_inc(&port->count);
43906 spin_unlock_irq(&port->lock);
43907 tty_port_tty_set(port, tty);
43908
43909diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
43910index a9af1b9a..1e08e7f 100644
43911--- a/drivers/tty/vt/keyboard.c
43912+++ b/drivers/tty/vt/keyboard.c
43913@@ -647,6 +647,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
43914 kbd->kbdmode == VC_OFF) &&
43915 value != KVAL(K_SAK))
43916 return; /* SAK is allowed even in raw mode */
43917+
43918+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
43919+ {
43920+ void *func = fn_handler[value];
43921+ if (func == fn_show_state || func == fn_show_ptregs ||
43922+ func == fn_show_mem)
43923+ return;
43924+ }
43925+#endif
43926+
43927 fn_handler[value](vc);
43928 }
43929
43930@@ -1795,9 +1805,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
43931 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
43932 return -EFAULT;
43933
43934- if (!capable(CAP_SYS_TTY_CONFIG))
43935- perm = 0;
43936-
43937 switch (cmd) {
43938 case KDGKBENT:
43939 /* Ensure another thread doesn't free it under us */
43940@@ -1812,6 +1819,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
43941 spin_unlock_irqrestore(&kbd_event_lock, flags);
43942 return put_user(val, &user_kbe->kb_value);
43943 case KDSKBENT:
43944+ if (!capable(CAP_SYS_TTY_CONFIG))
43945+ perm = 0;
43946+
43947 if (!perm)
43948 return -EPERM;
43949 if (!i && v == K_NOSUCHMAP) {
43950@@ -1902,9 +1912,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
43951 int i, j, k;
43952 int ret;
43953
43954- if (!capable(CAP_SYS_TTY_CONFIG))
43955- perm = 0;
43956-
43957 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
43958 if (!kbs) {
43959 ret = -ENOMEM;
43960@@ -1938,6 +1945,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
43961 kfree(kbs);
43962 return ((p && *p) ? -EOVERFLOW : 0);
43963 case KDSKBSENT:
43964+ if (!capable(CAP_SYS_TTY_CONFIG))
43965+ perm = 0;
43966+
43967 if (!perm) {
43968 ret = -EPERM;
43969 goto reterr;
43970diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
43971index c8b9262..7e824e6 100644
43972--- a/drivers/uio/uio.c
43973+++ b/drivers/uio/uio.c
43974@@ -25,6 +25,7 @@
43975 #include <linux/kobject.h>
43976 #include <linux/cdev.h>
43977 #include <linux/uio_driver.h>
43978+#include <asm/local.h>
43979
43980 #define UIO_MAX_DEVICES (1U << MINORBITS)
43981
43982@@ -32,10 +33,10 @@ struct uio_device {
43983 struct module *owner;
43984 struct device *dev;
43985 int minor;
43986- atomic_t event;
43987+ atomic_unchecked_t event;
43988 struct fasync_struct *async_queue;
43989 wait_queue_head_t wait;
43990- int vma_count;
43991+ local_t vma_count;
43992 struct uio_info *info;
43993 struct kobject *map_dir;
43994 struct kobject *portio_dir;
43995@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
43996 struct device_attribute *attr, char *buf)
43997 {
43998 struct uio_device *idev = dev_get_drvdata(dev);
43999- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
44000+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
44001 }
44002
44003 static struct device_attribute uio_class_attributes[] = {
44004@@ -397,7 +398,7 @@ void uio_event_notify(struct uio_info *info)
44005 {
44006 struct uio_device *idev = info->uio_dev;
44007
44008- atomic_inc(&idev->event);
44009+ atomic_inc_unchecked(&idev->event);
44010 wake_up_interruptible(&idev->wait);
44011 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
44012 }
44013@@ -450,7 +451,7 @@ static int uio_open(struct inode *inode, struct file *filep)
44014 }
44015
44016 listener->dev = idev;
44017- listener->event_count = atomic_read(&idev->event);
44018+ listener->event_count = atomic_read_unchecked(&idev->event);
44019 filep->private_data = listener;
44020
44021 if (idev->info->open) {
44022@@ -501,7 +502,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
44023 return -EIO;
44024
44025 poll_wait(filep, &idev->wait, wait);
44026- if (listener->event_count != atomic_read(&idev->event))
44027+ if (listener->event_count != atomic_read_unchecked(&idev->event))
44028 return POLLIN | POLLRDNORM;
44029 return 0;
44030 }
44031@@ -526,7 +527,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
44032 do {
44033 set_current_state(TASK_INTERRUPTIBLE);
44034
44035- event_count = atomic_read(&idev->event);
44036+ event_count = atomic_read_unchecked(&idev->event);
44037 if (event_count != listener->event_count) {
44038 if (copy_to_user(buf, &event_count, count))
44039 retval = -EFAULT;
44040@@ -595,13 +596,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
44041 static void uio_vma_open(struct vm_area_struct *vma)
44042 {
44043 struct uio_device *idev = vma->vm_private_data;
44044- idev->vma_count++;
44045+ local_inc(&idev->vma_count);
44046 }
44047
44048 static void uio_vma_close(struct vm_area_struct *vma)
44049 {
44050 struct uio_device *idev = vma->vm_private_data;
44051- idev->vma_count--;
44052+ local_dec(&idev->vma_count);
44053 }
44054
44055 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
44056@@ -808,7 +809,7 @@ int __uio_register_device(struct module *owner,
44057 idev->owner = owner;
44058 idev->info = info;
44059 init_waitqueue_head(&idev->wait);
44060- atomic_set(&idev->event, 0);
44061+ atomic_set_unchecked(&idev->event, 0);
44062
44063 ret = uio_get_minor(idev);
44064 if (ret)
44065diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
44066index 8a7eb77..c00402f 100644
44067--- a/drivers/usb/atm/cxacru.c
44068+++ b/drivers/usb/atm/cxacru.c
44069@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
44070 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
44071 if (ret < 2)
44072 return -EINVAL;
44073- if (index < 0 || index > 0x7f)
44074+ if (index > 0x7f)
44075 return -EINVAL;
44076 pos += tmp;
44077
44078diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
44079index 35f10bf..6a38a0b 100644
44080--- a/drivers/usb/atm/usbatm.c
44081+++ b/drivers/usb/atm/usbatm.c
44082@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44083 if (printk_ratelimit())
44084 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
44085 __func__, vpi, vci);
44086- atomic_inc(&vcc->stats->rx_err);
44087+ atomic_inc_unchecked(&vcc->stats->rx_err);
44088 return;
44089 }
44090
44091@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44092 if (length > ATM_MAX_AAL5_PDU) {
44093 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
44094 __func__, length, vcc);
44095- atomic_inc(&vcc->stats->rx_err);
44096+ atomic_inc_unchecked(&vcc->stats->rx_err);
44097 goto out;
44098 }
44099
44100@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44101 if (sarb->len < pdu_length) {
44102 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
44103 __func__, pdu_length, sarb->len, vcc);
44104- atomic_inc(&vcc->stats->rx_err);
44105+ atomic_inc_unchecked(&vcc->stats->rx_err);
44106 goto out;
44107 }
44108
44109 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
44110 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
44111 __func__, vcc);
44112- atomic_inc(&vcc->stats->rx_err);
44113+ atomic_inc_unchecked(&vcc->stats->rx_err);
44114 goto out;
44115 }
44116
44117@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44118 if (printk_ratelimit())
44119 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
44120 __func__, length);
44121- atomic_inc(&vcc->stats->rx_drop);
44122+ atomic_inc_unchecked(&vcc->stats->rx_drop);
44123 goto out;
44124 }
44125
44126@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44127
44128 vcc->push(vcc, skb);
44129
44130- atomic_inc(&vcc->stats->rx);
44131+ atomic_inc_unchecked(&vcc->stats->rx);
44132 out:
44133 skb_trim(sarb, 0);
44134 }
44135@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
44136 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
44137
44138 usbatm_pop(vcc, skb);
44139- atomic_inc(&vcc->stats->tx);
44140+ atomic_inc_unchecked(&vcc->stats->tx);
44141
44142 skb = skb_dequeue(&instance->sndqueue);
44143 }
44144@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
44145 if (!left--)
44146 return sprintf(page,
44147 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
44148- atomic_read(&atm_dev->stats.aal5.tx),
44149- atomic_read(&atm_dev->stats.aal5.tx_err),
44150- atomic_read(&atm_dev->stats.aal5.rx),
44151- atomic_read(&atm_dev->stats.aal5.rx_err),
44152- atomic_read(&atm_dev->stats.aal5.rx_drop));
44153+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
44154+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
44155+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
44156+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
44157+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
44158
44159 if (!left--) {
44160 if (instance->disconnected)
44161diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
44162index 2a3bbdf..91d72cf 100644
44163--- a/drivers/usb/core/devices.c
44164+++ b/drivers/usb/core/devices.c
44165@@ -126,7 +126,7 @@ static const char format_endpt[] =
44166 * time it gets called.
44167 */
44168 static struct device_connect_event {
44169- atomic_t count;
44170+ atomic_unchecked_t count;
44171 wait_queue_head_t wait;
44172 } device_event = {
44173 .count = ATOMIC_INIT(1),
44174@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
44175
44176 void usbfs_conn_disc_event(void)
44177 {
44178- atomic_add(2, &device_event.count);
44179+ atomic_add_unchecked(2, &device_event.count);
44180 wake_up(&device_event.wait);
44181 }
44182
44183@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
44184
44185 poll_wait(file, &device_event.wait, wait);
44186
44187- event_count = atomic_read(&device_event.count);
44188+ event_count = atomic_read_unchecked(&device_event.count);
44189 if (file->f_version != event_count) {
44190 file->f_version = event_count;
44191 return POLLIN | POLLRDNORM;
44192diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
44193index f9ec44c..eb5779f 100644
44194--- a/drivers/usb/core/hcd.c
44195+++ b/drivers/usb/core/hcd.c
44196@@ -1526,7 +1526,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44197 */
44198 usb_get_urb(urb);
44199 atomic_inc(&urb->use_count);
44200- atomic_inc(&urb->dev->urbnum);
44201+ atomic_inc_unchecked(&urb->dev->urbnum);
44202 usbmon_urb_submit(&hcd->self, urb);
44203
44204 /* NOTE requirements on root-hub callers (usbfs and the hub
44205@@ -1553,7 +1553,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44206 urb->hcpriv = NULL;
44207 INIT_LIST_HEAD(&urb->urb_list);
44208 atomic_dec(&urb->use_count);
44209- atomic_dec(&urb->dev->urbnum);
44210+ atomic_dec_unchecked(&urb->dev->urbnum);
44211 if (atomic_read(&urb->reject))
44212 wake_up(&usb_kill_urb_queue);
44213 usb_put_urb(urb);
44214diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
44215index 444d30e..f15c850 100644
44216--- a/drivers/usb/core/message.c
44217+++ b/drivers/usb/core/message.c
44218@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
44219 * method can wait for it to complete. Since you don't have a handle on the
44220 * URB used, you can't cancel the request.
44221 */
44222-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44223+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44224 __u8 requesttype, __u16 value, __u16 index, void *data,
44225 __u16 size, int timeout)
44226 {
44227diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
44228index 3f81a3d..a3aa993 100644
44229--- a/drivers/usb/core/sysfs.c
44230+++ b/drivers/usb/core/sysfs.c
44231@@ -239,7 +239,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
44232 struct usb_device *udev;
44233
44234 udev = to_usb_device(dev);
44235- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
44236+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
44237 }
44238 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
44239
44240diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
44241index f81b925..78d22ec 100644
44242--- a/drivers/usb/core/usb.c
44243+++ b/drivers/usb/core/usb.c
44244@@ -388,7 +388,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
44245 set_dev_node(&dev->dev, dev_to_node(bus->controller));
44246 dev->state = USB_STATE_ATTACHED;
44247 dev->lpm_disable_count = 1;
44248- atomic_set(&dev->urbnum, 0);
44249+ atomic_set_unchecked(&dev->urbnum, 0);
44250
44251 INIT_LIST_HEAD(&dev->ep0.urb_list);
44252 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
44253diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
44254index 5e29dde..eca992f 100644
44255--- a/drivers/usb/early/ehci-dbgp.c
44256+++ b/drivers/usb/early/ehci-dbgp.c
44257@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
44258
44259 #ifdef CONFIG_KGDB
44260 static struct kgdb_io kgdbdbgp_io_ops;
44261-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
44262+static struct kgdb_io kgdbdbgp_io_ops_console;
44263+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
44264 #else
44265 #define dbgp_kgdb_mode (0)
44266 #endif
44267@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
44268 .write_char = kgdbdbgp_write_char,
44269 };
44270
44271+static struct kgdb_io kgdbdbgp_io_ops_console = {
44272+ .name = "kgdbdbgp",
44273+ .read_char = kgdbdbgp_read_char,
44274+ .write_char = kgdbdbgp_write_char,
44275+ .is_console = 1
44276+};
44277+
44278 static int kgdbdbgp_wait_time;
44279
44280 static int __init kgdbdbgp_parse_config(char *str)
44281@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
44282 ptr++;
44283 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
44284 }
44285- kgdb_register_io_module(&kgdbdbgp_io_ops);
44286- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
44287+ if (early_dbgp_console.index != -1)
44288+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
44289+ else
44290+ kgdb_register_io_module(&kgdbdbgp_io_ops);
44291
44292 return 0;
44293 }
44294diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
44295index b369292..9f3ba40 100644
44296--- a/drivers/usb/gadget/u_serial.c
44297+++ b/drivers/usb/gadget/u_serial.c
44298@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44299 spin_lock_irq(&port->port_lock);
44300
44301 /* already open? Great. */
44302- if (port->port.count) {
44303+ if (atomic_read(&port->port.count)) {
44304 status = 0;
44305- port->port.count++;
44306+ atomic_inc(&port->port.count);
44307
44308 /* currently opening/closing? wait ... */
44309 } else if (port->openclose) {
44310@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44311 tty->driver_data = port;
44312 port->port.tty = tty;
44313
44314- port->port.count = 1;
44315+ atomic_set(&port->port.count, 1);
44316 port->openclose = false;
44317
44318 /* if connected, start the I/O stream */
44319@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44320
44321 spin_lock_irq(&port->port_lock);
44322
44323- if (port->port.count != 1) {
44324- if (port->port.count == 0)
44325+ if (atomic_read(&port->port.count) != 1) {
44326+ if (atomic_read(&port->port.count) == 0)
44327 WARN_ON(1);
44328 else
44329- --port->port.count;
44330+ atomic_dec(&port->port.count);
44331 goto exit;
44332 }
44333
44334@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44335 * and sleep if necessary
44336 */
44337 port->openclose = true;
44338- port->port.count = 0;
44339+ atomic_set(&port->port.count, 0);
44340
44341 gser = port->port_usb;
44342 if (gser && gser->disconnect)
44343@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
44344 int cond;
44345
44346 spin_lock_irq(&port->port_lock);
44347- cond = (port->port.count == 0) && !port->openclose;
44348+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
44349 spin_unlock_irq(&port->port_lock);
44350 return cond;
44351 }
44352@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
44353 /* if it's already open, start I/O ... and notify the serial
44354 * protocol about open/close status (connect/disconnect).
44355 */
44356- if (port->port.count) {
44357+ if (atomic_read(&port->port.count)) {
44358 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
44359 gs_start_io(port);
44360 if (gser->connect)
44361@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
44362
44363 port->port_usb = NULL;
44364 gser->ioport = NULL;
44365- if (port->port.count > 0 || port->openclose) {
44366+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
44367 wake_up_interruptible(&port->drain_wait);
44368 if (port->port.tty)
44369 tty_hangup(port->port.tty);
44370@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
44371
44372 /* finally, free any unused/unusable I/O buffers */
44373 spin_lock_irqsave(&port->port_lock, flags);
44374- if (port->port.count == 0 && !port->openclose)
44375+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
44376 gs_buf_free(&port->port_write_buf);
44377 gs_free_requests(gser->out, &port->read_pool, NULL);
44378 gs_free_requests(gser->out, &port->read_queue, NULL);
44379diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
44380index 5f3bcd3..bfca43f 100644
44381--- a/drivers/usb/serial/console.c
44382+++ b/drivers/usb/serial/console.c
44383@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
44384
44385 info->port = port;
44386
44387- ++port->port.count;
44388+ atomic_inc(&port->port.count);
44389 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
44390 if (serial->type->set_termios) {
44391 /*
44392@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
44393 }
44394 /* Now that any required fake tty operations are completed restore
44395 * the tty port count */
44396- --port->port.count;
44397+ atomic_dec(&port->port.count);
44398 /* The console is special in terms of closing the device so
44399 * indicate this port is now acting as a system console. */
44400 port->port.console = 1;
44401@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
44402 free_tty:
44403 kfree(tty);
44404 reset_open_count:
44405- port->port.count = 0;
44406+ atomic_set(&port->port.count, 0);
44407 usb_autopm_put_interface(serial->interface);
44408 error_get_interface:
44409 usb_serial_put(serial);
44410diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c
44411index 6c3586a..a94e621 100644
44412--- a/drivers/usb/storage/realtek_cr.c
44413+++ b/drivers/usb/storage/realtek_cr.c
44414@@ -429,7 +429,7 @@ static int rts51x_read_status(struct us_data *us,
44415
44416 buf = kmalloc(len, GFP_NOIO);
44417 if (buf == NULL)
44418- return USB_STOR_TRANSPORT_ERROR;
44419+ return -ENOMEM;
44420
44421 US_DEBUGP("%s, lun = %d\n", __func__, lun);
44422
44423diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
44424index 75f70f0..d467e1a 100644
44425--- a/drivers/usb/storage/usb.h
44426+++ b/drivers/usb/storage/usb.h
44427@@ -63,7 +63,7 @@ struct us_unusual_dev {
44428 __u8 useProtocol;
44429 __u8 useTransport;
44430 int (*initFunction)(struct us_data *);
44431-};
44432+} __do_const;
44433
44434
44435 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
44436diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
44437index d6bea3e..60b250e 100644
44438--- a/drivers/usb/wusbcore/wa-hc.h
44439+++ b/drivers/usb/wusbcore/wa-hc.h
44440@@ -192,7 +192,7 @@ struct wahc {
44441 struct list_head xfer_delayed_list;
44442 spinlock_t xfer_list_lock;
44443 struct work_struct xfer_work;
44444- atomic_t xfer_id_count;
44445+ atomic_unchecked_t xfer_id_count;
44446 };
44447
44448
44449@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
44450 INIT_LIST_HEAD(&wa->xfer_delayed_list);
44451 spin_lock_init(&wa->xfer_list_lock);
44452 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
44453- atomic_set(&wa->xfer_id_count, 1);
44454+ atomic_set_unchecked(&wa->xfer_id_count, 1);
44455 }
44456
44457 /**
44458diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
44459index 6ef94bc..1b41265 100644
44460--- a/drivers/usb/wusbcore/wa-xfer.c
44461+++ b/drivers/usb/wusbcore/wa-xfer.c
44462@@ -296,7 +296,7 @@ out:
44463 */
44464 static void wa_xfer_id_init(struct wa_xfer *xfer)
44465 {
44466- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
44467+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
44468 }
44469
44470 /*
44471diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
44472index 8c55011..eed4ae1a 100644
44473--- a/drivers/video/aty/aty128fb.c
44474+++ b/drivers/video/aty/aty128fb.c
44475@@ -149,7 +149,7 @@ enum {
44476 };
44477
44478 /* Must match above enum */
44479-static char * const r128_family[] = {
44480+static const char * const r128_family[] = {
44481 "AGP",
44482 "PCI",
44483 "PRO AGP",
44484diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
44485index 4f27fdc..d3537e6 100644
44486--- a/drivers/video/aty/atyfb_base.c
44487+++ b/drivers/video/aty/atyfb_base.c
44488@@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
44489 par->accel_flags = var->accel_flags; /* hack */
44490
44491 if (var->accel_flags) {
44492- info->fbops->fb_sync = atyfb_sync;
44493+ pax_open_kernel();
44494+ *(void **)&info->fbops->fb_sync = atyfb_sync;
44495+ pax_close_kernel();
44496 info->flags &= ~FBINFO_HWACCEL_DISABLED;
44497 } else {
44498- info->fbops->fb_sync = NULL;
44499+ pax_open_kernel();
44500+ *(void **)&info->fbops->fb_sync = NULL;
44501+ pax_close_kernel();
44502 info->flags |= FBINFO_HWACCEL_DISABLED;
44503 }
44504
44505diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
44506index 95ec042..e6affdd 100644
44507--- a/drivers/video/aty/mach64_cursor.c
44508+++ b/drivers/video/aty/mach64_cursor.c
44509@@ -7,6 +7,7 @@
44510 #include <linux/string.h>
44511
44512 #include <asm/io.h>
44513+#include <asm/pgtable.h>
44514
44515 #ifdef __sparc__
44516 #include <asm/fbio.h>
44517@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
44518 info->sprite.buf_align = 16; /* and 64 lines tall. */
44519 info->sprite.flags = FB_PIXMAP_IO;
44520
44521- info->fbops->fb_cursor = atyfb_cursor;
44522+ pax_open_kernel();
44523+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
44524+ pax_close_kernel();
44525
44526 return 0;
44527 }
44528diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
44529index 6c5ed6b..b727c88 100644
44530--- a/drivers/video/backlight/kb3886_bl.c
44531+++ b/drivers/video/backlight/kb3886_bl.c
44532@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
44533 static unsigned long kb3886bl_flags;
44534 #define KB3886BL_SUSPENDED 0x01
44535
44536-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
44537+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
44538 {
44539 .ident = "Sahara Touch-iT",
44540 .matches = {
44541diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
44542index 900aa4e..6d49418 100644
44543--- a/drivers/video/fb_defio.c
44544+++ b/drivers/video/fb_defio.c
44545@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
44546
44547 BUG_ON(!fbdefio);
44548 mutex_init(&fbdefio->lock);
44549- info->fbops->fb_mmap = fb_deferred_io_mmap;
44550+ pax_open_kernel();
44551+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
44552+ pax_close_kernel();
44553 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
44554 INIT_LIST_HEAD(&fbdefio->pagelist);
44555 if (fbdefio->delay == 0) /* set a default of 1 s */
44556@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
44557 page->mapping = NULL;
44558 }
44559
44560- info->fbops->fb_mmap = NULL;
44561+ *(void **)&info->fbops->fb_mmap = NULL;
44562 mutex_destroy(&fbdefio->lock);
44563 }
44564 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
44565diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
44566index 5c3960d..15cf8fc 100644
44567--- a/drivers/video/fbcmap.c
44568+++ b/drivers/video/fbcmap.c
44569@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
44570 rc = -ENODEV;
44571 goto out;
44572 }
44573- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
44574- !info->fbops->fb_setcmap)) {
44575+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
44576 rc = -EINVAL;
44577 goto out1;
44578 }
44579diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
44580index 86291dc..7cc5962 100644
44581--- a/drivers/video/fbmem.c
44582+++ b/drivers/video/fbmem.c
44583@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
44584 image->dx += image->width + 8;
44585 }
44586 } else if (rotate == FB_ROTATE_UD) {
44587- for (x = 0; x < num && image->dx >= 0; x++) {
44588+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
44589 info->fbops->fb_imageblit(info, image);
44590 image->dx -= image->width + 8;
44591 }
44592@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
44593 image->dy += image->height + 8;
44594 }
44595 } else if (rotate == FB_ROTATE_CCW) {
44596- for (x = 0; x < num && image->dy >= 0; x++) {
44597+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
44598 info->fbops->fb_imageblit(info, image);
44599 image->dy -= image->height + 8;
44600 }
44601@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
44602 return -EFAULT;
44603 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
44604 return -EINVAL;
44605- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
44606+ if (con2fb.framebuffer >= FB_MAX)
44607 return -EINVAL;
44608 if (!registered_fb[con2fb.framebuffer])
44609 request_module("fb%d", con2fb.framebuffer);
44610diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
44611index 7672d2e..b56437f 100644
44612--- a/drivers/video/i810/i810_accel.c
44613+++ b/drivers/video/i810/i810_accel.c
44614@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
44615 }
44616 }
44617 printk("ringbuffer lockup!!!\n");
44618+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
44619 i810_report_error(mmio);
44620 par->dev_flags |= LOCKUP;
44621 info->pixmap.scan_align = 1;
44622diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
44623index 3c14e43..eafa544 100644
44624--- a/drivers/video/logo/logo_linux_clut224.ppm
44625+++ b/drivers/video/logo/logo_linux_clut224.ppm
44626@@ -1,1604 +1,1123 @@
44627 P3
44628-# Standard 224-color Linux logo
44629 80 80
44630 255
44631- 0 0 0 0 0 0 0 0 0 0 0 0
44632- 0 0 0 0 0 0 0 0 0 0 0 0
44633- 0 0 0 0 0 0 0 0 0 0 0 0
44634- 0 0 0 0 0 0 0 0 0 0 0 0
44635- 0 0 0 0 0 0 0 0 0 0 0 0
44636- 0 0 0 0 0 0 0 0 0 0 0 0
44637- 0 0 0 0 0 0 0 0 0 0 0 0
44638- 0 0 0 0 0 0 0 0 0 0 0 0
44639- 0 0 0 0 0 0 0 0 0 0 0 0
44640- 6 6 6 6 6 6 10 10 10 10 10 10
44641- 10 10 10 6 6 6 6 6 6 6 6 6
44642- 0 0 0 0 0 0 0 0 0 0 0 0
44643- 0 0 0 0 0 0 0 0 0 0 0 0
44644- 0 0 0 0 0 0 0 0 0 0 0 0
44645- 0 0 0 0 0 0 0 0 0 0 0 0
44646- 0 0 0 0 0 0 0 0 0 0 0 0
44647- 0 0 0 0 0 0 0 0 0 0 0 0
44648- 0 0 0 0 0 0 0 0 0 0 0 0
44649- 0 0 0 0 0 0 0 0 0 0 0 0
44650- 0 0 0 0 0 0 0 0 0 0 0 0
44651- 0 0 0 0 0 0 0 0 0 0 0 0
44652- 0 0 0 0 0 0 0 0 0 0 0 0
44653- 0 0 0 0 0 0 0 0 0 0 0 0
44654- 0 0 0 0 0 0 0 0 0 0 0 0
44655- 0 0 0 0 0 0 0 0 0 0 0 0
44656- 0 0 0 0 0 0 0 0 0 0 0 0
44657- 0 0 0 0 0 0 0 0 0 0 0 0
44658- 0 0 0 0 0 0 0 0 0 0 0 0
44659- 0 0 0 6 6 6 10 10 10 14 14 14
44660- 22 22 22 26 26 26 30 30 30 34 34 34
44661- 30 30 30 30 30 30 26 26 26 18 18 18
44662- 14 14 14 10 10 10 6 6 6 0 0 0
44663- 0 0 0 0 0 0 0 0 0 0 0 0
44664- 0 0 0 0 0 0 0 0 0 0 0 0
44665- 0 0 0 0 0 0 0 0 0 0 0 0
44666- 0 0 0 0 0 0 0 0 0 0 0 0
44667- 0 0 0 0 0 0 0 0 0 0 0 0
44668- 0 0 0 0 0 0 0 0 0 0 0 0
44669- 0 0 0 0 0 0 0 0 0 0 0 0
44670- 0 0 0 0 0 0 0 0 0 0 0 0
44671- 0 0 0 0 0 0 0 0 0 0 0 0
44672- 0 0 0 0 0 1 0 0 1 0 0 0
44673- 0 0 0 0 0 0 0 0 0 0 0 0
44674- 0 0 0 0 0 0 0 0 0 0 0 0
44675- 0 0 0 0 0 0 0 0 0 0 0 0
44676- 0 0 0 0 0 0 0 0 0 0 0 0
44677- 0 0 0 0 0 0 0 0 0 0 0 0
44678- 0 0 0 0 0 0 0 0 0 0 0 0
44679- 6 6 6 14 14 14 26 26 26 42 42 42
44680- 54 54 54 66 66 66 78 78 78 78 78 78
44681- 78 78 78 74 74 74 66 66 66 54 54 54
44682- 42 42 42 26 26 26 18 18 18 10 10 10
44683- 6 6 6 0 0 0 0 0 0 0 0 0
44684- 0 0 0 0 0 0 0 0 0 0 0 0
44685- 0 0 0 0 0 0 0 0 0 0 0 0
44686- 0 0 0 0 0 0 0 0 0 0 0 0
44687- 0 0 0 0 0 0 0 0 0 0 0 0
44688- 0 0 0 0 0 0 0 0 0 0 0 0
44689- 0 0 0 0 0 0 0 0 0 0 0 0
44690- 0 0 0 0 0 0 0 0 0 0 0 0
44691- 0 0 0 0 0 0 0 0 0 0 0 0
44692- 0 0 1 0 0 0 0 0 0 0 0 0
44693- 0 0 0 0 0 0 0 0 0 0 0 0
44694- 0 0 0 0 0 0 0 0 0 0 0 0
44695- 0 0 0 0 0 0 0 0 0 0 0 0
44696- 0 0 0 0 0 0 0 0 0 0 0 0
44697- 0 0 0 0 0 0 0 0 0 0 0 0
44698- 0 0 0 0 0 0 0 0 0 10 10 10
44699- 22 22 22 42 42 42 66 66 66 86 86 86
44700- 66 66 66 38 38 38 38 38 38 22 22 22
44701- 26 26 26 34 34 34 54 54 54 66 66 66
44702- 86 86 86 70 70 70 46 46 46 26 26 26
44703- 14 14 14 6 6 6 0 0 0 0 0 0
44704- 0 0 0 0 0 0 0 0 0 0 0 0
44705- 0 0 0 0 0 0 0 0 0 0 0 0
44706- 0 0 0 0 0 0 0 0 0 0 0 0
44707- 0 0 0 0 0 0 0 0 0 0 0 0
44708- 0 0 0 0 0 0 0 0 0 0 0 0
44709- 0 0 0 0 0 0 0 0 0 0 0 0
44710- 0 0 0 0 0 0 0 0 0 0 0 0
44711- 0 0 0 0 0 0 0 0 0 0 0 0
44712- 0 0 1 0 0 1 0 0 1 0 0 0
44713- 0 0 0 0 0 0 0 0 0 0 0 0
44714- 0 0 0 0 0 0 0 0 0 0 0 0
44715- 0 0 0 0 0 0 0 0 0 0 0 0
44716- 0 0 0 0 0 0 0 0 0 0 0 0
44717- 0 0 0 0 0 0 0 0 0 0 0 0
44718- 0 0 0 0 0 0 10 10 10 26 26 26
44719- 50 50 50 82 82 82 58 58 58 6 6 6
44720- 2 2 6 2 2 6 2 2 6 2 2 6
44721- 2 2 6 2 2 6 2 2 6 2 2 6
44722- 6 6 6 54 54 54 86 86 86 66 66 66
44723- 38 38 38 18 18 18 6 6 6 0 0 0
44724- 0 0 0 0 0 0 0 0 0 0 0 0
44725- 0 0 0 0 0 0 0 0 0 0 0 0
44726- 0 0 0 0 0 0 0 0 0 0 0 0
44727- 0 0 0 0 0 0 0 0 0 0 0 0
44728- 0 0 0 0 0 0 0 0 0 0 0 0
44729- 0 0 0 0 0 0 0 0 0 0 0 0
44730- 0 0 0 0 0 0 0 0 0 0 0 0
44731- 0 0 0 0 0 0 0 0 0 0 0 0
44732- 0 0 0 0 0 0 0 0 0 0 0 0
44733- 0 0 0 0 0 0 0 0 0 0 0 0
44734- 0 0 0 0 0 0 0 0 0 0 0 0
44735- 0 0 0 0 0 0 0 0 0 0 0 0
44736- 0 0 0 0 0 0 0 0 0 0 0 0
44737- 0 0 0 0 0 0 0 0 0 0 0 0
44738- 0 0 0 6 6 6 22 22 22 50 50 50
44739- 78 78 78 34 34 34 2 2 6 2 2 6
44740- 2 2 6 2 2 6 2 2 6 2 2 6
44741- 2 2 6 2 2 6 2 2 6 2 2 6
44742- 2 2 6 2 2 6 6 6 6 70 70 70
44743- 78 78 78 46 46 46 22 22 22 6 6 6
44744- 0 0 0 0 0 0 0 0 0 0 0 0
44745- 0 0 0 0 0 0 0 0 0 0 0 0
44746- 0 0 0 0 0 0 0 0 0 0 0 0
44747- 0 0 0 0 0 0 0 0 0 0 0 0
44748- 0 0 0 0 0 0 0 0 0 0 0 0
44749- 0 0 0 0 0 0 0 0 0 0 0 0
44750- 0 0 0 0 0 0 0 0 0 0 0 0
44751- 0 0 0 0 0 0 0 0 0 0 0 0
44752- 0 0 1 0 0 1 0 0 1 0 0 0
44753- 0 0 0 0 0 0 0 0 0 0 0 0
44754- 0 0 0 0 0 0 0 0 0 0 0 0
44755- 0 0 0 0 0 0 0 0 0 0 0 0
44756- 0 0 0 0 0 0 0 0 0 0 0 0
44757- 0 0 0 0 0 0 0 0 0 0 0 0
44758- 6 6 6 18 18 18 42 42 42 82 82 82
44759- 26 26 26 2 2 6 2 2 6 2 2 6
44760- 2 2 6 2 2 6 2 2 6 2 2 6
44761- 2 2 6 2 2 6 2 2 6 14 14 14
44762- 46 46 46 34 34 34 6 6 6 2 2 6
44763- 42 42 42 78 78 78 42 42 42 18 18 18
44764- 6 6 6 0 0 0 0 0 0 0 0 0
44765- 0 0 0 0 0 0 0 0 0 0 0 0
44766- 0 0 0 0 0 0 0 0 0 0 0 0
44767- 0 0 0 0 0 0 0 0 0 0 0 0
44768- 0 0 0 0 0 0 0 0 0 0 0 0
44769- 0 0 0 0 0 0 0 0 0 0 0 0
44770- 0 0 0 0 0 0 0 0 0 0 0 0
44771- 0 0 0 0 0 0 0 0 0 0 0 0
44772- 0 0 1 0 0 0 0 0 1 0 0 0
44773- 0 0 0 0 0 0 0 0 0 0 0 0
44774- 0 0 0 0 0 0 0 0 0 0 0 0
44775- 0 0 0 0 0 0 0 0 0 0 0 0
44776- 0 0 0 0 0 0 0 0 0 0 0 0
44777- 0 0 0 0 0 0 0 0 0 0 0 0
44778- 10 10 10 30 30 30 66 66 66 58 58 58
44779- 2 2 6 2 2 6 2 2 6 2 2 6
44780- 2 2 6 2 2 6 2 2 6 2 2 6
44781- 2 2 6 2 2 6 2 2 6 26 26 26
44782- 86 86 86 101 101 101 46 46 46 10 10 10
44783- 2 2 6 58 58 58 70 70 70 34 34 34
44784- 10 10 10 0 0 0 0 0 0 0 0 0
44785- 0 0 0 0 0 0 0 0 0 0 0 0
44786- 0 0 0 0 0 0 0 0 0 0 0 0
44787- 0 0 0 0 0 0 0 0 0 0 0 0
44788- 0 0 0 0 0 0 0 0 0 0 0 0
44789- 0 0 0 0 0 0 0 0 0 0 0 0
44790- 0 0 0 0 0 0 0 0 0 0 0 0
44791- 0 0 0 0 0 0 0 0 0 0 0 0
44792- 0 0 1 0 0 1 0 0 1 0 0 0
44793- 0 0 0 0 0 0 0 0 0 0 0 0
44794- 0 0 0 0 0 0 0 0 0 0 0 0
44795- 0 0 0 0 0 0 0 0 0 0 0 0
44796- 0 0 0 0 0 0 0 0 0 0 0 0
44797- 0 0 0 0 0 0 0 0 0 0 0 0
44798- 14 14 14 42 42 42 86 86 86 10 10 10
44799- 2 2 6 2 2 6 2 2 6 2 2 6
44800- 2 2 6 2 2 6 2 2 6 2 2 6
44801- 2 2 6 2 2 6 2 2 6 30 30 30
44802- 94 94 94 94 94 94 58 58 58 26 26 26
44803- 2 2 6 6 6 6 78 78 78 54 54 54
44804- 22 22 22 6 6 6 0 0 0 0 0 0
44805- 0 0 0 0 0 0 0 0 0 0 0 0
44806- 0 0 0 0 0 0 0 0 0 0 0 0
44807- 0 0 0 0 0 0 0 0 0 0 0 0
44808- 0 0 0 0 0 0 0 0 0 0 0 0
44809- 0 0 0 0 0 0 0 0 0 0 0 0
44810- 0 0 0 0 0 0 0 0 0 0 0 0
44811- 0 0 0 0 0 0 0 0 0 0 0 0
44812- 0 0 0 0 0 0 0 0 0 0 0 0
44813- 0 0 0 0 0 0 0 0 0 0 0 0
44814- 0 0 0 0 0 0 0 0 0 0 0 0
44815- 0 0 0 0 0 0 0 0 0 0 0 0
44816- 0 0 0 0 0 0 0 0 0 0 0 0
44817- 0 0 0 0 0 0 0 0 0 6 6 6
44818- 22 22 22 62 62 62 62 62 62 2 2 6
44819- 2 2 6 2 2 6 2 2 6 2 2 6
44820- 2 2 6 2 2 6 2 2 6 2 2 6
44821- 2 2 6 2 2 6 2 2 6 26 26 26
44822- 54 54 54 38 38 38 18 18 18 10 10 10
44823- 2 2 6 2 2 6 34 34 34 82 82 82
44824- 38 38 38 14 14 14 0 0 0 0 0 0
44825- 0 0 0 0 0 0 0 0 0 0 0 0
44826- 0 0 0 0 0 0 0 0 0 0 0 0
44827- 0 0 0 0 0 0 0 0 0 0 0 0
44828- 0 0 0 0 0 0 0 0 0 0 0 0
44829- 0 0 0 0 0 0 0 0 0 0 0 0
44830- 0 0 0 0 0 0 0 0 0 0 0 0
44831- 0 0 0 0 0 0 0 0 0 0 0 0
44832- 0 0 0 0 0 1 0 0 1 0 0 0
44833- 0 0 0 0 0 0 0 0 0 0 0 0
44834- 0 0 0 0 0 0 0 0 0 0 0 0
44835- 0 0 0 0 0 0 0 0 0 0 0 0
44836- 0 0 0 0 0 0 0 0 0 0 0 0
44837- 0 0 0 0 0 0 0 0 0 6 6 6
44838- 30 30 30 78 78 78 30 30 30 2 2 6
44839- 2 2 6 2 2 6 2 2 6 2 2 6
44840- 2 2 6 2 2 6 2 2 6 2 2 6
44841- 2 2 6 2 2 6 2 2 6 10 10 10
44842- 10 10 10 2 2 6 2 2 6 2 2 6
44843- 2 2 6 2 2 6 2 2 6 78 78 78
44844- 50 50 50 18 18 18 6 6 6 0 0 0
44845- 0 0 0 0 0 0 0 0 0 0 0 0
44846- 0 0 0 0 0 0 0 0 0 0 0 0
44847- 0 0 0 0 0 0 0 0 0 0 0 0
44848- 0 0 0 0 0 0 0 0 0 0 0 0
44849- 0 0 0 0 0 0 0 0 0 0 0 0
44850- 0 0 0 0 0 0 0 0 0 0 0 0
44851- 0 0 0 0 0 0 0 0 0 0 0 0
44852- 0 0 1 0 0 0 0 0 0 0 0 0
44853- 0 0 0 0 0 0 0 0 0 0 0 0
44854- 0 0 0 0 0 0 0 0 0 0 0 0
44855- 0 0 0 0 0 0 0 0 0 0 0 0
44856- 0 0 0 0 0 0 0 0 0 0 0 0
44857- 0 0 0 0 0 0 0 0 0 10 10 10
44858- 38 38 38 86 86 86 14 14 14 2 2 6
44859- 2 2 6 2 2 6 2 2 6 2 2 6
44860- 2 2 6 2 2 6 2 2 6 2 2 6
44861- 2 2 6 2 2 6 2 2 6 2 2 6
44862- 2 2 6 2 2 6 2 2 6 2 2 6
44863- 2 2 6 2 2 6 2 2 6 54 54 54
44864- 66 66 66 26 26 26 6 6 6 0 0 0
44865- 0 0 0 0 0 0 0 0 0 0 0 0
44866- 0 0 0 0 0 0 0 0 0 0 0 0
44867- 0 0 0 0 0 0 0 0 0 0 0 0
44868- 0 0 0 0 0 0 0 0 0 0 0 0
44869- 0 0 0 0 0 0 0 0 0 0 0 0
44870- 0 0 0 0 0 0 0 0 0 0 0 0
44871- 0 0 0 0 0 0 0 0 0 0 0 0
44872- 0 0 0 0 0 1 0 0 1 0 0 0
44873- 0 0 0 0 0 0 0 0 0 0 0 0
44874- 0 0 0 0 0 0 0 0 0 0 0 0
44875- 0 0 0 0 0 0 0 0 0 0 0 0
44876- 0 0 0 0 0 0 0 0 0 0 0 0
44877- 0 0 0 0 0 0 0 0 0 14 14 14
44878- 42 42 42 82 82 82 2 2 6 2 2 6
44879- 2 2 6 6 6 6 10 10 10 2 2 6
44880- 2 2 6 2 2 6 2 2 6 2 2 6
44881- 2 2 6 2 2 6 2 2 6 6 6 6
44882- 14 14 14 10 10 10 2 2 6 2 2 6
44883- 2 2 6 2 2 6 2 2 6 18 18 18
44884- 82 82 82 34 34 34 10 10 10 0 0 0
44885- 0 0 0 0 0 0 0 0 0 0 0 0
44886- 0 0 0 0 0 0 0 0 0 0 0 0
44887- 0 0 0 0 0 0 0 0 0 0 0 0
44888- 0 0 0 0 0 0 0 0 0 0 0 0
44889- 0 0 0 0 0 0 0 0 0 0 0 0
44890- 0 0 0 0 0 0 0 0 0 0 0 0
44891- 0 0 0 0 0 0 0 0 0 0 0 0
44892- 0 0 1 0 0 0 0 0 0 0 0 0
44893- 0 0 0 0 0 0 0 0 0 0 0 0
44894- 0 0 0 0 0 0 0 0 0 0 0 0
44895- 0 0 0 0 0 0 0 0 0 0 0 0
44896- 0 0 0 0 0 0 0 0 0 0 0 0
44897- 0 0 0 0 0 0 0 0 0 14 14 14
44898- 46 46 46 86 86 86 2 2 6 2 2 6
44899- 6 6 6 6 6 6 22 22 22 34 34 34
44900- 6 6 6 2 2 6 2 2 6 2 2 6
44901- 2 2 6 2 2 6 18 18 18 34 34 34
44902- 10 10 10 50 50 50 22 22 22 2 2 6
44903- 2 2 6 2 2 6 2 2 6 10 10 10
44904- 86 86 86 42 42 42 14 14 14 0 0 0
44905- 0 0 0 0 0 0 0 0 0 0 0 0
44906- 0 0 0 0 0 0 0 0 0 0 0 0
44907- 0 0 0 0 0 0 0 0 0 0 0 0
44908- 0 0 0 0 0 0 0 0 0 0 0 0
44909- 0 0 0 0 0 0 0 0 0 0 0 0
44910- 0 0 0 0 0 0 0 0 0 0 0 0
44911- 0 0 0 0 0 0 0 0 0 0 0 0
44912- 0 0 1 0 0 1 0 0 1 0 0 0
44913- 0 0 0 0 0 0 0 0 0 0 0 0
44914- 0 0 0 0 0 0 0 0 0 0 0 0
44915- 0 0 0 0 0 0 0 0 0 0 0 0
44916- 0 0 0 0 0 0 0 0 0 0 0 0
44917- 0 0 0 0 0 0 0 0 0 14 14 14
44918- 46 46 46 86 86 86 2 2 6 2 2 6
44919- 38 38 38 116 116 116 94 94 94 22 22 22
44920- 22 22 22 2 2 6 2 2 6 2 2 6
44921- 14 14 14 86 86 86 138 138 138 162 162 162
44922-154 154 154 38 38 38 26 26 26 6 6 6
44923- 2 2 6 2 2 6 2 2 6 2 2 6
44924- 86 86 86 46 46 46 14 14 14 0 0 0
44925- 0 0 0 0 0 0 0 0 0 0 0 0
44926- 0 0 0 0 0 0 0 0 0 0 0 0
44927- 0 0 0 0 0 0 0 0 0 0 0 0
44928- 0 0 0 0 0 0 0 0 0 0 0 0
44929- 0 0 0 0 0 0 0 0 0 0 0 0
44930- 0 0 0 0 0 0 0 0 0 0 0 0
44931- 0 0 0 0 0 0 0 0 0 0 0 0
44932- 0 0 0 0 0 0 0 0 0 0 0 0
44933- 0 0 0 0 0 0 0 0 0 0 0 0
44934- 0 0 0 0 0 0 0 0 0 0 0 0
44935- 0 0 0 0 0 0 0 0 0 0 0 0
44936- 0 0 0 0 0 0 0 0 0 0 0 0
44937- 0 0 0 0 0 0 0 0 0 14 14 14
44938- 46 46 46 86 86 86 2 2 6 14 14 14
44939-134 134 134 198 198 198 195 195 195 116 116 116
44940- 10 10 10 2 2 6 2 2 6 6 6 6
44941-101 98 89 187 187 187 210 210 210 218 218 218
44942-214 214 214 134 134 134 14 14 14 6 6 6
44943- 2 2 6 2 2 6 2 2 6 2 2 6
44944- 86 86 86 50 50 50 18 18 18 6 6 6
44945- 0 0 0 0 0 0 0 0 0 0 0 0
44946- 0 0 0 0 0 0 0 0 0 0 0 0
44947- 0 0 0 0 0 0 0 0 0 0 0 0
44948- 0 0 0 0 0 0 0 0 0 0 0 0
44949- 0 0 0 0 0 0 0 0 0 0 0 0
44950- 0 0 0 0 0 0 0 0 0 0 0 0
44951- 0 0 0 0 0 0 0 0 1 0 0 0
44952- 0 0 1 0 0 1 0 0 1 0 0 0
44953- 0 0 0 0 0 0 0 0 0 0 0 0
44954- 0 0 0 0 0 0 0 0 0 0 0 0
44955- 0 0 0 0 0 0 0 0 0 0 0 0
44956- 0 0 0 0 0 0 0 0 0 0 0 0
44957- 0 0 0 0 0 0 0 0 0 14 14 14
44958- 46 46 46 86 86 86 2 2 6 54 54 54
44959-218 218 218 195 195 195 226 226 226 246 246 246
44960- 58 58 58 2 2 6 2 2 6 30 30 30
44961-210 210 210 253 253 253 174 174 174 123 123 123
44962-221 221 221 234 234 234 74 74 74 2 2 6
44963- 2 2 6 2 2 6 2 2 6 2 2 6
44964- 70 70 70 58 58 58 22 22 22 6 6 6
44965- 0 0 0 0 0 0 0 0 0 0 0 0
44966- 0 0 0 0 0 0 0 0 0 0 0 0
44967- 0 0 0 0 0 0 0 0 0 0 0 0
44968- 0 0 0 0 0 0 0 0 0 0 0 0
44969- 0 0 0 0 0 0 0 0 0 0 0 0
44970- 0 0 0 0 0 0 0 0 0 0 0 0
44971- 0 0 0 0 0 0 0 0 0 0 0 0
44972- 0 0 0 0 0 0 0 0 0 0 0 0
44973- 0 0 0 0 0 0 0 0 0 0 0 0
44974- 0 0 0 0 0 0 0 0 0 0 0 0
44975- 0 0 0 0 0 0 0 0 0 0 0 0
44976- 0 0 0 0 0 0 0 0 0 0 0 0
44977- 0 0 0 0 0 0 0 0 0 14 14 14
44978- 46 46 46 82 82 82 2 2 6 106 106 106
44979-170 170 170 26 26 26 86 86 86 226 226 226
44980-123 123 123 10 10 10 14 14 14 46 46 46
44981-231 231 231 190 190 190 6 6 6 70 70 70
44982- 90 90 90 238 238 238 158 158 158 2 2 6
44983- 2 2 6 2 2 6 2 2 6 2 2 6
44984- 70 70 70 58 58 58 22 22 22 6 6 6
44985- 0 0 0 0 0 0 0 0 0 0 0 0
44986- 0 0 0 0 0 0 0 0 0 0 0 0
44987- 0 0 0 0 0 0 0 0 0 0 0 0
44988- 0 0 0 0 0 0 0 0 0 0 0 0
44989- 0 0 0 0 0 0 0 0 0 0 0 0
44990- 0 0 0 0 0 0 0 0 0 0 0 0
44991- 0 0 0 0 0 0 0 0 1 0 0 0
44992- 0 0 1 0 0 1 0 0 1 0 0 0
44993- 0 0 0 0 0 0 0 0 0 0 0 0
44994- 0 0 0 0 0 0 0 0 0 0 0 0
44995- 0 0 0 0 0 0 0 0 0 0 0 0
44996- 0 0 0 0 0 0 0 0 0 0 0 0
44997- 0 0 0 0 0 0 0 0 0 14 14 14
44998- 42 42 42 86 86 86 6 6 6 116 116 116
44999-106 106 106 6 6 6 70 70 70 149 149 149
45000-128 128 128 18 18 18 38 38 38 54 54 54
45001-221 221 221 106 106 106 2 2 6 14 14 14
45002- 46 46 46 190 190 190 198 198 198 2 2 6
45003- 2 2 6 2 2 6 2 2 6 2 2 6
45004- 74 74 74 62 62 62 22 22 22 6 6 6
45005- 0 0 0 0 0 0 0 0 0 0 0 0
45006- 0 0 0 0 0 0 0 0 0 0 0 0
45007- 0 0 0 0 0 0 0 0 0 0 0 0
45008- 0 0 0 0 0 0 0 0 0 0 0 0
45009- 0 0 0 0 0 0 0 0 0 0 0 0
45010- 0 0 0 0 0 0 0 0 0 0 0 0
45011- 0 0 0 0 0 0 0 0 1 0 0 0
45012- 0 0 1 0 0 0 0 0 1 0 0 0
45013- 0 0 0 0 0 0 0 0 0 0 0 0
45014- 0 0 0 0 0 0 0 0 0 0 0 0
45015- 0 0 0 0 0 0 0 0 0 0 0 0
45016- 0 0 0 0 0 0 0 0 0 0 0 0
45017- 0 0 0 0 0 0 0 0 0 14 14 14
45018- 42 42 42 94 94 94 14 14 14 101 101 101
45019-128 128 128 2 2 6 18 18 18 116 116 116
45020-118 98 46 121 92 8 121 92 8 98 78 10
45021-162 162 162 106 106 106 2 2 6 2 2 6
45022- 2 2 6 195 195 195 195 195 195 6 6 6
45023- 2 2 6 2 2 6 2 2 6 2 2 6
45024- 74 74 74 62 62 62 22 22 22 6 6 6
45025- 0 0 0 0 0 0 0 0 0 0 0 0
45026- 0 0 0 0 0 0 0 0 0 0 0 0
45027- 0 0 0 0 0 0 0 0 0 0 0 0
45028- 0 0 0 0 0 0 0 0 0 0 0 0
45029- 0 0 0 0 0 0 0 0 0 0 0 0
45030- 0 0 0 0 0 0 0 0 0 0 0 0
45031- 0 0 0 0 0 0 0 0 1 0 0 1
45032- 0 0 1 0 0 0 0 0 1 0 0 0
45033- 0 0 0 0 0 0 0 0 0 0 0 0
45034- 0 0 0 0 0 0 0 0 0 0 0 0
45035- 0 0 0 0 0 0 0 0 0 0 0 0
45036- 0 0 0 0 0 0 0 0 0 0 0 0
45037- 0 0 0 0 0 0 0 0 0 10 10 10
45038- 38 38 38 90 90 90 14 14 14 58 58 58
45039-210 210 210 26 26 26 54 38 6 154 114 10
45040-226 170 11 236 186 11 225 175 15 184 144 12
45041-215 174 15 175 146 61 37 26 9 2 2 6
45042- 70 70 70 246 246 246 138 138 138 2 2 6
45043- 2 2 6 2 2 6 2 2 6 2 2 6
45044- 70 70 70 66 66 66 26 26 26 6 6 6
45045- 0 0 0 0 0 0 0 0 0 0 0 0
45046- 0 0 0 0 0 0 0 0 0 0 0 0
45047- 0 0 0 0 0 0 0 0 0 0 0 0
45048- 0 0 0 0 0 0 0 0 0 0 0 0
45049- 0 0 0 0 0 0 0 0 0 0 0 0
45050- 0 0 0 0 0 0 0 0 0 0 0 0
45051- 0 0 0 0 0 0 0 0 0 0 0 0
45052- 0 0 0 0 0 0 0 0 0 0 0 0
45053- 0 0 0 0 0 0 0 0 0 0 0 0
45054- 0 0 0 0 0 0 0 0 0 0 0 0
45055- 0 0 0 0 0 0 0 0 0 0 0 0
45056- 0 0 0 0 0 0 0 0 0 0 0 0
45057- 0 0 0 0 0 0 0 0 0 10 10 10
45058- 38 38 38 86 86 86 14 14 14 10 10 10
45059-195 195 195 188 164 115 192 133 9 225 175 15
45060-239 182 13 234 190 10 232 195 16 232 200 30
45061-245 207 45 241 208 19 232 195 16 184 144 12
45062-218 194 134 211 206 186 42 42 42 2 2 6
45063- 2 2 6 2 2 6 2 2 6 2 2 6
45064- 50 50 50 74 74 74 30 30 30 6 6 6
45065- 0 0 0 0 0 0 0 0 0 0 0 0
45066- 0 0 0 0 0 0 0 0 0 0 0 0
45067- 0 0 0 0 0 0 0 0 0 0 0 0
45068- 0 0 0 0 0 0 0 0 0 0 0 0
45069- 0 0 0 0 0 0 0 0 0 0 0 0
45070- 0 0 0 0 0 0 0 0 0 0 0 0
45071- 0 0 0 0 0 0 0 0 0 0 0 0
45072- 0 0 0 0 0 0 0 0 0 0 0 0
45073- 0 0 0 0 0 0 0 0 0 0 0 0
45074- 0 0 0 0 0 0 0 0 0 0 0 0
45075- 0 0 0 0 0 0 0 0 0 0 0 0
45076- 0 0 0 0 0 0 0 0 0 0 0 0
45077- 0 0 0 0 0 0 0 0 0 10 10 10
45078- 34 34 34 86 86 86 14 14 14 2 2 6
45079-121 87 25 192 133 9 219 162 10 239 182 13
45080-236 186 11 232 195 16 241 208 19 244 214 54
45081-246 218 60 246 218 38 246 215 20 241 208 19
45082-241 208 19 226 184 13 121 87 25 2 2 6
45083- 2 2 6 2 2 6 2 2 6 2 2 6
45084- 50 50 50 82 82 82 34 34 34 10 10 10
45085- 0 0 0 0 0 0 0 0 0 0 0 0
45086- 0 0 0 0 0 0 0 0 0 0 0 0
45087- 0 0 0 0 0 0 0 0 0 0 0 0
45088- 0 0 0 0 0 0 0 0 0 0 0 0
45089- 0 0 0 0 0 0 0 0 0 0 0 0
45090- 0 0 0 0 0 0 0 0 0 0 0 0
45091- 0 0 0 0 0 0 0 0 0 0 0 0
45092- 0 0 0 0 0 0 0 0 0 0 0 0
45093- 0 0 0 0 0 0 0 0 0 0 0 0
45094- 0 0 0 0 0 0 0 0 0 0 0 0
45095- 0 0 0 0 0 0 0 0 0 0 0 0
45096- 0 0 0 0 0 0 0 0 0 0 0 0
45097- 0 0 0 0 0 0 0 0 0 10 10 10
45098- 34 34 34 82 82 82 30 30 30 61 42 6
45099-180 123 7 206 145 10 230 174 11 239 182 13
45100-234 190 10 238 202 15 241 208 19 246 218 74
45101-246 218 38 246 215 20 246 215 20 246 215 20
45102-226 184 13 215 174 15 184 144 12 6 6 6
45103- 2 2 6 2 2 6 2 2 6 2 2 6
45104- 26 26 26 94 94 94 42 42 42 14 14 14
45105- 0 0 0 0 0 0 0 0 0 0 0 0
45106- 0 0 0 0 0 0 0 0 0 0 0 0
45107- 0 0 0 0 0 0 0 0 0 0 0 0
45108- 0 0 0 0 0 0 0 0 0 0 0 0
45109- 0 0 0 0 0 0 0 0 0 0 0 0
45110- 0 0 0 0 0 0 0 0 0 0 0 0
45111- 0 0 0 0 0 0 0 0 0 0 0 0
45112- 0 0 0 0 0 0 0 0 0 0 0 0
45113- 0 0 0 0 0 0 0 0 0 0 0 0
45114- 0 0 0 0 0 0 0 0 0 0 0 0
45115- 0 0 0 0 0 0 0 0 0 0 0 0
45116- 0 0 0 0 0 0 0 0 0 0 0 0
45117- 0 0 0 0 0 0 0 0 0 10 10 10
45118- 30 30 30 78 78 78 50 50 50 104 69 6
45119-192 133 9 216 158 10 236 178 12 236 186 11
45120-232 195 16 241 208 19 244 214 54 245 215 43
45121-246 215 20 246 215 20 241 208 19 198 155 10
45122-200 144 11 216 158 10 156 118 10 2 2 6
45123- 2 2 6 2 2 6 2 2 6 2 2 6
45124- 6 6 6 90 90 90 54 54 54 18 18 18
45125- 6 6 6 0 0 0 0 0 0 0 0 0
45126- 0 0 0 0 0 0 0 0 0 0 0 0
45127- 0 0 0 0 0 0 0 0 0 0 0 0
45128- 0 0 0 0 0 0 0 0 0 0 0 0
45129- 0 0 0 0 0 0 0 0 0 0 0 0
45130- 0 0 0 0 0 0 0 0 0 0 0 0
45131- 0 0 0 0 0 0 0 0 0 0 0 0
45132- 0 0 0 0 0 0 0 0 0 0 0 0
45133- 0 0 0 0 0 0 0 0 0 0 0 0
45134- 0 0 0 0 0 0 0 0 0 0 0 0
45135- 0 0 0 0 0 0 0 0 0 0 0 0
45136- 0 0 0 0 0 0 0 0 0 0 0 0
45137- 0 0 0 0 0 0 0 0 0 10 10 10
45138- 30 30 30 78 78 78 46 46 46 22 22 22
45139-137 92 6 210 162 10 239 182 13 238 190 10
45140-238 202 15 241 208 19 246 215 20 246 215 20
45141-241 208 19 203 166 17 185 133 11 210 150 10
45142-216 158 10 210 150 10 102 78 10 2 2 6
45143- 6 6 6 54 54 54 14 14 14 2 2 6
45144- 2 2 6 62 62 62 74 74 74 30 30 30
45145- 10 10 10 0 0 0 0 0 0 0 0 0
45146- 0 0 0 0 0 0 0 0 0 0 0 0
45147- 0 0 0 0 0 0 0 0 0 0 0 0
45148- 0 0 0 0 0 0 0 0 0 0 0 0
45149- 0 0 0 0 0 0 0 0 0 0 0 0
45150- 0 0 0 0 0 0 0 0 0 0 0 0
45151- 0 0 0 0 0 0 0 0 0 0 0 0
45152- 0 0 0 0 0 0 0 0 0 0 0 0
45153- 0 0 0 0 0 0 0 0 0 0 0 0
45154- 0 0 0 0 0 0 0 0 0 0 0 0
45155- 0 0 0 0 0 0 0 0 0 0 0 0
45156- 0 0 0 0 0 0 0 0 0 0 0 0
45157- 0 0 0 0 0 0 0 0 0 10 10 10
45158- 34 34 34 78 78 78 50 50 50 6 6 6
45159- 94 70 30 139 102 15 190 146 13 226 184 13
45160-232 200 30 232 195 16 215 174 15 190 146 13
45161-168 122 10 192 133 9 210 150 10 213 154 11
45162-202 150 34 182 157 106 101 98 89 2 2 6
45163- 2 2 6 78 78 78 116 116 116 58 58 58
45164- 2 2 6 22 22 22 90 90 90 46 46 46
45165- 18 18 18 6 6 6 0 0 0 0 0 0
45166- 0 0 0 0 0 0 0 0 0 0 0 0
45167- 0 0 0 0 0 0 0 0 0 0 0 0
45168- 0 0 0 0 0 0 0 0 0 0 0 0
45169- 0 0 0 0 0 0 0 0 0 0 0 0
45170- 0 0 0 0 0 0 0 0 0 0 0 0
45171- 0 0 0 0 0 0 0 0 0 0 0 0
45172- 0 0 0 0 0 0 0 0 0 0 0 0
45173- 0 0 0 0 0 0 0 0 0 0 0 0
45174- 0 0 0 0 0 0 0 0 0 0 0 0
45175- 0 0 0 0 0 0 0 0 0 0 0 0
45176- 0 0 0 0 0 0 0 0 0 0 0 0
45177- 0 0 0 0 0 0 0 0 0 10 10 10
45178- 38 38 38 86 86 86 50 50 50 6 6 6
45179-128 128 128 174 154 114 156 107 11 168 122 10
45180-198 155 10 184 144 12 197 138 11 200 144 11
45181-206 145 10 206 145 10 197 138 11 188 164 115
45182-195 195 195 198 198 198 174 174 174 14 14 14
45183- 2 2 6 22 22 22 116 116 116 116 116 116
45184- 22 22 22 2 2 6 74 74 74 70 70 70
45185- 30 30 30 10 10 10 0 0 0 0 0 0
45186- 0 0 0 0 0 0 0 0 0 0 0 0
45187- 0 0 0 0 0 0 0 0 0 0 0 0
45188- 0 0 0 0 0 0 0 0 0 0 0 0
45189- 0 0 0 0 0 0 0 0 0 0 0 0
45190- 0 0 0 0 0 0 0 0 0 0 0 0
45191- 0 0 0 0 0 0 0 0 0 0 0 0
45192- 0 0 0 0 0 0 0 0 0 0 0 0
45193- 0 0 0 0 0 0 0 0 0 0 0 0
45194- 0 0 0 0 0 0 0 0 0 0 0 0
45195- 0 0 0 0 0 0 0 0 0 0 0 0
45196- 0 0 0 0 0 0 0 0 0 0 0 0
45197- 0 0 0 0 0 0 6 6 6 18 18 18
45198- 50 50 50 101 101 101 26 26 26 10 10 10
45199-138 138 138 190 190 190 174 154 114 156 107 11
45200-197 138 11 200 144 11 197 138 11 192 133 9
45201-180 123 7 190 142 34 190 178 144 187 187 187
45202-202 202 202 221 221 221 214 214 214 66 66 66
45203- 2 2 6 2 2 6 50 50 50 62 62 62
45204- 6 6 6 2 2 6 10 10 10 90 90 90
45205- 50 50 50 18 18 18 6 6 6 0 0 0
45206- 0 0 0 0 0 0 0 0 0 0 0 0
45207- 0 0 0 0 0 0 0 0 0 0 0 0
45208- 0 0 0 0 0 0 0 0 0 0 0 0
45209- 0 0 0 0 0 0 0 0 0 0 0 0
45210- 0 0 0 0 0 0 0 0 0 0 0 0
45211- 0 0 0 0 0 0 0 0 0 0 0 0
45212- 0 0 0 0 0 0 0 0 0 0 0 0
45213- 0 0 0 0 0 0 0 0 0 0 0 0
45214- 0 0 0 0 0 0 0 0 0 0 0 0
45215- 0 0 0 0 0 0 0 0 0 0 0 0
45216- 0 0 0 0 0 0 0 0 0 0 0 0
45217- 0 0 0 0 0 0 10 10 10 34 34 34
45218- 74 74 74 74 74 74 2 2 6 6 6 6
45219-144 144 144 198 198 198 190 190 190 178 166 146
45220-154 121 60 156 107 11 156 107 11 168 124 44
45221-174 154 114 187 187 187 190 190 190 210 210 210
45222-246 246 246 253 253 253 253 253 253 182 182 182
45223- 6 6 6 2 2 6 2 2 6 2 2 6
45224- 2 2 6 2 2 6 2 2 6 62 62 62
45225- 74 74 74 34 34 34 14 14 14 0 0 0
45226- 0 0 0 0 0 0 0 0 0 0 0 0
45227- 0 0 0 0 0 0 0 0 0 0 0 0
45228- 0 0 0 0 0 0 0 0 0 0 0 0
45229- 0 0 0 0 0 0 0 0 0 0 0 0
45230- 0 0 0 0 0 0 0 0 0 0 0 0
45231- 0 0 0 0 0 0 0 0 0 0 0 0
45232- 0 0 0 0 0 0 0 0 0 0 0 0
45233- 0 0 0 0 0 0 0 0 0 0 0 0
45234- 0 0 0 0 0 0 0 0 0 0 0 0
45235- 0 0 0 0 0 0 0 0 0 0 0 0
45236- 0 0 0 0 0 0 0 0 0 0 0 0
45237- 0 0 0 10 10 10 22 22 22 54 54 54
45238- 94 94 94 18 18 18 2 2 6 46 46 46
45239-234 234 234 221 221 221 190 190 190 190 190 190
45240-190 190 190 187 187 187 187 187 187 190 190 190
45241-190 190 190 195 195 195 214 214 214 242 242 242
45242-253 253 253 253 253 253 253 253 253 253 253 253
45243- 82 82 82 2 2 6 2 2 6 2 2 6
45244- 2 2 6 2 2 6 2 2 6 14 14 14
45245- 86 86 86 54 54 54 22 22 22 6 6 6
45246- 0 0 0 0 0 0 0 0 0 0 0 0
45247- 0 0 0 0 0 0 0 0 0 0 0 0
45248- 0 0 0 0 0 0 0 0 0 0 0 0
45249- 0 0 0 0 0 0 0 0 0 0 0 0
45250- 0 0 0 0 0 0 0 0 0 0 0 0
45251- 0 0 0 0 0 0 0 0 0 0 0 0
45252- 0 0 0 0 0 0 0 0 0 0 0 0
45253- 0 0 0 0 0 0 0 0 0 0 0 0
45254- 0 0 0 0 0 0 0 0 0 0 0 0
45255- 0 0 0 0 0 0 0 0 0 0 0 0
45256- 0 0 0 0 0 0 0 0 0 0 0 0
45257- 6 6 6 18 18 18 46 46 46 90 90 90
45258- 46 46 46 18 18 18 6 6 6 182 182 182
45259-253 253 253 246 246 246 206 206 206 190 190 190
45260-190 190 190 190 190 190 190 190 190 190 190 190
45261-206 206 206 231 231 231 250 250 250 253 253 253
45262-253 253 253 253 253 253 253 253 253 253 253 253
45263-202 202 202 14 14 14 2 2 6 2 2 6
45264- 2 2 6 2 2 6 2 2 6 2 2 6
45265- 42 42 42 86 86 86 42 42 42 18 18 18
45266- 6 6 6 0 0 0 0 0 0 0 0 0
45267- 0 0 0 0 0 0 0 0 0 0 0 0
45268- 0 0 0 0 0 0 0 0 0 0 0 0
45269- 0 0 0 0 0 0 0 0 0 0 0 0
45270- 0 0 0 0 0 0 0 0 0 0 0 0
45271- 0 0 0 0 0 0 0 0 0 0 0 0
45272- 0 0 0 0 0 0 0 0 0 0 0 0
45273- 0 0 0 0 0 0 0 0 0 0 0 0
45274- 0 0 0 0 0 0 0 0 0 0 0 0
45275- 0 0 0 0 0 0 0 0 0 0 0 0
45276- 0 0 0 0 0 0 0 0 0 6 6 6
45277- 14 14 14 38 38 38 74 74 74 66 66 66
45278- 2 2 6 6 6 6 90 90 90 250 250 250
45279-253 253 253 253 253 253 238 238 238 198 198 198
45280-190 190 190 190 190 190 195 195 195 221 221 221
45281-246 246 246 253 253 253 253 253 253 253 253 253
45282-253 253 253 253 253 253 253 253 253 253 253 253
45283-253 253 253 82 82 82 2 2 6 2 2 6
45284- 2 2 6 2 2 6 2 2 6 2 2 6
45285- 2 2 6 78 78 78 70 70 70 34 34 34
45286- 14 14 14 6 6 6 0 0 0 0 0 0
45287- 0 0 0 0 0 0 0 0 0 0 0 0
45288- 0 0 0 0 0 0 0 0 0 0 0 0
45289- 0 0 0 0 0 0 0 0 0 0 0 0
45290- 0 0 0 0 0 0 0 0 0 0 0 0
45291- 0 0 0 0 0 0 0 0 0 0 0 0
45292- 0 0 0 0 0 0 0 0 0 0 0 0
45293- 0 0 0 0 0 0 0 0 0 0 0 0
45294- 0 0 0 0 0 0 0 0 0 0 0 0
45295- 0 0 0 0 0 0 0 0 0 0 0 0
45296- 0 0 0 0 0 0 0 0 0 14 14 14
45297- 34 34 34 66 66 66 78 78 78 6 6 6
45298- 2 2 6 18 18 18 218 218 218 253 253 253
45299-253 253 253 253 253 253 253 253 253 246 246 246
45300-226 226 226 231 231 231 246 246 246 253 253 253
45301-253 253 253 253 253 253 253 253 253 253 253 253
45302-253 253 253 253 253 253 253 253 253 253 253 253
45303-253 253 253 178 178 178 2 2 6 2 2 6
45304- 2 2 6 2 2 6 2 2 6 2 2 6
45305- 2 2 6 18 18 18 90 90 90 62 62 62
45306- 30 30 30 10 10 10 0 0 0 0 0 0
45307- 0 0 0 0 0 0 0 0 0 0 0 0
45308- 0 0 0 0 0 0 0 0 0 0 0 0
45309- 0 0 0 0 0 0 0 0 0 0 0 0
45310- 0 0 0 0 0 0 0 0 0 0 0 0
45311- 0 0 0 0 0 0 0 0 0 0 0 0
45312- 0 0 0 0 0 0 0 0 0 0 0 0
45313- 0 0 0 0 0 0 0 0 0 0 0 0
45314- 0 0 0 0 0 0 0 0 0 0 0 0
45315- 0 0 0 0 0 0 0 0 0 0 0 0
45316- 0 0 0 0 0 0 10 10 10 26 26 26
45317- 58 58 58 90 90 90 18 18 18 2 2 6
45318- 2 2 6 110 110 110 253 253 253 253 253 253
45319-253 253 253 253 253 253 253 253 253 253 253 253
45320-250 250 250 253 253 253 253 253 253 253 253 253
45321-253 253 253 253 253 253 253 253 253 253 253 253
45322-253 253 253 253 253 253 253 253 253 253 253 253
45323-253 253 253 231 231 231 18 18 18 2 2 6
45324- 2 2 6 2 2 6 2 2 6 2 2 6
45325- 2 2 6 2 2 6 18 18 18 94 94 94
45326- 54 54 54 26 26 26 10 10 10 0 0 0
45327- 0 0 0 0 0 0 0 0 0 0 0 0
45328- 0 0 0 0 0 0 0 0 0 0 0 0
45329- 0 0 0 0 0 0 0 0 0 0 0 0
45330- 0 0 0 0 0 0 0 0 0 0 0 0
45331- 0 0 0 0 0 0 0 0 0 0 0 0
45332- 0 0 0 0 0 0 0 0 0 0 0 0
45333- 0 0 0 0 0 0 0 0 0 0 0 0
45334- 0 0 0 0 0 0 0 0 0 0 0 0
45335- 0 0 0 0 0 0 0 0 0 0 0 0
45336- 0 0 0 6 6 6 22 22 22 50 50 50
45337- 90 90 90 26 26 26 2 2 6 2 2 6
45338- 14 14 14 195 195 195 250 250 250 253 253 253
45339-253 253 253 253 253 253 253 253 253 253 253 253
45340-253 253 253 253 253 253 253 253 253 253 253 253
45341-253 253 253 253 253 253 253 253 253 253 253 253
45342-253 253 253 253 253 253 253 253 253 253 253 253
45343-250 250 250 242 242 242 54 54 54 2 2 6
45344- 2 2 6 2 2 6 2 2 6 2 2 6
45345- 2 2 6 2 2 6 2 2 6 38 38 38
45346- 86 86 86 50 50 50 22 22 22 6 6 6
45347- 0 0 0 0 0 0 0 0 0 0 0 0
45348- 0 0 0 0 0 0 0 0 0 0 0 0
45349- 0 0 0 0 0 0 0 0 0 0 0 0
45350- 0 0 0 0 0 0 0 0 0 0 0 0
45351- 0 0 0 0 0 0 0 0 0 0 0 0
45352- 0 0 0 0 0 0 0 0 0 0 0 0
45353- 0 0 0 0 0 0 0 0 0 0 0 0
45354- 0 0 0 0 0 0 0 0 0 0 0 0
45355- 0 0 0 0 0 0 0 0 0 0 0 0
45356- 6 6 6 14 14 14 38 38 38 82 82 82
45357- 34 34 34 2 2 6 2 2 6 2 2 6
45358- 42 42 42 195 195 195 246 246 246 253 253 253
45359-253 253 253 253 253 253 253 253 253 250 250 250
45360-242 242 242 242 242 242 250 250 250 253 253 253
45361-253 253 253 253 253 253 253 253 253 253 253 253
45362-253 253 253 250 250 250 246 246 246 238 238 238
45363-226 226 226 231 231 231 101 101 101 6 6 6
45364- 2 2 6 2 2 6 2 2 6 2 2 6
45365- 2 2 6 2 2 6 2 2 6 2 2 6
45366- 38 38 38 82 82 82 42 42 42 14 14 14
45367- 6 6 6 0 0 0 0 0 0 0 0 0
45368- 0 0 0 0 0 0 0 0 0 0 0 0
45369- 0 0 0 0 0 0 0 0 0 0 0 0
45370- 0 0 0 0 0 0 0 0 0 0 0 0
45371- 0 0 0 0 0 0 0 0 0 0 0 0
45372- 0 0 0 0 0 0 0 0 0 0 0 0
45373- 0 0 0 0 0 0 0 0 0 0 0 0
45374- 0 0 0 0 0 0 0 0 0 0 0 0
45375- 0 0 0 0 0 0 0 0 0 0 0 0
45376- 10 10 10 26 26 26 62 62 62 66 66 66
45377- 2 2 6 2 2 6 2 2 6 6 6 6
45378- 70 70 70 170 170 170 206 206 206 234 234 234
45379-246 246 246 250 250 250 250 250 250 238 238 238
45380-226 226 226 231 231 231 238 238 238 250 250 250
45381-250 250 250 250 250 250 246 246 246 231 231 231
45382-214 214 214 206 206 206 202 202 202 202 202 202
45383-198 198 198 202 202 202 182 182 182 18 18 18
45384- 2 2 6 2 2 6 2 2 6 2 2 6
45385- 2 2 6 2 2 6 2 2 6 2 2 6
45386- 2 2 6 62 62 62 66 66 66 30 30 30
45387- 10 10 10 0 0 0 0 0 0 0 0 0
45388- 0 0 0 0 0 0 0 0 0 0 0 0
45389- 0 0 0 0 0 0 0 0 0 0 0 0
45390- 0 0 0 0 0 0 0 0 0 0 0 0
45391- 0 0 0 0 0 0 0 0 0 0 0 0
45392- 0 0 0 0 0 0 0 0 0 0 0 0
45393- 0 0 0 0 0 0 0 0 0 0 0 0
45394- 0 0 0 0 0 0 0 0 0 0 0 0
45395- 0 0 0 0 0 0 0 0 0 0 0 0
45396- 14 14 14 42 42 42 82 82 82 18 18 18
45397- 2 2 6 2 2 6 2 2 6 10 10 10
45398- 94 94 94 182 182 182 218 218 218 242 242 242
45399-250 250 250 253 253 253 253 253 253 250 250 250
45400-234 234 234 253 253 253 253 253 253 253 253 253
45401-253 253 253 253 253 253 253 253 253 246 246 246
45402-238 238 238 226 226 226 210 210 210 202 202 202
45403-195 195 195 195 195 195 210 210 210 158 158 158
45404- 6 6 6 14 14 14 50 50 50 14 14 14
45405- 2 2 6 2 2 6 2 2 6 2 2 6
45406- 2 2 6 6 6 6 86 86 86 46 46 46
45407- 18 18 18 6 6 6 0 0 0 0 0 0
45408- 0 0 0 0 0 0 0 0 0 0 0 0
45409- 0 0 0 0 0 0 0 0 0 0 0 0
45410- 0 0 0 0 0 0 0 0 0 0 0 0
45411- 0 0 0 0 0 0 0 0 0 0 0 0
45412- 0 0 0 0 0 0 0 0 0 0 0 0
45413- 0 0 0 0 0 0 0 0 0 0 0 0
45414- 0 0 0 0 0 0 0 0 0 0 0 0
45415- 0 0 0 0 0 0 0 0 0 6 6 6
45416- 22 22 22 54 54 54 70 70 70 2 2 6
45417- 2 2 6 10 10 10 2 2 6 22 22 22
45418-166 166 166 231 231 231 250 250 250 253 253 253
45419-253 253 253 253 253 253 253 253 253 250 250 250
45420-242 242 242 253 253 253 253 253 253 253 253 253
45421-253 253 253 253 253 253 253 253 253 253 253 253
45422-253 253 253 253 253 253 253 253 253 246 246 246
45423-231 231 231 206 206 206 198 198 198 226 226 226
45424- 94 94 94 2 2 6 6 6 6 38 38 38
45425- 30 30 30 2 2 6 2 2 6 2 2 6
45426- 2 2 6 2 2 6 62 62 62 66 66 66
45427- 26 26 26 10 10 10 0 0 0 0 0 0
45428- 0 0 0 0 0 0 0 0 0 0 0 0
45429- 0 0 0 0 0 0 0 0 0 0 0 0
45430- 0 0 0 0 0 0 0 0 0 0 0 0
45431- 0 0 0 0 0 0 0 0 0 0 0 0
45432- 0 0 0 0 0 0 0 0 0 0 0 0
45433- 0 0 0 0 0 0 0 0 0 0 0 0
45434- 0 0 0 0 0 0 0 0 0 0 0 0
45435- 0 0 0 0 0 0 0 0 0 10 10 10
45436- 30 30 30 74 74 74 50 50 50 2 2 6
45437- 26 26 26 26 26 26 2 2 6 106 106 106
45438-238 238 238 253 253 253 253 253 253 253 253 253
45439-253 253 253 253 253 253 253 253 253 253 253 253
45440-253 253 253 253 253 253 253 253 253 253 253 253
45441-253 253 253 253 253 253 253 253 253 253 253 253
45442-253 253 253 253 253 253 253 253 253 253 253 253
45443-253 253 253 246 246 246 218 218 218 202 202 202
45444-210 210 210 14 14 14 2 2 6 2 2 6
45445- 30 30 30 22 22 22 2 2 6 2 2 6
45446- 2 2 6 2 2 6 18 18 18 86 86 86
45447- 42 42 42 14 14 14 0 0 0 0 0 0
45448- 0 0 0 0 0 0 0 0 0 0 0 0
45449- 0 0 0 0 0 0 0 0 0 0 0 0
45450- 0 0 0 0 0 0 0 0 0 0 0 0
45451- 0 0 0 0 0 0 0 0 0 0 0 0
45452- 0 0 0 0 0 0 0 0 0 0 0 0
45453- 0 0 0 0 0 0 0 0 0 0 0 0
45454- 0 0 0 0 0 0 0 0 0 0 0 0
45455- 0 0 0 0 0 0 0 0 0 14 14 14
45456- 42 42 42 90 90 90 22 22 22 2 2 6
45457- 42 42 42 2 2 6 18 18 18 218 218 218
45458-253 253 253 253 253 253 253 253 253 253 253 253
45459-253 253 253 253 253 253 253 253 253 253 253 253
45460-253 253 253 253 253 253 253 253 253 253 253 253
45461-253 253 253 253 253 253 253 253 253 253 253 253
45462-253 253 253 253 253 253 253 253 253 253 253 253
45463-253 253 253 253 253 253 250 250 250 221 221 221
45464-218 218 218 101 101 101 2 2 6 14 14 14
45465- 18 18 18 38 38 38 10 10 10 2 2 6
45466- 2 2 6 2 2 6 2 2 6 78 78 78
45467- 58 58 58 22 22 22 6 6 6 0 0 0
45468- 0 0 0 0 0 0 0 0 0 0 0 0
45469- 0 0 0 0 0 0 0 0 0 0 0 0
45470- 0 0 0 0 0 0 0 0 0 0 0 0
45471- 0 0 0 0 0 0 0 0 0 0 0 0
45472- 0 0 0 0 0 0 0 0 0 0 0 0
45473- 0 0 0 0 0 0 0 0 0 0 0 0
45474- 0 0 0 0 0 0 0 0 0 0 0 0
45475- 0 0 0 0 0 0 6 6 6 18 18 18
45476- 54 54 54 82 82 82 2 2 6 26 26 26
45477- 22 22 22 2 2 6 123 123 123 253 253 253
45478-253 253 253 253 253 253 253 253 253 253 253 253
45479-253 253 253 253 253 253 253 253 253 253 253 253
45480-253 253 253 253 253 253 253 253 253 253 253 253
45481-253 253 253 253 253 253 253 253 253 253 253 253
45482-253 253 253 253 253 253 253 253 253 253 253 253
45483-253 253 253 253 253 253 253 253 253 250 250 250
45484-238 238 238 198 198 198 6 6 6 38 38 38
45485- 58 58 58 26 26 26 38 38 38 2 2 6
45486- 2 2 6 2 2 6 2 2 6 46 46 46
45487- 78 78 78 30 30 30 10 10 10 0 0 0
45488- 0 0 0 0 0 0 0 0 0 0 0 0
45489- 0 0 0 0 0 0 0 0 0 0 0 0
45490- 0 0 0 0 0 0 0 0 0 0 0 0
45491- 0 0 0 0 0 0 0 0 0 0 0 0
45492- 0 0 0 0 0 0 0 0 0 0 0 0
45493- 0 0 0 0 0 0 0 0 0 0 0 0
45494- 0 0 0 0 0 0 0 0 0 0 0 0
45495- 0 0 0 0 0 0 10 10 10 30 30 30
45496- 74 74 74 58 58 58 2 2 6 42 42 42
45497- 2 2 6 22 22 22 231 231 231 253 253 253
45498-253 253 253 253 253 253 253 253 253 253 253 253
45499-253 253 253 253 253 253 253 253 253 250 250 250
45500-253 253 253 253 253 253 253 253 253 253 253 253
45501-253 253 253 253 253 253 253 253 253 253 253 253
45502-253 253 253 253 253 253 253 253 253 253 253 253
45503-253 253 253 253 253 253 253 253 253 253 253 253
45504-253 253 253 246 246 246 46 46 46 38 38 38
45505- 42 42 42 14 14 14 38 38 38 14 14 14
45506- 2 2 6 2 2 6 2 2 6 6 6 6
45507- 86 86 86 46 46 46 14 14 14 0 0 0
45508- 0 0 0 0 0 0 0 0 0 0 0 0
45509- 0 0 0 0 0 0 0 0 0 0 0 0
45510- 0 0 0 0 0 0 0 0 0 0 0 0
45511- 0 0 0 0 0 0 0 0 0 0 0 0
45512- 0 0 0 0 0 0 0 0 0 0 0 0
45513- 0 0 0 0 0 0 0 0 0 0 0 0
45514- 0 0 0 0 0 0 0 0 0 0 0 0
45515- 0 0 0 6 6 6 14 14 14 42 42 42
45516- 90 90 90 18 18 18 18 18 18 26 26 26
45517- 2 2 6 116 116 116 253 253 253 253 253 253
45518-253 253 253 253 253 253 253 253 253 253 253 253
45519-253 253 253 253 253 253 250 250 250 238 238 238
45520-253 253 253 253 253 253 253 253 253 253 253 253
45521-253 253 253 253 253 253 253 253 253 253 253 253
45522-253 253 253 253 253 253 253 253 253 253 253 253
45523-253 253 253 253 253 253 253 253 253 253 253 253
45524-253 253 253 253 253 253 94 94 94 6 6 6
45525- 2 2 6 2 2 6 10 10 10 34 34 34
45526- 2 2 6 2 2 6 2 2 6 2 2 6
45527- 74 74 74 58 58 58 22 22 22 6 6 6
45528- 0 0 0 0 0 0 0 0 0 0 0 0
45529- 0 0 0 0 0 0 0 0 0 0 0 0
45530- 0 0 0 0 0 0 0 0 0 0 0 0
45531- 0 0 0 0 0 0 0 0 0 0 0 0
45532- 0 0 0 0 0 0 0 0 0 0 0 0
45533- 0 0 0 0 0 0 0 0 0 0 0 0
45534- 0 0 0 0 0 0 0 0 0 0 0 0
45535- 0 0 0 10 10 10 26 26 26 66 66 66
45536- 82 82 82 2 2 6 38 38 38 6 6 6
45537- 14 14 14 210 210 210 253 253 253 253 253 253
45538-253 253 253 253 253 253 253 253 253 253 253 253
45539-253 253 253 253 253 253 246 246 246 242 242 242
45540-253 253 253 253 253 253 253 253 253 253 253 253
45541-253 253 253 253 253 253 253 253 253 253 253 253
45542-253 253 253 253 253 253 253 253 253 253 253 253
45543-253 253 253 253 253 253 253 253 253 253 253 253
45544-253 253 253 253 253 253 144 144 144 2 2 6
45545- 2 2 6 2 2 6 2 2 6 46 46 46
45546- 2 2 6 2 2 6 2 2 6 2 2 6
45547- 42 42 42 74 74 74 30 30 30 10 10 10
45548- 0 0 0 0 0 0 0 0 0 0 0 0
45549- 0 0 0 0 0 0 0 0 0 0 0 0
45550- 0 0 0 0 0 0 0 0 0 0 0 0
45551- 0 0 0 0 0 0 0 0 0 0 0 0
45552- 0 0 0 0 0 0 0 0 0 0 0 0
45553- 0 0 0 0 0 0 0 0 0 0 0 0
45554- 0 0 0 0 0 0 0 0 0 0 0 0
45555- 6 6 6 14 14 14 42 42 42 90 90 90
45556- 26 26 26 6 6 6 42 42 42 2 2 6
45557- 74 74 74 250 250 250 253 253 253 253 253 253
45558-253 253 253 253 253 253 253 253 253 253 253 253
45559-253 253 253 253 253 253 242 242 242 242 242 242
45560-253 253 253 253 253 253 253 253 253 253 253 253
45561-253 253 253 253 253 253 253 253 253 253 253 253
45562-253 253 253 253 253 253 253 253 253 253 253 253
45563-253 253 253 253 253 253 253 253 253 253 253 253
45564-253 253 253 253 253 253 182 182 182 2 2 6
45565- 2 2 6 2 2 6 2 2 6 46 46 46
45566- 2 2 6 2 2 6 2 2 6 2 2 6
45567- 10 10 10 86 86 86 38 38 38 10 10 10
45568- 0 0 0 0 0 0 0 0 0 0 0 0
45569- 0 0 0 0 0 0 0 0 0 0 0 0
45570- 0 0 0 0 0 0 0 0 0 0 0 0
45571- 0 0 0 0 0 0 0 0 0 0 0 0
45572- 0 0 0 0 0 0 0 0 0 0 0 0
45573- 0 0 0 0 0 0 0 0 0 0 0 0
45574- 0 0 0 0 0 0 0 0 0 0 0 0
45575- 10 10 10 26 26 26 66 66 66 82 82 82
45576- 2 2 6 22 22 22 18 18 18 2 2 6
45577-149 149 149 253 253 253 253 253 253 253 253 253
45578-253 253 253 253 253 253 253 253 253 253 253 253
45579-253 253 253 253 253 253 234 234 234 242 242 242
45580-253 253 253 253 253 253 253 253 253 253 253 253
45581-253 253 253 253 253 253 253 253 253 253 253 253
45582-253 253 253 253 253 253 253 253 253 253 253 253
45583-253 253 253 253 253 253 253 253 253 253 253 253
45584-253 253 253 253 253 253 206 206 206 2 2 6
45585- 2 2 6 2 2 6 2 2 6 38 38 38
45586- 2 2 6 2 2 6 2 2 6 2 2 6
45587- 6 6 6 86 86 86 46 46 46 14 14 14
45588- 0 0 0 0 0 0 0 0 0 0 0 0
45589- 0 0 0 0 0 0 0 0 0 0 0 0
45590- 0 0 0 0 0 0 0 0 0 0 0 0
45591- 0 0 0 0 0 0 0 0 0 0 0 0
45592- 0 0 0 0 0 0 0 0 0 0 0 0
45593- 0 0 0 0 0 0 0 0 0 0 0 0
45594- 0 0 0 0 0 0 0 0 0 6 6 6
45595- 18 18 18 46 46 46 86 86 86 18 18 18
45596- 2 2 6 34 34 34 10 10 10 6 6 6
45597-210 210 210 253 253 253 253 253 253 253 253 253
45598-253 253 253 253 253 253 253 253 253 253 253 253
45599-253 253 253 253 253 253 234 234 234 242 242 242
45600-253 253 253 253 253 253 253 253 253 253 253 253
45601-253 253 253 253 253 253 253 253 253 253 253 253
45602-253 253 253 253 253 253 253 253 253 253 253 253
45603-253 253 253 253 253 253 253 253 253 253 253 253
45604-253 253 253 253 253 253 221 221 221 6 6 6
45605- 2 2 6 2 2 6 6 6 6 30 30 30
45606- 2 2 6 2 2 6 2 2 6 2 2 6
45607- 2 2 6 82 82 82 54 54 54 18 18 18
45608- 6 6 6 0 0 0 0 0 0 0 0 0
45609- 0 0 0 0 0 0 0 0 0 0 0 0
45610- 0 0 0 0 0 0 0 0 0 0 0 0
45611- 0 0 0 0 0 0 0 0 0 0 0 0
45612- 0 0 0 0 0 0 0 0 0 0 0 0
45613- 0 0 0 0 0 0 0 0 0 0 0 0
45614- 0 0 0 0 0 0 0 0 0 10 10 10
45615- 26 26 26 66 66 66 62 62 62 2 2 6
45616- 2 2 6 38 38 38 10 10 10 26 26 26
45617-238 238 238 253 253 253 253 253 253 253 253 253
45618-253 253 253 253 253 253 253 253 253 253 253 253
45619-253 253 253 253 253 253 231 231 231 238 238 238
45620-253 253 253 253 253 253 253 253 253 253 253 253
45621-253 253 253 253 253 253 253 253 253 253 253 253
45622-253 253 253 253 253 253 253 253 253 253 253 253
45623-253 253 253 253 253 253 253 253 253 253 253 253
45624-253 253 253 253 253 253 231 231 231 6 6 6
45625- 2 2 6 2 2 6 10 10 10 30 30 30
45626- 2 2 6 2 2 6 2 2 6 2 2 6
45627- 2 2 6 66 66 66 58 58 58 22 22 22
45628- 6 6 6 0 0 0 0 0 0 0 0 0
45629- 0 0 0 0 0 0 0 0 0 0 0 0
45630- 0 0 0 0 0 0 0 0 0 0 0 0
45631- 0 0 0 0 0 0 0 0 0 0 0 0
45632- 0 0 0 0 0 0 0 0 0 0 0 0
45633- 0 0 0 0 0 0 0 0 0 0 0 0
45634- 0 0 0 0 0 0 0 0 0 10 10 10
45635- 38 38 38 78 78 78 6 6 6 2 2 6
45636- 2 2 6 46 46 46 14 14 14 42 42 42
45637-246 246 246 253 253 253 253 253 253 253 253 253
45638-253 253 253 253 253 253 253 253 253 253 253 253
45639-253 253 253 253 253 253 231 231 231 242 242 242
45640-253 253 253 253 253 253 253 253 253 253 253 253
45641-253 253 253 253 253 253 253 253 253 253 253 253
45642-253 253 253 253 253 253 253 253 253 253 253 253
45643-253 253 253 253 253 253 253 253 253 253 253 253
45644-253 253 253 253 253 253 234 234 234 10 10 10
45645- 2 2 6 2 2 6 22 22 22 14 14 14
45646- 2 2 6 2 2 6 2 2 6 2 2 6
45647- 2 2 6 66 66 66 62 62 62 22 22 22
45648- 6 6 6 0 0 0 0 0 0 0 0 0
45649- 0 0 0 0 0 0 0 0 0 0 0 0
45650- 0 0 0 0 0 0 0 0 0 0 0 0
45651- 0 0 0 0 0 0 0 0 0 0 0 0
45652- 0 0 0 0 0 0 0 0 0 0 0 0
45653- 0 0 0 0 0 0 0 0 0 0 0 0
45654- 0 0 0 0 0 0 6 6 6 18 18 18
45655- 50 50 50 74 74 74 2 2 6 2 2 6
45656- 14 14 14 70 70 70 34 34 34 62 62 62
45657-250 250 250 253 253 253 253 253 253 253 253 253
45658-253 253 253 253 253 253 253 253 253 253 253 253
45659-253 253 253 253 253 253 231 231 231 246 246 246
45660-253 253 253 253 253 253 253 253 253 253 253 253
45661-253 253 253 253 253 253 253 253 253 253 253 253
45662-253 253 253 253 253 253 253 253 253 253 253 253
45663-253 253 253 253 253 253 253 253 253 253 253 253
45664-253 253 253 253 253 253 234 234 234 14 14 14
45665- 2 2 6 2 2 6 30 30 30 2 2 6
45666- 2 2 6 2 2 6 2 2 6 2 2 6
45667- 2 2 6 66 66 66 62 62 62 22 22 22
45668- 6 6 6 0 0 0 0 0 0 0 0 0
45669- 0 0 0 0 0 0 0 0 0 0 0 0
45670- 0 0 0 0 0 0 0 0 0 0 0 0
45671- 0 0 0 0 0 0 0 0 0 0 0 0
45672- 0 0 0 0 0 0 0 0 0 0 0 0
45673- 0 0 0 0 0 0 0 0 0 0 0 0
45674- 0 0 0 0 0 0 6 6 6 18 18 18
45675- 54 54 54 62 62 62 2 2 6 2 2 6
45676- 2 2 6 30 30 30 46 46 46 70 70 70
45677-250 250 250 253 253 253 253 253 253 253 253 253
45678-253 253 253 253 253 253 253 253 253 253 253 253
45679-253 253 253 253 253 253 231 231 231 246 246 246
45680-253 253 253 253 253 253 253 253 253 253 253 253
45681-253 253 253 253 253 253 253 253 253 253 253 253
45682-253 253 253 253 253 253 253 253 253 253 253 253
45683-253 253 253 253 253 253 253 253 253 253 253 253
45684-253 253 253 253 253 253 226 226 226 10 10 10
45685- 2 2 6 6 6 6 30 30 30 2 2 6
45686- 2 2 6 2 2 6 2 2 6 2 2 6
45687- 2 2 6 66 66 66 58 58 58 22 22 22
45688- 6 6 6 0 0 0 0 0 0 0 0 0
45689- 0 0 0 0 0 0 0 0 0 0 0 0
45690- 0 0 0 0 0 0 0 0 0 0 0 0
45691- 0 0 0 0 0 0 0 0 0 0 0 0
45692- 0 0 0 0 0 0 0 0 0 0 0 0
45693- 0 0 0 0 0 0 0 0 0 0 0 0
45694- 0 0 0 0 0 0 6 6 6 22 22 22
45695- 58 58 58 62 62 62 2 2 6 2 2 6
45696- 2 2 6 2 2 6 30 30 30 78 78 78
45697-250 250 250 253 253 253 253 253 253 253 253 253
45698-253 253 253 253 253 253 253 253 253 253 253 253
45699-253 253 253 253 253 253 231 231 231 246 246 246
45700-253 253 253 253 253 253 253 253 253 253 253 253
45701-253 253 253 253 253 253 253 253 253 253 253 253
45702-253 253 253 253 253 253 253 253 253 253 253 253
45703-253 253 253 253 253 253 253 253 253 253 253 253
45704-253 253 253 253 253 253 206 206 206 2 2 6
45705- 22 22 22 34 34 34 18 14 6 22 22 22
45706- 26 26 26 18 18 18 6 6 6 2 2 6
45707- 2 2 6 82 82 82 54 54 54 18 18 18
45708- 6 6 6 0 0 0 0 0 0 0 0 0
45709- 0 0 0 0 0 0 0 0 0 0 0 0
45710- 0 0 0 0 0 0 0 0 0 0 0 0
45711- 0 0 0 0 0 0 0 0 0 0 0 0
45712- 0 0 0 0 0 0 0 0 0 0 0 0
45713- 0 0 0 0 0 0 0 0 0 0 0 0
45714- 0 0 0 0 0 0 6 6 6 26 26 26
45715- 62 62 62 106 106 106 74 54 14 185 133 11
45716-210 162 10 121 92 8 6 6 6 62 62 62
45717-238 238 238 253 253 253 253 253 253 253 253 253
45718-253 253 253 253 253 253 253 253 253 253 253 253
45719-253 253 253 253 253 253 231 231 231 246 246 246
45720-253 253 253 253 253 253 253 253 253 253 253 253
45721-253 253 253 253 253 253 253 253 253 253 253 253
45722-253 253 253 253 253 253 253 253 253 253 253 253
45723-253 253 253 253 253 253 253 253 253 253 253 253
45724-253 253 253 253 253 253 158 158 158 18 18 18
45725- 14 14 14 2 2 6 2 2 6 2 2 6
45726- 6 6 6 18 18 18 66 66 66 38 38 38
45727- 6 6 6 94 94 94 50 50 50 18 18 18
45728- 6 6 6 0 0 0 0 0 0 0 0 0
45729- 0 0 0 0 0 0 0 0 0 0 0 0
45730- 0 0 0 0 0 0 0 0 0 0 0 0
45731- 0 0 0 0 0 0 0 0 0 0 0 0
45732- 0 0 0 0 0 0 0 0 0 0 0 0
45733- 0 0 0 0 0 0 0 0 0 6 6 6
45734- 10 10 10 10 10 10 18 18 18 38 38 38
45735- 78 78 78 142 134 106 216 158 10 242 186 14
45736-246 190 14 246 190 14 156 118 10 10 10 10
45737- 90 90 90 238 238 238 253 253 253 253 253 253
45738-253 253 253 253 253 253 253 253 253 253 253 253
45739-253 253 253 253 253 253 231 231 231 250 250 250
45740-253 253 253 253 253 253 253 253 253 253 253 253
45741-253 253 253 253 253 253 253 253 253 253 253 253
45742-253 253 253 253 253 253 253 253 253 253 253 253
45743-253 253 253 253 253 253 253 253 253 246 230 190
45744-238 204 91 238 204 91 181 142 44 37 26 9
45745- 2 2 6 2 2 6 2 2 6 2 2 6
45746- 2 2 6 2 2 6 38 38 38 46 46 46
45747- 26 26 26 106 106 106 54 54 54 18 18 18
45748- 6 6 6 0 0 0 0 0 0 0 0 0
45749- 0 0 0 0 0 0 0 0 0 0 0 0
45750- 0 0 0 0 0 0 0 0 0 0 0 0
45751- 0 0 0 0 0 0 0 0 0 0 0 0
45752- 0 0 0 0 0 0 0 0 0 0 0 0
45753- 0 0 0 6 6 6 14 14 14 22 22 22
45754- 30 30 30 38 38 38 50 50 50 70 70 70
45755-106 106 106 190 142 34 226 170 11 242 186 14
45756-246 190 14 246 190 14 246 190 14 154 114 10
45757- 6 6 6 74 74 74 226 226 226 253 253 253
45758-253 253 253 253 253 253 253 253 253 253 253 253
45759-253 253 253 253 253 253 231 231 231 250 250 250
45760-253 253 253 253 253 253 253 253 253 253 253 253
45761-253 253 253 253 253 253 253 253 253 253 253 253
45762-253 253 253 253 253 253 253 253 253 253 253 253
45763-253 253 253 253 253 253 253 253 253 228 184 62
45764-241 196 14 241 208 19 232 195 16 38 30 10
45765- 2 2 6 2 2 6 2 2 6 2 2 6
45766- 2 2 6 6 6 6 30 30 30 26 26 26
45767-203 166 17 154 142 90 66 66 66 26 26 26
45768- 6 6 6 0 0 0 0 0 0 0 0 0
45769- 0 0 0 0 0 0 0 0 0 0 0 0
45770- 0 0 0 0 0 0 0 0 0 0 0 0
45771- 0 0 0 0 0 0 0 0 0 0 0 0
45772- 0 0 0 0 0 0 0 0 0 0 0 0
45773- 6 6 6 18 18 18 38 38 38 58 58 58
45774- 78 78 78 86 86 86 101 101 101 123 123 123
45775-175 146 61 210 150 10 234 174 13 246 186 14
45776-246 190 14 246 190 14 246 190 14 238 190 10
45777-102 78 10 2 2 6 46 46 46 198 198 198
45778-253 253 253 253 253 253 253 253 253 253 253 253
45779-253 253 253 253 253 253 234 234 234 242 242 242
45780-253 253 253 253 253 253 253 253 253 253 253 253
45781-253 253 253 253 253 253 253 253 253 253 253 253
45782-253 253 253 253 253 253 253 253 253 253 253 253
45783-253 253 253 253 253 253 253 253 253 224 178 62
45784-242 186 14 241 196 14 210 166 10 22 18 6
45785- 2 2 6 2 2 6 2 2 6 2 2 6
45786- 2 2 6 2 2 6 6 6 6 121 92 8
45787-238 202 15 232 195 16 82 82 82 34 34 34
45788- 10 10 10 0 0 0 0 0 0 0 0 0
45789- 0 0 0 0 0 0 0 0 0 0 0 0
45790- 0 0 0 0 0 0 0 0 0 0 0 0
45791- 0 0 0 0 0 0 0 0 0 0 0 0
45792- 0 0 0 0 0 0 0 0 0 0 0 0
45793- 14 14 14 38 38 38 70 70 70 154 122 46
45794-190 142 34 200 144 11 197 138 11 197 138 11
45795-213 154 11 226 170 11 242 186 14 246 190 14
45796-246 190 14 246 190 14 246 190 14 246 190 14
45797-225 175 15 46 32 6 2 2 6 22 22 22
45798-158 158 158 250 250 250 253 253 253 253 253 253
45799-253 253 253 253 253 253 253 253 253 253 253 253
45800-253 253 253 253 253 253 253 253 253 253 253 253
45801-253 253 253 253 253 253 253 253 253 253 253 253
45802-253 253 253 253 253 253 253 253 253 253 253 253
45803-253 253 253 250 250 250 242 242 242 224 178 62
45804-239 182 13 236 186 11 213 154 11 46 32 6
45805- 2 2 6 2 2 6 2 2 6 2 2 6
45806- 2 2 6 2 2 6 61 42 6 225 175 15
45807-238 190 10 236 186 11 112 100 78 42 42 42
45808- 14 14 14 0 0 0 0 0 0 0 0 0
45809- 0 0 0 0 0 0 0 0 0 0 0 0
45810- 0 0 0 0 0 0 0 0 0 0 0 0
45811- 0 0 0 0 0 0 0 0 0 0 0 0
45812- 0 0 0 0 0 0 0 0 0 6 6 6
45813- 22 22 22 54 54 54 154 122 46 213 154 11
45814-226 170 11 230 174 11 226 170 11 226 170 11
45815-236 178 12 242 186 14 246 190 14 246 190 14
45816-246 190 14 246 190 14 246 190 14 246 190 14
45817-241 196 14 184 144 12 10 10 10 2 2 6
45818- 6 6 6 116 116 116 242 242 242 253 253 253
45819-253 253 253 253 253 253 253 253 253 253 253 253
45820-253 253 253 253 253 253 253 253 253 253 253 253
45821-253 253 253 253 253 253 253 253 253 253 253 253
45822-253 253 253 253 253 253 253 253 253 253 253 253
45823-253 253 253 231 231 231 198 198 198 214 170 54
45824-236 178 12 236 178 12 210 150 10 137 92 6
45825- 18 14 6 2 2 6 2 2 6 2 2 6
45826- 6 6 6 70 47 6 200 144 11 236 178 12
45827-239 182 13 239 182 13 124 112 88 58 58 58
45828- 22 22 22 6 6 6 0 0 0 0 0 0
45829- 0 0 0 0 0 0 0 0 0 0 0 0
45830- 0 0 0 0 0 0 0 0 0 0 0 0
45831- 0 0 0 0 0 0 0 0 0 0 0 0
45832- 0 0 0 0 0 0 0 0 0 10 10 10
45833- 30 30 30 70 70 70 180 133 36 226 170 11
45834-239 182 13 242 186 14 242 186 14 246 186 14
45835-246 190 14 246 190 14 246 190 14 246 190 14
45836-246 190 14 246 190 14 246 190 14 246 190 14
45837-246 190 14 232 195 16 98 70 6 2 2 6
45838- 2 2 6 2 2 6 66 66 66 221 221 221
45839-253 253 253 253 253 253 253 253 253 253 253 253
45840-253 253 253 253 253 253 253 253 253 253 253 253
45841-253 253 253 253 253 253 253 253 253 253 253 253
45842-253 253 253 253 253 253 253 253 253 253 253 253
45843-253 253 253 206 206 206 198 198 198 214 166 58
45844-230 174 11 230 174 11 216 158 10 192 133 9
45845-163 110 8 116 81 8 102 78 10 116 81 8
45846-167 114 7 197 138 11 226 170 11 239 182 13
45847-242 186 14 242 186 14 162 146 94 78 78 78
45848- 34 34 34 14 14 14 6 6 6 0 0 0
45849- 0 0 0 0 0 0 0 0 0 0 0 0
45850- 0 0 0 0 0 0 0 0 0 0 0 0
45851- 0 0 0 0 0 0 0 0 0 0 0 0
45852- 0 0 0 0 0 0 0 0 0 6 6 6
45853- 30 30 30 78 78 78 190 142 34 226 170 11
45854-239 182 13 246 190 14 246 190 14 246 190 14
45855-246 190 14 246 190 14 246 190 14 246 190 14
45856-246 190 14 246 190 14 246 190 14 246 190 14
45857-246 190 14 241 196 14 203 166 17 22 18 6
45858- 2 2 6 2 2 6 2 2 6 38 38 38
45859-218 218 218 253 253 253 253 253 253 253 253 253
45860-253 253 253 253 253 253 253 253 253 253 253 253
45861-253 253 253 253 253 253 253 253 253 253 253 253
45862-253 253 253 253 253 253 253 253 253 253 253 253
45863-250 250 250 206 206 206 198 198 198 202 162 69
45864-226 170 11 236 178 12 224 166 10 210 150 10
45865-200 144 11 197 138 11 192 133 9 197 138 11
45866-210 150 10 226 170 11 242 186 14 246 190 14
45867-246 190 14 246 186 14 225 175 15 124 112 88
45868- 62 62 62 30 30 30 14 14 14 6 6 6
45869- 0 0 0 0 0 0 0 0 0 0 0 0
45870- 0 0 0 0 0 0 0 0 0 0 0 0
45871- 0 0 0 0 0 0 0 0 0 0 0 0
45872- 0 0 0 0 0 0 0 0 0 10 10 10
45873- 30 30 30 78 78 78 174 135 50 224 166 10
45874-239 182 13 246 190 14 246 190 14 246 190 14
45875-246 190 14 246 190 14 246 190 14 246 190 14
45876-246 190 14 246 190 14 246 190 14 246 190 14
45877-246 190 14 246 190 14 241 196 14 139 102 15
45878- 2 2 6 2 2 6 2 2 6 2 2 6
45879- 78 78 78 250 250 250 253 253 253 253 253 253
45880-253 253 253 253 253 253 253 253 253 253 253 253
45881-253 253 253 253 253 253 253 253 253 253 253 253
45882-253 253 253 253 253 253 253 253 253 253 253 253
45883-250 250 250 214 214 214 198 198 198 190 150 46
45884-219 162 10 236 178 12 234 174 13 224 166 10
45885-216 158 10 213 154 11 213 154 11 216 158 10
45886-226 170 11 239 182 13 246 190 14 246 190 14
45887-246 190 14 246 190 14 242 186 14 206 162 42
45888-101 101 101 58 58 58 30 30 30 14 14 14
45889- 6 6 6 0 0 0 0 0 0 0 0 0
45890- 0 0 0 0 0 0 0 0 0 0 0 0
45891- 0 0 0 0 0 0 0 0 0 0 0 0
45892- 0 0 0 0 0 0 0 0 0 10 10 10
45893- 30 30 30 74 74 74 174 135 50 216 158 10
45894-236 178 12 246 190 14 246 190 14 246 190 14
45895-246 190 14 246 190 14 246 190 14 246 190 14
45896-246 190 14 246 190 14 246 190 14 246 190 14
45897-246 190 14 246 190 14 241 196 14 226 184 13
45898- 61 42 6 2 2 6 2 2 6 2 2 6
45899- 22 22 22 238 238 238 253 253 253 253 253 253
45900-253 253 253 253 253 253 253 253 253 253 253 253
45901-253 253 253 253 253 253 253 253 253 253 253 253
45902-253 253 253 253 253 253 253 253 253 253 253 253
45903-253 253 253 226 226 226 187 187 187 180 133 36
45904-216 158 10 236 178 12 239 182 13 236 178 12
45905-230 174 11 226 170 11 226 170 11 230 174 11
45906-236 178 12 242 186 14 246 190 14 246 190 14
45907-246 190 14 246 190 14 246 186 14 239 182 13
45908-206 162 42 106 106 106 66 66 66 34 34 34
45909- 14 14 14 6 6 6 0 0 0 0 0 0
45910- 0 0 0 0 0 0 0 0 0 0 0 0
45911- 0 0 0 0 0 0 0 0 0 0 0 0
45912- 0 0 0 0 0 0 0 0 0 6 6 6
45913- 26 26 26 70 70 70 163 133 67 213 154 11
45914-236 178 12 246 190 14 246 190 14 246 190 14
45915-246 190 14 246 190 14 246 190 14 246 190 14
45916-246 190 14 246 190 14 246 190 14 246 190 14
45917-246 190 14 246 190 14 246 190 14 241 196 14
45918-190 146 13 18 14 6 2 2 6 2 2 6
45919- 46 46 46 246 246 246 253 253 253 253 253 253
45920-253 253 253 253 253 253 253 253 253 253 253 253
45921-253 253 253 253 253 253 253 253 253 253 253 253
45922-253 253 253 253 253 253 253 253 253 253 253 253
45923-253 253 253 221 221 221 86 86 86 156 107 11
45924-216 158 10 236 178 12 242 186 14 246 186 14
45925-242 186 14 239 182 13 239 182 13 242 186 14
45926-242 186 14 246 186 14 246 190 14 246 190 14
45927-246 190 14 246 190 14 246 190 14 246 190 14
45928-242 186 14 225 175 15 142 122 72 66 66 66
45929- 30 30 30 10 10 10 0 0 0 0 0 0
45930- 0 0 0 0 0 0 0 0 0 0 0 0
45931- 0 0 0 0 0 0 0 0 0 0 0 0
45932- 0 0 0 0 0 0 0 0 0 6 6 6
45933- 26 26 26 70 70 70 163 133 67 210 150 10
45934-236 178 12 246 190 14 246 190 14 246 190 14
45935-246 190 14 246 190 14 246 190 14 246 190 14
45936-246 190 14 246 190 14 246 190 14 246 190 14
45937-246 190 14 246 190 14 246 190 14 246 190 14
45938-232 195 16 121 92 8 34 34 34 106 106 106
45939-221 221 221 253 253 253 253 253 253 253 253 253
45940-253 253 253 253 253 253 253 253 253 253 253 253
45941-253 253 253 253 253 253 253 253 253 253 253 253
45942-253 253 253 253 253 253 253 253 253 253 253 253
45943-242 242 242 82 82 82 18 14 6 163 110 8
45944-216 158 10 236 178 12 242 186 14 246 190 14
45945-246 190 14 246 190 14 246 190 14 246 190 14
45946-246 190 14 246 190 14 246 190 14 246 190 14
45947-246 190 14 246 190 14 246 190 14 246 190 14
45948-246 190 14 246 190 14 242 186 14 163 133 67
45949- 46 46 46 18 18 18 6 6 6 0 0 0
45950- 0 0 0 0 0 0 0 0 0 0 0 0
45951- 0 0 0 0 0 0 0 0 0 0 0 0
45952- 0 0 0 0 0 0 0 0 0 10 10 10
45953- 30 30 30 78 78 78 163 133 67 210 150 10
45954-236 178 12 246 186 14 246 190 14 246 190 14
45955-246 190 14 246 190 14 246 190 14 246 190 14
45956-246 190 14 246 190 14 246 190 14 246 190 14
45957-246 190 14 246 190 14 246 190 14 246 190 14
45958-241 196 14 215 174 15 190 178 144 253 253 253
45959-253 253 253 253 253 253 253 253 253 253 253 253
45960-253 253 253 253 253 253 253 253 253 253 253 253
45961-253 253 253 253 253 253 253 253 253 253 253 253
45962-253 253 253 253 253 253 253 253 253 218 218 218
45963- 58 58 58 2 2 6 22 18 6 167 114 7
45964-216 158 10 236 178 12 246 186 14 246 190 14
45965-246 190 14 246 190 14 246 190 14 246 190 14
45966-246 190 14 246 190 14 246 190 14 246 190 14
45967-246 190 14 246 190 14 246 190 14 246 190 14
45968-246 190 14 246 186 14 242 186 14 190 150 46
45969- 54 54 54 22 22 22 6 6 6 0 0 0
45970- 0 0 0 0 0 0 0 0 0 0 0 0
45971- 0 0 0 0 0 0 0 0 0 0 0 0
45972- 0 0 0 0 0 0 0 0 0 14 14 14
45973- 38 38 38 86 86 86 180 133 36 213 154 11
45974-236 178 12 246 186 14 246 190 14 246 190 14
45975-246 190 14 246 190 14 246 190 14 246 190 14
45976-246 190 14 246 190 14 246 190 14 246 190 14
45977-246 190 14 246 190 14 246 190 14 246 190 14
45978-246 190 14 232 195 16 190 146 13 214 214 214
45979-253 253 253 253 253 253 253 253 253 253 253 253
45980-253 253 253 253 253 253 253 253 253 253 253 253
45981-253 253 253 253 253 253 253 253 253 253 253 253
45982-253 253 253 250 250 250 170 170 170 26 26 26
45983- 2 2 6 2 2 6 37 26 9 163 110 8
45984-219 162 10 239 182 13 246 186 14 246 190 14
45985-246 190 14 246 190 14 246 190 14 246 190 14
45986-246 190 14 246 190 14 246 190 14 246 190 14
45987-246 190 14 246 190 14 246 190 14 246 190 14
45988-246 186 14 236 178 12 224 166 10 142 122 72
45989- 46 46 46 18 18 18 6 6 6 0 0 0
45990- 0 0 0 0 0 0 0 0 0 0 0 0
45991- 0 0 0 0 0 0 0 0 0 0 0 0
45992- 0 0 0 0 0 0 6 6 6 18 18 18
45993- 50 50 50 109 106 95 192 133 9 224 166 10
45994-242 186 14 246 190 14 246 190 14 246 190 14
45995-246 190 14 246 190 14 246 190 14 246 190 14
45996-246 190 14 246 190 14 246 190 14 246 190 14
45997-246 190 14 246 190 14 246 190 14 246 190 14
45998-242 186 14 226 184 13 210 162 10 142 110 46
45999-226 226 226 253 253 253 253 253 253 253 253 253
46000-253 253 253 253 253 253 253 253 253 253 253 253
46001-253 253 253 253 253 253 253 253 253 253 253 253
46002-198 198 198 66 66 66 2 2 6 2 2 6
46003- 2 2 6 2 2 6 50 34 6 156 107 11
46004-219 162 10 239 182 13 246 186 14 246 190 14
46005-246 190 14 246 190 14 246 190 14 246 190 14
46006-246 190 14 246 190 14 246 190 14 246 190 14
46007-246 190 14 246 190 14 246 190 14 242 186 14
46008-234 174 13 213 154 11 154 122 46 66 66 66
46009- 30 30 30 10 10 10 0 0 0 0 0 0
46010- 0 0 0 0 0 0 0 0 0 0 0 0
46011- 0 0 0 0 0 0 0 0 0 0 0 0
46012- 0 0 0 0 0 0 6 6 6 22 22 22
46013- 58 58 58 154 121 60 206 145 10 234 174 13
46014-242 186 14 246 186 14 246 190 14 246 190 14
46015-246 190 14 246 190 14 246 190 14 246 190 14
46016-246 190 14 246 190 14 246 190 14 246 190 14
46017-246 190 14 246 190 14 246 190 14 246 190 14
46018-246 186 14 236 178 12 210 162 10 163 110 8
46019- 61 42 6 138 138 138 218 218 218 250 250 250
46020-253 253 253 253 253 253 253 253 253 250 250 250
46021-242 242 242 210 210 210 144 144 144 66 66 66
46022- 6 6 6 2 2 6 2 2 6 2 2 6
46023- 2 2 6 2 2 6 61 42 6 163 110 8
46024-216 158 10 236 178 12 246 190 14 246 190 14
46025-246 190 14 246 190 14 246 190 14 246 190 14
46026-246 190 14 246 190 14 246 190 14 246 190 14
46027-246 190 14 239 182 13 230 174 11 216 158 10
46028-190 142 34 124 112 88 70 70 70 38 38 38
46029- 18 18 18 6 6 6 0 0 0 0 0 0
46030- 0 0 0 0 0 0 0 0 0 0 0 0
46031- 0 0 0 0 0 0 0 0 0 0 0 0
46032- 0 0 0 0 0 0 6 6 6 22 22 22
46033- 62 62 62 168 124 44 206 145 10 224 166 10
46034-236 178 12 239 182 13 242 186 14 242 186 14
46035-246 186 14 246 190 14 246 190 14 246 190 14
46036-246 190 14 246 190 14 246 190 14 246 190 14
46037-246 190 14 246 190 14 246 190 14 246 190 14
46038-246 190 14 236 178 12 216 158 10 175 118 6
46039- 80 54 7 2 2 6 6 6 6 30 30 30
46040- 54 54 54 62 62 62 50 50 50 38 38 38
46041- 14 14 14 2 2 6 2 2 6 2 2 6
46042- 2 2 6 2 2 6 2 2 6 2 2 6
46043- 2 2 6 6 6 6 80 54 7 167 114 7
46044-213 154 11 236 178 12 246 190 14 246 190 14
46045-246 190 14 246 190 14 246 190 14 246 190 14
46046-246 190 14 242 186 14 239 182 13 239 182 13
46047-230 174 11 210 150 10 174 135 50 124 112 88
46048- 82 82 82 54 54 54 34 34 34 18 18 18
46049- 6 6 6 0 0 0 0 0 0 0 0 0
46050- 0 0 0 0 0 0 0 0 0 0 0 0
46051- 0 0 0 0 0 0 0 0 0 0 0 0
46052- 0 0 0 0 0 0 6 6 6 18 18 18
46053- 50 50 50 158 118 36 192 133 9 200 144 11
46054-216 158 10 219 162 10 224 166 10 226 170 11
46055-230 174 11 236 178 12 239 182 13 239 182 13
46056-242 186 14 246 186 14 246 190 14 246 190 14
46057-246 190 14 246 190 14 246 190 14 246 190 14
46058-246 186 14 230 174 11 210 150 10 163 110 8
46059-104 69 6 10 10 10 2 2 6 2 2 6
46060- 2 2 6 2 2 6 2 2 6 2 2 6
46061- 2 2 6 2 2 6 2 2 6 2 2 6
46062- 2 2 6 2 2 6 2 2 6 2 2 6
46063- 2 2 6 6 6 6 91 60 6 167 114 7
46064-206 145 10 230 174 11 242 186 14 246 190 14
46065-246 190 14 246 190 14 246 186 14 242 186 14
46066-239 182 13 230 174 11 224 166 10 213 154 11
46067-180 133 36 124 112 88 86 86 86 58 58 58
46068- 38 38 38 22 22 22 10 10 10 6 6 6
46069- 0 0 0 0 0 0 0 0 0 0 0 0
46070- 0 0 0 0 0 0 0 0 0 0 0 0
46071- 0 0 0 0 0 0 0 0 0 0 0 0
46072- 0 0 0 0 0 0 0 0 0 14 14 14
46073- 34 34 34 70 70 70 138 110 50 158 118 36
46074-167 114 7 180 123 7 192 133 9 197 138 11
46075-200 144 11 206 145 10 213 154 11 219 162 10
46076-224 166 10 230 174 11 239 182 13 242 186 14
46077-246 186 14 246 186 14 246 186 14 246 186 14
46078-239 182 13 216 158 10 185 133 11 152 99 6
46079-104 69 6 18 14 6 2 2 6 2 2 6
46080- 2 2 6 2 2 6 2 2 6 2 2 6
46081- 2 2 6 2 2 6 2 2 6 2 2 6
46082- 2 2 6 2 2 6 2 2 6 2 2 6
46083- 2 2 6 6 6 6 80 54 7 152 99 6
46084-192 133 9 219 162 10 236 178 12 239 182 13
46085-246 186 14 242 186 14 239 182 13 236 178 12
46086-224 166 10 206 145 10 192 133 9 154 121 60
46087- 94 94 94 62 62 62 42 42 42 22 22 22
46088- 14 14 14 6 6 6 0 0 0 0 0 0
46089- 0 0 0 0 0 0 0 0 0 0 0 0
46090- 0 0 0 0 0 0 0 0 0 0 0 0
46091- 0 0 0 0 0 0 0 0 0 0 0 0
46092- 0 0 0 0 0 0 0 0 0 6 6 6
46093- 18 18 18 34 34 34 58 58 58 78 78 78
46094-101 98 89 124 112 88 142 110 46 156 107 11
46095-163 110 8 167 114 7 175 118 6 180 123 7
46096-185 133 11 197 138 11 210 150 10 219 162 10
46097-226 170 11 236 178 12 236 178 12 234 174 13
46098-219 162 10 197 138 11 163 110 8 130 83 6
46099- 91 60 6 10 10 10 2 2 6 2 2 6
46100- 18 18 18 38 38 38 38 38 38 38 38 38
46101- 38 38 38 38 38 38 38 38 38 38 38 38
46102- 38 38 38 38 38 38 26 26 26 2 2 6
46103- 2 2 6 6 6 6 70 47 6 137 92 6
46104-175 118 6 200 144 11 219 162 10 230 174 11
46105-234 174 13 230 174 11 219 162 10 210 150 10
46106-192 133 9 163 110 8 124 112 88 82 82 82
46107- 50 50 50 30 30 30 14 14 14 6 6 6
46108- 0 0 0 0 0 0 0 0 0 0 0 0
46109- 0 0 0 0 0 0 0 0 0 0 0 0
46110- 0 0 0 0 0 0 0 0 0 0 0 0
46111- 0 0 0 0 0 0 0 0 0 0 0 0
46112- 0 0 0 0 0 0 0 0 0 0 0 0
46113- 6 6 6 14 14 14 22 22 22 34 34 34
46114- 42 42 42 58 58 58 74 74 74 86 86 86
46115-101 98 89 122 102 70 130 98 46 121 87 25
46116-137 92 6 152 99 6 163 110 8 180 123 7
46117-185 133 11 197 138 11 206 145 10 200 144 11
46118-180 123 7 156 107 11 130 83 6 104 69 6
46119- 50 34 6 54 54 54 110 110 110 101 98 89
46120- 86 86 86 82 82 82 78 78 78 78 78 78
46121- 78 78 78 78 78 78 78 78 78 78 78 78
46122- 78 78 78 82 82 82 86 86 86 94 94 94
46123-106 106 106 101 101 101 86 66 34 124 80 6
46124-156 107 11 180 123 7 192 133 9 200 144 11
46125-206 145 10 200 144 11 192 133 9 175 118 6
46126-139 102 15 109 106 95 70 70 70 42 42 42
46127- 22 22 22 10 10 10 0 0 0 0 0 0
46128- 0 0 0 0 0 0 0 0 0 0 0 0
46129- 0 0 0 0 0 0 0 0 0 0 0 0
46130- 0 0 0 0 0 0 0 0 0 0 0 0
46131- 0 0 0 0 0 0 0 0 0 0 0 0
46132- 0 0 0 0 0 0 0 0 0 0 0 0
46133- 0 0 0 0 0 0 6 6 6 10 10 10
46134- 14 14 14 22 22 22 30 30 30 38 38 38
46135- 50 50 50 62 62 62 74 74 74 90 90 90
46136-101 98 89 112 100 78 121 87 25 124 80 6
46137-137 92 6 152 99 6 152 99 6 152 99 6
46138-138 86 6 124 80 6 98 70 6 86 66 30
46139-101 98 89 82 82 82 58 58 58 46 46 46
46140- 38 38 38 34 34 34 34 34 34 34 34 34
46141- 34 34 34 34 34 34 34 34 34 34 34 34
46142- 34 34 34 34 34 34 38 38 38 42 42 42
46143- 54 54 54 82 82 82 94 86 76 91 60 6
46144-134 86 6 156 107 11 167 114 7 175 118 6
46145-175 118 6 167 114 7 152 99 6 121 87 25
46146-101 98 89 62 62 62 34 34 34 18 18 18
46147- 6 6 6 0 0 0 0 0 0 0 0 0
46148- 0 0 0 0 0 0 0 0 0 0 0 0
46149- 0 0 0 0 0 0 0 0 0 0 0 0
46150- 0 0 0 0 0 0 0 0 0 0 0 0
46151- 0 0 0 0 0 0 0 0 0 0 0 0
46152- 0 0 0 0 0 0 0 0 0 0 0 0
46153- 0 0 0 0 0 0 0 0 0 0 0 0
46154- 0 0 0 6 6 6 6 6 6 10 10 10
46155- 18 18 18 22 22 22 30 30 30 42 42 42
46156- 50 50 50 66 66 66 86 86 86 101 98 89
46157-106 86 58 98 70 6 104 69 6 104 69 6
46158-104 69 6 91 60 6 82 62 34 90 90 90
46159- 62 62 62 38 38 38 22 22 22 14 14 14
46160- 10 10 10 10 10 10 10 10 10 10 10 10
46161- 10 10 10 10 10 10 6 6 6 10 10 10
46162- 10 10 10 10 10 10 10 10 10 14 14 14
46163- 22 22 22 42 42 42 70 70 70 89 81 66
46164- 80 54 7 104 69 6 124 80 6 137 92 6
46165-134 86 6 116 81 8 100 82 52 86 86 86
46166- 58 58 58 30 30 30 14 14 14 6 6 6
46167- 0 0 0 0 0 0 0 0 0 0 0 0
46168- 0 0 0 0 0 0 0 0 0 0 0 0
46169- 0 0 0 0 0 0 0 0 0 0 0 0
46170- 0 0 0 0 0 0 0 0 0 0 0 0
46171- 0 0 0 0 0 0 0 0 0 0 0 0
46172- 0 0 0 0 0 0 0 0 0 0 0 0
46173- 0 0 0 0 0 0 0 0 0 0 0 0
46174- 0 0 0 0 0 0 0 0 0 0 0 0
46175- 0 0 0 6 6 6 10 10 10 14 14 14
46176- 18 18 18 26 26 26 38 38 38 54 54 54
46177- 70 70 70 86 86 86 94 86 76 89 81 66
46178- 89 81 66 86 86 86 74 74 74 50 50 50
46179- 30 30 30 14 14 14 6 6 6 0 0 0
46180- 0 0 0 0 0 0 0 0 0 0 0 0
46181- 0 0 0 0 0 0 0 0 0 0 0 0
46182- 0 0 0 0 0 0 0 0 0 0 0 0
46183- 6 6 6 18 18 18 34 34 34 58 58 58
46184- 82 82 82 89 81 66 89 81 66 89 81 66
46185- 94 86 66 94 86 76 74 74 74 50 50 50
46186- 26 26 26 14 14 14 6 6 6 0 0 0
46187- 0 0 0 0 0 0 0 0 0 0 0 0
46188- 0 0 0 0 0 0 0 0 0 0 0 0
46189- 0 0 0 0 0 0 0 0 0 0 0 0
46190- 0 0 0 0 0 0 0 0 0 0 0 0
46191- 0 0 0 0 0 0 0 0 0 0 0 0
46192- 0 0 0 0 0 0 0 0 0 0 0 0
46193- 0 0 0 0 0 0 0 0 0 0 0 0
46194- 0 0 0 0 0 0 0 0 0 0 0 0
46195- 0 0 0 0 0 0 0 0 0 0 0 0
46196- 6 6 6 6 6 6 14 14 14 18 18 18
46197- 30 30 30 38 38 38 46 46 46 54 54 54
46198- 50 50 50 42 42 42 30 30 30 18 18 18
46199- 10 10 10 0 0 0 0 0 0 0 0 0
46200- 0 0 0 0 0 0 0 0 0 0 0 0
46201- 0 0 0 0 0 0 0 0 0 0 0 0
46202- 0 0 0 0 0 0 0 0 0 0 0 0
46203- 0 0 0 6 6 6 14 14 14 26 26 26
46204- 38 38 38 50 50 50 58 58 58 58 58 58
46205- 54 54 54 42 42 42 30 30 30 18 18 18
46206- 10 10 10 0 0 0 0 0 0 0 0 0
46207- 0 0 0 0 0 0 0 0 0 0 0 0
46208- 0 0 0 0 0 0 0 0 0 0 0 0
46209- 0 0 0 0 0 0 0 0 0 0 0 0
46210- 0 0 0 0 0 0 0 0 0 0 0 0
46211- 0 0 0 0 0 0 0 0 0 0 0 0
46212- 0 0 0 0 0 0 0 0 0 0 0 0
46213- 0 0 0 0 0 0 0 0 0 0 0 0
46214- 0 0 0 0 0 0 0 0 0 0 0 0
46215- 0 0 0 0 0 0 0 0 0 0 0 0
46216- 0 0 0 0 0 0 0 0 0 6 6 6
46217- 6 6 6 10 10 10 14 14 14 18 18 18
46218- 18 18 18 14 14 14 10 10 10 6 6 6
46219- 0 0 0 0 0 0 0 0 0 0 0 0
46220- 0 0 0 0 0 0 0 0 0 0 0 0
46221- 0 0 0 0 0 0 0 0 0 0 0 0
46222- 0 0 0 0 0 0 0 0 0 0 0 0
46223- 0 0 0 0 0 0 0 0 0 6 6 6
46224- 14 14 14 18 18 18 22 22 22 22 22 22
46225- 18 18 18 14 14 14 10 10 10 6 6 6
46226- 0 0 0 0 0 0 0 0 0 0 0 0
46227- 0 0 0 0 0 0 0 0 0 0 0 0
46228- 0 0 0 0 0 0 0 0 0 0 0 0
46229- 0 0 0 0 0 0 0 0 0 0 0 0
46230- 0 0 0 0 0 0 0 0 0 0 0 0
46231+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46232+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46233+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46234+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46237+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46238+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46239+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46240+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46241+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46242+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46243+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46244+4 4 4 4 4 4
46245+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46246+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46247+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46248+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46251+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46252+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46253+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46254+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46255+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46256+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46257+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46258+4 4 4 4 4 4
46259+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46260+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46261+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46262+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46265+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46266+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46267+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46268+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46269+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46270+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46271+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46272+4 4 4 4 4 4
46273+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46274+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46275+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46276+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46279+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46280+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46281+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46282+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46283+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46284+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46285+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46286+4 4 4 4 4 4
46287+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46288+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46289+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46290+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46293+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46294+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46295+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46296+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46297+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46298+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46299+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46300+4 4 4 4 4 4
46301+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46302+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46304+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46307+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46308+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46309+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46310+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46311+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46312+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46313+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46314+4 4 4 4 4 4
46315+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46316+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46317+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46318+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46319+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
46320+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
46321+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46322+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46323+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46324+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
46325+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46326+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
46327+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46328+4 4 4 4 4 4
46329+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46330+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46331+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46332+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46333+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
46334+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
46335+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46336+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46337+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46338+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
46339+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
46340+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
46341+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46342+4 4 4 4 4 4
46343+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46344+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46345+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46346+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46347+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
46348+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
46349+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46350+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46351+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46352+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
46353+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
46354+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
46355+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
46356+4 4 4 4 4 4
46357+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46358+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46359+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46360+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
46361+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
46362+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
46363+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
46364+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46365+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46366+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
46367+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
46368+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
46369+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
46370+4 4 4 4 4 4
46371+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46372+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46373+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46374+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
46375+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
46376+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
46377+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
46378+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46379+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
46380+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
46381+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
46382+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
46383+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
46384+4 4 4 4 4 4
46385+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46386+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46387+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46388+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
46389+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
46390+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
46391+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
46392+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
46393+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
46394+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
46395+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
46396+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
46397+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
46398+4 4 4 4 4 4
46399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46400+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46401+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
46402+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
46403+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
46404+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
46405+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
46406+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
46407+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
46408+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
46409+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
46410+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
46411+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
46412+4 4 4 4 4 4
46413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46414+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46415+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
46416+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
46417+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
46418+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
46419+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
46420+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
46421+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
46422+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
46423+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
46424+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
46425+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
46426+4 4 4 4 4 4
46427+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46428+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46429+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
46430+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
46431+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
46432+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
46433+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
46434+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
46435+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
46436+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
46437+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
46438+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
46439+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46440+4 4 4 4 4 4
46441+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46442+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46443+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
46444+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
46445+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
46446+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
46447+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
46448+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
46449+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
46450+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
46451+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
46452+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
46453+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
46454+4 4 4 4 4 4
46455+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46456+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
46457+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
46458+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
46459+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
46460+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
46461+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
46462+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
46463+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
46464+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
46465+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
46466+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
46467+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
46468+4 4 4 4 4 4
46469+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46470+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
46471+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
46472+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
46473+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
46474+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
46475+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
46476+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
46477+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
46478+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
46479+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
46480+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
46481+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
46482+0 0 0 4 4 4
46483+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46484+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
46485+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
46486+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
46487+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
46488+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
46489+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
46490+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
46491+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
46492+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
46493+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
46494+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
46495+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
46496+2 0 0 0 0 0
46497+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
46498+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
46499+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
46500+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
46501+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
46502+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
46503+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
46504+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
46505+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
46506+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
46507+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
46508+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
46509+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
46510+37 38 37 0 0 0
46511+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
46512+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
46513+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
46514+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
46515+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
46516+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
46517+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
46518+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
46519+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
46520+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
46521+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
46522+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
46523+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
46524+85 115 134 4 0 0
46525+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
46526+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
46527+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
46528+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
46529+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
46530+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
46531+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
46532+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
46533+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
46534+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
46535+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
46536+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
46537+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
46538+60 73 81 4 0 0
46539+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
46540+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
46541+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
46542+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
46543+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
46544+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
46545+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
46546+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
46547+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
46548+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
46549+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
46550+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
46551+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
46552+16 19 21 4 0 0
46553+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
46554+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
46555+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
46556+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
46557+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
46558+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
46559+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
46560+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
46561+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
46562+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
46563+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
46564+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
46565+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
46566+4 0 0 4 3 3
46567+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
46568+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
46569+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
46570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
46571+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
46572+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
46573+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
46574+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
46575+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
46576+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
46577+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
46578+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
46579+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
46580+3 2 2 4 4 4
46581+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
46582+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
46583+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
46584+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
46585+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
46586+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
46587+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
46588+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
46589+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
46590+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
46591+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
46592+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
46593+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
46594+4 4 4 4 4 4
46595+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
46596+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
46597+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
46598+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
46599+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
46600+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
46601+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
46602+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
46603+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
46604+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
46605+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
46606+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
46607+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
46608+4 4 4 4 4 4
46609+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
46610+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
46611+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
46612+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
46613+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
46614+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
46615+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
46616+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
46617+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
46618+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
46619+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
46620+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
46621+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
46622+5 5 5 5 5 5
46623+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
46624+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
46625+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
46626+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
46627+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
46628+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46629+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
46630+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
46631+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
46632+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
46633+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
46634+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
46635+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
46636+5 5 5 4 4 4
46637+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
46638+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
46639+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
46640+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
46641+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46642+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
46643+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
46644+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
46645+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
46646+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
46647+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
46648+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
46649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46650+4 4 4 4 4 4
46651+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
46652+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
46653+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
46654+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
46655+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
46656+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46657+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46658+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
46659+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
46660+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
46661+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
46662+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
46663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46664+4 4 4 4 4 4
46665+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
46666+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
46667+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
46668+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
46669+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46670+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
46671+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
46672+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
46673+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
46674+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
46675+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
46676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46678+4 4 4 4 4 4
46679+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
46680+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
46681+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
46682+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
46683+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46684+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46685+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46686+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
46687+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
46688+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
46689+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
46690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46692+4 4 4 4 4 4
46693+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
46694+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
46695+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
46696+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
46697+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46698+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
46699+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
46700+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
46701+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
46702+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
46703+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46706+4 4 4 4 4 4
46707+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
46708+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
46709+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
46710+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
46711+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46712+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
46713+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
46714+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
46715+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
46716+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
46717+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
46718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46720+4 4 4 4 4 4
46721+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
46722+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
46723+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
46724+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
46725+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46726+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
46727+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
46728+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
46729+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
46730+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
46731+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
46732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46734+4 4 4 4 4 4
46735+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
46736+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
46737+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
46738+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
46739+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
46740+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
46741+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
46742+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
46743+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
46744+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
46745+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46748+4 4 4 4 4 4
46749+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
46750+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
46751+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
46752+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
46753+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46754+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
46755+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
46756+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
46757+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
46758+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
46759+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46762+4 4 4 4 4 4
46763+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
46764+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
46765+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
46766+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
46767+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46768+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
46769+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
46770+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
46771+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
46772+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
46773+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46776+4 4 4 4 4 4
46777+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
46778+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
46779+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
46780+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
46781+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46782+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
46783+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
46784+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
46785+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
46786+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46787+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46790+4 4 4 4 4 4
46791+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
46792+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
46793+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
46794+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
46795+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
46796+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
46797+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
46798+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
46799+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46800+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46801+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46804+4 4 4 4 4 4
46805+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
46806+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
46807+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
46808+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
46809+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46810+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
46811+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
46812+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
46813+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46814+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46815+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46818+4 4 4 4 4 4
46819+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
46820+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
46821+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
46822+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
46823+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
46824+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
46825+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
46826+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
46827+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46828+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46829+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46832+4 4 4 4 4 4
46833+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
46834+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
46835+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46836+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
46837+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
46838+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
46839+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
46840+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
46841+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
46842+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46843+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46846+4 4 4 4 4 4
46847+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
46848+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
46849+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
46850+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
46851+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
46852+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
46853+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
46854+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
46855+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46856+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46857+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46860+4 4 4 4 4 4
46861+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
46862+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
46863+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46864+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
46865+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
46866+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
46867+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
46868+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
46869+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
46870+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46871+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46874+4 4 4 4 4 4
46875+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
46876+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
46877+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
46878+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
46879+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
46880+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
46881+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
46882+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
46883+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46884+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46885+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46888+4 4 4 4 4 4
46889+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46890+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
46891+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46892+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
46893+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
46894+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
46895+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
46896+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
46897+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46898+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46899+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46900+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46901+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46902+4 4 4 4 4 4
46903+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
46904+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
46905+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
46906+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
46907+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
46908+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
46909+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46910+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
46911+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46912+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46913+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46914+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46915+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46916+4 4 4 4 4 4
46917+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46918+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
46919+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
46920+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
46921+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
46922+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
46923+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46924+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
46925+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46926+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46927+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46928+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46929+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46930+4 4 4 4 4 4
46931+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
46932+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
46933+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
46934+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
46935+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
46936+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
46937+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
46938+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
46939+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
46940+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46941+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46942+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46943+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46944+4 4 4 4 4 4
46945+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46946+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
46947+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
46948+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
46949+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
46950+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
46951+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
46952+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
46953+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
46954+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46955+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46956+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46957+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46958+4 4 4 4 4 4
46959+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
46960+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
46961+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
46962+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
46963+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
46964+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
46965+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
46966+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
46967+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
46968+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46969+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46970+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46971+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46972+4 4 4 4 4 4
46973+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46974+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
46975+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
46976+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
46977+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
46978+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
46979+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
46980+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
46981+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
46982+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46983+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46984+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46985+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46986+4 4 4 4 4 4
46987+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
46988+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
46989+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
46990+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
46991+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
46992+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
46993+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
46994+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
46995+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
46996+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
46997+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46998+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46999+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47000+4 4 4 4 4 4
47001+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
47002+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
47003+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
47004+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
47005+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
47006+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
47007+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
47008+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
47009+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
47010+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
47011+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47013+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47014+4 4 4 4 4 4
47015+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
47016+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
47017+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
47018+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
47019+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
47020+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
47021+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47022+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
47023+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
47024+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
47025+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47026+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47027+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47028+4 4 4 4 4 4
47029+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
47030+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
47031+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
47032+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
47033+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
47034+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
47035+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
47036+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
47037+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
47038+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
47039+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47040+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47041+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47042+4 4 4 4 4 4
47043+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
47044+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
47045+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
47046+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
47047+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
47048+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
47049+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
47050+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
47051+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
47052+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
47053+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47054+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47055+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47056+4 4 4 4 4 4
47057+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47058+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
47059+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
47060+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
47061+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
47062+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
47063+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
47064+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
47065+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
47066+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
47067+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47068+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47069+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47070+4 4 4 4 4 4
47071+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
47072+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
47073+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
47074+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
47075+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
47076+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
47077+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
47078+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
47079+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
47080+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
47081+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47082+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47083+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47084+4 4 4 4 4 4
47085+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
47086+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
47087+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
47088+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
47089+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
47090+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
47091+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
47092+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
47093+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
47094+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47095+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47096+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47097+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47098+4 4 4 4 4 4
47099+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
47100+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47101+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
47102+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
47103+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
47104+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
47105+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
47106+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
47107+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
47108+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47109+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47111+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47112+4 4 4 4 4 4
47113+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
47114+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
47115+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
47116+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
47117+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
47118+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
47119+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
47120+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
47121+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
47122+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47123+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47124+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47125+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47126+4 4 4 4 4 4
47127+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47128+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
47129+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
47130+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
47131+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
47132+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
47133+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
47134+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
47135+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47136+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47139+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47140+4 4 4 4 4 4
47141+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
47142+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
47143+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47144+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
47145+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
47146+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
47147+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
47148+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
47149+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47150+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47151+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47153+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47154+4 4 4 4 4 4
47155+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47156+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
47157+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
47158+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
47159+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
47160+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
47161+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
47162+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
47163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47164+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47167+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47168+4 4 4 4 4 4
47169+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47170+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
47171+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47172+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
47173+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
47174+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
47175+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
47176+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
47177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47178+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47181+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47182+4 4 4 4 4 4
47183+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47184+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
47185+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
47186+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
47187+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
47188+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
47189+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
47190+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
47191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47192+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47195+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47196+4 4 4 4 4 4
47197+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47198+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
47199+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
47200+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47201+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
47202+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
47203+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
47204+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47206+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47209+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47210+4 4 4 4 4 4
47211+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47212+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47213+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47214+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
47215+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
47216+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
47217+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
47218+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47220+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47223+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47224+4 4 4 4 4 4
47225+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47226+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47227+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47228+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47229+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
47230+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
47231+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
47232+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47233+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47234+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47237+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47238+4 4 4 4 4 4
47239+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47240+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47241+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47242+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47243+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47244+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
47245+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
47246+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47247+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47248+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47251+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47252+4 4 4 4 4 4
47253+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47254+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47255+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47256+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47257+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47258+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47259+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
47260+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47261+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47262+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47265+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47266+4 4 4 4 4 4
47267+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47268+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47269+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47270+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
47271+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
47272+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
47273+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
47274+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47275+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47276+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47279+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47280+4 4 4 4 4 4
47281+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47282+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47283+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47284+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47285+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
47286+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47287+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47288+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47289+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47290+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47293+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47294+4 4 4 4 4 4
47295+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47296+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47297+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47298+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47299+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
47300+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
47301+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
47302+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47304+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47307+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47308+4 4 4 4 4 4
47309+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47310+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47311+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47312+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47313+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
47314+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
47315+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47316+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47317+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47318+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47319+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47321+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47322+4 4 4 4 4 4
47323+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47324+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47325+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47326+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47327+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
47328+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
47329+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47330+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47331+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47332+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47335+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47336+4 4 4 4 4 4
47337+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47338+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47339+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47340+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47341+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47342+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
47343+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47344+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47345+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47346+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47349+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47350+4 4 4 4 4 4
47351diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
47352index fe92eed..106e085 100644
47353--- a/drivers/video/mb862xx/mb862xxfb_accel.c
47354+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
47355@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
47356 struct mb862xxfb_par *par = info->par;
47357
47358 if (info->var.bits_per_pixel == 32) {
47359- info->fbops->fb_fillrect = cfb_fillrect;
47360- info->fbops->fb_copyarea = cfb_copyarea;
47361- info->fbops->fb_imageblit = cfb_imageblit;
47362+ pax_open_kernel();
47363+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47364+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47365+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47366+ pax_close_kernel();
47367 } else {
47368 outreg(disp, GC_L0EM, 3);
47369- info->fbops->fb_fillrect = mb86290fb_fillrect;
47370- info->fbops->fb_copyarea = mb86290fb_copyarea;
47371- info->fbops->fb_imageblit = mb86290fb_imageblit;
47372+ pax_open_kernel();
47373+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
47374+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
47375+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
47376+ pax_close_kernel();
47377 }
47378 outreg(draw, GDC_REG_DRAW_BASE, 0);
47379 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
47380diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
47381index ff22871..b129bed 100644
47382--- a/drivers/video/nvidia/nvidia.c
47383+++ b/drivers/video/nvidia/nvidia.c
47384@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
47385 info->fix.line_length = (info->var.xres_virtual *
47386 info->var.bits_per_pixel) >> 3;
47387 if (info->var.accel_flags) {
47388- info->fbops->fb_imageblit = nvidiafb_imageblit;
47389- info->fbops->fb_fillrect = nvidiafb_fillrect;
47390- info->fbops->fb_copyarea = nvidiafb_copyarea;
47391- info->fbops->fb_sync = nvidiafb_sync;
47392+ pax_open_kernel();
47393+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
47394+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
47395+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
47396+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
47397+ pax_close_kernel();
47398 info->pixmap.scan_align = 4;
47399 info->flags &= ~FBINFO_HWACCEL_DISABLED;
47400 info->flags |= FBINFO_READS_FAST;
47401 NVResetGraphics(info);
47402 } else {
47403- info->fbops->fb_imageblit = cfb_imageblit;
47404- info->fbops->fb_fillrect = cfb_fillrect;
47405- info->fbops->fb_copyarea = cfb_copyarea;
47406- info->fbops->fb_sync = NULL;
47407+ pax_open_kernel();
47408+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47409+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47410+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47411+ *(void **)&info->fbops->fb_sync = NULL;
47412+ pax_close_kernel();
47413 info->pixmap.scan_align = 1;
47414 info->flags |= FBINFO_HWACCEL_DISABLED;
47415 info->flags &= ~FBINFO_READS_FAST;
47416@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
47417 info->pixmap.size = 8 * 1024;
47418 info->pixmap.flags = FB_PIXMAP_SYSTEM;
47419
47420- if (!hwcur)
47421- info->fbops->fb_cursor = NULL;
47422+ if (!hwcur) {
47423+ pax_open_kernel();
47424+ *(void **)&info->fbops->fb_cursor = NULL;
47425+ pax_close_kernel();
47426+ }
47427
47428 info->var.accel_flags = (!noaccel);
47429
47430diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
47431index 76d9053..dec2bfd 100644
47432--- a/drivers/video/s1d13xxxfb.c
47433+++ b/drivers/video/s1d13xxxfb.c
47434@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
47435
47436 switch(prod_id) {
47437 case S1D13506_PROD_ID: /* activate acceleration */
47438- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
47439- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
47440+ pax_open_kernel();
47441+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
47442+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
47443+ pax_close_kernel();
47444 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
47445 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
47446 break;
47447diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
47448index 97bd662..39fab85 100644
47449--- a/drivers/video/smscufx.c
47450+++ b/drivers/video/smscufx.c
47451@@ -1171,7 +1171,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
47452 fb_deferred_io_cleanup(info);
47453 kfree(info->fbdefio);
47454 info->fbdefio = NULL;
47455- info->fbops->fb_mmap = ufx_ops_mmap;
47456+ pax_open_kernel();
47457+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
47458+ pax_close_kernel();
47459 }
47460
47461 pr_debug("released /dev/fb%d user=%d count=%d",
47462diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
47463index 86d449e..8e04dc5 100644
47464--- a/drivers/video/udlfb.c
47465+++ b/drivers/video/udlfb.c
47466@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
47467 dlfb_urb_completion(urb);
47468
47469 error:
47470- atomic_add(bytes_sent, &dev->bytes_sent);
47471- atomic_add(bytes_identical, &dev->bytes_identical);
47472- atomic_add(width*height*2, &dev->bytes_rendered);
47473+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
47474+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
47475+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
47476 end_cycles = get_cycles();
47477- atomic_add(((unsigned int) ((end_cycles - start_cycles)
47478+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
47479 >> 10)), /* Kcycles */
47480 &dev->cpu_kcycles_used);
47481
47482@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
47483 dlfb_urb_completion(urb);
47484
47485 error:
47486- atomic_add(bytes_sent, &dev->bytes_sent);
47487- atomic_add(bytes_identical, &dev->bytes_identical);
47488- atomic_add(bytes_rendered, &dev->bytes_rendered);
47489+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
47490+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
47491+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
47492 end_cycles = get_cycles();
47493- atomic_add(((unsigned int) ((end_cycles - start_cycles)
47494+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
47495 >> 10)), /* Kcycles */
47496 &dev->cpu_kcycles_used);
47497 }
47498@@ -989,7 +989,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
47499 fb_deferred_io_cleanup(info);
47500 kfree(info->fbdefio);
47501 info->fbdefio = NULL;
47502- info->fbops->fb_mmap = dlfb_ops_mmap;
47503+ pax_open_kernel();
47504+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
47505+ pax_close_kernel();
47506 }
47507
47508 pr_warn("released /dev/fb%d user=%d count=%d\n",
47509@@ -1372,7 +1374,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
47510 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47511 struct dlfb_data *dev = fb_info->par;
47512 return snprintf(buf, PAGE_SIZE, "%u\n",
47513- atomic_read(&dev->bytes_rendered));
47514+ atomic_read_unchecked(&dev->bytes_rendered));
47515 }
47516
47517 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
47518@@ -1380,7 +1382,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
47519 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47520 struct dlfb_data *dev = fb_info->par;
47521 return snprintf(buf, PAGE_SIZE, "%u\n",
47522- atomic_read(&dev->bytes_identical));
47523+ atomic_read_unchecked(&dev->bytes_identical));
47524 }
47525
47526 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
47527@@ -1388,7 +1390,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
47528 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47529 struct dlfb_data *dev = fb_info->par;
47530 return snprintf(buf, PAGE_SIZE, "%u\n",
47531- atomic_read(&dev->bytes_sent));
47532+ atomic_read_unchecked(&dev->bytes_sent));
47533 }
47534
47535 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
47536@@ -1396,7 +1398,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
47537 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47538 struct dlfb_data *dev = fb_info->par;
47539 return snprintf(buf, PAGE_SIZE, "%u\n",
47540- atomic_read(&dev->cpu_kcycles_used));
47541+ atomic_read_unchecked(&dev->cpu_kcycles_used));
47542 }
47543
47544 static ssize_t edid_show(
47545@@ -1456,10 +1458,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
47546 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47547 struct dlfb_data *dev = fb_info->par;
47548
47549- atomic_set(&dev->bytes_rendered, 0);
47550- atomic_set(&dev->bytes_identical, 0);
47551- atomic_set(&dev->bytes_sent, 0);
47552- atomic_set(&dev->cpu_kcycles_used, 0);
47553+ atomic_set_unchecked(&dev->bytes_rendered, 0);
47554+ atomic_set_unchecked(&dev->bytes_identical, 0);
47555+ atomic_set_unchecked(&dev->bytes_sent, 0);
47556+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
47557
47558 return count;
47559 }
47560diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
47561index d428445..79a78df 100644
47562--- a/drivers/video/uvesafb.c
47563+++ b/drivers/video/uvesafb.c
47564@@ -19,6 +19,7 @@
47565 #include <linux/io.h>
47566 #include <linux/mutex.h>
47567 #include <linux/slab.h>
47568+#include <linux/moduleloader.h>
47569 #include <video/edid.h>
47570 #include <video/uvesafb.h>
47571 #ifdef CONFIG_X86
47572@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
47573 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
47574 par->pmi_setpal = par->ypan = 0;
47575 } else {
47576+
47577+#ifdef CONFIG_PAX_KERNEXEC
47578+#ifdef CONFIG_MODULES
47579+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
47580+#endif
47581+ if (!par->pmi_code) {
47582+ par->pmi_setpal = par->ypan = 0;
47583+ return 0;
47584+ }
47585+#endif
47586+
47587 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
47588 + task->t.regs.edi);
47589+
47590+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47591+ pax_open_kernel();
47592+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
47593+ pax_close_kernel();
47594+
47595+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
47596+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
47597+#else
47598 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
47599 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
47600+#endif
47601+
47602 printk(KERN_INFO "uvesafb: protected mode interface info at "
47603 "%04x:%04x\n",
47604 (u16)task->t.regs.es, (u16)task->t.regs.edi);
47605@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
47606 par->ypan = ypan;
47607
47608 if (par->pmi_setpal || par->ypan) {
47609+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
47610 if (__supported_pte_mask & _PAGE_NX) {
47611 par->pmi_setpal = par->ypan = 0;
47612 printk(KERN_WARNING "uvesafb: NX protection is actively."
47613 "We have better not to use the PMI.\n");
47614- } else {
47615+ } else
47616+#endif
47617 uvesafb_vbe_getpmi(task, par);
47618- }
47619 }
47620 #else
47621 /* The protected mode interface is not available on non-x86. */
47622@@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
47623 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
47624
47625 /* Disable blanking if the user requested so. */
47626- if (!blank)
47627- info->fbops->fb_blank = NULL;
47628+ if (!blank) {
47629+ pax_open_kernel();
47630+ *(void **)&info->fbops->fb_blank = NULL;
47631+ pax_close_kernel();
47632+ }
47633
47634 /*
47635 * Find out how much IO memory is required for the mode with
47636@@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
47637 info->flags = FBINFO_FLAG_DEFAULT |
47638 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
47639
47640- if (!par->ypan)
47641- info->fbops->fb_pan_display = NULL;
47642+ if (!par->ypan) {
47643+ pax_open_kernel();
47644+ *(void **)&info->fbops->fb_pan_display = NULL;
47645+ pax_close_kernel();
47646+ }
47647 }
47648
47649 static void uvesafb_init_mtrr(struct fb_info *info)
47650@@ -1836,6 +1866,11 @@ out:
47651 if (par->vbe_modes)
47652 kfree(par->vbe_modes);
47653
47654+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47655+ if (par->pmi_code)
47656+ module_free_exec(NULL, par->pmi_code);
47657+#endif
47658+
47659 framebuffer_release(info);
47660 return err;
47661 }
47662@@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
47663 kfree(par->vbe_state_orig);
47664 if (par->vbe_state_saved)
47665 kfree(par->vbe_state_saved);
47666+
47667+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47668+ if (par->pmi_code)
47669+ module_free_exec(NULL, par->pmi_code);
47670+#endif
47671+
47672 }
47673
47674 framebuffer_release(info);
47675diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
47676index 501b340..d80aa17 100644
47677--- a/drivers/video/vesafb.c
47678+++ b/drivers/video/vesafb.c
47679@@ -9,6 +9,7 @@
47680 */
47681
47682 #include <linux/module.h>
47683+#include <linux/moduleloader.h>
47684 #include <linux/kernel.h>
47685 #include <linux/errno.h>
47686 #include <linux/string.h>
47687@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
47688 static int vram_total __initdata; /* Set total amount of memory */
47689 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
47690 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
47691-static void (*pmi_start)(void) __read_mostly;
47692-static void (*pmi_pal) (void) __read_mostly;
47693+static void (*pmi_start)(void) __read_only;
47694+static void (*pmi_pal) (void) __read_only;
47695 static int depth __read_mostly;
47696 static int vga_compat __read_mostly;
47697 /* --------------------------------------------------------------------- */
47698@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
47699 unsigned int size_vmode;
47700 unsigned int size_remap;
47701 unsigned int size_total;
47702+ void *pmi_code = NULL;
47703
47704 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
47705 return -ENODEV;
47706@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
47707 size_remap = size_total;
47708 vesafb_fix.smem_len = size_remap;
47709
47710-#ifndef __i386__
47711- screen_info.vesapm_seg = 0;
47712-#endif
47713-
47714 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
47715 printk(KERN_WARNING
47716 "vesafb: cannot reserve video memory at 0x%lx\n",
47717@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
47718 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
47719 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
47720
47721+#ifdef __i386__
47722+
47723+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47724+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
47725+ if (!pmi_code)
47726+#elif !defined(CONFIG_PAX_KERNEXEC)
47727+ if (0)
47728+#endif
47729+
47730+#endif
47731+ screen_info.vesapm_seg = 0;
47732+
47733 if (screen_info.vesapm_seg) {
47734- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
47735- screen_info.vesapm_seg,screen_info.vesapm_off);
47736+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
47737+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
47738 }
47739
47740 if (screen_info.vesapm_seg < 0xc000)
47741@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
47742
47743 if (ypan || pmi_setpal) {
47744 unsigned short *pmi_base;
47745+
47746 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
47747- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
47748- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
47749+
47750+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47751+ pax_open_kernel();
47752+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
47753+#else
47754+ pmi_code = pmi_base;
47755+#endif
47756+
47757+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
47758+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
47759+
47760+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47761+ pmi_start = ktva_ktla(pmi_start);
47762+ pmi_pal = ktva_ktla(pmi_pal);
47763+ pax_close_kernel();
47764+#endif
47765+
47766 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
47767 if (pmi_base[3]) {
47768 printk(KERN_INFO "vesafb: pmi: ports = ");
47769@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
47770 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
47771 (ypan ? FBINFO_HWACCEL_YPAN : 0);
47772
47773- if (!ypan)
47774- info->fbops->fb_pan_display = NULL;
47775+ if (!ypan) {
47776+ pax_open_kernel();
47777+ *(void **)&info->fbops->fb_pan_display = NULL;
47778+ pax_close_kernel();
47779+ }
47780
47781 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
47782 err = -ENOMEM;
47783@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
47784 info->node, info->fix.id);
47785 return 0;
47786 err:
47787+
47788+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47789+ module_free_exec(NULL, pmi_code);
47790+#endif
47791+
47792 if (info->screen_base)
47793 iounmap(info->screen_base);
47794 framebuffer_release(info);
47795diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
47796index 88714ae..16c2e11 100644
47797--- a/drivers/video/via/via_clock.h
47798+++ b/drivers/video/via/via_clock.h
47799@@ -56,7 +56,7 @@ struct via_clock {
47800
47801 void (*set_engine_pll_state)(u8 state);
47802 void (*set_engine_pll)(struct via_pll_config config);
47803-};
47804+} __no_const;
47805
47806
47807 static inline u32 get_pll_internal_frequency(u32 ref_freq,
47808diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
47809index fef20db..d28b1ab 100644
47810--- a/drivers/xen/xenfs/xenstored.c
47811+++ b/drivers/xen/xenfs/xenstored.c
47812@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
47813 static int xsd_kva_open(struct inode *inode, struct file *file)
47814 {
47815 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
47816+#ifdef CONFIG_GRKERNSEC_HIDESYM
47817+ NULL);
47818+#else
47819 xen_store_interface);
47820+#endif
47821+
47822 if (!file->private_data)
47823 return -ENOMEM;
47824 return 0;
47825diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
47826index 0ad61c6..f198bd7 100644
47827--- a/fs/9p/vfs_addr.c
47828+++ b/fs/9p/vfs_addr.c
47829@@ -185,7 +185,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
47830
47831 retval = v9fs_file_write_internal(inode,
47832 v9inode->writeback_fid,
47833- (__force const char __user *)buffer,
47834+ (const char __force_user *)buffer,
47835 len, &offset, 0);
47836 if (retval > 0)
47837 retval = 0;
47838diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
47839index d86edc8..40ff2fb 100644
47840--- a/fs/9p/vfs_inode.c
47841+++ b/fs/9p/vfs_inode.c
47842@@ -1314,7 +1314,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
47843 void
47844 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47845 {
47846- char *s = nd_get_link(nd);
47847+ const char *s = nd_get_link(nd);
47848
47849 p9_debug(P9_DEBUG_VFS, " %s %s\n",
47850 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
47851diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
47852index 0efd152..b5802ad 100644
47853--- a/fs/Kconfig.binfmt
47854+++ b/fs/Kconfig.binfmt
47855@@ -89,7 +89,7 @@ config HAVE_AOUT
47856
47857 config BINFMT_AOUT
47858 tristate "Kernel support for a.out and ECOFF binaries"
47859- depends on HAVE_AOUT
47860+ depends on HAVE_AOUT && BROKEN
47861 ---help---
47862 A.out (Assembler.OUTput) is a set of formats for libraries and
47863 executables used in the earliest versions of UNIX. Linux used
47864diff --git a/fs/aio.c b/fs/aio.c
47865index 1dc8786..d3b29e8 100644
47866--- a/fs/aio.c
47867+++ b/fs/aio.c
47868@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
47869 size += sizeof(struct io_event) * nr_events;
47870 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
47871
47872- if (nr_pages < 0)
47873+ if (nr_pages <= 0)
47874 return -EINVAL;
47875
47876 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
47877@@ -1375,18 +1375,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
47878 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
47879 {
47880 ssize_t ret;
47881+ struct iovec iovstack;
47882
47883 #ifdef CONFIG_COMPAT
47884 if (compat)
47885 ret = compat_rw_copy_check_uvector(type,
47886 (struct compat_iovec __user *)kiocb->ki_buf,
47887- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
47888+ kiocb->ki_nbytes, 1, &iovstack,
47889 &kiocb->ki_iovec);
47890 else
47891 #endif
47892 ret = rw_copy_check_uvector(type,
47893 (struct iovec __user *)kiocb->ki_buf,
47894- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
47895+ kiocb->ki_nbytes, 1, &iovstack,
47896 &kiocb->ki_iovec);
47897 if (ret < 0)
47898 goto out;
47899@@ -1395,6 +1396,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
47900 if (ret < 0)
47901 goto out;
47902
47903+ if (kiocb->ki_iovec == &iovstack) {
47904+ kiocb->ki_inline_vec = iovstack;
47905+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
47906+ }
47907 kiocb->ki_nr_segs = kiocb->ki_nbytes;
47908 kiocb->ki_cur_seg = 0;
47909 /* ki_nbytes/left now reflect bytes instead of segs */
47910diff --git a/fs/attr.c b/fs/attr.c
47911index 1449adb..a2038c2 100644
47912--- a/fs/attr.c
47913+++ b/fs/attr.c
47914@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
47915 unsigned long limit;
47916
47917 limit = rlimit(RLIMIT_FSIZE);
47918+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
47919 if (limit != RLIM_INFINITY && offset > limit)
47920 goto out_sig;
47921 if (offset > inode->i_sb->s_maxbytes)
47922diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
47923index 3db70da..7aeec5b 100644
47924--- a/fs/autofs4/waitq.c
47925+++ b/fs/autofs4/waitq.c
47926@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
47927 {
47928 unsigned long sigpipe, flags;
47929 mm_segment_t fs;
47930- const char *data = (const char *)addr;
47931+ const char __user *data = (const char __force_user *)addr;
47932 ssize_t wr = 0;
47933
47934 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
47935@@ -346,6 +346,10 @@ static int validate_request(struct autofs_wait_queue **wait,
47936 return 1;
47937 }
47938
47939+#ifdef CONFIG_GRKERNSEC_HIDESYM
47940+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
47941+#endif
47942+
47943 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
47944 enum autofs_notify notify)
47945 {
47946@@ -379,7 +383,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
47947
47948 /* If this is a direct mount request create a dummy name */
47949 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
47950+#ifdef CONFIG_GRKERNSEC_HIDESYM
47951+ /* this name does get written to userland via autofs4_write() */
47952+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
47953+#else
47954 qstr.len = sprintf(name, "%p", dentry);
47955+#endif
47956 else {
47957 qstr.len = autofs4_getpath(sbi, dentry, &name);
47958 if (!qstr.len) {
47959diff --git a/fs/befs/endian.h b/fs/befs/endian.h
47960index 2722387..c8dd2a7 100644
47961--- a/fs/befs/endian.h
47962+++ b/fs/befs/endian.h
47963@@ -11,7 +11,7 @@
47964
47965 #include <asm/byteorder.h>
47966
47967-static inline u64
47968+static inline u64 __intentional_overflow(-1)
47969 fs64_to_cpu(const struct super_block *sb, fs64 n)
47970 {
47971 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
47972@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
47973 return (__force fs64)cpu_to_be64(n);
47974 }
47975
47976-static inline u32
47977+static inline u32 __intentional_overflow(-1)
47978 fs32_to_cpu(const struct super_block *sb, fs32 n)
47979 {
47980 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
47981diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
47982index 8615ee8..388ed68 100644
47983--- a/fs/befs/linuxvfs.c
47984+++ b/fs/befs/linuxvfs.c
47985@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47986 {
47987 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
47988 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
47989- char *link = nd_get_link(nd);
47990+ const char *link = nd_get_link(nd);
47991 if (!IS_ERR(link))
47992 kfree(link);
47993 }
47994diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
47995index bbc8f88..7c7ac97 100644
47996--- a/fs/binfmt_aout.c
47997+++ b/fs/binfmt_aout.c
47998@@ -16,6 +16,7 @@
47999 #include <linux/string.h>
48000 #include <linux/fs.h>
48001 #include <linux/file.h>
48002+#include <linux/security.h>
48003 #include <linux/stat.h>
48004 #include <linux/fcntl.h>
48005 #include <linux/ptrace.h>
48006@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
48007 #endif
48008 # define START_STACK(u) ((void __user *)u.start_stack)
48009
48010+ memset(&dump, 0, sizeof(dump));
48011+
48012 fs = get_fs();
48013 set_fs(KERNEL_DS);
48014 has_dumped = 1;
48015@@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
48016
48017 /* If the size of the dump file exceeds the rlimit, then see what would happen
48018 if we wrote the stack, but not the data area. */
48019+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
48020 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
48021 dump.u_dsize = 0;
48022
48023 /* Make sure we have enough room to write the stack and data areas. */
48024+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
48025 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
48026 dump.u_ssize = 0;
48027
48028@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
48029 rlim = rlimit(RLIMIT_DATA);
48030 if (rlim >= RLIM_INFINITY)
48031 rlim = ~0;
48032+
48033+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
48034 if (ex.a_data + ex.a_bss > rlim)
48035 return -ENOMEM;
48036
48037@@ -268,6 +275,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
48038
48039 install_exec_creds(bprm);
48040
48041+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48042+ current->mm->pax_flags = 0UL;
48043+#endif
48044+
48045+#ifdef CONFIG_PAX_PAGEEXEC
48046+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
48047+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
48048+
48049+#ifdef CONFIG_PAX_EMUTRAMP
48050+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
48051+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
48052+#endif
48053+
48054+#ifdef CONFIG_PAX_MPROTECT
48055+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
48056+ current->mm->pax_flags |= MF_PAX_MPROTECT;
48057+#endif
48058+
48059+ }
48060+#endif
48061+
48062 if (N_MAGIC(ex) == OMAGIC) {
48063 unsigned long text_addr, map_size;
48064 loff_t pos;
48065@@ -333,7 +361,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
48066 }
48067
48068 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
48069- PROT_READ | PROT_WRITE | PROT_EXEC,
48070+ PROT_READ | PROT_WRITE,
48071 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
48072 fd_offset + ex.a_text);
48073 if (error != N_DATADDR(ex)) {
48074diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
48075index 86af964..5d53bf6 100644
48076--- a/fs/binfmt_elf.c
48077+++ b/fs/binfmt_elf.c
48078@@ -34,6 +34,7 @@
48079 #include <linux/utsname.h>
48080 #include <linux/coredump.h>
48081 #include <linux/sched.h>
48082+#include <linux/xattr.h>
48083 #include <asm/uaccess.h>
48084 #include <asm/param.h>
48085 #include <asm/page.h>
48086@@ -60,6 +61,10 @@ static int elf_core_dump(struct coredump_params *cprm);
48087 #define elf_core_dump NULL
48088 #endif
48089
48090+#ifdef CONFIG_PAX_MPROTECT
48091+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
48092+#endif
48093+
48094 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
48095 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
48096 #else
48097@@ -79,6 +84,11 @@ static struct linux_binfmt elf_format = {
48098 .load_binary = load_elf_binary,
48099 .load_shlib = load_elf_library,
48100 .core_dump = elf_core_dump,
48101+
48102+#ifdef CONFIG_PAX_MPROTECT
48103+ .handle_mprotect= elf_handle_mprotect,
48104+#endif
48105+
48106 .min_coredump = ELF_EXEC_PAGESIZE,
48107 };
48108
48109@@ -86,6 +96,8 @@ static struct linux_binfmt elf_format = {
48110
48111 static int set_brk(unsigned long start, unsigned long end)
48112 {
48113+ unsigned long e = end;
48114+
48115 start = ELF_PAGEALIGN(start);
48116 end = ELF_PAGEALIGN(end);
48117 if (end > start) {
48118@@ -94,7 +106,7 @@ static int set_brk(unsigned long start, unsigned long end)
48119 if (BAD_ADDR(addr))
48120 return addr;
48121 }
48122- current->mm->start_brk = current->mm->brk = end;
48123+ current->mm->start_brk = current->mm->brk = e;
48124 return 0;
48125 }
48126
48127@@ -155,12 +167,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48128 elf_addr_t __user *u_rand_bytes;
48129 const char *k_platform = ELF_PLATFORM;
48130 const char *k_base_platform = ELF_BASE_PLATFORM;
48131- unsigned char k_rand_bytes[16];
48132+ u32 k_rand_bytes[4];
48133 int items;
48134 elf_addr_t *elf_info;
48135 int ei_index = 0;
48136 const struct cred *cred = current_cred();
48137 struct vm_area_struct *vma;
48138+ unsigned long saved_auxv[AT_VECTOR_SIZE];
48139
48140 /*
48141 * In some cases (e.g. Hyper-Threading), we want to avoid L1
48142@@ -202,8 +215,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48143 * Generate 16 random bytes for userspace PRNG seeding.
48144 */
48145 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
48146- u_rand_bytes = (elf_addr_t __user *)
48147- STACK_ALLOC(p, sizeof(k_rand_bytes));
48148+ srandom32(k_rand_bytes[0] ^ random32());
48149+ srandom32(k_rand_bytes[1] ^ random32());
48150+ srandom32(k_rand_bytes[2] ^ random32());
48151+ srandom32(k_rand_bytes[3] ^ random32());
48152+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
48153+ u_rand_bytes = (elf_addr_t __user *) p;
48154 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
48155 return -EFAULT;
48156
48157@@ -315,9 +332,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48158 return -EFAULT;
48159 current->mm->env_end = p;
48160
48161+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
48162+
48163 /* Put the elf_info on the stack in the right place. */
48164 sp = (elf_addr_t __user *)envp + 1;
48165- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
48166+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
48167 return -EFAULT;
48168 return 0;
48169 }
48170@@ -385,15 +404,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
48171 an ELF header */
48172
48173 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48174- struct file *interpreter, unsigned long *interp_map_addr,
48175- unsigned long no_base)
48176+ struct file *interpreter, unsigned long no_base)
48177 {
48178 struct elf_phdr *elf_phdata;
48179 struct elf_phdr *eppnt;
48180- unsigned long load_addr = 0;
48181+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
48182 int load_addr_set = 0;
48183 unsigned long last_bss = 0, elf_bss = 0;
48184- unsigned long error = ~0UL;
48185+ unsigned long error = -EINVAL;
48186 unsigned long total_size;
48187 int retval, i, size;
48188
48189@@ -439,6 +457,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48190 goto out_close;
48191 }
48192
48193+#ifdef CONFIG_PAX_SEGMEXEC
48194+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
48195+ pax_task_size = SEGMEXEC_TASK_SIZE;
48196+#endif
48197+
48198 eppnt = elf_phdata;
48199 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
48200 if (eppnt->p_type == PT_LOAD) {
48201@@ -462,8 +485,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48202 map_addr = elf_map(interpreter, load_addr + vaddr,
48203 eppnt, elf_prot, elf_type, total_size);
48204 total_size = 0;
48205- if (!*interp_map_addr)
48206- *interp_map_addr = map_addr;
48207 error = map_addr;
48208 if (BAD_ADDR(map_addr))
48209 goto out_close;
48210@@ -482,8 +503,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48211 k = load_addr + eppnt->p_vaddr;
48212 if (BAD_ADDR(k) ||
48213 eppnt->p_filesz > eppnt->p_memsz ||
48214- eppnt->p_memsz > TASK_SIZE ||
48215- TASK_SIZE - eppnt->p_memsz < k) {
48216+ eppnt->p_memsz > pax_task_size ||
48217+ pax_task_size - eppnt->p_memsz < k) {
48218 error = -ENOMEM;
48219 goto out_close;
48220 }
48221@@ -535,6 +556,315 @@ out:
48222 return error;
48223 }
48224
48225+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48226+#ifdef CONFIG_PAX_SOFTMODE
48227+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
48228+{
48229+ unsigned long pax_flags = 0UL;
48230+
48231+#ifdef CONFIG_PAX_PAGEEXEC
48232+ if (elf_phdata->p_flags & PF_PAGEEXEC)
48233+ pax_flags |= MF_PAX_PAGEEXEC;
48234+#endif
48235+
48236+#ifdef CONFIG_PAX_SEGMEXEC
48237+ if (elf_phdata->p_flags & PF_SEGMEXEC)
48238+ pax_flags |= MF_PAX_SEGMEXEC;
48239+#endif
48240+
48241+#ifdef CONFIG_PAX_EMUTRAMP
48242+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
48243+ pax_flags |= MF_PAX_EMUTRAMP;
48244+#endif
48245+
48246+#ifdef CONFIG_PAX_MPROTECT
48247+ if (elf_phdata->p_flags & PF_MPROTECT)
48248+ pax_flags |= MF_PAX_MPROTECT;
48249+#endif
48250+
48251+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48252+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
48253+ pax_flags |= MF_PAX_RANDMMAP;
48254+#endif
48255+
48256+ return pax_flags;
48257+}
48258+#endif
48259+
48260+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
48261+{
48262+ unsigned long pax_flags = 0UL;
48263+
48264+#ifdef CONFIG_PAX_PAGEEXEC
48265+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
48266+ pax_flags |= MF_PAX_PAGEEXEC;
48267+#endif
48268+
48269+#ifdef CONFIG_PAX_SEGMEXEC
48270+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
48271+ pax_flags |= MF_PAX_SEGMEXEC;
48272+#endif
48273+
48274+#ifdef CONFIG_PAX_EMUTRAMP
48275+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
48276+ pax_flags |= MF_PAX_EMUTRAMP;
48277+#endif
48278+
48279+#ifdef CONFIG_PAX_MPROTECT
48280+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
48281+ pax_flags |= MF_PAX_MPROTECT;
48282+#endif
48283+
48284+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48285+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
48286+ pax_flags |= MF_PAX_RANDMMAP;
48287+#endif
48288+
48289+ return pax_flags;
48290+}
48291+#endif
48292+
48293+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48294+#ifdef CONFIG_PAX_SOFTMODE
48295+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
48296+{
48297+ unsigned long pax_flags = 0UL;
48298+
48299+#ifdef CONFIG_PAX_PAGEEXEC
48300+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
48301+ pax_flags |= MF_PAX_PAGEEXEC;
48302+#endif
48303+
48304+#ifdef CONFIG_PAX_SEGMEXEC
48305+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
48306+ pax_flags |= MF_PAX_SEGMEXEC;
48307+#endif
48308+
48309+#ifdef CONFIG_PAX_EMUTRAMP
48310+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
48311+ pax_flags |= MF_PAX_EMUTRAMP;
48312+#endif
48313+
48314+#ifdef CONFIG_PAX_MPROTECT
48315+ if (pax_flags_softmode & MF_PAX_MPROTECT)
48316+ pax_flags |= MF_PAX_MPROTECT;
48317+#endif
48318+
48319+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48320+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
48321+ pax_flags |= MF_PAX_RANDMMAP;
48322+#endif
48323+
48324+ return pax_flags;
48325+}
48326+#endif
48327+
48328+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
48329+{
48330+ unsigned long pax_flags = 0UL;
48331+
48332+#ifdef CONFIG_PAX_PAGEEXEC
48333+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
48334+ pax_flags |= MF_PAX_PAGEEXEC;
48335+#endif
48336+
48337+#ifdef CONFIG_PAX_SEGMEXEC
48338+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
48339+ pax_flags |= MF_PAX_SEGMEXEC;
48340+#endif
48341+
48342+#ifdef CONFIG_PAX_EMUTRAMP
48343+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
48344+ pax_flags |= MF_PAX_EMUTRAMP;
48345+#endif
48346+
48347+#ifdef CONFIG_PAX_MPROTECT
48348+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
48349+ pax_flags |= MF_PAX_MPROTECT;
48350+#endif
48351+
48352+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48353+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
48354+ pax_flags |= MF_PAX_RANDMMAP;
48355+#endif
48356+
48357+ return pax_flags;
48358+}
48359+#endif
48360+
48361+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48362+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
48363+{
48364+ unsigned long pax_flags = 0UL;
48365+
48366+#ifdef CONFIG_PAX_EI_PAX
48367+
48368+#ifdef CONFIG_PAX_PAGEEXEC
48369+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
48370+ pax_flags |= MF_PAX_PAGEEXEC;
48371+#endif
48372+
48373+#ifdef CONFIG_PAX_SEGMEXEC
48374+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
48375+ pax_flags |= MF_PAX_SEGMEXEC;
48376+#endif
48377+
48378+#ifdef CONFIG_PAX_EMUTRAMP
48379+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
48380+ pax_flags |= MF_PAX_EMUTRAMP;
48381+#endif
48382+
48383+#ifdef CONFIG_PAX_MPROTECT
48384+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
48385+ pax_flags |= MF_PAX_MPROTECT;
48386+#endif
48387+
48388+#ifdef CONFIG_PAX_ASLR
48389+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
48390+ pax_flags |= MF_PAX_RANDMMAP;
48391+#endif
48392+
48393+#else
48394+
48395+#ifdef CONFIG_PAX_PAGEEXEC
48396+ pax_flags |= MF_PAX_PAGEEXEC;
48397+#endif
48398+
48399+#ifdef CONFIG_PAX_SEGMEXEC
48400+ pax_flags |= MF_PAX_SEGMEXEC;
48401+#endif
48402+
48403+#ifdef CONFIG_PAX_MPROTECT
48404+ pax_flags |= MF_PAX_MPROTECT;
48405+#endif
48406+
48407+#ifdef CONFIG_PAX_RANDMMAP
48408+ if (randomize_va_space)
48409+ pax_flags |= MF_PAX_RANDMMAP;
48410+#endif
48411+
48412+#endif
48413+
48414+ return pax_flags;
48415+}
48416+
48417+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
48418+{
48419+
48420+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48421+ unsigned long i;
48422+
48423+ for (i = 0UL; i < elf_ex->e_phnum; i++)
48424+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
48425+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
48426+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
48427+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
48428+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
48429+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
48430+ return ~0UL;
48431+
48432+#ifdef CONFIG_PAX_SOFTMODE
48433+ if (pax_softmode)
48434+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
48435+ else
48436+#endif
48437+
48438+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
48439+ break;
48440+ }
48441+#endif
48442+
48443+ return ~0UL;
48444+}
48445+
48446+static unsigned long pax_parse_xattr_pax(struct file * const file)
48447+{
48448+
48449+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48450+ ssize_t xattr_size, i;
48451+ unsigned char xattr_value[sizeof("pemrs") - 1];
48452+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
48453+
48454+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
48455+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
48456+ return ~0UL;
48457+
48458+ for (i = 0; i < xattr_size; i++)
48459+ switch (xattr_value[i]) {
48460+ default:
48461+ return ~0UL;
48462+
48463+#define parse_flag(option1, option2, flag) \
48464+ case option1: \
48465+ if (pax_flags_hardmode & MF_PAX_##flag) \
48466+ return ~0UL; \
48467+ pax_flags_hardmode |= MF_PAX_##flag; \
48468+ break; \
48469+ case option2: \
48470+ if (pax_flags_softmode & MF_PAX_##flag) \
48471+ return ~0UL; \
48472+ pax_flags_softmode |= MF_PAX_##flag; \
48473+ break;
48474+
48475+ parse_flag('p', 'P', PAGEEXEC);
48476+ parse_flag('e', 'E', EMUTRAMP);
48477+ parse_flag('m', 'M', MPROTECT);
48478+ parse_flag('r', 'R', RANDMMAP);
48479+ parse_flag('s', 'S', SEGMEXEC);
48480+
48481+#undef parse_flag
48482+ }
48483+
48484+ if (pax_flags_hardmode & pax_flags_softmode)
48485+ return ~0UL;
48486+
48487+#ifdef CONFIG_PAX_SOFTMODE
48488+ if (pax_softmode)
48489+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
48490+ else
48491+#endif
48492+
48493+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
48494+#else
48495+ return ~0UL;
48496+#endif
48497+
48498+}
48499+
48500+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
48501+{
48502+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
48503+
48504+ pax_flags = pax_parse_ei_pax(elf_ex);
48505+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
48506+ xattr_pax_flags = pax_parse_xattr_pax(file);
48507+
48508+ if (pt_pax_flags == ~0UL)
48509+ pt_pax_flags = xattr_pax_flags;
48510+ else if (xattr_pax_flags == ~0UL)
48511+ xattr_pax_flags = pt_pax_flags;
48512+ if (pt_pax_flags != xattr_pax_flags)
48513+ return -EINVAL;
48514+ if (pt_pax_flags != ~0UL)
48515+ pax_flags = pt_pax_flags;
48516+
48517+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
48518+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48519+ if ((__supported_pte_mask & _PAGE_NX))
48520+ pax_flags &= ~MF_PAX_SEGMEXEC;
48521+ else
48522+ pax_flags &= ~MF_PAX_PAGEEXEC;
48523+ }
48524+#endif
48525+
48526+ if (0 > pax_check_flags(&pax_flags))
48527+ return -EINVAL;
48528+
48529+ current->mm->pax_flags = pax_flags;
48530+ return 0;
48531+}
48532+#endif
48533+
48534 /*
48535 * These are the functions used to load ELF style executables and shared
48536 * libraries. There is no binary dependent code anywhere else.
48537@@ -551,6 +881,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
48538 {
48539 unsigned int random_variable = 0;
48540
48541+#ifdef CONFIG_PAX_RANDUSTACK
48542+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
48543+ return stack_top - current->mm->delta_stack;
48544+#endif
48545+
48546 if ((current->flags & PF_RANDOMIZE) &&
48547 !(current->personality & ADDR_NO_RANDOMIZE)) {
48548 random_variable = get_random_int() & STACK_RND_MASK;
48549@@ -569,7 +904,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
48550 unsigned long load_addr = 0, load_bias = 0;
48551 int load_addr_set = 0;
48552 char * elf_interpreter = NULL;
48553- unsigned long error;
48554+ unsigned long error = 0;
48555 struct elf_phdr *elf_ppnt, *elf_phdata;
48556 unsigned long elf_bss, elf_brk;
48557 int retval, i;
48558@@ -579,12 +914,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
48559 unsigned long start_code, end_code, start_data, end_data;
48560 unsigned long reloc_func_desc __maybe_unused = 0;
48561 int executable_stack = EXSTACK_DEFAULT;
48562- unsigned long def_flags = 0;
48563 struct pt_regs *regs = current_pt_regs();
48564 struct {
48565 struct elfhdr elf_ex;
48566 struct elfhdr interp_elf_ex;
48567 } *loc;
48568+ unsigned long pax_task_size = TASK_SIZE;
48569
48570 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
48571 if (!loc) {
48572@@ -720,11 +1055,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
48573 goto out_free_dentry;
48574
48575 /* OK, This is the point of no return */
48576- current->mm->def_flags = def_flags;
48577+
48578+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48579+ current->mm->pax_flags = 0UL;
48580+#endif
48581+
48582+#ifdef CONFIG_PAX_DLRESOLVE
48583+ current->mm->call_dl_resolve = 0UL;
48584+#endif
48585+
48586+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
48587+ current->mm->call_syscall = 0UL;
48588+#endif
48589+
48590+#ifdef CONFIG_PAX_ASLR
48591+ current->mm->delta_mmap = 0UL;
48592+ current->mm->delta_stack = 0UL;
48593+#endif
48594+
48595+ current->mm->def_flags = 0;
48596+
48597+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48598+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
48599+ send_sig(SIGKILL, current, 0);
48600+ goto out_free_dentry;
48601+ }
48602+#endif
48603+
48604+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
48605+ pax_set_initial_flags(bprm);
48606+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
48607+ if (pax_set_initial_flags_func)
48608+ (pax_set_initial_flags_func)(bprm);
48609+#endif
48610+
48611+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48612+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
48613+ current->mm->context.user_cs_limit = PAGE_SIZE;
48614+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
48615+ }
48616+#endif
48617+
48618+#ifdef CONFIG_PAX_SEGMEXEC
48619+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
48620+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
48621+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
48622+ pax_task_size = SEGMEXEC_TASK_SIZE;
48623+ current->mm->def_flags |= VM_NOHUGEPAGE;
48624+ }
48625+#endif
48626+
48627+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
48628+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48629+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
48630+ put_cpu();
48631+ }
48632+#endif
48633
48634 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
48635 may depend on the personality. */
48636 SET_PERSONALITY(loc->elf_ex);
48637+
48638+#ifdef CONFIG_PAX_ASLR
48639+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
48640+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
48641+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
48642+ }
48643+#endif
48644+
48645+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
48646+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48647+ executable_stack = EXSTACK_DISABLE_X;
48648+ current->personality &= ~READ_IMPLIES_EXEC;
48649+ } else
48650+#endif
48651+
48652 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
48653 current->personality |= READ_IMPLIES_EXEC;
48654
48655@@ -815,6 +1220,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
48656 #else
48657 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
48658 #endif
48659+
48660+#ifdef CONFIG_PAX_RANDMMAP
48661+ /* PaX: randomize base address at the default exe base if requested */
48662+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
48663+#ifdef CONFIG_SPARC64
48664+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
48665+#else
48666+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
48667+#endif
48668+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
48669+ elf_flags |= MAP_FIXED;
48670+ }
48671+#endif
48672+
48673 }
48674
48675 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
48676@@ -847,9 +1266,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
48677 * allowed task size. Note that p_filesz must always be
48678 * <= p_memsz so it is only necessary to check p_memsz.
48679 */
48680- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
48681- elf_ppnt->p_memsz > TASK_SIZE ||
48682- TASK_SIZE - elf_ppnt->p_memsz < k) {
48683+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
48684+ elf_ppnt->p_memsz > pax_task_size ||
48685+ pax_task_size - elf_ppnt->p_memsz < k) {
48686 /* set_brk can never work. Avoid overflows. */
48687 send_sig(SIGKILL, current, 0);
48688 retval = -EINVAL;
48689@@ -888,17 +1307,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
48690 goto out_free_dentry;
48691 }
48692 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
48693- send_sig(SIGSEGV, current, 0);
48694- retval = -EFAULT; /* Nobody gets to see this, but.. */
48695- goto out_free_dentry;
48696+ /*
48697+ * This bss-zeroing can fail if the ELF
48698+ * file specifies odd protections. So
48699+ * we don't check the return value
48700+ */
48701 }
48702
48703+#ifdef CONFIG_PAX_RANDMMAP
48704+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
48705+ unsigned long start, size, flags;
48706+ vm_flags_t vm_flags;
48707+
48708+ start = ELF_PAGEALIGN(elf_brk);
48709+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
48710+ flags = MAP_FIXED | MAP_PRIVATE;
48711+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
48712+
48713+ down_write(&current->mm->mmap_sem);
48714+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
48715+ retval = -ENOMEM;
48716+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
48717+// if (current->personality & ADDR_NO_RANDOMIZE)
48718+// vm_flags |= VM_READ | VM_MAYREAD;
48719+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
48720+ retval = IS_ERR_VALUE(start) ? start : 0;
48721+ }
48722+ up_write(&current->mm->mmap_sem);
48723+ if (retval == 0)
48724+ retval = set_brk(start + size, start + size + PAGE_SIZE);
48725+ if (retval < 0) {
48726+ send_sig(SIGKILL, current, 0);
48727+ goto out_free_dentry;
48728+ }
48729+ }
48730+#endif
48731+
48732 if (elf_interpreter) {
48733- unsigned long interp_map_addr = 0;
48734-
48735 elf_entry = load_elf_interp(&loc->interp_elf_ex,
48736 interpreter,
48737- &interp_map_addr,
48738 load_bias);
48739 if (!IS_ERR((void *)elf_entry)) {
48740 /*
48741@@ -1120,7 +1567,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
48742 * Decide what to dump of a segment, part, all or none.
48743 */
48744 static unsigned long vma_dump_size(struct vm_area_struct *vma,
48745- unsigned long mm_flags)
48746+ unsigned long mm_flags, long signr)
48747 {
48748 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
48749
48750@@ -1158,7 +1605,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
48751 if (vma->vm_file == NULL)
48752 return 0;
48753
48754- if (FILTER(MAPPED_PRIVATE))
48755+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
48756 goto whole;
48757
48758 /*
48759@@ -1383,9 +1830,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
48760 {
48761 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
48762 int i = 0;
48763- do
48764+ do {
48765 i += 2;
48766- while (auxv[i - 2] != AT_NULL);
48767+ } while (auxv[i - 2] != AT_NULL);
48768 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
48769 }
48770
48771@@ -1394,7 +1841,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
48772 {
48773 mm_segment_t old_fs = get_fs();
48774 set_fs(KERNEL_DS);
48775- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
48776+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
48777 set_fs(old_fs);
48778 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
48779 }
48780@@ -2015,14 +2462,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
48781 }
48782
48783 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
48784- unsigned long mm_flags)
48785+ struct coredump_params *cprm)
48786 {
48787 struct vm_area_struct *vma;
48788 size_t size = 0;
48789
48790 for (vma = first_vma(current, gate_vma); vma != NULL;
48791 vma = next_vma(vma, gate_vma))
48792- size += vma_dump_size(vma, mm_flags);
48793+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48794 return size;
48795 }
48796
48797@@ -2116,7 +2563,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48798
48799 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
48800
48801- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
48802+ offset += elf_core_vma_data_size(gate_vma, cprm);
48803 offset += elf_core_extra_data_size();
48804 e_shoff = offset;
48805
48806@@ -2130,10 +2577,12 @@ static int elf_core_dump(struct coredump_params *cprm)
48807 offset = dataoff;
48808
48809 size += sizeof(*elf);
48810+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48811 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
48812 goto end_coredump;
48813
48814 size += sizeof(*phdr4note);
48815+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48816 if (size > cprm->limit
48817 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
48818 goto end_coredump;
48819@@ -2147,7 +2596,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48820 phdr.p_offset = offset;
48821 phdr.p_vaddr = vma->vm_start;
48822 phdr.p_paddr = 0;
48823- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
48824+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48825 phdr.p_memsz = vma->vm_end - vma->vm_start;
48826 offset += phdr.p_filesz;
48827 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
48828@@ -2158,6 +2607,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48829 phdr.p_align = ELF_EXEC_PAGESIZE;
48830
48831 size += sizeof(phdr);
48832+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48833 if (size > cprm->limit
48834 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
48835 goto end_coredump;
48836@@ -2182,7 +2632,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48837 unsigned long addr;
48838 unsigned long end;
48839
48840- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
48841+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48842
48843 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
48844 struct page *page;
48845@@ -2191,6 +2641,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48846 page = get_dump_page(addr);
48847 if (page) {
48848 void *kaddr = kmap(page);
48849+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
48850 stop = ((size += PAGE_SIZE) > cprm->limit) ||
48851 !dump_write(cprm->file, kaddr,
48852 PAGE_SIZE);
48853@@ -2208,6 +2659,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48854
48855 if (e_phnum == PN_XNUM) {
48856 size += sizeof(*shdr4extnum);
48857+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48858 if (size > cprm->limit
48859 || !dump_write(cprm->file, shdr4extnum,
48860 sizeof(*shdr4extnum)))
48861@@ -2228,6 +2680,97 @@ out:
48862
48863 #endif /* CONFIG_ELF_CORE */
48864
48865+#ifdef CONFIG_PAX_MPROTECT
48866+/* PaX: non-PIC ELF libraries need relocations on their executable segments
48867+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
48868+ * we'll remove VM_MAYWRITE for good on RELRO segments.
48869+ *
48870+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
48871+ * basis because we want to allow the common case and not the special ones.
48872+ */
48873+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
48874+{
48875+ struct elfhdr elf_h;
48876+ struct elf_phdr elf_p;
48877+ unsigned long i;
48878+ unsigned long oldflags;
48879+ bool is_textrel_rw, is_textrel_rx, is_relro;
48880+
48881+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
48882+ return;
48883+
48884+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
48885+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
48886+
48887+#ifdef CONFIG_PAX_ELFRELOCS
48888+ /* possible TEXTREL */
48889+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
48890+ 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);
48891+#else
48892+ is_textrel_rw = false;
48893+ is_textrel_rx = false;
48894+#endif
48895+
48896+ /* possible RELRO */
48897+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
48898+
48899+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
48900+ return;
48901+
48902+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
48903+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
48904+
48905+#ifdef CONFIG_PAX_ETEXECRELOCS
48906+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
48907+#else
48908+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
48909+#endif
48910+
48911+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
48912+ !elf_check_arch(&elf_h) ||
48913+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
48914+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
48915+ return;
48916+
48917+ for (i = 0UL; i < elf_h.e_phnum; i++) {
48918+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
48919+ return;
48920+ switch (elf_p.p_type) {
48921+ case PT_DYNAMIC:
48922+ if (!is_textrel_rw && !is_textrel_rx)
48923+ continue;
48924+ i = 0UL;
48925+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
48926+ elf_dyn dyn;
48927+
48928+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
48929+ return;
48930+ if (dyn.d_tag == DT_NULL)
48931+ return;
48932+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
48933+ gr_log_textrel(vma);
48934+ if (is_textrel_rw)
48935+ vma->vm_flags |= VM_MAYWRITE;
48936+ else
48937+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
48938+ vma->vm_flags &= ~VM_MAYWRITE;
48939+ return;
48940+ }
48941+ i++;
48942+ }
48943+ return;
48944+
48945+ case PT_GNU_RELRO:
48946+ if (!is_relro)
48947+ continue;
48948+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
48949+ vma->vm_flags &= ~VM_MAYWRITE;
48950+ return;
48951+ }
48952+ }
48953+}
48954+#endif
48955+
48956 static int __init init_elf_binfmt(void)
48957 {
48958 register_binfmt(&elf_format);
48959diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
48960index 2036d21..b0430d0 100644
48961--- a/fs/binfmt_flat.c
48962+++ b/fs/binfmt_flat.c
48963@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
48964 realdatastart = (unsigned long) -ENOMEM;
48965 printk("Unable to allocate RAM for process data, errno %d\n",
48966 (int)-realdatastart);
48967+ down_write(&current->mm->mmap_sem);
48968 vm_munmap(textpos, text_len);
48969+ up_write(&current->mm->mmap_sem);
48970 ret = realdatastart;
48971 goto err;
48972 }
48973@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
48974 }
48975 if (IS_ERR_VALUE(result)) {
48976 printk("Unable to read data+bss, errno %d\n", (int)-result);
48977+ down_write(&current->mm->mmap_sem);
48978 vm_munmap(textpos, text_len);
48979 vm_munmap(realdatastart, len);
48980+ up_write(&current->mm->mmap_sem);
48981 ret = result;
48982 goto err;
48983 }
48984@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
48985 }
48986 if (IS_ERR_VALUE(result)) {
48987 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
48988+ down_write(&current->mm->mmap_sem);
48989 vm_munmap(textpos, text_len + data_len + extra +
48990 MAX_SHARED_LIBS * sizeof(unsigned long));
48991+ up_write(&current->mm->mmap_sem);
48992 ret = result;
48993 goto err;
48994 }
48995diff --git a/fs/bio.c b/fs/bio.c
48996index b96fc6c..431d628 100644
48997--- a/fs/bio.c
48998+++ b/fs/bio.c
48999@@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
49000 /*
49001 * Overflow, abort
49002 */
49003- if (end < start)
49004+ if (end < start || end - start > INT_MAX - nr_pages)
49005 return ERR_PTR(-EINVAL);
49006
49007 nr_pages += end - start;
49008@@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
49009 /*
49010 * Overflow, abort
49011 */
49012- if (end < start)
49013+ if (end < start || end - start > INT_MAX - nr_pages)
49014 return ERR_PTR(-EINVAL);
49015
49016 nr_pages += end - start;
49017@@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
49018 const int read = bio_data_dir(bio) == READ;
49019 struct bio_map_data *bmd = bio->bi_private;
49020 int i;
49021- char *p = bmd->sgvecs[0].iov_base;
49022+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
49023
49024 __bio_for_each_segment(bvec, bio, i, 0) {
49025 char *addr = page_address(bvec->bv_page);
49026diff --git a/fs/block_dev.c b/fs/block_dev.c
49027index aae187a..fd790ba 100644
49028--- a/fs/block_dev.c
49029+++ b/fs/block_dev.c
49030@@ -652,7 +652,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
49031 else if (bdev->bd_contains == bdev)
49032 return true; /* is a whole device which isn't held */
49033
49034- else if (whole->bd_holder == bd_may_claim)
49035+ else if (whole->bd_holder == (void *)bd_may_claim)
49036 return true; /* is a partition of a device that is being partitioned */
49037 else if (whole->bd_holder != NULL)
49038 return false; /* is a partition of a held device */
49039diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
49040index ca9d8f1..8c0142d 100644
49041--- a/fs/btrfs/ctree.c
49042+++ b/fs/btrfs/ctree.c
49043@@ -1036,9 +1036,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
49044 free_extent_buffer(buf);
49045 add_root_to_dirty_list(root);
49046 } else {
49047- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
49048- parent_start = parent->start;
49049- else
49050+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
49051+ if (parent)
49052+ parent_start = parent->start;
49053+ else
49054+ parent_start = 0;
49055+ } else
49056 parent_start = 0;
49057
49058 WARN_ON(trans->transid != btrfs_header_generation(parent));
49059diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
49060index f49b62f..07834ab 100644
49061--- a/fs/btrfs/ioctl.c
49062+++ b/fs/btrfs/ioctl.c
49063@@ -3077,9 +3077,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
49064 for (i = 0; i < num_types; i++) {
49065 struct btrfs_space_info *tmp;
49066
49067+ /* Don't copy in more than we allocated */
49068 if (!slot_count)
49069 break;
49070
49071+ slot_count--;
49072+
49073 info = NULL;
49074 rcu_read_lock();
49075 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
49076@@ -3101,10 +3104,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
49077 memcpy(dest, &space, sizeof(space));
49078 dest++;
49079 space_args.total_spaces++;
49080- slot_count--;
49081 }
49082- if (!slot_count)
49083- break;
49084 }
49085 up_read(&info->groups_sem);
49086 }
49087diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
49088index f6b8859..54fe8c5 100644
49089--- a/fs/btrfs/super.c
49090+++ b/fs/btrfs/super.c
49091@@ -266,7 +266,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
49092 function, line, errstr);
49093 return;
49094 }
49095- ACCESS_ONCE(trans->transaction->aborted) = errno;
49096+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
49097 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
49098 }
49099 /*
49100diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
49101index 622f469..e8d2d55 100644
49102--- a/fs/cachefiles/bind.c
49103+++ b/fs/cachefiles/bind.c
49104@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
49105 args);
49106
49107 /* start by checking things over */
49108- ASSERT(cache->fstop_percent >= 0 &&
49109- cache->fstop_percent < cache->fcull_percent &&
49110+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
49111 cache->fcull_percent < cache->frun_percent &&
49112 cache->frun_percent < 100);
49113
49114- ASSERT(cache->bstop_percent >= 0 &&
49115- cache->bstop_percent < cache->bcull_percent &&
49116+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
49117 cache->bcull_percent < cache->brun_percent &&
49118 cache->brun_percent < 100);
49119
49120diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
49121index 0a1467b..6a53245 100644
49122--- a/fs/cachefiles/daemon.c
49123+++ b/fs/cachefiles/daemon.c
49124@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
49125 if (n > buflen)
49126 return -EMSGSIZE;
49127
49128- if (copy_to_user(_buffer, buffer, n) != 0)
49129+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
49130 return -EFAULT;
49131
49132 return n;
49133@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
49134 if (test_bit(CACHEFILES_DEAD, &cache->flags))
49135 return -EIO;
49136
49137- if (datalen < 0 || datalen > PAGE_SIZE - 1)
49138+ if (datalen > PAGE_SIZE - 1)
49139 return -EOPNOTSUPP;
49140
49141 /* drag the command string into the kernel so we can parse it */
49142@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
49143 if (args[0] != '%' || args[1] != '\0')
49144 return -EINVAL;
49145
49146- if (fstop < 0 || fstop >= cache->fcull_percent)
49147+ if (fstop >= cache->fcull_percent)
49148 return cachefiles_daemon_range_error(cache, args);
49149
49150 cache->fstop_percent = fstop;
49151@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
49152 if (args[0] != '%' || args[1] != '\0')
49153 return -EINVAL;
49154
49155- if (bstop < 0 || bstop >= cache->bcull_percent)
49156+ if (bstop >= cache->bcull_percent)
49157 return cachefiles_daemon_range_error(cache, args);
49158
49159 cache->bstop_percent = bstop;
49160diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
49161index 4938251..7e01445 100644
49162--- a/fs/cachefiles/internal.h
49163+++ b/fs/cachefiles/internal.h
49164@@ -59,7 +59,7 @@ struct cachefiles_cache {
49165 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
49166 struct rb_root active_nodes; /* active nodes (can't be culled) */
49167 rwlock_t active_lock; /* lock for active_nodes */
49168- atomic_t gravecounter; /* graveyard uniquifier */
49169+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
49170 unsigned frun_percent; /* when to stop culling (% files) */
49171 unsigned fcull_percent; /* when to start culling (% files) */
49172 unsigned fstop_percent; /* when to stop allocating (% files) */
49173@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
49174 * proc.c
49175 */
49176 #ifdef CONFIG_CACHEFILES_HISTOGRAM
49177-extern atomic_t cachefiles_lookup_histogram[HZ];
49178-extern atomic_t cachefiles_mkdir_histogram[HZ];
49179-extern atomic_t cachefiles_create_histogram[HZ];
49180+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49181+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49182+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
49183
49184 extern int __init cachefiles_proc_init(void);
49185 extern void cachefiles_proc_cleanup(void);
49186 static inline
49187-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
49188+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
49189 {
49190 unsigned long jif = jiffies - start_jif;
49191 if (jif >= HZ)
49192 jif = HZ - 1;
49193- atomic_inc(&histogram[jif]);
49194+ atomic_inc_unchecked(&histogram[jif]);
49195 }
49196
49197 #else
49198diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
49199index 8c01c5fc..15f982e 100644
49200--- a/fs/cachefiles/namei.c
49201+++ b/fs/cachefiles/namei.c
49202@@ -317,7 +317,7 @@ try_again:
49203 /* first step is to make up a grave dentry in the graveyard */
49204 sprintf(nbuffer, "%08x%08x",
49205 (uint32_t) get_seconds(),
49206- (uint32_t) atomic_inc_return(&cache->gravecounter));
49207+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
49208
49209 /* do the multiway lock magic */
49210 trap = lock_rename(cache->graveyard, dir);
49211diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
49212index eccd339..4c1d995 100644
49213--- a/fs/cachefiles/proc.c
49214+++ b/fs/cachefiles/proc.c
49215@@ -14,9 +14,9 @@
49216 #include <linux/seq_file.h>
49217 #include "internal.h"
49218
49219-atomic_t cachefiles_lookup_histogram[HZ];
49220-atomic_t cachefiles_mkdir_histogram[HZ];
49221-atomic_t cachefiles_create_histogram[HZ];
49222+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49223+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49224+atomic_unchecked_t cachefiles_create_histogram[HZ];
49225
49226 /*
49227 * display the latency histogram
49228@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
49229 return 0;
49230 default:
49231 index = (unsigned long) v - 3;
49232- x = atomic_read(&cachefiles_lookup_histogram[index]);
49233- y = atomic_read(&cachefiles_mkdir_histogram[index]);
49234- z = atomic_read(&cachefiles_create_histogram[index]);
49235+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
49236+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
49237+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
49238 if (x == 0 && y == 0 && z == 0)
49239 return 0;
49240
49241diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
49242index 4809922..aab2c39 100644
49243--- a/fs/cachefiles/rdwr.c
49244+++ b/fs/cachefiles/rdwr.c
49245@@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
49246 old_fs = get_fs();
49247 set_fs(KERNEL_DS);
49248 ret = file->f_op->write(
49249- file, (const void __user *) data, len, &pos);
49250+ file, (const void __force_user *) data, len, &pos);
49251 set_fs(old_fs);
49252 kunmap(page);
49253 if (ret != len)
49254diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
49255index 6d797f4..0ace2e5 100644
49256--- a/fs/ceph/dir.c
49257+++ b/fs/ceph/dir.c
49258@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
49259 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
49260 struct ceph_mds_client *mdsc = fsc->mdsc;
49261 unsigned frag = fpos_frag(filp->f_pos);
49262- int off = fpos_off(filp->f_pos);
49263+ unsigned int off = fpos_off(filp->f_pos);
49264 int err;
49265 u32 ftype;
49266 struct ceph_mds_reply_info_parsed *rinfo;
49267diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
49268index d9ea6ed..1e6c8ac 100644
49269--- a/fs/cifs/cifs_debug.c
49270+++ b/fs/cifs/cifs_debug.c
49271@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49272
49273 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
49274 #ifdef CONFIG_CIFS_STATS2
49275- atomic_set(&totBufAllocCount, 0);
49276- atomic_set(&totSmBufAllocCount, 0);
49277+ atomic_set_unchecked(&totBufAllocCount, 0);
49278+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49279 #endif /* CONFIG_CIFS_STATS2 */
49280 spin_lock(&cifs_tcp_ses_lock);
49281 list_for_each(tmp1, &cifs_tcp_ses_list) {
49282@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49283 tcon = list_entry(tmp3,
49284 struct cifs_tcon,
49285 tcon_list);
49286- atomic_set(&tcon->num_smbs_sent, 0);
49287+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
49288 if (server->ops->clear_stats)
49289 server->ops->clear_stats(tcon);
49290 }
49291@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49292 smBufAllocCount.counter, cifs_min_small);
49293 #ifdef CONFIG_CIFS_STATS2
49294 seq_printf(m, "Total Large %d Small %d Allocations\n",
49295- atomic_read(&totBufAllocCount),
49296- atomic_read(&totSmBufAllocCount));
49297+ atomic_read_unchecked(&totBufAllocCount),
49298+ atomic_read_unchecked(&totSmBufAllocCount));
49299 #endif /* CONFIG_CIFS_STATS2 */
49300
49301 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
49302@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49303 if (tcon->need_reconnect)
49304 seq_puts(m, "\tDISCONNECTED ");
49305 seq_printf(m, "\nSMBs: %d",
49306- atomic_read(&tcon->num_smbs_sent));
49307+ atomic_read_unchecked(&tcon->num_smbs_sent));
49308 if (server->ops->print_stats)
49309 server->ops->print_stats(m, tcon);
49310 }
49311diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
49312index 345fc89..b2acae5 100644
49313--- a/fs/cifs/cifsfs.c
49314+++ b/fs/cifs/cifsfs.c
49315@@ -1033,7 +1033,7 @@ cifs_init_request_bufs(void)
49316 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
49317 cifs_req_cachep = kmem_cache_create("cifs_request",
49318 CIFSMaxBufSize + max_hdr_size, 0,
49319- SLAB_HWCACHE_ALIGN, NULL);
49320+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
49321 if (cifs_req_cachep == NULL)
49322 return -ENOMEM;
49323
49324@@ -1060,7 +1060,7 @@ cifs_init_request_bufs(void)
49325 efficient to alloc 1 per page off the slab compared to 17K (5page)
49326 alloc of large cifs buffers even when page debugging is on */
49327 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
49328- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
49329+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
49330 NULL);
49331 if (cifs_sm_req_cachep == NULL) {
49332 mempool_destroy(cifs_req_poolp);
49333@@ -1145,8 +1145,8 @@ init_cifs(void)
49334 atomic_set(&bufAllocCount, 0);
49335 atomic_set(&smBufAllocCount, 0);
49336 #ifdef CONFIG_CIFS_STATS2
49337- atomic_set(&totBufAllocCount, 0);
49338- atomic_set(&totSmBufAllocCount, 0);
49339+ atomic_set_unchecked(&totBufAllocCount, 0);
49340+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49341 #endif /* CONFIG_CIFS_STATS2 */
49342
49343 atomic_set(&midCount, 0);
49344diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
49345index 4f07f6f..55de8ce 100644
49346--- a/fs/cifs/cifsglob.h
49347+++ b/fs/cifs/cifsglob.h
49348@@ -751,35 +751,35 @@ struct cifs_tcon {
49349 __u16 Flags; /* optional support bits */
49350 enum statusEnum tidStatus;
49351 #ifdef CONFIG_CIFS_STATS
49352- atomic_t num_smbs_sent;
49353+ atomic_unchecked_t num_smbs_sent;
49354 union {
49355 struct {
49356- atomic_t num_writes;
49357- atomic_t num_reads;
49358- atomic_t num_flushes;
49359- atomic_t num_oplock_brks;
49360- atomic_t num_opens;
49361- atomic_t num_closes;
49362- atomic_t num_deletes;
49363- atomic_t num_mkdirs;
49364- atomic_t num_posixopens;
49365- atomic_t num_posixmkdirs;
49366- atomic_t num_rmdirs;
49367- atomic_t num_renames;
49368- atomic_t num_t2renames;
49369- atomic_t num_ffirst;
49370- atomic_t num_fnext;
49371- atomic_t num_fclose;
49372- atomic_t num_hardlinks;
49373- atomic_t num_symlinks;
49374- atomic_t num_locks;
49375- atomic_t num_acl_get;
49376- atomic_t num_acl_set;
49377+ atomic_unchecked_t num_writes;
49378+ atomic_unchecked_t num_reads;
49379+ atomic_unchecked_t num_flushes;
49380+ atomic_unchecked_t num_oplock_brks;
49381+ atomic_unchecked_t num_opens;
49382+ atomic_unchecked_t num_closes;
49383+ atomic_unchecked_t num_deletes;
49384+ atomic_unchecked_t num_mkdirs;
49385+ atomic_unchecked_t num_posixopens;
49386+ atomic_unchecked_t num_posixmkdirs;
49387+ atomic_unchecked_t num_rmdirs;
49388+ atomic_unchecked_t num_renames;
49389+ atomic_unchecked_t num_t2renames;
49390+ atomic_unchecked_t num_ffirst;
49391+ atomic_unchecked_t num_fnext;
49392+ atomic_unchecked_t num_fclose;
49393+ atomic_unchecked_t num_hardlinks;
49394+ atomic_unchecked_t num_symlinks;
49395+ atomic_unchecked_t num_locks;
49396+ atomic_unchecked_t num_acl_get;
49397+ atomic_unchecked_t num_acl_set;
49398 } cifs_stats;
49399 #ifdef CONFIG_CIFS_SMB2
49400 struct {
49401- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49402- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49403+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49404+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49405 } smb2_stats;
49406 #endif /* CONFIG_CIFS_SMB2 */
49407 } stats;
49408@@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
49409 }
49410
49411 #ifdef CONFIG_CIFS_STATS
49412-#define cifs_stats_inc atomic_inc
49413+#define cifs_stats_inc atomic_inc_unchecked
49414
49415 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
49416 unsigned int bytes)
49417@@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
49418 /* Various Debug counters */
49419 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
49420 #ifdef CONFIG_CIFS_STATS2
49421-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
49422-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
49423+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
49424+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
49425 #endif
49426 GLOBAL_EXTERN atomic_t smBufAllocCount;
49427 GLOBAL_EXTERN atomic_t midCount;
49428diff --git a/fs/cifs/link.c b/fs/cifs/link.c
49429index 9f6c4c4..8de307a 100644
49430--- a/fs/cifs/link.c
49431+++ b/fs/cifs/link.c
49432@@ -616,7 +616,7 @@ symlink_exit:
49433
49434 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
49435 {
49436- char *p = nd_get_link(nd);
49437+ const char *p = nd_get_link(nd);
49438 if (!IS_ERR(p))
49439 kfree(p);
49440 }
49441diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
49442index 1b15bf8..1ce489e 100644
49443--- a/fs/cifs/misc.c
49444+++ b/fs/cifs/misc.c
49445@@ -169,7 +169,7 @@ cifs_buf_get(void)
49446 memset(ret_buf, 0, buf_size + 3);
49447 atomic_inc(&bufAllocCount);
49448 #ifdef CONFIG_CIFS_STATS2
49449- atomic_inc(&totBufAllocCount);
49450+ atomic_inc_unchecked(&totBufAllocCount);
49451 #endif /* CONFIG_CIFS_STATS2 */
49452 }
49453
49454@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
49455 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
49456 atomic_inc(&smBufAllocCount);
49457 #ifdef CONFIG_CIFS_STATS2
49458- atomic_inc(&totSmBufAllocCount);
49459+ atomic_inc_unchecked(&totSmBufAllocCount);
49460 #endif /* CONFIG_CIFS_STATS2 */
49461
49462 }
49463diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
49464index 47bc5a8..10decbe 100644
49465--- a/fs/cifs/smb1ops.c
49466+++ b/fs/cifs/smb1ops.c
49467@@ -586,27 +586,27 @@ static void
49468 cifs_clear_stats(struct cifs_tcon *tcon)
49469 {
49470 #ifdef CONFIG_CIFS_STATS
49471- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
49472- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
49473- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
49474- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
49475- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
49476- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
49477- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
49478- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
49479- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
49480- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
49481- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
49482- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
49483- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
49484- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
49485- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
49486- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
49487- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
49488- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
49489- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
49490- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
49491- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
49492+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
49493+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
49494+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
49495+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
49496+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
49497+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
49498+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
49499+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
49500+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
49501+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
49502+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
49503+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
49504+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
49505+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
49506+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
49507+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
49508+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
49509+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
49510+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
49511+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
49512+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
49513 #endif
49514 }
49515
49516@@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
49517 {
49518 #ifdef CONFIG_CIFS_STATS
49519 seq_printf(m, " Oplocks breaks: %d",
49520- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
49521+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
49522 seq_printf(m, "\nReads: %d Bytes: %llu",
49523- atomic_read(&tcon->stats.cifs_stats.num_reads),
49524+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
49525 (long long)(tcon->bytes_read));
49526 seq_printf(m, "\nWrites: %d Bytes: %llu",
49527- atomic_read(&tcon->stats.cifs_stats.num_writes),
49528+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
49529 (long long)(tcon->bytes_written));
49530 seq_printf(m, "\nFlushes: %d",
49531- atomic_read(&tcon->stats.cifs_stats.num_flushes));
49532+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
49533 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
49534- atomic_read(&tcon->stats.cifs_stats.num_locks),
49535- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
49536- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
49537+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
49538+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
49539+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
49540 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
49541- atomic_read(&tcon->stats.cifs_stats.num_opens),
49542- atomic_read(&tcon->stats.cifs_stats.num_closes),
49543- atomic_read(&tcon->stats.cifs_stats.num_deletes));
49544+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
49545+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
49546+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
49547 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
49548- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
49549- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
49550+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
49551+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
49552 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
49553- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
49554- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
49555+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
49556+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
49557 seq_printf(m, "\nRenames: %d T2 Renames %d",
49558- atomic_read(&tcon->stats.cifs_stats.num_renames),
49559- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
49560+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
49561+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
49562 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
49563- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
49564- atomic_read(&tcon->stats.cifs_stats.num_fnext),
49565- atomic_read(&tcon->stats.cifs_stats.num_fclose));
49566+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
49567+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
49568+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
49569 #endif
49570 }
49571
49572diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
49573index bceffe7..cd1ae59 100644
49574--- a/fs/cifs/smb2ops.c
49575+++ b/fs/cifs/smb2ops.c
49576@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
49577 #ifdef CONFIG_CIFS_STATS
49578 int i;
49579 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
49580- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
49581- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
49582+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
49583+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
49584 }
49585 #endif
49586 }
49587@@ -284,66 +284,66 @@ static void
49588 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
49589 {
49590 #ifdef CONFIG_CIFS_STATS
49591- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
49592- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
49593+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
49594+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
49595 seq_printf(m, "\nNegotiates: %d sent %d failed",
49596- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
49597- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
49598+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
49599+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
49600 seq_printf(m, "\nSessionSetups: %d sent %d failed",
49601- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
49602- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
49603+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
49604+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
49605 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
49606 seq_printf(m, "\nLogoffs: %d sent %d failed",
49607- atomic_read(&sent[SMB2_LOGOFF_HE]),
49608- atomic_read(&failed[SMB2_LOGOFF_HE]));
49609+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
49610+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
49611 seq_printf(m, "\nTreeConnects: %d sent %d failed",
49612- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
49613- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
49614+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
49615+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
49616 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
49617- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
49618- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
49619+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
49620+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
49621 seq_printf(m, "\nCreates: %d sent %d failed",
49622- atomic_read(&sent[SMB2_CREATE_HE]),
49623- atomic_read(&failed[SMB2_CREATE_HE]));
49624+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
49625+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
49626 seq_printf(m, "\nCloses: %d sent %d failed",
49627- atomic_read(&sent[SMB2_CLOSE_HE]),
49628- atomic_read(&failed[SMB2_CLOSE_HE]));
49629+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
49630+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
49631 seq_printf(m, "\nFlushes: %d sent %d failed",
49632- atomic_read(&sent[SMB2_FLUSH_HE]),
49633- atomic_read(&failed[SMB2_FLUSH_HE]));
49634+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
49635+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
49636 seq_printf(m, "\nReads: %d sent %d failed",
49637- atomic_read(&sent[SMB2_READ_HE]),
49638- atomic_read(&failed[SMB2_READ_HE]));
49639+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
49640+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
49641 seq_printf(m, "\nWrites: %d sent %d failed",
49642- atomic_read(&sent[SMB2_WRITE_HE]),
49643- atomic_read(&failed[SMB2_WRITE_HE]));
49644+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
49645+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
49646 seq_printf(m, "\nLocks: %d sent %d failed",
49647- atomic_read(&sent[SMB2_LOCK_HE]),
49648- atomic_read(&failed[SMB2_LOCK_HE]));
49649+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
49650+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
49651 seq_printf(m, "\nIOCTLs: %d sent %d failed",
49652- atomic_read(&sent[SMB2_IOCTL_HE]),
49653- atomic_read(&failed[SMB2_IOCTL_HE]));
49654+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
49655+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
49656 seq_printf(m, "\nCancels: %d sent %d failed",
49657- atomic_read(&sent[SMB2_CANCEL_HE]),
49658- atomic_read(&failed[SMB2_CANCEL_HE]));
49659+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
49660+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
49661 seq_printf(m, "\nEchos: %d sent %d failed",
49662- atomic_read(&sent[SMB2_ECHO_HE]),
49663- atomic_read(&failed[SMB2_ECHO_HE]));
49664+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
49665+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
49666 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
49667- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
49668- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
49669+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
49670+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
49671 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
49672- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
49673- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
49674+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
49675+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
49676 seq_printf(m, "\nQueryInfos: %d sent %d failed",
49677- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
49678- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
49679+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
49680+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
49681 seq_printf(m, "\nSetInfos: %d sent %d failed",
49682- atomic_read(&sent[SMB2_SET_INFO_HE]),
49683- atomic_read(&failed[SMB2_SET_INFO_HE]));
49684+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
49685+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
49686 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
49687- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
49688- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
49689+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
49690+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
49691 #endif
49692 }
49693
49694diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
49695index 41d9d07..dbb4772 100644
49696--- a/fs/cifs/smb2pdu.c
49697+++ b/fs/cifs/smb2pdu.c
49698@@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
49699 default:
49700 cERROR(1, "info level %u isn't supported",
49701 srch_inf->info_level);
49702- rc = -EINVAL;
49703- goto qdir_exit;
49704+ return -EINVAL;
49705 }
49706
49707 req->FileIndex = cpu_to_le32(index);
49708diff --git a/fs/coda/cache.c b/fs/coda/cache.c
49709index 1da168c..8bc7ff6 100644
49710--- a/fs/coda/cache.c
49711+++ b/fs/coda/cache.c
49712@@ -24,7 +24,7 @@
49713 #include "coda_linux.h"
49714 #include "coda_cache.h"
49715
49716-static atomic_t permission_epoch = ATOMIC_INIT(0);
49717+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
49718
49719 /* replace or extend an acl cache hit */
49720 void coda_cache_enter(struct inode *inode, int mask)
49721@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
49722 struct coda_inode_info *cii = ITOC(inode);
49723
49724 spin_lock(&cii->c_lock);
49725- cii->c_cached_epoch = atomic_read(&permission_epoch);
49726+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
49727 if (!uid_eq(cii->c_uid, current_fsuid())) {
49728 cii->c_uid = current_fsuid();
49729 cii->c_cached_perm = mask;
49730@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
49731 {
49732 struct coda_inode_info *cii = ITOC(inode);
49733 spin_lock(&cii->c_lock);
49734- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
49735+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
49736 spin_unlock(&cii->c_lock);
49737 }
49738
49739 /* remove all acl caches */
49740 void coda_cache_clear_all(struct super_block *sb)
49741 {
49742- atomic_inc(&permission_epoch);
49743+ atomic_inc_unchecked(&permission_epoch);
49744 }
49745
49746
49747@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
49748 spin_lock(&cii->c_lock);
49749 hit = (mask & cii->c_cached_perm) == mask &&
49750 uid_eq(cii->c_uid, current_fsuid()) &&
49751- cii->c_cached_epoch == atomic_read(&permission_epoch);
49752+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
49753 spin_unlock(&cii->c_lock);
49754
49755 return hit;
49756diff --git a/fs/compat.c b/fs/compat.c
49757index d487985..c9e04b1 100644
49758--- a/fs/compat.c
49759+++ b/fs/compat.c
49760@@ -54,7 +54,7 @@
49761 #include <asm/ioctls.h>
49762 #include "internal.h"
49763
49764-int compat_log = 1;
49765+int compat_log = 0;
49766
49767 int compat_printk(const char *fmt, ...)
49768 {
49769@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
49770
49771 set_fs(KERNEL_DS);
49772 /* The __user pointer cast is valid because of the set_fs() */
49773- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
49774+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
49775 set_fs(oldfs);
49776 /* truncating is ok because it's a user address */
49777 if (!ret)
49778@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
49779 goto out;
49780
49781 ret = -EINVAL;
49782- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
49783+ if (nr_segs > UIO_MAXIOV)
49784 goto out;
49785 if (nr_segs > fast_segs) {
49786 ret = -ENOMEM;
49787@@ -835,6 +835,7 @@ struct compat_old_linux_dirent {
49788
49789 struct compat_readdir_callback {
49790 struct compat_old_linux_dirent __user *dirent;
49791+ struct file * file;
49792 int result;
49793 };
49794
49795@@ -852,6 +853,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
49796 buf->result = -EOVERFLOW;
49797 return -EOVERFLOW;
49798 }
49799+
49800+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49801+ return 0;
49802+
49803 buf->result++;
49804 dirent = buf->dirent;
49805 if (!access_ok(VERIFY_WRITE, dirent,
49806@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
49807
49808 buf.result = 0;
49809 buf.dirent = dirent;
49810+ buf.file = f.file;
49811
49812 error = vfs_readdir(f.file, compat_fillonedir, &buf);
49813 if (buf.result)
49814@@ -901,6 +907,7 @@ struct compat_linux_dirent {
49815 struct compat_getdents_callback {
49816 struct compat_linux_dirent __user *current_dir;
49817 struct compat_linux_dirent __user *previous;
49818+ struct file * file;
49819 int count;
49820 int error;
49821 };
49822@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
49823 buf->error = -EOVERFLOW;
49824 return -EOVERFLOW;
49825 }
49826+
49827+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49828+ return 0;
49829+
49830 dirent = buf->previous;
49831 if (dirent) {
49832 if (__put_user(offset, &dirent->d_off))
49833@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
49834 buf.previous = NULL;
49835 buf.count = count;
49836 buf.error = 0;
49837+ buf.file = f.file;
49838
49839 error = vfs_readdir(f.file, compat_filldir, &buf);
49840 if (error >= 0)
49841@@ -987,6 +999,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
49842 struct compat_getdents_callback64 {
49843 struct linux_dirent64 __user *current_dir;
49844 struct linux_dirent64 __user *previous;
49845+ struct file * file;
49846 int count;
49847 int error;
49848 };
49849@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
49850 buf->error = -EINVAL; /* only used if we fail.. */
49851 if (reclen > buf->count)
49852 return -EINVAL;
49853+
49854+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49855+ return 0;
49856+
49857 dirent = buf->previous;
49858
49859 if (dirent) {
49860@@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
49861 buf.previous = NULL;
49862 buf.count = count;
49863 buf.error = 0;
49864+ buf.file = f.file;
49865
49866 error = vfs_readdir(f.file, compat_filldir64, &buf);
49867 if (error >= 0)
49868 error = buf.error;
49869 lastdirent = buf.previous;
49870 if (lastdirent) {
49871- typeof(lastdirent->d_off) d_off = f.file->f_pos;
49872+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
49873 if (__put_user_unaligned(d_off, &lastdirent->d_off))
49874 error = -EFAULT;
49875 else
49876diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
49877index a81147e..20bf2b5 100644
49878--- a/fs/compat_binfmt_elf.c
49879+++ b/fs/compat_binfmt_elf.c
49880@@ -30,11 +30,13 @@
49881 #undef elf_phdr
49882 #undef elf_shdr
49883 #undef elf_note
49884+#undef elf_dyn
49885 #undef elf_addr_t
49886 #define elfhdr elf32_hdr
49887 #define elf_phdr elf32_phdr
49888 #define elf_shdr elf32_shdr
49889 #define elf_note elf32_note
49890+#define elf_dyn Elf32_Dyn
49891 #define elf_addr_t Elf32_Addr
49892
49893 /*
49894diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
49895index 3ced75f..b28d192 100644
49896--- a/fs/compat_ioctl.c
49897+++ b/fs/compat_ioctl.c
49898@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
49899 return -EFAULT;
49900 if (__get_user(udata, &ss32->iomem_base))
49901 return -EFAULT;
49902- ss.iomem_base = compat_ptr(udata);
49903+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
49904 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
49905 __get_user(ss.port_high, &ss32->port_high))
49906 return -EFAULT;
49907@@ -704,8 +704,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
49908 for (i = 0; i < nmsgs; i++) {
49909 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
49910 return -EFAULT;
49911- if (get_user(datap, &umsgs[i].buf) ||
49912- put_user(compat_ptr(datap), &tmsgs[i].buf))
49913+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
49914+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
49915 return -EFAULT;
49916 }
49917 return sys_ioctl(fd, cmd, (unsigned long)tdata);
49918@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
49919 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
49920 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
49921 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
49922- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
49923+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
49924 return -EFAULT;
49925
49926 return ioctl_preallocate(file, p);
49927@@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
49928 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
49929 {
49930 unsigned int a, b;
49931- a = *(unsigned int *)p;
49932- b = *(unsigned int *)q;
49933+ a = *(const unsigned int *)p;
49934+ b = *(const unsigned int *)q;
49935 if (a > b)
49936 return 1;
49937 if (a < b)
49938diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
49939index 7aabc6a..34c1197 100644
49940--- a/fs/configfs/dir.c
49941+++ b/fs/configfs/dir.c
49942@@ -1565,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
49943 }
49944 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
49945 struct configfs_dirent *next;
49946- const char * name;
49947+ const unsigned char * name;
49948+ char d_name[sizeof(next->s_dentry->d_iname)];
49949 int len;
49950 struct inode *inode = NULL;
49951
49952@@ -1575,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
49953 continue;
49954
49955 name = configfs_get_name(next);
49956- len = strlen(name);
49957+ if (next->s_dentry && name == next->s_dentry->d_iname) {
49958+ len = next->s_dentry->d_name.len;
49959+ memcpy(d_name, name, len);
49960+ name = d_name;
49961+ } else
49962+ len = strlen(name);
49963
49964 /*
49965 * We'll have a dentry and an inode for
49966diff --git a/fs/coredump.c b/fs/coredump.c
49967index c647965..a77bff3 100644
49968--- a/fs/coredump.c
49969+++ b/fs/coredump.c
49970@@ -52,7 +52,7 @@ struct core_name {
49971 char *corename;
49972 int used, size;
49973 };
49974-static atomic_t call_count = ATOMIC_INIT(1);
49975+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
49976
49977 /* The maximal length of core_pattern is also specified in sysctl.c */
49978
49979@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
49980 {
49981 char *old_corename = cn->corename;
49982
49983- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
49984+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
49985 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
49986
49987 if (!cn->corename) {
49988@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
49989 int pid_in_pattern = 0;
49990 int err = 0;
49991
49992- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
49993+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
49994 cn->corename = kmalloc(cn->size, GFP_KERNEL);
49995 cn->used = 0;
49996
49997@@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
49998 pipe = file_inode(file)->i_pipe;
49999
50000 pipe_lock(pipe);
50001- pipe->readers++;
50002- pipe->writers--;
50003+ atomic_inc(&pipe->readers);
50004+ atomic_dec(&pipe->writers);
50005
50006- while ((pipe->readers > 1) && (!signal_pending(current))) {
50007+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
50008 wake_up_interruptible_sync(&pipe->wait);
50009 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
50010 pipe_wait(pipe);
50011 }
50012
50013- pipe->readers--;
50014- pipe->writers++;
50015+ atomic_dec(&pipe->readers);
50016+ atomic_inc(&pipe->writers);
50017 pipe_unlock(pipe);
50018
50019 }
50020@@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
50021 int ispipe;
50022 struct files_struct *displaced;
50023 bool need_nonrelative = false;
50024- static atomic_t core_dump_count = ATOMIC_INIT(0);
50025+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
50026+ long signr = siginfo->si_signo;
50027 struct coredump_params cprm = {
50028 .siginfo = siginfo,
50029 .regs = signal_pt_regs(),
50030@@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
50031 .mm_flags = mm->flags,
50032 };
50033
50034- audit_core_dumps(siginfo->si_signo);
50035+ audit_core_dumps(signr);
50036+
50037+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
50038+ gr_handle_brute_attach(cprm.mm_flags);
50039
50040 binfmt = mm->binfmt;
50041 if (!binfmt || !binfmt->core_dump)
50042@@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
50043 need_nonrelative = true;
50044 }
50045
50046- retval = coredump_wait(siginfo->si_signo, &core_state);
50047+ retval = coredump_wait(signr, &core_state);
50048 if (retval < 0)
50049 goto fail_creds;
50050
50051@@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
50052 }
50053 cprm.limit = RLIM_INFINITY;
50054
50055- dump_count = atomic_inc_return(&core_dump_count);
50056+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
50057 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
50058 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
50059 task_tgid_vnr(current), current->comm);
50060@@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
50061 } else {
50062 struct inode *inode;
50063
50064+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
50065+
50066 if (cprm.limit < binfmt->min_coredump)
50067 goto fail_unlock;
50068
50069@@ -640,7 +646,7 @@ close_fail:
50070 filp_close(cprm.file, NULL);
50071 fail_dropcount:
50072 if (ispipe)
50073- atomic_dec(&core_dump_count);
50074+ atomic_dec_unchecked(&core_dump_count);
50075 fail_unlock:
50076 kfree(cn.corename);
50077 fail_corename:
50078@@ -659,7 +665,7 @@ fail:
50079 */
50080 int dump_write(struct file *file, const void *addr, int nr)
50081 {
50082- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
50083+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
50084 }
50085 EXPORT_SYMBOL(dump_write);
50086
50087diff --git a/fs/dcache.c b/fs/dcache.c
50088index e689268..f36956e 100644
50089--- a/fs/dcache.c
50090+++ b/fs/dcache.c
50091@@ -3100,7 +3100,7 @@ void __init vfs_caches_init(unsigned long mempages)
50092 mempages -= reserve;
50093
50094 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
50095- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
50096+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
50097
50098 dcache_init();
50099 inode_init();
50100diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
50101index 4888cb3..e0f7cf8 100644
50102--- a/fs/debugfs/inode.c
50103+++ b/fs/debugfs/inode.c
50104@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
50105 */
50106 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
50107 {
50108+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50109+ return __create_file(name, S_IFDIR | S_IRWXU,
50110+#else
50111 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
50112+#endif
50113 parent, NULL, NULL);
50114 }
50115 EXPORT_SYMBOL_GPL(debugfs_create_dir);
50116diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
50117index 5eab400..810a3f5 100644
50118--- a/fs/ecryptfs/inode.c
50119+++ b/fs/ecryptfs/inode.c
50120@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
50121 old_fs = get_fs();
50122 set_fs(get_ds());
50123 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
50124- (char __user *)lower_buf,
50125+ (char __force_user *)lower_buf,
50126 PATH_MAX);
50127 set_fs(old_fs);
50128 if (rc < 0)
50129@@ -706,7 +706,7 @@ out:
50130 static void
50131 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
50132 {
50133- char *buf = nd_get_link(nd);
50134+ const char *buf = nd_get_link(nd);
50135 if (!IS_ERR(buf)) {
50136 /* Free the char* */
50137 kfree(buf);
50138diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
50139index e4141f2..d8263e8 100644
50140--- a/fs/ecryptfs/miscdev.c
50141+++ b/fs/ecryptfs/miscdev.c
50142@@ -304,7 +304,7 @@ check_list:
50143 goto out_unlock_msg_ctx;
50144 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
50145 if (msg_ctx->msg) {
50146- if (copy_to_user(&buf[i], packet_length, packet_length_size))
50147+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
50148 goto out_unlock_msg_ctx;
50149 i += packet_length_size;
50150 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
50151diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
50152index 6a16053..2155147 100644
50153--- a/fs/ecryptfs/read_write.c
50154+++ b/fs/ecryptfs/read_write.c
50155@@ -240,7 +240,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
50156 return -EIO;
50157 fs_save = get_fs();
50158 set_fs(get_ds());
50159- rc = vfs_read(lower_file, data, size, &offset);
50160+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
50161 set_fs(fs_save);
50162 return rc;
50163 }
50164diff --git a/fs/exec.c b/fs/exec.c
50165index 6d56ff2..3bc6638 100644
50166--- a/fs/exec.c
50167+++ b/fs/exec.c
50168@@ -55,8 +55,20 @@
50169 #include <linux/pipe_fs_i.h>
50170 #include <linux/oom.h>
50171 #include <linux/compat.h>
50172+#include <linux/random.h>
50173+#include <linux/seq_file.h>
50174+#include <linux/coredump.h>
50175+#include <linux/mman.h>
50176+
50177+#ifdef CONFIG_PAX_REFCOUNT
50178+#include <linux/kallsyms.h>
50179+#include <linux/kdebug.h>
50180+#endif
50181+
50182+#include <trace/events/fs.h>
50183
50184 #include <asm/uaccess.h>
50185+#include <asm/sections.h>
50186 #include <asm/mmu_context.h>
50187 #include <asm/tlb.h>
50188
50189@@ -66,6 +78,18 @@
50190
50191 #include <trace/events/sched.h>
50192
50193+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
50194+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
50195+{
50196+ pr_warn_once("PAX: PAX_HAVE_ACL_FLAGS was enabled without providing the pax_set_initial_flags callback, this is probably not what you wanted.\n");
50197+}
50198+#endif
50199+
50200+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
50201+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
50202+EXPORT_SYMBOL(pax_set_initial_flags_func);
50203+#endif
50204+
50205 int suid_dumpable = 0;
50206
50207 static LIST_HEAD(formats);
50208@@ -75,8 +99,8 @@ void __register_binfmt(struct linux_binfmt * fmt, int insert)
50209 {
50210 BUG_ON(!fmt);
50211 write_lock(&binfmt_lock);
50212- insert ? list_add(&fmt->lh, &formats) :
50213- list_add_tail(&fmt->lh, &formats);
50214+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
50215+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
50216 write_unlock(&binfmt_lock);
50217 }
50218
50219@@ -85,7 +109,7 @@ EXPORT_SYMBOL(__register_binfmt);
50220 void unregister_binfmt(struct linux_binfmt * fmt)
50221 {
50222 write_lock(&binfmt_lock);
50223- list_del(&fmt->lh);
50224+ pax_list_del((struct list_head *)&fmt->lh);
50225 write_unlock(&binfmt_lock);
50226 }
50227
50228@@ -180,18 +204,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50229 int write)
50230 {
50231 struct page *page;
50232- int ret;
50233
50234-#ifdef CONFIG_STACK_GROWSUP
50235- if (write) {
50236- ret = expand_downwards(bprm->vma, pos);
50237- if (ret < 0)
50238- return NULL;
50239- }
50240-#endif
50241- ret = get_user_pages(current, bprm->mm, pos,
50242- 1, write, 1, &page, NULL);
50243- if (ret <= 0)
50244+ if (0 > expand_downwards(bprm->vma, pos))
50245+ return NULL;
50246+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
50247 return NULL;
50248
50249 if (write) {
50250@@ -207,6 +223,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50251 if (size <= ARG_MAX)
50252 return page;
50253
50254+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50255+ // only allow 512KB for argv+env on suid/sgid binaries
50256+ // to prevent easy ASLR exhaustion
50257+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
50258+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
50259+ (size > (512 * 1024))) {
50260+ put_page(page);
50261+ return NULL;
50262+ }
50263+#endif
50264+
50265 /*
50266 * Limit to 1/4-th the stack size for the argv+env strings.
50267 * This ensures that:
50268@@ -266,6 +293,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50269 vma->vm_end = STACK_TOP_MAX;
50270 vma->vm_start = vma->vm_end - PAGE_SIZE;
50271 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
50272+
50273+#ifdef CONFIG_PAX_SEGMEXEC
50274+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
50275+#endif
50276+
50277 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
50278 INIT_LIST_HEAD(&vma->anon_vma_chain);
50279
50280@@ -276,6 +308,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50281 mm->stack_vm = mm->total_vm = 1;
50282 up_write(&mm->mmap_sem);
50283 bprm->p = vma->vm_end - sizeof(void *);
50284+
50285+#ifdef CONFIG_PAX_RANDUSTACK
50286+ if (randomize_va_space)
50287+ bprm->p ^= random32() & ~PAGE_MASK;
50288+#endif
50289+
50290 return 0;
50291 err:
50292 up_write(&mm->mmap_sem);
50293@@ -396,7 +434,7 @@ struct user_arg_ptr {
50294 } ptr;
50295 };
50296
50297-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50298+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50299 {
50300 const char __user *native;
50301
50302@@ -405,14 +443,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50303 compat_uptr_t compat;
50304
50305 if (get_user(compat, argv.ptr.compat + nr))
50306- return ERR_PTR(-EFAULT);
50307+ return (const char __force_user *)ERR_PTR(-EFAULT);
50308
50309 return compat_ptr(compat);
50310 }
50311 #endif
50312
50313 if (get_user(native, argv.ptr.native + nr))
50314- return ERR_PTR(-EFAULT);
50315+ return (const char __force_user *)ERR_PTR(-EFAULT);
50316
50317 return native;
50318 }
50319@@ -431,7 +469,7 @@ static int count(struct user_arg_ptr argv, int max)
50320 if (!p)
50321 break;
50322
50323- if (IS_ERR(p))
50324+ if (IS_ERR((const char __force_kernel *)p))
50325 return -EFAULT;
50326
50327 if (i >= max)
50328@@ -466,7 +504,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
50329
50330 ret = -EFAULT;
50331 str = get_user_arg_ptr(argv, argc);
50332- if (IS_ERR(str))
50333+ if (IS_ERR((const char __force_kernel *)str))
50334 goto out;
50335
50336 len = strnlen_user(str, MAX_ARG_STRLEN);
50337@@ -548,7 +586,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
50338 int r;
50339 mm_segment_t oldfs = get_fs();
50340 struct user_arg_ptr argv = {
50341- .ptr.native = (const char __user *const __user *)__argv,
50342+ .ptr.native = (const char __force_user * const __force_user *)__argv,
50343 };
50344
50345 set_fs(KERNEL_DS);
50346@@ -583,7 +621,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50347 unsigned long new_end = old_end - shift;
50348 struct mmu_gather tlb;
50349
50350- BUG_ON(new_start > new_end);
50351+ if (new_start >= new_end || new_start < mmap_min_addr)
50352+ return -ENOMEM;
50353
50354 /*
50355 * ensure there are no vmas between where we want to go
50356@@ -592,6 +631,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50357 if (vma != find_vma(mm, new_start))
50358 return -EFAULT;
50359
50360+#ifdef CONFIG_PAX_SEGMEXEC
50361+ BUG_ON(pax_find_mirror_vma(vma));
50362+#endif
50363+
50364 /*
50365 * cover the whole range: [new_start, old_end)
50366 */
50367@@ -672,10 +715,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50368 stack_top = arch_align_stack(stack_top);
50369 stack_top = PAGE_ALIGN(stack_top);
50370
50371- if (unlikely(stack_top < mmap_min_addr) ||
50372- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
50373- return -ENOMEM;
50374-
50375 stack_shift = vma->vm_end - stack_top;
50376
50377 bprm->p -= stack_shift;
50378@@ -687,8 +726,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
50379 bprm->exec -= stack_shift;
50380
50381 down_write(&mm->mmap_sem);
50382+
50383+ /* Move stack pages down in memory. */
50384+ if (stack_shift) {
50385+ ret = shift_arg_pages(vma, stack_shift);
50386+ if (ret)
50387+ goto out_unlock;
50388+ }
50389+
50390 vm_flags = VM_STACK_FLAGS;
50391
50392+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
50393+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
50394+ vm_flags &= ~VM_EXEC;
50395+
50396+#ifdef CONFIG_PAX_MPROTECT
50397+ if (mm->pax_flags & MF_PAX_MPROTECT)
50398+ vm_flags &= ~VM_MAYEXEC;
50399+#endif
50400+
50401+ }
50402+#endif
50403+
50404 /*
50405 * Adjust stack execute permissions; explicitly enable for
50406 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
50407@@ -707,13 +766,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50408 goto out_unlock;
50409 BUG_ON(prev != vma);
50410
50411- /* Move stack pages down in memory. */
50412- if (stack_shift) {
50413- ret = shift_arg_pages(vma, stack_shift);
50414- if (ret)
50415- goto out_unlock;
50416- }
50417-
50418 /* mprotect_fixup is overkill to remove the temporary stack flags */
50419 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
50420
50421@@ -737,6 +789,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
50422 #endif
50423 current->mm->start_stack = bprm->p;
50424 ret = expand_stack(vma, stack_base);
50425+
50426+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
50427+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
50428+ unsigned long size;
50429+ vm_flags_t vm_flags;
50430+
50431+ size = STACK_TOP - vma->vm_end;
50432+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
50433+
50434+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
50435+
50436+#ifdef CONFIG_X86
50437+ if (!ret) {
50438+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
50439+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
50440+ }
50441+#endif
50442+
50443+ }
50444+#endif
50445+
50446 if (ret)
50447 ret = -EFAULT;
50448
50449@@ -772,6 +845,8 @@ struct file *open_exec(const char *name)
50450
50451 fsnotify_open(file);
50452
50453+ trace_open_exec(name);
50454+
50455 err = deny_write_access(file);
50456 if (err)
50457 goto exit;
50458@@ -795,7 +870,7 @@ int kernel_read(struct file *file, loff_t offset,
50459 old_fs = get_fs();
50460 set_fs(get_ds());
50461 /* The cast to a user pointer is valid due to the set_fs() */
50462- result = vfs_read(file, (void __user *)addr, count, &pos);
50463+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
50464 set_fs(old_fs);
50465 return result;
50466 }
50467@@ -1250,7 +1325,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
50468 }
50469 rcu_read_unlock();
50470
50471- if (p->fs->users > n_fs) {
50472+ if (atomic_read(&p->fs->users) > n_fs) {
50473 bprm->unsafe |= LSM_UNSAFE_SHARE;
50474 } else {
50475 res = -EAGAIN;
50476@@ -1450,6 +1525,31 @@ int search_binary_handler(struct linux_binprm *bprm)
50477
50478 EXPORT_SYMBOL(search_binary_handler);
50479
50480+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50481+static DEFINE_PER_CPU(u64, exec_counter);
50482+static int __init init_exec_counters(void)
50483+{
50484+ unsigned int cpu;
50485+
50486+ for_each_possible_cpu(cpu) {
50487+ per_cpu(exec_counter, cpu) = (u64)cpu;
50488+ }
50489+
50490+ return 0;
50491+}
50492+early_initcall(init_exec_counters);
50493+static inline void increment_exec_counter(void)
50494+{
50495+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
50496+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
50497+}
50498+#else
50499+static inline void increment_exec_counter(void) {}
50500+#endif
50501+
50502+extern void gr_handle_exec_args(struct linux_binprm *bprm,
50503+ struct user_arg_ptr argv);
50504+
50505 /*
50506 * sys_execve() executes a new program.
50507 */
50508@@ -1457,6 +1557,11 @@ static int do_execve_common(const char *filename,
50509 struct user_arg_ptr argv,
50510 struct user_arg_ptr envp)
50511 {
50512+#ifdef CONFIG_GRKERNSEC
50513+ struct file *old_exec_file;
50514+ struct acl_subject_label *old_acl;
50515+ struct rlimit old_rlim[RLIM_NLIMITS];
50516+#endif
50517 struct linux_binprm *bprm;
50518 struct file *file;
50519 struct files_struct *displaced;
50520@@ -1464,6 +1569,8 @@ static int do_execve_common(const char *filename,
50521 int retval;
50522 const struct cred *cred = current_cred();
50523
50524+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&cred->user->processes), 1);
50525+
50526 /*
50527 * We move the actual failure in case of RLIMIT_NPROC excess from
50528 * set*uid() to execve() because too many poorly written programs
50529@@ -1504,12 +1611,27 @@ static int do_execve_common(const char *filename,
50530 if (IS_ERR(file))
50531 goto out_unmark;
50532
50533+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
50534+ retval = -EPERM;
50535+ goto out_file;
50536+ }
50537+
50538 sched_exec();
50539
50540 bprm->file = file;
50541 bprm->filename = filename;
50542 bprm->interp = filename;
50543
50544+ if (gr_process_user_ban()) {
50545+ retval = -EPERM;
50546+ goto out_file;
50547+ }
50548+
50549+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
50550+ retval = -EACCES;
50551+ goto out_file;
50552+ }
50553+
50554 retval = bprm_mm_init(bprm);
50555 if (retval)
50556 goto out_file;
50557@@ -1526,24 +1648,65 @@ static int do_execve_common(const char *filename,
50558 if (retval < 0)
50559 goto out;
50560
50561+#ifdef CONFIG_GRKERNSEC
50562+ old_acl = current->acl;
50563+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
50564+ old_exec_file = current->exec_file;
50565+ get_file(file);
50566+ current->exec_file = file;
50567+#endif
50568+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50569+ /* limit suid stack to 8MB
50570+ * we saved the old limits above and will restore them if this exec fails
50571+ */
50572+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
50573+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
50574+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
50575+#endif
50576+
50577+ if (!gr_tpe_allow(file)) {
50578+ retval = -EACCES;
50579+ goto out_fail;
50580+ }
50581+
50582+ if (gr_check_crash_exec(file)) {
50583+ retval = -EACCES;
50584+ goto out_fail;
50585+ }
50586+
50587+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
50588+ bprm->unsafe);
50589+ if (retval < 0)
50590+ goto out_fail;
50591+
50592 retval = copy_strings_kernel(1, &bprm->filename, bprm);
50593 if (retval < 0)
50594- goto out;
50595+ goto out_fail;
50596
50597 bprm->exec = bprm->p;
50598 retval = copy_strings(bprm->envc, envp, bprm);
50599 if (retval < 0)
50600- goto out;
50601+ goto out_fail;
50602
50603 retval = copy_strings(bprm->argc, argv, bprm);
50604 if (retval < 0)
50605- goto out;
50606+ goto out_fail;
50607+
50608+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
50609+
50610+ gr_handle_exec_args(bprm, argv);
50611
50612 retval = search_binary_handler(bprm);
50613 if (retval < 0)
50614- goto out;
50615+ goto out_fail;
50616+#ifdef CONFIG_GRKERNSEC
50617+ if (old_exec_file)
50618+ fput(old_exec_file);
50619+#endif
50620
50621 /* execve succeeded */
50622+
50623+ increment_exec_counter();
50624 current->fs->in_exec = 0;
50625 current->in_execve = 0;
50626 acct_update_integrals(current);
50627@@ -1552,6 +1715,14 @@ static int do_execve_common(const char *filename,
50628 put_files_struct(displaced);
50629 return retval;
50630
50631+out_fail:
50632+#ifdef CONFIG_GRKERNSEC
50633+ current->acl = old_acl;
50634+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
50635+ fput(current->exec_file);
50636+ current->exec_file = old_exec_file;
50637+#endif
50638+
50639 out:
50640 if (bprm->mm) {
50641 acct_arg_size(bprm, 0);
50642@@ -1700,3 +1871,283 @@ asmlinkage long compat_sys_execve(const char __user * filename,
50643 return error;
50644 }
50645 #endif
50646+
50647+int pax_check_flags(unsigned long *flags)
50648+{
50649+ int retval = 0;
50650+
50651+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
50652+ if (*flags & MF_PAX_SEGMEXEC)
50653+ {
50654+ *flags &= ~MF_PAX_SEGMEXEC;
50655+ retval = -EINVAL;
50656+ }
50657+#endif
50658+
50659+ if ((*flags & MF_PAX_PAGEEXEC)
50660+
50661+#ifdef CONFIG_PAX_PAGEEXEC
50662+ && (*flags & MF_PAX_SEGMEXEC)
50663+#endif
50664+
50665+ )
50666+ {
50667+ *flags &= ~MF_PAX_PAGEEXEC;
50668+ retval = -EINVAL;
50669+ }
50670+
50671+ if ((*flags & MF_PAX_MPROTECT)
50672+
50673+#ifdef CONFIG_PAX_MPROTECT
50674+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
50675+#endif
50676+
50677+ )
50678+ {
50679+ *flags &= ~MF_PAX_MPROTECT;
50680+ retval = -EINVAL;
50681+ }
50682+
50683+ if ((*flags & MF_PAX_EMUTRAMP)
50684+
50685+#ifdef CONFIG_PAX_EMUTRAMP
50686+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
50687+#endif
50688+
50689+ )
50690+ {
50691+ *flags &= ~MF_PAX_EMUTRAMP;
50692+ retval = -EINVAL;
50693+ }
50694+
50695+ return retval;
50696+}
50697+
50698+EXPORT_SYMBOL(pax_check_flags);
50699+
50700+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
50701+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
50702+{
50703+ struct task_struct *tsk = current;
50704+ struct mm_struct *mm = current->mm;
50705+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
50706+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
50707+ char *path_exec = NULL;
50708+ char *path_fault = NULL;
50709+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
50710+ siginfo_t info = { };
50711+
50712+ if (buffer_exec && buffer_fault) {
50713+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
50714+
50715+ down_read(&mm->mmap_sem);
50716+ vma = mm->mmap;
50717+ while (vma && (!vma_exec || !vma_fault)) {
50718+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
50719+ vma_exec = vma;
50720+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
50721+ vma_fault = vma;
50722+ vma = vma->vm_next;
50723+ }
50724+ if (vma_exec) {
50725+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
50726+ if (IS_ERR(path_exec))
50727+ path_exec = "<path too long>";
50728+ else {
50729+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
50730+ if (path_exec) {
50731+ *path_exec = 0;
50732+ path_exec = buffer_exec;
50733+ } else
50734+ path_exec = "<path too long>";
50735+ }
50736+ }
50737+ if (vma_fault) {
50738+ start = vma_fault->vm_start;
50739+ end = vma_fault->vm_end;
50740+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
50741+ if (vma_fault->vm_file) {
50742+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
50743+ if (IS_ERR(path_fault))
50744+ path_fault = "<path too long>";
50745+ else {
50746+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
50747+ if (path_fault) {
50748+ *path_fault = 0;
50749+ path_fault = buffer_fault;
50750+ } else
50751+ path_fault = "<path too long>";
50752+ }
50753+ } else
50754+ path_fault = "<anonymous mapping>";
50755+ }
50756+ up_read(&mm->mmap_sem);
50757+ }
50758+ if (tsk->signal->curr_ip)
50759+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
50760+ else
50761+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
50762+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
50763+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
50764+ free_page((unsigned long)buffer_exec);
50765+ free_page((unsigned long)buffer_fault);
50766+ pax_report_insns(regs, pc, sp);
50767+ info.si_signo = SIGKILL;
50768+ info.si_errno = 0;
50769+ info.si_code = SI_KERNEL;
50770+ info.si_pid = 0;
50771+ info.si_uid = 0;
50772+ do_coredump(&info);
50773+}
50774+#endif
50775+
50776+#ifdef CONFIG_PAX_REFCOUNT
50777+void pax_report_refcount_overflow(struct pt_regs *regs)
50778+{
50779+ if (current->signal->curr_ip)
50780+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
50781+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
50782+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
50783+ else
50784+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
50785+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
50786+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
50787+ show_regs(regs);
50788+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
50789+}
50790+#endif
50791+
50792+#ifdef CONFIG_PAX_USERCOPY
50793+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
50794+static noinline int check_stack_object(const void *obj, unsigned long len)
50795+{
50796+ const void * const stack = task_stack_page(current);
50797+ const void * const stackend = stack + THREAD_SIZE;
50798+
50799+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
50800+ const void *frame = NULL;
50801+ const void *oldframe;
50802+#endif
50803+
50804+ if (obj + len < obj)
50805+ return -1;
50806+
50807+ if (obj + len <= stack || stackend <= obj)
50808+ return 0;
50809+
50810+ if (obj < stack || stackend < obj + len)
50811+ return -1;
50812+
50813+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
50814+ oldframe = __builtin_frame_address(1);
50815+ if (oldframe)
50816+ frame = __builtin_frame_address(2);
50817+ /*
50818+ low ----------------------------------------------> high
50819+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
50820+ ^----------------^
50821+ allow copies only within here
50822+ */
50823+ while (stack <= frame && frame < stackend) {
50824+ /* if obj + len extends past the last frame, this
50825+ check won't pass and the next frame will be 0,
50826+ causing us to bail out and correctly report
50827+ the copy as invalid
50828+ */
50829+ if (obj + len <= frame)
50830+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
50831+ oldframe = frame;
50832+ frame = *(const void * const *)frame;
50833+ }
50834+ return -1;
50835+#else
50836+ return 1;
50837+#endif
50838+}
50839+
50840+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
50841+{
50842+ if (current->signal->curr_ip)
50843+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
50844+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
50845+ else
50846+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
50847+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
50848+ dump_stack();
50849+ gr_handle_kernel_exploit();
50850+ do_group_exit(SIGKILL);
50851+}
50852+#endif
50853+
50854+#ifdef CONFIG_PAX_USERCOPY
50855+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
50856+{
50857+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
50858+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
50859+#ifdef CONFIG_MODULES
50860+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
50861+#else
50862+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
50863+#endif
50864+
50865+#else
50866+ unsigned long textlow = (unsigned long)_stext;
50867+ unsigned long texthigh = (unsigned long)_etext;
50868+#endif
50869+
50870+ if (high <= textlow || low > texthigh)
50871+ return false;
50872+ else
50873+ return true;
50874+}
50875+#endif
50876+
50877+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
50878+{
50879+
50880+#ifdef CONFIG_PAX_USERCOPY
50881+ const char *type;
50882+
50883+ if (!n)
50884+ return;
50885+
50886+ type = check_heap_object(ptr, n);
50887+ if (!type) {
50888+ int ret = check_stack_object(ptr, n);
50889+ if (ret == 1 || ret == 2)
50890+ return;
50891+ if (ret == 0) {
50892+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
50893+ type = "<kernel text>";
50894+ else
50895+ return;
50896+ } else
50897+ type = "<process stack>";
50898+ }
50899+
50900+ pax_report_usercopy(ptr, n, to_user, type);
50901+#endif
50902+
50903+}
50904+EXPORT_SYMBOL(__check_object_size);
50905+
50906+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
50907+void pax_track_stack(void)
50908+{
50909+ unsigned long sp = (unsigned long)&sp;
50910+ if (sp < current_thread_info()->lowest_stack &&
50911+ sp > (unsigned long)task_stack_page(current))
50912+ current_thread_info()->lowest_stack = sp;
50913+}
50914+EXPORT_SYMBOL(pax_track_stack);
50915+#endif
50916+
50917+#ifdef CONFIG_PAX_SIZE_OVERFLOW
50918+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
50919+{
50920+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
50921+ dump_stack();
50922+ do_group_exit(SIGKILL);
50923+}
50924+EXPORT_SYMBOL(report_size_overflow);
50925+#endif
50926diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
50927index 9f9992b..8b59411 100644
50928--- a/fs/ext2/balloc.c
50929+++ b/fs/ext2/balloc.c
50930@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
50931
50932 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
50933 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
50934- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
50935+ if (free_blocks < root_blocks + 1 &&
50936 !uid_eq(sbi->s_resuid, current_fsuid()) &&
50937 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
50938- !in_group_p (sbi->s_resgid))) {
50939+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
50940 return 0;
50941 }
50942 return 1;
50943diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
50944index 22548f5..41521d8 100644
50945--- a/fs/ext3/balloc.c
50946+++ b/fs/ext3/balloc.c
50947@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
50948
50949 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
50950 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
50951- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
50952+ if (free_blocks < root_blocks + 1 &&
50953 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
50954 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
50955- !in_group_p (sbi->s_resgid))) {
50956+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
50957 return 0;
50958 }
50959 return 1;
50960diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
50961index 92e68b3..115d987 100644
50962--- a/fs/ext4/balloc.c
50963+++ b/fs/ext4/balloc.c
50964@@ -505,8 +505,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
50965 /* Hm, nope. Are (enough) root reserved clusters available? */
50966 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
50967 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
50968- capable(CAP_SYS_RESOURCE) ||
50969- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
50970+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
50971+ capable_nolog(CAP_SYS_RESOURCE)) {
50972
50973 if (free_clusters >= (nclusters + dirty_clusters))
50974 return 1;
50975diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
50976index 3b83cd6..0f34dcd 100644
50977--- a/fs/ext4/ext4.h
50978+++ b/fs/ext4/ext4.h
50979@@ -1254,19 +1254,19 @@ struct ext4_sb_info {
50980 unsigned long s_mb_last_start;
50981
50982 /* stats for buddy allocator */
50983- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
50984- atomic_t s_bal_success; /* we found long enough chunks */
50985- atomic_t s_bal_allocated; /* in blocks */
50986- atomic_t s_bal_ex_scanned; /* total extents scanned */
50987- atomic_t s_bal_goals; /* goal hits */
50988- atomic_t s_bal_breaks; /* too long searches */
50989- atomic_t s_bal_2orders; /* 2^order hits */
50990+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
50991+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
50992+ atomic_unchecked_t s_bal_allocated; /* in blocks */
50993+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
50994+ atomic_unchecked_t s_bal_goals; /* goal hits */
50995+ atomic_unchecked_t s_bal_breaks; /* too long searches */
50996+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
50997 spinlock_t s_bal_lock;
50998 unsigned long s_mb_buddies_generated;
50999 unsigned long long s_mb_generation_time;
51000- atomic_t s_mb_lost_chunks;
51001- atomic_t s_mb_preallocated;
51002- atomic_t s_mb_discarded;
51003+ atomic_unchecked_t s_mb_lost_chunks;
51004+ atomic_unchecked_t s_mb_preallocated;
51005+ atomic_unchecked_t s_mb_discarded;
51006 atomic_t s_lock_busy;
51007
51008 /* locality groups */
51009diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
51010index f3190ab..84ffb21 100644
51011--- a/fs/ext4/mballoc.c
51012+++ b/fs/ext4/mballoc.c
51013@@ -1754,7 +1754,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
51014 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
51015
51016 if (EXT4_SB(sb)->s_mb_stats)
51017- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
51018+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
51019
51020 break;
51021 }
51022@@ -2059,7 +2059,7 @@ repeat:
51023 ac->ac_status = AC_STATUS_CONTINUE;
51024 ac->ac_flags |= EXT4_MB_HINT_FIRST;
51025 cr = 3;
51026- atomic_inc(&sbi->s_mb_lost_chunks);
51027+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
51028 goto repeat;
51029 }
51030 }
51031@@ -2567,25 +2567,25 @@ int ext4_mb_release(struct super_block *sb)
51032 if (sbi->s_mb_stats) {
51033 ext4_msg(sb, KERN_INFO,
51034 "mballoc: %u blocks %u reqs (%u success)",
51035- atomic_read(&sbi->s_bal_allocated),
51036- atomic_read(&sbi->s_bal_reqs),
51037- atomic_read(&sbi->s_bal_success));
51038+ atomic_read_unchecked(&sbi->s_bal_allocated),
51039+ atomic_read_unchecked(&sbi->s_bal_reqs),
51040+ atomic_read_unchecked(&sbi->s_bal_success));
51041 ext4_msg(sb, KERN_INFO,
51042 "mballoc: %u extents scanned, %u goal hits, "
51043 "%u 2^N hits, %u breaks, %u lost",
51044- atomic_read(&sbi->s_bal_ex_scanned),
51045- atomic_read(&sbi->s_bal_goals),
51046- atomic_read(&sbi->s_bal_2orders),
51047- atomic_read(&sbi->s_bal_breaks),
51048- atomic_read(&sbi->s_mb_lost_chunks));
51049+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
51050+ atomic_read_unchecked(&sbi->s_bal_goals),
51051+ atomic_read_unchecked(&sbi->s_bal_2orders),
51052+ atomic_read_unchecked(&sbi->s_bal_breaks),
51053+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
51054 ext4_msg(sb, KERN_INFO,
51055 "mballoc: %lu generated and it took %Lu",
51056 sbi->s_mb_buddies_generated,
51057 sbi->s_mb_generation_time);
51058 ext4_msg(sb, KERN_INFO,
51059 "mballoc: %u preallocated, %u discarded",
51060- atomic_read(&sbi->s_mb_preallocated),
51061- atomic_read(&sbi->s_mb_discarded));
51062+ atomic_read_unchecked(&sbi->s_mb_preallocated),
51063+ atomic_read_unchecked(&sbi->s_mb_discarded));
51064 }
51065
51066 free_percpu(sbi->s_locality_groups);
51067@@ -3039,16 +3039,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
51068 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
51069
51070 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
51071- atomic_inc(&sbi->s_bal_reqs);
51072- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
51073+ atomic_inc_unchecked(&sbi->s_bal_reqs);
51074+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
51075 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
51076- atomic_inc(&sbi->s_bal_success);
51077- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
51078+ atomic_inc_unchecked(&sbi->s_bal_success);
51079+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
51080 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
51081 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
51082- atomic_inc(&sbi->s_bal_goals);
51083+ atomic_inc_unchecked(&sbi->s_bal_goals);
51084 if (ac->ac_found > sbi->s_mb_max_to_scan)
51085- atomic_inc(&sbi->s_bal_breaks);
51086+ atomic_inc_unchecked(&sbi->s_bal_breaks);
51087 }
51088
51089 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
51090@@ -3448,7 +3448,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
51091 trace_ext4_mb_new_inode_pa(ac, pa);
51092
51093 ext4_mb_use_inode_pa(ac, pa);
51094- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
51095+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
51096
51097 ei = EXT4_I(ac->ac_inode);
51098 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51099@@ -3508,7 +3508,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
51100 trace_ext4_mb_new_group_pa(ac, pa);
51101
51102 ext4_mb_use_group_pa(ac, pa);
51103- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51104+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51105
51106 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51107 lg = ac->ac_lg;
51108@@ -3597,7 +3597,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
51109 * from the bitmap and continue.
51110 */
51111 }
51112- atomic_add(free, &sbi->s_mb_discarded);
51113+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
51114
51115 return err;
51116 }
51117@@ -3615,7 +3615,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
51118 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
51119 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
51120 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
51121- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51122+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51123 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
51124
51125 return 0;
51126diff --git a/fs/ext4/super.c b/fs/ext4/super.c
51127index febbe0e..782c4fd 100644
51128--- a/fs/ext4/super.c
51129+++ b/fs/ext4/super.c
51130@@ -2380,7 +2380,7 @@ struct ext4_attr {
51131 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
51132 const char *, size_t);
51133 int offset;
51134-};
51135+} __do_const;
51136
51137 static int parse_strtoul(const char *buf,
51138 unsigned long max, unsigned long *value)
51139diff --git a/fs/fcntl.c b/fs/fcntl.c
51140index 6599222..e7bf0de 100644
51141--- a/fs/fcntl.c
51142+++ b/fs/fcntl.c
51143@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
51144 if (err)
51145 return err;
51146
51147+ if (gr_handle_chroot_fowner(pid, type))
51148+ return -ENOENT;
51149+ if (gr_check_protected_task_fowner(pid, type))
51150+ return -EACCES;
51151+
51152 f_modown(filp, pid, type, force);
51153 return 0;
51154 }
51155diff --git a/fs/fhandle.c b/fs/fhandle.c
51156index 999ff5c..41f4109 100644
51157--- a/fs/fhandle.c
51158+++ b/fs/fhandle.c
51159@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
51160 } else
51161 retval = 0;
51162 /* copy the mount id */
51163- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
51164- sizeof(*mnt_id)) ||
51165+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
51166 copy_to_user(ufh, handle,
51167 sizeof(struct file_handle) + handle_bytes))
51168 retval = -EFAULT;
51169diff --git a/fs/fifo.c b/fs/fifo.c
51170index cf6f434..3d7942c 100644
51171--- a/fs/fifo.c
51172+++ b/fs/fifo.c
51173@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
51174 */
51175 filp->f_op = &read_pipefifo_fops;
51176 pipe->r_counter++;
51177- if (pipe->readers++ == 0)
51178+ if (atomic_inc_return(&pipe->readers) == 1)
51179 wake_up_partner(inode);
51180
51181- if (!pipe->writers) {
51182+ if (!atomic_read(&pipe->writers)) {
51183 if ((filp->f_flags & O_NONBLOCK)) {
51184 /* suppress POLLHUP until we have
51185 * seen a writer */
51186@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
51187 * errno=ENXIO when there is no process reading the FIFO.
51188 */
51189 ret = -ENXIO;
51190- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
51191+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
51192 goto err;
51193
51194 filp->f_op = &write_pipefifo_fops;
51195 pipe->w_counter++;
51196- if (!pipe->writers++)
51197+ if (atomic_inc_return(&pipe->writers) == 1)
51198 wake_up_partner(inode);
51199
51200- if (!pipe->readers) {
51201+ if (!atomic_read(&pipe->readers)) {
51202 if (wait_for_partner(inode, &pipe->r_counter))
51203 goto err_wr;
51204 }
51205@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
51206 */
51207 filp->f_op = &rdwr_pipefifo_fops;
51208
51209- pipe->readers++;
51210- pipe->writers++;
51211+ atomic_inc(&pipe->readers);
51212+ atomic_inc(&pipe->writers);
51213 pipe->r_counter++;
51214 pipe->w_counter++;
51215- if (pipe->readers == 1 || pipe->writers == 1)
51216+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
51217 wake_up_partner(inode);
51218 break;
51219
51220@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
51221 return 0;
51222
51223 err_rd:
51224- if (!--pipe->readers)
51225+ if (atomic_dec_and_test(&pipe->readers))
51226 wake_up_interruptible(&pipe->wait);
51227 ret = -ERESTARTSYS;
51228 goto err;
51229
51230 err_wr:
51231- if (!--pipe->writers)
51232+ if (atomic_dec_and_test(&pipe->writers))
51233 wake_up_interruptible(&pipe->wait);
51234 ret = -ERESTARTSYS;
51235 goto err;
51236
51237 err:
51238- if (!pipe->readers && !pipe->writers)
51239+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
51240 free_pipe_info(inode);
51241
51242 err_nocleanup:
51243diff --git a/fs/file.c b/fs/file.c
51244index 3906d95..5fe379b 100644
51245--- a/fs/file.c
51246+++ b/fs/file.c
51247@@ -16,6 +16,7 @@
51248 #include <linux/slab.h>
51249 #include <linux/vmalloc.h>
51250 #include <linux/file.h>
51251+#include <linux/security.h>
51252 #include <linux/fdtable.h>
51253 #include <linux/bitops.h>
51254 #include <linux/interrupt.h>
51255@@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
51256 if (!file)
51257 return __close_fd(files, fd);
51258
51259+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
51260 if (fd >= rlimit(RLIMIT_NOFILE))
51261 return -EBADF;
51262
51263@@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
51264 if (unlikely(oldfd == newfd))
51265 return -EINVAL;
51266
51267+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
51268 if (newfd >= rlimit(RLIMIT_NOFILE))
51269 return -EBADF;
51270
51271@@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
51272 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
51273 {
51274 int err;
51275+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
51276 if (from >= rlimit(RLIMIT_NOFILE))
51277 return -EINVAL;
51278 err = alloc_fd(from, flags);
51279diff --git a/fs/filesystems.c b/fs/filesystems.c
51280index 92567d9..fcd8cbf 100644
51281--- a/fs/filesystems.c
51282+++ b/fs/filesystems.c
51283@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
51284 int len = dot ? dot - name : strlen(name);
51285
51286 fs = __get_fs_type(name, len);
51287+#ifdef CONFIG_GRKERNSEC_MODHARDEN
51288+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
51289+#else
51290 if (!fs && (request_module("fs-%.*s", len, name) == 0))
51291+#endif
51292 fs = __get_fs_type(name, len);
51293
51294 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
51295diff --git a/fs/fs_struct.c b/fs/fs_struct.c
51296index d8ac61d..79a36f0 100644
51297--- a/fs/fs_struct.c
51298+++ b/fs/fs_struct.c
51299@@ -4,6 +4,7 @@
51300 #include <linux/path.h>
51301 #include <linux/slab.h>
51302 #include <linux/fs_struct.h>
51303+#include <linux/grsecurity.h>
51304 #include "internal.h"
51305
51306 /*
51307@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
51308 write_seqcount_begin(&fs->seq);
51309 old_root = fs->root;
51310 fs->root = *path;
51311+ gr_set_chroot_entries(current, path);
51312 write_seqcount_end(&fs->seq);
51313 spin_unlock(&fs->lock);
51314 if (old_root.dentry)
51315@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
51316 int hits = 0;
51317 spin_lock(&fs->lock);
51318 write_seqcount_begin(&fs->seq);
51319+ /* this root replacement is only done by pivot_root,
51320+ leave grsec's chroot tagging alone for this task
51321+ so that a pivoted root isn't treated as a chroot
51322+ */
51323 hits += replace_path(&fs->root, old_root, new_root);
51324 hits += replace_path(&fs->pwd, old_root, new_root);
51325 write_seqcount_end(&fs->seq);
51326@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
51327 task_lock(tsk);
51328 spin_lock(&fs->lock);
51329 tsk->fs = NULL;
51330- kill = !--fs->users;
51331+ gr_clear_chroot_entries(tsk);
51332+ kill = !atomic_dec_return(&fs->users);
51333 spin_unlock(&fs->lock);
51334 task_unlock(tsk);
51335 if (kill)
51336@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51337 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
51338 /* We don't need to lock fs - think why ;-) */
51339 if (fs) {
51340- fs->users = 1;
51341+ atomic_set(&fs->users, 1);
51342 fs->in_exec = 0;
51343 spin_lock_init(&fs->lock);
51344 seqcount_init(&fs->seq);
51345@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51346 spin_lock(&old->lock);
51347 fs->root = old->root;
51348 path_get(&fs->root);
51349+ /* instead of calling gr_set_chroot_entries here,
51350+ we call it from every caller of this function
51351+ */
51352 fs->pwd = old->pwd;
51353 path_get(&fs->pwd);
51354 spin_unlock(&old->lock);
51355@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
51356
51357 task_lock(current);
51358 spin_lock(&fs->lock);
51359- kill = !--fs->users;
51360+ kill = !atomic_dec_return(&fs->users);
51361 current->fs = new_fs;
51362+ gr_set_chroot_entries(current, &new_fs->root);
51363 spin_unlock(&fs->lock);
51364 task_unlock(current);
51365
51366@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
51367
51368 int current_umask(void)
51369 {
51370- return current->fs->umask;
51371+ return current->fs->umask | gr_acl_umask();
51372 }
51373 EXPORT_SYMBOL(current_umask);
51374
51375 /* to be mentioned only in INIT_TASK */
51376 struct fs_struct init_fs = {
51377- .users = 1,
51378+ .users = ATOMIC_INIT(1),
51379 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
51380 .seq = SEQCNT_ZERO,
51381 .umask = 0022,
51382diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
51383index e2cba1f..17a25bb 100644
51384--- a/fs/fscache/cookie.c
51385+++ b/fs/fscache/cookie.c
51386@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
51387 parent ? (char *) parent->def->name : "<no-parent>",
51388 def->name, netfs_data);
51389
51390- fscache_stat(&fscache_n_acquires);
51391+ fscache_stat_unchecked(&fscache_n_acquires);
51392
51393 /* if there's no parent cookie, then we don't create one here either */
51394 if (!parent) {
51395- fscache_stat(&fscache_n_acquires_null);
51396+ fscache_stat_unchecked(&fscache_n_acquires_null);
51397 _leave(" [no parent]");
51398 return NULL;
51399 }
51400@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
51401 /* allocate and initialise a cookie */
51402 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
51403 if (!cookie) {
51404- fscache_stat(&fscache_n_acquires_oom);
51405+ fscache_stat_unchecked(&fscache_n_acquires_oom);
51406 _leave(" [ENOMEM]");
51407 return NULL;
51408 }
51409@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
51410
51411 switch (cookie->def->type) {
51412 case FSCACHE_COOKIE_TYPE_INDEX:
51413- fscache_stat(&fscache_n_cookie_index);
51414+ fscache_stat_unchecked(&fscache_n_cookie_index);
51415 break;
51416 case FSCACHE_COOKIE_TYPE_DATAFILE:
51417- fscache_stat(&fscache_n_cookie_data);
51418+ fscache_stat_unchecked(&fscache_n_cookie_data);
51419 break;
51420 default:
51421- fscache_stat(&fscache_n_cookie_special);
51422+ fscache_stat_unchecked(&fscache_n_cookie_special);
51423 break;
51424 }
51425
51426@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
51427 if (fscache_acquire_non_index_cookie(cookie) < 0) {
51428 atomic_dec(&parent->n_children);
51429 __fscache_cookie_put(cookie);
51430- fscache_stat(&fscache_n_acquires_nobufs);
51431+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
51432 _leave(" = NULL");
51433 return NULL;
51434 }
51435 }
51436
51437- fscache_stat(&fscache_n_acquires_ok);
51438+ fscache_stat_unchecked(&fscache_n_acquires_ok);
51439 _leave(" = %p", cookie);
51440 return cookie;
51441 }
51442@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
51443 cache = fscache_select_cache_for_object(cookie->parent);
51444 if (!cache) {
51445 up_read(&fscache_addremove_sem);
51446- fscache_stat(&fscache_n_acquires_no_cache);
51447+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
51448 _leave(" = -ENOMEDIUM [no cache]");
51449 return -ENOMEDIUM;
51450 }
51451@@ -255,12 +255,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
51452 object = cache->ops->alloc_object(cache, cookie);
51453 fscache_stat_d(&fscache_n_cop_alloc_object);
51454 if (IS_ERR(object)) {
51455- fscache_stat(&fscache_n_object_no_alloc);
51456+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
51457 ret = PTR_ERR(object);
51458 goto error;
51459 }
51460
51461- fscache_stat(&fscache_n_object_alloc);
51462+ fscache_stat_unchecked(&fscache_n_object_alloc);
51463
51464 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
51465
51466@@ -376,7 +376,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
51467
51468 _enter("{%s}", cookie->def->name);
51469
51470- fscache_stat(&fscache_n_invalidates);
51471+ fscache_stat_unchecked(&fscache_n_invalidates);
51472
51473 /* Only permit invalidation of data files. Invalidating an index will
51474 * require the caller to release all its attachments to the tree rooted
51475@@ -434,10 +434,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
51476 {
51477 struct fscache_object *object;
51478
51479- fscache_stat(&fscache_n_updates);
51480+ fscache_stat_unchecked(&fscache_n_updates);
51481
51482 if (!cookie) {
51483- fscache_stat(&fscache_n_updates_null);
51484+ fscache_stat_unchecked(&fscache_n_updates_null);
51485 _leave(" [no cookie]");
51486 return;
51487 }
51488@@ -471,12 +471,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
51489 struct fscache_object *object;
51490 unsigned long event;
51491
51492- fscache_stat(&fscache_n_relinquishes);
51493+ fscache_stat_unchecked(&fscache_n_relinquishes);
51494 if (retire)
51495- fscache_stat(&fscache_n_relinquishes_retire);
51496+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
51497
51498 if (!cookie) {
51499- fscache_stat(&fscache_n_relinquishes_null);
51500+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
51501 _leave(" [no cookie]");
51502 return;
51503 }
51504@@ -492,7 +492,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
51505
51506 /* wait for the cookie to finish being instantiated (or to fail) */
51507 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
51508- fscache_stat(&fscache_n_relinquishes_waitcrt);
51509+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
51510 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
51511 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
51512 }
51513diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
51514index ee38fef..0a326d4 100644
51515--- a/fs/fscache/internal.h
51516+++ b/fs/fscache/internal.h
51517@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
51518 * stats.c
51519 */
51520 #ifdef CONFIG_FSCACHE_STATS
51521-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
51522-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
51523+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
51524+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
51525
51526-extern atomic_t fscache_n_op_pend;
51527-extern atomic_t fscache_n_op_run;
51528-extern atomic_t fscache_n_op_enqueue;
51529-extern atomic_t fscache_n_op_deferred_release;
51530-extern atomic_t fscache_n_op_release;
51531-extern atomic_t fscache_n_op_gc;
51532-extern atomic_t fscache_n_op_cancelled;
51533-extern atomic_t fscache_n_op_rejected;
51534+extern atomic_unchecked_t fscache_n_op_pend;
51535+extern atomic_unchecked_t fscache_n_op_run;
51536+extern atomic_unchecked_t fscache_n_op_enqueue;
51537+extern atomic_unchecked_t fscache_n_op_deferred_release;
51538+extern atomic_unchecked_t fscache_n_op_release;
51539+extern atomic_unchecked_t fscache_n_op_gc;
51540+extern atomic_unchecked_t fscache_n_op_cancelled;
51541+extern atomic_unchecked_t fscache_n_op_rejected;
51542
51543-extern atomic_t fscache_n_attr_changed;
51544-extern atomic_t fscache_n_attr_changed_ok;
51545-extern atomic_t fscache_n_attr_changed_nobufs;
51546-extern atomic_t fscache_n_attr_changed_nomem;
51547-extern atomic_t fscache_n_attr_changed_calls;
51548+extern atomic_unchecked_t fscache_n_attr_changed;
51549+extern atomic_unchecked_t fscache_n_attr_changed_ok;
51550+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
51551+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
51552+extern atomic_unchecked_t fscache_n_attr_changed_calls;
51553
51554-extern atomic_t fscache_n_allocs;
51555-extern atomic_t fscache_n_allocs_ok;
51556-extern atomic_t fscache_n_allocs_wait;
51557-extern atomic_t fscache_n_allocs_nobufs;
51558-extern atomic_t fscache_n_allocs_intr;
51559-extern atomic_t fscache_n_allocs_object_dead;
51560-extern atomic_t fscache_n_alloc_ops;
51561-extern atomic_t fscache_n_alloc_op_waits;
51562+extern atomic_unchecked_t fscache_n_allocs;
51563+extern atomic_unchecked_t fscache_n_allocs_ok;
51564+extern atomic_unchecked_t fscache_n_allocs_wait;
51565+extern atomic_unchecked_t fscache_n_allocs_nobufs;
51566+extern atomic_unchecked_t fscache_n_allocs_intr;
51567+extern atomic_unchecked_t fscache_n_allocs_object_dead;
51568+extern atomic_unchecked_t fscache_n_alloc_ops;
51569+extern atomic_unchecked_t fscache_n_alloc_op_waits;
51570
51571-extern atomic_t fscache_n_retrievals;
51572-extern atomic_t fscache_n_retrievals_ok;
51573-extern atomic_t fscache_n_retrievals_wait;
51574-extern atomic_t fscache_n_retrievals_nodata;
51575-extern atomic_t fscache_n_retrievals_nobufs;
51576-extern atomic_t fscache_n_retrievals_intr;
51577-extern atomic_t fscache_n_retrievals_nomem;
51578-extern atomic_t fscache_n_retrievals_object_dead;
51579-extern atomic_t fscache_n_retrieval_ops;
51580-extern atomic_t fscache_n_retrieval_op_waits;
51581+extern atomic_unchecked_t fscache_n_retrievals;
51582+extern atomic_unchecked_t fscache_n_retrievals_ok;
51583+extern atomic_unchecked_t fscache_n_retrievals_wait;
51584+extern atomic_unchecked_t fscache_n_retrievals_nodata;
51585+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
51586+extern atomic_unchecked_t fscache_n_retrievals_intr;
51587+extern atomic_unchecked_t fscache_n_retrievals_nomem;
51588+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
51589+extern atomic_unchecked_t fscache_n_retrieval_ops;
51590+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
51591
51592-extern atomic_t fscache_n_stores;
51593-extern atomic_t fscache_n_stores_ok;
51594-extern atomic_t fscache_n_stores_again;
51595-extern atomic_t fscache_n_stores_nobufs;
51596-extern atomic_t fscache_n_stores_oom;
51597-extern atomic_t fscache_n_store_ops;
51598-extern atomic_t fscache_n_store_calls;
51599-extern atomic_t fscache_n_store_pages;
51600-extern atomic_t fscache_n_store_radix_deletes;
51601-extern atomic_t fscache_n_store_pages_over_limit;
51602+extern atomic_unchecked_t fscache_n_stores;
51603+extern atomic_unchecked_t fscache_n_stores_ok;
51604+extern atomic_unchecked_t fscache_n_stores_again;
51605+extern atomic_unchecked_t fscache_n_stores_nobufs;
51606+extern atomic_unchecked_t fscache_n_stores_oom;
51607+extern atomic_unchecked_t fscache_n_store_ops;
51608+extern atomic_unchecked_t fscache_n_store_calls;
51609+extern atomic_unchecked_t fscache_n_store_pages;
51610+extern atomic_unchecked_t fscache_n_store_radix_deletes;
51611+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
51612
51613-extern atomic_t fscache_n_store_vmscan_not_storing;
51614-extern atomic_t fscache_n_store_vmscan_gone;
51615-extern atomic_t fscache_n_store_vmscan_busy;
51616-extern atomic_t fscache_n_store_vmscan_cancelled;
51617-extern atomic_t fscache_n_store_vmscan_wait;
51618+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
51619+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
51620+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
51621+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
51622+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
51623
51624-extern atomic_t fscache_n_marks;
51625-extern atomic_t fscache_n_uncaches;
51626+extern atomic_unchecked_t fscache_n_marks;
51627+extern atomic_unchecked_t fscache_n_uncaches;
51628
51629-extern atomic_t fscache_n_acquires;
51630-extern atomic_t fscache_n_acquires_null;
51631-extern atomic_t fscache_n_acquires_no_cache;
51632-extern atomic_t fscache_n_acquires_ok;
51633-extern atomic_t fscache_n_acquires_nobufs;
51634-extern atomic_t fscache_n_acquires_oom;
51635+extern atomic_unchecked_t fscache_n_acquires;
51636+extern atomic_unchecked_t fscache_n_acquires_null;
51637+extern atomic_unchecked_t fscache_n_acquires_no_cache;
51638+extern atomic_unchecked_t fscache_n_acquires_ok;
51639+extern atomic_unchecked_t fscache_n_acquires_nobufs;
51640+extern atomic_unchecked_t fscache_n_acquires_oom;
51641
51642-extern atomic_t fscache_n_invalidates;
51643-extern atomic_t fscache_n_invalidates_run;
51644+extern atomic_unchecked_t fscache_n_invalidates;
51645+extern atomic_unchecked_t fscache_n_invalidates_run;
51646
51647-extern atomic_t fscache_n_updates;
51648-extern atomic_t fscache_n_updates_null;
51649-extern atomic_t fscache_n_updates_run;
51650+extern atomic_unchecked_t fscache_n_updates;
51651+extern atomic_unchecked_t fscache_n_updates_null;
51652+extern atomic_unchecked_t fscache_n_updates_run;
51653
51654-extern atomic_t fscache_n_relinquishes;
51655-extern atomic_t fscache_n_relinquishes_null;
51656-extern atomic_t fscache_n_relinquishes_waitcrt;
51657-extern atomic_t fscache_n_relinquishes_retire;
51658+extern atomic_unchecked_t fscache_n_relinquishes;
51659+extern atomic_unchecked_t fscache_n_relinquishes_null;
51660+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
51661+extern atomic_unchecked_t fscache_n_relinquishes_retire;
51662
51663-extern atomic_t fscache_n_cookie_index;
51664-extern atomic_t fscache_n_cookie_data;
51665-extern atomic_t fscache_n_cookie_special;
51666+extern atomic_unchecked_t fscache_n_cookie_index;
51667+extern atomic_unchecked_t fscache_n_cookie_data;
51668+extern atomic_unchecked_t fscache_n_cookie_special;
51669
51670-extern atomic_t fscache_n_object_alloc;
51671-extern atomic_t fscache_n_object_no_alloc;
51672-extern atomic_t fscache_n_object_lookups;
51673-extern atomic_t fscache_n_object_lookups_negative;
51674-extern atomic_t fscache_n_object_lookups_positive;
51675-extern atomic_t fscache_n_object_lookups_timed_out;
51676-extern atomic_t fscache_n_object_created;
51677-extern atomic_t fscache_n_object_avail;
51678-extern atomic_t fscache_n_object_dead;
51679+extern atomic_unchecked_t fscache_n_object_alloc;
51680+extern atomic_unchecked_t fscache_n_object_no_alloc;
51681+extern atomic_unchecked_t fscache_n_object_lookups;
51682+extern atomic_unchecked_t fscache_n_object_lookups_negative;
51683+extern atomic_unchecked_t fscache_n_object_lookups_positive;
51684+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
51685+extern atomic_unchecked_t fscache_n_object_created;
51686+extern atomic_unchecked_t fscache_n_object_avail;
51687+extern atomic_unchecked_t fscache_n_object_dead;
51688
51689-extern atomic_t fscache_n_checkaux_none;
51690-extern atomic_t fscache_n_checkaux_okay;
51691-extern atomic_t fscache_n_checkaux_update;
51692-extern atomic_t fscache_n_checkaux_obsolete;
51693+extern atomic_unchecked_t fscache_n_checkaux_none;
51694+extern atomic_unchecked_t fscache_n_checkaux_okay;
51695+extern atomic_unchecked_t fscache_n_checkaux_update;
51696+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
51697
51698 extern atomic_t fscache_n_cop_alloc_object;
51699 extern atomic_t fscache_n_cop_lookup_object;
51700@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
51701 atomic_inc(stat);
51702 }
51703
51704+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
51705+{
51706+ atomic_inc_unchecked(stat);
51707+}
51708+
51709 static inline void fscache_stat_d(atomic_t *stat)
51710 {
51711 atomic_dec(stat);
51712@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
51713
51714 #define __fscache_stat(stat) (NULL)
51715 #define fscache_stat(stat) do {} while (0)
51716+#define fscache_stat_unchecked(stat) do {} while (0)
51717 #define fscache_stat_d(stat) do {} while (0)
51718 #endif
51719
51720diff --git a/fs/fscache/object.c b/fs/fscache/object.c
51721index 50d41c1..10ee117 100644
51722--- a/fs/fscache/object.c
51723+++ b/fs/fscache/object.c
51724@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51725 /* Invalidate an object on disk */
51726 case FSCACHE_OBJECT_INVALIDATING:
51727 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
51728- fscache_stat(&fscache_n_invalidates_run);
51729+ fscache_stat_unchecked(&fscache_n_invalidates_run);
51730 fscache_stat(&fscache_n_cop_invalidate_object);
51731 fscache_invalidate_object(object);
51732 fscache_stat_d(&fscache_n_cop_invalidate_object);
51733@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51734 /* update the object metadata on disk */
51735 case FSCACHE_OBJECT_UPDATING:
51736 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
51737- fscache_stat(&fscache_n_updates_run);
51738+ fscache_stat_unchecked(&fscache_n_updates_run);
51739 fscache_stat(&fscache_n_cop_update_object);
51740 object->cache->ops->update_object(object);
51741 fscache_stat_d(&fscache_n_cop_update_object);
51742@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51743 spin_lock(&object->lock);
51744 object->state = FSCACHE_OBJECT_DEAD;
51745 spin_unlock(&object->lock);
51746- fscache_stat(&fscache_n_object_dead);
51747+ fscache_stat_unchecked(&fscache_n_object_dead);
51748 goto terminal_transit;
51749
51750 /* handle the parent cache of this object being withdrawn from
51751@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51752 spin_lock(&object->lock);
51753 object->state = FSCACHE_OBJECT_DEAD;
51754 spin_unlock(&object->lock);
51755- fscache_stat(&fscache_n_object_dead);
51756+ fscache_stat_unchecked(&fscache_n_object_dead);
51757 goto terminal_transit;
51758
51759 /* complain about the object being woken up once it is
51760@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
51761 parent->cookie->def->name, cookie->def->name,
51762 object->cache->tag->name);
51763
51764- fscache_stat(&fscache_n_object_lookups);
51765+ fscache_stat_unchecked(&fscache_n_object_lookups);
51766 fscache_stat(&fscache_n_cop_lookup_object);
51767 ret = object->cache->ops->lookup_object(object);
51768 fscache_stat_d(&fscache_n_cop_lookup_object);
51769@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
51770 if (ret == -ETIMEDOUT) {
51771 /* probably stuck behind another object, so move this one to
51772 * the back of the queue */
51773- fscache_stat(&fscache_n_object_lookups_timed_out);
51774+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
51775 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
51776 }
51777
51778@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
51779
51780 spin_lock(&object->lock);
51781 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
51782- fscache_stat(&fscache_n_object_lookups_negative);
51783+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
51784
51785 /* transit here to allow write requests to begin stacking up
51786 * and read requests to begin returning ENODATA */
51787@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
51788 * result, in which case there may be data available */
51789 spin_lock(&object->lock);
51790 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
51791- fscache_stat(&fscache_n_object_lookups_positive);
51792+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
51793
51794 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
51795
51796@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
51797 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
51798 } else {
51799 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
51800- fscache_stat(&fscache_n_object_created);
51801+ fscache_stat_unchecked(&fscache_n_object_created);
51802
51803 object->state = FSCACHE_OBJECT_AVAILABLE;
51804 spin_unlock(&object->lock);
51805@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
51806 fscache_enqueue_dependents(object);
51807
51808 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
51809- fscache_stat(&fscache_n_object_avail);
51810+ fscache_stat_unchecked(&fscache_n_object_avail);
51811
51812 _leave("");
51813 }
51814@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
51815 enum fscache_checkaux result;
51816
51817 if (!object->cookie->def->check_aux) {
51818- fscache_stat(&fscache_n_checkaux_none);
51819+ fscache_stat_unchecked(&fscache_n_checkaux_none);
51820 return FSCACHE_CHECKAUX_OKAY;
51821 }
51822
51823@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
51824 switch (result) {
51825 /* entry okay as is */
51826 case FSCACHE_CHECKAUX_OKAY:
51827- fscache_stat(&fscache_n_checkaux_okay);
51828+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
51829 break;
51830
51831 /* entry requires update */
51832 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
51833- fscache_stat(&fscache_n_checkaux_update);
51834+ fscache_stat_unchecked(&fscache_n_checkaux_update);
51835 break;
51836
51837 /* entry requires deletion */
51838 case FSCACHE_CHECKAUX_OBSOLETE:
51839- fscache_stat(&fscache_n_checkaux_obsolete);
51840+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
51841 break;
51842
51843 default:
51844diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
51845index 762a9ec..2023284 100644
51846--- a/fs/fscache/operation.c
51847+++ b/fs/fscache/operation.c
51848@@ -17,7 +17,7 @@
51849 #include <linux/slab.h>
51850 #include "internal.h"
51851
51852-atomic_t fscache_op_debug_id;
51853+atomic_unchecked_t fscache_op_debug_id;
51854 EXPORT_SYMBOL(fscache_op_debug_id);
51855
51856 /**
51857@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
51858 ASSERTCMP(atomic_read(&op->usage), >, 0);
51859 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
51860
51861- fscache_stat(&fscache_n_op_enqueue);
51862+ fscache_stat_unchecked(&fscache_n_op_enqueue);
51863 switch (op->flags & FSCACHE_OP_TYPE) {
51864 case FSCACHE_OP_ASYNC:
51865 _debug("queue async");
51866@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
51867 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
51868 if (op->processor)
51869 fscache_enqueue_operation(op);
51870- fscache_stat(&fscache_n_op_run);
51871+ fscache_stat_unchecked(&fscache_n_op_run);
51872 }
51873
51874 /*
51875@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
51876 if (object->n_in_progress > 0) {
51877 atomic_inc(&op->usage);
51878 list_add_tail(&op->pend_link, &object->pending_ops);
51879- fscache_stat(&fscache_n_op_pend);
51880+ fscache_stat_unchecked(&fscache_n_op_pend);
51881 } else if (!list_empty(&object->pending_ops)) {
51882 atomic_inc(&op->usage);
51883 list_add_tail(&op->pend_link, &object->pending_ops);
51884- fscache_stat(&fscache_n_op_pend);
51885+ fscache_stat_unchecked(&fscache_n_op_pend);
51886 fscache_start_operations(object);
51887 } else {
51888 ASSERTCMP(object->n_in_progress, ==, 0);
51889@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
51890 object->n_exclusive++; /* reads and writes must wait */
51891 atomic_inc(&op->usage);
51892 list_add_tail(&op->pend_link, &object->pending_ops);
51893- fscache_stat(&fscache_n_op_pend);
51894+ fscache_stat_unchecked(&fscache_n_op_pend);
51895 ret = 0;
51896 } else {
51897 /* If we're in any other state, there must have been an I/O
51898@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
51899 if (object->n_exclusive > 0) {
51900 atomic_inc(&op->usage);
51901 list_add_tail(&op->pend_link, &object->pending_ops);
51902- fscache_stat(&fscache_n_op_pend);
51903+ fscache_stat_unchecked(&fscache_n_op_pend);
51904 } else if (!list_empty(&object->pending_ops)) {
51905 atomic_inc(&op->usage);
51906 list_add_tail(&op->pend_link, &object->pending_ops);
51907- fscache_stat(&fscache_n_op_pend);
51908+ fscache_stat_unchecked(&fscache_n_op_pend);
51909 fscache_start_operations(object);
51910 } else {
51911 ASSERTCMP(object->n_exclusive, ==, 0);
51912@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
51913 object->n_ops++;
51914 atomic_inc(&op->usage);
51915 list_add_tail(&op->pend_link, &object->pending_ops);
51916- fscache_stat(&fscache_n_op_pend);
51917+ fscache_stat_unchecked(&fscache_n_op_pend);
51918 ret = 0;
51919 } else if (object->state == FSCACHE_OBJECT_DYING ||
51920 object->state == FSCACHE_OBJECT_LC_DYING ||
51921 object->state == FSCACHE_OBJECT_WITHDRAWING) {
51922- fscache_stat(&fscache_n_op_rejected);
51923+ fscache_stat_unchecked(&fscache_n_op_rejected);
51924 op->state = FSCACHE_OP_ST_CANCELLED;
51925 ret = -ENOBUFS;
51926 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
51927@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
51928 ret = -EBUSY;
51929 if (op->state == FSCACHE_OP_ST_PENDING) {
51930 ASSERT(!list_empty(&op->pend_link));
51931- fscache_stat(&fscache_n_op_cancelled);
51932+ fscache_stat_unchecked(&fscache_n_op_cancelled);
51933 list_del_init(&op->pend_link);
51934 if (do_cancel)
51935 do_cancel(op);
51936@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
51937 while (!list_empty(&object->pending_ops)) {
51938 op = list_entry(object->pending_ops.next,
51939 struct fscache_operation, pend_link);
51940- fscache_stat(&fscache_n_op_cancelled);
51941+ fscache_stat_unchecked(&fscache_n_op_cancelled);
51942 list_del_init(&op->pend_link);
51943
51944 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
51945@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
51946 op->state, ==, FSCACHE_OP_ST_CANCELLED);
51947 op->state = FSCACHE_OP_ST_DEAD;
51948
51949- fscache_stat(&fscache_n_op_release);
51950+ fscache_stat_unchecked(&fscache_n_op_release);
51951
51952 if (op->release) {
51953 op->release(op);
51954@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
51955 * lock, and defer it otherwise */
51956 if (!spin_trylock(&object->lock)) {
51957 _debug("defer put");
51958- fscache_stat(&fscache_n_op_deferred_release);
51959+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
51960
51961 cache = object->cache;
51962 spin_lock(&cache->op_gc_list_lock);
51963@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
51964
51965 _debug("GC DEFERRED REL OBJ%x OP%x",
51966 object->debug_id, op->debug_id);
51967- fscache_stat(&fscache_n_op_gc);
51968+ fscache_stat_unchecked(&fscache_n_op_gc);
51969
51970 ASSERTCMP(atomic_read(&op->usage), ==, 0);
51971 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
51972diff --git a/fs/fscache/page.c b/fs/fscache/page.c
51973index ff000e5..c44ec6d 100644
51974--- a/fs/fscache/page.c
51975+++ b/fs/fscache/page.c
51976@@ -61,7 +61,7 @@ try_again:
51977 val = radix_tree_lookup(&cookie->stores, page->index);
51978 if (!val) {
51979 rcu_read_unlock();
51980- fscache_stat(&fscache_n_store_vmscan_not_storing);
51981+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
51982 __fscache_uncache_page(cookie, page);
51983 return true;
51984 }
51985@@ -91,11 +91,11 @@ try_again:
51986 spin_unlock(&cookie->stores_lock);
51987
51988 if (xpage) {
51989- fscache_stat(&fscache_n_store_vmscan_cancelled);
51990- fscache_stat(&fscache_n_store_radix_deletes);
51991+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
51992+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
51993 ASSERTCMP(xpage, ==, page);
51994 } else {
51995- fscache_stat(&fscache_n_store_vmscan_gone);
51996+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
51997 }
51998
51999 wake_up_bit(&cookie->flags, 0);
52000@@ -110,11 +110,11 @@ page_busy:
52001 * sleeping on memory allocation, so we may need to impose a timeout
52002 * too. */
52003 if (!(gfp & __GFP_WAIT)) {
52004- fscache_stat(&fscache_n_store_vmscan_busy);
52005+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
52006 return false;
52007 }
52008
52009- fscache_stat(&fscache_n_store_vmscan_wait);
52010+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
52011 __fscache_wait_on_page_write(cookie, page);
52012 gfp &= ~__GFP_WAIT;
52013 goto try_again;
52014@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
52015 FSCACHE_COOKIE_STORING_TAG);
52016 if (!radix_tree_tag_get(&cookie->stores, page->index,
52017 FSCACHE_COOKIE_PENDING_TAG)) {
52018- fscache_stat(&fscache_n_store_radix_deletes);
52019+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
52020 xpage = radix_tree_delete(&cookie->stores, page->index);
52021 }
52022 spin_unlock(&cookie->stores_lock);
52023@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
52024
52025 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
52026
52027- fscache_stat(&fscache_n_attr_changed_calls);
52028+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
52029
52030 if (fscache_object_is_active(object)) {
52031 fscache_stat(&fscache_n_cop_attr_changed);
52032@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52033
52034 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52035
52036- fscache_stat(&fscache_n_attr_changed);
52037+ fscache_stat_unchecked(&fscache_n_attr_changed);
52038
52039 op = kzalloc(sizeof(*op), GFP_KERNEL);
52040 if (!op) {
52041- fscache_stat(&fscache_n_attr_changed_nomem);
52042+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
52043 _leave(" = -ENOMEM");
52044 return -ENOMEM;
52045 }
52046@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52047 if (fscache_submit_exclusive_op(object, op) < 0)
52048 goto nobufs;
52049 spin_unlock(&cookie->lock);
52050- fscache_stat(&fscache_n_attr_changed_ok);
52051+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
52052 fscache_put_operation(op);
52053 _leave(" = 0");
52054 return 0;
52055@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52056 nobufs:
52057 spin_unlock(&cookie->lock);
52058 kfree(op);
52059- fscache_stat(&fscache_n_attr_changed_nobufs);
52060+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
52061 _leave(" = %d", -ENOBUFS);
52062 return -ENOBUFS;
52063 }
52064@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
52065 /* allocate a retrieval operation and attempt to submit it */
52066 op = kzalloc(sizeof(*op), GFP_NOIO);
52067 if (!op) {
52068- fscache_stat(&fscache_n_retrievals_nomem);
52069+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52070 return NULL;
52071 }
52072
52073@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
52074 return 0;
52075 }
52076
52077- fscache_stat(&fscache_n_retrievals_wait);
52078+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
52079
52080 jif = jiffies;
52081 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
52082 fscache_wait_bit_interruptible,
52083 TASK_INTERRUPTIBLE) != 0) {
52084- fscache_stat(&fscache_n_retrievals_intr);
52085+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52086 _leave(" = -ERESTARTSYS");
52087 return -ERESTARTSYS;
52088 }
52089@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
52090 */
52091 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52092 struct fscache_retrieval *op,
52093- atomic_t *stat_op_waits,
52094- atomic_t *stat_object_dead)
52095+ atomic_unchecked_t *stat_op_waits,
52096+ atomic_unchecked_t *stat_object_dead)
52097 {
52098 int ret;
52099
52100@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52101 goto check_if_dead;
52102
52103 _debug(">>> WT");
52104- fscache_stat(stat_op_waits);
52105+ fscache_stat_unchecked(stat_op_waits);
52106 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
52107 fscache_wait_bit_interruptible,
52108 TASK_INTERRUPTIBLE) != 0) {
52109@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52110
52111 check_if_dead:
52112 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
52113- fscache_stat(stat_object_dead);
52114+ fscache_stat_unchecked(stat_object_dead);
52115 _leave(" = -ENOBUFS [cancelled]");
52116 return -ENOBUFS;
52117 }
52118 if (unlikely(fscache_object_is_dead(object))) {
52119 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
52120 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
52121- fscache_stat(stat_object_dead);
52122+ fscache_stat_unchecked(stat_object_dead);
52123 return -ENOBUFS;
52124 }
52125 return 0;
52126@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52127
52128 _enter("%p,%p,,,", cookie, page);
52129
52130- fscache_stat(&fscache_n_retrievals);
52131+ fscache_stat_unchecked(&fscache_n_retrievals);
52132
52133 if (hlist_empty(&cookie->backing_objects))
52134 goto nobufs;
52135@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52136 goto nobufs_unlock_dec;
52137 spin_unlock(&cookie->lock);
52138
52139- fscache_stat(&fscache_n_retrieval_ops);
52140+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52141
52142 /* pin the netfs read context in case we need to do the actual netfs
52143 * read because we've encountered a cache read failure */
52144@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52145
52146 error:
52147 if (ret == -ENOMEM)
52148- fscache_stat(&fscache_n_retrievals_nomem);
52149+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52150 else if (ret == -ERESTARTSYS)
52151- fscache_stat(&fscache_n_retrievals_intr);
52152+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52153 else if (ret == -ENODATA)
52154- fscache_stat(&fscache_n_retrievals_nodata);
52155+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52156 else if (ret < 0)
52157- fscache_stat(&fscache_n_retrievals_nobufs);
52158+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52159 else
52160- fscache_stat(&fscache_n_retrievals_ok);
52161+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52162
52163 fscache_put_retrieval(op);
52164 _leave(" = %d", ret);
52165@@ -467,7 +467,7 @@ nobufs_unlock:
52166 spin_unlock(&cookie->lock);
52167 kfree(op);
52168 nobufs:
52169- fscache_stat(&fscache_n_retrievals_nobufs);
52170+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52171 _leave(" = -ENOBUFS");
52172 return -ENOBUFS;
52173 }
52174@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52175
52176 _enter("%p,,%d,,,", cookie, *nr_pages);
52177
52178- fscache_stat(&fscache_n_retrievals);
52179+ fscache_stat_unchecked(&fscache_n_retrievals);
52180
52181 if (hlist_empty(&cookie->backing_objects))
52182 goto nobufs;
52183@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52184 goto nobufs_unlock_dec;
52185 spin_unlock(&cookie->lock);
52186
52187- fscache_stat(&fscache_n_retrieval_ops);
52188+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52189
52190 /* pin the netfs read context in case we need to do the actual netfs
52191 * read because we've encountered a cache read failure */
52192@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52193
52194 error:
52195 if (ret == -ENOMEM)
52196- fscache_stat(&fscache_n_retrievals_nomem);
52197+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52198 else if (ret == -ERESTARTSYS)
52199- fscache_stat(&fscache_n_retrievals_intr);
52200+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52201 else if (ret == -ENODATA)
52202- fscache_stat(&fscache_n_retrievals_nodata);
52203+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52204 else if (ret < 0)
52205- fscache_stat(&fscache_n_retrievals_nobufs);
52206+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52207 else
52208- fscache_stat(&fscache_n_retrievals_ok);
52209+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52210
52211 fscache_put_retrieval(op);
52212 _leave(" = %d", ret);
52213@@ -591,7 +591,7 @@ nobufs_unlock:
52214 spin_unlock(&cookie->lock);
52215 kfree(op);
52216 nobufs:
52217- fscache_stat(&fscache_n_retrievals_nobufs);
52218+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52219 _leave(" = -ENOBUFS");
52220 return -ENOBUFS;
52221 }
52222@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52223
52224 _enter("%p,%p,,,", cookie, page);
52225
52226- fscache_stat(&fscache_n_allocs);
52227+ fscache_stat_unchecked(&fscache_n_allocs);
52228
52229 if (hlist_empty(&cookie->backing_objects))
52230 goto nobufs;
52231@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52232 goto nobufs_unlock;
52233 spin_unlock(&cookie->lock);
52234
52235- fscache_stat(&fscache_n_alloc_ops);
52236+ fscache_stat_unchecked(&fscache_n_alloc_ops);
52237
52238 ret = fscache_wait_for_retrieval_activation(
52239 object, op,
52240@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52241
52242 error:
52243 if (ret == -ERESTARTSYS)
52244- fscache_stat(&fscache_n_allocs_intr);
52245+ fscache_stat_unchecked(&fscache_n_allocs_intr);
52246 else if (ret < 0)
52247- fscache_stat(&fscache_n_allocs_nobufs);
52248+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52249 else
52250- fscache_stat(&fscache_n_allocs_ok);
52251+ fscache_stat_unchecked(&fscache_n_allocs_ok);
52252
52253 fscache_put_retrieval(op);
52254 _leave(" = %d", ret);
52255@@ -677,7 +677,7 @@ nobufs_unlock:
52256 spin_unlock(&cookie->lock);
52257 kfree(op);
52258 nobufs:
52259- fscache_stat(&fscache_n_allocs_nobufs);
52260+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52261 _leave(" = -ENOBUFS");
52262 return -ENOBUFS;
52263 }
52264@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52265
52266 spin_lock(&cookie->stores_lock);
52267
52268- fscache_stat(&fscache_n_store_calls);
52269+ fscache_stat_unchecked(&fscache_n_store_calls);
52270
52271 /* find a page to store */
52272 page = NULL;
52273@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52274 page = results[0];
52275 _debug("gang %d [%lx]", n, page->index);
52276 if (page->index > op->store_limit) {
52277- fscache_stat(&fscache_n_store_pages_over_limit);
52278+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
52279 goto superseded;
52280 }
52281
52282@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52283 spin_unlock(&cookie->stores_lock);
52284 spin_unlock(&object->lock);
52285
52286- fscache_stat(&fscache_n_store_pages);
52287+ fscache_stat_unchecked(&fscache_n_store_pages);
52288 fscache_stat(&fscache_n_cop_write_page);
52289 ret = object->cache->ops->write_page(op, page);
52290 fscache_stat_d(&fscache_n_cop_write_page);
52291@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52292 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52293 ASSERT(PageFsCache(page));
52294
52295- fscache_stat(&fscache_n_stores);
52296+ fscache_stat_unchecked(&fscache_n_stores);
52297
52298 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
52299 _leave(" = -ENOBUFS [invalidating]");
52300@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52301 spin_unlock(&cookie->stores_lock);
52302 spin_unlock(&object->lock);
52303
52304- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
52305+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
52306 op->store_limit = object->store_limit;
52307
52308 if (fscache_submit_op(object, &op->op) < 0)
52309@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52310
52311 spin_unlock(&cookie->lock);
52312 radix_tree_preload_end();
52313- fscache_stat(&fscache_n_store_ops);
52314- fscache_stat(&fscache_n_stores_ok);
52315+ fscache_stat_unchecked(&fscache_n_store_ops);
52316+ fscache_stat_unchecked(&fscache_n_stores_ok);
52317
52318 /* the work queue now carries its own ref on the object */
52319 fscache_put_operation(&op->op);
52320@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52321 return 0;
52322
52323 already_queued:
52324- fscache_stat(&fscache_n_stores_again);
52325+ fscache_stat_unchecked(&fscache_n_stores_again);
52326 already_pending:
52327 spin_unlock(&cookie->stores_lock);
52328 spin_unlock(&object->lock);
52329 spin_unlock(&cookie->lock);
52330 radix_tree_preload_end();
52331 kfree(op);
52332- fscache_stat(&fscache_n_stores_ok);
52333+ fscache_stat_unchecked(&fscache_n_stores_ok);
52334 _leave(" = 0");
52335 return 0;
52336
52337@@ -959,14 +959,14 @@ nobufs:
52338 spin_unlock(&cookie->lock);
52339 radix_tree_preload_end();
52340 kfree(op);
52341- fscache_stat(&fscache_n_stores_nobufs);
52342+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
52343 _leave(" = -ENOBUFS");
52344 return -ENOBUFS;
52345
52346 nomem_free:
52347 kfree(op);
52348 nomem:
52349- fscache_stat(&fscache_n_stores_oom);
52350+ fscache_stat_unchecked(&fscache_n_stores_oom);
52351 _leave(" = -ENOMEM");
52352 return -ENOMEM;
52353 }
52354@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
52355 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52356 ASSERTCMP(page, !=, NULL);
52357
52358- fscache_stat(&fscache_n_uncaches);
52359+ fscache_stat_unchecked(&fscache_n_uncaches);
52360
52361 /* cache withdrawal may beat us to it */
52362 if (!PageFsCache(page))
52363@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
52364 struct fscache_cookie *cookie = op->op.object->cookie;
52365
52366 #ifdef CONFIG_FSCACHE_STATS
52367- atomic_inc(&fscache_n_marks);
52368+ atomic_inc_unchecked(&fscache_n_marks);
52369 #endif
52370
52371 _debug("- mark %p{%lx}", page, page->index);
52372diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
52373index 40d13c7..ddf52b9 100644
52374--- a/fs/fscache/stats.c
52375+++ b/fs/fscache/stats.c
52376@@ -18,99 +18,99 @@
52377 /*
52378 * operation counters
52379 */
52380-atomic_t fscache_n_op_pend;
52381-atomic_t fscache_n_op_run;
52382-atomic_t fscache_n_op_enqueue;
52383-atomic_t fscache_n_op_requeue;
52384-atomic_t fscache_n_op_deferred_release;
52385-atomic_t fscache_n_op_release;
52386-atomic_t fscache_n_op_gc;
52387-atomic_t fscache_n_op_cancelled;
52388-atomic_t fscache_n_op_rejected;
52389+atomic_unchecked_t fscache_n_op_pend;
52390+atomic_unchecked_t fscache_n_op_run;
52391+atomic_unchecked_t fscache_n_op_enqueue;
52392+atomic_unchecked_t fscache_n_op_requeue;
52393+atomic_unchecked_t fscache_n_op_deferred_release;
52394+atomic_unchecked_t fscache_n_op_release;
52395+atomic_unchecked_t fscache_n_op_gc;
52396+atomic_unchecked_t fscache_n_op_cancelled;
52397+atomic_unchecked_t fscache_n_op_rejected;
52398
52399-atomic_t fscache_n_attr_changed;
52400-atomic_t fscache_n_attr_changed_ok;
52401-atomic_t fscache_n_attr_changed_nobufs;
52402-atomic_t fscache_n_attr_changed_nomem;
52403-atomic_t fscache_n_attr_changed_calls;
52404+atomic_unchecked_t fscache_n_attr_changed;
52405+atomic_unchecked_t fscache_n_attr_changed_ok;
52406+atomic_unchecked_t fscache_n_attr_changed_nobufs;
52407+atomic_unchecked_t fscache_n_attr_changed_nomem;
52408+atomic_unchecked_t fscache_n_attr_changed_calls;
52409
52410-atomic_t fscache_n_allocs;
52411-atomic_t fscache_n_allocs_ok;
52412-atomic_t fscache_n_allocs_wait;
52413-atomic_t fscache_n_allocs_nobufs;
52414-atomic_t fscache_n_allocs_intr;
52415-atomic_t fscache_n_allocs_object_dead;
52416-atomic_t fscache_n_alloc_ops;
52417-atomic_t fscache_n_alloc_op_waits;
52418+atomic_unchecked_t fscache_n_allocs;
52419+atomic_unchecked_t fscache_n_allocs_ok;
52420+atomic_unchecked_t fscache_n_allocs_wait;
52421+atomic_unchecked_t fscache_n_allocs_nobufs;
52422+atomic_unchecked_t fscache_n_allocs_intr;
52423+atomic_unchecked_t fscache_n_allocs_object_dead;
52424+atomic_unchecked_t fscache_n_alloc_ops;
52425+atomic_unchecked_t fscache_n_alloc_op_waits;
52426
52427-atomic_t fscache_n_retrievals;
52428-atomic_t fscache_n_retrievals_ok;
52429-atomic_t fscache_n_retrievals_wait;
52430-atomic_t fscache_n_retrievals_nodata;
52431-atomic_t fscache_n_retrievals_nobufs;
52432-atomic_t fscache_n_retrievals_intr;
52433-atomic_t fscache_n_retrievals_nomem;
52434-atomic_t fscache_n_retrievals_object_dead;
52435-atomic_t fscache_n_retrieval_ops;
52436-atomic_t fscache_n_retrieval_op_waits;
52437+atomic_unchecked_t fscache_n_retrievals;
52438+atomic_unchecked_t fscache_n_retrievals_ok;
52439+atomic_unchecked_t fscache_n_retrievals_wait;
52440+atomic_unchecked_t fscache_n_retrievals_nodata;
52441+atomic_unchecked_t fscache_n_retrievals_nobufs;
52442+atomic_unchecked_t fscache_n_retrievals_intr;
52443+atomic_unchecked_t fscache_n_retrievals_nomem;
52444+atomic_unchecked_t fscache_n_retrievals_object_dead;
52445+atomic_unchecked_t fscache_n_retrieval_ops;
52446+atomic_unchecked_t fscache_n_retrieval_op_waits;
52447
52448-atomic_t fscache_n_stores;
52449-atomic_t fscache_n_stores_ok;
52450-atomic_t fscache_n_stores_again;
52451-atomic_t fscache_n_stores_nobufs;
52452-atomic_t fscache_n_stores_oom;
52453-atomic_t fscache_n_store_ops;
52454-atomic_t fscache_n_store_calls;
52455-atomic_t fscache_n_store_pages;
52456-atomic_t fscache_n_store_radix_deletes;
52457-atomic_t fscache_n_store_pages_over_limit;
52458+atomic_unchecked_t fscache_n_stores;
52459+atomic_unchecked_t fscache_n_stores_ok;
52460+atomic_unchecked_t fscache_n_stores_again;
52461+atomic_unchecked_t fscache_n_stores_nobufs;
52462+atomic_unchecked_t fscache_n_stores_oom;
52463+atomic_unchecked_t fscache_n_store_ops;
52464+atomic_unchecked_t fscache_n_store_calls;
52465+atomic_unchecked_t fscache_n_store_pages;
52466+atomic_unchecked_t fscache_n_store_radix_deletes;
52467+atomic_unchecked_t fscache_n_store_pages_over_limit;
52468
52469-atomic_t fscache_n_store_vmscan_not_storing;
52470-atomic_t fscache_n_store_vmscan_gone;
52471-atomic_t fscache_n_store_vmscan_busy;
52472-atomic_t fscache_n_store_vmscan_cancelled;
52473-atomic_t fscache_n_store_vmscan_wait;
52474+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
52475+atomic_unchecked_t fscache_n_store_vmscan_gone;
52476+atomic_unchecked_t fscache_n_store_vmscan_busy;
52477+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
52478+atomic_unchecked_t fscache_n_store_vmscan_wait;
52479
52480-atomic_t fscache_n_marks;
52481-atomic_t fscache_n_uncaches;
52482+atomic_unchecked_t fscache_n_marks;
52483+atomic_unchecked_t fscache_n_uncaches;
52484
52485-atomic_t fscache_n_acquires;
52486-atomic_t fscache_n_acquires_null;
52487-atomic_t fscache_n_acquires_no_cache;
52488-atomic_t fscache_n_acquires_ok;
52489-atomic_t fscache_n_acquires_nobufs;
52490-atomic_t fscache_n_acquires_oom;
52491+atomic_unchecked_t fscache_n_acquires;
52492+atomic_unchecked_t fscache_n_acquires_null;
52493+atomic_unchecked_t fscache_n_acquires_no_cache;
52494+atomic_unchecked_t fscache_n_acquires_ok;
52495+atomic_unchecked_t fscache_n_acquires_nobufs;
52496+atomic_unchecked_t fscache_n_acquires_oom;
52497
52498-atomic_t fscache_n_invalidates;
52499-atomic_t fscache_n_invalidates_run;
52500+atomic_unchecked_t fscache_n_invalidates;
52501+atomic_unchecked_t fscache_n_invalidates_run;
52502
52503-atomic_t fscache_n_updates;
52504-atomic_t fscache_n_updates_null;
52505-atomic_t fscache_n_updates_run;
52506+atomic_unchecked_t fscache_n_updates;
52507+atomic_unchecked_t fscache_n_updates_null;
52508+atomic_unchecked_t fscache_n_updates_run;
52509
52510-atomic_t fscache_n_relinquishes;
52511-atomic_t fscache_n_relinquishes_null;
52512-atomic_t fscache_n_relinquishes_waitcrt;
52513-atomic_t fscache_n_relinquishes_retire;
52514+atomic_unchecked_t fscache_n_relinquishes;
52515+atomic_unchecked_t fscache_n_relinquishes_null;
52516+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
52517+atomic_unchecked_t fscache_n_relinquishes_retire;
52518
52519-atomic_t fscache_n_cookie_index;
52520-atomic_t fscache_n_cookie_data;
52521-atomic_t fscache_n_cookie_special;
52522+atomic_unchecked_t fscache_n_cookie_index;
52523+atomic_unchecked_t fscache_n_cookie_data;
52524+atomic_unchecked_t fscache_n_cookie_special;
52525
52526-atomic_t fscache_n_object_alloc;
52527-atomic_t fscache_n_object_no_alloc;
52528-atomic_t fscache_n_object_lookups;
52529-atomic_t fscache_n_object_lookups_negative;
52530-atomic_t fscache_n_object_lookups_positive;
52531-atomic_t fscache_n_object_lookups_timed_out;
52532-atomic_t fscache_n_object_created;
52533-atomic_t fscache_n_object_avail;
52534-atomic_t fscache_n_object_dead;
52535+atomic_unchecked_t fscache_n_object_alloc;
52536+atomic_unchecked_t fscache_n_object_no_alloc;
52537+atomic_unchecked_t fscache_n_object_lookups;
52538+atomic_unchecked_t fscache_n_object_lookups_negative;
52539+atomic_unchecked_t fscache_n_object_lookups_positive;
52540+atomic_unchecked_t fscache_n_object_lookups_timed_out;
52541+atomic_unchecked_t fscache_n_object_created;
52542+atomic_unchecked_t fscache_n_object_avail;
52543+atomic_unchecked_t fscache_n_object_dead;
52544
52545-atomic_t fscache_n_checkaux_none;
52546-atomic_t fscache_n_checkaux_okay;
52547-atomic_t fscache_n_checkaux_update;
52548-atomic_t fscache_n_checkaux_obsolete;
52549+atomic_unchecked_t fscache_n_checkaux_none;
52550+atomic_unchecked_t fscache_n_checkaux_okay;
52551+atomic_unchecked_t fscache_n_checkaux_update;
52552+atomic_unchecked_t fscache_n_checkaux_obsolete;
52553
52554 atomic_t fscache_n_cop_alloc_object;
52555 atomic_t fscache_n_cop_lookup_object;
52556@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
52557 seq_puts(m, "FS-Cache statistics\n");
52558
52559 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
52560- atomic_read(&fscache_n_cookie_index),
52561- atomic_read(&fscache_n_cookie_data),
52562- atomic_read(&fscache_n_cookie_special));
52563+ atomic_read_unchecked(&fscache_n_cookie_index),
52564+ atomic_read_unchecked(&fscache_n_cookie_data),
52565+ atomic_read_unchecked(&fscache_n_cookie_special));
52566
52567 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
52568- atomic_read(&fscache_n_object_alloc),
52569- atomic_read(&fscache_n_object_no_alloc),
52570- atomic_read(&fscache_n_object_avail),
52571- atomic_read(&fscache_n_object_dead));
52572+ atomic_read_unchecked(&fscache_n_object_alloc),
52573+ atomic_read_unchecked(&fscache_n_object_no_alloc),
52574+ atomic_read_unchecked(&fscache_n_object_avail),
52575+ atomic_read_unchecked(&fscache_n_object_dead));
52576 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
52577- atomic_read(&fscache_n_checkaux_none),
52578- atomic_read(&fscache_n_checkaux_okay),
52579- atomic_read(&fscache_n_checkaux_update),
52580- atomic_read(&fscache_n_checkaux_obsolete));
52581+ atomic_read_unchecked(&fscache_n_checkaux_none),
52582+ atomic_read_unchecked(&fscache_n_checkaux_okay),
52583+ atomic_read_unchecked(&fscache_n_checkaux_update),
52584+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
52585
52586 seq_printf(m, "Pages : mrk=%u unc=%u\n",
52587- atomic_read(&fscache_n_marks),
52588- atomic_read(&fscache_n_uncaches));
52589+ atomic_read_unchecked(&fscache_n_marks),
52590+ atomic_read_unchecked(&fscache_n_uncaches));
52591
52592 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
52593 " oom=%u\n",
52594- atomic_read(&fscache_n_acquires),
52595- atomic_read(&fscache_n_acquires_null),
52596- atomic_read(&fscache_n_acquires_no_cache),
52597- atomic_read(&fscache_n_acquires_ok),
52598- atomic_read(&fscache_n_acquires_nobufs),
52599- atomic_read(&fscache_n_acquires_oom));
52600+ atomic_read_unchecked(&fscache_n_acquires),
52601+ atomic_read_unchecked(&fscache_n_acquires_null),
52602+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
52603+ atomic_read_unchecked(&fscache_n_acquires_ok),
52604+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
52605+ atomic_read_unchecked(&fscache_n_acquires_oom));
52606
52607 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
52608- atomic_read(&fscache_n_object_lookups),
52609- atomic_read(&fscache_n_object_lookups_negative),
52610- atomic_read(&fscache_n_object_lookups_positive),
52611- atomic_read(&fscache_n_object_created),
52612- atomic_read(&fscache_n_object_lookups_timed_out));
52613+ atomic_read_unchecked(&fscache_n_object_lookups),
52614+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
52615+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
52616+ atomic_read_unchecked(&fscache_n_object_created),
52617+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
52618
52619 seq_printf(m, "Invals : n=%u run=%u\n",
52620- atomic_read(&fscache_n_invalidates),
52621- atomic_read(&fscache_n_invalidates_run));
52622+ atomic_read_unchecked(&fscache_n_invalidates),
52623+ atomic_read_unchecked(&fscache_n_invalidates_run));
52624
52625 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
52626- atomic_read(&fscache_n_updates),
52627- atomic_read(&fscache_n_updates_null),
52628- atomic_read(&fscache_n_updates_run));
52629+ atomic_read_unchecked(&fscache_n_updates),
52630+ atomic_read_unchecked(&fscache_n_updates_null),
52631+ atomic_read_unchecked(&fscache_n_updates_run));
52632
52633 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
52634- atomic_read(&fscache_n_relinquishes),
52635- atomic_read(&fscache_n_relinquishes_null),
52636- atomic_read(&fscache_n_relinquishes_waitcrt),
52637- atomic_read(&fscache_n_relinquishes_retire));
52638+ atomic_read_unchecked(&fscache_n_relinquishes),
52639+ atomic_read_unchecked(&fscache_n_relinquishes_null),
52640+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
52641+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
52642
52643 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
52644- atomic_read(&fscache_n_attr_changed),
52645- atomic_read(&fscache_n_attr_changed_ok),
52646- atomic_read(&fscache_n_attr_changed_nobufs),
52647- atomic_read(&fscache_n_attr_changed_nomem),
52648- atomic_read(&fscache_n_attr_changed_calls));
52649+ atomic_read_unchecked(&fscache_n_attr_changed),
52650+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
52651+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
52652+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
52653+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
52654
52655 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
52656- atomic_read(&fscache_n_allocs),
52657- atomic_read(&fscache_n_allocs_ok),
52658- atomic_read(&fscache_n_allocs_wait),
52659- atomic_read(&fscache_n_allocs_nobufs),
52660- atomic_read(&fscache_n_allocs_intr));
52661+ atomic_read_unchecked(&fscache_n_allocs),
52662+ atomic_read_unchecked(&fscache_n_allocs_ok),
52663+ atomic_read_unchecked(&fscache_n_allocs_wait),
52664+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
52665+ atomic_read_unchecked(&fscache_n_allocs_intr));
52666 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
52667- atomic_read(&fscache_n_alloc_ops),
52668- atomic_read(&fscache_n_alloc_op_waits),
52669- atomic_read(&fscache_n_allocs_object_dead));
52670+ atomic_read_unchecked(&fscache_n_alloc_ops),
52671+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
52672+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
52673
52674 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
52675 " int=%u oom=%u\n",
52676- atomic_read(&fscache_n_retrievals),
52677- atomic_read(&fscache_n_retrievals_ok),
52678- atomic_read(&fscache_n_retrievals_wait),
52679- atomic_read(&fscache_n_retrievals_nodata),
52680- atomic_read(&fscache_n_retrievals_nobufs),
52681- atomic_read(&fscache_n_retrievals_intr),
52682- atomic_read(&fscache_n_retrievals_nomem));
52683+ atomic_read_unchecked(&fscache_n_retrievals),
52684+ atomic_read_unchecked(&fscache_n_retrievals_ok),
52685+ atomic_read_unchecked(&fscache_n_retrievals_wait),
52686+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
52687+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
52688+ atomic_read_unchecked(&fscache_n_retrievals_intr),
52689+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
52690 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
52691- atomic_read(&fscache_n_retrieval_ops),
52692- atomic_read(&fscache_n_retrieval_op_waits),
52693- atomic_read(&fscache_n_retrievals_object_dead));
52694+ atomic_read_unchecked(&fscache_n_retrieval_ops),
52695+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
52696+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
52697
52698 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
52699- atomic_read(&fscache_n_stores),
52700- atomic_read(&fscache_n_stores_ok),
52701- atomic_read(&fscache_n_stores_again),
52702- atomic_read(&fscache_n_stores_nobufs),
52703- atomic_read(&fscache_n_stores_oom));
52704+ atomic_read_unchecked(&fscache_n_stores),
52705+ atomic_read_unchecked(&fscache_n_stores_ok),
52706+ atomic_read_unchecked(&fscache_n_stores_again),
52707+ atomic_read_unchecked(&fscache_n_stores_nobufs),
52708+ atomic_read_unchecked(&fscache_n_stores_oom));
52709 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
52710- atomic_read(&fscache_n_store_ops),
52711- atomic_read(&fscache_n_store_calls),
52712- atomic_read(&fscache_n_store_pages),
52713- atomic_read(&fscache_n_store_radix_deletes),
52714- atomic_read(&fscache_n_store_pages_over_limit));
52715+ atomic_read_unchecked(&fscache_n_store_ops),
52716+ atomic_read_unchecked(&fscache_n_store_calls),
52717+ atomic_read_unchecked(&fscache_n_store_pages),
52718+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
52719+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
52720
52721 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
52722- atomic_read(&fscache_n_store_vmscan_not_storing),
52723- atomic_read(&fscache_n_store_vmscan_gone),
52724- atomic_read(&fscache_n_store_vmscan_busy),
52725- atomic_read(&fscache_n_store_vmscan_cancelled),
52726- atomic_read(&fscache_n_store_vmscan_wait));
52727+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
52728+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
52729+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
52730+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
52731+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
52732
52733 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
52734- atomic_read(&fscache_n_op_pend),
52735- atomic_read(&fscache_n_op_run),
52736- atomic_read(&fscache_n_op_enqueue),
52737- atomic_read(&fscache_n_op_cancelled),
52738- atomic_read(&fscache_n_op_rejected));
52739+ atomic_read_unchecked(&fscache_n_op_pend),
52740+ atomic_read_unchecked(&fscache_n_op_run),
52741+ atomic_read_unchecked(&fscache_n_op_enqueue),
52742+ atomic_read_unchecked(&fscache_n_op_cancelled),
52743+ atomic_read_unchecked(&fscache_n_op_rejected));
52744 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
52745- atomic_read(&fscache_n_op_deferred_release),
52746- atomic_read(&fscache_n_op_release),
52747- atomic_read(&fscache_n_op_gc));
52748+ atomic_read_unchecked(&fscache_n_op_deferred_release),
52749+ atomic_read_unchecked(&fscache_n_op_release),
52750+ atomic_read_unchecked(&fscache_n_op_gc));
52751
52752 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
52753 atomic_read(&fscache_n_cop_alloc_object),
52754diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
52755index 6f96a8d..6019bb9 100644
52756--- a/fs/fuse/cuse.c
52757+++ b/fs/fuse/cuse.c
52758@@ -597,10 +597,12 @@ static int __init cuse_init(void)
52759 INIT_LIST_HEAD(&cuse_conntbl[i]);
52760
52761 /* inherit and extend fuse_dev_operations */
52762- cuse_channel_fops = fuse_dev_operations;
52763- cuse_channel_fops.owner = THIS_MODULE;
52764- cuse_channel_fops.open = cuse_channel_open;
52765- cuse_channel_fops.release = cuse_channel_release;
52766+ pax_open_kernel();
52767+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
52768+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
52769+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
52770+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
52771+ pax_close_kernel();
52772
52773 cuse_class = class_create(THIS_MODULE, "cuse");
52774 if (IS_ERR(cuse_class))
52775diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
52776index 11dfa0c..6f64416 100644
52777--- a/fs/fuse/dev.c
52778+++ b/fs/fuse/dev.c
52779@@ -1294,7 +1294,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
52780 ret = 0;
52781 pipe_lock(pipe);
52782
52783- if (!pipe->readers) {
52784+ if (!atomic_read(&pipe->readers)) {
52785 send_sig(SIGPIPE, current, 0);
52786 if (!ret)
52787 ret = -EPIPE;
52788diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
52789index 185c479..51b9986 100644
52790--- a/fs/fuse/dir.c
52791+++ b/fs/fuse/dir.c
52792@@ -1415,7 +1415,7 @@ static char *read_link(struct dentry *dentry)
52793 return link;
52794 }
52795
52796-static void free_link(char *link)
52797+static void free_link(const char *link)
52798 {
52799 if (!IS_ERR(link))
52800 free_page((unsigned long) link);
52801diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
52802index cc00bd1..3edb692 100644
52803--- a/fs/gfs2/inode.c
52804+++ b/fs/gfs2/inode.c
52805@@ -1500,7 +1500,7 @@ out:
52806
52807 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52808 {
52809- char *s = nd_get_link(nd);
52810+ const char *s = nd_get_link(nd);
52811 if (!IS_ERR(s))
52812 kfree(s);
52813 }
52814diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
52815index a3f868a..bb308ae 100644
52816--- a/fs/hugetlbfs/inode.c
52817+++ b/fs/hugetlbfs/inode.c
52818@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
52819 struct mm_struct *mm = current->mm;
52820 struct vm_area_struct *vma;
52821 struct hstate *h = hstate_file(file);
52822+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
52823 struct vm_unmapped_area_info info;
52824
52825 if (len & ~huge_page_mask(h))
52826@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
52827 return addr;
52828 }
52829
52830+#ifdef CONFIG_PAX_RANDMMAP
52831+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
52832+#endif
52833+
52834 if (addr) {
52835 addr = ALIGN(addr, huge_page_size(h));
52836 vma = find_vma(mm, addr);
52837- if (TASK_SIZE - len >= addr &&
52838- (!vma || addr + len <= vma->vm_start))
52839+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
52840 return addr;
52841 }
52842
52843 info.flags = 0;
52844 info.length = len;
52845 info.low_limit = TASK_UNMAPPED_BASE;
52846+
52847+#ifdef CONFIG_PAX_RANDMMAP
52848+ if (mm->pax_flags & MF_PAX_RANDMMAP)
52849+ info.low_limit += mm->delta_mmap;
52850+#endif
52851+
52852 info.high_limit = TASK_SIZE;
52853 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
52854 info.align_offset = 0;
52855@@ -898,7 +908,7 @@ static struct file_system_type hugetlbfs_fs_type = {
52856 };
52857 MODULE_ALIAS_FS("hugetlbfs");
52858
52859-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
52860+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
52861
52862 static int can_do_hugetlb_shm(void)
52863 {
52864diff --git a/fs/inode.c b/fs/inode.c
52865index a898b3d..9b5a214 100644
52866--- a/fs/inode.c
52867+++ b/fs/inode.c
52868@@ -878,8 +878,8 @@ unsigned int get_next_ino(void)
52869
52870 #ifdef CONFIG_SMP
52871 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
52872- static atomic_t shared_last_ino;
52873- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
52874+ static atomic_unchecked_t shared_last_ino;
52875+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
52876
52877 res = next - LAST_INO_BATCH;
52878 }
52879diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
52880index 4a6cf28..d3a29d3 100644
52881--- a/fs/jffs2/erase.c
52882+++ b/fs/jffs2/erase.c
52883@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
52884 struct jffs2_unknown_node marker = {
52885 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
52886 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
52887- .totlen = cpu_to_je32(c->cleanmarker_size)
52888+ .totlen = cpu_to_je32(c->cleanmarker_size),
52889+ .hdr_crc = cpu_to_je32(0)
52890 };
52891
52892 jffs2_prealloc_raw_node_refs(c, jeb, 1);
52893diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
52894index a6597d6..41b30ec 100644
52895--- a/fs/jffs2/wbuf.c
52896+++ b/fs/jffs2/wbuf.c
52897@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
52898 {
52899 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
52900 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
52901- .totlen = constant_cpu_to_je32(8)
52902+ .totlen = constant_cpu_to_je32(8),
52903+ .hdr_crc = constant_cpu_to_je32(0)
52904 };
52905
52906 /*
52907diff --git a/fs/jfs/super.c b/fs/jfs/super.c
52908index 2003e83..40db287 100644
52909--- a/fs/jfs/super.c
52910+++ b/fs/jfs/super.c
52911@@ -856,7 +856,7 @@ static int __init init_jfs_fs(void)
52912
52913 jfs_inode_cachep =
52914 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
52915- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
52916+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
52917 init_once);
52918 if (jfs_inode_cachep == NULL)
52919 return -ENOMEM;
52920diff --git a/fs/libfs.c b/fs/libfs.c
52921index 916da8c..1588998 100644
52922--- a/fs/libfs.c
52923+++ b/fs/libfs.c
52924@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
52925
52926 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
52927 struct dentry *next;
52928+ char d_name[sizeof(next->d_iname)];
52929+ const unsigned char *name;
52930+
52931 next = list_entry(p, struct dentry, d_u.d_child);
52932 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
52933 if (!simple_positive(next)) {
52934@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
52935
52936 spin_unlock(&next->d_lock);
52937 spin_unlock(&dentry->d_lock);
52938- if (filldir(dirent, next->d_name.name,
52939+ name = next->d_name.name;
52940+ if (name == next->d_iname) {
52941+ memcpy(d_name, name, next->d_name.len);
52942+ name = d_name;
52943+ }
52944+ if (filldir(dirent, name,
52945 next->d_name.len, filp->f_pos,
52946 next->d_inode->i_ino,
52947 dt_type(next->d_inode)) < 0)
52948diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
52949index 9760ecb..9b838ef 100644
52950--- a/fs/lockd/clntproc.c
52951+++ b/fs/lockd/clntproc.c
52952@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
52953 /*
52954 * Cookie counter for NLM requests
52955 */
52956-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
52957+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
52958
52959 void nlmclnt_next_cookie(struct nlm_cookie *c)
52960 {
52961- u32 cookie = atomic_inc_return(&nlm_cookie);
52962+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
52963
52964 memcpy(c->data, &cookie, 4);
52965 c->len=4;
52966diff --git a/fs/locks.c b/fs/locks.c
52967index cb424a4..850e4dd 100644
52968--- a/fs/locks.c
52969+++ b/fs/locks.c
52970@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
52971 return;
52972
52973 if (filp->f_op && filp->f_op->flock) {
52974- struct file_lock fl = {
52975+ struct file_lock flock = {
52976 .fl_pid = current->tgid,
52977 .fl_file = filp,
52978 .fl_flags = FL_FLOCK,
52979 .fl_type = F_UNLCK,
52980 .fl_end = OFFSET_MAX,
52981 };
52982- filp->f_op->flock(filp, F_SETLKW, &fl);
52983- if (fl.fl_ops && fl.fl_ops->fl_release_private)
52984- fl.fl_ops->fl_release_private(&fl);
52985+ filp->f_op->flock(filp, F_SETLKW, &flock);
52986+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
52987+ flock.fl_ops->fl_release_private(&flock);
52988 }
52989
52990 lock_flocks();
52991diff --git a/fs/namei.c b/fs/namei.c
52992index 85e40d1..b66744e 100644
52993--- a/fs/namei.c
52994+++ b/fs/namei.c
52995@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
52996 if (ret != -EACCES)
52997 return ret;
52998
52999+#ifdef CONFIG_GRKERNSEC
53000+ /* we'll block if we have to log due to a denied capability use */
53001+ if (mask & MAY_NOT_BLOCK)
53002+ return -ECHILD;
53003+#endif
53004+
53005 if (S_ISDIR(inode->i_mode)) {
53006 /* DACs are overridable for directories */
53007- if (inode_capable(inode, CAP_DAC_OVERRIDE))
53008- return 0;
53009 if (!(mask & MAY_WRITE))
53010- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
53011+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
53012+ inode_capable(inode, CAP_DAC_READ_SEARCH))
53013 return 0;
53014+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
53015+ return 0;
53016 return -EACCES;
53017 }
53018 /*
53019+ * Searching includes executable on directories, else just read.
53020+ */
53021+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
53022+ if (mask == MAY_READ)
53023+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
53024+ inode_capable(inode, CAP_DAC_READ_SEARCH))
53025+ return 0;
53026+
53027+ /*
53028 * Read/write DACs are always overridable.
53029 * Executable DACs are overridable when there is
53030 * at least one exec bit set.
53031@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
53032 if (inode_capable(inode, CAP_DAC_OVERRIDE))
53033 return 0;
53034
53035- /*
53036- * Searching includes executable on directories, else just read.
53037- */
53038- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
53039- if (mask == MAY_READ)
53040- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
53041- return 0;
53042-
53043 return -EACCES;
53044 }
53045
53046@@ -820,7 +828,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53047 {
53048 struct dentry *dentry = link->dentry;
53049 int error;
53050- char *s;
53051+ const char *s;
53052
53053 BUG_ON(nd->flags & LOOKUP_RCU);
53054
53055@@ -841,6 +849,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53056 if (error)
53057 goto out_put_nd_path;
53058
53059+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
53060+ dentry->d_inode, dentry, nd->path.mnt)) {
53061+ error = -EACCES;
53062+ goto out_put_nd_path;
53063+ }
53064+
53065 nd->last_type = LAST_BIND;
53066 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
53067 error = PTR_ERR(*p);
53068@@ -1588,6 +1602,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
53069 if (res)
53070 break;
53071 res = walk_component(nd, path, LOOKUP_FOLLOW);
53072+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
53073+ res = -EACCES;
53074 put_link(nd, &link, cookie);
53075 } while (res > 0);
53076
53077@@ -1686,7 +1702,7 @@ EXPORT_SYMBOL(full_name_hash);
53078 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
53079 {
53080 unsigned long a, b, adata, bdata, mask, hash, len;
53081- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53082+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53083
53084 hash = a = 0;
53085 len = -sizeof(unsigned long);
53086@@ -1968,6 +1984,8 @@ static int path_lookupat(int dfd, const char *name,
53087 if (err)
53088 break;
53089 err = lookup_last(nd, &path);
53090+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
53091+ err = -EACCES;
53092 put_link(nd, &link, cookie);
53093 }
53094 }
53095@@ -1975,6 +1993,13 @@ static int path_lookupat(int dfd, const char *name,
53096 if (!err)
53097 err = complete_walk(nd);
53098
53099+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
53100+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53101+ path_put(&nd->path);
53102+ err = -ENOENT;
53103+ }
53104+ }
53105+
53106 if (!err && nd->flags & LOOKUP_DIRECTORY) {
53107 if (!nd->inode->i_op->lookup) {
53108 path_put(&nd->path);
53109@@ -2002,8 +2027,15 @@ static int filename_lookup(int dfd, struct filename *name,
53110 retval = path_lookupat(dfd, name->name,
53111 flags | LOOKUP_REVAL, nd);
53112
53113- if (likely(!retval))
53114+ if (likely(!retval)) {
53115 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
53116+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
53117+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
53118+ path_put(&nd->path);
53119+ return -ENOENT;
53120+ }
53121+ }
53122+ }
53123 return retval;
53124 }
53125
53126@@ -2381,6 +2413,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
53127 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
53128 return -EPERM;
53129
53130+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
53131+ return -EPERM;
53132+ if (gr_handle_rawio(inode))
53133+ return -EPERM;
53134+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
53135+ return -EACCES;
53136+
53137 return 0;
53138 }
53139
53140@@ -2602,7 +2641,7 @@ looked_up:
53141 * cleared otherwise prior to returning.
53142 */
53143 static int lookup_open(struct nameidata *nd, struct path *path,
53144- struct file *file,
53145+ struct path *link, struct file *file,
53146 const struct open_flags *op,
53147 bool got_write, int *opened)
53148 {
53149@@ -2637,6 +2676,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53150 /* Negative dentry, just create the file */
53151 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
53152 umode_t mode = op->mode;
53153+
53154+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
53155+ error = -EACCES;
53156+ goto out_dput;
53157+ }
53158+
53159+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
53160+ error = -EACCES;
53161+ goto out_dput;
53162+ }
53163+
53164 if (!IS_POSIXACL(dir->d_inode))
53165 mode &= ~current_umask();
53166 /*
53167@@ -2658,6 +2708,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53168 nd->flags & LOOKUP_EXCL);
53169 if (error)
53170 goto out_dput;
53171+ else
53172+ gr_handle_create(dentry, nd->path.mnt);
53173 }
53174 out_no_open:
53175 path->dentry = dentry;
53176@@ -2672,7 +2724,7 @@ out_dput:
53177 /*
53178 * Handle the last step of open()
53179 */
53180-static int do_last(struct nameidata *nd, struct path *path,
53181+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
53182 struct file *file, const struct open_flags *op,
53183 int *opened, struct filename *name)
53184 {
53185@@ -2701,16 +2753,32 @@ static int do_last(struct nameidata *nd, struct path *path,
53186 error = complete_walk(nd);
53187 if (error)
53188 return error;
53189+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53190+ error = -ENOENT;
53191+ goto out;
53192+ }
53193 audit_inode(name, nd->path.dentry, 0);
53194 if (open_flag & O_CREAT) {
53195 error = -EISDIR;
53196 goto out;
53197 }
53198+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53199+ error = -EACCES;
53200+ goto out;
53201+ }
53202 goto finish_open;
53203 case LAST_BIND:
53204 error = complete_walk(nd);
53205 if (error)
53206 return error;
53207+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
53208+ error = -ENOENT;
53209+ goto out;
53210+ }
53211+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53212+ error = -EACCES;
53213+ goto out;
53214+ }
53215 audit_inode(name, dir, 0);
53216 goto finish_open;
53217 }
53218@@ -2759,7 +2827,7 @@ retry_lookup:
53219 */
53220 }
53221 mutex_lock(&dir->d_inode->i_mutex);
53222- error = lookup_open(nd, path, file, op, got_write, opened);
53223+ error = lookup_open(nd, path, link, file, op, got_write, opened);
53224 mutex_unlock(&dir->d_inode->i_mutex);
53225
53226 if (error <= 0) {
53227@@ -2783,11 +2851,28 @@ retry_lookup:
53228 goto finish_open_created;
53229 }
53230
53231+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
53232+ error = -ENOENT;
53233+ goto exit_dput;
53234+ }
53235+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
53236+ error = -EACCES;
53237+ goto exit_dput;
53238+ }
53239+
53240 /*
53241 * create/update audit record if it already exists.
53242 */
53243- if (path->dentry->d_inode)
53244+ if (path->dentry->d_inode) {
53245+ /* only check if O_CREAT is specified, all other checks need to go
53246+ into may_open */
53247+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
53248+ error = -EACCES;
53249+ goto exit_dput;
53250+ }
53251+
53252 audit_inode(name, path->dentry, 0);
53253+ }
53254
53255 /*
53256 * If atomic_open() acquired write access it is dropped now due to
53257@@ -2828,6 +2913,11 @@ finish_lookup:
53258 }
53259 }
53260 BUG_ON(inode != path->dentry->d_inode);
53261+ /* if we're resolving a symlink to another symlink */
53262+ if (link && gr_handle_symlink_owner(link, inode)) {
53263+ error = -EACCES;
53264+ goto out;
53265+ }
53266 return 1;
53267 }
53268
53269@@ -2837,7 +2927,6 @@ finish_lookup:
53270 save_parent.dentry = nd->path.dentry;
53271 save_parent.mnt = mntget(path->mnt);
53272 nd->path.dentry = path->dentry;
53273-
53274 }
53275 nd->inode = inode;
53276 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
53277@@ -2846,6 +2935,16 @@ finish_lookup:
53278 path_put(&save_parent);
53279 return error;
53280 }
53281+
53282+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53283+ error = -ENOENT;
53284+ goto out;
53285+ }
53286+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53287+ error = -EACCES;
53288+ goto out;
53289+ }
53290+
53291 error = -EISDIR;
53292 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
53293 goto out;
53294@@ -2944,7 +3043,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53295 if (unlikely(error))
53296 goto out;
53297
53298- error = do_last(nd, &path, file, op, &opened, pathname);
53299+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
53300 while (unlikely(error > 0)) { /* trailing symlink */
53301 struct path link = path;
53302 void *cookie;
53303@@ -2962,7 +3061,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53304 error = follow_link(&link, nd, &cookie);
53305 if (unlikely(error))
53306 break;
53307- error = do_last(nd, &path, file, op, &opened, pathname);
53308+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
53309 put_link(nd, &link, cookie);
53310 }
53311 out:
53312@@ -3062,8 +3161,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
53313 goto unlock;
53314
53315 error = -EEXIST;
53316- if (dentry->d_inode)
53317+ if (dentry->d_inode) {
53318+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
53319+ error = -ENOENT;
53320+ }
53321 goto fail;
53322+ }
53323 /*
53324 * Special case - lookup gave negative, but... we had foo/bar/
53325 * From the vfs_mknod() POV we just have a negative dentry -
53326@@ -3115,6 +3218,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
53327 }
53328 EXPORT_SYMBOL(user_path_create);
53329
53330+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
53331+{
53332+ struct filename *tmp = getname(pathname);
53333+ struct dentry *res;
53334+ if (IS_ERR(tmp))
53335+ return ERR_CAST(tmp);
53336+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
53337+ if (IS_ERR(res))
53338+ putname(tmp);
53339+ else
53340+ *to = tmp;
53341+ return res;
53342+}
53343+
53344 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
53345 {
53346 int error = may_create(dir, dentry);
53347@@ -3177,6 +3294,17 @@ retry:
53348
53349 if (!IS_POSIXACL(path.dentry->d_inode))
53350 mode &= ~current_umask();
53351+
53352+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
53353+ error = -EPERM;
53354+ goto out;
53355+ }
53356+
53357+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
53358+ error = -EACCES;
53359+ goto out;
53360+ }
53361+
53362 error = security_path_mknod(&path, dentry, mode, dev);
53363 if (error)
53364 goto out;
53365@@ -3193,6 +3321,8 @@ retry:
53366 break;
53367 }
53368 out:
53369+ if (!error)
53370+ gr_handle_create(dentry, path.mnt);
53371 done_path_create(&path, dentry);
53372 if (retry_estale(error, lookup_flags)) {
53373 lookup_flags |= LOOKUP_REVAL;
53374@@ -3245,9 +3375,16 @@ retry:
53375
53376 if (!IS_POSIXACL(path.dentry->d_inode))
53377 mode &= ~current_umask();
53378+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
53379+ error = -EACCES;
53380+ goto out;
53381+ }
53382 error = security_path_mkdir(&path, dentry, mode);
53383 if (!error)
53384 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
53385+ if (!error)
53386+ gr_handle_create(dentry, path.mnt);
53387+out:
53388 done_path_create(&path, dentry);
53389 if (retry_estale(error, lookup_flags)) {
53390 lookup_flags |= LOOKUP_REVAL;
53391@@ -3328,6 +3465,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
53392 struct filename *name;
53393 struct dentry *dentry;
53394 struct nameidata nd;
53395+ ino_t saved_ino = 0;
53396+ dev_t saved_dev = 0;
53397 unsigned int lookup_flags = 0;
53398 retry:
53399 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
53400@@ -3360,10 +3499,21 @@ retry:
53401 error = -ENOENT;
53402 goto exit3;
53403 }
53404+
53405+ saved_ino = dentry->d_inode->i_ino;
53406+ saved_dev = gr_get_dev_from_dentry(dentry);
53407+
53408+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
53409+ error = -EACCES;
53410+ goto exit3;
53411+ }
53412+
53413 error = security_path_rmdir(&nd.path, dentry);
53414 if (error)
53415 goto exit3;
53416 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
53417+ if (!error && (saved_dev || saved_ino))
53418+ gr_handle_delete(saved_ino, saved_dev);
53419 exit3:
53420 dput(dentry);
53421 exit2:
53422@@ -3429,6 +3579,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
53423 struct dentry *dentry;
53424 struct nameidata nd;
53425 struct inode *inode = NULL;
53426+ ino_t saved_ino = 0;
53427+ dev_t saved_dev = 0;
53428 unsigned int lookup_flags = 0;
53429 retry:
53430 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
53431@@ -3455,10 +3607,22 @@ retry:
53432 if (!inode)
53433 goto slashes;
53434 ihold(inode);
53435+
53436+ if (inode->i_nlink <= 1) {
53437+ saved_ino = inode->i_ino;
53438+ saved_dev = gr_get_dev_from_dentry(dentry);
53439+ }
53440+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
53441+ error = -EACCES;
53442+ goto exit2;
53443+ }
53444+
53445 error = security_path_unlink(&nd.path, dentry);
53446 if (error)
53447 goto exit2;
53448 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
53449+ if (!error && (saved_ino || saved_dev))
53450+ gr_handle_delete(saved_ino, saved_dev);
53451 exit2:
53452 dput(dentry);
53453 }
53454@@ -3536,9 +3700,17 @@ retry:
53455 if (IS_ERR(dentry))
53456 goto out_putname;
53457
53458+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
53459+ error = -EACCES;
53460+ goto out;
53461+ }
53462+
53463 error = security_path_symlink(&path, dentry, from->name);
53464 if (!error)
53465 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
53466+ if (!error)
53467+ gr_handle_create(dentry, path.mnt);
53468+out:
53469 done_path_create(&path, dentry);
53470 if (retry_estale(error, lookup_flags)) {
53471 lookup_flags |= LOOKUP_REVAL;
53472@@ -3612,6 +3784,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
53473 {
53474 struct dentry *new_dentry;
53475 struct path old_path, new_path;
53476+ struct filename *to = NULL;
53477 int how = 0;
53478 int error;
53479
53480@@ -3635,7 +3808,7 @@ retry:
53481 if (error)
53482 return error;
53483
53484- new_dentry = user_path_create(newdfd, newname, &new_path,
53485+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
53486 (how & LOOKUP_REVAL));
53487 error = PTR_ERR(new_dentry);
53488 if (IS_ERR(new_dentry))
53489@@ -3647,11 +3820,28 @@ retry:
53490 error = may_linkat(&old_path);
53491 if (unlikely(error))
53492 goto out_dput;
53493+
53494+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
53495+ old_path.dentry->d_inode,
53496+ old_path.dentry->d_inode->i_mode, to)) {
53497+ error = -EACCES;
53498+ goto out_dput;
53499+ }
53500+
53501+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
53502+ old_path.dentry, old_path.mnt, to)) {
53503+ error = -EACCES;
53504+ goto out_dput;
53505+ }
53506+
53507 error = security_path_link(old_path.dentry, &new_path, new_dentry);
53508 if (error)
53509 goto out_dput;
53510 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
53511+ if (!error)
53512+ gr_handle_create(new_dentry, new_path.mnt);
53513 out_dput:
53514+ putname(to);
53515 done_path_create(&new_path, new_dentry);
53516 if (retry_estale(error, how)) {
53517 how |= LOOKUP_REVAL;
53518@@ -3897,12 +4087,21 @@ retry:
53519 if (new_dentry == trap)
53520 goto exit5;
53521
53522+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
53523+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
53524+ to);
53525+ if (error)
53526+ goto exit5;
53527+
53528 error = security_path_rename(&oldnd.path, old_dentry,
53529 &newnd.path, new_dentry);
53530 if (error)
53531 goto exit5;
53532 error = vfs_rename(old_dir->d_inode, old_dentry,
53533 new_dir->d_inode, new_dentry);
53534+ if (!error)
53535+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
53536+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
53537 exit5:
53538 dput(new_dentry);
53539 exit4:
53540@@ -3934,6 +4133,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
53541
53542 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
53543 {
53544+ char tmpbuf[64];
53545+ const char *newlink;
53546 int len;
53547
53548 len = PTR_ERR(link);
53549@@ -3943,7 +4144,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
53550 len = strlen(link);
53551 if (len > (unsigned) buflen)
53552 len = buflen;
53553- if (copy_to_user(buffer, link, len))
53554+
53555+ if (len < sizeof(tmpbuf)) {
53556+ memcpy(tmpbuf, link, len);
53557+ newlink = tmpbuf;
53558+ } else
53559+ newlink = link;
53560+
53561+ if (copy_to_user(buffer, newlink, len))
53562 len = -EFAULT;
53563 out:
53564 return len;
53565diff --git a/fs/namespace.c b/fs/namespace.c
53566index e945b81..fc018e2 100644
53567--- a/fs/namespace.c
53568+++ b/fs/namespace.c
53569@@ -1219,6 +1219,9 @@ static int do_umount(struct mount *mnt, int flags)
53570 if (!(sb->s_flags & MS_RDONLY))
53571 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
53572 up_write(&sb->s_umount);
53573+
53574+ gr_log_remount(mnt->mnt_devname, retval);
53575+
53576 return retval;
53577 }
53578
53579@@ -1238,6 +1241,9 @@ static int do_umount(struct mount *mnt, int flags)
53580 br_write_unlock(&vfsmount_lock);
53581 up_write(&namespace_sem);
53582 release_mounts(&umount_list);
53583+
53584+ gr_log_unmount(mnt->mnt_devname, retval);
53585+
53586 return retval;
53587 }
53588
53589@@ -1257,7 +1263,7 @@ static inline bool may_mount(void)
53590 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
53591 */
53592
53593-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
53594+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
53595 {
53596 struct path path;
53597 struct mount *mnt;
53598@@ -1297,7 +1303,7 @@ out:
53599 /*
53600 * The 2.0 compatible umount. No flags.
53601 */
53602-SYSCALL_DEFINE1(oldumount, char __user *, name)
53603+SYSCALL_DEFINE1(oldumount, const char __user *, name)
53604 {
53605 return sys_umount(name, 0);
53606 }
53607@@ -2267,6 +2273,16 @@ long do_mount(const char *dev_name, const char *dir_name,
53608 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
53609 MS_STRICTATIME);
53610
53611+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
53612+ retval = -EPERM;
53613+ goto dput_out;
53614+ }
53615+
53616+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
53617+ retval = -EPERM;
53618+ goto dput_out;
53619+ }
53620+
53621 if (flags & MS_REMOUNT)
53622 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
53623 data_page);
53624@@ -2281,6 +2297,9 @@ long do_mount(const char *dev_name, const char *dir_name,
53625 dev_name, data_page);
53626 dput_out:
53627 path_put(&path);
53628+
53629+ gr_log_mount(dev_name, dir_name, retval);
53630+
53631 return retval;
53632 }
53633
53634@@ -2454,8 +2473,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
53635 }
53636 EXPORT_SYMBOL(mount_subtree);
53637
53638-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
53639- char __user *, type, unsigned long, flags, void __user *, data)
53640+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
53641+ const char __user *, type, unsigned long, flags, void __user *, data)
53642 {
53643 int ret;
53644 char *kernel_type;
53645@@ -2567,6 +2586,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
53646 if (error)
53647 goto out2;
53648
53649+ if (gr_handle_chroot_pivot()) {
53650+ error = -EPERM;
53651+ goto out2;
53652+ }
53653+
53654 get_fs_root(current->fs, &root);
53655 error = lock_mount(&old);
53656 if (error)
53657@@ -2815,7 +2839,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
53658 !nsown_capable(CAP_SYS_ADMIN))
53659 return -EPERM;
53660
53661- if (fs->users != 1)
53662+ if (atomic_read(&fs->users) != 1)
53663 return -EINVAL;
53664
53665 get_mnt_ns(mnt_ns);
53666diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
53667index 59461c9..b17c57e 100644
53668--- a/fs/nfs/callback_xdr.c
53669+++ b/fs/nfs/callback_xdr.c
53670@@ -51,7 +51,7 @@ struct callback_op {
53671 callback_decode_arg_t decode_args;
53672 callback_encode_res_t encode_res;
53673 long res_maxsize;
53674-};
53675+} __do_const;
53676
53677 static struct callback_op callback_ops[];
53678
53679diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
53680index 1f94167..79c4ce4 100644
53681--- a/fs/nfs/inode.c
53682+++ b/fs/nfs/inode.c
53683@@ -1041,16 +1041,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
53684 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
53685 }
53686
53687-static atomic_long_t nfs_attr_generation_counter;
53688+static atomic_long_unchecked_t nfs_attr_generation_counter;
53689
53690 static unsigned long nfs_read_attr_generation_counter(void)
53691 {
53692- return atomic_long_read(&nfs_attr_generation_counter);
53693+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
53694 }
53695
53696 unsigned long nfs_inc_attr_generation_counter(void)
53697 {
53698- return atomic_long_inc_return(&nfs_attr_generation_counter);
53699+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
53700 }
53701
53702 void nfs_fattr_init(struct nfs_fattr *fattr)
53703diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
53704index d401d01..10b3e62 100644
53705--- a/fs/nfsd/nfs4proc.c
53706+++ b/fs/nfsd/nfs4proc.c
53707@@ -1109,7 +1109,7 @@ struct nfsd4_operation {
53708 nfsd4op_rsize op_rsize_bop;
53709 stateid_getter op_get_currentstateid;
53710 stateid_setter op_set_currentstateid;
53711-};
53712+} __do_const;
53713
53714 static struct nfsd4_operation nfsd4_ops[];
53715
53716diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
53717index 6eb0dc5..29067a9 100644
53718--- a/fs/nfsd/nfs4xdr.c
53719+++ b/fs/nfsd/nfs4xdr.c
53720@@ -1457,7 +1457,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
53721
53722 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
53723
53724-static nfsd4_dec nfsd4_dec_ops[] = {
53725+static const nfsd4_dec nfsd4_dec_ops[] = {
53726 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
53727 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
53728 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
53729@@ -1497,7 +1497,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
53730 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
53731 };
53732
53733-static nfsd4_dec nfsd41_dec_ops[] = {
53734+static const nfsd4_dec nfsd41_dec_ops[] = {
53735 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
53736 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
53737 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
53738@@ -1559,7 +1559,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
53739 };
53740
53741 struct nfsd4_minorversion_ops {
53742- nfsd4_dec *decoders;
53743+ const nfsd4_dec *decoders;
53744 int nops;
53745 };
53746
53747diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
53748index ca05f6d..411a576 100644
53749--- a/fs/nfsd/nfscache.c
53750+++ b/fs/nfsd/nfscache.c
53751@@ -461,13 +461,15 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
53752 {
53753 struct svc_cacherep *rp = rqstp->rq_cacherep;
53754 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
53755- int len;
53756+ long len;
53757
53758 if (!rp)
53759 return;
53760
53761- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
53762- len >>= 2;
53763+ if (statp) {
53764+ len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
53765+ len >>= 2;
53766+ }
53767
53768 /* Don't cache excessive amounts of data and XDR failures */
53769 if (!statp || len > (256 >> 2)) {
53770diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
53771index 2b2e239..c915b48 100644
53772--- a/fs/nfsd/vfs.c
53773+++ b/fs/nfsd/vfs.c
53774@@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
53775 } else {
53776 oldfs = get_fs();
53777 set_fs(KERNEL_DS);
53778- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
53779+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
53780 set_fs(oldfs);
53781 }
53782
53783@@ -1026,7 +1026,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
53784
53785 /* Write the data. */
53786 oldfs = get_fs(); set_fs(KERNEL_DS);
53787- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
53788+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
53789 set_fs(oldfs);
53790 if (host_err < 0)
53791 goto out_nfserr;
53792@@ -1572,7 +1572,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
53793 */
53794
53795 oldfs = get_fs(); set_fs(KERNEL_DS);
53796- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
53797+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
53798 set_fs(oldfs);
53799
53800 if (host_err < 0)
53801diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
53802index fea6bd5..8ee9d81 100644
53803--- a/fs/nls/nls_base.c
53804+++ b/fs/nls/nls_base.c
53805@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
53806
53807 int register_nls(struct nls_table * nls)
53808 {
53809- struct nls_table ** tmp = &tables;
53810+ struct nls_table *tmp = tables;
53811
53812 if (nls->next)
53813 return -EBUSY;
53814
53815 spin_lock(&nls_lock);
53816- while (*tmp) {
53817- if (nls == *tmp) {
53818+ while (tmp) {
53819+ if (nls == tmp) {
53820 spin_unlock(&nls_lock);
53821 return -EBUSY;
53822 }
53823- tmp = &(*tmp)->next;
53824+ tmp = tmp->next;
53825 }
53826- nls->next = tables;
53827+ pax_open_kernel();
53828+ *(struct nls_table **)&nls->next = tables;
53829+ pax_close_kernel();
53830 tables = nls;
53831 spin_unlock(&nls_lock);
53832 return 0;
53833@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
53834
53835 int unregister_nls(struct nls_table * nls)
53836 {
53837- struct nls_table ** tmp = &tables;
53838+ struct nls_table * const * tmp = &tables;
53839
53840 spin_lock(&nls_lock);
53841 while (*tmp) {
53842 if (nls == *tmp) {
53843- *tmp = nls->next;
53844+ pax_open_kernel();
53845+ *(struct nls_table **)tmp = nls->next;
53846+ pax_close_kernel();
53847 spin_unlock(&nls_lock);
53848 return 0;
53849 }
53850diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
53851index 7424929..35f6be5 100644
53852--- a/fs/nls/nls_euc-jp.c
53853+++ b/fs/nls/nls_euc-jp.c
53854@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
53855 p_nls = load_nls("cp932");
53856
53857 if (p_nls) {
53858- table.charset2upper = p_nls->charset2upper;
53859- table.charset2lower = p_nls->charset2lower;
53860+ pax_open_kernel();
53861+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
53862+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
53863+ pax_close_kernel();
53864 return register_nls(&table);
53865 }
53866
53867diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
53868index e7bc1d7..06bd4bb 100644
53869--- a/fs/nls/nls_koi8-ru.c
53870+++ b/fs/nls/nls_koi8-ru.c
53871@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
53872 p_nls = load_nls("koi8-u");
53873
53874 if (p_nls) {
53875- table.charset2upper = p_nls->charset2upper;
53876- table.charset2lower = p_nls->charset2lower;
53877+ pax_open_kernel();
53878+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
53879+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
53880+ pax_close_kernel();
53881 return register_nls(&table);
53882 }
53883
53884diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
53885index 5d84442..2c034ba 100644
53886--- a/fs/notify/fanotify/fanotify_user.c
53887+++ b/fs/notify/fanotify/fanotify_user.c
53888@@ -121,6 +121,7 @@ static int fill_event_metadata(struct fsnotify_group *group,
53889 metadata->event_len = FAN_EVENT_METADATA_LEN;
53890 metadata->metadata_len = FAN_EVENT_METADATA_LEN;
53891 metadata->vers = FANOTIFY_METADATA_VERSION;
53892+ metadata->reserved = 0;
53893 metadata->mask = event->mask & FAN_ALL_OUTGOING_EVENTS;
53894 metadata->pid = pid_vnr(event->tgid);
53895 if (unlikely(event->mask & FAN_Q_OVERFLOW))
53896@@ -251,8 +252,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
53897
53898 fd = fanotify_event_metadata.fd;
53899 ret = -EFAULT;
53900- if (copy_to_user(buf, &fanotify_event_metadata,
53901- fanotify_event_metadata.event_len))
53902+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
53903+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
53904 goto out_close_fd;
53905
53906 ret = prepare_for_access_response(group, event, fd);
53907diff --git a/fs/notify/notification.c b/fs/notify/notification.c
53908index 7b51b05..5ea5ef6 100644
53909--- a/fs/notify/notification.c
53910+++ b/fs/notify/notification.c
53911@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
53912 * get set to 0 so it will never get 'freed'
53913 */
53914 static struct fsnotify_event *q_overflow_event;
53915-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53916+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53917
53918 /**
53919 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
53920@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53921 */
53922 u32 fsnotify_get_cookie(void)
53923 {
53924- return atomic_inc_return(&fsnotify_sync_cookie);
53925+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
53926 }
53927 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
53928
53929diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
53930index aa411c3..c260a84 100644
53931--- a/fs/ntfs/dir.c
53932+++ b/fs/ntfs/dir.c
53933@@ -1329,7 +1329,7 @@ find_next_index_buffer:
53934 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
53935 ~(s64)(ndir->itype.index.block_size - 1)));
53936 /* Bounds checks. */
53937- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
53938+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
53939 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
53940 "inode 0x%lx or driver bug.", vdir->i_ino);
53941 goto err_out;
53942diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
53943index 5b2d4f0..c6de396 100644
53944--- a/fs/ntfs/file.c
53945+++ b/fs/ntfs/file.c
53946@@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
53947 #endif /* NTFS_RW */
53948 };
53949
53950-const struct file_operations ntfs_empty_file_ops = {};
53951+const struct file_operations ntfs_empty_file_ops __read_only;
53952
53953-const struct inode_operations ntfs_empty_inode_ops = {};
53954+const struct inode_operations ntfs_empty_inode_ops __read_only;
53955diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
53956index aebeacd..0dcdd26 100644
53957--- a/fs/ocfs2/localalloc.c
53958+++ b/fs/ocfs2/localalloc.c
53959@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
53960 goto bail;
53961 }
53962
53963- atomic_inc(&osb->alloc_stats.moves);
53964+ atomic_inc_unchecked(&osb->alloc_stats.moves);
53965
53966 bail:
53967 if (handle)
53968diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
53969index d355e6e..578d905 100644
53970--- a/fs/ocfs2/ocfs2.h
53971+++ b/fs/ocfs2/ocfs2.h
53972@@ -235,11 +235,11 @@ enum ocfs2_vol_state
53973
53974 struct ocfs2_alloc_stats
53975 {
53976- atomic_t moves;
53977- atomic_t local_data;
53978- atomic_t bitmap_data;
53979- atomic_t bg_allocs;
53980- atomic_t bg_extends;
53981+ atomic_unchecked_t moves;
53982+ atomic_unchecked_t local_data;
53983+ atomic_unchecked_t bitmap_data;
53984+ atomic_unchecked_t bg_allocs;
53985+ atomic_unchecked_t bg_extends;
53986 };
53987
53988 enum ocfs2_local_alloc_state
53989diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
53990index b7e74b5..19c6536 100644
53991--- a/fs/ocfs2/suballoc.c
53992+++ b/fs/ocfs2/suballoc.c
53993@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
53994 mlog_errno(status);
53995 goto bail;
53996 }
53997- atomic_inc(&osb->alloc_stats.bg_extends);
53998+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
53999
54000 /* You should never ask for this much metadata */
54001 BUG_ON(bits_wanted >
54002@@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
54003 mlog_errno(status);
54004 goto bail;
54005 }
54006- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54007+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54008
54009 *suballoc_loc = res.sr_bg_blkno;
54010 *suballoc_bit_start = res.sr_bit_offset;
54011@@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
54012 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
54013 res->sr_bits);
54014
54015- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54016+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54017
54018 BUG_ON(res->sr_bits != 1);
54019
54020@@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
54021 mlog_errno(status);
54022 goto bail;
54023 }
54024- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54025+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54026
54027 BUG_ON(res.sr_bits != 1);
54028
54029@@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
54030 cluster_start,
54031 num_clusters);
54032 if (!status)
54033- atomic_inc(&osb->alloc_stats.local_data);
54034+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
54035 } else {
54036 if (min_clusters > (osb->bitmap_cpg - 1)) {
54037 /* The only paths asking for contiguousness
54038@@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
54039 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
54040 res.sr_bg_blkno,
54041 res.sr_bit_offset);
54042- atomic_inc(&osb->alloc_stats.bitmap_data);
54043+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
54044 *num_clusters = res.sr_bits;
54045 }
54046 }
54047diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
54048index 01b8516..579c4df 100644
54049--- a/fs/ocfs2/super.c
54050+++ b/fs/ocfs2/super.c
54051@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
54052 "%10s => GlobalAllocs: %d LocalAllocs: %d "
54053 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
54054 "Stats",
54055- atomic_read(&osb->alloc_stats.bitmap_data),
54056- atomic_read(&osb->alloc_stats.local_data),
54057- atomic_read(&osb->alloc_stats.bg_allocs),
54058- atomic_read(&osb->alloc_stats.moves),
54059- atomic_read(&osb->alloc_stats.bg_extends));
54060+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
54061+ atomic_read_unchecked(&osb->alloc_stats.local_data),
54062+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
54063+ atomic_read_unchecked(&osb->alloc_stats.moves),
54064+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
54065
54066 out += snprintf(buf + out, len - out,
54067 "%10s => State: %u Descriptor: %llu Size: %u bits "
54068@@ -2122,11 +2122,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
54069 spin_lock_init(&osb->osb_xattr_lock);
54070 ocfs2_init_steal_slots(osb);
54071
54072- atomic_set(&osb->alloc_stats.moves, 0);
54073- atomic_set(&osb->alloc_stats.local_data, 0);
54074- atomic_set(&osb->alloc_stats.bitmap_data, 0);
54075- atomic_set(&osb->alloc_stats.bg_allocs, 0);
54076- atomic_set(&osb->alloc_stats.bg_extends, 0);
54077+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
54078+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
54079+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
54080+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
54081+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
54082
54083 /* Copy the blockcheck stats from the superblock probe */
54084 osb->osb_ecc_stats = *stats;
54085diff --git a/fs/open.c b/fs/open.c
54086index 6835446..eadf09f 100644
54087--- a/fs/open.c
54088+++ b/fs/open.c
54089@@ -32,6 +32,8 @@
54090 #include <linux/dnotify.h>
54091 #include <linux/compat.h>
54092
54093+#define CREATE_TRACE_POINTS
54094+#include <trace/events/fs.h>
54095 #include "internal.h"
54096
54097 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
54098@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
54099 error = locks_verify_truncate(inode, NULL, length);
54100 if (!error)
54101 error = security_path_truncate(path);
54102+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
54103+ error = -EACCES;
54104 if (!error)
54105 error = do_truncate(path->dentry, length, 0, NULL);
54106
54107@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
54108 error = locks_verify_truncate(inode, f.file, length);
54109 if (!error)
54110 error = security_path_truncate(&f.file->f_path);
54111+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
54112+ error = -EACCES;
54113 if (!error)
54114 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
54115 sb_end_write(inode->i_sb);
54116@@ -388,6 +394,9 @@ retry:
54117 if (__mnt_is_readonly(path.mnt))
54118 res = -EROFS;
54119
54120+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
54121+ res = -EACCES;
54122+
54123 out_path_release:
54124 path_put(&path);
54125 if (retry_estale(res, lookup_flags)) {
54126@@ -419,6 +428,8 @@ retry:
54127 if (error)
54128 goto dput_and_out;
54129
54130+ gr_log_chdir(path.dentry, path.mnt);
54131+
54132 set_fs_pwd(current->fs, &path);
54133
54134 dput_and_out:
54135@@ -448,6 +459,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
54136 goto out_putf;
54137
54138 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
54139+
54140+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
54141+ error = -EPERM;
54142+
54143+ if (!error)
54144+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
54145+
54146 if (!error)
54147 set_fs_pwd(current->fs, &f.file->f_path);
54148 out_putf:
54149@@ -477,7 +495,13 @@ retry:
54150 if (error)
54151 goto dput_and_out;
54152
54153+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
54154+ goto dput_and_out;
54155+
54156 set_fs_root(current->fs, &path);
54157+
54158+ gr_handle_chroot_chdir(&path);
54159+
54160 error = 0;
54161 dput_and_out:
54162 path_put(&path);
54163@@ -499,6 +523,16 @@ static int chmod_common(struct path *path, umode_t mode)
54164 if (error)
54165 return error;
54166 mutex_lock(&inode->i_mutex);
54167+
54168+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
54169+ error = -EACCES;
54170+ goto out_unlock;
54171+ }
54172+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
54173+ error = -EACCES;
54174+ goto out_unlock;
54175+ }
54176+
54177 error = security_path_chmod(path, mode);
54178 if (error)
54179 goto out_unlock;
54180@@ -559,6 +593,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
54181 uid = make_kuid(current_user_ns(), user);
54182 gid = make_kgid(current_user_ns(), group);
54183
54184+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
54185+ return -EACCES;
54186+
54187 newattrs.ia_valid = ATTR_CTIME;
54188 if (user != (uid_t) -1) {
54189 if (!uid_valid(uid))
54190@@ -974,6 +1011,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
54191 } else {
54192 fsnotify_open(f);
54193 fd_install(fd, f);
54194+ trace_do_sys_open(tmp->name, flags, mode);
54195 }
54196 }
54197 putname(tmp);
54198diff --git a/fs/pipe.c b/fs/pipe.c
54199index 2234f3f..f9083a1 100644
54200--- a/fs/pipe.c
54201+++ b/fs/pipe.c
54202@@ -438,9 +438,9 @@ redo:
54203 }
54204 if (bufs) /* More to do? */
54205 continue;
54206- if (!pipe->writers)
54207+ if (!atomic_read(&pipe->writers))
54208 break;
54209- if (!pipe->waiting_writers) {
54210+ if (!atomic_read(&pipe->waiting_writers)) {
54211 /* syscall merging: Usually we must not sleep
54212 * if O_NONBLOCK is set, or if we got some data.
54213 * But if a writer sleeps in kernel space, then
54214@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
54215 mutex_lock(&inode->i_mutex);
54216 pipe = inode->i_pipe;
54217
54218- if (!pipe->readers) {
54219+ if (!atomic_read(&pipe->readers)) {
54220 send_sig(SIGPIPE, current, 0);
54221 ret = -EPIPE;
54222 goto out;
54223@@ -553,7 +553,7 @@ redo1:
54224 for (;;) {
54225 int bufs;
54226
54227- if (!pipe->readers) {
54228+ if (!atomic_read(&pipe->readers)) {
54229 send_sig(SIGPIPE, current, 0);
54230 if (!ret)
54231 ret = -EPIPE;
54232@@ -644,9 +644,9 @@ redo2:
54233 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54234 do_wakeup = 0;
54235 }
54236- pipe->waiting_writers++;
54237+ atomic_inc(&pipe->waiting_writers);
54238 pipe_wait(pipe);
54239- pipe->waiting_writers--;
54240+ atomic_dec(&pipe->waiting_writers);
54241 }
54242 out:
54243 mutex_unlock(&inode->i_mutex);
54244@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54245 mask = 0;
54246 if (filp->f_mode & FMODE_READ) {
54247 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
54248- if (!pipe->writers && filp->f_version != pipe->w_counter)
54249+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
54250 mask |= POLLHUP;
54251 }
54252
54253@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54254 * Most Unices do not set POLLERR for FIFOs but on Linux they
54255 * behave exactly like pipes for poll().
54256 */
54257- if (!pipe->readers)
54258+ if (!atomic_read(&pipe->readers))
54259 mask |= POLLERR;
54260 }
54261
54262@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
54263
54264 mutex_lock(&inode->i_mutex);
54265 pipe = inode->i_pipe;
54266- pipe->readers -= decr;
54267- pipe->writers -= decw;
54268+ atomic_sub(decr, &pipe->readers);
54269+ atomic_sub(decw, &pipe->writers);
54270
54271- if (!pipe->readers && !pipe->writers) {
54272+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
54273 free_pipe_info(inode);
54274 } else {
54275 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
54276@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
54277
54278 if (inode->i_pipe) {
54279 ret = 0;
54280- inode->i_pipe->readers++;
54281+ atomic_inc(&inode->i_pipe->readers);
54282 }
54283
54284 mutex_unlock(&inode->i_mutex);
54285@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
54286
54287 if (inode->i_pipe) {
54288 ret = 0;
54289- inode->i_pipe->writers++;
54290+ atomic_inc(&inode->i_pipe->writers);
54291 }
54292
54293 mutex_unlock(&inode->i_mutex);
54294@@ -871,9 +871,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
54295 if (inode->i_pipe) {
54296 ret = 0;
54297 if (filp->f_mode & FMODE_READ)
54298- inode->i_pipe->readers++;
54299+ atomic_inc(&inode->i_pipe->readers);
54300 if (filp->f_mode & FMODE_WRITE)
54301- inode->i_pipe->writers++;
54302+ atomic_inc(&inode->i_pipe->writers);
54303 }
54304
54305 mutex_unlock(&inode->i_mutex);
54306@@ -965,7 +965,7 @@ void free_pipe_info(struct inode *inode)
54307 inode->i_pipe = NULL;
54308 }
54309
54310-static struct vfsmount *pipe_mnt __read_mostly;
54311+struct vfsmount *pipe_mnt __read_mostly;
54312
54313 /*
54314 * pipefs_dname() is called from d_path().
54315@@ -995,7 +995,8 @@ static struct inode * get_pipe_inode(void)
54316 goto fail_iput;
54317 inode->i_pipe = pipe;
54318
54319- pipe->readers = pipe->writers = 1;
54320+ atomic_set(&pipe->readers, 1);
54321+ atomic_set(&pipe->writers, 1);
54322 inode->i_fop = &rdwr_pipefifo_fops;
54323
54324 /*
54325diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
54326index 15af622..0e9f4467 100644
54327--- a/fs/proc/Kconfig
54328+++ b/fs/proc/Kconfig
54329@@ -30,12 +30,12 @@ config PROC_FS
54330
54331 config PROC_KCORE
54332 bool "/proc/kcore support" if !ARM
54333- depends on PROC_FS && MMU
54334+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
54335
54336 config PROC_VMCORE
54337 bool "/proc/vmcore support"
54338- depends on PROC_FS && CRASH_DUMP
54339- default y
54340+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
54341+ default n
54342 help
54343 Exports the dump image of crashed kernel in ELF format.
54344
54345@@ -59,8 +59,8 @@ config PROC_SYSCTL
54346 limited in memory.
54347
54348 config PROC_PAGE_MONITOR
54349- default y
54350- depends on PROC_FS && MMU
54351+ default n
54352+ depends on PROC_FS && MMU && !GRKERNSEC
54353 bool "Enable /proc page monitoring" if EXPERT
54354 help
54355 Various /proc files exist to monitor process memory utilization:
54356diff --git a/fs/proc/array.c b/fs/proc/array.c
54357index cbd0f1b..adec3f0 100644
54358--- a/fs/proc/array.c
54359+++ b/fs/proc/array.c
54360@@ -60,6 +60,7 @@
54361 #include <linux/tty.h>
54362 #include <linux/string.h>
54363 #include <linux/mman.h>
54364+#include <linux/grsecurity.h>
54365 #include <linux/proc_fs.h>
54366 #include <linux/ioport.h>
54367 #include <linux/uaccess.h>
54368@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
54369 seq_putc(m, '\n');
54370 }
54371
54372+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54373+static inline void task_pax(struct seq_file *m, struct task_struct *p)
54374+{
54375+ if (p->mm)
54376+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
54377+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
54378+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
54379+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
54380+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
54381+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
54382+ else
54383+ seq_printf(m, "PaX:\t-----\n");
54384+}
54385+#endif
54386+
54387 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54388 struct pid *pid, struct task_struct *task)
54389 {
54390@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54391 task_cpus_allowed(m, task);
54392 cpuset_task_status_allowed(m, task);
54393 task_context_switch_counts(m, task);
54394+
54395+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54396+ task_pax(m, task);
54397+#endif
54398+
54399+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
54400+ task_grsec_rbac(m, task);
54401+#endif
54402+
54403 return 0;
54404 }
54405
54406+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54407+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
54408+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
54409+ _mm->pax_flags & MF_PAX_SEGMEXEC))
54410+#endif
54411+
54412 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54413 struct pid *pid, struct task_struct *task, int whole)
54414 {
54415@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54416 char tcomm[sizeof(task->comm)];
54417 unsigned long flags;
54418
54419+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54420+ if (current->exec_id != m->exec_id) {
54421+ gr_log_badprocpid("stat");
54422+ return 0;
54423+ }
54424+#endif
54425+
54426 state = *get_task_state(task);
54427 vsize = eip = esp = 0;
54428 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
54429@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54430 gtime = task_gtime(task);
54431 }
54432
54433+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54434+ if (PAX_RAND_FLAGS(mm)) {
54435+ eip = 0;
54436+ esp = 0;
54437+ wchan = 0;
54438+ }
54439+#endif
54440+#ifdef CONFIG_GRKERNSEC_HIDESYM
54441+ wchan = 0;
54442+ eip =0;
54443+ esp =0;
54444+#endif
54445+
54446 /* scale priority and nice values from timeslices to -20..20 */
54447 /* to make it look like a "normal" Unix priority/nice value */
54448 priority = task_prio(task);
54449@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54450 seq_put_decimal_ull(m, ' ', vsize);
54451 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
54452 seq_put_decimal_ull(m, ' ', rsslim);
54453+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54454+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
54455+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
54456+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
54457+#else
54458 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
54459 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
54460 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
54461+#endif
54462 seq_put_decimal_ull(m, ' ', esp);
54463 seq_put_decimal_ull(m, ' ', eip);
54464 /* The signal information here is obsolete.
54465@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54466 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
54467 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
54468
54469- if (mm && permitted) {
54470+ if (mm && permitted
54471+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54472+ && !PAX_RAND_FLAGS(mm)
54473+#endif
54474+ ) {
54475 seq_put_decimal_ull(m, ' ', mm->start_data);
54476 seq_put_decimal_ull(m, ' ', mm->end_data);
54477 seq_put_decimal_ull(m, ' ', mm->start_brk);
54478@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
54479 struct pid *pid, struct task_struct *task)
54480 {
54481 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
54482- struct mm_struct *mm = get_task_mm(task);
54483+ struct mm_struct *mm;
54484
54485+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54486+ if (current->exec_id != m->exec_id) {
54487+ gr_log_badprocpid("statm");
54488+ return 0;
54489+ }
54490+#endif
54491+ mm = get_task_mm(task);
54492 if (mm) {
54493 size = task_statm(mm, &shared, &text, &data, &resident);
54494 mmput(mm);
54495@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
54496 return 0;
54497 }
54498
54499+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54500+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
54501+{
54502+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
54503+}
54504+#endif
54505+
54506 #ifdef CONFIG_CHECKPOINT_RESTORE
54507 static struct pid *
54508 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
54509diff --git a/fs/proc/base.c b/fs/proc/base.c
54510index 69078c7..3e12a75 100644
54511--- a/fs/proc/base.c
54512+++ b/fs/proc/base.c
54513@@ -112,6 +112,14 @@ struct pid_entry {
54514 union proc_op op;
54515 };
54516
54517+struct getdents_callback {
54518+ struct linux_dirent __user * current_dir;
54519+ struct linux_dirent __user * previous;
54520+ struct file * file;
54521+ int count;
54522+ int error;
54523+};
54524+
54525 #define NOD(NAME, MODE, IOP, FOP, OP) { \
54526 .name = (NAME), \
54527 .len = sizeof(NAME) - 1, \
54528@@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
54529 if (!mm->arg_end)
54530 goto out_mm; /* Shh! No looking before we're done */
54531
54532+ if (gr_acl_handle_procpidmem(task))
54533+ goto out_mm;
54534+
54535 len = mm->arg_end - mm->arg_start;
54536
54537 if (len > PAGE_SIZE)
54538@@ -236,12 +247,28 @@ out:
54539 return res;
54540 }
54541
54542+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54543+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
54544+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
54545+ _mm->pax_flags & MF_PAX_SEGMEXEC))
54546+#endif
54547+
54548 static int proc_pid_auxv(struct task_struct *task, char *buffer)
54549 {
54550 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
54551 int res = PTR_ERR(mm);
54552 if (mm && !IS_ERR(mm)) {
54553 unsigned int nwords = 0;
54554+
54555+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54556+ /* allow if we're currently ptracing this task */
54557+ if (PAX_RAND_FLAGS(mm) &&
54558+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
54559+ mmput(mm);
54560+ return 0;
54561+ }
54562+#endif
54563+
54564 do {
54565 nwords += 2;
54566 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
54567@@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
54568 }
54569
54570
54571-#ifdef CONFIG_KALLSYMS
54572+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54573 /*
54574 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
54575 * Returns the resolved symbol. If that fails, simply return the address.
54576@@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
54577 mutex_unlock(&task->signal->cred_guard_mutex);
54578 }
54579
54580-#ifdef CONFIG_STACKTRACE
54581+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54582
54583 #define MAX_STACK_TRACE_DEPTH 64
54584
54585@@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
54586 return count;
54587 }
54588
54589-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54590+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54591 static int proc_pid_syscall(struct task_struct *task, char *buffer)
54592 {
54593 long nr;
54594@@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
54595 /************************************************************************/
54596
54597 /* permission checks */
54598-static int proc_fd_access_allowed(struct inode *inode)
54599+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
54600 {
54601 struct task_struct *task;
54602 int allowed = 0;
54603@@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
54604 */
54605 task = get_proc_task(inode);
54606 if (task) {
54607- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
54608+ if (log)
54609+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
54610+ else
54611+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
54612 put_task_struct(task);
54613 }
54614 return allowed;
54615@@ -556,10 +586,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
54616 struct task_struct *task,
54617 int hide_pid_min)
54618 {
54619+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54620+ return false;
54621+
54622+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54623+ rcu_read_lock();
54624+ {
54625+ const struct cred *tmpcred = current_cred();
54626+ const struct cred *cred = __task_cred(task);
54627+
54628+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
54629+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54630+ || in_group_p(grsec_proc_gid)
54631+#endif
54632+ ) {
54633+ rcu_read_unlock();
54634+ return true;
54635+ }
54636+ }
54637+ rcu_read_unlock();
54638+
54639+ if (!pid->hide_pid)
54640+ return false;
54641+#endif
54642+
54643 if (pid->hide_pid < hide_pid_min)
54644 return true;
54645 if (in_group_p(pid->pid_gid))
54646 return true;
54647+
54648 return ptrace_may_access(task, PTRACE_MODE_READ);
54649 }
54650
54651@@ -577,7 +632,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
54652 put_task_struct(task);
54653
54654 if (!has_perms) {
54655+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54656+ {
54657+#else
54658 if (pid->hide_pid == 2) {
54659+#endif
54660 /*
54661 * Let's make getdents(), stat(), and open()
54662 * consistent with each other. If a process
54663@@ -675,6 +734,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
54664 if (!task)
54665 return -ESRCH;
54666
54667+ if (gr_acl_handle_procpidmem(task)) {
54668+ put_task_struct(task);
54669+ return -EPERM;
54670+ }
54671+
54672 mm = mm_access(task, mode);
54673 put_task_struct(task);
54674
54675@@ -690,6 +754,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
54676
54677 file->private_data = mm;
54678
54679+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54680+ file->f_version = current->exec_id;
54681+#endif
54682+
54683 return 0;
54684 }
54685
54686@@ -711,6 +779,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
54687 ssize_t copied;
54688 char *page;
54689
54690+#ifdef CONFIG_GRKERNSEC
54691+ if (write)
54692+ return -EPERM;
54693+#endif
54694+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54695+ if (file->f_version != current->exec_id) {
54696+ gr_log_badprocpid("mem");
54697+ return 0;
54698+ }
54699+#endif
54700+
54701 if (!mm)
54702 return 0;
54703
54704@@ -723,7 +802,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
54705 goto free;
54706
54707 while (count > 0) {
54708- int this_len = min_t(int, count, PAGE_SIZE);
54709+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
54710
54711 if (write && copy_from_user(page, buf, this_len)) {
54712 copied = -EFAULT;
54713@@ -815,6 +894,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
54714 if (!mm)
54715 return 0;
54716
54717+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54718+ if (file->f_version != current->exec_id) {
54719+ gr_log_badprocpid("environ");
54720+ return 0;
54721+ }
54722+#endif
54723+
54724 page = (char *)__get_free_page(GFP_TEMPORARY);
54725 if (!page)
54726 return -ENOMEM;
54727@@ -824,7 +910,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
54728 goto free;
54729 while (count > 0) {
54730 size_t this_len, max_len;
54731- int retval;
54732+ ssize_t retval;
54733
54734 if (src >= (mm->env_end - mm->env_start))
54735 break;
54736@@ -1430,7 +1516,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
54737 int error = -EACCES;
54738
54739 /* Are we allowed to snoop on the tasks file descriptors? */
54740- if (!proc_fd_access_allowed(inode))
54741+ if (!proc_fd_access_allowed(inode, 0))
54742 goto out;
54743
54744 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
54745@@ -1474,8 +1560,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
54746 struct path path;
54747
54748 /* Are we allowed to snoop on the tasks file descriptors? */
54749- if (!proc_fd_access_allowed(inode))
54750- goto out;
54751+ /* logging this is needed for learning on chromium to work properly,
54752+ but we don't want to flood the logs from 'ps' which does a readlink
54753+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
54754+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
54755+ */
54756+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
54757+ if (!proc_fd_access_allowed(inode,0))
54758+ goto out;
54759+ } else {
54760+ if (!proc_fd_access_allowed(inode,1))
54761+ goto out;
54762+ }
54763
54764 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
54765 if (error)
54766@@ -1525,7 +1621,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
54767 rcu_read_lock();
54768 cred = __task_cred(task);
54769 inode->i_uid = cred->euid;
54770+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54771+ inode->i_gid = grsec_proc_gid;
54772+#else
54773 inode->i_gid = cred->egid;
54774+#endif
54775 rcu_read_unlock();
54776 }
54777 security_task_to_inode(task, inode);
54778@@ -1561,10 +1661,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
54779 return -ENOENT;
54780 }
54781 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
54782+#ifdef CONFIG_GRKERNSEC_PROC_USER
54783+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
54784+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54785+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
54786+#endif
54787 task_dumpable(task)) {
54788 cred = __task_cred(task);
54789 stat->uid = cred->euid;
54790+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54791+ stat->gid = grsec_proc_gid;
54792+#else
54793 stat->gid = cred->egid;
54794+#endif
54795 }
54796 }
54797 rcu_read_unlock();
54798@@ -1602,11 +1711,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
54799
54800 if (task) {
54801 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
54802+#ifdef CONFIG_GRKERNSEC_PROC_USER
54803+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
54804+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54805+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
54806+#endif
54807 task_dumpable(task)) {
54808 rcu_read_lock();
54809 cred = __task_cred(task);
54810 inode->i_uid = cred->euid;
54811+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54812+ inode->i_gid = grsec_proc_gid;
54813+#else
54814 inode->i_gid = cred->egid;
54815+#endif
54816 rcu_read_unlock();
54817 } else {
54818 inode->i_uid = GLOBAL_ROOT_UID;
54819@@ -2059,6 +2177,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
54820 if (!task)
54821 goto out_no_task;
54822
54823+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54824+ goto out;
54825+
54826 /*
54827 * Yes, it does not scale. And it should not. Don't add
54828 * new entries into /proc/<tgid>/ without very good reasons.
54829@@ -2103,6 +2224,9 @@ static int proc_pident_readdir(struct file *filp,
54830 if (!task)
54831 goto out_no_task;
54832
54833+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54834+ goto out;
54835+
54836 ret = 0;
54837 i = filp->f_pos;
54838 switch (i) {
54839@@ -2516,7 +2640,7 @@ static const struct pid_entry tgid_base_stuff[] = {
54840 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
54841 #endif
54842 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
54843-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54844+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54845 INF("syscall", S_IRUGO, proc_pid_syscall),
54846 #endif
54847 INF("cmdline", S_IRUGO, proc_pid_cmdline),
54848@@ -2541,10 +2665,10 @@ static const struct pid_entry tgid_base_stuff[] = {
54849 #ifdef CONFIG_SECURITY
54850 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
54851 #endif
54852-#ifdef CONFIG_KALLSYMS
54853+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54854 INF("wchan", S_IRUGO, proc_pid_wchan),
54855 #endif
54856-#ifdef CONFIG_STACKTRACE
54857+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54858 ONE("stack", S_IRUGO, proc_pid_stack),
54859 #endif
54860 #ifdef CONFIG_SCHEDSTATS
54861@@ -2578,6 +2702,9 @@ static const struct pid_entry tgid_base_stuff[] = {
54862 #ifdef CONFIG_HARDWALL
54863 INF("hardwall", S_IRUGO, proc_pid_hardwall),
54864 #endif
54865+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54866+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
54867+#endif
54868 #ifdef CONFIG_USER_NS
54869 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
54870 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
54871@@ -2707,7 +2834,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
54872 if (!inode)
54873 goto out;
54874
54875+#ifdef CONFIG_GRKERNSEC_PROC_USER
54876+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
54877+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54878+ inode->i_gid = grsec_proc_gid;
54879+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
54880+#else
54881 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
54882+#endif
54883 inode->i_op = &proc_tgid_base_inode_operations;
54884 inode->i_fop = &proc_tgid_base_operations;
54885 inode->i_flags|=S_IMMUTABLE;
54886@@ -2745,7 +2879,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
54887 if (!task)
54888 goto out;
54889
54890+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54891+ goto out_put_task;
54892+
54893 result = proc_pid_instantiate(dir, dentry, task, NULL);
54894+out_put_task:
54895 put_task_struct(task);
54896 out:
54897 return result;
54898@@ -2808,6 +2946,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
54899 static int fake_filldir(void *buf, const char *name, int namelen,
54900 loff_t offset, u64 ino, unsigned d_type)
54901 {
54902+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
54903+ __buf->error = -EINVAL;
54904 return 0;
54905 }
54906
54907@@ -2859,7 +2999,7 @@ static const struct pid_entry tid_base_stuff[] = {
54908 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
54909 #endif
54910 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
54911-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54912+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54913 INF("syscall", S_IRUGO, proc_pid_syscall),
54914 #endif
54915 INF("cmdline", S_IRUGO, proc_pid_cmdline),
54916@@ -2886,10 +3026,10 @@ static const struct pid_entry tid_base_stuff[] = {
54917 #ifdef CONFIG_SECURITY
54918 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
54919 #endif
54920-#ifdef CONFIG_KALLSYMS
54921+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54922 INF("wchan", S_IRUGO, proc_pid_wchan),
54923 #endif
54924-#ifdef CONFIG_STACKTRACE
54925+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54926 ONE("stack", S_IRUGO, proc_pid_stack),
54927 #endif
54928 #ifdef CONFIG_SCHEDSTATS
54929diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
54930index 82676e3..5f8518a 100644
54931--- a/fs/proc/cmdline.c
54932+++ b/fs/proc/cmdline.c
54933@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
54934
54935 static int __init proc_cmdline_init(void)
54936 {
54937+#ifdef CONFIG_GRKERNSEC_PROC_ADD
54938+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
54939+#else
54940 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
54941+#endif
54942 return 0;
54943 }
54944 module_init(proc_cmdline_init);
54945diff --git a/fs/proc/devices.c b/fs/proc/devices.c
54946index b143471..bb105e5 100644
54947--- a/fs/proc/devices.c
54948+++ b/fs/proc/devices.c
54949@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
54950
54951 static int __init proc_devices_init(void)
54952 {
54953+#ifdef CONFIG_GRKERNSEC_PROC_ADD
54954+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
54955+#else
54956 proc_create("devices", 0, NULL, &proc_devinfo_operations);
54957+#endif
54958 return 0;
54959 }
54960 module_init(proc_devices_init);
54961diff --git a/fs/proc/fd.c b/fs/proc/fd.c
54962index d7a4a28..0201742 100644
54963--- a/fs/proc/fd.c
54964+++ b/fs/proc/fd.c
54965@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
54966 if (!task)
54967 return -ENOENT;
54968
54969- files = get_files_struct(task);
54970+ if (!gr_acl_handle_procpidmem(task))
54971+ files = get_files_struct(task);
54972 put_task_struct(task);
54973
54974 if (files) {
54975@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
54976 */
54977 int proc_fd_permission(struct inode *inode, int mask)
54978 {
54979+ struct task_struct *task;
54980 int rv = generic_permission(inode, mask);
54981- if (rv == 0)
54982- return 0;
54983+
54984 if (task_pid(current) == proc_pid(inode))
54985 rv = 0;
54986+
54987+ task = get_proc_task(inode);
54988+ if (task == NULL)
54989+ return rv;
54990+
54991+ if (gr_acl_handle_procpidmem(task))
54992+ rv = -EACCES;
54993+
54994+ put_task_struct(task);
54995+
54996 return rv;
54997 }
54998
54999diff --git a/fs/proc/inode.c b/fs/proc/inode.c
55000index 869116c..820cb27 100644
55001--- a/fs/proc/inode.c
55002+++ b/fs/proc/inode.c
55003@@ -22,11 +22,17 @@
55004 #include <linux/seq_file.h>
55005 #include <linux/slab.h>
55006 #include <linux/mount.h>
55007+#include <linux/grsecurity.h>
55008
55009 #include <asm/uaccess.h>
55010
55011 #include "internal.h"
55012
55013+#ifdef CONFIG_PROC_SYSCTL
55014+extern const struct inode_operations proc_sys_inode_operations;
55015+extern const struct inode_operations proc_sys_dir_operations;
55016+#endif
55017+
55018 static void proc_evict_inode(struct inode *inode)
55019 {
55020 struct proc_dir_entry *de;
55021@@ -54,6 +60,13 @@ static void proc_evict_inode(struct inode *inode)
55022 ns = PROC_I(inode)->ns;
55023 if (ns_ops && ns)
55024 ns_ops->put(ns);
55025+
55026+#ifdef CONFIG_PROC_SYSCTL
55027+ if (inode->i_op == &proc_sys_inode_operations ||
55028+ inode->i_op == &proc_sys_dir_operations)
55029+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
55030+#endif
55031+
55032 }
55033
55034 static struct kmem_cache * proc_inode_cachep;
55035@@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
55036 if (de->mode) {
55037 inode->i_mode = de->mode;
55038 inode->i_uid = de->uid;
55039+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55040+ inode->i_gid = grsec_proc_gid;
55041+#else
55042 inode->i_gid = de->gid;
55043+#endif
55044 }
55045 if (de->size)
55046 inode->i_size = de->size;
55047diff --git a/fs/proc/internal.h b/fs/proc/internal.h
55048index 85ff3a4..a512bd8 100644
55049--- a/fs/proc/internal.h
55050+++ b/fs/proc/internal.h
55051@@ -56,6 +56,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55052 struct pid *pid, struct task_struct *task);
55053 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55054 struct pid *pid, struct task_struct *task);
55055+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55056+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
55057+#endif
55058 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
55059
55060 extern const struct file_operations proc_tid_children_operations;
55061diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
55062index eda6f01..006ae24 100644
55063--- a/fs/proc/kcore.c
55064+++ b/fs/proc/kcore.c
55065@@ -481,9 +481,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55066 * the addresses in the elf_phdr on our list.
55067 */
55068 start = kc_offset_to_vaddr(*fpos - elf_buflen);
55069- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
55070+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
55071+ if (tsz > buflen)
55072 tsz = buflen;
55073-
55074+
55075 while (buflen) {
55076 struct kcore_list *m;
55077
55078@@ -512,20 +513,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55079 kfree(elf_buf);
55080 } else {
55081 if (kern_addr_valid(start)) {
55082- unsigned long n;
55083+ char *elf_buf;
55084+ mm_segment_t oldfs;
55085
55086- n = copy_to_user(buffer, (char *)start, tsz);
55087- /*
55088- * We cannot distinguish between fault on source
55089- * and fault on destination. When this happens
55090- * we clear too and hope it will trigger the
55091- * EFAULT again.
55092- */
55093- if (n) {
55094- if (clear_user(buffer + tsz - n,
55095- n))
55096+ elf_buf = kmalloc(tsz, GFP_KERNEL);
55097+ if (!elf_buf)
55098+ return -ENOMEM;
55099+ oldfs = get_fs();
55100+ set_fs(KERNEL_DS);
55101+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
55102+ set_fs(oldfs);
55103+ if (copy_to_user(buffer, elf_buf, tsz)) {
55104+ kfree(elf_buf);
55105 return -EFAULT;
55106+ }
55107 }
55108+ set_fs(oldfs);
55109+ kfree(elf_buf);
55110 } else {
55111 if (clear_user(buffer, tsz))
55112 return -EFAULT;
55113@@ -545,6 +549,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55114
55115 static int open_kcore(struct inode *inode, struct file *filp)
55116 {
55117+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
55118+ return -EPERM;
55119+#endif
55120 if (!capable(CAP_SYS_RAWIO))
55121 return -EPERM;
55122 if (kcore_need_update)
55123diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
55124index 1efaaa1..834e49a 100644
55125--- a/fs/proc/meminfo.c
55126+++ b/fs/proc/meminfo.c
55127@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
55128 vmi.used >> 10,
55129 vmi.largest_chunk >> 10
55130 #ifdef CONFIG_MEMORY_FAILURE
55131- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
55132+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
55133 #endif
55134 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
55135 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
55136diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
55137index ccfd99b..1b7e255 100644
55138--- a/fs/proc/nommu.c
55139+++ b/fs/proc/nommu.c
55140@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
55141 if (len < 1)
55142 len = 1;
55143 seq_printf(m, "%*c", len, ' ');
55144- seq_path(m, &file->f_path, "");
55145+ seq_path(m, &file->f_path, "\n\\");
55146 }
55147
55148 seq_putc(m, '\n');
55149diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
55150index b4ac657..0842bd2 100644
55151--- a/fs/proc/proc_net.c
55152+++ b/fs/proc/proc_net.c
55153@@ -23,6 +23,7 @@
55154 #include <linux/nsproxy.h>
55155 #include <net/net_namespace.h>
55156 #include <linux/seq_file.h>
55157+#include <linux/grsecurity.h>
55158
55159 #include "internal.h"
55160
55161@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
55162 struct task_struct *task;
55163 struct nsproxy *ns;
55164 struct net *net = NULL;
55165+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55166+ const struct cred *cred = current_cred();
55167+#endif
55168+
55169+#ifdef CONFIG_GRKERNSEC_PROC_USER
55170+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
55171+ return net;
55172+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55173+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
55174+ return net;
55175+#endif
55176
55177 rcu_read_lock();
55178 task = pid_task(proc_pid(dir), PIDTYPE_PID);
55179diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
55180index ac05f33..1e6dc7e 100644
55181--- a/fs/proc/proc_sysctl.c
55182+++ b/fs/proc/proc_sysctl.c
55183@@ -13,11 +13,15 @@
55184 #include <linux/module.h>
55185 #include "internal.h"
55186
55187+extern int gr_handle_chroot_sysctl(const int op);
55188+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
55189+ const int op);
55190+
55191 static const struct dentry_operations proc_sys_dentry_operations;
55192 static const struct file_operations proc_sys_file_operations;
55193-static const struct inode_operations proc_sys_inode_operations;
55194+const struct inode_operations proc_sys_inode_operations;
55195 static const struct file_operations proc_sys_dir_file_operations;
55196-static const struct inode_operations proc_sys_dir_operations;
55197+const struct inode_operations proc_sys_dir_operations;
55198
55199 void proc_sys_poll_notify(struct ctl_table_poll *poll)
55200 {
55201@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
55202
55203 err = NULL;
55204 d_set_d_op(dentry, &proc_sys_dentry_operations);
55205+
55206+ gr_handle_proc_create(dentry, inode);
55207+
55208 d_add(dentry, inode);
55209
55210 out:
55211@@ -482,6 +489,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55212 struct inode *inode = file_inode(filp);
55213 struct ctl_table_header *head = grab_header(inode);
55214 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
55215+ int op = write ? MAY_WRITE : MAY_READ;
55216 ssize_t error;
55217 size_t res;
55218
55219@@ -493,7 +501,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55220 * and won't be until we finish.
55221 */
55222 error = -EPERM;
55223- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
55224+ if (sysctl_perm(head, table, op))
55225 goto out;
55226
55227 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
55228@@ -501,6 +509,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55229 if (!table->proc_handler)
55230 goto out;
55231
55232+#ifdef CONFIG_GRKERNSEC
55233+ error = -EPERM;
55234+ if (gr_handle_chroot_sysctl(op))
55235+ goto out;
55236+ dget(filp->f_path.dentry);
55237+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
55238+ dput(filp->f_path.dentry);
55239+ goto out;
55240+ }
55241+ dput(filp->f_path.dentry);
55242+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
55243+ goto out;
55244+ if (write && !capable(CAP_SYS_ADMIN))
55245+ goto out;
55246+#endif
55247+
55248 /* careful: calling conventions are nasty here */
55249 res = count;
55250 error = table->proc_handler(table, write, buf, &res, ppos);
55251@@ -598,6 +622,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
55252 return -ENOMEM;
55253 } else {
55254 d_set_d_op(child, &proc_sys_dentry_operations);
55255+
55256+ gr_handle_proc_create(child, inode);
55257+
55258 d_add(child, inode);
55259 }
55260 } else {
55261@@ -641,6 +668,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
55262 if ((*pos)++ < file->f_pos)
55263 return 0;
55264
55265+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
55266+ return 0;
55267+
55268 if (unlikely(S_ISLNK(table->mode)))
55269 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
55270 else
55271@@ -751,6 +781,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
55272 if (IS_ERR(head))
55273 return PTR_ERR(head);
55274
55275+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
55276+ return -ENOENT;
55277+
55278 generic_fillattr(inode, stat);
55279 if (table)
55280 stat->mode = (stat->mode & S_IFMT) | table->mode;
55281@@ -773,13 +806,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
55282 .llseek = generic_file_llseek,
55283 };
55284
55285-static const struct inode_operations proc_sys_inode_operations = {
55286+const struct inode_operations proc_sys_inode_operations = {
55287 .permission = proc_sys_permission,
55288 .setattr = proc_sys_setattr,
55289 .getattr = proc_sys_getattr,
55290 };
55291
55292-static const struct inode_operations proc_sys_dir_operations = {
55293+const struct inode_operations proc_sys_dir_operations = {
55294 .lookup = proc_sys_lookup,
55295 .permission = proc_sys_permission,
55296 .setattr = proc_sys_setattr,
55297@@ -855,7 +888,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
55298 static struct ctl_dir *new_dir(struct ctl_table_set *set,
55299 const char *name, int namelen)
55300 {
55301- struct ctl_table *table;
55302+ ctl_table_no_const *table;
55303 struct ctl_dir *new;
55304 struct ctl_node *node;
55305 char *new_name;
55306@@ -867,7 +900,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
55307 return NULL;
55308
55309 node = (struct ctl_node *)(new + 1);
55310- table = (struct ctl_table *)(node + 1);
55311+ table = (ctl_table_no_const *)(node + 1);
55312 new_name = (char *)(table + 2);
55313 memcpy(new_name, name, namelen);
55314 new_name[namelen] = '\0';
55315@@ -1036,7 +1069,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
55316 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
55317 struct ctl_table_root *link_root)
55318 {
55319- struct ctl_table *link_table, *entry, *link;
55320+ ctl_table_no_const *link_table, *link;
55321+ struct ctl_table *entry;
55322 struct ctl_table_header *links;
55323 struct ctl_node *node;
55324 char *link_name;
55325@@ -1059,7 +1093,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
55326 return NULL;
55327
55328 node = (struct ctl_node *)(links + 1);
55329- link_table = (struct ctl_table *)(node + nr_entries);
55330+ link_table = (ctl_table_no_const *)(node + nr_entries);
55331 link_name = (char *)&link_table[nr_entries + 1];
55332
55333 for (link = link_table, entry = table; entry->procname; link++, entry++) {
55334@@ -1307,8 +1341,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55335 struct ctl_table_header ***subheader, struct ctl_table_set *set,
55336 struct ctl_table *table)
55337 {
55338- struct ctl_table *ctl_table_arg = NULL;
55339- struct ctl_table *entry, *files;
55340+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
55341+ struct ctl_table *entry;
55342 int nr_files = 0;
55343 int nr_dirs = 0;
55344 int err = -ENOMEM;
55345@@ -1320,10 +1354,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55346 nr_files++;
55347 }
55348
55349- files = table;
55350 /* If there are mixed files and directories we need a new table */
55351 if (nr_dirs && nr_files) {
55352- struct ctl_table *new;
55353+ ctl_table_no_const *new;
55354 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
55355 GFP_KERNEL);
55356 if (!files)
55357@@ -1341,7 +1374,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55358 /* Register everything except a directory full of subdirectories */
55359 if (nr_files || !nr_dirs) {
55360 struct ctl_table_header *header;
55361- header = __register_sysctl_table(set, path, files);
55362+ header = __register_sysctl_table(set, path, files ? files : table);
55363 if (!header) {
55364 kfree(ctl_table_arg);
55365 goto out;
55366diff --git a/fs/proc/root.c b/fs/proc/root.c
55367index 9c7fab1..ed1c8e0 100644
55368--- a/fs/proc/root.c
55369+++ b/fs/proc/root.c
55370@@ -180,7 +180,15 @@ void __init proc_root_init(void)
55371 #ifdef CONFIG_PROC_DEVICETREE
55372 proc_device_tree_init();
55373 #endif
55374+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55375+#ifdef CONFIG_GRKERNSEC_PROC_USER
55376+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
55377+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55378+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
55379+#endif
55380+#else
55381 proc_mkdir("bus", NULL);
55382+#endif
55383 proc_sys_init();
55384 }
55385
55386diff --git a/fs/proc/self.c b/fs/proc/self.c
55387index aa5cc3b..c91a5d0 100644
55388--- a/fs/proc/self.c
55389+++ b/fs/proc/self.c
55390@@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
55391 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
55392 void *cookie)
55393 {
55394- char *s = nd_get_link(nd);
55395+ const char *s = nd_get_link(nd);
55396 if (!IS_ERR(s))
55397 kfree(s);
55398 }
55399diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
55400index 3e636d8..83e3b71 100644
55401--- a/fs/proc/task_mmu.c
55402+++ b/fs/proc/task_mmu.c
55403@@ -11,12 +11,19 @@
55404 #include <linux/rmap.h>
55405 #include <linux/swap.h>
55406 #include <linux/swapops.h>
55407+#include <linux/grsecurity.h>
55408
55409 #include <asm/elf.h>
55410 #include <asm/uaccess.h>
55411 #include <asm/tlbflush.h>
55412 #include "internal.h"
55413
55414+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55415+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55416+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55417+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55418+#endif
55419+
55420 void task_mem(struct seq_file *m, struct mm_struct *mm)
55421 {
55422 unsigned long data, text, lib, swap;
55423@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
55424 "VmExe:\t%8lu kB\n"
55425 "VmLib:\t%8lu kB\n"
55426 "VmPTE:\t%8lu kB\n"
55427- "VmSwap:\t%8lu kB\n",
55428- hiwater_vm << (PAGE_SHIFT-10),
55429+ "VmSwap:\t%8lu kB\n"
55430+
55431+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
55432+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
55433+#endif
55434+
55435+ ,hiwater_vm << (PAGE_SHIFT-10),
55436 total_vm << (PAGE_SHIFT-10),
55437 mm->locked_vm << (PAGE_SHIFT-10),
55438 mm->pinned_vm << (PAGE_SHIFT-10),
55439@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
55440 data << (PAGE_SHIFT-10),
55441 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
55442 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
55443- swap << (PAGE_SHIFT-10));
55444+ swap << (PAGE_SHIFT-10)
55445+
55446+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
55447+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55448+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
55449+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
55450+#else
55451+ , mm->context.user_cs_base
55452+ , mm->context.user_cs_limit
55453+#endif
55454+#endif
55455+
55456+ );
55457 }
55458
55459 unsigned long task_vsize(struct mm_struct *mm)
55460@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55461 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
55462 }
55463
55464- /* We don't show the stack guard page in /proc/maps */
55465+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55466+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
55467+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
55468+#else
55469 start = vma->vm_start;
55470- if (stack_guard_page_start(vma, start))
55471- start += PAGE_SIZE;
55472 end = vma->vm_end;
55473- if (stack_guard_page_end(vma, end))
55474- end -= PAGE_SIZE;
55475+#endif
55476
55477 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
55478 start,
55479@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55480 flags & VM_WRITE ? 'w' : '-',
55481 flags & VM_EXEC ? 'x' : '-',
55482 flags & VM_MAYSHARE ? 's' : 'p',
55483+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55484+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
55485+#else
55486 pgoff,
55487+#endif
55488 MAJOR(dev), MINOR(dev), ino, &len);
55489
55490 /*
55491@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55492 */
55493 if (file) {
55494 pad_len_spaces(m, len);
55495- seq_path(m, &file->f_path, "\n");
55496+ seq_path(m, &file->f_path, "\n\\");
55497 goto done;
55498 }
55499
55500@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55501 * Thread stack in /proc/PID/task/TID/maps or
55502 * the main process stack.
55503 */
55504- if (!is_pid || (vma->vm_start <= mm->start_stack &&
55505- vma->vm_end >= mm->start_stack)) {
55506+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
55507+ (vma->vm_start <= mm->start_stack &&
55508+ vma->vm_end >= mm->start_stack)) {
55509 name = "[stack]";
55510 } else {
55511 /* Thread stack in /proc/PID/maps */
55512@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
55513 struct proc_maps_private *priv = m->private;
55514 struct task_struct *task = priv->task;
55515
55516+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55517+ if (current->exec_id != m->exec_id) {
55518+ gr_log_badprocpid("maps");
55519+ return 0;
55520+ }
55521+#endif
55522+
55523 show_map_vma(m, vma, is_pid);
55524
55525 if (m->count < m->size) /* vma is copied successfully */
55526@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
55527 .private = &mss,
55528 };
55529
55530+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55531+ if (current->exec_id != m->exec_id) {
55532+ gr_log_badprocpid("smaps");
55533+ return 0;
55534+ }
55535+#endif
55536 memset(&mss, 0, sizeof mss);
55537- mss.vma = vma;
55538- /* mmap_sem is held in m_start */
55539- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
55540- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
55541-
55542+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55543+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
55544+#endif
55545+ mss.vma = vma;
55546+ /* mmap_sem is held in m_start */
55547+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
55548+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
55549+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55550+ }
55551+#endif
55552 show_map_vma(m, vma, is_pid);
55553
55554 seq_printf(m,
55555@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
55556 "KernelPageSize: %8lu kB\n"
55557 "MMUPageSize: %8lu kB\n"
55558 "Locked: %8lu kB\n",
55559+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55560+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
55561+#else
55562 (vma->vm_end - vma->vm_start) >> 10,
55563+#endif
55564 mss.resident >> 10,
55565 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
55566 mss.shared_clean >> 10,
55567@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
55568 int n;
55569 char buffer[50];
55570
55571+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55572+ if (current->exec_id != m->exec_id) {
55573+ gr_log_badprocpid("numa_maps");
55574+ return 0;
55575+ }
55576+#endif
55577+
55578 if (!mm)
55579 return 0;
55580
55581@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
55582 mpol_to_str(buffer, sizeof(buffer), pol);
55583 mpol_cond_put(pol);
55584
55585+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55586+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
55587+#else
55588 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
55589+#endif
55590
55591 if (file) {
55592 seq_printf(m, " file=");
55593- seq_path(m, &file->f_path, "\n\t= ");
55594+ seq_path(m, &file->f_path, "\n\t\\= ");
55595 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
55596 seq_printf(m, " heap");
55597 } else {
55598diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
55599index 56123a6..5a2f6ec 100644
55600--- a/fs/proc/task_nommu.c
55601+++ b/fs/proc/task_nommu.c
55602@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
55603 else
55604 bytes += kobjsize(mm);
55605
55606- if (current->fs && current->fs->users > 1)
55607+ if (current->fs && atomic_read(&current->fs->users) > 1)
55608 sbytes += kobjsize(current->fs);
55609 else
55610 bytes += kobjsize(current->fs);
55611@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
55612
55613 if (file) {
55614 pad_len_spaces(m, len);
55615- seq_path(m, &file->f_path, "");
55616+ seq_path(m, &file->f_path, "\n\\");
55617 } else if (mm) {
55618 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
55619
55620diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
55621index b870f74..e9048df 100644
55622--- a/fs/proc/vmcore.c
55623+++ b/fs/proc/vmcore.c
55624@@ -98,9 +98,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
55625 nr_bytes = count;
55626
55627 /* If pfn is not ram, return zeros for sparse dump files */
55628- if (pfn_is_ram(pfn) == 0)
55629- memset(buf, 0, nr_bytes);
55630- else {
55631+ if (pfn_is_ram(pfn) == 0) {
55632+ if (userbuf) {
55633+ if (clear_user((char __force_user *)buf, nr_bytes))
55634+ return -EFAULT;
55635+ } else
55636+ memset(buf, 0, nr_bytes);
55637+ } else {
55638 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
55639 offset, userbuf);
55640 if (tmp < 0)
55641@@ -185,7 +189,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
55642 if (tsz > nr_bytes)
55643 tsz = nr_bytes;
55644
55645- tmp = read_from_oldmem(buffer, tsz, &start, 1);
55646+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, 1);
55647 if (tmp < 0)
55648 return tmp;
55649 buflen -= tsz;
55650diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
55651index b00fcc9..e0c6381 100644
55652--- a/fs/qnx6/qnx6.h
55653+++ b/fs/qnx6/qnx6.h
55654@@ -74,7 +74,7 @@ enum {
55655 BYTESEX_BE,
55656 };
55657
55658-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
55659+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
55660 {
55661 if (sbi->s_bytesex == BYTESEX_LE)
55662 return le64_to_cpu((__force __le64)n);
55663@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
55664 return (__force __fs64)cpu_to_be64(n);
55665 }
55666
55667-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
55668+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
55669 {
55670 if (sbi->s_bytesex == BYTESEX_LE)
55671 return le32_to_cpu((__force __le32)n);
55672diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
55673index 16e8abb..2dcf914 100644
55674--- a/fs/quota/netlink.c
55675+++ b/fs/quota/netlink.c
55676@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
55677 void quota_send_warning(struct kqid qid, dev_t dev,
55678 const char warntype)
55679 {
55680- static atomic_t seq;
55681+ static atomic_unchecked_t seq;
55682 struct sk_buff *skb;
55683 void *msg_head;
55684 int ret;
55685@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
55686 "VFS: Not enough memory to send quota warning.\n");
55687 return;
55688 }
55689- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
55690+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
55691 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
55692 if (!msg_head) {
55693 printk(KERN_ERR
55694diff --git a/fs/read_write.c b/fs/read_write.c
55695index e6ddc8d..9155227 100644
55696--- a/fs/read_write.c
55697+++ b/fs/read_write.c
55698@@ -429,7 +429,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
55699
55700 old_fs = get_fs();
55701 set_fs(get_ds());
55702- p = (__force const char __user *)buf;
55703+ p = (const char __force_user *)buf;
55704 if (count > MAX_RW_COUNT)
55705 count = MAX_RW_COUNT;
55706 if (file->f_op->write)
55707diff --git a/fs/readdir.c b/fs/readdir.c
55708index fee38e0..12fdf47 100644
55709--- a/fs/readdir.c
55710+++ b/fs/readdir.c
55711@@ -17,6 +17,7 @@
55712 #include <linux/security.h>
55713 #include <linux/syscalls.h>
55714 #include <linux/unistd.h>
55715+#include <linux/namei.h>
55716
55717 #include <asm/uaccess.h>
55718
55719@@ -67,6 +68,7 @@ struct old_linux_dirent {
55720
55721 struct readdir_callback {
55722 struct old_linux_dirent __user * dirent;
55723+ struct file * file;
55724 int result;
55725 };
55726
55727@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
55728 buf->result = -EOVERFLOW;
55729 return -EOVERFLOW;
55730 }
55731+
55732+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55733+ return 0;
55734+
55735 buf->result++;
55736 dirent = buf->dirent;
55737 if (!access_ok(VERIFY_WRITE, dirent,
55738@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
55739
55740 buf.result = 0;
55741 buf.dirent = dirent;
55742+ buf.file = f.file;
55743
55744 error = vfs_readdir(f.file, fillonedir, &buf);
55745 if (buf.result)
55746@@ -139,6 +146,7 @@ struct linux_dirent {
55747 struct getdents_callback {
55748 struct linux_dirent __user * current_dir;
55749 struct linux_dirent __user * previous;
55750+ struct file * file;
55751 int count;
55752 int error;
55753 };
55754@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
55755 buf->error = -EOVERFLOW;
55756 return -EOVERFLOW;
55757 }
55758+
55759+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55760+ return 0;
55761+
55762 dirent = buf->previous;
55763 if (dirent) {
55764 if (__put_user(offset, &dirent->d_off))
55765@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
55766 buf.previous = NULL;
55767 buf.count = count;
55768 buf.error = 0;
55769+ buf.file = f.file;
55770
55771 error = vfs_readdir(f.file, filldir, &buf);
55772 if (error >= 0)
55773@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
55774 struct getdents_callback64 {
55775 struct linux_dirent64 __user * current_dir;
55776 struct linux_dirent64 __user * previous;
55777+ struct file *file;
55778 int count;
55779 int error;
55780 };
55781@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
55782 buf->error = -EINVAL; /* only used if we fail.. */
55783 if (reclen > buf->count)
55784 return -EINVAL;
55785+
55786+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55787+ return 0;
55788+
55789 dirent = buf->previous;
55790 if (dirent) {
55791 if (__put_user(offset, &dirent->d_off))
55792@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
55793
55794 buf.current_dir = dirent;
55795 buf.previous = NULL;
55796+ buf.file = f.file;
55797 buf.count = count;
55798 buf.error = 0;
55799
55800@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
55801 error = buf.error;
55802 lastdirent = buf.previous;
55803 if (lastdirent) {
55804- typeof(lastdirent->d_off) d_off = f.file->f_pos;
55805+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
55806 if (__put_user(d_off, &lastdirent->d_off))
55807 error = -EFAULT;
55808 else
55809diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
55810index 2b7882b..1c5ef48 100644
55811--- a/fs/reiserfs/do_balan.c
55812+++ b/fs/reiserfs/do_balan.c
55813@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
55814 return;
55815 }
55816
55817- atomic_inc(&(fs_generation(tb->tb_sb)));
55818+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
55819 do_balance_starts(tb);
55820
55821 /* balance leaf returns 0 except if combining L R and S into
55822diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
55823index 9cc0740a..46bf953 100644
55824--- a/fs/reiserfs/procfs.c
55825+++ b/fs/reiserfs/procfs.c
55826@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
55827 "SMALL_TAILS " : "NO_TAILS ",
55828 replay_only(sb) ? "REPLAY_ONLY " : "",
55829 convert_reiserfs(sb) ? "CONV " : "",
55830- atomic_read(&r->s_generation_counter),
55831+ atomic_read_unchecked(&r->s_generation_counter),
55832 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
55833 SF(s_do_balance), SF(s_unneeded_left_neighbor),
55834 SF(s_good_search_by_key_reada), SF(s_bmaps),
55835diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
55836index 157e474..65a6114 100644
55837--- a/fs/reiserfs/reiserfs.h
55838+++ b/fs/reiserfs/reiserfs.h
55839@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
55840 /* Comment? -Hans */
55841 wait_queue_head_t s_wait;
55842 /* To be obsoleted soon by per buffer seals.. -Hans */
55843- atomic_t s_generation_counter; // increased by one every time the
55844+ atomic_unchecked_t s_generation_counter; // increased by one every time the
55845 // tree gets re-balanced
55846 unsigned long s_properties; /* File system properties. Currently holds
55847 on-disk FS format */
55848@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
55849 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
55850
55851 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
55852-#define get_generation(s) atomic_read (&fs_generation(s))
55853+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
55854 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
55855 #define __fs_changed(gen,s) (gen != get_generation (s))
55856 #define fs_changed(gen,s) \
55857diff --git a/fs/select.c b/fs/select.c
55858index 8c1c96c..a0f9b6d 100644
55859--- a/fs/select.c
55860+++ b/fs/select.c
55861@@ -20,6 +20,7 @@
55862 #include <linux/export.h>
55863 #include <linux/slab.h>
55864 #include <linux/poll.h>
55865+#include <linux/security.h>
55866 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
55867 #include <linux/file.h>
55868 #include <linux/fdtable.h>
55869@@ -827,6 +828,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
55870 struct poll_list *walk = head;
55871 unsigned long todo = nfds;
55872
55873+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
55874 if (nfds > rlimit(RLIMIT_NOFILE))
55875 return -EINVAL;
55876
55877diff --git a/fs/seq_file.c b/fs/seq_file.c
55878index 38bb59f..a304f9d 100644
55879--- a/fs/seq_file.c
55880+++ b/fs/seq_file.c
55881@@ -10,6 +10,7 @@
55882 #include <linux/seq_file.h>
55883 #include <linux/slab.h>
55884 #include <linux/cred.h>
55885+#include <linux/sched.h>
55886
55887 #include <asm/uaccess.h>
55888 #include <asm/page.h>
55889@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
55890 #ifdef CONFIG_USER_NS
55891 p->user_ns = file->f_cred->user_ns;
55892 #endif
55893+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55894+ p->exec_id = current->exec_id;
55895+#endif
55896
55897 /*
55898 * Wrappers around seq_open(e.g. swaps_open) need to be
55899@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
55900 return 0;
55901 }
55902 if (!m->buf) {
55903- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
55904+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
55905 if (!m->buf)
55906 return -ENOMEM;
55907 }
55908@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
55909 Eoverflow:
55910 m->op->stop(m, p);
55911 kfree(m->buf);
55912- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
55913+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
55914 return !m->buf ? -ENOMEM : -EAGAIN;
55915 }
55916
55917@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
55918
55919 /* grab buffer if we didn't have one */
55920 if (!m->buf) {
55921- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
55922+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
55923 if (!m->buf)
55924 goto Enomem;
55925 }
55926@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
55927 goto Fill;
55928 m->op->stop(m, p);
55929 kfree(m->buf);
55930- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
55931+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
55932 if (!m->buf)
55933 goto Enomem;
55934 m->count = 0;
55935@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
55936 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
55937 void *data)
55938 {
55939- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
55940+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
55941 int res = -ENOMEM;
55942
55943 if (op) {
55944diff --git a/fs/splice.c b/fs/splice.c
55945index 29e394e..b13c247 100644
55946--- a/fs/splice.c
55947+++ b/fs/splice.c
55948@@ -195,7 +195,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
55949 pipe_lock(pipe);
55950
55951 for (;;) {
55952- if (!pipe->readers) {
55953+ if (!atomic_read(&pipe->readers)) {
55954 send_sig(SIGPIPE, current, 0);
55955 if (!ret)
55956 ret = -EPIPE;
55957@@ -249,9 +249,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
55958 do_wakeup = 0;
55959 }
55960
55961- pipe->waiting_writers++;
55962+ atomic_inc(&pipe->waiting_writers);
55963 pipe_wait(pipe);
55964- pipe->waiting_writers--;
55965+ atomic_dec(&pipe->waiting_writers);
55966 }
55967
55968 pipe_unlock(pipe);
55969@@ -564,7 +564,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
55970 old_fs = get_fs();
55971 set_fs(get_ds());
55972 /* The cast to a user pointer is valid due to the set_fs() */
55973- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
55974+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
55975 set_fs(old_fs);
55976
55977 return res;
55978@@ -579,7 +579,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
55979 old_fs = get_fs();
55980 set_fs(get_ds());
55981 /* The cast to a user pointer is valid due to the set_fs() */
55982- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
55983+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
55984 set_fs(old_fs);
55985
55986 return res;
55987@@ -632,7 +632,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
55988 goto err;
55989
55990 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
55991- vec[i].iov_base = (void __user *) page_address(page);
55992+ vec[i].iov_base = (void __force_user *) page_address(page);
55993 vec[i].iov_len = this_len;
55994 spd.pages[i] = page;
55995 spd.nr_pages++;
55996@@ -853,10 +853,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
55997 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
55998 {
55999 while (!pipe->nrbufs) {
56000- if (!pipe->writers)
56001+ if (!atomic_read(&pipe->writers))
56002 return 0;
56003
56004- if (!pipe->waiting_writers && sd->num_spliced)
56005+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
56006 return 0;
56007
56008 if (sd->flags & SPLICE_F_NONBLOCK)
56009@@ -1192,7 +1192,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
56010 * out of the pipe right after the splice_to_pipe(). So set
56011 * PIPE_READERS appropriately.
56012 */
56013- pipe->readers = 1;
56014+ atomic_set(&pipe->readers, 1);
56015
56016 current->splice_pipe = pipe;
56017 }
56018@@ -1741,9 +1741,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56019 ret = -ERESTARTSYS;
56020 break;
56021 }
56022- if (!pipe->writers)
56023+ if (!atomic_read(&pipe->writers))
56024 break;
56025- if (!pipe->waiting_writers) {
56026+ if (!atomic_read(&pipe->waiting_writers)) {
56027 if (flags & SPLICE_F_NONBLOCK) {
56028 ret = -EAGAIN;
56029 break;
56030@@ -1775,7 +1775,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56031 pipe_lock(pipe);
56032
56033 while (pipe->nrbufs >= pipe->buffers) {
56034- if (!pipe->readers) {
56035+ if (!atomic_read(&pipe->readers)) {
56036 send_sig(SIGPIPE, current, 0);
56037 ret = -EPIPE;
56038 break;
56039@@ -1788,9 +1788,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56040 ret = -ERESTARTSYS;
56041 break;
56042 }
56043- pipe->waiting_writers++;
56044+ atomic_inc(&pipe->waiting_writers);
56045 pipe_wait(pipe);
56046- pipe->waiting_writers--;
56047+ atomic_dec(&pipe->waiting_writers);
56048 }
56049
56050 pipe_unlock(pipe);
56051@@ -1826,14 +1826,14 @@ retry:
56052 pipe_double_lock(ipipe, opipe);
56053
56054 do {
56055- if (!opipe->readers) {
56056+ if (!atomic_read(&opipe->readers)) {
56057 send_sig(SIGPIPE, current, 0);
56058 if (!ret)
56059 ret = -EPIPE;
56060 break;
56061 }
56062
56063- if (!ipipe->nrbufs && !ipipe->writers)
56064+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
56065 break;
56066
56067 /*
56068@@ -1930,7 +1930,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
56069 pipe_double_lock(ipipe, opipe);
56070
56071 do {
56072- if (!opipe->readers) {
56073+ if (!atomic_read(&opipe->readers)) {
56074 send_sig(SIGPIPE, current, 0);
56075 if (!ret)
56076 ret = -EPIPE;
56077@@ -1975,7 +1975,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
56078 * return EAGAIN if we have the potential of some data in the
56079 * future, otherwise just return 0
56080 */
56081- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
56082+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
56083 ret = -EAGAIN;
56084
56085 pipe_unlock(ipipe);
56086diff --git a/fs/stat.c b/fs/stat.c
56087index 04ce1ac..a13dd1e 100644
56088--- a/fs/stat.c
56089+++ b/fs/stat.c
56090@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
56091 stat->gid = inode->i_gid;
56092 stat->rdev = inode->i_rdev;
56093 stat->size = i_size_read(inode);
56094- stat->atime = inode->i_atime;
56095- stat->mtime = inode->i_mtime;
56096+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
56097+ stat->atime = inode->i_ctime;
56098+ stat->mtime = inode->i_ctime;
56099+ } else {
56100+ stat->atime = inode->i_atime;
56101+ stat->mtime = inode->i_mtime;
56102+ }
56103 stat->ctime = inode->i_ctime;
56104 stat->blksize = (1 << inode->i_blkbits);
56105 stat->blocks = inode->i_blocks;
56106@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
56107 if (retval)
56108 return retval;
56109
56110- if (inode->i_op->getattr)
56111- return inode->i_op->getattr(path->mnt, path->dentry, stat);
56112+ if (inode->i_op->getattr) {
56113+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
56114+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
56115+ stat->atime = stat->ctime;
56116+ stat->mtime = stat->ctime;
56117+ }
56118+ return retval;
56119+ }
56120
56121 generic_fillattr(inode, stat);
56122 return 0;
56123diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
56124index 15c68f9..36a8b3e 100644
56125--- a/fs/sysfs/bin.c
56126+++ b/fs/sysfs/bin.c
56127@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
56128 return ret;
56129 }
56130
56131-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
56132- void *buf, int len, int write)
56133+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
56134+ void *buf, size_t len, int write)
56135 {
56136 struct file *file = vma->vm_file;
56137 struct bin_buffer *bb = file->private_data;
56138 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
56139- int ret;
56140+ ssize_t ret;
56141
56142 if (!bb->vm_ops)
56143 return -EINVAL;
56144diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
56145index 6f31590..3c87c8a 100644
56146--- a/fs/sysfs/dir.c
56147+++ b/fs/sysfs/dir.c
56148@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
56149 *
56150 * Returns 31 bit hash of ns + name (so it fits in an off_t )
56151 */
56152-static unsigned int sysfs_name_hash(const void *ns, const char *name)
56153+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
56154 {
56155 unsigned long hash = init_name_hash();
56156 unsigned int len = strlen(name);
56157@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
56158 struct sysfs_dirent *sd;
56159 int rc;
56160
56161+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
56162+ const char *parent_name = parent_sd->s_name;
56163+
56164+ mode = S_IFDIR | S_IRWXU;
56165+
56166+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
56167+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
56168+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
56169+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
56170+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
56171+#endif
56172+
56173 /* allocate */
56174 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
56175 if (!sd)
56176diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
56177index 602f56d..6853db8 100644
56178--- a/fs/sysfs/file.c
56179+++ b/fs/sysfs/file.c
56180@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
56181
56182 struct sysfs_open_dirent {
56183 atomic_t refcnt;
56184- atomic_t event;
56185+ atomic_unchecked_t event;
56186 wait_queue_head_t poll;
56187 struct list_head buffers; /* goes through sysfs_buffer.list */
56188 };
56189@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
56190 if (!sysfs_get_active(attr_sd))
56191 return -ENODEV;
56192
56193- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
56194+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
56195 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
56196
56197 sysfs_put_active(attr_sd);
56198@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
56199 return -ENOMEM;
56200
56201 atomic_set(&new_od->refcnt, 0);
56202- atomic_set(&new_od->event, 1);
56203+ atomic_set_unchecked(&new_od->event, 1);
56204 init_waitqueue_head(&new_od->poll);
56205 INIT_LIST_HEAD(&new_od->buffers);
56206 goto retry;
56207@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
56208
56209 sysfs_put_active(attr_sd);
56210
56211- if (buffer->event != atomic_read(&od->event))
56212+ if (buffer->event != atomic_read_unchecked(&od->event))
56213 goto trigger;
56214
56215 return DEFAULT_POLLMASK;
56216@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
56217
56218 od = sd->s_attr.open;
56219 if (od) {
56220- atomic_inc(&od->event);
56221+ atomic_inc_unchecked(&od->event);
56222 wake_up_interruptible(&od->poll);
56223 }
56224
56225diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
56226index 8c940df..25b733e 100644
56227--- a/fs/sysfs/symlink.c
56228+++ b/fs/sysfs/symlink.c
56229@@ -305,7 +305,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
56230
56231 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
56232 {
56233- char *page = nd_get_link(nd);
56234+ const char *page = nd_get_link(nd);
56235 if (!IS_ERR(page))
56236 free_page((unsigned long)page);
56237 }
56238diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
56239index 69d4889..a810bd4 100644
56240--- a/fs/sysv/sysv.h
56241+++ b/fs/sysv/sysv.h
56242@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
56243 #endif
56244 }
56245
56246-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
56247+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
56248 {
56249 if (sbi->s_bytesex == BYTESEX_PDP)
56250 return PDP_swab((__force __u32)n);
56251diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
56252index e18b988..f1d4ad0f 100644
56253--- a/fs/ubifs/io.c
56254+++ b/fs/ubifs/io.c
56255@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
56256 return err;
56257 }
56258
56259-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
56260+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
56261 {
56262 int err;
56263
56264diff --git a/fs/udf/misc.c b/fs/udf/misc.c
56265index c175b4d..8f36a16 100644
56266--- a/fs/udf/misc.c
56267+++ b/fs/udf/misc.c
56268@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
56269
56270 u8 udf_tag_checksum(const struct tag *t)
56271 {
56272- u8 *data = (u8 *)t;
56273+ const u8 *data = (const u8 *)t;
56274 u8 checksum = 0;
56275 int i;
56276 for (i = 0; i < sizeof(struct tag); ++i)
56277diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
56278index 8d974c4..b82f6ec 100644
56279--- a/fs/ufs/swab.h
56280+++ b/fs/ufs/swab.h
56281@@ -22,7 +22,7 @@ enum {
56282 BYTESEX_BE
56283 };
56284
56285-static inline u64
56286+static inline u64 __intentional_overflow(-1)
56287 fs64_to_cpu(struct super_block *sbp, __fs64 n)
56288 {
56289 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
56290@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
56291 return (__force __fs64)cpu_to_be64(n);
56292 }
56293
56294-static inline u32
56295+static inline u32 __intentional_overflow(-1)
56296 fs32_to_cpu(struct super_block *sbp, __fs32 n)
56297 {
56298 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
56299diff --git a/fs/utimes.c b/fs/utimes.c
56300index f4fb7ec..3fe03c0 100644
56301--- a/fs/utimes.c
56302+++ b/fs/utimes.c
56303@@ -1,6 +1,7 @@
56304 #include <linux/compiler.h>
56305 #include <linux/file.h>
56306 #include <linux/fs.h>
56307+#include <linux/security.h>
56308 #include <linux/linkage.h>
56309 #include <linux/mount.h>
56310 #include <linux/namei.h>
56311@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
56312 goto mnt_drop_write_and_out;
56313 }
56314 }
56315+
56316+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
56317+ error = -EACCES;
56318+ goto mnt_drop_write_and_out;
56319+ }
56320+
56321 mutex_lock(&inode->i_mutex);
56322 error = notify_change(path->dentry, &newattrs);
56323 mutex_unlock(&inode->i_mutex);
56324diff --git a/fs/xattr.c b/fs/xattr.c
56325index 3377dff..4d074d9 100644
56326--- a/fs/xattr.c
56327+++ b/fs/xattr.c
56328@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
56329 return rc;
56330 }
56331
56332+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56333+ssize_t
56334+pax_getxattr(struct dentry *dentry, void *value, size_t size)
56335+{
56336+ struct inode *inode = dentry->d_inode;
56337+ ssize_t error;
56338+
56339+ error = inode_permission(inode, MAY_EXEC);
56340+ if (error)
56341+ return error;
56342+
56343+ if (inode->i_op->getxattr)
56344+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
56345+ else
56346+ error = -EOPNOTSUPP;
56347+
56348+ return error;
56349+}
56350+EXPORT_SYMBOL(pax_getxattr);
56351+#endif
56352+
56353 ssize_t
56354 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
56355 {
56356@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
56357 * Extended attribute SET operations
56358 */
56359 static long
56360-setxattr(struct dentry *d, const char __user *name, const void __user *value,
56361+setxattr(struct path *path, const char __user *name, const void __user *value,
56362 size_t size, int flags)
56363 {
56364 int error;
56365@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
56366 posix_acl_fix_xattr_from_user(kvalue, size);
56367 }
56368
56369- error = vfs_setxattr(d, kname, kvalue, size, flags);
56370+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
56371+ error = -EACCES;
56372+ goto out;
56373+ }
56374+
56375+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
56376 out:
56377 if (vvalue)
56378 vfree(vvalue);
56379@@ -377,7 +403,7 @@ retry:
56380 return error;
56381 error = mnt_want_write(path.mnt);
56382 if (!error) {
56383- error = setxattr(path.dentry, name, value, size, flags);
56384+ error = setxattr(&path, name, value, size, flags);
56385 mnt_drop_write(path.mnt);
56386 }
56387 path_put(&path);
56388@@ -401,7 +427,7 @@ retry:
56389 return error;
56390 error = mnt_want_write(path.mnt);
56391 if (!error) {
56392- error = setxattr(path.dentry, name, value, size, flags);
56393+ error = setxattr(&path, name, value, size, flags);
56394 mnt_drop_write(path.mnt);
56395 }
56396 path_put(&path);
56397@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
56398 const void __user *,value, size_t, size, int, flags)
56399 {
56400 struct fd f = fdget(fd);
56401- struct dentry *dentry;
56402 int error = -EBADF;
56403
56404 if (!f.file)
56405 return error;
56406- dentry = f.file->f_path.dentry;
56407- audit_inode(NULL, dentry, 0);
56408+ audit_inode(NULL, f.file->f_path.dentry, 0);
56409 error = mnt_want_write_file(f.file);
56410 if (!error) {
56411- error = setxattr(dentry, name, value, size, flags);
56412+ error = setxattr(&f.file->f_path, name, value, size, flags);
56413 mnt_drop_write_file(f.file);
56414 }
56415 fdput(f);
56416diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
56417index 9fbea87..6b19972 100644
56418--- a/fs/xattr_acl.c
56419+++ b/fs/xattr_acl.c
56420@@ -76,8 +76,8 @@ struct posix_acl *
56421 posix_acl_from_xattr(struct user_namespace *user_ns,
56422 const void *value, size_t size)
56423 {
56424- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
56425- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
56426+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
56427+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
56428 int count;
56429 struct posix_acl *acl;
56430 struct posix_acl_entry *acl_e;
56431diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
56432index b44af92..06073da 100644
56433--- a/fs/xfs/xfs_bmap.c
56434+++ b/fs/xfs/xfs_bmap.c
56435@@ -192,7 +192,7 @@ xfs_bmap_validate_ret(
56436 int nmap,
56437 int ret_nmap);
56438 #else
56439-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
56440+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
56441 #endif /* DEBUG */
56442
56443 STATIC int
56444diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
56445index 1b9fc3e..e1bdde0 100644
56446--- a/fs/xfs/xfs_dir2_sf.c
56447+++ b/fs/xfs/xfs_dir2_sf.c
56448@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
56449 }
56450
56451 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
56452- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
56453+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
56454+ char name[sfep->namelen];
56455+ memcpy(name, sfep->name, sfep->namelen);
56456+ if (filldir(dirent, name, sfep->namelen,
56457+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
56458+ *offset = off & 0x7fffffff;
56459+ return 0;
56460+ }
56461+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
56462 off & 0x7fffffff, ino, DT_UNKNOWN)) {
56463 *offset = off & 0x7fffffff;
56464 return 0;
56465diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
56466index d681e34..2a3f5ab 100644
56467--- a/fs/xfs/xfs_ioctl.c
56468+++ b/fs/xfs/xfs_ioctl.c
56469@@ -127,7 +127,7 @@ xfs_find_handle(
56470 }
56471
56472 error = -EFAULT;
56473- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
56474+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
56475 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
56476 goto out_put;
56477
56478diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
56479index ca9ecaa..60100c7 100644
56480--- a/fs/xfs/xfs_iops.c
56481+++ b/fs/xfs/xfs_iops.c
56482@@ -395,7 +395,7 @@ xfs_vn_put_link(
56483 struct nameidata *nd,
56484 void *p)
56485 {
56486- char *s = nd_get_link(nd);
56487+ const char *s = nd_get_link(nd);
56488
56489 if (!IS_ERR(s))
56490 kfree(s);
56491diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
56492new file mode 100644
56493index 0000000..ba9c5e3
56494--- /dev/null
56495+++ b/grsecurity/Kconfig
56496@@ -0,0 +1,1053 @@
56497+#
56498+# grecurity configuration
56499+#
56500+menu "Memory Protections"
56501+depends on GRKERNSEC
56502+
56503+config GRKERNSEC_KMEM
56504+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
56505+ default y if GRKERNSEC_CONFIG_AUTO
56506+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
56507+ help
56508+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
56509+ be written to or read from to modify or leak the contents of the running
56510+ kernel. /dev/port will also not be allowed to be opened and support
56511+ for /dev/cpu/*/msr will be removed. If you have module
56512+ support disabled, enabling this will close up five ways that are
56513+ currently used to insert malicious code into the running kernel.
56514+
56515+ Even with all these features enabled, we still highly recommend that
56516+ you use the RBAC system, as it is still possible for an attacker to
56517+ modify the running kernel through privileged I/O granted by ioperm/iopl.
56518+
56519+ If you are not using XFree86, you may be able to stop this additional
56520+ case by enabling the 'Disable privileged I/O' option. Though nothing
56521+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
56522+ but only to video memory, which is the only writing we allow in this
56523+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
56524+ not be allowed to mprotect it with PROT_WRITE later.
56525+ Enabling this feature will prevent the "cpupower" and "powertop" tools
56526+ from working.
56527+
56528+ It is highly recommended that you say Y here if you meet all the
56529+ conditions above.
56530+
56531+config GRKERNSEC_VM86
56532+ bool "Restrict VM86 mode"
56533+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
56534+ depends on X86_32
56535+
56536+ help
56537+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
56538+ make use of a special execution mode on 32bit x86 processors called
56539+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
56540+ video cards and will still work with this option enabled. The purpose
56541+ of the option is to prevent exploitation of emulation errors in
56542+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
56543+ Nearly all users should be able to enable this option.
56544+
56545+config GRKERNSEC_IO
56546+ bool "Disable privileged I/O"
56547+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
56548+ depends on X86
56549+ select RTC_CLASS
56550+ select RTC_INTF_DEV
56551+ select RTC_DRV_CMOS
56552+
56553+ help
56554+ If you say Y here, all ioperm and iopl calls will return an error.
56555+ Ioperm and iopl can be used to modify the running kernel.
56556+ Unfortunately, some programs need this access to operate properly,
56557+ the most notable of which are XFree86 and hwclock. hwclock can be
56558+ remedied by having RTC support in the kernel, so real-time
56559+ clock support is enabled if this option is enabled, to ensure
56560+ that hwclock operates correctly. XFree86 still will not
56561+ operate correctly with this option enabled, so DO NOT CHOOSE Y
56562+ IF YOU USE XFree86. If you use XFree86 and you still want to
56563+ protect your kernel against modification, use the RBAC system.
56564+
56565+config GRKERNSEC_JIT_HARDEN
56566+ bool "Harden BPF JIT against spray attacks"
56567+ default y if GRKERNSEC_CONFIG_AUTO
56568+ depends on BPF_JIT
56569+ help
56570+ If you say Y here, the native code generated by the kernel's Berkeley
56571+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
56572+ attacks that attempt to fit attacker-beneficial instructions in
56573+ 32bit immediate fields of JIT-generated native instructions. The
56574+ attacker will generally aim to cause an unintended instruction sequence
56575+ of JIT-generated native code to execute by jumping into the middle of
56576+ a generated instruction. This feature effectively randomizes the 32bit
56577+ immediate constants present in the generated code to thwart such attacks.
56578+
56579+ If you're using KERNEXEC, it's recommended that you enable this option
56580+ to supplement the hardening of the kernel.
56581+
56582+config GRKERNSEC_PERF_HARDEN
56583+ bool "Disable unprivileged PERF_EVENTS usage by default"
56584+ default y if GRKERNSEC_CONFIG_AUTO
56585+ depends on PERF_EVENTS
56586+ help
56587+ If you say Y here, the range of acceptable values for the
56588+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
56589+ default to a new value: 3. When the sysctl is set to this value, no
56590+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
56591+
56592+ Though PERF_EVENTS can be used legitimately for performance monitoring
56593+ and low-level application profiling, it is forced on regardless of
56594+ configuration, has been at fault for several vulnerabilities, and
56595+ creates new opportunities for side channels and other information leaks.
56596+
56597+ This feature puts PERF_EVENTS into a secure default state and permits
56598+ the administrator to change out of it temporarily if unprivileged
56599+ application profiling is needed.
56600+
56601+config GRKERNSEC_RAND_THREADSTACK
56602+ bool "Insert random gaps between thread stacks"
56603+ default y if GRKERNSEC_CONFIG_AUTO
56604+ depends on PAX_RANDMMAP && !PPC && BROKEN
56605+ help
56606+ If you say Y here, a random-sized gap will be enforced between allocated
56607+ thread stacks. Glibc's NPTL and other threading libraries that
56608+ pass MAP_STACK to the kernel for thread stack allocation are supported.
56609+ The implementation currently provides 8 bits of entropy for the gap.
56610+
56611+ Many distributions do not compile threaded remote services with the
56612+ -fstack-check argument to GCC, causing the variable-sized stack-based
56613+ allocator, alloca(), to not probe the stack on allocation. This
56614+ permits an unbounded alloca() to skip over any guard page and potentially
56615+ modify another thread's stack reliably. An enforced random gap
56616+ reduces the reliability of such an attack and increases the chance
56617+ that such a read/write to another thread's stack instead lands in
56618+ an unmapped area, causing a crash and triggering grsecurity's
56619+ anti-bruteforcing logic.
56620+
56621+config GRKERNSEC_PROC_MEMMAP
56622+ bool "Harden ASLR against information leaks and entropy reduction"
56623+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
56624+ depends on PAX_NOEXEC || PAX_ASLR
56625+ help
56626+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
56627+ give no information about the addresses of its mappings if
56628+ PaX features that rely on random addresses are enabled on the task.
56629+ In addition to sanitizing this information and disabling other
56630+ dangerous sources of information, this option causes reads of sensitive
56631+ /proc/<pid> entries where the file descriptor was opened in a different
56632+ task than the one performing the read. Such attempts are logged.
56633+ This option also limits argv/env strings for suid/sgid binaries
56634+ to 512KB to prevent a complete exhaustion of the stack entropy provided
56635+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
56636+ binaries to prevent alternative mmap layouts from being abused.
56637+
56638+ If you use PaX it is essential that you say Y here as it closes up
56639+ several holes that make full ASLR useless locally.
56640+
56641+config GRKERNSEC_BRUTE
56642+ bool "Deter exploit bruteforcing"
56643+ default y if GRKERNSEC_CONFIG_AUTO
56644+ help
56645+ If you say Y here, attempts to bruteforce exploits against forking
56646+ daemons such as apache or sshd, as well as against suid/sgid binaries
56647+ will be deterred. When a child of a forking daemon is killed by PaX
56648+ or crashes due to an illegal instruction or other suspicious signal,
56649+ the parent process will be delayed 30 seconds upon every subsequent
56650+ fork until the administrator is able to assess the situation and
56651+ restart the daemon.
56652+ In the suid/sgid case, the attempt is logged, the user has all their
56653+ processes terminated, and they are prevented from executing any further
56654+ processes for 15 minutes.
56655+ It is recommended that you also enable signal logging in the auditing
56656+ section so that logs are generated when a process triggers a suspicious
56657+ signal.
56658+ If the sysctl option is enabled, a sysctl option with name
56659+ "deter_bruteforce" is created.
56660+
56661+
56662+config GRKERNSEC_MODHARDEN
56663+ bool "Harden module auto-loading"
56664+ default y if GRKERNSEC_CONFIG_AUTO
56665+ depends on MODULES
56666+ help
56667+ If you say Y here, module auto-loading in response to use of some
56668+ feature implemented by an unloaded module will be restricted to
56669+ root users. Enabling this option helps defend against attacks
56670+ by unprivileged users who abuse the auto-loading behavior to
56671+ cause a vulnerable module to load that is then exploited.
56672+
56673+ If this option prevents a legitimate use of auto-loading for a
56674+ non-root user, the administrator can execute modprobe manually
56675+ with the exact name of the module mentioned in the alert log.
56676+ Alternatively, the administrator can add the module to the list
56677+ of modules loaded at boot by modifying init scripts.
56678+
56679+ Modification of init scripts will most likely be needed on
56680+ Ubuntu servers with encrypted home directory support enabled,
56681+ as the first non-root user logging in will cause the ecb(aes),
56682+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
56683+
56684+config GRKERNSEC_HIDESYM
56685+ bool "Hide kernel symbols"
56686+ default y if GRKERNSEC_CONFIG_AUTO
56687+ select PAX_USERCOPY_SLABS
56688+ help
56689+ If you say Y here, getting information on loaded modules, and
56690+ displaying all kernel symbols through a syscall will be restricted
56691+ to users with CAP_SYS_MODULE. For software compatibility reasons,
56692+ /proc/kallsyms will be restricted to the root user. The RBAC
56693+ system can hide that entry even from root.
56694+
56695+ This option also prevents leaking of kernel addresses through
56696+ several /proc entries.
56697+
56698+ Note that this option is only effective provided the following
56699+ conditions are met:
56700+ 1) The kernel using grsecurity is not precompiled by some distribution
56701+ 2) You have also enabled GRKERNSEC_DMESG
56702+ 3) You are using the RBAC system and hiding other files such as your
56703+ kernel image and System.map. Alternatively, enabling this option
56704+ causes the permissions on /boot, /lib/modules, and the kernel
56705+ source directory to change at compile time to prevent
56706+ reading by non-root users.
56707+ If the above conditions are met, this option will aid in providing a
56708+ useful protection against local kernel exploitation of overflows
56709+ and arbitrary read/write vulnerabilities.
56710+
56711+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
56712+ in addition to this feature.
56713+
56714+config GRKERNSEC_KERN_LOCKOUT
56715+ bool "Active kernel exploit response"
56716+ default y if GRKERNSEC_CONFIG_AUTO
56717+ depends on X86 || ARM || PPC || SPARC
56718+ help
56719+ If you say Y here, when a PaX alert is triggered due to suspicious
56720+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
56721+ or an OOPS occurs due to bad memory accesses, instead of just
56722+ terminating the offending process (and potentially allowing
56723+ a subsequent exploit from the same user), we will take one of two
56724+ actions:
56725+ If the user was root, we will panic the system
56726+ If the user was non-root, we will log the attempt, terminate
56727+ all processes owned by the user, then prevent them from creating
56728+ any new processes until the system is restarted
56729+ This deters repeated kernel exploitation/bruteforcing attempts
56730+ and is useful for later forensics.
56731+
56732+endmenu
56733+menu "Role Based Access Control Options"
56734+depends on GRKERNSEC
56735+
56736+config GRKERNSEC_RBAC_DEBUG
56737+ bool
56738+
56739+config GRKERNSEC_NO_RBAC
56740+ bool "Disable RBAC system"
56741+ help
56742+ If you say Y here, the /dev/grsec device will be removed from the kernel,
56743+ preventing the RBAC system from being enabled. You should only say Y
56744+ here if you have no intention of using the RBAC system, so as to prevent
56745+ an attacker with root access from misusing the RBAC system to hide files
56746+ and processes when loadable module support and /dev/[k]mem have been
56747+ locked down.
56748+
56749+config GRKERNSEC_ACL_HIDEKERN
56750+ bool "Hide kernel processes"
56751+ help
56752+ If you say Y here, all kernel threads will be hidden to all
56753+ processes but those whose subject has the "view hidden processes"
56754+ flag.
56755+
56756+config GRKERNSEC_ACL_MAXTRIES
56757+ int "Maximum tries before password lockout"
56758+ default 3
56759+ help
56760+ This option enforces the maximum number of times a user can attempt
56761+ to authorize themselves with the grsecurity RBAC system before being
56762+ denied the ability to attempt authorization again for a specified time.
56763+ The lower the number, the harder it will be to brute-force a password.
56764+
56765+config GRKERNSEC_ACL_TIMEOUT
56766+ int "Time to wait after max password tries, in seconds"
56767+ default 30
56768+ help
56769+ This option specifies the time the user must wait after attempting to
56770+ authorize to the RBAC system with the maximum number of invalid
56771+ passwords. The higher the number, the harder it will be to brute-force
56772+ a password.
56773+
56774+endmenu
56775+menu "Filesystem Protections"
56776+depends on GRKERNSEC
56777+
56778+config GRKERNSEC_PROC
56779+ bool "Proc restrictions"
56780+ default y if GRKERNSEC_CONFIG_AUTO
56781+ help
56782+ If you say Y here, the permissions of the /proc filesystem
56783+ will be altered to enhance system security and privacy. You MUST
56784+ choose either a user only restriction or a user and group restriction.
56785+ Depending upon the option you choose, you can either restrict users to
56786+ see only the processes they themselves run, or choose a group that can
56787+ view all processes and files normally restricted to root if you choose
56788+ the "restrict to user only" option. NOTE: If you're running identd or
56789+ ntpd as a non-root user, you will have to run it as the group you
56790+ specify here.
56791+
56792+config GRKERNSEC_PROC_USER
56793+ bool "Restrict /proc to user only"
56794+ depends on GRKERNSEC_PROC
56795+ help
56796+ If you say Y here, non-root users will only be able to view their own
56797+ processes, and restricts them from viewing network-related information,
56798+ and viewing kernel symbol and module information.
56799+
56800+config GRKERNSEC_PROC_USERGROUP
56801+ bool "Allow special group"
56802+ default y if GRKERNSEC_CONFIG_AUTO
56803+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
56804+ help
56805+ If you say Y here, you will be able to select a group that will be
56806+ able to view all processes and network-related information. If you've
56807+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
56808+ remain hidden. This option is useful if you want to run identd as
56809+ a non-root user. The group you select may also be chosen at boot time
56810+ via "grsec_proc_gid=" on the kernel commandline.
56811+
56812+config GRKERNSEC_PROC_GID
56813+ int "GID for special group"
56814+ depends on GRKERNSEC_PROC_USERGROUP
56815+ default 1001
56816+
56817+config GRKERNSEC_PROC_ADD
56818+ bool "Additional restrictions"
56819+ default y if GRKERNSEC_CONFIG_AUTO
56820+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
56821+ help
56822+ If you say Y here, additional restrictions will be placed on
56823+ /proc that keep normal users from viewing device information and
56824+ slabinfo information that could be useful for exploits.
56825+
56826+config GRKERNSEC_LINK
56827+ bool "Linking restrictions"
56828+ default y if GRKERNSEC_CONFIG_AUTO
56829+ help
56830+ If you say Y here, /tmp race exploits will be prevented, since users
56831+ will no longer be able to follow symlinks owned by other users in
56832+ world-writable +t directories (e.g. /tmp), unless the owner of the
56833+ symlink is the owner of the directory. users will also not be
56834+ able to hardlink to files they do not own. If the sysctl option is
56835+ enabled, a sysctl option with name "linking_restrictions" is created.
56836+
56837+config GRKERNSEC_SYMLINKOWN
56838+ bool "Kernel-enforced SymlinksIfOwnerMatch"
56839+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
56840+ help
56841+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
56842+ that prevents it from being used as a security feature. As Apache
56843+ verifies the symlink by performing a stat() against the target of
56844+ the symlink before it is followed, an attacker can setup a symlink
56845+ to point to a same-owned file, then replace the symlink with one
56846+ that targets another user's file just after Apache "validates" the
56847+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
56848+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
56849+ will be in place for the group you specify. If the sysctl option
56850+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
56851+ created.
56852+
56853+config GRKERNSEC_SYMLINKOWN_GID
56854+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
56855+ depends on GRKERNSEC_SYMLINKOWN
56856+ default 1006
56857+ help
56858+ Setting this GID determines what group kernel-enforced
56859+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
56860+ is enabled, a sysctl option with name "symlinkown_gid" is created.
56861+
56862+config GRKERNSEC_FIFO
56863+ bool "FIFO restrictions"
56864+ default y if GRKERNSEC_CONFIG_AUTO
56865+ help
56866+ If you say Y here, users will not be able to write to FIFOs they don't
56867+ own in world-writable +t directories (e.g. /tmp), unless the owner of
56868+ the FIFO is the same owner of the directory it's held in. If the sysctl
56869+ option is enabled, a sysctl option with name "fifo_restrictions" is
56870+ created.
56871+
56872+config GRKERNSEC_SYSFS_RESTRICT
56873+ bool "Sysfs/debugfs restriction"
56874+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
56875+ depends on SYSFS
56876+ help
56877+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
56878+ any filesystem normally mounted under it (e.g. debugfs) will be
56879+ mostly accessible only by root. These filesystems generally provide access
56880+ to hardware and debug information that isn't appropriate for unprivileged
56881+ users of the system. Sysfs and debugfs have also become a large source
56882+ of new vulnerabilities, ranging from infoleaks to local compromise.
56883+ There has been very little oversight with an eye toward security involved
56884+ in adding new exporters of information to these filesystems, so their
56885+ use is discouraged.
56886+ For reasons of compatibility, a few directories have been whitelisted
56887+ for access by non-root users:
56888+ /sys/fs/selinux
56889+ /sys/fs/fuse
56890+ /sys/devices/system/cpu
56891+
56892+config GRKERNSEC_ROFS
56893+ bool "Runtime read-only mount protection"
56894+ help
56895+ If you say Y here, a sysctl option with name "romount_protect" will
56896+ be created. By setting this option to 1 at runtime, filesystems
56897+ will be protected in the following ways:
56898+ * No new writable mounts will be allowed
56899+ * Existing read-only mounts won't be able to be remounted read/write
56900+ * Write operations will be denied on all block devices
56901+ This option acts independently of grsec_lock: once it is set to 1,
56902+ it cannot be turned off. Therefore, please be mindful of the resulting
56903+ behavior if this option is enabled in an init script on a read-only
56904+ filesystem. This feature is mainly intended for secure embedded systems.
56905+
56906+config GRKERNSEC_DEVICE_SIDECHANNEL
56907+ bool "Eliminate stat/notify-based device sidechannels"
56908+ default y if GRKERNSEC_CONFIG_AUTO
56909+ help
56910+ If you say Y here, timing analyses on block or character
56911+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
56912+ will be thwarted for unprivileged users. If a process without
56913+ CAP_MKNOD stats such a device, the last access and last modify times
56914+ will match the device's create time. No access or modify events
56915+ will be triggered through inotify/dnotify/fanotify for such devices.
56916+ This feature will prevent attacks that may at a minimum
56917+ allow an attacker to determine the administrator's password length.
56918+
56919+config GRKERNSEC_CHROOT
56920+ bool "Chroot jail restrictions"
56921+ default y if GRKERNSEC_CONFIG_AUTO
56922+ help
56923+ If you say Y here, you will be able to choose several options that will
56924+ make breaking out of a chrooted jail much more difficult. If you
56925+ encounter no software incompatibilities with the following options, it
56926+ is recommended that you enable each one.
56927+
56928+config GRKERNSEC_CHROOT_MOUNT
56929+ bool "Deny mounts"
56930+ default y if GRKERNSEC_CONFIG_AUTO
56931+ depends on GRKERNSEC_CHROOT
56932+ help
56933+ If you say Y here, processes inside a chroot will not be able to
56934+ mount or remount filesystems. If the sysctl option is enabled, a
56935+ sysctl option with name "chroot_deny_mount" is created.
56936+
56937+config GRKERNSEC_CHROOT_DOUBLE
56938+ bool "Deny double-chroots"
56939+ default y if GRKERNSEC_CONFIG_AUTO
56940+ depends on GRKERNSEC_CHROOT
56941+ help
56942+ If you say Y here, processes inside a chroot will not be able to chroot
56943+ again outside the chroot. This is a widely used method of breaking
56944+ out of a chroot jail and should not be allowed. If the sysctl
56945+ option is enabled, a sysctl option with name
56946+ "chroot_deny_chroot" is created.
56947+
56948+config GRKERNSEC_CHROOT_PIVOT
56949+ bool "Deny pivot_root in chroot"
56950+ default y if GRKERNSEC_CONFIG_AUTO
56951+ depends on GRKERNSEC_CHROOT
56952+ help
56953+ If you say Y here, processes inside a chroot will not be able to use
56954+ a function called pivot_root() that was introduced in Linux 2.3.41. It
56955+ works similar to chroot in that it changes the root filesystem. This
56956+ function could be misused in a chrooted process to attempt to break out
56957+ of the chroot, and therefore should not be allowed. If the sysctl
56958+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
56959+ created.
56960+
56961+config GRKERNSEC_CHROOT_CHDIR
56962+ bool "Enforce chdir(\"/\") on all chroots"
56963+ default y if GRKERNSEC_CONFIG_AUTO
56964+ depends on GRKERNSEC_CHROOT
56965+ help
56966+ If you say Y here, the current working directory of all newly-chrooted
56967+ applications will be set to the the root directory of the chroot.
56968+ The man page on chroot(2) states:
56969+ Note that this call does not change the current working
56970+ directory, so that `.' can be outside the tree rooted at
56971+ `/'. In particular, the super-user can escape from a
56972+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
56973+
56974+ It is recommended that you say Y here, since it's not known to break
56975+ any software. If the sysctl option is enabled, a sysctl option with
56976+ name "chroot_enforce_chdir" is created.
56977+
56978+config GRKERNSEC_CHROOT_CHMOD
56979+ bool "Deny (f)chmod +s"
56980+ default y if GRKERNSEC_CONFIG_AUTO
56981+ depends on GRKERNSEC_CHROOT
56982+ help
56983+ If you say Y here, processes inside a chroot will not be able to chmod
56984+ or fchmod files to make them have suid or sgid bits. This protects
56985+ against another published method of breaking a chroot. If the sysctl
56986+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
56987+ created.
56988+
56989+config GRKERNSEC_CHROOT_FCHDIR
56990+ bool "Deny fchdir out of chroot"
56991+ default y if GRKERNSEC_CONFIG_AUTO
56992+ depends on GRKERNSEC_CHROOT
56993+ help
56994+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
56995+ to a file descriptor of the chrooting process that points to a directory
56996+ outside the filesystem will be stopped. If the sysctl option
56997+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
56998+
56999+config GRKERNSEC_CHROOT_MKNOD
57000+ bool "Deny mknod"
57001+ default y if GRKERNSEC_CONFIG_AUTO
57002+ depends on GRKERNSEC_CHROOT
57003+ help
57004+ If you say Y here, processes inside a chroot will not be allowed to
57005+ mknod. The problem with using mknod inside a chroot is that it
57006+ would allow an attacker to create a device entry that is the same
57007+ as one on the physical root of your system, which could range from
57008+ anything from the console device to a device for your harddrive (which
57009+ they could then use to wipe the drive or steal data). It is recommended
57010+ that you say Y here, unless you run into software incompatibilities.
57011+ If the sysctl option is enabled, a sysctl option with name
57012+ "chroot_deny_mknod" is created.
57013+
57014+config GRKERNSEC_CHROOT_SHMAT
57015+ bool "Deny shmat() out of chroot"
57016+ default y if GRKERNSEC_CONFIG_AUTO
57017+ depends on GRKERNSEC_CHROOT
57018+ help
57019+ If you say Y here, processes inside a chroot will not be able to attach
57020+ to shared memory segments that were created outside of the chroot jail.
57021+ It is recommended that you say Y here. If the sysctl option is enabled,
57022+ a sysctl option with name "chroot_deny_shmat" is created.
57023+
57024+config GRKERNSEC_CHROOT_UNIX
57025+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
57026+ default y if GRKERNSEC_CONFIG_AUTO
57027+ depends on GRKERNSEC_CHROOT
57028+ help
57029+ If you say Y here, processes inside a chroot will not be able to
57030+ connect to abstract (meaning not belonging to a filesystem) Unix
57031+ domain sockets that were bound outside of a chroot. It is recommended
57032+ that you say Y here. If the sysctl option is enabled, a sysctl option
57033+ with name "chroot_deny_unix" is created.
57034+
57035+config GRKERNSEC_CHROOT_FINDTASK
57036+ bool "Protect outside processes"
57037+ default y if GRKERNSEC_CONFIG_AUTO
57038+ depends on GRKERNSEC_CHROOT
57039+ help
57040+ If you say Y here, processes inside a chroot will not be able to
57041+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
57042+ getsid, or view any process outside of the chroot. If the sysctl
57043+ option is enabled, a sysctl option with name "chroot_findtask" is
57044+ created.
57045+
57046+config GRKERNSEC_CHROOT_NICE
57047+ bool "Restrict priority changes"
57048+ default y if GRKERNSEC_CONFIG_AUTO
57049+ depends on GRKERNSEC_CHROOT
57050+ help
57051+ If you say Y here, processes inside a chroot will not be able to raise
57052+ the priority of processes in the chroot, or alter the priority of
57053+ processes outside the chroot. This provides more security than simply
57054+ removing CAP_SYS_NICE from the process' capability set. If the
57055+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
57056+ is created.
57057+
57058+config GRKERNSEC_CHROOT_SYSCTL
57059+ bool "Deny sysctl writes"
57060+ default y if GRKERNSEC_CONFIG_AUTO
57061+ depends on GRKERNSEC_CHROOT
57062+ help
57063+ If you say Y here, an attacker in a chroot will not be able to
57064+ write to sysctl entries, either by sysctl(2) or through a /proc
57065+ interface. It is strongly recommended that you say Y here. If the
57066+ sysctl option is enabled, a sysctl option with name
57067+ "chroot_deny_sysctl" is created.
57068+
57069+config GRKERNSEC_CHROOT_CAPS
57070+ bool "Capability restrictions"
57071+ default y if GRKERNSEC_CONFIG_AUTO
57072+ depends on GRKERNSEC_CHROOT
57073+ help
57074+ If you say Y here, the capabilities on all processes within a
57075+ chroot jail will be lowered to stop module insertion, raw i/o,
57076+ system and net admin tasks, rebooting the system, modifying immutable
57077+ files, modifying IPC owned by another, and changing the system time.
57078+ This is left an option because it can break some apps. Disable this
57079+ if your chrooted apps are having problems performing those kinds of
57080+ tasks. If the sysctl option is enabled, a sysctl option with
57081+ name "chroot_caps" is created.
57082+
57083+config GRKERNSEC_CHROOT_INITRD
57084+ bool "Exempt initrd tasks from restrictions"
57085+ default y if GRKERNSEC_CONFIG_AUTO
57086+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
57087+ help
57088+ If you say Y here, tasks started prior to init will be exempted from
57089+ grsecurity's chroot restrictions. This option is mainly meant to
57090+ resolve Plymouth's performing privileged operations unnecessarily
57091+ in a chroot.
57092+
57093+endmenu
57094+menu "Kernel Auditing"
57095+depends on GRKERNSEC
57096+
57097+config GRKERNSEC_AUDIT_GROUP
57098+ bool "Single group for auditing"
57099+ help
57100+ If you say Y here, the exec and chdir logging features will only operate
57101+ on a group you specify. This option is recommended if you only want to
57102+ watch certain users instead of having a large amount of logs from the
57103+ entire system. If the sysctl option is enabled, a sysctl option with
57104+ name "audit_group" is created.
57105+
57106+config GRKERNSEC_AUDIT_GID
57107+ int "GID for auditing"
57108+ depends on GRKERNSEC_AUDIT_GROUP
57109+ default 1007
57110+
57111+config GRKERNSEC_EXECLOG
57112+ bool "Exec logging"
57113+ help
57114+ If you say Y here, all execve() calls will be logged (since the
57115+ other exec*() calls are frontends to execve(), all execution
57116+ will be logged). Useful for shell-servers that like to keep track
57117+ of their users. If the sysctl option is enabled, a sysctl option with
57118+ name "exec_logging" is created.
57119+ WARNING: This option when enabled will produce a LOT of logs, especially
57120+ on an active system.
57121+
57122+config GRKERNSEC_RESLOG
57123+ bool "Resource logging"
57124+ default y if GRKERNSEC_CONFIG_AUTO
57125+ help
57126+ If you say Y here, all attempts to overstep resource limits will
57127+ be logged with the resource name, the requested size, and the current
57128+ limit. It is highly recommended that you say Y here. If the sysctl
57129+ option is enabled, a sysctl option with name "resource_logging" is
57130+ created. If the RBAC system is enabled, the sysctl value is ignored.
57131+
57132+config GRKERNSEC_CHROOT_EXECLOG
57133+ bool "Log execs within chroot"
57134+ help
57135+ If you say Y here, all executions inside a chroot jail will be logged
57136+ to syslog. This can cause a large amount of logs if certain
57137+ applications (eg. djb's daemontools) are installed on the system, and
57138+ is therefore left as an option. If the sysctl option is enabled, a
57139+ sysctl option with name "chroot_execlog" is created.
57140+
57141+config GRKERNSEC_AUDIT_PTRACE
57142+ bool "Ptrace logging"
57143+ help
57144+ If you say Y here, all attempts to attach to a process via ptrace
57145+ will be logged. If the sysctl option is enabled, a sysctl option
57146+ with name "audit_ptrace" is created.
57147+
57148+config GRKERNSEC_AUDIT_CHDIR
57149+ bool "Chdir logging"
57150+ help
57151+ If you say Y here, all chdir() calls will be logged. If the sysctl
57152+ option is enabled, a sysctl option with name "audit_chdir" is created.
57153+
57154+config GRKERNSEC_AUDIT_MOUNT
57155+ bool "(Un)Mount logging"
57156+ help
57157+ If you say Y here, all mounts and unmounts will be logged. If the
57158+ sysctl option is enabled, a sysctl option with name "audit_mount" is
57159+ created.
57160+
57161+config GRKERNSEC_SIGNAL
57162+ bool "Signal logging"
57163+ default y if GRKERNSEC_CONFIG_AUTO
57164+ help
57165+ If you say Y here, certain important signals will be logged, such as
57166+ SIGSEGV, which will as a result inform you of when a error in a program
57167+ occurred, which in some cases could mean a possible exploit attempt.
57168+ If the sysctl option is enabled, a sysctl option with name
57169+ "signal_logging" is created.
57170+
57171+config GRKERNSEC_FORKFAIL
57172+ bool "Fork failure logging"
57173+ help
57174+ If you say Y here, all failed fork() attempts will be logged.
57175+ This could suggest a fork bomb, or someone attempting to overstep
57176+ their process limit. If the sysctl option is enabled, a sysctl option
57177+ with name "forkfail_logging" is created.
57178+
57179+config GRKERNSEC_TIME
57180+ bool "Time change logging"
57181+ default y if GRKERNSEC_CONFIG_AUTO
57182+ help
57183+ If you say Y here, any changes of the system clock will be logged.
57184+ If the sysctl option is enabled, a sysctl option with name
57185+ "timechange_logging" is created.
57186+
57187+config GRKERNSEC_PROC_IPADDR
57188+ bool "/proc/<pid>/ipaddr support"
57189+ default y if GRKERNSEC_CONFIG_AUTO
57190+ help
57191+ If you say Y here, a new entry will be added to each /proc/<pid>
57192+ directory that contains the IP address of the person using the task.
57193+ The IP is carried across local TCP and AF_UNIX stream sockets.
57194+ This information can be useful for IDS/IPSes to perform remote response
57195+ to a local attack. The entry is readable by only the owner of the
57196+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
57197+ the RBAC system), and thus does not create privacy concerns.
57198+
57199+config GRKERNSEC_RWXMAP_LOG
57200+ bool 'Denied RWX mmap/mprotect logging'
57201+ default y if GRKERNSEC_CONFIG_AUTO
57202+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
57203+ help
57204+ If you say Y here, calls to mmap() and mprotect() with explicit
57205+ usage of PROT_WRITE and PROT_EXEC together will be logged when
57206+ denied by the PAX_MPROTECT feature. If the sysctl option is
57207+ enabled, a sysctl option with name "rwxmap_logging" is created.
57208+
57209+config GRKERNSEC_AUDIT_TEXTREL
57210+ bool 'ELF text relocations logging (READ HELP)'
57211+ depends on PAX_MPROTECT
57212+ help
57213+ If you say Y here, text relocations will be logged with the filename
57214+ of the offending library or binary. The purpose of the feature is
57215+ to help Linux distribution developers get rid of libraries and
57216+ binaries that need text relocations which hinder the future progress
57217+ of PaX. Only Linux distribution developers should say Y here, and
57218+ never on a production machine, as this option creates an information
57219+ leak that could aid an attacker in defeating the randomization of
57220+ a single memory region. If the sysctl option is enabled, a sysctl
57221+ option with name "audit_textrel" is created.
57222+
57223+endmenu
57224+
57225+menu "Executable Protections"
57226+depends on GRKERNSEC
57227+
57228+config GRKERNSEC_DMESG
57229+ bool "Dmesg(8) restriction"
57230+ default y if GRKERNSEC_CONFIG_AUTO
57231+ help
57232+ If you say Y here, non-root users will not be able to use dmesg(8)
57233+ to view the contents of the kernel's circular log buffer.
57234+ The kernel's log buffer often contains kernel addresses and other
57235+ identifying information useful to an attacker in fingerprinting a
57236+ system for a targeted exploit.
57237+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
57238+ created.
57239+
57240+config GRKERNSEC_HARDEN_PTRACE
57241+ bool "Deter ptrace-based process snooping"
57242+ default y if GRKERNSEC_CONFIG_AUTO
57243+ help
57244+ If you say Y here, TTY sniffers and other malicious monitoring
57245+ programs implemented through ptrace will be defeated. If you
57246+ have been using the RBAC system, this option has already been
57247+ enabled for several years for all users, with the ability to make
57248+ fine-grained exceptions.
57249+
57250+ This option only affects the ability of non-root users to ptrace
57251+ processes that are not a descendent of the ptracing process.
57252+ This means that strace ./binary and gdb ./binary will still work,
57253+ but attaching to arbitrary processes will not. If the sysctl
57254+ option is enabled, a sysctl option with name "harden_ptrace" is
57255+ created.
57256+
57257+config GRKERNSEC_PTRACE_READEXEC
57258+ bool "Require read access to ptrace sensitive binaries"
57259+ default y if GRKERNSEC_CONFIG_AUTO
57260+ help
57261+ If you say Y here, unprivileged users will not be able to ptrace unreadable
57262+ binaries. This option is useful in environments that
57263+ remove the read bits (e.g. file mode 4711) from suid binaries to
57264+ prevent infoleaking of their contents. This option adds
57265+ consistency to the use of that file mode, as the binary could normally
57266+ be read out when run without privileges while ptracing.
57267+
57268+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
57269+ is created.
57270+
57271+config GRKERNSEC_SETXID
57272+ bool "Enforce consistent multithreaded privileges"
57273+ default y if GRKERNSEC_CONFIG_AUTO
57274+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
57275+ help
57276+ If you say Y here, a change from a root uid to a non-root uid
57277+ in a multithreaded application will cause the resulting uids,
57278+ gids, supplementary groups, and capabilities in that thread
57279+ to be propagated to the other threads of the process. In most
57280+ cases this is unnecessary, as glibc will emulate this behavior
57281+ on behalf of the application. Other libcs do not act in the
57282+ same way, allowing the other threads of the process to continue
57283+ running with root privileges. If the sysctl option is enabled,
57284+ a sysctl option with name "consistent_setxid" is created.
57285+
57286+config GRKERNSEC_TPE
57287+ bool "Trusted Path Execution (TPE)"
57288+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
57289+ help
57290+ If you say Y here, you will be able to choose a gid to add to the
57291+ supplementary groups of users you want to mark as "untrusted."
57292+ These users will not be able to execute any files that are not in
57293+ root-owned directories writable only by root. If the sysctl option
57294+ is enabled, a sysctl option with name "tpe" is created.
57295+
57296+config GRKERNSEC_TPE_ALL
57297+ bool "Partially restrict all non-root users"
57298+ depends on GRKERNSEC_TPE
57299+ help
57300+ If you say Y here, all non-root users will be covered under
57301+ a weaker TPE restriction. This is separate from, and in addition to,
57302+ the main TPE options that you have selected elsewhere. Thus, if a
57303+ "trusted" GID is chosen, this restriction applies to even that GID.
57304+ Under this restriction, all non-root users will only be allowed to
57305+ execute files in directories they own that are not group or
57306+ world-writable, or in directories owned by root and writable only by
57307+ root. If the sysctl option is enabled, a sysctl option with name
57308+ "tpe_restrict_all" is created.
57309+
57310+config GRKERNSEC_TPE_INVERT
57311+ bool "Invert GID option"
57312+ depends on GRKERNSEC_TPE
57313+ help
57314+ If you say Y here, the group you specify in the TPE configuration will
57315+ decide what group TPE restrictions will be *disabled* for. This
57316+ option is useful if you want TPE restrictions to be applied to most
57317+ users on the system. If the sysctl option is enabled, a sysctl option
57318+ with name "tpe_invert" is created. Unlike other sysctl options, this
57319+ entry will default to on for backward-compatibility.
57320+
57321+config GRKERNSEC_TPE_GID
57322+ int
57323+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
57324+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
57325+
57326+config GRKERNSEC_TPE_UNTRUSTED_GID
57327+ int "GID for TPE-untrusted users"
57328+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
57329+ default 1005
57330+ help
57331+ Setting this GID determines what group TPE restrictions will be
57332+ *enabled* for. If the sysctl option is enabled, a sysctl option
57333+ with name "tpe_gid" is created.
57334+
57335+config GRKERNSEC_TPE_TRUSTED_GID
57336+ int "GID for TPE-trusted users"
57337+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
57338+ default 1005
57339+ help
57340+ Setting this GID determines what group TPE restrictions will be
57341+ *disabled* for. If the sysctl option is enabled, a sysctl option
57342+ with name "tpe_gid" is created.
57343+
57344+endmenu
57345+menu "Network Protections"
57346+depends on GRKERNSEC
57347+
57348+config GRKERNSEC_RANDNET
57349+ bool "Larger entropy pools"
57350+ default y if GRKERNSEC_CONFIG_AUTO
57351+ help
57352+ If you say Y here, the entropy pools used for many features of Linux
57353+ and grsecurity will be doubled in size. Since several grsecurity
57354+ features use additional randomness, it is recommended that you say Y
57355+ here. Saying Y here has a similar effect as modifying
57356+ /proc/sys/kernel/random/poolsize.
57357+
57358+config GRKERNSEC_BLACKHOLE
57359+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
57360+ default y if GRKERNSEC_CONFIG_AUTO
57361+ depends on NET
57362+ help
57363+ If you say Y here, neither TCP resets nor ICMP
57364+ destination-unreachable packets will be sent in response to packets
57365+ sent to ports for which no associated listening process exists.
57366+ This feature supports both IPV4 and IPV6 and exempts the
57367+ loopback interface from blackholing. Enabling this feature
57368+ makes a host more resilient to DoS attacks and reduces network
57369+ visibility against scanners.
57370+
57371+ The blackhole feature as-implemented is equivalent to the FreeBSD
57372+ blackhole feature, as it prevents RST responses to all packets, not
57373+ just SYNs. Under most application behavior this causes no
57374+ problems, but applications (like haproxy) may not close certain
57375+ connections in a way that cleanly terminates them on the remote
57376+ end, leaving the remote host in LAST_ACK state. Because of this
57377+ side-effect and to prevent intentional LAST_ACK DoSes, this
57378+ feature also adds automatic mitigation against such attacks.
57379+ The mitigation drastically reduces the amount of time a socket
57380+ can spend in LAST_ACK state. If you're using haproxy and not
57381+ all servers it connects to have this option enabled, consider
57382+ disabling this feature on the haproxy host.
57383+
57384+ If the sysctl option is enabled, two sysctl options with names
57385+ "ip_blackhole" and "lastack_retries" will be created.
57386+ While "ip_blackhole" takes the standard zero/non-zero on/off
57387+ toggle, "lastack_retries" uses the same kinds of values as
57388+ "tcp_retries1" and "tcp_retries2". The default value of 4
57389+ prevents a socket from lasting more than 45 seconds in LAST_ACK
57390+ state.
57391+
57392+config GRKERNSEC_NO_SIMULT_CONNECT
57393+ bool "Disable TCP Simultaneous Connect"
57394+ default y if GRKERNSEC_CONFIG_AUTO
57395+ depends on NET
57396+ help
57397+ If you say Y here, a feature by Willy Tarreau will be enabled that
57398+ removes a weakness in Linux's strict implementation of TCP that
57399+ allows two clients to connect to each other without either entering
57400+ a listening state. The weakness allows an attacker to easily prevent
57401+ a client from connecting to a known server provided the source port
57402+ for the connection is guessed correctly.
57403+
57404+ As the weakness could be used to prevent an antivirus or IPS from
57405+ fetching updates, or prevent an SSL gateway from fetching a CRL,
57406+ it should be eliminated by enabling this option. Though Linux is
57407+ one of few operating systems supporting simultaneous connect, it
57408+ has no legitimate use in practice and is rarely supported by firewalls.
57409+
57410+config GRKERNSEC_SOCKET
57411+ bool "Socket restrictions"
57412+ depends on NET
57413+ help
57414+ If you say Y here, you will be able to choose from several options.
57415+ If you assign a GID on your system and add it to the supplementary
57416+ groups of users you want to restrict socket access to, this patch
57417+ will perform up to three things, based on the option(s) you choose.
57418+
57419+config GRKERNSEC_SOCKET_ALL
57420+ bool "Deny any sockets to group"
57421+ depends on GRKERNSEC_SOCKET
57422+ help
57423+ If you say Y here, you will be able to choose a GID of whose users will
57424+ be unable to connect to other hosts from your machine or run server
57425+ applications from your machine. If the sysctl option is enabled, a
57426+ sysctl option with name "socket_all" is created.
57427+
57428+config GRKERNSEC_SOCKET_ALL_GID
57429+ int "GID to deny all sockets for"
57430+ depends on GRKERNSEC_SOCKET_ALL
57431+ default 1004
57432+ help
57433+ Here you can choose the GID to disable socket access for. Remember to
57434+ add the users you want socket access disabled for to the GID
57435+ specified here. If the sysctl option is enabled, a sysctl option
57436+ with name "socket_all_gid" is created.
57437+
57438+config GRKERNSEC_SOCKET_CLIENT
57439+ bool "Deny client sockets to group"
57440+ depends on GRKERNSEC_SOCKET
57441+ help
57442+ If you say Y here, you will be able to choose a GID of whose users will
57443+ be unable to connect to other hosts from your machine, but will be
57444+ able to run servers. If this option is enabled, all users in the group
57445+ you specify will have to use passive mode when initiating ftp transfers
57446+ from the shell on your machine. If the sysctl option is enabled, a
57447+ sysctl option with name "socket_client" is created.
57448+
57449+config GRKERNSEC_SOCKET_CLIENT_GID
57450+ int "GID to deny client sockets for"
57451+ depends on GRKERNSEC_SOCKET_CLIENT
57452+ default 1003
57453+ help
57454+ Here you can choose the GID to disable client socket access for.
57455+ Remember to add the users you want client socket access disabled for to
57456+ the GID specified here. If the sysctl option is enabled, a sysctl
57457+ option with name "socket_client_gid" is created.
57458+
57459+config GRKERNSEC_SOCKET_SERVER
57460+ bool "Deny server sockets to group"
57461+ depends on GRKERNSEC_SOCKET
57462+ help
57463+ If you say Y here, you will be able to choose a GID of whose users will
57464+ be unable to run server applications from your machine. If the sysctl
57465+ option is enabled, a sysctl option with name "socket_server" is created.
57466+
57467+config GRKERNSEC_SOCKET_SERVER_GID
57468+ int "GID to deny server sockets for"
57469+ depends on GRKERNSEC_SOCKET_SERVER
57470+ default 1002
57471+ help
57472+ Here you can choose the GID to disable server socket access for.
57473+ Remember to add the users you want server socket access disabled for to
57474+ the GID specified here. If the sysctl option is enabled, a sysctl
57475+ option with name "socket_server_gid" is created.
57476+
57477+endmenu
57478+menu "Sysctl Support"
57479+depends on GRKERNSEC && SYSCTL
57480+
57481+config GRKERNSEC_SYSCTL
57482+ bool "Sysctl support"
57483+ default y if GRKERNSEC_CONFIG_AUTO
57484+ help
57485+ If you say Y here, you will be able to change the options that
57486+ grsecurity runs with at bootup, without having to recompile your
57487+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
57488+ to enable (1) or disable (0) various features. All the sysctl entries
57489+ are mutable until the "grsec_lock" entry is set to a non-zero value.
57490+ All features enabled in the kernel configuration are disabled at boot
57491+ if you do not say Y to the "Turn on features by default" option.
57492+ All options should be set at startup, and the grsec_lock entry should
57493+ be set to a non-zero value after all the options are set.
57494+ *THIS IS EXTREMELY IMPORTANT*
57495+
57496+config GRKERNSEC_SYSCTL_DISTRO
57497+ bool "Extra sysctl support for distro makers (READ HELP)"
57498+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
57499+ help
57500+ If you say Y here, additional sysctl options will be created
57501+ for features that affect processes running as root. Therefore,
57502+ it is critical when using this option that the grsec_lock entry be
57503+ enabled after boot. Only distros with prebuilt kernel packages
57504+ with this option enabled that can ensure grsec_lock is enabled
57505+ after boot should use this option.
57506+ *Failure to set grsec_lock after boot makes all grsec features
57507+ this option covers useless*
57508+
57509+ Currently this option creates the following sysctl entries:
57510+ "Disable Privileged I/O": "disable_priv_io"
57511+
57512+config GRKERNSEC_SYSCTL_ON
57513+ bool "Turn on features by default"
57514+ default y if GRKERNSEC_CONFIG_AUTO
57515+ depends on GRKERNSEC_SYSCTL
57516+ help
57517+ If you say Y here, instead of having all features enabled in the
57518+ kernel configuration disabled at boot time, the features will be
57519+ enabled at boot time. It is recommended you say Y here unless
57520+ there is some reason you would want all sysctl-tunable features to
57521+ be disabled by default. As mentioned elsewhere, it is important
57522+ to enable the grsec_lock entry once you have finished modifying
57523+ the sysctl entries.
57524+
57525+endmenu
57526+menu "Logging Options"
57527+depends on GRKERNSEC
57528+
57529+config GRKERNSEC_FLOODTIME
57530+ int "Seconds in between log messages (minimum)"
57531+ default 10
57532+ help
57533+ This option allows you to enforce the number of seconds between
57534+ grsecurity log messages. The default should be suitable for most
57535+ people, however, if you choose to change it, choose a value small enough
57536+ to allow informative logs to be produced, but large enough to
57537+ prevent flooding.
57538+
57539+config GRKERNSEC_FLOODBURST
57540+ int "Number of messages in a burst (maximum)"
57541+ default 6
57542+ help
57543+ This option allows you to choose the maximum number of messages allowed
57544+ within the flood time interval you chose in a separate option. The
57545+ default should be suitable for most people, however if you find that
57546+ many of your logs are being interpreted as flooding, you may want to
57547+ raise this value.
57548+
57549+endmenu
57550diff --git a/grsecurity/Makefile b/grsecurity/Makefile
57551new file mode 100644
57552index 0000000..1b9afa9
57553--- /dev/null
57554+++ b/grsecurity/Makefile
57555@@ -0,0 +1,38 @@
57556+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
57557+# during 2001-2009 it has been completely redesigned by Brad Spengler
57558+# into an RBAC system
57559+#
57560+# All code in this directory and various hooks inserted throughout the kernel
57561+# are copyright Brad Spengler - Open Source Security, Inc., and released
57562+# under the GPL v2 or higher
57563+
57564+KBUILD_CFLAGS += -Werror
57565+
57566+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
57567+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
57568+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
57569+
57570+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
57571+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
57572+ gracl_learn.o grsec_log.o
57573+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
57574+
57575+ifdef CONFIG_NET
57576+obj-y += grsec_sock.o
57577+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
57578+endif
57579+
57580+ifndef CONFIG_GRKERNSEC
57581+obj-y += grsec_disabled.o
57582+endif
57583+
57584+ifdef CONFIG_GRKERNSEC_HIDESYM
57585+extra-y := grsec_hidesym.o
57586+$(obj)/grsec_hidesym.o:
57587+ @-chmod -f 500 /boot
57588+ @-chmod -f 500 /lib/modules
57589+ @-chmod -f 500 /lib64/modules
57590+ @-chmod -f 500 /lib32/modules
57591+ @-chmod -f 700 .
57592+ @echo ' grsec: protected kernel image paths'
57593+endif
57594diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
57595new file mode 100644
57596index 0000000..1248ee0
57597--- /dev/null
57598+++ b/grsecurity/gracl.c
57599@@ -0,0 +1,4073 @@
57600+#include <linux/kernel.h>
57601+#include <linux/module.h>
57602+#include <linux/sched.h>
57603+#include <linux/mm.h>
57604+#include <linux/file.h>
57605+#include <linux/fs.h>
57606+#include <linux/namei.h>
57607+#include <linux/mount.h>
57608+#include <linux/tty.h>
57609+#include <linux/proc_fs.h>
57610+#include <linux/lglock.h>
57611+#include <linux/slab.h>
57612+#include <linux/vmalloc.h>
57613+#include <linux/types.h>
57614+#include <linux/sysctl.h>
57615+#include <linux/netdevice.h>
57616+#include <linux/ptrace.h>
57617+#include <linux/gracl.h>
57618+#include <linux/gralloc.h>
57619+#include <linux/security.h>
57620+#include <linux/grinternal.h>
57621+#include <linux/pid_namespace.h>
57622+#include <linux/stop_machine.h>
57623+#include <linux/fdtable.h>
57624+#include <linux/percpu.h>
57625+#include <linux/lglock.h>
57626+#include <linux/hugetlb.h>
57627+#include <linux/posix-timers.h>
57628+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
57629+#include <linux/magic.h>
57630+#include <linux/pagemap.h>
57631+#include "../fs/btrfs/async-thread.h"
57632+#include "../fs/btrfs/ctree.h"
57633+#include "../fs/btrfs/btrfs_inode.h"
57634+#endif
57635+#include "../fs/mount.h"
57636+
57637+#include <asm/uaccess.h>
57638+#include <asm/errno.h>
57639+#include <asm/mman.h>
57640+
57641+extern struct lglock vfsmount_lock;
57642+
57643+static struct acl_role_db acl_role_set;
57644+static struct name_db name_set;
57645+static struct inodev_db inodev_set;
57646+
57647+/* for keeping track of userspace pointers used for subjects, so we
57648+ can share references in the kernel as well
57649+*/
57650+
57651+static struct path real_root;
57652+
57653+static struct acl_subj_map_db subj_map_set;
57654+
57655+static struct acl_role_label *default_role;
57656+
57657+static struct acl_role_label *role_list;
57658+
57659+static u16 acl_sp_role_value;
57660+
57661+extern char *gr_shared_page[4];
57662+static DEFINE_MUTEX(gr_dev_mutex);
57663+DEFINE_RWLOCK(gr_inode_lock);
57664+
57665+struct gr_arg *gr_usermode;
57666+
57667+static unsigned int gr_status __read_only = GR_STATUS_INIT;
57668+
57669+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
57670+extern void gr_clear_learn_entries(void);
57671+
57672+unsigned char *gr_system_salt;
57673+unsigned char *gr_system_sum;
57674+
57675+static struct sprole_pw **acl_special_roles = NULL;
57676+static __u16 num_sprole_pws = 0;
57677+
57678+static struct acl_role_label *kernel_role = NULL;
57679+
57680+static unsigned int gr_auth_attempts = 0;
57681+static unsigned long gr_auth_expires = 0UL;
57682+
57683+#ifdef CONFIG_NET
57684+extern struct vfsmount *sock_mnt;
57685+#endif
57686+
57687+extern struct vfsmount *pipe_mnt;
57688+extern struct vfsmount *shm_mnt;
57689+
57690+#ifdef CONFIG_HUGETLBFS
57691+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57692+#endif
57693+
57694+static struct acl_object_label *fakefs_obj_rw;
57695+static struct acl_object_label *fakefs_obj_rwx;
57696+
57697+extern int gr_init_uidset(void);
57698+extern void gr_free_uidset(void);
57699+extern void gr_remove_uid(uid_t uid);
57700+extern int gr_find_uid(uid_t uid);
57701+
57702+__inline__ int
57703+gr_acl_is_enabled(void)
57704+{
57705+ return (gr_status & GR_READY);
57706+}
57707+
57708+static inline dev_t __get_dev(const struct dentry *dentry)
57709+{
57710+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
57711+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
57712+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
57713+ else
57714+#endif
57715+ return dentry->d_sb->s_dev;
57716+}
57717+
57718+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57719+{
57720+ return __get_dev(dentry);
57721+}
57722+
57723+static char gr_task_roletype_to_char(struct task_struct *task)
57724+{
57725+ switch (task->role->roletype &
57726+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
57727+ GR_ROLE_SPECIAL)) {
57728+ case GR_ROLE_DEFAULT:
57729+ return 'D';
57730+ case GR_ROLE_USER:
57731+ return 'U';
57732+ case GR_ROLE_GROUP:
57733+ return 'G';
57734+ case GR_ROLE_SPECIAL:
57735+ return 'S';
57736+ }
57737+
57738+ return 'X';
57739+}
57740+
57741+char gr_roletype_to_char(void)
57742+{
57743+ return gr_task_roletype_to_char(current);
57744+}
57745+
57746+__inline__ int
57747+gr_acl_tpe_check(void)
57748+{
57749+ if (unlikely(!(gr_status & GR_READY)))
57750+ return 0;
57751+ if (current->role->roletype & GR_ROLE_TPE)
57752+ return 1;
57753+ else
57754+ return 0;
57755+}
57756+
57757+int
57758+gr_handle_rawio(const struct inode *inode)
57759+{
57760+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57761+ if (inode && S_ISBLK(inode->i_mode) &&
57762+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57763+ !capable(CAP_SYS_RAWIO))
57764+ return 1;
57765+#endif
57766+ return 0;
57767+}
57768+
57769+static int
57770+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
57771+{
57772+ if (likely(lena != lenb))
57773+ return 0;
57774+
57775+ return !memcmp(a, b, lena);
57776+}
57777+
57778+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
57779+{
57780+ *buflen -= namelen;
57781+ if (*buflen < 0)
57782+ return -ENAMETOOLONG;
57783+ *buffer -= namelen;
57784+ memcpy(*buffer, str, namelen);
57785+ return 0;
57786+}
57787+
57788+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
57789+{
57790+ return prepend(buffer, buflen, name->name, name->len);
57791+}
57792+
57793+static int prepend_path(const struct path *path, struct path *root,
57794+ char **buffer, int *buflen)
57795+{
57796+ struct dentry *dentry = path->dentry;
57797+ struct vfsmount *vfsmnt = path->mnt;
57798+ struct mount *mnt = real_mount(vfsmnt);
57799+ bool slash = false;
57800+ int error = 0;
57801+
57802+ while (dentry != root->dentry || vfsmnt != root->mnt) {
57803+ struct dentry * parent;
57804+
57805+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
57806+ /* Global root? */
57807+ if (!mnt_has_parent(mnt)) {
57808+ goto out;
57809+ }
57810+ dentry = mnt->mnt_mountpoint;
57811+ mnt = mnt->mnt_parent;
57812+ vfsmnt = &mnt->mnt;
57813+ continue;
57814+ }
57815+ parent = dentry->d_parent;
57816+ prefetch(parent);
57817+ spin_lock(&dentry->d_lock);
57818+ error = prepend_name(buffer, buflen, &dentry->d_name);
57819+ spin_unlock(&dentry->d_lock);
57820+ if (!error)
57821+ error = prepend(buffer, buflen, "/", 1);
57822+ if (error)
57823+ break;
57824+
57825+ slash = true;
57826+ dentry = parent;
57827+ }
57828+
57829+out:
57830+ if (!error && !slash)
57831+ error = prepend(buffer, buflen, "/", 1);
57832+
57833+ return error;
57834+}
57835+
57836+/* this must be called with vfsmount_lock and rename_lock held */
57837+
57838+static char *__our_d_path(const struct path *path, struct path *root,
57839+ char *buf, int buflen)
57840+{
57841+ char *res = buf + buflen;
57842+ int error;
57843+
57844+ prepend(&res, &buflen, "\0", 1);
57845+ error = prepend_path(path, root, &res, &buflen);
57846+ if (error)
57847+ return ERR_PTR(error);
57848+
57849+ return res;
57850+}
57851+
57852+static char *
57853+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
57854+{
57855+ char *retval;
57856+
57857+ retval = __our_d_path(path, root, buf, buflen);
57858+ if (unlikely(IS_ERR(retval)))
57859+ retval = strcpy(buf, "<path too long>");
57860+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
57861+ retval[1] = '\0';
57862+
57863+ return retval;
57864+}
57865+
57866+static char *
57867+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
57868+ char *buf, int buflen)
57869+{
57870+ struct path path;
57871+ char *res;
57872+
57873+ path.dentry = (struct dentry *)dentry;
57874+ path.mnt = (struct vfsmount *)vfsmnt;
57875+
57876+ /* we can use real_root.dentry, real_root.mnt, because this is only called
57877+ by the RBAC system */
57878+ res = gen_full_path(&path, &real_root, buf, buflen);
57879+
57880+ return res;
57881+}
57882+
57883+static char *
57884+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
57885+ char *buf, int buflen)
57886+{
57887+ char *res;
57888+ struct path path;
57889+ struct path root;
57890+ struct task_struct *reaper = init_pid_ns.child_reaper;
57891+
57892+ path.dentry = (struct dentry *)dentry;
57893+ path.mnt = (struct vfsmount *)vfsmnt;
57894+
57895+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
57896+ get_fs_root(reaper->fs, &root);
57897+
57898+ br_read_lock(&vfsmount_lock);
57899+ write_seqlock(&rename_lock);
57900+ res = gen_full_path(&path, &root, buf, buflen);
57901+ write_sequnlock(&rename_lock);
57902+ br_read_unlock(&vfsmount_lock);
57903+
57904+ path_put(&root);
57905+ return res;
57906+}
57907+
57908+static char *
57909+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
57910+{
57911+ char *ret;
57912+ br_read_lock(&vfsmount_lock);
57913+ write_seqlock(&rename_lock);
57914+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
57915+ PAGE_SIZE);
57916+ write_sequnlock(&rename_lock);
57917+ br_read_unlock(&vfsmount_lock);
57918+ return ret;
57919+}
57920+
57921+static char *
57922+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
57923+{
57924+ char *ret;
57925+ char *buf;
57926+ int buflen;
57927+
57928+ br_read_lock(&vfsmount_lock);
57929+ write_seqlock(&rename_lock);
57930+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
57931+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
57932+ buflen = (int)(ret - buf);
57933+ if (buflen >= 5)
57934+ prepend(&ret, &buflen, "/proc", 5);
57935+ else
57936+ ret = strcpy(buf, "<path too long>");
57937+ write_sequnlock(&rename_lock);
57938+ br_read_unlock(&vfsmount_lock);
57939+ return ret;
57940+}
57941+
57942+char *
57943+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
57944+{
57945+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
57946+ PAGE_SIZE);
57947+}
57948+
57949+char *
57950+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
57951+{
57952+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
57953+ PAGE_SIZE);
57954+}
57955+
57956+char *
57957+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
57958+{
57959+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
57960+ PAGE_SIZE);
57961+}
57962+
57963+char *
57964+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
57965+{
57966+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
57967+ PAGE_SIZE);
57968+}
57969+
57970+char *
57971+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
57972+{
57973+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
57974+ PAGE_SIZE);
57975+}
57976+
57977+__inline__ __u32
57978+to_gr_audit(const __u32 reqmode)
57979+{
57980+ /* masks off auditable permission flags, then shifts them to create
57981+ auditing flags, and adds the special case of append auditing if
57982+ we're requesting write */
57983+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
57984+}
57985+
57986+struct acl_subject_label *
57987+lookup_subject_map(const struct acl_subject_label *userp)
57988+{
57989+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
57990+ struct subject_map *match;
57991+
57992+ match = subj_map_set.s_hash[index];
57993+
57994+ while (match && match->user != userp)
57995+ match = match->next;
57996+
57997+ if (match != NULL)
57998+ return match->kernel;
57999+ else
58000+ return NULL;
58001+}
58002+
58003+static void
58004+insert_subj_map_entry(struct subject_map *subjmap)
58005+{
58006+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
58007+ struct subject_map **curr;
58008+
58009+ subjmap->prev = NULL;
58010+
58011+ curr = &subj_map_set.s_hash[index];
58012+ if (*curr != NULL)
58013+ (*curr)->prev = subjmap;
58014+
58015+ subjmap->next = *curr;
58016+ *curr = subjmap;
58017+
58018+ return;
58019+}
58020+
58021+static struct acl_role_label *
58022+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
58023+ const gid_t gid)
58024+{
58025+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
58026+ struct acl_role_label *match;
58027+ struct role_allowed_ip *ipp;
58028+ unsigned int x;
58029+ u32 curr_ip = task->signal->curr_ip;
58030+
58031+ task->signal->saved_ip = curr_ip;
58032+
58033+ match = acl_role_set.r_hash[index];
58034+
58035+ while (match) {
58036+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
58037+ for (x = 0; x < match->domain_child_num; x++) {
58038+ if (match->domain_children[x] == uid)
58039+ goto found;
58040+ }
58041+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
58042+ break;
58043+ match = match->next;
58044+ }
58045+found:
58046+ if (match == NULL) {
58047+ try_group:
58048+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
58049+ match = acl_role_set.r_hash[index];
58050+
58051+ while (match) {
58052+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
58053+ for (x = 0; x < match->domain_child_num; x++) {
58054+ if (match->domain_children[x] == gid)
58055+ goto found2;
58056+ }
58057+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
58058+ break;
58059+ match = match->next;
58060+ }
58061+found2:
58062+ if (match == NULL)
58063+ match = default_role;
58064+ if (match->allowed_ips == NULL)
58065+ return match;
58066+ else {
58067+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
58068+ if (likely
58069+ ((ntohl(curr_ip) & ipp->netmask) ==
58070+ (ntohl(ipp->addr) & ipp->netmask)))
58071+ return match;
58072+ }
58073+ match = default_role;
58074+ }
58075+ } else if (match->allowed_ips == NULL) {
58076+ return match;
58077+ } else {
58078+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
58079+ if (likely
58080+ ((ntohl(curr_ip) & ipp->netmask) ==
58081+ (ntohl(ipp->addr) & ipp->netmask)))
58082+ return match;
58083+ }
58084+ goto try_group;
58085+ }
58086+
58087+ return match;
58088+}
58089+
58090+struct acl_subject_label *
58091+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
58092+ const struct acl_role_label *role)
58093+{
58094+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
58095+ struct acl_subject_label *match;
58096+
58097+ match = role->subj_hash[index];
58098+
58099+ while (match && (match->inode != ino || match->device != dev ||
58100+ (match->mode & GR_DELETED))) {
58101+ match = match->next;
58102+ }
58103+
58104+ if (match && !(match->mode & GR_DELETED))
58105+ return match;
58106+ else
58107+ return NULL;
58108+}
58109+
58110+struct acl_subject_label *
58111+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
58112+ const struct acl_role_label *role)
58113+{
58114+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
58115+ struct acl_subject_label *match;
58116+
58117+ match = role->subj_hash[index];
58118+
58119+ while (match && (match->inode != ino || match->device != dev ||
58120+ !(match->mode & GR_DELETED))) {
58121+ match = match->next;
58122+ }
58123+
58124+ if (match && (match->mode & GR_DELETED))
58125+ return match;
58126+ else
58127+ return NULL;
58128+}
58129+
58130+static struct acl_object_label *
58131+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
58132+ const struct acl_subject_label *subj)
58133+{
58134+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
58135+ struct acl_object_label *match;
58136+
58137+ match = subj->obj_hash[index];
58138+
58139+ while (match && (match->inode != ino || match->device != dev ||
58140+ (match->mode & GR_DELETED))) {
58141+ match = match->next;
58142+ }
58143+
58144+ if (match && !(match->mode & GR_DELETED))
58145+ return match;
58146+ else
58147+ return NULL;
58148+}
58149+
58150+static struct acl_object_label *
58151+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
58152+ const struct acl_subject_label *subj)
58153+{
58154+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
58155+ struct acl_object_label *match;
58156+
58157+ match = subj->obj_hash[index];
58158+
58159+ while (match && (match->inode != ino || match->device != dev ||
58160+ !(match->mode & GR_DELETED))) {
58161+ match = match->next;
58162+ }
58163+
58164+ if (match && (match->mode & GR_DELETED))
58165+ return match;
58166+
58167+ match = subj->obj_hash[index];
58168+
58169+ while (match && (match->inode != ino || match->device != dev ||
58170+ (match->mode & GR_DELETED))) {
58171+ match = match->next;
58172+ }
58173+
58174+ if (match && !(match->mode & GR_DELETED))
58175+ return match;
58176+ else
58177+ return NULL;
58178+}
58179+
58180+static struct name_entry *
58181+lookup_name_entry(const char *name)
58182+{
58183+ unsigned int len = strlen(name);
58184+ unsigned int key = full_name_hash(name, len);
58185+ unsigned int index = key % name_set.n_size;
58186+ struct name_entry *match;
58187+
58188+ match = name_set.n_hash[index];
58189+
58190+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
58191+ match = match->next;
58192+
58193+ return match;
58194+}
58195+
58196+static struct name_entry *
58197+lookup_name_entry_create(const char *name)
58198+{
58199+ unsigned int len = strlen(name);
58200+ unsigned int key = full_name_hash(name, len);
58201+ unsigned int index = key % name_set.n_size;
58202+ struct name_entry *match;
58203+
58204+ match = name_set.n_hash[index];
58205+
58206+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
58207+ !match->deleted))
58208+ match = match->next;
58209+
58210+ if (match && match->deleted)
58211+ return match;
58212+
58213+ match = name_set.n_hash[index];
58214+
58215+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
58216+ match->deleted))
58217+ match = match->next;
58218+
58219+ if (match && !match->deleted)
58220+ return match;
58221+ else
58222+ return NULL;
58223+}
58224+
58225+static struct inodev_entry *
58226+lookup_inodev_entry(const ino_t ino, const dev_t dev)
58227+{
58228+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
58229+ struct inodev_entry *match;
58230+
58231+ match = inodev_set.i_hash[index];
58232+
58233+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
58234+ match = match->next;
58235+
58236+ return match;
58237+}
58238+
58239+static void
58240+insert_inodev_entry(struct inodev_entry *entry)
58241+{
58242+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
58243+ inodev_set.i_size);
58244+ struct inodev_entry **curr;
58245+
58246+ entry->prev = NULL;
58247+
58248+ curr = &inodev_set.i_hash[index];
58249+ if (*curr != NULL)
58250+ (*curr)->prev = entry;
58251+
58252+ entry->next = *curr;
58253+ *curr = entry;
58254+
58255+ return;
58256+}
58257+
58258+static void
58259+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
58260+{
58261+ unsigned int index =
58262+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
58263+ struct acl_role_label **curr;
58264+ struct acl_role_label *tmp, *tmp2;
58265+
58266+ curr = &acl_role_set.r_hash[index];
58267+
58268+ /* simple case, slot is empty, just set it to our role */
58269+ if (*curr == NULL) {
58270+ *curr = role;
58271+ } else {
58272+ /* example:
58273+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
58274+ 2 -> 3
58275+ */
58276+ /* first check to see if we can already be reached via this slot */
58277+ tmp = *curr;
58278+ while (tmp && tmp != role)
58279+ tmp = tmp->next;
58280+ if (tmp == role) {
58281+ /* we don't need to add ourselves to this slot's chain */
58282+ return;
58283+ }
58284+ /* we need to add ourselves to this chain, two cases */
58285+ if (role->next == NULL) {
58286+ /* simple case, append the current chain to our role */
58287+ role->next = *curr;
58288+ *curr = role;
58289+ } else {
58290+ /* 1 -> 2 -> 3 -> 4
58291+ 2 -> 3 -> 4
58292+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
58293+ */
58294+ /* trickier case: walk our role's chain until we find
58295+ the role for the start of the current slot's chain */
58296+ tmp = role;
58297+ tmp2 = *curr;
58298+ while (tmp->next && tmp->next != tmp2)
58299+ tmp = tmp->next;
58300+ if (tmp->next == tmp2) {
58301+ /* from example above, we found 3, so just
58302+ replace this slot's chain with ours */
58303+ *curr = role;
58304+ } else {
58305+ /* we didn't find a subset of our role's chain
58306+ in the current slot's chain, so append their
58307+ chain to ours, and set us as the first role in
58308+ the slot's chain
58309+
58310+ we could fold this case with the case above,
58311+ but making it explicit for clarity
58312+ */
58313+ tmp->next = tmp2;
58314+ *curr = role;
58315+ }
58316+ }
58317+ }
58318+
58319+ return;
58320+}
58321+
58322+static void
58323+insert_acl_role_label(struct acl_role_label *role)
58324+{
58325+ int i;
58326+
58327+ if (role_list == NULL) {
58328+ role_list = role;
58329+ role->prev = NULL;
58330+ } else {
58331+ role->prev = role_list;
58332+ role_list = role;
58333+ }
58334+
58335+ /* used for hash chains */
58336+ role->next = NULL;
58337+
58338+ if (role->roletype & GR_ROLE_DOMAIN) {
58339+ for (i = 0; i < role->domain_child_num; i++)
58340+ __insert_acl_role_label(role, role->domain_children[i]);
58341+ } else
58342+ __insert_acl_role_label(role, role->uidgid);
58343+}
58344+
58345+static int
58346+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
58347+{
58348+ struct name_entry **curr, *nentry;
58349+ struct inodev_entry *ientry;
58350+ unsigned int len = strlen(name);
58351+ unsigned int key = full_name_hash(name, len);
58352+ unsigned int index = key % name_set.n_size;
58353+
58354+ curr = &name_set.n_hash[index];
58355+
58356+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
58357+ curr = &((*curr)->next);
58358+
58359+ if (*curr != NULL)
58360+ return 1;
58361+
58362+ nentry = acl_alloc(sizeof (struct name_entry));
58363+ if (nentry == NULL)
58364+ return 0;
58365+ ientry = acl_alloc(sizeof (struct inodev_entry));
58366+ if (ientry == NULL)
58367+ return 0;
58368+ ientry->nentry = nentry;
58369+
58370+ nentry->key = key;
58371+ nentry->name = name;
58372+ nentry->inode = inode;
58373+ nentry->device = device;
58374+ nentry->len = len;
58375+ nentry->deleted = deleted;
58376+
58377+ nentry->prev = NULL;
58378+ curr = &name_set.n_hash[index];
58379+ if (*curr != NULL)
58380+ (*curr)->prev = nentry;
58381+ nentry->next = *curr;
58382+ *curr = nentry;
58383+
58384+ /* insert us into the table searchable by inode/dev */
58385+ insert_inodev_entry(ientry);
58386+
58387+ return 1;
58388+}
58389+
58390+static void
58391+insert_acl_obj_label(struct acl_object_label *obj,
58392+ struct acl_subject_label *subj)
58393+{
58394+ unsigned int index =
58395+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
58396+ struct acl_object_label **curr;
58397+
58398+
58399+ obj->prev = NULL;
58400+
58401+ curr = &subj->obj_hash[index];
58402+ if (*curr != NULL)
58403+ (*curr)->prev = obj;
58404+
58405+ obj->next = *curr;
58406+ *curr = obj;
58407+
58408+ return;
58409+}
58410+
58411+static void
58412+insert_acl_subj_label(struct acl_subject_label *obj,
58413+ struct acl_role_label *role)
58414+{
58415+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
58416+ struct acl_subject_label **curr;
58417+
58418+ obj->prev = NULL;
58419+
58420+ curr = &role->subj_hash[index];
58421+ if (*curr != NULL)
58422+ (*curr)->prev = obj;
58423+
58424+ obj->next = *curr;
58425+ *curr = obj;
58426+
58427+ return;
58428+}
58429+
58430+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
58431+
58432+static void *
58433+create_table(__u32 * len, int elementsize)
58434+{
58435+ unsigned int table_sizes[] = {
58436+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
58437+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
58438+ 4194301, 8388593, 16777213, 33554393, 67108859
58439+ };
58440+ void *newtable = NULL;
58441+ unsigned int pwr = 0;
58442+
58443+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
58444+ table_sizes[pwr] <= *len)
58445+ pwr++;
58446+
58447+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
58448+ return newtable;
58449+
58450+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
58451+ newtable =
58452+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
58453+ else
58454+ newtable = vmalloc(table_sizes[pwr] * elementsize);
58455+
58456+ *len = table_sizes[pwr];
58457+
58458+ return newtable;
58459+}
58460+
58461+static int
58462+init_variables(const struct gr_arg *arg)
58463+{
58464+ struct task_struct *reaper = init_pid_ns.child_reaper;
58465+ unsigned int stacksize;
58466+
58467+ subj_map_set.s_size = arg->role_db.num_subjects;
58468+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
58469+ name_set.n_size = arg->role_db.num_objects;
58470+ inodev_set.i_size = arg->role_db.num_objects;
58471+
58472+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
58473+ !name_set.n_size || !inodev_set.i_size)
58474+ return 1;
58475+
58476+ if (!gr_init_uidset())
58477+ return 1;
58478+
58479+ /* set up the stack that holds allocation info */
58480+
58481+ stacksize = arg->role_db.num_pointers + 5;
58482+
58483+ if (!acl_alloc_stack_init(stacksize))
58484+ return 1;
58485+
58486+ /* grab reference for the real root dentry and vfsmount */
58487+ get_fs_root(reaper->fs, &real_root);
58488+
58489+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58490+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
58491+#endif
58492+
58493+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
58494+ if (fakefs_obj_rw == NULL)
58495+ return 1;
58496+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
58497+
58498+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
58499+ if (fakefs_obj_rwx == NULL)
58500+ return 1;
58501+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
58502+
58503+ subj_map_set.s_hash =
58504+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
58505+ acl_role_set.r_hash =
58506+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
58507+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
58508+ inodev_set.i_hash =
58509+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
58510+
58511+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
58512+ !name_set.n_hash || !inodev_set.i_hash)
58513+ return 1;
58514+
58515+ memset(subj_map_set.s_hash, 0,
58516+ sizeof(struct subject_map *) * subj_map_set.s_size);
58517+ memset(acl_role_set.r_hash, 0,
58518+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
58519+ memset(name_set.n_hash, 0,
58520+ sizeof (struct name_entry *) * name_set.n_size);
58521+ memset(inodev_set.i_hash, 0,
58522+ sizeof (struct inodev_entry *) * inodev_set.i_size);
58523+
58524+ return 0;
58525+}
58526+
58527+/* free information not needed after startup
58528+ currently contains user->kernel pointer mappings for subjects
58529+*/
58530+
58531+static void
58532+free_init_variables(void)
58533+{
58534+ __u32 i;
58535+
58536+ if (subj_map_set.s_hash) {
58537+ for (i = 0; i < subj_map_set.s_size; i++) {
58538+ if (subj_map_set.s_hash[i]) {
58539+ kfree(subj_map_set.s_hash[i]);
58540+ subj_map_set.s_hash[i] = NULL;
58541+ }
58542+ }
58543+
58544+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
58545+ PAGE_SIZE)
58546+ kfree(subj_map_set.s_hash);
58547+ else
58548+ vfree(subj_map_set.s_hash);
58549+ }
58550+
58551+ return;
58552+}
58553+
58554+static void
58555+free_variables(void)
58556+{
58557+ struct acl_subject_label *s;
58558+ struct acl_role_label *r;
58559+ struct task_struct *task, *task2;
58560+ unsigned int x;
58561+
58562+ gr_clear_learn_entries();
58563+
58564+ read_lock(&tasklist_lock);
58565+ do_each_thread(task2, task) {
58566+ task->acl_sp_role = 0;
58567+ task->acl_role_id = 0;
58568+ task->acl = NULL;
58569+ task->role = NULL;
58570+ } while_each_thread(task2, task);
58571+ read_unlock(&tasklist_lock);
58572+
58573+ /* release the reference to the real root dentry and vfsmount */
58574+ path_put(&real_root);
58575+ memset(&real_root, 0, sizeof(real_root));
58576+
58577+ /* free all object hash tables */
58578+
58579+ FOR_EACH_ROLE_START(r)
58580+ if (r->subj_hash == NULL)
58581+ goto next_role;
58582+ FOR_EACH_SUBJECT_START(r, s, x)
58583+ if (s->obj_hash == NULL)
58584+ break;
58585+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
58586+ kfree(s->obj_hash);
58587+ else
58588+ vfree(s->obj_hash);
58589+ FOR_EACH_SUBJECT_END(s, x)
58590+ FOR_EACH_NESTED_SUBJECT_START(r, s)
58591+ if (s->obj_hash == NULL)
58592+ break;
58593+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
58594+ kfree(s->obj_hash);
58595+ else
58596+ vfree(s->obj_hash);
58597+ FOR_EACH_NESTED_SUBJECT_END(s)
58598+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
58599+ kfree(r->subj_hash);
58600+ else
58601+ vfree(r->subj_hash);
58602+ r->subj_hash = NULL;
58603+next_role:
58604+ FOR_EACH_ROLE_END(r)
58605+
58606+ acl_free_all();
58607+
58608+ if (acl_role_set.r_hash) {
58609+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
58610+ PAGE_SIZE)
58611+ kfree(acl_role_set.r_hash);
58612+ else
58613+ vfree(acl_role_set.r_hash);
58614+ }
58615+ if (name_set.n_hash) {
58616+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
58617+ PAGE_SIZE)
58618+ kfree(name_set.n_hash);
58619+ else
58620+ vfree(name_set.n_hash);
58621+ }
58622+
58623+ if (inodev_set.i_hash) {
58624+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
58625+ PAGE_SIZE)
58626+ kfree(inodev_set.i_hash);
58627+ else
58628+ vfree(inodev_set.i_hash);
58629+ }
58630+
58631+ gr_free_uidset();
58632+
58633+ memset(&name_set, 0, sizeof (struct name_db));
58634+ memset(&inodev_set, 0, sizeof (struct inodev_db));
58635+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
58636+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
58637+
58638+ default_role = NULL;
58639+ kernel_role = NULL;
58640+ role_list = NULL;
58641+
58642+ return;
58643+}
58644+
58645+static __u32
58646+count_user_objs(struct acl_object_label *userp)
58647+{
58648+ struct acl_object_label o_tmp;
58649+ __u32 num = 0;
58650+
58651+ while (userp) {
58652+ if (copy_from_user(&o_tmp, userp,
58653+ sizeof (struct acl_object_label)))
58654+ break;
58655+
58656+ userp = o_tmp.prev;
58657+ num++;
58658+ }
58659+
58660+ return num;
58661+}
58662+
58663+static struct acl_subject_label *
58664+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
58665+
58666+static int
58667+copy_user_glob(struct acl_object_label *obj)
58668+{
58669+ struct acl_object_label *g_tmp, **guser;
58670+ unsigned int len;
58671+ char *tmp;
58672+
58673+ if (obj->globbed == NULL)
58674+ return 0;
58675+
58676+ guser = &obj->globbed;
58677+ while (*guser) {
58678+ g_tmp = (struct acl_object_label *)
58679+ acl_alloc(sizeof (struct acl_object_label));
58680+ if (g_tmp == NULL)
58681+ return -ENOMEM;
58682+
58683+ if (copy_from_user(g_tmp, *guser,
58684+ sizeof (struct acl_object_label)))
58685+ return -EFAULT;
58686+
58687+ len = strnlen_user(g_tmp->filename, PATH_MAX);
58688+
58689+ if (!len || len >= PATH_MAX)
58690+ return -EINVAL;
58691+
58692+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58693+ return -ENOMEM;
58694+
58695+ if (copy_from_user(tmp, g_tmp->filename, len))
58696+ return -EFAULT;
58697+ tmp[len-1] = '\0';
58698+ g_tmp->filename = tmp;
58699+
58700+ *guser = g_tmp;
58701+ guser = &(g_tmp->next);
58702+ }
58703+
58704+ return 0;
58705+}
58706+
58707+static int
58708+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
58709+ struct acl_role_label *role)
58710+{
58711+ struct acl_object_label *o_tmp;
58712+ unsigned int len;
58713+ int ret;
58714+ char *tmp;
58715+
58716+ while (userp) {
58717+ if ((o_tmp = (struct acl_object_label *)
58718+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
58719+ return -ENOMEM;
58720+
58721+ if (copy_from_user(o_tmp, userp,
58722+ sizeof (struct acl_object_label)))
58723+ return -EFAULT;
58724+
58725+ userp = o_tmp->prev;
58726+
58727+ len = strnlen_user(o_tmp->filename, PATH_MAX);
58728+
58729+ if (!len || len >= PATH_MAX)
58730+ return -EINVAL;
58731+
58732+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58733+ return -ENOMEM;
58734+
58735+ if (copy_from_user(tmp, o_tmp->filename, len))
58736+ return -EFAULT;
58737+ tmp[len-1] = '\0';
58738+ o_tmp->filename = tmp;
58739+
58740+ insert_acl_obj_label(o_tmp, subj);
58741+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
58742+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
58743+ return -ENOMEM;
58744+
58745+ ret = copy_user_glob(o_tmp);
58746+ if (ret)
58747+ return ret;
58748+
58749+ if (o_tmp->nested) {
58750+ int already_copied;
58751+
58752+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
58753+ if (IS_ERR(o_tmp->nested))
58754+ return PTR_ERR(o_tmp->nested);
58755+
58756+ /* insert into nested subject list if we haven't copied this one yet
58757+ to prevent duplicate entries */
58758+ if (!already_copied) {
58759+ o_tmp->nested->next = role->hash->first;
58760+ role->hash->first = o_tmp->nested;
58761+ }
58762+ }
58763+ }
58764+
58765+ return 0;
58766+}
58767+
58768+static __u32
58769+count_user_subjs(struct acl_subject_label *userp)
58770+{
58771+ struct acl_subject_label s_tmp;
58772+ __u32 num = 0;
58773+
58774+ while (userp) {
58775+ if (copy_from_user(&s_tmp, userp,
58776+ sizeof (struct acl_subject_label)))
58777+ break;
58778+
58779+ userp = s_tmp.prev;
58780+ }
58781+
58782+ return num;
58783+}
58784+
58785+static int
58786+copy_user_allowedips(struct acl_role_label *rolep)
58787+{
58788+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
58789+
58790+ ruserip = rolep->allowed_ips;
58791+
58792+ while (ruserip) {
58793+ rlast = rtmp;
58794+
58795+ if ((rtmp = (struct role_allowed_ip *)
58796+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
58797+ return -ENOMEM;
58798+
58799+ if (copy_from_user(rtmp, ruserip,
58800+ sizeof (struct role_allowed_ip)))
58801+ return -EFAULT;
58802+
58803+ ruserip = rtmp->prev;
58804+
58805+ if (!rlast) {
58806+ rtmp->prev = NULL;
58807+ rolep->allowed_ips = rtmp;
58808+ } else {
58809+ rlast->next = rtmp;
58810+ rtmp->prev = rlast;
58811+ }
58812+
58813+ if (!ruserip)
58814+ rtmp->next = NULL;
58815+ }
58816+
58817+ return 0;
58818+}
58819+
58820+static int
58821+copy_user_transitions(struct acl_role_label *rolep)
58822+{
58823+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
58824+
58825+ unsigned int len;
58826+ char *tmp;
58827+
58828+ rusertp = rolep->transitions;
58829+
58830+ while (rusertp) {
58831+ rlast = rtmp;
58832+
58833+ if ((rtmp = (struct role_transition *)
58834+ acl_alloc(sizeof (struct role_transition))) == NULL)
58835+ return -ENOMEM;
58836+
58837+ if (copy_from_user(rtmp, rusertp,
58838+ sizeof (struct role_transition)))
58839+ return -EFAULT;
58840+
58841+ rusertp = rtmp->prev;
58842+
58843+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
58844+
58845+ if (!len || len >= GR_SPROLE_LEN)
58846+ return -EINVAL;
58847+
58848+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58849+ return -ENOMEM;
58850+
58851+ if (copy_from_user(tmp, rtmp->rolename, len))
58852+ return -EFAULT;
58853+ tmp[len-1] = '\0';
58854+ rtmp->rolename = tmp;
58855+
58856+ if (!rlast) {
58857+ rtmp->prev = NULL;
58858+ rolep->transitions = rtmp;
58859+ } else {
58860+ rlast->next = rtmp;
58861+ rtmp->prev = rlast;
58862+ }
58863+
58864+ if (!rusertp)
58865+ rtmp->next = NULL;
58866+ }
58867+
58868+ return 0;
58869+}
58870+
58871+static struct acl_subject_label *
58872+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
58873+{
58874+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
58875+ unsigned int len;
58876+ char *tmp;
58877+ __u32 num_objs;
58878+ struct acl_ip_label **i_tmp, *i_utmp2;
58879+ struct gr_hash_struct ghash;
58880+ struct subject_map *subjmap;
58881+ unsigned int i_num;
58882+ int err;
58883+
58884+ if (already_copied != NULL)
58885+ *already_copied = 0;
58886+
58887+ s_tmp = lookup_subject_map(userp);
58888+
58889+ /* we've already copied this subject into the kernel, just return
58890+ the reference to it, and don't copy it over again
58891+ */
58892+ if (s_tmp) {
58893+ if (already_copied != NULL)
58894+ *already_copied = 1;
58895+ return(s_tmp);
58896+ }
58897+
58898+ if ((s_tmp = (struct acl_subject_label *)
58899+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
58900+ return ERR_PTR(-ENOMEM);
58901+
58902+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
58903+ if (subjmap == NULL)
58904+ return ERR_PTR(-ENOMEM);
58905+
58906+ subjmap->user = userp;
58907+ subjmap->kernel = s_tmp;
58908+ insert_subj_map_entry(subjmap);
58909+
58910+ if (copy_from_user(s_tmp, userp,
58911+ sizeof (struct acl_subject_label)))
58912+ return ERR_PTR(-EFAULT);
58913+
58914+ len = strnlen_user(s_tmp->filename, PATH_MAX);
58915+
58916+ if (!len || len >= PATH_MAX)
58917+ return ERR_PTR(-EINVAL);
58918+
58919+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58920+ return ERR_PTR(-ENOMEM);
58921+
58922+ if (copy_from_user(tmp, s_tmp->filename, len))
58923+ return ERR_PTR(-EFAULT);
58924+ tmp[len-1] = '\0';
58925+ s_tmp->filename = tmp;
58926+
58927+ if (!strcmp(s_tmp->filename, "/"))
58928+ role->root_label = s_tmp;
58929+
58930+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
58931+ return ERR_PTR(-EFAULT);
58932+
58933+ /* copy user and group transition tables */
58934+
58935+ if (s_tmp->user_trans_num) {
58936+ uid_t *uidlist;
58937+
58938+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
58939+ if (uidlist == NULL)
58940+ return ERR_PTR(-ENOMEM);
58941+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
58942+ return ERR_PTR(-EFAULT);
58943+
58944+ s_tmp->user_transitions = uidlist;
58945+ }
58946+
58947+ if (s_tmp->group_trans_num) {
58948+ gid_t *gidlist;
58949+
58950+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
58951+ if (gidlist == NULL)
58952+ return ERR_PTR(-ENOMEM);
58953+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
58954+ return ERR_PTR(-EFAULT);
58955+
58956+ s_tmp->group_transitions = gidlist;
58957+ }
58958+
58959+ /* set up object hash table */
58960+ num_objs = count_user_objs(ghash.first);
58961+
58962+ s_tmp->obj_hash_size = num_objs;
58963+ s_tmp->obj_hash =
58964+ (struct acl_object_label **)
58965+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
58966+
58967+ if (!s_tmp->obj_hash)
58968+ return ERR_PTR(-ENOMEM);
58969+
58970+ memset(s_tmp->obj_hash, 0,
58971+ s_tmp->obj_hash_size *
58972+ sizeof (struct acl_object_label *));
58973+
58974+ /* add in objects */
58975+ err = copy_user_objs(ghash.first, s_tmp, role);
58976+
58977+ if (err)
58978+ return ERR_PTR(err);
58979+
58980+ /* set pointer for parent subject */
58981+ if (s_tmp->parent_subject) {
58982+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
58983+
58984+ if (IS_ERR(s_tmp2))
58985+ return s_tmp2;
58986+
58987+ s_tmp->parent_subject = s_tmp2;
58988+ }
58989+
58990+ /* add in ip acls */
58991+
58992+ if (!s_tmp->ip_num) {
58993+ s_tmp->ips = NULL;
58994+ goto insert;
58995+ }
58996+
58997+ i_tmp =
58998+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
58999+ sizeof (struct acl_ip_label *));
59000+
59001+ if (!i_tmp)
59002+ return ERR_PTR(-ENOMEM);
59003+
59004+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
59005+ *(i_tmp + i_num) =
59006+ (struct acl_ip_label *)
59007+ acl_alloc(sizeof (struct acl_ip_label));
59008+ if (!*(i_tmp + i_num))
59009+ return ERR_PTR(-ENOMEM);
59010+
59011+ if (copy_from_user
59012+ (&i_utmp2, s_tmp->ips + i_num,
59013+ sizeof (struct acl_ip_label *)))
59014+ return ERR_PTR(-EFAULT);
59015+
59016+ if (copy_from_user
59017+ (*(i_tmp + i_num), i_utmp2,
59018+ sizeof (struct acl_ip_label)))
59019+ return ERR_PTR(-EFAULT);
59020+
59021+ if ((*(i_tmp + i_num))->iface == NULL)
59022+ continue;
59023+
59024+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
59025+ if (!len || len >= IFNAMSIZ)
59026+ return ERR_PTR(-EINVAL);
59027+ tmp = acl_alloc(len);
59028+ if (tmp == NULL)
59029+ return ERR_PTR(-ENOMEM);
59030+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
59031+ return ERR_PTR(-EFAULT);
59032+ (*(i_tmp + i_num))->iface = tmp;
59033+ }
59034+
59035+ s_tmp->ips = i_tmp;
59036+
59037+insert:
59038+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
59039+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
59040+ return ERR_PTR(-ENOMEM);
59041+
59042+ return s_tmp;
59043+}
59044+
59045+static int
59046+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
59047+{
59048+ struct acl_subject_label s_pre;
59049+ struct acl_subject_label * ret;
59050+ int err;
59051+
59052+ while (userp) {
59053+ if (copy_from_user(&s_pre, userp,
59054+ sizeof (struct acl_subject_label)))
59055+ return -EFAULT;
59056+
59057+ ret = do_copy_user_subj(userp, role, NULL);
59058+
59059+ err = PTR_ERR(ret);
59060+ if (IS_ERR(ret))
59061+ return err;
59062+
59063+ insert_acl_subj_label(ret, role);
59064+
59065+ userp = s_pre.prev;
59066+ }
59067+
59068+ return 0;
59069+}
59070+
59071+static int
59072+copy_user_acl(struct gr_arg *arg)
59073+{
59074+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
59075+ struct acl_subject_label *subj_list;
59076+ struct sprole_pw *sptmp;
59077+ struct gr_hash_struct *ghash;
59078+ uid_t *domainlist;
59079+ unsigned int r_num;
59080+ unsigned int len;
59081+ char *tmp;
59082+ int err = 0;
59083+ __u16 i;
59084+ __u32 num_subjs;
59085+
59086+ /* we need a default and kernel role */
59087+ if (arg->role_db.num_roles < 2)
59088+ return -EINVAL;
59089+
59090+ /* copy special role authentication info from userspace */
59091+
59092+ num_sprole_pws = arg->num_sprole_pws;
59093+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
59094+
59095+ if (!acl_special_roles && num_sprole_pws)
59096+ return -ENOMEM;
59097+
59098+ for (i = 0; i < num_sprole_pws; i++) {
59099+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
59100+ if (!sptmp)
59101+ return -ENOMEM;
59102+ if (copy_from_user(sptmp, arg->sprole_pws + i,
59103+ sizeof (struct sprole_pw)))
59104+ return -EFAULT;
59105+
59106+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
59107+
59108+ if (!len || len >= GR_SPROLE_LEN)
59109+ return -EINVAL;
59110+
59111+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59112+ return -ENOMEM;
59113+
59114+ if (copy_from_user(tmp, sptmp->rolename, len))
59115+ return -EFAULT;
59116+
59117+ tmp[len-1] = '\0';
59118+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59119+ printk(KERN_ALERT "Copying special role %s\n", tmp);
59120+#endif
59121+ sptmp->rolename = tmp;
59122+ acl_special_roles[i] = sptmp;
59123+ }
59124+
59125+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
59126+
59127+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
59128+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
59129+
59130+ if (!r_tmp)
59131+ return -ENOMEM;
59132+
59133+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
59134+ sizeof (struct acl_role_label *)))
59135+ return -EFAULT;
59136+
59137+ if (copy_from_user(r_tmp, r_utmp2,
59138+ sizeof (struct acl_role_label)))
59139+ return -EFAULT;
59140+
59141+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
59142+
59143+ if (!len || len >= PATH_MAX)
59144+ return -EINVAL;
59145+
59146+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59147+ return -ENOMEM;
59148+
59149+ if (copy_from_user(tmp, r_tmp->rolename, len))
59150+ return -EFAULT;
59151+
59152+ tmp[len-1] = '\0';
59153+ r_tmp->rolename = tmp;
59154+
59155+ if (!strcmp(r_tmp->rolename, "default")
59156+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
59157+ default_role = r_tmp;
59158+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
59159+ kernel_role = r_tmp;
59160+ }
59161+
59162+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
59163+ return -ENOMEM;
59164+
59165+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
59166+ return -EFAULT;
59167+
59168+ r_tmp->hash = ghash;
59169+
59170+ num_subjs = count_user_subjs(r_tmp->hash->first);
59171+
59172+ r_tmp->subj_hash_size = num_subjs;
59173+ r_tmp->subj_hash =
59174+ (struct acl_subject_label **)
59175+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
59176+
59177+ if (!r_tmp->subj_hash)
59178+ return -ENOMEM;
59179+
59180+ err = copy_user_allowedips(r_tmp);
59181+ if (err)
59182+ return err;
59183+
59184+ /* copy domain info */
59185+ if (r_tmp->domain_children != NULL) {
59186+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
59187+ if (domainlist == NULL)
59188+ return -ENOMEM;
59189+
59190+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
59191+ return -EFAULT;
59192+
59193+ r_tmp->domain_children = domainlist;
59194+ }
59195+
59196+ err = copy_user_transitions(r_tmp);
59197+ if (err)
59198+ return err;
59199+
59200+ memset(r_tmp->subj_hash, 0,
59201+ r_tmp->subj_hash_size *
59202+ sizeof (struct acl_subject_label *));
59203+
59204+ /* acquire the list of subjects, then NULL out
59205+ the list prior to parsing the subjects for this role,
59206+ as during this parsing the list is replaced with a list
59207+ of *nested* subjects for the role
59208+ */
59209+ subj_list = r_tmp->hash->first;
59210+
59211+ /* set nested subject list to null */
59212+ r_tmp->hash->first = NULL;
59213+
59214+ err = copy_user_subjs(subj_list, r_tmp);
59215+
59216+ if (err)
59217+ return err;
59218+
59219+ insert_acl_role_label(r_tmp);
59220+ }
59221+
59222+ if (default_role == NULL || kernel_role == NULL)
59223+ return -EINVAL;
59224+
59225+ return err;
59226+}
59227+
59228+static int
59229+gracl_init(struct gr_arg *args)
59230+{
59231+ int error = 0;
59232+
59233+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
59234+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
59235+
59236+ if (init_variables(args)) {
59237+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
59238+ error = -ENOMEM;
59239+ free_variables();
59240+ goto out;
59241+ }
59242+
59243+ error = copy_user_acl(args);
59244+ free_init_variables();
59245+ if (error) {
59246+ free_variables();
59247+ goto out;
59248+ }
59249+
59250+ if ((error = gr_set_acls(0))) {
59251+ free_variables();
59252+ goto out;
59253+ }
59254+
59255+ pax_open_kernel();
59256+ gr_status |= GR_READY;
59257+ pax_close_kernel();
59258+
59259+ out:
59260+ return error;
59261+}
59262+
59263+/* derived from glibc fnmatch() 0: match, 1: no match*/
59264+
59265+static int
59266+glob_match(const char *p, const char *n)
59267+{
59268+ char c;
59269+
59270+ while ((c = *p++) != '\0') {
59271+ switch (c) {
59272+ case '?':
59273+ if (*n == '\0')
59274+ return 1;
59275+ else if (*n == '/')
59276+ return 1;
59277+ break;
59278+ case '\\':
59279+ if (*n != c)
59280+ return 1;
59281+ break;
59282+ case '*':
59283+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
59284+ if (*n == '/')
59285+ return 1;
59286+ else if (c == '?') {
59287+ if (*n == '\0')
59288+ return 1;
59289+ else
59290+ ++n;
59291+ }
59292+ }
59293+ if (c == '\0') {
59294+ return 0;
59295+ } else {
59296+ const char *endp;
59297+
59298+ if ((endp = strchr(n, '/')) == NULL)
59299+ endp = n + strlen(n);
59300+
59301+ if (c == '[') {
59302+ for (--p; n < endp; ++n)
59303+ if (!glob_match(p, n))
59304+ return 0;
59305+ } else if (c == '/') {
59306+ while (*n != '\0' && *n != '/')
59307+ ++n;
59308+ if (*n == '/' && !glob_match(p, n + 1))
59309+ return 0;
59310+ } else {
59311+ for (--p; n < endp; ++n)
59312+ if (*n == c && !glob_match(p, n))
59313+ return 0;
59314+ }
59315+
59316+ return 1;
59317+ }
59318+ case '[':
59319+ {
59320+ int not;
59321+ char cold;
59322+
59323+ if (*n == '\0' || *n == '/')
59324+ return 1;
59325+
59326+ not = (*p == '!' || *p == '^');
59327+ if (not)
59328+ ++p;
59329+
59330+ c = *p++;
59331+ for (;;) {
59332+ unsigned char fn = (unsigned char)*n;
59333+
59334+ if (c == '\0')
59335+ return 1;
59336+ else {
59337+ if (c == fn)
59338+ goto matched;
59339+ cold = c;
59340+ c = *p++;
59341+
59342+ if (c == '-' && *p != ']') {
59343+ unsigned char cend = *p++;
59344+
59345+ if (cend == '\0')
59346+ return 1;
59347+
59348+ if (cold <= fn && fn <= cend)
59349+ goto matched;
59350+
59351+ c = *p++;
59352+ }
59353+ }
59354+
59355+ if (c == ']')
59356+ break;
59357+ }
59358+ if (!not)
59359+ return 1;
59360+ break;
59361+ matched:
59362+ while (c != ']') {
59363+ if (c == '\0')
59364+ return 1;
59365+
59366+ c = *p++;
59367+ }
59368+ if (not)
59369+ return 1;
59370+ }
59371+ break;
59372+ default:
59373+ if (c != *n)
59374+ return 1;
59375+ }
59376+
59377+ ++n;
59378+ }
59379+
59380+ if (*n == '\0')
59381+ return 0;
59382+
59383+ if (*n == '/')
59384+ return 0;
59385+
59386+ return 1;
59387+}
59388+
59389+static struct acl_object_label *
59390+chk_glob_label(struct acl_object_label *globbed,
59391+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
59392+{
59393+ struct acl_object_label *tmp;
59394+
59395+ if (*path == NULL)
59396+ *path = gr_to_filename_nolock(dentry, mnt);
59397+
59398+ tmp = globbed;
59399+
59400+ while (tmp) {
59401+ if (!glob_match(tmp->filename, *path))
59402+ return tmp;
59403+ tmp = tmp->next;
59404+ }
59405+
59406+ return NULL;
59407+}
59408+
59409+static struct acl_object_label *
59410+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
59411+ const ino_t curr_ino, const dev_t curr_dev,
59412+ const struct acl_subject_label *subj, char **path, const int checkglob)
59413+{
59414+ struct acl_subject_label *tmpsubj;
59415+ struct acl_object_label *retval;
59416+ struct acl_object_label *retval2;
59417+
59418+ tmpsubj = (struct acl_subject_label *) subj;
59419+ read_lock(&gr_inode_lock);
59420+ do {
59421+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
59422+ if (retval) {
59423+ if (checkglob && retval->globbed) {
59424+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
59425+ if (retval2)
59426+ retval = retval2;
59427+ }
59428+ break;
59429+ }
59430+ } while ((tmpsubj = tmpsubj->parent_subject));
59431+ read_unlock(&gr_inode_lock);
59432+
59433+ return retval;
59434+}
59435+
59436+static __inline__ struct acl_object_label *
59437+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
59438+ struct dentry *curr_dentry,
59439+ const struct acl_subject_label *subj, char **path, const int checkglob)
59440+{
59441+ int newglob = checkglob;
59442+ ino_t inode;
59443+ dev_t device;
59444+
59445+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
59446+ as we don't want a / * rule to match instead of the / object
59447+ don't do this for create lookups that call this function though, since they're looking up
59448+ on the parent and thus need globbing checks on all paths
59449+ */
59450+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
59451+ newglob = GR_NO_GLOB;
59452+
59453+ spin_lock(&curr_dentry->d_lock);
59454+ inode = curr_dentry->d_inode->i_ino;
59455+ device = __get_dev(curr_dentry);
59456+ spin_unlock(&curr_dentry->d_lock);
59457+
59458+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
59459+}
59460+
59461+#ifdef CONFIG_HUGETLBFS
59462+static inline bool
59463+is_hugetlbfs_mnt(const struct vfsmount *mnt)
59464+{
59465+ int i;
59466+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
59467+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
59468+ return true;
59469+ }
59470+
59471+ return false;
59472+}
59473+#endif
59474+
59475+static struct acl_object_label *
59476+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59477+ const struct acl_subject_label *subj, char *path, const int checkglob)
59478+{
59479+ struct dentry *dentry = (struct dentry *) l_dentry;
59480+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
59481+ struct mount *real_mnt = real_mount(mnt);
59482+ struct acl_object_label *retval;
59483+ struct dentry *parent;
59484+
59485+ br_read_lock(&vfsmount_lock);
59486+ write_seqlock(&rename_lock);
59487+
59488+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
59489+#ifdef CONFIG_NET
59490+ mnt == sock_mnt ||
59491+#endif
59492+#ifdef CONFIG_HUGETLBFS
59493+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
59494+#endif
59495+ /* ignore Eric Biederman */
59496+ IS_PRIVATE(l_dentry->d_inode))) {
59497+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
59498+ goto out;
59499+ }
59500+
59501+ for (;;) {
59502+ if (dentry == real_root.dentry && mnt == real_root.mnt)
59503+ break;
59504+
59505+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
59506+ if (!mnt_has_parent(real_mnt))
59507+ break;
59508+
59509+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
59510+ if (retval != NULL)
59511+ goto out;
59512+
59513+ dentry = real_mnt->mnt_mountpoint;
59514+ real_mnt = real_mnt->mnt_parent;
59515+ mnt = &real_mnt->mnt;
59516+ continue;
59517+ }
59518+
59519+ parent = dentry->d_parent;
59520+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
59521+ if (retval != NULL)
59522+ goto out;
59523+
59524+ dentry = parent;
59525+ }
59526+
59527+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
59528+
59529+ /* real_root is pinned so we don't have to hold a reference */
59530+ if (retval == NULL)
59531+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
59532+out:
59533+ write_sequnlock(&rename_lock);
59534+ br_read_unlock(&vfsmount_lock);
59535+
59536+ BUG_ON(retval == NULL);
59537+
59538+ return retval;
59539+}
59540+
59541+static __inline__ struct acl_object_label *
59542+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59543+ const struct acl_subject_label *subj)
59544+{
59545+ char *path = NULL;
59546+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
59547+}
59548+
59549+static __inline__ struct acl_object_label *
59550+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59551+ const struct acl_subject_label *subj)
59552+{
59553+ char *path = NULL;
59554+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
59555+}
59556+
59557+static __inline__ struct acl_object_label *
59558+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59559+ const struct acl_subject_label *subj, char *path)
59560+{
59561+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
59562+}
59563+
59564+static struct acl_subject_label *
59565+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59566+ const struct acl_role_label *role)
59567+{
59568+ struct dentry *dentry = (struct dentry *) l_dentry;
59569+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
59570+ struct mount *real_mnt = real_mount(mnt);
59571+ struct acl_subject_label *retval;
59572+ struct dentry *parent;
59573+
59574+ br_read_lock(&vfsmount_lock);
59575+ write_seqlock(&rename_lock);
59576+
59577+ for (;;) {
59578+ if (dentry == real_root.dentry && mnt == real_root.mnt)
59579+ break;
59580+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
59581+ if (!mnt_has_parent(real_mnt))
59582+ break;
59583+
59584+ spin_lock(&dentry->d_lock);
59585+ read_lock(&gr_inode_lock);
59586+ retval =
59587+ lookup_acl_subj_label(dentry->d_inode->i_ino,
59588+ __get_dev(dentry), role);
59589+ read_unlock(&gr_inode_lock);
59590+ spin_unlock(&dentry->d_lock);
59591+ if (retval != NULL)
59592+ goto out;
59593+
59594+ dentry = real_mnt->mnt_mountpoint;
59595+ real_mnt = real_mnt->mnt_parent;
59596+ mnt = &real_mnt->mnt;
59597+ continue;
59598+ }
59599+
59600+ spin_lock(&dentry->d_lock);
59601+ read_lock(&gr_inode_lock);
59602+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
59603+ __get_dev(dentry), role);
59604+ read_unlock(&gr_inode_lock);
59605+ parent = dentry->d_parent;
59606+ spin_unlock(&dentry->d_lock);
59607+
59608+ if (retval != NULL)
59609+ goto out;
59610+
59611+ dentry = parent;
59612+ }
59613+
59614+ spin_lock(&dentry->d_lock);
59615+ read_lock(&gr_inode_lock);
59616+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
59617+ __get_dev(dentry), role);
59618+ read_unlock(&gr_inode_lock);
59619+ spin_unlock(&dentry->d_lock);
59620+
59621+ if (unlikely(retval == NULL)) {
59622+ /* real_root is pinned, we don't need to hold a reference */
59623+ read_lock(&gr_inode_lock);
59624+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
59625+ __get_dev(real_root.dentry), role);
59626+ read_unlock(&gr_inode_lock);
59627+ }
59628+out:
59629+ write_sequnlock(&rename_lock);
59630+ br_read_unlock(&vfsmount_lock);
59631+
59632+ BUG_ON(retval == NULL);
59633+
59634+ return retval;
59635+}
59636+
59637+static void
59638+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
59639+{
59640+ struct task_struct *task = current;
59641+ const struct cred *cred = current_cred();
59642+
59643+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
59644+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
59645+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
59646+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
59647+
59648+ return;
59649+}
59650+
59651+static void
59652+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
59653+{
59654+ struct task_struct *task = current;
59655+ const struct cred *cred = current_cred();
59656+
59657+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
59658+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
59659+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
59660+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
59661+
59662+ return;
59663+}
59664+
59665+static void
59666+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
59667+{
59668+ struct task_struct *task = current;
59669+ const struct cred *cred = current_cred();
59670+
59671+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
59672+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
59673+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
59674+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
59675+
59676+ return;
59677+}
59678+
59679+__u32
59680+gr_search_file(const struct dentry * dentry, const __u32 mode,
59681+ const struct vfsmount * mnt)
59682+{
59683+ __u32 retval = mode;
59684+ struct acl_subject_label *curracl;
59685+ struct acl_object_label *currobj;
59686+
59687+ if (unlikely(!(gr_status & GR_READY)))
59688+ return (mode & ~GR_AUDITS);
59689+
59690+ curracl = current->acl;
59691+
59692+ currobj = chk_obj_label(dentry, mnt, curracl);
59693+ retval = currobj->mode & mode;
59694+
59695+ /* if we're opening a specified transfer file for writing
59696+ (e.g. /dev/initctl), then transfer our role to init
59697+ */
59698+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
59699+ current->role->roletype & GR_ROLE_PERSIST)) {
59700+ struct task_struct *task = init_pid_ns.child_reaper;
59701+
59702+ if (task->role != current->role) {
59703+ task->acl_sp_role = 0;
59704+ task->acl_role_id = current->acl_role_id;
59705+ task->role = current->role;
59706+ rcu_read_lock();
59707+ read_lock(&grsec_exec_file_lock);
59708+ gr_apply_subject_to_task(task);
59709+ read_unlock(&grsec_exec_file_lock);
59710+ rcu_read_unlock();
59711+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
59712+ }
59713+ }
59714+
59715+ if (unlikely
59716+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
59717+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
59718+ __u32 new_mode = mode;
59719+
59720+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
59721+
59722+ retval = new_mode;
59723+
59724+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
59725+ new_mode |= GR_INHERIT;
59726+
59727+ if (!(mode & GR_NOLEARN))
59728+ gr_log_learn(dentry, mnt, new_mode);
59729+ }
59730+
59731+ return retval;
59732+}
59733+
59734+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
59735+ const struct dentry *parent,
59736+ const struct vfsmount *mnt)
59737+{
59738+ struct name_entry *match;
59739+ struct acl_object_label *matchpo;
59740+ struct acl_subject_label *curracl;
59741+ char *path;
59742+
59743+ if (unlikely(!(gr_status & GR_READY)))
59744+ return NULL;
59745+
59746+ preempt_disable();
59747+ path = gr_to_filename_rbac(new_dentry, mnt);
59748+ match = lookup_name_entry_create(path);
59749+
59750+ curracl = current->acl;
59751+
59752+ if (match) {
59753+ read_lock(&gr_inode_lock);
59754+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
59755+ read_unlock(&gr_inode_lock);
59756+
59757+ if (matchpo) {
59758+ preempt_enable();
59759+ return matchpo;
59760+ }
59761+ }
59762+
59763+ // lookup parent
59764+
59765+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
59766+
59767+ preempt_enable();
59768+ return matchpo;
59769+}
59770+
59771+__u32
59772+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
59773+ const struct vfsmount * mnt, const __u32 mode)
59774+{
59775+ struct acl_object_label *matchpo;
59776+ __u32 retval;
59777+
59778+ if (unlikely(!(gr_status & GR_READY)))
59779+ return (mode & ~GR_AUDITS);
59780+
59781+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
59782+
59783+ retval = matchpo->mode & mode;
59784+
59785+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
59786+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
59787+ __u32 new_mode = mode;
59788+
59789+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
59790+
59791+ gr_log_learn(new_dentry, mnt, new_mode);
59792+ return new_mode;
59793+ }
59794+
59795+ return retval;
59796+}
59797+
59798+__u32
59799+gr_check_link(const struct dentry * new_dentry,
59800+ const struct dentry * parent_dentry,
59801+ const struct vfsmount * parent_mnt,
59802+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
59803+{
59804+ struct acl_object_label *obj;
59805+ __u32 oldmode, newmode;
59806+ __u32 needmode;
59807+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
59808+ GR_DELETE | GR_INHERIT;
59809+
59810+ if (unlikely(!(gr_status & GR_READY)))
59811+ return (GR_CREATE | GR_LINK);
59812+
59813+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
59814+ oldmode = obj->mode;
59815+
59816+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
59817+ newmode = obj->mode;
59818+
59819+ needmode = newmode & checkmodes;
59820+
59821+ // old name for hardlink must have at least the permissions of the new name
59822+ if ((oldmode & needmode) != needmode)
59823+ goto bad;
59824+
59825+ // if old name had restrictions/auditing, make sure the new name does as well
59826+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
59827+
59828+ // don't allow hardlinking of suid/sgid/fcapped files without permission
59829+ if (is_privileged_binary(old_dentry))
59830+ needmode |= GR_SETID;
59831+
59832+ if ((newmode & needmode) != needmode)
59833+ goto bad;
59834+
59835+ // enforce minimum permissions
59836+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
59837+ return newmode;
59838+bad:
59839+ needmode = oldmode;
59840+ if (is_privileged_binary(old_dentry))
59841+ needmode |= GR_SETID;
59842+
59843+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
59844+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
59845+ return (GR_CREATE | GR_LINK);
59846+ } else if (newmode & GR_SUPPRESS)
59847+ return GR_SUPPRESS;
59848+ else
59849+ return 0;
59850+}
59851+
59852+int
59853+gr_check_hidden_task(const struct task_struct *task)
59854+{
59855+ if (unlikely(!(gr_status & GR_READY)))
59856+ return 0;
59857+
59858+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
59859+ return 1;
59860+
59861+ return 0;
59862+}
59863+
59864+int
59865+gr_check_protected_task(const struct task_struct *task)
59866+{
59867+ if (unlikely(!(gr_status & GR_READY) || !task))
59868+ return 0;
59869+
59870+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
59871+ task->acl != current->acl)
59872+ return 1;
59873+
59874+ return 0;
59875+}
59876+
59877+int
59878+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
59879+{
59880+ struct task_struct *p;
59881+ int ret = 0;
59882+
59883+ if (unlikely(!(gr_status & GR_READY) || !pid))
59884+ return ret;
59885+
59886+ read_lock(&tasklist_lock);
59887+ do_each_pid_task(pid, type, p) {
59888+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
59889+ p->acl != current->acl) {
59890+ ret = 1;
59891+ goto out;
59892+ }
59893+ } while_each_pid_task(pid, type, p);
59894+out:
59895+ read_unlock(&tasklist_lock);
59896+
59897+ return ret;
59898+}
59899+
59900+void
59901+gr_copy_label(struct task_struct *tsk)
59902+{
59903+ tsk->signal->used_accept = 0;
59904+ tsk->acl_sp_role = 0;
59905+ tsk->acl_role_id = current->acl_role_id;
59906+ tsk->acl = current->acl;
59907+ tsk->role = current->role;
59908+ tsk->signal->curr_ip = current->signal->curr_ip;
59909+ tsk->signal->saved_ip = current->signal->saved_ip;
59910+ if (current->exec_file)
59911+ get_file(current->exec_file);
59912+ tsk->exec_file = current->exec_file;
59913+ tsk->is_writable = current->is_writable;
59914+ if (unlikely(current->signal->used_accept)) {
59915+ current->signal->curr_ip = 0;
59916+ current->signal->saved_ip = 0;
59917+ }
59918+
59919+ return;
59920+}
59921+
59922+static void
59923+gr_set_proc_res(struct task_struct *task)
59924+{
59925+ struct acl_subject_label *proc;
59926+ unsigned short i;
59927+
59928+ proc = task->acl;
59929+
59930+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
59931+ return;
59932+
59933+ for (i = 0; i < RLIM_NLIMITS; i++) {
59934+ if (!(proc->resmask & (1U << i)))
59935+ continue;
59936+
59937+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
59938+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
59939+
59940+ if (i == RLIMIT_CPU)
59941+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
59942+ }
59943+
59944+ return;
59945+}
59946+
59947+extern int __gr_process_user_ban(struct user_struct *user);
59948+
59949+int
59950+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
59951+{
59952+ unsigned int i;
59953+ __u16 num;
59954+ uid_t *uidlist;
59955+ uid_t curuid;
59956+ int realok = 0;
59957+ int effectiveok = 0;
59958+ int fsok = 0;
59959+ uid_t globalreal, globaleffective, globalfs;
59960+
59961+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59962+ struct user_struct *user;
59963+
59964+ if (!uid_valid(real))
59965+ goto skipit;
59966+
59967+ /* find user based on global namespace */
59968+
59969+ globalreal = GR_GLOBAL_UID(real);
59970+
59971+ user = find_user(make_kuid(&init_user_ns, globalreal));
59972+ if (user == NULL)
59973+ goto skipit;
59974+
59975+ if (__gr_process_user_ban(user)) {
59976+ /* for find_user */
59977+ free_uid(user);
59978+ return 1;
59979+ }
59980+
59981+ /* for find_user */
59982+ free_uid(user);
59983+
59984+skipit:
59985+#endif
59986+
59987+ if (unlikely(!(gr_status & GR_READY)))
59988+ return 0;
59989+
59990+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59991+ gr_log_learn_uid_change(real, effective, fs);
59992+
59993+ num = current->acl->user_trans_num;
59994+ uidlist = current->acl->user_transitions;
59995+
59996+ if (uidlist == NULL)
59997+ return 0;
59998+
59999+ if (!uid_valid(real)) {
60000+ realok = 1;
60001+ globalreal = (uid_t)-1;
60002+ } else {
60003+ globalreal = GR_GLOBAL_UID(real);
60004+ }
60005+ if (!uid_valid(effective)) {
60006+ effectiveok = 1;
60007+ globaleffective = (uid_t)-1;
60008+ } else {
60009+ globaleffective = GR_GLOBAL_UID(effective);
60010+ }
60011+ if (!uid_valid(fs)) {
60012+ fsok = 1;
60013+ globalfs = (uid_t)-1;
60014+ } else {
60015+ globalfs = GR_GLOBAL_UID(fs);
60016+ }
60017+
60018+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
60019+ for (i = 0; i < num; i++) {
60020+ curuid = uidlist[i];
60021+ if (globalreal == curuid)
60022+ realok = 1;
60023+ if (globaleffective == curuid)
60024+ effectiveok = 1;
60025+ if (globalfs == curuid)
60026+ fsok = 1;
60027+ }
60028+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
60029+ for (i = 0; i < num; i++) {
60030+ curuid = uidlist[i];
60031+ if (globalreal == curuid)
60032+ break;
60033+ if (globaleffective == curuid)
60034+ break;
60035+ if (globalfs == curuid)
60036+ break;
60037+ }
60038+ /* not in deny list */
60039+ if (i == num) {
60040+ realok = 1;
60041+ effectiveok = 1;
60042+ fsok = 1;
60043+ }
60044+ }
60045+
60046+ if (realok && effectiveok && fsok)
60047+ return 0;
60048+ else {
60049+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
60050+ return 1;
60051+ }
60052+}
60053+
60054+int
60055+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
60056+{
60057+ unsigned int i;
60058+ __u16 num;
60059+ gid_t *gidlist;
60060+ gid_t curgid;
60061+ int realok = 0;
60062+ int effectiveok = 0;
60063+ int fsok = 0;
60064+ gid_t globalreal, globaleffective, globalfs;
60065+
60066+ if (unlikely(!(gr_status & GR_READY)))
60067+ return 0;
60068+
60069+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60070+ gr_log_learn_gid_change(real, effective, fs);
60071+
60072+ num = current->acl->group_trans_num;
60073+ gidlist = current->acl->group_transitions;
60074+
60075+ if (gidlist == NULL)
60076+ return 0;
60077+
60078+ if (!gid_valid(real)) {
60079+ realok = 1;
60080+ globalreal = (gid_t)-1;
60081+ } else {
60082+ globalreal = GR_GLOBAL_GID(real);
60083+ }
60084+ if (!gid_valid(effective)) {
60085+ effectiveok = 1;
60086+ globaleffective = (gid_t)-1;
60087+ } else {
60088+ globaleffective = GR_GLOBAL_GID(effective);
60089+ }
60090+ if (!gid_valid(fs)) {
60091+ fsok = 1;
60092+ globalfs = (gid_t)-1;
60093+ } else {
60094+ globalfs = GR_GLOBAL_GID(fs);
60095+ }
60096+
60097+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
60098+ for (i = 0; i < num; i++) {
60099+ curgid = gidlist[i];
60100+ if (globalreal == curgid)
60101+ realok = 1;
60102+ if (globaleffective == curgid)
60103+ effectiveok = 1;
60104+ if (globalfs == curgid)
60105+ fsok = 1;
60106+ }
60107+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
60108+ for (i = 0; i < num; i++) {
60109+ curgid = gidlist[i];
60110+ if (globalreal == curgid)
60111+ break;
60112+ if (globaleffective == curgid)
60113+ break;
60114+ if (globalfs == curgid)
60115+ break;
60116+ }
60117+ /* not in deny list */
60118+ if (i == num) {
60119+ realok = 1;
60120+ effectiveok = 1;
60121+ fsok = 1;
60122+ }
60123+ }
60124+
60125+ if (realok && effectiveok && fsok)
60126+ return 0;
60127+ else {
60128+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
60129+ return 1;
60130+ }
60131+}
60132+
60133+extern int gr_acl_is_capable(const int cap);
60134+
60135+void
60136+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
60137+{
60138+ struct acl_role_label *role = task->role;
60139+ struct acl_subject_label *subj = NULL;
60140+ struct acl_object_label *obj;
60141+ struct file *filp;
60142+ uid_t uid;
60143+ gid_t gid;
60144+
60145+ if (unlikely(!(gr_status & GR_READY)))
60146+ return;
60147+
60148+ uid = GR_GLOBAL_UID(kuid);
60149+ gid = GR_GLOBAL_GID(kgid);
60150+
60151+ filp = task->exec_file;
60152+
60153+ /* kernel process, we'll give them the kernel role */
60154+ if (unlikely(!filp)) {
60155+ task->role = kernel_role;
60156+ task->acl = kernel_role->root_label;
60157+ return;
60158+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
60159+ role = lookup_acl_role_label(task, uid, gid);
60160+
60161+ /* don't change the role if we're not a privileged process */
60162+ if (role && task->role != role &&
60163+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
60164+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
60165+ return;
60166+
60167+ /* perform subject lookup in possibly new role
60168+ we can use this result below in the case where role == task->role
60169+ */
60170+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
60171+
60172+ /* if we changed uid/gid, but result in the same role
60173+ and are using inheritance, don't lose the inherited subject
60174+ if current subject is other than what normal lookup
60175+ would result in, we arrived via inheritance, don't
60176+ lose subject
60177+ */
60178+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
60179+ (subj == task->acl)))
60180+ task->acl = subj;
60181+
60182+ task->role = role;
60183+
60184+ task->is_writable = 0;
60185+
60186+ /* ignore additional mmap checks for processes that are writable
60187+ by the default ACL */
60188+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60189+ if (unlikely(obj->mode & GR_WRITE))
60190+ task->is_writable = 1;
60191+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
60192+ if (unlikely(obj->mode & GR_WRITE))
60193+ task->is_writable = 1;
60194+
60195+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60196+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task_pid_nr(task), task->role->rolename, task->acl->filename);
60197+#endif
60198+
60199+ gr_set_proc_res(task);
60200+
60201+ return;
60202+}
60203+
60204+int
60205+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
60206+ const int unsafe_flags)
60207+{
60208+ struct task_struct *task = current;
60209+ struct acl_subject_label *newacl;
60210+ struct acl_object_label *obj;
60211+ __u32 retmode;
60212+
60213+ if (unlikely(!(gr_status & GR_READY)))
60214+ return 0;
60215+
60216+ newacl = chk_subj_label(dentry, mnt, task->role);
60217+
60218+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
60219+ did an exec
60220+ */
60221+ rcu_read_lock();
60222+ read_lock(&tasklist_lock);
60223+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
60224+ (task->parent->acl->mode & GR_POVERRIDE))) {
60225+ read_unlock(&tasklist_lock);
60226+ rcu_read_unlock();
60227+ goto skip_check;
60228+ }
60229+ read_unlock(&tasklist_lock);
60230+ rcu_read_unlock();
60231+
60232+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
60233+ !(task->role->roletype & GR_ROLE_GOD) &&
60234+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
60235+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
60236+ if (unsafe_flags & LSM_UNSAFE_SHARE)
60237+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
60238+ else
60239+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
60240+ return -EACCES;
60241+ }
60242+
60243+skip_check:
60244+
60245+ obj = chk_obj_label(dentry, mnt, task->acl);
60246+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
60247+
60248+ if (!(task->acl->mode & GR_INHERITLEARN) &&
60249+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
60250+ if (obj->nested)
60251+ task->acl = obj->nested;
60252+ else
60253+ task->acl = newacl;
60254+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
60255+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
60256+
60257+ task->is_writable = 0;
60258+
60259+ /* ignore additional mmap checks for processes that are writable
60260+ by the default ACL */
60261+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
60262+ if (unlikely(obj->mode & GR_WRITE))
60263+ task->is_writable = 1;
60264+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
60265+ if (unlikely(obj->mode & GR_WRITE))
60266+ task->is_writable = 1;
60267+
60268+ gr_set_proc_res(task);
60269+
60270+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60271+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task_pid_nr(task), task->role->rolename, task->acl->filename);
60272+#endif
60273+ return 0;
60274+}
60275+
60276+/* always called with valid inodev ptr */
60277+static void
60278+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
60279+{
60280+ struct acl_object_label *matchpo;
60281+ struct acl_subject_label *matchps;
60282+ struct acl_subject_label *subj;
60283+ struct acl_role_label *role;
60284+ unsigned int x;
60285+
60286+ FOR_EACH_ROLE_START(role)
60287+ FOR_EACH_SUBJECT_START(role, subj, x)
60288+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
60289+ matchpo->mode |= GR_DELETED;
60290+ FOR_EACH_SUBJECT_END(subj,x)
60291+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
60292+ /* nested subjects aren't in the role's subj_hash table */
60293+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
60294+ matchpo->mode |= GR_DELETED;
60295+ FOR_EACH_NESTED_SUBJECT_END(subj)
60296+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
60297+ matchps->mode |= GR_DELETED;
60298+ FOR_EACH_ROLE_END(role)
60299+
60300+ inodev->nentry->deleted = 1;
60301+
60302+ return;
60303+}
60304+
60305+void
60306+gr_handle_delete(const ino_t ino, const dev_t dev)
60307+{
60308+ struct inodev_entry *inodev;
60309+
60310+ if (unlikely(!(gr_status & GR_READY)))
60311+ return;
60312+
60313+ write_lock(&gr_inode_lock);
60314+ inodev = lookup_inodev_entry(ino, dev);
60315+ if (inodev != NULL)
60316+ do_handle_delete(inodev, ino, dev);
60317+ write_unlock(&gr_inode_lock);
60318+
60319+ return;
60320+}
60321+
60322+static void
60323+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
60324+ const ino_t newinode, const dev_t newdevice,
60325+ struct acl_subject_label *subj)
60326+{
60327+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
60328+ struct acl_object_label *match;
60329+
60330+ match = subj->obj_hash[index];
60331+
60332+ while (match && (match->inode != oldinode ||
60333+ match->device != olddevice ||
60334+ !(match->mode & GR_DELETED)))
60335+ match = match->next;
60336+
60337+ if (match && (match->inode == oldinode)
60338+ && (match->device == olddevice)
60339+ && (match->mode & GR_DELETED)) {
60340+ if (match->prev == NULL) {
60341+ subj->obj_hash[index] = match->next;
60342+ if (match->next != NULL)
60343+ match->next->prev = NULL;
60344+ } else {
60345+ match->prev->next = match->next;
60346+ if (match->next != NULL)
60347+ match->next->prev = match->prev;
60348+ }
60349+ match->prev = NULL;
60350+ match->next = NULL;
60351+ match->inode = newinode;
60352+ match->device = newdevice;
60353+ match->mode &= ~GR_DELETED;
60354+
60355+ insert_acl_obj_label(match, subj);
60356+ }
60357+
60358+ return;
60359+}
60360+
60361+static void
60362+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
60363+ const ino_t newinode, const dev_t newdevice,
60364+ struct acl_role_label *role)
60365+{
60366+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
60367+ struct acl_subject_label *match;
60368+
60369+ match = role->subj_hash[index];
60370+
60371+ while (match && (match->inode != oldinode ||
60372+ match->device != olddevice ||
60373+ !(match->mode & GR_DELETED)))
60374+ match = match->next;
60375+
60376+ if (match && (match->inode == oldinode)
60377+ && (match->device == olddevice)
60378+ && (match->mode & GR_DELETED)) {
60379+ if (match->prev == NULL) {
60380+ role->subj_hash[index] = match->next;
60381+ if (match->next != NULL)
60382+ match->next->prev = NULL;
60383+ } else {
60384+ match->prev->next = match->next;
60385+ if (match->next != NULL)
60386+ match->next->prev = match->prev;
60387+ }
60388+ match->prev = NULL;
60389+ match->next = NULL;
60390+ match->inode = newinode;
60391+ match->device = newdevice;
60392+ match->mode &= ~GR_DELETED;
60393+
60394+ insert_acl_subj_label(match, role);
60395+ }
60396+
60397+ return;
60398+}
60399+
60400+static void
60401+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
60402+ const ino_t newinode, const dev_t newdevice)
60403+{
60404+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
60405+ struct inodev_entry *match;
60406+
60407+ match = inodev_set.i_hash[index];
60408+
60409+ while (match && (match->nentry->inode != oldinode ||
60410+ match->nentry->device != olddevice || !match->nentry->deleted))
60411+ match = match->next;
60412+
60413+ if (match && (match->nentry->inode == oldinode)
60414+ && (match->nentry->device == olddevice) &&
60415+ match->nentry->deleted) {
60416+ if (match->prev == NULL) {
60417+ inodev_set.i_hash[index] = match->next;
60418+ if (match->next != NULL)
60419+ match->next->prev = NULL;
60420+ } else {
60421+ match->prev->next = match->next;
60422+ if (match->next != NULL)
60423+ match->next->prev = match->prev;
60424+ }
60425+ match->prev = NULL;
60426+ match->next = NULL;
60427+ match->nentry->inode = newinode;
60428+ match->nentry->device = newdevice;
60429+ match->nentry->deleted = 0;
60430+
60431+ insert_inodev_entry(match);
60432+ }
60433+
60434+ return;
60435+}
60436+
60437+static void
60438+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
60439+{
60440+ struct acl_subject_label *subj;
60441+ struct acl_role_label *role;
60442+ unsigned int x;
60443+
60444+ FOR_EACH_ROLE_START(role)
60445+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
60446+
60447+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
60448+ if ((subj->inode == ino) && (subj->device == dev)) {
60449+ subj->inode = ino;
60450+ subj->device = dev;
60451+ }
60452+ /* nested subjects aren't in the role's subj_hash table */
60453+ update_acl_obj_label(matchn->inode, matchn->device,
60454+ ino, dev, subj);
60455+ FOR_EACH_NESTED_SUBJECT_END(subj)
60456+ FOR_EACH_SUBJECT_START(role, subj, x)
60457+ update_acl_obj_label(matchn->inode, matchn->device,
60458+ ino, dev, subj);
60459+ FOR_EACH_SUBJECT_END(subj,x)
60460+ FOR_EACH_ROLE_END(role)
60461+
60462+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
60463+
60464+ return;
60465+}
60466+
60467+static void
60468+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
60469+ const struct vfsmount *mnt)
60470+{
60471+ ino_t ino = dentry->d_inode->i_ino;
60472+ dev_t dev = __get_dev(dentry);
60473+
60474+ __do_handle_create(matchn, ino, dev);
60475+
60476+ return;
60477+}
60478+
60479+void
60480+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
60481+{
60482+ struct name_entry *matchn;
60483+
60484+ if (unlikely(!(gr_status & GR_READY)))
60485+ return;
60486+
60487+ preempt_disable();
60488+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
60489+
60490+ if (unlikely((unsigned long)matchn)) {
60491+ write_lock(&gr_inode_lock);
60492+ do_handle_create(matchn, dentry, mnt);
60493+ write_unlock(&gr_inode_lock);
60494+ }
60495+ preempt_enable();
60496+
60497+ return;
60498+}
60499+
60500+void
60501+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
60502+{
60503+ struct name_entry *matchn;
60504+
60505+ if (unlikely(!(gr_status & GR_READY)))
60506+ return;
60507+
60508+ preempt_disable();
60509+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
60510+
60511+ if (unlikely((unsigned long)matchn)) {
60512+ write_lock(&gr_inode_lock);
60513+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
60514+ write_unlock(&gr_inode_lock);
60515+ }
60516+ preempt_enable();
60517+
60518+ return;
60519+}
60520+
60521+void
60522+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
60523+ struct dentry *old_dentry,
60524+ struct dentry *new_dentry,
60525+ struct vfsmount *mnt, const __u8 replace)
60526+{
60527+ struct name_entry *matchn;
60528+ struct inodev_entry *inodev;
60529+ struct inode *inode = new_dentry->d_inode;
60530+ ino_t old_ino = old_dentry->d_inode->i_ino;
60531+ dev_t old_dev = __get_dev(old_dentry);
60532+
60533+ /* vfs_rename swaps the name and parent link for old_dentry and
60534+ new_dentry
60535+ at this point, old_dentry has the new name, parent link, and inode
60536+ for the renamed file
60537+ if a file is being replaced by a rename, new_dentry has the inode
60538+ and name for the replaced file
60539+ */
60540+
60541+ if (unlikely(!(gr_status & GR_READY)))
60542+ return;
60543+
60544+ preempt_disable();
60545+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
60546+
60547+ /* we wouldn't have to check d_inode if it weren't for
60548+ NFS silly-renaming
60549+ */
60550+
60551+ write_lock(&gr_inode_lock);
60552+ if (unlikely(replace && inode)) {
60553+ ino_t new_ino = inode->i_ino;
60554+ dev_t new_dev = __get_dev(new_dentry);
60555+
60556+ inodev = lookup_inodev_entry(new_ino, new_dev);
60557+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
60558+ do_handle_delete(inodev, new_ino, new_dev);
60559+ }
60560+
60561+ inodev = lookup_inodev_entry(old_ino, old_dev);
60562+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
60563+ do_handle_delete(inodev, old_ino, old_dev);
60564+
60565+ if (unlikely((unsigned long)matchn))
60566+ do_handle_create(matchn, old_dentry, mnt);
60567+
60568+ write_unlock(&gr_inode_lock);
60569+ preempt_enable();
60570+
60571+ return;
60572+}
60573+
60574+static int
60575+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
60576+ unsigned char **sum)
60577+{
60578+ struct acl_role_label *r;
60579+ struct role_allowed_ip *ipp;
60580+ struct role_transition *trans;
60581+ unsigned int i;
60582+ int found = 0;
60583+ u32 curr_ip = current->signal->curr_ip;
60584+
60585+ current->signal->saved_ip = curr_ip;
60586+
60587+ /* check transition table */
60588+
60589+ for (trans = current->role->transitions; trans; trans = trans->next) {
60590+ if (!strcmp(rolename, trans->rolename)) {
60591+ found = 1;
60592+ break;
60593+ }
60594+ }
60595+
60596+ if (!found)
60597+ return 0;
60598+
60599+ /* handle special roles that do not require authentication
60600+ and check ip */
60601+
60602+ FOR_EACH_ROLE_START(r)
60603+ if (!strcmp(rolename, r->rolename) &&
60604+ (r->roletype & GR_ROLE_SPECIAL)) {
60605+ found = 0;
60606+ if (r->allowed_ips != NULL) {
60607+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
60608+ if ((ntohl(curr_ip) & ipp->netmask) ==
60609+ (ntohl(ipp->addr) & ipp->netmask))
60610+ found = 1;
60611+ }
60612+ } else
60613+ found = 2;
60614+ if (!found)
60615+ return 0;
60616+
60617+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
60618+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
60619+ *salt = NULL;
60620+ *sum = NULL;
60621+ return 1;
60622+ }
60623+ }
60624+ FOR_EACH_ROLE_END(r)
60625+
60626+ for (i = 0; i < num_sprole_pws; i++) {
60627+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
60628+ *salt = acl_special_roles[i]->salt;
60629+ *sum = acl_special_roles[i]->sum;
60630+ return 1;
60631+ }
60632+ }
60633+
60634+ return 0;
60635+}
60636+
60637+static void
60638+assign_special_role(char *rolename)
60639+{
60640+ struct acl_object_label *obj;
60641+ struct acl_role_label *r;
60642+ struct acl_role_label *assigned = NULL;
60643+ struct task_struct *tsk;
60644+ struct file *filp;
60645+
60646+ FOR_EACH_ROLE_START(r)
60647+ if (!strcmp(rolename, r->rolename) &&
60648+ (r->roletype & GR_ROLE_SPECIAL)) {
60649+ assigned = r;
60650+ break;
60651+ }
60652+ FOR_EACH_ROLE_END(r)
60653+
60654+ if (!assigned)
60655+ return;
60656+
60657+ read_lock(&tasklist_lock);
60658+ read_lock(&grsec_exec_file_lock);
60659+
60660+ tsk = current->real_parent;
60661+ if (tsk == NULL)
60662+ goto out_unlock;
60663+
60664+ filp = tsk->exec_file;
60665+ if (filp == NULL)
60666+ goto out_unlock;
60667+
60668+ tsk->is_writable = 0;
60669+
60670+ tsk->acl_sp_role = 1;
60671+ tsk->acl_role_id = ++acl_sp_role_value;
60672+ tsk->role = assigned;
60673+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
60674+
60675+ /* ignore additional mmap checks for processes that are writable
60676+ by the default ACL */
60677+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60678+ if (unlikely(obj->mode & GR_WRITE))
60679+ tsk->is_writable = 1;
60680+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
60681+ if (unlikely(obj->mode & GR_WRITE))
60682+ tsk->is_writable = 1;
60683+
60684+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60685+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
60686+#endif
60687+
60688+out_unlock:
60689+ read_unlock(&grsec_exec_file_lock);
60690+ read_unlock(&tasklist_lock);
60691+ return;
60692+}
60693+
60694+int gr_check_secure_terminal(struct task_struct *task)
60695+{
60696+ struct task_struct *p, *p2, *p3;
60697+ struct files_struct *files;
60698+ struct fdtable *fdt;
60699+ struct file *our_file = NULL, *file;
60700+ int i;
60701+
60702+ if (task->signal->tty == NULL)
60703+ return 1;
60704+
60705+ files = get_files_struct(task);
60706+ if (files != NULL) {
60707+ rcu_read_lock();
60708+ fdt = files_fdtable(files);
60709+ for (i=0; i < fdt->max_fds; i++) {
60710+ file = fcheck_files(files, i);
60711+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
60712+ get_file(file);
60713+ our_file = file;
60714+ }
60715+ }
60716+ rcu_read_unlock();
60717+ put_files_struct(files);
60718+ }
60719+
60720+ if (our_file == NULL)
60721+ return 1;
60722+
60723+ read_lock(&tasklist_lock);
60724+ do_each_thread(p2, p) {
60725+ files = get_files_struct(p);
60726+ if (files == NULL ||
60727+ (p->signal && p->signal->tty == task->signal->tty)) {
60728+ if (files != NULL)
60729+ put_files_struct(files);
60730+ continue;
60731+ }
60732+ rcu_read_lock();
60733+ fdt = files_fdtable(files);
60734+ for (i=0; i < fdt->max_fds; i++) {
60735+ file = fcheck_files(files, i);
60736+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
60737+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
60738+ p3 = task;
60739+ while (task_pid_nr(p3) > 0) {
60740+ if (p3 == p)
60741+ break;
60742+ p3 = p3->real_parent;
60743+ }
60744+ if (p3 == p)
60745+ break;
60746+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
60747+ gr_handle_alertkill(p);
60748+ rcu_read_unlock();
60749+ put_files_struct(files);
60750+ read_unlock(&tasklist_lock);
60751+ fput(our_file);
60752+ return 0;
60753+ }
60754+ }
60755+ rcu_read_unlock();
60756+ put_files_struct(files);
60757+ } while_each_thread(p2, p);
60758+ read_unlock(&tasklist_lock);
60759+
60760+ fput(our_file);
60761+ return 1;
60762+}
60763+
60764+static int gr_rbac_disable(void *unused)
60765+{
60766+ pax_open_kernel();
60767+ gr_status &= ~GR_READY;
60768+ pax_close_kernel();
60769+
60770+ return 0;
60771+}
60772+
60773+ssize_t
60774+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
60775+{
60776+ struct gr_arg_wrapper uwrap;
60777+ unsigned char *sprole_salt = NULL;
60778+ unsigned char *sprole_sum = NULL;
60779+ int error = sizeof (struct gr_arg_wrapper);
60780+ int error2 = 0;
60781+
60782+ mutex_lock(&gr_dev_mutex);
60783+
60784+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
60785+ error = -EPERM;
60786+ goto out;
60787+ }
60788+
60789+ if (count != sizeof (struct gr_arg_wrapper)) {
60790+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
60791+ error = -EINVAL;
60792+ goto out;
60793+ }
60794+
60795+
60796+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
60797+ gr_auth_expires = 0;
60798+ gr_auth_attempts = 0;
60799+ }
60800+
60801+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
60802+ error = -EFAULT;
60803+ goto out;
60804+ }
60805+
60806+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
60807+ error = -EINVAL;
60808+ goto out;
60809+ }
60810+
60811+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
60812+ error = -EFAULT;
60813+ goto out;
60814+ }
60815+
60816+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
60817+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
60818+ time_after(gr_auth_expires, get_seconds())) {
60819+ error = -EBUSY;
60820+ goto out;
60821+ }
60822+
60823+ /* if non-root trying to do anything other than use a special role,
60824+ do not attempt authentication, do not count towards authentication
60825+ locking
60826+ */
60827+
60828+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
60829+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
60830+ gr_is_global_nonroot(current_uid())) {
60831+ error = -EPERM;
60832+ goto out;
60833+ }
60834+
60835+ /* ensure pw and special role name are null terminated */
60836+
60837+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
60838+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
60839+
60840+ /* Okay.
60841+ * We have our enough of the argument structure..(we have yet
60842+ * to copy_from_user the tables themselves) . Copy the tables
60843+ * only if we need them, i.e. for loading operations. */
60844+
60845+ switch (gr_usermode->mode) {
60846+ case GR_STATUS:
60847+ if (gr_status & GR_READY) {
60848+ error = 1;
60849+ if (!gr_check_secure_terminal(current))
60850+ error = 3;
60851+ } else
60852+ error = 2;
60853+ goto out;
60854+ case GR_SHUTDOWN:
60855+ if ((gr_status & GR_READY)
60856+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60857+ stop_machine(gr_rbac_disable, NULL, NULL);
60858+ free_variables();
60859+ memset(gr_usermode, 0, sizeof (struct gr_arg));
60860+ memset(gr_system_salt, 0, GR_SALT_LEN);
60861+ memset(gr_system_sum, 0, GR_SHA_LEN);
60862+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
60863+ } else if (gr_status & GR_READY) {
60864+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
60865+ error = -EPERM;
60866+ } else {
60867+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
60868+ error = -EAGAIN;
60869+ }
60870+ break;
60871+ case GR_ENABLE:
60872+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
60873+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
60874+ else {
60875+ if (gr_status & GR_READY)
60876+ error = -EAGAIN;
60877+ else
60878+ error = error2;
60879+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
60880+ }
60881+ break;
60882+ case GR_RELOAD:
60883+ if (!(gr_status & GR_READY)) {
60884+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
60885+ error = -EAGAIN;
60886+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60887+ stop_machine(gr_rbac_disable, NULL, NULL);
60888+ free_variables();
60889+ error2 = gracl_init(gr_usermode);
60890+ if (!error2)
60891+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
60892+ else {
60893+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
60894+ error = error2;
60895+ }
60896+ } else {
60897+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
60898+ error = -EPERM;
60899+ }
60900+ break;
60901+ case GR_SEGVMOD:
60902+ if (unlikely(!(gr_status & GR_READY))) {
60903+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
60904+ error = -EAGAIN;
60905+ break;
60906+ }
60907+
60908+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60909+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
60910+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
60911+ struct acl_subject_label *segvacl;
60912+ segvacl =
60913+ lookup_acl_subj_label(gr_usermode->segv_inode,
60914+ gr_usermode->segv_device,
60915+ current->role);
60916+ if (segvacl) {
60917+ segvacl->crashes = 0;
60918+ segvacl->expires = 0;
60919+ }
60920+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
60921+ gr_remove_uid(gr_usermode->segv_uid);
60922+ }
60923+ } else {
60924+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
60925+ error = -EPERM;
60926+ }
60927+ break;
60928+ case GR_SPROLE:
60929+ case GR_SPROLEPAM:
60930+ if (unlikely(!(gr_status & GR_READY))) {
60931+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
60932+ error = -EAGAIN;
60933+ break;
60934+ }
60935+
60936+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
60937+ current->role->expires = 0;
60938+ current->role->auth_attempts = 0;
60939+ }
60940+
60941+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
60942+ time_after(current->role->expires, get_seconds())) {
60943+ error = -EBUSY;
60944+ goto out;
60945+ }
60946+
60947+ if (lookup_special_role_auth
60948+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
60949+ && ((!sprole_salt && !sprole_sum)
60950+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
60951+ char *p = "";
60952+ assign_special_role(gr_usermode->sp_role);
60953+ read_lock(&tasklist_lock);
60954+ if (current->real_parent)
60955+ p = current->real_parent->role->rolename;
60956+ read_unlock(&tasklist_lock);
60957+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
60958+ p, acl_sp_role_value);
60959+ } else {
60960+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
60961+ error = -EPERM;
60962+ if(!(current->role->auth_attempts++))
60963+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
60964+
60965+ goto out;
60966+ }
60967+ break;
60968+ case GR_UNSPROLE:
60969+ if (unlikely(!(gr_status & GR_READY))) {
60970+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
60971+ error = -EAGAIN;
60972+ break;
60973+ }
60974+
60975+ if (current->role->roletype & GR_ROLE_SPECIAL) {
60976+ char *p = "";
60977+ int i = 0;
60978+
60979+ read_lock(&tasklist_lock);
60980+ if (current->real_parent) {
60981+ p = current->real_parent->role->rolename;
60982+ i = current->real_parent->acl_role_id;
60983+ }
60984+ read_unlock(&tasklist_lock);
60985+
60986+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
60987+ gr_set_acls(1);
60988+ } else {
60989+ error = -EPERM;
60990+ goto out;
60991+ }
60992+ break;
60993+ default:
60994+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
60995+ error = -EINVAL;
60996+ break;
60997+ }
60998+
60999+ if (error != -EPERM)
61000+ goto out;
61001+
61002+ if(!(gr_auth_attempts++))
61003+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
61004+
61005+ out:
61006+ mutex_unlock(&gr_dev_mutex);
61007+ return error;
61008+}
61009+
61010+/* must be called with
61011+ rcu_read_lock();
61012+ read_lock(&tasklist_lock);
61013+ read_lock(&grsec_exec_file_lock);
61014+*/
61015+int gr_apply_subject_to_task(struct task_struct *task)
61016+{
61017+ struct acl_object_label *obj;
61018+ char *tmpname;
61019+ struct acl_subject_label *tmpsubj;
61020+ struct file *filp;
61021+ struct name_entry *nmatch;
61022+
61023+ filp = task->exec_file;
61024+ if (filp == NULL)
61025+ return 0;
61026+
61027+ /* the following is to apply the correct subject
61028+ on binaries running when the RBAC system
61029+ is enabled, when the binaries have been
61030+ replaced or deleted since their execution
61031+ -----
61032+ when the RBAC system starts, the inode/dev
61033+ from exec_file will be one the RBAC system
61034+ is unaware of. It only knows the inode/dev
61035+ of the present file on disk, or the absence
61036+ of it.
61037+ */
61038+ preempt_disable();
61039+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
61040+
61041+ nmatch = lookup_name_entry(tmpname);
61042+ preempt_enable();
61043+ tmpsubj = NULL;
61044+ if (nmatch) {
61045+ if (nmatch->deleted)
61046+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
61047+ else
61048+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
61049+ if (tmpsubj != NULL)
61050+ task->acl = tmpsubj;
61051+ }
61052+ if (tmpsubj == NULL)
61053+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
61054+ task->role);
61055+ if (task->acl) {
61056+ task->is_writable = 0;
61057+ /* ignore additional mmap checks for processes that are writable
61058+ by the default ACL */
61059+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61060+ if (unlikely(obj->mode & GR_WRITE))
61061+ task->is_writable = 1;
61062+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
61063+ if (unlikely(obj->mode & GR_WRITE))
61064+ task->is_writable = 1;
61065+
61066+ gr_set_proc_res(task);
61067+
61068+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61069+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task_pid_nr(task), task->role->rolename, task->acl->filename);
61070+#endif
61071+ } else {
61072+ return 1;
61073+ }
61074+
61075+ return 0;
61076+}
61077+
61078+int
61079+gr_set_acls(const int type)
61080+{
61081+ struct task_struct *task, *task2;
61082+ struct acl_role_label *role = current->role;
61083+ __u16 acl_role_id = current->acl_role_id;
61084+ const struct cred *cred;
61085+ int ret;
61086+
61087+ rcu_read_lock();
61088+ read_lock(&tasklist_lock);
61089+ read_lock(&grsec_exec_file_lock);
61090+ do_each_thread(task2, task) {
61091+ /* check to see if we're called from the exit handler,
61092+ if so, only replace ACLs that have inherited the admin
61093+ ACL */
61094+
61095+ if (type && (task->role != role ||
61096+ task->acl_role_id != acl_role_id))
61097+ continue;
61098+
61099+ task->acl_role_id = 0;
61100+ task->acl_sp_role = 0;
61101+
61102+ if (task->exec_file) {
61103+ cred = __task_cred(task);
61104+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
61105+ ret = gr_apply_subject_to_task(task);
61106+ if (ret) {
61107+ read_unlock(&grsec_exec_file_lock);
61108+ read_unlock(&tasklist_lock);
61109+ rcu_read_unlock();
61110+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
61111+ return ret;
61112+ }
61113+ } else {
61114+ // it's a kernel process
61115+ task->role = kernel_role;
61116+ task->acl = kernel_role->root_label;
61117+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
61118+ task->acl->mode &= ~GR_PROCFIND;
61119+#endif
61120+ }
61121+ } while_each_thread(task2, task);
61122+ read_unlock(&grsec_exec_file_lock);
61123+ read_unlock(&tasklist_lock);
61124+ rcu_read_unlock();
61125+
61126+ return 0;
61127+}
61128+
61129+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
61130+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
61131+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
61132+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
61133+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
61134+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
61135+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
61136+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
61137+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
61138+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
61139+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
61140+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
61141+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
61142+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
61143+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
61144+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
61145+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
61146+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
61147+};
61148+
61149+void
61150+gr_learn_resource(const struct task_struct *task,
61151+ const int res, const unsigned long wanted, const int gt)
61152+{
61153+ struct acl_subject_label *acl;
61154+ const struct cred *cred;
61155+
61156+ if (unlikely((gr_status & GR_READY) &&
61157+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
61158+ goto skip_reslog;
61159+
61160+ gr_log_resource(task, res, wanted, gt);
61161+skip_reslog:
61162+
61163+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
61164+ return;
61165+
61166+ acl = task->acl;
61167+
61168+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
61169+ !(acl->resmask & (1U << (unsigned short) res))))
61170+ return;
61171+
61172+ if (wanted >= acl->res[res].rlim_cur) {
61173+ unsigned long res_add;
61174+
61175+ res_add = wanted + res_learn_bumps[res];
61176+
61177+ acl->res[res].rlim_cur = res_add;
61178+
61179+ if (wanted > acl->res[res].rlim_max)
61180+ acl->res[res].rlim_max = res_add;
61181+
61182+ /* only log the subject filename, since resource logging is supported for
61183+ single-subject learning only */
61184+ rcu_read_lock();
61185+ cred = __task_cred(task);
61186+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
61187+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
61188+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
61189+ "", (unsigned long) res, &task->signal->saved_ip);
61190+ rcu_read_unlock();
61191+ }
61192+
61193+ return;
61194+}
61195+EXPORT_SYMBOL(gr_learn_resource);
61196+#endif
61197+
61198+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
61199+void
61200+pax_set_initial_flags(struct linux_binprm *bprm)
61201+{
61202+ struct task_struct *task = current;
61203+ struct acl_subject_label *proc;
61204+ unsigned long flags;
61205+
61206+ if (unlikely(!(gr_status & GR_READY)))
61207+ return;
61208+
61209+ flags = pax_get_flags(task);
61210+
61211+ proc = task->acl;
61212+
61213+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
61214+ flags &= ~MF_PAX_PAGEEXEC;
61215+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
61216+ flags &= ~MF_PAX_SEGMEXEC;
61217+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
61218+ flags &= ~MF_PAX_RANDMMAP;
61219+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
61220+ flags &= ~MF_PAX_EMUTRAMP;
61221+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
61222+ flags &= ~MF_PAX_MPROTECT;
61223+
61224+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
61225+ flags |= MF_PAX_PAGEEXEC;
61226+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
61227+ flags |= MF_PAX_SEGMEXEC;
61228+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
61229+ flags |= MF_PAX_RANDMMAP;
61230+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
61231+ flags |= MF_PAX_EMUTRAMP;
61232+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
61233+ flags |= MF_PAX_MPROTECT;
61234+
61235+ pax_set_flags(task, flags);
61236+
61237+ return;
61238+}
61239+#endif
61240+
61241+int
61242+gr_handle_proc_ptrace(struct task_struct *task)
61243+{
61244+ struct file *filp;
61245+ struct task_struct *tmp = task;
61246+ struct task_struct *curtemp = current;
61247+ __u32 retmode;
61248+
61249+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
61250+ if (unlikely(!(gr_status & GR_READY)))
61251+ return 0;
61252+#endif
61253+
61254+ read_lock(&tasklist_lock);
61255+ read_lock(&grsec_exec_file_lock);
61256+ filp = task->exec_file;
61257+
61258+ while (task_pid_nr(tmp) > 0) {
61259+ if (tmp == curtemp)
61260+ break;
61261+ tmp = tmp->real_parent;
61262+ }
61263+
61264+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
61265+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
61266+ read_unlock(&grsec_exec_file_lock);
61267+ read_unlock(&tasklist_lock);
61268+ return 1;
61269+ }
61270+
61271+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61272+ if (!(gr_status & GR_READY)) {
61273+ read_unlock(&grsec_exec_file_lock);
61274+ read_unlock(&tasklist_lock);
61275+ return 0;
61276+ }
61277+#endif
61278+
61279+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
61280+ read_unlock(&grsec_exec_file_lock);
61281+ read_unlock(&tasklist_lock);
61282+
61283+ if (retmode & GR_NOPTRACE)
61284+ return 1;
61285+
61286+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
61287+ && (current->acl != task->acl || (current->acl != current->role->root_label
61288+ && task_pid_nr(current) != task_pid_nr(task))))
61289+ return 1;
61290+
61291+ return 0;
61292+}
61293+
61294+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
61295+{
61296+ if (unlikely(!(gr_status & GR_READY)))
61297+ return;
61298+
61299+ if (!(current->role->roletype & GR_ROLE_GOD))
61300+ return;
61301+
61302+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
61303+ p->role->rolename, gr_task_roletype_to_char(p),
61304+ p->acl->filename);
61305+}
61306+
61307+int
61308+gr_handle_ptrace(struct task_struct *task, const long request)
61309+{
61310+ struct task_struct *tmp = task;
61311+ struct task_struct *curtemp = current;
61312+ __u32 retmode;
61313+
61314+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
61315+ if (unlikely(!(gr_status & GR_READY)))
61316+ return 0;
61317+#endif
61318+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
61319+ read_lock(&tasklist_lock);
61320+ while (task_pid_nr(tmp) > 0) {
61321+ if (tmp == curtemp)
61322+ break;
61323+ tmp = tmp->real_parent;
61324+ }
61325+
61326+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
61327+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
61328+ read_unlock(&tasklist_lock);
61329+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61330+ return 1;
61331+ }
61332+ read_unlock(&tasklist_lock);
61333+ }
61334+
61335+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61336+ if (!(gr_status & GR_READY))
61337+ return 0;
61338+#endif
61339+
61340+ read_lock(&grsec_exec_file_lock);
61341+ if (unlikely(!task->exec_file)) {
61342+ read_unlock(&grsec_exec_file_lock);
61343+ return 0;
61344+ }
61345+
61346+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
61347+ read_unlock(&grsec_exec_file_lock);
61348+
61349+ if (retmode & GR_NOPTRACE) {
61350+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61351+ return 1;
61352+ }
61353+
61354+ if (retmode & GR_PTRACERD) {
61355+ switch (request) {
61356+ case PTRACE_SEIZE:
61357+ case PTRACE_POKETEXT:
61358+ case PTRACE_POKEDATA:
61359+ case PTRACE_POKEUSR:
61360+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
61361+ case PTRACE_SETREGS:
61362+ case PTRACE_SETFPREGS:
61363+#endif
61364+#ifdef CONFIG_X86
61365+ case PTRACE_SETFPXREGS:
61366+#endif
61367+#ifdef CONFIG_ALTIVEC
61368+ case PTRACE_SETVRREGS:
61369+#endif
61370+ return 1;
61371+ default:
61372+ return 0;
61373+ }
61374+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
61375+ !(current->role->roletype & GR_ROLE_GOD) &&
61376+ (current->acl != task->acl)) {
61377+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61378+ return 1;
61379+ }
61380+
61381+ return 0;
61382+}
61383+
61384+static int is_writable_mmap(const struct file *filp)
61385+{
61386+ struct task_struct *task = current;
61387+ struct acl_object_label *obj, *obj2;
61388+
61389+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
61390+ !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))) {
61391+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61392+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
61393+ task->role->root_label);
61394+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
61395+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
61396+ return 1;
61397+ }
61398+ }
61399+ return 0;
61400+}
61401+
61402+int
61403+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
61404+{
61405+ __u32 mode;
61406+
61407+ if (unlikely(!file || !(prot & PROT_EXEC)))
61408+ return 1;
61409+
61410+ if (is_writable_mmap(file))
61411+ return 0;
61412+
61413+ mode =
61414+ gr_search_file(file->f_path.dentry,
61415+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
61416+ file->f_path.mnt);
61417+
61418+ if (!gr_tpe_allow(file))
61419+ return 0;
61420+
61421+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
61422+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61423+ return 0;
61424+ } else if (unlikely(!(mode & GR_EXEC))) {
61425+ return 0;
61426+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
61427+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61428+ return 1;
61429+ }
61430+
61431+ return 1;
61432+}
61433+
61434+int
61435+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
61436+{
61437+ __u32 mode;
61438+
61439+ if (unlikely(!file || !(prot & PROT_EXEC)))
61440+ return 1;
61441+
61442+ if (is_writable_mmap(file))
61443+ return 0;
61444+
61445+ mode =
61446+ gr_search_file(file->f_path.dentry,
61447+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
61448+ file->f_path.mnt);
61449+
61450+ if (!gr_tpe_allow(file))
61451+ return 0;
61452+
61453+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
61454+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61455+ return 0;
61456+ } else if (unlikely(!(mode & GR_EXEC))) {
61457+ return 0;
61458+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
61459+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61460+ return 1;
61461+ }
61462+
61463+ return 1;
61464+}
61465+
61466+void
61467+gr_acl_handle_psacct(struct task_struct *task, const long code)
61468+{
61469+ unsigned long runtime;
61470+ unsigned long cputime;
61471+ unsigned int wday, cday;
61472+ __u8 whr, chr;
61473+ __u8 wmin, cmin;
61474+ __u8 wsec, csec;
61475+ struct timespec timeval;
61476+
61477+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
61478+ !(task->acl->mode & GR_PROCACCT)))
61479+ return;
61480+
61481+ do_posix_clock_monotonic_gettime(&timeval);
61482+ runtime = timeval.tv_sec - task->start_time.tv_sec;
61483+ wday = runtime / (3600 * 24);
61484+ runtime -= wday * (3600 * 24);
61485+ whr = runtime / 3600;
61486+ runtime -= whr * 3600;
61487+ wmin = runtime / 60;
61488+ runtime -= wmin * 60;
61489+ wsec = runtime;
61490+
61491+ cputime = (task->utime + task->stime) / HZ;
61492+ cday = cputime / (3600 * 24);
61493+ cputime -= cday * (3600 * 24);
61494+ chr = cputime / 3600;
61495+ cputime -= chr * 3600;
61496+ cmin = cputime / 60;
61497+ cputime -= cmin * 60;
61498+ csec = cputime;
61499+
61500+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
61501+
61502+ return;
61503+}
61504+
61505+void gr_set_kernel_label(struct task_struct *task)
61506+{
61507+ if (gr_status & GR_READY) {
61508+ task->role = kernel_role;
61509+ task->acl = kernel_role->root_label;
61510+ }
61511+ return;
61512+}
61513+
61514+#ifdef CONFIG_TASKSTATS
61515+int gr_is_taskstats_denied(int pid)
61516+{
61517+ struct task_struct *task;
61518+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61519+ const struct cred *cred;
61520+#endif
61521+ int ret = 0;
61522+
61523+ /* restrict taskstats viewing to un-chrooted root users
61524+ who have the 'view' subject flag if the RBAC system is enabled
61525+ */
61526+
61527+ rcu_read_lock();
61528+ read_lock(&tasklist_lock);
61529+ task = find_task_by_vpid(pid);
61530+ if (task) {
61531+#ifdef CONFIG_GRKERNSEC_CHROOT
61532+ if (proc_is_chrooted(task))
61533+ ret = -EACCES;
61534+#endif
61535+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61536+ cred = __task_cred(task);
61537+#ifdef CONFIG_GRKERNSEC_PROC_USER
61538+ if (gr_is_global_nonroot(cred->uid))
61539+ ret = -EACCES;
61540+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61541+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
61542+ ret = -EACCES;
61543+#endif
61544+#endif
61545+ if (gr_status & GR_READY) {
61546+ if (!(task->acl->mode & GR_VIEW))
61547+ ret = -EACCES;
61548+ }
61549+ } else
61550+ ret = -ENOENT;
61551+
61552+ read_unlock(&tasklist_lock);
61553+ rcu_read_unlock();
61554+
61555+ return ret;
61556+}
61557+#endif
61558+
61559+/* AUXV entries are filled via a descendant of search_binary_handler
61560+ after we've already applied the subject for the target
61561+*/
61562+int gr_acl_enable_at_secure(void)
61563+{
61564+ if (unlikely(!(gr_status & GR_READY)))
61565+ return 0;
61566+
61567+ if (current->acl->mode & GR_ATSECURE)
61568+ return 1;
61569+
61570+ return 0;
61571+}
61572+
61573+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
61574+{
61575+ struct task_struct *task = current;
61576+ struct dentry *dentry = file->f_path.dentry;
61577+ struct vfsmount *mnt = file->f_path.mnt;
61578+ struct acl_object_label *obj, *tmp;
61579+ struct acl_subject_label *subj;
61580+ unsigned int bufsize;
61581+ int is_not_root;
61582+ char *path;
61583+ dev_t dev = __get_dev(dentry);
61584+
61585+ if (unlikely(!(gr_status & GR_READY)))
61586+ return 1;
61587+
61588+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
61589+ return 1;
61590+
61591+ /* ignore Eric Biederman */
61592+ if (IS_PRIVATE(dentry->d_inode))
61593+ return 1;
61594+
61595+ subj = task->acl;
61596+ read_lock(&gr_inode_lock);
61597+ do {
61598+ obj = lookup_acl_obj_label(ino, dev, subj);
61599+ if (obj != NULL) {
61600+ read_unlock(&gr_inode_lock);
61601+ return (obj->mode & GR_FIND) ? 1 : 0;
61602+ }
61603+ } while ((subj = subj->parent_subject));
61604+ read_unlock(&gr_inode_lock);
61605+
61606+ /* this is purely an optimization since we're looking for an object
61607+ for the directory we're doing a readdir on
61608+ if it's possible for any globbed object to match the entry we're
61609+ filling into the directory, then the object we find here will be
61610+ an anchor point with attached globbed objects
61611+ */
61612+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
61613+ if (obj->globbed == NULL)
61614+ return (obj->mode & GR_FIND) ? 1 : 0;
61615+
61616+ is_not_root = ((obj->filename[0] == '/') &&
61617+ (obj->filename[1] == '\0')) ? 0 : 1;
61618+ bufsize = PAGE_SIZE - namelen - is_not_root;
61619+
61620+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
61621+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
61622+ return 1;
61623+
61624+ preempt_disable();
61625+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
61626+ bufsize);
61627+
61628+ bufsize = strlen(path);
61629+
61630+ /* if base is "/", don't append an additional slash */
61631+ if (is_not_root)
61632+ *(path + bufsize) = '/';
61633+ memcpy(path + bufsize + is_not_root, name, namelen);
61634+ *(path + bufsize + namelen + is_not_root) = '\0';
61635+
61636+ tmp = obj->globbed;
61637+ while (tmp) {
61638+ if (!glob_match(tmp->filename, path)) {
61639+ preempt_enable();
61640+ return (tmp->mode & GR_FIND) ? 1 : 0;
61641+ }
61642+ tmp = tmp->next;
61643+ }
61644+ preempt_enable();
61645+ return (obj->mode & GR_FIND) ? 1 : 0;
61646+}
61647+
61648+void gr_put_exec_file(struct task_struct *task)
61649+{
61650+ struct file *filp;
61651+
61652+ write_lock(&grsec_exec_file_lock);
61653+ filp = task->exec_file;
61654+ task->exec_file = NULL;
61655+ write_unlock(&grsec_exec_file_lock);
61656+
61657+ if (filp)
61658+ fput(filp);
61659+
61660+ return;
61661+}
61662+
61663+
61664+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
61665+EXPORT_SYMBOL(gr_acl_is_enabled);
61666+#endif
61667+EXPORT_SYMBOL(gr_set_kernel_label);
61668+#ifdef CONFIG_SECURITY
61669+EXPORT_SYMBOL(gr_check_user_change);
61670+EXPORT_SYMBOL(gr_check_group_change);
61671+#endif
61672+
61673diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
61674new file mode 100644
61675index 0000000..34fefda
61676--- /dev/null
61677+++ b/grsecurity/gracl_alloc.c
61678@@ -0,0 +1,105 @@
61679+#include <linux/kernel.h>
61680+#include <linux/mm.h>
61681+#include <linux/slab.h>
61682+#include <linux/vmalloc.h>
61683+#include <linux/gracl.h>
61684+#include <linux/grsecurity.h>
61685+
61686+static unsigned long alloc_stack_next = 1;
61687+static unsigned long alloc_stack_size = 1;
61688+static void **alloc_stack;
61689+
61690+static __inline__ int
61691+alloc_pop(void)
61692+{
61693+ if (alloc_stack_next == 1)
61694+ return 0;
61695+
61696+ kfree(alloc_stack[alloc_stack_next - 2]);
61697+
61698+ alloc_stack_next--;
61699+
61700+ return 1;
61701+}
61702+
61703+static __inline__ int
61704+alloc_push(void *buf)
61705+{
61706+ if (alloc_stack_next >= alloc_stack_size)
61707+ return 1;
61708+
61709+ alloc_stack[alloc_stack_next - 1] = buf;
61710+
61711+ alloc_stack_next++;
61712+
61713+ return 0;
61714+}
61715+
61716+void *
61717+acl_alloc(unsigned long len)
61718+{
61719+ void *ret = NULL;
61720+
61721+ if (!len || len > PAGE_SIZE)
61722+ goto out;
61723+
61724+ ret = kmalloc(len, GFP_KERNEL);
61725+
61726+ if (ret) {
61727+ if (alloc_push(ret)) {
61728+ kfree(ret);
61729+ ret = NULL;
61730+ }
61731+ }
61732+
61733+out:
61734+ return ret;
61735+}
61736+
61737+void *
61738+acl_alloc_num(unsigned long num, unsigned long len)
61739+{
61740+ if (!len || (num > (PAGE_SIZE / len)))
61741+ return NULL;
61742+
61743+ return acl_alloc(num * len);
61744+}
61745+
61746+void
61747+acl_free_all(void)
61748+{
61749+ if (gr_acl_is_enabled() || !alloc_stack)
61750+ return;
61751+
61752+ while (alloc_pop()) ;
61753+
61754+ if (alloc_stack) {
61755+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
61756+ kfree(alloc_stack);
61757+ else
61758+ vfree(alloc_stack);
61759+ }
61760+
61761+ alloc_stack = NULL;
61762+ alloc_stack_size = 1;
61763+ alloc_stack_next = 1;
61764+
61765+ return;
61766+}
61767+
61768+int
61769+acl_alloc_stack_init(unsigned long size)
61770+{
61771+ if ((size * sizeof (void *)) <= PAGE_SIZE)
61772+ alloc_stack =
61773+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
61774+ else
61775+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
61776+
61777+ alloc_stack_size = size;
61778+
61779+ if (!alloc_stack)
61780+ return 0;
61781+ else
61782+ return 1;
61783+}
61784diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
61785new file mode 100644
61786index 0000000..bdd51ea
61787--- /dev/null
61788+++ b/grsecurity/gracl_cap.c
61789@@ -0,0 +1,110 @@
61790+#include <linux/kernel.h>
61791+#include <linux/module.h>
61792+#include <linux/sched.h>
61793+#include <linux/gracl.h>
61794+#include <linux/grsecurity.h>
61795+#include <linux/grinternal.h>
61796+
61797+extern const char *captab_log[];
61798+extern int captab_log_entries;
61799+
61800+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
61801+{
61802+ struct acl_subject_label *curracl;
61803+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
61804+ kernel_cap_t cap_audit = __cap_empty_set;
61805+
61806+ if (!gr_acl_is_enabled())
61807+ return 1;
61808+
61809+ curracl = task->acl;
61810+
61811+ cap_drop = curracl->cap_lower;
61812+ cap_mask = curracl->cap_mask;
61813+ cap_audit = curracl->cap_invert_audit;
61814+
61815+ while ((curracl = curracl->parent_subject)) {
61816+ /* if the cap isn't specified in the current computed mask but is specified in the
61817+ current level subject, and is lowered in the current level subject, then add
61818+ it to the set of dropped capabilities
61819+ otherwise, add the current level subject's mask to the current computed mask
61820+ */
61821+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
61822+ cap_raise(cap_mask, cap);
61823+ if (cap_raised(curracl->cap_lower, cap))
61824+ cap_raise(cap_drop, cap);
61825+ if (cap_raised(curracl->cap_invert_audit, cap))
61826+ cap_raise(cap_audit, cap);
61827+ }
61828+ }
61829+
61830+ if (!cap_raised(cap_drop, cap)) {
61831+ if (cap_raised(cap_audit, cap))
61832+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
61833+ return 1;
61834+ }
61835+
61836+ curracl = task->acl;
61837+
61838+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
61839+ && cap_raised(cred->cap_effective, cap)) {
61840+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
61841+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
61842+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
61843+ gr_to_filename(task->exec_file->f_path.dentry,
61844+ task->exec_file->f_path.mnt) : curracl->filename,
61845+ curracl->filename, 0UL,
61846+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
61847+ return 1;
61848+ }
61849+
61850+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
61851+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
61852+
61853+ return 0;
61854+}
61855+
61856+int
61857+gr_acl_is_capable(const int cap)
61858+{
61859+ return gr_task_acl_is_capable(current, current_cred(), cap);
61860+}
61861+
61862+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
61863+{
61864+ struct acl_subject_label *curracl;
61865+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
61866+
61867+ if (!gr_acl_is_enabled())
61868+ return 1;
61869+
61870+ curracl = task->acl;
61871+
61872+ cap_drop = curracl->cap_lower;
61873+ cap_mask = curracl->cap_mask;
61874+
61875+ while ((curracl = curracl->parent_subject)) {
61876+ /* if the cap isn't specified in the current computed mask but is specified in the
61877+ current level subject, and is lowered in the current level subject, then add
61878+ it to the set of dropped capabilities
61879+ otherwise, add the current level subject's mask to the current computed mask
61880+ */
61881+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
61882+ cap_raise(cap_mask, cap);
61883+ if (cap_raised(curracl->cap_lower, cap))
61884+ cap_raise(cap_drop, cap);
61885+ }
61886+ }
61887+
61888+ if (!cap_raised(cap_drop, cap))
61889+ return 1;
61890+
61891+ return 0;
61892+}
61893+
61894+int
61895+gr_acl_is_capable_nolog(const int cap)
61896+{
61897+ return gr_task_acl_is_capable_nolog(current, cap);
61898+}
61899+
61900diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
61901new file mode 100644
61902index 0000000..a340c17
61903--- /dev/null
61904+++ b/grsecurity/gracl_fs.c
61905@@ -0,0 +1,431 @@
61906+#include <linux/kernel.h>
61907+#include <linux/sched.h>
61908+#include <linux/types.h>
61909+#include <linux/fs.h>
61910+#include <linux/file.h>
61911+#include <linux/stat.h>
61912+#include <linux/grsecurity.h>
61913+#include <linux/grinternal.h>
61914+#include <linux/gracl.h>
61915+
61916+umode_t
61917+gr_acl_umask(void)
61918+{
61919+ if (unlikely(!gr_acl_is_enabled()))
61920+ return 0;
61921+
61922+ return current->role->umask;
61923+}
61924+
61925+__u32
61926+gr_acl_handle_hidden_file(const struct dentry * dentry,
61927+ const struct vfsmount * mnt)
61928+{
61929+ __u32 mode;
61930+
61931+ if (unlikely(!dentry->d_inode))
61932+ return GR_FIND;
61933+
61934+ mode =
61935+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
61936+
61937+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
61938+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
61939+ return mode;
61940+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
61941+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
61942+ return 0;
61943+ } else if (unlikely(!(mode & GR_FIND)))
61944+ return 0;
61945+
61946+ return GR_FIND;
61947+}
61948+
61949+__u32
61950+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
61951+ int acc_mode)
61952+{
61953+ __u32 reqmode = GR_FIND;
61954+ __u32 mode;
61955+
61956+ if (unlikely(!dentry->d_inode))
61957+ return reqmode;
61958+
61959+ if (acc_mode & MAY_APPEND)
61960+ reqmode |= GR_APPEND;
61961+ else if (acc_mode & MAY_WRITE)
61962+ reqmode |= GR_WRITE;
61963+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
61964+ reqmode |= GR_READ;
61965+
61966+ mode =
61967+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
61968+ mnt);
61969+
61970+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61971+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
61972+ reqmode & GR_READ ? " reading" : "",
61973+ reqmode & GR_WRITE ? " writing" : reqmode &
61974+ GR_APPEND ? " appending" : "");
61975+ return reqmode;
61976+ } else
61977+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61978+ {
61979+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
61980+ reqmode & GR_READ ? " reading" : "",
61981+ reqmode & GR_WRITE ? " writing" : reqmode &
61982+ GR_APPEND ? " appending" : "");
61983+ return 0;
61984+ } else if (unlikely((mode & reqmode) != reqmode))
61985+ return 0;
61986+
61987+ return reqmode;
61988+}
61989+
61990+__u32
61991+gr_acl_handle_creat(const struct dentry * dentry,
61992+ const struct dentry * p_dentry,
61993+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
61994+ const int imode)
61995+{
61996+ __u32 reqmode = GR_WRITE | GR_CREATE;
61997+ __u32 mode;
61998+
61999+ if (acc_mode & MAY_APPEND)
62000+ reqmode |= GR_APPEND;
62001+ // if a directory was required or the directory already exists, then
62002+ // don't count this open as a read
62003+ if ((acc_mode & MAY_READ) &&
62004+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
62005+ reqmode |= GR_READ;
62006+ if ((open_flags & O_CREAT) &&
62007+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
62008+ reqmode |= GR_SETID;
62009+
62010+ mode =
62011+ gr_check_create(dentry, p_dentry, p_mnt,
62012+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
62013+
62014+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62015+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
62016+ reqmode & GR_READ ? " reading" : "",
62017+ reqmode & GR_WRITE ? " writing" : reqmode &
62018+ GR_APPEND ? " appending" : "");
62019+ return reqmode;
62020+ } else
62021+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62022+ {
62023+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
62024+ reqmode & GR_READ ? " reading" : "",
62025+ reqmode & GR_WRITE ? " writing" : reqmode &
62026+ GR_APPEND ? " appending" : "");
62027+ return 0;
62028+ } else if (unlikely((mode & reqmode) != reqmode))
62029+ return 0;
62030+
62031+ return reqmode;
62032+}
62033+
62034+__u32
62035+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
62036+ const int fmode)
62037+{
62038+ __u32 mode, reqmode = GR_FIND;
62039+
62040+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
62041+ reqmode |= GR_EXEC;
62042+ if (fmode & S_IWOTH)
62043+ reqmode |= GR_WRITE;
62044+ if (fmode & S_IROTH)
62045+ reqmode |= GR_READ;
62046+
62047+ mode =
62048+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
62049+ mnt);
62050+
62051+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62052+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
62053+ reqmode & GR_READ ? " reading" : "",
62054+ reqmode & GR_WRITE ? " writing" : "",
62055+ reqmode & GR_EXEC ? " executing" : "");
62056+ return reqmode;
62057+ } else
62058+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62059+ {
62060+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
62061+ reqmode & GR_READ ? " reading" : "",
62062+ reqmode & GR_WRITE ? " writing" : "",
62063+ reqmode & GR_EXEC ? " executing" : "");
62064+ return 0;
62065+ } else if (unlikely((mode & reqmode) != reqmode))
62066+ return 0;
62067+
62068+ return reqmode;
62069+}
62070+
62071+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
62072+{
62073+ __u32 mode;
62074+
62075+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
62076+
62077+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
62078+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
62079+ return mode;
62080+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
62081+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
62082+ return 0;
62083+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
62084+ return 0;
62085+
62086+ return (reqmode);
62087+}
62088+
62089+__u32
62090+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
62091+{
62092+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
62093+}
62094+
62095+__u32
62096+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
62097+{
62098+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
62099+}
62100+
62101+__u32
62102+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
62103+{
62104+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
62105+}
62106+
62107+__u32
62108+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
62109+{
62110+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
62111+}
62112+
62113+__u32
62114+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
62115+ umode_t *modeptr)
62116+{
62117+ umode_t mode;
62118+
62119+ *modeptr &= ~gr_acl_umask();
62120+ mode = *modeptr;
62121+
62122+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
62123+ return 1;
62124+
62125+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
62126+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
62127+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
62128+ GR_CHMOD_ACL_MSG);
62129+ } else {
62130+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
62131+ }
62132+}
62133+
62134+__u32
62135+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
62136+{
62137+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
62138+}
62139+
62140+__u32
62141+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
62142+{
62143+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
62144+}
62145+
62146+__u32
62147+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
62148+{
62149+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
62150+}
62151+
62152+__u32
62153+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
62154+{
62155+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
62156+ GR_UNIXCONNECT_ACL_MSG);
62157+}
62158+
62159+/* hardlinks require at minimum create and link permission,
62160+ any additional privilege required is based on the
62161+ privilege of the file being linked to
62162+*/
62163+__u32
62164+gr_acl_handle_link(const struct dentry * new_dentry,
62165+ const struct dentry * parent_dentry,
62166+ const struct vfsmount * parent_mnt,
62167+ const struct dentry * old_dentry,
62168+ const struct vfsmount * old_mnt, const struct filename *to)
62169+{
62170+ __u32 mode;
62171+ __u32 needmode = GR_CREATE | GR_LINK;
62172+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
62173+
62174+ mode =
62175+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
62176+ old_mnt);
62177+
62178+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
62179+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
62180+ return mode;
62181+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
62182+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
62183+ return 0;
62184+ } else if (unlikely((mode & needmode) != needmode))
62185+ return 0;
62186+
62187+ return 1;
62188+}
62189+
62190+__u32
62191+gr_acl_handle_symlink(const struct dentry * new_dentry,
62192+ const struct dentry * parent_dentry,
62193+ const struct vfsmount * parent_mnt, const struct filename *from)
62194+{
62195+ __u32 needmode = GR_WRITE | GR_CREATE;
62196+ __u32 mode;
62197+
62198+ mode =
62199+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
62200+ GR_CREATE | GR_AUDIT_CREATE |
62201+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
62202+
62203+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
62204+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
62205+ return mode;
62206+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
62207+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
62208+ return 0;
62209+ } else if (unlikely((mode & needmode) != needmode))
62210+ return 0;
62211+
62212+ return (GR_WRITE | GR_CREATE);
62213+}
62214+
62215+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)
62216+{
62217+ __u32 mode;
62218+
62219+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
62220+
62221+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
62222+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
62223+ return mode;
62224+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
62225+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
62226+ return 0;
62227+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
62228+ return 0;
62229+
62230+ return (reqmode);
62231+}
62232+
62233+__u32
62234+gr_acl_handle_mknod(const struct dentry * new_dentry,
62235+ const struct dentry * parent_dentry,
62236+ const struct vfsmount * parent_mnt,
62237+ const int mode)
62238+{
62239+ __u32 reqmode = GR_WRITE | GR_CREATE;
62240+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
62241+ reqmode |= GR_SETID;
62242+
62243+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
62244+ reqmode, GR_MKNOD_ACL_MSG);
62245+}
62246+
62247+__u32
62248+gr_acl_handle_mkdir(const struct dentry *new_dentry,
62249+ const struct dentry *parent_dentry,
62250+ const struct vfsmount *parent_mnt)
62251+{
62252+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
62253+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
62254+}
62255+
62256+#define RENAME_CHECK_SUCCESS(old, new) \
62257+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
62258+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
62259+
62260+int
62261+gr_acl_handle_rename(struct dentry *new_dentry,
62262+ struct dentry *parent_dentry,
62263+ const struct vfsmount *parent_mnt,
62264+ struct dentry *old_dentry,
62265+ struct inode *old_parent_inode,
62266+ struct vfsmount *old_mnt, const struct filename *newname)
62267+{
62268+ __u32 comp1, comp2;
62269+ int error = 0;
62270+
62271+ if (unlikely(!gr_acl_is_enabled()))
62272+ return 0;
62273+
62274+ if (!new_dentry->d_inode) {
62275+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
62276+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
62277+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
62278+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
62279+ GR_DELETE | GR_AUDIT_DELETE |
62280+ GR_AUDIT_READ | GR_AUDIT_WRITE |
62281+ GR_SUPPRESS, old_mnt);
62282+ } else {
62283+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
62284+ GR_CREATE | GR_DELETE |
62285+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
62286+ GR_AUDIT_READ | GR_AUDIT_WRITE |
62287+ GR_SUPPRESS, parent_mnt);
62288+ comp2 =
62289+ gr_search_file(old_dentry,
62290+ GR_READ | GR_WRITE | GR_AUDIT_READ |
62291+ GR_DELETE | GR_AUDIT_DELETE |
62292+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
62293+ }
62294+
62295+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
62296+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
62297+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
62298+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
62299+ && !(comp2 & GR_SUPPRESS)) {
62300+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
62301+ error = -EACCES;
62302+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
62303+ error = -EACCES;
62304+
62305+ return error;
62306+}
62307+
62308+void
62309+gr_acl_handle_exit(void)
62310+{
62311+ u16 id;
62312+ char *rolename;
62313+
62314+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
62315+ !(current->role->roletype & GR_ROLE_PERSIST))) {
62316+ id = current->acl_role_id;
62317+ rolename = current->role->rolename;
62318+ gr_set_acls(1);
62319+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
62320+ }
62321+
62322+ gr_put_exec_file(current);
62323+ return;
62324+}
62325+
62326+int
62327+gr_acl_handle_procpidmem(const struct task_struct *task)
62328+{
62329+ if (unlikely(!gr_acl_is_enabled()))
62330+ return 0;
62331+
62332+ if (task != current && task->acl->mode & GR_PROTPROCFD)
62333+ return -EACCES;
62334+
62335+ return 0;
62336+}
62337diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
62338new file mode 100644
62339index 0000000..8132048
62340--- /dev/null
62341+++ b/grsecurity/gracl_ip.c
62342@@ -0,0 +1,387 @@
62343+#include <linux/kernel.h>
62344+#include <asm/uaccess.h>
62345+#include <asm/errno.h>
62346+#include <net/sock.h>
62347+#include <linux/file.h>
62348+#include <linux/fs.h>
62349+#include <linux/net.h>
62350+#include <linux/in.h>
62351+#include <linux/skbuff.h>
62352+#include <linux/ip.h>
62353+#include <linux/udp.h>
62354+#include <linux/types.h>
62355+#include <linux/sched.h>
62356+#include <linux/netdevice.h>
62357+#include <linux/inetdevice.h>
62358+#include <linux/gracl.h>
62359+#include <linux/grsecurity.h>
62360+#include <linux/grinternal.h>
62361+
62362+#define GR_BIND 0x01
62363+#define GR_CONNECT 0x02
62364+#define GR_INVERT 0x04
62365+#define GR_BINDOVERRIDE 0x08
62366+#define GR_CONNECTOVERRIDE 0x10
62367+#define GR_SOCK_FAMILY 0x20
62368+
62369+static const char * gr_protocols[IPPROTO_MAX] = {
62370+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
62371+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
62372+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
62373+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
62374+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
62375+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
62376+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
62377+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
62378+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
62379+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
62380+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
62381+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
62382+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
62383+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
62384+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
62385+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
62386+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
62387+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
62388+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
62389+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
62390+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
62391+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
62392+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
62393+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
62394+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
62395+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
62396+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
62397+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
62398+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
62399+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
62400+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
62401+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
62402+ };
62403+
62404+static const char * gr_socktypes[SOCK_MAX] = {
62405+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
62406+ "unknown:7", "unknown:8", "unknown:9", "packet"
62407+ };
62408+
62409+static const char * gr_sockfamilies[AF_MAX+1] = {
62410+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
62411+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
62412+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
62413+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
62414+ };
62415+
62416+const char *
62417+gr_proto_to_name(unsigned char proto)
62418+{
62419+ return gr_protocols[proto];
62420+}
62421+
62422+const char *
62423+gr_socktype_to_name(unsigned char type)
62424+{
62425+ return gr_socktypes[type];
62426+}
62427+
62428+const char *
62429+gr_sockfamily_to_name(unsigned char family)
62430+{
62431+ return gr_sockfamilies[family];
62432+}
62433+
62434+int
62435+gr_search_socket(const int domain, const int type, const int protocol)
62436+{
62437+ struct acl_subject_label *curr;
62438+ const struct cred *cred = current_cred();
62439+
62440+ if (unlikely(!gr_acl_is_enabled()))
62441+ goto exit;
62442+
62443+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
62444+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
62445+ goto exit; // let the kernel handle it
62446+
62447+ curr = current->acl;
62448+
62449+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
62450+ /* the family is allowed, if this is PF_INET allow it only if
62451+ the extra sock type/protocol checks pass */
62452+ if (domain == PF_INET)
62453+ goto inet_check;
62454+ goto exit;
62455+ } else {
62456+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
62457+ __u32 fakeip = 0;
62458+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62459+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62460+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62461+ gr_to_filename(current->exec_file->f_path.dentry,
62462+ current->exec_file->f_path.mnt) :
62463+ curr->filename, curr->filename,
62464+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
62465+ &current->signal->saved_ip);
62466+ goto exit;
62467+ }
62468+ goto exit_fail;
62469+ }
62470+
62471+inet_check:
62472+ /* the rest of this checking is for IPv4 only */
62473+ if (!curr->ips)
62474+ goto exit;
62475+
62476+ if ((curr->ip_type & (1U << type)) &&
62477+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
62478+ goto exit;
62479+
62480+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
62481+ /* we don't place acls on raw sockets , and sometimes
62482+ dgram/ip sockets are opened for ioctl and not
62483+ bind/connect, so we'll fake a bind learn log */
62484+ if (type == SOCK_RAW || type == SOCK_PACKET) {
62485+ __u32 fakeip = 0;
62486+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62487+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62488+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62489+ gr_to_filename(current->exec_file->f_path.dentry,
62490+ current->exec_file->f_path.mnt) :
62491+ curr->filename, curr->filename,
62492+ &fakeip, 0, type,
62493+ protocol, GR_CONNECT, &current->signal->saved_ip);
62494+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
62495+ __u32 fakeip = 0;
62496+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62497+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62498+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62499+ gr_to_filename(current->exec_file->f_path.dentry,
62500+ current->exec_file->f_path.mnt) :
62501+ curr->filename, curr->filename,
62502+ &fakeip, 0, type,
62503+ protocol, GR_BIND, &current->signal->saved_ip);
62504+ }
62505+ /* we'll log when they use connect or bind */
62506+ goto exit;
62507+ }
62508+
62509+exit_fail:
62510+ if (domain == PF_INET)
62511+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
62512+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
62513+ else
62514+#ifndef CONFIG_IPV6
62515+ if (domain != PF_INET6)
62516+#endif
62517+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
62518+ gr_socktype_to_name(type), protocol);
62519+
62520+ return 0;
62521+exit:
62522+ return 1;
62523+}
62524+
62525+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)
62526+{
62527+ if ((ip->mode & mode) &&
62528+ (ip_port >= ip->low) &&
62529+ (ip_port <= ip->high) &&
62530+ ((ntohl(ip_addr) & our_netmask) ==
62531+ (ntohl(our_addr) & our_netmask))
62532+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
62533+ && (ip->type & (1U << type))) {
62534+ if (ip->mode & GR_INVERT)
62535+ return 2; // specifically denied
62536+ else
62537+ return 1; // allowed
62538+ }
62539+
62540+ return 0; // not specifically allowed, may continue parsing
62541+}
62542+
62543+static int
62544+gr_search_connectbind(const int full_mode, struct sock *sk,
62545+ struct sockaddr_in *addr, const int type)
62546+{
62547+ char iface[IFNAMSIZ] = {0};
62548+ struct acl_subject_label *curr;
62549+ struct acl_ip_label *ip;
62550+ struct inet_sock *isk;
62551+ struct net_device *dev;
62552+ struct in_device *idev;
62553+ unsigned long i;
62554+ int ret;
62555+ int mode = full_mode & (GR_BIND | GR_CONNECT);
62556+ __u32 ip_addr = 0;
62557+ __u32 our_addr;
62558+ __u32 our_netmask;
62559+ char *p;
62560+ __u16 ip_port = 0;
62561+ const struct cred *cred = current_cred();
62562+
62563+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
62564+ return 0;
62565+
62566+ curr = current->acl;
62567+ isk = inet_sk(sk);
62568+
62569+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
62570+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
62571+ addr->sin_addr.s_addr = curr->inaddr_any_override;
62572+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
62573+ struct sockaddr_in saddr;
62574+ int err;
62575+
62576+ saddr.sin_family = AF_INET;
62577+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
62578+ saddr.sin_port = isk->inet_sport;
62579+
62580+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
62581+ if (err)
62582+ return err;
62583+
62584+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
62585+ if (err)
62586+ return err;
62587+ }
62588+
62589+ if (!curr->ips)
62590+ return 0;
62591+
62592+ ip_addr = addr->sin_addr.s_addr;
62593+ ip_port = ntohs(addr->sin_port);
62594+
62595+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
62596+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62597+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62598+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62599+ gr_to_filename(current->exec_file->f_path.dentry,
62600+ current->exec_file->f_path.mnt) :
62601+ curr->filename, curr->filename,
62602+ &ip_addr, ip_port, type,
62603+ sk->sk_protocol, mode, &current->signal->saved_ip);
62604+ return 0;
62605+ }
62606+
62607+ for (i = 0; i < curr->ip_num; i++) {
62608+ ip = *(curr->ips + i);
62609+ if (ip->iface != NULL) {
62610+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
62611+ p = strchr(iface, ':');
62612+ if (p != NULL)
62613+ *p = '\0';
62614+ dev = dev_get_by_name(sock_net(sk), iface);
62615+ if (dev == NULL)
62616+ continue;
62617+ idev = in_dev_get(dev);
62618+ if (idev == NULL) {
62619+ dev_put(dev);
62620+ continue;
62621+ }
62622+ rcu_read_lock();
62623+ for_ifa(idev) {
62624+ if (!strcmp(ip->iface, ifa->ifa_label)) {
62625+ our_addr = ifa->ifa_address;
62626+ our_netmask = 0xffffffff;
62627+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
62628+ if (ret == 1) {
62629+ rcu_read_unlock();
62630+ in_dev_put(idev);
62631+ dev_put(dev);
62632+ return 0;
62633+ } else if (ret == 2) {
62634+ rcu_read_unlock();
62635+ in_dev_put(idev);
62636+ dev_put(dev);
62637+ goto denied;
62638+ }
62639+ }
62640+ } endfor_ifa(idev);
62641+ rcu_read_unlock();
62642+ in_dev_put(idev);
62643+ dev_put(dev);
62644+ } else {
62645+ our_addr = ip->addr;
62646+ our_netmask = ip->netmask;
62647+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
62648+ if (ret == 1)
62649+ return 0;
62650+ else if (ret == 2)
62651+ goto denied;
62652+ }
62653+ }
62654+
62655+denied:
62656+ if (mode == GR_BIND)
62657+ 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));
62658+ else if (mode == GR_CONNECT)
62659+ 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));
62660+
62661+ return -EACCES;
62662+}
62663+
62664+int
62665+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
62666+{
62667+ /* always allow disconnection of dgram sockets with connect */
62668+ if (addr->sin_family == AF_UNSPEC)
62669+ return 0;
62670+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
62671+}
62672+
62673+int
62674+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
62675+{
62676+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
62677+}
62678+
62679+int gr_search_listen(struct socket *sock)
62680+{
62681+ struct sock *sk = sock->sk;
62682+ struct sockaddr_in addr;
62683+
62684+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
62685+ addr.sin_port = inet_sk(sk)->inet_sport;
62686+
62687+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
62688+}
62689+
62690+int gr_search_accept(struct socket *sock)
62691+{
62692+ struct sock *sk = sock->sk;
62693+ struct sockaddr_in addr;
62694+
62695+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
62696+ addr.sin_port = inet_sk(sk)->inet_sport;
62697+
62698+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
62699+}
62700+
62701+int
62702+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
62703+{
62704+ if (addr)
62705+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
62706+ else {
62707+ struct sockaddr_in sin;
62708+ const struct inet_sock *inet = inet_sk(sk);
62709+
62710+ sin.sin_addr.s_addr = inet->inet_daddr;
62711+ sin.sin_port = inet->inet_dport;
62712+
62713+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
62714+ }
62715+}
62716+
62717+int
62718+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
62719+{
62720+ struct sockaddr_in sin;
62721+
62722+ if (unlikely(skb->len < sizeof (struct udphdr)))
62723+ return 0; // skip this packet
62724+
62725+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
62726+ sin.sin_port = udp_hdr(skb)->source;
62727+
62728+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
62729+}
62730diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
62731new file mode 100644
62732index 0000000..25f54ef
62733--- /dev/null
62734+++ b/grsecurity/gracl_learn.c
62735@@ -0,0 +1,207 @@
62736+#include <linux/kernel.h>
62737+#include <linux/mm.h>
62738+#include <linux/sched.h>
62739+#include <linux/poll.h>
62740+#include <linux/string.h>
62741+#include <linux/file.h>
62742+#include <linux/types.h>
62743+#include <linux/vmalloc.h>
62744+#include <linux/grinternal.h>
62745+
62746+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
62747+ size_t count, loff_t *ppos);
62748+extern int gr_acl_is_enabled(void);
62749+
62750+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
62751+static int gr_learn_attached;
62752+
62753+/* use a 512k buffer */
62754+#define LEARN_BUFFER_SIZE (512 * 1024)
62755+
62756+static DEFINE_SPINLOCK(gr_learn_lock);
62757+static DEFINE_MUTEX(gr_learn_user_mutex);
62758+
62759+/* we need to maintain two buffers, so that the kernel context of grlearn
62760+ uses a semaphore around the userspace copying, and the other kernel contexts
62761+ use a spinlock when copying into the buffer, since they cannot sleep
62762+*/
62763+static char *learn_buffer;
62764+static char *learn_buffer_user;
62765+static int learn_buffer_len;
62766+static int learn_buffer_user_len;
62767+
62768+static ssize_t
62769+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
62770+{
62771+ DECLARE_WAITQUEUE(wait, current);
62772+ ssize_t retval = 0;
62773+
62774+ add_wait_queue(&learn_wait, &wait);
62775+ set_current_state(TASK_INTERRUPTIBLE);
62776+ do {
62777+ mutex_lock(&gr_learn_user_mutex);
62778+ spin_lock(&gr_learn_lock);
62779+ if (learn_buffer_len)
62780+ break;
62781+ spin_unlock(&gr_learn_lock);
62782+ mutex_unlock(&gr_learn_user_mutex);
62783+ if (file->f_flags & O_NONBLOCK) {
62784+ retval = -EAGAIN;
62785+ goto out;
62786+ }
62787+ if (signal_pending(current)) {
62788+ retval = -ERESTARTSYS;
62789+ goto out;
62790+ }
62791+
62792+ schedule();
62793+ } while (1);
62794+
62795+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
62796+ learn_buffer_user_len = learn_buffer_len;
62797+ retval = learn_buffer_len;
62798+ learn_buffer_len = 0;
62799+
62800+ spin_unlock(&gr_learn_lock);
62801+
62802+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
62803+ retval = -EFAULT;
62804+
62805+ mutex_unlock(&gr_learn_user_mutex);
62806+out:
62807+ set_current_state(TASK_RUNNING);
62808+ remove_wait_queue(&learn_wait, &wait);
62809+ return retval;
62810+}
62811+
62812+static unsigned int
62813+poll_learn(struct file * file, poll_table * wait)
62814+{
62815+ poll_wait(file, &learn_wait, wait);
62816+
62817+ if (learn_buffer_len)
62818+ return (POLLIN | POLLRDNORM);
62819+
62820+ return 0;
62821+}
62822+
62823+void
62824+gr_clear_learn_entries(void)
62825+{
62826+ char *tmp;
62827+
62828+ mutex_lock(&gr_learn_user_mutex);
62829+ spin_lock(&gr_learn_lock);
62830+ tmp = learn_buffer;
62831+ learn_buffer = NULL;
62832+ spin_unlock(&gr_learn_lock);
62833+ if (tmp)
62834+ vfree(tmp);
62835+ if (learn_buffer_user != NULL) {
62836+ vfree(learn_buffer_user);
62837+ learn_buffer_user = NULL;
62838+ }
62839+ learn_buffer_len = 0;
62840+ mutex_unlock(&gr_learn_user_mutex);
62841+
62842+ return;
62843+}
62844+
62845+void
62846+gr_add_learn_entry(const char *fmt, ...)
62847+{
62848+ va_list args;
62849+ unsigned int len;
62850+
62851+ if (!gr_learn_attached)
62852+ return;
62853+
62854+ spin_lock(&gr_learn_lock);
62855+
62856+ /* leave a gap at the end so we know when it's "full" but don't have to
62857+ compute the exact length of the string we're trying to append
62858+ */
62859+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
62860+ spin_unlock(&gr_learn_lock);
62861+ wake_up_interruptible(&learn_wait);
62862+ return;
62863+ }
62864+ if (learn_buffer == NULL) {
62865+ spin_unlock(&gr_learn_lock);
62866+ return;
62867+ }
62868+
62869+ va_start(args, fmt);
62870+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
62871+ va_end(args);
62872+
62873+ learn_buffer_len += len + 1;
62874+
62875+ spin_unlock(&gr_learn_lock);
62876+ wake_up_interruptible(&learn_wait);
62877+
62878+ return;
62879+}
62880+
62881+static int
62882+open_learn(struct inode *inode, struct file *file)
62883+{
62884+ if (file->f_mode & FMODE_READ && gr_learn_attached)
62885+ return -EBUSY;
62886+ if (file->f_mode & FMODE_READ) {
62887+ int retval = 0;
62888+ mutex_lock(&gr_learn_user_mutex);
62889+ if (learn_buffer == NULL)
62890+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
62891+ if (learn_buffer_user == NULL)
62892+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
62893+ if (learn_buffer == NULL) {
62894+ retval = -ENOMEM;
62895+ goto out_error;
62896+ }
62897+ if (learn_buffer_user == NULL) {
62898+ retval = -ENOMEM;
62899+ goto out_error;
62900+ }
62901+ learn_buffer_len = 0;
62902+ learn_buffer_user_len = 0;
62903+ gr_learn_attached = 1;
62904+out_error:
62905+ mutex_unlock(&gr_learn_user_mutex);
62906+ return retval;
62907+ }
62908+ return 0;
62909+}
62910+
62911+static int
62912+close_learn(struct inode *inode, struct file *file)
62913+{
62914+ if (file->f_mode & FMODE_READ) {
62915+ char *tmp = NULL;
62916+ mutex_lock(&gr_learn_user_mutex);
62917+ spin_lock(&gr_learn_lock);
62918+ tmp = learn_buffer;
62919+ learn_buffer = NULL;
62920+ spin_unlock(&gr_learn_lock);
62921+ if (tmp)
62922+ vfree(tmp);
62923+ if (learn_buffer_user != NULL) {
62924+ vfree(learn_buffer_user);
62925+ learn_buffer_user = NULL;
62926+ }
62927+ learn_buffer_len = 0;
62928+ learn_buffer_user_len = 0;
62929+ gr_learn_attached = 0;
62930+ mutex_unlock(&gr_learn_user_mutex);
62931+ }
62932+
62933+ return 0;
62934+}
62935+
62936+const struct file_operations grsec_fops = {
62937+ .read = read_learn,
62938+ .write = write_grsec_handler,
62939+ .open = open_learn,
62940+ .release = close_learn,
62941+ .poll = poll_learn,
62942+};
62943diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
62944new file mode 100644
62945index 0000000..39645c9
62946--- /dev/null
62947+++ b/grsecurity/gracl_res.c
62948@@ -0,0 +1,68 @@
62949+#include <linux/kernel.h>
62950+#include <linux/sched.h>
62951+#include <linux/gracl.h>
62952+#include <linux/grinternal.h>
62953+
62954+static const char *restab_log[] = {
62955+ [RLIMIT_CPU] = "RLIMIT_CPU",
62956+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
62957+ [RLIMIT_DATA] = "RLIMIT_DATA",
62958+ [RLIMIT_STACK] = "RLIMIT_STACK",
62959+ [RLIMIT_CORE] = "RLIMIT_CORE",
62960+ [RLIMIT_RSS] = "RLIMIT_RSS",
62961+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
62962+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
62963+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
62964+ [RLIMIT_AS] = "RLIMIT_AS",
62965+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
62966+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
62967+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
62968+ [RLIMIT_NICE] = "RLIMIT_NICE",
62969+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
62970+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
62971+ [GR_CRASH_RES] = "RLIMIT_CRASH"
62972+};
62973+
62974+void
62975+gr_log_resource(const struct task_struct *task,
62976+ const int res, const unsigned long wanted, const int gt)
62977+{
62978+ const struct cred *cred;
62979+ unsigned long rlim;
62980+
62981+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
62982+ return;
62983+
62984+ // not yet supported resource
62985+ if (unlikely(!restab_log[res]))
62986+ return;
62987+
62988+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
62989+ rlim = task_rlimit_max(task, res);
62990+ else
62991+ rlim = task_rlimit(task, res);
62992+
62993+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
62994+ return;
62995+
62996+ rcu_read_lock();
62997+ cred = __task_cred(task);
62998+
62999+ if (res == RLIMIT_NPROC &&
63000+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
63001+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
63002+ goto out_rcu_unlock;
63003+ else if (res == RLIMIT_MEMLOCK &&
63004+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
63005+ goto out_rcu_unlock;
63006+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
63007+ goto out_rcu_unlock;
63008+ rcu_read_unlock();
63009+
63010+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
63011+
63012+ return;
63013+out_rcu_unlock:
63014+ rcu_read_unlock();
63015+ return;
63016+}
63017diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
63018new file mode 100644
63019index 0000000..4dcc92a
63020--- /dev/null
63021+++ b/grsecurity/gracl_segv.c
63022@@ -0,0 +1,305 @@
63023+#include <linux/kernel.h>
63024+#include <linux/mm.h>
63025+#include <asm/uaccess.h>
63026+#include <asm/errno.h>
63027+#include <asm/mman.h>
63028+#include <net/sock.h>
63029+#include <linux/file.h>
63030+#include <linux/fs.h>
63031+#include <linux/net.h>
63032+#include <linux/in.h>
63033+#include <linux/slab.h>
63034+#include <linux/types.h>
63035+#include <linux/sched.h>
63036+#include <linux/timer.h>
63037+#include <linux/gracl.h>
63038+#include <linux/grsecurity.h>
63039+#include <linux/grinternal.h>
63040+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
63041+#include <linux/magic.h>
63042+#include <linux/pagemap.h>
63043+#include "../fs/btrfs/async-thread.h"
63044+#include "../fs/btrfs/ctree.h"
63045+#include "../fs/btrfs/btrfs_inode.h"
63046+#endif
63047+
63048+static struct crash_uid *uid_set;
63049+static unsigned short uid_used;
63050+static DEFINE_SPINLOCK(gr_uid_lock);
63051+extern rwlock_t gr_inode_lock;
63052+extern struct acl_subject_label *
63053+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
63054+ struct acl_role_label *role);
63055+
63056+static inline dev_t __get_dev(const struct dentry *dentry)
63057+{
63058+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
63059+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
63060+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
63061+ else
63062+#endif
63063+ return dentry->d_sb->s_dev;
63064+}
63065+
63066+int
63067+gr_init_uidset(void)
63068+{
63069+ uid_set =
63070+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
63071+ uid_used = 0;
63072+
63073+ return uid_set ? 1 : 0;
63074+}
63075+
63076+void
63077+gr_free_uidset(void)
63078+{
63079+ if (uid_set)
63080+ kfree(uid_set);
63081+
63082+ return;
63083+}
63084+
63085+int
63086+gr_find_uid(const uid_t uid)
63087+{
63088+ struct crash_uid *tmp = uid_set;
63089+ uid_t buid;
63090+ int low = 0, high = uid_used - 1, mid;
63091+
63092+ while (high >= low) {
63093+ mid = (low + high) >> 1;
63094+ buid = tmp[mid].uid;
63095+ if (buid == uid)
63096+ return mid;
63097+ if (buid > uid)
63098+ high = mid - 1;
63099+ if (buid < uid)
63100+ low = mid + 1;
63101+ }
63102+
63103+ return -1;
63104+}
63105+
63106+static __inline__ void
63107+gr_insertsort(void)
63108+{
63109+ unsigned short i, j;
63110+ struct crash_uid index;
63111+
63112+ for (i = 1; i < uid_used; i++) {
63113+ index = uid_set[i];
63114+ j = i;
63115+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
63116+ uid_set[j] = uid_set[j - 1];
63117+ j--;
63118+ }
63119+ uid_set[j] = index;
63120+ }
63121+
63122+ return;
63123+}
63124+
63125+static __inline__ void
63126+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
63127+{
63128+ int loc;
63129+ uid_t uid = GR_GLOBAL_UID(kuid);
63130+
63131+ if (uid_used == GR_UIDTABLE_MAX)
63132+ return;
63133+
63134+ loc = gr_find_uid(uid);
63135+
63136+ if (loc >= 0) {
63137+ uid_set[loc].expires = expires;
63138+ return;
63139+ }
63140+
63141+ uid_set[uid_used].uid = uid;
63142+ uid_set[uid_used].expires = expires;
63143+ uid_used++;
63144+
63145+ gr_insertsort();
63146+
63147+ return;
63148+}
63149+
63150+void
63151+gr_remove_uid(const unsigned short loc)
63152+{
63153+ unsigned short i;
63154+
63155+ for (i = loc + 1; i < uid_used; i++)
63156+ uid_set[i - 1] = uid_set[i];
63157+
63158+ uid_used--;
63159+
63160+ return;
63161+}
63162+
63163+int
63164+gr_check_crash_uid(const kuid_t kuid)
63165+{
63166+ int loc;
63167+ int ret = 0;
63168+ uid_t uid;
63169+
63170+ if (unlikely(!gr_acl_is_enabled()))
63171+ return 0;
63172+
63173+ uid = GR_GLOBAL_UID(kuid);
63174+
63175+ spin_lock(&gr_uid_lock);
63176+ loc = gr_find_uid(uid);
63177+
63178+ if (loc < 0)
63179+ goto out_unlock;
63180+
63181+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
63182+ gr_remove_uid(loc);
63183+ else
63184+ ret = 1;
63185+
63186+out_unlock:
63187+ spin_unlock(&gr_uid_lock);
63188+ return ret;
63189+}
63190+
63191+static __inline__ int
63192+proc_is_setxid(const struct cred *cred)
63193+{
63194+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
63195+ !uid_eq(cred->uid, cred->fsuid))
63196+ return 1;
63197+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
63198+ !gid_eq(cred->gid, cred->fsgid))
63199+ return 1;
63200+
63201+ return 0;
63202+}
63203+
63204+extern int gr_fake_force_sig(int sig, struct task_struct *t);
63205+
63206+void
63207+gr_handle_crash(struct task_struct *task, const int sig)
63208+{
63209+ struct acl_subject_label *curr;
63210+ struct task_struct *tsk, *tsk2;
63211+ const struct cred *cred;
63212+ const struct cred *cred2;
63213+
63214+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
63215+ return;
63216+
63217+ if (unlikely(!gr_acl_is_enabled()))
63218+ return;
63219+
63220+ curr = task->acl;
63221+
63222+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
63223+ return;
63224+
63225+ if (time_before_eq(curr->expires, get_seconds())) {
63226+ curr->expires = 0;
63227+ curr->crashes = 0;
63228+ }
63229+
63230+ curr->crashes++;
63231+
63232+ if (!curr->expires)
63233+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
63234+
63235+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
63236+ time_after(curr->expires, get_seconds())) {
63237+ rcu_read_lock();
63238+ cred = __task_cred(task);
63239+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
63240+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
63241+ spin_lock(&gr_uid_lock);
63242+ gr_insert_uid(cred->uid, curr->expires);
63243+ spin_unlock(&gr_uid_lock);
63244+ curr->expires = 0;
63245+ curr->crashes = 0;
63246+ read_lock(&tasklist_lock);
63247+ do_each_thread(tsk2, tsk) {
63248+ cred2 = __task_cred(tsk);
63249+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
63250+ gr_fake_force_sig(SIGKILL, tsk);
63251+ } while_each_thread(tsk2, tsk);
63252+ read_unlock(&tasklist_lock);
63253+ } else {
63254+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
63255+ read_lock(&tasklist_lock);
63256+ read_lock(&grsec_exec_file_lock);
63257+ do_each_thread(tsk2, tsk) {
63258+ if (likely(tsk != task)) {
63259+ // if this thread has the same subject as the one that triggered
63260+ // RES_CRASH and it's the same binary, kill it
63261+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
63262+ gr_fake_force_sig(SIGKILL, tsk);
63263+ }
63264+ } while_each_thread(tsk2, tsk);
63265+ read_unlock(&grsec_exec_file_lock);
63266+ read_unlock(&tasklist_lock);
63267+ }
63268+ rcu_read_unlock();
63269+ }
63270+
63271+ return;
63272+}
63273+
63274+int
63275+gr_check_crash_exec(const struct file *filp)
63276+{
63277+ struct acl_subject_label *curr;
63278+
63279+ if (unlikely(!gr_acl_is_enabled()))
63280+ return 0;
63281+
63282+ read_lock(&gr_inode_lock);
63283+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
63284+ __get_dev(filp->f_path.dentry),
63285+ current->role);
63286+ read_unlock(&gr_inode_lock);
63287+
63288+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
63289+ (!curr->crashes && !curr->expires))
63290+ return 0;
63291+
63292+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
63293+ time_after(curr->expires, get_seconds()))
63294+ return 1;
63295+ else if (time_before_eq(curr->expires, get_seconds())) {
63296+ curr->crashes = 0;
63297+ curr->expires = 0;
63298+ }
63299+
63300+ return 0;
63301+}
63302+
63303+void
63304+gr_handle_alertkill(struct task_struct *task)
63305+{
63306+ struct acl_subject_label *curracl;
63307+ __u32 curr_ip;
63308+ struct task_struct *p, *p2;
63309+
63310+ if (unlikely(!gr_acl_is_enabled()))
63311+ return;
63312+
63313+ curracl = task->acl;
63314+ curr_ip = task->signal->curr_ip;
63315+
63316+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
63317+ read_lock(&tasklist_lock);
63318+ do_each_thread(p2, p) {
63319+ if (p->signal->curr_ip == curr_ip)
63320+ gr_fake_force_sig(SIGKILL, p);
63321+ } while_each_thread(p2, p);
63322+ read_unlock(&tasklist_lock);
63323+ } else if (curracl->mode & GR_KILLPROC)
63324+ gr_fake_force_sig(SIGKILL, task);
63325+
63326+ return;
63327+}
63328diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
63329new file mode 100644
63330index 0000000..98011b0
63331--- /dev/null
63332+++ b/grsecurity/gracl_shm.c
63333@@ -0,0 +1,40 @@
63334+#include <linux/kernel.h>
63335+#include <linux/mm.h>
63336+#include <linux/sched.h>
63337+#include <linux/file.h>
63338+#include <linux/ipc.h>
63339+#include <linux/gracl.h>
63340+#include <linux/grsecurity.h>
63341+#include <linux/grinternal.h>
63342+
63343+int
63344+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63345+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
63346+{
63347+ struct task_struct *task;
63348+
63349+ if (!gr_acl_is_enabled())
63350+ return 1;
63351+
63352+ rcu_read_lock();
63353+ read_lock(&tasklist_lock);
63354+
63355+ task = find_task_by_vpid(shm_cprid);
63356+
63357+ if (unlikely(!task))
63358+ task = find_task_by_vpid(shm_lapid);
63359+
63360+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
63361+ (task_pid_nr(task) == shm_lapid)) &&
63362+ (task->acl->mode & GR_PROTSHM) &&
63363+ (task->acl != current->acl))) {
63364+ read_unlock(&tasklist_lock);
63365+ rcu_read_unlock();
63366+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
63367+ return 0;
63368+ }
63369+ read_unlock(&tasklist_lock);
63370+ rcu_read_unlock();
63371+
63372+ return 1;
63373+}
63374diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
63375new file mode 100644
63376index 0000000..bc0be01
63377--- /dev/null
63378+++ b/grsecurity/grsec_chdir.c
63379@@ -0,0 +1,19 @@
63380+#include <linux/kernel.h>
63381+#include <linux/sched.h>
63382+#include <linux/fs.h>
63383+#include <linux/file.h>
63384+#include <linux/grsecurity.h>
63385+#include <linux/grinternal.h>
63386+
63387+void
63388+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
63389+{
63390+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
63391+ if ((grsec_enable_chdir && grsec_enable_group &&
63392+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
63393+ !grsec_enable_group)) {
63394+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
63395+ }
63396+#endif
63397+ return;
63398+}
63399diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
63400new file mode 100644
63401index 0000000..bd6e105
63402--- /dev/null
63403+++ b/grsecurity/grsec_chroot.c
63404@@ -0,0 +1,370 @@
63405+#include <linux/kernel.h>
63406+#include <linux/module.h>
63407+#include <linux/sched.h>
63408+#include <linux/file.h>
63409+#include <linux/fs.h>
63410+#include <linux/mount.h>
63411+#include <linux/types.h>
63412+#include "../fs/mount.h"
63413+#include <linux/grsecurity.h>
63414+#include <linux/grinternal.h>
63415+
63416+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
63417+static int gr_init_ran;
63418+#endif
63419+
63420+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
63421+{
63422+#ifdef CONFIG_GRKERNSEC
63423+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
63424+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
63425+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
63426+ && gr_init_ran
63427+#endif
63428+ )
63429+ task->gr_is_chrooted = 1;
63430+ else {
63431+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
63432+ if (task_pid_nr(task) == 1 && !gr_init_ran)
63433+ gr_init_ran = 1;
63434+#endif
63435+ task->gr_is_chrooted = 0;
63436+ }
63437+
63438+ task->gr_chroot_dentry = path->dentry;
63439+#endif
63440+ return;
63441+}
63442+
63443+void gr_clear_chroot_entries(struct task_struct *task)
63444+{
63445+#ifdef CONFIG_GRKERNSEC
63446+ task->gr_is_chrooted = 0;
63447+ task->gr_chroot_dentry = NULL;
63448+#endif
63449+ return;
63450+}
63451+
63452+int
63453+gr_handle_chroot_unix(const pid_t pid)
63454+{
63455+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
63456+ struct task_struct *p;
63457+
63458+ if (unlikely(!grsec_enable_chroot_unix))
63459+ return 1;
63460+
63461+ if (likely(!proc_is_chrooted(current)))
63462+ return 1;
63463+
63464+ rcu_read_lock();
63465+ read_lock(&tasklist_lock);
63466+ p = find_task_by_vpid_unrestricted(pid);
63467+ if (unlikely(p && !have_same_root(current, p))) {
63468+ read_unlock(&tasklist_lock);
63469+ rcu_read_unlock();
63470+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
63471+ return 0;
63472+ }
63473+ read_unlock(&tasklist_lock);
63474+ rcu_read_unlock();
63475+#endif
63476+ return 1;
63477+}
63478+
63479+int
63480+gr_handle_chroot_nice(void)
63481+{
63482+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
63483+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
63484+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
63485+ return -EPERM;
63486+ }
63487+#endif
63488+ return 0;
63489+}
63490+
63491+int
63492+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
63493+{
63494+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
63495+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
63496+ && proc_is_chrooted(current)) {
63497+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
63498+ return -EACCES;
63499+ }
63500+#endif
63501+ return 0;
63502+}
63503+
63504+int
63505+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
63506+{
63507+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63508+ struct task_struct *p;
63509+ int ret = 0;
63510+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
63511+ return ret;
63512+
63513+ read_lock(&tasklist_lock);
63514+ do_each_pid_task(pid, type, p) {
63515+ if (!have_same_root(current, p)) {
63516+ ret = 1;
63517+ goto out;
63518+ }
63519+ } while_each_pid_task(pid, type, p);
63520+out:
63521+ read_unlock(&tasklist_lock);
63522+ return ret;
63523+#endif
63524+ return 0;
63525+}
63526+
63527+int
63528+gr_pid_is_chrooted(struct task_struct *p)
63529+{
63530+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63531+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
63532+ return 0;
63533+
63534+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
63535+ !have_same_root(current, p)) {
63536+ return 1;
63537+ }
63538+#endif
63539+ return 0;
63540+}
63541+
63542+EXPORT_SYMBOL(gr_pid_is_chrooted);
63543+
63544+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
63545+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
63546+{
63547+ struct path path, currentroot;
63548+ int ret = 0;
63549+
63550+ path.dentry = (struct dentry *)u_dentry;
63551+ path.mnt = (struct vfsmount *)u_mnt;
63552+ get_fs_root(current->fs, &currentroot);
63553+ if (path_is_under(&path, &currentroot))
63554+ ret = 1;
63555+ path_put(&currentroot);
63556+
63557+ return ret;
63558+}
63559+#endif
63560+
63561+int
63562+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
63563+{
63564+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
63565+ if (!grsec_enable_chroot_fchdir)
63566+ return 1;
63567+
63568+ if (!proc_is_chrooted(current))
63569+ return 1;
63570+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
63571+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
63572+ return 0;
63573+ }
63574+#endif
63575+ return 1;
63576+}
63577+
63578+int
63579+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63580+ const time_t shm_createtime)
63581+{
63582+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
63583+ struct task_struct *p;
63584+ time_t starttime;
63585+
63586+ if (unlikely(!grsec_enable_chroot_shmat))
63587+ return 1;
63588+
63589+ if (likely(!proc_is_chrooted(current)))
63590+ return 1;
63591+
63592+ rcu_read_lock();
63593+ read_lock(&tasklist_lock);
63594+
63595+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
63596+ starttime = p->start_time.tv_sec;
63597+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
63598+ if (have_same_root(current, p)) {
63599+ goto allow;
63600+ } else {
63601+ read_unlock(&tasklist_lock);
63602+ rcu_read_unlock();
63603+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
63604+ return 0;
63605+ }
63606+ }
63607+ /* creator exited, pid reuse, fall through to next check */
63608+ }
63609+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
63610+ if (unlikely(!have_same_root(current, p))) {
63611+ read_unlock(&tasklist_lock);
63612+ rcu_read_unlock();
63613+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
63614+ return 0;
63615+ }
63616+ }
63617+
63618+allow:
63619+ read_unlock(&tasklist_lock);
63620+ rcu_read_unlock();
63621+#endif
63622+ return 1;
63623+}
63624+
63625+void
63626+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
63627+{
63628+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
63629+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
63630+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
63631+#endif
63632+ return;
63633+}
63634+
63635+int
63636+gr_handle_chroot_mknod(const struct dentry *dentry,
63637+ const struct vfsmount *mnt, const int mode)
63638+{
63639+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
63640+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
63641+ proc_is_chrooted(current)) {
63642+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
63643+ return -EPERM;
63644+ }
63645+#endif
63646+ return 0;
63647+}
63648+
63649+int
63650+gr_handle_chroot_mount(const struct dentry *dentry,
63651+ const struct vfsmount *mnt, const char *dev_name)
63652+{
63653+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
63654+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
63655+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
63656+ return -EPERM;
63657+ }
63658+#endif
63659+ return 0;
63660+}
63661+
63662+int
63663+gr_handle_chroot_pivot(void)
63664+{
63665+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
63666+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
63667+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
63668+ return -EPERM;
63669+ }
63670+#endif
63671+ return 0;
63672+}
63673+
63674+int
63675+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
63676+{
63677+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
63678+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
63679+ !gr_is_outside_chroot(dentry, mnt)) {
63680+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
63681+ return -EPERM;
63682+ }
63683+#endif
63684+ return 0;
63685+}
63686+
63687+extern const char *captab_log[];
63688+extern int captab_log_entries;
63689+
63690+int
63691+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
63692+{
63693+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63694+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
63695+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
63696+ if (cap_raised(chroot_caps, cap)) {
63697+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
63698+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
63699+ }
63700+ return 0;
63701+ }
63702+ }
63703+#endif
63704+ return 1;
63705+}
63706+
63707+int
63708+gr_chroot_is_capable(const int cap)
63709+{
63710+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63711+ return gr_task_chroot_is_capable(current, current_cred(), cap);
63712+#endif
63713+ return 1;
63714+}
63715+
63716+int
63717+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
63718+{
63719+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63720+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
63721+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
63722+ if (cap_raised(chroot_caps, cap)) {
63723+ return 0;
63724+ }
63725+ }
63726+#endif
63727+ return 1;
63728+}
63729+
63730+int
63731+gr_chroot_is_capable_nolog(const int cap)
63732+{
63733+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63734+ return gr_task_chroot_is_capable_nolog(current, cap);
63735+#endif
63736+ return 1;
63737+}
63738+
63739+int
63740+gr_handle_chroot_sysctl(const int op)
63741+{
63742+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
63743+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
63744+ proc_is_chrooted(current))
63745+ return -EACCES;
63746+#endif
63747+ return 0;
63748+}
63749+
63750+void
63751+gr_handle_chroot_chdir(const struct path *path)
63752+{
63753+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
63754+ if (grsec_enable_chroot_chdir)
63755+ set_fs_pwd(current->fs, path);
63756+#endif
63757+ return;
63758+}
63759+
63760+int
63761+gr_handle_chroot_chmod(const struct dentry *dentry,
63762+ const struct vfsmount *mnt, const int mode)
63763+{
63764+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
63765+ /* allow chmod +s on directories, but not files */
63766+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
63767+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
63768+ proc_is_chrooted(current)) {
63769+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
63770+ return -EPERM;
63771+ }
63772+#endif
63773+ return 0;
63774+}
63775diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
63776new file mode 100644
63777index 0000000..ce65ceb
63778--- /dev/null
63779+++ b/grsecurity/grsec_disabled.c
63780@@ -0,0 +1,434 @@
63781+#include <linux/kernel.h>
63782+#include <linux/module.h>
63783+#include <linux/sched.h>
63784+#include <linux/file.h>
63785+#include <linux/fs.h>
63786+#include <linux/kdev_t.h>
63787+#include <linux/net.h>
63788+#include <linux/in.h>
63789+#include <linux/ip.h>
63790+#include <linux/skbuff.h>
63791+#include <linux/sysctl.h>
63792+
63793+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63794+void
63795+pax_set_initial_flags(struct linux_binprm *bprm)
63796+{
63797+ return;
63798+}
63799+#endif
63800+
63801+#ifdef CONFIG_SYSCTL
63802+__u32
63803+gr_handle_sysctl(const struct ctl_table * table, const int op)
63804+{
63805+ return 0;
63806+}
63807+#endif
63808+
63809+#ifdef CONFIG_TASKSTATS
63810+int gr_is_taskstats_denied(int pid)
63811+{
63812+ return 0;
63813+}
63814+#endif
63815+
63816+int
63817+gr_acl_is_enabled(void)
63818+{
63819+ return 0;
63820+}
63821+
63822+void
63823+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
63824+{
63825+ return;
63826+}
63827+
63828+int
63829+gr_handle_rawio(const struct inode *inode)
63830+{
63831+ return 0;
63832+}
63833+
63834+void
63835+gr_acl_handle_psacct(struct task_struct *task, const long code)
63836+{
63837+ return;
63838+}
63839+
63840+int
63841+gr_handle_ptrace(struct task_struct *task, const long request)
63842+{
63843+ return 0;
63844+}
63845+
63846+int
63847+gr_handle_proc_ptrace(struct task_struct *task)
63848+{
63849+ return 0;
63850+}
63851+
63852+int
63853+gr_set_acls(const int type)
63854+{
63855+ return 0;
63856+}
63857+
63858+int
63859+gr_check_hidden_task(const struct task_struct *tsk)
63860+{
63861+ return 0;
63862+}
63863+
63864+int
63865+gr_check_protected_task(const struct task_struct *task)
63866+{
63867+ return 0;
63868+}
63869+
63870+int
63871+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
63872+{
63873+ return 0;
63874+}
63875+
63876+void
63877+gr_copy_label(struct task_struct *tsk)
63878+{
63879+ return;
63880+}
63881+
63882+void
63883+gr_set_pax_flags(struct task_struct *task)
63884+{
63885+ return;
63886+}
63887+
63888+int
63889+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
63890+ const int unsafe_share)
63891+{
63892+ return 0;
63893+}
63894+
63895+void
63896+gr_handle_delete(const ino_t ino, const dev_t dev)
63897+{
63898+ return;
63899+}
63900+
63901+void
63902+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
63903+{
63904+ return;
63905+}
63906+
63907+void
63908+gr_handle_crash(struct task_struct *task, const int sig)
63909+{
63910+ return;
63911+}
63912+
63913+int
63914+gr_check_crash_exec(const struct file *filp)
63915+{
63916+ return 0;
63917+}
63918+
63919+int
63920+gr_check_crash_uid(const kuid_t uid)
63921+{
63922+ return 0;
63923+}
63924+
63925+void
63926+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
63927+ struct dentry *old_dentry,
63928+ struct dentry *new_dentry,
63929+ struct vfsmount *mnt, const __u8 replace)
63930+{
63931+ return;
63932+}
63933+
63934+int
63935+gr_search_socket(const int family, const int type, const int protocol)
63936+{
63937+ return 1;
63938+}
63939+
63940+int
63941+gr_search_connectbind(const int mode, const struct socket *sock,
63942+ const struct sockaddr_in *addr)
63943+{
63944+ return 0;
63945+}
63946+
63947+void
63948+gr_handle_alertkill(struct task_struct *task)
63949+{
63950+ return;
63951+}
63952+
63953+__u32
63954+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
63955+{
63956+ return 1;
63957+}
63958+
63959+__u32
63960+gr_acl_handle_hidden_file(const struct dentry * dentry,
63961+ const struct vfsmount * mnt)
63962+{
63963+ return 1;
63964+}
63965+
63966+__u32
63967+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
63968+ int acc_mode)
63969+{
63970+ return 1;
63971+}
63972+
63973+__u32
63974+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
63975+{
63976+ return 1;
63977+}
63978+
63979+__u32
63980+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
63981+{
63982+ return 1;
63983+}
63984+
63985+int
63986+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
63987+ unsigned int *vm_flags)
63988+{
63989+ return 1;
63990+}
63991+
63992+__u32
63993+gr_acl_handle_truncate(const struct dentry * dentry,
63994+ const struct vfsmount * mnt)
63995+{
63996+ return 1;
63997+}
63998+
63999+__u32
64000+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
64001+{
64002+ return 1;
64003+}
64004+
64005+__u32
64006+gr_acl_handle_access(const struct dentry * dentry,
64007+ const struct vfsmount * mnt, const int fmode)
64008+{
64009+ return 1;
64010+}
64011+
64012+__u32
64013+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
64014+ umode_t *mode)
64015+{
64016+ return 1;
64017+}
64018+
64019+__u32
64020+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
64021+{
64022+ return 1;
64023+}
64024+
64025+__u32
64026+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
64027+{
64028+ return 1;
64029+}
64030+
64031+void
64032+grsecurity_init(void)
64033+{
64034+ return;
64035+}
64036+
64037+umode_t gr_acl_umask(void)
64038+{
64039+ return 0;
64040+}
64041+
64042+__u32
64043+gr_acl_handle_mknod(const struct dentry * new_dentry,
64044+ const struct dentry * parent_dentry,
64045+ const struct vfsmount * parent_mnt,
64046+ const int mode)
64047+{
64048+ return 1;
64049+}
64050+
64051+__u32
64052+gr_acl_handle_mkdir(const struct dentry * new_dentry,
64053+ const struct dentry * parent_dentry,
64054+ const struct vfsmount * parent_mnt)
64055+{
64056+ return 1;
64057+}
64058+
64059+__u32
64060+gr_acl_handle_symlink(const struct dentry * new_dentry,
64061+ const struct dentry * parent_dentry,
64062+ const struct vfsmount * parent_mnt, const struct filename *from)
64063+{
64064+ return 1;
64065+}
64066+
64067+__u32
64068+gr_acl_handle_link(const struct dentry * new_dentry,
64069+ const struct dentry * parent_dentry,
64070+ const struct vfsmount * parent_mnt,
64071+ const struct dentry * old_dentry,
64072+ const struct vfsmount * old_mnt, const struct filename *to)
64073+{
64074+ return 1;
64075+}
64076+
64077+int
64078+gr_acl_handle_rename(const struct dentry *new_dentry,
64079+ const struct dentry *parent_dentry,
64080+ const struct vfsmount *parent_mnt,
64081+ const struct dentry *old_dentry,
64082+ const struct inode *old_parent_inode,
64083+ const struct vfsmount *old_mnt, const struct filename *newname)
64084+{
64085+ return 0;
64086+}
64087+
64088+int
64089+gr_acl_handle_filldir(const struct file *file, const char *name,
64090+ const int namelen, const ino_t ino)
64091+{
64092+ return 1;
64093+}
64094+
64095+int
64096+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64097+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
64098+{
64099+ return 1;
64100+}
64101+
64102+int
64103+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
64104+{
64105+ return 0;
64106+}
64107+
64108+int
64109+gr_search_accept(const struct socket *sock)
64110+{
64111+ return 0;
64112+}
64113+
64114+int
64115+gr_search_listen(const struct socket *sock)
64116+{
64117+ return 0;
64118+}
64119+
64120+int
64121+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
64122+{
64123+ return 0;
64124+}
64125+
64126+__u32
64127+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
64128+{
64129+ return 1;
64130+}
64131+
64132+__u32
64133+gr_acl_handle_creat(const struct dentry * dentry,
64134+ const struct dentry * p_dentry,
64135+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
64136+ const int imode)
64137+{
64138+ return 1;
64139+}
64140+
64141+void
64142+gr_acl_handle_exit(void)
64143+{
64144+ return;
64145+}
64146+
64147+int
64148+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
64149+{
64150+ return 1;
64151+}
64152+
64153+void
64154+gr_set_role_label(const kuid_t uid, const kgid_t gid)
64155+{
64156+ return;
64157+}
64158+
64159+int
64160+gr_acl_handle_procpidmem(const struct task_struct *task)
64161+{
64162+ return 0;
64163+}
64164+
64165+int
64166+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
64167+{
64168+ return 0;
64169+}
64170+
64171+int
64172+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
64173+{
64174+ return 0;
64175+}
64176+
64177+void
64178+gr_set_kernel_label(struct task_struct *task)
64179+{
64180+ return;
64181+}
64182+
64183+int
64184+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64185+{
64186+ return 0;
64187+}
64188+
64189+int
64190+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64191+{
64192+ return 0;
64193+}
64194+
64195+int gr_acl_enable_at_secure(void)
64196+{
64197+ return 0;
64198+}
64199+
64200+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
64201+{
64202+ return dentry->d_sb->s_dev;
64203+}
64204+
64205+void gr_put_exec_file(struct task_struct *task)
64206+{
64207+ return;
64208+}
64209+
64210+EXPORT_SYMBOL(gr_set_kernel_label);
64211+#ifdef CONFIG_SECURITY
64212+EXPORT_SYMBOL(gr_check_user_change);
64213+EXPORT_SYMBOL(gr_check_group_change);
64214+#endif
64215diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
64216new file mode 100644
64217index 0000000..387032b
64218--- /dev/null
64219+++ b/grsecurity/grsec_exec.c
64220@@ -0,0 +1,187 @@
64221+#include <linux/kernel.h>
64222+#include <linux/sched.h>
64223+#include <linux/file.h>
64224+#include <linux/binfmts.h>
64225+#include <linux/fs.h>
64226+#include <linux/types.h>
64227+#include <linux/grdefs.h>
64228+#include <linux/grsecurity.h>
64229+#include <linux/grinternal.h>
64230+#include <linux/capability.h>
64231+#include <linux/module.h>
64232+#include <linux/compat.h>
64233+
64234+#include <asm/uaccess.h>
64235+
64236+#ifdef CONFIG_GRKERNSEC_EXECLOG
64237+static char gr_exec_arg_buf[132];
64238+static DEFINE_MUTEX(gr_exec_arg_mutex);
64239+#endif
64240+
64241+struct user_arg_ptr {
64242+#ifdef CONFIG_COMPAT
64243+ bool is_compat;
64244+#endif
64245+ union {
64246+ const char __user *const __user *native;
64247+#ifdef CONFIG_COMPAT
64248+ const compat_uptr_t __user *compat;
64249+#endif
64250+ } ptr;
64251+};
64252+
64253+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
64254+
64255+void
64256+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
64257+{
64258+#ifdef CONFIG_GRKERNSEC_EXECLOG
64259+ char *grarg = gr_exec_arg_buf;
64260+ unsigned int i, x, execlen = 0;
64261+ char c;
64262+
64263+ if (!((grsec_enable_execlog && grsec_enable_group &&
64264+ in_group_p(grsec_audit_gid))
64265+ || (grsec_enable_execlog && !grsec_enable_group)))
64266+ return;
64267+
64268+ mutex_lock(&gr_exec_arg_mutex);
64269+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
64270+
64271+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
64272+ const char __user *p;
64273+ unsigned int len;
64274+
64275+ p = get_user_arg_ptr(argv, i);
64276+ if (IS_ERR(p))
64277+ goto log;
64278+
64279+ len = strnlen_user(p, 128 - execlen);
64280+ if (len > 128 - execlen)
64281+ len = 128 - execlen;
64282+ else if (len > 0)
64283+ len--;
64284+ if (copy_from_user(grarg + execlen, p, len))
64285+ goto log;
64286+
64287+ /* rewrite unprintable characters */
64288+ for (x = 0; x < len; x++) {
64289+ c = *(grarg + execlen + x);
64290+ if (c < 32 || c > 126)
64291+ *(grarg + execlen + x) = ' ';
64292+ }
64293+
64294+ execlen += len;
64295+ *(grarg + execlen) = ' ';
64296+ *(grarg + execlen + 1) = '\0';
64297+ execlen++;
64298+ }
64299+
64300+ log:
64301+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
64302+ bprm->file->f_path.mnt, grarg);
64303+ mutex_unlock(&gr_exec_arg_mutex);
64304+#endif
64305+ return;
64306+}
64307+
64308+#ifdef CONFIG_GRKERNSEC
64309+extern int gr_acl_is_capable(const int cap);
64310+extern int gr_acl_is_capable_nolog(const int cap);
64311+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64312+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
64313+extern int gr_chroot_is_capable(const int cap);
64314+extern int gr_chroot_is_capable_nolog(const int cap);
64315+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64316+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
64317+#endif
64318+
64319+const char *captab_log[] = {
64320+ "CAP_CHOWN",
64321+ "CAP_DAC_OVERRIDE",
64322+ "CAP_DAC_READ_SEARCH",
64323+ "CAP_FOWNER",
64324+ "CAP_FSETID",
64325+ "CAP_KILL",
64326+ "CAP_SETGID",
64327+ "CAP_SETUID",
64328+ "CAP_SETPCAP",
64329+ "CAP_LINUX_IMMUTABLE",
64330+ "CAP_NET_BIND_SERVICE",
64331+ "CAP_NET_BROADCAST",
64332+ "CAP_NET_ADMIN",
64333+ "CAP_NET_RAW",
64334+ "CAP_IPC_LOCK",
64335+ "CAP_IPC_OWNER",
64336+ "CAP_SYS_MODULE",
64337+ "CAP_SYS_RAWIO",
64338+ "CAP_SYS_CHROOT",
64339+ "CAP_SYS_PTRACE",
64340+ "CAP_SYS_PACCT",
64341+ "CAP_SYS_ADMIN",
64342+ "CAP_SYS_BOOT",
64343+ "CAP_SYS_NICE",
64344+ "CAP_SYS_RESOURCE",
64345+ "CAP_SYS_TIME",
64346+ "CAP_SYS_TTY_CONFIG",
64347+ "CAP_MKNOD",
64348+ "CAP_LEASE",
64349+ "CAP_AUDIT_WRITE",
64350+ "CAP_AUDIT_CONTROL",
64351+ "CAP_SETFCAP",
64352+ "CAP_MAC_OVERRIDE",
64353+ "CAP_MAC_ADMIN",
64354+ "CAP_SYSLOG",
64355+ "CAP_WAKE_ALARM"
64356+};
64357+
64358+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
64359+
64360+int gr_is_capable(const int cap)
64361+{
64362+#ifdef CONFIG_GRKERNSEC
64363+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
64364+ return 1;
64365+ return 0;
64366+#else
64367+ return 1;
64368+#endif
64369+}
64370+
64371+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
64372+{
64373+#ifdef CONFIG_GRKERNSEC
64374+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
64375+ return 1;
64376+ return 0;
64377+#else
64378+ return 1;
64379+#endif
64380+}
64381+
64382+int gr_is_capable_nolog(const int cap)
64383+{
64384+#ifdef CONFIG_GRKERNSEC
64385+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
64386+ return 1;
64387+ return 0;
64388+#else
64389+ return 1;
64390+#endif
64391+}
64392+
64393+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
64394+{
64395+#ifdef CONFIG_GRKERNSEC
64396+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
64397+ return 1;
64398+ return 0;
64399+#else
64400+ return 1;
64401+#endif
64402+}
64403+
64404+EXPORT_SYMBOL(gr_is_capable);
64405+EXPORT_SYMBOL(gr_is_capable_nolog);
64406+EXPORT_SYMBOL(gr_task_is_capable);
64407+EXPORT_SYMBOL(gr_task_is_capable_nolog);
64408diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
64409new file mode 100644
64410index 0000000..06cc6ea
64411--- /dev/null
64412+++ b/grsecurity/grsec_fifo.c
64413@@ -0,0 +1,24 @@
64414+#include <linux/kernel.h>
64415+#include <linux/sched.h>
64416+#include <linux/fs.h>
64417+#include <linux/file.h>
64418+#include <linux/grinternal.h>
64419+
64420+int
64421+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
64422+ const struct dentry *dir, const int flag, const int acc_mode)
64423+{
64424+#ifdef CONFIG_GRKERNSEC_FIFO
64425+ const struct cred *cred = current_cred();
64426+
64427+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
64428+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
64429+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
64430+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
64431+ if (!inode_permission(dentry->d_inode, acc_mode))
64432+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, GR_GLOBAL_UID(dentry->d_inode->i_uid), GR_GLOBAL_GID(dentry->d_inode->i_gid));
64433+ return -EACCES;
64434+ }
64435+#endif
64436+ return 0;
64437+}
64438diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
64439new file mode 100644
64440index 0000000..8ca18bf
64441--- /dev/null
64442+++ b/grsecurity/grsec_fork.c
64443@@ -0,0 +1,23 @@
64444+#include <linux/kernel.h>
64445+#include <linux/sched.h>
64446+#include <linux/grsecurity.h>
64447+#include <linux/grinternal.h>
64448+#include <linux/errno.h>
64449+
64450+void
64451+gr_log_forkfail(const int retval)
64452+{
64453+#ifdef CONFIG_GRKERNSEC_FORKFAIL
64454+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
64455+ switch (retval) {
64456+ case -EAGAIN:
64457+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
64458+ break;
64459+ case -ENOMEM:
64460+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
64461+ break;
64462+ }
64463+ }
64464+#endif
64465+ return;
64466+}
64467diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
64468new file mode 100644
64469index 0000000..a862e9f
64470--- /dev/null
64471+++ b/grsecurity/grsec_init.c
64472@@ -0,0 +1,283 @@
64473+#include <linux/kernel.h>
64474+#include <linux/sched.h>
64475+#include <linux/mm.h>
64476+#include <linux/gracl.h>
64477+#include <linux/slab.h>
64478+#include <linux/vmalloc.h>
64479+#include <linux/percpu.h>
64480+#include <linux/module.h>
64481+
64482+int grsec_enable_ptrace_readexec;
64483+int grsec_enable_setxid;
64484+int grsec_enable_symlinkown;
64485+kgid_t grsec_symlinkown_gid;
64486+int grsec_enable_brute;
64487+int grsec_enable_link;
64488+int grsec_enable_dmesg;
64489+int grsec_enable_harden_ptrace;
64490+int grsec_enable_fifo;
64491+int grsec_enable_execlog;
64492+int grsec_enable_signal;
64493+int grsec_enable_forkfail;
64494+int grsec_enable_audit_ptrace;
64495+int grsec_enable_time;
64496+int grsec_enable_audit_textrel;
64497+int grsec_enable_group;
64498+kgid_t grsec_audit_gid;
64499+int grsec_enable_chdir;
64500+int grsec_enable_mount;
64501+int grsec_enable_rofs;
64502+int grsec_enable_chroot_findtask;
64503+int grsec_enable_chroot_mount;
64504+int grsec_enable_chroot_shmat;
64505+int grsec_enable_chroot_fchdir;
64506+int grsec_enable_chroot_double;
64507+int grsec_enable_chroot_pivot;
64508+int grsec_enable_chroot_chdir;
64509+int grsec_enable_chroot_chmod;
64510+int grsec_enable_chroot_mknod;
64511+int grsec_enable_chroot_nice;
64512+int grsec_enable_chroot_execlog;
64513+int grsec_enable_chroot_caps;
64514+int grsec_enable_chroot_sysctl;
64515+int grsec_enable_chroot_unix;
64516+int grsec_enable_tpe;
64517+kgid_t grsec_tpe_gid;
64518+int grsec_enable_blackhole;
64519+#ifdef CONFIG_IPV6_MODULE
64520+EXPORT_SYMBOL(grsec_enable_blackhole);
64521+#endif
64522+int grsec_lastack_retries;
64523+int grsec_enable_tpe_all;
64524+int grsec_enable_tpe_invert;
64525+int grsec_enable_socket_all;
64526+kgid_t grsec_socket_all_gid;
64527+int grsec_enable_socket_client;
64528+kgid_t grsec_socket_client_gid;
64529+int grsec_enable_socket_server;
64530+kgid_t grsec_socket_server_gid;
64531+int grsec_resource_logging;
64532+int grsec_disable_privio;
64533+int grsec_enable_log_rwxmaps;
64534+int grsec_lock;
64535+
64536+DEFINE_SPINLOCK(grsec_alert_lock);
64537+unsigned long grsec_alert_wtime = 0;
64538+unsigned long grsec_alert_fyet = 0;
64539+
64540+DEFINE_SPINLOCK(grsec_audit_lock);
64541+
64542+DEFINE_RWLOCK(grsec_exec_file_lock);
64543+
64544+char *gr_shared_page[4];
64545+
64546+char *gr_alert_log_fmt;
64547+char *gr_audit_log_fmt;
64548+char *gr_alert_log_buf;
64549+char *gr_audit_log_buf;
64550+
64551+extern struct gr_arg *gr_usermode;
64552+extern unsigned char *gr_system_salt;
64553+extern unsigned char *gr_system_sum;
64554+
64555+void __init
64556+grsecurity_init(void)
64557+{
64558+ int j;
64559+ /* create the per-cpu shared pages */
64560+
64561+#ifdef CONFIG_X86
64562+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
64563+#endif
64564+
64565+ for (j = 0; j < 4; j++) {
64566+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
64567+ if (gr_shared_page[j] == NULL) {
64568+ panic("Unable to allocate grsecurity shared page");
64569+ return;
64570+ }
64571+ }
64572+
64573+ /* allocate log buffers */
64574+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
64575+ if (!gr_alert_log_fmt) {
64576+ panic("Unable to allocate grsecurity alert log format buffer");
64577+ return;
64578+ }
64579+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
64580+ if (!gr_audit_log_fmt) {
64581+ panic("Unable to allocate grsecurity audit log format buffer");
64582+ return;
64583+ }
64584+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
64585+ if (!gr_alert_log_buf) {
64586+ panic("Unable to allocate grsecurity alert log buffer");
64587+ return;
64588+ }
64589+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
64590+ if (!gr_audit_log_buf) {
64591+ panic("Unable to allocate grsecurity audit log buffer");
64592+ return;
64593+ }
64594+
64595+ /* allocate memory for authentication structure */
64596+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
64597+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
64598+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
64599+
64600+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
64601+ panic("Unable to allocate grsecurity authentication structure");
64602+ return;
64603+ }
64604+
64605+
64606+#ifdef CONFIG_GRKERNSEC_IO
64607+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
64608+ grsec_disable_privio = 1;
64609+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
64610+ grsec_disable_privio = 1;
64611+#else
64612+ grsec_disable_privio = 0;
64613+#endif
64614+#endif
64615+
64616+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
64617+ /* for backward compatibility, tpe_invert always defaults to on if
64618+ enabled in the kernel
64619+ */
64620+ grsec_enable_tpe_invert = 1;
64621+#endif
64622+
64623+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
64624+#ifndef CONFIG_GRKERNSEC_SYSCTL
64625+ grsec_lock = 1;
64626+#endif
64627+
64628+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
64629+ grsec_enable_audit_textrel = 1;
64630+#endif
64631+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64632+ grsec_enable_log_rwxmaps = 1;
64633+#endif
64634+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
64635+ grsec_enable_group = 1;
64636+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
64637+#endif
64638+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
64639+ grsec_enable_ptrace_readexec = 1;
64640+#endif
64641+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
64642+ grsec_enable_chdir = 1;
64643+#endif
64644+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
64645+ grsec_enable_harden_ptrace = 1;
64646+#endif
64647+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64648+ grsec_enable_mount = 1;
64649+#endif
64650+#ifdef CONFIG_GRKERNSEC_LINK
64651+ grsec_enable_link = 1;
64652+#endif
64653+#ifdef CONFIG_GRKERNSEC_BRUTE
64654+ grsec_enable_brute = 1;
64655+#endif
64656+#ifdef CONFIG_GRKERNSEC_DMESG
64657+ grsec_enable_dmesg = 1;
64658+#endif
64659+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
64660+ grsec_enable_blackhole = 1;
64661+ grsec_lastack_retries = 4;
64662+#endif
64663+#ifdef CONFIG_GRKERNSEC_FIFO
64664+ grsec_enable_fifo = 1;
64665+#endif
64666+#ifdef CONFIG_GRKERNSEC_EXECLOG
64667+ grsec_enable_execlog = 1;
64668+#endif
64669+#ifdef CONFIG_GRKERNSEC_SETXID
64670+ grsec_enable_setxid = 1;
64671+#endif
64672+#ifdef CONFIG_GRKERNSEC_SIGNAL
64673+ grsec_enable_signal = 1;
64674+#endif
64675+#ifdef CONFIG_GRKERNSEC_FORKFAIL
64676+ grsec_enable_forkfail = 1;
64677+#endif
64678+#ifdef CONFIG_GRKERNSEC_TIME
64679+ grsec_enable_time = 1;
64680+#endif
64681+#ifdef CONFIG_GRKERNSEC_RESLOG
64682+ grsec_resource_logging = 1;
64683+#endif
64684+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64685+ grsec_enable_chroot_findtask = 1;
64686+#endif
64687+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
64688+ grsec_enable_chroot_unix = 1;
64689+#endif
64690+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
64691+ grsec_enable_chroot_mount = 1;
64692+#endif
64693+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
64694+ grsec_enable_chroot_fchdir = 1;
64695+#endif
64696+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
64697+ grsec_enable_chroot_shmat = 1;
64698+#endif
64699+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
64700+ grsec_enable_audit_ptrace = 1;
64701+#endif
64702+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
64703+ grsec_enable_chroot_double = 1;
64704+#endif
64705+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
64706+ grsec_enable_chroot_pivot = 1;
64707+#endif
64708+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
64709+ grsec_enable_chroot_chdir = 1;
64710+#endif
64711+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
64712+ grsec_enable_chroot_chmod = 1;
64713+#endif
64714+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
64715+ grsec_enable_chroot_mknod = 1;
64716+#endif
64717+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64718+ grsec_enable_chroot_nice = 1;
64719+#endif
64720+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
64721+ grsec_enable_chroot_execlog = 1;
64722+#endif
64723+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64724+ grsec_enable_chroot_caps = 1;
64725+#endif
64726+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
64727+ grsec_enable_chroot_sysctl = 1;
64728+#endif
64729+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
64730+ grsec_enable_symlinkown = 1;
64731+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
64732+#endif
64733+#ifdef CONFIG_GRKERNSEC_TPE
64734+ grsec_enable_tpe = 1;
64735+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
64736+#ifdef CONFIG_GRKERNSEC_TPE_ALL
64737+ grsec_enable_tpe_all = 1;
64738+#endif
64739+#endif
64740+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
64741+ grsec_enable_socket_all = 1;
64742+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
64743+#endif
64744+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
64745+ grsec_enable_socket_client = 1;
64746+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
64747+#endif
64748+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
64749+ grsec_enable_socket_server = 1;
64750+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
64751+#endif
64752+#endif
64753+
64754+ return;
64755+}
64756diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
64757new file mode 100644
64758index 0000000..5e05e20
64759--- /dev/null
64760+++ b/grsecurity/grsec_link.c
64761@@ -0,0 +1,58 @@
64762+#include <linux/kernel.h>
64763+#include <linux/sched.h>
64764+#include <linux/fs.h>
64765+#include <linux/file.h>
64766+#include <linux/grinternal.h>
64767+
64768+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
64769+{
64770+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
64771+ const struct inode *link_inode = link->dentry->d_inode;
64772+
64773+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
64774+ /* ignore root-owned links, e.g. /proc/self */
64775+ gr_is_global_nonroot(link_inode->i_uid) && target &&
64776+ !uid_eq(link_inode->i_uid, target->i_uid)) {
64777+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
64778+ return 1;
64779+ }
64780+#endif
64781+ return 0;
64782+}
64783+
64784+int
64785+gr_handle_follow_link(const struct inode *parent,
64786+ const struct inode *inode,
64787+ const struct dentry *dentry, const struct vfsmount *mnt)
64788+{
64789+#ifdef CONFIG_GRKERNSEC_LINK
64790+ const struct cred *cred = current_cred();
64791+
64792+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
64793+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
64794+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
64795+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
64796+ return -EACCES;
64797+ }
64798+#endif
64799+ return 0;
64800+}
64801+
64802+int
64803+gr_handle_hardlink(const struct dentry *dentry,
64804+ const struct vfsmount *mnt,
64805+ struct inode *inode, const int mode, const struct filename *to)
64806+{
64807+#ifdef CONFIG_GRKERNSEC_LINK
64808+ const struct cred *cred = current_cred();
64809+
64810+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
64811+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
64812+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
64813+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
64814+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
64815+ return -EPERM;
64816+ }
64817+#endif
64818+ return 0;
64819+}
64820diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
64821new file mode 100644
64822index 0000000..7c06085
64823--- /dev/null
64824+++ b/grsecurity/grsec_log.c
64825@@ -0,0 +1,326 @@
64826+#include <linux/kernel.h>
64827+#include <linux/sched.h>
64828+#include <linux/file.h>
64829+#include <linux/tty.h>
64830+#include <linux/fs.h>
64831+#include <linux/grinternal.h>
64832+
64833+#ifdef CONFIG_TREE_PREEMPT_RCU
64834+#define DISABLE_PREEMPT() preempt_disable()
64835+#define ENABLE_PREEMPT() preempt_enable()
64836+#else
64837+#define DISABLE_PREEMPT()
64838+#define ENABLE_PREEMPT()
64839+#endif
64840+
64841+#define BEGIN_LOCKS(x) \
64842+ DISABLE_PREEMPT(); \
64843+ rcu_read_lock(); \
64844+ read_lock(&tasklist_lock); \
64845+ read_lock(&grsec_exec_file_lock); \
64846+ if (x != GR_DO_AUDIT) \
64847+ spin_lock(&grsec_alert_lock); \
64848+ else \
64849+ spin_lock(&grsec_audit_lock)
64850+
64851+#define END_LOCKS(x) \
64852+ if (x != GR_DO_AUDIT) \
64853+ spin_unlock(&grsec_alert_lock); \
64854+ else \
64855+ spin_unlock(&grsec_audit_lock); \
64856+ read_unlock(&grsec_exec_file_lock); \
64857+ read_unlock(&tasklist_lock); \
64858+ rcu_read_unlock(); \
64859+ ENABLE_PREEMPT(); \
64860+ if (x == GR_DONT_AUDIT) \
64861+ gr_handle_alertkill(current)
64862+
64863+enum {
64864+ FLOODING,
64865+ NO_FLOODING
64866+};
64867+
64868+extern char *gr_alert_log_fmt;
64869+extern char *gr_audit_log_fmt;
64870+extern char *gr_alert_log_buf;
64871+extern char *gr_audit_log_buf;
64872+
64873+static int gr_log_start(int audit)
64874+{
64875+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
64876+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
64877+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64878+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
64879+ unsigned long curr_secs = get_seconds();
64880+
64881+ if (audit == GR_DO_AUDIT)
64882+ goto set_fmt;
64883+
64884+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
64885+ grsec_alert_wtime = curr_secs;
64886+ grsec_alert_fyet = 0;
64887+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
64888+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
64889+ grsec_alert_fyet++;
64890+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
64891+ grsec_alert_wtime = curr_secs;
64892+ grsec_alert_fyet++;
64893+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
64894+ return FLOODING;
64895+ }
64896+ else return FLOODING;
64897+
64898+set_fmt:
64899+#endif
64900+ memset(buf, 0, PAGE_SIZE);
64901+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
64902+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
64903+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
64904+ } else if (current->signal->curr_ip) {
64905+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
64906+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
64907+ } else if (gr_acl_is_enabled()) {
64908+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
64909+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
64910+ } else {
64911+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
64912+ strcpy(buf, fmt);
64913+ }
64914+
64915+ return NO_FLOODING;
64916+}
64917+
64918+static void gr_log_middle(int audit, const char *msg, va_list ap)
64919+ __attribute__ ((format (printf, 2, 0)));
64920+
64921+static void gr_log_middle(int audit, const char *msg, va_list ap)
64922+{
64923+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64924+ unsigned int len = strlen(buf);
64925+
64926+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
64927+
64928+ return;
64929+}
64930+
64931+static void gr_log_middle_varargs(int audit, const char *msg, ...)
64932+ __attribute__ ((format (printf, 2, 3)));
64933+
64934+static void gr_log_middle_varargs(int audit, const char *msg, ...)
64935+{
64936+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64937+ unsigned int len = strlen(buf);
64938+ va_list ap;
64939+
64940+ va_start(ap, msg);
64941+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
64942+ va_end(ap);
64943+
64944+ return;
64945+}
64946+
64947+static void gr_log_end(int audit, int append_default)
64948+{
64949+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64950+ if (append_default) {
64951+ struct task_struct *task = current;
64952+ struct task_struct *parent = task->real_parent;
64953+ const struct cred *cred = __task_cred(task);
64954+ const struct cred *pcred = __task_cred(parent);
64955+ unsigned int len = strlen(buf);
64956+
64957+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
64958+ }
64959+
64960+ printk("%s\n", buf);
64961+
64962+ return;
64963+}
64964+
64965+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
64966+{
64967+ int logtype;
64968+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
64969+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
64970+ void *voidptr = NULL;
64971+ int num1 = 0, num2 = 0;
64972+ unsigned long ulong1 = 0, ulong2 = 0;
64973+ struct dentry *dentry = NULL;
64974+ struct vfsmount *mnt = NULL;
64975+ struct file *file = NULL;
64976+ struct task_struct *task = NULL;
64977+ const struct cred *cred, *pcred;
64978+ va_list ap;
64979+
64980+ BEGIN_LOCKS(audit);
64981+ logtype = gr_log_start(audit);
64982+ if (logtype == FLOODING) {
64983+ END_LOCKS(audit);
64984+ return;
64985+ }
64986+ va_start(ap, argtypes);
64987+ switch (argtypes) {
64988+ case GR_TTYSNIFF:
64989+ task = va_arg(ap, struct task_struct *);
64990+ gr_log_middle_varargs(audit, msg, &task->signal->curr_ip, gr_task_fullpath0(task), task->comm, task_pid_nr(task), gr_parent_task_fullpath0(task), task->real_parent->comm, task_pid_nr(task->real_parent));
64991+ break;
64992+ case GR_SYSCTL_HIDDEN:
64993+ str1 = va_arg(ap, char *);
64994+ gr_log_middle_varargs(audit, msg, result, str1);
64995+ break;
64996+ case GR_RBAC:
64997+ dentry = va_arg(ap, struct dentry *);
64998+ mnt = va_arg(ap, struct vfsmount *);
64999+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
65000+ break;
65001+ case GR_RBAC_STR:
65002+ dentry = va_arg(ap, struct dentry *);
65003+ mnt = va_arg(ap, struct vfsmount *);
65004+ str1 = va_arg(ap, char *);
65005+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
65006+ break;
65007+ case GR_STR_RBAC:
65008+ str1 = va_arg(ap, char *);
65009+ dentry = va_arg(ap, struct dentry *);
65010+ mnt = va_arg(ap, struct vfsmount *);
65011+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
65012+ break;
65013+ case GR_RBAC_MODE2:
65014+ dentry = va_arg(ap, struct dentry *);
65015+ mnt = va_arg(ap, struct vfsmount *);
65016+ str1 = va_arg(ap, char *);
65017+ str2 = va_arg(ap, char *);
65018+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
65019+ break;
65020+ case GR_RBAC_MODE3:
65021+ dentry = va_arg(ap, struct dentry *);
65022+ mnt = va_arg(ap, struct vfsmount *);
65023+ str1 = va_arg(ap, char *);
65024+ str2 = va_arg(ap, char *);
65025+ str3 = va_arg(ap, char *);
65026+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
65027+ break;
65028+ case GR_FILENAME:
65029+ dentry = va_arg(ap, struct dentry *);
65030+ mnt = va_arg(ap, struct vfsmount *);
65031+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
65032+ break;
65033+ case GR_STR_FILENAME:
65034+ str1 = va_arg(ap, char *);
65035+ dentry = va_arg(ap, struct dentry *);
65036+ mnt = va_arg(ap, struct vfsmount *);
65037+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
65038+ break;
65039+ case GR_FILENAME_STR:
65040+ dentry = va_arg(ap, struct dentry *);
65041+ mnt = va_arg(ap, struct vfsmount *);
65042+ str1 = va_arg(ap, char *);
65043+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
65044+ break;
65045+ case GR_FILENAME_TWO_INT:
65046+ dentry = va_arg(ap, struct dentry *);
65047+ mnt = va_arg(ap, struct vfsmount *);
65048+ num1 = va_arg(ap, int);
65049+ num2 = va_arg(ap, int);
65050+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
65051+ break;
65052+ case GR_FILENAME_TWO_INT_STR:
65053+ dentry = va_arg(ap, struct dentry *);
65054+ mnt = va_arg(ap, struct vfsmount *);
65055+ num1 = va_arg(ap, int);
65056+ num2 = va_arg(ap, int);
65057+ str1 = va_arg(ap, char *);
65058+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
65059+ break;
65060+ case GR_TEXTREL:
65061+ file = va_arg(ap, struct file *);
65062+ ulong1 = va_arg(ap, unsigned long);
65063+ ulong2 = va_arg(ap, unsigned long);
65064+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
65065+ break;
65066+ case GR_PTRACE:
65067+ task = va_arg(ap, struct task_struct *);
65068+ 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_nr(task));
65069+ break;
65070+ case GR_RESOURCE:
65071+ task = va_arg(ap, struct task_struct *);
65072+ cred = __task_cred(task);
65073+ pcred = __task_cred(task->real_parent);
65074+ ulong1 = va_arg(ap, unsigned long);
65075+ str1 = va_arg(ap, char *);
65076+ ulong2 = va_arg(ap, unsigned long);
65077+ gr_log_middle_varargs(audit, msg, ulong1, str1, ulong2, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
65078+ break;
65079+ case GR_CAP:
65080+ task = va_arg(ap, struct task_struct *);
65081+ cred = __task_cred(task);
65082+ pcred = __task_cred(task->real_parent);
65083+ str1 = va_arg(ap, char *);
65084+ gr_log_middle_varargs(audit, msg, str1, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
65085+ break;
65086+ case GR_SIG:
65087+ str1 = va_arg(ap, char *);
65088+ voidptr = va_arg(ap, void *);
65089+ gr_log_middle_varargs(audit, msg, str1, voidptr);
65090+ break;
65091+ case GR_SIG2:
65092+ task = va_arg(ap, struct task_struct *);
65093+ cred = __task_cred(task);
65094+ pcred = __task_cred(task->real_parent);
65095+ num1 = va_arg(ap, int);
65096+ gr_log_middle_varargs(audit, msg, num1, gr_task_fullpath0(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath0(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
65097+ break;
65098+ case GR_CRASH1:
65099+ task = va_arg(ap, struct task_struct *);
65100+ cred = __task_cred(task);
65101+ pcred = __task_cred(task->real_parent);
65102+ ulong1 = va_arg(ap, unsigned long);
65103+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid), GR_GLOBAL_UID(cred->uid), ulong1);
65104+ break;
65105+ case GR_CRASH2:
65106+ task = va_arg(ap, struct task_struct *);
65107+ cred = __task_cred(task);
65108+ pcred = __task_cred(task->real_parent);
65109+ ulong1 = va_arg(ap, unsigned long);
65110+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid), ulong1);
65111+ break;
65112+ case GR_RWXMAP:
65113+ file = va_arg(ap, struct file *);
65114+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
65115+ break;
65116+ case GR_PSACCT:
65117+ {
65118+ unsigned int wday, cday;
65119+ __u8 whr, chr;
65120+ __u8 wmin, cmin;
65121+ __u8 wsec, csec;
65122+ char cur_tty[64] = { 0 };
65123+ char parent_tty[64] = { 0 };
65124+
65125+ task = va_arg(ap, struct task_struct *);
65126+ wday = va_arg(ap, unsigned int);
65127+ cday = va_arg(ap, unsigned int);
65128+ whr = va_arg(ap, int);
65129+ chr = va_arg(ap, int);
65130+ wmin = va_arg(ap, int);
65131+ cmin = va_arg(ap, int);
65132+ wsec = va_arg(ap, int);
65133+ csec = va_arg(ap, int);
65134+ ulong1 = va_arg(ap, unsigned long);
65135+ cred = __task_cred(task);
65136+ pcred = __task_cred(task->real_parent);
65137+
65138+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), &task->signal->curr_ip, tty_name(task->signal->tty, cur_tty), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_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_pid_nr(task->real_parent), &task->real_parent->signal->curr_ip, tty_name(task->real_parent->signal->tty, parent_tty), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
65139+ }
65140+ break;
65141+ default:
65142+ gr_log_middle(audit, msg, ap);
65143+ }
65144+ va_end(ap);
65145+ // these don't need DEFAULTSECARGS printed on the end
65146+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
65147+ gr_log_end(audit, 0);
65148+ else
65149+ gr_log_end(audit, 1);
65150+ END_LOCKS(audit);
65151+}
65152diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
65153new file mode 100644
65154index 0000000..f536303
65155--- /dev/null
65156+++ b/grsecurity/grsec_mem.c
65157@@ -0,0 +1,40 @@
65158+#include <linux/kernel.h>
65159+#include <linux/sched.h>
65160+#include <linux/mm.h>
65161+#include <linux/mman.h>
65162+#include <linux/grinternal.h>
65163+
65164+void
65165+gr_handle_ioperm(void)
65166+{
65167+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
65168+ return;
65169+}
65170+
65171+void
65172+gr_handle_iopl(void)
65173+{
65174+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
65175+ return;
65176+}
65177+
65178+void
65179+gr_handle_mem_readwrite(u64 from, u64 to)
65180+{
65181+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
65182+ return;
65183+}
65184+
65185+void
65186+gr_handle_vm86(void)
65187+{
65188+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
65189+ return;
65190+}
65191+
65192+void
65193+gr_log_badprocpid(const char *entry)
65194+{
65195+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
65196+ return;
65197+}
65198diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
65199new file mode 100644
65200index 0000000..2131422
65201--- /dev/null
65202+++ b/grsecurity/grsec_mount.c
65203@@ -0,0 +1,62 @@
65204+#include <linux/kernel.h>
65205+#include <linux/sched.h>
65206+#include <linux/mount.h>
65207+#include <linux/grsecurity.h>
65208+#include <linux/grinternal.h>
65209+
65210+void
65211+gr_log_remount(const char *devname, const int retval)
65212+{
65213+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65214+ if (grsec_enable_mount && (retval >= 0))
65215+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
65216+#endif
65217+ return;
65218+}
65219+
65220+void
65221+gr_log_unmount(const char *devname, const int retval)
65222+{
65223+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65224+ if (grsec_enable_mount && (retval >= 0))
65225+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
65226+#endif
65227+ return;
65228+}
65229+
65230+void
65231+gr_log_mount(const char *from, const char *to, const int retval)
65232+{
65233+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65234+ if (grsec_enable_mount && (retval >= 0))
65235+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
65236+#endif
65237+ return;
65238+}
65239+
65240+int
65241+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
65242+{
65243+#ifdef CONFIG_GRKERNSEC_ROFS
65244+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
65245+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
65246+ return -EPERM;
65247+ } else
65248+ return 0;
65249+#endif
65250+ return 0;
65251+}
65252+
65253+int
65254+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
65255+{
65256+#ifdef CONFIG_GRKERNSEC_ROFS
65257+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
65258+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
65259+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
65260+ return -EPERM;
65261+ } else
65262+ return 0;
65263+#endif
65264+ return 0;
65265+}
65266diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
65267new file mode 100644
65268index 0000000..a3b12a0
65269--- /dev/null
65270+++ b/grsecurity/grsec_pax.c
65271@@ -0,0 +1,36 @@
65272+#include <linux/kernel.h>
65273+#include <linux/sched.h>
65274+#include <linux/mm.h>
65275+#include <linux/file.h>
65276+#include <linux/grinternal.h>
65277+#include <linux/grsecurity.h>
65278+
65279+void
65280+gr_log_textrel(struct vm_area_struct * vma)
65281+{
65282+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65283+ if (grsec_enable_audit_textrel)
65284+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
65285+#endif
65286+ return;
65287+}
65288+
65289+void
65290+gr_log_rwxmmap(struct file *file)
65291+{
65292+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65293+ if (grsec_enable_log_rwxmaps)
65294+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
65295+#endif
65296+ return;
65297+}
65298+
65299+void
65300+gr_log_rwxmprotect(struct file *file)
65301+{
65302+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65303+ if (grsec_enable_log_rwxmaps)
65304+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
65305+#endif
65306+ return;
65307+}
65308diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
65309new file mode 100644
65310index 0000000..f7f29aa
65311--- /dev/null
65312+++ b/grsecurity/grsec_ptrace.c
65313@@ -0,0 +1,30 @@
65314+#include <linux/kernel.h>
65315+#include <linux/sched.h>
65316+#include <linux/grinternal.h>
65317+#include <linux/security.h>
65318+
65319+void
65320+gr_audit_ptrace(struct task_struct *task)
65321+{
65322+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65323+ if (grsec_enable_audit_ptrace)
65324+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
65325+#endif
65326+ return;
65327+}
65328+
65329+int
65330+gr_ptrace_readexec(struct file *file, int unsafe_flags)
65331+{
65332+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65333+ const struct dentry *dentry = file->f_path.dentry;
65334+ const struct vfsmount *mnt = file->f_path.mnt;
65335+
65336+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
65337+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
65338+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
65339+ return -EACCES;
65340+ }
65341+#endif
65342+ return 0;
65343+}
65344diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
65345new file mode 100644
65346index 0000000..e09715a
65347--- /dev/null
65348+++ b/grsecurity/grsec_sig.c
65349@@ -0,0 +1,222 @@
65350+#include <linux/kernel.h>
65351+#include <linux/sched.h>
65352+#include <linux/delay.h>
65353+#include <linux/grsecurity.h>
65354+#include <linux/grinternal.h>
65355+#include <linux/hardirq.h>
65356+
65357+char *signames[] = {
65358+ [SIGSEGV] = "Segmentation fault",
65359+ [SIGILL] = "Illegal instruction",
65360+ [SIGABRT] = "Abort",
65361+ [SIGBUS] = "Invalid alignment/Bus error"
65362+};
65363+
65364+void
65365+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
65366+{
65367+#ifdef CONFIG_GRKERNSEC_SIGNAL
65368+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
65369+ (sig == SIGABRT) || (sig == SIGBUS))) {
65370+ if (task_pid_nr(t) == task_pid_nr(current)) {
65371+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
65372+ } else {
65373+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
65374+ }
65375+ }
65376+#endif
65377+ return;
65378+}
65379+
65380+int
65381+gr_handle_signal(const struct task_struct *p, const int sig)
65382+{
65383+#ifdef CONFIG_GRKERNSEC
65384+ /* ignore the 0 signal for protected task checks */
65385+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
65386+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
65387+ return -EPERM;
65388+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
65389+ return -EPERM;
65390+ }
65391+#endif
65392+ return 0;
65393+}
65394+
65395+#ifdef CONFIG_GRKERNSEC
65396+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
65397+
65398+int gr_fake_force_sig(int sig, struct task_struct *t)
65399+{
65400+ unsigned long int flags;
65401+ int ret, blocked, ignored;
65402+ struct k_sigaction *action;
65403+
65404+ spin_lock_irqsave(&t->sighand->siglock, flags);
65405+ action = &t->sighand->action[sig-1];
65406+ ignored = action->sa.sa_handler == SIG_IGN;
65407+ blocked = sigismember(&t->blocked, sig);
65408+ if (blocked || ignored) {
65409+ action->sa.sa_handler = SIG_DFL;
65410+ if (blocked) {
65411+ sigdelset(&t->blocked, sig);
65412+ recalc_sigpending_and_wake(t);
65413+ }
65414+ }
65415+ if (action->sa.sa_handler == SIG_DFL)
65416+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
65417+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
65418+
65419+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
65420+
65421+ return ret;
65422+}
65423+#endif
65424+
65425+#ifdef CONFIG_GRKERNSEC_BRUTE
65426+#define GR_USER_BAN_TIME (15 * 60)
65427+#define GR_DAEMON_BRUTE_TIME (30 * 60)
65428+
65429+static int __get_dumpable(unsigned long mm_flags)
65430+{
65431+ int ret;
65432+
65433+ ret = mm_flags & MMF_DUMPABLE_MASK;
65434+ return (ret >= 2) ? 2 : ret;
65435+}
65436+#endif
65437+
65438+void gr_handle_brute_attach(unsigned long mm_flags)
65439+{
65440+#ifdef CONFIG_GRKERNSEC_BRUTE
65441+ struct task_struct *p = current;
65442+ kuid_t uid = GLOBAL_ROOT_UID;
65443+ int daemon = 0;
65444+
65445+ if (!grsec_enable_brute)
65446+ return;
65447+
65448+ rcu_read_lock();
65449+ read_lock(&tasklist_lock);
65450+ read_lock(&grsec_exec_file_lock);
65451+ if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
65452+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
65453+ p->real_parent->brute = 1;
65454+ daemon = 1;
65455+ } else {
65456+ const struct cred *cred = __task_cred(p), *cred2;
65457+ struct task_struct *tsk, *tsk2;
65458+
65459+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
65460+ struct user_struct *user;
65461+
65462+ uid = cred->uid;
65463+
65464+ /* this is put upon execution past expiration */
65465+ user = find_user(uid);
65466+ if (user == NULL)
65467+ goto unlock;
65468+ user->banned = 1;
65469+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
65470+ if (user->ban_expires == ~0UL)
65471+ user->ban_expires--;
65472+
65473+ do_each_thread(tsk2, tsk) {
65474+ cred2 = __task_cred(tsk);
65475+ if (tsk != p && uid_eq(cred2->uid, uid))
65476+ gr_fake_force_sig(SIGKILL, tsk);
65477+ } while_each_thread(tsk2, tsk);
65478+ }
65479+ }
65480+unlock:
65481+ read_unlock(&grsec_exec_file_lock);
65482+ read_unlock(&tasklist_lock);
65483+ rcu_read_unlock();
65484+
65485+ if (gr_is_global_nonroot(uid))
65486+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
65487+ GR_GLOBAL_UID(uid), GR_USER_BAN_TIME / 60);
65488+ else if (daemon)
65489+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
65490+
65491+#endif
65492+ return;
65493+}
65494+
65495+void gr_handle_brute_check(void)
65496+{
65497+#ifdef CONFIG_GRKERNSEC_BRUTE
65498+ struct task_struct *p = current;
65499+
65500+ if (unlikely(p->brute)) {
65501+ if (!grsec_enable_brute)
65502+ p->brute = 0;
65503+ else if (time_before(get_seconds(), p->brute_expires))
65504+ msleep(30 * 1000);
65505+ }
65506+#endif
65507+ return;
65508+}
65509+
65510+void gr_handle_kernel_exploit(void)
65511+{
65512+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
65513+ const struct cred *cred;
65514+ struct task_struct *tsk, *tsk2;
65515+ struct user_struct *user;
65516+ kuid_t uid;
65517+
65518+ if (in_irq() || in_serving_softirq() || in_nmi())
65519+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
65520+
65521+ uid = current_uid();
65522+
65523+ if (gr_is_global_root(uid))
65524+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
65525+ else {
65526+ /* kill all the processes of this user, hold a reference
65527+ to their creds struct, and prevent them from creating
65528+ another process until system reset
65529+ */
65530+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
65531+ GR_GLOBAL_UID(uid));
65532+ /* we intentionally leak this ref */
65533+ user = get_uid(current->cred->user);
65534+ if (user) {
65535+ user->banned = 1;
65536+ user->ban_expires = ~0UL;
65537+ }
65538+
65539+ read_lock(&tasklist_lock);
65540+ do_each_thread(tsk2, tsk) {
65541+ cred = __task_cred(tsk);
65542+ if (uid_eq(cred->uid, uid))
65543+ gr_fake_force_sig(SIGKILL, tsk);
65544+ } while_each_thread(tsk2, tsk);
65545+ read_unlock(&tasklist_lock);
65546+ }
65547+#endif
65548+}
65549+
65550+int __gr_process_user_ban(struct user_struct *user)
65551+{
65552+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
65553+ if (unlikely(user->banned)) {
65554+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
65555+ user->banned = 0;
65556+ user->ban_expires = 0;
65557+ free_uid(user);
65558+ } else
65559+ return -EPERM;
65560+ }
65561+#endif
65562+ return 0;
65563+}
65564+
65565+int gr_process_user_ban(void)
65566+{
65567+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
65568+ return __gr_process_user_ban(current->cred->user);
65569+#endif
65570+ return 0;
65571+}
65572diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
65573new file mode 100644
65574index 0000000..4030d57
65575--- /dev/null
65576+++ b/grsecurity/grsec_sock.c
65577@@ -0,0 +1,244 @@
65578+#include <linux/kernel.h>
65579+#include <linux/module.h>
65580+#include <linux/sched.h>
65581+#include <linux/file.h>
65582+#include <linux/net.h>
65583+#include <linux/in.h>
65584+#include <linux/ip.h>
65585+#include <net/sock.h>
65586+#include <net/inet_sock.h>
65587+#include <linux/grsecurity.h>
65588+#include <linux/grinternal.h>
65589+#include <linux/gracl.h>
65590+
65591+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
65592+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
65593+
65594+EXPORT_SYMBOL(gr_search_udp_recvmsg);
65595+EXPORT_SYMBOL(gr_search_udp_sendmsg);
65596+
65597+#ifdef CONFIG_UNIX_MODULE
65598+EXPORT_SYMBOL(gr_acl_handle_unix);
65599+EXPORT_SYMBOL(gr_acl_handle_mknod);
65600+EXPORT_SYMBOL(gr_handle_chroot_unix);
65601+EXPORT_SYMBOL(gr_handle_create);
65602+#endif
65603+
65604+#ifdef CONFIG_GRKERNSEC
65605+#define gr_conn_table_size 32749
65606+struct conn_table_entry {
65607+ struct conn_table_entry *next;
65608+ struct signal_struct *sig;
65609+};
65610+
65611+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
65612+DEFINE_SPINLOCK(gr_conn_table_lock);
65613+
65614+extern const char * gr_socktype_to_name(unsigned char type);
65615+extern const char * gr_proto_to_name(unsigned char proto);
65616+extern const char * gr_sockfamily_to_name(unsigned char family);
65617+
65618+static __inline__ int
65619+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
65620+{
65621+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
65622+}
65623+
65624+static __inline__ int
65625+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
65626+ __u16 sport, __u16 dport)
65627+{
65628+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
65629+ sig->gr_sport == sport && sig->gr_dport == dport))
65630+ return 1;
65631+ else
65632+ return 0;
65633+}
65634+
65635+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
65636+{
65637+ struct conn_table_entry **match;
65638+ unsigned int index;
65639+
65640+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
65641+ sig->gr_sport, sig->gr_dport,
65642+ gr_conn_table_size);
65643+
65644+ newent->sig = sig;
65645+
65646+ match = &gr_conn_table[index];
65647+ newent->next = *match;
65648+ *match = newent;
65649+
65650+ return;
65651+}
65652+
65653+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
65654+{
65655+ struct conn_table_entry *match, *last = NULL;
65656+ unsigned int index;
65657+
65658+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
65659+ sig->gr_sport, sig->gr_dport,
65660+ gr_conn_table_size);
65661+
65662+ match = gr_conn_table[index];
65663+ while (match && !conn_match(match->sig,
65664+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
65665+ sig->gr_dport)) {
65666+ last = match;
65667+ match = match->next;
65668+ }
65669+
65670+ if (match) {
65671+ if (last)
65672+ last->next = match->next;
65673+ else
65674+ gr_conn_table[index] = NULL;
65675+ kfree(match);
65676+ }
65677+
65678+ return;
65679+}
65680+
65681+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
65682+ __u16 sport, __u16 dport)
65683+{
65684+ struct conn_table_entry *match;
65685+ unsigned int index;
65686+
65687+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
65688+
65689+ match = gr_conn_table[index];
65690+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
65691+ match = match->next;
65692+
65693+ if (match)
65694+ return match->sig;
65695+ else
65696+ return NULL;
65697+}
65698+
65699+#endif
65700+
65701+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
65702+{
65703+#ifdef CONFIG_GRKERNSEC
65704+ struct signal_struct *sig = task->signal;
65705+ struct conn_table_entry *newent;
65706+
65707+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
65708+ if (newent == NULL)
65709+ return;
65710+ /* no bh lock needed since we are called with bh disabled */
65711+ spin_lock(&gr_conn_table_lock);
65712+ gr_del_task_from_ip_table_nolock(sig);
65713+ sig->gr_saddr = inet->inet_rcv_saddr;
65714+ sig->gr_daddr = inet->inet_daddr;
65715+ sig->gr_sport = inet->inet_sport;
65716+ sig->gr_dport = inet->inet_dport;
65717+ gr_add_to_task_ip_table_nolock(sig, newent);
65718+ spin_unlock(&gr_conn_table_lock);
65719+#endif
65720+ return;
65721+}
65722+
65723+void gr_del_task_from_ip_table(struct task_struct *task)
65724+{
65725+#ifdef CONFIG_GRKERNSEC
65726+ spin_lock_bh(&gr_conn_table_lock);
65727+ gr_del_task_from_ip_table_nolock(task->signal);
65728+ spin_unlock_bh(&gr_conn_table_lock);
65729+#endif
65730+ return;
65731+}
65732+
65733+void
65734+gr_attach_curr_ip(const struct sock *sk)
65735+{
65736+#ifdef CONFIG_GRKERNSEC
65737+ struct signal_struct *p, *set;
65738+ const struct inet_sock *inet = inet_sk(sk);
65739+
65740+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
65741+ return;
65742+
65743+ set = current->signal;
65744+
65745+ spin_lock_bh(&gr_conn_table_lock);
65746+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
65747+ inet->inet_dport, inet->inet_sport);
65748+ if (unlikely(p != NULL)) {
65749+ set->curr_ip = p->curr_ip;
65750+ set->used_accept = 1;
65751+ gr_del_task_from_ip_table_nolock(p);
65752+ spin_unlock_bh(&gr_conn_table_lock);
65753+ return;
65754+ }
65755+ spin_unlock_bh(&gr_conn_table_lock);
65756+
65757+ set->curr_ip = inet->inet_daddr;
65758+ set->used_accept = 1;
65759+#endif
65760+ return;
65761+}
65762+
65763+int
65764+gr_handle_sock_all(const int family, const int type, const int protocol)
65765+{
65766+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65767+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
65768+ (family != AF_UNIX)) {
65769+ if (family == AF_INET)
65770+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
65771+ else
65772+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
65773+ return -EACCES;
65774+ }
65775+#endif
65776+ return 0;
65777+}
65778+
65779+int
65780+gr_handle_sock_server(const struct sockaddr *sck)
65781+{
65782+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65783+ if (grsec_enable_socket_server &&
65784+ in_group_p(grsec_socket_server_gid) &&
65785+ sck && (sck->sa_family != AF_UNIX) &&
65786+ (sck->sa_family != AF_LOCAL)) {
65787+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
65788+ return -EACCES;
65789+ }
65790+#endif
65791+ return 0;
65792+}
65793+
65794+int
65795+gr_handle_sock_server_other(const struct sock *sck)
65796+{
65797+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65798+ if (grsec_enable_socket_server &&
65799+ in_group_p(grsec_socket_server_gid) &&
65800+ sck && (sck->sk_family != AF_UNIX) &&
65801+ (sck->sk_family != AF_LOCAL)) {
65802+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
65803+ return -EACCES;
65804+ }
65805+#endif
65806+ return 0;
65807+}
65808+
65809+int
65810+gr_handle_sock_client(const struct sockaddr *sck)
65811+{
65812+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65813+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
65814+ sck && (sck->sa_family != AF_UNIX) &&
65815+ (sck->sa_family != AF_LOCAL)) {
65816+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
65817+ return -EACCES;
65818+ }
65819+#endif
65820+ return 0;
65821+}
65822diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
65823new file mode 100644
65824index 0000000..f55ef0f
65825--- /dev/null
65826+++ b/grsecurity/grsec_sysctl.c
65827@@ -0,0 +1,469 @@
65828+#include <linux/kernel.h>
65829+#include <linux/sched.h>
65830+#include <linux/sysctl.h>
65831+#include <linux/grsecurity.h>
65832+#include <linux/grinternal.h>
65833+
65834+int
65835+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
65836+{
65837+#ifdef CONFIG_GRKERNSEC_SYSCTL
65838+ if (dirname == NULL || name == NULL)
65839+ return 0;
65840+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
65841+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
65842+ return -EACCES;
65843+ }
65844+#endif
65845+ return 0;
65846+}
65847+
65848+#ifdef CONFIG_GRKERNSEC_ROFS
65849+static int __maybe_unused one = 1;
65850+#endif
65851+
65852+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
65853+struct ctl_table grsecurity_table[] = {
65854+#ifdef CONFIG_GRKERNSEC_SYSCTL
65855+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
65856+#ifdef CONFIG_GRKERNSEC_IO
65857+ {
65858+ .procname = "disable_priv_io",
65859+ .data = &grsec_disable_privio,
65860+ .maxlen = sizeof(int),
65861+ .mode = 0600,
65862+ .proc_handler = &proc_dointvec,
65863+ },
65864+#endif
65865+#endif
65866+#ifdef CONFIG_GRKERNSEC_LINK
65867+ {
65868+ .procname = "linking_restrictions",
65869+ .data = &grsec_enable_link,
65870+ .maxlen = sizeof(int),
65871+ .mode = 0600,
65872+ .proc_handler = &proc_dointvec,
65873+ },
65874+#endif
65875+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65876+ {
65877+ .procname = "enforce_symlinksifowner",
65878+ .data = &grsec_enable_symlinkown,
65879+ .maxlen = sizeof(int),
65880+ .mode = 0600,
65881+ .proc_handler = &proc_dointvec,
65882+ },
65883+ {
65884+ .procname = "symlinkown_gid",
65885+ .data = &grsec_symlinkown_gid,
65886+ .maxlen = sizeof(int),
65887+ .mode = 0600,
65888+ .proc_handler = &proc_dointvec,
65889+ },
65890+#endif
65891+#ifdef CONFIG_GRKERNSEC_BRUTE
65892+ {
65893+ .procname = "deter_bruteforce",
65894+ .data = &grsec_enable_brute,
65895+ .maxlen = sizeof(int),
65896+ .mode = 0600,
65897+ .proc_handler = &proc_dointvec,
65898+ },
65899+#endif
65900+#ifdef CONFIG_GRKERNSEC_FIFO
65901+ {
65902+ .procname = "fifo_restrictions",
65903+ .data = &grsec_enable_fifo,
65904+ .maxlen = sizeof(int),
65905+ .mode = 0600,
65906+ .proc_handler = &proc_dointvec,
65907+ },
65908+#endif
65909+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65910+ {
65911+ .procname = "ptrace_readexec",
65912+ .data = &grsec_enable_ptrace_readexec,
65913+ .maxlen = sizeof(int),
65914+ .mode = 0600,
65915+ .proc_handler = &proc_dointvec,
65916+ },
65917+#endif
65918+#ifdef CONFIG_GRKERNSEC_SETXID
65919+ {
65920+ .procname = "consistent_setxid",
65921+ .data = &grsec_enable_setxid,
65922+ .maxlen = sizeof(int),
65923+ .mode = 0600,
65924+ .proc_handler = &proc_dointvec,
65925+ },
65926+#endif
65927+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
65928+ {
65929+ .procname = "ip_blackhole",
65930+ .data = &grsec_enable_blackhole,
65931+ .maxlen = sizeof(int),
65932+ .mode = 0600,
65933+ .proc_handler = &proc_dointvec,
65934+ },
65935+ {
65936+ .procname = "lastack_retries",
65937+ .data = &grsec_lastack_retries,
65938+ .maxlen = sizeof(int),
65939+ .mode = 0600,
65940+ .proc_handler = &proc_dointvec,
65941+ },
65942+#endif
65943+#ifdef CONFIG_GRKERNSEC_EXECLOG
65944+ {
65945+ .procname = "exec_logging",
65946+ .data = &grsec_enable_execlog,
65947+ .maxlen = sizeof(int),
65948+ .mode = 0600,
65949+ .proc_handler = &proc_dointvec,
65950+ },
65951+#endif
65952+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65953+ {
65954+ .procname = "rwxmap_logging",
65955+ .data = &grsec_enable_log_rwxmaps,
65956+ .maxlen = sizeof(int),
65957+ .mode = 0600,
65958+ .proc_handler = &proc_dointvec,
65959+ },
65960+#endif
65961+#ifdef CONFIG_GRKERNSEC_SIGNAL
65962+ {
65963+ .procname = "signal_logging",
65964+ .data = &grsec_enable_signal,
65965+ .maxlen = sizeof(int),
65966+ .mode = 0600,
65967+ .proc_handler = &proc_dointvec,
65968+ },
65969+#endif
65970+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65971+ {
65972+ .procname = "forkfail_logging",
65973+ .data = &grsec_enable_forkfail,
65974+ .maxlen = sizeof(int),
65975+ .mode = 0600,
65976+ .proc_handler = &proc_dointvec,
65977+ },
65978+#endif
65979+#ifdef CONFIG_GRKERNSEC_TIME
65980+ {
65981+ .procname = "timechange_logging",
65982+ .data = &grsec_enable_time,
65983+ .maxlen = sizeof(int),
65984+ .mode = 0600,
65985+ .proc_handler = &proc_dointvec,
65986+ },
65987+#endif
65988+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
65989+ {
65990+ .procname = "chroot_deny_shmat",
65991+ .data = &grsec_enable_chroot_shmat,
65992+ .maxlen = sizeof(int),
65993+ .mode = 0600,
65994+ .proc_handler = &proc_dointvec,
65995+ },
65996+#endif
65997+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
65998+ {
65999+ .procname = "chroot_deny_unix",
66000+ .data = &grsec_enable_chroot_unix,
66001+ .maxlen = sizeof(int),
66002+ .mode = 0600,
66003+ .proc_handler = &proc_dointvec,
66004+ },
66005+#endif
66006+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
66007+ {
66008+ .procname = "chroot_deny_mount",
66009+ .data = &grsec_enable_chroot_mount,
66010+ .maxlen = sizeof(int),
66011+ .mode = 0600,
66012+ .proc_handler = &proc_dointvec,
66013+ },
66014+#endif
66015+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
66016+ {
66017+ .procname = "chroot_deny_fchdir",
66018+ .data = &grsec_enable_chroot_fchdir,
66019+ .maxlen = sizeof(int),
66020+ .mode = 0600,
66021+ .proc_handler = &proc_dointvec,
66022+ },
66023+#endif
66024+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
66025+ {
66026+ .procname = "chroot_deny_chroot",
66027+ .data = &grsec_enable_chroot_double,
66028+ .maxlen = sizeof(int),
66029+ .mode = 0600,
66030+ .proc_handler = &proc_dointvec,
66031+ },
66032+#endif
66033+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
66034+ {
66035+ .procname = "chroot_deny_pivot",
66036+ .data = &grsec_enable_chroot_pivot,
66037+ .maxlen = sizeof(int),
66038+ .mode = 0600,
66039+ .proc_handler = &proc_dointvec,
66040+ },
66041+#endif
66042+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
66043+ {
66044+ .procname = "chroot_enforce_chdir",
66045+ .data = &grsec_enable_chroot_chdir,
66046+ .maxlen = sizeof(int),
66047+ .mode = 0600,
66048+ .proc_handler = &proc_dointvec,
66049+ },
66050+#endif
66051+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
66052+ {
66053+ .procname = "chroot_deny_chmod",
66054+ .data = &grsec_enable_chroot_chmod,
66055+ .maxlen = sizeof(int),
66056+ .mode = 0600,
66057+ .proc_handler = &proc_dointvec,
66058+ },
66059+#endif
66060+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
66061+ {
66062+ .procname = "chroot_deny_mknod",
66063+ .data = &grsec_enable_chroot_mknod,
66064+ .maxlen = sizeof(int),
66065+ .mode = 0600,
66066+ .proc_handler = &proc_dointvec,
66067+ },
66068+#endif
66069+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
66070+ {
66071+ .procname = "chroot_restrict_nice",
66072+ .data = &grsec_enable_chroot_nice,
66073+ .maxlen = sizeof(int),
66074+ .mode = 0600,
66075+ .proc_handler = &proc_dointvec,
66076+ },
66077+#endif
66078+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
66079+ {
66080+ .procname = "chroot_execlog",
66081+ .data = &grsec_enable_chroot_execlog,
66082+ .maxlen = sizeof(int),
66083+ .mode = 0600,
66084+ .proc_handler = &proc_dointvec,
66085+ },
66086+#endif
66087+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66088+ {
66089+ .procname = "chroot_caps",
66090+ .data = &grsec_enable_chroot_caps,
66091+ .maxlen = sizeof(int),
66092+ .mode = 0600,
66093+ .proc_handler = &proc_dointvec,
66094+ },
66095+#endif
66096+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
66097+ {
66098+ .procname = "chroot_deny_sysctl",
66099+ .data = &grsec_enable_chroot_sysctl,
66100+ .maxlen = sizeof(int),
66101+ .mode = 0600,
66102+ .proc_handler = &proc_dointvec,
66103+ },
66104+#endif
66105+#ifdef CONFIG_GRKERNSEC_TPE
66106+ {
66107+ .procname = "tpe",
66108+ .data = &grsec_enable_tpe,
66109+ .maxlen = sizeof(int),
66110+ .mode = 0600,
66111+ .proc_handler = &proc_dointvec,
66112+ },
66113+ {
66114+ .procname = "tpe_gid",
66115+ .data = &grsec_tpe_gid,
66116+ .maxlen = sizeof(int),
66117+ .mode = 0600,
66118+ .proc_handler = &proc_dointvec,
66119+ },
66120+#endif
66121+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
66122+ {
66123+ .procname = "tpe_invert",
66124+ .data = &grsec_enable_tpe_invert,
66125+ .maxlen = sizeof(int),
66126+ .mode = 0600,
66127+ .proc_handler = &proc_dointvec,
66128+ },
66129+#endif
66130+#ifdef CONFIG_GRKERNSEC_TPE_ALL
66131+ {
66132+ .procname = "tpe_restrict_all",
66133+ .data = &grsec_enable_tpe_all,
66134+ .maxlen = sizeof(int),
66135+ .mode = 0600,
66136+ .proc_handler = &proc_dointvec,
66137+ },
66138+#endif
66139+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
66140+ {
66141+ .procname = "socket_all",
66142+ .data = &grsec_enable_socket_all,
66143+ .maxlen = sizeof(int),
66144+ .mode = 0600,
66145+ .proc_handler = &proc_dointvec,
66146+ },
66147+ {
66148+ .procname = "socket_all_gid",
66149+ .data = &grsec_socket_all_gid,
66150+ .maxlen = sizeof(int),
66151+ .mode = 0600,
66152+ .proc_handler = &proc_dointvec,
66153+ },
66154+#endif
66155+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
66156+ {
66157+ .procname = "socket_client",
66158+ .data = &grsec_enable_socket_client,
66159+ .maxlen = sizeof(int),
66160+ .mode = 0600,
66161+ .proc_handler = &proc_dointvec,
66162+ },
66163+ {
66164+ .procname = "socket_client_gid",
66165+ .data = &grsec_socket_client_gid,
66166+ .maxlen = sizeof(int),
66167+ .mode = 0600,
66168+ .proc_handler = &proc_dointvec,
66169+ },
66170+#endif
66171+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66172+ {
66173+ .procname = "socket_server",
66174+ .data = &grsec_enable_socket_server,
66175+ .maxlen = sizeof(int),
66176+ .mode = 0600,
66177+ .proc_handler = &proc_dointvec,
66178+ },
66179+ {
66180+ .procname = "socket_server_gid",
66181+ .data = &grsec_socket_server_gid,
66182+ .maxlen = sizeof(int),
66183+ .mode = 0600,
66184+ .proc_handler = &proc_dointvec,
66185+ },
66186+#endif
66187+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
66188+ {
66189+ .procname = "audit_group",
66190+ .data = &grsec_enable_group,
66191+ .maxlen = sizeof(int),
66192+ .mode = 0600,
66193+ .proc_handler = &proc_dointvec,
66194+ },
66195+ {
66196+ .procname = "audit_gid",
66197+ .data = &grsec_audit_gid,
66198+ .maxlen = sizeof(int),
66199+ .mode = 0600,
66200+ .proc_handler = &proc_dointvec,
66201+ },
66202+#endif
66203+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
66204+ {
66205+ .procname = "audit_chdir",
66206+ .data = &grsec_enable_chdir,
66207+ .maxlen = sizeof(int),
66208+ .mode = 0600,
66209+ .proc_handler = &proc_dointvec,
66210+ },
66211+#endif
66212+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
66213+ {
66214+ .procname = "audit_mount",
66215+ .data = &grsec_enable_mount,
66216+ .maxlen = sizeof(int),
66217+ .mode = 0600,
66218+ .proc_handler = &proc_dointvec,
66219+ },
66220+#endif
66221+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
66222+ {
66223+ .procname = "audit_textrel",
66224+ .data = &grsec_enable_audit_textrel,
66225+ .maxlen = sizeof(int),
66226+ .mode = 0600,
66227+ .proc_handler = &proc_dointvec,
66228+ },
66229+#endif
66230+#ifdef CONFIG_GRKERNSEC_DMESG
66231+ {
66232+ .procname = "dmesg",
66233+ .data = &grsec_enable_dmesg,
66234+ .maxlen = sizeof(int),
66235+ .mode = 0600,
66236+ .proc_handler = &proc_dointvec,
66237+ },
66238+#endif
66239+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
66240+ {
66241+ .procname = "chroot_findtask",
66242+ .data = &grsec_enable_chroot_findtask,
66243+ .maxlen = sizeof(int),
66244+ .mode = 0600,
66245+ .proc_handler = &proc_dointvec,
66246+ },
66247+#endif
66248+#ifdef CONFIG_GRKERNSEC_RESLOG
66249+ {
66250+ .procname = "resource_logging",
66251+ .data = &grsec_resource_logging,
66252+ .maxlen = sizeof(int),
66253+ .mode = 0600,
66254+ .proc_handler = &proc_dointvec,
66255+ },
66256+#endif
66257+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
66258+ {
66259+ .procname = "audit_ptrace",
66260+ .data = &grsec_enable_audit_ptrace,
66261+ .maxlen = sizeof(int),
66262+ .mode = 0600,
66263+ .proc_handler = &proc_dointvec,
66264+ },
66265+#endif
66266+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
66267+ {
66268+ .procname = "harden_ptrace",
66269+ .data = &grsec_enable_harden_ptrace,
66270+ .maxlen = sizeof(int),
66271+ .mode = 0600,
66272+ .proc_handler = &proc_dointvec,
66273+ },
66274+#endif
66275+ {
66276+ .procname = "grsec_lock",
66277+ .data = &grsec_lock,
66278+ .maxlen = sizeof(int),
66279+ .mode = 0600,
66280+ .proc_handler = &proc_dointvec,
66281+ },
66282+#endif
66283+#ifdef CONFIG_GRKERNSEC_ROFS
66284+ {
66285+ .procname = "romount_protect",
66286+ .data = &grsec_enable_rofs,
66287+ .maxlen = sizeof(int),
66288+ .mode = 0600,
66289+ .proc_handler = &proc_dointvec_minmax,
66290+ .extra1 = &one,
66291+ .extra2 = &one,
66292+ },
66293+#endif
66294+ { }
66295+};
66296+#endif
66297diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
66298new file mode 100644
66299index 0000000..0dc13c3
66300--- /dev/null
66301+++ b/grsecurity/grsec_time.c
66302@@ -0,0 +1,16 @@
66303+#include <linux/kernel.h>
66304+#include <linux/sched.h>
66305+#include <linux/grinternal.h>
66306+#include <linux/module.h>
66307+
66308+void
66309+gr_log_timechange(void)
66310+{
66311+#ifdef CONFIG_GRKERNSEC_TIME
66312+ if (grsec_enable_time)
66313+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
66314+#endif
66315+ return;
66316+}
66317+
66318+EXPORT_SYMBOL(gr_log_timechange);
66319diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
66320new file mode 100644
66321index 0000000..ee57dcf
66322--- /dev/null
66323+++ b/grsecurity/grsec_tpe.c
66324@@ -0,0 +1,73 @@
66325+#include <linux/kernel.h>
66326+#include <linux/sched.h>
66327+#include <linux/file.h>
66328+#include <linux/fs.h>
66329+#include <linux/grinternal.h>
66330+
66331+extern int gr_acl_tpe_check(void);
66332+
66333+int
66334+gr_tpe_allow(const struct file *file)
66335+{
66336+#ifdef CONFIG_GRKERNSEC
66337+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
66338+ const struct cred *cred = current_cred();
66339+ char *msg = NULL;
66340+ char *msg2 = NULL;
66341+
66342+ // never restrict root
66343+ if (gr_is_global_root(cred->uid))
66344+ return 1;
66345+
66346+ if (grsec_enable_tpe) {
66347+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
66348+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
66349+ msg = "not being in trusted group";
66350+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
66351+ msg = "being in untrusted group";
66352+#else
66353+ if (in_group_p(grsec_tpe_gid))
66354+ msg = "being in untrusted group";
66355+#endif
66356+ }
66357+ if (!msg && gr_acl_tpe_check())
66358+ msg = "being in untrusted role";
66359+
66360+ // not in any affected group/role
66361+ if (!msg)
66362+ goto next_check;
66363+
66364+ if (gr_is_global_nonroot(inode->i_uid))
66365+ msg2 = "file in non-root-owned directory";
66366+ else if (inode->i_mode & S_IWOTH)
66367+ msg2 = "file in world-writable directory";
66368+ else if (inode->i_mode & S_IWGRP)
66369+ msg2 = "file in group-writable directory";
66370+
66371+ if (msg && msg2) {
66372+ char fullmsg[70] = {0};
66373+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
66374+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
66375+ return 0;
66376+ }
66377+ msg = NULL;
66378+next_check:
66379+#ifdef CONFIG_GRKERNSEC_TPE_ALL
66380+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
66381+ return 1;
66382+
66383+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
66384+ msg = "directory not owned by user";
66385+ else if (inode->i_mode & S_IWOTH)
66386+ msg = "file in world-writable directory";
66387+ else if (inode->i_mode & S_IWGRP)
66388+ msg = "file in group-writable directory";
66389+
66390+ if (msg) {
66391+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
66392+ return 0;
66393+ }
66394+#endif
66395+#endif
66396+ return 1;
66397+}
66398diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
66399new file mode 100644
66400index 0000000..9f7b1ac
66401--- /dev/null
66402+++ b/grsecurity/grsum.c
66403@@ -0,0 +1,61 @@
66404+#include <linux/err.h>
66405+#include <linux/kernel.h>
66406+#include <linux/sched.h>
66407+#include <linux/mm.h>
66408+#include <linux/scatterlist.h>
66409+#include <linux/crypto.h>
66410+#include <linux/gracl.h>
66411+
66412+
66413+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
66414+#error "crypto and sha256 must be built into the kernel"
66415+#endif
66416+
66417+int
66418+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
66419+{
66420+ char *p;
66421+ struct crypto_hash *tfm;
66422+ struct hash_desc desc;
66423+ struct scatterlist sg;
66424+ unsigned char temp_sum[GR_SHA_LEN];
66425+ volatile int retval = 0;
66426+ volatile int dummy = 0;
66427+ unsigned int i;
66428+
66429+ sg_init_table(&sg, 1);
66430+
66431+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
66432+ if (IS_ERR(tfm)) {
66433+ /* should never happen, since sha256 should be built in */
66434+ return 1;
66435+ }
66436+
66437+ desc.tfm = tfm;
66438+ desc.flags = 0;
66439+
66440+ crypto_hash_init(&desc);
66441+
66442+ p = salt;
66443+ sg_set_buf(&sg, p, GR_SALT_LEN);
66444+ crypto_hash_update(&desc, &sg, sg.length);
66445+
66446+ p = entry->pw;
66447+ sg_set_buf(&sg, p, strlen(p));
66448+
66449+ crypto_hash_update(&desc, &sg, sg.length);
66450+
66451+ crypto_hash_final(&desc, temp_sum);
66452+
66453+ memset(entry->pw, 0, GR_PW_LEN);
66454+
66455+ for (i = 0; i < GR_SHA_LEN; i++)
66456+ if (sum[i] != temp_sum[i])
66457+ retval = 1;
66458+ else
66459+ dummy = 1; // waste a cycle
66460+
66461+ crypto_free_hash(tfm);
66462+
66463+ return retval;
66464+}
66465diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
66466index 77ff547..181834f 100644
66467--- a/include/asm-generic/4level-fixup.h
66468+++ b/include/asm-generic/4level-fixup.h
66469@@ -13,8 +13,10 @@
66470 #define pmd_alloc(mm, pud, address) \
66471 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
66472 NULL: pmd_offset(pud, address))
66473+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
66474
66475 #define pud_alloc(mm, pgd, address) (pgd)
66476+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
66477 #define pud_offset(pgd, start) (pgd)
66478 #define pud_none(pud) 0
66479 #define pud_bad(pud) 0
66480diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
66481index b7babf0..04ad282 100644
66482--- a/include/asm-generic/atomic-long.h
66483+++ b/include/asm-generic/atomic-long.h
66484@@ -22,6 +22,12 @@
66485
66486 typedef atomic64_t atomic_long_t;
66487
66488+#ifdef CONFIG_PAX_REFCOUNT
66489+typedef atomic64_unchecked_t atomic_long_unchecked_t;
66490+#else
66491+typedef atomic64_t atomic_long_unchecked_t;
66492+#endif
66493+
66494 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
66495
66496 static inline long atomic_long_read(atomic_long_t *l)
66497@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
66498 return (long)atomic64_read(v);
66499 }
66500
66501+#ifdef CONFIG_PAX_REFCOUNT
66502+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
66503+{
66504+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66505+
66506+ return (long)atomic64_read_unchecked(v);
66507+}
66508+#endif
66509+
66510 static inline void atomic_long_set(atomic_long_t *l, long i)
66511 {
66512 atomic64_t *v = (atomic64_t *)l;
66513@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
66514 atomic64_set(v, i);
66515 }
66516
66517+#ifdef CONFIG_PAX_REFCOUNT
66518+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
66519+{
66520+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66521+
66522+ atomic64_set_unchecked(v, i);
66523+}
66524+#endif
66525+
66526 static inline void atomic_long_inc(atomic_long_t *l)
66527 {
66528 atomic64_t *v = (atomic64_t *)l;
66529@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
66530 atomic64_inc(v);
66531 }
66532
66533+#ifdef CONFIG_PAX_REFCOUNT
66534+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
66535+{
66536+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66537+
66538+ atomic64_inc_unchecked(v);
66539+}
66540+#endif
66541+
66542 static inline void atomic_long_dec(atomic_long_t *l)
66543 {
66544 atomic64_t *v = (atomic64_t *)l;
66545@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
66546 atomic64_dec(v);
66547 }
66548
66549+#ifdef CONFIG_PAX_REFCOUNT
66550+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
66551+{
66552+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66553+
66554+ atomic64_dec_unchecked(v);
66555+}
66556+#endif
66557+
66558 static inline void atomic_long_add(long i, atomic_long_t *l)
66559 {
66560 atomic64_t *v = (atomic64_t *)l;
66561@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
66562 atomic64_add(i, v);
66563 }
66564
66565+#ifdef CONFIG_PAX_REFCOUNT
66566+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
66567+{
66568+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66569+
66570+ atomic64_add_unchecked(i, v);
66571+}
66572+#endif
66573+
66574 static inline void atomic_long_sub(long i, atomic_long_t *l)
66575 {
66576 atomic64_t *v = (atomic64_t *)l;
66577@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
66578 atomic64_sub(i, v);
66579 }
66580
66581+#ifdef CONFIG_PAX_REFCOUNT
66582+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
66583+{
66584+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66585+
66586+ atomic64_sub_unchecked(i, v);
66587+}
66588+#endif
66589+
66590 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
66591 {
66592 atomic64_t *v = (atomic64_t *)l;
66593@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
66594 return (long)atomic64_add_return(i, v);
66595 }
66596
66597+#ifdef CONFIG_PAX_REFCOUNT
66598+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
66599+{
66600+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66601+
66602+ return (long)atomic64_add_return_unchecked(i, v);
66603+}
66604+#endif
66605+
66606 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
66607 {
66608 atomic64_t *v = (atomic64_t *)l;
66609@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
66610 return (long)atomic64_inc_return(v);
66611 }
66612
66613+#ifdef CONFIG_PAX_REFCOUNT
66614+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
66615+{
66616+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66617+
66618+ return (long)atomic64_inc_return_unchecked(v);
66619+}
66620+#endif
66621+
66622 static inline long atomic_long_dec_return(atomic_long_t *l)
66623 {
66624 atomic64_t *v = (atomic64_t *)l;
66625@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
66626
66627 typedef atomic_t atomic_long_t;
66628
66629+#ifdef CONFIG_PAX_REFCOUNT
66630+typedef atomic_unchecked_t atomic_long_unchecked_t;
66631+#else
66632+typedef atomic_t atomic_long_unchecked_t;
66633+#endif
66634+
66635 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
66636 static inline long atomic_long_read(atomic_long_t *l)
66637 {
66638@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
66639 return (long)atomic_read(v);
66640 }
66641
66642+#ifdef CONFIG_PAX_REFCOUNT
66643+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
66644+{
66645+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66646+
66647+ return (long)atomic_read_unchecked(v);
66648+}
66649+#endif
66650+
66651 static inline void atomic_long_set(atomic_long_t *l, long i)
66652 {
66653 atomic_t *v = (atomic_t *)l;
66654@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
66655 atomic_set(v, i);
66656 }
66657
66658+#ifdef CONFIG_PAX_REFCOUNT
66659+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
66660+{
66661+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66662+
66663+ atomic_set_unchecked(v, i);
66664+}
66665+#endif
66666+
66667 static inline void atomic_long_inc(atomic_long_t *l)
66668 {
66669 atomic_t *v = (atomic_t *)l;
66670@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
66671 atomic_inc(v);
66672 }
66673
66674+#ifdef CONFIG_PAX_REFCOUNT
66675+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
66676+{
66677+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66678+
66679+ atomic_inc_unchecked(v);
66680+}
66681+#endif
66682+
66683 static inline void atomic_long_dec(atomic_long_t *l)
66684 {
66685 atomic_t *v = (atomic_t *)l;
66686@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
66687 atomic_dec(v);
66688 }
66689
66690+#ifdef CONFIG_PAX_REFCOUNT
66691+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
66692+{
66693+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66694+
66695+ atomic_dec_unchecked(v);
66696+}
66697+#endif
66698+
66699 static inline void atomic_long_add(long i, atomic_long_t *l)
66700 {
66701 atomic_t *v = (atomic_t *)l;
66702@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
66703 atomic_add(i, v);
66704 }
66705
66706+#ifdef CONFIG_PAX_REFCOUNT
66707+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
66708+{
66709+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66710+
66711+ atomic_add_unchecked(i, v);
66712+}
66713+#endif
66714+
66715 static inline void atomic_long_sub(long i, atomic_long_t *l)
66716 {
66717 atomic_t *v = (atomic_t *)l;
66718@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
66719 atomic_sub(i, v);
66720 }
66721
66722+#ifdef CONFIG_PAX_REFCOUNT
66723+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
66724+{
66725+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66726+
66727+ atomic_sub_unchecked(i, v);
66728+}
66729+#endif
66730+
66731 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
66732 {
66733 atomic_t *v = (atomic_t *)l;
66734@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
66735 return (long)atomic_add_return(i, v);
66736 }
66737
66738+#ifdef CONFIG_PAX_REFCOUNT
66739+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
66740+{
66741+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66742+
66743+ return (long)atomic_add_return_unchecked(i, v);
66744+}
66745+
66746+#endif
66747+
66748 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
66749 {
66750 atomic_t *v = (atomic_t *)l;
66751@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
66752 return (long)atomic_inc_return(v);
66753 }
66754
66755+#ifdef CONFIG_PAX_REFCOUNT
66756+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
66757+{
66758+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66759+
66760+ return (long)atomic_inc_return_unchecked(v);
66761+}
66762+#endif
66763+
66764 static inline long atomic_long_dec_return(atomic_long_t *l)
66765 {
66766 atomic_t *v = (atomic_t *)l;
66767@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
66768
66769 #endif /* BITS_PER_LONG == 64 */
66770
66771+#ifdef CONFIG_PAX_REFCOUNT
66772+static inline void pax_refcount_needs_these_functions(void)
66773+{
66774+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
66775+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
66776+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
66777+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
66778+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
66779+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
66780+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
66781+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
66782+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
66783+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
66784+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
66785+#ifdef CONFIG_X86
66786+ atomic_clear_mask_unchecked(0, NULL);
66787+ atomic_set_mask_unchecked(0, NULL);
66788+#endif
66789+
66790+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
66791+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
66792+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
66793+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
66794+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
66795+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
66796+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
66797+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
66798+}
66799+#else
66800+#define atomic_read_unchecked(v) atomic_read(v)
66801+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
66802+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
66803+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
66804+#define atomic_inc_unchecked(v) atomic_inc(v)
66805+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
66806+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
66807+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
66808+#define atomic_dec_unchecked(v) atomic_dec(v)
66809+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
66810+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
66811+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
66812+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
66813+
66814+#define atomic_long_read_unchecked(v) atomic_long_read(v)
66815+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
66816+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
66817+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
66818+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
66819+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
66820+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
66821+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
66822+#endif
66823+
66824 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
66825diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
66826index 33bd2de..f31bff97 100644
66827--- a/include/asm-generic/atomic.h
66828+++ b/include/asm-generic/atomic.h
66829@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
66830 * Atomically clears the bits set in @mask from @v
66831 */
66832 #ifndef atomic_clear_mask
66833-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
66834+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
66835 {
66836 unsigned long flags;
66837
66838diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
66839index b18ce4f..2ee2843 100644
66840--- a/include/asm-generic/atomic64.h
66841+++ b/include/asm-generic/atomic64.h
66842@@ -16,6 +16,8 @@ typedef struct {
66843 long long counter;
66844 } atomic64_t;
66845
66846+typedef atomic64_t atomic64_unchecked_t;
66847+
66848 #define ATOMIC64_INIT(i) { (i) }
66849
66850 extern long long atomic64_read(const atomic64_t *v);
66851@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
66852 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
66853 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
66854
66855+#define atomic64_read_unchecked(v) atomic64_read(v)
66856+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
66857+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
66858+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
66859+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
66860+#define atomic64_inc_unchecked(v) atomic64_inc(v)
66861+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
66862+#define atomic64_dec_unchecked(v) atomic64_dec(v)
66863+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
66864+
66865 #endif /* _ASM_GENERIC_ATOMIC64_H */
66866diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
66867index 1bfcfe5..e04c5c9 100644
66868--- a/include/asm-generic/cache.h
66869+++ b/include/asm-generic/cache.h
66870@@ -6,7 +6,7 @@
66871 * cache lines need to provide their own cache.h.
66872 */
66873
66874-#define L1_CACHE_SHIFT 5
66875-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
66876+#define L1_CACHE_SHIFT 5UL
66877+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
66878
66879 #endif /* __ASM_GENERIC_CACHE_H */
66880diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
66881index 0d68a1e..b74a761 100644
66882--- a/include/asm-generic/emergency-restart.h
66883+++ b/include/asm-generic/emergency-restart.h
66884@@ -1,7 +1,7 @@
66885 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
66886 #define _ASM_GENERIC_EMERGENCY_RESTART_H
66887
66888-static inline void machine_emergency_restart(void)
66889+static inline __noreturn void machine_emergency_restart(void)
66890 {
66891 machine_restart(NULL);
66892 }
66893diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
66894index 90f99c7..00ce236 100644
66895--- a/include/asm-generic/kmap_types.h
66896+++ b/include/asm-generic/kmap_types.h
66897@@ -2,9 +2,9 @@
66898 #define _ASM_GENERIC_KMAP_TYPES_H
66899
66900 #ifdef __WITH_KM_FENCE
66901-# define KM_TYPE_NR 41
66902+# define KM_TYPE_NR 42
66903 #else
66904-# define KM_TYPE_NR 20
66905+# define KM_TYPE_NR 21
66906 #endif
66907
66908 #endif
66909diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
66910index 9ceb03b..62b0b8f 100644
66911--- a/include/asm-generic/local.h
66912+++ b/include/asm-generic/local.h
66913@@ -23,24 +23,37 @@ typedef struct
66914 atomic_long_t a;
66915 } local_t;
66916
66917+typedef struct {
66918+ atomic_long_unchecked_t a;
66919+} local_unchecked_t;
66920+
66921 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
66922
66923 #define local_read(l) atomic_long_read(&(l)->a)
66924+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
66925 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
66926+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
66927 #define local_inc(l) atomic_long_inc(&(l)->a)
66928+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
66929 #define local_dec(l) atomic_long_dec(&(l)->a)
66930+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
66931 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
66932+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
66933 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
66934+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
66935
66936 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
66937 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
66938 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
66939 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
66940 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
66941+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
66942 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
66943 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
66944+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
66945
66946 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
66947+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
66948 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
66949 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
66950 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
66951diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
66952index 725612b..9cc513a 100644
66953--- a/include/asm-generic/pgtable-nopmd.h
66954+++ b/include/asm-generic/pgtable-nopmd.h
66955@@ -1,14 +1,19 @@
66956 #ifndef _PGTABLE_NOPMD_H
66957 #define _PGTABLE_NOPMD_H
66958
66959-#ifndef __ASSEMBLY__
66960-
66961 #include <asm-generic/pgtable-nopud.h>
66962
66963-struct mm_struct;
66964-
66965 #define __PAGETABLE_PMD_FOLDED
66966
66967+#define PMD_SHIFT PUD_SHIFT
66968+#define PTRS_PER_PMD 1
66969+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
66970+#define PMD_MASK (~(PMD_SIZE-1))
66971+
66972+#ifndef __ASSEMBLY__
66973+
66974+struct mm_struct;
66975+
66976 /*
66977 * Having the pmd type consist of a pud gets the size right, and allows
66978 * us to conceptually access the pud entry that this pmd is folded into
66979@@ -16,11 +21,6 @@ struct mm_struct;
66980 */
66981 typedef struct { pud_t pud; } pmd_t;
66982
66983-#define PMD_SHIFT PUD_SHIFT
66984-#define PTRS_PER_PMD 1
66985-#define PMD_SIZE (1UL << PMD_SHIFT)
66986-#define PMD_MASK (~(PMD_SIZE-1))
66987-
66988 /*
66989 * The "pud_xxx()" functions here are trivial for a folded two-level
66990 * setup: the pmd is never bad, and a pmd always exists (as it's folded
66991diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
66992index 810431d..0ec4804f 100644
66993--- a/include/asm-generic/pgtable-nopud.h
66994+++ b/include/asm-generic/pgtable-nopud.h
66995@@ -1,10 +1,15 @@
66996 #ifndef _PGTABLE_NOPUD_H
66997 #define _PGTABLE_NOPUD_H
66998
66999-#ifndef __ASSEMBLY__
67000-
67001 #define __PAGETABLE_PUD_FOLDED
67002
67003+#define PUD_SHIFT PGDIR_SHIFT
67004+#define PTRS_PER_PUD 1
67005+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
67006+#define PUD_MASK (~(PUD_SIZE-1))
67007+
67008+#ifndef __ASSEMBLY__
67009+
67010 /*
67011 * Having the pud type consist of a pgd gets the size right, and allows
67012 * us to conceptually access the pgd entry that this pud is folded into
67013@@ -12,11 +17,6 @@
67014 */
67015 typedef struct { pgd_t pgd; } pud_t;
67016
67017-#define PUD_SHIFT PGDIR_SHIFT
67018-#define PTRS_PER_PUD 1
67019-#define PUD_SIZE (1UL << PUD_SHIFT)
67020-#define PUD_MASK (~(PUD_SIZE-1))
67021-
67022 /*
67023 * The "pgd_xxx()" functions here are trivial for a folded two-level
67024 * setup: the pud is never bad, and a pud always exists (as it's folded
67025@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
67026 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
67027
67028 #define pgd_populate(mm, pgd, pud) do { } while (0)
67029+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
67030 /*
67031 * (puds are folded into pgds so this doesn't get actually called,
67032 * but the define is needed for a generic inline function.)
67033diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
67034index a59ff51..2594a70 100644
67035--- a/include/asm-generic/pgtable.h
67036+++ b/include/asm-generic/pgtable.h
67037@@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
67038 }
67039 #endif /* CONFIG_NUMA_BALANCING */
67040
67041+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
67042+static inline unsigned long pax_open_kernel(void) { return 0; }
67043+#endif
67044+
67045+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
67046+static inline unsigned long pax_close_kernel(void) { return 0; }
67047+#endif
67048+
67049 #endif /* CONFIG_MMU */
67050
67051 #endif /* !__ASSEMBLY__ */
67052diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
67053index afa12c7..99d4da0 100644
67054--- a/include/asm-generic/vmlinux.lds.h
67055+++ b/include/asm-generic/vmlinux.lds.h
67056@@ -245,6 +245,7 @@
67057 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
67058 VMLINUX_SYMBOL(__start_rodata) = .; \
67059 *(.rodata) *(.rodata.*) \
67060+ *(.data..read_only) \
67061 *(__vermagic) /* Kernel version magic */ \
67062 . = ALIGN(8); \
67063 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
67064@@ -755,17 +756,18 @@
67065 * section in the linker script will go there too. @phdr should have
67066 * a leading colon.
67067 *
67068- * Note that this macros defines __per_cpu_load as an absolute symbol.
67069+ * Note that this macros defines per_cpu_load as an absolute symbol.
67070 * If there is no need to put the percpu section at a predetermined
67071 * address, use PERCPU_SECTION.
67072 */
67073 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
67074- VMLINUX_SYMBOL(__per_cpu_load) = .; \
67075- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
67076+ per_cpu_load = .; \
67077+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
67078 - LOAD_OFFSET) { \
67079+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
67080 PERCPU_INPUT(cacheline) \
67081 } phdr \
67082- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
67083+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
67084
67085 /**
67086 * PERCPU_SECTION - define output section for percpu area, simple version
67087diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
67088index 418d270..bfd2794 100644
67089--- a/include/crypto/algapi.h
67090+++ b/include/crypto/algapi.h
67091@@ -34,7 +34,7 @@ struct crypto_type {
67092 unsigned int maskclear;
67093 unsigned int maskset;
67094 unsigned int tfmsize;
67095-};
67096+} __do_const;
67097
67098 struct crypto_instance {
67099 struct crypto_alg alg;
67100diff --git a/include/drm/drmP.h b/include/drm/drmP.h
67101index f1ce786..086a7a5 100644
67102--- a/include/drm/drmP.h
67103+++ b/include/drm/drmP.h
67104@@ -72,6 +72,7 @@
67105 #include <linux/workqueue.h>
67106 #include <linux/poll.h>
67107 #include <asm/pgalloc.h>
67108+#include <asm/local.h>
67109 #include <drm/drm.h>
67110 #include <drm/drm_sarea.h>
67111
67112@@ -296,10 +297,12 @@ do { \
67113 * \param cmd command.
67114 * \param arg argument.
67115 */
67116-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
67117+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
67118+ struct drm_file *file_priv);
67119+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
67120 struct drm_file *file_priv);
67121
67122-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
67123+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
67124 unsigned long arg);
67125
67126 #define DRM_IOCTL_NR(n) _IOC_NR(n)
67127@@ -314,9 +317,9 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
67128 struct drm_ioctl_desc {
67129 unsigned int cmd;
67130 int flags;
67131- drm_ioctl_t *func;
67132+ drm_ioctl_t func;
67133 unsigned int cmd_drv;
67134-};
67135+} __do_const;
67136
67137 /**
67138 * Creates a driver or general drm_ioctl_desc array entry for the given
67139@@ -1014,7 +1017,7 @@ struct drm_info_list {
67140 int (*show)(struct seq_file*, void*); /** show callback */
67141 u32 driver_features; /**< Required driver features for this entry */
67142 void *data;
67143-};
67144+} __do_const;
67145
67146 /**
67147 * debugfs node structure. This structure represents a debugfs file.
67148@@ -1087,7 +1090,7 @@ struct drm_device {
67149
67150 /** \name Usage Counters */
67151 /*@{ */
67152- int open_count; /**< Outstanding files open */
67153+ local_t open_count; /**< Outstanding files open */
67154 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
67155 atomic_t vma_count; /**< Outstanding vma areas open */
67156 int buf_use; /**< Buffers in use -- cannot alloc */
67157@@ -1098,7 +1101,7 @@ struct drm_device {
67158 /*@{ */
67159 unsigned long counters;
67160 enum drm_stat_type types[15];
67161- atomic_t counts[15];
67162+ atomic_unchecked_t counts[15];
67163 /*@} */
67164
67165 struct list_head filelist;
67166diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
67167index f43d556..94d9343 100644
67168--- a/include/drm/drm_crtc_helper.h
67169+++ b/include/drm/drm_crtc_helper.h
67170@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
67171 struct drm_connector *connector);
67172 /* disable encoder when not in use - more explicit than dpms off */
67173 void (*disable)(struct drm_encoder *encoder);
67174-};
67175+} __no_const;
67176
67177 /**
67178 * drm_connector_helper_funcs - helper operations for connectors
67179diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
67180index 72dcbe8..8db58d7 100644
67181--- a/include/drm/ttm/ttm_memory.h
67182+++ b/include/drm/ttm/ttm_memory.h
67183@@ -48,7 +48,7 @@
67184
67185 struct ttm_mem_shrink {
67186 int (*do_shrink) (struct ttm_mem_shrink *);
67187-};
67188+} __no_const;
67189
67190 /**
67191 * struct ttm_mem_global - Global memory accounting structure.
67192diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
67193index 4b840e8..155d235 100644
67194--- a/include/keys/asymmetric-subtype.h
67195+++ b/include/keys/asymmetric-subtype.h
67196@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
67197 /* Verify the signature on a key of this subtype (optional) */
67198 int (*verify_signature)(const struct key *key,
67199 const struct public_key_signature *sig);
67200-};
67201+} __do_const;
67202
67203 /**
67204 * asymmetric_key_subtype - Get the subtype from an asymmetric key
67205diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
67206index c1da539..1dcec55 100644
67207--- a/include/linux/atmdev.h
67208+++ b/include/linux/atmdev.h
67209@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
67210 #endif
67211
67212 struct k_atm_aal_stats {
67213-#define __HANDLE_ITEM(i) atomic_t i
67214+#define __HANDLE_ITEM(i) atomic_unchecked_t i
67215 __AAL_STAT_ITEMS
67216 #undef __HANDLE_ITEM
67217 };
67218@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
67219 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
67220 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
67221 struct module *owner;
67222-};
67223+} __do_const ;
67224
67225 struct atmphy_ops {
67226 int (*start)(struct atm_dev *dev);
67227diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
67228index c3a0914..ec5d48a 100644
67229--- a/include/linux/binfmts.h
67230+++ b/include/linux/binfmts.h
67231@@ -73,8 +73,9 @@ struct linux_binfmt {
67232 int (*load_binary)(struct linux_binprm *);
67233 int (*load_shlib)(struct file *);
67234 int (*core_dump)(struct coredump_params *cprm);
67235+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
67236 unsigned long min_coredump; /* minimal dump size */
67237-};
67238+} __do_const;
67239
67240 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
67241
67242diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
67243index 33f358f..7f2c27f 100644
67244--- a/include/linux/blkdev.h
67245+++ b/include/linux/blkdev.h
67246@@ -1499,7 +1499,7 @@ struct block_device_operations {
67247 /* this callback is with swap_lock and sometimes page table lock held */
67248 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
67249 struct module *owner;
67250-};
67251+} __do_const;
67252
67253 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
67254 unsigned long);
67255diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
67256index 7c2e030..b72475d 100644
67257--- a/include/linux/blktrace_api.h
67258+++ b/include/linux/blktrace_api.h
67259@@ -23,7 +23,7 @@ struct blk_trace {
67260 struct dentry *dir;
67261 struct dentry *dropped_file;
67262 struct dentry *msg_file;
67263- atomic_t dropped;
67264+ atomic_unchecked_t dropped;
67265 };
67266
67267 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
67268diff --git a/include/linux/cache.h b/include/linux/cache.h
67269index 4c57065..4307975 100644
67270--- a/include/linux/cache.h
67271+++ b/include/linux/cache.h
67272@@ -16,6 +16,10 @@
67273 #define __read_mostly
67274 #endif
67275
67276+#ifndef __read_only
67277+#define __read_only __read_mostly
67278+#endif
67279+
67280 #ifndef ____cacheline_aligned
67281 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
67282 #endif
67283diff --git a/include/linux/capability.h b/include/linux/capability.h
67284index d9a4f7f4..19f77d6 100644
67285--- a/include/linux/capability.h
67286+++ b/include/linux/capability.h
67287@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
67288 extern bool nsown_capable(int cap);
67289 extern bool inode_capable(const struct inode *inode, int cap);
67290 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
67291+extern bool capable_nolog(int cap);
67292+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
67293+extern bool inode_capable_nolog(const struct inode *inode, int cap);
67294
67295 /* audit system wants to get cap info from files as well */
67296 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
67297
67298+extern int is_privileged_binary(const struct dentry *dentry);
67299+
67300 #endif /* !_LINUX_CAPABILITY_H */
67301diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
67302index 8609d57..86e4d79 100644
67303--- a/include/linux/cdrom.h
67304+++ b/include/linux/cdrom.h
67305@@ -87,7 +87,6 @@ struct cdrom_device_ops {
67306
67307 /* driver specifications */
67308 const int capability; /* capability flags */
67309- int n_minors; /* number of active minor devices */
67310 /* handle uniform packets for scsi type devices (scsi,atapi) */
67311 int (*generic_packet) (struct cdrom_device_info *,
67312 struct packet_command *);
67313diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
67314index 42e55de..1cd0e66 100644
67315--- a/include/linux/cleancache.h
67316+++ b/include/linux/cleancache.h
67317@@ -31,7 +31,7 @@ struct cleancache_ops {
67318 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
67319 void (*invalidate_inode)(int, struct cleancache_filekey);
67320 void (*invalidate_fs)(int);
67321-};
67322+} __no_const;
67323
67324 extern struct cleancache_ops
67325 cleancache_register_ops(struct cleancache_ops *ops);
67326diff --git a/include/linux/compat.h b/include/linux/compat.h
67327index 377cd8c..2479845 100644
67328--- a/include/linux/compat.h
67329+++ b/include/linux/compat.h
67330@@ -332,14 +332,14 @@ long compat_sys_msgsnd(int first, int second, int third, void __user *uptr);
67331 long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
67332 int version, void __user *uptr);
67333 long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
67334- void __user *uptr);
67335+ void __user *uptr) __intentional_overflow(0);
67336 #else
67337 long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
67338 long compat_sys_msgsnd(int msqid, struct compat_msgbuf __user *msgp,
67339 compat_ssize_t msgsz, int msgflg);
67340 long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp,
67341 compat_ssize_t msgsz, long msgtyp, int msgflg);
67342-long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
67343+long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
67344 #endif
67345 long compat_sys_msgctl(int first, int second, void __user *uptr);
67346 long compat_sys_shmctl(int first, int second, void __user *uptr);
67347@@ -442,7 +442,7 @@ extern int compat_ptrace_request(struct task_struct *child,
67348 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
67349 compat_ulong_t addr, compat_ulong_t data);
67350 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
67351- compat_long_t addr, compat_long_t data);
67352+ compat_ulong_t addr, compat_ulong_t data);
67353
67354 /*
67355 * epoll (fs/eventpoll.c) compat bits follow ...
67356diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
67357index 68b162d..660f5f0 100644
67358--- a/include/linux/compiler-gcc4.h
67359+++ b/include/linux/compiler-gcc4.h
67360@@ -39,9 +39,29 @@
67361 # define __compiletime_warning(message) __attribute__((warning(message)))
67362 # define __compiletime_error(message) __attribute__((error(message)))
67363 #endif /* __CHECKER__ */
67364+
67365+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
67366+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
67367+#define __bos0(ptr) __bos((ptr), 0)
67368+#define __bos1(ptr) __bos((ptr), 1)
67369 #endif /* GCC_VERSION >= 40300 */
67370
67371 #if GCC_VERSION >= 40500
67372+
67373+#ifdef CONSTIFY_PLUGIN
67374+#define __no_const __attribute__((no_const))
67375+#define __do_const __attribute__((do_const))
67376+#endif
67377+
67378+#ifdef SIZE_OVERFLOW_PLUGIN
67379+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
67380+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
67381+#endif
67382+
67383+#ifdef LATENT_ENTROPY_PLUGIN
67384+#define __latent_entropy __attribute__((latent_entropy))
67385+#endif
67386+
67387 /*
67388 * Mark a position in code as unreachable. This can be used to
67389 * suppress control flow warnings after asm blocks that transfer
67390diff --git a/include/linux/compiler.h b/include/linux/compiler.h
67391index 10b8f23..5e0b083 100644
67392--- a/include/linux/compiler.h
67393+++ b/include/linux/compiler.h
67394@@ -5,11 +5,14 @@
67395
67396 #ifdef __CHECKER__
67397 # define __user __attribute__((noderef, address_space(1)))
67398+# define __force_user __force __user
67399 # define __kernel __attribute__((address_space(0)))
67400+# define __force_kernel __force __kernel
67401 # define __safe __attribute__((safe))
67402 # define __force __attribute__((force))
67403 # define __nocast __attribute__((nocast))
67404 # define __iomem __attribute__((noderef, address_space(2)))
67405+# define __force_iomem __force __iomem
67406 # define __must_hold(x) __attribute__((context(x,1,1)))
67407 # define __acquires(x) __attribute__((context(x,0,1)))
67408 # define __releases(x) __attribute__((context(x,1,0)))
67409@@ -17,20 +20,37 @@
67410 # define __release(x) __context__(x,-1)
67411 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
67412 # define __percpu __attribute__((noderef, address_space(3)))
67413+# define __force_percpu __force __percpu
67414 #ifdef CONFIG_SPARSE_RCU_POINTER
67415 # define __rcu __attribute__((noderef, address_space(4)))
67416+# define __force_rcu __force __rcu
67417 #else
67418 # define __rcu
67419+# define __force_rcu
67420 #endif
67421 extern void __chk_user_ptr(const volatile void __user *);
67422 extern void __chk_io_ptr(const volatile void __iomem *);
67423 #else
67424-# define __user
67425-# define __kernel
67426+# ifdef CHECKER_PLUGIN
67427+//# define __user
67428+//# define __force_user
67429+//# define __kernel
67430+//# define __force_kernel
67431+# else
67432+# ifdef STRUCTLEAK_PLUGIN
67433+# define __user __attribute__((user))
67434+# else
67435+# define __user
67436+# endif
67437+# define __force_user
67438+# define __kernel
67439+# define __force_kernel
67440+# endif
67441 # define __safe
67442 # define __force
67443 # define __nocast
67444 # define __iomem
67445+# define __force_iomem
67446 # define __chk_user_ptr(x) (void)0
67447 # define __chk_io_ptr(x) (void)0
67448 # define __builtin_warning(x, y...) (1)
67449@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
67450 # define __release(x) (void)0
67451 # define __cond_lock(x,c) (c)
67452 # define __percpu
67453+# define __force_percpu
67454 # define __rcu
67455+# define __force_rcu
67456 #endif
67457
67458 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
67459@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
67460 # define __attribute_const__ /* unimplemented */
67461 #endif
67462
67463+#ifndef __no_const
67464+# define __no_const
67465+#endif
67466+
67467+#ifndef __do_const
67468+# define __do_const
67469+#endif
67470+
67471+#ifndef __size_overflow
67472+# define __size_overflow(...)
67473+#endif
67474+
67475+#ifndef __intentional_overflow
67476+# define __intentional_overflow(...)
67477+#endif
67478+
67479+#ifndef __latent_entropy
67480+# define __latent_entropy
67481+#endif
67482+
67483 /*
67484 * Tell gcc if a function is cold. The compiler will assume any path
67485 * directly leading to the call is unlikely.
67486@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
67487 #define __cold
67488 #endif
67489
67490+#ifndef __alloc_size
67491+#define __alloc_size(...)
67492+#endif
67493+
67494+#ifndef __bos
67495+#define __bos(ptr, arg)
67496+#endif
67497+
67498+#ifndef __bos0
67499+#define __bos0(ptr)
67500+#endif
67501+
67502+#ifndef __bos1
67503+#define __bos1(ptr)
67504+#endif
67505+
67506 /* Simple shorthand for a section definition */
67507 #ifndef __section
67508 # define __section(S) __attribute__ ((__section__(#S)))
67509@@ -349,6 +407,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
67510 * use is to mediate communication between process-level code and irq/NMI
67511 * handlers, all running on the same CPU.
67512 */
67513-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
67514+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
67515+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
67516
67517 #endif /* __LINUX_COMPILER_H */
67518diff --git a/include/linux/completion.h b/include/linux/completion.h
67519index 33f0280..35c6568 100644
67520--- a/include/linux/completion.h
67521+++ b/include/linux/completion.h
67522@@ -79,15 +79,15 @@ static inline void init_completion(struct completion *x)
67523 extern void wait_for_completion(struct completion *);
67524 extern void wait_for_completion_io(struct completion *);
67525 extern int wait_for_completion_interruptible(struct completion *x);
67526-extern int wait_for_completion_killable(struct completion *x);
67527+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
67528 extern unsigned long wait_for_completion_timeout(struct completion *x,
67529 unsigned long timeout);
67530 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
67531 unsigned long timeout);
67532 extern long wait_for_completion_interruptible_timeout(
67533- struct completion *x, unsigned long timeout);
67534+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
67535 extern long wait_for_completion_killable_timeout(
67536- struct completion *x, unsigned long timeout);
67537+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
67538 extern bool try_wait_for_completion(struct completion *x);
67539 extern bool completion_done(struct completion *x);
67540
67541diff --git a/include/linux/configfs.h b/include/linux/configfs.h
67542index 34025df..d94bbbc 100644
67543--- a/include/linux/configfs.h
67544+++ b/include/linux/configfs.h
67545@@ -125,7 +125,7 @@ struct configfs_attribute {
67546 const char *ca_name;
67547 struct module *ca_owner;
67548 umode_t ca_mode;
67549-};
67550+} __do_const;
67551
67552 /*
67553 * Users often need to create attribute structures for their configurable
67554diff --git a/include/linux/cpu.h b/include/linux/cpu.h
67555index ce7a074..01ab8ac 100644
67556--- a/include/linux/cpu.h
67557+++ b/include/linux/cpu.h
67558@@ -115,7 +115,7 @@ enum {
67559 /* Need to know about CPUs going up/down? */
67560 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
67561 #define cpu_notifier(fn, pri) { \
67562- static struct notifier_block fn##_nb __cpuinitdata = \
67563+ static struct notifier_block fn##_nb = \
67564 { .notifier_call = fn, .priority = pri }; \
67565 register_cpu_notifier(&fn##_nb); \
67566 }
67567diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
67568index a22944c..4e695fe 100644
67569--- a/include/linux/cpufreq.h
67570+++ b/include/linux/cpufreq.h
67571@@ -252,7 +252,7 @@ struct cpufreq_driver {
67572 int (*suspend) (struct cpufreq_policy *policy);
67573 int (*resume) (struct cpufreq_policy *policy);
67574 struct freq_attr **attr;
67575-};
67576+} __do_const;
67577
67578 /* flags */
67579
67580@@ -311,6 +311,7 @@ struct global_attr {
67581 ssize_t (*store)(struct kobject *a, struct attribute *b,
67582 const char *c, size_t count);
67583 };
67584+typedef struct global_attr __no_const global_attr_no_const;
67585
67586 #define define_one_global_ro(_name) \
67587 static struct global_attr _name = \
67588diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
67589index 480c14d..552896f 100644
67590--- a/include/linux/cpuidle.h
67591+++ b/include/linux/cpuidle.h
67592@@ -52,7 +52,8 @@ struct cpuidle_state {
67593 int index);
67594
67595 int (*enter_dead) (struct cpuidle_device *dev, int index);
67596-};
67597+} __do_const;
67598+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
67599
67600 /* Idle State Flags */
67601 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
67602@@ -194,7 +195,7 @@ struct cpuidle_governor {
67603 void (*reflect) (struct cpuidle_device *dev, int index);
67604
67605 struct module *owner;
67606-};
67607+} __do_const;
67608
67609 #ifdef CONFIG_CPU_IDLE
67610
67611diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
67612index 0325602..5e9feff 100644
67613--- a/include/linux/cpumask.h
67614+++ b/include/linux/cpumask.h
67615@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
67616 }
67617
67618 /* Valid inputs for n are -1 and 0. */
67619-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
67620+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
67621 {
67622 return n+1;
67623 }
67624
67625-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
67626+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
67627 {
67628 return n+1;
67629 }
67630
67631-static inline unsigned int cpumask_next_and(int n,
67632+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
67633 const struct cpumask *srcp,
67634 const struct cpumask *andp)
67635 {
67636@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
67637 *
67638 * Returns >= nr_cpu_ids if no further cpus set.
67639 */
67640-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
67641+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
67642 {
67643 /* -1 is a legal arg here. */
67644 if (n != -1)
67645@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
67646 *
67647 * Returns >= nr_cpu_ids if no further cpus unset.
67648 */
67649-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
67650+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
67651 {
67652 /* -1 is a legal arg here. */
67653 if (n != -1)
67654@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
67655 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
67656 }
67657
67658-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
67659+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
67660 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
67661
67662 /**
67663diff --git a/include/linux/cred.h b/include/linux/cred.h
67664index 04421e8..6bce4ef 100644
67665--- a/include/linux/cred.h
67666+++ b/include/linux/cred.h
67667@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
67668 static inline void validate_process_creds(void)
67669 {
67670 }
67671+static inline void validate_task_creds(struct task_struct *task)
67672+{
67673+}
67674 #endif
67675
67676 /**
67677diff --git a/include/linux/crypto.h b/include/linux/crypto.h
67678index b92eadf..b4ecdc1 100644
67679--- a/include/linux/crypto.h
67680+++ b/include/linux/crypto.h
67681@@ -373,7 +373,7 @@ struct cipher_tfm {
67682 const u8 *key, unsigned int keylen);
67683 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
67684 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
67685-};
67686+} __no_const;
67687
67688 struct hash_tfm {
67689 int (*init)(struct hash_desc *desc);
67690@@ -394,13 +394,13 @@ struct compress_tfm {
67691 int (*cot_decompress)(struct crypto_tfm *tfm,
67692 const u8 *src, unsigned int slen,
67693 u8 *dst, unsigned int *dlen);
67694-};
67695+} __no_const;
67696
67697 struct rng_tfm {
67698 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
67699 unsigned int dlen);
67700 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
67701-};
67702+} __no_const;
67703
67704 #define crt_ablkcipher crt_u.ablkcipher
67705 #define crt_aead crt_u.aead
67706diff --git a/include/linux/ctype.h b/include/linux/ctype.h
67707index 8acfe31..6ffccd63 100644
67708--- a/include/linux/ctype.h
67709+++ b/include/linux/ctype.h
67710@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
67711 * Fast implementation of tolower() for internal usage. Do not use in your
67712 * code.
67713 */
67714-static inline char _tolower(const char c)
67715+static inline unsigned char _tolower(const unsigned char c)
67716 {
67717 return c | 0x20;
67718 }
67719diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
67720index 7925bf0..d5143d2 100644
67721--- a/include/linux/decompress/mm.h
67722+++ b/include/linux/decompress/mm.h
67723@@ -77,7 +77,7 @@ static void free(void *where)
67724 * warnings when not needed (indeed large_malloc / large_free are not
67725 * needed by inflate */
67726
67727-#define malloc(a) kmalloc(a, GFP_KERNEL)
67728+#define malloc(a) kmalloc((a), GFP_KERNEL)
67729 #define free(a) kfree(a)
67730
67731 #define large_malloc(a) vmalloc(a)
67732diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
67733index fe8c447..bdc1f33 100644
67734--- a/include/linux/devfreq.h
67735+++ b/include/linux/devfreq.h
67736@@ -114,7 +114,7 @@ struct devfreq_governor {
67737 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
67738 int (*event_handler)(struct devfreq *devfreq,
67739 unsigned int event, void *data);
67740-};
67741+} __do_const;
67742
67743 /**
67744 * struct devfreq - Device devfreq structure
67745diff --git a/include/linux/device.h b/include/linux/device.h
67746index 9d6464e..8a5cc92 100644
67747--- a/include/linux/device.h
67748+++ b/include/linux/device.h
67749@@ -295,7 +295,7 @@ struct subsys_interface {
67750 struct list_head node;
67751 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
67752 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
67753-};
67754+} __do_const;
67755
67756 int subsys_interface_register(struct subsys_interface *sif);
67757 void subsys_interface_unregister(struct subsys_interface *sif);
67758@@ -475,7 +475,7 @@ struct device_type {
67759 void (*release)(struct device *dev);
67760
67761 const struct dev_pm_ops *pm;
67762-};
67763+} __do_const;
67764
67765 /* interface for exporting device attributes */
67766 struct device_attribute {
67767@@ -485,11 +485,12 @@ struct device_attribute {
67768 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
67769 const char *buf, size_t count);
67770 };
67771+typedef struct device_attribute __no_const device_attribute_no_const;
67772
67773 struct dev_ext_attribute {
67774 struct device_attribute attr;
67775 void *var;
67776-};
67777+} __do_const;
67778
67779 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
67780 char *buf);
67781diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
67782index 94af418..b1ca7a2 100644
67783--- a/include/linux/dma-mapping.h
67784+++ b/include/linux/dma-mapping.h
67785@@ -54,7 +54,7 @@ struct dma_map_ops {
67786 u64 (*get_required_mask)(struct device *dev);
67787 #endif
67788 int is_phys;
67789-};
67790+} __do_const;
67791
67792 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
67793
67794diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
67795index 91ac8da..a841318 100644
67796--- a/include/linux/dmaengine.h
67797+++ b/include/linux/dmaengine.h
67798@@ -1034,9 +1034,9 @@ struct dma_pinned_list {
67799 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
67800 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
67801
67802-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
67803+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
67804 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
67805-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
67806+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
67807 struct dma_pinned_list *pinned_list, struct page *page,
67808 unsigned int offset, size_t len);
67809
67810diff --git a/include/linux/efi.h b/include/linux/efi.h
67811index 3d7df3d..301f024 100644
67812--- a/include/linux/efi.h
67813+++ b/include/linux/efi.h
67814@@ -740,6 +740,7 @@ struct efivar_operations {
67815 efi_set_variable_t *set_variable;
67816 efi_query_variable_store_t *query_variable_store;
67817 };
67818+typedef struct efivar_operations __no_const efivar_operations_no_const;
67819
67820 struct efivars {
67821 /*
67822diff --git a/include/linux/elf.h b/include/linux/elf.h
67823index 40a3c0e..4c45a38 100644
67824--- a/include/linux/elf.h
67825+++ b/include/linux/elf.h
67826@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
67827 #define elf_note elf32_note
67828 #define elf_addr_t Elf32_Off
67829 #define Elf_Half Elf32_Half
67830+#define elf_dyn Elf32_Dyn
67831
67832 #else
67833
67834@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
67835 #define elf_note elf64_note
67836 #define elf_addr_t Elf64_Off
67837 #define Elf_Half Elf64_Half
67838+#define elf_dyn Elf64_Dyn
67839
67840 #endif
67841
67842diff --git a/include/linux/err.h b/include/linux/err.h
67843index f2edce2..cc2082c 100644
67844--- a/include/linux/err.h
67845+++ b/include/linux/err.h
67846@@ -19,12 +19,12 @@
67847
67848 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
67849
67850-static inline void * __must_check ERR_PTR(long error)
67851+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
67852 {
67853 return (void *) error;
67854 }
67855
67856-static inline long __must_check PTR_ERR(const void *ptr)
67857+static inline long __must_check __intentional_overflow(-1) PTR_ERR(const void *ptr)
67858 {
67859 return (long) ptr;
67860 }
67861diff --git a/include/linux/extcon.h b/include/linux/extcon.h
67862index fcb51c8..bdafcf6 100644
67863--- a/include/linux/extcon.h
67864+++ b/include/linux/extcon.h
67865@@ -134,7 +134,7 @@ struct extcon_dev {
67866 /* /sys/class/extcon/.../mutually_exclusive/... */
67867 struct attribute_group attr_g_muex;
67868 struct attribute **attrs_muex;
67869- struct device_attribute *d_attrs_muex;
67870+ device_attribute_no_const *d_attrs_muex;
67871 };
67872
67873 /**
67874diff --git a/include/linux/fb.h b/include/linux/fb.h
67875index 58b9860..58e5516 100644
67876--- a/include/linux/fb.h
67877+++ b/include/linux/fb.h
67878@@ -304,7 +304,7 @@ struct fb_ops {
67879 /* called at KDB enter and leave time to prepare the console */
67880 int (*fb_debug_enter)(struct fb_info *info);
67881 int (*fb_debug_leave)(struct fb_info *info);
67882-};
67883+} __do_const;
67884
67885 #ifdef CONFIG_FB_TILEBLITTING
67886 #define FB_TILE_CURSOR_NONE 0
67887diff --git a/include/linux/filter.h b/include/linux/filter.h
67888index c45eabc..baa0be5 100644
67889--- a/include/linux/filter.h
67890+++ b/include/linux/filter.h
67891@@ -20,6 +20,7 @@ struct compat_sock_fprog {
67892
67893 struct sk_buff;
67894 struct sock;
67895+struct bpf_jit_work;
67896
67897 struct sk_filter
67898 {
67899@@ -27,6 +28,9 @@ struct sk_filter
67900 unsigned int len; /* Number of filter blocks */
67901 unsigned int (*bpf_func)(const struct sk_buff *skb,
67902 const struct sock_filter *filter);
67903+#ifdef CONFIG_BPF_JIT
67904+ struct bpf_jit_work *work;
67905+#endif
67906 struct rcu_head rcu;
67907 struct sock_filter insns[0];
67908 };
67909diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
67910index 3044254..9767f41 100644
67911--- a/include/linux/frontswap.h
67912+++ b/include/linux/frontswap.h
67913@@ -11,7 +11,7 @@ struct frontswap_ops {
67914 int (*load)(unsigned, pgoff_t, struct page *);
67915 void (*invalidate_page)(unsigned, pgoff_t);
67916 void (*invalidate_area)(unsigned);
67917-};
67918+} __no_const;
67919
67920 extern bool frontswap_enabled;
67921 extern struct frontswap_ops
67922diff --git a/include/linux/fs.h b/include/linux/fs.h
67923index 2c28271..8d3d74c 100644
67924--- a/include/linux/fs.h
67925+++ b/include/linux/fs.h
67926@@ -1541,7 +1541,8 @@ struct file_operations {
67927 long (*fallocate)(struct file *file, int mode, loff_t offset,
67928 loff_t len);
67929 int (*show_fdinfo)(struct seq_file *m, struct file *f);
67930-};
67931+} __do_const;
67932+typedef struct file_operations __no_const file_operations_no_const;
67933
67934 struct inode_operations {
67935 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
67936@@ -2672,4 +2673,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
67937 inode->i_flags |= S_NOSEC;
67938 }
67939
67940+static inline bool is_sidechannel_device(const struct inode *inode)
67941+{
67942+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
67943+ umode_t mode = inode->i_mode;
67944+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
67945+#else
67946+ return false;
67947+#endif
67948+}
67949+
67950 #endif /* _LINUX_FS_H */
67951diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
67952index 2b93a9a..855d94a 100644
67953--- a/include/linux/fs_struct.h
67954+++ b/include/linux/fs_struct.h
67955@@ -6,7 +6,7 @@
67956 #include <linux/seqlock.h>
67957
67958 struct fs_struct {
67959- int users;
67960+ atomic_t users;
67961 spinlock_t lock;
67962 seqcount_t seq;
67963 int umask;
67964diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
67965index 5dfa0aa..6acf322 100644
67966--- a/include/linux/fscache-cache.h
67967+++ b/include/linux/fscache-cache.h
67968@@ -112,7 +112,7 @@ struct fscache_operation {
67969 fscache_operation_release_t release;
67970 };
67971
67972-extern atomic_t fscache_op_debug_id;
67973+extern atomic_unchecked_t fscache_op_debug_id;
67974 extern void fscache_op_work_func(struct work_struct *work);
67975
67976 extern void fscache_enqueue_operation(struct fscache_operation *);
67977@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
67978 INIT_WORK(&op->work, fscache_op_work_func);
67979 atomic_set(&op->usage, 1);
67980 op->state = FSCACHE_OP_ST_INITIALISED;
67981- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
67982+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
67983 op->processor = processor;
67984 op->release = release;
67985 INIT_LIST_HEAD(&op->pend_link);
67986diff --git a/include/linux/fscache.h b/include/linux/fscache.h
67987index 7a08623..4c07b0f 100644
67988--- a/include/linux/fscache.h
67989+++ b/include/linux/fscache.h
67990@@ -152,7 +152,7 @@ struct fscache_cookie_def {
67991 * - this is mandatory for any object that may have data
67992 */
67993 void (*now_uncached)(void *cookie_netfs_data);
67994-};
67995+} __do_const;
67996
67997 /*
67998 * fscache cached network filesystem type
67999diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
68000index a78680a..87bd73e 100644
68001--- a/include/linux/fsnotify.h
68002+++ b/include/linux/fsnotify.h
68003@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
68004 struct inode *inode = path->dentry->d_inode;
68005 __u32 mask = FS_ACCESS;
68006
68007+ if (is_sidechannel_device(inode))
68008+ return;
68009+
68010 if (S_ISDIR(inode->i_mode))
68011 mask |= FS_ISDIR;
68012
68013@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
68014 struct inode *inode = path->dentry->d_inode;
68015 __u32 mask = FS_MODIFY;
68016
68017+ if (is_sidechannel_device(inode))
68018+ return;
68019+
68020 if (S_ISDIR(inode->i_mode))
68021 mask |= FS_ISDIR;
68022
68023@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
68024 */
68025 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
68026 {
68027- return kstrdup(name, GFP_KERNEL);
68028+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
68029 }
68030
68031 /*
68032diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
68033index 13a54d0..c6ce2a7 100644
68034--- a/include/linux/ftrace_event.h
68035+++ b/include/linux/ftrace_event.h
68036@@ -274,7 +274,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
68037 extern int trace_add_event_call(struct ftrace_event_call *call);
68038 extern void trace_remove_event_call(struct ftrace_event_call *call);
68039
68040-#define is_signed_type(type) (((type)(-1)) < (type)0)
68041+#define is_signed_type(type) (((type)(-1)) < (type)1)
68042
68043 int trace_set_clr_event(const char *system, const char *event, int set);
68044
68045diff --git a/include/linux/genhd.h b/include/linux/genhd.h
68046index 9f3c275..911b591 100644
68047--- a/include/linux/genhd.h
68048+++ b/include/linux/genhd.h
68049@@ -194,7 +194,7 @@ struct gendisk {
68050 struct kobject *slave_dir;
68051
68052 struct timer_rand_state *random;
68053- atomic_t sync_io; /* RAID */
68054+ atomic_unchecked_t sync_io; /* RAID */
68055 struct disk_events *ev;
68056 #ifdef CONFIG_BLK_DEV_INTEGRITY
68057 struct blk_integrity *integrity;
68058diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
68059index 023bc34..b02b46a 100644
68060--- a/include/linux/genl_magic_func.h
68061+++ b/include/linux/genl_magic_func.h
68062@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
68063 },
68064
68065 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
68066-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
68067+static struct genl_ops ZZZ_genl_ops[] = {
68068 #include GENL_MAGIC_INCLUDE_FILE
68069 };
68070
68071diff --git a/include/linux/gfp.h b/include/linux/gfp.h
68072index 0f615eb..5c3832f 100644
68073--- a/include/linux/gfp.h
68074+++ b/include/linux/gfp.h
68075@@ -35,6 +35,13 @@ struct vm_area_struct;
68076 #define ___GFP_NO_KSWAPD 0x400000u
68077 #define ___GFP_OTHER_NODE 0x800000u
68078 #define ___GFP_WRITE 0x1000000u
68079+
68080+#ifdef CONFIG_PAX_USERCOPY_SLABS
68081+#define ___GFP_USERCOPY 0x2000000u
68082+#else
68083+#define ___GFP_USERCOPY 0
68084+#endif
68085+
68086 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
68087
68088 /*
68089@@ -92,6 +99,7 @@ struct vm_area_struct;
68090 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
68091 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
68092 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
68093+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
68094
68095 /*
68096 * This may seem redundant, but it's a way of annotating false positives vs.
68097@@ -99,7 +107,7 @@ struct vm_area_struct;
68098 */
68099 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
68100
68101-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
68102+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
68103 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
68104
68105 /* This equals 0, but use constants in case they ever change */
68106@@ -153,6 +161,8 @@ struct vm_area_struct;
68107 /* 4GB DMA on some platforms */
68108 #define GFP_DMA32 __GFP_DMA32
68109
68110+#define GFP_USERCOPY __GFP_USERCOPY
68111+
68112 /* Convert GFP flags to their corresponding migrate type */
68113 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
68114 {
68115diff --git a/include/linux/gracl.h b/include/linux/gracl.h
68116new file mode 100644
68117index 0000000..ebe6d72
68118--- /dev/null
68119+++ b/include/linux/gracl.h
68120@@ -0,0 +1,319 @@
68121+#ifndef GR_ACL_H
68122+#define GR_ACL_H
68123+
68124+#include <linux/grdefs.h>
68125+#include <linux/resource.h>
68126+#include <linux/capability.h>
68127+#include <linux/dcache.h>
68128+#include <asm/resource.h>
68129+
68130+/* Major status information */
68131+
68132+#define GR_VERSION "grsecurity 2.9.1"
68133+#define GRSECURITY_VERSION 0x2901
68134+
68135+enum {
68136+ GR_SHUTDOWN = 0,
68137+ GR_ENABLE = 1,
68138+ GR_SPROLE = 2,
68139+ GR_RELOAD = 3,
68140+ GR_SEGVMOD = 4,
68141+ GR_STATUS = 5,
68142+ GR_UNSPROLE = 6,
68143+ GR_PASSSET = 7,
68144+ GR_SPROLEPAM = 8,
68145+};
68146+
68147+/* Password setup definitions
68148+ * kernel/grhash.c */
68149+enum {
68150+ GR_PW_LEN = 128,
68151+ GR_SALT_LEN = 16,
68152+ GR_SHA_LEN = 32,
68153+};
68154+
68155+enum {
68156+ GR_SPROLE_LEN = 64,
68157+};
68158+
68159+enum {
68160+ GR_NO_GLOB = 0,
68161+ GR_REG_GLOB,
68162+ GR_CREATE_GLOB
68163+};
68164+
68165+#define GR_NLIMITS 32
68166+
68167+/* Begin Data Structures */
68168+
68169+struct sprole_pw {
68170+ unsigned char *rolename;
68171+ unsigned char salt[GR_SALT_LEN];
68172+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
68173+};
68174+
68175+struct name_entry {
68176+ __u32 key;
68177+ ino_t inode;
68178+ dev_t device;
68179+ char *name;
68180+ __u16 len;
68181+ __u8 deleted;
68182+ struct name_entry *prev;
68183+ struct name_entry *next;
68184+};
68185+
68186+struct inodev_entry {
68187+ struct name_entry *nentry;
68188+ struct inodev_entry *prev;
68189+ struct inodev_entry *next;
68190+};
68191+
68192+struct acl_role_db {
68193+ struct acl_role_label **r_hash;
68194+ __u32 r_size;
68195+};
68196+
68197+struct inodev_db {
68198+ struct inodev_entry **i_hash;
68199+ __u32 i_size;
68200+};
68201+
68202+struct name_db {
68203+ struct name_entry **n_hash;
68204+ __u32 n_size;
68205+};
68206+
68207+struct crash_uid {
68208+ uid_t uid;
68209+ unsigned long expires;
68210+};
68211+
68212+struct gr_hash_struct {
68213+ void **table;
68214+ void **nametable;
68215+ void *first;
68216+ __u32 table_size;
68217+ __u32 used_size;
68218+ int type;
68219+};
68220+
68221+/* Userspace Grsecurity ACL data structures */
68222+
68223+struct acl_subject_label {
68224+ char *filename;
68225+ ino_t inode;
68226+ dev_t device;
68227+ __u32 mode;
68228+ kernel_cap_t cap_mask;
68229+ kernel_cap_t cap_lower;
68230+ kernel_cap_t cap_invert_audit;
68231+
68232+ struct rlimit res[GR_NLIMITS];
68233+ __u32 resmask;
68234+
68235+ __u8 user_trans_type;
68236+ __u8 group_trans_type;
68237+ uid_t *user_transitions;
68238+ gid_t *group_transitions;
68239+ __u16 user_trans_num;
68240+ __u16 group_trans_num;
68241+
68242+ __u32 sock_families[2];
68243+ __u32 ip_proto[8];
68244+ __u32 ip_type;
68245+ struct acl_ip_label **ips;
68246+ __u32 ip_num;
68247+ __u32 inaddr_any_override;
68248+
68249+ __u32 crashes;
68250+ unsigned long expires;
68251+
68252+ struct acl_subject_label *parent_subject;
68253+ struct gr_hash_struct *hash;
68254+ struct acl_subject_label *prev;
68255+ struct acl_subject_label *next;
68256+
68257+ struct acl_object_label **obj_hash;
68258+ __u32 obj_hash_size;
68259+ __u16 pax_flags;
68260+};
68261+
68262+struct role_allowed_ip {
68263+ __u32 addr;
68264+ __u32 netmask;
68265+
68266+ struct role_allowed_ip *prev;
68267+ struct role_allowed_ip *next;
68268+};
68269+
68270+struct role_transition {
68271+ char *rolename;
68272+
68273+ struct role_transition *prev;
68274+ struct role_transition *next;
68275+};
68276+
68277+struct acl_role_label {
68278+ char *rolename;
68279+ uid_t uidgid;
68280+ __u16 roletype;
68281+
68282+ __u16 auth_attempts;
68283+ unsigned long expires;
68284+
68285+ struct acl_subject_label *root_label;
68286+ struct gr_hash_struct *hash;
68287+
68288+ struct acl_role_label *prev;
68289+ struct acl_role_label *next;
68290+
68291+ struct role_transition *transitions;
68292+ struct role_allowed_ip *allowed_ips;
68293+ uid_t *domain_children;
68294+ __u16 domain_child_num;
68295+
68296+ umode_t umask;
68297+
68298+ struct acl_subject_label **subj_hash;
68299+ __u32 subj_hash_size;
68300+};
68301+
68302+struct user_acl_role_db {
68303+ struct acl_role_label **r_table;
68304+ __u32 num_pointers; /* Number of allocations to track */
68305+ __u32 num_roles; /* Number of roles */
68306+ __u32 num_domain_children; /* Number of domain children */
68307+ __u32 num_subjects; /* Number of subjects */
68308+ __u32 num_objects; /* Number of objects */
68309+};
68310+
68311+struct acl_object_label {
68312+ char *filename;
68313+ ino_t inode;
68314+ dev_t device;
68315+ __u32 mode;
68316+
68317+ struct acl_subject_label *nested;
68318+ struct acl_object_label *globbed;
68319+
68320+ /* next two structures not used */
68321+
68322+ struct acl_object_label *prev;
68323+ struct acl_object_label *next;
68324+};
68325+
68326+struct acl_ip_label {
68327+ char *iface;
68328+ __u32 addr;
68329+ __u32 netmask;
68330+ __u16 low, high;
68331+ __u8 mode;
68332+ __u32 type;
68333+ __u32 proto[8];
68334+
68335+ /* next two structures not used */
68336+
68337+ struct acl_ip_label *prev;
68338+ struct acl_ip_label *next;
68339+};
68340+
68341+struct gr_arg {
68342+ struct user_acl_role_db role_db;
68343+ unsigned char pw[GR_PW_LEN];
68344+ unsigned char salt[GR_SALT_LEN];
68345+ unsigned char sum[GR_SHA_LEN];
68346+ unsigned char sp_role[GR_SPROLE_LEN];
68347+ struct sprole_pw *sprole_pws;
68348+ dev_t segv_device;
68349+ ino_t segv_inode;
68350+ uid_t segv_uid;
68351+ __u16 num_sprole_pws;
68352+ __u16 mode;
68353+};
68354+
68355+struct gr_arg_wrapper {
68356+ struct gr_arg *arg;
68357+ __u32 version;
68358+ __u32 size;
68359+};
68360+
68361+struct subject_map {
68362+ struct acl_subject_label *user;
68363+ struct acl_subject_label *kernel;
68364+ struct subject_map *prev;
68365+ struct subject_map *next;
68366+};
68367+
68368+struct acl_subj_map_db {
68369+ struct subject_map **s_hash;
68370+ __u32 s_size;
68371+};
68372+
68373+/* End Data Structures Section */
68374+
68375+/* Hash functions generated by empirical testing by Brad Spengler
68376+ Makes good use of the low bits of the inode. Generally 0-1 times
68377+ in loop for successful match. 0-3 for unsuccessful match.
68378+ Shift/add algorithm with modulus of table size and an XOR*/
68379+
68380+static __inline__ unsigned int
68381+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
68382+{
68383+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
68384+}
68385+
68386+ static __inline__ unsigned int
68387+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
68388+{
68389+ return ((const unsigned long)userp % sz);
68390+}
68391+
68392+static __inline__ unsigned int
68393+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
68394+{
68395+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
68396+}
68397+
68398+static __inline__ unsigned int
68399+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
68400+{
68401+ return full_name_hash((const unsigned char *)name, len) % sz;
68402+}
68403+
68404+#define FOR_EACH_ROLE_START(role) \
68405+ role = role_list; \
68406+ while (role) {
68407+
68408+#define FOR_EACH_ROLE_END(role) \
68409+ role = role->prev; \
68410+ }
68411+
68412+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
68413+ subj = NULL; \
68414+ iter = 0; \
68415+ while (iter < role->subj_hash_size) { \
68416+ if (subj == NULL) \
68417+ subj = role->subj_hash[iter]; \
68418+ if (subj == NULL) { \
68419+ iter++; \
68420+ continue; \
68421+ }
68422+
68423+#define FOR_EACH_SUBJECT_END(subj,iter) \
68424+ subj = subj->next; \
68425+ if (subj == NULL) \
68426+ iter++; \
68427+ }
68428+
68429+
68430+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
68431+ subj = role->hash->first; \
68432+ while (subj != NULL) {
68433+
68434+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
68435+ subj = subj->next; \
68436+ }
68437+
68438+#endif
68439+
68440diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
68441new file mode 100644
68442index 0000000..323ecf2
68443--- /dev/null
68444+++ b/include/linux/gralloc.h
68445@@ -0,0 +1,9 @@
68446+#ifndef __GRALLOC_H
68447+#define __GRALLOC_H
68448+
68449+void acl_free_all(void);
68450+int acl_alloc_stack_init(unsigned long size);
68451+void *acl_alloc(unsigned long len);
68452+void *acl_alloc_num(unsigned long num, unsigned long len);
68453+
68454+#endif
68455diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
68456new file mode 100644
68457index 0000000..be66033
68458--- /dev/null
68459+++ b/include/linux/grdefs.h
68460@@ -0,0 +1,140 @@
68461+#ifndef GRDEFS_H
68462+#define GRDEFS_H
68463+
68464+/* Begin grsecurity status declarations */
68465+
68466+enum {
68467+ GR_READY = 0x01,
68468+ GR_STATUS_INIT = 0x00 // disabled state
68469+};
68470+
68471+/* Begin ACL declarations */
68472+
68473+/* Role flags */
68474+
68475+enum {
68476+ GR_ROLE_USER = 0x0001,
68477+ GR_ROLE_GROUP = 0x0002,
68478+ GR_ROLE_DEFAULT = 0x0004,
68479+ GR_ROLE_SPECIAL = 0x0008,
68480+ GR_ROLE_AUTH = 0x0010,
68481+ GR_ROLE_NOPW = 0x0020,
68482+ GR_ROLE_GOD = 0x0040,
68483+ GR_ROLE_LEARN = 0x0080,
68484+ GR_ROLE_TPE = 0x0100,
68485+ GR_ROLE_DOMAIN = 0x0200,
68486+ GR_ROLE_PAM = 0x0400,
68487+ GR_ROLE_PERSIST = 0x0800
68488+};
68489+
68490+/* ACL Subject and Object mode flags */
68491+enum {
68492+ GR_DELETED = 0x80000000
68493+};
68494+
68495+/* ACL Object-only mode flags */
68496+enum {
68497+ GR_READ = 0x00000001,
68498+ GR_APPEND = 0x00000002,
68499+ GR_WRITE = 0x00000004,
68500+ GR_EXEC = 0x00000008,
68501+ GR_FIND = 0x00000010,
68502+ GR_INHERIT = 0x00000020,
68503+ GR_SETID = 0x00000040,
68504+ GR_CREATE = 0x00000080,
68505+ GR_DELETE = 0x00000100,
68506+ GR_LINK = 0x00000200,
68507+ GR_AUDIT_READ = 0x00000400,
68508+ GR_AUDIT_APPEND = 0x00000800,
68509+ GR_AUDIT_WRITE = 0x00001000,
68510+ GR_AUDIT_EXEC = 0x00002000,
68511+ GR_AUDIT_FIND = 0x00004000,
68512+ GR_AUDIT_INHERIT= 0x00008000,
68513+ GR_AUDIT_SETID = 0x00010000,
68514+ GR_AUDIT_CREATE = 0x00020000,
68515+ GR_AUDIT_DELETE = 0x00040000,
68516+ GR_AUDIT_LINK = 0x00080000,
68517+ GR_PTRACERD = 0x00100000,
68518+ GR_NOPTRACE = 0x00200000,
68519+ GR_SUPPRESS = 0x00400000,
68520+ GR_NOLEARN = 0x00800000,
68521+ GR_INIT_TRANSFER= 0x01000000
68522+};
68523+
68524+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
68525+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
68526+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
68527+
68528+/* ACL subject-only mode flags */
68529+enum {
68530+ GR_KILL = 0x00000001,
68531+ GR_VIEW = 0x00000002,
68532+ GR_PROTECTED = 0x00000004,
68533+ GR_LEARN = 0x00000008,
68534+ GR_OVERRIDE = 0x00000010,
68535+ /* just a placeholder, this mode is only used in userspace */
68536+ GR_DUMMY = 0x00000020,
68537+ GR_PROTSHM = 0x00000040,
68538+ GR_KILLPROC = 0x00000080,
68539+ GR_KILLIPPROC = 0x00000100,
68540+ /* just a placeholder, this mode is only used in userspace */
68541+ GR_NOTROJAN = 0x00000200,
68542+ GR_PROTPROCFD = 0x00000400,
68543+ GR_PROCACCT = 0x00000800,
68544+ GR_RELAXPTRACE = 0x00001000,
68545+ //GR_NESTED = 0x00002000,
68546+ GR_INHERITLEARN = 0x00004000,
68547+ GR_PROCFIND = 0x00008000,
68548+ GR_POVERRIDE = 0x00010000,
68549+ GR_KERNELAUTH = 0x00020000,
68550+ GR_ATSECURE = 0x00040000,
68551+ GR_SHMEXEC = 0x00080000
68552+};
68553+
68554+enum {
68555+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
68556+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
68557+ GR_PAX_ENABLE_MPROTECT = 0x0004,
68558+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
68559+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
68560+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
68561+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
68562+ GR_PAX_DISABLE_MPROTECT = 0x0400,
68563+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
68564+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
68565+};
68566+
68567+enum {
68568+ GR_ID_USER = 0x01,
68569+ GR_ID_GROUP = 0x02,
68570+};
68571+
68572+enum {
68573+ GR_ID_ALLOW = 0x01,
68574+ GR_ID_DENY = 0x02,
68575+};
68576+
68577+#define GR_CRASH_RES 31
68578+#define GR_UIDTABLE_MAX 500
68579+
68580+/* begin resource learning section */
68581+enum {
68582+ GR_RLIM_CPU_BUMP = 60,
68583+ GR_RLIM_FSIZE_BUMP = 50000,
68584+ GR_RLIM_DATA_BUMP = 10000,
68585+ GR_RLIM_STACK_BUMP = 1000,
68586+ GR_RLIM_CORE_BUMP = 10000,
68587+ GR_RLIM_RSS_BUMP = 500000,
68588+ GR_RLIM_NPROC_BUMP = 1,
68589+ GR_RLIM_NOFILE_BUMP = 5,
68590+ GR_RLIM_MEMLOCK_BUMP = 50000,
68591+ GR_RLIM_AS_BUMP = 500000,
68592+ GR_RLIM_LOCKS_BUMP = 2,
68593+ GR_RLIM_SIGPENDING_BUMP = 5,
68594+ GR_RLIM_MSGQUEUE_BUMP = 10000,
68595+ GR_RLIM_NICE_BUMP = 1,
68596+ GR_RLIM_RTPRIO_BUMP = 1,
68597+ GR_RLIM_RTTIME_BUMP = 1000000
68598+};
68599+
68600+#endif
68601diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
68602new file mode 100644
68603index 0000000..5402bce
68604--- /dev/null
68605+++ b/include/linux/grinternal.h
68606@@ -0,0 +1,215 @@
68607+#ifndef __GRINTERNAL_H
68608+#define __GRINTERNAL_H
68609+
68610+#ifdef CONFIG_GRKERNSEC
68611+
68612+#include <linux/fs.h>
68613+#include <linux/mnt_namespace.h>
68614+#include <linux/nsproxy.h>
68615+#include <linux/gracl.h>
68616+#include <linux/grdefs.h>
68617+#include <linux/grmsg.h>
68618+
68619+void gr_add_learn_entry(const char *fmt, ...)
68620+ __attribute__ ((format (printf, 1, 2)));
68621+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
68622+ const struct vfsmount *mnt);
68623+__u32 gr_check_create(const struct dentry *new_dentry,
68624+ const struct dentry *parent,
68625+ const struct vfsmount *mnt, const __u32 mode);
68626+int gr_check_protected_task(const struct task_struct *task);
68627+__u32 to_gr_audit(const __u32 reqmode);
68628+int gr_set_acls(const int type);
68629+int gr_apply_subject_to_task(struct task_struct *task);
68630+int gr_acl_is_enabled(void);
68631+char gr_roletype_to_char(void);
68632+
68633+void gr_handle_alertkill(struct task_struct *task);
68634+char *gr_to_filename(const struct dentry *dentry,
68635+ const struct vfsmount *mnt);
68636+char *gr_to_filename1(const struct dentry *dentry,
68637+ const struct vfsmount *mnt);
68638+char *gr_to_filename2(const struct dentry *dentry,
68639+ const struct vfsmount *mnt);
68640+char *gr_to_filename3(const struct dentry *dentry,
68641+ const struct vfsmount *mnt);
68642+
68643+extern int grsec_enable_ptrace_readexec;
68644+extern int grsec_enable_harden_ptrace;
68645+extern int grsec_enable_link;
68646+extern int grsec_enable_fifo;
68647+extern int grsec_enable_execve;
68648+extern int grsec_enable_shm;
68649+extern int grsec_enable_execlog;
68650+extern int grsec_enable_signal;
68651+extern int grsec_enable_audit_ptrace;
68652+extern int grsec_enable_forkfail;
68653+extern int grsec_enable_time;
68654+extern int grsec_enable_rofs;
68655+extern int grsec_enable_chroot_shmat;
68656+extern int grsec_enable_chroot_mount;
68657+extern int grsec_enable_chroot_double;
68658+extern int grsec_enable_chroot_pivot;
68659+extern int grsec_enable_chroot_chdir;
68660+extern int grsec_enable_chroot_chmod;
68661+extern int grsec_enable_chroot_mknod;
68662+extern int grsec_enable_chroot_fchdir;
68663+extern int grsec_enable_chroot_nice;
68664+extern int grsec_enable_chroot_execlog;
68665+extern int grsec_enable_chroot_caps;
68666+extern int grsec_enable_chroot_sysctl;
68667+extern int grsec_enable_chroot_unix;
68668+extern int grsec_enable_symlinkown;
68669+extern kgid_t grsec_symlinkown_gid;
68670+extern int grsec_enable_tpe;
68671+extern kgid_t grsec_tpe_gid;
68672+extern int grsec_enable_tpe_all;
68673+extern int grsec_enable_tpe_invert;
68674+extern int grsec_enable_socket_all;
68675+extern kgid_t grsec_socket_all_gid;
68676+extern int grsec_enable_socket_client;
68677+extern kgid_t grsec_socket_client_gid;
68678+extern int grsec_enable_socket_server;
68679+extern kgid_t grsec_socket_server_gid;
68680+extern kgid_t grsec_audit_gid;
68681+extern int grsec_enable_group;
68682+extern int grsec_enable_audit_textrel;
68683+extern int grsec_enable_log_rwxmaps;
68684+extern int grsec_enable_mount;
68685+extern int grsec_enable_chdir;
68686+extern int grsec_resource_logging;
68687+extern int grsec_enable_blackhole;
68688+extern int grsec_lastack_retries;
68689+extern int grsec_enable_brute;
68690+extern int grsec_lock;
68691+
68692+extern spinlock_t grsec_alert_lock;
68693+extern unsigned long grsec_alert_wtime;
68694+extern unsigned long grsec_alert_fyet;
68695+
68696+extern spinlock_t grsec_audit_lock;
68697+
68698+extern rwlock_t grsec_exec_file_lock;
68699+
68700+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
68701+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
68702+ (tsk)->exec_file->f_path.mnt) : "/")
68703+
68704+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
68705+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
68706+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
68707+
68708+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
68709+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
68710+ (tsk)->exec_file->f_path.mnt) : "/")
68711+
68712+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
68713+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
68714+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
68715+
68716+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
68717+
68718+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
68719+
68720+#define GR_CHROOT_CAPS {{ \
68721+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
68722+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
68723+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
68724+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
68725+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
68726+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
68727+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
68728+
68729+#define security_learn(normal_msg,args...) \
68730+({ \
68731+ read_lock(&grsec_exec_file_lock); \
68732+ gr_add_learn_entry(normal_msg "\n", ## args); \
68733+ read_unlock(&grsec_exec_file_lock); \
68734+})
68735+
68736+enum {
68737+ GR_DO_AUDIT,
68738+ GR_DONT_AUDIT,
68739+ /* used for non-audit messages that we shouldn't kill the task on */
68740+ GR_DONT_AUDIT_GOOD
68741+};
68742+
68743+enum {
68744+ GR_TTYSNIFF,
68745+ GR_RBAC,
68746+ GR_RBAC_STR,
68747+ GR_STR_RBAC,
68748+ GR_RBAC_MODE2,
68749+ GR_RBAC_MODE3,
68750+ GR_FILENAME,
68751+ GR_SYSCTL_HIDDEN,
68752+ GR_NOARGS,
68753+ GR_ONE_INT,
68754+ GR_ONE_INT_TWO_STR,
68755+ GR_ONE_STR,
68756+ GR_STR_INT,
68757+ GR_TWO_STR_INT,
68758+ GR_TWO_INT,
68759+ GR_TWO_U64,
68760+ GR_THREE_INT,
68761+ GR_FIVE_INT_TWO_STR,
68762+ GR_TWO_STR,
68763+ GR_THREE_STR,
68764+ GR_FOUR_STR,
68765+ GR_STR_FILENAME,
68766+ GR_FILENAME_STR,
68767+ GR_FILENAME_TWO_INT,
68768+ GR_FILENAME_TWO_INT_STR,
68769+ GR_TEXTREL,
68770+ GR_PTRACE,
68771+ GR_RESOURCE,
68772+ GR_CAP,
68773+ GR_SIG,
68774+ GR_SIG2,
68775+ GR_CRASH1,
68776+ GR_CRASH2,
68777+ GR_PSACCT,
68778+ GR_RWXMAP
68779+};
68780+
68781+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
68782+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
68783+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
68784+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
68785+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
68786+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
68787+#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)
68788+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
68789+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
68790+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
68791+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
68792+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
68793+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
68794+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
68795+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
68796+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
68797+#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)
68798+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
68799+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
68800+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
68801+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
68802+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
68803+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
68804+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
68805+#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)
68806+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
68807+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
68808+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
68809+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
68810+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
68811+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
68812+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
68813+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
68814+#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)
68815+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
68816+
68817+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
68818+
68819+#endif
68820+
68821+#endif
68822diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
68823new file mode 100644
68824index 0000000..2bd4c8d
68825--- /dev/null
68826+++ b/include/linux/grmsg.h
68827@@ -0,0 +1,111 @@
68828+#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"
68829+#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"
68830+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
68831+#define GR_STOPMOD_MSG "denied modification of module state by "
68832+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
68833+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
68834+#define GR_IOPERM_MSG "denied use of ioperm() by "
68835+#define GR_IOPL_MSG "denied use of iopl() by "
68836+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
68837+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
68838+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
68839+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
68840+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
68841+#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"
68842+#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"
68843+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
68844+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
68845+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
68846+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
68847+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
68848+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
68849+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
68850+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
68851+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
68852+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
68853+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
68854+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
68855+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
68856+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
68857+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
68858+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
68859+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
68860+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
68861+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
68862+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
68863+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
68864+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
68865+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
68866+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
68867+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
68868+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
68869+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
68870+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
68871+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
68872+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
68873+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
68874+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
68875+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
68876+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
68877+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
68878+#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"
68879+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
68880+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
68881+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
68882+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
68883+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
68884+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
68885+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
68886+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
68887+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
68888+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
68889+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
68890+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
68891+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
68892+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
68893+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
68894+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
68895+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
68896+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
68897+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
68898+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
68899+#define GR_FAILFORK_MSG "failed fork with errno %s by "
68900+#define GR_NICE_CHROOT_MSG "denied priority change by "
68901+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
68902+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
68903+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
68904+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
68905+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
68906+#define GR_TIME_MSG "time set by "
68907+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
68908+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
68909+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
68910+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
68911+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
68912+#define GR_BIND_MSG "denied bind() by "
68913+#define GR_CONNECT_MSG "denied connect() by "
68914+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
68915+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
68916+#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"
68917+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
68918+#define GR_CAP_ACL_MSG "use of %s denied for "
68919+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
68920+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
68921+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
68922+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
68923+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
68924+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
68925+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
68926+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
68927+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
68928+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
68929+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
68930+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
68931+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
68932+#define GR_VM86_MSG "denied use of vm86 by "
68933+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
68934+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
68935+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
68936+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
68937+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
68938+#define GR_BRUTE_DAEMON_MSG "bruteforce prevention initiated for the next 30 minutes or until service restarted, stalling each fork 30 seconds. Please investigate the crash report for "
68939diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
68940new file mode 100644
68941index 0000000..d7ef0ac
68942--- /dev/null
68943+++ b/include/linux/grsecurity.h
68944@@ -0,0 +1,242 @@
68945+#ifndef GR_SECURITY_H
68946+#define GR_SECURITY_H
68947+#include <linux/fs.h>
68948+#include <linux/fs_struct.h>
68949+#include <linux/binfmts.h>
68950+#include <linux/gracl.h>
68951+
68952+/* notify of brain-dead configs */
68953+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68954+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
68955+#endif
68956+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
68957+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
68958+#endif
68959+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
68960+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
68961+#endif
68962+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
68963+#error "CONFIG_PAX enabled, but no PaX options are enabled."
68964+#endif
68965+
68966+void gr_handle_brute_attach(unsigned long mm_flags);
68967+void gr_handle_brute_check(void);
68968+void gr_handle_kernel_exploit(void);
68969+int gr_process_user_ban(void);
68970+
68971+char gr_roletype_to_char(void);
68972+
68973+int gr_acl_enable_at_secure(void);
68974+
68975+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
68976+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
68977+
68978+void gr_del_task_from_ip_table(struct task_struct *p);
68979+
68980+int gr_pid_is_chrooted(struct task_struct *p);
68981+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
68982+int gr_handle_chroot_nice(void);
68983+int gr_handle_chroot_sysctl(const int op);
68984+int gr_handle_chroot_setpriority(struct task_struct *p,
68985+ const int niceval);
68986+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
68987+int gr_handle_chroot_chroot(const struct dentry *dentry,
68988+ const struct vfsmount *mnt);
68989+void gr_handle_chroot_chdir(const struct path *path);
68990+int gr_handle_chroot_chmod(const struct dentry *dentry,
68991+ const struct vfsmount *mnt, const int mode);
68992+int gr_handle_chroot_mknod(const struct dentry *dentry,
68993+ const struct vfsmount *mnt, const int mode);
68994+int gr_handle_chroot_mount(const struct dentry *dentry,
68995+ const struct vfsmount *mnt,
68996+ const char *dev_name);
68997+int gr_handle_chroot_pivot(void);
68998+int gr_handle_chroot_unix(const pid_t pid);
68999+
69000+int gr_handle_rawio(const struct inode *inode);
69001+
69002+void gr_handle_ioperm(void);
69003+void gr_handle_iopl(void);
69004+
69005+umode_t gr_acl_umask(void);
69006+
69007+int gr_tpe_allow(const struct file *file);
69008+
69009+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
69010+void gr_clear_chroot_entries(struct task_struct *task);
69011+
69012+void gr_log_forkfail(const int retval);
69013+void gr_log_timechange(void);
69014+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
69015+void gr_log_chdir(const struct dentry *dentry,
69016+ const struct vfsmount *mnt);
69017+void gr_log_chroot_exec(const struct dentry *dentry,
69018+ const struct vfsmount *mnt);
69019+void gr_log_remount(const char *devname, const int retval);
69020+void gr_log_unmount(const char *devname, const int retval);
69021+void gr_log_mount(const char *from, const char *to, const int retval);
69022+void gr_log_textrel(struct vm_area_struct *vma);
69023+void gr_log_rwxmmap(struct file *file);
69024+void gr_log_rwxmprotect(struct file *file);
69025+
69026+int gr_handle_follow_link(const struct inode *parent,
69027+ const struct inode *inode,
69028+ const struct dentry *dentry,
69029+ const struct vfsmount *mnt);
69030+int gr_handle_fifo(const struct dentry *dentry,
69031+ const struct vfsmount *mnt,
69032+ const struct dentry *dir, const int flag,
69033+ const int acc_mode);
69034+int gr_handle_hardlink(const struct dentry *dentry,
69035+ const struct vfsmount *mnt,
69036+ struct inode *inode,
69037+ const int mode, const struct filename *to);
69038+
69039+int gr_is_capable(const int cap);
69040+int gr_is_capable_nolog(const int cap);
69041+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69042+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
69043+
69044+void gr_copy_label(struct task_struct *tsk);
69045+void gr_handle_crash(struct task_struct *task, const int sig);
69046+int gr_handle_signal(const struct task_struct *p, const int sig);
69047+int gr_check_crash_uid(const kuid_t uid);
69048+int gr_check_protected_task(const struct task_struct *task);
69049+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
69050+int gr_acl_handle_mmap(const struct file *file,
69051+ const unsigned long prot);
69052+int gr_acl_handle_mprotect(const struct file *file,
69053+ const unsigned long prot);
69054+int gr_check_hidden_task(const struct task_struct *tsk);
69055+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
69056+ const struct vfsmount *mnt);
69057+__u32 gr_acl_handle_utime(const struct dentry *dentry,
69058+ const struct vfsmount *mnt);
69059+__u32 gr_acl_handle_access(const struct dentry *dentry,
69060+ const struct vfsmount *mnt, const int fmode);
69061+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
69062+ const struct vfsmount *mnt, umode_t *mode);
69063+__u32 gr_acl_handle_chown(const struct dentry *dentry,
69064+ const struct vfsmount *mnt);
69065+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
69066+ const struct vfsmount *mnt);
69067+int gr_handle_ptrace(struct task_struct *task, const long request);
69068+int gr_handle_proc_ptrace(struct task_struct *task);
69069+__u32 gr_acl_handle_execve(const struct dentry *dentry,
69070+ const struct vfsmount *mnt);
69071+int gr_check_crash_exec(const struct file *filp);
69072+int gr_acl_is_enabled(void);
69073+void gr_set_kernel_label(struct task_struct *task);
69074+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
69075+ const kgid_t gid);
69076+int gr_set_proc_label(const struct dentry *dentry,
69077+ const struct vfsmount *mnt,
69078+ const int unsafe_flags);
69079+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
69080+ const struct vfsmount *mnt);
69081+__u32 gr_acl_handle_open(const struct dentry *dentry,
69082+ const struct vfsmount *mnt, int acc_mode);
69083+__u32 gr_acl_handle_creat(const struct dentry *dentry,
69084+ const struct dentry *p_dentry,
69085+ const struct vfsmount *p_mnt,
69086+ int open_flags, int acc_mode, const int imode);
69087+void gr_handle_create(const struct dentry *dentry,
69088+ const struct vfsmount *mnt);
69089+void gr_handle_proc_create(const struct dentry *dentry,
69090+ const struct inode *inode);
69091+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
69092+ const struct dentry *parent_dentry,
69093+ const struct vfsmount *parent_mnt,
69094+ const int mode);
69095+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
69096+ const struct dentry *parent_dentry,
69097+ const struct vfsmount *parent_mnt);
69098+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
69099+ const struct vfsmount *mnt);
69100+void gr_handle_delete(const ino_t ino, const dev_t dev);
69101+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
69102+ const struct vfsmount *mnt);
69103+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
69104+ const struct dentry *parent_dentry,
69105+ const struct vfsmount *parent_mnt,
69106+ const struct filename *from);
69107+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
69108+ const struct dentry *parent_dentry,
69109+ const struct vfsmount *parent_mnt,
69110+ const struct dentry *old_dentry,
69111+ const struct vfsmount *old_mnt, const struct filename *to);
69112+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
69113+int gr_acl_handle_rename(struct dentry *new_dentry,
69114+ struct dentry *parent_dentry,
69115+ const struct vfsmount *parent_mnt,
69116+ struct dentry *old_dentry,
69117+ struct inode *old_parent_inode,
69118+ struct vfsmount *old_mnt, const struct filename *newname);
69119+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69120+ struct dentry *old_dentry,
69121+ struct dentry *new_dentry,
69122+ struct vfsmount *mnt, const __u8 replace);
69123+__u32 gr_check_link(const struct dentry *new_dentry,
69124+ const struct dentry *parent_dentry,
69125+ const struct vfsmount *parent_mnt,
69126+ const struct dentry *old_dentry,
69127+ const struct vfsmount *old_mnt);
69128+int gr_acl_handle_filldir(const struct file *file, const char *name,
69129+ const unsigned int namelen, const ino_t ino);
69130+
69131+__u32 gr_acl_handle_unix(const struct dentry *dentry,
69132+ const struct vfsmount *mnt);
69133+void gr_acl_handle_exit(void);
69134+void gr_acl_handle_psacct(struct task_struct *task, const long code);
69135+int gr_acl_handle_procpidmem(const struct task_struct *task);
69136+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
69137+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
69138+void gr_audit_ptrace(struct task_struct *task);
69139+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
69140+void gr_put_exec_file(struct task_struct *task);
69141+
69142+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
69143+
69144+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
69145+extern void gr_learn_resource(const struct task_struct *task, const int res,
69146+ const unsigned long wanted, const int gt);
69147+#else
69148+static inline void gr_learn_resource(const struct task_struct *task, const int res,
69149+ const unsigned long wanted, const int gt)
69150+{
69151+}
69152+#endif
69153+
69154+#ifdef CONFIG_GRKERNSEC_RESLOG
69155+extern void gr_log_resource(const struct task_struct *task, const int res,
69156+ const unsigned long wanted, const int gt);
69157+#else
69158+static inline void gr_log_resource(const struct task_struct *task, const int res,
69159+ const unsigned long wanted, const int gt)
69160+{
69161+}
69162+#endif
69163+
69164+#ifdef CONFIG_GRKERNSEC
69165+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
69166+void gr_handle_vm86(void);
69167+void gr_handle_mem_readwrite(u64 from, u64 to);
69168+
69169+void gr_log_badprocpid(const char *entry);
69170+
69171+extern int grsec_enable_dmesg;
69172+extern int grsec_disable_privio;
69173+
69174+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
69175+extern kgid_t grsec_proc_gid;
69176+#endif
69177+
69178+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69179+extern int grsec_enable_chroot_findtask;
69180+#endif
69181+#ifdef CONFIG_GRKERNSEC_SETXID
69182+extern int grsec_enable_setxid;
69183+#endif
69184+#endif
69185+
69186+#endif
69187diff --git a/include/linux/grsock.h b/include/linux/grsock.h
69188new file mode 100644
69189index 0000000..e7ffaaf
69190--- /dev/null
69191+++ b/include/linux/grsock.h
69192@@ -0,0 +1,19 @@
69193+#ifndef __GRSOCK_H
69194+#define __GRSOCK_H
69195+
69196+extern void gr_attach_curr_ip(const struct sock *sk);
69197+extern int gr_handle_sock_all(const int family, const int type,
69198+ const int protocol);
69199+extern int gr_handle_sock_server(const struct sockaddr *sck);
69200+extern int gr_handle_sock_server_other(const struct sock *sck);
69201+extern int gr_handle_sock_client(const struct sockaddr *sck);
69202+extern int gr_search_connect(struct socket * sock,
69203+ struct sockaddr_in * addr);
69204+extern int gr_search_bind(struct socket * sock,
69205+ struct sockaddr_in * addr);
69206+extern int gr_search_listen(struct socket * sock);
69207+extern int gr_search_accept(struct socket * sock);
69208+extern int gr_search_socket(const int domain, const int type,
69209+ const int protocol);
69210+
69211+#endif
69212diff --git a/include/linux/highmem.h b/include/linux/highmem.h
69213index 7fb31da..08b5114 100644
69214--- a/include/linux/highmem.h
69215+++ b/include/linux/highmem.h
69216@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
69217 kunmap_atomic(kaddr);
69218 }
69219
69220+static inline void sanitize_highpage(struct page *page)
69221+{
69222+ void *kaddr;
69223+ unsigned long flags;
69224+
69225+ local_irq_save(flags);
69226+ kaddr = kmap_atomic(page);
69227+ clear_page(kaddr);
69228+ kunmap_atomic(kaddr);
69229+ local_irq_restore(flags);
69230+}
69231+
69232 static inline void zero_user_segments(struct page *page,
69233 unsigned start1, unsigned end1,
69234 unsigned start2, unsigned end2)
69235diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
69236index 1c7b89a..7f52502 100644
69237--- a/include/linux/hwmon-sysfs.h
69238+++ b/include/linux/hwmon-sysfs.h
69239@@ -25,7 +25,8 @@
69240 struct sensor_device_attribute{
69241 struct device_attribute dev_attr;
69242 int index;
69243-};
69244+} __do_const;
69245+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
69246 #define to_sensor_dev_attr(_dev_attr) \
69247 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
69248
69249@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
69250 struct device_attribute dev_attr;
69251 u8 index;
69252 u8 nr;
69253-};
69254+} __do_const;
69255 #define to_sensor_dev_attr_2(_dev_attr) \
69256 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
69257
69258diff --git a/include/linux/i2c.h b/include/linux/i2c.h
69259index d0c4db7..61b3577 100644
69260--- a/include/linux/i2c.h
69261+++ b/include/linux/i2c.h
69262@@ -369,6 +369,7 @@ struct i2c_algorithm {
69263 /* To determine what the adapter supports */
69264 u32 (*functionality) (struct i2c_adapter *);
69265 };
69266+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
69267
69268 /*
69269 * i2c_adapter is the structure used to identify a physical i2c bus along
69270diff --git a/include/linux/i2o.h b/include/linux/i2o.h
69271index d23c3c2..eb63c81 100644
69272--- a/include/linux/i2o.h
69273+++ b/include/linux/i2o.h
69274@@ -565,7 +565,7 @@ struct i2o_controller {
69275 struct i2o_device *exec; /* Executive */
69276 #if BITS_PER_LONG == 64
69277 spinlock_t context_list_lock; /* lock for context_list */
69278- atomic_t context_list_counter; /* needed for unique contexts */
69279+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
69280 struct list_head context_list; /* list of context id's
69281 and pointers */
69282 #endif
69283diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
69284index aff7ad8..3942bbd 100644
69285--- a/include/linux/if_pppox.h
69286+++ b/include/linux/if_pppox.h
69287@@ -76,7 +76,7 @@ struct pppox_proto {
69288 int (*ioctl)(struct socket *sock, unsigned int cmd,
69289 unsigned long arg);
69290 struct module *owner;
69291-};
69292+} __do_const;
69293
69294 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
69295 extern void unregister_pppox_proto(int proto_num);
69296diff --git a/include/linux/init.h b/include/linux/init.h
69297index 8618147..0821126 100644
69298--- a/include/linux/init.h
69299+++ b/include/linux/init.h
69300@@ -39,9 +39,36 @@
69301 * Also note, that this data cannot be "const".
69302 */
69303
69304+#ifdef MODULE
69305+#define add_init_latent_entropy
69306+#define add_devinit_latent_entropy
69307+#define add_cpuinit_latent_entropy
69308+#define add_meminit_latent_entropy
69309+#else
69310+#define add_init_latent_entropy __latent_entropy
69311+
69312+#ifdef CONFIG_HOTPLUG
69313+#define add_devinit_latent_entropy
69314+#else
69315+#define add_devinit_latent_entropy __latent_entropy
69316+#endif
69317+
69318+#ifdef CONFIG_HOTPLUG_CPU
69319+#define add_cpuinit_latent_entropy
69320+#else
69321+#define add_cpuinit_latent_entropy __latent_entropy
69322+#endif
69323+
69324+#ifdef CONFIG_MEMORY_HOTPLUG
69325+#define add_meminit_latent_entropy
69326+#else
69327+#define add_meminit_latent_entropy __latent_entropy
69328+#endif
69329+#endif
69330+
69331 /* These are for everybody (although not all archs will actually
69332 discard it in modules) */
69333-#define __init __section(.init.text) __cold notrace
69334+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
69335 #define __initdata __section(.init.data)
69336 #define __initconst __constsection(.init.rodata)
69337 #define __exitdata __section(.exit.data)
69338@@ -94,7 +121,7 @@
69339 #define __exit __section(.exit.text) __exitused __cold notrace
69340
69341 /* Used for HOTPLUG_CPU */
69342-#define __cpuinit __section(.cpuinit.text) __cold notrace
69343+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
69344 #define __cpuinitdata __section(.cpuinit.data)
69345 #define __cpuinitconst __constsection(.cpuinit.rodata)
69346 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
69347@@ -102,7 +129,7 @@
69348 #define __cpuexitconst __constsection(.cpuexit.rodata)
69349
69350 /* Used for MEMORY_HOTPLUG */
69351-#define __meminit __section(.meminit.text) __cold notrace
69352+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
69353 #define __meminitdata __section(.meminit.data)
69354 #define __meminitconst __constsection(.meminit.rodata)
69355 #define __memexit __section(.memexit.text) __exitused __cold notrace
69356diff --git a/include/linux/init_task.h b/include/linux/init_task.h
69357index 5cd0f09..c9f67cc 100644
69358--- a/include/linux/init_task.h
69359+++ b/include/linux/init_task.h
69360@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
69361
69362 #define INIT_TASK_COMM "swapper"
69363
69364+#ifdef CONFIG_X86
69365+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
69366+#else
69367+#define INIT_TASK_THREAD_INFO
69368+#endif
69369+
69370 /*
69371 * INIT_TASK is used to set up the first task table, touch at
69372 * your own risk!. Base=0, limit=0x1fffff (=2MB)
69373@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
69374 RCU_POINTER_INITIALIZER(cred, &init_cred), \
69375 .comm = INIT_TASK_COMM, \
69376 .thread = INIT_THREAD, \
69377+ INIT_TASK_THREAD_INFO \
69378 .fs = &init_fs, \
69379 .files = &init_files, \
69380 .signal = &init_signals, \
69381diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
69382index 5fa5afe..ac55b25 100644
69383--- a/include/linux/interrupt.h
69384+++ b/include/linux/interrupt.h
69385@@ -430,7 +430,7 @@ enum
69386 /* map softirq index to softirq name. update 'softirq_to_name' in
69387 * kernel/softirq.c when adding a new softirq.
69388 */
69389-extern char *softirq_to_name[NR_SOFTIRQS];
69390+extern const char * const softirq_to_name[NR_SOFTIRQS];
69391
69392 /* softirq mask and active fields moved to irq_cpustat_t in
69393 * asm/hardirq.h to get better cache usage. KAO
69394@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
69395
69396 struct softirq_action
69397 {
69398- void (*action)(struct softirq_action *);
69399-};
69400+ void (*action)(void);
69401+} __no_const;
69402
69403 asmlinkage void do_softirq(void);
69404 asmlinkage void __do_softirq(void);
69405-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
69406+extern void open_softirq(int nr, void (*action)(void));
69407 extern void softirq_init(void);
69408 extern void __raise_softirq_irqoff(unsigned int nr);
69409
69410diff --git a/include/linux/iommu.h b/include/linux/iommu.h
69411index ba3b8a9..7e14ed8 100644
69412--- a/include/linux/iommu.h
69413+++ b/include/linux/iommu.h
69414@@ -113,7 +113,7 @@ struct iommu_ops {
69415 u32 (*domain_get_windows)(struct iommu_domain *domain);
69416
69417 unsigned long pgsize_bitmap;
69418-};
69419+} __do_const;
69420
69421 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
69422 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
69423diff --git a/include/linux/ioport.h b/include/linux/ioport.h
69424index 85ac9b9b..e5759ab 100644
69425--- a/include/linux/ioport.h
69426+++ b/include/linux/ioport.h
69427@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
69428 int adjust_resource(struct resource *res, resource_size_t start,
69429 resource_size_t size);
69430 resource_size_t resource_alignment(struct resource *res);
69431-static inline resource_size_t resource_size(const struct resource *res)
69432+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
69433 {
69434 return res->end - res->start + 1;
69435 }
69436diff --git a/include/linux/irq.h b/include/linux/irq.h
69437index bc4e066..50468a9 100644
69438--- a/include/linux/irq.h
69439+++ b/include/linux/irq.h
69440@@ -328,7 +328,8 @@ struct irq_chip {
69441 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
69442
69443 unsigned long flags;
69444-};
69445+} __do_const;
69446+typedef struct irq_chip __no_const irq_chip_no_const;
69447
69448 /*
69449 * irq_chip specific flags
69450diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
69451index 3fd8e42..a73e966 100644
69452--- a/include/linux/irqchip/arm-gic.h
69453+++ b/include/linux/irqchip/arm-gic.h
69454@@ -59,9 +59,11 @@
69455
69456 #ifndef __ASSEMBLY__
69457
69458+#include <linux/irq.h>
69459+
69460 struct device_node;
69461
69462-extern struct irq_chip gic_arch_extn;
69463+extern irq_chip_no_const gic_arch_extn;
69464
69465 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
69466 u32 offset, struct device_node *);
69467diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
69468index 6883e19..06992b1 100644
69469--- a/include/linux/kallsyms.h
69470+++ b/include/linux/kallsyms.h
69471@@ -15,7 +15,8 @@
69472
69473 struct module;
69474
69475-#ifdef CONFIG_KALLSYMS
69476+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
69477+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
69478 /* Lookup the address for a symbol. Returns 0 if not found. */
69479 unsigned long kallsyms_lookup_name(const char *name);
69480
69481@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
69482 /* Stupid that this does nothing, but I didn't create this mess. */
69483 #define __print_symbol(fmt, addr)
69484 #endif /*CONFIG_KALLSYMS*/
69485+#else /* when included by kallsyms.c, vsnprintf.c, or
69486+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
69487+extern void __print_symbol(const char *fmt, unsigned long address);
69488+extern int sprint_backtrace(char *buffer, unsigned long address);
69489+extern int sprint_symbol(char *buffer, unsigned long address);
69490+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
69491+const char *kallsyms_lookup(unsigned long addr,
69492+ unsigned long *symbolsize,
69493+ unsigned long *offset,
69494+ char **modname, char *namebuf);
69495+#endif
69496
69497 /* This macro allows us to keep printk typechecking */
69498 static __printf(1, 2)
69499diff --git a/include/linux/key-type.h b/include/linux/key-type.h
69500index 518a53a..5e28358 100644
69501--- a/include/linux/key-type.h
69502+++ b/include/linux/key-type.h
69503@@ -125,7 +125,7 @@ struct key_type {
69504 /* internal fields */
69505 struct list_head link; /* link in types list */
69506 struct lock_class_key lock_class; /* key->sem lock class */
69507-};
69508+} __do_const;
69509
69510 extern struct key_type key_type_keyring;
69511
69512diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
69513index c6e091b..a940adf 100644
69514--- a/include/linux/kgdb.h
69515+++ b/include/linux/kgdb.h
69516@@ -52,7 +52,7 @@ extern int kgdb_connected;
69517 extern int kgdb_io_module_registered;
69518
69519 extern atomic_t kgdb_setting_breakpoint;
69520-extern atomic_t kgdb_cpu_doing_single_step;
69521+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
69522
69523 extern struct task_struct *kgdb_usethread;
69524 extern struct task_struct *kgdb_contthread;
69525@@ -254,7 +254,7 @@ struct kgdb_arch {
69526 void (*correct_hw_break)(void);
69527
69528 void (*enable_nmi)(bool on);
69529-};
69530+} __do_const;
69531
69532 /**
69533 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
69534@@ -279,7 +279,7 @@ struct kgdb_io {
69535 void (*pre_exception) (void);
69536 void (*post_exception) (void);
69537 int is_console;
69538-};
69539+} __do_const;
69540
69541 extern struct kgdb_arch arch_kgdb_ops;
69542
69543diff --git a/include/linux/kmod.h b/include/linux/kmod.h
69544index 5398d58..5883a34 100644
69545--- a/include/linux/kmod.h
69546+++ b/include/linux/kmod.h
69547@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
69548 * usually useless though. */
69549 extern __printf(2, 3)
69550 int __request_module(bool wait, const char *name, ...);
69551+extern __printf(3, 4)
69552+int ___request_module(bool wait, char *param_name, const char *name, ...);
69553 #define request_module(mod...) __request_module(true, mod)
69554 #define request_module_nowait(mod...) __request_module(false, mod)
69555 #define try_then_request_module(x, mod...) \
69556diff --git a/include/linux/kobject.h b/include/linux/kobject.h
69557index 939b112..ed6ed51 100644
69558--- a/include/linux/kobject.h
69559+++ b/include/linux/kobject.h
69560@@ -111,7 +111,7 @@ struct kobj_type {
69561 struct attribute **default_attrs;
69562 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
69563 const void *(*namespace)(struct kobject *kobj);
69564-};
69565+} __do_const;
69566
69567 struct kobj_uevent_env {
69568 char *envp[UEVENT_NUM_ENVP];
69569@@ -134,6 +134,7 @@ struct kobj_attribute {
69570 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
69571 const char *buf, size_t count);
69572 };
69573+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
69574
69575 extern const struct sysfs_ops kobj_sysfs_ops;
69576
69577diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
69578index f66b065..c2c29b4 100644
69579--- a/include/linux/kobject_ns.h
69580+++ b/include/linux/kobject_ns.h
69581@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
69582 const void *(*netlink_ns)(struct sock *sk);
69583 const void *(*initial_ns)(void);
69584 void (*drop_ns)(void *);
69585-};
69586+} __do_const;
69587
69588 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
69589 int kobj_ns_type_registered(enum kobj_ns_type type);
69590diff --git a/include/linux/kref.h b/include/linux/kref.h
69591index 7419c02..aa2f02d 100644
69592--- a/include/linux/kref.h
69593+++ b/include/linux/kref.h
69594@@ -65,7 +65,7 @@ static inline void kref_get(struct kref *kref)
69595 static inline int kref_sub(struct kref *kref, unsigned int count,
69596 void (*release)(struct kref *kref))
69597 {
69598- WARN_ON(release == NULL);
69599+ BUG_ON(release == NULL);
69600
69601 if (atomic_sub_and_test((int) count, &kref->refcount)) {
69602 release(kref);
69603diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
69604index c139582..0b5b102 100644
69605--- a/include/linux/kvm_host.h
69606+++ b/include/linux/kvm_host.h
69607@@ -424,7 +424,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
69608 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
69609 void vcpu_put(struct kvm_vcpu *vcpu);
69610
69611-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
69612+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
69613 struct module *module);
69614 void kvm_exit(void);
69615
69616@@ -582,7 +582,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
69617 struct kvm_guest_debug *dbg);
69618 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
69619
69620-int kvm_arch_init(void *opaque);
69621+int kvm_arch_init(const void *opaque);
69622 void kvm_arch_exit(void);
69623
69624 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
69625diff --git a/include/linux/libata.h b/include/linux/libata.h
69626index eae7a05..2cdd875 100644
69627--- a/include/linux/libata.h
69628+++ b/include/linux/libata.h
69629@@ -919,7 +919,7 @@ struct ata_port_operations {
69630 * fields must be pointers.
69631 */
69632 const struct ata_port_operations *inherits;
69633-};
69634+} __do_const;
69635
69636 struct ata_port_info {
69637 unsigned long flags;
69638diff --git a/include/linux/list.h b/include/linux/list.h
69639index 6a1f8df..eaec1ff 100644
69640--- a/include/linux/list.h
69641+++ b/include/linux/list.h
69642@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
69643 extern void list_del(struct list_head *entry);
69644 #endif
69645
69646+extern void __pax_list_add(struct list_head *new,
69647+ struct list_head *prev,
69648+ struct list_head *next);
69649+static inline void pax_list_add(struct list_head *new, struct list_head *head)
69650+{
69651+ __pax_list_add(new, head, head->next);
69652+}
69653+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
69654+{
69655+ __pax_list_add(new, head->prev, head);
69656+}
69657+extern void pax_list_del(struct list_head *entry);
69658+
69659 /**
69660 * list_replace - replace old entry by new one
69661 * @old : the element to be replaced
69662@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
69663 INIT_LIST_HEAD(entry);
69664 }
69665
69666+extern void pax_list_del_init(struct list_head *entry);
69667+
69668 /**
69669 * list_move - delete from one list and add as another's head
69670 * @list: the entry to move
69671diff --git a/include/linux/math64.h b/include/linux/math64.h
69672index b8ba855..0148090 100644
69673--- a/include/linux/math64.h
69674+++ b/include/linux/math64.h
69675@@ -14,7 +14,7 @@
69676 * This is commonly provided by 32bit archs to provide an optimized 64bit
69677 * divide.
69678 */
69679-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69680+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69681 {
69682 *remainder = dividend % divisor;
69683 return dividend / divisor;
69684@@ -50,7 +50,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
69685 #define div64_long(x,y) div_s64((x),(y))
69686
69687 #ifndef div_u64_rem
69688-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69689+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69690 {
69691 *remainder = do_div(dividend, divisor);
69692 return dividend;
69693@@ -79,7 +79,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
69694 * divide.
69695 */
69696 #ifndef div_u64
69697-static inline u64 div_u64(u64 dividend, u32 divisor)
69698+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
69699 {
69700 u32 remainder;
69701 return div_u64_rem(dividend, divisor, &remainder);
69702diff --git a/include/linux/mm.h b/include/linux/mm.h
69703index e2091b8..821db54 100644
69704--- a/include/linux/mm.h
69705+++ b/include/linux/mm.h
69706@@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
69707 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
69708 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
69709 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
69710+
69711+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
69712+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
69713+#endif
69714+
69715 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
69716
69717 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
69718@@ -202,8 +207,8 @@ struct vm_operations_struct {
69719 /* called by access_process_vm when get_user_pages() fails, typically
69720 * for use by special VMAs that can switch between memory and hardware
69721 */
69722- int (*access)(struct vm_area_struct *vma, unsigned long addr,
69723- void *buf, int len, int write);
69724+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
69725+ void *buf, size_t len, int write);
69726 #ifdef CONFIG_NUMA
69727 /*
69728 * set_policy() op must add a reference to any non-NULL @new mempolicy
69729@@ -233,6 +238,7 @@ struct vm_operations_struct {
69730 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
69731 unsigned long size, pgoff_t pgoff);
69732 };
69733+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
69734
69735 struct mmu_gather;
69736 struct inode;
69737@@ -970,8 +976,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
69738 unsigned long *pfn);
69739 int follow_phys(struct vm_area_struct *vma, unsigned long address,
69740 unsigned int flags, unsigned long *prot, resource_size_t *phys);
69741-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
69742- void *buf, int len, int write);
69743+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
69744+ void *buf, size_t len, int write);
69745
69746 static inline void unmap_shared_mapping_range(struct address_space *mapping,
69747 loff_t const holebegin, loff_t const holelen)
69748@@ -1010,9 +1016,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
69749 }
69750 #endif
69751
69752-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
69753-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
69754- void *buf, int len, int write);
69755+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
69756+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
69757+ void *buf, size_t len, int write);
69758
69759 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69760 unsigned long start, unsigned long nr_pages,
69761@@ -1043,34 +1049,6 @@ int set_page_dirty(struct page *page);
69762 int set_page_dirty_lock(struct page *page);
69763 int clear_page_dirty_for_io(struct page *page);
69764
69765-/* Is the vma a continuation of the stack vma above it? */
69766-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
69767-{
69768- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
69769-}
69770-
69771-static inline int stack_guard_page_start(struct vm_area_struct *vma,
69772- unsigned long addr)
69773-{
69774- return (vma->vm_flags & VM_GROWSDOWN) &&
69775- (vma->vm_start == addr) &&
69776- !vma_growsdown(vma->vm_prev, addr);
69777-}
69778-
69779-/* Is the vma a continuation of the stack vma below it? */
69780-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
69781-{
69782- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
69783-}
69784-
69785-static inline int stack_guard_page_end(struct vm_area_struct *vma,
69786- unsigned long addr)
69787-{
69788- return (vma->vm_flags & VM_GROWSUP) &&
69789- (vma->vm_end == addr) &&
69790- !vma_growsup(vma->vm_next, addr);
69791-}
69792-
69793 extern pid_t
69794 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
69795
69796@@ -1173,6 +1151,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
69797 }
69798 #endif
69799
69800+#ifdef CONFIG_MMU
69801+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
69802+#else
69803+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
69804+{
69805+ return __pgprot(0);
69806+}
69807+#endif
69808+
69809 int vma_wants_writenotify(struct vm_area_struct *vma);
69810
69811 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
69812@@ -1191,8 +1178,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
69813 {
69814 return 0;
69815 }
69816+
69817+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
69818+ unsigned long address)
69819+{
69820+ return 0;
69821+}
69822 #else
69823 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
69824+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
69825 #endif
69826
69827 #ifdef __PAGETABLE_PMD_FOLDED
69828@@ -1201,8 +1195,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
69829 {
69830 return 0;
69831 }
69832+
69833+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
69834+ unsigned long address)
69835+{
69836+ return 0;
69837+}
69838 #else
69839 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
69840+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
69841 #endif
69842
69843 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
69844@@ -1220,11 +1221,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
69845 NULL: pud_offset(pgd, address);
69846 }
69847
69848+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
69849+{
69850+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
69851+ NULL: pud_offset(pgd, address);
69852+}
69853+
69854 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
69855 {
69856 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
69857 NULL: pmd_offset(pud, address);
69858 }
69859+
69860+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
69861+{
69862+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
69863+ NULL: pmd_offset(pud, address);
69864+}
69865 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
69866
69867 #if USE_SPLIT_PTLOCKS
69868@@ -1455,6 +1468,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
69869 unsigned long len, unsigned long prot, unsigned long flags,
69870 unsigned long pgoff, unsigned long *populate);
69871 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
69872+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
69873
69874 #ifdef CONFIG_MMU
69875 extern int __mm_populate(unsigned long addr, unsigned long len,
69876@@ -1483,6 +1497,7 @@ struct vm_unmapped_area_info {
69877 unsigned long high_limit;
69878 unsigned long align_mask;
69879 unsigned long align_offset;
69880+ unsigned long threadstack_offset;
69881 };
69882
69883 extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
69884@@ -1561,6 +1576,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
69885 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
69886 struct vm_area_struct **pprev);
69887
69888+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
69889+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
69890+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
69891+
69892 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
69893 NULL if none. Assume start_addr < end_addr. */
69894 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
69895@@ -1589,15 +1608,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
69896 return vma;
69897 }
69898
69899-#ifdef CONFIG_MMU
69900-pgprot_t vm_get_page_prot(unsigned long vm_flags);
69901-#else
69902-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
69903-{
69904- return __pgprot(0);
69905-}
69906-#endif
69907-
69908 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
69909 unsigned long change_prot_numa(struct vm_area_struct *vma,
69910 unsigned long start, unsigned long end);
69911@@ -1649,6 +1659,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
69912 static inline void vm_stat_account(struct mm_struct *mm,
69913 unsigned long flags, struct file *file, long pages)
69914 {
69915+
69916+#ifdef CONFIG_PAX_RANDMMAP
69917+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
69918+#endif
69919+
69920 mm->total_vm += pages;
69921 }
69922 #endif /* CONFIG_PROC_FS */
69923@@ -1725,7 +1740,7 @@ extern int unpoison_memory(unsigned long pfn);
69924 extern int sysctl_memory_failure_early_kill;
69925 extern int sysctl_memory_failure_recovery;
69926 extern void shake_page(struct page *p, int access);
69927-extern atomic_long_t num_poisoned_pages;
69928+extern atomic_long_unchecked_t num_poisoned_pages;
69929 extern int soft_offline_page(struct page *page, int flags);
69930
69931 extern void dump_page(struct page *page);
69932@@ -1756,5 +1771,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
69933 static inline bool page_is_guard(struct page *page) { return false; }
69934 #endif /* CONFIG_DEBUG_PAGEALLOC */
69935
69936+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
69937+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
69938+#else
69939+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
69940+#endif
69941+
69942 #endif /* __KERNEL__ */
69943 #endif /* _LINUX_MM_H */
69944diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
69945index ace9a5f..81bdb59 100644
69946--- a/include/linux/mm_types.h
69947+++ b/include/linux/mm_types.h
69948@@ -289,6 +289,8 @@ struct vm_area_struct {
69949 #ifdef CONFIG_NUMA
69950 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
69951 #endif
69952+
69953+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
69954 };
69955
69956 struct core_thread {
69957@@ -437,6 +439,24 @@ struct mm_struct {
69958 int first_nid;
69959 #endif
69960 struct uprobes_state uprobes_state;
69961+
69962+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
69963+ unsigned long pax_flags;
69964+#endif
69965+
69966+#ifdef CONFIG_PAX_DLRESOLVE
69967+ unsigned long call_dl_resolve;
69968+#endif
69969+
69970+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
69971+ unsigned long call_syscall;
69972+#endif
69973+
69974+#ifdef CONFIG_PAX_ASLR
69975+ unsigned long delta_mmap; /* randomized offset */
69976+ unsigned long delta_stack; /* randomized offset */
69977+#endif
69978+
69979 };
69980
69981 /* first nid will either be a valid NID or one of these values */
69982diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
69983index c5d5278..f0b68c8 100644
69984--- a/include/linux/mmiotrace.h
69985+++ b/include/linux/mmiotrace.h
69986@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
69987 /* Called from ioremap.c */
69988 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
69989 void __iomem *addr);
69990-extern void mmiotrace_iounmap(volatile void __iomem *addr);
69991+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
69992
69993 /* For anyone to insert markers. Remember trailing newline. */
69994 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
69995@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
69996 {
69997 }
69998
69999-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
70000+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
70001 {
70002 }
70003
70004diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
70005index c74092e..b663967 100644
70006--- a/include/linux/mmzone.h
70007+++ b/include/linux/mmzone.h
70008@@ -396,7 +396,7 @@ struct zone {
70009 unsigned long flags; /* zone flags, see below */
70010
70011 /* Zone statistics */
70012- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70013+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70014
70015 /*
70016 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
70017diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
70018index 779cf7c..e6768240 100644
70019--- a/include/linux/mod_devicetable.h
70020+++ b/include/linux/mod_devicetable.h
70021@@ -12,7 +12,7 @@
70022 typedef unsigned long kernel_ulong_t;
70023 #endif
70024
70025-#define PCI_ANY_ID (~0)
70026+#define PCI_ANY_ID ((__u16)~0)
70027
70028 struct pci_device_id {
70029 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
70030@@ -138,7 +138,7 @@ struct usb_device_id {
70031 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
70032 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
70033
70034-#define HID_ANY_ID (~0)
70035+#define HID_ANY_ID (~0U)
70036 #define HID_BUS_ANY 0xffff
70037 #define HID_GROUP_ANY 0x0000
70038
70039@@ -464,7 +464,7 @@ struct dmi_system_id {
70040 const char *ident;
70041 struct dmi_strmatch matches[4];
70042 void *driver_data;
70043-};
70044+} __do_const;
70045 /*
70046 * struct dmi_device_id appears during expansion of
70047 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
70048diff --git a/include/linux/module.h b/include/linux/module.h
70049index ead1b57..81a3b6c 100644
70050--- a/include/linux/module.h
70051+++ b/include/linux/module.h
70052@@ -17,9 +17,11 @@
70053 #include <linux/moduleparam.h>
70054 #include <linux/tracepoint.h>
70055 #include <linux/export.h>
70056+#include <linux/fs.h>
70057
70058 #include <linux/percpu.h>
70059 #include <asm/module.h>
70060+#include <asm/pgtable.h>
70061
70062 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
70063 #define MODULE_SIG_STRING "~Module signature appended~\n"
70064@@ -54,12 +56,13 @@ struct module_attribute {
70065 int (*test)(struct module *);
70066 void (*free)(struct module *);
70067 };
70068+typedef struct module_attribute __no_const module_attribute_no_const;
70069
70070 struct module_version_attribute {
70071 struct module_attribute mattr;
70072 const char *module_name;
70073 const char *version;
70074-} __attribute__ ((__aligned__(sizeof(void *))));
70075+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
70076
70077 extern ssize_t __modver_version_show(struct module_attribute *,
70078 struct module_kobject *, char *);
70079@@ -232,7 +235,7 @@ struct module
70080
70081 /* Sysfs stuff. */
70082 struct module_kobject mkobj;
70083- struct module_attribute *modinfo_attrs;
70084+ module_attribute_no_const *modinfo_attrs;
70085 const char *version;
70086 const char *srcversion;
70087 struct kobject *holders_dir;
70088@@ -281,19 +284,16 @@ struct module
70089 int (*init)(void);
70090
70091 /* If this is non-NULL, vfree after init() returns */
70092- void *module_init;
70093+ void *module_init_rx, *module_init_rw;
70094
70095 /* Here is the actual code + data, vfree'd on unload. */
70096- void *module_core;
70097+ void *module_core_rx, *module_core_rw;
70098
70099 /* Here are the sizes of the init and core sections */
70100- unsigned int init_size, core_size;
70101+ unsigned int init_size_rw, core_size_rw;
70102
70103 /* The size of the executable code in each section. */
70104- unsigned int init_text_size, core_text_size;
70105-
70106- /* Size of RO sections of the module (text+rodata) */
70107- unsigned int init_ro_size, core_ro_size;
70108+ unsigned int init_size_rx, core_size_rx;
70109
70110 /* Arch-specific module values */
70111 struct mod_arch_specific arch;
70112@@ -349,6 +349,10 @@ struct module
70113 #ifdef CONFIG_EVENT_TRACING
70114 struct ftrace_event_call **trace_events;
70115 unsigned int num_trace_events;
70116+ struct file_operations trace_id;
70117+ struct file_operations trace_enable;
70118+ struct file_operations trace_format;
70119+ struct file_operations trace_filter;
70120 #endif
70121 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
70122 unsigned int num_ftrace_callsites;
70123@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
70124 bool is_module_percpu_address(unsigned long addr);
70125 bool is_module_text_address(unsigned long addr);
70126
70127+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
70128+{
70129+
70130+#ifdef CONFIG_PAX_KERNEXEC
70131+ if (ktla_ktva(addr) >= (unsigned long)start &&
70132+ ktla_ktva(addr) < (unsigned long)start + size)
70133+ return 1;
70134+#endif
70135+
70136+ return ((void *)addr >= start && (void *)addr < start + size);
70137+}
70138+
70139+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
70140+{
70141+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
70142+}
70143+
70144+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
70145+{
70146+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
70147+}
70148+
70149+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
70150+{
70151+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
70152+}
70153+
70154+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
70155+{
70156+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
70157+}
70158+
70159 static inline int within_module_core(unsigned long addr, const struct module *mod)
70160 {
70161- return (unsigned long)mod->module_core <= addr &&
70162- addr < (unsigned long)mod->module_core + mod->core_size;
70163+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
70164 }
70165
70166 static inline int within_module_init(unsigned long addr, const struct module *mod)
70167 {
70168- return (unsigned long)mod->module_init <= addr &&
70169- addr < (unsigned long)mod->module_init + mod->init_size;
70170+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
70171 }
70172
70173 /* Search for module by name: must hold module_mutex. */
70174diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
70175index 560ca53..ef621ef 100644
70176--- a/include/linux/moduleloader.h
70177+++ b/include/linux/moduleloader.h
70178@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
70179 sections. Returns NULL on failure. */
70180 void *module_alloc(unsigned long size);
70181
70182+#ifdef CONFIG_PAX_KERNEXEC
70183+void *module_alloc_exec(unsigned long size);
70184+#else
70185+#define module_alloc_exec(x) module_alloc(x)
70186+#endif
70187+
70188 /* Free memory returned from module_alloc. */
70189 void module_free(struct module *mod, void *module_region);
70190
70191+#ifdef CONFIG_PAX_KERNEXEC
70192+void module_free_exec(struct module *mod, void *module_region);
70193+#else
70194+#define module_free_exec(x, y) module_free((x), (y))
70195+#endif
70196+
70197 /*
70198 * Apply the given relocation to the (simplified) ELF. Return -error
70199 * or 0.
70200@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
70201 unsigned int relsec,
70202 struct module *me)
70203 {
70204+#ifdef CONFIG_MODULES
70205 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
70206+#endif
70207 return -ENOEXEC;
70208 }
70209 #endif
70210@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
70211 unsigned int relsec,
70212 struct module *me)
70213 {
70214+#ifdef CONFIG_MODULES
70215 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
70216+#endif
70217 return -ENOEXEC;
70218 }
70219 #endif
70220diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
70221index 137b419..fe663ec 100644
70222--- a/include/linux/moduleparam.h
70223+++ b/include/linux/moduleparam.h
70224@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
70225 * @len is usually just sizeof(string).
70226 */
70227 #define module_param_string(name, string, len, perm) \
70228- static const struct kparam_string __param_string_##name \
70229+ static const struct kparam_string __param_string_##name __used \
70230 = { len, string }; \
70231 __module_param_call(MODULE_PARAM_PREFIX, name, \
70232 &param_ops_string, \
70233@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
70234 */
70235 #define module_param_array_named(name, array, type, nump, perm) \
70236 param_check_##type(name, &(array)[0]); \
70237- static const struct kparam_array __param_arr_##name \
70238+ static const struct kparam_array __param_arr_##name __used \
70239 = { .max = ARRAY_SIZE(array), .num = nump, \
70240 .ops = &param_ops_##type, \
70241 .elemsize = sizeof(array[0]), .elem = array }; \
70242diff --git a/include/linux/namei.h b/include/linux/namei.h
70243index 5a5ff57..5ae5070 100644
70244--- a/include/linux/namei.h
70245+++ b/include/linux/namei.h
70246@@ -19,7 +19,7 @@ struct nameidata {
70247 unsigned seq;
70248 int last_type;
70249 unsigned depth;
70250- char *saved_names[MAX_NESTED_LINKS + 1];
70251+ const char *saved_names[MAX_NESTED_LINKS + 1];
70252 };
70253
70254 /*
70255@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
70256
70257 extern void nd_jump_link(struct nameidata *nd, struct path *path);
70258
70259-static inline void nd_set_link(struct nameidata *nd, char *path)
70260+static inline void nd_set_link(struct nameidata *nd, const char *path)
70261 {
70262 nd->saved_names[nd->depth] = path;
70263 }
70264
70265-static inline char *nd_get_link(struct nameidata *nd)
70266+static inline const char *nd_get_link(const struct nameidata *nd)
70267 {
70268 return nd->saved_names[nd->depth];
70269 }
70270diff --git a/include/linux/net.h b/include/linux/net.h
70271index aa16731..514b875 100644
70272--- a/include/linux/net.h
70273+++ b/include/linux/net.h
70274@@ -183,7 +183,7 @@ struct net_proto_family {
70275 int (*create)(struct net *net, struct socket *sock,
70276 int protocol, int kern);
70277 struct module *owner;
70278-};
70279+} __do_const;
70280
70281 struct iovec;
70282 struct kvec;
70283diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
70284index 6151e90..2e0afb0 100644
70285--- a/include/linux/netdevice.h
70286+++ b/include/linux/netdevice.h
70287@@ -1028,6 +1028,7 @@ struct net_device_ops {
70288 int (*ndo_change_carrier)(struct net_device *dev,
70289 bool new_carrier);
70290 };
70291+typedef struct net_device_ops __no_const net_device_ops_no_const;
70292
70293 /*
70294 * The DEVICE structure.
70295@@ -1094,7 +1095,7 @@ struct net_device {
70296 int iflink;
70297
70298 struct net_device_stats stats;
70299- atomic_long_t rx_dropped; /* dropped packets by core network
70300+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
70301 * Do not use this in drivers.
70302 */
70303
70304diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
70305index ee14284..bc65d63 100644
70306--- a/include/linux/netfilter.h
70307+++ b/include/linux/netfilter.h
70308@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
70309 #endif
70310 /* Use the module struct to lock set/get code in place */
70311 struct module *owner;
70312-};
70313+} __do_const;
70314
70315 /* Function to register/unregister hook points. */
70316 int nf_register_hook(struct nf_hook_ops *reg);
70317diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
70318index 7958e84..ed74d7a 100644
70319--- a/include/linux/netfilter/ipset/ip_set.h
70320+++ b/include/linux/netfilter/ipset/ip_set.h
70321@@ -98,7 +98,7 @@ struct ip_set_type_variant {
70322 /* Return true if "b" set is the same as "a"
70323 * according to the create set parameters */
70324 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
70325-};
70326+} __do_const;
70327
70328 /* The core set type structure */
70329 struct ip_set_type {
70330diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
70331index ecbb8e4..8a1c4e1 100644
70332--- a/include/linux/netfilter/nfnetlink.h
70333+++ b/include/linux/netfilter/nfnetlink.h
70334@@ -16,7 +16,7 @@ struct nfnl_callback {
70335 const struct nlattr * const cda[]);
70336 const struct nla_policy *policy; /* netlink attribute policy */
70337 const u_int16_t attr_count; /* number of nlattr's */
70338-};
70339+} __do_const;
70340
70341 struct nfnetlink_subsystem {
70342 const char *name;
70343diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
70344new file mode 100644
70345index 0000000..33f4af8
70346--- /dev/null
70347+++ b/include/linux/netfilter/xt_gradm.h
70348@@ -0,0 +1,9 @@
70349+#ifndef _LINUX_NETFILTER_XT_GRADM_H
70350+#define _LINUX_NETFILTER_XT_GRADM_H 1
70351+
70352+struct xt_gradm_mtinfo {
70353+ __u16 flags;
70354+ __u16 invflags;
70355+};
70356+
70357+#endif
70358diff --git a/include/linux/nls.h b/include/linux/nls.h
70359index 5dc635f..35f5e11 100644
70360--- a/include/linux/nls.h
70361+++ b/include/linux/nls.h
70362@@ -31,7 +31,7 @@ struct nls_table {
70363 const unsigned char *charset2upper;
70364 struct module *owner;
70365 struct nls_table *next;
70366-};
70367+} __do_const;
70368
70369 /* this value hold the maximum octet of charset */
70370 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
70371diff --git a/include/linux/notifier.h b/include/linux/notifier.h
70372index d65746e..62e72c2 100644
70373--- a/include/linux/notifier.h
70374+++ b/include/linux/notifier.h
70375@@ -51,7 +51,8 @@ struct notifier_block {
70376 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
70377 struct notifier_block __rcu *next;
70378 int priority;
70379-};
70380+} __do_const;
70381+typedef struct notifier_block __no_const notifier_block_no_const;
70382
70383 struct atomic_notifier_head {
70384 spinlock_t lock;
70385diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
70386index a4c5624..79d6d88 100644
70387--- a/include/linux/oprofile.h
70388+++ b/include/linux/oprofile.h
70389@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
70390 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
70391 char const * name, ulong * val);
70392
70393-/** Create a file for read-only access to an atomic_t. */
70394+/** Create a file for read-only access to an atomic_unchecked_t. */
70395 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
70396- char const * name, atomic_t * val);
70397+ char const * name, atomic_unchecked_t * val);
70398
70399 /** create a directory */
70400 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
70401diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
70402index 45fc162..01a4068 100644
70403--- a/include/linux/pci_hotplug.h
70404+++ b/include/linux/pci_hotplug.h
70405@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
70406 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
70407 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
70408 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
70409-};
70410+} __do_const;
70411+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
70412
70413 /**
70414 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
70415diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
70416index 1d795df..b0a6449 100644
70417--- a/include/linux/perf_event.h
70418+++ b/include/linux/perf_event.h
70419@@ -333,8 +333,8 @@ struct perf_event {
70420
70421 enum perf_event_active_state state;
70422 unsigned int attach_state;
70423- local64_t count;
70424- atomic64_t child_count;
70425+ local64_t count; /* PaX: fix it one day */
70426+ atomic64_unchecked_t child_count;
70427
70428 /*
70429 * These are the total time in nanoseconds that the event
70430@@ -385,8 +385,8 @@ struct perf_event {
70431 * These accumulate total time (in nanoseconds) that children
70432 * events have been enabled and running, respectively.
70433 */
70434- atomic64_t child_total_time_enabled;
70435- atomic64_t child_total_time_running;
70436+ atomic64_unchecked_t child_total_time_enabled;
70437+ atomic64_unchecked_t child_total_time_running;
70438
70439 /*
70440 * Protect attach/detach and child_list:
70441@@ -704,7 +704,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
70442 entry->ip[entry->nr++] = ip;
70443 }
70444
70445-extern int sysctl_perf_event_paranoid;
70446+extern int sysctl_perf_event_legitimately_concerned;
70447 extern int sysctl_perf_event_mlock;
70448 extern int sysctl_perf_event_sample_rate;
70449
70450@@ -712,19 +712,24 @@ extern int perf_proc_update_handler(struct ctl_table *table, int write,
70451 void __user *buffer, size_t *lenp,
70452 loff_t *ppos);
70453
70454+static inline bool perf_paranoid_any(void)
70455+{
70456+ return sysctl_perf_event_legitimately_concerned > 2;
70457+}
70458+
70459 static inline bool perf_paranoid_tracepoint_raw(void)
70460 {
70461- return sysctl_perf_event_paranoid > -1;
70462+ return sysctl_perf_event_legitimately_concerned > -1;
70463 }
70464
70465 static inline bool perf_paranoid_cpu(void)
70466 {
70467- return sysctl_perf_event_paranoid > 0;
70468+ return sysctl_perf_event_legitimately_concerned > 0;
70469 }
70470
70471 static inline bool perf_paranoid_kernel(void)
70472 {
70473- return sysctl_perf_event_paranoid > 1;
70474+ return sysctl_perf_event_legitimately_concerned > 1;
70475 }
70476
70477 extern void perf_event_init(void);
70478@@ -812,7 +817,7 @@ static inline void perf_restore_debug_store(void) { }
70479 */
70480 #define perf_cpu_notifier(fn) \
70481 do { \
70482- static struct notifier_block fn##_nb __cpuinitdata = \
70483+ static struct notifier_block fn##_nb = \
70484 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
70485 unsigned long cpu = smp_processor_id(); \
70486 unsigned long flags; \
70487@@ -831,7 +836,7 @@ do { \
70488 struct perf_pmu_events_attr {
70489 struct device_attribute attr;
70490 u64 id;
70491-};
70492+} __do_const;
70493
70494 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
70495 static struct perf_pmu_events_attr _var = { \
70496diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
70497index ad1a427..6419649 100644
70498--- a/include/linux/pipe_fs_i.h
70499+++ b/include/linux/pipe_fs_i.h
70500@@ -45,9 +45,9 @@ struct pipe_buffer {
70501 struct pipe_inode_info {
70502 wait_queue_head_t wait;
70503 unsigned int nrbufs, curbuf, buffers;
70504- unsigned int readers;
70505- unsigned int writers;
70506- unsigned int waiting_writers;
70507+ atomic_t readers;
70508+ atomic_t writers;
70509+ atomic_t waiting_writers;
70510 unsigned int r_counter;
70511 unsigned int w_counter;
70512 struct page *tmp_page;
70513diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
70514index 5f28cae..3d23723 100644
70515--- a/include/linux/platform_data/usb-ehci-s5p.h
70516+++ b/include/linux/platform_data/usb-ehci-s5p.h
70517@@ -14,7 +14,7 @@
70518 struct s5p_ehci_platdata {
70519 int (*phy_init)(struct platform_device *pdev, int type);
70520 int (*phy_exit)(struct platform_device *pdev, int type);
70521-};
70522+} __no_const;
70523
70524 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
70525
70526diff --git a/include/linux/platform_data/usb-exynos.h b/include/linux/platform_data/usb-exynos.h
70527index c256c59..8ea94c7 100644
70528--- a/include/linux/platform_data/usb-exynos.h
70529+++ b/include/linux/platform_data/usb-exynos.h
70530@@ -14,7 +14,7 @@
70531 struct exynos4_ohci_platdata {
70532 int (*phy_init)(struct platform_device *pdev, int type);
70533 int (*phy_exit)(struct platform_device *pdev, int type);
70534-};
70535+} __no_const;
70536
70537 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
70538
70539diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
70540index 7c1d252..c5c773e 100644
70541--- a/include/linux/pm_domain.h
70542+++ b/include/linux/pm_domain.h
70543@@ -48,7 +48,7 @@ struct gpd_dev_ops {
70544
70545 struct gpd_cpu_data {
70546 unsigned int saved_exit_latency;
70547- struct cpuidle_state *idle_state;
70548+ cpuidle_state_no_const *idle_state;
70549 };
70550
70551 struct generic_pm_domain {
70552diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
70553index 7d7e09e..8671ef8 100644
70554--- a/include/linux/pm_runtime.h
70555+++ b/include/linux/pm_runtime.h
70556@@ -104,7 +104,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
70557
70558 static inline void pm_runtime_mark_last_busy(struct device *dev)
70559 {
70560- ACCESS_ONCE(dev->power.last_busy) = jiffies;
70561+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
70562 }
70563
70564 #else /* !CONFIG_PM_RUNTIME */
70565diff --git a/include/linux/pnp.h b/include/linux/pnp.h
70566index 195aafc..49a7bc2 100644
70567--- a/include/linux/pnp.h
70568+++ b/include/linux/pnp.h
70569@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
70570 struct pnp_fixup {
70571 char id[7];
70572 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
70573-};
70574+} __do_const;
70575
70576 /* config parameters */
70577 #define PNP_CONFIG_NORMAL 0x0001
70578diff --git a/include/linux/poison.h b/include/linux/poison.h
70579index 2110a81..13a11bb 100644
70580--- a/include/linux/poison.h
70581+++ b/include/linux/poison.h
70582@@ -19,8 +19,8 @@
70583 * under normal circumstances, used to verify that nobody uses
70584 * non-initialized list entries.
70585 */
70586-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
70587-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
70588+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
70589+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
70590
70591 /********** include/linux/timer.h **********/
70592 /*
70593diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
70594index c0f44c2..1572583 100644
70595--- a/include/linux/power/smartreflex.h
70596+++ b/include/linux/power/smartreflex.h
70597@@ -238,7 +238,7 @@ struct omap_sr_class_data {
70598 int (*notify)(struct omap_sr *sr, u32 status);
70599 u8 notify_flags;
70600 u8 class_type;
70601-};
70602+} __do_const;
70603
70604 /**
70605 * struct omap_sr_nvalue_table - Smartreflex n-target value info
70606diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
70607index 4ea1d37..80f4b33 100644
70608--- a/include/linux/ppp-comp.h
70609+++ b/include/linux/ppp-comp.h
70610@@ -84,7 +84,7 @@ struct compressor {
70611 struct module *owner;
70612 /* Extra skb space needed by the compressor algorithm */
70613 unsigned int comp_extra;
70614-};
70615+} __do_const;
70616
70617 /*
70618 * The return value from decompress routine is the length of the
70619diff --git a/include/linux/printk.h b/include/linux/printk.h
70620index 822171f..12b30e8 100644
70621--- a/include/linux/printk.h
70622+++ b/include/linux/printk.h
70623@@ -98,6 +98,8 @@ int no_printk(const char *fmt, ...)
70624 extern asmlinkage __printf(1, 2)
70625 void early_printk(const char *fmt, ...);
70626
70627+extern int kptr_restrict;
70628+
70629 #ifdef CONFIG_PRINTK
70630 asmlinkage __printf(5, 0)
70631 int vprintk_emit(int facility, int level,
70632@@ -132,7 +134,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
70633
70634 extern int printk_delay_msec;
70635 extern int dmesg_restrict;
70636-extern int kptr_restrict;
70637
70638 extern void wake_up_klogd(void);
70639
70640diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
70641index 94dfb2a..88b9d3b 100644
70642--- a/include/linux/proc_fs.h
70643+++ b/include/linux/proc_fs.h
70644@@ -165,6 +165,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
70645 return proc_create_data(name, mode, parent, proc_fops, NULL);
70646 }
70647
70648+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
70649+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
70650+{
70651+#ifdef CONFIG_GRKERNSEC_PROC_USER
70652+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
70653+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70654+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
70655+#else
70656+ return proc_create_data(name, mode, parent, proc_fops, NULL);
70657+#endif
70658+}
70659+
70660 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
70661 umode_t mode, struct proc_dir_entry *base,
70662 read_proc_t *read_proc, void * data)
70663@@ -266,7 +278,7 @@ struct proc_ns_operations {
70664 void (*put)(void *ns);
70665 int (*install)(struct nsproxy *nsproxy, void *ns);
70666 unsigned int (*inum)(void *ns);
70667-};
70668+} __do_const;
70669 extern const struct proc_ns_operations netns_operations;
70670 extern const struct proc_ns_operations utsns_operations;
70671 extern const struct proc_ns_operations ipcns_operations;
70672diff --git a/include/linux/random.h b/include/linux/random.h
70673index 347ce55..880f97c 100644
70674--- a/include/linux/random.h
70675+++ b/include/linux/random.h
70676@@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
70677 u32 prandom_u32_state(struct rnd_state *);
70678 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
70679
70680+static inline unsigned long pax_get_random_long(void)
70681+{
70682+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
70683+}
70684+
70685 /*
70686 * Handle minimum values for seeds
70687 */
70688diff --git a/include/linux/rculist.h b/include/linux/rculist.h
70689index 8089e35..3a0d59a 100644
70690--- a/include/linux/rculist.h
70691+++ b/include/linux/rculist.h
70692@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
70693 struct list_head *prev, struct list_head *next);
70694 #endif
70695
70696+extern void __pax_list_add_rcu(struct list_head *new,
70697+ struct list_head *prev, struct list_head *next);
70698+
70699 /**
70700 * list_add_rcu - add a new entry to rcu-protected list
70701 * @new: new entry to be added
70702@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
70703 __list_add_rcu(new, head, head->next);
70704 }
70705
70706+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
70707+{
70708+ __pax_list_add_rcu(new, head, head->next);
70709+}
70710+
70711 /**
70712 * list_add_tail_rcu - add a new entry to rcu-protected list
70713 * @new: new entry to be added
70714@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
70715 __list_add_rcu(new, head->prev, head);
70716 }
70717
70718+static inline void pax_list_add_tail_rcu(struct list_head *new,
70719+ struct list_head *head)
70720+{
70721+ __pax_list_add_rcu(new, head->prev, head);
70722+}
70723+
70724 /**
70725 * list_del_rcu - deletes entry from list without re-initialization
70726 * @entry: the element to delete from the list.
70727@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
70728 entry->prev = LIST_POISON2;
70729 }
70730
70731+extern void pax_list_del_rcu(struct list_head *entry);
70732+
70733 /**
70734 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
70735 * @n: the element to delete from the hash list.
70736diff --git a/include/linux/reboot.h b/include/linux/reboot.h
70737index 23b3630..e1bc12b 100644
70738--- a/include/linux/reboot.h
70739+++ b/include/linux/reboot.h
70740@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
70741 * Architecture-specific implementations of sys_reboot commands.
70742 */
70743
70744-extern void machine_restart(char *cmd);
70745-extern void machine_halt(void);
70746-extern void machine_power_off(void);
70747+extern void machine_restart(char *cmd) __noreturn;
70748+extern void machine_halt(void) __noreturn;
70749+extern void machine_power_off(void) __noreturn;
70750
70751 extern void machine_shutdown(void);
70752 struct pt_regs;
70753@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
70754 */
70755
70756 extern void kernel_restart_prepare(char *cmd);
70757-extern void kernel_restart(char *cmd);
70758-extern void kernel_halt(void);
70759-extern void kernel_power_off(void);
70760+extern void kernel_restart(char *cmd) __noreturn;
70761+extern void kernel_halt(void) __noreturn;
70762+extern void kernel_power_off(void) __noreturn;
70763
70764 extern int C_A_D; /* for sysctl */
70765 void ctrl_alt_del(void);
70766@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
70767 * Emergency restart, callable from an interrupt handler.
70768 */
70769
70770-extern void emergency_restart(void);
70771+extern void emergency_restart(void) __noreturn;
70772 #include <asm/emergency-restart.h>
70773
70774 #endif /* _LINUX_REBOOT_H */
70775diff --git a/include/linux/regset.h b/include/linux/regset.h
70776index 8e0c9fe..ac4d221 100644
70777--- a/include/linux/regset.h
70778+++ b/include/linux/regset.h
70779@@ -161,7 +161,8 @@ struct user_regset {
70780 unsigned int align;
70781 unsigned int bias;
70782 unsigned int core_note_type;
70783-};
70784+} __do_const;
70785+typedef struct user_regset __no_const user_regset_no_const;
70786
70787 /**
70788 * struct user_regset_view - available regsets
70789diff --git a/include/linux/relay.h b/include/linux/relay.h
70790index 91cacc3..b55ff74 100644
70791--- a/include/linux/relay.h
70792+++ b/include/linux/relay.h
70793@@ -160,7 +160,7 @@ struct rchan_callbacks
70794 * The callback should return 0 if successful, negative if not.
70795 */
70796 int (*remove_buf_file)(struct dentry *dentry);
70797-};
70798+} __no_const;
70799
70800 /*
70801 * CONFIG_RELAY kernel API, kernel/relay.c
70802diff --git a/include/linux/rio.h b/include/linux/rio.h
70803index a3e7842..d973ca6 100644
70804--- a/include/linux/rio.h
70805+++ b/include/linux/rio.h
70806@@ -339,7 +339,7 @@ struct rio_ops {
70807 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
70808 u64 rstart, u32 size, u32 flags);
70809 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
70810-};
70811+} __no_const;
70812
70813 #define RIO_RESOURCE_MEM 0x00000100
70814 #define RIO_RESOURCE_DOORBELL 0x00000200
70815diff --git a/include/linux/rmap.h b/include/linux/rmap.h
70816index 6dacb93..6174423 100644
70817--- a/include/linux/rmap.h
70818+++ b/include/linux/rmap.h
70819@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
70820 void anon_vma_init(void); /* create anon_vma_cachep */
70821 int anon_vma_prepare(struct vm_area_struct *);
70822 void unlink_anon_vmas(struct vm_area_struct *);
70823-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
70824-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
70825+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
70826+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
70827
70828 static inline void anon_vma_merge(struct vm_area_struct *vma,
70829 struct vm_area_struct *next)
70830diff --git a/include/linux/sched.h b/include/linux/sched.h
70831index be4e742..7f9d593 100644
70832--- a/include/linux/sched.h
70833+++ b/include/linux/sched.h
70834@@ -62,6 +62,7 @@ struct bio_list;
70835 struct fs_struct;
70836 struct perf_event_context;
70837 struct blk_plug;
70838+struct linux_binprm;
70839
70840 /*
70841 * List of flags we want to share for kernel threads,
70842@@ -315,7 +316,7 @@ extern char __sched_text_start[], __sched_text_end[];
70843 extern int in_sched_functions(unsigned long addr);
70844
70845 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
70846-extern signed long schedule_timeout(signed long timeout);
70847+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
70848 extern signed long schedule_timeout_interruptible(signed long timeout);
70849 extern signed long schedule_timeout_killable(signed long timeout);
70850 extern signed long schedule_timeout_uninterruptible(signed long timeout);
70851@@ -329,6 +330,18 @@ struct user_namespace;
70852 #include <linux/aio.h>
70853
70854 #ifdef CONFIG_MMU
70855+
70856+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
70857+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
70858+#else
70859+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
70860+{
70861+ return 0;
70862+}
70863+#endif
70864+
70865+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
70866+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
70867 extern void arch_pick_mmap_layout(struct mm_struct *mm);
70868 extern unsigned long
70869 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
70870@@ -605,6 +618,17 @@ struct signal_struct {
70871 #ifdef CONFIG_TASKSTATS
70872 struct taskstats *stats;
70873 #endif
70874+
70875+#ifdef CONFIG_GRKERNSEC
70876+ u32 curr_ip;
70877+ u32 saved_ip;
70878+ u32 gr_saddr;
70879+ u32 gr_daddr;
70880+ u16 gr_sport;
70881+ u16 gr_dport;
70882+ u8 used_accept:1;
70883+#endif
70884+
70885 #ifdef CONFIG_AUDIT
70886 unsigned audit_tty;
70887 struct tty_audit_buf *tty_audit_buf;
70888@@ -683,6 +707,11 @@ struct user_struct {
70889 struct key *session_keyring; /* UID's default session keyring */
70890 #endif
70891
70892+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
70893+ unsigned int banned;
70894+ unsigned long ban_expires;
70895+#endif
70896+
70897 /* Hash table maintenance information */
70898 struct hlist_node uidhash_node;
70899 kuid_t uid;
70900@@ -1082,7 +1111,7 @@ struct sched_class {
70901 #ifdef CONFIG_FAIR_GROUP_SCHED
70902 void (*task_move_group) (struct task_struct *p, int on_rq);
70903 #endif
70904-};
70905+} __do_const;
70906
70907 struct load_weight {
70908 unsigned long weight, inv_weight;
70909@@ -1323,8 +1352,8 @@ struct task_struct {
70910 struct list_head thread_group;
70911
70912 struct completion *vfork_done; /* for vfork() */
70913- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
70914- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
70915+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
70916+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
70917
70918 cputime_t utime, stime, utimescaled, stimescaled;
70919 cputime_t gtime;
70920@@ -1349,11 +1378,6 @@ struct task_struct {
70921 struct task_cputime cputime_expires;
70922 struct list_head cpu_timers[3];
70923
70924-/* process credentials */
70925- const struct cred __rcu *real_cred; /* objective and real subjective task
70926- * credentials (COW) */
70927- const struct cred __rcu *cred; /* effective (overridable) subjective task
70928- * credentials (COW) */
70929 char comm[TASK_COMM_LEN]; /* executable name excluding path
70930 - access with [gs]et_task_comm (which lock
70931 it with task_lock())
70932@@ -1370,6 +1394,10 @@ struct task_struct {
70933 #endif
70934 /* CPU-specific state of this task */
70935 struct thread_struct thread;
70936+/* thread_info moved to task_struct */
70937+#ifdef CONFIG_X86
70938+ struct thread_info tinfo;
70939+#endif
70940 /* filesystem information */
70941 struct fs_struct *fs;
70942 /* open file information */
70943@@ -1443,6 +1471,10 @@ struct task_struct {
70944 gfp_t lockdep_reclaim_gfp;
70945 #endif
70946
70947+/* process credentials */
70948+ const struct cred __rcu *real_cred; /* objective and real subjective task
70949+ * credentials (COW) */
70950+
70951 /* journalling filesystem info */
70952 void *journal_info;
70953
70954@@ -1481,6 +1513,10 @@ struct task_struct {
70955 /* cg_list protected by css_set_lock and tsk->alloc_lock */
70956 struct list_head cg_list;
70957 #endif
70958+
70959+ const struct cred __rcu *cred; /* effective (overridable) subjective task
70960+ * credentials (COW) */
70961+
70962 #ifdef CONFIG_FUTEX
70963 struct robust_list_head __user *robust_list;
70964 #ifdef CONFIG_COMPAT
70965@@ -1577,8 +1613,74 @@ struct task_struct {
70966 #ifdef CONFIG_UPROBES
70967 struct uprobe_task *utask;
70968 #endif
70969+
70970+#ifdef CONFIG_GRKERNSEC
70971+ /* grsecurity */
70972+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
70973+ u64 exec_id;
70974+#endif
70975+#ifdef CONFIG_GRKERNSEC_SETXID
70976+ const struct cred *delayed_cred;
70977+#endif
70978+ struct dentry *gr_chroot_dentry;
70979+ struct acl_subject_label *acl;
70980+ struct acl_role_label *role;
70981+ struct file *exec_file;
70982+ unsigned long brute_expires;
70983+ u16 acl_role_id;
70984+ /* is this the task that authenticated to the special role */
70985+ u8 acl_sp_role;
70986+ u8 is_writable;
70987+ u8 brute;
70988+ u8 gr_is_chrooted;
70989+#endif
70990+
70991 };
70992
70993+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
70994+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
70995+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
70996+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
70997+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
70998+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
70999+
71000+#ifdef CONFIG_PAX_SOFTMODE
71001+extern int pax_softmode;
71002+#endif
71003+
71004+extern int pax_check_flags(unsigned long *);
71005+
71006+/* if tsk != current then task_lock must be held on it */
71007+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
71008+static inline unsigned long pax_get_flags(struct task_struct *tsk)
71009+{
71010+ if (likely(tsk->mm))
71011+ return tsk->mm->pax_flags;
71012+ else
71013+ return 0UL;
71014+}
71015+
71016+/* if tsk != current then task_lock must be held on it */
71017+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
71018+{
71019+ if (likely(tsk->mm)) {
71020+ tsk->mm->pax_flags = flags;
71021+ return 0;
71022+ }
71023+ return -EINVAL;
71024+}
71025+#endif
71026+
71027+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
71028+extern void pax_set_initial_flags(struct linux_binprm *bprm);
71029+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
71030+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
71031+#endif
71032+
71033+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
71034+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
71035+extern void pax_report_refcount_overflow(struct pt_regs *regs);
71036+
71037 /* Future-safe accessor for struct task_struct's cpus_allowed. */
71038 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
71039
71040@@ -1637,7 +1739,7 @@ struct pid_namespace;
71041 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
71042 struct pid_namespace *ns);
71043
71044-static inline pid_t task_pid_nr(struct task_struct *tsk)
71045+static inline pid_t task_pid_nr(const struct task_struct *tsk)
71046 {
71047 return tsk->pid;
71048 }
71049@@ -2073,7 +2175,9 @@ void yield(void);
71050 extern struct exec_domain default_exec_domain;
71051
71052 union thread_union {
71053+#ifndef CONFIG_X86
71054 struct thread_info thread_info;
71055+#endif
71056 unsigned long stack[THREAD_SIZE/sizeof(long)];
71057 };
71058
71059@@ -2106,6 +2210,7 @@ extern struct pid_namespace init_pid_ns;
71060 */
71061
71062 extern struct task_struct *find_task_by_vpid(pid_t nr);
71063+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
71064 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
71065 struct pid_namespace *ns);
71066
71067@@ -2272,7 +2377,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
71068 extern void exit_itimers(struct signal_struct *);
71069 extern void flush_itimer_signals(void);
71070
71071-extern void do_group_exit(int);
71072+extern __noreturn void do_group_exit(int);
71073
71074 extern int allow_signal(int);
71075 extern int disallow_signal(int);
71076@@ -2463,9 +2568,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
71077
71078 #endif
71079
71080-static inline int object_is_on_stack(void *obj)
71081+static inline int object_starts_on_stack(void *obj)
71082 {
71083- void *stack = task_stack_page(current);
71084+ const void *stack = task_stack_page(current);
71085
71086 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
71087 }
71088diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
71089index bf8086b..962b035 100644
71090--- a/include/linux/sched/sysctl.h
71091+++ b/include/linux/sched/sysctl.h
71092@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
71093 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
71094
71095 extern int sysctl_max_map_count;
71096+extern unsigned long sysctl_heap_stack_gap;
71097
71098 extern unsigned int sysctl_sched_latency;
71099 extern unsigned int sysctl_sched_min_granularity;
71100diff --git a/include/linux/security.h b/include/linux/security.h
71101index 032c366..2c1c2dc2 100644
71102--- a/include/linux/security.h
71103+++ b/include/linux/security.h
71104@@ -26,6 +26,7 @@
71105 #include <linux/capability.h>
71106 #include <linux/slab.h>
71107 #include <linux/err.h>
71108+#include <linux/grsecurity.h>
71109
71110 struct linux_binprm;
71111 struct cred;
71112diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
71113index 68a04a3..866e6a1 100644
71114--- a/include/linux/seq_file.h
71115+++ b/include/linux/seq_file.h
71116@@ -26,6 +26,9 @@ struct seq_file {
71117 struct mutex lock;
71118 const struct seq_operations *op;
71119 int poll_event;
71120+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71121+ u64 exec_id;
71122+#endif
71123 #ifdef CONFIG_USER_NS
71124 struct user_namespace *user_ns;
71125 #endif
71126@@ -38,6 +41,7 @@ struct seq_operations {
71127 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
71128 int (*show) (struct seq_file *m, void *v);
71129 };
71130+typedef struct seq_operations __no_const seq_operations_no_const;
71131
71132 #define SEQ_SKIP 1
71133
71134diff --git a/include/linux/shm.h b/include/linux/shm.h
71135index 429c199..4d42e38 100644
71136--- a/include/linux/shm.h
71137+++ b/include/linux/shm.h
71138@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
71139
71140 /* The task created the shm object. NULL if the task is dead. */
71141 struct task_struct *shm_creator;
71142+#ifdef CONFIG_GRKERNSEC
71143+ time_t shm_createtime;
71144+ pid_t shm_lapid;
71145+#endif
71146 };
71147
71148 /* shm_mode upper byte flags */
71149diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
71150index b8292d8..96db310 100644
71151--- a/include/linux/skbuff.h
71152+++ b/include/linux/skbuff.h
71153@@ -599,7 +599,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
71154 extern struct sk_buff *__alloc_skb(unsigned int size,
71155 gfp_t priority, int flags, int node);
71156 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
71157-static inline struct sk_buff *alloc_skb(unsigned int size,
71158+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
71159 gfp_t priority)
71160 {
71161 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
71162@@ -709,7 +709,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
71163 */
71164 static inline int skb_queue_empty(const struct sk_buff_head *list)
71165 {
71166- return list->next == (struct sk_buff *)list;
71167+ return list->next == (const struct sk_buff *)list;
71168 }
71169
71170 /**
71171@@ -722,7 +722,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
71172 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
71173 const struct sk_buff *skb)
71174 {
71175- return skb->next == (struct sk_buff *)list;
71176+ return skb->next == (const struct sk_buff *)list;
71177 }
71178
71179 /**
71180@@ -735,7 +735,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
71181 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
71182 const struct sk_buff *skb)
71183 {
71184- return skb->prev == (struct sk_buff *)list;
71185+ return skb->prev == (const struct sk_buff *)list;
71186 }
71187
71188 /**
71189@@ -1756,7 +1756,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
71190 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
71191 */
71192 #ifndef NET_SKB_PAD
71193-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
71194+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
71195 #endif
71196
71197 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
71198@@ -2351,7 +2351,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
71199 int noblock, int *err);
71200 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
71201 struct poll_table_struct *wait);
71202-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
71203+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
71204 int offset, struct iovec *to,
71205 int size);
71206 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
71207@@ -2641,6 +2641,9 @@ static inline void nf_reset(struct sk_buff *skb)
71208 nf_bridge_put(skb->nf_bridge);
71209 skb->nf_bridge = NULL;
71210 #endif
71211+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
71212+ skb->nf_trace = 0;
71213+#endif
71214 }
71215
71216 static inline void nf_reset_trace(struct sk_buff *skb)
71217diff --git a/include/linux/slab.h b/include/linux/slab.h
71218index 5d168d7..720bff3 100644
71219--- a/include/linux/slab.h
71220+++ b/include/linux/slab.h
71221@@ -12,13 +12,20 @@
71222 #include <linux/gfp.h>
71223 #include <linux/types.h>
71224 #include <linux/workqueue.h>
71225-
71226+#include <linux/err.h>
71227
71228 /*
71229 * Flags to pass to kmem_cache_create().
71230 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
71231 */
71232 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
71233+
71234+#ifdef CONFIG_PAX_USERCOPY_SLABS
71235+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
71236+#else
71237+#define SLAB_USERCOPY 0x00000000UL
71238+#endif
71239+
71240 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
71241 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
71242 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
71243@@ -89,10 +96,13 @@
71244 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
71245 * Both make kfree a no-op.
71246 */
71247-#define ZERO_SIZE_PTR ((void *)16)
71248+#define ZERO_SIZE_PTR \
71249+({ \
71250+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
71251+ (void *)(-MAX_ERRNO-1L); \
71252+})
71253
71254-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
71255- (unsigned long)ZERO_SIZE_PTR)
71256+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
71257
71258 /*
71259 * Common fields provided in kmem_cache by all slab allocators
71260@@ -112,7 +122,7 @@ struct kmem_cache {
71261 unsigned int align; /* Alignment as calculated */
71262 unsigned long flags; /* Active flags on the slab */
71263 const char *name; /* Slab name for sysfs */
71264- int refcount; /* Use counter */
71265+ atomic_t refcount; /* Use counter */
71266 void (*ctor)(void *); /* Called on object slot creation */
71267 struct list_head list; /* List of all slab caches on the system */
71268 };
71269@@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
71270 void kfree(const void *);
71271 void kzfree(const void *);
71272 size_t ksize(const void *);
71273+const char *check_heap_object(const void *ptr, unsigned long n);
71274+bool is_usercopy_object(const void *ptr);
71275
71276 /*
71277 * Allocator specific definitions. These are mainly used to establish optimized
71278@@ -311,6 +323,7 @@ size_t ksize(const void *);
71279 * for general use, and so are not documented here. For a full list of
71280 * potential flags, always refer to linux/gfp.h.
71281 */
71282+
71283 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
71284 {
71285 if (size != 0 && n > SIZE_MAX / size)
71286@@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
71287 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
71288 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
71289 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
71290-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
71291+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
71292 #define kmalloc_track_caller(size, flags) \
71293 __kmalloc_track_caller(size, flags, _RET_IP_)
71294 #else
71295@@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
71296 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
71297 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
71298 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
71299-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
71300+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
71301 #define kmalloc_node_track_caller(size, flags, node) \
71302 __kmalloc_node_track_caller(size, flags, node, \
71303 _RET_IP_)
71304diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
71305index 8bb6e0e..8eb0dbe 100644
71306--- a/include/linux/slab_def.h
71307+++ b/include/linux/slab_def.h
71308@@ -52,7 +52,7 @@ struct kmem_cache {
71309 /* 4) cache creation/removal */
71310 const char *name;
71311 struct list_head list;
71312- int refcount;
71313+ atomic_t refcount;
71314 int object_size;
71315 int align;
71316
71317@@ -68,10 +68,10 @@ struct kmem_cache {
71318 unsigned long node_allocs;
71319 unsigned long node_frees;
71320 unsigned long node_overflow;
71321- atomic_t allochit;
71322- atomic_t allocmiss;
71323- atomic_t freehit;
71324- atomic_t freemiss;
71325+ atomic_unchecked_t allochit;
71326+ atomic_unchecked_t allocmiss;
71327+ atomic_unchecked_t freehit;
71328+ atomic_unchecked_t freemiss;
71329
71330 /*
71331 * If debugging is enabled, then the allocator can add additional
71332@@ -111,11 +111,16 @@ struct cache_sizes {
71333 #ifdef CONFIG_ZONE_DMA
71334 struct kmem_cache *cs_dmacachep;
71335 #endif
71336+
71337+#ifdef CONFIG_PAX_USERCOPY_SLABS
71338+ struct kmem_cache *cs_usercopycachep;
71339+#endif
71340+
71341 };
71342 extern struct cache_sizes malloc_sizes[];
71343
71344 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
71345-void *__kmalloc(size_t size, gfp_t flags);
71346+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
71347
71348 #ifdef CONFIG_TRACING
71349 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
71350@@ -152,6 +157,13 @@ found:
71351 cachep = malloc_sizes[i].cs_dmacachep;
71352 else
71353 #endif
71354+
71355+#ifdef CONFIG_PAX_USERCOPY_SLABS
71356+ if (flags & GFP_USERCOPY)
71357+ cachep = malloc_sizes[i].cs_usercopycachep;
71358+ else
71359+#endif
71360+
71361 cachep = malloc_sizes[i].cs_cachep;
71362
71363 ret = kmem_cache_alloc_trace(cachep, flags, size);
71364@@ -162,7 +174,7 @@ found:
71365 }
71366
71367 #ifdef CONFIG_NUMA
71368-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
71369+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
71370 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
71371
71372 #ifdef CONFIG_TRACING
71373@@ -205,6 +217,13 @@ found:
71374 cachep = malloc_sizes[i].cs_dmacachep;
71375 else
71376 #endif
71377+
71378+#ifdef CONFIG_PAX_USERCOPY_SLABS
71379+ if (flags & GFP_USERCOPY)
71380+ cachep = malloc_sizes[i].cs_usercopycachep;
71381+ else
71382+#endif
71383+
71384 cachep = malloc_sizes[i].cs_cachep;
71385
71386 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
71387diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
71388index f28e14a..7831211 100644
71389--- a/include/linux/slob_def.h
71390+++ b/include/linux/slob_def.h
71391@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
71392 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
71393 }
71394
71395-void *__kmalloc_node(size_t size, gfp_t flags, int node);
71396+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
71397
71398 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
71399 {
71400@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
71401 return __kmalloc_node(size, flags, NUMA_NO_NODE);
71402 }
71403
71404-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
71405+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
71406 {
71407 return kmalloc(size, flags);
71408 }
71409diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
71410index 9db4825..ed42fb5 100644
71411--- a/include/linux/slub_def.h
71412+++ b/include/linux/slub_def.h
71413@@ -91,7 +91,7 @@ struct kmem_cache {
71414 struct kmem_cache_order_objects max;
71415 struct kmem_cache_order_objects min;
71416 gfp_t allocflags; /* gfp flags to use on each alloc */
71417- int refcount; /* Refcount for slab cache destroy */
71418+ atomic_t refcount; /* Refcount for slab cache destroy */
71419 void (*ctor)(void *);
71420 int inuse; /* Offset to metadata */
71421 int align; /* Alignment */
71422@@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
71423 * Sorry that the following has to be that ugly but some versions of GCC
71424 * have trouble with constant propagation and loops.
71425 */
71426-static __always_inline int kmalloc_index(size_t size)
71427+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
71428 {
71429 if (!size)
71430 return 0;
71431@@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
71432 }
71433
71434 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
71435-void *__kmalloc(size_t size, gfp_t flags);
71436+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
71437
71438 static __always_inline void *
71439 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
71440@@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
71441 }
71442 #endif
71443
71444-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
71445+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
71446 {
71447 unsigned int order = get_order(size);
71448 return kmalloc_order_trace(size, flags, order);
71449@@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
71450 }
71451
71452 #ifdef CONFIG_NUMA
71453-void *__kmalloc_node(size_t size, gfp_t flags, int node);
71454+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
71455 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
71456
71457 #ifdef CONFIG_TRACING
71458diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
71459index e8d702e..0a56eb4 100644
71460--- a/include/linux/sock_diag.h
71461+++ b/include/linux/sock_diag.h
71462@@ -10,7 +10,7 @@ struct sock;
71463 struct sock_diag_handler {
71464 __u8 family;
71465 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
71466-};
71467+} __do_const;
71468
71469 int sock_diag_register(const struct sock_diag_handler *h);
71470 void sock_diag_unregister(const struct sock_diag_handler *h);
71471diff --git a/include/linux/sonet.h b/include/linux/sonet.h
71472index 680f9a3..f13aeb0 100644
71473--- a/include/linux/sonet.h
71474+++ b/include/linux/sonet.h
71475@@ -7,7 +7,7 @@
71476 #include <uapi/linux/sonet.h>
71477
71478 struct k_sonet_stats {
71479-#define __HANDLE_ITEM(i) atomic_t i
71480+#define __HANDLE_ITEM(i) atomic_unchecked_t i
71481 __SONET_ITEMS
71482 #undef __HANDLE_ITEM
71483 };
71484diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
71485index 07d8e53..dc934c9 100644
71486--- a/include/linux/sunrpc/addr.h
71487+++ b/include/linux/sunrpc/addr.h
71488@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
71489 {
71490 switch (sap->sa_family) {
71491 case AF_INET:
71492- return ntohs(((struct sockaddr_in *)sap)->sin_port);
71493+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
71494 case AF_INET6:
71495- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
71496+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
71497 }
71498 return 0;
71499 }
71500@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
71501 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
71502 const struct sockaddr *src)
71503 {
71504- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
71505+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
71506 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
71507
71508 dsin->sin_family = ssin->sin_family;
71509@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
71510 if (sa->sa_family != AF_INET6)
71511 return 0;
71512
71513- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
71514+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
71515 }
71516
71517 #endif /* _LINUX_SUNRPC_ADDR_H */
71518diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
71519index 2cf4ffa..470d140 100644
71520--- a/include/linux/sunrpc/clnt.h
71521+++ b/include/linux/sunrpc/clnt.h
71522@@ -96,7 +96,7 @@ struct rpc_procinfo {
71523 unsigned int p_timer; /* Which RTT timer to use */
71524 u32 p_statidx; /* Which procedure to account */
71525 const char * p_name; /* name of procedure */
71526-};
71527+} __do_const;
71528
71529 #ifdef __KERNEL__
71530
71531diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
71532index 1f0216b..6a4fa50 100644
71533--- a/include/linux/sunrpc/svc.h
71534+++ b/include/linux/sunrpc/svc.h
71535@@ -411,7 +411,7 @@ struct svc_procedure {
71536 unsigned int pc_count; /* call count */
71537 unsigned int pc_cachetype; /* cache info (NFS) */
71538 unsigned int pc_xdrressize; /* maximum size of XDR reply */
71539-};
71540+} __do_const;
71541
71542 /*
71543 * Function prototypes.
71544diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
71545index 0b8e3e6..33e0a01 100644
71546--- a/include/linux/sunrpc/svc_rdma.h
71547+++ b/include/linux/sunrpc/svc_rdma.h
71548@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
71549 extern unsigned int svcrdma_max_requests;
71550 extern unsigned int svcrdma_max_req_size;
71551
71552-extern atomic_t rdma_stat_recv;
71553-extern atomic_t rdma_stat_read;
71554-extern atomic_t rdma_stat_write;
71555-extern atomic_t rdma_stat_sq_starve;
71556-extern atomic_t rdma_stat_rq_starve;
71557-extern atomic_t rdma_stat_rq_poll;
71558-extern atomic_t rdma_stat_rq_prod;
71559-extern atomic_t rdma_stat_sq_poll;
71560-extern atomic_t rdma_stat_sq_prod;
71561+extern atomic_unchecked_t rdma_stat_recv;
71562+extern atomic_unchecked_t rdma_stat_read;
71563+extern atomic_unchecked_t rdma_stat_write;
71564+extern atomic_unchecked_t rdma_stat_sq_starve;
71565+extern atomic_unchecked_t rdma_stat_rq_starve;
71566+extern atomic_unchecked_t rdma_stat_rq_poll;
71567+extern atomic_unchecked_t rdma_stat_rq_prod;
71568+extern atomic_unchecked_t rdma_stat_sq_poll;
71569+extern atomic_unchecked_t rdma_stat_sq_prod;
71570
71571 #define RPCRDMA_VERSION 1
71572
71573diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
71574index ff374ab..7fd2ecb 100644
71575--- a/include/linux/sunrpc/svcauth.h
71576+++ b/include/linux/sunrpc/svcauth.h
71577@@ -109,7 +109,7 @@ struct auth_ops {
71578 int (*release)(struct svc_rqst *rq);
71579 void (*domain_release)(struct auth_domain *);
71580 int (*set_client)(struct svc_rqst *rq);
71581-};
71582+} __do_const;
71583
71584 #define SVC_GARBAGE 1
71585 #define SVC_SYSERR 2
71586diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
71587index a5ffd32..0935dea 100644
71588--- a/include/linux/swiotlb.h
71589+++ b/include/linux/swiotlb.h
71590@@ -60,7 +60,8 @@ extern void
71591
71592 extern void
71593 swiotlb_free_coherent(struct device *hwdev, size_t size,
71594- void *vaddr, dma_addr_t dma_handle);
71595+ void *vaddr, dma_addr_t dma_handle,
71596+ struct dma_attrs *attrs);
71597
71598 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
71599 unsigned long offset, size_t size,
71600diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
71601index 313a8e0..6b273a9 100644
71602--- a/include/linux/syscalls.h
71603+++ b/include/linux/syscalls.h
71604@@ -418,11 +418,11 @@ asmlinkage long sys_sync(void);
71605 asmlinkage long sys_fsync(unsigned int fd);
71606 asmlinkage long sys_fdatasync(unsigned int fd);
71607 asmlinkage long sys_bdflush(int func, long data);
71608-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
71609- char __user *type, unsigned long flags,
71610+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
71611+ const char __user *type, unsigned long flags,
71612 void __user *data);
71613-asmlinkage long sys_umount(char __user *name, int flags);
71614-asmlinkage long sys_oldumount(char __user *name);
71615+asmlinkage long sys_umount(const char __user *name, int flags);
71616+asmlinkage long sys_oldumount(const char __user *name);
71617 asmlinkage long sys_truncate(const char __user *path, long length);
71618 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
71619 asmlinkage long sys_stat(const char __user *filename,
71620@@ -634,7 +634,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
71621 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
71622 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
71623 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
71624- struct sockaddr __user *, int);
71625+ struct sockaddr __user *, int) __intentional_overflow(0);
71626 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
71627 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
71628 unsigned int vlen, unsigned flags);
71629diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
71630index 27b3b0b..e093dd9 100644
71631--- a/include/linux/syscore_ops.h
71632+++ b/include/linux/syscore_ops.h
71633@@ -16,7 +16,7 @@ struct syscore_ops {
71634 int (*suspend)(void);
71635 void (*resume)(void);
71636 void (*shutdown)(void);
71637-};
71638+} __do_const;
71639
71640 extern void register_syscore_ops(struct syscore_ops *ops);
71641 extern void unregister_syscore_ops(struct syscore_ops *ops);
71642diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
71643index 14a8ff2..af52bad 100644
71644--- a/include/linux/sysctl.h
71645+++ b/include/linux/sysctl.h
71646@@ -34,13 +34,13 @@ struct ctl_table_root;
71647 struct ctl_table_header;
71648 struct ctl_dir;
71649
71650-typedef struct ctl_table ctl_table;
71651-
71652 typedef int proc_handler (struct ctl_table *ctl, int write,
71653 void __user *buffer, size_t *lenp, loff_t *ppos);
71654
71655 extern int proc_dostring(struct ctl_table *, int,
71656 void __user *, size_t *, loff_t *);
71657+extern int proc_dostring_modpriv(struct ctl_table *, int,
71658+ void __user *, size_t *, loff_t *);
71659 extern int proc_dointvec(struct ctl_table *, int,
71660 void __user *, size_t *, loff_t *);
71661 extern int proc_dointvec_minmax(struct ctl_table *, int,
71662@@ -115,7 +115,9 @@ struct ctl_table
71663 struct ctl_table_poll *poll;
71664 void *extra1;
71665 void *extra2;
71666-};
71667+} __do_const;
71668+typedef struct ctl_table __no_const ctl_table_no_const;
71669+typedef struct ctl_table ctl_table;
71670
71671 struct ctl_node {
71672 struct rb_node node;
71673diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
71674index e2cee22..3ddb921 100644
71675--- a/include/linux/sysfs.h
71676+++ b/include/linux/sysfs.h
71677@@ -31,7 +31,8 @@ struct attribute {
71678 struct lock_class_key *key;
71679 struct lock_class_key skey;
71680 #endif
71681-};
71682+} __do_const;
71683+typedef struct attribute __no_const attribute_no_const;
71684
71685 /**
71686 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
71687@@ -59,8 +60,8 @@ struct attribute_group {
71688 umode_t (*is_visible)(struct kobject *,
71689 struct attribute *, int);
71690 struct attribute **attrs;
71691-};
71692-
71693+} __do_const;
71694+typedef struct attribute_group __no_const attribute_group_no_const;
71695
71696
71697 /**
71698@@ -107,7 +108,8 @@ struct bin_attribute {
71699 char *, loff_t, size_t);
71700 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
71701 struct vm_area_struct *vma);
71702-};
71703+} __do_const;
71704+typedef struct bin_attribute __no_const bin_attribute_no_const;
71705
71706 /**
71707 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
71708diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
71709index 7faf933..9b85a0c 100644
71710--- a/include/linux/sysrq.h
71711+++ b/include/linux/sysrq.h
71712@@ -16,6 +16,7 @@
71713
71714 #include <linux/errno.h>
71715 #include <linux/types.h>
71716+#include <linux/compiler.h>
71717
71718 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
71719 #define SYSRQ_DEFAULT_ENABLE 1
71720@@ -36,7 +37,7 @@ struct sysrq_key_op {
71721 char *help_msg;
71722 char *action_msg;
71723 int enable_mask;
71724-};
71725+} __do_const;
71726
71727 #ifdef CONFIG_MAGIC_SYSRQ
71728
71729diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
71730index e7e0473..7989295 100644
71731--- a/include/linux/thread_info.h
71732+++ b/include/linux/thread_info.h
71733@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
71734 #error "no set_restore_sigmask() provided and default one won't work"
71735 #endif
71736
71737+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
71738+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
71739+{
71740+#ifndef CONFIG_PAX_USERCOPY_DEBUG
71741+ if (!__builtin_constant_p(n))
71742+#endif
71743+ __check_object_size(ptr, n, to_user);
71744+}
71745+
71746 #endif /* __KERNEL__ */
71747
71748 #endif /* _LINUX_THREAD_INFO_H */
71749diff --git a/include/linux/tty.h b/include/linux/tty.h
71750index c75d886..04cb148 100644
71751--- a/include/linux/tty.h
71752+++ b/include/linux/tty.h
71753@@ -194,7 +194,7 @@ struct tty_port {
71754 const struct tty_port_operations *ops; /* Port operations */
71755 spinlock_t lock; /* Lock protecting tty field */
71756 int blocked_open; /* Waiting to open */
71757- int count; /* Usage count */
71758+ atomic_t count; /* Usage count */
71759 wait_queue_head_t open_wait; /* Open waiters */
71760 wait_queue_head_t close_wait; /* Close waiters */
71761 wait_queue_head_t delta_msr_wait; /* Modem status change */
71762@@ -515,7 +515,7 @@ extern int tty_port_open(struct tty_port *port,
71763 struct tty_struct *tty, struct file *filp);
71764 static inline int tty_port_users(struct tty_port *port)
71765 {
71766- return port->count + port->blocked_open;
71767+ return atomic_read(&port->count) + port->blocked_open;
71768 }
71769
71770 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
71771diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
71772index 756a609..b302dd6 100644
71773--- a/include/linux/tty_driver.h
71774+++ b/include/linux/tty_driver.h
71775@@ -285,7 +285,7 @@ struct tty_operations {
71776 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
71777 #endif
71778 const struct file_operations *proc_fops;
71779-};
71780+} __do_const;
71781
71782 struct tty_driver {
71783 int magic; /* magic number for this structure */
71784diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
71785index 455a0d7..bf97ff5 100644
71786--- a/include/linux/tty_ldisc.h
71787+++ b/include/linux/tty_ldisc.h
71788@@ -146,7 +146,7 @@ struct tty_ldisc_ops {
71789
71790 struct module *owner;
71791
71792- int refcount;
71793+ atomic_t refcount;
71794 };
71795
71796 struct tty_ldisc {
71797diff --git a/include/linux/types.h b/include/linux/types.h
71798index 4d118ba..c3ee9bf 100644
71799--- a/include/linux/types.h
71800+++ b/include/linux/types.h
71801@@ -176,10 +176,26 @@ typedef struct {
71802 int counter;
71803 } atomic_t;
71804
71805+#ifdef CONFIG_PAX_REFCOUNT
71806+typedef struct {
71807+ int counter;
71808+} atomic_unchecked_t;
71809+#else
71810+typedef atomic_t atomic_unchecked_t;
71811+#endif
71812+
71813 #ifdef CONFIG_64BIT
71814 typedef struct {
71815 long counter;
71816 } atomic64_t;
71817+
71818+#ifdef CONFIG_PAX_REFCOUNT
71819+typedef struct {
71820+ long counter;
71821+} atomic64_unchecked_t;
71822+#else
71823+typedef atomic64_t atomic64_unchecked_t;
71824+#endif
71825 #endif
71826
71827 struct list_head {
71828diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
71829index 5ca0951..ab496a5 100644
71830--- a/include/linux/uaccess.h
71831+++ b/include/linux/uaccess.h
71832@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
71833 long ret; \
71834 mm_segment_t old_fs = get_fs(); \
71835 \
71836- set_fs(KERNEL_DS); \
71837 pagefault_disable(); \
71838- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
71839- pagefault_enable(); \
71840+ set_fs(KERNEL_DS); \
71841+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
71842 set_fs(old_fs); \
71843+ pagefault_enable(); \
71844 ret; \
71845 })
71846
71847diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
71848index 8e522cbc..aa8572d 100644
71849--- a/include/linux/uidgid.h
71850+++ b/include/linux/uidgid.h
71851@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
71852
71853 #endif /* CONFIG_USER_NS */
71854
71855+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
71856+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
71857+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
71858+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
71859+
71860 #endif /* _LINUX_UIDGID_H */
71861diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
71862index 99c1b4d..562e6f3 100644
71863--- a/include/linux/unaligned/access_ok.h
71864+++ b/include/linux/unaligned/access_ok.h
71865@@ -4,34 +4,34 @@
71866 #include <linux/kernel.h>
71867 #include <asm/byteorder.h>
71868
71869-static inline u16 get_unaligned_le16(const void *p)
71870+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
71871 {
71872- return le16_to_cpup((__le16 *)p);
71873+ return le16_to_cpup((const __le16 *)p);
71874 }
71875
71876-static inline u32 get_unaligned_le32(const void *p)
71877+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
71878 {
71879- return le32_to_cpup((__le32 *)p);
71880+ return le32_to_cpup((const __le32 *)p);
71881 }
71882
71883-static inline u64 get_unaligned_le64(const void *p)
71884+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
71885 {
71886- return le64_to_cpup((__le64 *)p);
71887+ return le64_to_cpup((const __le64 *)p);
71888 }
71889
71890-static inline u16 get_unaligned_be16(const void *p)
71891+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
71892 {
71893- return be16_to_cpup((__be16 *)p);
71894+ return be16_to_cpup((const __be16 *)p);
71895 }
71896
71897-static inline u32 get_unaligned_be32(const void *p)
71898+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
71899 {
71900- return be32_to_cpup((__be32 *)p);
71901+ return be32_to_cpup((const __be32 *)p);
71902 }
71903
71904-static inline u64 get_unaligned_be64(const void *p)
71905+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
71906 {
71907- return be64_to_cpup((__be64 *)p);
71908+ return be64_to_cpup((const __be64 *)p);
71909 }
71910
71911 static inline void put_unaligned_le16(u16 val, void *p)
71912diff --git a/include/linux/usb.h b/include/linux/usb.h
71913index 4d22d0f..8d0e8f8 100644
71914--- a/include/linux/usb.h
71915+++ b/include/linux/usb.h
71916@@ -554,7 +554,7 @@ struct usb_device {
71917 int maxchild;
71918
71919 u32 quirks;
71920- atomic_t urbnum;
71921+ atomic_unchecked_t urbnum;
71922
71923 unsigned long active_duration;
71924
71925@@ -1604,7 +1604,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
71926
71927 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
71928 __u8 request, __u8 requesttype, __u16 value, __u16 index,
71929- void *data, __u16 size, int timeout);
71930+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
71931 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
71932 void *data, int len, int *actual_length, int timeout);
71933 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
71934diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
71935index c5d36c6..108f4f9 100644
71936--- a/include/linux/usb/renesas_usbhs.h
71937+++ b/include/linux/usb/renesas_usbhs.h
71938@@ -39,7 +39,7 @@ enum {
71939 */
71940 struct renesas_usbhs_driver_callback {
71941 int (*notify_hotplug)(struct platform_device *pdev);
71942-};
71943+} __no_const;
71944
71945 /*
71946 * callback functions for platform
71947diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
71948index 6f8fbcf..8259001 100644
71949--- a/include/linux/vermagic.h
71950+++ b/include/linux/vermagic.h
71951@@ -25,9 +25,35 @@
71952 #define MODULE_ARCH_VERMAGIC ""
71953 #endif
71954
71955+#ifdef CONFIG_PAX_REFCOUNT
71956+#define MODULE_PAX_REFCOUNT "REFCOUNT "
71957+#else
71958+#define MODULE_PAX_REFCOUNT ""
71959+#endif
71960+
71961+#ifdef CONSTIFY_PLUGIN
71962+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
71963+#else
71964+#define MODULE_CONSTIFY_PLUGIN ""
71965+#endif
71966+
71967+#ifdef STACKLEAK_PLUGIN
71968+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
71969+#else
71970+#define MODULE_STACKLEAK_PLUGIN ""
71971+#endif
71972+
71973+#ifdef CONFIG_GRKERNSEC
71974+#define MODULE_GRSEC "GRSEC "
71975+#else
71976+#define MODULE_GRSEC ""
71977+#endif
71978+
71979 #define VERMAGIC_STRING \
71980 UTS_RELEASE " " \
71981 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
71982 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
71983- MODULE_ARCH_VERMAGIC
71984+ MODULE_ARCH_VERMAGIC \
71985+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
71986+ MODULE_GRSEC
71987
71988diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
71989index 6071e91..ca6a489 100644
71990--- a/include/linux/vmalloc.h
71991+++ b/include/linux/vmalloc.h
71992@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
71993 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
71994 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
71995 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
71996+
71997+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
71998+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
71999+#endif
72000+
72001 /* bits [20..32] reserved for arch specific ioremap internals */
72002
72003 /*
72004@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
72005 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
72006 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
72007 unsigned long start, unsigned long end, gfp_t gfp_mask,
72008- pgprot_t prot, int node, const void *caller);
72009+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
72010 extern void vfree(const void *addr);
72011
72012 extern void *vmap(struct page **pages, unsigned int count,
72013@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
72014 extern void free_vm_area(struct vm_struct *area);
72015
72016 /* for /dev/kmem */
72017-extern long vread(char *buf, char *addr, unsigned long count);
72018-extern long vwrite(char *buf, char *addr, unsigned long count);
72019+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
72020+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
72021
72022 /*
72023 * Internals. Dont't use..
72024diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
72025index 5fd71a7..e5ef9a9 100644
72026--- a/include/linux/vmstat.h
72027+++ b/include/linux/vmstat.h
72028@@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
72029 /*
72030 * Zone based page accounting with per cpu differentials.
72031 */
72032-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
72033+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
72034
72035 static inline void zone_page_state_add(long x, struct zone *zone,
72036 enum zone_stat_item item)
72037 {
72038- atomic_long_add(x, &zone->vm_stat[item]);
72039- atomic_long_add(x, &vm_stat[item]);
72040+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
72041+ atomic_long_add_unchecked(x, &vm_stat[item]);
72042 }
72043
72044 static inline unsigned long global_page_state(enum zone_stat_item item)
72045 {
72046- long x = atomic_long_read(&vm_stat[item]);
72047+ long x = atomic_long_read_unchecked(&vm_stat[item]);
72048 #ifdef CONFIG_SMP
72049 if (x < 0)
72050 x = 0;
72051@@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
72052 static inline unsigned long zone_page_state(struct zone *zone,
72053 enum zone_stat_item item)
72054 {
72055- long x = atomic_long_read(&zone->vm_stat[item]);
72056+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
72057 #ifdef CONFIG_SMP
72058 if (x < 0)
72059 x = 0;
72060@@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
72061 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
72062 enum zone_stat_item item)
72063 {
72064- long x = atomic_long_read(&zone->vm_stat[item]);
72065+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
72066
72067 #ifdef CONFIG_SMP
72068 int cpu;
72069@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
72070
72071 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
72072 {
72073- atomic_long_inc(&zone->vm_stat[item]);
72074- atomic_long_inc(&vm_stat[item]);
72075+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
72076+ atomic_long_inc_unchecked(&vm_stat[item]);
72077 }
72078
72079 static inline void __inc_zone_page_state(struct page *page,
72080@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
72081
72082 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
72083 {
72084- atomic_long_dec(&zone->vm_stat[item]);
72085- atomic_long_dec(&vm_stat[item]);
72086+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
72087+ atomic_long_dec_unchecked(&vm_stat[item]);
72088 }
72089
72090 static inline void __dec_zone_page_state(struct page *page,
72091diff --git a/include/linux/xattr.h b/include/linux/xattr.h
72092index fdbafc6..49dfe4f 100644
72093--- a/include/linux/xattr.h
72094+++ b/include/linux/xattr.h
72095@@ -28,7 +28,7 @@ struct xattr_handler {
72096 size_t size, int handler_flags);
72097 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
72098 size_t size, int flags, int handler_flags);
72099-};
72100+} __do_const;
72101
72102 struct xattr {
72103 char *name;
72104@@ -37,6 +37,9 @@ struct xattr {
72105 };
72106
72107 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
72108+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
72109+ssize_t pax_getxattr(struct dentry *, void *, size_t);
72110+#endif
72111 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
72112 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
72113 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
72114diff --git a/include/linux/zlib.h b/include/linux/zlib.h
72115index 9c5a6b4..09c9438 100644
72116--- a/include/linux/zlib.h
72117+++ b/include/linux/zlib.h
72118@@ -31,6 +31,7 @@
72119 #define _ZLIB_H
72120
72121 #include <linux/zconf.h>
72122+#include <linux/compiler.h>
72123
72124 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
72125 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
72126@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
72127
72128 /* basic functions */
72129
72130-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
72131+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
72132 /*
72133 Returns the number of bytes that needs to be allocated for a per-
72134 stream workspace with the specified parameters. A pointer to this
72135diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
72136index 95d1c91..6798cca 100644
72137--- a/include/media/v4l2-dev.h
72138+++ b/include/media/v4l2-dev.h
72139@@ -76,7 +76,7 @@ struct v4l2_file_operations {
72140 int (*mmap) (struct file *, struct vm_area_struct *);
72141 int (*open) (struct file *);
72142 int (*release) (struct file *);
72143-};
72144+} __do_const;
72145
72146 /*
72147 * Newer version of video_device, handled by videodev2.c
72148diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
72149index 4118ad1..cb7e25f 100644
72150--- a/include/media/v4l2-ioctl.h
72151+++ b/include/media/v4l2-ioctl.h
72152@@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
72153 bool valid_prio, int cmd, void *arg);
72154 };
72155
72156-
72157 /* v4l debugging and diagnostics */
72158
72159 /* Debug bitmask flags to be used on V4L2 */
72160diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
72161index adcbb20..62c2559 100644
72162--- a/include/net/9p/transport.h
72163+++ b/include/net/9p/transport.h
72164@@ -57,7 +57,7 @@ struct p9_trans_module {
72165 int (*cancel) (struct p9_client *, struct p9_req_t *req);
72166 int (*zc_request)(struct p9_client *, struct p9_req_t *,
72167 char *, char *, int , int, int, int);
72168-};
72169+} __do_const;
72170
72171 void v9fs_register_trans(struct p9_trans_module *m);
72172 void v9fs_unregister_trans(struct p9_trans_module *m);
72173diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
72174index cdd3302..76f8ede 100644
72175--- a/include/net/bluetooth/l2cap.h
72176+++ b/include/net/bluetooth/l2cap.h
72177@@ -551,7 +551,7 @@ struct l2cap_ops {
72178 void (*defer) (struct l2cap_chan *chan);
72179 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
72180 unsigned long len, int nb);
72181-};
72182+} __do_const;
72183
72184 struct l2cap_conn {
72185 struct hci_conn *hcon;
72186diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
72187index 9e5425b..8136ffc 100644
72188--- a/include/net/caif/cfctrl.h
72189+++ b/include/net/caif/cfctrl.h
72190@@ -52,7 +52,7 @@ struct cfctrl_rsp {
72191 void (*radioset_rsp)(void);
72192 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
72193 struct cflayer *client_layer);
72194-};
72195+} __no_const;
72196
72197 /* Link Setup Parameters for CAIF-Links. */
72198 struct cfctrl_link_param {
72199@@ -101,8 +101,8 @@ struct cfctrl_request_info {
72200 struct cfctrl {
72201 struct cfsrvl serv;
72202 struct cfctrl_rsp res;
72203- atomic_t req_seq_no;
72204- atomic_t rsp_seq_no;
72205+ atomic_unchecked_t req_seq_no;
72206+ atomic_unchecked_t rsp_seq_no;
72207 struct list_head list;
72208 /* Protects from simultaneous access to first_req list */
72209 spinlock_t info_list_lock;
72210diff --git a/include/net/flow.h b/include/net/flow.h
72211index 628e11b..4c475df 100644
72212--- a/include/net/flow.h
72213+++ b/include/net/flow.h
72214@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
72215
72216 extern void flow_cache_flush(void);
72217 extern void flow_cache_flush_deferred(void);
72218-extern atomic_t flow_cache_genid;
72219+extern atomic_unchecked_t flow_cache_genid;
72220
72221 #endif
72222diff --git a/include/net/genetlink.h b/include/net/genetlink.h
72223index bdfbe68..4402ebe 100644
72224--- a/include/net/genetlink.h
72225+++ b/include/net/genetlink.h
72226@@ -118,7 +118,7 @@ struct genl_ops {
72227 struct netlink_callback *cb);
72228 int (*done)(struct netlink_callback *cb);
72229 struct list_head ops_list;
72230-};
72231+} __do_const;
72232
72233 extern int genl_register_family(struct genl_family *family);
72234 extern int genl_register_family_with_ops(struct genl_family *family,
72235diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
72236index 734d9b5..48a9a4b 100644
72237--- a/include/net/gro_cells.h
72238+++ b/include/net/gro_cells.h
72239@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
72240 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
72241
72242 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
72243- atomic_long_inc(&dev->rx_dropped);
72244+ atomic_long_inc_unchecked(&dev->rx_dropped);
72245 kfree_skb(skb);
72246 return;
72247 }
72248diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
72249index 1832927..ce39aea 100644
72250--- a/include/net/inet_connection_sock.h
72251+++ b/include/net/inet_connection_sock.h
72252@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
72253 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
72254 int (*bind_conflict)(const struct sock *sk,
72255 const struct inet_bind_bucket *tb, bool relax);
72256-};
72257+} __do_const;
72258
72259 /** inet_connection_sock - INET connection oriented sock
72260 *
72261diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
72262index 53f464d..ba76aaa 100644
72263--- a/include/net/inetpeer.h
72264+++ b/include/net/inetpeer.h
72265@@ -47,8 +47,8 @@ struct inet_peer {
72266 */
72267 union {
72268 struct {
72269- atomic_t rid; /* Frag reception counter */
72270- atomic_t ip_id_count; /* IP ID for the next packet */
72271+ atomic_unchecked_t rid; /* Frag reception counter */
72272+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
72273 };
72274 struct rcu_head rcu;
72275 struct inet_peer *gc_next;
72276@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
72277 more++;
72278 inet_peer_refcheck(p);
72279 do {
72280- old = atomic_read(&p->ip_id_count);
72281+ old = atomic_read_unchecked(&p->ip_id_count);
72282 new = old + more;
72283 if (!new)
72284 new = 1;
72285- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
72286+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
72287 return new;
72288 }
72289
72290diff --git a/include/net/ip.h b/include/net/ip.h
72291index a68f838..74518ab 100644
72292--- a/include/net/ip.h
72293+++ b/include/net/ip.h
72294@@ -202,7 +202,7 @@ extern struct local_ports {
72295 } sysctl_local_ports;
72296 extern void inet_get_local_port_range(int *low, int *high);
72297
72298-extern unsigned long *sysctl_local_reserved_ports;
72299+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
72300 static inline int inet_is_reserved_local_port(int port)
72301 {
72302 return test_bit(port, sysctl_local_reserved_ports);
72303diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
72304index e49db91..76a81de 100644
72305--- a/include/net/ip_fib.h
72306+++ b/include/net/ip_fib.h
72307@@ -167,7 +167,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
72308
72309 #define FIB_RES_SADDR(net, res) \
72310 ((FIB_RES_NH(res).nh_saddr_genid == \
72311- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
72312+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
72313 FIB_RES_NH(res).nh_saddr : \
72314 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
72315 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
72316diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
72317index fce8e6b..3ca4916 100644
72318--- a/include/net/ip_vs.h
72319+++ b/include/net/ip_vs.h
72320@@ -599,7 +599,7 @@ struct ip_vs_conn {
72321 struct ip_vs_conn *control; /* Master control connection */
72322 atomic_t n_control; /* Number of controlled ones */
72323 struct ip_vs_dest *dest; /* real server */
72324- atomic_t in_pkts; /* incoming packet counter */
72325+ atomic_unchecked_t in_pkts; /* incoming packet counter */
72326
72327 /* packet transmitter for different forwarding methods. If it
72328 mangles the packet, it must return NF_DROP or better NF_STOLEN,
72329@@ -737,7 +737,7 @@ struct ip_vs_dest {
72330 __be16 port; /* port number of the server */
72331 union nf_inet_addr addr; /* IP address of the server */
72332 volatile unsigned int flags; /* dest status flags */
72333- atomic_t conn_flags; /* flags to copy to conn */
72334+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
72335 atomic_t weight; /* server weight */
72336
72337 atomic_t refcnt; /* reference counter */
72338@@ -981,11 +981,11 @@ struct netns_ipvs {
72339 /* ip_vs_lblc */
72340 int sysctl_lblc_expiration;
72341 struct ctl_table_header *lblc_ctl_header;
72342- struct ctl_table *lblc_ctl_table;
72343+ ctl_table_no_const *lblc_ctl_table;
72344 /* ip_vs_lblcr */
72345 int sysctl_lblcr_expiration;
72346 struct ctl_table_header *lblcr_ctl_header;
72347- struct ctl_table *lblcr_ctl_table;
72348+ ctl_table_no_const *lblcr_ctl_table;
72349 /* ip_vs_est */
72350 struct list_head est_list; /* estimator list */
72351 spinlock_t est_lock;
72352diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
72353index 80ffde3..968b0f4 100644
72354--- a/include/net/irda/ircomm_tty.h
72355+++ b/include/net/irda/ircomm_tty.h
72356@@ -35,6 +35,7 @@
72357 #include <linux/termios.h>
72358 #include <linux/timer.h>
72359 #include <linux/tty.h> /* struct tty_struct */
72360+#include <asm/local.h>
72361
72362 #include <net/irda/irias_object.h>
72363 #include <net/irda/ircomm_core.h>
72364diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
72365index 714cc9a..ea05f3e 100644
72366--- a/include/net/iucv/af_iucv.h
72367+++ b/include/net/iucv/af_iucv.h
72368@@ -149,7 +149,7 @@ struct iucv_skb_cb {
72369 struct iucv_sock_list {
72370 struct hlist_head head;
72371 rwlock_t lock;
72372- atomic_t autobind_name;
72373+ atomic_unchecked_t autobind_name;
72374 };
72375
72376 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
72377diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
72378index df83f69..9b640b8 100644
72379--- a/include/net/llc_c_ac.h
72380+++ b/include/net/llc_c_ac.h
72381@@ -87,7 +87,7 @@
72382 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
72383 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
72384
72385-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
72386+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
72387
72388 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
72389 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
72390diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
72391index 6ca3113..f8026dd 100644
72392--- a/include/net/llc_c_ev.h
72393+++ b/include/net/llc_c_ev.h
72394@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
72395 return (struct llc_conn_state_ev *)skb->cb;
72396 }
72397
72398-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
72399-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
72400+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
72401+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
72402
72403 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
72404 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
72405diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
72406index 0e79cfb..f46db31 100644
72407--- a/include/net/llc_c_st.h
72408+++ b/include/net/llc_c_st.h
72409@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
72410 u8 next_state;
72411 llc_conn_ev_qfyr_t *ev_qualifiers;
72412 llc_conn_action_t *ev_actions;
72413-};
72414+} __do_const;
72415
72416 struct llc_conn_state {
72417 u8 current_state;
72418diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
72419index 37a3bbd..55a4241 100644
72420--- a/include/net/llc_s_ac.h
72421+++ b/include/net/llc_s_ac.h
72422@@ -23,7 +23,7 @@
72423 #define SAP_ACT_TEST_IND 9
72424
72425 /* All action functions must look like this */
72426-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
72427+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
72428
72429 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
72430 struct sk_buff *skb);
72431diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
72432index 567c681..cd73ac0 100644
72433--- a/include/net/llc_s_st.h
72434+++ b/include/net/llc_s_st.h
72435@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
72436 llc_sap_ev_t ev;
72437 u8 next_state;
72438 llc_sap_action_t *ev_actions;
72439-};
72440+} __do_const;
72441
72442 struct llc_sap_state {
72443 u8 curr_state;
72444diff --git a/include/net/mac80211.h b/include/net/mac80211.h
72445index f7eba13..91ed983 100644
72446--- a/include/net/mac80211.h
72447+++ b/include/net/mac80211.h
72448@@ -4119,7 +4119,7 @@ struct rate_control_ops {
72449 void (*add_sta_debugfs)(void *priv, void *priv_sta,
72450 struct dentry *dir);
72451 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
72452-};
72453+} __do_const;
72454
72455 static inline int rate_supported(struct ieee80211_sta *sta,
72456 enum ieee80211_band band,
72457diff --git a/include/net/neighbour.h b/include/net/neighbour.h
72458index 7e748ad..5c6229b 100644
72459--- a/include/net/neighbour.h
72460+++ b/include/net/neighbour.h
72461@@ -123,7 +123,7 @@ struct neigh_ops {
72462 void (*error_report)(struct neighbour *, struct sk_buff *);
72463 int (*output)(struct neighbour *, struct sk_buff *);
72464 int (*connected_output)(struct neighbour *, struct sk_buff *);
72465-};
72466+} __do_const;
72467
72468 struct pneigh_entry {
72469 struct pneigh_entry *next;
72470diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
72471index de644bc..dfbcc4c 100644
72472--- a/include/net/net_namespace.h
72473+++ b/include/net/net_namespace.h
72474@@ -115,7 +115,7 @@ struct net {
72475 #endif
72476 struct netns_ipvs *ipvs;
72477 struct sock *diag_nlsk;
72478- atomic_t rt_genid;
72479+ atomic_unchecked_t rt_genid;
72480 };
72481
72482 /*
72483@@ -272,7 +272,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
72484 #define __net_init __init
72485 #define __net_exit __exit_refok
72486 #define __net_initdata __initdata
72487+#ifdef CONSTIFY_PLUGIN
72488 #define __net_initconst __initconst
72489+#else
72490+#define __net_initconst __initdata
72491+#endif
72492 #endif
72493
72494 struct pernet_operations {
72495@@ -282,7 +286,7 @@ struct pernet_operations {
72496 void (*exit_batch)(struct list_head *net_exit_list);
72497 int *id;
72498 size_t size;
72499-};
72500+} __do_const;
72501
72502 /*
72503 * Use these carefully. If you implement a network device and it
72504@@ -330,12 +334,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
72505
72506 static inline int rt_genid(struct net *net)
72507 {
72508- return atomic_read(&net->rt_genid);
72509+ return atomic_read_unchecked(&net->rt_genid);
72510 }
72511
72512 static inline void rt_genid_bump(struct net *net)
72513 {
72514- atomic_inc(&net->rt_genid);
72515+ atomic_inc_unchecked(&net->rt_genid);
72516 }
72517
72518 #endif /* __NET_NET_NAMESPACE_H */
72519diff --git a/include/net/netdma.h b/include/net/netdma.h
72520index 8ba8ce2..99b7fff 100644
72521--- a/include/net/netdma.h
72522+++ b/include/net/netdma.h
72523@@ -24,7 +24,7 @@
72524 #include <linux/dmaengine.h>
72525 #include <linux/skbuff.h>
72526
72527-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
72528+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
72529 struct sk_buff *skb, int offset, struct iovec *to,
72530 size_t len, struct dma_pinned_list *pinned_list);
72531
72532diff --git a/include/net/netlink.h b/include/net/netlink.h
72533index 9690b0f..87aded7 100644
72534--- a/include/net/netlink.h
72535+++ b/include/net/netlink.h
72536@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
72537 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
72538 {
72539 if (mark)
72540- skb_trim(skb, (unsigned char *) mark - skb->data);
72541+ skb_trim(skb, (const unsigned char *) mark - skb->data);
72542 }
72543
72544 /**
72545diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
72546index c9c0c53..53f24c3 100644
72547--- a/include/net/netns/conntrack.h
72548+++ b/include/net/netns/conntrack.h
72549@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
72550 struct nf_proto_net {
72551 #ifdef CONFIG_SYSCTL
72552 struct ctl_table_header *ctl_table_header;
72553- struct ctl_table *ctl_table;
72554+ ctl_table_no_const *ctl_table;
72555 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
72556 struct ctl_table_header *ctl_compat_header;
72557- struct ctl_table *ctl_compat_table;
72558+ ctl_table_no_const *ctl_compat_table;
72559 #endif
72560 #endif
72561 unsigned int users;
72562@@ -58,7 +58,7 @@ struct nf_ip_net {
72563 struct nf_icmp_net icmpv6;
72564 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
72565 struct ctl_table_header *ctl_table_header;
72566- struct ctl_table *ctl_table;
72567+ ctl_table_no_const *ctl_table;
72568 #endif
72569 };
72570
72571diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
72572index 2ba9de8..47bd6c7 100644
72573--- a/include/net/netns/ipv4.h
72574+++ b/include/net/netns/ipv4.h
72575@@ -67,7 +67,7 @@ struct netns_ipv4 {
72576 kgid_t sysctl_ping_group_range[2];
72577 long sysctl_tcp_mem[3];
72578
72579- atomic_t dev_addr_genid;
72580+ atomic_unchecked_t dev_addr_genid;
72581
72582 #ifdef CONFIG_IP_MROUTE
72583 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
72584diff --git a/include/net/protocol.h b/include/net/protocol.h
72585index 047c047..b9dad15 100644
72586--- a/include/net/protocol.h
72587+++ b/include/net/protocol.h
72588@@ -44,7 +44,7 @@ struct net_protocol {
72589 void (*err_handler)(struct sk_buff *skb, u32 info);
72590 unsigned int no_policy:1,
72591 netns_ok:1;
72592-};
72593+} __do_const;
72594
72595 #if IS_ENABLED(CONFIG_IPV6)
72596 struct inet6_protocol {
72597@@ -57,7 +57,7 @@ struct inet6_protocol {
72598 u8 type, u8 code, int offset,
72599 __be32 info);
72600 unsigned int flags; /* INET6_PROTO_xxx */
72601-};
72602+} __do_const;
72603
72604 #define INET6_PROTO_NOPOLICY 0x1
72605 #define INET6_PROTO_FINAL 0x2
72606diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
72607index 5a15fab..d799ea7 100644
72608--- a/include/net/rtnetlink.h
72609+++ b/include/net/rtnetlink.h
72610@@ -81,7 +81,7 @@ struct rtnl_link_ops {
72611 const struct net_device *dev);
72612 unsigned int (*get_num_tx_queues)(void);
72613 unsigned int (*get_num_rx_queues)(void);
72614-};
72615+} __do_const;
72616
72617 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
72618 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
72619diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
72620index df85a0c..19ac300 100644
72621--- a/include/net/sctp/sctp.h
72622+++ b/include/net/sctp/sctp.h
72623@@ -330,9 +330,9 @@ do { \
72624
72625 #else /* SCTP_DEBUG */
72626
72627-#define SCTP_DEBUG_PRINTK(whatever...)
72628-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
72629-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
72630+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
72631+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
72632+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
72633 #define SCTP_ENABLE_DEBUG
72634 #define SCTP_DISABLE_DEBUG
72635 #define SCTP_ASSERT(expr, str, func)
72636diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
72637index 2a82d13..62a31c2 100644
72638--- a/include/net/sctp/sm.h
72639+++ b/include/net/sctp/sm.h
72640@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
72641 typedef struct {
72642 sctp_state_fn_t *fn;
72643 const char *name;
72644-} sctp_sm_table_entry_t;
72645+} __do_const sctp_sm_table_entry_t;
72646
72647 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
72648 * currently in use.
72649@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
72650 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
72651
72652 /* Extern declarations for major data structures. */
72653-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
72654+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
72655
72656
72657 /* Get the size of a DATA chunk payload. */
72658diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
72659index 0e0f9d2..cd05ebb 100644
72660--- a/include/net/sctp/structs.h
72661+++ b/include/net/sctp/structs.h
72662@@ -517,7 +517,7 @@ struct sctp_pf {
72663 struct sctp_association *asoc);
72664 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
72665 struct sctp_af *af;
72666-};
72667+} __do_const;
72668
72669
72670 /* Structure to track chunk fragments that have been acked, but peer
72671diff --git a/include/net/secure_seq.h b/include/net/secure_seq.h
72672index c2e542b..6ca975b 100644
72673--- a/include/net/secure_seq.h
72674+++ b/include/net/secure_seq.h
72675@@ -3,6 +3,7 @@
72676
72677 #include <linux/types.h>
72678
72679+extern void net_secret_init(void);
72680 extern __u32 secure_ip_id(__be32 daddr);
72681 extern __u32 secure_ipv6_id(const __be32 daddr[4]);
72682 extern u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport);
72683diff --git a/include/net/sock.h b/include/net/sock.h
72684index 0be480a..586232f 100644
72685--- a/include/net/sock.h
72686+++ b/include/net/sock.h
72687@@ -325,7 +325,7 @@ struct sock {
72688 #ifdef CONFIG_RPS
72689 __u32 sk_rxhash;
72690 #endif
72691- atomic_t sk_drops;
72692+ atomic_unchecked_t sk_drops;
72693 int sk_rcvbuf;
72694
72695 struct sk_filter __rcu *sk_filter;
72696@@ -1796,7 +1796,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
72697 }
72698
72699 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
72700- char __user *from, char *to,
72701+ char __user *from, unsigned char *to,
72702 int copy, int offset)
72703 {
72704 if (skb->ip_summed == CHECKSUM_NONE) {
72705@@ -2055,7 +2055,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
72706 }
72707 }
72708
72709-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
72710+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
72711
72712 /**
72713 * sk_page_frag - return an appropriate page_frag
72714diff --git a/include/net/tcp.h b/include/net/tcp.h
72715index a345480..3c65cf4 100644
72716--- a/include/net/tcp.h
72717+++ b/include/net/tcp.h
72718@@ -529,7 +529,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
72719 extern void tcp_xmit_retransmit_queue(struct sock *);
72720 extern void tcp_simple_retransmit(struct sock *);
72721 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
72722-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
72723+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
72724
72725 extern void tcp_send_probe0(struct sock *);
72726 extern void tcp_send_partial(struct sock *);
72727@@ -700,8 +700,8 @@ struct tcp_skb_cb {
72728 struct inet6_skb_parm h6;
72729 #endif
72730 } header; /* For incoming frames */
72731- __u32 seq; /* Starting sequence number */
72732- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
72733+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
72734+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
72735 __u32 when; /* used to compute rtt's */
72736 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
72737
72738@@ -715,7 +715,7 @@ struct tcp_skb_cb {
72739
72740 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
72741 /* 1 byte hole */
72742- __u32 ack_seq; /* Sequence number ACK'd */
72743+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
72744 };
72745
72746 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
72747diff --git a/include/net/xfrm.h b/include/net/xfrm.h
72748index 24c8886..e6fb816 100644
72749--- a/include/net/xfrm.h
72750+++ b/include/net/xfrm.h
72751@@ -304,7 +304,7 @@ struct xfrm_policy_afinfo {
72752 struct net_device *dev,
72753 const struct flowi *fl);
72754 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
72755-};
72756+} __do_const;
72757
72758 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
72759 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
72760@@ -340,7 +340,7 @@ struct xfrm_state_afinfo {
72761 struct sk_buff *skb);
72762 int (*transport_finish)(struct sk_buff *skb,
72763 int async);
72764-};
72765+} __do_const;
72766
72767 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
72768 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
72769@@ -423,7 +423,7 @@ struct xfrm_mode {
72770 struct module *owner;
72771 unsigned int encap;
72772 int flags;
72773-};
72774+} __do_const;
72775
72776 /* Flags for xfrm_mode. */
72777 enum {
72778@@ -520,7 +520,7 @@ struct xfrm_policy {
72779 struct timer_list timer;
72780
72781 struct flow_cache_object flo;
72782- atomic_t genid;
72783+ atomic_unchecked_t genid;
72784 u32 priority;
72785 u32 index;
72786 struct xfrm_mark mark;
72787diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
72788index 1a046b1..ee0bef0 100644
72789--- a/include/rdma/iw_cm.h
72790+++ b/include/rdma/iw_cm.h
72791@@ -122,7 +122,7 @@ struct iw_cm_verbs {
72792 int backlog);
72793
72794 int (*destroy_listen)(struct iw_cm_id *cm_id);
72795-};
72796+} __no_const;
72797
72798 /**
72799 * iw_create_cm_id - Create an IW CM identifier.
72800diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
72801index e1379b4..67eafbe 100644
72802--- a/include/scsi/libfc.h
72803+++ b/include/scsi/libfc.h
72804@@ -762,6 +762,7 @@ struct libfc_function_template {
72805 */
72806 void (*disc_stop_final) (struct fc_lport *);
72807 };
72808+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
72809
72810 /**
72811 * struct fc_disc - Discovery context
72812@@ -866,7 +867,7 @@ struct fc_lport {
72813 struct fc_vport *vport;
72814
72815 /* Operational Information */
72816- struct libfc_function_template tt;
72817+ libfc_function_template_no_const tt;
72818 u8 link_up;
72819 u8 qfull;
72820 enum fc_lport_state state;
72821diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
72822index a7f9cba..b1f44d0 100644
72823--- a/include/scsi/scsi_device.h
72824+++ b/include/scsi/scsi_device.h
72825@@ -171,9 +171,9 @@ struct scsi_device {
72826 unsigned int max_device_blocked; /* what device_blocked counts down from */
72827 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
72828
72829- atomic_t iorequest_cnt;
72830- atomic_t iodone_cnt;
72831- atomic_t ioerr_cnt;
72832+ atomic_unchecked_t iorequest_cnt;
72833+ atomic_unchecked_t iodone_cnt;
72834+ atomic_unchecked_t ioerr_cnt;
72835
72836 struct device sdev_gendev,
72837 sdev_dev;
72838diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
72839index b797e8f..8e2c3aa 100644
72840--- a/include/scsi/scsi_transport_fc.h
72841+++ b/include/scsi/scsi_transport_fc.h
72842@@ -751,7 +751,8 @@ struct fc_function_template {
72843 unsigned long show_host_system_hostname:1;
72844
72845 unsigned long disable_target_scan:1;
72846-};
72847+} __do_const;
72848+typedef struct fc_function_template __no_const fc_function_template_no_const;
72849
72850
72851 /**
72852diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
72853index ff6c741..393815f 100644
72854--- a/include/sound/compress_driver.h
72855+++ b/include/sound/compress_driver.h
72856@@ -130,7 +130,7 @@ struct snd_compr_ops {
72857 struct snd_compr_caps *caps);
72858 int (*get_codec_caps) (struct snd_compr_stream *stream,
72859 struct snd_compr_codec_caps *codec);
72860-};
72861+} __no_const;
72862
72863 /**
72864 * struct snd_compr: Compressed device
72865diff --git a/include/sound/soc.h b/include/sound/soc.h
72866index a6a059c..2243336 100644
72867--- a/include/sound/soc.h
72868+++ b/include/sound/soc.h
72869@@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
72870 /* probe ordering - for components with runtime dependencies */
72871 int probe_order;
72872 int remove_order;
72873-};
72874+} __do_const;
72875
72876 /* SoC platform interface */
72877 struct snd_soc_platform_driver {
72878@@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
72879 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
72880 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
72881 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
72882-};
72883+} __do_const;
72884
72885 struct snd_soc_platform {
72886 const char *name;
72887diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
72888index f8640f3..b72d113 100644
72889--- a/include/target/target_core_base.h
72890+++ b/include/target/target_core_base.h
72891@@ -658,7 +658,7 @@ struct se_device {
72892 spinlock_t stats_lock;
72893 /* Active commands on this virtual SE device */
72894 atomic_t simple_cmds;
72895- atomic_t dev_ordered_id;
72896+ atomic_unchecked_t dev_ordered_id;
72897 atomic_t dev_ordered_sync;
72898 atomic_t dev_qf_count;
72899 int export_count;
72900diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
72901new file mode 100644
72902index 0000000..fb634b7
72903--- /dev/null
72904+++ b/include/trace/events/fs.h
72905@@ -0,0 +1,53 @@
72906+#undef TRACE_SYSTEM
72907+#define TRACE_SYSTEM fs
72908+
72909+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
72910+#define _TRACE_FS_H
72911+
72912+#include <linux/fs.h>
72913+#include <linux/tracepoint.h>
72914+
72915+TRACE_EVENT(do_sys_open,
72916+
72917+ TP_PROTO(const char *filename, int flags, int mode),
72918+
72919+ TP_ARGS(filename, flags, mode),
72920+
72921+ TP_STRUCT__entry(
72922+ __string( filename, filename )
72923+ __field( int, flags )
72924+ __field( int, mode )
72925+ ),
72926+
72927+ TP_fast_assign(
72928+ __assign_str(filename, filename);
72929+ __entry->flags = flags;
72930+ __entry->mode = mode;
72931+ ),
72932+
72933+ TP_printk("\"%s\" %x %o",
72934+ __get_str(filename), __entry->flags, __entry->mode)
72935+);
72936+
72937+TRACE_EVENT(open_exec,
72938+
72939+ TP_PROTO(const char *filename),
72940+
72941+ TP_ARGS(filename),
72942+
72943+ TP_STRUCT__entry(
72944+ __string( filename, filename )
72945+ ),
72946+
72947+ TP_fast_assign(
72948+ __assign_str(filename, filename);
72949+ ),
72950+
72951+ TP_printk("\"%s\"",
72952+ __get_str(filename))
72953+);
72954+
72955+#endif /* _TRACE_FS_H */
72956+
72957+/* This part must be outside protection */
72958+#include <trace/define_trace.h>
72959diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
72960index 1c09820..7f5ec79 100644
72961--- a/include/trace/events/irq.h
72962+++ b/include/trace/events/irq.h
72963@@ -36,7 +36,7 @@ struct softirq_action;
72964 */
72965 TRACE_EVENT(irq_handler_entry,
72966
72967- TP_PROTO(int irq, struct irqaction *action),
72968+ TP_PROTO(int irq, const struct irqaction *action),
72969
72970 TP_ARGS(irq, action),
72971
72972@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
72973 */
72974 TRACE_EVENT(irq_handler_exit,
72975
72976- TP_PROTO(int irq, struct irqaction *action, int ret),
72977+ TP_PROTO(int irq, const struct irqaction *action, int ret),
72978
72979 TP_ARGS(irq, action, ret),
72980
72981diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
72982index 7caf44c..23c6f27 100644
72983--- a/include/uapi/linux/a.out.h
72984+++ b/include/uapi/linux/a.out.h
72985@@ -39,6 +39,14 @@ enum machine_type {
72986 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
72987 };
72988
72989+/* Constants for the N_FLAGS field */
72990+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
72991+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
72992+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
72993+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
72994+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
72995+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
72996+
72997 #if !defined (N_MAGIC)
72998 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
72999 #endif
73000diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
73001index d876736..ccce5c0 100644
73002--- a/include/uapi/linux/byteorder/little_endian.h
73003+++ b/include/uapi/linux/byteorder/little_endian.h
73004@@ -42,51 +42,51 @@
73005
73006 static inline __le64 __cpu_to_le64p(const __u64 *p)
73007 {
73008- return (__force __le64)*p;
73009+ return (__force const __le64)*p;
73010 }
73011-static inline __u64 __le64_to_cpup(const __le64 *p)
73012+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
73013 {
73014- return (__force __u64)*p;
73015+ return (__force const __u64)*p;
73016 }
73017 static inline __le32 __cpu_to_le32p(const __u32 *p)
73018 {
73019- return (__force __le32)*p;
73020+ return (__force const __le32)*p;
73021 }
73022 static inline __u32 __le32_to_cpup(const __le32 *p)
73023 {
73024- return (__force __u32)*p;
73025+ return (__force const __u32)*p;
73026 }
73027 static inline __le16 __cpu_to_le16p(const __u16 *p)
73028 {
73029- return (__force __le16)*p;
73030+ return (__force const __le16)*p;
73031 }
73032 static inline __u16 __le16_to_cpup(const __le16 *p)
73033 {
73034- return (__force __u16)*p;
73035+ return (__force const __u16)*p;
73036 }
73037 static inline __be64 __cpu_to_be64p(const __u64 *p)
73038 {
73039- return (__force __be64)__swab64p(p);
73040+ return (__force const __be64)__swab64p(p);
73041 }
73042 static inline __u64 __be64_to_cpup(const __be64 *p)
73043 {
73044- return __swab64p((__u64 *)p);
73045+ return __swab64p((const __u64 *)p);
73046 }
73047 static inline __be32 __cpu_to_be32p(const __u32 *p)
73048 {
73049- return (__force __be32)__swab32p(p);
73050+ return (__force const __be32)__swab32p(p);
73051 }
73052-static inline __u32 __be32_to_cpup(const __be32 *p)
73053+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
73054 {
73055- return __swab32p((__u32 *)p);
73056+ return __swab32p((const __u32 *)p);
73057 }
73058 static inline __be16 __cpu_to_be16p(const __u16 *p)
73059 {
73060- return (__force __be16)__swab16p(p);
73061+ return (__force const __be16)__swab16p(p);
73062 }
73063 static inline __u16 __be16_to_cpup(const __be16 *p)
73064 {
73065- return __swab16p((__u16 *)p);
73066+ return __swab16p((const __u16 *)p);
73067 }
73068 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
73069 #define __le64_to_cpus(x) do { (void)(x); } while (0)
73070diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
73071index 8072d35..e77aeb8 100644
73072--- a/include/uapi/linux/elf.h
73073+++ b/include/uapi/linux/elf.h
73074@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
73075 #define PT_GNU_EH_FRAME 0x6474e550
73076
73077 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
73078+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
73079+
73080+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
73081+
73082+/* Constants for the e_flags field */
73083+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
73084+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
73085+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
73086+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
73087+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
73088+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
73089
73090 /*
73091 * Extended Numbering
73092@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
73093 #define DT_DEBUG 21
73094 #define DT_TEXTREL 22
73095 #define DT_JMPREL 23
73096+#define DT_FLAGS 30
73097+ #define DF_TEXTREL 0x00000004
73098 #define DT_ENCODING 32
73099 #define OLD_DT_LOOS 0x60000000
73100 #define DT_LOOS 0x6000000d
73101@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
73102 #define PF_W 0x2
73103 #define PF_X 0x1
73104
73105+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
73106+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
73107+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
73108+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
73109+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
73110+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
73111+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
73112+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
73113+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
73114+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
73115+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
73116+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
73117+
73118 typedef struct elf32_phdr{
73119 Elf32_Word p_type;
73120 Elf32_Off p_offset;
73121@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
73122 #define EI_OSABI 7
73123 #define EI_PAD 8
73124
73125+#define EI_PAX 14
73126+
73127 #define ELFMAG0 0x7f /* EI_MAG */
73128 #define ELFMAG1 'E'
73129 #define ELFMAG2 'L'
73130diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
73131index aa169c4..6a2771d 100644
73132--- a/include/uapi/linux/personality.h
73133+++ b/include/uapi/linux/personality.h
73134@@ -30,6 +30,7 @@ enum {
73135 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
73136 ADDR_NO_RANDOMIZE | \
73137 ADDR_COMPAT_LAYOUT | \
73138+ ADDR_LIMIT_3GB | \
73139 MMAP_PAGE_ZERO)
73140
73141 /*
73142diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
73143index 7530e74..e714828 100644
73144--- a/include/uapi/linux/screen_info.h
73145+++ b/include/uapi/linux/screen_info.h
73146@@ -43,7 +43,8 @@ struct screen_info {
73147 __u16 pages; /* 0x32 */
73148 __u16 vesa_attributes; /* 0x34 */
73149 __u32 capabilities; /* 0x36 */
73150- __u8 _reserved[6]; /* 0x3a */
73151+ __u16 vesapm_size; /* 0x3a */
73152+ __u8 _reserved[4]; /* 0x3c */
73153 } __attribute__((packed));
73154
73155 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
73156diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
73157index 0e011eb..82681b1 100644
73158--- a/include/uapi/linux/swab.h
73159+++ b/include/uapi/linux/swab.h
73160@@ -43,7 +43,7 @@
73161 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
73162 */
73163
73164-static inline __attribute_const__ __u16 __fswab16(__u16 val)
73165+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
73166 {
73167 #ifdef __HAVE_BUILTIN_BSWAP16__
73168 return __builtin_bswap16(val);
73169@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
73170 #endif
73171 }
73172
73173-static inline __attribute_const__ __u32 __fswab32(__u32 val)
73174+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
73175 {
73176 #ifdef __HAVE_BUILTIN_BSWAP32__
73177 return __builtin_bswap32(val);
73178@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
73179 #endif
73180 }
73181
73182-static inline __attribute_const__ __u64 __fswab64(__u64 val)
73183+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
73184 {
73185 #ifdef __HAVE_BUILTIN_BSWAP64__
73186 return __builtin_bswap64(val);
73187diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
73188index 6d67213..8dab561 100644
73189--- a/include/uapi/linux/sysctl.h
73190+++ b/include/uapi/linux/sysctl.h
73191@@ -155,7 +155,11 @@ enum
73192 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
73193 };
73194
73195-
73196+#ifdef CONFIG_PAX_SOFTMODE
73197+enum {
73198+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
73199+};
73200+#endif
73201
73202 /* CTL_VM names: */
73203 enum
73204diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
73205index e4629b9..6958086 100644
73206--- a/include/uapi/linux/xattr.h
73207+++ b/include/uapi/linux/xattr.h
73208@@ -63,5 +63,9 @@
73209 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
73210 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
73211
73212+/* User namespace */
73213+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
73214+#define XATTR_PAX_FLAGS_SUFFIX "flags"
73215+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
73216
73217 #endif /* _UAPI_LINUX_XATTR_H */
73218diff --git a/include/video/udlfb.h b/include/video/udlfb.h
73219index f9466fa..f4e2b81 100644
73220--- a/include/video/udlfb.h
73221+++ b/include/video/udlfb.h
73222@@ -53,10 +53,10 @@ struct dlfb_data {
73223 u32 pseudo_palette[256];
73224 int blank_mode; /*one of FB_BLANK_ */
73225 /* blit-only rendering path metrics, exposed through sysfs */
73226- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
73227- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
73228- atomic_t bytes_sent; /* to usb, after compression including overhead */
73229- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
73230+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
73231+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
73232+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
73233+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
73234 };
73235
73236 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
73237diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
73238index 1a91850..28573f8 100644
73239--- a/include/video/uvesafb.h
73240+++ b/include/video/uvesafb.h
73241@@ -122,6 +122,7 @@ struct uvesafb_par {
73242 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
73243 u8 pmi_setpal; /* PMI for palette changes */
73244 u16 *pmi_base; /* protected mode interface location */
73245+ u8 *pmi_code; /* protected mode code location */
73246 void *pmi_start;
73247 void *pmi_pal;
73248 u8 *vbe_state_orig; /*
73249diff --git a/init/Kconfig b/init/Kconfig
73250index 5341d72..153f24f 100644
73251--- a/init/Kconfig
73252+++ b/init/Kconfig
73253@@ -984,6 +984,7 @@ endif # CGROUPS
73254
73255 config CHECKPOINT_RESTORE
73256 bool "Checkpoint/restore support" if EXPERT
73257+ depends on !GRKERNSEC
73258 default n
73259 help
73260 Enables additional kernel features in a sake of checkpoint/restore.
73261@@ -1471,7 +1472,7 @@ config SLUB_DEBUG
73262
73263 config COMPAT_BRK
73264 bool "Disable heap randomization"
73265- default y
73266+ default n
73267 help
73268 Randomizing heap placement makes heap exploits harder, but it
73269 also breaks ancient binaries (including anything libc5 based).
73270@@ -1734,7 +1735,7 @@ config INIT_ALL_POSSIBLE
73271 config STOP_MACHINE
73272 bool
73273 default y
73274- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
73275+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
73276 help
73277 Need stop_machine() primitive.
73278
73279diff --git a/init/Makefile b/init/Makefile
73280index 7bc47ee..6da2dc7 100644
73281--- a/init/Makefile
73282+++ b/init/Makefile
73283@@ -2,6 +2,9 @@
73284 # Makefile for the linux kernel.
73285 #
73286
73287+ccflags-y := $(GCC_PLUGINS_CFLAGS)
73288+asflags-y := $(GCC_PLUGINS_AFLAGS)
73289+
73290 obj-y := main.o version.o mounts.o
73291 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
73292 obj-y += noinitramfs.o
73293diff --git a/init/do_mounts.c b/init/do_mounts.c
73294index a2b49f2..03a0e17c 100644
73295--- a/init/do_mounts.c
73296+++ b/init/do_mounts.c
73297@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
73298 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
73299 {
73300 struct super_block *s;
73301- int err = sys_mount(name, "/root", fs, flags, data);
73302+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
73303 if (err)
73304 return err;
73305
73306- sys_chdir("/root");
73307+ sys_chdir((const char __force_user *)"/root");
73308 s = current->fs->pwd.dentry->d_sb;
73309 ROOT_DEV = s->s_dev;
73310 printk(KERN_INFO
73311@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
73312 va_start(args, fmt);
73313 vsprintf(buf, fmt, args);
73314 va_end(args);
73315- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
73316+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
73317 if (fd >= 0) {
73318 sys_ioctl(fd, FDEJECT, 0);
73319 sys_close(fd);
73320 }
73321 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
73322- fd = sys_open("/dev/console", O_RDWR, 0);
73323+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
73324 if (fd >= 0) {
73325 sys_ioctl(fd, TCGETS, (long)&termios);
73326 termios.c_lflag &= ~ICANON;
73327 sys_ioctl(fd, TCSETSF, (long)&termios);
73328- sys_read(fd, &c, 1);
73329+ sys_read(fd, (char __user *)&c, 1);
73330 termios.c_lflag |= ICANON;
73331 sys_ioctl(fd, TCSETSF, (long)&termios);
73332 sys_close(fd);
73333@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
73334 mount_root();
73335 out:
73336 devtmpfs_mount("dev");
73337- sys_mount(".", "/", NULL, MS_MOVE, NULL);
73338- sys_chroot(".");
73339+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
73340+ sys_chroot((const char __force_user *)".");
73341 }
73342diff --git a/init/do_mounts.h b/init/do_mounts.h
73343index f5b978a..69dbfe8 100644
73344--- a/init/do_mounts.h
73345+++ b/init/do_mounts.h
73346@@ -15,15 +15,15 @@ extern int root_mountflags;
73347
73348 static inline int create_dev(char *name, dev_t dev)
73349 {
73350- sys_unlink(name);
73351- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
73352+ sys_unlink((char __force_user *)name);
73353+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
73354 }
73355
73356 #if BITS_PER_LONG == 32
73357 static inline u32 bstat(char *name)
73358 {
73359 struct stat64 stat;
73360- if (sys_stat64(name, &stat) != 0)
73361+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
73362 return 0;
73363 if (!S_ISBLK(stat.st_mode))
73364 return 0;
73365@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
73366 static inline u32 bstat(char *name)
73367 {
73368 struct stat stat;
73369- if (sys_newstat(name, &stat) != 0)
73370+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
73371 return 0;
73372 if (!S_ISBLK(stat.st_mode))
73373 return 0;
73374diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
73375index a32ec1c..60a6659 100644
73376--- a/init/do_mounts_initrd.c
73377+++ b/init/do_mounts_initrd.c
73378@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
73379 {
73380 sys_unshare(CLONE_FS | CLONE_FILES);
73381 /* stdin/stdout/stderr for /linuxrc */
73382- sys_open("/dev/console", O_RDWR, 0);
73383+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
73384 sys_dup(0);
73385 sys_dup(0);
73386 /* move initrd over / and chdir/chroot in initrd root */
73387- sys_chdir("/root");
73388- sys_mount(".", "/", NULL, MS_MOVE, NULL);
73389- sys_chroot(".");
73390+ sys_chdir((const char __force_user *)"/root");
73391+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
73392+ sys_chroot((const char __force_user *)".");
73393 sys_setsid();
73394 return 0;
73395 }
73396@@ -58,8 +58,8 @@ static void __init handle_initrd(void)
73397 create_dev("/dev/root.old", Root_RAM0);
73398 /* mount initrd on rootfs' /root */
73399 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
73400- sys_mkdir("/old", 0700);
73401- sys_chdir("/old");
73402+ sys_mkdir((const char __force_user *)"/old", 0700);
73403+ sys_chdir((const char __force_user *)"/old");
73404
73405 /* try loading default modules from initrd */
73406 load_default_modules();
73407@@ -76,31 +76,31 @@ static void __init handle_initrd(void)
73408 current->flags &= ~PF_FREEZER_SKIP;
73409
73410 /* move initrd to rootfs' /old */
73411- sys_mount("..", ".", NULL, MS_MOVE, NULL);
73412+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
73413 /* switch root and cwd back to / of rootfs */
73414- sys_chroot("..");
73415+ sys_chroot((const char __force_user *)"..");
73416
73417 if (new_decode_dev(real_root_dev) == Root_RAM0) {
73418- sys_chdir("/old");
73419+ sys_chdir((const char __force_user *)"/old");
73420 return;
73421 }
73422
73423- sys_chdir("/");
73424+ sys_chdir((const char __force_user *)"/");
73425 ROOT_DEV = new_decode_dev(real_root_dev);
73426 mount_root();
73427
73428 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
73429- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
73430+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
73431 if (!error)
73432 printk("okay\n");
73433 else {
73434- int fd = sys_open("/dev/root.old", O_RDWR, 0);
73435+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
73436 if (error == -ENOENT)
73437 printk("/initrd does not exist. Ignored.\n");
73438 else
73439 printk("failed\n");
73440 printk(KERN_NOTICE "Unmounting old root\n");
73441- sys_umount("/old", MNT_DETACH);
73442+ sys_umount((char __force_user *)"/old", MNT_DETACH);
73443 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
73444 if (fd < 0) {
73445 error = fd;
73446@@ -123,11 +123,11 @@ int __init initrd_load(void)
73447 * mounted in the normal path.
73448 */
73449 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
73450- sys_unlink("/initrd.image");
73451+ sys_unlink((const char __force_user *)"/initrd.image");
73452 handle_initrd();
73453 return 1;
73454 }
73455 }
73456- sys_unlink("/initrd.image");
73457+ sys_unlink((const char __force_user *)"/initrd.image");
73458 return 0;
73459 }
73460diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
73461index 8cb6db5..d729f50 100644
73462--- a/init/do_mounts_md.c
73463+++ b/init/do_mounts_md.c
73464@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
73465 partitioned ? "_d" : "", minor,
73466 md_setup_args[ent].device_names);
73467
73468- fd = sys_open(name, 0, 0);
73469+ fd = sys_open((char __force_user *)name, 0, 0);
73470 if (fd < 0) {
73471 printk(KERN_ERR "md: open failed - cannot start "
73472 "array %s\n", name);
73473@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
73474 * array without it
73475 */
73476 sys_close(fd);
73477- fd = sys_open(name, 0, 0);
73478+ fd = sys_open((char __force_user *)name, 0, 0);
73479 sys_ioctl(fd, BLKRRPART, 0);
73480 }
73481 sys_close(fd);
73482@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
73483
73484 wait_for_device_probe();
73485
73486- fd = sys_open("/dev/md0", 0, 0);
73487+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
73488 if (fd >= 0) {
73489 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
73490 sys_close(fd);
73491diff --git a/init/init_task.c b/init/init_task.c
73492index ba0a7f36..2bcf1d5 100644
73493--- a/init/init_task.c
73494+++ b/init/init_task.c
73495@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
73496 * Initial thread structure. Alignment of this is handled by a special
73497 * linker map entry.
73498 */
73499+#ifdef CONFIG_X86
73500+union thread_union init_thread_union __init_task_data;
73501+#else
73502 union thread_union init_thread_union __init_task_data =
73503 { INIT_THREAD_INFO(init_task) };
73504+#endif
73505diff --git a/init/initramfs.c b/init/initramfs.c
73506index a67ef9d..3d88592 100644
73507--- a/init/initramfs.c
73508+++ b/init/initramfs.c
73509@@ -84,7 +84,7 @@ static void __init free_hash(void)
73510 }
73511 }
73512
73513-static long __init do_utime(char *filename, time_t mtime)
73514+static long __init do_utime(char __force_user *filename, time_t mtime)
73515 {
73516 struct timespec t[2];
73517
73518@@ -119,7 +119,7 @@ static void __init dir_utime(void)
73519 struct dir_entry *de, *tmp;
73520 list_for_each_entry_safe(de, tmp, &dir_list, list) {
73521 list_del(&de->list);
73522- do_utime(de->name, de->mtime);
73523+ do_utime((char __force_user *)de->name, de->mtime);
73524 kfree(de->name);
73525 kfree(de);
73526 }
73527@@ -281,7 +281,7 @@ static int __init maybe_link(void)
73528 if (nlink >= 2) {
73529 char *old = find_link(major, minor, ino, mode, collected);
73530 if (old)
73531- return (sys_link(old, collected) < 0) ? -1 : 1;
73532+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
73533 }
73534 return 0;
73535 }
73536@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
73537 {
73538 struct stat st;
73539
73540- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
73541+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
73542 if (S_ISDIR(st.st_mode))
73543- sys_rmdir(path);
73544+ sys_rmdir((char __force_user *)path);
73545 else
73546- sys_unlink(path);
73547+ sys_unlink((char __force_user *)path);
73548 }
73549 }
73550
73551@@ -315,7 +315,7 @@ static int __init do_name(void)
73552 int openflags = O_WRONLY|O_CREAT;
73553 if (ml != 1)
73554 openflags |= O_TRUNC;
73555- wfd = sys_open(collected, openflags, mode);
73556+ wfd = sys_open((char __force_user *)collected, openflags, mode);
73557
73558 if (wfd >= 0) {
73559 sys_fchown(wfd, uid, gid);
73560@@ -327,17 +327,17 @@ static int __init do_name(void)
73561 }
73562 }
73563 } else if (S_ISDIR(mode)) {
73564- sys_mkdir(collected, mode);
73565- sys_chown(collected, uid, gid);
73566- sys_chmod(collected, mode);
73567+ sys_mkdir((char __force_user *)collected, mode);
73568+ sys_chown((char __force_user *)collected, uid, gid);
73569+ sys_chmod((char __force_user *)collected, mode);
73570 dir_add(collected, mtime);
73571 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
73572 S_ISFIFO(mode) || S_ISSOCK(mode)) {
73573 if (maybe_link() == 0) {
73574- sys_mknod(collected, mode, rdev);
73575- sys_chown(collected, uid, gid);
73576- sys_chmod(collected, mode);
73577- do_utime(collected, mtime);
73578+ sys_mknod((char __force_user *)collected, mode, rdev);
73579+ sys_chown((char __force_user *)collected, uid, gid);
73580+ sys_chmod((char __force_user *)collected, mode);
73581+ do_utime((char __force_user *)collected, mtime);
73582 }
73583 }
73584 return 0;
73585@@ -346,15 +346,15 @@ static int __init do_name(void)
73586 static int __init do_copy(void)
73587 {
73588 if (count >= body_len) {
73589- sys_write(wfd, victim, body_len);
73590+ sys_write(wfd, (char __force_user *)victim, body_len);
73591 sys_close(wfd);
73592- do_utime(vcollected, mtime);
73593+ do_utime((char __force_user *)vcollected, mtime);
73594 kfree(vcollected);
73595 eat(body_len);
73596 state = SkipIt;
73597 return 0;
73598 } else {
73599- sys_write(wfd, victim, count);
73600+ sys_write(wfd, (char __force_user *)victim, count);
73601 body_len -= count;
73602 eat(count);
73603 return 1;
73604@@ -365,9 +365,9 @@ static int __init do_symlink(void)
73605 {
73606 collected[N_ALIGN(name_len) + body_len] = '\0';
73607 clean_path(collected, 0);
73608- sys_symlink(collected + N_ALIGN(name_len), collected);
73609- sys_lchown(collected, uid, gid);
73610- do_utime(collected, mtime);
73611+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
73612+ sys_lchown((char __force_user *)collected, uid, gid);
73613+ do_utime((char __force_user *)collected, mtime);
73614 state = SkipIt;
73615 next_state = Reset;
73616 return 0;
73617diff --git a/init/main.c b/init/main.c
73618index 63534a1..85feae2 100644
73619--- a/init/main.c
73620+++ b/init/main.c
73621@@ -98,6 +98,8 @@ static inline void mark_rodata_ro(void) { }
73622 extern void tc_init(void);
73623 #endif
73624
73625+extern void grsecurity_init(void);
73626+
73627 /*
73628 * Debug helper: via this flag we know that we are in 'early bootup code'
73629 * where only the boot processor is running with IRQ disabled. This means
73630@@ -151,6 +153,64 @@ static int __init set_reset_devices(char *str)
73631
73632 __setup("reset_devices", set_reset_devices);
73633
73634+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
73635+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
73636+static int __init setup_grsec_proc_gid(char *str)
73637+{
73638+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
73639+ return 1;
73640+}
73641+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
73642+#endif
73643+
73644+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
73645+unsigned long pax_user_shadow_base __read_only = 1UL << TASK_SIZE_MAX_SHIFT;
73646+EXPORT_SYMBOL(pax_user_shadow_base);
73647+extern char pax_enter_kernel_user[];
73648+extern char pax_exit_kernel_user[];
73649+extern pgdval_t clone_pgd_mask;
73650+#endif
73651+
73652+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
73653+static int __init setup_pax_nouderef(char *str)
73654+{
73655+#ifdef CONFIG_X86_32
73656+ unsigned int cpu;
73657+ struct desc_struct *gdt;
73658+
73659+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
73660+ gdt = get_cpu_gdt_table(cpu);
73661+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
73662+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
73663+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
73664+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
73665+ }
73666+ loadsegment(ds, __KERNEL_DS);
73667+ loadsegment(es, __KERNEL_DS);
73668+ loadsegment(ss, __KERNEL_DS);
73669+#else
73670+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
73671+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
73672+ clone_pgd_mask = ~(pgdval_t)0UL;
73673+ pax_user_shadow_base = 0UL;
73674+#endif
73675+
73676+ return 0;
73677+}
73678+early_param("pax_nouderef", setup_pax_nouderef);
73679+#endif
73680+
73681+#ifdef CONFIG_PAX_SOFTMODE
73682+int pax_softmode;
73683+
73684+static int __init setup_pax_softmode(char *str)
73685+{
73686+ get_option(&str, &pax_softmode);
73687+ return 1;
73688+}
73689+__setup("pax_softmode=", setup_pax_softmode);
73690+#endif
73691+
73692 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
73693 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
73694 static const char *panic_later, *panic_param;
73695@@ -683,6 +743,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
73696 {
73697 int count = preempt_count();
73698 int ret;
73699+ const char *msg1 = "", *msg2 = "";
73700
73701 if (initcall_debug)
73702 ret = do_one_initcall_debug(fn);
73703@@ -695,15 +756,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
73704 sprintf(msgbuf, "error code %d ", ret);
73705
73706 if (preempt_count() != count) {
73707- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
73708+ msg1 = " preemption imbalance";
73709 preempt_count() = count;
73710 }
73711 if (irqs_disabled()) {
73712- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
73713+ msg2 = " disabled interrupts";
73714 local_irq_enable();
73715 }
73716- if (msgbuf[0]) {
73717- printk("initcall %pF returned with %s\n", fn, msgbuf);
73718+ if (msgbuf[0] || *msg1 || *msg2) {
73719+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
73720 }
73721
73722 return ret;
73723@@ -757,8 +818,14 @@ static void __init do_initcall_level(int level)
73724 level, level,
73725 &repair_env_string);
73726
73727- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
73728+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
73729 do_one_initcall(*fn);
73730+
73731+#ifdef LATENT_ENTROPY_PLUGIN
73732+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
73733+#endif
73734+
73735+ }
73736 }
73737
73738 static void __init do_initcalls(void)
73739@@ -792,8 +859,14 @@ static void __init do_pre_smp_initcalls(void)
73740 {
73741 initcall_t *fn;
73742
73743- for (fn = __initcall_start; fn < __initcall0_start; fn++)
73744+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
73745 do_one_initcall(*fn);
73746+
73747+#ifdef LATENT_ENTROPY_PLUGIN
73748+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
73749+#endif
73750+
73751+ }
73752 }
73753
73754 /*
73755@@ -811,8 +884,8 @@ static int run_init_process(const char *init_filename)
73756 {
73757 argv_init[0] = init_filename;
73758 return do_execve(init_filename,
73759- (const char __user *const __user *)argv_init,
73760- (const char __user *const __user *)envp_init);
73761+ (const char __user *const __force_user *)argv_init,
73762+ (const char __user *const __force_user *)envp_init);
73763 }
73764
73765 static noinline void __init kernel_init_freeable(void);
73766@@ -890,7 +963,7 @@ static noinline void __init kernel_init_freeable(void)
73767 do_basic_setup();
73768
73769 /* Open the /dev/console on the rootfs, this should never fail */
73770- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
73771+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
73772 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
73773
73774 (void) sys_dup(0);
73775@@ -903,11 +976,13 @@ static noinline void __init kernel_init_freeable(void)
73776 if (!ramdisk_execute_command)
73777 ramdisk_execute_command = "/init";
73778
73779- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
73780+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
73781 ramdisk_execute_command = NULL;
73782 prepare_namespace();
73783 }
73784
73785+ grsecurity_init();
73786+
73787 /*
73788 * Ok, we have completed the initial bootup, and
73789 * we're essentially up and running. Get rid of the
73790diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
73791index 130dfec..cc88451 100644
73792--- a/ipc/ipc_sysctl.c
73793+++ b/ipc/ipc_sysctl.c
73794@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
73795 static int proc_ipc_dointvec(ctl_table *table, int write,
73796 void __user *buffer, size_t *lenp, loff_t *ppos)
73797 {
73798- struct ctl_table ipc_table;
73799+ ctl_table_no_const ipc_table;
73800
73801 memcpy(&ipc_table, table, sizeof(ipc_table));
73802 ipc_table.data = get_ipc(table);
73803@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
73804 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
73805 void __user *buffer, size_t *lenp, loff_t *ppos)
73806 {
73807- struct ctl_table ipc_table;
73808+ ctl_table_no_const ipc_table;
73809
73810 memcpy(&ipc_table, table, sizeof(ipc_table));
73811 ipc_table.data = get_ipc(table);
73812@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
73813 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
73814 void __user *buffer, size_t *lenp, loff_t *ppos)
73815 {
73816- struct ctl_table ipc_table;
73817+ ctl_table_no_const ipc_table;
73818 size_t lenp_bef = *lenp;
73819 int rc;
73820
73821@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
73822 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
73823 void __user *buffer, size_t *lenp, loff_t *ppos)
73824 {
73825- struct ctl_table ipc_table;
73826+ ctl_table_no_const ipc_table;
73827 memcpy(&ipc_table, table, sizeof(ipc_table));
73828 ipc_table.data = get_ipc(table);
73829
73830@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
73831 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
73832 void __user *buffer, size_t *lenp, loff_t *ppos)
73833 {
73834- struct ctl_table ipc_table;
73835+ ctl_table_no_const ipc_table;
73836 size_t lenp_bef = *lenp;
73837 int oldval;
73838 int rc;
73839diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
73840index 383d638..943fdbb 100644
73841--- a/ipc/mq_sysctl.c
73842+++ b/ipc/mq_sysctl.c
73843@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
73844 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
73845 void __user *buffer, size_t *lenp, loff_t *ppos)
73846 {
73847- struct ctl_table mq_table;
73848+ ctl_table_no_const mq_table;
73849 memcpy(&mq_table, table, sizeof(mq_table));
73850 mq_table.data = get_mq(table);
73851
73852diff --git a/ipc/mqueue.c b/ipc/mqueue.c
73853index e4e47f6..a85e0ad 100644
73854--- a/ipc/mqueue.c
73855+++ b/ipc/mqueue.c
73856@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
73857 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
73858 info->attr.mq_msgsize);
73859
73860+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
73861 spin_lock(&mq_lock);
73862 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
73863 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
73864diff --git a/ipc/msg.c b/ipc/msg.c
73865index fede1d0..9778e0f8 100644
73866--- a/ipc/msg.c
73867+++ b/ipc/msg.c
73868@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
73869 return security_msg_queue_associate(msq, msgflg);
73870 }
73871
73872+static struct ipc_ops msg_ops = {
73873+ .getnew = newque,
73874+ .associate = msg_security,
73875+ .more_checks = NULL
73876+};
73877+
73878 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
73879 {
73880 struct ipc_namespace *ns;
73881- struct ipc_ops msg_ops;
73882 struct ipc_params msg_params;
73883
73884 ns = current->nsproxy->ipc_ns;
73885
73886- msg_ops.getnew = newque;
73887- msg_ops.associate = msg_security;
73888- msg_ops.more_checks = NULL;
73889-
73890 msg_params.key = key;
73891 msg_params.flg = msgflg;
73892
73893diff --git a/ipc/sem.c b/ipc/sem.c
73894index 58d31f1..cce7a55 100644
73895--- a/ipc/sem.c
73896+++ b/ipc/sem.c
73897@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
73898 return 0;
73899 }
73900
73901+static struct ipc_ops sem_ops = {
73902+ .getnew = newary,
73903+ .associate = sem_security,
73904+ .more_checks = sem_more_checks
73905+};
73906+
73907 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
73908 {
73909 struct ipc_namespace *ns;
73910- struct ipc_ops sem_ops;
73911 struct ipc_params sem_params;
73912
73913 ns = current->nsproxy->ipc_ns;
73914@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
73915 if (nsems < 0 || nsems > ns->sc_semmsl)
73916 return -EINVAL;
73917
73918- sem_ops.getnew = newary;
73919- sem_ops.associate = sem_security;
73920- sem_ops.more_checks = sem_more_checks;
73921-
73922 sem_params.key = key;
73923 sem_params.flg = semflg;
73924 sem_params.u.nsems = nsems;
73925diff --git a/ipc/shm.c b/ipc/shm.c
73926index 7e199fa..180a1ca 100644
73927--- a/ipc/shm.c
73928+++ b/ipc/shm.c
73929@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
73930 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
73931 #endif
73932
73933+#ifdef CONFIG_GRKERNSEC
73934+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73935+ const time_t shm_createtime, const kuid_t cuid,
73936+ const int shmid);
73937+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73938+ const time_t shm_createtime);
73939+#endif
73940+
73941 void shm_init_ns(struct ipc_namespace *ns)
73942 {
73943 ns->shm_ctlmax = SHMMAX;
73944@@ -531,6 +539,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
73945 shp->shm_lprid = 0;
73946 shp->shm_atim = shp->shm_dtim = 0;
73947 shp->shm_ctim = get_seconds();
73948+#ifdef CONFIG_GRKERNSEC
73949+ {
73950+ struct timespec timeval;
73951+ do_posix_clock_monotonic_gettime(&timeval);
73952+
73953+ shp->shm_createtime = timeval.tv_sec;
73954+ }
73955+#endif
73956 shp->shm_segsz = size;
73957 shp->shm_nattch = 0;
73958 shp->shm_file = file;
73959@@ -582,18 +598,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
73960 return 0;
73961 }
73962
73963+static struct ipc_ops shm_ops = {
73964+ .getnew = newseg,
73965+ .associate = shm_security,
73966+ .more_checks = shm_more_checks
73967+};
73968+
73969 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
73970 {
73971 struct ipc_namespace *ns;
73972- struct ipc_ops shm_ops;
73973 struct ipc_params shm_params;
73974
73975 ns = current->nsproxy->ipc_ns;
73976
73977- shm_ops.getnew = newseg;
73978- shm_ops.associate = shm_security;
73979- shm_ops.more_checks = shm_more_checks;
73980-
73981 shm_params.key = key;
73982 shm_params.flg = shmflg;
73983 shm_params.u.size = size;
73984@@ -1014,6 +1031,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
73985 f_mode = FMODE_READ | FMODE_WRITE;
73986 }
73987 if (shmflg & SHM_EXEC) {
73988+
73989+#ifdef CONFIG_PAX_MPROTECT
73990+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
73991+ goto out;
73992+#endif
73993+
73994 prot |= PROT_EXEC;
73995 acc_mode |= S_IXUGO;
73996 }
73997@@ -1037,9 +1060,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
73998 if (err)
73999 goto out_unlock;
74000
74001+#ifdef CONFIG_GRKERNSEC
74002+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
74003+ shp->shm_perm.cuid, shmid) ||
74004+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
74005+ err = -EACCES;
74006+ goto out_unlock;
74007+ }
74008+#endif
74009+
74010 path = shp->shm_file->f_path;
74011 path_get(&path);
74012 shp->shm_nattch++;
74013+#ifdef CONFIG_GRKERNSEC
74014+ shp->shm_lapid = current->pid;
74015+#endif
74016 size = i_size_read(path.dentry->d_inode);
74017 shm_unlock(shp);
74018
74019diff --git a/kernel/acct.c b/kernel/acct.c
74020index b9bd7f0..1762b4a 100644
74021--- a/kernel/acct.c
74022+++ b/kernel/acct.c
74023@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
74024 */
74025 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
74026 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
74027- file->f_op->write(file, (char *)&ac,
74028+ file->f_op->write(file, (char __force_user *)&ac,
74029 sizeof(acct_t), &file->f_pos);
74030 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
74031 set_fs(fs);
74032diff --git a/kernel/audit.c b/kernel/audit.c
74033index d596e53..dbef3c3 100644
74034--- a/kernel/audit.c
74035+++ b/kernel/audit.c
74036@@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
74037 3) suppressed due to audit_rate_limit
74038 4) suppressed due to audit_backlog_limit
74039 */
74040-static atomic_t audit_lost = ATOMIC_INIT(0);
74041+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
74042
74043 /* The netlink socket. */
74044 static struct sock *audit_sock;
74045@@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
74046 unsigned long now;
74047 int print;
74048
74049- atomic_inc(&audit_lost);
74050+ atomic_inc_unchecked(&audit_lost);
74051
74052 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
74053
74054@@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
74055 printk(KERN_WARNING
74056 "audit: audit_lost=%d audit_rate_limit=%d "
74057 "audit_backlog_limit=%d\n",
74058- atomic_read(&audit_lost),
74059+ atomic_read_unchecked(&audit_lost),
74060 audit_rate_limit,
74061 audit_backlog_limit);
74062 audit_panic(message);
74063@@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
74064 status_set.pid = audit_pid;
74065 status_set.rate_limit = audit_rate_limit;
74066 status_set.backlog_limit = audit_backlog_limit;
74067- status_set.lost = atomic_read(&audit_lost);
74068+ status_set.lost = atomic_read_unchecked(&audit_lost);
74069 status_set.backlog = skb_queue_len(&audit_skb_queue);
74070 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
74071 &status_set, sizeof(status_set));
74072diff --git a/kernel/auditsc.c b/kernel/auditsc.c
74073index c4b72b0..8654c4e 100644
74074--- a/kernel/auditsc.c
74075+++ b/kernel/auditsc.c
74076@@ -2295,7 +2295,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
74077 }
74078
74079 /* global counter which is incremented every time something logs in */
74080-static atomic_t session_id = ATOMIC_INIT(0);
74081+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
74082
74083 /**
74084 * audit_set_loginuid - set current task's audit_context loginuid
74085@@ -2319,7 +2319,7 @@ int audit_set_loginuid(kuid_t loginuid)
74086 return -EPERM;
74087 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
74088
74089- sessionid = atomic_inc_return(&session_id);
74090+ sessionid = atomic_inc_return_unchecked(&session_id);
74091 if (context && context->in_syscall) {
74092 struct audit_buffer *ab;
74093
74094diff --git a/kernel/capability.c b/kernel/capability.c
74095index f6c2ce5..982c0f9 100644
74096--- a/kernel/capability.c
74097+++ b/kernel/capability.c
74098@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
74099 * before modification is attempted and the application
74100 * fails.
74101 */
74102+ if (tocopy > ARRAY_SIZE(kdata))
74103+ return -EFAULT;
74104+
74105 if (copy_to_user(dataptr, kdata, tocopy
74106 * sizeof(struct __user_cap_data_struct))) {
74107 return -EFAULT;
74108@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
74109 int ret;
74110
74111 rcu_read_lock();
74112- ret = security_capable(__task_cred(t), ns, cap);
74113+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
74114+ gr_task_is_capable(t, __task_cred(t), cap);
74115 rcu_read_unlock();
74116
74117- return (ret == 0);
74118+ return ret;
74119 }
74120
74121 /**
74122@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
74123 int ret;
74124
74125 rcu_read_lock();
74126- ret = security_capable_noaudit(__task_cred(t), ns, cap);
74127+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
74128 rcu_read_unlock();
74129
74130- return (ret == 0);
74131+ return ret;
74132 }
74133
74134 /**
74135@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
74136 BUG();
74137 }
74138
74139- if (security_capable(current_cred(), ns, cap) == 0) {
74140+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
74141 current->flags |= PF_SUPERPRIV;
74142 return true;
74143 }
74144@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
74145 }
74146 EXPORT_SYMBOL(ns_capable);
74147
74148+bool ns_capable_nolog(struct user_namespace *ns, int cap)
74149+{
74150+ if (unlikely(!cap_valid(cap))) {
74151+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
74152+ BUG();
74153+ }
74154+
74155+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
74156+ current->flags |= PF_SUPERPRIV;
74157+ return true;
74158+ }
74159+ return false;
74160+}
74161+EXPORT_SYMBOL(ns_capable_nolog);
74162+
74163 /**
74164 * file_ns_capable - Determine if the file's opener had a capability in effect
74165 * @file: The file we want to check
74166@@ -432,6 +451,12 @@ bool capable(int cap)
74167 }
74168 EXPORT_SYMBOL(capable);
74169
74170+bool capable_nolog(int cap)
74171+{
74172+ return ns_capable_nolog(&init_user_ns, cap);
74173+}
74174+EXPORT_SYMBOL(capable_nolog);
74175+
74176 /**
74177 * nsown_capable - Check superior capability to one's own user_ns
74178 * @cap: The capability in question
74179@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
74180
74181 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
74182 }
74183+
74184+bool inode_capable_nolog(const struct inode *inode, int cap)
74185+{
74186+ struct user_namespace *ns = current_user_ns();
74187+
74188+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
74189+}
74190diff --git a/kernel/cgroup.c b/kernel/cgroup.c
74191index a48de6a..df24bfe 100644
74192--- a/kernel/cgroup.c
74193+++ b/kernel/cgroup.c
74194@@ -5567,7 +5567,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
74195 struct css_set *cg = link->cg;
74196 struct task_struct *task;
74197 int count = 0;
74198- seq_printf(seq, "css_set %p\n", cg);
74199+ seq_printf(seq, "css_set %pK\n", cg);
74200 list_for_each_entry(task, &cg->tasks, cg_list) {
74201 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
74202 seq_puts(seq, " ...\n");
74203diff --git a/kernel/compat.c b/kernel/compat.c
74204index 19971d8..02fe2df 100644
74205--- a/kernel/compat.c
74206+++ b/kernel/compat.c
74207@@ -13,6 +13,7 @@
74208
74209 #include <linux/linkage.h>
74210 #include <linux/compat.h>
74211+#include <linux/module.h>
74212 #include <linux/errno.h>
74213 #include <linux/time.h>
74214 #include <linux/signal.h>
74215@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
74216 mm_segment_t oldfs;
74217 long ret;
74218
74219- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
74220+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
74221 oldfs = get_fs();
74222 set_fs(KERNEL_DS);
74223 ret = hrtimer_nanosleep_restart(restart);
74224@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
74225 oldfs = get_fs();
74226 set_fs(KERNEL_DS);
74227 ret = hrtimer_nanosleep(&tu,
74228- rmtp ? (struct timespec __user *)&rmt : NULL,
74229+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
74230 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
74231 set_fs(oldfs);
74232
74233@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
74234 mm_segment_t old_fs = get_fs();
74235
74236 set_fs(KERNEL_DS);
74237- ret = sys_sigpending((old_sigset_t __user *) &s);
74238+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
74239 set_fs(old_fs);
74240 if (ret == 0)
74241 ret = put_user(s, set);
74242@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
74243 mm_segment_t old_fs = get_fs();
74244
74245 set_fs(KERNEL_DS);
74246- ret = sys_old_getrlimit(resource, &r);
74247+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
74248 set_fs(old_fs);
74249
74250 if (!ret) {
74251@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
74252 mm_segment_t old_fs = get_fs();
74253
74254 set_fs(KERNEL_DS);
74255- ret = sys_getrusage(who, (struct rusage __user *) &r);
74256+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
74257 set_fs(old_fs);
74258
74259 if (ret)
74260@@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
74261 set_fs (KERNEL_DS);
74262 ret = sys_wait4(pid,
74263 (stat_addr ?
74264- (unsigned int __user *) &status : NULL),
74265- options, (struct rusage __user *) &r);
74266+ (unsigned int __force_user *) &status : NULL),
74267+ options, (struct rusage __force_user *) &r);
74268 set_fs (old_fs);
74269
74270 if (ret > 0) {
74271@@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
74272 memset(&info, 0, sizeof(info));
74273
74274 set_fs(KERNEL_DS);
74275- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
74276- uru ? (struct rusage __user *)&ru : NULL);
74277+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
74278+ uru ? (struct rusage __force_user *)&ru : NULL);
74279 set_fs(old_fs);
74280
74281 if ((ret < 0) || (info.si_signo == 0))
74282@@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
74283 oldfs = get_fs();
74284 set_fs(KERNEL_DS);
74285 err = sys_timer_settime(timer_id, flags,
74286- (struct itimerspec __user *) &newts,
74287- (struct itimerspec __user *) &oldts);
74288+ (struct itimerspec __force_user *) &newts,
74289+ (struct itimerspec __force_user *) &oldts);
74290 set_fs(oldfs);
74291 if (!err && old && put_compat_itimerspec(old, &oldts))
74292 return -EFAULT;
74293@@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
74294 oldfs = get_fs();
74295 set_fs(KERNEL_DS);
74296 err = sys_timer_gettime(timer_id,
74297- (struct itimerspec __user *) &ts);
74298+ (struct itimerspec __force_user *) &ts);
74299 set_fs(oldfs);
74300 if (!err && put_compat_itimerspec(setting, &ts))
74301 return -EFAULT;
74302@@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
74303 oldfs = get_fs();
74304 set_fs(KERNEL_DS);
74305 err = sys_clock_settime(which_clock,
74306- (struct timespec __user *) &ts);
74307+ (struct timespec __force_user *) &ts);
74308 set_fs(oldfs);
74309 return err;
74310 }
74311@@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
74312 oldfs = get_fs();
74313 set_fs(KERNEL_DS);
74314 err = sys_clock_gettime(which_clock,
74315- (struct timespec __user *) &ts);
74316+ (struct timespec __force_user *) &ts);
74317 set_fs(oldfs);
74318 if (!err && put_compat_timespec(&ts, tp))
74319 return -EFAULT;
74320@@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
74321
74322 oldfs = get_fs();
74323 set_fs(KERNEL_DS);
74324- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
74325+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
74326 set_fs(oldfs);
74327
74328 err = compat_put_timex(utp, &txc);
74329@@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
74330 oldfs = get_fs();
74331 set_fs(KERNEL_DS);
74332 err = sys_clock_getres(which_clock,
74333- (struct timespec __user *) &ts);
74334+ (struct timespec __force_user *) &ts);
74335 set_fs(oldfs);
74336 if (!err && tp && put_compat_timespec(&ts, tp))
74337 return -EFAULT;
74338@@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
74339 long err;
74340 mm_segment_t oldfs;
74341 struct timespec tu;
74342- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
74343+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
74344
74345- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
74346+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
74347 oldfs = get_fs();
74348 set_fs(KERNEL_DS);
74349 err = clock_nanosleep_restart(restart);
74350@@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
74351 oldfs = get_fs();
74352 set_fs(KERNEL_DS);
74353 err = sys_clock_nanosleep(which_clock, flags,
74354- (struct timespec __user *) &in,
74355- (struct timespec __user *) &out);
74356+ (struct timespec __force_user *) &in,
74357+ (struct timespec __force_user *) &out);
74358 set_fs(oldfs);
74359
74360 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
74361diff --git a/kernel/configs.c b/kernel/configs.c
74362index 42e8fa0..9e7406b 100644
74363--- a/kernel/configs.c
74364+++ b/kernel/configs.c
74365@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
74366 struct proc_dir_entry *entry;
74367
74368 /* create the current config file */
74369+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
74370+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
74371+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
74372+ &ikconfig_file_ops);
74373+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
74374+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
74375+ &ikconfig_file_ops);
74376+#endif
74377+#else
74378 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
74379 &ikconfig_file_ops);
74380+#endif
74381+
74382 if (!entry)
74383 return -ENOMEM;
74384
74385diff --git a/kernel/cred.c b/kernel/cred.c
74386index e0573a4..3874e41 100644
74387--- a/kernel/cred.c
74388+++ b/kernel/cred.c
74389@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
74390 validate_creds(cred);
74391 alter_cred_subscribers(cred, -1);
74392 put_cred(cred);
74393+
74394+#ifdef CONFIG_GRKERNSEC_SETXID
74395+ cred = (struct cred *) tsk->delayed_cred;
74396+ if (cred != NULL) {
74397+ tsk->delayed_cred = NULL;
74398+ validate_creds(cred);
74399+ alter_cred_subscribers(cred, -1);
74400+ put_cred(cred);
74401+ }
74402+#endif
74403 }
74404
74405 /**
74406@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
74407 * Always returns 0 thus allowing this function to be tail-called at the end
74408 * of, say, sys_setgid().
74409 */
74410-int commit_creds(struct cred *new)
74411+static int __commit_creds(struct cred *new)
74412 {
74413 struct task_struct *task = current;
74414 const struct cred *old = task->real_cred;
74415@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
74416
74417 get_cred(new); /* we will require a ref for the subj creds too */
74418
74419+ gr_set_role_label(task, new->uid, new->gid);
74420+
74421 /* dumpability changes */
74422 if (!uid_eq(old->euid, new->euid) ||
74423 !gid_eq(old->egid, new->egid) ||
74424@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
74425 put_cred(old);
74426 return 0;
74427 }
74428+#ifdef CONFIG_GRKERNSEC_SETXID
74429+extern int set_user(struct cred *new);
74430+
74431+void gr_delayed_cred_worker(void)
74432+{
74433+ const struct cred *new = current->delayed_cred;
74434+ struct cred *ncred;
74435+
74436+ current->delayed_cred = NULL;
74437+
74438+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
74439+ // from doing get_cred on it when queueing this
74440+ put_cred(new);
74441+ return;
74442+ } else if (new == NULL)
74443+ return;
74444+
74445+ ncred = prepare_creds();
74446+ if (!ncred)
74447+ goto die;
74448+ // uids
74449+ ncred->uid = new->uid;
74450+ ncred->euid = new->euid;
74451+ ncred->suid = new->suid;
74452+ ncred->fsuid = new->fsuid;
74453+ // gids
74454+ ncred->gid = new->gid;
74455+ ncred->egid = new->egid;
74456+ ncred->sgid = new->sgid;
74457+ ncred->fsgid = new->fsgid;
74458+ // groups
74459+ if (set_groups(ncred, new->group_info) < 0) {
74460+ abort_creds(ncred);
74461+ goto die;
74462+ }
74463+ // caps
74464+ ncred->securebits = new->securebits;
74465+ ncred->cap_inheritable = new->cap_inheritable;
74466+ ncred->cap_permitted = new->cap_permitted;
74467+ ncred->cap_effective = new->cap_effective;
74468+ ncred->cap_bset = new->cap_bset;
74469+
74470+ if (set_user(ncred)) {
74471+ abort_creds(ncred);
74472+ goto die;
74473+ }
74474+
74475+ // from doing get_cred on it when queueing this
74476+ put_cred(new);
74477+
74478+ __commit_creds(ncred);
74479+ return;
74480+die:
74481+ // from doing get_cred on it when queueing this
74482+ put_cred(new);
74483+ do_group_exit(SIGKILL);
74484+}
74485+#endif
74486+
74487+int commit_creds(struct cred *new)
74488+{
74489+#ifdef CONFIG_GRKERNSEC_SETXID
74490+ int ret;
74491+ int schedule_it = 0;
74492+ struct task_struct *t;
74493+
74494+ /* we won't get called with tasklist_lock held for writing
74495+ and interrupts disabled as the cred struct in that case is
74496+ init_cred
74497+ */
74498+ if (grsec_enable_setxid && !current_is_single_threaded() &&
74499+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
74500+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
74501+ schedule_it = 1;
74502+ }
74503+ ret = __commit_creds(new);
74504+ if (schedule_it) {
74505+ rcu_read_lock();
74506+ read_lock(&tasklist_lock);
74507+ for (t = next_thread(current); t != current;
74508+ t = next_thread(t)) {
74509+ if (t->delayed_cred == NULL) {
74510+ t->delayed_cred = get_cred(new);
74511+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
74512+ set_tsk_need_resched(t);
74513+ }
74514+ }
74515+ read_unlock(&tasklist_lock);
74516+ rcu_read_unlock();
74517+ }
74518+ return ret;
74519+#else
74520+ return __commit_creds(new);
74521+#endif
74522+}
74523+
74524 EXPORT_SYMBOL(commit_creds);
74525
74526 /**
74527diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
74528index c26278f..e323fb8 100644
74529--- a/kernel/debug/debug_core.c
74530+++ b/kernel/debug/debug_core.c
74531@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
74532 */
74533 static atomic_t masters_in_kgdb;
74534 static atomic_t slaves_in_kgdb;
74535-static atomic_t kgdb_break_tasklet_var;
74536+static atomic_unchecked_t kgdb_break_tasklet_var;
74537 atomic_t kgdb_setting_breakpoint;
74538
74539 struct task_struct *kgdb_usethread;
74540@@ -133,7 +133,7 @@ int kgdb_single_step;
74541 static pid_t kgdb_sstep_pid;
74542
74543 /* to keep track of the CPU which is doing the single stepping*/
74544-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
74545+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
74546
74547 /*
74548 * If you are debugging a problem where roundup (the collection of
74549@@ -541,7 +541,7 @@ return_normal:
74550 * kernel will only try for the value of sstep_tries before
74551 * giving up and continuing on.
74552 */
74553- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
74554+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
74555 (kgdb_info[cpu].task &&
74556 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
74557 atomic_set(&kgdb_active, -1);
74558@@ -635,8 +635,8 @@ cpu_master_loop:
74559 }
74560
74561 kgdb_restore:
74562- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
74563- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
74564+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
74565+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
74566 if (kgdb_info[sstep_cpu].task)
74567 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
74568 else
74569@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
74570 static void kgdb_tasklet_bpt(unsigned long ing)
74571 {
74572 kgdb_breakpoint();
74573- atomic_set(&kgdb_break_tasklet_var, 0);
74574+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
74575 }
74576
74577 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
74578
74579 void kgdb_schedule_breakpoint(void)
74580 {
74581- if (atomic_read(&kgdb_break_tasklet_var) ||
74582+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
74583 atomic_read(&kgdb_active) != -1 ||
74584 atomic_read(&kgdb_setting_breakpoint))
74585 return;
74586- atomic_inc(&kgdb_break_tasklet_var);
74587+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
74588 tasklet_schedule(&kgdb_tasklet_breakpoint);
74589 }
74590 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
74591diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
74592index 00eb8f7..d7e3244 100644
74593--- a/kernel/debug/kdb/kdb_main.c
74594+++ b/kernel/debug/kdb/kdb_main.c
74595@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
74596 continue;
74597
74598 kdb_printf("%-20s%8u 0x%p ", mod->name,
74599- mod->core_size, (void *)mod);
74600+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
74601 #ifdef CONFIG_MODULE_UNLOAD
74602 kdb_printf("%4ld ", module_refcount(mod));
74603 #endif
74604@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
74605 kdb_printf(" (Loading)");
74606 else
74607 kdb_printf(" (Live)");
74608- kdb_printf(" 0x%p", mod->module_core);
74609+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
74610
74611 #ifdef CONFIG_MODULE_UNLOAD
74612 {
74613diff --git a/kernel/events/core.c b/kernel/events/core.c
74614index 9fcb094..8370228 100644
74615--- a/kernel/events/core.c
74616+++ b/kernel/events/core.c
74617@@ -154,8 +154,15 @@ static struct srcu_struct pmus_srcu;
74618 * 0 - disallow raw tracepoint access for unpriv
74619 * 1 - disallow cpu events for unpriv
74620 * 2 - disallow kernel profiling for unpriv
74621+ * 3 - disallow all unpriv perf event use
74622 */
74623-int sysctl_perf_event_paranoid __read_mostly = 1;
74624+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
74625+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
74626+#elif CONFIG_GRKERNSEC_HIDESYM
74627+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
74628+#else
74629+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
74630+#endif
74631
74632 /* Minimum for 512 kiB + 1 user control page */
74633 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
74634@@ -182,7 +189,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
74635 return 0;
74636 }
74637
74638-static atomic64_t perf_event_id;
74639+static atomic64_unchecked_t perf_event_id;
74640
74641 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
74642 enum event_type_t event_type);
74643@@ -2677,7 +2684,7 @@ static void __perf_event_read(void *info)
74644
74645 static inline u64 perf_event_count(struct perf_event *event)
74646 {
74647- return local64_read(&event->count) + atomic64_read(&event->child_count);
74648+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
74649 }
74650
74651 static u64 perf_event_read(struct perf_event *event)
74652@@ -3007,9 +3014,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
74653 mutex_lock(&event->child_mutex);
74654 total += perf_event_read(event);
74655 *enabled += event->total_time_enabled +
74656- atomic64_read(&event->child_total_time_enabled);
74657+ atomic64_read_unchecked(&event->child_total_time_enabled);
74658 *running += event->total_time_running +
74659- atomic64_read(&event->child_total_time_running);
74660+ atomic64_read_unchecked(&event->child_total_time_running);
74661
74662 list_for_each_entry(child, &event->child_list, child_list) {
74663 total += perf_event_read(child);
74664@@ -3412,10 +3419,10 @@ void perf_event_update_userpage(struct perf_event *event)
74665 userpg->offset -= local64_read(&event->hw.prev_count);
74666
74667 userpg->time_enabled = enabled +
74668- atomic64_read(&event->child_total_time_enabled);
74669+ atomic64_read_unchecked(&event->child_total_time_enabled);
74670
74671 userpg->time_running = running +
74672- atomic64_read(&event->child_total_time_running);
74673+ atomic64_read_unchecked(&event->child_total_time_running);
74674
74675 arch_perf_update_userpage(userpg, now);
74676
74677@@ -3886,7 +3893,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
74678
74679 /* Data. */
74680 sp = perf_user_stack_pointer(regs);
74681- rem = __output_copy_user(handle, (void *) sp, dump_size);
74682+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
74683 dyn_size = dump_size - rem;
74684
74685 perf_output_skip(handle, rem);
74686@@ -3974,11 +3981,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
74687 values[n++] = perf_event_count(event);
74688 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
74689 values[n++] = enabled +
74690- atomic64_read(&event->child_total_time_enabled);
74691+ atomic64_read_unchecked(&event->child_total_time_enabled);
74692 }
74693 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
74694 values[n++] = running +
74695- atomic64_read(&event->child_total_time_running);
74696+ atomic64_read_unchecked(&event->child_total_time_running);
74697 }
74698 if (read_format & PERF_FORMAT_ID)
74699 values[n++] = primary_event_id(event);
74700@@ -4726,12 +4733,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
74701 * need to add enough zero bytes after the string to handle
74702 * the 64bit alignment we do later.
74703 */
74704- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
74705+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
74706 if (!buf) {
74707 name = strncpy(tmp, "//enomem", sizeof(tmp));
74708 goto got_name;
74709 }
74710- name = d_path(&file->f_path, buf, PATH_MAX);
74711+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
74712 if (IS_ERR(name)) {
74713 name = strncpy(tmp, "//toolong", sizeof(tmp));
74714 goto got_name;
74715@@ -6167,7 +6174,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
74716 event->parent = parent_event;
74717
74718 event->ns = get_pid_ns(task_active_pid_ns(current));
74719- event->id = atomic64_inc_return(&perf_event_id);
74720+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
74721
74722 event->state = PERF_EVENT_STATE_INACTIVE;
74723
74724@@ -6463,6 +6470,11 @@ SYSCALL_DEFINE5(perf_event_open,
74725 if (flags & ~PERF_FLAG_ALL)
74726 return -EINVAL;
74727
74728+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
74729+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
74730+ return -EACCES;
74731+#endif
74732+
74733 err = perf_copy_attr(attr_uptr, &attr);
74734 if (err)
74735 return err;
74736@@ -6795,10 +6807,10 @@ static void sync_child_event(struct perf_event *child_event,
74737 /*
74738 * Add back the child's count to the parent's count:
74739 */
74740- atomic64_add(child_val, &parent_event->child_count);
74741- atomic64_add(child_event->total_time_enabled,
74742+ atomic64_add_unchecked(child_val, &parent_event->child_count);
74743+ atomic64_add_unchecked(child_event->total_time_enabled,
74744 &parent_event->child_total_time_enabled);
74745- atomic64_add(child_event->total_time_running,
74746+ atomic64_add_unchecked(child_event->total_time_running,
74747 &parent_event->child_total_time_running);
74748
74749 /*
74750diff --git a/kernel/events/internal.h b/kernel/events/internal.h
74751index eb675c4..54912ff 100644
74752--- a/kernel/events/internal.h
74753+++ b/kernel/events/internal.h
74754@@ -77,10 +77,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
74755 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
74756 }
74757
74758-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
74759+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
74760 static inline unsigned int \
74761 func_name(struct perf_output_handle *handle, \
74762- const void *buf, unsigned int len) \
74763+ const void user *buf, unsigned int len) \
74764 { \
74765 unsigned long size, written; \
74766 \
74767@@ -112,17 +112,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
74768 return n;
74769 }
74770
74771-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
74772+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
74773
74774 #define MEMCPY_SKIP(dst, src, n) (n)
74775
74776-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
74777+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
74778
74779 #ifndef arch_perf_out_copy_user
74780 #define arch_perf_out_copy_user __copy_from_user_inatomic
74781 #endif
74782
74783-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
74784+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
74785
74786 /* Callchain handling */
74787 extern struct perf_callchain_entry *
74788diff --git a/kernel/exit.c b/kernel/exit.c
74789index 60bc027..ca6d727 100644
74790--- a/kernel/exit.c
74791+++ b/kernel/exit.c
74792@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
74793 struct task_struct *leader;
74794 int zap_leader;
74795 repeat:
74796+#ifdef CONFIG_NET
74797+ gr_del_task_from_ip_table(p);
74798+#endif
74799+
74800 /* don't need to get the RCU readlock here - the process is dead and
74801 * can't be modifying its own credentials. But shut RCU-lockdep up */
74802 rcu_read_lock();
74803@@ -340,7 +344,7 @@ int allow_signal(int sig)
74804 * know it'll be handled, so that they don't get converted to
74805 * SIGKILL or just silently dropped.
74806 */
74807- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
74808+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
74809 recalc_sigpending();
74810 spin_unlock_irq(&current->sighand->siglock);
74811 return 0;
74812@@ -710,6 +714,8 @@ void do_exit(long code)
74813 struct task_struct *tsk = current;
74814 int group_dead;
74815
74816+ set_fs(USER_DS);
74817+
74818 profile_task_exit(tsk);
74819
74820 WARN_ON(blk_needs_flush_plug(tsk));
74821@@ -726,7 +732,6 @@ void do_exit(long code)
74822 * mm_release()->clear_child_tid() from writing to a user-controlled
74823 * kernel address.
74824 */
74825- set_fs(USER_DS);
74826
74827 ptrace_event(PTRACE_EVENT_EXIT, code);
74828
74829@@ -785,6 +790,9 @@ void do_exit(long code)
74830 tsk->exit_code = code;
74831 taskstats_exit(tsk, group_dead);
74832
74833+ gr_acl_handle_psacct(tsk, code);
74834+ gr_acl_handle_exit();
74835+
74836 exit_mm(tsk);
74837
74838 if (group_dead)
74839@@ -905,7 +913,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
74840 * Take down every thread in the group. This is called by fatal signals
74841 * as well as by sys_exit_group (below).
74842 */
74843-void
74844+__noreturn void
74845 do_group_exit(int exit_code)
74846 {
74847 struct signal_struct *sig = current->signal;
74848diff --git a/kernel/fork.c b/kernel/fork.c
74849index 1766d32..c0e44e2 100644
74850--- a/kernel/fork.c
74851+++ b/kernel/fork.c
74852@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
74853 *stackend = STACK_END_MAGIC; /* for overflow detection */
74854
74855 #ifdef CONFIG_CC_STACKPROTECTOR
74856- tsk->stack_canary = get_random_int();
74857+ tsk->stack_canary = pax_get_random_long();
74858 #endif
74859
74860 /*
74861@@ -344,13 +344,81 @@ free_tsk:
74862 }
74863
74864 #ifdef CONFIG_MMU
74865+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
74866+{
74867+ struct vm_area_struct *tmp;
74868+ unsigned long charge;
74869+ struct mempolicy *pol;
74870+ struct file *file;
74871+
74872+ charge = 0;
74873+ if (mpnt->vm_flags & VM_ACCOUNT) {
74874+ unsigned long len = vma_pages(mpnt);
74875+
74876+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
74877+ goto fail_nomem;
74878+ charge = len;
74879+ }
74880+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
74881+ if (!tmp)
74882+ goto fail_nomem;
74883+ *tmp = *mpnt;
74884+ tmp->vm_mm = mm;
74885+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
74886+ pol = mpol_dup(vma_policy(mpnt));
74887+ if (IS_ERR(pol))
74888+ goto fail_nomem_policy;
74889+ vma_set_policy(tmp, pol);
74890+ if (anon_vma_fork(tmp, mpnt))
74891+ goto fail_nomem_anon_vma_fork;
74892+ tmp->vm_flags &= ~VM_LOCKED;
74893+ tmp->vm_next = tmp->vm_prev = NULL;
74894+ tmp->vm_mirror = NULL;
74895+ file = tmp->vm_file;
74896+ if (file) {
74897+ struct inode *inode = file_inode(file);
74898+ struct address_space *mapping = file->f_mapping;
74899+
74900+ get_file(file);
74901+ if (tmp->vm_flags & VM_DENYWRITE)
74902+ atomic_dec(&inode->i_writecount);
74903+ mutex_lock(&mapping->i_mmap_mutex);
74904+ if (tmp->vm_flags & VM_SHARED)
74905+ mapping->i_mmap_writable++;
74906+ flush_dcache_mmap_lock(mapping);
74907+ /* insert tmp into the share list, just after mpnt */
74908+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
74909+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
74910+ else
74911+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
74912+ flush_dcache_mmap_unlock(mapping);
74913+ mutex_unlock(&mapping->i_mmap_mutex);
74914+ }
74915+
74916+ /*
74917+ * Clear hugetlb-related page reserves for children. This only
74918+ * affects MAP_PRIVATE mappings. Faults generated by the child
74919+ * are not guaranteed to succeed, even if read-only
74920+ */
74921+ if (is_vm_hugetlb_page(tmp))
74922+ reset_vma_resv_huge_pages(tmp);
74923+
74924+ return tmp;
74925+
74926+fail_nomem_anon_vma_fork:
74927+ mpol_put(pol);
74928+fail_nomem_policy:
74929+ kmem_cache_free(vm_area_cachep, tmp);
74930+fail_nomem:
74931+ vm_unacct_memory(charge);
74932+ return NULL;
74933+}
74934+
74935 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
74936 {
74937 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
74938 struct rb_node **rb_link, *rb_parent;
74939 int retval;
74940- unsigned long charge;
74941- struct mempolicy *pol;
74942
74943 uprobe_start_dup_mmap();
74944 down_write(&oldmm->mmap_sem);
74945@@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
74946 mm->locked_vm = 0;
74947 mm->mmap = NULL;
74948 mm->mmap_cache = NULL;
74949- mm->free_area_cache = oldmm->mmap_base;
74950- mm->cached_hole_size = ~0UL;
74951+ mm->free_area_cache = oldmm->free_area_cache;
74952+ mm->cached_hole_size = oldmm->cached_hole_size;
74953 mm->map_count = 0;
74954 cpumask_clear(mm_cpumask(mm));
74955 mm->mm_rb = RB_ROOT;
74956@@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
74957
74958 prev = NULL;
74959 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
74960- struct file *file;
74961-
74962 if (mpnt->vm_flags & VM_DONTCOPY) {
74963 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
74964 -vma_pages(mpnt));
74965 continue;
74966 }
74967- charge = 0;
74968- if (mpnt->vm_flags & VM_ACCOUNT) {
74969- unsigned long len = vma_pages(mpnt);
74970-
74971- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
74972- goto fail_nomem;
74973- charge = len;
74974- }
74975- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
74976- if (!tmp)
74977- goto fail_nomem;
74978- *tmp = *mpnt;
74979- INIT_LIST_HEAD(&tmp->anon_vma_chain);
74980- pol = mpol_dup(vma_policy(mpnt));
74981- retval = PTR_ERR(pol);
74982- if (IS_ERR(pol))
74983- goto fail_nomem_policy;
74984- vma_set_policy(tmp, pol);
74985- tmp->vm_mm = mm;
74986- if (anon_vma_fork(tmp, mpnt))
74987- goto fail_nomem_anon_vma_fork;
74988- tmp->vm_flags &= ~VM_LOCKED;
74989- tmp->vm_next = tmp->vm_prev = NULL;
74990- file = tmp->vm_file;
74991- if (file) {
74992- struct inode *inode = file_inode(file);
74993- struct address_space *mapping = file->f_mapping;
74994-
74995- get_file(file);
74996- if (tmp->vm_flags & VM_DENYWRITE)
74997- atomic_dec(&inode->i_writecount);
74998- mutex_lock(&mapping->i_mmap_mutex);
74999- if (tmp->vm_flags & VM_SHARED)
75000- mapping->i_mmap_writable++;
75001- flush_dcache_mmap_lock(mapping);
75002- /* insert tmp into the share list, just after mpnt */
75003- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
75004- vma_nonlinear_insert(tmp,
75005- &mapping->i_mmap_nonlinear);
75006- else
75007- vma_interval_tree_insert_after(tmp, mpnt,
75008- &mapping->i_mmap);
75009- flush_dcache_mmap_unlock(mapping);
75010- mutex_unlock(&mapping->i_mmap_mutex);
75011+ tmp = dup_vma(mm, oldmm, mpnt);
75012+ if (!tmp) {
75013+ retval = -ENOMEM;
75014+ goto out;
75015 }
75016
75017 /*
75018@@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75019 if (retval)
75020 goto out;
75021 }
75022+
75023+#ifdef CONFIG_PAX_SEGMEXEC
75024+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
75025+ struct vm_area_struct *mpnt_m;
75026+
75027+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
75028+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
75029+
75030+ if (!mpnt->vm_mirror)
75031+ continue;
75032+
75033+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
75034+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
75035+ mpnt->vm_mirror = mpnt_m;
75036+ } else {
75037+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
75038+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
75039+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
75040+ mpnt->vm_mirror->vm_mirror = mpnt;
75041+ }
75042+ }
75043+ BUG_ON(mpnt_m);
75044+ }
75045+#endif
75046+
75047 /* a new mm has just been created */
75048 arch_dup_mmap(oldmm, mm);
75049 retval = 0;
75050@@ -472,14 +523,6 @@ out:
75051 up_write(&oldmm->mmap_sem);
75052 uprobe_end_dup_mmap();
75053 return retval;
75054-fail_nomem_anon_vma_fork:
75055- mpol_put(pol);
75056-fail_nomem_policy:
75057- kmem_cache_free(vm_area_cachep, tmp);
75058-fail_nomem:
75059- retval = -ENOMEM;
75060- vm_unacct_memory(charge);
75061- goto out;
75062 }
75063
75064 static inline int mm_alloc_pgd(struct mm_struct *mm)
75065@@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
75066 return ERR_PTR(err);
75067
75068 mm = get_task_mm(task);
75069- if (mm && mm != current->mm &&
75070- !ptrace_may_access(task, mode)) {
75071+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
75072+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
75073 mmput(mm);
75074 mm = ERR_PTR(-EACCES);
75075 }
75076@@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
75077 spin_unlock(&fs->lock);
75078 return -EAGAIN;
75079 }
75080- fs->users++;
75081+ atomic_inc(&fs->users);
75082 spin_unlock(&fs->lock);
75083 return 0;
75084 }
75085 tsk->fs = copy_fs_struct(fs);
75086 if (!tsk->fs)
75087 return -ENOMEM;
75088+ /* Carry through gr_chroot_dentry and is_chrooted instead
75089+ of recomputing it here. Already copied when the task struct
75090+ is duplicated. This allows pivot_root to not be treated as
75091+ a chroot
75092+ */
75093+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
75094+
75095 return 0;
75096 }
75097
75098@@ -1196,6 +1246,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
75099 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
75100 #endif
75101 retval = -EAGAIN;
75102+
75103+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
75104+
75105 if (atomic_read(&p->real_cred->user->processes) >=
75106 task_rlimit(p, RLIMIT_NPROC)) {
75107 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
75108@@ -1441,6 +1494,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
75109 goto bad_fork_free_pid;
75110 }
75111
75112+ /* synchronizes with gr_set_acls()
75113+ we need to call this past the point of no return for fork()
75114+ */
75115+ gr_copy_label(p);
75116+
75117 if (clone_flags & CLONE_THREAD) {
75118 current->signal->nr_threads++;
75119 atomic_inc(&current->signal->live);
75120@@ -1524,6 +1582,8 @@ bad_fork_cleanup_count:
75121 bad_fork_free:
75122 free_task(p);
75123 fork_out:
75124+ gr_log_forkfail(retval);
75125+
75126 return ERR_PTR(retval);
75127 }
75128
75129@@ -1574,6 +1634,23 @@ long do_fork(unsigned long clone_flags,
75130 return -EINVAL;
75131 }
75132
75133+#ifdef CONFIG_GRKERNSEC
75134+ if (clone_flags & CLONE_NEWUSER) {
75135+ /*
75136+ * This doesn't really inspire confidence:
75137+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
75138+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
75139+ * Increases kernel attack surface in areas developers
75140+ * previously cared little about ("low importance due
75141+ * to requiring "root" capability")
75142+ * To be removed when this code receives *proper* review
75143+ */
75144+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
75145+ !capable(CAP_SETGID))
75146+ return -EPERM;
75147+ }
75148+#endif
75149+
75150 /*
75151 * Determine whether and which event to report to ptracer. When
75152 * called from kernel_thread or CLONE_UNTRACED is explicitly
75153@@ -1608,6 +1685,8 @@ long do_fork(unsigned long clone_flags,
75154 if (clone_flags & CLONE_PARENT_SETTID)
75155 put_user(nr, parent_tidptr);
75156
75157+ gr_handle_brute_check();
75158+
75159 if (clone_flags & CLONE_VFORK) {
75160 p->vfork_done = &vfork;
75161 init_completion(&vfork);
75162@@ -1761,7 +1840,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
75163 return 0;
75164
75165 /* don't need lock here; in the worst case we'll do useless copy */
75166- if (fs->users == 1)
75167+ if (atomic_read(&fs->users) == 1)
75168 return 0;
75169
75170 *new_fsp = copy_fs_struct(fs);
75171@@ -1873,7 +1952,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
75172 fs = current->fs;
75173 spin_lock(&fs->lock);
75174 current->fs = new_fs;
75175- if (--fs->users)
75176+ gr_set_chroot_entries(current, &current->fs->root);
75177+ if (atomic_dec_return(&fs->users))
75178 new_fs = NULL;
75179 else
75180 new_fs = fs;
75181diff --git a/kernel/futex.c b/kernel/futex.c
75182index b26dcfc..39e266a 100644
75183--- a/kernel/futex.c
75184+++ b/kernel/futex.c
75185@@ -54,6 +54,7 @@
75186 #include <linux/mount.h>
75187 #include <linux/pagemap.h>
75188 #include <linux/syscalls.h>
75189+#include <linux/ptrace.h>
75190 #include <linux/signal.h>
75191 #include <linux/export.h>
75192 #include <linux/magic.h>
75193@@ -241,6 +242,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
75194 struct page *page, *page_head;
75195 int err, ro = 0;
75196
75197+#ifdef CONFIG_PAX_SEGMEXEC
75198+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
75199+ return -EFAULT;
75200+#endif
75201+
75202 /*
75203 * The futex address must be "naturally" aligned.
75204 */
75205@@ -2732,6 +2738,7 @@ static int __init futex_init(void)
75206 {
75207 u32 curval;
75208 int i;
75209+ mm_segment_t oldfs;
75210
75211 /*
75212 * This will fail and we want it. Some arch implementations do
75213@@ -2743,8 +2750,11 @@ static int __init futex_init(void)
75214 * implementation, the non-functional ones will return
75215 * -ENOSYS.
75216 */
75217+ oldfs = get_fs();
75218+ set_fs(USER_DS);
75219 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
75220 futex_cmpxchg_enabled = 1;
75221+ set_fs(oldfs);
75222
75223 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
75224 plist_head_init(&futex_queues[i].chain);
75225diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
75226index f9f44fd..29885e4 100644
75227--- a/kernel/futex_compat.c
75228+++ b/kernel/futex_compat.c
75229@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
75230 return 0;
75231 }
75232
75233-static void __user *futex_uaddr(struct robust_list __user *entry,
75234+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
75235 compat_long_t futex_offset)
75236 {
75237 compat_uptr_t base = ptr_to_compat(entry);
75238diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
75239index 9b22d03..6295b62 100644
75240--- a/kernel/gcov/base.c
75241+++ b/kernel/gcov/base.c
75242@@ -102,11 +102,6 @@ void gcov_enable_events(void)
75243 }
75244
75245 #ifdef CONFIG_MODULES
75246-static inline int within(void *addr, void *start, unsigned long size)
75247-{
75248- return ((addr >= start) && (addr < start + size));
75249-}
75250-
75251 /* Update list and generate events when modules are unloaded. */
75252 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
75253 void *data)
75254@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
75255 prev = NULL;
75256 /* Remove entries located in module from linked list. */
75257 for (info = gcov_info_head; info; info = info->next) {
75258- if (within(info, mod->module_core, mod->core_size)) {
75259+ if (within_module_core_rw((unsigned long)info, mod)) {
75260 if (prev)
75261 prev->next = info->next;
75262 else
75263diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
75264index 7ef5556..8247f11 100644
75265--- a/kernel/hrtimer.c
75266+++ b/kernel/hrtimer.c
75267@@ -1416,7 +1416,7 @@ void hrtimer_peek_ahead_timers(void)
75268 local_irq_restore(flags);
75269 }
75270
75271-static void run_hrtimer_softirq(struct softirq_action *h)
75272+static void run_hrtimer_softirq(void)
75273 {
75274 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
75275
75276@@ -1758,7 +1758,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
75277 return NOTIFY_OK;
75278 }
75279
75280-static struct notifier_block __cpuinitdata hrtimers_nb = {
75281+static struct notifier_block hrtimers_nb = {
75282 .notifier_call = hrtimer_cpu_notify,
75283 };
75284
75285diff --git a/kernel/irq_work.c b/kernel/irq_work.c
75286index 55fcce6..0e4cf34 100644
75287--- a/kernel/irq_work.c
75288+++ b/kernel/irq_work.c
75289@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
75290 return NOTIFY_OK;
75291 }
75292
75293-static struct notifier_block cpu_notify;
75294+static struct notifier_block cpu_notify = {
75295+ .notifier_call = irq_work_cpu_notify,
75296+ .priority = 0,
75297+};
75298
75299 static __init int irq_work_init_cpu_notifier(void)
75300 {
75301- cpu_notify.notifier_call = irq_work_cpu_notify;
75302- cpu_notify.priority = 0;
75303 register_cpu_notifier(&cpu_notify);
75304 return 0;
75305 }
75306diff --git a/kernel/jump_label.c b/kernel/jump_label.c
75307index 60f48fa..7f3a770 100644
75308--- a/kernel/jump_label.c
75309+++ b/kernel/jump_label.c
75310@@ -13,6 +13,7 @@
75311 #include <linux/sort.h>
75312 #include <linux/err.h>
75313 #include <linux/static_key.h>
75314+#include <linux/mm.h>
75315
75316 #ifdef HAVE_JUMP_LABEL
75317
75318@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
75319
75320 size = (((unsigned long)stop - (unsigned long)start)
75321 / sizeof(struct jump_entry));
75322+ pax_open_kernel();
75323 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
75324+ pax_close_kernel();
75325 }
75326
75327 static void jump_label_update(struct static_key *key, int enable);
75328@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
75329 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
75330 struct jump_entry *iter;
75331
75332+ pax_open_kernel();
75333 for (iter = iter_start; iter < iter_stop; iter++) {
75334 if (within_module_init(iter->code, mod))
75335 iter->code = 0;
75336 }
75337+ pax_close_kernel();
75338 }
75339
75340 static int
75341diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
75342index 2169fee..706ccca 100644
75343--- a/kernel/kallsyms.c
75344+++ b/kernel/kallsyms.c
75345@@ -11,6 +11,9 @@
75346 * Changed the compression method from stem compression to "table lookup"
75347 * compression (see scripts/kallsyms.c for a more complete description)
75348 */
75349+#ifdef CONFIG_GRKERNSEC_HIDESYM
75350+#define __INCLUDED_BY_HIDESYM 1
75351+#endif
75352 #include <linux/kallsyms.h>
75353 #include <linux/module.h>
75354 #include <linux/init.h>
75355@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
75356
75357 static inline int is_kernel_inittext(unsigned long addr)
75358 {
75359+ if (system_state != SYSTEM_BOOTING)
75360+ return 0;
75361+
75362 if (addr >= (unsigned long)_sinittext
75363 && addr <= (unsigned long)_einittext)
75364 return 1;
75365 return 0;
75366 }
75367
75368+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75369+#ifdef CONFIG_MODULES
75370+static inline int is_module_text(unsigned long addr)
75371+{
75372+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
75373+ return 1;
75374+
75375+ addr = ktla_ktva(addr);
75376+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
75377+}
75378+#else
75379+static inline int is_module_text(unsigned long addr)
75380+{
75381+ return 0;
75382+}
75383+#endif
75384+#endif
75385+
75386 static inline int is_kernel_text(unsigned long addr)
75387 {
75388 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
75389@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
75390
75391 static inline int is_kernel(unsigned long addr)
75392 {
75393+
75394+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75395+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
75396+ return 1;
75397+
75398+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
75399+#else
75400 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
75401+#endif
75402+
75403 return 1;
75404 return in_gate_area_no_mm(addr);
75405 }
75406
75407 static int is_ksym_addr(unsigned long addr)
75408 {
75409+
75410+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75411+ if (is_module_text(addr))
75412+ return 0;
75413+#endif
75414+
75415 if (all_var)
75416 return is_kernel(addr);
75417
75418@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
75419
75420 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
75421 {
75422- iter->name[0] = '\0';
75423 iter->nameoff = get_symbol_offset(new_pos);
75424 iter->pos = new_pos;
75425 }
75426@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
75427 {
75428 struct kallsym_iter *iter = m->private;
75429
75430+#ifdef CONFIG_GRKERNSEC_HIDESYM
75431+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
75432+ return 0;
75433+#endif
75434+
75435 /* Some debugging symbols have no name. Ignore them. */
75436 if (!iter->name[0])
75437 return 0;
75438@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
75439 */
75440 type = iter->exported ? toupper(iter->type) :
75441 tolower(iter->type);
75442+
75443 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
75444 type, iter->name, iter->module_name);
75445 } else
75446@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
75447 struct kallsym_iter *iter;
75448 int ret;
75449
75450- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
75451+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
75452 if (!iter)
75453 return -ENOMEM;
75454 reset_iter(iter, 0);
75455diff --git a/kernel/kcmp.c b/kernel/kcmp.c
75456index e30ac0f..3528cac 100644
75457--- a/kernel/kcmp.c
75458+++ b/kernel/kcmp.c
75459@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
75460 struct task_struct *task1, *task2;
75461 int ret;
75462
75463+#ifdef CONFIG_GRKERNSEC
75464+ return -ENOSYS;
75465+#endif
75466+
75467 rcu_read_lock();
75468
75469 /*
75470diff --git a/kernel/kexec.c b/kernel/kexec.c
75471index ffd4e11..c3ff6bf 100644
75472--- a/kernel/kexec.c
75473+++ b/kernel/kexec.c
75474@@ -1048,7 +1048,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
75475 unsigned long flags)
75476 {
75477 struct compat_kexec_segment in;
75478- struct kexec_segment out, __user *ksegments;
75479+ struct kexec_segment out;
75480+ struct kexec_segment __user *ksegments;
75481 unsigned long i, result;
75482
75483 /* Don't allow clients that don't understand the native
75484diff --git a/kernel/kmod.c b/kernel/kmod.c
75485index 8985c87..f539dbe 100644
75486--- a/kernel/kmod.c
75487+++ b/kernel/kmod.c
75488@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
75489 kfree(info->argv);
75490 }
75491
75492-static int call_modprobe(char *module_name, int wait)
75493+static int call_modprobe(char *module_name, char *module_param, int wait)
75494 {
75495 static char *envp[] = {
75496 "HOME=/",
75497@@ -84,7 +84,7 @@ static int call_modprobe(char *module_name, int wait)
75498 NULL
75499 };
75500
75501- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
75502+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
75503 if (!argv)
75504 goto out;
75505
75506@@ -96,7 +96,8 @@ static int call_modprobe(char *module_name, int wait)
75507 argv[1] = "-q";
75508 argv[2] = "--";
75509 argv[3] = module_name; /* check free_modprobe_argv() */
75510- argv[4] = NULL;
75511+ argv[4] = module_param;
75512+ argv[5] = NULL;
75513
75514 return call_usermodehelper_fns(modprobe_path, argv, envp,
75515 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
75516@@ -121,9 +122,8 @@ out:
75517 * If module auto-loading support is disabled then this function
75518 * becomes a no-operation.
75519 */
75520-int __request_module(bool wait, const char *fmt, ...)
75521+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
75522 {
75523- va_list args;
75524 char module_name[MODULE_NAME_LEN];
75525 unsigned int max_modprobes;
75526 int ret;
75527@@ -139,9 +139,7 @@ int __request_module(bool wait, const char *fmt, ...)
75528 */
75529 WARN_ON_ONCE(wait && current_is_async());
75530
75531- va_start(args, fmt);
75532- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
75533- va_end(args);
75534+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
75535 if (ret >= MODULE_NAME_LEN)
75536 return -ENAMETOOLONG;
75537
75538@@ -149,6 +147,20 @@ int __request_module(bool wait, const char *fmt, ...)
75539 if (ret)
75540 return ret;
75541
75542+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75543+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
75544+ /* hack to workaround consolekit/udisks stupidity */
75545+ read_lock(&tasklist_lock);
75546+ if (!strcmp(current->comm, "mount") &&
75547+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
75548+ read_unlock(&tasklist_lock);
75549+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
75550+ return -EPERM;
75551+ }
75552+ read_unlock(&tasklist_lock);
75553+ }
75554+#endif
75555+
75556 /* If modprobe needs a service that is in a module, we get a recursive
75557 * loop. Limit the number of running kmod threads to max_threads/2 or
75558 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
75559@@ -177,11 +189,52 @@ int __request_module(bool wait, const char *fmt, ...)
75560
75561 trace_module_request(module_name, wait, _RET_IP_);
75562
75563- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
75564+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
75565
75566 atomic_dec(&kmod_concurrent);
75567 return ret;
75568 }
75569+
75570+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
75571+{
75572+ va_list args;
75573+ int ret;
75574+
75575+ va_start(args, fmt);
75576+ ret = ____request_module(wait, module_param, fmt, args);
75577+ va_end(args);
75578+
75579+ return ret;
75580+}
75581+
75582+int __request_module(bool wait, const char *fmt, ...)
75583+{
75584+ va_list args;
75585+ int ret;
75586+
75587+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75588+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
75589+ char module_param[MODULE_NAME_LEN];
75590+
75591+ memset(module_param, 0, sizeof(module_param));
75592+
75593+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
75594+
75595+ va_start(args, fmt);
75596+ ret = ____request_module(wait, module_param, fmt, args);
75597+ va_end(args);
75598+
75599+ return ret;
75600+ }
75601+#endif
75602+
75603+ va_start(args, fmt);
75604+ ret = ____request_module(wait, NULL, fmt, args);
75605+ va_end(args);
75606+
75607+ return ret;
75608+}
75609+
75610 EXPORT_SYMBOL(__request_module);
75611 #endif /* CONFIG_MODULES */
75612
75613@@ -292,7 +345,7 @@ static int wait_for_helper(void *data)
75614 *
75615 * Thus the __user pointer cast is valid here.
75616 */
75617- sys_wait4(pid, (int __user *)&ret, 0, NULL);
75618+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
75619
75620 /*
75621 * If ret is 0, either ____call_usermodehelper failed and the
75622@@ -649,7 +702,7 @@ EXPORT_SYMBOL(call_usermodehelper_fns);
75623 static int proc_cap_handler(struct ctl_table *table, int write,
75624 void __user *buffer, size_t *lenp, loff_t *ppos)
75625 {
75626- struct ctl_table t;
75627+ ctl_table_no_const t;
75628 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
75629 kernel_cap_t new_cap;
75630 int err, i;
75631diff --git a/kernel/kprobes.c b/kernel/kprobes.c
75632index 3fed7f0..a3f95ed 100644
75633--- a/kernel/kprobes.c
75634+++ b/kernel/kprobes.c
75635@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
75636 * kernel image and loaded module images reside. This is required
75637 * so x86_64 can correctly handle the %rip-relative fixups.
75638 */
75639- kip->insns = module_alloc(PAGE_SIZE);
75640+ kip->insns = module_alloc_exec(PAGE_SIZE);
75641 if (!kip->insns) {
75642 kfree(kip);
75643 return NULL;
75644@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
75645 */
75646 if (!list_is_singular(&kip->list)) {
75647 list_del(&kip->list);
75648- module_free(NULL, kip->insns);
75649+ module_free_exec(NULL, kip->insns);
75650 kfree(kip);
75651 }
75652 return 1;
75653@@ -2073,7 +2073,7 @@ static int __init init_kprobes(void)
75654 {
75655 int i, err = 0;
75656 unsigned long offset = 0, size = 0;
75657- char *modname, namebuf[128];
75658+ char *modname, namebuf[KSYM_NAME_LEN];
75659 const char *symbol_name;
75660 void *addr;
75661 struct kprobe_blackpoint *kb;
75662@@ -2158,11 +2158,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
75663 kprobe_type = "k";
75664
75665 if (sym)
75666- seq_printf(pi, "%p %s %s+0x%x %s ",
75667+ seq_printf(pi, "%pK %s %s+0x%x %s ",
75668 p->addr, kprobe_type, sym, offset,
75669 (modname ? modname : " "));
75670 else
75671- seq_printf(pi, "%p %s %p ",
75672+ seq_printf(pi, "%pK %s %pK ",
75673 p->addr, kprobe_type, p->addr);
75674
75675 if (!pp)
75676@@ -2199,7 +2199,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
75677 const char *sym = NULL;
75678 unsigned int i = *(loff_t *) v;
75679 unsigned long offset = 0;
75680- char *modname, namebuf[128];
75681+ char *modname, namebuf[KSYM_NAME_LEN];
75682
75683 head = &kprobe_table[i];
75684 preempt_disable();
75685diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
75686index 6ada93c..dce7d5d 100644
75687--- a/kernel/ksysfs.c
75688+++ b/kernel/ksysfs.c
75689@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
75690 {
75691 if (count+1 > UEVENT_HELPER_PATH_LEN)
75692 return -ENOENT;
75693+ if (!capable(CAP_SYS_ADMIN))
75694+ return -EPERM;
75695 memcpy(uevent_helper, buf, count);
75696 uevent_helper[count] = '\0';
75697 if (count && uevent_helper[count-1] == '\n')
75698@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
75699 return count;
75700 }
75701
75702-static struct bin_attribute notes_attr = {
75703+static bin_attribute_no_const notes_attr __read_only = {
75704 .attr = {
75705 .name = "notes",
75706 .mode = S_IRUGO,
75707diff --git a/kernel/lockdep.c b/kernel/lockdep.c
75708index 8a0efac..56f1e2d 100644
75709--- a/kernel/lockdep.c
75710+++ b/kernel/lockdep.c
75711@@ -590,6 +590,10 @@ static int static_obj(void *obj)
75712 end = (unsigned long) &_end,
75713 addr = (unsigned long) obj;
75714
75715+#ifdef CONFIG_PAX_KERNEXEC
75716+ start = ktla_ktva(start);
75717+#endif
75718+
75719 /*
75720 * static variable?
75721 */
75722@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
75723 if (!static_obj(lock->key)) {
75724 debug_locks_off();
75725 printk("INFO: trying to register non-static key.\n");
75726+ printk("lock:%pS key:%pS.\n", lock, lock->key);
75727 printk("the code is fine but needs lockdep annotation.\n");
75728 printk("turning off the locking correctness validator.\n");
75729 dump_stack();
75730@@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
75731 if (!class)
75732 return 0;
75733 }
75734- atomic_inc((atomic_t *)&class->ops);
75735+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
75736 if (very_verbose(class)) {
75737 printk("\nacquire class [%p] %s", class->key, class->name);
75738 if (class->name_version > 1)
75739diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
75740index b2c71c5..7b88d63 100644
75741--- a/kernel/lockdep_proc.c
75742+++ b/kernel/lockdep_proc.c
75743@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
75744 return 0;
75745 }
75746
75747- seq_printf(m, "%p", class->key);
75748+ seq_printf(m, "%pK", class->key);
75749 #ifdef CONFIG_DEBUG_LOCKDEP
75750 seq_printf(m, " OPS:%8ld", class->ops);
75751 #endif
75752@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
75753
75754 list_for_each_entry(entry, &class->locks_after, entry) {
75755 if (entry->distance == 1) {
75756- seq_printf(m, " -> [%p] ", entry->class->key);
75757+ seq_printf(m, " -> [%pK] ", entry->class->key);
75758 print_name(m, entry->class);
75759 seq_puts(m, "\n");
75760 }
75761@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
75762 if (!class->key)
75763 continue;
75764
75765- seq_printf(m, "[%p] ", class->key);
75766+ seq_printf(m, "[%pK] ", class->key);
75767 print_name(m, class);
75768 seq_puts(m, "\n");
75769 }
75770@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
75771 if (!i)
75772 seq_line(m, '-', 40-namelen, namelen);
75773
75774- snprintf(ip, sizeof(ip), "[<%p>]",
75775+ snprintf(ip, sizeof(ip), "[<%pK>]",
75776 (void *)class->contention_point[i]);
75777 seq_printf(m, "%40s %14lu %29s %pS\n",
75778 name, stats->contention_point[i],
75779@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
75780 if (!i)
75781 seq_line(m, '-', 40-namelen, namelen);
75782
75783- snprintf(ip, sizeof(ip), "[<%p>]",
75784+ snprintf(ip, sizeof(ip), "[<%pK>]",
75785 (void *)class->contending_point[i]);
75786 seq_printf(m, "%40s %14lu %29s %pS\n",
75787 name, stats->contending_point[i],
75788diff --git a/kernel/module.c b/kernel/module.c
75789index 97f202c..109575f 100644
75790--- a/kernel/module.c
75791+++ b/kernel/module.c
75792@@ -61,6 +61,7 @@
75793 #include <linux/pfn.h>
75794 #include <linux/bsearch.h>
75795 #include <linux/fips.h>
75796+#include <linux/grsecurity.h>
75797 #include <uapi/linux/module.h>
75798 #include "module-internal.h"
75799
75800@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
75801
75802 /* Bounds of module allocation, for speeding __module_address.
75803 * Protected by module_mutex. */
75804-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
75805+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
75806+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
75807
75808 int register_module_notifier(struct notifier_block * nb)
75809 {
75810@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
75811 return true;
75812
75813 list_for_each_entry_rcu(mod, &modules, list) {
75814- struct symsearch arr[] = {
75815+ struct symsearch modarr[] = {
75816 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
75817 NOT_GPL_ONLY, false },
75818 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
75819@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
75820 if (mod->state == MODULE_STATE_UNFORMED)
75821 continue;
75822
75823- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
75824+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
75825 return true;
75826 }
75827 return false;
75828@@ -485,7 +487,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
75829 static int percpu_modalloc(struct module *mod,
75830 unsigned long size, unsigned long align)
75831 {
75832- if (align > PAGE_SIZE) {
75833+ if (align-1 >= PAGE_SIZE) {
75834 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
75835 mod->name, align, PAGE_SIZE);
75836 align = PAGE_SIZE;
75837@@ -1089,7 +1091,7 @@ struct module_attribute module_uevent =
75838 static ssize_t show_coresize(struct module_attribute *mattr,
75839 struct module_kobject *mk, char *buffer)
75840 {
75841- return sprintf(buffer, "%u\n", mk->mod->core_size);
75842+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
75843 }
75844
75845 static struct module_attribute modinfo_coresize =
75846@@ -1098,7 +1100,7 @@ static struct module_attribute modinfo_coresize =
75847 static ssize_t show_initsize(struct module_attribute *mattr,
75848 struct module_kobject *mk, char *buffer)
75849 {
75850- return sprintf(buffer, "%u\n", mk->mod->init_size);
75851+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
75852 }
75853
75854 static struct module_attribute modinfo_initsize =
75855@@ -1312,7 +1314,7 @@ resolve_symbol_wait(struct module *mod,
75856 */
75857 #ifdef CONFIG_SYSFS
75858
75859-#ifdef CONFIG_KALLSYMS
75860+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
75861 static inline bool sect_empty(const Elf_Shdr *sect)
75862 {
75863 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
75864@@ -1452,7 +1454,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
75865 {
75866 unsigned int notes, loaded, i;
75867 struct module_notes_attrs *notes_attrs;
75868- struct bin_attribute *nattr;
75869+ bin_attribute_no_const *nattr;
75870
75871 /* failed to create section attributes, so can't create notes */
75872 if (!mod->sect_attrs)
75873@@ -1564,7 +1566,7 @@ static void del_usage_links(struct module *mod)
75874 static int module_add_modinfo_attrs(struct module *mod)
75875 {
75876 struct module_attribute *attr;
75877- struct module_attribute *temp_attr;
75878+ module_attribute_no_const *temp_attr;
75879 int error = 0;
75880 int i;
75881
75882@@ -1778,21 +1780,21 @@ static void set_section_ro_nx(void *base,
75883
75884 static void unset_module_core_ro_nx(struct module *mod)
75885 {
75886- set_page_attributes(mod->module_core + mod->core_text_size,
75887- mod->module_core + mod->core_size,
75888+ set_page_attributes(mod->module_core_rw,
75889+ mod->module_core_rw + mod->core_size_rw,
75890 set_memory_x);
75891- set_page_attributes(mod->module_core,
75892- mod->module_core + mod->core_ro_size,
75893+ set_page_attributes(mod->module_core_rx,
75894+ mod->module_core_rx + mod->core_size_rx,
75895 set_memory_rw);
75896 }
75897
75898 static void unset_module_init_ro_nx(struct module *mod)
75899 {
75900- set_page_attributes(mod->module_init + mod->init_text_size,
75901- mod->module_init + mod->init_size,
75902+ set_page_attributes(mod->module_init_rw,
75903+ mod->module_init_rw + mod->init_size_rw,
75904 set_memory_x);
75905- set_page_attributes(mod->module_init,
75906- mod->module_init + mod->init_ro_size,
75907+ set_page_attributes(mod->module_init_rx,
75908+ mod->module_init_rx + mod->init_size_rx,
75909 set_memory_rw);
75910 }
75911
75912@@ -1805,14 +1807,14 @@ void set_all_modules_text_rw(void)
75913 list_for_each_entry_rcu(mod, &modules, list) {
75914 if (mod->state == MODULE_STATE_UNFORMED)
75915 continue;
75916- if ((mod->module_core) && (mod->core_text_size)) {
75917- set_page_attributes(mod->module_core,
75918- mod->module_core + mod->core_text_size,
75919+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
75920+ set_page_attributes(mod->module_core_rx,
75921+ mod->module_core_rx + mod->core_size_rx,
75922 set_memory_rw);
75923 }
75924- if ((mod->module_init) && (mod->init_text_size)) {
75925- set_page_attributes(mod->module_init,
75926- mod->module_init + mod->init_text_size,
75927+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
75928+ set_page_attributes(mod->module_init_rx,
75929+ mod->module_init_rx + mod->init_size_rx,
75930 set_memory_rw);
75931 }
75932 }
75933@@ -1828,14 +1830,14 @@ void set_all_modules_text_ro(void)
75934 list_for_each_entry_rcu(mod, &modules, list) {
75935 if (mod->state == MODULE_STATE_UNFORMED)
75936 continue;
75937- if ((mod->module_core) && (mod->core_text_size)) {
75938- set_page_attributes(mod->module_core,
75939- mod->module_core + mod->core_text_size,
75940+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
75941+ set_page_attributes(mod->module_core_rx,
75942+ mod->module_core_rx + mod->core_size_rx,
75943 set_memory_ro);
75944 }
75945- if ((mod->module_init) && (mod->init_text_size)) {
75946- set_page_attributes(mod->module_init,
75947- mod->module_init + mod->init_text_size,
75948+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
75949+ set_page_attributes(mod->module_init_rx,
75950+ mod->module_init_rx + mod->init_size_rx,
75951 set_memory_ro);
75952 }
75953 }
75954@@ -1886,16 +1888,19 @@ static void free_module(struct module *mod)
75955
75956 /* This may be NULL, but that's OK */
75957 unset_module_init_ro_nx(mod);
75958- module_free(mod, mod->module_init);
75959+ module_free(mod, mod->module_init_rw);
75960+ module_free_exec(mod, mod->module_init_rx);
75961 kfree(mod->args);
75962 percpu_modfree(mod);
75963
75964 /* Free lock-classes: */
75965- lockdep_free_key_range(mod->module_core, mod->core_size);
75966+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
75967+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
75968
75969 /* Finally, free the core (containing the module structure) */
75970 unset_module_core_ro_nx(mod);
75971- module_free(mod, mod->module_core);
75972+ module_free_exec(mod, mod->module_core_rx);
75973+ module_free(mod, mod->module_core_rw);
75974
75975 #ifdef CONFIG_MPU
75976 update_protections(current->mm);
75977@@ -1965,9 +1970,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
75978 int ret = 0;
75979 const struct kernel_symbol *ksym;
75980
75981+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75982+ int is_fs_load = 0;
75983+ int register_filesystem_found = 0;
75984+ char *p;
75985+
75986+ p = strstr(mod->args, "grsec_modharden_fs");
75987+ if (p) {
75988+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
75989+ /* copy \0 as well */
75990+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
75991+ is_fs_load = 1;
75992+ }
75993+#endif
75994+
75995 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
75996 const char *name = info->strtab + sym[i].st_name;
75997
75998+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75999+ /* it's a real shame this will never get ripped and copied
76000+ upstream! ;(
76001+ */
76002+ if (is_fs_load && !strcmp(name, "register_filesystem"))
76003+ register_filesystem_found = 1;
76004+#endif
76005+
76006 switch (sym[i].st_shndx) {
76007 case SHN_COMMON:
76008 /* We compiled with -fno-common. These are not
76009@@ -1988,7 +2015,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76010 ksym = resolve_symbol_wait(mod, info, name);
76011 /* Ok if resolved. */
76012 if (ksym && !IS_ERR(ksym)) {
76013+ pax_open_kernel();
76014 sym[i].st_value = ksym->value;
76015+ pax_close_kernel();
76016 break;
76017 }
76018
76019@@ -2007,11 +2036,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76020 secbase = (unsigned long)mod_percpu(mod);
76021 else
76022 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
76023+ pax_open_kernel();
76024 sym[i].st_value += secbase;
76025+ pax_close_kernel();
76026 break;
76027 }
76028 }
76029
76030+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76031+ if (is_fs_load && !register_filesystem_found) {
76032+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
76033+ ret = -EPERM;
76034+ }
76035+#endif
76036+
76037 return ret;
76038 }
76039
76040@@ -2095,22 +2133,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
76041 || s->sh_entsize != ~0UL
76042 || strstarts(sname, ".init"))
76043 continue;
76044- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
76045+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
76046+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
76047+ else
76048+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
76049 pr_debug("\t%s\n", sname);
76050 }
76051- switch (m) {
76052- case 0: /* executable */
76053- mod->core_size = debug_align(mod->core_size);
76054- mod->core_text_size = mod->core_size;
76055- break;
76056- case 1: /* RO: text and ro-data */
76057- mod->core_size = debug_align(mod->core_size);
76058- mod->core_ro_size = mod->core_size;
76059- break;
76060- case 3: /* whole core */
76061- mod->core_size = debug_align(mod->core_size);
76062- break;
76063- }
76064 }
76065
76066 pr_debug("Init section allocation order:\n");
76067@@ -2124,23 +2152,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
76068 || s->sh_entsize != ~0UL
76069 || !strstarts(sname, ".init"))
76070 continue;
76071- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
76072- | INIT_OFFSET_MASK);
76073+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
76074+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
76075+ else
76076+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
76077+ s->sh_entsize |= INIT_OFFSET_MASK;
76078 pr_debug("\t%s\n", sname);
76079 }
76080- switch (m) {
76081- case 0: /* executable */
76082- mod->init_size = debug_align(mod->init_size);
76083- mod->init_text_size = mod->init_size;
76084- break;
76085- case 1: /* RO: text and ro-data */
76086- mod->init_size = debug_align(mod->init_size);
76087- mod->init_ro_size = mod->init_size;
76088- break;
76089- case 3: /* whole init */
76090- mod->init_size = debug_align(mod->init_size);
76091- break;
76092- }
76093 }
76094 }
76095
76096@@ -2313,7 +2331,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
76097
76098 /* Put symbol section at end of init part of module. */
76099 symsect->sh_flags |= SHF_ALLOC;
76100- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
76101+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
76102 info->index.sym) | INIT_OFFSET_MASK;
76103 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
76104
76105@@ -2330,13 +2348,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
76106 }
76107
76108 /* Append room for core symbols at end of core part. */
76109- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
76110- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
76111- mod->core_size += strtab_size;
76112+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
76113+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
76114+ mod->core_size_rx += strtab_size;
76115
76116 /* Put string table section at end of init part of module. */
76117 strsect->sh_flags |= SHF_ALLOC;
76118- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
76119+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
76120 info->index.str) | INIT_OFFSET_MASK;
76121 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
76122 }
76123@@ -2354,12 +2372,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
76124 /* Make sure we get permanent strtab: don't use info->strtab. */
76125 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
76126
76127+ pax_open_kernel();
76128+
76129 /* Set types up while we still have access to sections. */
76130 for (i = 0; i < mod->num_symtab; i++)
76131 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
76132
76133- mod->core_symtab = dst = mod->module_core + info->symoffs;
76134- mod->core_strtab = s = mod->module_core + info->stroffs;
76135+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
76136+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
76137 src = mod->symtab;
76138 for (ndst = i = 0; i < mod->num_symtab; i++) {
76139 if (i == 0 ||
76140@@ -2371,6 +2391,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
76141 }
76142 }
76143 mod->core_num_syms = ndst;
76144+
76145+ pax_close_kernel();
76146 }
76147 #else
76148 static inline void layout_symtab(struct module *mod, struct load_info *info)
76149@@ -2404,17 +2426,33 @@ void * __weak module_alloc(unsigned long size)
76150 return vmalloc_exec(size);
76151 }
76152
76153-static void *module_alloc_update_bounds(unsigned long size)
76154+static void *module_alloc_update_bounds_rw(unsigned long size)
76155 {
76156 void *ret = module_alloc(size);
76157
76158 if (ret) {
76159 mutex_lock(&module_mutex);
76160 /* Update module bounds. */
76161- if ((unsigned long)ret < module_addr_min)
76162- module_addr_min = (unsigned long)ret;
76163- if ((unsigned long)ret + size > module_addr_max)
76164- module_addr_max = (unsigned long)ret + size;
76165+ if ((unsigned long)ret < module_addr_min_rw)
76166+ module_addr_min_rw = (unsigned long)ret;
76167+ if ((unsigned long)ret + size > module_addr_max_rw)
76168+ module_addr_max_rw = (unsigned long)ret + size;
76169+ mutex_unlock(&module_mutex);
76170+ }
76171+ return ret;
76172+}
76173+
76174+static void *module_alloc_update_bounds_rx(unsigned long size)
76175+{
76176+ void *ret = module_alloc_exec(size);
76177+
76178+ if (ret) {
76179+ mutex_lock(&module_mutex);
76180+ /* Update module bounds. */
76181+ if ((unsigned long)ret < module_addr_min_rx)
76182+ module_addr_min_rx = (unsigned long)ret;
76183+ if ((unsigned long)ret + size > module_addr_max_rx)
76184+ module_addr_max_rx = (unsigned long)ret + size;
76185 mutex_unlock(&module_mutex);
76186 }
76187 return ret;
76188@@ -2690,8 +2728,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
76189 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
76190 {
76191 const char *modmagic = get_modinfo(info, "vermagic");
76192+ const char *license = get_modinfo(info, "license");
76193 int err;
76194
76195+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
76196+ if (!license || !license_is_gpl_compatible(license))
76197+ return -ENOEXEC;
76198+#endif
76199+
76200 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
76201 modmagic = NULL;
76202
76203@@ -2717,7 +2761,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
76204 }
76205
76206 /* Set up license info based on the info section */
76207- set_license(mod, get_modinfo(info, "license"));
76208+ set_license(mod, license);
76209
76210 return 0;
76211 }
76212@@ -2811,7 +2855,7 @@ static int move_module(struct module *mod, struct load_info *info)
76213 void *ptr;
76214
76215 /* Do the allocs. */
76216- ptr = module_alloc_update_bounds(mod->core_size);
76217+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
76218 /*
76219 * The pointer to this block is stored in the module structure
76220 * which is inside the block. Just mark it as not being a
76221@@ -2821,11 +2865,11 @@ static int move_module(struct module *mod, struct load_info *info)
76222 if (!ptr)
76223 return -ENOMEM;
76224
76225- memset(ptr, 0, mod->core_size);
76226- mod->module_core = ptr;
76227+ memset(ptr, 0, mod->core_size_rw);
76228+ mod->module_core_rw = ptr;
76229
76230- if (mod->init_size) {
76231- ptr = module_alloc_update_bounds(mod->init_size);
76232+ if (mod->init_size_rw) {
76233+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
76234 /*
76235 * The pointer to this block is stored in the module structure
76236 * which is inside the block. This block doesn't need to be
76237@@ -2834,13 +2878,45 @@ static int move_module(struct module *mod, struct load_info *info)
76238 */
76239 kmemleak_ignore(ptr);
76240 if (!ptr) {
76241- module_free(mod, mod->module_core);
76242+ module_free(mod, mod->module_core_rw);
76243 return -ENOMEM;
76244 }
76245- memset(ptr, 0, mod->init_size);
76246- mod->module_init = ptr;
76247+ memset(ptr, 0, mod->init_size_rw);
76248+ mod->module_init_rw = ptr;
76249 } else
76250- mod->module_init = NULL;
76251+ mod->module_init_rw = NULL;
76252+
76253+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
76254+ kmemleak_not_leak(ptr);
76255+ if (!ptr) {
76256+ if (mod->module_init_rw)
76257+ module_free(mod, mod->module_init_rw);
76258+ module_free(mod, mod->module_core_rw);
76259+ return -ENOMEM;
76260+ }
76261+
76262+ pax_open_kernel();
76263+ memset(ptr, 0, mod->core_size_rx);
76264+ pax_close_kernel();
76265+ mod->module_core_rx = ptr;
76266+
76267+ if (mod->init_size_rx) {
76268+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
76269+ kmemleak_ignore(ptr);
76270+ if (!ptr && mod->init_size_rx) {
76271+ module_free_exec(mod, mod->module_core_rx);
76272+ if (mod->module_init_rw)
76273+ module_free(mod, mod->module_init_rw);
76274+ module_free(mod, mod->module_core_rw);
76275+ return -ENOMEM;
76276+ }
76277+
76278+ pax_open_kernel();
76279+ memset(ptr, 0, mod->init_size_rx);
76280+ pax_close_kernel();
76281+ mod->module_init_rx = ptr;
76282+ } else
76283+ mod->module_init_rx = NULL;
76284
76285 /* Transfer each section which specifies SHF_ALLOC */
76286 pr_debug("final section addresses:\n");
76287@@ -2851,16 +2927,45 @@ static int move_module(struct module *mod, struct load_info *info)
76288 if (!(shdr->sh_flags & SHF_ALLOC))
76289 continue;
76290
76291- if (shdr->sh_entsize & INIT_OFFSET_MASK)
76292- dest = mod->module_init
76293- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
76294- else
76295- dest = mod->module_core + shdr->sh_entsize;
76296+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
76297+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
76298+ dest = mod->module_init_rw
76299+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
76300+ else
76301+ dest = mod->module_init_rx
76302+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
76303+ } else {
76304+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
76305+ dest = mod->module_core_rw + shdr->sh_entsize;
76306+ else
76307+ dest = mod->module_core_rx + shdr->sh_entsize;
76308+ }
76309+
76310+ if (shdr->sh_type != SHT_NOBITS) {
76311+
76312+#ifdef CONFIG_PAX_KERNEXEC
76313+#ifdef CONFIG_X86_64
76314+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
76315+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
76316+#endif
76317+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
76318+ pax_open_kernel();
76319+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
76320+ pax_close_kernel();
76321+ } else
76322+#endif
76323
76324- if (shdr->sh_type != SHT_NOBITS)
76325 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
76326+ }
76327 /* Update sh_addr to point to copy in image. */
76328- shdr->sh_addr = (unsigned long)dest;
76329+
76330+#ifdef CONFIG_PAX_KERNEXEC
76331+ if (shdr->sh_flags & SHF_EXECINSTR)
76332+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
76333+ else
76334+#endif
76335+
76336+ shdr->sh_addr = (unsigned long)dest;
76337 pr_debug("\t0x%lx %s\n",
76338 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
76339 }
76340@@ -2917,12 +3022,12 @@ static void flush_module_icache(const struct module *mod)
76341 * Do it before processing of module parameters, so the module
76342 * can provide parameter accessor functions of its own.
76343 */
76344- if (mod->module_init)
76345- flush_icache_range((unsigned long)mod->module_init,
76346- (unsigned long)mod->module_init
76347- + mod->init_size);
76348- flush_icache_range((unsigned long)mod->module_core,
76349- (unsigned long)mod->module_core + mod->core_size);
76350+ if (mod->module_init_rx)
76351+ flush_icache_range((unsigned long)mod->module_init_rx,
76352+ (unsigned long)mod->module_init_rx
76353+ + mod->init_size_rx);
76354+ flush_icache_range((unsigned long)mod->module_core_rx,
76355+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
76356
76357 set_fs(old_fs);
76358 }
76359@@ -2992,8 +3097,10 @@ out:
76360 static void module_deallocate(struct module *mod, struct load_info *info)
76361 {
76362 percpu_modfree(mod);
76363- module_free(mod, mod->module_init);
76364- module_free(mod, mod->module_core);
76365+ module_free_exec(mod, mod->module_init_rx);
76366+ module_free_exec(mod, mod->module_core_rx);
76367+ module_free(mod, mod->module_init_rw);
76368+ module_free(mod, mod->module_core_rw);
76369 }
76370
76371 int __weak module_finalize(const Elf_Ehdr *hdr,
76372@@ -3006,7 +3113,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
76373 static int post_relocation(struct module *mod, const struct load_info *info)
76374 {
76375 /* Sort exception table now relocations are done. */
76376+ pax_open_kernel();
76377 sort_extable(mod->extable, mod->extable + mod->num_exentries);
76378+ pax_close_kernel();
76379
76380 /* Copy relocated percpu area over. */
76381 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
76382@@ -3060,16 +3169,16 @@ static int do_init_module(struct module *mod)
76383 MODULE_STATE_COMING, mod);
76384
76385 /* Set RO and NX regions for core */
76386- set_section_ro_nx(mod->module_core,
76387- mod->core_text_size,
76388- mod->core_ro_size,
76389- mod->core_size);
76390+ set_section_ro_nx(mod->module_core_rx,
76391+ mod->core_size_rx,
76392+ mod->core_size_rx,
76393+ mod->core_size_rx);
76394
76395 /* Set RO and NX regions for init */
76396- set_section_ro_nx(mod->module_init,
76397- mod->init_text_size,
76398- mod->init_ro_size,
76399- mod->init_size);
76400+ set_section_ro_nx(mod->module_init_rx,
76401+ mod->init_size_rx,
76402+ mod->init_size_rx,
76403+ mod->init_size_rx);
76404
76405 do_mod_ctors(mod);
76406 /* Start the module */
76407@@ -3131,11 +3240,12 @@ static int do_init_module(struct module *mod)
76408 mod->strtab = mod->core_strtab;
76409 #endif
76410 unset_module_init_ro_nx(mod);
76411- module_free(mod, mod->module_init);
76412- mod->module_init = NULL;
76413- mod->init_size = 0;
76414- mod->init_ro_size = 0;
76415- mod->init_text_size = 0;
76416+ module_free(mod, mod->module_init_rw);
76417+ module_free_exec(mod, mod->module_init_rx);
76418+ mod->module_init_rw = NULL;
76419+ mod->module_init_rx = NULL;
76420+ mod->init_size_rw = 0;
76421+ mod->init_size_rx = 0;
76422 mutex_unlock(&module_mutex);
76423 wake_up_all(&module_wq);
76424
76425@@ -3262,9 +3372,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
76426 if (err)
76427 goto free_unload;
76428
76429+ /* Now copy in args */
76430+ mod->args = strndup_user(uargs, ~0UL >> 1);
76431+ if (IS_ERR(mod->args)) {
76432+ err = PTR_ERR(mod->args);
76433+ goto free_unload;
76434+ }
76435+
76436 /* Set up MODINFO_ATTR fields */
76437 setup_modinfo(mod, info);
76438
76439+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76440+ {
76441+ char *p, *p2;
76442+
76443+ if (strstr(mod->args, "grsec_modharden_netdev")) {
76444+ 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);
76445+ err = -EPERM;
76446+ goto free_modinfo;
76447+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
76448+ p += sizeof("grsec_modharden_normal") - 1;
76449+ p2 = strstr(p, "_");
76450+ if (p2) {
76451+ *p2 = '\0';
76452+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
76453+ *p2 = '_';
76454+ }
76455+ err = -EPERM;
76456+ goto free_modinfo;
76457+ }
76458+ }
76459+#endif
76460+
76461 /* Fix up syms, so that st_value is a pointer to location. */
76462 err = simplify_symbols(mod, info);
76463 if (err < 0)
76464@@ -3280,13 +3419,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
76465
76466 flush_module_icache(mod);
76467
76468- /* Now copy in args */
76469- mod->args = strndup_user(uargs, ~0UL >> 1);
76470- if (IS_ERR(mod->args)) {
76471- err = PTR_ERR(mod->args);
76472- goto free_arch_cleanup;
76473- }
76474-
76475 dynamic_debug_setup(info->debug, info->num_debug);
76476
76477 /* Finally it's fully formed, ready to start executing. */
76478@@ -3321,11 +3453,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
76479 ddebug_cleanup:
76480 dynamic_debug_remove(info->debug);
76481 synchronize_sched();
76482- kfree(mod->args);
76483- free_arch_cleanup:
76484 module_arch_cleanup(mod);
76485 free_modinfo:
76486 free_modinfo(mod);
76487+ kfree(mod->args);
76488 free_unload:
76489 module_unload_free(mod);
76490 unlink_mod:
76491@@ -3408,10 +3539,16 @@ static const char *get_ksymbol(struct module *mod,
76492 unsigned long nextval;
76493
76494 /* At worse, next value is at end of module */
76495- if (within_module_init(addr, mod))
76496- nextval = (unsigned long)mod->module_init+mod->init_text_size;
76497+ if (within_module_init_rx(addr, mod))
76498+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
76499+ else if (within_module_init_rw(addr, mod))
76500+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
76501+ else if (within_module_core_rx(addr, mod))
76502+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
76503+ else if (within_module_core_rw(addr, mod))
76504+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
76505 else
76506- nextval = (unsigned long)mod->module_core+mod->core_text_size;
76507+ return NULL;
76508
76509 /* Scan for closest preceding symbol, and next symbol. (ELF
76510 starts real symbols at 1). */
76511@@ -3664,7 +3801,7 @@ static int m_show(struct seq_file *m, void *p)
76512 return 0;
76513
76514 seq_printf(m, "%s %u",
76515- mod->name, mod->init_size + mod->core_size);
76516+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
76517 print_unload_info(m, mod);
76518
76519 /* Informative for users. */
76520@@ -3673,7 +3810,7 @@ static int m_show(struct seq_file *m, void *p)
76521 mod->state == MODULE_STATE_COMING ? "Loading":
76522 "Live");
76523 /* Used by oprofile and other similar tools. */
76524- seq_printf(m, " 0x%pK", mod->module_core);
76525+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
76526
76527 /* Taints info */
76528 if (mod->taints)
76529@@ -3709,7 +3846,17 @@ static const struct file_operations proc_modules_operations = {
76530
76531 static int __init proc_modules_init(void)
76532 {
76533+#ifndef CONFIG_GRKERNSEC_HIDESYM
76534+#ifdef CONFIG_GRKERNSEC_PROC_USER
76535+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
76536+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
76537+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
76538+#else
76539 proc_create("modules", 0, NULL, &proc_modules_operations);
76540+#endif
76541+#else
76542+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
76543+#endif
76544 return 0;
76545 }
76546 module_init(proc_modules_init);
76547@@ -3770,14 +3917,14 @@ struct module *__module_address(unsigned long addr)
76548 {
76549 struct module *mod;
76550
76551- if (addr < module_addr_min || addr > module_addr_max)
76552+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
76553+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
76554 return NULL;
76555
76556 list_for_each_entry_rcu(mod, &modules, list) {
76557 if (mod->state == MODULE_STATE_UNFORMED)
76558 continue;
76559- if (within_module_core(addr, mod)
76560- || within_module_init(addr, mod))
76561+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
76562 return mod;
76563 }
76564 return NULL;
76565@@ -3812,11 +3959,20 @@ bool is_module_text_address(unsigned long addr)
76566 */
76567 struct module *__module_text_address(unsigned long addr)
76568 {
76569- struct module *mod = __module_address(addr);
76570+ struct module *mod;
76571+
76572+#ifdef CONFIG_X86_32
76573+ addr = ktla_ktva(addr);
76574+#endif
76575+
76576+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
76577+ return NULL;
76578+
76579+ mod = __module_address(addr);
76580+
76581 if (mod) {
76582 /* Make sure it's within the text section. */
76583- if (!within(addr, mod->module_init, mod->init_text_size)
76584- && !within(addr, mod->module_core, mod->core_text_size))
76585+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
76586 mod = NULL;
76587 }
76588 return mod;
76589diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
76590index 7e3443f..b2a1e6b 100644
76591--- a/kernel/mutex-debug.c
76592+++ b/kernel/mutex-debug.c
76593@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
76594 }
76595
76596 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
76597- struct thread_info *ti)
76598+ struct task_struct *task)
76599 {
76600 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
76601
76602 /* Mark the current thread as blocked on the lock: */
76603- ti->task->blocked_on = waiter;
76604+ task->blocked_on = waiter;
76605 }
76606
76607 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
76608- struct thread_info *ti)
76609+ struct task_struct *task)
76610 {
76611 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
76612- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
76613- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
76614- ti->task->blocked_on = NULL;
76615+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
76616+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
76617+ task->blocked_on = NULL;
76618
76619 list_del_init(&waiter->list);
76620 waiter->task = NULL;
76621diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
76622index 0799fd3..d06ae3b 100644
76623--- a/kernel/mutex-debug.h
76624+++ b/kernel/mutex-debug.h
76625@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
76626 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
76627 extern void debug_mutex_add_waiter(struct mutex *lock,
76628 struct mutex_waiter *waiter,
76629- struct thread_info *ti);
76630+ struct task_struct *task);
76631 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
76632- struct thread_info *ti);
76633+ struct task_struct *task);
76634 extern void debug_mutex_unlock(struct mutex *lock);
76635 extern void debug_mutex_init(struct mutex *lock, const char *name,
76636 struct lock_class_key *key);
76637diff --git a/kernel/mutex.c b/kernel/mutex.c
76638index 52f2301..73f7528 100644
76639--- a/kernel/mutex.c
76640+++ b/kernel/mutex.c
76641@@ -199,7 +199,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
76642 spin_lock_mutex(&lock->wait_lock, flags);
76643
76644 debug_mutex_lock_common(lock, &waiter);
76645- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
76646+ debug_mutex_add_waiter(lock, &waiter, task);
76647
76648 /* add waiting tasks to the end of the waitqueue (FIFO): */
76649 list_add_tail(&waiter.list, &lock->wait_list);
76650@@ -228,8 +228,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
76651 * TASK_UNINTERRUPTIBLE case.)
76652 */
76653 if (unlikely(signal_pending_state(state, task))) {
76654- mutex_remove_waiter(lock, &waiter,
76655- task_thread_info(task));
76656+ mutex_remove_waiter(lock, &waiter, task);
76657 mutex_release(&lock->dep_map, 1, ip);
76658 spin_unlock_mutex(&lock->wait_lock, flags);
76659
76660@@ -248,7 +247,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
76661 done:
76662 lock_acquired(&lock->dep_map, ip);
76663 /* got the lock - rejoice! */
76664- mutex_remove_waiter(lock, &waiter, current_thread_info());
76665+ mutex_remove_waiter(lock, &waiter, task);
76666 mutex_set_owner(lock);
76667
76668 /* set it to 0 if there are no waiters left: */
76669diff --git a/kernel/notifier.c b/kernel/notifier.c
76670index 2d5cc4c..d9ea600 100644
76671--- a/kernel/notifier.c
76672+++ b/kernel/notifier.c
76673@@ -5,6 +5,7 @@
76674 #include <linux/rcupdate.h>
76675 #include <linux/vmalloc.h>
76676 #include <linux/reboot.h>
76677+#include <linux/mm.h>
76678
76679 /*
76680 * Notifier list for kernel code which wants to be called
76681@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
76682 while ((*nl) != NULL) {
76683 if (n->priority > (*nl)->priority)
76684 break;
76685- nl = &((*nl)->next);
76686+ nl = (struct notifier_block **)&((*nl)->next);
76687 }
76688- n->next = *nl;
76689+ pax_open_kernel();
76690+ *(const void **)&n->next = *nl;
76691 rcu_assign_pointer(*nl, n);
76692+ pax_close_kernel();
76693 return 0;
76694 }
76695
76696@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
76697 return 0;
76698 if (n->priority > (*nl)->priority)
76699 break;
76700- nl = &((*nl)->next);
76701+ nl = (struct notifier_block **)&((*nl)->next);
76702 }
76703- n->next = *nl;
76704+ pax_open_kernel();
76705+ *(const void **)&n->next = *nl;
76706 rcu_assign_pointer(*nl, n);
76707+ pax_close_kernel();
76708 return 0;
76709 }
76710
76711@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
76712 {
76713 while ((*nl) != NULL) {
76714 if ((*nl) == n) {
76715+ pax_open_kernel();
76716 rcu_assign_pointer(*nl, n->next);
76717+ pax_close_kernel();
76718 return 0;
76719 }
76720- nl = &((*nl)->next);
76721+ nl = (struct notifier_block **)&((*nl)->next);
76722 }
76723 return -ENOENT;
76724 }
76725diff --git a/kernel/panic.c b/kernel/panic.c
76726index 7c57cc9..28f1b3f 100644
76727--- a/kernel/panic.c
76728+++ b/kernel/panic.c
76729@@ -403,7 +403,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
76730 const char *board;
76731
76732 printk(KERN_WARNING "------------[ cut here ]------------\n");
76733- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
76734+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
76735 board = dmi_get_system_info(DMI_PRODUCT_NAME);
76736 if (board)
76737 printk(KERN_WARNING "Hardware name: %s\n", board);
76738@@ -459,7 +459,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
76739 */
76740 void __stack_chk_fail(void)
76741 {
76742- panic("stack-protector: Kernel stack is corrupted in: %p\n",
76743+ dump_stack();
76744+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
76745 __builtin_return_address(0));
76746 }
76747 EXPORT_SYMBOL(__stack_chk_fail);
76748diff --git a/kernel/pid.c b/kernel/pid.c
76749index 047dc62..418d74b 100644
76750--- a/kernel/pid.c
76751+++ b/kernel/pid.c
76752@@ -33,6 +33,7 @@
76753 #include <linux/rculist.h>
76754 #include <linux/bootmem.h>
76755 #include <linux/hash.h>
76756+#include <linux/security.h>
76757 #include <linux/pid_namespace.h>
76758 #include <linux/init_task.h>
76759 #include <linux/syscalls.h>
76760@@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
76761
76762 int pid_max = PID_MAX_DEFAULT;
76763
76764-#define RESERVED_PIDS 300
76765+#define RESERVED_PIDS 500
76766
76767 int pid_max_min = RESERVED_PIDS + 1;
76768 int pid_max_max = PID_MAX_LIMIT;
76769@@ -440,10 +441,18 @@ EXPORT_SYMBOL(pid_task);
76770 */
76771 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
76772 {
76773+ struct task_struct *task;
76774+
76775 rcu_lockdep_assert(rcu_read_lock_held(),
76776 "find_task_by_pid_ns() needs rcu_read_lock()"
76777 " protection");
76778- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
76779+
76780+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
76781+
76782+ if (gr_pid_is_chrooted(task))
76783+ return NULL;
76784+
76785+ return task;
76786 }
76787
76788 struct task_struct *find_task_by_vpid(pid_t vnr)
76789@@ -451,6 +460,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
76790 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
76791 }
76792
76793+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
76794+{
76795+ rcu_lockdep_assert(rcu_read_lock_held(),
76796+ "find_task_by_pid_ns() needs rcu_read_lock()"
76797+ " protection");
76798+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
76799+}
76800+
76801 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
76802 {
76803 struct pid *pid;
76804diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
76805index bea15bd..789f3d0 100644
76806--- a/kernel/pid_namespace.c
76807+++ b/kernel/pid_namespace.c
76808@@ -249,7 +249,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
76809 void __user *buffer, size_t *lenp, loff_t *ppos)
76810 {
76811 struct pid_namespace *pid_ns = task_active_pid_ns(current);
76812- struct ctl_table tmp = *table;
76813+ ctl_table_no_const tmp = *table;
76814
76815 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
76816 return -EPERM;
76817diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
76818index 8fd709c..542bf4b 100644
76819--- a/kernel/posix-cpu-timers.c
76820+++ b/kernel/posix-cpu-timers.c
76821@@ -1592,14 +1592,14 @@ struct k_clock clock_posix_cpu = {
76822
76823 static __init int init_posix_cpu_timers(void)
76824 {
76825- struct k_clock process = {
76826+ static struct k_clock process = {
76827 .clock_getres = process_cpu_clock_getres,
76828 .clock_get = process_cpu_clock_get,
76829 .timer_create = process_cpu_timer_create,
76830 .nsleep = process_cpu_nsleep,
76831 .nsleep_restart = process_cpu_nsleep_restart,
76832 };
76833- struct k_clock thread = {
76834+ static struct k_clock thread = {
76835 .clock_getres = thread_cpu_clock_getres,
76836 .clock_get = thread_cpu_clock_get,
76837 .timer_create = thread_cpu_timer_create,
76838diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
76839index 6edbb2c..334f085 100644
76840--- a/kernel/posix-timers.c
76841+++ b/kernel/posix-timers.c
76842@@ -43,6 +43,7 @@
76843 #include <linux/idr.h>
76844 #include <linux/posix-clock.h>
76845 #include <linux/posix-timers.h>
76846+#include <linux/grsecurity.h>
76847 #include <linux/syscalls.h>
76848 #include <linux/wait.h>
76849 #include <linux/workqueue.h>
76850@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
76851 * which we beg off on and pass to do_sys_settimeofday().
76852 */
76853
76854-static struct k_clock posix_clocks[MAX_CLOCKS];
76855+static struct k_clock *posix_clocks[MAX_CLOCKS];
76856
76857 /*
76858 * These ones are defined below.
76859@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
76860 */
76861 static __init int init_posix_timers(void)
76862 {
76863- struct k_clock clock_realtime = {
76864+ static struct k_clock clock_realtime = {
76865 .clock_getres = hrtimer_get_res,
76866 .clock_get = posix_clock_realtime_get,
76867 .clock_set = posix_clock_realtime_set,
76868@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
76869 .timer_get = common_timer_get,
76870 .timer_del = common_timer_del,
76871 };
76872- struct k_clock clock_monotonic = {
76873+ static struct k_clock clock_monotonic = {
76874 .clock_getres = hrtimer_get_res,
76875 .clock_get = posix_ktime_get_ts,
76876 .nsleep = common_nsleep,
76877@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
76878 .timer_get = common_timer_get,
76879 .timer_del = common_timer_del,
76880 };
76881- struct k_clock clock_monotonic_raw = {
76882+ static struct k_clock clock_monotonic_raw = {
76883 .clock_getres = hrtimer_get_res,
76884 .clock_get = posix_get_monotonic_raw,
76885 };
76886- struct k_clock clock_realtime_coarse = {
76887+ static struct k_clock clock_realtime_coarse = {
76888 .clock_getres = posix_get_coarse_res,
76889 .clock_get = posix_get_realtime_coarse,
76890 };
76891- struct k_clock clock_monotonic_coarse = {
76892+ static struct k_clock clock_monotonic_coarse = {
76893 .clock_getres = posix_get_coarse_res,
76894 .clock_get = posix_get_monotonic_coarse,
76895 };
76896- struct k_clock clock_boottime = {
76897+ static struct k_clock clock_boottime = {
76898 .clock_getres = hrtimer_get_res,
76899 .clock_get = posix_get_boottime,
76900 .nsleep = common_nsleep,
76901@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
76902 return;
76903 }
76904
76905- posix_clocks[clock_id] = *new_clock;
76906+ posix_clocks[clock_id] = new_clock;
76907 }
76908 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
76909
76910@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
76911 return (id & CLOCKFD_MASK) == CLOCKFD ?
76912 &clock_posix_dynamic : &clock_posix_cpu;
76913
76914- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
76915+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
76916 return NULL;
76917- return &posix_clocks[id];
76918+ return posix_clocks[id];
76919 }
76920
76921 static int common_timer_create(struct k_itimer *new_timer)
76922@@ -964,6 +965,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
76923 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
76924 return -EFAULT;
76925
76926+ /* only the CLOCK_REALTIME clock can be set, all other clocks
76927+ have their clock_set fptr set to a nosettime dummy function
76928+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
76929+ call common_clock_set, which calls do_sys_settimeofday, which
76930+ we hook
76931+ */
76932+
76933 return kc->clock_set(which_clock, &new_tp);
76934 }
76935
76936diff --git a/kernel/power/process.c b/kernel/power/process.c
76937index 98088e0..aaf95c0 100644
76938--- a/kernel/power/process.c
76939+++ b/kernel/power/process.c
76940@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
76941 u64 elapsed_csecs64;
76942 unsigned int elapsed_csecs;
76943 bool wakeup = false;
76944+ bool timedout = false;
76945
76946 do_gettimeofday(&start);
76947
76948@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
76949
76950 while (true) {
76951 todo = 0;
76952+ if (time_after(jiffies, end_time))
76953+ timedout = true;
76954 read_lock(&tasklist_lock);
76955 do_each_thread(g, p) {
76956 if (p == current || !freeze_task(p))
76957 continue;
76958
76959- if (!freezer_should_skip(p))
76960+ if (!freezer_should_skip(p)) {
76961 todo++;
76962+ if (timedout) {
76963+ printk(KERN_ERR "Task refusing to freeze:\n");
76964+ sched_show_task(p);
76965+ }
76966+ }
76967 } while_each_thread(g, p);
76968 read_unlock(&tasklist_lock);
76969
76970@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
76971 todo += wq_busy;
76972 }
76973
76974- if (!todo || time_after(jiffies, end_time))
76975+ if (!todo || timedout)
76976 break;
76977
76978 if (pm_wakeup_pending()) {
76979diff --git a/kernel/printk.c b/kernel/printk.c
76980index abbdd9e..f294251 100644
76981--- a/kernel/printk.c
76982+++ b/kernel/printk.c
76983@@ -615,11 +615,17 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
76984 return ret;
76985 }
76986
76987+static int check_syslog_permissions(int type, bool from_file);
76988+
76989 static int devkmsg_open(struct inode *inode, struct file *file)
76990 {
76991 struct devkmsg_user *user;
76992 int err;
76993
76994+ err = check_syslog_permissions(SYSLOG_ACTION_OPEN, SYSLOG_FROM_FILE);
76995+ if (err)
76996+ return err;
76997+
76998 /* write-only does not need any file context */
76999 if ((file->f_flags & O_ACCMODE) == O_WRONLY)
77000 return 0;
77001@@ -828,7 +834,7 @@ static int syslog_action_restricted(int type)
77002 if (dmesg_restrict)
77003 return 1;
77004 /* Unless restricted, we allow "read all" and "get buffer size" for everybody */
77005- return type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
77006+ return type != SYSLOG_ACTION_OPEN && type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
77007 }
77008
77009 static int check_syslog_permissions(int type, bool from_file)
77010@@ -840,6 +846,11 @@ static int check_syslog_permissions(int type, bool from_file)
77011 if (from_file && type != SYSLOG_ACTION_OPEN)
77012 return 0;
77013
77014+#ifdef CONFIG_GRKERNSEC_DMESG
77015+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
77016+ return -EPERM;
77017+#endif
77018+
77019 if (syslog_action_restricted(type)) {
77020 if (capable(CAP_SYSLOG))
77021 return 0;
77022diff --git a/kernel/profile.c b/kernel/profile.c
77023index dc3384e..0de5b49 100644
77024--- a/kernel/profile.c
77025+++ b/kernel/profile.c
77026@@ -37,7 +37,7 @@ struct profile_hit {
77027 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
77028 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
77029
77030-static atomic_t *prof_buffer;
77031+static atomic_unchecked_t *prof_buffer;
77032 static unsigned long prof_len, prof_shift;
77033
77034 int prof_on __read_mostly;
77035@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
77036 hits[i].pc = 0;
77037 continue;
77038 }
77039- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
77040+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
77041 hits[i].hits = hits[i].pc = 0;
77042 }
77043 }
77044@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
77045 * Add the current hit(s) and flush the write-queue out
77046 * to the global buffer:
77047 */
77048- atomic_add(nr_hits, &prof_buffer[pc]);
77049+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
77050 for (i = 0; i < NR_PROFILE_HIT; ++i) {
77051- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
77052+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
77053 hits[i].pc = hits[i].hits = 0;
77054 }
77055 out:
77056@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
77057 {
77058 unsigned long pc;
77059 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
77060- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
77061+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
77062 }
77063 #endif /* !CONFIG_SMP */
77064
77065@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
77066 return -EFAULT;
77067 buf++; p++; count--; read++;
77068 }
77069- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
77070+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
77071 if (copy_to_user(buf, (void *)pnt, count))
77072 return -EFAULT;
77073 read += count;
77074@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
77075 }
77076 #endif
77077 profile_discard_flip_buffers();
77078- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
77079+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
77080 return count;
77081 }
77082
77083diff --git a/kernel/ptrace.c b/kernel/ptrace.c
77084index acbd284..00bb0c9 100644
77085--- a/kernel/ptrace.c
77086+++ b/kernel/ptrace.c
77087@@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
77088 if (seize)
77089 flags |= PT_SEIZED;
77090 rcu_read_lock();
77091- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
77092+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
77093 flags |= PT_PTRACE_CAP;
77094 rcu_read_unlock();
77095 task->ptrace = flags;
77096@@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
77097 break;
77098 return -EIO;
77099 }
77100- if (copy_to_user(dst, buf, retval))
77101+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
77102 return -EFAULT;
77103 copied += retval;
77104 src += retval;
77105@@ -726,7 +726,7 @@ int ptrace_request(struct task_struct *child, long request,
77106 bool seized = child->ptrace & PT_SEIZED;
77107 int ret = -EIO;
77108 siginfo_t siginfo, *si;
77109- void __user *datavp = (void __user *) data;
77110+ void __user *datavp = (__force void __user *) data;
77111 unsigned long __user *datalp = datavp;
77112 unsigned long flags;
77113
77114@@ -928,14 +928,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
77115 goto out;
77116 }
77117
77118+ if (gr_handle_ptrace(child, request)) {
77119+ ret = -EPERM;
77120+ goto out_put_task_struct;
77121+ }
77122+
77123 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
77124 ret = ptrace_attach(child, request, addr, data);
77125 /*
77126 * Some architectures need to do book-keeping after
77127 * a ptrace attach.
77128 */
77129- if (!ret)
77130+ if (!ret) {
77131 arch_ptrace_attach(child);
77132+ gr_audit_ptrace(child);
77133+ }
77134 goto out_put_task_struct;
77135 }
77136
77137@@ -963,7 +970,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
77138 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
77139 if (copied != sizeof(tmp))
77140 return -EIO;
77141- return put_user(tmp, (unsigned long __user *)data);
77142+ return put_user(tmp, (__force unsigned long __user *)data);
77143 }
77144
77145 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
77146@@ -1057,7 +1064,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
77147 }
77148
77149 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77150- compat_long_t addr, compat_long_t data)
77151+ compat_ulong_t addr, compat_ulong_t data)
77152 {
77153 struct task_struct *child;
77154 long ret;
77155@@ -1073,14 +1080,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77156 goto out;
77157 }
77158
77159+ if (gr_handle_ptrace(child, request)) {
77160+ ret = -EPERM;
77161+ goto out_put_task_struct;
77162+ }
77163+
77164 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
77165 ret = ptrace_attach(child, request, addr, data);
77166 /*
77167 * Some architectures need to do book-keeping after
77168 * a ptrace attach.
77169 */
77170- if (!ret)
77171+ if (!ret) {
77172 arch_ptrace_attach(child);
77173+ gr_audit_ptrace(child);
77174+ }
77175 goto out_put_task_struct;
77176 }
77177
77178diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
77179index 48ab703..07561d4 100644
77180--- a/kernel/rcupdate.c
77181+++ b/kernel/rcupdate.c
77182@@ -439,10 +439,10 @@ int rcu_jiffies_till_stall_check(void)
77183 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
77184 */
77185 if (till_stall_check < 3) {
77186- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
77187+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
77188 till_stall_check = 3;
77189 } else if (till_stall_check > 300) {
77190- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
77191+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
77192 till_stall_check = 300;
77193 }
77194 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
77195diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
77196index a0714a5..2ab5e34 100644
77197--- a/kernel/rcutiny.c
77198+++ b/kernel/rcutiny.c
77199@@ -46,7 +46,7 @@
77200 struct rcu_ctrlblk;
77201 static void invoke_rcu_callbacks(void);
77202 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
77203-static void rcu_process_callbacks(struct softirq_action *unused);
77204+static void rcu_process_callbacks(void);
77205 static void __call_rcu(struct rcu_head *head,
77206 void (*func)(struct rcu_head *rcu),
77207 struct rcu_ctrlblk *rcp);
77208@@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
77209 rcu_is_callbacks_kthread()));
77210 }
77211
77212-static void rcu_process_callbacks(struct softirq_action *unused)
77213+static void rcu_process_callbacks(void)
77214 {
77215 __rcu_process_callbacks(&rcu_sched_ctrlblk);
77216 __rcu_process_callbacks(&rcu_bh_ctrlblk);
77217diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
77218index 8a23300..4255818 100644
77219--- a/kernel/rcutiny_plugin.h
77220+++ b/kernel/rcutiny_plugin.h
77221@@ -945,7 +945,7 @@ static int rcu_kthread(void *arg)
77222 have_rcu_kthread_work = morework;
77223 local_irq_restore(flags);
77224 if (work)
77225- rcu_process_callbacks(NULL);
77226+ rcu_process_callbacks();
77227 schedule_timeout_interruptible(1); /* Leave CPU for others. */
77228 }
77229
77230diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
77231index e1f3a8c..42c94a2 100644
77232--- a/kernel/rcutorture.c
77233+++ b/kernel/rcutorture.c
77234@@ -164,12 +164,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
77235 { 0 };
77236 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
77237 { 0 };
77238-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
77239-static atomic_t n_rcu_torture_alloc;
77240-static atomic_t n_rcu_torture_alloc_fail;
77241-static atomic_t n_rcu_torture_free;
77242-static atomic_t n_rcu_torture_mberror;
77243-static atomic_t n_rcu_torture_error;
77244+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
77245+static atomic_unchecked_t n_rcu_torture_alloc;
77246+static atomic_unchecked_t n_rcu_torture_alloc_fail;
77247+static atomic_unchecked_t n_rcu_torture_free;
77248+static atomic_unchecked_t n_rcu_torture_mberror;
77249+static atomic_unchecked_t n_rcu_torture_error;
77250 static long n_rcu_torture_barrier_error;
77251 static long n_rcu_torture_boost_ktrerror;
77252 static long n_rcu_torture_boost_rterror;
77253@@ -287,11 +287,11 @@ rcu_torture_alloc(void)
77254
77255 spin_lock_bh(&rcu_torture_lock);
77256 if (list_empty(&rcu_torture_freelist)) {
77257- atomic_inc(&n_rcu_torture_alloc_fail);
77258+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
77259 spin_unlock_bh(&rcu_torture_lock);
77260 return NULL;
77261 }
77262- atomic_inc(&n_rcu_torture_alloc);
77263+ atomic_inc_unchecked(&n_rcu_torture_alloc);
77264 p = rcu_torture_freelist.next;
77265 list_del_init(p);
77266 spin_unlock_bh(&rcu_torture_lock);
77267@@ -304,7 +304,7 @@ rcu_torture_alloc(void)
77268 static void
77269 rcu_torture_free(struct rcu_torture *p)
77270 {
77271- atomic_inc(&n_rcu_torture_free);
77272+ atomic_inc_unchecked(&n_rcu_torture_free);
77273 spin_lock_bh(&rcu_torture_lock);
77274 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
77275 spin_unlock_bh(&rcu_torture_lock);
77276@@ -424,7 +424,7 @@ rcu_torture_cb(struct rcu_head *p)
77277 i = rp->rtort_pipe_count;
77278 if (i > RCU_TORTURE_PIPE_LEN)
77279 i = RCU_TORTURE_PIPE_LEN;
77280- atomic_inc(&rcu_torture_wcount[i]);
77281+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
77282 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
77283 rp->rtort_mbtest = 0;
77284 rcu_torture_free(rp);
77285@@ -472,7 +472,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
77286 i = rp->rtort_pipe_count;
77287 if (i > RCU_TORTURE_PIPE_LEN)
77288 i = RCU_TORTURE_PIPE_LEN;
77289- atomic_inc(&rcu_torture_wcount[i]);
77290+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
77291 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
77292 rp->rtort_mbtest = 0;
77293 list_del(&rp->rtort_free);
77294@@ -990,7 +990,7 @@ rcu_torture_writer(void *arg)
77295 i = old_rp->rtort_pipe_count;
77296 if (i > RCU_TORTURE_PIPE_LEN)
77297 i = RCU_TORTURE_PIPE_LEN;
77298- atomic_inc(&rcu_torture_wcount[i]);
77299+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
77300 old_rp->rtort_pipe_count++;
77301 cur_ops->deferred_free(old_rp);
77302 }
77303@@ -1076,7 +1076,7 @@ static void rcu_torture_timer(unsigned long unused)
77304 return;
77305 }
77306 if (p->rtort_mbtest == 0)
77307- atomic_inc(&n_rcu_torture_mberror);
77308+ atomic_inc_unchecked(&n_rcu_torture_mberror);
77309 spin_lock(&rand_lock);
77310 cur_ops->read_delay(&rand);
77311 n_rcu_torture_timers++;
77312@@ -1146,7 +1146,7 @@ rcu_torture_reader(void *arg)
77313 continue;
77314 }
77315 if (p->rtort_mbtest == 0)
77316- atomic_inc(&n_rcu_torture_mberror);
77317+ atomic_inc_unchecked(&n_rcu_torture_mberror);
77318 cur_ops->read_delay(&rand);
77319 preempt_disable();
77320 pipe_count = p->rtort_pipe_count;
77321@@ -1209,11 +1209,11 @@ rcu_torture_printk(char *page)
77322 rcu_torture_current,
77323 rcu_torture_current_version,
77324 list_empty(&rcu_torture_freelist),
77325- atomic_read(&n_rcu_torture_alloc),
77326- atomic_read(&n_rcu_torture_alloc_fail),
77327- atomic_read(&n_rcu_torture_free));
77328+ atomic_read_unchecked(&n_rcu_torture_alloc),
77329+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
77330+ atomic_read_unchecked(&n_rcu_torture_free));
77331 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
77332- atomic_read(&n_rcu_torture_mberror),
77333+ atomic_read_unchecked(&n_rcu_torture_mberror),
77334 n_rcu_torture_boost_ktrerror,
77335 n_rcu_torture_boost_rterror);
77336 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
77337@@ -1232,14 +1232,14 @@ rcu_torture_printk(char *page)
77338 n_barrier_attempts,
77339 n_rcu_torture_barrier_error);
77340 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
77341- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
77342+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
77343 n_rcu_torture_barrier_error != 0 ||
77344 n_rcu_torture_boost_ktrerror != 0 ||
77345 n_rcu_torture_boost_rterror != 0 ||
77346 n_rcu_torture_boost_failure != 0 ||
77347 i > 1) {
77348 cnt += sprintf(&page[cnt], "!!! ");
77349- atomic_inc(&n_rcu_torture_error);
77350+ atomic_inc_unchecked(&n_rcu_torture_error);
77351 WARN_ON_ONCE(1);
77352 }
77353 cnt += sprintf(&page[cnt], "Reader Pipe: ");
77354@@ -1253,7 +1253,7 @@ rcu_torture_printk(char *page)
77355 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
77356 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
77357 cnt += sprintf(&page[cnt], " %d",
77358- atomic_read(&rcu_torture_wcount[i]));
77359+ atomic_read_unchecked(&rcu_torture_wcount[i]));
77360 }
77361 cnt += sprintf(&page[cnt], "\n");
77362 if (cur_ops->stats)
77363@@ -1962,7 +1962,7 @@ rcu_torture_cleanup(void)
77364
77365 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
77366
77367- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
77368+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
77369 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
77370 else if (n_online_successes != n_online_attempts ||
77371 n_offline_successes != n_offline_attempts)
77372@@ -2031,18 +2031,18 @@ rcu_torture_init(void)
77373
77374 rcu_torture_current = NULL;
77375 rcu_torture_current_version = 0;
77376- atomic_set(&n_rcu_torture_alloc, 0);
77377- atomic_set(&n_rcu_torture_alloc_fail, 0);
77378- atomic_set(&n_rcu_torture_free, 0);
77379- atomic_set(&n_rcu_torture_mberror, 0);
77380- atomic_set(&n_rcu_torture_error, 0);
77381+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
77382+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
77383+ atomic_set_unchecked(&n_rcu_torture_free, 0);
77384+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
77385+ atomic_set_unchecked(&n_rcu_torture_error, 0);
77386 n_rcu_torture_barrier_error = 0;
77387 n_rcu_torture_boost_ktrerror = 0;
77388 n_rcu_torture_boost_rterror = 0;
77389 n_rcu_torture_boost_failure = 0;
77390 n_rcu_torture_boosts = 0;
77391 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
77392- atomic_set(&rcu_torture_wcount[i], 0);
77393+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
77394 for_each_possible_cpu(cpu) {
77395 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
77396 per_cpu(rcu_torture_count, cpu)[i] = 0;
77397diff --git a/kernel/rcutree.c b/kernel/rcutree.c
77398index 5b8ad82..17274d1 100644
77399--- a/kernel/rcutree.c
77400+++ b/kernel/rcutree.c
77401@@ -353,9 +353,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
77402 rcu_prepare_for_idle(smp_processor_id());
77403 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
77404 smp_mb__before_atomic_inc(); /* See above. */
77405- atomic_inc(&rdtp->dynticks);
77406+ atomic_inc_unchecked(&rdtp->dynticks);
77407 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
77408- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
77409+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
77410
77411 /*
77412 * It is illegal to enter an extended quiescent state while
77413@@ -491,10 +491,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
77414 int user)
77415 {
77416 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
77417- atomic_inc(&rdtp->dynticks);
77418+ atomic_inc_unchecked(&rdtp->dynticks);
77419 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
77420 smp_mb__after_atomic_inc(); /* See above. */
77421- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
77422+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
77423 rcu_cleanup_after_idle(smp_processor_id());
77424 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
77425 if (!user && !is_idle_task(current)) {
77426@@ -633,14 +633,14 @@ void rcu_nmi_enter(void)
77427 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
77428
77429 if (rdtp->dynticks_nmi_nesting == 0 &&
77430- (atomic_read(&rdtp->dynticks) & 0x1))
77431+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
77432 return;
77433 rdtp->dynticks_nmi_nesting++;
77434 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
77435- atomic_inc(&rdtp->dynticks);
77436+ atomic_inc_unchecked(&rdtp->dynticks);
77437 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
77438 smp_mb__after_atomic_inc(); /* See above. */
77439- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
77440+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
77441 }
77442
77443 /**
77444@@ -659,9 +659,9 @@ void rcu_nmi_exit(void)
77445 return;
77446 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
77447 smp_mb__before_atomic_inc(); /* See above. */
77448- atomic_inc(&rdtp->dynticks);
77449+ atomic_inc_unchecked(&rdtp->dynticks);
77450 smp_mb__after_atomic_inc(); /* Force delay to next write. */
77451- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
77452+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
77453 }
77454
77455 /**
77456@@ -675,7 +675,7 @@ int rcu_is_cpu_idle(void)
77457 int ret;
77458
77459 preempt_disable();
77460- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
77461+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
77462 preempt_enable();
77463 return ret;
77464 }
77465@@ -743,7 +743,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
77466 */
77467 static int dyntick_save_progress_counter(struct rcu_data *rdp)
77468 {
77469- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
77470+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
77471 return (rdp->dynticks_snap & 0x1) == 0;
77472 }
77473
77474@@ -758,7 +758,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
77475 unsigned int curr;
77476 unsigned int snap;
77477
77478- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
77479+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
77480 snap = (unsigned int)rdp->dynticks_snap;
77481
77482 /*
77483@@ -1698,7 +1698,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
77484 rsp->qlen += rdp->qlen;
77485 rdp->n_cbs_orphaned += rdp->qlen;
77486 rdp->qlen_lazy = 0;
77487- ACCESS_ONCE(rdp->qlen) = 0;
77488+ ACCESS_ONCE_RW(rdp->qlen) = 0;
77489 }
77490
77491 /*
77492@@ -1944,7 +1944,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
77493 }
77494 smp_mb(); /* List handling before counting for rcu_barrier(). */
77495 rdp->qlen_lazy -= count_lazy;
77496- ACCESS_ONCE(rdp->qlen) -= count;
77497+ ACCESS_ONCE_RW(rdp->qlen) -= count;
77498 rdp->n_cbs_invoked += count;
77499
77500 /* Reinstate batch limit if we have worked down the excess. */
77501@@ -2137,7 +2137,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
77502 /*
77503 * Do RCU core processing for the current CPU.
77504 */
77505-static void rcu_process_callbacks(struct softirq_action *unused)
77506+static void rcu_process_callbacks(void)
77507 {
77508 struct rcu_state *rsp;
77509
77510@@ -2260,7 +2260,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
77511 local_irq_restore(flags);
77512 return;
77513 }
77514- ACCESS_ONCE(rdp->qlen)++;
77515+ ACCESS_ONCE_RW(rdp->qlen)++;
77516 if (lazy)
77517 rdp->qlen_lazy++;
77518 else
77519@@ -2469,11 +2469,11 @@ void synchronize_sched_expedited(void)
77520 * counter wrap on a 32-bit system. Quite a few more CPUs would of
77521 * course be required on a 64-bit system.
77522 */
77523- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
77524+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
77525 (ulong)atomic_long_read(&rsp->expedited_done) +
77526 ULONG_MAX / 8)) {
77527 synchronize_sched();
77528- atomic_long_inc(&rsp->expedited_wrap);
77529+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
77530 return;
77531 }
77532
77533@@ -2481,7 +2481,7 @@ void synchronize_sched_expedited(void)
77534 * Take a ticket. Note that atomic_inc_return() implies a
77535 * full memory barrier.
77536 */
77537- snap = atomic_long_inc_return(&rsp->expedited_start);
77538+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
77539 firstsnap = snap;
77540 get_online_cpus();
77541 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
77542@@ -2494,14 +2494,14 @@ void synchronize_sched_expedited(void)
77543 synchronize_sched_expedited_cpu_stop,
77544 NULL) == -EAGAIN) {
77545 put_online_cpus();
77546- atomic_long_inc(&rsp->expedited_tryfail);
77547+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
77548
77549 /* Check to see if someone else did our work for us. */
77550 s = atomic_long_read(&rsp->expedited_done);
77551 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
77552 /* ensure test happens before caller kfree */
77553 smp_mb__before_atomic_inc(); /* ^^^ */
77554- atomic_long_inc(&rsp->expedited_workdone1);
77555+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
77556 return;
77557 }
77558
77559@@ -2510,7 +2510,7 @@ void synchronize_sched_expedited(void)
77560 udelay(trycount * num_online_cpus());
77561 } else {
77562 wait_rcu_gp(call_rcu_sched);
77563- atomic_long_inc(&rsp->expedited_normal);
77564+ atomic_long_inc_unchecked(&rsp->expedited_normal);
77565 return;
77566 }
77567
77568@@ -2519,7 +2519,7 @@ void synchronize_sched_expedited(void)
77569 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
77570 /* ensure test happens before caller kfree */
77571 smp_mb__before_atomic_inc(); /* ^^^ */
77572- atomic_long_inc(&rsp->expedited_workdone2);
77573+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
77574 return;
77575 }
77576
77577@@ -2531,10 +2531,10 @@ void synchronize_sched_expedited(void)
77578 * period works for us.
77579 */
77580 get_online_cpus();
77581- snap = atomic_long_read(&rsp->expedited_start);
77582+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
77583 smp_mb(); /* ensure read is before try_stop_cpus(). */
77584 }
77585- atomic_long_inc(&rsp->expedited_stoppedcpus);
77586+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
77587
77588 /*
77589 * Everyone up to our most recent fetch is covered by our grace
77590@@ -2543,16 +2543,16 @@ void synchronize_sched_expedited(void)
77591 * than we did already did their update.
77592 */
77593 do {
77594- atomic_long_inc(&rsp->expedited_done_tries);
77595+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
77596 s = atomic_long_read(&rsp->expedited_done);
77597 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
77598 /* ensure test happens before caller kfree */
77599 smp_mb__before_atomic_inc(); /* ^^^ */
77600- atomic_long_inc(&rsp->expedited_done_lost);
77601+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
77602 break;
77603 }
77604 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
77605- atomic_long_inc(&rsp->expedited_done_exit);
77606+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
77607
77608 put_online_cpus();
77609 }
77610@@ -2726,7 +2726,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
77611 * ACCESS_ONCE() to prevent the compiler from speculating
77612 * the increment to precede the early-exit check.
77613 */
77614- ACCESS_ONCE(rsp->n_barrier_done)++;
77615+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
77616 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
77617 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
77618 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
77619@@ -2776,7 +2776,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
77620
77621 /* Increment ->n_barrier_done to prevent duplicate work. */
77622 smp_mb(); /* Keep increment after above mechanism. */
77623- ACCESS_ONCE(rsp->n_barrier_done)++;
77624+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
77625 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
77626 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
77627 smp_mb(); /* Keep increment before caller's subsequent code. */
77628@@ -2821,10 +2821,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
77629 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
77630 init_callback_list(rdp);
77631 rdp->qlen_lazy = 0;
77632- ACCESS_ONCE(rdp->qlen) = 0;
77633+ ACCESS_ONCE_RW(rdp->qlen) = 0;
77634 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
77635 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
77636- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
77637+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
77638 rdp->cpu = cpu;
77639 rdp->rsp = rsp;
77640 rcu_boot_init_nocb_percpu_data(rdp);
77641@@ -2857,8 +2857,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
77642 rdp->blimit = blimit;
77643 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
77644 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
77645- atomic_set(&rdp->dynticks->dynticks,
77646- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
77647+ atomic_set_unchecked(&rdp->dynticks->dynticks,
77648+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
77649 rcu_prepare_for_idle_init(cpu);
77650 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
77651
77652diff --git a/kernel/rcutree.h b/kernel/rcutree.h
77653index c896b50..c357252 100644
77654--- a/kernel/rcutree.h
77655+++ b/kernel/rcutree.h
77656@@ -86,7 +86,7 @@ struct rcu_dynticks {
77657 long long dynticks_nesting; /* Track irq/process nesting level. */
77658 /* Process level is worth LLONG_MAX/2. */
77659 int dynticks_nmi_nesting; /* Track NMI nesting level. */
77660- atomic_t dynticks; /* Even value for idle, else odd. */
77661+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
77662 #ifdef CONFIG_RCU_FAST_NO_HZ
77663 int dyntick_drain; /* Prepare-for-idle state variable. */
77664 unsigned long dyntick_holdoff;
77665@@ -416,17 +416,17 @@ struct rcu_state {
77666 /* _rcu_barrier(). */
77667 /* End of fields guarded by barrier_mutex. */
77668
77669- atomic_long_t expedited_start; /* Starting ticket. */
77670- atomic_long_t expedited_done; /* Done ticket. */
77671- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
77672- atomic_long_t expedited_tryfail; /* # acquisition failures. */
77673- atomic_long_t expedited_workdone1; /* # done by others #1. */
77674- atomic_long_t expedited_workdone2; /* # done by others #2. */
77675- atomic_long_t expedited_normal; /* # fallbacks to normal. */
77676- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
77677- atomic_long_t expedited_done_tries; /* # tries to update _done. */
77678- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
77679- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
77680+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
77681+ atomic_long_t expedited_done; /* Done ticket. */
77682+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
77683+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
77684+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
77685+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
77686+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
77687+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
77688+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
77689+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
77690+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
77691
77692 unsigned long jiffies_force_qs; /* Time at which to invoke */
77693 /* force_quiescent_state(). */
77694diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
77695index c1cc7e1..f62e436 100644
77696--- a/kernel/rcutree_plugin.h
77697+++ b/kernel/rcutree_plugin.h
77698@@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
77699
77700 /* Clean up and exit. */
77701 smp_mb(); /* ensure expedited GP seen before counter increment. */
77702- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
77703+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
77704 unlock_mb_ret:
77705 mutex_unlock(&sync_rcu_preempt_exp_mutex);
77706 mb_ret:
77707@@ -1440,7 +1440,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
77708 free_cpumask_var(cm);
77709 }
77710
77711-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
77712+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
77713 .store = &rcu_cpu_kthread_task,
77714 .thread_should_run = rcu_cpu_kthread_should_run,
77715 .thread_fn = rcu_cpu_kthread,
77716@@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
77717 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
77718 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
77719 cpu, ticks_value, ticks_title,
77720- atomic_read(&rdtp->dynticks) & 0xfff,
77721+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
77722 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
77723 fast_no_hz);
77724 }
77725@@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
77726
77727 /* Enqueue the callback on the nocb list and update counts. */
77728 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
77729- ACCESS_ONCE(*old_rhpp) = rhp;
77730+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
77731 atomic_long_add(rhcount, &rdp->nocb_q_count);
77732 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
77733
77734@@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
77735 * Extract queued callbacks, update counts, and wait
77736 * for a grace period to elapse.
77737 */
77738- ACCESS_ONCE(rdp->nocb_head) = NULL;
77739+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
77740 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
77741 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
77742 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
77743- ACCESS_ONCE(rdp->nocb_p_count) += c;
77744- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
77745+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
77746+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
77747 wait_rcu_gp(rdp->rsp->call_remote);
77748
77749 /* Each pass through the following loop invokes a callback. */
77750@@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
77751 list = next;
77752 }
77753 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
77754- ACCESS_ONCE(rdp->nocb_p_count) -= c;
77755- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
77756+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
77757+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
77758 rdp->n_nocbs_invoked += c;
77759 }
77760 return 0;
77761@@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
77762 rdp = per_cpu_ptr(rsp->rda, cpu);
77763 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
77764 BUG_ON(IS_ERR(t));
77765- ACCESS_ONCE(rdp->nocb_kthread) = t;
77766+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
77767 }
77768 }
77769
77770diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
77771index 93f8e8f..cf812ae 100644
77772--- a/kernel/rcutree_trace.c
77773+++ b/kernel/rcutree_trace.c
77774@@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
77775 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
77776 rdp->passed_quiesce, rdp->qs_pending);
77777 seq_printf(m, " dt=%d/%llx/%d df=%lu",
77778- atomic_read(&rdp->dynticks->dynticks),
77779+ atomic_read_unchecked(&rdp->dynticks->dynticks),
77780 rdp->dynticks->dynticks_nesting,
77781 rdp->dynticks->dynticks_nmi_nesting,
77782 rdp->dynticks_fqs);
77783@@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
77784 struct rcu_state *rsp = (struct rcu_state *)m->private;
77785
77786 seq_printf(m, "s=%lu d=%lu w=%lu tf=%lu wd1=%lu wd2=%lu n=%lu sc=%lu dt=%lu dl=%lu dx=%lu\n",
77787- atomic_long_read(&rsp->expedited_start),
77788+ atomic_long_read_unchecked(&rsp->expedited_start),
77789 atomic_long_read(&rsp->expedited_done),
77790- atomic_long_read(&rsp->expedited_wrap),
77791- atomic_long_read(&rsp->expedited_tryfail),
77792- atomic_long_read(&rsp->expedited_workdone1),
77793- atomic_long_read(&rsp->expedited_workdone2),
77794- atomic_long_read(&rsp->expedited_normal),
77795- atomic_long_read(&rsp->expedited_stoppedcpus),
77796- atomic_long_read(&rsp->expedited_done_tries),
77797- atomic_long_read(&rsp->expedited_done_lost),
77798- atomic_long_read(&rsp->expedited_done_exit));
77799+ atomic_long_read_unchecked(&rsp->expedited_wrap),
77800+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
77801+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
77802+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
77803+ atomic_long_read_unchecked(&rsp->expedited_normal),
77804+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
77805+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
77806+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
77807+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
77808 return 0;
77809 }
77810
77811diff --git a/kernel/resource.c b/kernel/resource.c
77812index 73f35d4..4684fc4 100644
77813--- a/kernel/resource.c
77814+++ b/kernel/resource.c
77815@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
77816
77817 static int __init ioresources_init(void)
77818 {
77819+#ifdef CONFIG_GRKERNSEC_PROC_ADD
77820+#ifdef CONFIG_GRKERNSEC_PROC_USER
77821+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
77822+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
77823+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77824+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
77825+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
77826+#endif
77827+#else
77828 proc_create("ioports", 0, NULL, &proc_ioports_operations);
77829 proc_create("iomem", 0, NULL, &proc_iomem_operations);
77830+#endif
77831 return 0;
77832 }
77833 __initcall(ioresources_init);
77834diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
77835index 7890b10..8b68605f 100644
77836--- a/kernel/rtmutex-tester.c
77837+++ b/kernel/rtmutex-tester.c
77838@@ -21,7 +21,7 @@
77839 #define MAX_RT_TEST_MUTEXES 8
77840
77841 static spinlock_t rttest_lock;
77842-static atomic_t rttest_event;
77843+static atomic_unchecked_t rttest_event;
77844
77845 struct test_thread_data {
77846 int opcode;
77847@@ -62,7 +62,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77848
77849 case RTTEST_LOCKCONT:
77850 td->mutexes[td->opdata] = 1;
77851- td->event = atomic_add_return(1, &rttest_event);
77852+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77853 return 0;
77854
77855 case RTTEST_RESET:
77856@@ -75,7 +75,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77857 return 0;
77858
77859 case RTTEST_RESETEVENT:
77860- atomic_set(&rttest_event, 0);
77861+ atomic_set_unchecked(&rttest_event, 0);
77862 return 0;
77863
77864 default:
77865@@ -92,9 +92,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77866 return ret;
77867
77868 td->mutexes[id] = 1;
77869- td->event = atomic_add_return(1, &rttest_event);
77870+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77871 rt_mutex_lock(&mutexes[id]);
77872- td->event = atomic_add_return(1, &rttest_event);
77873+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77874 td->mutexes[id] = 4;
77875 return 0;
77876
77877@@ -105,9 +105,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77878 return ret;
77879
77880 td->mutexes[id] = 1;
77881- td->event = atomic_add_return(1, &rttest_event);
77882+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77883 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
77884- td->event = atomic_add_return(1, &rttest_event);
77885+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77886 td->mutexes[id] = ret ? 0 : 4;
77887 return ret ? -EINTR : 0;
77888
77889@@ -116,9 +116,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
77890 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
77891 return ret;
77892
77893- td->event = atomic_add_return(1, &rttest_event);
77894+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77895 rt_mutex_unlock(&mutexes[id]);
77896- td->event = atomic_add_return(1, &rttest_event);
77897+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77898 td->mutexes[id] = 0;
77899 return 0;
77900
77901@@ -165,7 +165,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
77902 break;
77903
77904 td->mutexes[dat] = 2;
77905- td->event = atomic_add_return(1, &rttest_event);
77906+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77907 break;
77908
77909 default:
77910@@ -185,7 +185,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
77911 return;
77912
77913 td->mutexes[dat] = 3;
77914- td->event = atomic_add_return(1, &rttest_event);
77915+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77916 break;
77917
77918 case RTTEST_LOCKNOWAIT:
77919@@ -197,7 +197,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
77920 return;
77921
77922 td->mutexes[dat] = 1;
77923- td->event = atomic_add_return(1, &rttest_event);
77924+ td->event = atomic_add_return_unchecked(1, &rttest_event);
77925 return;
77926
77927 default:
77928diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
77929index 64de5f8..7735e12 100644
77930--- a/kernel/sched/auto_group.c
77931+++ b/kernel/sched/auto_group.c
77932@@ -11,7 +11,7 @@
77933
77934 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
77935 static struct autogroup autogroup_default;
77936-static atomic_t autogroup_seq_nr;
77937+static atomic_unchecked_t autogroup_seq_nr;
77938
77939 void __init autogroup_init(struct task_struct *init_task)
77940 {
77941@@ -81,7 +81,7 @@ static inline struct autogroup *autogroup_create(void)
77942
77943 kref_init(&ag->kref);
77944 init_rwsem(&ag->lock);
77945- ag->id = atomic_inc_return(&autogroup_seq_nr);
77946+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
77947 ag->tg = tg;
77948 #ifdef CONFIG_RT_GROUP_SCHED
77949 /*
77950diff --git a/kernel/sched/core.c b/kernel/sched/core.c
77951index 67d0465..4cf9361 100644
77952--- a/kernel/sched/core.c
77953+++ b/kernel/sched/core.c
77954@@ -3406,7 +3406,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
77955 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
77956 * positive (at least 1, or number of jiffies left till timeout) if completed.
77957 */
77958-long __sched
77959+long __sched __intentional_overflow(-1)
77960 wait_for_completion_interruptible_timeout(struct completion *x,
77961 unsigned long timeout)
77962 {
77963@@ -3423,7 +3423,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
77964 *
77965 * The return value is -ERESTARTSYS if interrupted, 0 if completed.
77966 */
77967-int __sched wait_for_completion_killable(struct completion *x)
77968+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
77969 {
77970 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
77971 if (t == -ERESTARTSYS)
77972@@ -3444,7 +3444,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
77973 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
77974 * positive (at least 1, or number of jiffies left till timeout) if completed.
77975 */
77976-long __sched
77977+long __sched __intentional_overflow(-1)
77978 wait_for_completion_killable_timeout(struct completion *x,
77979 unsigned long timeout)
77980 {
77981@@ -3670,6 +3670,8 @@ int can_nice(const struct task_struct *p, const int nice)
77982 /* convert nice value [19,-20] to rlimit style value [1,40] */
77983 int nice_rlim = 20 - nice;
77984
77985+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
77986+
77987 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
77988 capable(CAP_SYS_NICE));
77989 }
77990@@ -3703,7 +3705,8 @@ SYSCALL_DEFINE1(nice, int, increment)
77991 if (nice > 19)
77992 nice = 19;
77993
77994- if (increment < 0 && !can_nice(current, nice))
77995+ if (increment < 0 && (!can_nice(current, nice) ||
77996+ gr_handle_chroot_nice()))
77997 return -EPERM;
77998
77999 retval = security_task_setnice(current, nice);
78000@@ -3857,6 +3860,7 @@ recheck:
78001 unsigned long rlim_rtprio =
78002 task_rlimit(p, RLIMIT_RTPRIO);
78003
78004+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
78005 /* can't set/change the rt policy */
78006 if (policy != p->policy && !rlim_rtprio)
78007 return -EPERM;
78008@@ -4954,7 +4958,7 @@ static void migrate_tasks(unsigned int dead_cpu)
78009
78010 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
78011
78012-static struct ctl_table sd_ctl_dir[] = {
78013+static ctl_table_no_const sd_ctl_dir[] __read_only = {
78014 {
78015 .procname = "sched_domain",
78016 .mode = 0555,
78017@@ -4971,17 +4975,17 @@ static struct ctl_table sd_ctl_root[] = {
78018 {}
78019 };
78020
78021-static struct ctl_table *sd_alloc_ctl_entry(int n)
78022+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
78023 {
78024- struct ctl_table *entry =
78025+ ctl_table_no_const *entry =
78026 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
78027
78028 return entry;
78029 }
78030
78031-static void sd_free_ctl_entry(struct ctl_table **tablep)
78032+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
78033 {
78034- struct ctl_table *entry;
78035+ ctl_table_no_const *entry;
78036
78037 /*
78038 * In the intermediate directories, both the child directory and
78039@@ -4989,22 +4993,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
78040 * will always be set. In the lowest directory the names are
78041 * static strings and all have proc handlers.
78042 */
78043- for (entry = *tablep; entry->mode; entry++) {
78044- if (entry->child)
78045- sd_free_ctl_entry(&entry->child);
78046+ for (entry = tablep; entry->mode; entry++) {
78047+ if (entry->child) {
78048+ sd_free_ctl_entry(entry->child);
78049+ pax_open_kernel();
78050+ entry->child = NULL;
78051+ pax_close_kernel();
78052+ }
78053 if (entry->proc_handler == NULL)
78054 kfree(entry->procname);
78055 }
78056
78057- kfree(*tablep);
78058- *tablep = NULL;
78059+ kfree(tablep);
78060 }
78061
78062 static int min_load_idx = 0;
78063 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
78064
78065 static void
78066-set_table_entry(struct ctl_table *entry,
78067+set_table_entry(ctl_table_no_const *entry,
78068 const char *procname, void *data, int maxlen,
78069 umode_t mode, proc_handler *proc_handler,
78070 bool load_idx)
78071@@ -5024,7 +5031,7 @@ set_table_entry(struct ctl_table *entry,
78072 static struct ctl_table *
78073 sd_alloc_ctl_domain_table(struct sched_domain *sd)
78074 {
78075- struct ctl_table *table = sd_alloc_ctl_entry(13);
78076+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
78077
78078 if (table == NULL)
78079 return NULL;
78080@@ -5059,9 +5066,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
78081 return table;
78082 }
78083
78084-static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
78085+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
78086 {
78087- struct ctl_table *entry, *table;
78088+ ctl_table_no_const *entry, *table;
78089 struct sched_domain *sd;
78090 int domain_num = 0, i;
78091 char buf[32];
78092@@ -5088,11 +5095,13 @@ static struct ctl_table_header *sd_sysctl_header;
78093 static void register_sched_domain_sysctl(void)
78094 {
78095 int i, cpu_num = num_possible_cpus();
78096- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
78097+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
78098 char buf[32];
78099
78100 WARN_ON(sd_ctl_dir[0].child);
78101+ pax_open_kernel();
78102 sd_ctl_dir[0].child = entry;
78103+ pax_close_kernel();
78104
78105 if (entry == NULL)
78106 return;
78107@@ -5115,8 +5124,12 @@ static void unregister_sched_domain_sysctl(void)
78108 if (sd_sysctl_header)
78109 unregister_sysctl_table(sd_sysctl_header);
78110 sd_sysctl_header = NULL;
78111- if (sd_ctl_dir[0].child)
78112- sd_free_ctl_entry(&sd_ctl_dir[0].child);
78113+ if (sd_ctl_dir[0].child) {
78114+ sd_free_ctl_entry(sd_ctl_dir[0].child);
78115+ pax_open_kernel();
78116+ sd_ctl_dir[0].child = NULL;
78117+ pax_close_kernel();
78118+ }
78119 }
78120 #else
78121 static void register_sched_domain_sysctl(void)
78122@@ -5215,7 +5228,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
78123 * happens before everything else. This has to be lower priority than
78124 * the notifier in the perf_event subsystem, though.
78125 */
78126-static struct notifier_block __cpuinitdata migration_notifier = {
78127+static struct notifier_block migration_notifier = {
78128 .notifier_call = migration_call,
78129 .priority = CPU_PRI_MIGRATION,
78130 };
78131diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
78132index 7a33e59..2f7730c 100644
78133--- a/kernel/sched/fair.c
78134+++ b/kernel/sched/fair.c
78135@@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
78136
78137 static void reset_ptenuma_scan(struct task_struct *p)
78138 {
78139- ACCESS_ONCE(p->mm->numa_scan_seq)++;
78140+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
78141 p->mm->numa_scan_offset = 0;
78142 }
78143
78144@@ -5654,7 +5654,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
78145 * run_rebalance_domains is triggered when needed from the scheduler tick.
78146 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
78147 */
78148-static void run_rebalance_domains(struct softirq_action *h)
78149+static void run_rebalance_domains(void)
78150 {
78151 int this_cpu = smp_processor_id();
78152 struct rq *this_rq = cpu_rq(this_cpu);
78153diff --git a/kernel/signal.c b/kernel/signal.c
78154index 598dc06..471310a 100644
78155--- a/kernel/signal.c
78156+++ b/kernel/signal.c
78157@@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
78158
78159 int print_fatal_signals __read_mostly;
78160
78161-static void __user *sig_handler(struct task_struct *t, int sig)
78162+static __sighandler_t sig_handler(struct task_struct *t, int sig)
78163 {
78164 return t->sighand->action[sig - 1].sa.sa_handler;
78165 }
78166
78167-static int sig_handler_ignored(void __user *handler, int sig)
78168+static int sig_handler_ignored(__sighandler_t handler, int sig)
78169 {
78170 /* Is it explicitly or implicitly ignored? */
78171 return handler == SIG_IGN ||
78172@@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
78173
78174 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
78175 {
78176- void __user *handler;
78177+ __sighandler_t handler;
78178
78179 handler = sig_handler(t, sig);
78180
78181@@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
78182 atomic_inc(&user->sigpending);
78183 rcu_read_unlock();
78184
78185+ if (!override_rlimit)
78186+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
78187+
78188 if (override_rlimit ||
78189 atomic_read(&user->sigpending) <=
78190 task_rlimit(t, RLIMIT_SIGPENDING)) {
78191@@ -495,7 +498,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
78192
78193 int unhandled_signal(struct task_struct *tsk, int sig)
78194 {
78195- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
78196+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
78197 if (is_global_init(tsk))
78198 return 1;
78199 if (handler != SIG_IGN && handler != SIG_DFL)
78200@@ -815,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
78201 }
78202 }
78203
78204+ /* allow glibc communication via tgkill to other threads in our
78205+ thread group */
78206+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
78207+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
78208+ && gr_handle_signal(t, sig))
78209+ return -EPERM;
78210+
78211 return security_task_kill(t, info, sig, 0);
78212 }
78213
78214@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
78215 return send_signal(sig, info, p, 1);
78216 }
78217
78218-static int
78219+int
78220 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78221 {
78222 return send_signal(sig, info, t, 0);
78223@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78224 unsigned long int flags;
78225 int ret, blocked, ignored;
78226 struct k_sigaction *action;
78227+ int is_unhandled = 0;
78228
78229 spin_lock_irqsave(&t->sighand->siglock, flags);
78230 action = &t->sighand->action[sig-1];
78231@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78232 }
78233 if (action->sa.sa_handler == SIG_DFL)
78234 t->signal->flags &= ~SIGNAL_UNKILLABLE;
78235+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
78236+ is_unhandled = 1;
78237 ret = specific_send_sig_info(sig, info, t);
78238 spin_unlock_irqrestore(&t->sighand->siglock, flags);
78239
78240+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
78241+ normal operation */
78242+ if (is_unhandled) {
78243+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
78244+ gr_handle_crash(t, sig);
78245+ }
78246+
78247 return ret;
78248 }
78249
78250@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
78251 ret = check_kill_permission(sig, info, p);
78252 rcu_read_unlock();
78253
78254- if (!ret && sig)
78255+ if (!ret && sig) {
78256 ret = do_send_sig_info(sig, info, p, true);
78257+ if (!ret)
78258+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
78259+ }
78260
78261 return ret;
78262 }
78263@@ -2923,7 +2946,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
78264 int error = -ESRCH;
78265
78266 rcu_read_lock();
78267- p = find_task_by_vpid(pid);
78268+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
78269+ /* allow glibc communication via tgkill to other threads in our
78270+ thread group */
78271+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
78272+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
78273+ p = find_task_by_vpid_unrestricted(pid);
78274+ else
78275+#endif
78276+ p = find_task_by_vpid(pid);
78277 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
78278 error = check_kill_permission(sig, info, p);
78279 /*
78280@@ -3237,8 +3268,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
78281 }
78282 seg = get_fs();
78283 set_fs(KERNEL_DS);
78284- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
78285- (stack_t __force __user *) &uoss,
78286+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
78287+ (stack_t __force_user *) &uoss,
78288 compat_user_stack_pointer());
78289 set_fs(seg);
78290 if (ret >= 0 && uoss_ptr) {
78291diff --git a/kernel/smp.c b/kernel/smp.c
78292index 8e451f3..8322029 100644
78293--- a/kernel/smp.c
78294+++ b/kernel/smp.c
78295@@ -73,7 +73,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
78296 return NOTIFY_OK;
78297 }
78298
78299-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
78300+static struct notifier_block hotplug_cfd_notifier = {
78301 .notifier_call = hotplug_cfd,
78302 };
78303
78304diff --git a/kernel/smpboot.c b/kernel/smpboot.c
78305index 02fc5c9..e54c335 100644
78306--- a/kernel/smpboot.c
78307+++ b/kernel/smpboot.c
78308@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
78309 }
78310 smpboot_unpark_thread(plug_thread, cpu);
78311 }
78312- list_add(&plug_thread->list, &hotplug_threads);
78313+ pax_list_add(&plug_thread->list, &hotplug_threads);
78314 out:
78315 mutex_unlock(&smpboot_threads_lock);
78316 return ret;
78317@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
78318 {
78319 get_online_cpus();
78320 mutex_lock(&smpboot_threads_lock);
78321- list_del(&plug_thread->list);
78322+ pax_list_del(&plug_thread->list);
78323 smpboot_destroy_threads(plug_thread);
78324 mutex_unlock(&smpboot_threads_lock);
78325 put_online_cpus();
78326diff --git a/kernel/softirq.c b/kernel/softirq.c
78327index 14d7758..012121f 100644
78328--- a/kernel/softirq.c
78329+++ b/kernel/softirq.c
78330@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
78331 EXPORT_SYMBOL(irq_stat);
78332 #endif
78333
78334-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
78335+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
78336
78337 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
78338
78339-char *softirq_to_name[NR_SOFTIRQS] = {
78340+const char * const softirq_to_name[NR_SOFTIRQS] = {
78341 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
78342 "TASKLET", "SCHED", "HRTIMER", "RCU"
78343 };
78344@@ -244,7 +244,7 @@ restart:
78345 kstat_incr_softirqs_this_cpu(vec_nr);
78346
78347 trace_softirq_entry(vec_nr);
78348- h->action(h);
78349+ h->action();
78350 trace_softirq_exit(vec_nr);
78351 if (unlikely(prev_count != preempt_count())) {
78352 printk(KERN_ERR "huh, entered softirq %u %s %p"
78353@@ -389,7 +389,7 @@ void __raise_softirq_irqoff(unsigned int nr)
78354 or_softirq_pending(1UL << nr);
78355 }
78356
78357-void open_softirq(int nr, void (*action)(struct softirq_action *))
78358+void __init open_softirq(int nr, void (*action)(void))
78359 {
78360 softirq_vec[nr].action = action;
78361 }
78362@@ -445,7 +445,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
78363
78364 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
78365
78366-static void tasklet_action(struct softirq_action *a)
78367+static void tasklet_action(void)
78368 {
78369 struct tasklet_struct *list;
78370
78371@@ -480,7 +480,7 @@ static void tasklet_action(struct softirq_action *a)
78372 }
78373 }
78374
78375-static void tasklet_hi_action(struct softirq_action *a)
78376+static void tasklet_hi_action(void)
78377 {
78378 struct tasklet_struct *list;
78379
78380@@ -716,7 +716,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
78381 return NOTIFY_OK;
78382 }
78383
78384-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
78385+static struct notifier_block remote_softirq_cpu_notifier = {
78386 .notifier_call = remote_softirq_cpu_notify,
78387 };
78388
78389@@ -833,11 +833,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
78390 return NOTIFY_OK;
78391 }
78392
78393-static struct notifier_block __cpuinitdata cpu_nfb = {
78394+static struct notifier_block cpu_nfb = {
78395 .notifier_call = cpu_callback
78396 };
78397
78398-static struct smp_hotplug_thread softirq_threads = {
78399+static struct smp_hotplug_thread softirq_threads __read_only = {
78400 .store = &ksoftirqd,
78401 .thread_should_run = ksoftirqd_should_run,
78402 .thread_fn = run_ksoftirqd,
78403diff --git a/kernel/srcu.c b/kernel/srcu.c
78404index 01d5ccb..cdcbee6 100644
78405--- a/kernel/srcu.c
78406+++ b/kernel/srcu.c
78407@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
78408
78409 idx = ACCESS_ONCE(sp->completed) & 0x1;
78410 preempt_disable();
78411- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
78412+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
78413 smp_mb(); /* B */ /* Avoid leaking the critical section. */
78414- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
78415+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
78416 preempt_enable();
78417 return idx;
78418 }
78419diff --git a/kernel/sys.c b/kernel/sys.c
78420index 0da73cf..5c2af3c 100644
78421--- a/kernel/sys.c
78422+++ b/kernel/sys.c
78423@@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
78424 error = -EACCES;
78425 goto out;
78426 }
78427+
78428+ if (gr_handle_chroot_setpriority(p, niceval)) {
78429+ error = -EACCES;
78430+ goto out;
78431+ }
78432+
78433 no_nice = security_task_setnice(p, niceval);
78434 if (no_nice) {
78435 error = no_nice;
78436@@ -598,6 +604,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
78437 goto error;
78438 }
78439
78440+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
78441+ goto error;
78442+
78443 if (rgid != (gid_t) -1 ||
78444 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
78445 new->sgid = new->egid;
78446@@ -633,6 +642,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
78447 old = current_cred();
78448
78449 retval = -EPERM;
78450+
78451+ if (gr_check_group_change(kgid, kgid, kgid))
78452+ goto error;
78453+
78454 if (nsown_capable(CAP_SETGID))
78455 new->gid = new->egid = new->sgid = new->fsgid = kgid;
78456 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
78457@@ -650,7 +663,7 @@ error:
78458 /*
78459 * change the user struct in a credentials set to match the new UID
78460 */
78461-static int set_user(struct cred *new)
78462+int set_user(struct cred *new)
78463 {
78464 struct user_struct *new_user;
78465
78466@@ -730,6 +743,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
78467 goto error;
78468 }
78469
78470+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
78471+ goto error;
78472+
78473 if (!uid_eq(new->uid, old->uid)) {
78474 retval = set_user(new);
78475 if (retval < 0)
78476@@ -780,6 +796,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
78477 old = current_cred();
78478
78479 retval = -EPERM;
78480+
78481+ if (gr_check_crash_uid(kuid))
78482+ goto error;
78483+ if (gr_check_user_change(kuid, kuid, kuid))
78484+ goto error;
78485+
78486 if (nsown_capable(CAP_SETUID)) {
78487 new->suid = new->uid = kuid;
78488 if (!uid_eq(kuid, old->uid)) {
78489@@ -849,6 +871,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
78490 goto error;
78491 }
78492
78493+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
78494+ goto error;
78495+
78496 if (ruid != (uid_t) -1) {
78497 new->uid = kruid;
78498 if (!uid_eq(kruid, old->uid)) {
78499@@ -931,6 +956,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
78500 goto error;
78501 }
78502
78503+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
78504+ goto error;
78505+
78506 if (rgid != (gid_t) -1)
78507 new->gid = krgid;
78508 if (egid != (gid_t) -1)
78509@@ -992,12 +1020,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
78510 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
78511 nsown_capable(CAP_SETUID)) {
78512 if (!uid_eq(kuid, old->fsuid)) {
78513+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
78514+ goto error;
78515+
78516 new->fsuid = kuid;
78517 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
78518 goto change_okay;
78519 }
78520 }
78521
78522+error:
78523 abort_creds(new);
78524 return old_fsuid;
78525
78526@@ -1030,12 +1062,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
78527 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
78528 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
78529 nsown_capable(CAP_SETGID)) {
78530+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
78531+ goto error;
78532+
78533 if (!gid_eq(kgid, old->fsgid)) {
78534 new->fsgid = kgid;
78535 goto change_okay;
78536 }
78537 }
78538
78539+error:
78540 abort_creds(new);
78541 return old_fsgid;
78542
78543@@ -1343,19 +1379,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
78544 return -EFAULT;
78545
78546 down_read(&uts_sem);
78547- error = __copy_to_user(&name->sysname, &utsname()->sysname,
78548+ error = __copy_to_user(name->sysname, &utsname()->sysname,
78549 __OLD_UTS_LEN);
78550 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
78551- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
78552+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
78553 __OLD_UTS_LEN);
78554 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
78555- error |= __copy_to_user(&name->release, &utsname()->release,
78556+ error |= __copy_to_user(name->release, &utsname()->release,
78557 __OLD_UTS_LEN);
78558 error |= __put_user(0, name->release + __OLD_UTS_LEN);
78559- error |= __copy_to_user(&name->version, &utsname()->version,
78560+ error |= __copy_to_user(name->version, &utsname()->version,
78561 __OLD_UTS_LEN);
78562 error |= __put_user(0, name->version + __OLD_UTS_LEN);
78563- error |= __copy_to_user(&name->machine, &utsname()->machine,
78564+ error |= __copy_to_user(name->machine, &utsname()->machine,
78565 __OLD_UTS_LEN);
78566 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
78567 up_read(&uts_sem);
78568@@ -1557,6 +1593,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
78569 */
78570 new_rlim->rlim_cur = 1;
78571 }
78572+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
78573+ is changed to a lower value. Since tasks can be created by the same
78574+ user in between this limit change and an execve by this task, force
78575+ a recheck only for this task by setting PF_NPROC_EXCEEDED
78576+ */
78577+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
78578+ tsk->flags |= PF_NPROC_EXCEEDED;
78579 }
78580 if (!retval) {
78581 if (old_rlim)
78582diff --git a/kernel/sysctl.c b/kernel/sysctl.c
78583index afc1dc6..f6cf355 100644
78584--- a/kernel/sysctl.c
78585+++ b/kernel/sysctl.c
78586@@ -93,7 +93,6 @@
78587
78588
78589 #if defined(CONFIG_SYSCTL)
78590-
78591 /* External variables not in a header file. */
78592 extern int sysctl_overcommit_memory;
78593 extern int sysctl_overcommit_ratio;
78594@@ -120,18 +119,18 @@ extern int blk_iopoll_enabled;
78595
78596 /* Constants used for minimum and maximum */
78597 #ifdef CONFIG_LOCKUP_DETECTOR
78598-static int sixty = 60;
78599-static int neg_one = -1;
78600+static int sixty __read_only = 60;
78601 #endif
78602
78603-static int zero;
78604-static int __maybe_unused one = 1;
78605-static int __maybe_unused two = 2;
78606-static int __maybe_unused three = 3;
78607-static unsigned long one_ul = 1;
78608-static int one_hundred = 100;
78609+static int neg_one __read_only = -1;
78610+static int zero __read_only = 0;
78611+static int __maybe_unused one __read_only = 1;
78612+static int __maybe_unused two __read_only = 2;
78613+static int __maybe_unused three __read_only = 3;
78614+static unsigned long one_ul __read_only = 1;
78615+static int one_hundred __read_only = 100;
78616 #ifdef CONFIG_PRINTK
78617-static int ten_thousand = 10000;
78618+static int ten_thousand __read_only = 10000;
78619 #endif
78620
78621 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
78622@@ -178,10 +177,8 @@ static int proc_taint(struct ctl_table *table, int write,
78623 void __user *buffer, size_t *lenp, loff_t *ppos);
78624 #endif
78625
78626-#ifdef CONFIG_PRINTK
78627 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
78628 void __user *buffer, size_t *lenp, loff_t *ppos);
78629-#endif
78630
78631 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
78632 void __user *buffer, size_t *lenp, loff_t *ppos);
78633@@ -212,6 +209,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
78634
78635 #endif
78636
78637+extern struct ctl_table grsecurity_table[];
78638+
78639 static struct ctl_table kern_table[];
78640 static struct ctl_table vm_table[];
78641 static struct ctl_table fs_table[];
78642@@ -226,6 +225,20 @@ extern struct ctl_table epoll_table[];
78643 int sysctl_legacy_va_layout;
78644 #endif
78645
78646+#ifdef CONFIG_PAX_SOFTMODE
78647+static ctl_table pax_table[] = {
78648+ {
78649+ .procname = "softmode",
78650+ .data = &pax_softmode,
78651+ .maxlen = sizeof(unsigned int),
78652+ .mode = 0600,
78653+ .proc_handler = &proc_dointvec,
78654+ },
78655+
78656+ { }
78657+};
78658+#endif
78659+
78660 /* The default sysctl tables: */
78661
78662 static struct ctl_table sysctl_base_table[] = {
78663@@ -274,6 +287,22 @@ static int max_extfrag_threshold = 1000;
78664 #endif
78665
78666 static struct ctl_table kern_table[] = {
78667+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
78668+ {
78669+ .procname = "grsecurity",
78670+ .mode = 0500,
78671+ .child = grsecurity_table,
78672+ },
78673+#endif
78674+
78675+#ifdef CONFIG_PAX_SOFTMODE
78676+ {
78677+ .procname = "pax",
78678+ .mode = 0500,
78679+ .child = pax_table,
78680+ },
78681+#endif
78682+
78683 {
78684 .procname = "sched_child_runs_first",
78685 .data = &sysctl_sched_child_runs_first,
78686@@ -608,7 +637,7 @@ static struct ctl_table kern_table[] = {
78687 .data = &modprobe_path,
78688 .maxlen = KMOD_PATH_LEN,
78689 .mode = 0644,
78690- .proc_handler = proc_dostring,
78691+ .proc_handler = proc_dostring_modpriv,
78692 },
78693 {
78694 .procname = "modules_disabled",
78695@@ -775,16 +804,20 @@ static struct ctl_table kern_table[] = {
78696 .extra1 = &zero,
78697 .extra2 = &one,
78698 },
78699+#endif
78700 {
78701 .procname = "kptr_restrict",
78702 .data = &kptr_restrict,
78703 .maxlen = sizeof(int),
78704 .mode = 0644,
78705 .proc_handler = proc_dointvec_minmax_sysadmin,
78706+#ifdef CONFIG_GRKERNSEC_HIDESYM
78707+ .extra1 = &two,
78708+#else
78709 .extra1 = &zero,
78710+#endif
78711 .extra2 = &two,
78712 },
78713-#endif
78714 {
78715 .procname = "ngroups_max",
78716 .data = &ngroups_max,
78717@@ -1026,10 +1059,17 @@ static struct ctl_table kern_table[] = {
78718 */
78719 {
78720 .procname = "perf_event_paranoid",
78721- .data = &sysctl_perf_event_paranoid,
78722- .maxlen = sizeof(sysctl_perf_event_paranoid),
78723+ .data = &sysctl_perf_event_legitimately_concerned,
78724+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
78725 .mode = 0644,
78726- .proc_handler = proc_dointvec,
78727+ /* go ahead, be a hero */
78728+ .proc_handler = proc_dointvec_minmax_sysadmin,
78729+ .extra1 = &neg_one,
78730+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
78731+ .extra2 = &three,
78732+#else
78733+ .extra2 = &two,
78734+#endif
78735 },
78736 {
78737 .procname = "perf_event_mlock_kb",
78738@@ -1283,6 +1323,13 @@ static struct ctl_table vm_table[] = {
78739 .proc_handler = proc_dointvec_minmax,
78740 .extra1 = &zero,
78741 },
78742+ {
78743+ .procname = "heap_stack_gap",
78744+ .data = &sysctl_heap_stack_gap,
78745+ .maxlen = sizeof(sysctl_heap_stack_gap),
78746+ .mode = 0644,
78747+ .proc_handler = proc_doulongvec_minmax,
78748+ },
78749 #else
78750 {
78751 .procname = "nr_trim_pages",
78752@@ -1733,6 +1780,16 @@ int proc_dostring(struct ctl_table *table, int write,
78753 buffer, lenp, ppos);
78754 }
78755
78756+int proc_dostring_modpriv(struct ctl_table *table, int write,
78757+ void __user *buffer, size_t *lenp, loff_t *ppos)
78758+{
78759+ if (write && !capable(CAP_SYS_MODULE))
78760+ return -EPERM;
78761+
78762+ return _proc_do_string(table->data, table->maxlen, write,
78763+ buffer, lenp, ppos);
78764+}
78765+
78766 static size_t proc_skip_spaces(char **buf)
78767 {
78768 size_t ret;
78769@@ -1838,6 +1895,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
78770 len = strlen(tmp);
78771 if (len > *size)
78772 len = *size;
78773+ if (len > sizeof(tmp))
78774+ len = sizeof(tmp);
78775 if (copy_to_user(*buf, tmp, len))
78776 return -EFAULT;
78777 *size -= len;
78778@@ -2002,7 +2061,7 @@ int proc_dointvec(struct ctl_table *table, int write,
78779 static int proc_taint(struct ctl_table *table, int write,
78780 void __user *buffer, size_t *lenp, loff_t *ppos)
78781 {
78782- struct ctl_table t;
78783+ ctl_table_no_const t;
78784 unsigned long tmptaint = get_taint();
78785 int err;
78786
78787@@ -2030,7 +2089,6 @@ static int proc_taint(struct ctl_table *table, int write,
78788 return err;
78789 }
78790
78791-#ifdef CONFIG_PRINTK
78792 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
78793 void __user *buffer, size_t *lenp, loff_t *ppos)
78794 {
78795@@ -2039,7 +2097,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
78796
78797 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
78798 }
78799-#endif
78800
78801 struct do_proc_dointvec_minmax_conv_param {
78802 int *min;
78803@@ -2186,8 +2243,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
78804 *i = val;
78805 } else {
78806 val = convdiv * (*i) / convmul;
78807- if (!first)
78808+ if (!first) {
78809 err = proc_put_char(&buffer, &left, '\t');
78810+ if (err)
78811+ break;
78812+ }
78813 err = proc_put_long(&buffer, &left, val, false);
78814 if (err)
78815 break;
78816@@ -2579,6 +2639,12 @@ int proc_dostring(struct ctl_table *table, int write,
78817 return -ENOSYS;
78818 }
78819
78820+int proc_dostring_modpriv(struct ctl_table *table, int write,
78821+ void __user *buffer, size_t *lenp, loff_t *ppos)
78822+{
78823+ return -ENOSYS;
78824+}
78825+
78826 int proc_dointvec(struct ctl_table *table, int write,
78827 void __user *buffer, size_t *lenp, loff_t *ppos)
78828 {
78829@@ -2635,5 +2701,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
78830 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
78831 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
78832 EXPORT_SYMBOL(proc_dostring);
78833+EXPORT_SYMBOL(proc_dostring_modpriv);
78834 EXPORT_SYMBOL(proc_doulongvec_minmax);
78835 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
78836diff --git a/kernel/taskstats.c b/kernel/taskstats.c
78837index 145bb4d..b2aa969 100644
78838--- a/kernel/taskstats.c
78839+++ b/kernel/taskstats.c
78840@@ -28,9 +28,12 @@
78841 #include <linux/fs.h>
78842 #include <linux/file.h>
78843 #include <linux/pid_namespace.h>
78844+#include <linux/grsecurity.h>
78845 #include <net/genetlink.h>
78846 #include <linux/atomic.h>
78847
78848+extern int gr_is_taskstats_denied(int pid);
78849+
78850 /*
78851 * Maximum length of a cpumask that can be specified in
78852 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
78853@@ -570,6 +573,9 @@ err:
78854
78855 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
78856 {
78857+ if (gr_is_taskstats_denied(current->pid))
78858+ return -EACCES;
78859+
78860 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
78861 return cmd_attr_register_cpumask(info);
78862 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
78863diff --git a/kernel/time.c b/kernel/time.c
78864index f8342a4..288f13b 100644
78865--- a/kernel/time.c
78866+++ b/kernel/time.c
78867@@ -171,6 +171,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
78868 return error;
78869
78870 if (tz) {
78871+ /* we log in do_settimeofday called below, so don't log twice
78872+ */
78873+ if (!tv)
78874+ gr_log_timechange();
78875+
78876 sys_tz = *tz;
78877 update_vsyscall_tz();
78878 if (firsttime) {
78879@@ -501,7 +506,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
78880 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
78881 * value to a scaled second value.
78882 */
78883-unsigned long
78884+unsigned long __intentional_overflow(-1)
78885 timespec_to_jiffies(const struct timespec *value)
78886 {
78887 unsigned long sec = value->tv_sec;
78888diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
78889index f11d83b..d016d91 100644
78890--- a/kernel/time/alarmtimer.c
78891+++ b/kernel/time/alarmtimer.c
78892@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
78893 struct platform_device *pdev;
78894 int error = 0;
78895 int i;
78896- struct k_clock alarm_clock = {
78897+ static struct k_clock alarm_clock = {
78898 .clock_getres = alarm_clock_getres,
78899 .clock_get = alarm_clock_get,
78900 .timer_create = alarm_timer_create,
78901diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
78902index 90ad470..1814e9a 100644
78903--- a/kernel/time/tick-broadcast.c
78904+++ b/kernel/time/tick-broadcast.c
78905@@ -138,7 +138,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
78906 * then clear the broadcast bit.
78907 */
78908 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
78909- int cpu = smp_processor_id();
78910+ cpu = smp_processor_id();
78911 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
78912 tick_broadcast_clear_oneshot(cpu);
78913 } else {
78914diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
78915index 9a0bc98..fceb7d0 100644
78916--- a/kernel/time/timekeeping.c
78917+++ b/kernel/time/timekeeping.c
78918@@ -15,6 +15,7 @@
78919 #include <linux/init.h>
78920 #include <linux/mm.h>
78921 #include <linux/sched.h>
78922+#include <linux/grsecurity.h>
78923 #include <linux/syscore_ops.h>
78924 #include <linux/clocksource.h>
78925 #include <linux/jiffies.h>
78926@@ -448,6 +449,8 @@ int do_settimeofday(const struct timespec *tv)
78927 if (!timespec_valid_strict(tv))
78928 return -EINVAL;
78929
78930+ gr_log_timechange();
78931+
78932 write_seqlock_irqsave(&tk->lock, flags);
78933
78934 timekeeping_forward_now(tk);
78935diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
78936index af5a7e9..715611a 100644
78937--- a/kernel/time/timer_list.c
78938+++ b/kernel/time/timer_list.c
78939@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
78940
78941 static void print_name_offset(struct seq_file *m, void *sym)
78942 {
78943+#ifdef CONFIG_GRKERNSEC_HIDESYM
78944+ SEQ_printf(m, "<%p>", NULL);
78945+#else
78946 char symname[KSYM_NAME_LEN];
78947
78948 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
78949 SEQ_printf(m, "<%pK>", sym);
78950 else
78951 SEQ_printf(m, "%s", symname);
78952+#endif
78953 }
78954
78955 static void
78956@@ -112,7 +116,11 @@ next_one:
78957 static void
78958 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
78959 {
78960+#ifdef CONFIG_GRKERNSEC_HIDESYM
78961+ SEQ_printf(m, " .base: %p\n", NULL);
78962+#else
78963 SEQ_printf(m, " .base: %pK\n", base);
78964+#endif
78965 SEQ_printf(m, " .index: %d\n",
78966 base->index);
78967 SEQ_printf(m, " .resolution: %Lu nsecs\n",
78968@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
78969 {
78970 struct proc_dir_entry *pe;
78971
78972+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78973+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
78974+#else
78975 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
78976+#endif
78977 if (!pe)
78978 return -ENOMEM;
78979 return 0;
78980diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
78981index 0b537f2..40d6c20 100644
78982--- a/kernel/time/timer_stats.c
78983+++ b/kernel/time/timer_stats.c
78984@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
78985 static unsigned long nr_entries;
78986 static struct entry entries[MAX_ENTRIES];
78987
78988-static atomic_t overflow_count;
78989+static atomic_unchecked_t overflow_count;
78990
78991 /*
78992 * The entries are in a hash-table, for fast lookup:
78993@@ -140,7 +140,7 @@ static void reset_entries(void)
78994 nr_entries = 0;
78995 memset(entries, 0, sizeof(entries));
78996 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
78997- atomic_set(&overflow_count, 0);
78998+ atomic_set_unchecked(&overflow_count, 0);
78999 }
79000
79001 static struct entry *alloc_entry(void)
79002@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
79003 if (likely(entry))
79004 entry->count++;
79005 else
79006- atomic_inc(&overflow_count);
79007+ atomic_inc_unchecked(&overflow_count);
79008
79009 out_unlock:
79010 raw_spin_unlock_irqrestore(lock, flags);
79011@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
79012
79013 static void print_name_offset(struct seq_file *m, unsigned long addr)
79014 {
79015+#ifdef CONFIG_GRKERNSEC_HIDESYM
79016+ seq_printf(m, "<%p>", NULL);
79017+#else
79018 char symname[KSYM_NAME_LEN];
79019
79020 if (lookup_symbol_name(addr, symname) < 0)
79021- seq_printf(m, "<%p>", (void *)addr);
79022+ seq_printf(m, "<%pK>", (void *)addr);
79023 else
79024 seq_printf(m, "%s", symname);
79025+#endif
79026 }
79027
79028 static int tstats_show(struct seq_file *m, void *v)
79029@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
79030
79031 seq_puts(m, "Timer Stats Version: v0.2\n");
79032 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
79033- if (atomic_read(&overflow_count))
79034+ if (atomic_read_unchecked(&overflow_count))
79035 seq_printf(m, "Overflow: %d entries\n",
79036- atomic_read(&overflow_count));
79037+ atomic_read_unchecked(&overflow_count));
79038
79039 for (i = 0; i < nr_entries; i++) {
79040 entry = entries + i;
79041@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
79042 {
79043 struct proc_dir_entry *pe;
79044
79045+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79046+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
79047+#else
79048 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
79049+#endif
79050 if (!pe)
79051 return -ENOMEM;
79052 return 0;
79053diff --git a/kernel/timer.c b/kernel/timer.c
79054index 1b399c8..90e1849 100644
79055--- a/kernel/timer.c
79056+++ b/kernel/timer.c
79057@@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
79058 /*
79059 * This function runs timers and the timer-tq in bottom half context.
79060 */
79061-static void run_timer_softirq(struct softirq_action *h)
79062+static void run_timer_softirq(void)
79063 {
79064 struct tvec_base *base = __this_cpu_read(tvec_bases);
79065
79066@@ -1481,7 +1481,7 @@ static void process_timeout(unsigned long __data)
79067 *
79068 * In all cases the return value is guaranteed to be non-negative.
79069 */
79070-signed long __sched schedule_timeout(signed long timeout)
79071+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
79072 {
79073 struct timer_list timer;
79074 unsigned long expire;
79075@@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
79076 return NOTIFY_OK;
79077 }
79078
79079-static struct notifier_block __cpuinitdata timers_nb = {
79080+static struct notifier_block timers_nb = {
79081 .notifier_call = timer_cpu_notify,
79082 };
79083
79084diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
79085index 5a0f781..1497f95 100644
79086--- a/kernel/trace/blktrace.c
79087+++ b/kernel/trace/blktrace.c
79088@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
79089 struct blk_trace *bt = filp->private_data;
79090 char buf[16];
79091
79092- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
79093+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
79094
79095 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
79096 }
79097@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
79098 return 1;
79099
79100 bt = buf->chan->private_data;
79101- atomic_inc(&bt->dropped);
79102+ atomic_inc_unchecked(&bt->dropped);
79103 return 0;
79104 }
79105
79106@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
79107
79108 bt->dir = dir;
79109 bt->dev = dev;
79110- atomic_set(&bt->dropped, 0);
79111+ atomic_set_unchecked(&bt->dropped, 0);
79112
79113 ret = -EIO;
79114 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
79115diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
79116index 0a0e2a6..943495e 100644
79117--- a/kernel/trace/ftrace.c
79118+++ b/kernel/trace/ftrace.c
79119@@ -1909,12 +1909,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
79120 if (unlikely(ftrace_disabled))
79121 return 0;
79122
79123+ ret = ftrace_arch_code_modify_prepare();
79124+ FTRACE_WARN_ON(ret);
79125+ if (ret)
79126+ return 0;
79127+
79128 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
79129+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
79130 if (ret) {
79131 ftrace_bug(ret, ip);
79132- return 0;
79133 }
79134- return 1;
79135+ return ret ? 0 : 1;
79136 }
79137
79138 /*
79139@@ -2986,7 +2991,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
79140
79141 int
79142 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
79143- void *data)
79144+ void *data)
79145 {
79146 struct ftrace_func_probe *entry;
79147 struct ftrace_page *pg;
79148@@ -3854,8 +3859,10 @@ static int ftrace_process_locs(struct module *mod,
79149 if (!count)
79150 return 0;
79151
79152+ pax_open_kernel();
79153 sort(start, count, sizeof(*start),
79154 ftrace_cmp_ips, ftrace_swap_ips);
79155+ pax_close_kernel();
79156
79157 start_pg = ftrace_allocate_pages(count);
79158 if (!start_pg)
79159@@ -4574,8 +4581,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
79160 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
79161
79162 static int ftrace_graph_active;
79163-static struct notifier_block ftrace_suspend_notifier;
79164-
79165 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
79166 {
79167 return 0;
79168@@ -4719,6 +4724,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
79169 return NOTIFY_DONE;
79170 }
79171
79172+static struct notifier_block ftrace_suspend_notifier = {
79173+ .notifier_call = ftrace_suspend_notifier_call
79174+};
79175+
79176 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
79177 trace_func_graph_ent_t entryfunc)
79178 {
79179@@ -4732,7 +4741,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
79180 goto out;
79181 }
79182
79183- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
79184 register_pm_notifier(&ftrace_suspend_notifier);
79185
79186 ftrace_graph_active++;
79187diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
79188index 6989df2..c2265cf 100644
79189--- a/kernel/trace/ring_buffer.c
79190+++ b/kernel/trace/ring_buffer.c
79191@@ -349,9 +349,9 @@ struct buffer_data_page {
79192 */
79193 struct buffer_page {
79194 struct list_head list; /* list of buffer pages */
79195- local_t write; /* index for next write */
79196+ local_unchecked_t write; /* index for next write */
79197 unsigned read; /* index for next read */
79198- local_t entries; /* entries on this page */
79199+ local_unchecked_t entries; /* entries on this page */
79200 unsigned long real_end; /* real end of data */
79201 struct buffer_data_page *page; /* Actual data page */
79202 };
79203@@ -464,8 +464,8 @@ struct ring_buffer_per_cpu {
79204 unsigned long last_overrun;
79205 local_t entries_bytes;
79206 local_t entries;
79207- local_t overrun;
79208- local_t commit_overrun;
79209+ local_unchecked_t overrun;
79210+ local_unchecked_t commit_overrun;
79211 local_t dropped_events;
79212 local_t committing;
79213 local_t commits;
79214@@ -864,8 +864,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
79215 *
79216 * We add a counter to the write field to denote this.
79217 */
79218- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
79219- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
79220+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
79221+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
79222
79223 /*
79224 * Just make sure we have seen our old_write and synchronize
79225@@ -893,8 +893,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
79226 * cmpxchg to only update if an interrupt did not already
79227 * do it for us. If the cmpxchg fails, we don't care.
79228 */
79229- (void)local_cmpxchg(&next_page->write, old_write, val);
79230- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
79231+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
79232+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
79233
79234 /*
79235 * No need to worry about races with clearing out the commit.
79236@@ -1253,12 +1253,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
79237
79238 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
79239 {
79240- return local_read(&bpage->entries) & RB_WRITE_MASK;
79241+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
79242 }
79243
79244 static inline unsigned long rb_page_write(struct buffer_page *bpage)
79245 {
79246- return local_read(&bpage->write) & RB_WRITE_MASK;
79247+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
79248 }
79249
79250 static int
79251@@ -1353,7 +1353,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
79252 * bytes consumed in ring buffer from here.
79253 * Increment overrun to account for the lost events.
79254 */
79255- local_add(page_entries, &cpu_buffer->overrun);
79256+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
79257 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
79258 }
79259
79260@@ -1909,7 +1909,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
79261 * it is our responsibility to update
79262 * the counters.
79263 */
79264- local_add(entries, &cpu_buffer->overrun);
79265+ local_add_unchecked(entries, &cpu_buffer->overrun);
79266 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
79267
79268 /*
79269@@ -2059,7 +2059,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
79270 if (tail == BUF_PAGE_SIZE)
79271 tail_page->real_end = 0;
79272
79273- local_sub(length, &tail_page->write);
79274+ local_sub_unchecked(length, &tail_page->write);
79275 return;
79276 }
79277
79278@@ -2094,7 +2094,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
79279 rb_event_set_padding(event);
79280
79281 /* Set the write back to the previous setting */
79282- local_sub(length, &tail_page->write);
79283+ local_sub_unchecked(length, &tail_page->write);
79284 return;
79285 }
79286
79287@@ -2106,7 +2106,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
79288
79289 /* Set write to end of buffer */
79290 length = (tail + length) - BUF_PAGE_SIZE;
79291- local_sub(length, &tail_page->write);
79292+ local_sub_unchecked(length, &tail_page->write);
79293 }
79294
79295 /*
79296@@ -2132,7 +2132,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
79297 * about it.
79298 */
79299 if (unlikely(next_page == commit_page)) {
79300- local_inc(&cpu_buffer->commit_overrun);
79301+ local_inc_unchecked(&cpu_buffer->commit_overrun);
79302 goto out_reset;
79303 }
79304
79305@@ -2188,7 +2188,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
79306 cpu_buffer->tail_page) &&
79307 (cpu_buffer->commit_page ==
79308 cpu_buffer->reader_page))) {
79309- local_inc(&cpu_buffer->commit_overrun);
79310+ local_inc_unchecked(&cpu_buffer->commit_overrun);
79311 goto out_reset;
79312 }
79313 }
79314@@ -2236,7 +2236,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
79315 length += RB_LEN_TIME_EXTEND;
79316
79317 tail_page = cpu_buffer->tail_page;
79318- write = local_add_return(length, &tail_page->write);
79319+ write = local_add_return_unchecked(length, &tail_page->write);
79320
79321 /* set write to only the index of the write */
79322 write &= RB_WRITE_MASK;
79323@@ -2253,7 +2253,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
79324 kmemcheck_annotate_bitfield(event, bitfield);
79325 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
79326
79327- local_inc(&tail_page->entries);
79328+ local_inc_unchecked(&tail_page->entries);
79329
79330 /*
79331 * If this is the first commit on the page, then update
79332@@ -2286,7 +2286,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
79333
79334 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
79335 unsigned long write_mask =
79336- local_read(&bpage->write) & ~RB_WRITE_MASK;
79337+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
79338 unsigned long event_length = rb_event_length(event);
79339 /*
79340 * This is on the tail page. It is possible that
79341@@ -2296,7 +2296,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
79342 */
79343 old_index += write_mask;
79344 new_index += write_mask;
79345- index = local_cmpxchg(&bpage->write, old_index, new_index);
79346+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
79347 if (index == old_index) {
79348 /* update counters */
79349 local_sub(event_length, &cpu_buffer->entries_bytes);
79350@@ -2670,7 +2670,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
79351
79352 /* Do the likely case first */
79353 if (likely(bpage->page == (void *)addr)) {
79354- local_dec(&bpage->entries);
79355+ local_dec_unchecked(&bpage->entries);
79356 return;
79357 }
79358
79359@@ -2682,7 +2682,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
79360 start = bpage;
79361 do {
79362 if (bpage->page == (void *)addr) {
79363- local_dec(&bpage->entries);
79364+ local_dec_unchecked(&bpage->entries);
79365 return;
79366 }
79367 rb_inc_page(cpu_buffer, &bpage);
79368@@ -2964,7 +2964,7 @@ static inline unsigned long
79369 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
79370 {
79371 return local_read(&cpu_buffer->entries) -
79372- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
79373+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
79374 }
79375
79376 /**
79377@@ -3053,7 +3053,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
79378 return 0;
79379
79380 cpu_buffer = buffer->buffers[cpu];
79381- ret = local_read(&cpu_buffer->overrun);
79382+ ret = local_read_unchecked(&cpu_buffer->overrun);
79383
79384 return ret;
79385 }
79386@@ -3076,7 +3076,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
79387 return 0;
79388
79389 cpu_buffer = buffer->buffers[cpu];
79390- ret = local_read(&cpu_buffer->commit_overrun);
79391+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
79392
79393 return ret;
79394 }
79395@@ -3161,7 +3161,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
79396 /* if you care about this being correct, lock the buffer */
79397 for_each_buffer_cpu(buffer, cpu) {
79398 cpu_buffer = buffer->buffers[cpu];
79399- overruns += local_read(&cpu_buffer->overrun);
79400+ overruns += local_read_unchecked(&cpu_buffer->overrun);
79401 }
79402
79403 return overruns;
79404@@ -3337,8 +3337,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
79405 /*
79406 * Reset the reader page to size zero.
79407 */
79408- local_set(&cpu_buffer->reader_page->write, 0);
79409- local_set(&cpu_buffer->reader_page->entries, 0);
79410+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
79411+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
79412 local_set(&cpu_buffer->reader_page->page->commit, 0);
79413 cpu_buffer->reader_page->real_end = 0;
79414
79415@@ -3372,7 +3372,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
79416 * want to compare with the last_overrun.
79417 */
79418 smp_mb();
79419- overwrite = local_read(&(cpu_buffer->overrun));
79420+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
79421
79422 /*
79423 * Here's the tricky part.
79424@@ -3942,8 +3942,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
79425
79426 cpu_buffer->head_page
79427 = list_entry(cpu_buffer->pages, struct buffer_page, list);
79428- local_set(&cpu_buffer->head_page->write, 0);
79429- local_set(&cpu_buffer->head_page->entries, 0);
79430+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
79431+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
79432 local_set(&cpu_buffer->head_page->page->commit, 0);
79433
79434 cpu_buffer->head_page->read = 0;
79435@@ -3953,14 +3953,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
79436
79437 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
79438 INIT_LIST_HEAD(&cpu_buffer->new_pages);
79439- local_set(&cpu_buffer->reader_page->write, 0);
79440- local_set(&cpu_buffer->reader_page->entries, 0);
79441+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
79442+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
79443 local_set(&cpu_buffer->reader_page->page->commit, 0);
79444 cpu_buffer->reader_page->read = 0;
79445
79446 local_set(&cpu_buffer->entries_bytes, 0);
79447- local_set(&cpu_buffer->overrun, 0);
79448- local_set(&cpu_buffer->commit_overrun, 0);
79449+ local_set_unchecked(&cpu_buffer->overrun, 0);
79450+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
79451 local_set(&cpu_buffer->dropped_events, 0);
79452 local_set(&cpu_buffer->entries, 0);
79453 local_set(&cpu_buffer->committing, 0);
79454@@ -4364,8 +4364,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
79455 rb_init_page(bpage);
79456 bpage = reader->page;
79457 reader->page = *data_page;
79458- local_set(&reader->write, 0);
79459- local_set(&reader->entries, 0);
79460+ local_set_unchecked(&reader->write, 0);
79461+ local_set_unchecked(&reader->entries, 0);
79462 reader->read = 0;
79463 *data_page = bpage;
79464
79465diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
79466index 3f28192..a29e8b0 100644
79467--- a/kernel/trace/trace.c
79468+++ b/kernel/trace/trace.c
79469@@ -2893,7 +2893,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
79470 return 0;
79471 }
79472
79473-int set_tracer_flag(unsigned int mask, int enabled)
79474+int set_tracer_flag(unsigned long mask, int enabled)
79475 {
79476 /* do nothing if flag is already set */
79477 if (!!(trace_flags & mask) == !!enabled)
79478@@ -4637,10 +4637,9 @@ static const struct file_operations tracing_dyn_info_fops = {
79479 };
79480 #endif
79481
79482-static struct dentry *d_tracer;
79483-
79484 struct dentry *tracing_init_dentry(void)
79485 {
79486+ static struct dentry *d_tracer;
79487 static int once;
79488
79489 if (d_tracer)
79490@@ -4660,10 +4659,9 @@ struct dentry *tracing_init_dentry(void)
79491 return d_tracer;
79492 }
79493
79494-static struct dentry *d_percpu;
79495-
79496 static struct dentry *tracing_dentry_percpu(void)
79497 {
79498+ static struct dentry *d_percpu;
79499 static int once;
79500 struct dentry *d_tracer;
79501
79502diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
79503index 2081971..09f861e 100644
79504--- a/kernel/trace/trace.h
79505+++ b/kernel/trace/trace.h
79506@@ -948,7 +948,7 @@ extern const char *__stop___trace_bprintk_fmt[];
79507 void trace_printk_init_buffers(void);
79508 void trace_printk_start_comm(void);
79509 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
79510-int set_tracer_flag(unsigned int mask, int enabled);
79511+int set_tracer_flag(unsigned long mask, int enabled);
79512
79513 #undef FTRACE_ENTRY
79514 #define FTRACE_ENTRY(call, struct_name, id, tstruct, print, filter) \
79515diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
79516index 57e9b28..eebe41c 100644
79517--- a/kernel/trace/trace_events.c
79518+++ b/kernel/trace/trace_events.c
79519@@ -1329,10 +1329,6 @@ static LIST_HEAD(ftrace_module_file_list);
79520 struct ftrace_module_file_ops {
79521 struct list_head list;
79522 struct module *mod;
79523- struct file_operations id;
79524- struct file_operations enable;
79525- struct file_operations format;
79526- struct file_operations filter;
79527 };
79528
79529 static struct ftrace_module_file_ops *
79530@@ -1353,17 +1349,12 @@ trace_create_file_ops(struct module *mod)
79531
79532 file_ops->mod = mod;
79533
79534- file_ops->id = ftrace_event_id_fops;
79535- file_ops->id.owner = mod;
79536-
79537- file_ops->enable = ftrace_enable_fops;
79538- file_ops->enable.owner = mod;
79539-
79540- file_ops->filter = ftrace_event_filter_fops;
79541- file_ops->filter.owner = mod;
79542-
79543- file_ops->format = ftrace_event_format_fops;
79544- file_ops->format.owner = mod;
79545+ pax_open_kernel();
79546+ mod->trace_id.owner = mod;
79547+ mod->trace_enable.owner = mod;
79548+ mod->trace_filter.owner = mod;
79549+ mod->trace_format.owner = mod;
79550+ pax_close_kernel();
79551
79552 list_add(&file_ops->list, &ftrace_module_file_list);
79553
79554@@ -1387,8 +1378,8 @@ static void trace_module_add_events(struct module *mod)
79555
79556 for_each_event(call, start, end) {
79557 __trace_add_event_call(*call, mod,
79558- &file_ops->id, &file_ops->enable,
79559- &file_ops->filter, &file_ops->format);
79560+ &mod->trace_id, &mod->trace_enable,
79561+ &mod->trace_filter, &mod->trace_format);
79562 }
79563 }
79564
79565diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
79566index fd3c8aa..5f324a6 100644
79567--- a/kernel/trace/trace_mmiotrace.c
79568+++ b/kernel/trace/trace_mmiotrace.c
79569@@ -24,7 +24,7 @@ struct header_iter {
79570 static struct trace_array *mmio_trace_array;
79571 static bool overrun_detected;
79572 static unsigned long prev_overruns;
79573-static atomic_t dropped_count;
79574+static atomic_unchecked_t dropped_count;
79575
79576 static void mmio_reset_data(struct trace_array *tr)
79577 {
79578@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
79579
79580 static unsigned long count_overruns(struct trace_iterator *iter)
79581 {
79582- unsigned long cnt = atomic_xchg(&dropped_count, 0);
79583+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
79584 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
79585
79586 if (over > prev_overruns)
79587@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
79588 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
79589 sizeof(*entry), 0, pc);
79590 if (!event) {
79591- atomic_inc(&dropped_count);
79592+ atomic_inc_unchecked(&dropped_count);
79593 return;
79594 }
79595 entry = ring_buffer_event_data(event);
79596@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
79597 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
79598 sizeof(*entry), 0, pc);
79599 if (!event) {
79600- atomic_inc(&dropped_count);
79601+ atomic_inc_unchecked(&dropped_count);
79602 return;
79603 }
79604 entry = ring_buffer_event_data(event);
79605diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
79606index 697e88d..1a79993 100644
79607--- a/kernel/trace/trace_output.c
79608+++ b/kernel/trace/trace_output.c
79609@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
79610
79611 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
79612 if (!IS_ERR(p)) {
79613- p = mangle_path(s->buffer + s->len, p, "\n");
79614+ p = mangle_path(s->buffer + s->len, p, "\n\\");
79615 if (p) {
79616 s->len = p - s->buffer;
79617 return 1;
79618@@ -851,14 +851,16 @@ int register_ftrace_event(struct trace_event *event)
79619 goto out;
79620 }
79621
79622+ pax_open_kernel();
79623 if (event->funcs->trace == NULL)
79624- event->funcs->trace = trace_nop_print;
79625+ *(void **)&event->funcs->trace = trace_nop_print;
79626 if (event->funcs->raw == NULL)
79627- event->funcs->raw = trace_nop_print;
79628+ *(void **)&event->funcs->raw = trace_nop_print;
79629 if (event->funcs->hex == NULL)
79630- event->funcs->hex = trace_nop_print;
79631+ *(void **)&event->funcs->hex = trace_nop_print;
79632 if (event->funcs->binary == NULL)
79633- event->funcs->binary = trace_nop_print;
79634+ *(void **)&event->funcs->binary = trace_nop_print;
79635+ pax_close_kernel();
79636
79637 key = event->type & (EVENT_HASHSIZE - 1);
79638
79639diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
79640index b20428c..4845a10 100644
79641--- a/kernel/trace/trace_stack.c
79642+++ b/kernel/trace/trace_stack.c
79643@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
79644 return;
79645
79646 /* we do not handle interrupt stacks yet */
79647- if (!object_is_on_stack(stack))
79648+ if (!object_starts_on_stack(stack))
79649 return;
79650
79651 local_irq_save(flags);
79652diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
79653index e134d8f..a018cdd 100644
79654--- a/kernel/user_namespace.c
79655+++ b/kernel/user_namespace.c
79656@@ -853,7 +853,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
79657 if (atomic_read(&current->mm->mm_users) > 1)
79658 return -EINVAL;
79659
79660- if (current->fs->users != 1)
79661+ if (atomic_read(&current->fs->users) != 1)
79662 return -EINVAL;
79663
79664 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
79665diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
79666index 4f69f9a..7c6f8f8 100644
79667--- a/kernel/utsname_sysctl.c
79668+++ b/kernel/utsname_sysctl.c
79669@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
79670 static int proc_do_uts_string(ctl_table *table, int write,
79671 void __user *buffer, size_t *lenp, loff_t *ppos)
79672 {
79673- struct ctl_table uts_table;
79674+ ctl_table_no_const uts_table;
79675 int r;
79676 memcpy(&uts_table, table, sizeof(uts_table));
79677 uts_table.data = get_uts(table, write);
79678diff --git a/kernel/watchdog.c b/kernel/watchdog.c
79679index 4a94467..80a6f9c 100644
79680--- a/kernel/watchdog.c
79681+++ b/kernel/watchdog.c
79682@@ -526,7 +526,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
79683 }
79684 #endif /* CONFIG_SYSCTL */
79685
79686-static struct smp_hotplug_thread watchdog_threads = {
79687+static struct smp_hotplug_thread watchdog_threads __read_only = {
79688 .store = &softlockup_watchdog,
79689 .thread_should_run = watchdog_should_run,
79690 .thread_fn = watchdog,
79691diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
79692index 28be08c..47bab92 100644
79693--- a/lib/Kconfig.debug
79694+++ b/lib/Kconfig.debug
79695@@ -549,7 +549,7 @@ config DEBUG_MUTEXES
79696
79697 config DEBUG_LOCK_ALLOC
79698 bool "Lock debugging: detect incorrect freeing of live locks"
79699- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
79700+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
79701 select DEBUG_SPINLOCK
79702 select DEBUG_MUTEXES
79703 select LOCKDEP
79704@@ -563,7 +563,7 @@ config DEBUG_LOCK_ALLOC
79705
79706 config PROVE_LOCKING
79707 bool "Lock debugging: prove locking correctness"
79708- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
79709+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
79710 select LOCKDEP
79711 select DEBUG_SPINLOCK
79712 select DEBUG_MUTEXES
79713@@ -614,7 +614,7 @@ config LOCKDEP
79714
79715 config LOCK_STAT
79716 bool "Lock usage statistics"
79717- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
79718+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
79719 select LOCKDEP
79720 select DEBUG_SPINLOCK
79721 select DEBUG_MUTEXES
79722@@ -1282,6 +1282,7 @@ config LATENCYTOP
79723 depends on DEBUG_KERNEL
79724 depends on STACKTRACE_SUPPORT
79725 depends on PROC_FS
79726+ depends on !GRKERNSEC_HIDESYM
79727 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
79728 select KALLSYMS
79729 select KALLSYMS_ALL
79730@@ -1310,7 +1311,7 @@ config INTERVAL_TREE_TEST
79731
79732 config PROVIDE_OHCI1394_DMA_INIT
79733 bool "Remote debugging over FireWire early on boot"
79734- depends on PCI && X86
79735+ depends on PCI && X86 && !GRKERNSEC
79736 help
79737 If you want to debug problems which hang or crash the kernel early
79738 on boot and the crashing machine has a FireWire port, you can use
79739@@ -1339,7 +1340,7 @@ config PROVIDE_OHCI1394_DMA_INIT
79740
79741 config FIREWIRE_OHCI_REMOTE_DMA
79742 bool "Remote debugging over FireWire with firewire-ohci"
79743- depends on FIREWIRE_OHCI
79744+ depends on FIREWIRE_OHCI && !GRKERNSEC
79745 help
79746 This option lets you use the FireWire bus for remote debugging
79747 with help of the firewire-ohci driver. It enables unfiltered
79748diff --git a/lib/Makefile b/lib/Makefile
79749index 6e2cc56..9b13738 100644
79750--- a/lib/Makefile
79751+++ b/lib/Makefile
79752@@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
79753
79754 obj-$(CONFIG_BTREE) += btree.o
79755 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
79756-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
79757+obj-y += list_debug.o
79758 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
79759
79760 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
79761diff --git a/lib/bitmap.c b/lib/bitmap.c
79762index 06f7e4f..f3cf2b0 100644
79763--- a/lib/bitmap.c
79764+++ b/lib/bitmap.c
79765@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
79766 {
79767 int c, old_c, totaldigits, ndigits, nchunks, nbits;
79768 u32 chunk;
79769- const char __user __force *ubuf = (const char __user __force *)buf;
79770+ const char __user *ubuf = (const char __force_user *)buf;
79771
79772 bitmap_zero(maskp, nmaskbits);
79773
79774@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
79775 {
79776 if (!access_ok(VERIFY_READ, ubuf, ulen))
79777 return -EFAULT;
79778- return __bitmap_parse((const char __force *)ubuf,
79779+ return __bitmap_parse((const char __force_kernel *)ubuf,
79780 ulen, 1, maskp, nmaskbits);
79781
79782 }
79783@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
79784 {
79785 unsigned a, b;
79786 int c, old_c, totaldigits;
79787- const char __user __force *ubuf = (const char __user __force *)buf;
79788+ const char __user *ubuf = (const char __force_user *)buf;
79789 int exp_digit, in_range;
79790
79791 totaldigits = c = 0;
79792@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
79793 {
79794 if (!access_ok(VERIFY_READ, ubuf, ulen))
79795 return -EFAULT;
79796- return __bitmap_parselist((const char __force *)ubuf,
79797+ return __bitmap_parselist((const char __force_kernel *)ubuf,
79798 ulen, 1, maskp, nmaskbits);
79799 }
79800 EXPORT_SYMBOL(bitmap_parselist_user);
79801diff --git a/lib/bug.c b/lib/bug.c
79802index 1686034..a9c00c8 100644
79803--- a/lib/bug.c
79804+++ b/lib/bug.c
79805@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
79806 return BUG_TRAP_TYPE_NONE;
79807
79808 bug = find_bug(bugaddr);
79809+ if (!bug)
79810+ return BUG_TRAP_TYPE_NONE;
79811
79812 file = NULL;
79813 line = 0;
79814diff --git a/lib/debugobjects.c b/lib/debugobjects.c
79815index 37061ed..da83f48 100644
79816--- a/lib/debugobjects.c
79817+++ b/lib/debugobjects.c
79818@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
79819 if (limit > 4)
79820 return;
79821
79822- is_on_stack = object_is_on_stack(addr);
79823+ is_on_stack = object_starts_on_stack(addr);
79824 if (is_on_stack == onstack)
79825 return;
79826
79827diff --git a/lib/devres.c b/lib/devres.c
79828index 8235331..5881053 100644
79829--- a/lib/devres.c
79830+++ b/lib/devres.c
79831@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
79832 void devm_iounmap(struct device *dev, void __iomem *addr)
79833 {
79834 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
79835- (void *)addr));
79836+ (void __force *)addr));
79837 iounmap(addr);
79838 }
79839 EXPORT_SYMBOL(devm_iounmap);
79840@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
79841 {
79842 ioport_unmap(addr);
79843 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
79844- devm_ioport_map_match, (void *)addr));
79845+ devm_ioport_map_match, (void __force *)addr));
79846 }
79847 EXPORT_SYMBOL(devm_ioport_unmap);
79848 #endif /* CONFIG_HAS_IOPORT */
79849diff --git a/lib/div64.c b/lib/div64.c
79850index a163b6c..9618fa5 100644
79851--- a/lib/div64.c
79852+++ b/lib/div64.c
79853@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
79854 EXPORT_SYMBOL(__div64_32);
79855
79856 #ifndef div_s64_rem
79857-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
79858+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
79859 {
79860 u64 quotient;
79861
79862@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
79863 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
79864 */
79865 #ifndef div64_u64
79866-u64 div64_u64(u64 dividend, u64 divisor)
79867+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
79868 {
79869 u32 high = divisor >> 32;
79870 u64 quot;
79871diff --git a/lib/dma-debug.c b/lib/dma-debug.c
79872index d87a17a..ac0d79a 100644
79873--- a/lib/dma-debug.c
79874+++ b/lib/dma-debug.c
79875@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
79876
79877 void dma_debug_add_bus(struct bus_type *bus)
79878 {
79879- struct notifier_block *nb;
79880+ notifier_block_no_const *nb;
79881
79882 if (global_disable)
79883 return;
79884@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
79885
79886 static void check_for_stack(struct device *dev, void *addr)
79887 {
79888- if (object_is_on_stack(addr))
79889+ if (object_starts_on_stack(addr))
79890 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
79891 "stack [addr=%p]\n", addr);
79892 }
79893diff --git a/lib/inflate.c b/lib/inflate.c
79894index 013a761..c28f3fc 100644
79895--- a/lib/inflate.c
79896+++ b/lib/inflate.c
79897@@ -269,7 +269,7 @@ static void free(void *where)
79898 malloc_ptr = free_mem_ptr;
79899 }
79900 #else
79901-#define malloc(a) kmalloc(a, GFP_KERNEL)
79902+#define malloc(a) kmalloc((a), GFP_KERNEL)
79903 #define free(a) kfree(a)
79904 #endif
79905
79906diff --git a/lib/ioremap.c b/lib/ioremap.c
79907index 0c9216c..863bd89 100644
79908--- a/lib/ioremap.c
79909+++ b/lib/ioremap.c
79910@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
79911 unsigned long next;
79912
79913 phys_addr -= addr;
79914- pmd = pmd_alloc(&init_mm, pud, addr);
79915+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
79916 if (!pmd)
79917 return -ENOMEM;
79918 do {
79919@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
79920 unsigned long next;
79921
79922 phys_addr -= addr;
79923- pud = pud_alloc(&init_mm, pgd, addr);
79924+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
79925 if (!pud)
79926 return -ENOMEM;
79927 do {
79928diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
79929index bd2bea9..6b3c95e 100644
79930--- a/lib/is_single_threaded.c
79931+++ b/lib/is_single_threaded.c
79932@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
79933 struct task_struct *p, *t;
79934 bool ret;
79935
79936+ if (!mm)
79937+ return true;
79938+
79939 if (atomic_read(&task->signal->live) != 1)
79940 return false;
79941
79942diff --git a/lib/kobject.c b/lib/kobject.c
79943index a654866..a4fd13d 100644
79944--- a/lib/kobject.c
79945+++ b/lib/kobject.c
79946@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
79947
79948
79949 static DEFINE_SPINLOCK(kobj_ns_type_lock);
79950-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
79951+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
79952
79953-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
79954+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
79955 {
79956 enum kobj_ns_type type = ops->type;
79957 int error;
79958diff --git a/lib/list_debug.c b/lib/list_debug.c
79959index c24c2f7..06e070b 100644
79960--- a/lib/list_debug.c
79961+++ b/lib/list_debug.c
79962@@ -11,7 +11,9 @@
79963 #include <linux/bug.h>
79964 #include <linux/kernel.h>
79965 #include <linux/rculist.h>
79966+#include <linux/mm.h>
79967
79968+#ifdef CONFIG_DEBUG_LIST
79969 /*
79970 * Insert a new entry between two known consecutive entries.
79971 *
79972@@ -19,21 +21,32 @@
79973 * the prev/next entries already!
79974 */
79975
79976-void __list_add(struct list_head *new,
79977- struct list_head *prev,
79978- struct list_head *next)
79979+static bool __list_add_debug(struct list_head *new,
79980+ struct list_head *prev,
79981+ struct list_head *next)
79982 {
79983- WARN(next->prev != prev,
79984+ if (WARN(next->prev != prev,
79985 "list_add corruption. next->prev should be "
79986 "prev (%p), but was %p. (next=%p).\n",
79987- prev, next->prev, next);
79988- WARN(prev->next != next,
79989+ prev, next->prev, next) ||
79990+ WARN(prev->next != next,
79991 "list_add corruption. prev->next should be "
79992 "next (%p), but was %p. (prev=%p).\n",
79993- next, prev->next, prev);
79994- WARN(new == prev || new == next,
79995- "list_add double add: new=%p, prev=%p, next=%p.\n",
79996- new, prev, next);
79997+ next, prev->next, prev) ||
79998+ WARN(new == prev || new == next,
79999+ "list_add double add: new=%p, prev=%p, next=%p.\n",
80000+ new, prev, next))
80001+ return false;
80002+ return true;
80003+}
80004+
80005+void __list_add(struct list_head *new,
80006+ struct list_head *prev,
80007+ struct list_head *next)
80008+{
80009+ if (!__list_add_debug(new, prev, next))
80010+ return;
80011+
80012 next->prev = new;
80013 new->next = next;
80014 new->prev = prev;
80015@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
80016 }
80017 EXPORT_SYMBOL(__list_add);
80018
80019-void __list_del_entry(struct list_head *entry)
80020+static bool __list_del_entry_debug(struct list_head *entry)
80021 {
80022 struct list_head *prev, *next;
80023
80024@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
80025 WARN(next->prev != entry,
80026 "list_del corruption. next->prev should be %p, "
80027 "but was %p\n", entry, next->prev))
80028+ return false;
80029+ return true;
80030+}
80031+
80032+void __list_del_entry(struct list_head *entry)
80033+{
80034+ if (!__list_del_entry_debug(entry))
80035 return;
80036
80037- __list_del(prev, next);
80038+ __list_del(entry->prev, entry->next);
80039 }
80040 EXPORT_SYMBOL(__list_del_entry);
80041
80042@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
80043 void __list_add_rcu(struct list_head *new,
80044 struct list_head *prev, struct list_head *next)
80045 {
80046- WARN(next->prev != prev,
80047- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
80048- prev, next->prev, next);
80049- WARN(prev->next != next,
80050- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
80051- next, prev->next, prev);
80052+ if (!__list_add_debug(new, prev, next))
80053+ return;
80054+
80055 new->next = next;
80056 new->prev = prev;
80057 rcu_assign_pointer(list_next_rcu(prev), new);
80058 next->prev = new;
80059 }
80060 EXPORT_SYMBOL(__list_add_rcu);
80061+#endif
80062+
80063+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
80064+{
80065+#ifdef CONFIG_DEBUG_LIST
80066+ if (!__list_add_debug(new, prev, next))
80067+ return;
80068+#endif
80069+
80070+ pax_open_kernel();
80071+ next->prev = new;
80072+ new->next = next;
80073+ new->prev = prev;
80074+ prev->next = new;
80075+ pax_close_kernel();
80076+}
80077+EXPORT_SYMBOL(__pax_list_add);
80078+
80079+void pax_list_del(struct list_head *entry)
80080+{
80081+#ifdef CONFIG_DEBUG_LIST
80082+ if (!__list_del_entry_debug(entry))
80083+ return;
80084+#endif
80085+
80086+ pax_open_kernel();
80087+ __list_del(entry->prev, entry->next);
80088+ entry->next = LIST_POISON1;
80089+ entry->prev = LIST_POISON2;
80090+ pax_close_kernel();
80091+}
80092+EXPORT_SYMBOL(pax_list_del);
80093+
80094+void pax_list_del_init(struct list_head *entry)
80095+{
80096+ pax_open_kernel();
80097+ __list_del(entry->prev, entry->next);
80098+ INIT_LIST_HEAD(entry);
80099+ pax_close_kernel();
80100+}
80101+EXPORT_SYMBOL(pax_list_del_init);
80102+
80103+void __pax_list_add_rcu(struct list_head *new,
80104+ struct list_head *prev, struct list_head *next)
80105+{
80106+#ifdef CONFIG_DEBUG_LIST
80107+ if (!__list_add_debug(new, prev, next))
80108+ return;
80109+#endif
80110+
80111+ pax_open_kernel();
80112+ new->next = next;
80113+ new->prev = prev;
80114+ rcu_assign_pointer(list_next_rcu(prev), new);
80115+ next->prev = new;
80116+ pax_close_kernel();
80117+}
80118+EXPORT_SYMBOL(__pax_list_add_rcu);
80119+
80120+void pax_list_del_rcu(struct list_head *entry)
80121+{
80122+#ifdef CONFIG_DEBUG_LIST
80123+ if (!__list_del_entry_debug(entry))
80124+ return;
80125+#endif
80126+
80127+ pax_open_kernel();
80128+ __list_del(entry->prev, entry->next);
80129+ entry->next = LIST_POISON1;
80130+ entry->prev = LIST_POISON2;
80131+ pax_close_kernel();
80132+}
80133+EXPORT_SYMBOL(pax_list_del_rcu);
80134diff --git a/lib/radix-tree.c b/lib/radix-tree.c
80135index e796429..6e38f9f 100644
80136--- a/lib/radix-tree.c
80137+++ b/lib/radix-tree.c
80138@@ -92,7 +92,7 @@ struct radix_tree_preload {
80139 int nr;
80140 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
80141 };
80142-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
80143+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
80144
80145 static inline void *ptr_to_indirect(void *ptr)
80146 {
80147diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
80148index bb2b201..46abaf9 100644
80149--- a/lib/strncpy_from_user.c
80150+++ b/lib/strncpy_from_user.c
80151@@ -21,7 +21,7 @@
80152 */
80153 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
80154 {
80155- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80156+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80157 long res = 0;
80158
80159 /*
80160diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
80161index a28df52..3d55877 100644
80162--- a/lib/strnlen_user.c
80163+++ b/lib/strnlen_user.c
80164@@ -26,7 +26,7 @@
80165 */
80166 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
80167 {
80168- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80169+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80170 long align, res = 0;
80171 unsigned long c;
80172
80173diff --git a/lib/swiotlb.c b/lib/swiotlb.c
80174index d23762e..e21eab2 100644
80175--- a/lib/swiotlb.c
80176+++ b/lib/swiotlb.c
80177@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
80178
80179 void
80180 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
80181- dma_addr_t dev_addr)
80182+ dma_addr_t dev_addr, struct dma_attrs *attrs)
80183 {
80184 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
80185
80186diff --git a/lib/vsprintf.c b/lib/vsprintf.c
80187index 0d62fd7..b7bc911 100644
80188--- a/lib/vsprintf.c
80189+++ b/lib/vsprintf.c
80190@@ -16,6 +16,9 @@
80191 * - scnprintf and vscnprintf
80192 */
80193
80194+#ifdef CONFIG_GRKERNSEC_HIDESYM
80195+#define __INCLUDED_BY_HIDESYM 1
80196+#endif
80197 #include <stdarg.h>
80198 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
80199 #include <linux/types.h>
80200@@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
80201 return number(buf, end, *(const netdev_features_t *)addr, spec);
80202 }
80203
80204+#ifdef CONFIG_GRKERNSEC_HIDESYM
80205+int kptr_restrict __read_mostly = 2;
80206+#else
80207 int kptr_restrict __read_mostly;
80208+#endif
80209
80210 /*
80211 * Show a '%p' thing. A kernel extension is that the '%p' is followed
80212@@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
80213 * - 'S' For symbolic direct pointers with offset
80214 * - 's' For symbolic direct pointers without offset
80215 * - 'B' For backtraced symbolic direct pointers with offset
80216+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
80217+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
80218 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
80219 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
80220 * - 'M' For a 6-byte MAC address, it prints the address in the
80221@@ -1044,12 +1053,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80222
80223 if (!ptr && *fmt != 'K') {
80224 /*
80225- * Print (null) with the same width as a pointer so it makes
80226+ * Print (nil) with the same width as a pointer so it makes
80227 * tabular output look nice.
80228 */
80229 if (spec.field_width == -1)
80230 spec.field_width = default_width;
80231- return string(buf, end, "(null)", spec);
80232+ return string(buf, end, "(nil)", spec);
80233 }
80234
80235 switch (*fmt) {
80236@@ -1059,6 +1068,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80237 /* Fallthrough */
80238 case 'S':
80239 case 's':
80240+#ifdef CONFIG_GRKERNSEC_HIDESYM
80241+ break;
80242+#else
80243+ return symbol_string(buf, end, ptr, spec, *fmt);
80244+#endif
80245+ case 'A':
80246 case 'B':
80247 return symbol_string(buf, end, ptr, spec, *fmt);
80248 case 'R':
80249@@ -1099,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80250 va_end(va);
80251 return buf;
80252 }
80253+ case 'P':
80254+ break;
80255 case 'K':
80256 /*
80257 * %pK cannot be used in IRQ context because its test
80258@@ -1128,6 +1145,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80259 return number(buf, end,
80260 (unsigned long long) *((phys_addr_t *)ptr), spec);
80261 }
80262+
80263+#ifdef CONFIG_GRKERNSEC_HIDESYM
80264+ /* 'P' = approved pointers to copy to userland,
80265+ as in the /proc/kallsyms case, as we make it display nothing
80266+ for non-root users, and the real contents for root users
80267+ Also ignore 'K' pointers, since we force their NULLing for non-root users
80268+ above
80269+ */
80270+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
80271+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
80272+ dump_stack();
80273+ ptr = NULL;
80274+ }
80275+#endif
80276+
80277 spec.flags |= SMALL;
80278 if (spec.field_width == -1) {
80279 spec.field_width = default_width;
80280@@ -1849,11 +1881,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
80281 typeof(type) value; \
80282 if (sizeof(type) == 8) { \
80283 args = PTR_ALIGN(args, sizeof(u32)); \
80284- *(u32 *)&value = *(u32 *)args; \
80285- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
80286+ *(u32 *)&value = *(const u32 *)args; \
80287+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
80288 } else { \
80289 args = PTR_ALIGN(args, sizeof(type)); \
80290- value = *(typeof(type) *)args; \
80291+ value = *(const typeof(type) *)args; \
80292 } \
80293 args += sizeof(type); \
80294 value; \
80295@@ -1916,7 +1948,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
80296 case FORMAT_TYPE_STR: {
80297 const char *str_arg = args;
80298 args += strlen(str_arg) + 1;
80299- str = string(str, end, (char *)str_arg, spec);
80300+ str = string(str, end, str_arg, spec);
80301 break;
80302 }
80303
80304diff --git a/localversion-grsec b/localversion-grsec
80305new file mode 100644
80306index 0000000..7cd6065
80307--- /dev/null
80308+++ b/localversion-grsec
80309@@ -0,0 +1 @@
80310+-grsec
80311diff --git a/mm/Kconfig b/mm/Kconfig
80312index 3bea74f..e821c99 100644
80313--- a/mm/Kconfig
80314+++ b/mm/Kconfig
80315@@ -311,10 +311,10 @@ config KSM
80316 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
80317
80318 config DEFAULT_MMAP_MIN_ADDR
80319- int "Low address space to protect from user allocation"
80320+ int "Low address space to protect from user allocation"
80321 depends on MMU
80322- default 4096
80323- help
80324+ default 65536
80325+ help
80326 This is the portion of low virtual memory which should be protected
80327 from userspace allocation. Keeping a user from writing to low pages
80328 can help reduce the impact of kernel NULL pointer bugs.
80329@@ -345,7 +345,7 @@ config MEMORY_FAILURE
80330
80331 config HWPOISON_INJECT
80332 tristate "HWPoison pages injector"
80333- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
80334+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
80335 select PROC_PAGE_MONITOR
80336
80337 config NOMMU_INITIAL_TRIM_EXCESS
80338diff --git a/mm/filemap.c b/mm/filemap.c
80339index e1979fd..dda5120 100644
80340--- a/mm/filemap.c
80341+++ b/mm/filemap.c
80342@@ -1748,7 +1748,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
80343 struct address_space *mapping = file->f_mapping;
80344
80345 if (!mapping->a_ops->readpage)
80346- return -ENOEXEC;
80347+ return -ENODEV;
80348 file_accessed(file);
80349 vma->vm_ops = &generic_file_vm_ops;
80350 return 0;
80351@@ -2088,6 +2088,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
80352 *pos = i_size_read(inode);
80353
80354 if (limit != RLIM_INFINITY) {
80355+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
80356 if (*pos >= limit) {
80357 send_sig(SIGXFSZ, current, 0);
80358 return -EFBIG;
80359diff --git a/mm/fremap.c b/mm/fremap.c
80360index 87da359..3f41cb1 100644
80361--- a/mm/fremap.c
80362+++ b/mm/fremap.c
80363@@ -158,6 +158,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
80364 retry:
80365 vma = find_vma(mm, start);
80366
80367+#ifdef CONFIG_PAX_SEGMEXEC
80368+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
80369+ goto out;
80370+#endif
80371+
80372 /*
80373 * Make sure the vma is shared, that it supports prefaulting,
80374 * and that the remapped range is valid and fully within
80375diff --git a/mm/highmem.c b/mm/highmem.c
80376index b32b70c..e512eb0 100644
80377--- a/mm/highmem.c
80378+++ b/mm/highmem.c
80379@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
80380 * So no dangers, even with speculative execution.
80381 */
80382 page = pte_page(pkmap_page_table[i]);
80383+ pax_open_kernel();
80384 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
80385-
80386+ pax_close_kernel();
80387 set_page_address(page, NULL);
80388 need_flush = 1;
80389 }
80390@@ -198,9 +199,11 @@ start:
80391 }
80392 }
80393 vaddr = PKMAP_ADDR(last_pkmap_nr);
80394+
80395+ pax_open_kernel();
80396 set_pte_at(&init_mm, vaddr,
80397 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
80398-
80399+ pax_close_kernel();
80400 pkmap_count[last_pkmap_nr] = 1;
80401 set_page_address(page, (void *)vaddr);
80402
80403diff --git a/mm/hugetlb.c b/mm/hugetlb.c
80404index 1a12f5b..a85b8fc 100644
80405--- a/mm/hugetlb.c
80406+++ b/mm/hugetlb.c
80407@@ -2005,15 +2005,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
80408 struct hstate *h = &default_hstate;
80409 unsigned long tmp;
80410 int ret;
80411+ ctl_table_no_const hugetlb_table;
80412
80413 tmp = h->max_huge_pages;
80414
80415 if (write && h->order >= MAX_ORDER)
80416 return -EINVAL;
80417
80418- table->data = &tmp;
80419- table->maxlen = sizeof(unsigned long);
80420- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
80421+ hugetlb_table = *table;
80422+ hugetlb_table.data = &tmp;
80423+ hugetlb_table.maxlen = sizeof(unsigned long);
80424+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
80425 if (ret)
80426 goto out;
80427
80428@@ -2070,15 +2072,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
80429 struct hstate *h = &default_hstate;
80430 unsigned long tmp;
80431 int ret;
80432+ ctl_table_no_const hugetlb_table;
80433
80434 tmp = h->nr_overcommit_huge_pages;
80435
80436 if (write && h->order >= MAX_ORDER)
80437 return -EINVAL;
80438
80439- table->data = &tmp;
80440- table->maxlen = sizeof(unsigned long);
80441- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
80442+ hugetlb_table = *table;
80443+ hugetlb_table.data = &tmp;
80444+ hugetlb_table.maxlen = sizeof(unsigned long);
80445+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
80446 if (ret)
80447 goto out;
80448
80449@@ -2512,6 +2516,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
80450 return 1;
80451 }
80452
80453+#ifdef CONFIG_PAX_SEGMEXEC
80454+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
80455+{
80456+ struct mm_struct *mm = vma->vm_mm;
80457+ struct vm_area_struct *vma_m;
80458+ unsigned long address_m;
80459+ pte_t *ptep_m;
80460+
80461+ vma_m = pax_find_mirror_vma(vma);
80462+ if (!vma_m)
80463+ return;
80464+
80465+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
80466+ address_m = address + SEGMEXEC_TASK_SIZE;
80467+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
80468+ get_page(page_m);
80469+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
80470+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
80471+}
80472+#endif
80473+
80474 /*
80475 * Hugetlb_cow() should be called with page lock of the original hugepage held.
80476 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
80477@@ -2630,6 +2655,11 @@ retry_avoidcopy:
80478 make_huge_pte(vma, new_page, 1));
80479 page_remove_rmap(old_page);
80480 hugepage_add_new_anon_rmap(new_page, vma, address);
80481+
80482+#ifdef CONFIG_PAX_SEGMEXEC
80483+ pax_mirror_huge_pte(vma, address, new_page);
80484+#endif
80485+
80486 /* Make the old page be freed below */
80487 new_page = old_page;
80488 }
80489@@ -2788,6 +2818,10 @@ retry:
80490 && (vma->vm_flags & VM_SHARED)));
80491 set_huge_pte_at(mm, address, ptep, new_pte);
80492
80493+#ifdef CONFIG_PAX_SEGMEXEC
80494+ pax_mirror_huge_pte(vma, address, page);
80495+#endif
80496+
80497 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
80498 /* Optimization, do the COW without a second fault */
80499 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
80500@@ -2817,6 +2851,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80501 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
80502 struct hstate *h = hstate_vma(vma);
80503
80504+#ifdef CONFIG_PAX_SEGMEXEC
80505+ struct vm_area_struct *vma_m;
80506+#endif
80507+
80508 address &= huge_page_mask(h);
80509
80510 ptep = huge_pte_offset(mm, address);
80511@@ -2830,6 +2868,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80512 VM_FAULT_SET_HINDEX(hstate_index(h));
80513 }
80514
80515+#ifdef CONFIG_PAX_SEGMEXEC
80516+ vma_m = pax_find_mirror_vma(vma);
80517+ if (vma_m) {
80518+ unsigned long address_m;
80519+
80520+ if (vma->vm_start > vma_m->vm_start) {
80521+ address_m = address;
80522+ address -= SEGMEXEC_TASK_SIZE;
80523+ vma = vma_m;
80524+ h = hstate_vma(vma);
80525+ } else
80526+ address_m = address + SEGMEXEC_TASK_SIZE;
80527+
80528+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
80529+ return VM_FAULT_OOM;
80530+ address_m &= HPAGE_MASK;
80531+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
80532+ }
80533+#endif
80534+
80535 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
80536 if (!ptep)
80537 return VM_FAULT_OOM;
80538diff --git a/mm/internal.h b/mm/internal.h
80539index 8562de0..7fdfe92 100644
80540--- a/mm/internal.h
80541+++ b/mm/internal.h
80542@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
80543 * in mm/page_alloc.c
80544 */
80545 extern void __free_pages_bootmem(struct page *page, unsigned int order);
80546+extern void free_compound_page(struct page *page);
80547 extern void prep_compound_page(struct page *page, unsigned long order);
80548 #ifdef CONFIG_MEMORY_FAILURE
80549 extern bool is_free_buddy_page(struct page *page);
80550diff --git a/mm/kmemleak.c b/mm/kmemleak.c
80551index c8d7f31..2dbeffd 100644
80552--- a/mm/kmemleak.c
80553+++ b/mm/kmemleak.c
80554@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
80555
80556 for (i = 0; i < object->trace_len; i++) {
80557 void *ptr = (void *)object->trace[i];
80558- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
80559+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
80560 }
80561 }
80562
80563@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
80564 return -ENOMEM;
80565 }
80566
80567- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
80568+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
80569 &kmemleak_fops);
80570 if (!dentry)
80571 pr_warning("Failed to create the debugfs kmemleak file\n");
80572diff --git a/mm/maccess.c b/mm/maccess.c
80573index d53adf9..03a24bf 100644
80574--- a/mm/maccess.c
80575+++ b/mm/maccess.c
80576@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
80577 set_fs(KERNEL_DS);
80578 pagefault_disable();
80579 ret = __copy_from_user_inatomic(dst,
80580- (__force const void __user *)src, size);
80581+ (const void __force_user *)src, size);
80582 pagefault_enable();
80583 set_fs(old_fs);
80584
80585@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
80586
80587 set_fs(KERNEL_DS);
80588 pagefault_disable();
80589- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
80590+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
80591 pagefault_enable();
80592 set_fs(old_fs);
80593
80594diff --git a/mm/madvise.c b/mm/madvise.c
80595index c58c94b..86ec14e 100644
80596--- a/mm/madvise.c
80597+++ b/mm/madvise.c
80598@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
80599 pgoff_t pgoff;
80600 unsigned long new_flags = vma->vm_flags;
80601
80602+#ifdef CONFIG_PAX_SEGMEXEC
80603+ struct vm_area_struct *vma_m;
80604+#endif
80605+
80606 switch (behavior) {
80607 case MADV_NORMAL:
80608 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
80609@@ -126,6 +130,13 @@ success:
80610 /*
80611 * vm_flags is protected by the mmap_sem held in write mode.
80612 */
80613+
80614+#ifdef CONFIG_PAX_SEGMEXEC
80615+ vma_m = pax_find_mirror_vma(vma);
80616+ if (vma_m)
80617+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
80618+#endif
80619+
80620 vma->vm_flags = new_flags;
80621
80622 out:
80623@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
80624 struct vm_area_struct ** prev,
80625 unsigned long start, unsigned long end)
80626 {
80627+
80628+#ifdef CONFIG_PAX_SEGMEXEC
80629+ struct vm_area_struct *vma_m;
80630+#endif
80631+
80632 *prev = vma;
80633 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
80634 return -EINVAL;
80635@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
80636 zap_page_range(vma, start, end - start, &details);
80637 } else
80638 zap_page_range(vma, start, end - start, NULL);
80639+
80640+#ifdef CONFIG_PAX_SEGMEXEC
80641+ vma_m = pax_find_mirror_vma(vma);
80642+ if (vma_m) {
80643+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
80644+ struct zap_details details = {
80645+ .nonlinear_vma = vma_m,
80646+ .last_index = ULONG_MAX,
80647+ };
80648+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
80649+ } else
80650+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
80651+ }
80652+#endif
80653+
80654 return 0;
80655 }
80656
80657@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
80658 if (end < start)
80659 goto out;
80660
80661+#ifdef CONFIG_PAX_SEGMEXEC
80662+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
80663+ if (end > SEGMEXEC_TASK_SIZE)
80664+ goto out;
80665+ } else
80666+#endif
80667+
80668+ if (end > TASK_SIZE)
80669+ goto out;
80670+
80671 error = 0;
80672 if (end == start)
80673 goto out;
80674diff --git a/mm/memory-failure.c b/mm/memory-failure.c
80675index df0694c..bc95539 100644
80676--- a/mm/memory-failure.c
80677+++ b/mm/memory-failure.c
80678@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
80679
80680 int sysctl_memory_failure_recovery __read_mostly = 1;
80681
80682-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
80683+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
80684
80685 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
80686
80687@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
80688 pfn, t->comm, t->pid);
80689 si.si_signo = SIGBUS;
80690 si.si_errno = 0;
80691- si.si_addr = (void *)addr;
80692+ si.si_addr = (void __user *)addr;
80693 #ifdef __ARCH_SI_TRAPNO
80694 si.si_trapno = trapno;
80695 #endif
80696@@ -760,7 +760,7 @@ static struct page_state {
80697 unsigned long res;
80698 char *msg;
80699 int (*action)(struct page *p, unsigned long pfn);
80700-} error_states[] = {
80701+} __do_const error_states[] = {
80702 { reserved, reserved, "reserved kernel", me_kernel },
80703 /*
80704 * free pages are specially detected outside this table:
80705@@ -1051,7 +1051,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
80706 nr_pages = 1 << compound_order(hpage);
80707 else /* normal page or thp */
80708 nr_pages = 1;
80709- atomic_long_add(nr_pages, &num_poisoned_pages);
80710+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
80711
80712 /*
80713 * We need/can do nothing about count=0 pages.
80714@@ -1081,7 +1081,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
80715 if (!PageHWPoison(hpage)
80716 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
80717 || (p != hpage && TestSetPageHWPoison(hpage))) {
80718- atomic_long_sub(nr_pages, &num_poisoned_pages);
80719+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
80720 return 0;
80721 }
80722 set_page_hwpoison_huge_page(hpage);
80723@@ -1148,7 +1148,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
80724 }
80725 if (hwpoison_filter(p)) {
80726 if (TestClearPageHWPoison(p))
80727- atomic_long_sub(nr_pages, &num_poisoned_pages);
80728+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
80729 unlock_page(hpage);
80730 put_page(hpage);
80731 return 0;
80732@@ -1350,7 +1350,7 @@ int unpoison_memory(unsigned long pfn)
80733 return 0;
80734 }
80735 if (TestClearPageHWPoison(p))
80736- atomic_long_sub(nr_pages, &num_poisoned_pages);
80737+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
80738 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
80739 return 0;
80740 }
80741@@ -1364,7 +1364,7 @@ int unpoison_memory(unsigned long pfn)
80742 */
80743 if (TestClearPageHWPoison(page)) {
80744 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
80745- atomic_long_sub(nr_pages, &num_poisoned_pages);
80746+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
80747 freeit = 1;
80748 if (PageHuge(page))
80749 clear_page_hwpoison_huge_page(page);
80750@@ -1491,7 +1491,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
80751 } else {
80752 set_page_hwpoison_huge_page(hpage);
80753 dequeue_hwpoisoned_huge_page(hpage);
80754- atomic_long_add(1 << compound_trans_order(hpage),
80755+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
80756 &num_poisoned_pages);
80757 }
80758 /* keep elevated page count for bad page */
80759@@ -1552,11 +1552,11 @@ int soft_offline_page(struct page *page, int flags)
80760 if (PageHuge(page)) {
80761 set_page_hwpoison_huge_page(hpage);
80762 dequeue_hwpoisoned_huge_page(hpage);
80763- atomic_long_add(1 << compound_trans_order(hpage),
80764+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
80765 &num_poisoned_pages);
80766 } else {
80767 SetPageHWPoison(page);
80768- atomic_long_inc(&num_poisoned_pages);
80769+ atomic_long_inc_unchecked(&num_poisoned_pages);
80770 }
80771 }
80772 /* keep elevated page count for bad page */
80773@@ -1596,7 +1596,7 @@ static int __soft_offline_page(struct page *page, int flags)
80774 put_page(page);
80775 pr_info("soft_offline: %#lx: invalidated\n", pfn);
80776 SetPageHWPoison(page);
80777- atomic_long_inc(&num_poisoned_pages);
80778+ atomic_long_inc_unchecked(&num_poisoned_pages);
80779 return 0;
80780 }
80781
80782@@ -1626,7 +1626,7 @@ static int __soft_offline_page(struct page *page, int flags)
80783 ret = -EIO;
80784 } else {
80785 SetPageHWPoison(page);
80786- atomic_long_inc(&num_poisoned_pages);
80787+ atomic_long_inc_unchecked(&num_poisoned_pages);
80788 }
80789 } else {
80790 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
80791diff --git a/mm/memory.c b/mm/memory.c
80792index ba94dec..08ffe0d 100644
80793--- a/mm/memory.c
80794+++ b/mm/memory.c
80795@@ -438,6 +438,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
80796 free_pte_range(tlb, pmd, addr);
80797 } while (pmd++, addr = next, addr != end);
80798
80799+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
80800 start &= PUD_MASK;
80801 if (start < floor)
80802 return;
80803@@ -452,6 +453,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
80804 pmd = pmd_offset(pud, start);
80805 pud_clear(pud);
80806 pmd_free_tlb(tlb, pmd, start);
80807+#endif
80808+
80809 }
80810
80811 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
80812@@ -471,6 +474,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
80813 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
80814 } while (pud++, addr = next, addr != end);
80815
80816+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
80817 start &= PGDIR_MASK;
80818 if (start < floor)
80819 return;
80820@@ -485,6 +489,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
80821 pud = pud_offset(pgd, start);
80822 pgd_clear(pgd);
80823 pud_free_tlb(tlb, pud, start);
80824+#endif
80825+
80826 }
80827
80828 /*
80829@@ -1644,12 +1650,6 @@ no_page_table:
80830 return page;
80831 }
80832
80833-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
80834-{
80835- return stack_guard_page_start(vma, addr) ||
80836- stack_guard_page_end(vma, addr+PAGE_SIZE);
80837-}
80838-
80839 /**
80840 * __get_user_pages() - pin user pages in memory
80841 * @tsk: task_struct of target task
80842@@ -1736,10 +1736,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80843
80844 i = 0;
80845
80846- do {
80847+ while (nr_pages) {
80848 struct vm_area_struct *vma;
80849
80850- vma = find_extend_vma(mm, start);
80851+ vma = find_vma(mm, start);
80852 if (!vma && in_gate_area(mm, start)) {
80853 unsigned long pg = start & PAGE_MASK;
80854 pgd_t *pgd;
80855@@ -1788,7 +1788,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80856 goto next_page;
80857 }
80858
80859- if (!vma ||
80860+ if (!vma || start < vma->vm_start ||
80861 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
80862 !(vm_flags & vma->vm_flags))
80863 return i ? : -EFAULT;
80864@@ -1817,11 +1817,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80865 int ret;
80866 unsigned int fault_flags = 0;
80867
80868- /* For mlock, just skip the stack guard page. */
80869- if (foll_flags & FOLL_MLOCK) {
80870- if (stack_guard_page(vma, start))
80871- goto next_page;
80872- }
80873 if (foll_flags & FOLL_WRITE)
80874 fault_flags |= FAULT_FLAG_WRITE;
80875 if (nonblocking)
80876@@ -1901,7 +1896,7 @@ next_page:
80877 start += page_increm * PAGE_SIZE;
80878 nr_pages -= page_increm;
80879 } while (nr_pages && start < vma->vm_end);
80880- } while (nr_pages);
80881+ }
80882 return i;
80883 }
80884 EXPORT_SYMBOL(__get_user_pages);
80885@@ -2108,6 +2103,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
80886 page_add_file_rmap(page);
80887 set_pte_at(mm, addr, pte, mk_pte(page, prot));
80888
80889+#ifdef CONFIG_PAX_SEGMEXEC
80890+ pax_mirror_file_pte(vma, addr, page, ptl);
80891+#endif
80892+
80893 retval = 0;
80894 pte_unmap_unlock(pte, ptl);
80895 return retval;
80896@@ -2152,9 +2151,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
80897 if (!page_count(page))
80898 return -EINVAL;
80899 if (!(vma->vm_flags & VM_MIXEDMAP)) {
80900+
80901+#ifdef CONFIG_PAX_SEGMEXEC
80902+ struct vm_area_struct *vma_m;
80903+#endif
80904+
80905 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
80906 BUG_ON(vma->vm_flags & VM_PFNMAP);
80907 vma->vm_flags |= VM_MIXEDMAP;
80908+
80909+#ifdef CONFIG_PAX_SEGMEXEC
80910+ vma_m = pax_find_mirror_vma(vma);
80911+ if (vma_m)
80912+ vma_m->vm_flags |= VM_MIXEDMAP;
80913+#endif
80914+
80915 }
80916 return insert_page(vma, addr, page, vma->vm_page_prot);
80917 }
80918@@ -2237,6 +2248,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
80919 unsigned long pfn)
80920 {
80921 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
80922+ BUG_ON(vma->vm_mirror);
80923
80924 if (addr < vma->vm_start || addr >= vma->vm_end)
80925 return -EFAULT;
80926@@ -2484,7 +2496,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
80927
80928 BUG_ON(pud_huge(*pud));
80929
80930- pmd = pmd_alloc(mm, pud, addr);
80931+ pmd = (mm == &init_mm) ?
80932+ pmd_alloc_kernel(mm, pud, addr) :
80933+ pmd_alloc(mm, pud, addr);
80934 if (!pmd)
80935 return -ENOMEM;
80936 do {
80937@@ -2504,7 +2518,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
80938 unsigned long next;
80939 int err;
80940
80941- pud = pud_alloc(mm, pgd, addr);
80942+ pud = (mm == &init_mm) ?
80943+ pud_alloc_kernel(mm, pgd, addr) :
80944+ pud_alloc(mm, pgd, addr);
80945 if (!pud)
80946 return -ENOMEM;
80947 do {
80948@@ -2592,6 +2608,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
80949 copy_user_highpage(dst, src, va, vma);
80950 }
80951
80952+#ifdef CONFIG_PAX_SEGMEXEC
80953+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
80954+{
80955+ struct mm_struct *mm = vma->vm_mm;
80956+ spinlock_t *ptl;
80957+ pte_t *pte, entry;
80958+
80959+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
80960+ entry = *pte;
80961+ if (!pte_present(entry)) {
80962+ if (!pte_none(entry)) {
80963+ BUG_ON(pte_file(entry));
80964+ free_swap_and_cache(pte_to_swp_entry(entry));
80965+ pte_clear_not_present_full(mm, address, pte, 0);
80966+ }
80967+ } else {
80968+ struct page *page;
80969+
80970+ flush_cache_page(vma, address, pte_pfn(entry));
80971+ entry = ptep_clear_flush(vma, address, pte);
80972+ BUG_ON(pte_dirty(entry));
80973+ page = vm_normal_page(vma, address, entry);
80974+ if (page) {
80975+ update_hiwater_rss(mm);
80976+ if (PageAnon(page))
80977+ dec_mm_counter_fast(mm, MM_ANONPAGES);
80978+ else
80979+ dec_mm_counter_fast(mm, MM_FILEPAGES);
80980+ page_remove_rmap(page);
80981+ page_cache_release(page);
80982+ }
80983+ }
80984+ pte_unmap_unlock(pte, ptl);
80985+}
80986+
80987+/* PaX: if vma is mirrored, synchronize the mirror's PTE
80988+ *
80989+ * the ptl of the lower mapped page is held on entry and is not released on exit
80990+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
80991+ */
80992+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
80993+{
80994+ struct mm_struct *mm = vma->vm_mm;
80995+ unsigned long address_m;
80996+ spinlock_t *ptl_m;
80997+ struct vm_area_struct *vma_m;
80998+ pmd_t *pmd_m;
80999+ pte_t *pte_m, entry_m;
81000+
81001+ BUG_ON(!page_m || !PageAnon(page_m));
81002+
81003+ vma_m = pax_find_mirror_vma(vma);
81004+ if (!vma_m)
81005+ return;
81006+
81007+ BUG_ON(!PageLocked(page_m));
81008+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81009+ address_m = address + SEGMEXEC_TASK_SIZE;
81010+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81011+ pte_m = pte_offset_map(pmd_m, address_m);
81012+ ptl_m = pte_lockptr(mm, pmd_m);
81013+ if (ptl != ptl_m) {
81014+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81015+ if (!pte_none(*pte_m))
81016+ goto out;
81017+ }
81018+
81019+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
81020+ page_cache_get(page_m);
81021+ page_add_anon_rmap(page_m, vma_m, address_m);
81022+ inc_mm_counter_fast(mm, MM_ANONPAGES);
81023+ set_pte_at(mm, address_m, pte_m, entry_m);
81024+ update_mmu_cache(vma_m, address_m, pte_m);
81025+out:
81026+ if (ptl != ptl_m)
81027+ spin_unlock(ptl_m);
81028+ pte_unmap(pte_m);
81029+ unlock_page(page_m);
81030+}
81031+
81032+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
81033+{
81034+ struct mm_struct *mm = vma->vm_mm;
81035+ unsigned long address_m;
81036+ spinlock_t *ptl_m;
81037+ struct vm_area_struct *vma_m;
81038+ pmd_t *pmd_m;
81039+ pte_t *pte_m, entry_m;
81040+
81041+ BUG_ON(!page_m || PageAnon(page_m));
81042+
81043+ vma_m = pax_find_mirror_vma(vma);
81044+ if (!vma_m)
81045+ return;
81046+
81047+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81048+ address_m = address + SEGMEXEC_TASK_SIZE;
81049+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81050+ pte_m = pte_offset_map(pmd_m, address_m);
81051+ ptl_m = pte_lockptr(mm, pmd_m);
81052+ if (ptl != ptl_m) {
81053+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81054+ if (!pte_none(*pte_m))
81055+ goto out;
81056+ }
81057+
81058+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
81059+ page_cache_get(page_m);
81060+ page_add_file_rmap(page_m);
81061+ inc_mm_counter_fast(mm, MM_FILEPAGES);
81062+ set_pte_at(mm, address_m, pte_m, entry_m);
81063+ update_mmu_cache(vma_m, address_m, pte_m);
81064+out:
81065+ if (ptl != ptl_m)
81066+ spin_unlock(ptl_m);
81067+ pte_unmap(pte_m);
81068+}
81069+
81070+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
81071+{
81072+ struct mm_struct *mm = vma->vm_mm;
81073+ unsigned long address_m;
81074+ spinlock_t *ptl_m;
81075+ struct vm_area_struct *vma_m;
81076+ pmd_t *pmd_m;
81077+ pte_t *pte_m, entry_m;
81078+
81079+ vma_m = pax_find_mirror_vma(vma);
81080+ if (!vma_m)
81081+ return;
81082+
81083+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81084+ address_m = address + SEGMEXEC_TASK_SIZE;
81085+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81086+ pte_m = pte_offset_map(pmd_m, address_m);
81087+ ptl_m = pte_lockptr(mm, pmd_m);
81088+ if (ptl != ptl_m) {
81089+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81090+ if (!pte_none(*pte_m))
81091+ goto out;
81092+ }
81093+
81094+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
81095+ set_pte_at(mm, address_m, pte_m, entry_m);
81096+out:
81097+ if (ptl != ptl_m)
81098+ spin_unlock(ptl_m);
81099+ pte_unmap(pte_m);
81100+}
81101+
81102+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
81103+{
81104+ struct page *page_m;
81105+ pte_t entry;
81106+
81107+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
81108+ goto out;
81109+
81110+ entry = *pte;
81111+ page_m = vm_normal_page(vma, address, entry);
81112+ if (!page_m)
81113+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
81114+ else if (PageAnon(page_m)) {
81115+ if (pax_find_mirror_vma(vma)) {
81116+ pte_unmap_unlock(pte, ptl);
81117+ lock_page(page_m);
81118+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
81119+ if (pte_same(entry, *pte))
81120+ pax_mirror_anon_pte(vma, address, page_m, ptl);
81121+ else
81122+ unlock_page(page_m);
81123+ }
81124+ } else
81125+ pax_mirror_file_pte(vma, address, page_m, ptl);
81126+
81127+out:
81128+ pte_unmap_unlock(pte, ptl);
81129+}
81130+#endif
81131+
81132 /*
81133 * This routine handles present pages, when users try to write
81134 * to a shared page. It is done by copying the page to a new address
81135@@ -2808,6 +3004,12 @@ gotten:
81136 */
81137 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
81138 if (likely(pte_same(*page_table, orig_pte))) {
81139+
81140+#ifdef CONFIG_PAX_SEGMEXEC
81141+ if (pax_find_mirror_vma(vma))
81142+ BUG_ON(!trylock_page(new_page));
81143+#endif
81144+
81145 if (old_page) {
81146 if (!PageAnon(old_page)) {
81147 dec_mm_counter_fast(mm, MM_FILEPAGES);
81148@@ -2859,6 +3061,10 @@ gotten:
81149 page_remove_rmap(old_page);
81150 }
81151
81152+#ifdef CONFIG_PAX_SEGMEXEC
81153+ pax_mirror_anon_pte(vma, address, new_page, ptl);
81154+#endif
81155+
81156 /* Free the old page.. */
81157 new_page = old_page;
81158 ret |= VM_FAULT_WRITE;
81159@@ -3134,6 +3340,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
81160 swap_free(entry);
81161 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
81162 try_to_free_swap(page);
81163+
81164+#ifdef CONFIG_PAX_SEGMEXEC
81165+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
81166+#endif
81167+
81168 unlock_page(page);
81169 if (page != swapcache) {
81170 /*
81171@@ -3157,6 +3368,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
81172
81173 /* No need to invalidate - it was non-present before */
81174 update_mmu_cache(vma, address, page_table);
81175+
81176+#ifdef CONFIG_PAX_SEGMEXEC
81177+ pax_mirror_anon_pte(vma, address, page, ptl);
81178+#endif
81179+
81180 unlock:
81181 pte_unmap_unlock(page_table, ptl);
81182 out:
81183@@ -3176,40 +3392,6 @@ out_release:
81184 }
81185
81186 /*
81187- * This is like a special single-page "expand_{down|up}wards()",
81188- * except we must first make sure that 'address{-|+}PAGE_SIZE'
81189- * doesn't hit another vma.
81190- */
81191-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
81192-{
81193- address &= PAGE_MASK;
81194- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
81195- struct vm_area_struct *prev = vma->vm_prev;
81196-
81197- /*
81198- * Is there a mapping abutting this one below?
81199- *
81200- * That's only ok if it's the same stack mapping
81201- * that has gotten split..
81202- */
81203- if (prev && prev->vm_end == address)
81204- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
81205-
81206- expand_downwards(vma, address - PAGE_SIZE);
81207- }
81208- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
81209- struct vm_area_struct *next = vma->vm_next;
81210-
81211- /* As VM_GROWSDOWN but s/below/above/ */
81212- if (next && next->vm_start == address + PAGE_SIZE)
81213- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
81214-
81215- expand_upwards(vma, address + PAGE_SIZE);
81216- }
81217- return 0;
81218-}
81219-
81220-/*
81221 * We enter with non-exclusive mmap_sem (to exclude vma changes,
81222 * but allow concurrent faults), and pte mapped but not yet locked.
81223 * We return with mmap_sem still held, but pte unmapped and unlocked.
81224@@ -3218,27 +3400,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
81225 unsigned long address, pte_t *page_table, pmd_t *pmd,
81226 unsigned int flags)
81227 {
81228- struct page *page;
81229+ struct page *page = NULL;
81230 spinlock_t *ptl;
81231 pte_t entry;
81232
81233- pte_unmap(page_table);
81234-
81235- /* Check if we need to add a guard page to the stack */
81236- if (check_stack_guard_page(vma, address) < 0)
81237- return VM_FAULT_SIGBUS;
81238-
81239- /* Use the zero-page for reads */
81240 if (!(flags & FAULT_FLAG_WRITE)) {
81241 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
81242 vma->vm_page_prot));
81243- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
81244+ ptl = pte_lockptr(mm, pmd);
81245+ spin_lock(ptl);
81246 if (!pte_none(*page_table))
81247 goto unlock;
81248 goto setpte;
81249 }
81250
81251 /* Allocate our own private page. */
81252+ pte_unmap(page_table);
81253+
81254 if (unlikely(anon_vma_prepare(vma)))
81255 goto oom;
81256 page = alloc_zeroed_user_highpage_movable(vma, address);
81257@@ -3257,6 +3435,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
81258 if (!pte_none(*page_table))
81259 goto release;
81260
81261+#ifdef CONFIG_PAX_SEGMEXEC
81262+ if (pax_find_mirror_vma(vma))
81263+ BUG_ON(!trylock_page(page));
81264+#endif
81265+
81266 inc_mm_counter_fast(mm, MM_ANONPAGES);
81267 page_add_new_anon_rmap(page, vma, address);
81268 setpte:
81269@@ -3264,6 +3447,12 @@ setpte:
81270
81271 /* No need to invalidate - it was non-present before */
81272 update_mmu_cache(vma, address, page_table);
81273+
81274+#ifdef CONFIG_PAX_SEGMEXEC
81275+ if (page)
81276+ pax_mirror_anon_pte(vma, address, page, ptl);
81277+#endif
81278+
81279 unlock:
81280 pte_unmap_unlock(page_table, ptl);
81281 return 0;
81282@@ -3407,6 +3596,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81283 */
81284 /* Only go through if we didn't race with anybody else... */
81285 if (likely(pte_same(*page_table, orig_pte))) {
81286+
81287+#ifdef CONFIG_PAX_SEGMEXEC
81288+ if (anon && pax_find_mirror_vma(vma))
81289+ BUG_ON(!trylock_page(page));
81290+#endif
81291+
81292 flush_icache_page(vma, page);
81293 entry = mk_pte(page, vma->vm_page_prot);
81294 if (flags & FAULT_FLAG_WRITE)
81295@@ -3426,6 +3621,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81296
81297 /* no need to invalidate: a not-present page won't be cached */
81298 update_mmu_cache(vma, address, page_table);
81299+
81300+#ifdef CONFIG_PAX_SEGMEXEC
81301+ if (anon)
81302+ pax_mirror_anon_pte(vma, address, page, ptl);
81303+ else
81304+ pax_mirror_file_pte(vma, address, page, ptl);
81305+#endif
81306+
81307 } else {
81308 if (cow_page)
81309 mem_cgroup_uncharge_page(cow_page);
81310@@ -3747,6 +3950,12 @@ int handle_pte_fault(struct mm_struct *mm,
81311 if (flags & FAULT_FLAG_WRITE)
81312 flush_tlb_fix_spurious_fault(vma, address);
81313 }
81314+
81315+#ifdef CONFIG_PAX_SEGMEXEC
81316+ pax_mirror_pte(vma, address, pte, pmd, ptl);
81317+ return 0;
81318+#endif
81319+
81320 unlock:
81321 pte_unmap_unlock(pte, ptl);
81322 return 0;
81323@@ -3763,6 +3972,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81324 pmd_t *pmd;
81325 pte_t *pte;
81326
81327+#ifdef CONFIG_PAX_SEGMEXEC
81328+ struct vm_area_struct *vma_m;
81329+#endif
81330+
81331 __set_current_state(TASK_RUNNING);
81332
81333 count_vm_event(PGFAULT);
81334@@ -3774,6 +3987,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81335 if (unlikely(is_vm_hugetlb_page(vma)))
81336 return hugetlb_fault(mm, vma, address, flags);
81337
81338+#ifdef CONFIG_PAX_SEGMEXEC
81339+ vma_m = pax_find_mirror_vma(vma);
81340+ if (vma_m) {
81341+ unsigned long address_m;
81342+ pgd_t *pgd_m;
81343+ pud_t *pud_m;
81344+ pmd_t *pmd_m;
81345+
81346+ if (vma->vm_start > vma_m->vm_start) {
81347+ address_m = address;
81348+ address -= SEGMEXEC_TASK_SIZE;
81349+ vma = vma_m;
81350+ } else
81351+ address_m = address + SEGMEXEC_TASK_SIZE;
81352+
81353+ pgd_m = pgd_offset(mm, address_m);
81354+ pud_m = pud_alloc(mm, pgd_m, address_m);
81355+ if (!pud_m)
81356+ return VM_FAULT_OOM;
81357+ pmd_m = pmd_alloc(mm, pud_m, address_m);
81358+ if (!pmd_m)
81359+ return VM_FAULT_OOM;
81360+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
81361+ return VM_FAULT_OOM;
81362+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
81363+ }
81364+#endif
81365+
81366 retry:
81367 pgd = pgd_offset(mm, address);
81368 pud = pud_alloc(mm, pgd, address);
81369@@ -3872,6 +4113,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
81370 spin_unlock(&mm->page_table_lock);
81371 return 0;
81372 }
81373+
81374+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
81375+{
81376+ pud_t *new = pud_alloc_one(mm, address);
81377+ if (!new)
81378+ return -ENOMEM;
81379+
81380+ smp_wmb(); /* See comment in __pte_alloc */
81381+
81382+ spin_lock(&mm->page_table_lock);
81383+ if (pgd_present(*pgd)) /* Another has populated it */
81384+ pud_free(mm, new);
81385+ else
81386+ pgd_populate_kernel(mm, pgd, new);
81387+ spin_unlock(&mm->page_table_lock);
81388+ return 0;
81389+}
81390 #endif /* __PAGETABLE_PUD_FOLDED */
81391
81392 #ifndef __PAGETABLE_PMD_FOLDED
81393@@ -3902,6 +4160,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
81394 spin_unlock(&mm->page_table_lock);
81395 return 0;
81396 }
81397+
81398+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
81399+{
81400+ pmd_t *new = pmd_alloc_one(mm, address);
81401+ if (!new)
81402+ return -ENOMEM;
81403+
81404+ smp_wmb(); /* See comment in __pte_alloc */
81405+
81406+ spin_lock(&mm->page_table_lock);
81407+#ifndef __ARCH_HAS_4LEVEL_HACK
81408+ if (pud_present(*pud)) /* Another has populated it */
81409+ pmd_free(mm, new);
81410+ else
81411+ pud_populate_kernel(mm, pud, new);
81412+#else
81413+ if (pgd_present(*pud)) /* Another has populated it */
81414+ pmd_free(mm, new);
81415+ else
81416+ pgd_populate_kernel(mm, pud, new);
81417+#endif /* __ARCH_HAS_4LEVEL_HACK */
81418+ spin_unlock(&mm->page_table_lock);
81419+ return 0;
81420+}
81421 #endif /* __PAGETABLE_PMD_FOLDED */
81422
81423 #if !defined(__HAVE_ARCH_GATE_AREA)
81424@@ -3915,7 +4197,7 @@ static int __init gate_vma_init(void)
81425 gate_vma.vm_start = FIXADDR_USER_START;
81426 gate_vma.vm_end = FIXADDR_USER_END;
81427 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
81428- gate_vma.vm_page_prot = __P101;
81429+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
81430
81431 return 0;
81432 }
81433@@ -4049,8 +4331,8 @@ out:
81434 return ret;
81435 }
81436
81437-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
81438- void *buf, int len, int write)
81439+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
81440+ void *buf, size_t len, int write)
81441 {
81442 resource_size_t phys_addr;
81443 unsigned long prot = 0;
81444@@ -4075,8 +4357,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
81445 * Access another process' address space as given in mm. If non-NULL, use the
81446 * given task for page fault accounting.
81447 */
81448-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
81449- unsigned long addr, void *buf, int len, int write)
81450+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
81451+ unsigned long addr, void *buf, size_t len, int write)
81452 {
81453 struct vm_area_struct *vma;
81454 void *old_buf = buf;
81455@@ -4084,7 +4366,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
81456 down_read(&mm->mmap_sem);
81457 /* ignore errors, just check how much was successfully transferred */
81458 while (len) {
81459- int bytes, ret, offset;
81460+ ssize_t bytes, ret, offset;
81461 void *maddr;
81462 struct page *page = NULL;
81463
81464@@ -4143,8 +4425,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
81465 *
81466 * The caller must hold a reference on @mm.
81467 */
81468-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
81469- void *buf, int len, int write)
81470+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
81471+ void *buf, size_t len, int write)
81472 {
81473 return __access_remote_vm(NULL, mm, addr, buf, len, write);
81474 }
81475@@ -4154,11 +4436,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
81476 * Source/target buffer must be kernel space,
81477 * Do not walk the page table directly, use get_user_pages
81478 */
81479-int access_process_vm(struct task_struct *tsk, unsigned long addr,
81480- void *buf, int len, int write)
81481+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
81482+ void *buf, size_t len, int write)
81483 {
81484 struct mm_struct *mm;
81485- int ret;
81486+ ssize_t ret;
81487
81488 mm = get_task_mm(tsk);
81489 if (!mm)
81490diff --git a/mm/mempolicy.c b/mm/mempolicy.c
81491index 7431001..0f8344e 100644
81492--- a/mm/mempolicy.c
81493+++ b/mm/mempolicy.c
81494@@ -708,6 +708,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
81495 unsigned long vmstart;
81496 unsigned long vmend;
81497
81498+#ifdef CONFIG_PAX_SEGMEXEC
81499+ struct vm_area_struct *vma_m;
81500+#endif
81501+
81502 vma = find_vma(mm, start);
81503 if (!vma || vma->vm_start > start)
81504 return -EFAULT;
81505@@ -744,9 +748,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
81506 if (err)
81507 goto out;
81508 }
81509+
81510 err = vma_replace_policy(vma, new_pol);
81511 if (err)
81512 goto out;
81513+
81514+#ifdef CONFIG_PAX_SEGMEXEC
81515+ vma_m = pax_find_mirror_vma(vma);
81516+ if (vma_m) {
81517+ err = vma_replace_policy(vma_m, new_pol);
81518+ if (err)
81519+ goto out;
81520+ }
81521+#endif
81522+
81523 }
81524
81525 out:
81526@@ -1202,6 +1217,17 @@ static long do_mbind(unsigned long start, unsigned long len,
81527
81528 if (end < start)
81529 return -EINVAL;
81530+
81531+#ifdef CONFIG_PAX_SEGMEXEC
81532+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
81533+ if (end > SEGMEXEC_TASK_SIZE)
81534+ return -EINVAL;
81535+ } else
81536+#endif
81537+
81538+ if (end > TASK_SIZE)
81539+ return -EINVAL;
81540+
81541 if (end == start)
81542 return 0;
81543
81544@@ -1430,8 +1456,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
81545 */
81546 tcred = __task_cred(task);
81547 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
81548- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
81549- !capable(CAP_SYS_NICE)) {
81550+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
81551 rcu_read_unlock();
81552 err = -EPERM;
81553 goto out_put;
81554@@ -1462,6 +1487,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
81555 goto out;
81556 }
81557
81558+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81559+ if (mm != current->mm &&
81560+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
81561+ mmput(mm);
81562+ err = -EPERM;
81563+ goto out;
81564+ }
81565+#endif
81566+
81567 err = do_migrate_pages(mm, old, new,
81568 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
81569
81570diff --git a/mm/migrate.c b/mm/migrate.c
81571index 22ed5c1..87c424c 100644
81572--- a/mm/migrate.c
81573+++ b/mm/migrate.c
81574@@ -1382,8 +1382,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
81575 */
81576 tcred = __task_cred(task);
81577 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
81578- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
81579- !capable(CAP_SYS_NICE)) {
81580+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
81581 rcu_read_unlock();
81582 err = -EPERM;
81583 goto out;
81584diff --git a/mm/mlock.c b/mm/mlock.c
81585index 79b7cf7..9944291 100644
81586--- a/mm/mlock.c
81587+++ b/mm/mlock.c
81588@@ -13,6 +13,7 @@
81589 #include <linux/pagemap.h>
81590 #include <linux/mempolicy.h>
81591 #include <linux/syscalls.h>
81592+#include <linux/security.h>
81593 #include <linux/sched.h>
81594 #include <linux/export.h>
81595 #include <linux/rmap.h>
81596@@ -334,7 +335,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
81597 {
81598 unsigned long nstart, end, tmp;
81599 struct vm_area_struct * vma, * prev;
81600- int error;
81601+ int error = 0;
81602
81603 VM_BUG_ON(start & ~PAGE_MASK);
81604 VM_BUG_ON(len != PAGE_ALIGN(len));
81605@@ -343,6 +344,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
81606 return -EINVAL;
81607 if (end == start)
81608 return 0;
81609+ if (end > TASK_SIZE)
81610+ return -EINVAL;
81611+
81612 vma = find_vma(current->mm, start);
81613 if (!vma || vma->vm_start > start)
81614 return -ENOMEM;
81615@@ -354,6 +358,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
81616 for (nstart = start ; ; ) {
81617 vm_flags_t newflags;
81618
81619+#ifdef CONFIG_PAX_SEGMEXEC
81620+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
81621+ break;
81622+#endif
81623+
81624 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
81625
81626 newflags = vma->vm_flags & ~VM_LOCKED;
81627@@ -466,6 +475,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
81628 lock_limit >>= PAGE_SHIFT;
81629
81630 /* check against resource limits */
81631+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
81632 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
81633 error = do_mlock(start, len, 1);
81634 up_write(&current->mm->mmap_sem);
81635@@ -500,6 +510,11 @@ static int do_mlockall(int flags)
81636 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
81637 vm_flags_t newflags;
81638
81639+#ifdef CONFIG_PAX_SEGMEXEC
81640+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
81641+ break;
81642+#endif
81643+
81644 newflags = vma->vm_flags & ~VM_LOCKED;
81645 if (flags & MCL_CURRENT)
81646 newflags |= VM_LOCKED;
81647@@ -532,6 +547,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
81648 lock_limit >>= PAGE_SHIFT;
81649
81650 ret = -ENOMEM;
81651+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
81652 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
81653 capable(CAP_IPC_LOCK))
81654 ret = do_mlockall(flags);
81655diff --git a/mm/mmap.c b/mm/mmap.c
81656index 0dceed8..671951c 100644
81657--- a/mm/mmap.c
81658+++ b/mm/mmap.c
81659@@ -33,6 +33,7 @@
81660 #include <linux/uprobes.h>
81661 #include <linux/rbtree_augmented.h>
81662 #include <linux/sched/sysctl.h>
81663+#include <linux/random.h>
81664
81665 #include <asm/uaccess.h>
81666 #include <asm/cacheflush.h>
81667@@ -49,6 +50,16 @@
81668 #define arch_rebalance_pgtables(addr, len) (addr)
81669 #endif
81670
81671+static inline void verify_mm_writelocked(struct mm_struct *mm)
81672+{
81673+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
81674+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
81675+ up_read(&mm->mmap_sem);
81676+ BUG();
81677+ }
81678+#endif
81679+}
81680+
81681 static void unmap_region(struct mm_struct *mm,
81682 struct vm_area_struct *vma, struct vm_area_struct *prev,
81683 unsigned long start, unsigned long end);
81684@@ -68,22 +79,32 @@ static void unmap_region(struct mm_struct *mm,
81685 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
81686 *
81687 */
81688-pgprot_t protection_map[16] = {
81689+pgprot_t protection_map[16] __read_only = {
81690 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
81691 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
81692 };
81693
81694-pgprot_t vm_get_page_prot(unsigned long vm_flags)
81695+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
81696 {
81697- return __pgprot(pgprot_val(protection_map[vm_flags &
81698+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
81699 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
81700 pgprot_val(arch_vm_get_page_prot(vm_flags)));
81701+
81702+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
81703+ if (!(__supported_pte_mask & _PAGE_NX) &&
81704+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
81705+ (vm_flags & (VM_READ | VM_WRITE)))
81706+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
81707+#endif
81708+
81709+ return prot;
81710 }
81711 EXPORT_SYMBOL(vm_get_page_prot);
81712
81713 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
81714 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
81715 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
81716+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
81717 /*
81718 * Make sure vm_committed_as in one cacheline and not cacheline shared with
81719 * other variables. It can be updated by several CPUs frequently.
81720@@ -239,6 +260,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
81721 struct vm_area_struct *next = vma->vm_next;
81722
81723 might_sleep();
81724+ BUG_ON(vma->vm_mirror);
81725 if (vma->vm_ops && vma->vm_ops->close)
81726 vma->vm_ops->close(vma);
81727 if (vma->vm_file)
81728@@ -283,6 +305,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
81729 * not page aligned -Ram Gupta
81730 */
81731 rlim = rlimit(RLIMIT_DATA);
81732+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
81733 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
81734 (mm->end_data - mm->start_data) > rlim)
81735 goto out;
81736@@ -897,6 +920,12 @@ static int
81737 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
81738 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
81739 {
81740+
81741+#ifdef CONFIG_PAX_SEGMEXEC
81742+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
81743+ return 0;
81744+#endif
81745+
81746 if (is_mergeable_vma(vma, file, vm_flags) &&
81747 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
81748 if (vma->vm_pgoff == vm_pgoff)
81749@@ -916,6 +945,12 @@ static int
81750 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
81751 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
81752 {
81753+
81754+#ifdef CONFIG_PAX_SEGMEXEC
81755+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
81756+ return 0;
81757+#endif
81758+
81759 if (is_mergeable_vma(vma, file, vm_flags) &&
81760 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
81761 pgoff_t vm_pglen;
81762@@ -958,13 +993,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
81763 struct vm_area_struct *vma_merge(struct mm_struct *mm,
81764 struct vm_area_struct *prev, unsigned long addr,
81765 unsigned long end, unsigned long vm_flags,
81766- struct anon_vma *anon_vma, struct file *file,
81767+ struct anon_vma *anon_vma, struct file *file,
81768 pgoff_t pgoff, struct mempolicy *policy)
81769 {
81770 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
81771 struct vm_area_struct *area, *next;
81772 int err;
81773
81774+#ifdef CONFIG_PAX_SEGMEXEC
81775+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
81776+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
81777+
81778+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
81779+#endif
81780+
81781 /*
81782 * We later require that vma->vm_flags == vm_flags,
81783 * so this tests vma->vm_flags & VM_SPECIAL, too.
81784@@ -980,6 +1022,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
81785 if (next && next->vm_end == end) /* cases 6, 7, 8 */
81786 next = next->vm_next;
81787
81788+#ifdef CONFIG_PAX_SEGMEXEC
81789+ if (prev)
81790+ prev_m = pax_find_mirror_vma(prev);
81791+ if (area)
81792+ area_m = pax_find_mirror_vma(area);
81793+ if (next)
81794+ next_m = pax_find_mirror_vma(next);
81795+#endif
81796+
81797 /*
81798 * Can it merge with the predecessor?
81799 */
81800@@ -999,9 +1050,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
81801 /* cases 1, 6 */
81802 err = vma_adjust(prev, prev->vm_start,
81803 next->vm_end, prev->vm_pgoff, NULL);
81804- } else /* cases 2, 5, 7 */
81805+
81806+#ifdef CONFIG_PAX_SEGMEXEC
81807+ if (!err && prev_m)
81808+ err = vma_adjust(prev_m, prev_m->vm_start,
81809+ next_m->vm_end, prev_m->vm_pgoff, NULL);
81810+#endif
81811+
81812+ } else { /* cases 2, 5, 7 */
81813 err = vma_adjust(prev, prev->vm_start,
81814 end, prev->vm_pgoff, NULL);
81815+
81816+#ifdef CONFIG_PAX_SEGMEXEC
81817+ if (!err && prev_m)
81818+ err = vma_adjust(prev_m, prev_m->vm_start,
81819+ end_m, prev_m->vm_pgoff, NULL);
81820+#endif
81821+
81822+ }
81823 if (err)
81824 return NULL;
81825 khugepaged_enter_vma_merge(prev);
81826@@ -1015,12 +1081,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
81827 mpol_equal(policy, vma_policy(next)) &&
81828 can_vma_merge_before(next, vm_flags,
81829 anon_vma, file, pgoff+pglen)) {
81830- if (prev && addr < prev->vm_end) /* case 4 */
81831+ if (prev && addr < prev->vm_end) { /* case 4 */
81832 err = vma_adjust(prev, prev->vm_start,
81833 addr, prev->vm_pgoff, NULL);
81834- else /* cases 3, 8 */
81835+
81836+#ifdef CONFIG_PAX_SEGMEXEC
81837+ if (!err && prev_m)
81838+ err = vma_adjust(prev_m, prev_m->vm_start,
81839+ addr_m, prev_m->vm_pgoff, NULL);
81840+#endif
81841+
81842+ } else { /* cases 3, 8 */
81843 err = vma_adjust(area, addr, next->vm_end,
81844 next->vm_pgoff - pglen, NULL);
81845+
81846+#ifdef CONFIG_PAX_SEGMEXEC
81847+ if (!err && area_m)
81848+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
81849+ next_m->vm_pgoff - pglen, NULL);
81850+#endif
81851+
81852+ }
81853 if (err)
81854 return NULL;
81855 khugepaged_enter_vma_merge(area);
81856@@ -1129,8 +1210,10 @@ none:
81857 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
81858 struct file *file, long pages)
81859 {
81860- const unsigned long stack_flags
81861- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
81862+
81863+#ifdef CONFIG_PAX_RANDMMAP
81864+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
81865+#endif
81866
81867 mm->total_vm += pages;
81868
81869@@ -1138,7 +1221,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
81870 mm->shared_vm += pages;
81871 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
81872 mm->exec_vm += pages;
81873- } else if (flags & stack_flags)
81874+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
81875 mm->stack_vm += pages;
81876 }
81877 #endif /* CONFIG_PROC_FS */
81878@@ -1177,7 +1260,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81879 * (the exception is when the underlying filesystem is noexec
81880 * mounted, in which case we dont add PROT_EXEC.)
81881 */
81882- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
81883+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
81884 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
81885 prot |= PROT_EXEC;
81886
81887@@ -1203,7 +1286,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81888 /* Obtain the address to map to. we verify (or select) it and ensure
81889 * that it represents a valid section of the address space.
81890 */
81891- addr = get_unmapped_area(file, addr, len, pgoff, flags);
81892+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
81893 if (addr & ~PAGE_MASK)
81894 return addr;
81895
81896@@ -1214,6 +1297,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81897 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
81898 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
81899
81900+#ifdef CONFIG_PAX_MPROTECT
81901+ if (mm->pax_flags & MF_PAX_MPROTECT) {
81902+#ifndef CONFIG_PAX_MPROTECT_COMPAT
81903+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
81904+ gr_log_rwxmmap(file);
81905+
81906+#ifdef CONFIG_PAX_EMUPLT
81907+ vm_flags &= ~VM_EXEC;
81908+#else
81909+ return -EPERM;
81910+#endif
81911+
81912+ }
81913+
81914+ if (!(vm_flags & VM_EXEC))
81915+ vm_flags &= ~VM_MAYEXEC;
81916+#else
81917+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
81918+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
81919+#endif
81920+ else
81921+ vm_flags &= ~VM_MAYWRITE;
81922+ }
81923+#endif
81924+
81925+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
81926+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
81927+ vm_flags &= ~VM_PAGEEXEC;
81928+#endif
81929+
81930 if (flags & MAP_LOCKED)
81931 if (!can_do_mlock())
81932 return -EPERM;
81933@@ -1225,6 +1338,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81934 locked += mm->locked_vm;
81935 lock_limit = rlimit(RLIMIT_MEMLOCK);
81936 lock_limit >>= PAGE_SHIFT;
81937+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
81938 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
81939 return -EAGAIN;
81940 }
81941@@ -1305,6 +1419,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
81942 vm_flags |= VM_NORESERVE;
81943 }
81944
81945+ if (!gr_acl_handle_mmap(file, prot))
81946+ return -EACCES;
81947+
81948 addr = mmap_region(file, addr, len, vm_flags, pgoff);
81949 if (!IS_ERR_VALUE(addr) &&
81950 ((vm_flags & VM_LOCKED) ||
81951@@ -1396,7 +1513,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
81952 vm_flags_t vm_flags = vma->vm_flags;
81953
81954 /* If it was private or non-writable, the write bit is already clear */
81955- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
81956+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
81957 return 0;
81958
81959 /* The backer wishes to know when pages are first written to? */
81960@@ -1444,16 +1561,30 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
81961 unsigned long charged = 0;
81962 struct inode *inode = file ? file_inode(file) : NULL;
81963
81964+#ifdef CONFIG_PAX_SEGMEXEC
81965+ struct vm_area_struct *vma_m = NULL;
81966+#endif
81967+
81968+ /*
81969+ * mm->mmap_sem is required to protect against another thread
81970+ * changing the mappings in case we sleep.
81971+ */
81972+ verify_mm_writelocked(mm);
81973+
81974 /* Clear old maps */
81975 error = -ENOMEM;
81976-munmap_back:
81977 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
81978 if (do_munmap(mm, addr, len))
81979 return -ENOMEM;
81980- goto munmap_back;
81981+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
81982 }
81983
81984 /* Check against address space limit. */
81985+
81986+#ifdef CONFIG_PAX_RANDMMAP
81987+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
81988+#endif
81989+
81990 if (!may_expand_vm(mm, len >> PAGE_SHIFT))
81991 return -ENOMEM;
81992
81993@@ -1485,6 +1616,16 @@ munmap_back:
81994 goto unacct_error;
81995 }
81996
81997+#ifdef CONFIG_PAX_SEGMEXEC
81998+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
81999+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82000+ if (!vma_m) {
82001+ error = -ENOMEM;
82002+ goto free_vma;
82003+ }
82004+ }
82005+#endif
82006+
82007 vma->vm_mm = mm;
82008 vma->vm_start = addr;
82009 vma->vm_end = addr + len;
82010@@ -1509,6 +1650,13 @@ munmap_back:
82011 if (error)
82012 goto unmap_and_free_vma;
82013
82014+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82015+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
82016+ vma->vm_flags |= VM_PAGEEXEC;
82017+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
82018+ }
82019+#endif
82020+
82021 /* Can addr have changed??
82022 *
82023 * Answer: Yes, several device drivers can do it in their
82024@@ -1547,6 +1695,11 @@ munmap_back:
82025 vma_link(mm, vma, prev, rb_link, rb_parent);
82026 file = vma->vm_file;
82027
82028+#ifdef CONFIG_PAX_SEGMEXEC
82029+ if (vma_m)
82030+ BUG_ON(pax_mirror_vma(vma_m, vma));
82031+#endif
82032+
82033 /* Once vma denies write, undo our temporary denial count */
82034 if (correct_wcount)
82035 atomic_inc(&inode->i_writecount);
82036@@ -1554,6 +1707,7 @@ out:
82037 perf_event_mmap(vma);
82038
82039 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
82040+ track_exec_limit(mm, addr, addr + len, vm_flags);
82041 if (vm_flags & VM_LOCKED) {
82042 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
82043 vma == get_gate_vma(current->mm)))
82044@@ -1577,6 +1731,12 @@ unmap_and_free_vma:
82045 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
82046 charged = 0;
82047 free_vma:
82048+
82049+#ifdef CONFIG_PAX_SEGMEXEC
82050+ if (vma_m)
82051+ kmem_cache_free(vm_area_cachep, vma_m);
82052+#endif
82053+
82054 kmem_cache_free(vm_area_cachep, vma);
82055 unacct_error:
82056 if (charged)
82057@@ -1584,6 +1744,62 @@ unacct_error:
82058 return error;
82059 }
82060
82061+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
82062+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
82063+{
82064+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
82065+ return (random32() & 0xFF) << PAGE_SHIFT;
82066+
82067+ return 0;
82068+}
82069+#endif
82070+
82071+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
82072+{
82073+ if (!vma) {
82074+#ifdef CONFIG_STACK_GROWSUP
82075+ if (addr > sysctl_heap_stack_gap)
82076+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
82077+ else
82078+ vma = find_vma(current->mm, 0);
82079+ if (vma && (vma->vm_flags & VM_GROWSUP))
82080+ return false;
82081+#endif
82082+ return true;
82083+ }
82084+
82085+ if (addr + len > vma->vm_start)
82086+ return false;
82087+
82088+ if (vma->vm_flags & VM_GROWSDOWN)
82089+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
82090+#ifdef CONFIG_STACK_GROWSUP
82091+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
82092+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
82093+#endif
82094+ else if (offset)
82095+ return offset <= vma->vm_start - addr - len;
82096+
82097+ return true;
82098+}
82099+
82100+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
82101+{
82102+ if (vma->vm_start < len)
82103+ return -ENOMEM;
82104+
82105+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
82106+ if (offset <= vma->vm_start - len)
82107+ return vma->vm_start - len - offset;
82108+ else
82109+ return -ENOMEM;
82110+ }
82111+
82112+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
82113+ return vma->vm_start - len - sysctl_heap_stack_gap;
82114+ return -ENOMEM;
82115+}
82116+
82117 unsigned long unmapped_area(struct vm_unmapped_area_info *info)
82118 {
82119 /*
82120@@ -1803,6 +2019,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
82121 struct mm_struct *mm = current->mm;
82122 struct vm_area_struct *vma;
82123 struct vm_unmapped_area_info info;
82124+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
82125
82126 if (len > TASK_SIZE)
82127 return -ENOMEM;
82128@@ -1810,29 +2027,45 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
82129 if (flags & MAP_FIXED)
82130 return addr;
82131
82132+#ifdef CONFIG_PAX_RANDMMAP
82133+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
82134+#endif
82135+
82136 if (addr) {
82137 addr = PAGE_ALIGN(addr);
82138 vma = find_vma(mm, addr);
82139- if (TASK_SIZE - len >= addr &&
82140- (!vma || addr + len <= vma->vm_start))
82141+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
82142 return addr;
82143 }
82144
82145 info.flags = 0;
82146 info.length = len;
82147 info.low_limit = TASK_UNMAPPED_BASE;
82148+
82149+#ifdef CONFIG_PAX_RANDMMAP
82150+ if (mm->pax_flags & MF_PAX_RANDMMAP)
82151+ info.low_limit += mm->delta_mmap;
82152+#endif
82153+
82154 info.high_limit = TASK_SIZE;
82155 info.align_mask = 0;
82156+ info.threadstack_offset = offset;
82157 return vm_unmapped_area(&info);
82158 }
82159 #endif
82160
82161 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
82162 {
82163+
82164+#ifdef CONFIG_PAX_SEGMEXEC
82165+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
82166+ return;
82167+#endif
82168+
82169 /*
82170 * Is this a new hole at the lowest possible address?
82171 */
82172- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
82173+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
82174 mm->free_area_cache = addr;
82175 }
82176
82177@@ -1850,6 +2083,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82178 struct mm_struct *mm = current->mm;
82179 unsigned long addr = addr0;
82180 struct vm_unmapped_area_info info;
82181+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
82182
82183 /* requested length too big for entire address space */
82184 if (len > TASK_SIZE)
82185@@ -1858,12 +2092,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82186 if (flags & MAP_FIXED)
82187 return addr;
82188
82189+#ifdef CONFIG_PAX_RANDMMAP
82190+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
82191+#endif
82192+
82193 /* requesting a specific address */
82194 if (addr) {
82195 addr = PAGE_ALIGN(addr);
82196 vma = find_vma(mm, addr);
82197- if (TASK_SIZE - len >= addr &&
82198- (!vma || addr + len <= vma->vm_start))
82199+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
82200 return addr;
82201 }
82202
82203@@ -1872,6 +2109,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82204 info.low_limit = PAGE_SIZE;
82205 info.high_limit = mm->mmap_base;
82206 info.align_mask = 0;
82207+ info.threadstack_offset = offset;
82208 addr = vm_unmapped_area(&info);
82209
82210 /*
82211@@ -1884,6 +2122,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82212 VM_BUG_ON(addr != -ENOMEM);
82213 info.flags = 0;
82214 info.low_limit = TASK_UNMAPPED_BASE;
82215+
82216+#ifdef CONFIG_PAX_RANDMMAP
82217+ if (mm->pax_flags & MF_PAX_RANDMMAP)
82218+ info.low_limit += mm->delta_mmap;
82219+#endif
82220+
82221 info.high_limit = TASK_SIZE;
82222 addr = vm_unmapped_area(&info);
82223 }
82224@@ -1894,6 +2138,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82225
82226 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
82227 {
82228+
82229+#ifdef CONFIG_PAX_SEGMEXEC
82230+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
82231+ return;
82232+#endif
82233+
82234 /*
82235 * Is this a new hole at the highest possible address?
82236 */
82237@@ -1901,8 +2151,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
82238 mm->free_area_cache = addr;
82239
82240 /* dont allow allocations above current base */
82241- if (mm->free_area_cache > mm->mmap_base)
82242+ if (mm->free_area_cache > mm->mmap_base) {
82243 mm->free_area_cache = mm->mmap_base;
82244+ mm->cached_hole_size = ~0UL;
82245+ }
82246 }
82247
82248 unsigned long
82249@@ -2001,6 +2253,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
82250 return vma;
82251 }
82252
82253+#ifdef CONFIG_PAX_SEGMEXEC
82254+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
82255+{
82256+ struct vm_area_struct *vma_m;
82257+
82258+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
82259+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
82260+ BUG_ON(vma->vm_mirror);
82261+ return NULL;
82262+ }
82263+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
82264+ vma_m = vma->vm_mirror;
82265+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
82266+ BUG_ON(vma->vm_file != vma_m->vm_file);
82267+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
82268+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
82269+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
82270+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
82271+ return vma_m;
82272+}
82273+#endif
82274+
82275 /*
82276 * Verify that the stack growth is acceptable and
82277 * update accounting. This is shared with both the
82278@@ -2017,6 +2291,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
82279 return -ENOMEM;
82280
82281 /* Stack limit test */
82282+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
82283 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
82284 return -ENOMEM;
82285
82286@@ -2027,6 +2302,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
82287 locked = mm->locked_vm + grow;
82288 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
82289 limit >>= PAGE_SHIFT;
82290+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
82291 if (locked > limit && !capable(CAP_IPC_LOCK))
82292 return -ENOMEM;
82293 }
82294@@ -2056,37 +2332,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
82295 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
82296 * vma is the last one with address > vma->vm_end. Have to extend vma.
82297 */
82298+#ifndef CONFIG_IA64
82299+static
82300+#endif
82301 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
82302 {
82303 int error;
82304+ bool locknext;
82305
82306 if (!(vma->vm_flags & VM_GROWSUP))
82307 return -EFAULT;
82308
82309+ /* Also guard against wrapping around to address 0. */
82310+ if (address < PAGE_ALIGN(address+1))
82311+ address = PAGE_ALIGN(address+1);
82312+ else
82313+ return -ENOMEM;
82314+
82315 /*
82316 * We must make sure the anon_vma is allocated
82317 * so that the anon_vma locking is not a noop.
82318 */
82319 if (unlikely(anon_vma_prepare(vma)))
82320 return -ENOMEM;
82321+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
82322+ if (locknext && anon_vma_prepare(vma->vm_next))
82323+ return -ENOMEM;
82324 vma_lock_anon_vma(vma);
82325+ if (locknext)
82326+ vma_lock_anon_vma(vma->vm_next);
82327
82328 /*
82329 * vma->vm_start/vm_end cannot change under us because the caller
82330 * is required to hold the mmap_sem in read mode. We need the
82331- * anon_vma lock to serialize against concurrent expand_stacks.
82332- * Also guard against wrapping around to address 0.
82333+ * anon_vma locks to serialize against concurrent expand_stacks
82334+ * and expand_upwards.
82335 */
82336- if (address < PAGE_ALIGN(address+4))
82337- address = PAGE_ALIGN(address+4);
82338- else {
82339- vma_unlock_anon_vma(vma);
82340- return -ENOMEM;
82341- }
82342 error = 0;
82343
82344 /* Somebody else might have raced and expanded it already */
82345- if (address > vma->vm_end) {
82346+ 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)
82347+ error = -ENOMEM;
82348+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
82349 unsigned long size, grow;
82350
82351 size = address - vma->vm_start;
82352@@ -2121,6 +2408,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
82353 }
82354 }
82355 }
82356+ if (locknext)
82357+ vma_unlock_anon_vma(vma->vm_next);
82358 vma_unlock_anon_vma(vma);
82359 khugepaged_enter_vma_merge(vma);
82360 validate_mm(vma->vm_mm);
82361@@ -2135,6 +2424,8 @@ int expand_downwards(struct vm_area_struct *vma,
82362 unsigned long address)
82363 {
82364 int error;
82365+ bool lockprev = false;
82366+ struct vm_area_struct *prev;
82367
82368 /*
82369 * We must make sure the anon_vma is allocated
82370@@ -2148,6 +2439,15 @@ int expand_downwards(struct vm_area_struct *vma,
82371 if (error)
82372 return error;
82373
82374+ prev = vma->vm_prev;
82375+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
82376+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
82377+#endif
82378+ if (lockprev && anon_vma_prepare(prev))
82379+ return -ENOMEM;
82380+ if (lockprev)
82381+ vma_lock_anon_vma(prev);
82382+
82383 vma_lock_anon_vma(vma);
82384
82385 /*
82386@@ -2157,9 +2457,17 @@ int expand_downwards(struct vm_area_struct *vma,
82387 */
82388
82389 /* Somebody else might have raced and expanded it already */
82390- if (address < vma->vm_start) {
82391+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
82392+ error = -ENOMEM;
82393+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
82394 unsigned long size, grow;
82395
82396+#ifdef CONFIG_PAX_SEGMEXEC
82397+ struct vm_area_struct *vma_m;
82398+
82399+ vma_m = pax_find_mirror_vma(vma);
82400+#endif
82401+
82402 size = vma->vm_end - address;
82403 grow = (vma->vm_start - address) >> PAGE_SHIFT;
82404
82405@@ -2184,6 +2492,18 @@ int expand_downwards(struct vm_area_struct *vma,
82406 vma->vm_pgoff -= grow;
82407 anon_vma_interval_tree_post_update_vma(vma);
82408 vma_gap_update(vma);
82409+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
82410+
82411+#ifdef CONFIG_PAX_SEGMEXEC
82412+ if (vma_m) {
82413+ anon_vma_interval_tree_pre_update_vma(vma_m);
82414+ vma_m->vm_start -= grow << PAGE_SHIFT;
82415+ vma_m->vm_pgoff -= grow;
82416+ anon_vma_interval_tree_post_update_vma(vma_m);
82417+ vma_gap_update(vma_m);
82418+ }
82419+#endif
82420+
82421 spin_unlock(&vma->vm_mm->page_table_lock);
82422
82423 perf_event_mmap(vma);
82424@@ -2288,6 +2608,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
82425 do {
82426 long nrpages = vma_pages(vma);
82427
82428+#ifdef CONFIG_PAX_SEGMEXEC
82429+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
82430+ vma = remove_vma(vma);
82431+ continue;
82432+ }
82433+#endif
82434+
82435 if (vma->vm_flags & VM_ACCOUNT)
82436 nr_accounted += nrpages;
82437 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
82438@@ -2333,6 +2660,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
82439 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
82440 vma->vm_prev = NULL;
82441 do {
82442+
82443+#ifdef CONFIG_PAX_SEGMEXEC
82444+ if (vma->vm_mirror) {
82445+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
82446+ vma->vm_mirror->vm_mirror = NULL;
82447+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
82448+ vma->vm_mirror = NULL;
82449+ }
82450+#endif
82451+
82452 vma_rb_erase(vma, &mm->mm_rb);
82453 mm->map_count--;
82454 tail_vma = vma;
82455@@ -2364,14 +2701,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
82456 struct vm_area_struct *new;
82457 int err = -ENOMEM;
82458
82459+#ifdef CONFIG_PAX_SEGMEXEC
82460+ struct vm_area_struct *vma_m, *new_m = NULL;
82461+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
82462+#endif
82463+
82464 if (is_vm_hugetlb_page(vma) && (addr &
82465 ~(huge_page_mask(hstate_vma(vma)))))
82466 return -EINVAL;
82467
82468+#ifdef CONFIG_PAX_SEGMEXEC
82469+ vma_m = pax_find_mirror_vma(vma);
82470+#endif
82471+
82472 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
82473 if (!new)
82474 goto out_err;
82475
82476+#ifdef CONFIG_PAX_SEGMEXEC
82477+ if (vma_m) {
82478+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
82479+ if (!new_m) {
82480+ kmem_cache_free(vm_area_cachep, new);
82481+ goto out_err;
82482+ }
82483+ }
82484+#endif
82485+
82486 /* most fields are the same, copy all, and then fixup */
82487 *new = *vma;
82488
82489@@ -2384,6 +2740,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
82490 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
82491 }
82492
82493+#ifdef CONFIG_PAX_SEGMEXEC
82494+ if (vma_m) {
82495+ *new_m = *vma_m;
82496+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
82497+ new_m->vm_mirror = new;
82498+ new->vm_mirror = new_m;
82499+
82500+ if (new_below)
82501+ new_m->vm_end = addr_m;
82502+ else {
82503+ new_m->vm_start = addr_m;
82504+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
82505+ }
82506+ }
82507+#endif
82508+
82509 pol = mpol_dup(vma_policy(vma));
82510 if (IS_ERR(pol)) {
82511 err = PTR_ERR(pol);
82512@@ -2406,6 +2778,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
82513 else
82514 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
82515
82516+#ifdef CONFIG_PAX_SEGMEXEC
82517+ if (!err && vma_m) {
82518+ if (anon_vma_clone(new_m, vma_m))
82519+ goto out_free_mpol;
82520+
82521+ mpol_get(pol);
82522+ vma_set_policy(new_m, pol);
82523+
82524+ if (new_m->vm_file)
82525+ get_file(new_m->vm_file);
82526+
82527+ if (new_m->vm_ops && new_m->vm_ops->open)
82528+ new_m->vm_ops->open(new_m);
82529+
82530+ if (new_below)
82531+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
82532+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
82533+ else
82534+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
82535+
82536+ if (err) {
82537+ if (new_m->vm_ops && new_m->vm_ops->close)
82538+ new_m->vm_ops->close(new_m);
82539+ if (new_m->vm_file)
82540+ fput(new_m->vm_file);
82541+ mpol_put(pol);
82542+ }
82543+ }
82544+#endif
82545+
82546 /* Success. */
82547 if (!err)
82548 return 0;
82549@@ -2415,10 +2817,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
82550 new->vm_ops->close(new);
82551 if (new->vm_file)
82552 fput(new->vm_file);
82553- unlink_anon_vmas(new);
82554 out_free_mpol:
82555 mpol_put(pol);
82556 out_free_vma:
82557+
82558+#ifdef CONFIG_PAX_SEGMEXEC
82559+ if (new_m) {
82560+ unlink_anon_vmas(new_m);
82561+ kmem_cache_free(vm_area_cachep, new_m);
82562+ }
82563+#endif
82564+
82565+ unlink_anon_vmas(new);
82566 kmem_cache_free(vm_area_cachep, new);
82567 out_err:
82568 return err;
82569@@ -2431,6 +2841,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
82570 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
82571 unsigned long addr, int new_below)
82572 {
82573+
82574+#ifdef CONFIG_PAX_SEGMEXEC
82575+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
82576+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
82577+ if (mm->map_count >= sysctl_max_map_count-1)
82578+ return -ENOMEM;
82579+ } else
82580+#endif
82581+
82582 if (mm->map_count >= sysctl_max_map_count)
82583 return -ENOMEM;
82584
82585@@ -2442,11 +2861,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
82586 * work. This now handles partial unmappings.
82587 * Jeremy Fitzhardinge <jeremy@goop.org>
82588 */
82589+#ifdef CONFIG_PAX_SEGMEXEC
82590 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
82591 {
82592+ int ret = __do_munmap(mm, start, len);
82593+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
82594+ return ret;
82595+
82596+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
82597+}
82598+
82599+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
82600+#else
82601+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
82602+#endif
82603+{
82604 unsigned long end;
82605 struct vm_area_struct *vma, *prev, *last;
82606
82607+ /*
82608+ * mm->mmap_sem is required to protect against another thread
82609+ * changing the mappings in case we sleep.
82610+ */
82611+ verify_mm_writelocked(mm);
82612+
82613 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
82614 return -EINVAL;
82615
82616@@ -2521,6 +2959,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
82617 /* Fix up all other VM information */
82618 remove_vma_list(mm, vma);
82619
82620+ track_exec_limit(mm, start, end, 0UL);
82621+
82622 return 0;
82623 }
82624
82625@@ -2529,6 +2969,13 @@ int vm_munmap(unsigned long start, size_t len)
82626 int ret;
82627 struct mm_struct *mm = current->mm;
82628
82629+
82630+#ifdef CONFIG_PAX_SEGMEXEC
82631+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
82632+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
82633+ return -EINVAL;
82634+#endif
82635+
82636 down_write(&mm->mmap_sem);
82637 ret = do_munmap(mm, start, len);
82638 up_write(&mm->mmap_sem);
82639@@ -2542,16 +2989,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
82640 return vm_munmap(addr, len);
82641 }
82642
82643-static inline void verify_mm_writelocked(struct mm_struct *mm)
82644-{
82645-#ifdef CONFIG_DEBUG_VM
82646- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
82647- WARN_ON(1);
82648- up_read(&mm->mmap_sem);
82649- }
82650-#endif
82651-}
82652-
82653 /*
82654 * this is really a simplified "do_mmap". it only handles
82655 * anonymous maps. eventually we may be able to do some
82656@@ -2565,6 +3002,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
82657 struct rb_node ** rb_link, * rb_parent;
82658 pgoff_t pgoff = addr >> PAGE_SHIFT;
82659 int error;
82660+ unsigned long charged;
82661
82662 len = PAGE_ALIGN(len);
82663 if (!len)
82664@@ -2572,16 +3010,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
82665
82666 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
82667
82668+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
82669+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
82670+ flags &= ~VM_EXEC;
82671+
82672+#ifdef CONFIG_PAX_MPROTECT
82673+ if (mm->pax_flags & MF_PAX_MPROTECT)
82674+ flags &= ~VM_MAYEXEC;
82675+#endif
82676+
82677+ }
82678+#endif
82679+
82680 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
82681 if (error & ~PAGE_MASK)
82682 return error;
82683
82684+ charged = len >> PAGE_SHIFT;
82685+
82686 /*
82687 * mlock MCL_FUTURE?
82688 */
82689 if (mm->def_flags & VM_LOCKED) {
82690 unsigned long locked, lock_limit;
82691- locked = len >> PAGE_SHIFT;
82692+ locked = charged;
82693 locked += mm->locked_vm;
82694 lock_limit = rlimit(RLIMIT_MEMLOCK);
82695 lock_limit >>= PAGE_SHIFT;
82696@@ -2598,21 +3050,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
82697 /*
82698 * Clear old maps. this also does some error checking for us
82699 */
82700- munmap_back:
82701 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
82702 if (do_munmap(mm, addr, len))
82703 return -ENOMEM;
82704- goto munmap_back;
82705+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
82706 }
82707
82708 /* Check against address space limits *after* clearing old maps... */
82709- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
82710+ if (!may_expand_vm(mm, charged))
82711 return -ENOMEM;
82712
82713 if (mm->map_count > sysctl_max_map_count)
82714 return -ENOMEM;
82715
82716- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
82717+ if (security_vm_enough_memory_mm(mm, charged))
82718 return -ENOMEM;
82719
82720 /* Can we just expand an old private anonymous mapping? */
82721@@ -2626,7 +3077,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
82722 */
82723 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82724 if (!vma) {
82725- vm_unacct_memory(len >> PAGE_SHIFT);
82726+ vm_unacct_memory(charged);
82727 return -ENOMEM;
82728 }
82729
82730@@ -2640,9 +3091,10 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
82731 vma_link(mm, vma, prev, rb_link, rb_parent);
82732 out:
82733 perf_event_mmap(vma);
82734- mm->total_vm += len >> PAGE_SHIFT;
82735+ mm->total_vm += charged;
82736 if (flags & VM_LOCKED)
82737- mm->locked_vm += (len >> PAGE_SHIFT);
82738+ mm->locked_vm += charged;
82739+ track_exec_limit(mm, addr, addr + len, flags);
82740 return addr;
82741 }
82742
82743@@ -2704,6 +3156,7 @@ void exit_mmap(struct mm_struct *mm)
82744 while (vma) {
82745 if (vma->vm_flags & VM_ACCOUNT)
82746 nr_accounted += vma_pages(vma);
82747+ vma->vm_mirror = NULL;
82748 vma = remove_vma(vma);
82749 }
82750 vm_unacct_memory(nr_accounted);
82751@@ -2720,6 +3173,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
82752 struct vm_area_struct *prev;
82753 struct rb_node **rb_link, *rb_parent;
82754
82755+#ifdef CONFIG_PAX_SEGMEXEC
82756+ struct vm_area_struct *vma_m = NULL;
82757+#endif
82758+
82759+ if (security_mmap_addr(vma->vm_start))
82760+ return -EPERM;
82761+
82762 /*
82763 * The vm_pgoff of a purely anonymous vma should be irrelevant
82764 * until its first write fault, when page's anon_vma and index
82765@@ -2743,7 +3203,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
82766 security_vm_enough_memory_mm(mm, vma_pages(vma)))
82767 return -ENOMEM;
82768
82769+#ifdef CONFIG_PAX_SEGMEXEC
82770+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
82771+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82772+ if (!vma_m)
82773+ return -ENOMEM;
82774+ }
82775+#endif
82776+
82777 vma_link(mm, vma, prev, rb_link, rb_parent);
82778+
82779+#ifdef CONFIG_PAX_SEGMEXEC
82780+ if (vma_m)
82781+ BUG_ON(pax_mirror_vma(vma_m, vma));
82782+#endif
82783+
82784 return 0;
82785 }
82786
82787@@ -2763,6 +3237,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
82788 struct mempolicy *pol;
82789 bool faulted_in_anon_vma = true;
82790
82791+ BUG_ON(vma->vm_mirror);
82792+
82793 /*
82794 * If anonymous vma has not yet been faulted, update new pgoff
82795 * to match new location, to increase its chance of merging.
82796@@ -2829,6 +3305,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
82797 return NULL;
82798 }
82799
82800+#ifdef CONFIG_PAX_SEGMEXEC
82801+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
82802+{
82803+ struct vm_area_struct *prev_m;
82804+ struct rb_node **rb_link_m, *rb_parent_m;
82805+ struct mempolicy *pol_m;
82806+
82807+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
82808+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
82809+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
82810+ *vma_m = *vma;
82811+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
82812+ if (anon_vma_clone(vma_m, vma))
82813+ return -ENOMEM;
82814+ pol_m = vma_policy(vma_m);
82815+ mpol_get(pol_m);
82816+ vma_set_policy(vma_m, pol_m);
82817+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
82818+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
82819+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
82820+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
82821+ if (vma_m->vm_file)
82822+ get_file(vma_m->vm_file);
82823+ if (vma_m->vm_ops && vma_m->vm_ops->open)
82824+ vma_m->vm_ops->open(vma_m);
82825+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
82826+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
82827+ vma_m->vm_mirror = vma;
82828+ vma->vm_mirror = vma_m;
82829+ return 0;
82830+}
82831+#endif
82832+
82833 /*
82834 * Return true if the calling process may expand its vm space by the passed
82835 * number of pages
82836@@ -2840,6 +3349,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
82837
82838 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
82839
82840+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
82841 if (cur + npages > lim)
82842 return 0;
82843 return 1;
82844@@ -2910,6 +3420,22 @@ int install_special_mapping(struct mm_struct *mm,
82845 vma->vm_start = addr;
82846 vma->vm_end = addr + len;
82847
82848+#ifdef CONFIG_PAX_MPROTECT
82849+ if (mm->pax_flags & MF_PAX_MPROTECT) {
82850+#ifndef CONFIG_PAX_MPROTECT_COMPAT
82851+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
82852+ return -EPERM;
82853+ if (!(vm_flags & VM_EXEC))
82854+ vm_flags &= ~VM_MAYEXEC;
82855+#else
82856+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
82857+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
82858+#endif
82859+ else
82860+ vm_flags &= ~VM_MAYWRITE;
82861+ }
82862+#endif
82863+
82864 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
82865 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
82866
82867diff --git a/mm/mprotect.c b/mm/mprotect.c
82868index 94722a4..07d9926 100644
82869--- a/mm/mprotect.c
82870+++ b/mm/mprotect.c
82871@@ -23,10 +23,18 @@
82872 #include <linux/mmu_notifier.h>
82873 #include <linux/migrate.h>
82874 #include <linux/perf_event.h>
82875+#include <linux/sched/sysctl.h>
82876+
82877+#ifdef CONFIG_PAX_MPROTECT
82878+#include <linux/elf.h>
82879+#include <linux/binfmts.h>
82880+#endif
82881+
82882 #include <asm/uaccess.h>
82883 #include <asm/pgtable.h>
82884 #include <asm/cacheflush.h>
82885 #include <asm/tlbflush.h>
82886+#include <asm/mmu_context.h>
82887
82888 #ifndef pgprot_modify
82889 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
82890@@ -233,6 +241,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
82891 return pages;
82892 }
82893
82894+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
82895+/* called while holding the mmap semaphor for writing except stack expansion */
82896+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
82897+{
82898+ unsigned long oldlimit, newlimit = 0UL;
82899+
82900+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
82901+ return;
82902+
82903+ spin_lock(&mm->page_table_lock);
82904+ oldlimit = mm->context.user_cs_limit;
82905+ if ((prot & VM_EXEC) && oldlimit < end)
82906+ /* USER_CS limit moved up */
82907+ newlimit = end;
82908+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
82909+ /* USER_CS limit moved down */
82910+ newlimit = start;
82911+
82912+ if (newlimit) {
82913+ mm->context.user_cs_limit = newlimit;
82914+
82915+#ifdef CONFIG_SMP
82916+ wmb();
82917+ cpus_clear(mm->context.cpu_user_cs_mask);
82918+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
82919+#endif
82920+
82921+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
82922+ }
82923+ spin_unlock(&mm->page_table_lock);
82924+ if (newlimit == end) {
82925+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
82926+
82927+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
82928+ if (is_vm_hugetlb_page(vma))
82929+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
82930+ else
82931+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
82932+ }
82933+}
82934+#endif
82935+
82936 int
82937 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
82938 unsigned long start, unsigned long end, unsigned long newflags)
82939@@ -245,11 +295,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
82940 int error;
82941 int dirty_accountable = 0;
82942
82943+#ifdef CONFIG_PAX_SEGMEXEC
82944+ struct vm_area_struct *vma_m = NULL;
82945+ unsigned long start_m, end_m;
82946+
82947+ start_m = start + SEGMEXEC_TASK_SIZE;
82948+ end_m = end + SEGMEXEC_TASK_SIZE;
82949+#endif
82950+
82951 if (newflags == oldflags) {
82952 *pprev = vma;
82953 return 0;
82954 }
82955
82956+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
82957+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
82958+
82959+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
82960+ return -ENOMEM;
82961+
82962+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
82963+ return -ENOMEM;
82964+ }
82965+
82966 /*
82967 * If we make a private mapping writable we increase our commit;
82968 * but (without finer accounting) cannot reduce our commit if we
82969@@ -266,6 +334,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
82970 }
82971 }
82972
82973+#ifdef CONFIG_PAX_SEGMEXEC
82974+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
82975+ if (start != vma->vm_start) {
82976+ error = split_vma(mm, vma, start, 1);
82977+ if (error)
82978+ goto fail;
82979+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
82980+ *pprev = (*pprev)->vm_next;
82981+ }
82982+
82983+ if (end != vma->vm_end) {
82984+ error = split_vma(mm, vma, end, 0);
82985+ if (error)
82986+ goto fail;
82987+ }
82988+
82989+ if (pax_find_mirror_vma(vma)) {
82990+ error = __do_munmap(mm, start_m, end_m - start_m);
82991+ if (error)
82992+ goto fail;
82993+ } else {
82994+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82995+ if (!vma_m) {
82996+ error = -ENOMEM;
82997+ goto fail;
82998+ }
82999+ vma->vm_flags = newflags;
83000+ error = pax_mirror_vma(vma_m, vma);
83001+ if (error) {
83002+ vma->vm_flags = oldflags;
83003+ goto fail;
83004+ }
83005+ }
83006+ }
83007+#endif
83008+
83009 /*
83010 * First try to merge with previous and/or next vma.
83011 */
83012@@ -296,9 +400,21 @@ success:
83013 * vm_flags and vm_page_prot are protected by the mmap_sem
83014 * held in write mode.
83015 */
83016+
83017+#ifdef CONFIG_PAX_SEGMEXEC
83018+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
83019+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
83020+#endif
83021+
83022 vma->vm_flags = newflags;
83023+
83024+#ifdef CONFIG_PAX_MPROTECT
83025+ if (mm->binfmt && mm->binfmt->handle_mprotect)
83026+ mm->binfmt->handle_mprotect(vma, newflags);
83027+#endif
83028+
83029 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
83030- vm_get_page_prot(newflags));
83031+ vm_get_page_prot(vma->vm_flags));
83032
83033 if (vma_wants_writenotify(vma)) {
83034 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
83035@@ -337,6 +453,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83036 end = start + len;
83037 if (end <= start)
83038 return -ENOMEM;
83039+
83040+#ifdef CONFIG_PAX_SEGMEXEC
83041+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
83042+ if (end > SEGMEXEC_TASK_SIZE)
83043+ return -EINVAL;
83044+ } else
83045+#endif
83046+
83047+ if (end > TASK_SIZE)
83048+ return -EINVAL;
83049+
83050 if (!arch_validate_prot(prot))
83051 return -EINVAL;
83052
83053@@ -344,7 +471,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83054 /*
83055 * Does the application expect PROT_READ to imply PROT_EXEC:
83056 */
83057- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
83058+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
83059 prot |= PROT_EXEC;
83060
83061 vm_flags = calc_vm_prot_bits(prot);
83062@@ -376,6 +503,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83063 if (start > vma->vm_start)
83064 prev = vma;
83065
83066+#ifdef CONFIG_PAX_MPROTECT
83067+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
83068+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
83069+#endif
83070+
83071 for (nstart = start ; ; ) {
83072 unsigned long newflags;
83073
83074@@ -386,6 +518,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83075
83076 /* newflags >> 4 shift VM_MAY% in place of VM_% */
83077 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
83078+ if (prot & (PROT_WRITE | PROT_EXEC))
83079+ gr_log_rwxmprotect(vma->vm_file);
83080+
83081+ error = -EACCES;
83082+ goto out;
83083+ }
83084+
83085+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
83086 error = -EACCES;
83087 goto out;
83088 }
83089@@ -400,6 +540,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83090 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
83091 if (error)
83092 goto out;
83093+
83094+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
83095+
83096 nstart = tmp;
83097
83098 if (nstart < prev->vm_end)
83099diff --git a/mm/mremap.c b/mm/mremap.c
83100index 463a257..c0c7a92 100644
83101--- a/mm/mremap.c
83102+++ b/mm/mremap.c
83103@@ -126,6 +126,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
83104 continue;
83105 pte = ptep_get_and_clear(mm, old_addr, old_pte);
83106 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
83107+
83108+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83109+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
83110+ pte = pte_exprotect(pte);
83111+#endif
83112+
83113 set_pte_at(mm, new_addr, new_pte, pte);
83114 }
83115
83116@@ -318,6 +324,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
83117 if (is_vm_hugetlb_page(vma))
83118 goto Einval;
83119
83120+#ifdef CONFIG_PAX_SEGMEXEC
83121+ if (pax_find_mirror_vma(vma))
83122+ goto Einval;
83123+#endif
83124+
83125 /* We can't remap across vm area boundaries */
83126 if (old_len > vma->vm_end - addr)
83127 goto Efault;
83128@@ -373,20 +384,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
83129 unsigned long ret = -EINVAL;
83130 unsigned long charged = 0;
83131 unsigned long map_flags;
83132+ unsigned long pax_task_size = TASK_SIZE;
83133
83134 if (new_addr & ~PAGE_MASK)
83135 goto out;
83136
83137- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
83138+#ifdef CONFIG_PAX_SEGMEXEC
83139+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
83140+ pax_task_size = SEGMEXEC_TASK_SIZE;
83141+#endif
83142+
83143+ pax_task_size -= PAGE_SIZE;
83144+
83145+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
83146 goto out;
83147
83148 /* Check if the location we're moving into overlaps the
83149 * old location at all, and fail if it does.
83150 */
83151- if ((new_addr <= addr) && (new_addr+new_len) > addr)
83152- goto out;
83153-
83154- if ((addr <= new_addr) && (addr+old_len) > new_addr)
83155+ if (addr + old_len > new_addr && new_addr + new_len > addr)
83156 goto out;
83157
83158 ret = do_munmap(mm, new_addr, new_len);
83159@@ -455,6 +471,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83160 unsigned long ret = -EINVAL;
83161 unsigned long charged = 0;
83162 bool locked = false;
83163+ unsigned long pax_task_size = TASK_SIZE;
83164
83165 down_write(&current->mm->mmap_sem);
83166
83167@@ -475,6 +492,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83168 if (!new_len)
83169 goto out;
83170
83171+#ifdef CONFIG_PAX_SEGMEXEC
83172+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
83173+ pax_task_size = SEGMEXEC_TASK_SIZE;
83174+#endif
83175+
83176+ pax_task_size -= PAGE_SIZE;
83177+
83178+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
83179+ old_len > pax_task_size || addr > pax_task_size-old_len)
83180+ goto out;
83181+
83182 if (flags & MREMAP_FIXED) {
83183 if (flags & MREMAP_MAYMOVE)
83184 ret = mremap_to(addr, old_len, new_addr, new_len,
83185@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83186 new_addr = addr;
83187 }
83188 ret = addr;
83189+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
83190 goto out;
83191 }
83192 }
83193@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83194 goto out;
83195 }
83196
83197+ map_flags = vma->vm_flags;
83198 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
83199+ if (!(ret & ~PAGE_MASK)) {
83200+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
83201+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
83202+ }
83203 }
83204 out:
83205 if (ret & ~PAGE_MASK)
83206diff --git a/mm/nommu.c b/mm/nommu.c
83207index e001768..9b52b30 100644
83208--- a/mm/nommu.c
83209+++ b/mm/nommu.c
83210@@ -63,7 +63,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
83211 int sysctl_overcommit_ratio = 50; /* default is 50% */
83212 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
83213 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
83214-int heap_stack_gap = 0;
83215
83216 atomic_long_t mmap_pages_allocated;
83217
83218@@ -841,15 +840,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
83219 EXPORT_SYMBOL(find_vma);
83220
83221 /*
83222- * find a VMA
83223- * - we don't extend stack VMAs under NOMMU conditions
83224- */
83225-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
83226-{
83227- return find_vma(mm, addr);
83228-}
83229-
83230-/*
83231 * expand a stack to a given address
83232 * - not supported under NOMMU conditions
83233 */
83234@@ -1560,6 +1550,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83235
83236 /* most fields are the same, copy all, and then fixup */
83237 *new = *vma;
83238+ INIT_LIST_HEAD(&new->anon_vma_chain);
83239 *region = *vma->vm_region;
83240 new->vm_region = region;
83241
83242@@ -1992,8 +1983,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
83243 }
83244 EXPORT_SYMBOL(generic_file_remap_pages);
83245
83246-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83247- unsigned long addr, void *buf, int len, int write)
83248+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83249+ unsigned long addr, void *buf, size_t len, int write)
83250 {
83251 struct vm_area_struct *vma;
83252
83253@@ -2034,8 +2025,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83254 *
83255 * The caller must hold a reference on @mm.
83256 */
83257-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83258- void *buf, int len, int write)
83259+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
83260+ void *buf, size_t len, int write)
83261 {
83262 return __access_remote_vm(NULL, mm, addr, buf, len, write);
83263 }
83264@@ -2044,7 +2035,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83265 * Access another process' address space.
83266 * - source/target buffer must be kernel space
83267 */
83268-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
83269+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
83270 {
83271 struct mm_struct *mm;
83272
83273diff --git a/mm/page-writeback.c b/mm/page-writeback.c
83274index efe6814..64b4701 100644
83275--- a/mm/page-writeback.c
83276+++ b/mm/page-writeback.c
83277@@ -659,7 +659,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
83278 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
83279 * - the bdi dirty thresh drops quickly due to change of JBOD workload
83280 */
83281-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
83282+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
83283 unsigned long thresh,
83284 unsigned long bg_thresh,
83285 unsigned long dirty,
83286@@ -1634,7 +1634,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
83287 }
83288 }
83289
83290-static struct notifier_block __cpuinitdata ratelimit_nb = {
83291+static struct notifier_block ratelimit_nb = {
83292 .notifier_call = ratelimit_handler,
83293 .next = NULL,
83294 };
83295diff --git a/mm/page_alloc.c b/mm/page_alloc.c
83296index 8fcced7..ebcd481 100644
83297--- a/mm/page_alloc.c
83298+++ b/mm/page_alloc.c
83299@@ -59,6 +59,7 @@
83300 #include <linux/migrate.h>
83301 #include <linux/page-debug-flags.h>
83302 #include <linux/sched/rt.h>
83303+#include <linux/random.h>
83304
83305 #include <asm/tlbflush.h>
83306 #include <asm/div64.h>
83307@@ -344,7 +345,7 @@ out:
83308 * This usage means that zero-order pages may not be compound.
83309 */
83310
83311-static void free_compound_page(struct page *page)
83312+void free_compound_page(struct page *page)
83313 {
83314 __free_pages_ok(page, compound_order(page));
83315 }
83316@@ -701,6 +702,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
83317 int i;
83318 int bad = 0;
83319
83320+#ifdef CONFIG_PAX_MEMORY_SANITIZE
83321+ unsigned long index = 1UL << order;
83322+#endif
83323+
83324 trace_mm_page_free(page, order);
83325 kmemcheck_free_shadow(page, order);
83326
83327@@ -716,6 +721,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
83328 debug_check_no_obj_freed(page_address(page),
83329 PAGE_SIZE << order);
83330 }
83331+
83332+#ifdef CONFIG_PAX_MEMORY_SANITIZE
83333+ for (; index; --index)
83334+ sanitize_highpage(page + index - 1);
83335+#endif
83336+
83337 arch_free_page(page, order);
83338 kernel_map_pages(page, 1 << order, 0);
83339
83340@@ -738,6 +749,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
83341 local_irq_restore(flags);
83342 }
83343
83344+#ifdef CONFIG_PAX_LATENT_ENTROPY
83345+bool __meminitdata extra_latent_entropy;
83346+
83347+static int __init setup_pax_extra_latent_entropy(char *str)
83348+{
83349+ extra_latent_entropy = true;
83350+ return 0;
83351+}
83352+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
83353+
83354+volatile u64 latent_entropy;
83355+#endif
83356+
83357 /*
83358 * Read access to zone->managed_pages is safe because it's unsigned long,
83359 * but we still need to serialize writers. Currently all callers of
83360@@ -760,6 +784,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
83361 set_page_count(p, 0);
83362 }
83363
83364+#ifdef CONFIG_PAX_LATENT_ENTROPY
83365+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
83366+ u64 hash = 0;
83367+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
83368+ const u64 *data = lowmem_page_address(page);
83369+
83370+ for (index = 0; index < end; index++)
83371+ hash ^= hash + data[index];
83372+ latent_entropy ^= hash;
83373+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
83374+ }
83375+#endif
83376+
83377 page_zone(page)->managed_pages += 1 << order;
83378 set_page_refcounted(page);
83379 __free_pages(page, order);
83380@@ -869,8 +906,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
83381 arch_alloc_page(page, order);
83382 kernel_map_pages(page, 1 << order, 1);
83383
83384+#ifndef CONFIG_PAX_MEMORY_SANITIZE
83385 if (gfp_flags & __GFP_ZERO)
83386 prep_zero_page(page, order, gfp_flags);
83387+#endif
83388
83389 if (order && (gfp_flags & __GFP_COMP))
83390 prep_compound_page(page, order);
83391diff --git a/mm/page_io.c b/mm/page_io.c
83392index 6182870..4bba6a2 100644
83393--- a/mm/page_io.c
83394+++ b/mm/page_io.c
83395@@ -205,7 +205,7 @@ int swap_writepage(struct page *page, struct writeback_control *wbc)
83396 struct file *swap_file = sis->swap_file;
83397 struct address_space *mapping = swap_file->f_mapping;
83398 struct iovec iov = {
83399- .iov_base = kmap(page),
83400+ .iov_base = (void __force_user *)kmap(page),
83401 .iov_len = PAGE_SIZE,
83402 };
83403
83404diff --git a/mm/percpu.c b/mm/percpu.c
83405index 8c8e08f..73a5cda 100644
83406--- a/mm/percpu.c
83407+++ b/mm/percpu.c
83408@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
83409 static unsigned int pcpu_high_unit_cpu __read_mostly;
83410
83411 /* the address of the first chunk which starts with the kernel static area */
83412-void *pcpu_base_addr __read_mostly;
83413+void *pcpu_base_addr __read_only;
83414 EXPORT_SYMBOL_GPL(pcpu_base_addr);
83415
83416 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
83417diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
83418index fd26d04..0cea1b0 100644
83419--- a/mm/process_vm_access.c
83420+++ b/mm/process_vm_access.c
83421@@ -13,6 +13,7 @@
83422 #include <linux/uio.h>
83423 #include <linux/sched.h>
83424 #include <linux/highmem.h>
83425+#include <linux/security.h>
83426 #include <linux/ptrace.h>
83427 #include <linux/slab.h>
83428 #include <linux/syscalls.h>
83429@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
83430 size_t iov_l_curr_offset = 0;
83431 ssize_t iov_len;
83432
83433+ return -ENOSYS; // PaX: until properly audited
83434+
83435 /*
83436 * Work out how many pages of struct pages we're going to need
83437 * when eventually calling get_user_pages
83438 */
83439 for (i = 0; i < riovcnt; i++) {
83440 iov_len = rvec[i].iov_len;
83441- if (iov_len > 0) {
83442- nr_pages_iov = ((unsigned long)rvec[i].iov_base
83443- + iov_len)
83444- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
83445- / PAGE_SIZE + 1;
83446- nr_pages = max(nr_pages, nr_pages_iov);
83447- }
83448+ if (iov_len <= 0)
83449+ continue;
83450+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
83451+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
83452+ nr_pages = max(nr_pages, nr_pages_iov);
83453 }
83454
83455 if (nr_pages == 0)
83456@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
83457 goto free_proc_pages;
83458 }
83459
83460+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
83461+ rc = -EPERM;
83462+ goto put_task_struct;
83463+ }
83464+
83465 mm = mm_access(task, PTRACE_MODE_ATTACH);
83466 if (!mm || IS_ERR(mm)) {
83467 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
83468diff --git a/mm/rmap.c b/mm/rmap.c
83469index 807c96b..0e05279 100644
83470--- a/mm/rmap.c
83471+++ b/mm/rmap.c
83472@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
83473 struct anon_vma *anon_vma = vma->anon_vma;
83474 struct anon_vma_chain *avc;
83475
83476+#ifdef CONFIG_PAX_SEGMEXEC
83477+ struct anon_vma_chain *avc_m = NULL;
83478+#endif
83479+
83480 might_sleep();
83481 if (unlikely(!anon_vma)) {
83482 struct mm_struct *mm = vma->vm_mm;
83483@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
83484 if (!avc)
83485 goto out_enomem;
83486
83487+#ifdef CONFIG_PAX_SEGMEXEC
83488+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
83489+ if (!avc_m)
83490+ goto out_enomem_free_avc;
83491+#endif
83492+
83493 anon_vma = find_mergeable_anon_vma(vma);
83494 allocated = NULL;
83495 if (!anon_vma) {
83496@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
83497 /* page_table_lock to protect against threads */
83498 spin_lock(&mm->page_table_lock);
83499 if (likely(!vma->anon_vma)) {
83500+
83501+#ifdef CONFIG_PAX_SEGMEXEC
83502+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
83503+
83504+ if (vma_m) {
83505+ BUG_ON(vma_m->anon_vma);
83506+ vma_m->anon_vma = anon_vma;
83507+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
83508+ avc_m = NULL;
83509+ }
83510+#endif
83511+
83512 vma->anon_vma = anon_vma;
83513 anon_vma_chain_link(vma, avc, anon_vma);
83514 allocated = NULL;
83515@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
83516
83517 if (unlikely(allocated))
83518 put_anon_vma(allocated);
83519+
83520+#ifdef CONFIG_PAX_SEGMEXEC
83521+ if (unlikely(avc_m))
83522+ anon_vma_chain_free(avc_m);
83523+#endif
83524+
83525 if (unlikely(avc))
83526 anon_vma_chain_free(avc);
83527 }
83528 return 0;
83529
83530 out_enomem_free_avc:
83531+
83532+#ifdef CONFIG_PAX_SEGMEXEC
83533+ if (avc_m)
83534+ anon_vma_chain_free(avc_m);
83535+#endif
83536+
83537 anon_vma_chain_free(avc);
83538 out_enomem:
83539 return -ENOMEM;
83540@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
83541 * Attach the anon_vmas from src to dst.
83542 * Returns 0 on success, -ENOMEM on failure.
83543 */
83544-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
83545+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
83546 {
83547 struct anon_vma_chain *avc, *pavc;
83548 struct anon_vma *root = NULL;
83549@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
83550 * the corresponding VMA in the parent process is attached to.
83551 * Returns 0 on success, non-zero on failure.
83552 */
83553-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
83554+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
83555 {
83556 struct anon_vma_chain *avc;
83557 struct anon_vma *anon_vma;
83558diff --git a/mm/shmem.c b/mm/shmem.c
83559index 1c44af7..cefe9a6 100644
83560--- a/mm/shmem.c
83561+++ b/mm/shmem.c
83562@@ -31,7 +31,7 @@
83563 #include <linux/export.h>
83564 #include <linux/swap.h>
83565
83566-static struct vfsmount *shm_mnt;
83567+struct vfsmount *shm_mnt;
83568
83569 #ifdef CONFIG_SHMEM
83570 /*
83571@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
83572 #define BOGO_DIRENT_SIZE 20
83573
83574 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
83575-#define SHORT_SYMLINK_LEN 128
83576+#define SHORT_SYMLINK_LEN 64
83577
83578 /*
83579 * shmem_fallocate and shmem_writepage communicate via inode->i_private
83580@@ -2201,6 +2201,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
83581 static int shmem_xattr_validate(const char *name)
83582 {
83583 struct { const char *prefix; size_t len; } arr[] = {
83584+
83585+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83586+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
83587+#endif
83588+
83589 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
83590 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
83591 };
83592@@ -2256,6 +2261,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
83593 if (err)
83594 return err;
83595
83596+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83597+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
83598+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
83599+ return -EOPNOTSUPP;
83600+ if (size > 8)
83601+ return -EINVAL;
83602+ }
83603+#endif
83604+
83605 return simple_xattr_set(&info->xattrs, name, value, size, flags);
83606 }
83607
83608@@ -2568,8 +2582,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
83609 int err = -ENOMEM;
83610
83611 /* Round up to L1_CACHE_BYTES to resist false sharing */
83612- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
83613- L1_CACHE_BYTES), GFP_KERNEL);
83614+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
83615 if (!sbinfo)
83616 return -ENOMEM;
83617
83618diff --git a/mm/slab.c b/mm/slab.c
83619index 856e4a1..fafb820 100644
83620--- a/mm/slab.c
83621+++ b/mm/slab.c
83622@@ -306,7 +306,7 @@ struct kmem_list3 {
83623 * Need this for bootstrapping a per node allocator.
83624 */
83625 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
83626-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
83627+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
83628 #define CACHE_CACHE 0
83629 #define SIZE_AC MAX_NUMNODES
83630 #define SIZE_L3 (2 * MAX_NUMNODES)
83631@@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
83632 if ((x)->max_freeable < i) \
83633 (x)->max_freeable = i; \
83634 } while (0)
83635-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
83636-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
83637-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
83638-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
83639+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
83640+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
83641+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
83642+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
83643 #else
83644 #define STATS_INC_ACTIVE(x) do { } while (0)
83645 #define STATS_DEC_ACTIVE(x) do { } while (0)
83646@@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
83647 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
83648 */
83649 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
83650- const struct slab *slab, void *obj)
83651+ const struct slab *slab, const void *obj)
83652 {
83653 u32 offset = (obj - slab->s_mem);
83654 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
83655@@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
83656 struct cache_names {
83657 char *name;
83658 char *name_dma;
83659+ char *name_usercopy;
83660 };
83661
83662 static struct cache_names __initdata cache_names[] = {
83663-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
83664+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
83665 #include <linux/kmalloc_sizes.h>
83666- {NULL,}
83667+ {NULL}
83668 #undef CACHE
83669 };
83670
83671@@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
83672 if (unlikely(gfpflags & GFP_DMA))
83673 return csizep->cs_dmacachep;
83674 #endif
83675+
83676+#ifdef CONFIG_PAX_USERCOPY_SLABS
83677+ if (unlikely(gfpflags & GFP_USERCOPY))
83678+ return csizep->cs_usercopycachep;
83679+#endif
83680+
83681 return csizep->cs_cachep;
83682 }
83683
83684@@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
83685 return notifier_from_errno(err);
83686 }
83687
83688-static struct notifier_block __cpuinitdata cpucache_notifier = {
83689+static struct notifier_block cpucache_notifier = {
83690 &cpuup_callback, NULL, 0
83691 };
83692
83693@@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
83694 */
83695
83696 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
83697- sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
83698+ sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
83699
83700 if (INDEX_AC != INDEX_L3)
83701 sizes[INDEX_L3].cs_cachep =
83702 create_kmalloc_cache(names[INDEX_L3].name,
83703- sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
83704+ sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
83705
83706 slab_early_init = 0;
83707
83708@@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
83709 */
83710 if (!sizes->cs_cachep)
83711 sizes->cs_cachep = create_kmalloc_cache(names->name,
83712- sizes->cs_size, ARCH_KMALLOC_FLAGS);
83713+ sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
83714
83715 #ifdef CONFIG_ZONE_DMA
83716 sizes->cs_dmacachep = create_kmalloc_cache(
83717 names->name_dma, sizes->cs_size,
83718 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
83719 #endif
83720+
83721+#ifdef CONFIG_PAX_USERCOPY_SLABS
83722+ sizes->cs_usercopycachep = create_kmalloc_cache(
83723+ names->name_usercopy, sizes->cs_size,
83724+ ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
83725+#endif
83726+
83727 sizes++;
83728 names++;
83729 }
83730@@ -3924,6 +3938,7 @@ void kfree(const void *objp)
83731
83732 if (unlikely(ZERO_OR_NULL_PTR(objp)))
83733 return;
83734+ VM_BUG_ON(!virt_addr_valid(objp));
83735 local_irq_save(flags);
83736 kfree_debugcheck(objp);
83737 c = virt_to_cache(objp);
83738@@ -4365,10 +4380,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
83739 }
83740 /* cpu stats */
83741 {
83742- unsigned long allochit = atomic_read(&cachep->allochit);
83743- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
83744- unsigned long freehit = atomic_read(&cachep->freehit);
83745- unsigned long freemiss = atomic_read(&cachep->freemiss);
83746+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
83747+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
83748+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
83749+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
83750
83751 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
83752 allochit, allocmiss, freehit, freemiss);
83753@@ -4600,13 +4615,71 @@ static const struct file_operations proc_slabstats_operations = {
83754 static int __init slab_proc_init(void)
83755 {
83756 #ifdef CONFIG_DEBUG_SLAB_LEAK
83757- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
83758+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
83759 #endif
83760 return 0;
83761 }
83762 module_init(slab_proc_init);
83763 #endif
83764
83765+bool is_usercopy_object(const void *ptr)
83766+{
83767+ struct page *page;
83768+ struct kmem_cache *cachep;
83769+
83770+ if (ZERO_OR_NULL_PTR(ptr))
83771+ return false;
83772+
83773+ if (!slab_is_available())
83774+ return false;
83775+
83776+ if (!virt_addr_valid(ptr))
83777+ return false;
83778+
83779+ page = virt_to_head_page(ptr);
83780+
83781+ if (!PageSlab(page))
83782+ return false;
83783+
83784+ cachep = page->slab_cache;
83785+ return cachep->flags & SLAB_USERCOPY;
83786+}
83787+
83788+#ifdef CONFIG_PAX_USERCOPY
83789+const char *check_heap_object(const void *ptr, unsigned long n)
83790+{
83791+ struct page *page;
83792+ struct kmem_cache *cachep;
83793+ struct slab *slabp;
83794+ unsigned int objnr;
83795+ unsigned long offset;
83796+
83797+ if (ZERO_OR_NULL_PTR(ptr))
83798+ return "<null>";
83799+
83800+ if (!virt_addr_valid(ptr))
83801+ return NULL;
83802+
83803+ page = virt_to_head_page(ptr);
83804+
83805+ if (!PageSlab(page))
83806+ return NULL;
83807+
83808+ cachep = page->slab_cache;
83809+ if (!(cachep->flags & SLAB_USERCOPY))
83810+ return cachep->name;
83811+
83812+ slabp = page->slab_page;
83813+ objnr = obj_to_index(cachep, slabp, ptr);
83814+ BUG_ON(objnr >= cachep->num);
83815+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
83816+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
83817+ return NULL;
83818+
83819+ return cachep->name;
83820+}
83821+#endif
83822+
83823 /**
83824 * ksize - get the actual amount of memory allocated for a given object
83825 * @objp: Pointer to the object
83826diff --git a/mm/slab.h b/mm/slab.h
83827index 34a98d6..73633d1 100644
83828--- a/mm/slab.h
83829+++ b/mm/slab.h
83830@@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
83831
83832 /* Legal flag mask for kmem_cache_create(), for various configurations */
83833 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
83834- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
83835+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
83836
83837 #if defined(CONFIG_DEBUG_SLAB)
83838 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
83839@@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
83840 return s;
83841
83842 page = virt_to_head_page(x);
83843+
83844+ BUG_ON(!PageSlab(page));
83845+
83846 cachep = page->slab_cache;
83847 if (slab_equal_or_root(cachep, s))
83848 return cachep;
83849diff --git a/mm/slab_common.c b/mm/slab_common.c
83850index 3f3cd97..93b0236 100644
83851--- a/mm/slab_common.c
83852+++ b/mm/slab_common.c
83853@@ -22,7 +22,7 @@
83854
83855 #include "slab.h"
83856
83857-enum slab_state slab_state;
83858+enum slab_state slab_state __read_only;
83859 LIST_HEAD(slab_caches);
83860 DEFINE_MUTEX(slab_mutex);
83861 struct kmem_cache *kmem_cache;
83862@@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
83863
83864 err = __kmem_cache_create(s, flags);
83865 if (!err) {
83866- s->refcount = 1;
83867+ atomic_set(&s->refcount, 1);
83868 list_add(&s->list, &slab_caches);
83869 memcg_cache_list_add(memcg, s);
83870 } else {
83871@@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
83872
83873 get_online_cpus();
83874 mutex_lock(&slab_mutex);
83875- s->refcount--;
83876- if (!s->refcount) {
83877+ if (atomic_dec_and_test(&s->refcount)) {
83878 list_del(&s->list);
83879
83880 if (!__kmem_cache_shutdown(s)) {
83881@@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
83882 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
83883 name, size, err);
83884
83885- s->refcount = -1; /* Exempt from merging for now */
83886+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
83887 }
83888
83889 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
83890@@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
83891
83892 create_boot_cache(s, name, size, flags);
83893 list_add(&s->list, &slab_caches);
83894- s->refcount = 1;
83895+ atomic_set(&s->refcount, 1);
83896 return s;
83897 }
83898
83899diff --git a/mm/slob.c b/mm/slob.c
83900index eeed4a0..6ee34ec 100644
83901--- a/mm/slob.c
83902+++ b/mm/slob.c
83903@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
83904 /*
83905 * Return the size of a slob block.
83906 */
83907-static slobidx_t slob_units(slob_t *s)
83908+static slobidx_t slob_units(const slob_t *s)
83909 {
83910 if (s->units > 0)
83911 return s->units;
83912@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
83913 /*
83914 * Return the next free slob block pointer after this one.
83915 */
83916-static slob_t *slob_next(slob_t *s)
83917+static slob_t *slob_next(const slob_t *s)
83918 {
83919 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
83920 slobidx_t next;
83921@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
83922 /*
83923 * Returns true if s is the last free block in its page.
83924 */
83925-static int slob_last(slob_t *s)
83926+static int slob_last(const slob_t *s)
83927 {
83928 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
83929 }
83930
83931-static void *slob_new_pages(gfp_t gfp, int order, int node)
83932+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
83933 {
83934- void *page;
83935+ struct page *page;
83936
83937 #ifdef CONFIG_NUMA
83938 if (node != NUMA_NO_NODE)
83939@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
83940 if (!page)
83941 return NULL;
83942
83943- return page_address(page);
83944+ __SetPageSlab(page);
83945+ return page;
83946 }
83947
83948-static void slob_free_pages(void *b, int order)
83949+static void slob_free_pages(struct page *sp, int order)
83950 {
83951 if (current->reclaim_state)
83952 current->reclaim_state->reclaimed_slab += 1 << order;
83953- free_pages((unsigned long)b, order);
83954+ __ClearPageSlab(sp);
83955+ reset_page_mapcount(sp);
83956+ sp->private = 0;
83957+ __free_pages(sp, order);
83958 }
83959
83960 /*
83961@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
83962
83963 /* Not enough space: must allocate a new page */
83964 if (!b) {
83965- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
83966- if (!b)
83967+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
83968+ if (!sp)
83969 return NULL;
83970- sp = virt_to_page(b);
83971- __SetPageSlab(sp);
83972+ b = page_address(sp);
83973
83974 spin_lock_irqsave(&slob_lock, flags);
83975 sp->units = SLOB_UNITS(PAGE_SIZE);
83976 sp->freelist = b;
83977+ sp->private = 0;
83978 INIT_LIST_HEAD(&sp->list);
83979 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
83980 set_slob_page_free(sp, slob_list);
83981@@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
83982 if (slob_page_free(sp))
83983 clear_slob_page_free(sp);
83984 spin_unlock_irqrestore(&slob_lock, flags);
83985- __ClearPageSlab(sp);
83986- page_mapcount_reset(sp);
83987- slob_free_pages(b, 0);
83988+ slob_free_pages(sp, 0);
83989 return;
83990 }
83991
83992@@ -424,11 +426,10 @@ out:
83993 */
83994
83995 static __always_inline void *
83996-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
83997+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
83998 {
83999- unsigned int *m;
84000- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84001- void *ret;
84002+ slob_t *m;
84003+ void *ret = NULL;
84004
84005 gfp &= gfp_allowed_mask;
84006
84007@@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84008
84009 if (!m)
84010 return NULL;
84011- *m = size;
84012+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
84013+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
84014+ m[0].units = size;
84015+ m[1].units = align;
84016 ret = (void *)m + align;
84017
84018 trace_kmalloc_node(caller, ret,
84019 size, size + align, gfp, node);
84020 } else {
84021 unsigned int order = get_order(size);
84022+ struct page *page;
84023
84024 if (likely(order))
84025 gfp |= __GFP_COMP;
84026- ret = slob_new_pages(gfp, order, node);
84027+ page = slob_new_pages(gfp, order, node);
84028+ if (page) {
84029+ ret = page_address(page);
84030+ page->private = size;
84031+ }
84032
84033 trace_kmalloc_node(caller, ret,
84034 size, PAGE_SIZE << order, gfp, node);
84035 }
84036
84037- kmemleak_alloc(ret, size, 1, gfp);
84038+ return ret;
84039+}
84040+
84041+static __always_inline void *
84042+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84043+{
84044+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84045+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
84046+
84047+ if (!ZERO_OR_NULL_PTR(ret))
84048+ kmemleak_alloc(ret, size, 1, gfp);
84049 return ret;
84050 }
84051
84052@@ -493,34 +512,112 @@ void kfree(const void *block)
84053 return;
84054 kmemleak_free(block);
84055
84056+ VM_BUG_ON(!virt_addr_valid(block));
84057 sp = virt_to_page(block);
84058- if (PageSlab(sp)) {
84059+ VM_BUG_ON(!PageSlab(sp));
84060+ if (!sp->private) {
84061 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84062- unsigned int *m = (unsigned int *)(block - align);
84063- slob_free(m, *m + align);
84064- } else
84065+ slob_t *m = (slob_t *)(block - align);
84066+ slob_free(m, m[0].units + align);
84067+ } else {
84068+ __ClearPageSlab(sp);
84069+ reset_page_mapcount(sp);
84070+ sp->private = 0;
84071 __free_pages(sp, compound_order(sp));
84072+ }
84073 }
84074 EXPORT_SYMBOL(kfree);
84075
84076+bool is_usercopy_object(const void *ptr)
84077+{
84078+ if (!slab_is_available())
84079+ return false;
84080+
84081+ // PAX: TODO
84082+
84083+ return false;
84084+}
84085+
84086+#ifdef CONFIG_PAX_USERCOPY
84087+const char *check_heap_object(const void *ptr, unsigned long n)
84088+{
84089+ struct page *page;
84090+ const slob_t *free;
84091+ const void *base;
84092+ unsigned long flags;
84093+
84094+ if (ZERO_OR_NULL_PTR(ptr))
84095+ return "<null>";
84096+
84097+ if (!virt_addr_valid(ptr))
84098+ return NULL;
84099+
84100+ page = virt_to_head_page(ptr);
84101+ if (!PageSlab(page))
84102+ return NULL;
84103+
84104+ if (page->private) {
84105+ base = page;
84106+ if (base <= ptr && n <= page->private - (ptr - base))
84107+ return NULL;
84108+ return "<slob>";
84109+ }
84110+
84111+ /* some tricky double walking to find the chunk */
84112+ spin_lock_irqsave(&slob_lock, flags);
84113+ base = (void *)((unsigned long)ptr & PAGE_MASK);
84114+ free = page->freelist;
84115+
84116+ while (!slob_last(free) && (void *)free <= ptr) {
84117+ base = free + slob_units(free);
84118+ free = slob_next(free);
84119+ }
84120+
84121+ while (base < (void *)free) {
84122+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
84123+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
84124+ int offset;
84125+
84126+ if (ptr < base + align)
84127+ break;
84128+
84129+ offset = ptr - base - align;
84130+ if (offset >= m) {
84131+ base += size;
84132+ continue;
84133+ }
84134+
84135+ if (n > m - offset)
84136+ break;
84137+
84138+ spin_unlock_irqrestore(&slob_lock, flags);
84139+ return NULL;
84140+ }
84141+
84142+ spin_unlock_irqrestore(&slob_lock, flags);
84143+ return "<slob>";
84144+}
84145+#endif
84146+
84147 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
84148 size_t ksize(const void *block)
84149 {
84150 struct page *sp;
84151 int align;
84152- unsigned int *m;
84153+ slob_t *m;
84154
84155 BUG_ON(!block);
84156 if (unlikely(block == ZERO_SIZE_PTR))
84157 return 0;
84158
84159 sp = virt_to_page(block);
84160- if (unlikely(!PageSlab(sp)))
84161- return PAGE_SIZE << compound_order(sp);
84162+ VM_BUG_ON(!PageSlab(sp));
84163+ if (sp->private)
84164+ return sp->private;
84165
84166 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84167- m = (unsigned int *)(block - align);
84168- return SLOB_UNITS(*m) * SLOB_UNIT;
84169+ m = (slob_t *)(block - align);
84170+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
84171 }
84172 EXPORT_SYMBOL(ksize);
84173
84174@@ -536,23 +633,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
84175
84176 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
84177 {
84178- void *b;
84179+ void *b = NULL;
84180
84181 flags &= gfp_allowed_mask;
84182
84183 lockdep_trace_alloc(flags);
84184
84185+#ifdef CONFIG_PAX_USERCOPY_SLABS
84186+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
84187+#else
84188 if (c->size < PAGE_SIZE) {
84189 b = slob_alloc(c->size, flags, c->align, node);
84190 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
84191 SLOB_UNITS(c->size) * SLOB_UNIT,
84192 flags, node);
84193 } else {
84194- b = slob_new_pages(flags, get_order(c->size), node);
84195+ struct page *sp;
84196+
84197+ sp = slob_new_pages(flags, get_order(c->size), node);
84198+ if (sp) {
84199+ b = page_address(sp);
84200+ sp->private = c->size;
84201+ }
84202 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
84203 PAGE_SIZE << get_order(c->size),
84204 flags, node);
84205 }
84206+#endif
84207
84208 if (c->ctor)
84209 c->ctor(b);
84210@@ -564,10 +671,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
84211
84212 static void __kmem_cache_free(void *b, int size)
84213 {
84214- if (size < PAGE_SIZE)
84215+ struct page *sp;
84216+
84217+ sp = virt_to_page(b);
84218+ BUG_ON(!PageSlab(sp));
84219+ if (!sp->private)
84220 slob_free(b, size);
84221 else
84222- slob_free_pages(b, get_order(size));
84223+ slob_free_pages(sp, get_order(size));
84224 }
84225
84226 static void kmem_rcu_free(struct rcu_head *head)
84227@@ -580,17 +691,31 @@ static void kmem_rcu_free(struct rcu_head *head)
84228
84229 void kmem_cache_free(struct kmem_cache *c, void *b)
84230 {
84231+ int size = c->size;
84232+
84233+#ifdef CONFIG_PAX_USERCOPY_SLABS
84234+ if (size + c->align < PAGE_SIZE) {
84235+ size += c->align;
84236+ b -= c->align;
84237+ }
84238+#endif
84239+
84240 kmemleak_free_recursive(b, c->flags);
84241 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
84242 struct slob_rcu *slob_rcu;
84243- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
84244- slob_rcu->size = c->size;
84245+ slob_rcu = b + (size - sizeof(struct slob_rcu));
84246+ slob_rcu->size = size;
84247 call_rcu(&slob_rcu->head, kmem_rcu_free);
84248 } else {
84249- __kmem_cache_free(b, c->size);
84250+ __kmem_cache_free(b, size);
84251 }
84252
84253+#ifdef CONFIG_PAX_USERCOPY_SLABS
84254+ trace_kfree(_RET_IP_, b);
84255+#else
84256 trace_kmem_cache_free(_RET_IP_, b);
84257+#endif
84258+
84259 }
84260 EXPORT_SYMBOL(kmem_cache_free);
84261
84262diff --git a/mm/slub.c b/mm/slub.c
84263index 4aec537..a64753d 100644
84264--- a/mm/slub.c
84265+++ b/mm/slub.c
84266@@ -197,7 +197,7 @@ struct track {
84267
84268 enum track_item { TRACK_ALLOC, TRACK_FREE };
84269
84270-#ifdef CONFIG_SYSFS
84271+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84272 static int sysfs_slab_add(struct kmem_cache *);
84273 static int sysfs_slab_alias(struct kmem_cache *, const char *);
84274 static void sysfs_slab_remove(struct kmem_cache *);
84275@@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
84276 if (!t->addr)
84277 return;
84278
84279- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
84280+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
84281 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
84282 #ifdef CONFIG_STACKTRACE
84283 {
84284@@ -2653,7 +2653,7 @@ static int slub_min_objects;
84285 * Merge control. If this is set then no merging of slab caches will occur.
84286 * (Could be removed. This was introduced to pacify the merge skeptics.)
84287 */
84288-static int slub_nomerge;
84289+static int slub_nomerge = 1;
84290
84291 /*
84292 * Calculate the order of allocation given an slab object size.
84293@@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
84294 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
84295 #endif
84296
84297+#ifdef CONFIG_PAX_USERCOPY_SLABS
84298+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
84299+#endif
84300+
84301 static int __init setup_slub_min_order(char *str)
84302 {
84303 get_option(&str, &slub_min_order);
84304@@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
84305 return kmalloc_dma_caches[index];
84306
84307 #endif
84308+
84309+#ifdef CONFIG_PAX_USERCOPY_SLABS
84310+ if (flags & SLAB_USERCOPY)
84311+ return kmalloc_usercopy_caches[index];
84312+
84313+#endif
84314+
84315 return kmalloc_caches[index];
84316 }
84317
84318@@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
84319 EXPORT_SYMBOL(__kmalloc_node);
84320 #endif
84321
84322+bool is_usercopy_object(const void *ptr)
84323+{
84324+ struct page *page;
84325+ struct kmem_cache *s;
84326+
84327+ if (ZERO_OR_NULL_PTR(ptr))
84328+ return false;
84329+
84330+ if (!slab_is_available())
84331+ return false;
84332+
84333+ if (!virt_addr_valid(ptr))
84334+ return false;
84335+
84336+ page = virt_to_head_page(ptr);
84337+
84338+ if (!PageSlab(page))
84339+ return false;
84340+
84341+ s = page->slab_cache;
84342+ return s->flags & SLAB_USERCOPY;
84343+}
84344+
84345+#ifdef CONFIG_PAX_USERCOPY
84346+const char *check_heap_object(const void *ptr, unsigned long n)
84347+{
84348+ struct page *page;
84349+ struct kmem_cache *s;
84350+ unsigned long offset;
84351+
84352+ if (ZERO_OR_NULL_PTR(ptr))
84353+ return "<null>";
84354+
84355+ if (!virt_addr_valid(ptr))
84356+ return NULL;
84357+
84358+ page = virt_to_head_page(ptr);
84359+
84360+ if (!PageSlab(page))
84361+ return NULL;
84362+
84363+ s = page->slab_cache;
84364+ if (!(s->flags & SLAB_USERCOPY))
84365+ return s->name;
84366+
84367+ offset = (ptr - page_address(page)) % s->size;
84368+ if (offset <= s->object_size && n <= s->object_size - offset)
84369+ return NULL;
84370+
84371+ return s->name;
84372+}
84373+#endif
84374+
84375 size_t ksize(const void *object)
84376 {
84377 struct page *page;
84378@@ -3404,6 +3468,7 @@ void kfree(const void *x)
84379 if (unlikely(ZERO_OR_NULL_PTR(x)))
84380 return;
84381
84382+ VM_BUG_ON(!virt_addr_valid(x));
84383 page = virt_to_head_page(x);
84384 if (unlikely(!PageSlab(page))) {
84385 BUG_ON(!PageCompound(page));
84386@@ -3712,17 +3777,17 @@ void __init kmem_cache_init(void)
84387
84388 /* Caches that are not of the two-to-the-power-of size */
84389 if (KMALLOC_MIN_SIZE <= 32) {
84390- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
84391+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
84392 caches++;
84393 }
84394
84395 if (KMALLOC_MIN_SIZE <= 64) {
84396- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
84397+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
84398 caches++;
84399 }
84400
84401 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
84402- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
84403+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
84404 caches++;
84405 }
84406
84407@@ -3764,6 +3829,22 @@ void __init kmem_cache_init(void)
84408 }
84409 }
84410 #endif
84411+
84412+#ifdef CONFIG_PAX_USERCOPY_SLABS
84413+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
84414+ struct kmem_cache *s = kmalloc_caches[i];
84415+
84416+ if (s && s->size) {
84417+ char *name = kasprintf(GFP_NOWAIT,
84418+ "usercopy-kmalloc-%d", s->object_size);
84419+
84420+ BUG_ON(!name);
84421+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
84422+ s->object_size, SLAB_USERCOPY);
84423+ }
84424+ }
84425+#endif
84426+
84427 printk(KERN_INFO
84428 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
84429 " CPUs=%d, Nodes=%d\n",
84430@@ -3790,7 +3871,7 @@ static int slab_unmergeable(struct kmem_cache *s)
84431 /*
84432 * We may have set a slab to be unmergeable during bootstrap.
84433 */
84434- if (s->refcount < 0)
84435+ if (atomic_read(&s->refcount) < 0)
84436 return 1;
84437
84438 return 0;
84439@@ -3848,7 +3929,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
84440
84441 s = find_mergeable(memcg, size, align, flags, name, ctor);
84442 if (s) {
84443- s->refcount++;
84444+ atomic_inc(&s->refcount);
84445 /*
84446 * Adjust the object sizes so that we clear
84447 * the complete object on kzalloc.
84448@@ -3857,7 +3938,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
84449 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
84450
84451 if (sysfs_slab_alias(s, name)) {
84452- s->refcount--;
84453+ atomic_dec(&s->refcount);
84454 s = NULL;
84455 }
84456 }
84457@@ -3919,7 +4000,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
84458 return NOTIFY_OK;
84459 }
84460
84461-static struct notifier_block __cpuinitdata slab_notifier = {
84462+static struct notifier_block slab_notifier = {
84463 .notifier_call = slab_cpuup_callback
84464 };
84465
84466@@ -3977,7 +4058,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
84467 }
84468 #endif
84469
84470-#ifdef CONFIG_SYSFS
84471+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84472 static int count_inuse(struct page *page)
84473 {
84474 return page->inuse;
84475@@ -4364,12 +4445,12 @@ static void resiliency_test(void)
84476 validate_slab_cache(kmalloc_caches[9]);
84477 }
84478 #else
84479-#ifdef CONFIG_SYSFS
84480+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84481 static void resiliency_test(void) {};
84482 #endif
84483 #endif
84484
84485-#ifdef CONFIG_SYSFS
84486+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84487 enum slab_stat_type {
84488 SL_ALL, /* All slabs */
84489 SL_PARTIAL, /* Only partially allocated slabs */
84490@@ -4613,7 +4694,7 @@ SLAB_ATTR_RO(ctor);
84491
84492 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
84493 {
84494- return sprintf(buf, "%d\n", s->refcount - 1);
84495+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
84496 }
84497 SLAB_ATTR_RO(aliases);
84498
84499@@ -5266,6 +5347,7 @@ static char *create_unique_id(struct kmem_cache *s)
84500 return name;
84501 }
84502
84503+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84504 static int sysfs_slab_add(struct kmem_cache *s)
84505 {
84506 int err;
84507@@ -5323,6 +5405,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
84508 kobject_del(&s->kobj);
84509 kobject_put(&s->kobj);
84510 }
84511+#endif
84512
84513 /*
84514 * Need to buffer aliases during bootup until sysfs becomes
84515@@ -5336,6 +5419,7 @@ struct saved_alias {
84516
84517 static struct saved_alias *alias_list;
84518
84519+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84520 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
84521 {
84522 struct saved_alias *al;
84523@@ -5358,6 +5442,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
84524 alias_list = al;
84525 return 0;
84526 }
84527+#endif
84528
84529 static int __init slab_sysfs_init(void)
84530 {
84531diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
84532index 1b7e22a..3fcd4f3 100644
84533--- a/mm/sparse-vmemmap.c
84534+++ b/mm/sparse-vmemmap.c
84535@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
84536 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
84537 if (!p)
84538 return NULL;
84539- pud_populate(&init_mm, pud, p);
84540+ pud_populate_kernel(&init_mm, pud, p);
84541 }
84542 return pud;
84543 }
84544@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
84545 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
84546 if (!p)
84547 return NULL;
84548- pgd_populate(&init_mm, pgd, p);
84549+ pgd_populate_kernel(&init_mm, pgd, p);
84550 }
84551 return pgd;
84552 }
84553diff --git a/mm/sparse.c b/mm/sparse.c
84554index 7ca6dc8..6472aa1 100644
84555--- a/mm/sparse.c
84556+++ b/mm/sparse.c
84557@@ -783,7 +783,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
84558
84559 for (i = 0; i < PAGES_PER_SECTION; i++) {
84560 if (PageHWPoison(&memmap[i])) {
84561- atomic_long_sub(1, &num_poisoned_pages);
84562+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
84563 ClearPageHWPoison(&memmap[i]);
84564 }
84565 }
84566diff --git a/mm/swap.c b/mm/swap.c
84567index 8a529a0..154ef26 100644
84568--- a/mm/swap.c
84569+++ b/mm/swap.c
84570@@ -30,6 +30,7 @@
84571 #include <linux/backing-dev.h>
84572 #include <linux/memcontrol.h>
84573 #include <linux/gfp.h>
84574+#include <linux/hugetlb.h>
84575
84576 #include "internal.h"
84577
84578@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
84579
84580 __page_cache_release(page);
84581 dtor = get_compound_page_dtor(page);
84582+ if (!PageHuge(page))
84583+ BUG_ON(dtor != free_compound_page);
84584 (*dtor)(page);
84585 }
84586
84587diff --git a/mm/swapfile.c b/mm/swapfile.c
84588index a1f7772..9e982ac 100644
84589--- a/mm/swapfile.c
84590+++ b/mm/swapfile.c
84591@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
84592
84593 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
84594 /* Activity counter to indicate that a swapon or swapoff has occurred */
84595-static atomic_t proc_poll_event = ATOMIC_INIT(0);
84596+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
84597
84598 static inline unsigned char swap_count(unsigned char ent)
84599 {
84600@@ -1683,7 +1683,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
84601 }
84602 filp_close(swap_file, NULL);
84603 err = 0;
84604- atomic_inc(&proc_poll_event);
84605+ atomic_inc_unchecked(&proc_poll_event);
84606 wake_up_interruptible(&proc_poll_wait);
84607
84608 out_dput:
84609@@ -1700,8 +1700,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
84610
84611 poll_wait(file, &proc_poll_wait, wait);
84612
84613- if (seq->poll_event != atomic_read(&proc_poll_event)) {
84614- seq->poll_event = atomic_read(&proc_poll_event);
84615+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
84616+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
84617 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
84618 }
84619
84620@@ -1799,7 +1799,7 @@ static int swaps_open(struct inode *inode, struct file *file)
84621 return ret;
84622
84623 seq = file->private_data;
84624- seq->poll_event = atomic_read(&proc_poll_event);
84625+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
84626 return 0;
84627 }
84628
84629@@ -2142,7 +2142,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
84630 (frontswap_map) ? "FS" : "");
84631
84632 mutex_unlock(&swapon_mutex);
84633- atomic_inc(&proc_poll_event);
84634+ atomic_inc_unchecked(&proc_poll_event);
84635 wake_up_interruptible(&proc_poll_wait);
84636
84637 if (S_ISREG(inode->i_mode))
84638diff --git a/mm/util.c b/mm/util.c
84639index ab1424d..7c5bd5a 100644
84640--- a/mm/util.c
84641+++ b/mm/util.c
84642@@ -294,6 +294,12 @@ done:
84643 void arch_pick_mmap_layout(struct mm_struct *mm)
84644 {
84645 mm->mmap_base = TASK_UNMAPPED_BASE;
84646+
84647+#ifdef CONFIG_PAX_RANDMMAP
84648+ if (mm->pax_flags & MF_PAX_RANDMMAP)
84649+ mm->mmap_base += mm->delta_mmap;
84650+#endif
84651+
84652 mm->get_unmapped_area = arch_get_unmapped_area;
84653 mm->unmap_area = arch_unmap_area;
84654 }
84655diff --git a/mm/vmalloc.c b/mm/vmalloc.c
84656index 0f751f2..ef398a0 100644
84657--- a/mm/vmalloc.c
84658+++ b/mm/vmalloc.c
84659@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
84660
84661 pte = pte_offset_kernel(pmd, addr);
84662 do {
84663- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
84664- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
84665+
84666+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84667+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
84668+ BUG_ON(!pte_exec(*pte));
84669+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
84670+ continue;
84671+ }
84672+#endif
84673+
84674+ {
84675+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
84676+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
84677+ }
84678 } while (pte++, addr += PAGE_SIZE, addr != end);
84679 }
84680
84681@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
84682 pte = pte_alloc_kernel(pmd, addr);
84683 if (!pte)
84684 return -ENOMEM;
84685+
84686+ pax_open_kernel();
84687 do {
84688 struct page *page = pages[*nr];
84689
84690- if (WARN_ON(!pte_none(*pte)))
84691+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84692+ if (pgprot_val(prot) & _PAGE_NX)
84693+#endif
84694+
84695+ if (!pte_none(*pte)) {
84696+ pax_close_kernel();
84697+ WARN_ON(1);
84698 return -EBUSY;
84699- if (WARN_ON(!page))
84700+ }
84701+ if (!page) {
84702+ pax_close_kernel();
84703+ WARN_ON(1);
84704 return -ENOMEM;
84705+ }
84706 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
84707 (*nr)++;
84708 } while (pte++, addr += PAGE_SIZE, addr != end);
84709+ pax_close_kernel();
84710 return 0;
84711 }
84712
84713@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
84714 pmd_t *pmd;
84715 unsigned long next;
84716
84717- pmd = pmd_alloc(&init_mm, pud, addr);
84718+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
84719 if (!pmd)
84720 return -ENOMEM;
84721 do {
84722@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
84723 pud_t *pud;
84724 unsigned long next;
84725
84726- pud = pud_alloc(&init_mm, pgd, addr);
84727+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
84728 if (!pud)
84729 return -ENOMEM;
84730 do {
84731@@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
84732 * and fall back on vmalloc() if that fails. Others
84733 * just put it in the vmalloc space.
84734 */
84735-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
84736+#ifdef CONFIG_MODULES
84737+#ifdef MODULES_VADDR
84738 unsigned long addr = (unsigned long)x;
84739 if (addr >= MODULES_VADDR && addr < MODULES_END)
84740 return 1;
84741 #endif
84742+
84743+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84744+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
84745+ return 1;
84746+#endif
84747+
84748+#endif
84749+
84750 return is_vmalloc_addr(x);
84751 }
84752
84753@@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
84754
84755 if (!pgd_none(*pgd)) {
84756 pud_t *pud = pud_offset(pgd, addr);
84757+#ifdef CONFIG_X86
84758+ if (!pud_large(*pud))
84759+#endif
84760 if (!pud_none(*pud)) {
84761 pmd_t *pmd = pmd_offset(pud, addr);
84762+#ifdef CONFIG_X86
84763+ if (!pmd_large(*pmd))
84764+#endif
84765 if (!pmd_none(*pmd)) {
84766 pte_t *ptep, pte;
84767
84768@@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
84769 * Allocate a region of KVA of the specified size and alignment, within the
84770 * vstart and vend.
84771 */
84772-static struct vmap_area *alloc_vmap_area(unsigned long size,
84773+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
84774 unsigned long align,
84775 unsigned long vstart, unsigned long vend,
84776 int node, gfp_t gfp_mask)
84777@@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
84778 struct vm_struct *area;
84779
84780 BUG_ON(in_interrupt());
84781+
84782+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
84783+ if (flags & VM_KERNEXEC) {
84784+ if (start != VMALLOC_START || end != VMALLOC_END)
84785+ return NULL;
84786+ start = (unsigned long)MODULES_EXEC_VADDR;
84787+ end = (unsigned long)MODULES_EXEC_END;
84788+ }
84789+#endif
84790+
84791 if (flags & VM_IOREMAP) {
84792 int bit = fls(size);
84793
84794@@ -1569,6 +1618,11 @@ void *vmap(struct page **pages, unsigned int count,
84795 if (count > totalram_pages)
84796 return NULL;
84797
84798+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
84799+ if (!(pgprot_val(prot) & _PAGE_NX))
84800+ flags |= VM_KERNEXEC;
84801+#endif
84802+
84803 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
84804 __builtin_return_address(0));
84805 if (!area)
84806@@ -1670,6 +1724,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
84807 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
84808 goto fail;
84809
84810+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
84811+ if (!(pgprot_val(prot) & _PAGE_NX))
84812+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
84813+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
84814+ else
84815+#endif
84816+
84817 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
84818 start, end, node, gfp_mask, caller);
84819 if (!area)
84820@@ -1845,10 +1906,9 @@ EXPORT_SYMBOL(vzalloc_node);
84821 * For tight control over page level allocator and protection flags
84822 * use __vmalloc() instead.
84823 */
84824-
84825 void *vmalloc_exec(unsigned long size)
84826 {
84827- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
84828+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
84829 NUMA_NO_NODE, __builtin_return_address(0));
84830 }
84831
84832@@ -2139,6 +2199,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
84833 unsigned long uaddr = vma->vm_start;
84834 unsigned long usize = vma->vm_end - vma->vm_start;
84835
84836+ BUG_ON(vma->vm_mirror);
84837+
84838 if ((PAGE_SIZE-1) & (unsigned long)addr)
84839 return -EINVAL;
84840
84841@@ -2578,7 +2640,11 @@ static int s_show(struct seq_file *m, void *p)
84842 v->addr, v->addr + v->size, v->size);
84843
84844 if (v->caller)
84845+#ifdef CONFIG_GRKERNSEC_HIDESYM
84846+ seq_printf(m, " %pK", v->caller);
84847+#else
84848 seq_printf(m, " %pS", v->caller);
84849+#endif
84850
84851 if (v->nr_pages)
84852 seq_printf(m, " pages=%d", v->nr_pages);
84853diff --git a/mm/vmstat.c b/mm/vmstat.c
84854index e1d8ed1..253fa3c 100644
84855--- a/mm/vmstat.c
84856+++ b/mm/vmstat.c
84857@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
84858 *
84859 * vm_stat contains the global counters
84860 */
84861-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
84862+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
84863 EXPORT_SYMBOL(vm_stat);
84864
84865 #ifdef CONFIG_SMP
84866@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
84867 v = p->vm_stat_diff[i];
84868 p->vm_stat_diff[i] = 0;
84869 local_irq_restore(flags);
84870- atomic_long_add(v, &zone->vm_stat[i]);
84871+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
84872 global_diff[i] += v;
84873 #ifdef CONFIG_NUMA
84874 /* 3 seconds idle till flush */
84875@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
84876
84877 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
84878 if (global_diff[i])
84879- atomic_long_add(global_diff[i], &vm_stat[i]);
84880+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
84881 }
84882
84883 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
84884@@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
84885 if (pset->vm_stat_diff[i]) {
84886 int v = pset->vm_stat_diff[i];
84887 pset->vm_stat_diff[i] = 0;
84888- atomic_long_add(v, &zone->vm_stat[i]);
84889- atomic_long_add(v, &vm_stat[i]);
84890+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
84891+ atomic_long_add_unchecked(v, &vm_stat[i]);
84892 }
84893 }
84894 #endif
84895@@ -1224,7 +1224,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
84896 return NOTIFY_OK;
84897 }
84898
84899-static struct notifier_block __cpuinitdata vmstat_notifier =
84900+static struct notifier_block vmstat_notifier =
84901 { &vmstat_cpuup_callback, NULL, 0 };
84902 #endif
84903
84904@@ -1239,10 +1239,20 @@ static int __init setup_vmstat(void)
84905 start_cpu_timer(cpu);
84906 #endif
84907 #ifdef CONFIG_PROC_FS
84908- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
84909- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
84910- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
84911- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
84912+ {
84913+ mode_t gr_mode = S_IRUGO;
84914+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84915+ gr_mode = S_IRUSR;
84916+#endif
84917+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
84918+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
84919+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
84920+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
84921+#else
84922+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
84923+#endif
84924+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
84925+ }
84926 #endif
84927 return 0;
84928 }
84929diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
84930index 85addcd..c429a13 100644
84931--- a/net/8021q/vlan.c
84932+++ b/net/8021q/vlan.c
84933@@ -114,6 +114,13 @@ void unregister_vlan_dev(struct net_device *dev, struct list_head *head)
84934 if (vlan_id)
84935 vlan_vid_del(real_dev, vlan_id);
84936
84937+ /* Take it out of our own structures, but be sure to interlock with
84938+ * HW accelerating devices or SW vlan input packet processing if
84939+ * VLAN is not 0 (leave it there for 802.1p).
84940+ */
84941+ if (vlan_id)
84942+ vlan_vid_del(real_dev, vlan_id);
84943+
84944 /* Get rid of the vlan's reference to real_dev */
84945 dev_put(real_dev);
84946 }
84947@@ -496,7 +503,7 @@ out:
84948 return NOTIFY_DONE;
84949 }
84950
84951-static struct notifier_block vlan_notifier_block __read_mostly = {
84952+static struct notifier_block vlan_notifier_block = {
84953 .notifier_call = vlan_device_event,
84954 };
84955
84956@@ -571,8 +578,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
84957 err = -EPERM;
84958 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
84959 break;
84960- if ((args.u.name_type >= 0) &&
84961- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
84962+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
84963 struct vlan_net *vn;
84964
84965 vn = net_generic(net, vlan_net_id);
84966diff --git a/net/9p/mod.c b/net/9p/mod.c
84967index 6ab36ae..6f1841b 100644
84968--- a/net/9p/mod.c
84969+++ b/net/9p/mod.c
84970@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
84971 void v9fs_register_trans(struct p9_trans_module *m)
84972 {
84973 spin_lock(&v9fs_trans_lock);
84974- list_add_tail(&m->list, &v9fs_trans_list);
84975+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
84976 spin_unlock(&v9fs_trans_lock);
84977 }
84978 EXPORT_SYMBOL(v9fs_register_trans);
84979@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
84980 void v9fs_unregister_trans(struct p9_trans_module *m)
84981 {
84982 spin_lock(&v9fs_trans_lock);
84983- list_del_init(&m->list);
84984+ pax_list_del_init((struct list_head *)&m->list);
84985 spin_unlock(&v9fs_trans_lock);
84986 }
84987 EXPORT_SYMBOL(v9fs_unregister_trans);
84988diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
84989index 02efb25..41541a9 100644
84990--- a/net/9p/trans_fd.c
84991+++ b/net/9p/trans_fd.c
84992@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
84993 oldfs = get_fs();
84994 set_fs(get_ds());
84995 /* The cast to a user pointer is valid due to the set_fs() */
84996- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
84997+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
84998 set_fs(oldfs);
84999
85000 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
85001diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
85002index 876fbe8..8bbea9f 100644
85003--- a/net/atm/atm_misc.c
85004+++ b/net/atm/atm_misc.c
85005@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
85006 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
85007 return 1;
85008 atm_return(vcc, truesize);
85009- atomic_inc(&vcc->stats->rx_drop);
85010+ atomic_inc_unchecked(&vcc->stats->rx_drop);
85011 return 0;
85012 }
85013 EXPORT_SYMBOL(atm_charge);
85014@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
85015 }
85016 }
85017 atm_return(vcc, guess);
85018- atomic_inc(&vcc->stats->rx_drop);
85019+ atomic_inc_unchecked(&vcc->stats->rx_drop);
85020 return NULL;
85021 }
85022 EXPORT_SYMBOL(atm_alloc_charge);
85023@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
85024
85025 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
85026 {
85027-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
85028+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
85029 __SONET_ITEMS
85030 #undef __HANDLE_ITEM
85031 }
85032@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
85033
85034 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
85035 {
85036-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
85037+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
85038 __SONET_ITEMS
85039 #undef __HANDLE_ITEM
85040 }
85041diff --git a/net/atm/lec.h b/net/atm/lec.h
85042index a86aff9..3a0d6f6 100644
85043--- a/net/atm/lec.h
85044+++ b/net/atm/lec.h
85045@@ -48,7 +48,7 @@ struct lane2_ops {
85046 const u8 *tlvs, u32 sizeoftlvs);
85047 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
85048 const u8 *tlvs, u32 sizeoftlvs);
85049-};
85050+} __no_const;
85051
85052 /*
85053 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
85054diff --git a/net/atm/proc.c b/net/atm/proc.c
85055index 6ac35ff..ac0e136 100644
85056--- a/net/atm/proc.c
85057+++ b/net/atm/proc.c
85058@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
85059 const struct k_atm_aal_stats *stats)
85060 {
85061 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
85062- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
85063- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
85064- atomic_read(&stats->rx_drop));
85065+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
85066+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
85067+ atomic_read_unchecked(&stats->rx_drop));
85068 }
85069
85070 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
85071diff --git a/net/atm/resources.c b/net/atm/resources.c
85072index 0447d5d..3cf4728 100644
85073--- a/net/atm/resources.c
85074+++ b/net/atm/resources.c
85075@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
85076 static void copy_aal_stats(struct k_atm_aal_stats *from,
85077 struct atm_aal_stats *to)
85078 {
85079-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
85080+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
85081 __AAL_STAT_ITEMS
85082 #undef __HANDLE_ITEM
85083 }
85084@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
85085 static void subtract_aal_stats(struct k_atm_aal_stats *from,
85086 struct atm_aal_stats *to)
85087 {
85088-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
85089+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
85090 __AAL_STAT_ITEMS
85091 #undef __HANDLE_ITEM
85092 }
85093diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
85094index d5744b7..506bae3 100644
85095--- a/net/ax25/sysctl_net_ax25.c
85096+++ b/net/ax25/sysctl_net_ax25.c
85097@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
85098 {
85099 char path[sizeof("net/ax25/") + IFNAMSIZ];
85100 int k;
85101- struct ctl_table *table;
85102+ ctl_table_no_const *table;
85103
85104 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
85105 if (!table)
85106diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
85107index a5bb0a7..e1d8b97 100644
85108--- a/net/batman-adv/bat_iv_ogm.c
85109+++ b/net/batman-adv/bat_iv_ogm.c
85110@@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
85111
85112 /* randomize initial seqno to avoid collision */
85113 get_random_bytes(&random_seqno, sizeof(random_seqno));
85114- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
85115+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
85116
85117 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
85118 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
85119@@ -611,9 +611,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
85120 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
85121
85122 /* change sequence number to network order */
85123- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
85124+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
85125 batadv_ogm_packet->seqno = htonl(seqno);
85126- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
85127+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
85128
85129 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
85130 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
85131@@ -1013,7 +1013,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
85132 return;
85133
85134 /* could be changed by schedule_own_packet() */
85135- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
85136+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
85137
85138 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
85139 has_directlink_flag = 1;
85140diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
85141index 368219e..53f56f9 100644
85142--- a/net/batman-adv/hard-interface.c
85143+++ b/net/batman-adv/hard-interface.c
85144@@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
85145 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
85146 dev_add_pack(&hard_iface->batman_adv_ptype);
85147
85148- atomic_set(&hard_iface->frag_seqno, 1);
85149+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
85150 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
85151 hard_iface->net_dev->name);
85152
85153@@ -514,7 +514,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
85154 /* This can't be called via a bat_priv callback because
85155 * we have no bat_priv yet.
85156 */
85157- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
85158+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
85159 hard_iface->bat_iv.ogm_buff = NULL;
85160
85161 return hard_iface;
85162diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
85163index 2711e87..4ca48fa 100644
85164--- a/net/batman-adv/soft-interface.c
85165+++ b/net/batman-adv/soft-interface.c
85166@@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
85167 primary_if->net_dev->dev_addr, ETH_ALEN);
85168
85169 /* set broadcast sequence number */
85170- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
85171+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
85172 bcast_packet->seqno = htonl(seqno);
85173
85174 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
85175@@ -527,7 +527,7 @@ struct net_device *batadv_softif_create(const char *name)
85176 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
85177
85178 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
85179- atomic_set(&bat_priv->bcast_seqno, 1);
85180+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
85181 atomic_set(&bat_priv->tt.vn, 0);
85182 atomic_set(&bat_priv->tt.local_changes, 0);
85183 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
85184diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
85185index 4cd87a0..348e705 100644
85186--- a/net/batman-adv/types.h
85187+++ b/net/batman-adv/types.h
85188@@ -51,7 +51,7 @@
85189 struct batadv_hard_iface_bat_iv {
85190 unsigned char *ogm_buff;
85191 int ogm_buff_len;
85192- atomic_t ogm_seqno;
85193+ atomic_unchecked_t ogm_seqno;
85194 };
85195
85196 /**
85197@@ -75,7 +75,7 @@ struct batadv_hard_iface {
85198 int16_t if_num;
85199 char if_status;
85200 struct net_device *net_dev;
85201- atomic_t frag_seqno;
85202+ atomic_unchecked_t frag_seqno;
85203 struct kobject *hardif_obj;
85204 atomic_t refcount;
85205 struct packet_type batman_adv_ptype;
85206@@ -495,7 +495,7 @@ struct batadv_priv {
85207 #ifdef CONFIG_BATMAN_ADV_DEBUG
85208 atomic_t log_level;
85209 #endif
85210- atomic_t bcast_seqno;
85211+ atomic_unchecked_t bcast_seqno;
85212 atomic_t bcast_queue_left;
85213 atomic_t batman_queue_left;
85214 char num_ifaces;
85215diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
85216index 50e079f..49ce2d2 100644
85217--- a/net/batman-adv/unicast.c
85218+++ b/net/batman-adv/unicast.c
85219@@ -270,7 +270,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
85220 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
85221 frag2->flags = large_tail;
85222
85223- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
85224+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
85225 frag1->seqno = htons(seqno - 1);
85226 frag2->seqno = htons(seqno);
85227
85228diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
85229index 6a93614..1415549 100644
85230--- a/net/bluetooth/hci_sock.c
85231+++ b/net/bluetooth/hci_sock.c
85232@@ -929,7 +929,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
85233 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
85234 }
85235
85236- len = min_t(unsigned int, len, sizeof(uf));
85237+ len = min((size_t)len, sizeof(uf));
85238 if (copy_from_user(&uf, optval, len)) {
85239 err = -EFAULT;
85240 break;
85241diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
85242index 7c7e932..7a7815d 100644
85243--- a/net/bluetooth/l2cap_core.c
85244+++ b/net/bluetooth/l2cap_core.c
85245@@ -3395,8 +3395,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
85246 break;
85247
85248 case L2CAP_CONF_RFC:
85249- if (olen == sizeof(rfc))
85250- memcpy(&rfc, (void *)val, olen);
85251+ if (olen != sizeof(rfc))
85252+ break;
85253+
85254+ memcpy(&rfc, (void *)val, olen);
85255
85256 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
85257 rfc.mode != chan->mode)
85258diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
85259index 1bcfb84..dad9f98 100644
85260--- a/net/bluetooth/l2cap_sock.c
85261+++ b/net/bluetooth/l2cap_sock.c
85262@@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
85263 struct sock *sk = sock->sk;
85264 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
85265 struct l2cap_options opts;
85266- int len, err = 0;
85267+ int err = 0;
85268+ size_t len = optlen;
85269 u32 opt;
85270
85271 BT_DBG("sk %p", sk);
85272@@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
85273 opts.max_tx = chan->max_tx;
85274 opts.txwin_size = chan->tx_win;
85275
85276- len = min_t(unsigned int, sizeof(opts), optlen);
85277+ len = min(sizeof(opts), len);
85278 if (copy_from_user((char *) &opts, optval, len)) {
85279 err = -EFAULT;
85280 break;
85281@@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
85282 struct bt_security sec;
85283 struct bt_power pwr;
85284 struct l2cap_conn *conn;
85285- int len, err = 0;
85286+ int err = 0;
85287+ size_t len = optlen;
85288 u32 opt;
85289
85290 BT_DBG("sk %p", sk);
85291@@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
85292
85293 sec.level = BT_SECURITY_LOW;
85294
85295- len = min_t(unsigned int, sizeof(sec), optlen);
85296+ len = min(sizeof(sec), len);
85297 if (copy_from_user((char *) &sec, optval, len)) {
85298 err = -EFAULT;
85299 break;
85300@@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
85301
85302 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
85303
85304- len = min_t(unsigned int, sizeof(pwr), optlen);
85305+ len = min(sizeof(pwr), len);
85306 if (copy_from_user((char *) &pwr, optval, len)) {
85307 err = -EFAULT;
85308 break;
85309diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
85310index 7c9224b..381009e 100644
85311--- a/net/bluetooth/rfcomm/sock.c
85312+++ b/net/bluetooth/rfcomm/sock.c
85313@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
85314 struct sock *sk = sock->sk;
85315 struct bt_security sec;
85316 int err = 0;
85317- size_t len;
85318+ size_t len = optlen;
85319 u32 opt;
85320
85321 BT_DBG("sk %p", sk);
85322@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
85323
85324 sec.level = BT_SECURITY_LOW;
85325
85326- len = min_t(unsigned int, sizeof(sec), optlen);
85327+ len = min(sizeof(sec), len);
85328 if (copy_from_user((char *) &sec, optval, len)) {
85329 err = -EFAULT;
85330 break;
85331diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
85332index b6e44ad..5b0d514 100644
85333--- a/net/bluetooth/rfcomm/tty.c
85334+++ b/net/bluetooth/rfcomm/tty.c
85335@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
85336 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
85337
85338 spin_lock_irqsave(&dev->port.lock, flags);
85339- if (dev->port.count > 0) {
85340+ if (atomic_read(&dev->port.count) > 0) {
85341 spin_unlock_irqrestore(&dev->port.lock, flags);
85342 return;
85343 }
85344@@ -659,10 +659,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
85345 return -ENODEV;
85346
85347 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
85348- dev->channel, dev->port.count);
85349+ dev->channel, atomic_read(&dev->port.count));
85350
85351 spin_lock_irqsave(&dev->port.lock, flags);
85352- if (++dev->port.count > 1) {
85353+ if (atomic_inc_return(&dev->port.count) > 1) {
85354 spin_unlock_irqrestore(&dev->port.lock, flags);
85355 return 0;
85356 }
85357@@ -727,10 +727,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
85358 return;
85359
85360 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
85361- dev->port.count);
85362+ atomic_read(&dev->port.count));
85363
85364 spin_lock_irqsave(&dev->port.lock, flags);
85365- if (!--dev->port.count) {
85366+ if (!atomic_dec_return(&dev->port.count)) {
85367 spin_unlock_irqrestore(&dev->port.lock, flags);
85368 if (dev->tty_dev->parent)
85369 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
85370diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
85371index 8d493c9..3849e49 100644
85372--- a/net/bridge/netfilter/ebtables.c
85373+++ b/net/bridge/netfilter/ebtables.c
85374@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85375 tmp.valid_hooks = t->table->valid_hooks;
85376 }
85377 mutex_unlock(&ebt_mutex);
85378- if (copy_to_user(user, &tmp, *len) != 0){
85379+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
85380 BUGPRINT("c2u Didn't work\n");
85381 ret = -EFAULT;
85382 break;
85383@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
85384 goto out;
85385 tmp.valid_hooks = t->valid_hooks;
85386
85387- if (copy_to_user(user, &tmp, *len) != 0) {
85388+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
85389 ret = -EFAULT;
85390 break;
85391 }
85392@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
85393 tmp.entries_size = t->table->entries_size;
85394 tmp.valid_hooks = t->table->valid_hooks;
85395
85396- if (copy_to_user(user, &tmp, *len) != 0) {
85397+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
85398 ret = -EFAULT;
85399 break;
85400 }
85401diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
85402index a376ec1..1fbd6be 100644
85403--- a/net/caif/cfctrl.c
85404+++ b/net/caif/cfctrl.c
85405@@ -10,6 +10,7 @@
85406 #include <linux/spinlock.h>
85407 #include <linux/slab.h>
85408 #include <linux/pkt_sched.h>
85409+#include <linux/sched.h>
85410 #include <net/caif/caif_layer.h>
85411 #include <net/caif/cfpkt.h>
85412 #include <net/caif/cfctrl.h>
85413@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
85414 memset(&dev_info, 0, sizeof(dev_info));
85415 dev_info.id = 0xff;
85416 cfsrvl_init(&this->serv, 0, &dev_info, false);
85417- atomic_set(&this->req_seq_no, 1);
85418- atomic_set(&this->rsp_seq_no, 1);
85419+ atomic_set_unchecked(&this->req_seq_no, 1);
85420+ atomic_set_unchecked(&this->rsp_seq_no, 1);
85421 this->serv.layer.receive = cfctrl_recv;
85422 sprintf(this->serv.layer.name, "ctrl");
85423 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
85424@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
85425 struct cfctrl_request_info *req)
85426 {
85427 spin_lock_bh(&ctrl->info_list_lock);
85428- atomic_inc(&ctrl->req_seq_no);
85429- req->sequence_no = atomic_read(&ctrl->req_seq_no);
85430+ atomic_inc_unchecked(&ctrl->req_seq_no);
85431+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
85432 list_add_tail(&req->list, &ctrl->list);
85433 spin_unlock_bh(&ctrl->info_list_lock);
85434 }
85435@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
85436 if (p != first)
85437 pr_warn("Requests are not received in order\n");
85438
85439- atomic_set(&ctrl->rsp_seq_no,
85440+ atomic_set_unchecked(&ctrl->rsp_seq_no,
85441 p->sequence_no);
85442 list_del(&p->list);
85443 goto out;
85444diff --git a/net/can/af_can.c b/net/can/af_can.c
85445index c48e522..1223690 100644
85446--- a/net/can/af_can.c
85447+++ b/net/can/af_can.c
85448@@ -870,7 +870,7 @@ static const struct net_proto_family can_family_ops = {
85449 };
85450
85451 /* notifier block for netdevice event */
85452-static struct notifier_block can_netdev_notifier __read_mostly = {
85453+static struct notifier_block can_netdev_notifier = {
85454 .notifier_call = can_notifier,
85455 };
85456
85457diff --git a/net/can/gw.c b/net/can/gw.c
85458index 117814a..ad4fb73 100644
85459--- a/net/can/gw.c
85460+++ b/net/can/gw.c
85461@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
85462 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
85463
85464 static HLIST_HEAD(cgw_list);
85465-static struct notifier_block notifier;
85466
85467 static struct kmem_cache *cgw_cache __read_mostly;
85468
85469@@ -928,6 +927,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
85470 return err;
85471 }
85472
85473+static struct notifier_block notifier = {
85474+ .notifier_call = cgw_notifier
85475+};
85476+
85477 static __init int cgw_module_init(void)
85478 {
85479 /* sanitize given module parameter */
85480@@ -943,7 +946,6 @@ static __init int cgw_module_init(void)
85481 return -ENOMEM;
85482
85483 /* set notifier */
85484- notifier.notifier_call = cgw_notifier;
85485 register_netdevice_notifier(&notifier);
85486
85487 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
85488diff --git a/net/compat.c b/net/compat.c
85489index 79ae884..17c5c09 100644
85490--- a/net/compat.c
85491+++ b/net/compat.c
85492@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
85493 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
85494 __get_user(kmsg->msg_flags, &umsg->msg_flags))
85495 return -EFAULT;
85496- kmsg->msg_name = compat_ptr(tmp1);
85497- kmsg->msg_iov = compat_ptr(tmp2);
85498- kmsg->msg_control = compat_ptr(tmp3);
85499+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
85500+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
85501+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
85502 return 0;
85503 }
85504
85505@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
85506
85507 if (kern_msg->msg_namelen) {
85508 if (mode == VERIFY_READ) {
85509- int err = move_addr_to_kernel(kern_msg->msg_name,
85510+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
85511 kern_msg->msg_namelen,
85512 kern_address);
85513 if (err < 0)
85514@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
85515 kern_msg->msg_name = NULL;
85516
85517 tot_len = iov_from_user_compat_to_kern(kern_iov,
85518- (struct compat_iovec __user *)kern_msg->msg_iov,
85519+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
85520 kern_msg->msg_iovlen);
85521 if (tot_len >= 0)
85522 kern_msg->msg_iov = kern_iov;
85523@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
85524
85525 #define CMSG_COMPAT_FIRSTHDR(msg) \
85526 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
85527- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
85528+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
85529 (struct compat_cmsghdr __user *)NULL)
85530
85531 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
85532 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
85533 (ucmlen) <= (unsigned long) \
85534 ((mhdr)->msg_controllen - \
85535- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
85536+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
85537
85538 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
85539 struct compat_cmsghdr __user *cmsg, int cmsg_len)
85540 {
85541 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
85542- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
85543+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
85544 msg->msg_controllen)
85545 return NULL;
85546 return (struct compat_cmsghdr __user *)ptr;
85547@@ -219,7 +219,7 @@ Efault:
85548
85549 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
85550 {
85551- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
85552+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
85553 struct compat_cmsghdr cmhdr;
85554 struct compat_timeval ctv;
85555 struct compat_timespec cts[3];
85556@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
85557
85558 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
85559 {
85560- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
85561+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
85562 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
85563 int fdnum = scm->fp->count;
85564 struct file **fp = scm->fp->fp;
85565@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
85566 return -EFAULT;
85567 old_fs = get_fs();
85568 set_fs(KERNEL_DS);
85569- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
85570+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
85571 set_fs(old_fs);
85572
85573 return err;
85574@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
85575 len = sizeof(ktime);
85576 old_fs = get_fs();
85577 set_fs(KERNEL_DS);
85578- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
85579+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
85580 set_fs(old_fs);
85581
85582 if (!err) {
85583@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
85584 case MCAST_JOIN_GROUP:
85585 case MCAST_LEAVE_GROUP:
85586 {
85587- struct compat_group_req __user *gr32 = (void *)optval;
85588+ struct compat_group_req __user *gr32 = (void __user *)optval;
85589 struct group_req __user *kgr =
85590 compat_alloc_user_space(sizeof(struct group_req));
85591 u32 interface;
85592@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
85593 case MCAST_BLOCK_SOURCE:
85594 case MCAST_UNBLOCK_SOURCE:
85595 {
85596- struct compat_group_source_req __user *gsr32 = (void *)optval;
85597+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
85598 struct group_source_req __user *kgsr = compat_alloc_user_space(
85599 sizeof(struct group_source_req));
85600 u32 interface;
85601@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
85602 }
85603 case MCAST_MSFILTER:
85604 {
85605- struct compat_group_filter __user *gf32 = (void *)optval;
85606+ struct compat_group_filter __user *gf32 = (void __user *)optval;
85607 struct group_filter __user *kgf;
85608 u32 interface, fmode, numsrc;
85609
85610@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
85611 char __user *optval, int __user *optlen,
85612 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
85613 {
85614- struct compat_group_filter __user *gf32 = (void *)optval;
85615+ struct compat_group_filter __user *gf32 = (void __user *)optval;
85616 struct group_filter __user *kgf;
85617 int __user *koptlen;
85618 u32 interface, fmode, numsrc;
85619@@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
85620
85621 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
85622 return -EINVAL;
85623- if (copy_from_user(a, args, nas[call]))
85624+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
85625 return -EFAULT;
85626 a0 = a[0];
85627 a1 = a[1];
85628diff --git a/net/core/datagram.c b/net/core/datagram.c
85629index 368f9c3..f82d4a3 100644
85630--- a/net/core/datagram.c
85631+++ b/net/core/datagram.c
85632@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
85633 }
85634
85635 kfree_skb(skb);
85636- atomic_inc(&sk->sk_drops);
85637+ atomic_inc_unchecked(&sk->sk_drops);
85638 sk_mem_reclaim_partial(sk);
85639
85640 return err;
85641diff --git a/net/core/dev.c b/net/core/dev.c
85642index 9a278e9..15f2b9e 100644
85643--- a/net/core/dev.c
85644+++ b/net/core/dev.c
85645@@ -1617,7 +1617,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
85646 {
85647 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
85648 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
85649- atomic_long_inc(&dev->rx_dropped);
85650+ atomic_long_inc_unchecked(&dev->rx_dropped);
85651 kfree_skb(skb);
85652 return NET_RX_DROP;
85653 }
85654@@ -1626,7 +1626,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
85655 skb_orphan(skb);
85656
85657 if (unlikely(!is_skb_forwardable(dev, skb))) {
85658- atomic_long_inc(&dev->rx_dropped);
85659+ atomic_long_inc_unchecked(&dev->rx_dropped);
85660 kfree_skb(skb);
85661 return NET_RX_DROP;
85662 }
85663@@ -2351,7 +2351,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
85664
85665 struct dev_gso_cb {
85666 void (*destructor)(struct sk_buff *skb);
85667-};
85668+} __no_const;
85669
85670 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
85671
85672@@ -3093,7 +3093,7 @@ enqueue:
85673
85674 local_irq_restore(flags);
85675
85676- atomic_long_inc(&skb->dev->rx_dropped);
85677+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
85678 kfree_skb(skb);
85679 return NET_RX_DROP;
85680 }
85681@@ -3165,7 +3165,7 @@ int netif_rx_ni(struct sk_buff *skb)
85682 }
85683 EXPORT_SYMBOL(netif_rx_ni);
85684
85685-static void net_tx_action(struct softirq_action *h)
85686+static void net_tx_action(void)
85687 {
85688 struct softnet_data *sd = &__get_cpu_var(softnet_data);
85689
85690@@ -3490,7 +3490,7 @@ ncls:
85691 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
85692 } else {
85693 drop:
85694- atomic_long_inc(&skb->dev->rx_dropped);
85695+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
85696 kfree_skb(skb);
85697 /* Jamal, now you will not able to escape explaining
85698 * me how you were going to use this. :-)
85699@@ -4095,7 +4095,7 @@ void netif_napi_del(struct napi_struct *napi)
85700 }
85701 EXPORT_SYMBOL(netif_napi_del);
85702
85703-static void net_rx_action(struct softirq_action *h)
85704+static void net_rx_action(void)
85705 {
85706 struct softnet_data *sd = &__get_cpu_var(softnet_data);
85707 unsigned long time_limit = jiffies + 2;
85708@@ -5522,7 +5522,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
85709 } else {
85710 netdev_stats_to_stats64(storage, &dev->stats);
85711 }
85712- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
85713+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
85714 return storage;
85715 }
85716 EXPORT_SYMBOL(dev_get_stats);
85717diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
85718index 6cc0481..59cfb00 100644
85719--- a/net/core/dev_ioctl.c
85720+++ b/net/core/dev_ioctl.c
85721@@ -376,9 +376,13 @@ void dev_load(struct net *net, const char *name)
85722 if (no_module && capable(CAP_NET_ADMIN))
85723 no_module = request_module("netdev-%s", name);
85724 if (no_module && capable(CAP_SYS_MODULE)) {
85725+#ifdef CONFIG_GRKERNSEC_MODHARDEN
85726+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
85727+#else
85728 if (!request_module("%s", name))
85729 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
85730 name);
85731+#endif
85732 }
85733 }
85734 EXPORT_SYMBOL(dev_load);
85735diff --git a/net/core/flow.c b/net/core/flow.c
85736index 2bfd081..53c6058 100644
85737--- a/net/core/flow.c
85738+++ b/net/core/flow.c
85739@@ -61,7 +61,7 @@ struct flow_cache {
85740 struct timer_list rnd_timer;
85741 };
85742
85743-atomic_t flow_cache_genid = ATOMIC_INIT(0);
85744+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
85745 EXPORT_SYMBOL(flow_cache_genid);
85746 static struct flow_cache flow_cache_global;
85747 static struct kmem_cache *flow_cachep __read_mostly;
85748@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
85749
85750 static int flow_entry_valid(struct flow_cache_entry *fle)
85751 {
85752- if (atomic_read(&flow_cache_genid) != fle->genid)
85753+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
85754 return 0;
85755 if (fle->object && !fle->object->ops->check(fle->object))
85756 return 0;
85757@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
85758 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
85759 fcp->hash_count++;
85760 }
85761- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
85762+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
85763 flo = fle->object;
85764 if (!flo)
85765 goto ret_object;
85766@@ -279,7 +279,7 @@ nocache:
85767 }
85768 flo = resolver(net, key, family, dir, flo, ctx);
85769 if (fle) {
85770- fle->genid = atomic_read(&flow_cache_genid);
85771+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
85772 if (!IS_ERR(flo))
85773 fle->object = flo;
85774 else
85775diff --git a/net/core/iovec.c b/net/core/iovec.c
85776index 7e7aeb0..2a998cb 100644
85777--- a/net/core/iovec.c
85778+++ b/net/core/iovec.c
85779@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
85780 if (m->msg_namelen) {
85781 if (mode == VERIFY_READ) {
85782 void __user *namep;
85783- namep = (void __user __force *) m->msg_name;
85784+ namep = (void __force_user *) m->msg_name;
85785 err = move_addr_to_kernel(namep, m->msg_namelen,
85786 address);
85787 if (err < 0)
85788@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
85789 }
85790
85791 size = m->msg_iovlen * sizeof(struct iovec);
85792- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
85793+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
85794 return -EFAULT;
85795
85796 m->msg_iov = iov;
85797diff --git a/net/core/neighbour.c b/net/core/neighbour.c
85798index 3863b8f..85c99a6 100644
85799--- a/net/core/neighbour.c
85800+++ b/net/core/neighbour.c
85801@@ -2778,7 +2778,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
85802 size_t *lenp, loff_t *ppos)
85803 {
85804 int size, ret;
85805- ctl_table tmp = *ctl;
85806+ ctl_table_no_const tmp = *ctl;
85807
85808 tmp.extra1 = &zero;
85809 tmp.extra2 = &unres_qlen_max;
85810diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
85811index 3174f19..5810985 100644
85812--- a/net/core/net-procfs.c
85813+++ b/net/core/net-procfs.c
85814@@ -271,8 +271,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
85815 else
85816 seq_printf(seq, "%04x", ntohs(pt->type));
85817
85818+#ifdef CONFIG_GRKERNSEC_HIDESYM
85819+ seq_printf(seq, " %-8s %pF\n",
85820+ pt->dev ? pt->dev->name : "", NULL);
85821+#else
85822 seq_printf(seq, " %-8s %pF\n",
85823 pt->dev ? pt->dev->name : "", pt->func);
85824+#endif
85825 }
85826
85827 return 0;
85828diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
85829index 7427ab5..389f411 100644
85830--- a/net/core/net-sysfs.c
85831+++ b/net/core/net-sysfs.c
85832@@ -1321,7 +1321,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
85833 }
85834 EXPORT_SYMBOL(netdev_class_remove_file);
85835
85836-int netdev_kobject_init(void)
85837+int __init netdev_kobject_init(void)
85838 {
85839 kobj_ns_type_register(&net_ns_type_operations);
85840 return class_register(&net_class);
85841diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
85842index 80e271d..2980cc2 100644
85843--- a/net/core/net_namespace.c
85844+++ b/net/core/net_namespace.c
85845@@ -442,7 +442,7 @@ static int __register_pernet_operations(struct list_head *list,
85846 int error;
85847 LIST_HEAD(net_exit_list);
85848
85849- list_add_tail(&ops->list, list);
85850+ pax_list_add_tail((struct list_head *)&ops->list, list);
85851 if (ops->init || (ops->id && ops->size)) {
85852 for_each_net(net) {
85853 error = ops_init(ops, net);
85854@@ -455,7 +455,7 @@ static int __register_pernet_operations(struct list_head *list,
85855
85856 out_undo:
85857 /* If I have an error cleanup all namespaces I initialized */
85858- list_del(&ops->list);
85859+ pax_list_del((struct list_head *)&ops->list);
85860 ops_exit_list(ops, &net_exit_list);
85861 ops_free_list(ops, &net_exit_list);
85862 return error;
85863@@ -466,7 +466,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
85864 struct net *net;
85865 LIST_HEAD(net_exit_list);
85866
85867- list_del(&ops->list);
85868+ pax_list_del((struct list_head *)&ops->list);
85869 for_each_net(net)
85870 list_add_tail(&net->exit_list, &net_exit_list);
85871 ops_exit_list(ops, &net_exit_list);
85872@@ -600,7 +600,7 @@ int register_pernet_device(struct pernet_operations *ops)
85873 mutex_lock(&net_mutex);
85874 error = register_pernet_operations(&pernet_list, ops);
85875 if (!error && (first_device == &pernet_list))
85876- first_device = &ops->list;
85877+ first_device = (struct list_head *)&ops->list;
85878 mutex_unlock(&net_mutex);
85879 return error;
85880 }
85881diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
85882index 23854b5..ff4fda4 100644
85883--- a/net/core/rtnetlink.c
85884+++ b/net/core/rtnetlink.c
85885@@ -58,7 +58,7 @@ struct rtnl_link {
85886 rtnl_doit_func doit;
85887 rtnl_dumpit_func dumpit;
85888 rtnl_calcit_func calcit;
85889-};
85890+} __no_const;
85891
85892 static DEFINE_MUTEX(rtnl_mutex);
85893
85894@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
85895 if (rtnl_link_ops_get(ops->kind))
85896 return -EEXIST;
85897
85898- if (!ops->dellink)
85899- ops->dellink = unregister_netdevice_queue;
85900+ if (!ops->dellink) {
85901+ pax_open_kernel();
85902+ *(void **)&ops->dellink = unregister_netdevice_queue;
85903+ pax_close_kernel();
85904+ }
85905
85906- list_add_tail(&ops->list, &link_ops);
85907+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
85908 return 0;
85909 }
85910 EXPORT_SYMBOL_GPL(__rtnl_link_register);
85911@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
85912 for_each_net(net) {
85913 __rtnl_kill_links(net, ops);
85914 }
85915- list_del(&ops->list);
85916+ pax_list_del((struct list_head *)&ops->list);
85917 }
85918 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
85919
85920diff --git a/net/core/scm.c b/net/core/scm.c
85921index 2dc6cda..2159524 100644
85922--- a/net/core/scm.c
85923+++ b/net/core/scm.c
85924@@ -226,7 +226,7 @@ EXPORT_SYMBOL(__scm_send);
85925 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
85926 {
85927 struct cmsghdr __user *cm
85928- = (__force struct cmsghdr __user *)msg->msg_control;
85929+ = (struct cmsghdr __force_user *)msg->msg_control;
85930 struct cmsghdr cmhdr;
85931 int cmlen = CMSG_LEN(len);
85932 int err;
85933@@ -249,7 +249,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
85934 err = -EFAULT;
85935 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
85936 goto out;
85937- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
85938+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
85939 goto out;
85940 cmlen = CMSG_SPACE(len);
85941 if (msg->msg_controllen < cmlen)
85942@@ -265,7 +265,7 @@ EXPORT_SYMBOL(put_cmsg);
85943 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
85944 {
85945 struct cmsghdr __user *cm
85946- = (__force struct cmsghdr __user*)msg->msg_control;
85947+ = (struct cmsghdr __force_user *)msg->msg_control;
85948
85949 int fdmax = 0;
85950 int fdnum = scm->fp->count;
85951@@ -285,7 +285,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
85952 if (fdnum < fdmax)
85953 fdmax = fdnum;
85954
85955- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
85956+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
85957 i++, cmfptr++)
85958 {
85959 struct socket *sock;
85960diff --git a/net/core/secure_seq.c b/net/core/secure_seq.c
85961index e61a8bb..6a2f13c 100644
85962--- a/net/core/secure_seq.c
85963+++ b/net/core/secure_seq.c
85964@@ -12,12 +12,10 @@
85965
85966 static u32 net_secret[MD5_MESSAGE_BYTES / 4] ____cacheline_aligned;
85967
85968-static int __init net_secret_init(void)
85969+void net_secret_init(void)
85970 {
85971 get_random_bytes(net_secret, sizeof(net_secret));
85972- return 0;
85973 }
85974-late_initcall(net_secret_init);
85975
85976 #ifdef CONFIG_INET
85977 static u32 seq_scale(u32 seq)
85978diff --git a/net/core/sock.c b/net/core/sock.c
85979index 1432266..1a0d4a1 100644
85980--- a/net/core/sock.c
85981+++ b/net/core/sock.c
85982@@ -390,7 +390,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
85983 struct sk_buff_head *list = &sk->sk_receive_queue;
85984
85985 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
85986- atomic_inc(&sk->sk_drops);
85987+ atomic_inc_unchecked(&sk->sk_drops);
85988 trace_sock_rcvqueue_full(sk, skb);
85989 return -ENOMEM;
85990 }
85991@@ -400,7 +400,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
85992 return err;
85993
85994 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
85995- atomic_inc(&sk->sk_drops);
85996+ atomic_inc_unchecked(&sk->sk_drops);
85997 return -ENOBUFS;
85998 }
85999
86000@@ -420,7 +420,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86001 skb_dst_force(skb);
86002
86003 spin_lock_irqsave(&list->lock, flags);
86004- skb->dropcount = atomic_read(&sk->sk_drops);
86005+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
86006 __skb_queue_tail(list, skb);
86007 spin_unlock_irqrestore(&list->lock, flags);
86008
86009@@ -440,7 +440,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
86010 skb->dev = NULL;
86011
86012 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
86013- atomic_inc(&sk->sk_drops);
86014+ atomic_inc_unchecked(&sk->sk_drops);
86015 goto discard_and_relse;
86016 }
86017 if (nested)
86018@@ -458,7 +458,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
86019 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
86020 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
86021 bh_unlock_sock(sk);
86022- atomic_inc(&sk->sk_drops);
86023+ atomic_inc_unchecked(&sk->sk_drops);
86024 goto discard_and_relse;
86025 }
86026
86027@@ -942,12 +942,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86028 struct timeval tm;
86029 } v;
86030
86031- int lv = sizeof(int);
86032- int len;
86033+ unsigned int lv = sizeof(int);
86034+ unsigned int len;
86035
86036 if (get_user(len, optlen))
86037 return -EFAULT;
86038- if (len < 0)
86039+ if (len > INT_MAX)
86040 return -EINVAL;
86041
86042 memset(&v, 0, sizeof(v));
86043@@ -1099,11 +1099,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86044
86045 case SO_PEERNAME:
86046 {
86047- char address[128];
86048+ char address[_K_SS_MAXSIZE];
86049
86050 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
86051 return -ENOTCONN;
86052- if (lv < len)
86053+ if (lv < len || sizeof address < len)
86054 return -EINVAL;
86055 if (copy_to_user(optval, address, len))
86056 return -EFAULT;
86057@@ -1166,7 +1166,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86058
86059 if (len > lv)
86060 len = lv;
86061- if (copy_to_user(optval, &v, len))
86062+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
86063 return -EFAULT;
86064 lenout:
86065 if (put_user(len, optlen))
86066@@ -2284,7 +2284,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
86067 */
86068 smp_wmb();
86069 atomic_set(&sk->sk_refcnt, 1);
86070- atomic_set(&sk->sk_drops, 0);
86071+ atomic_set_unchecked(&sk->sk_drops, 0);
86072 }
86073 EXPORT_SYMBOL(sock_init_data);
86074
86075diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
86076index a29e90c..922399c 100644
86077--- a/net/core/sock_diag.c
86078+++ b/net/core/sock_diag.c
86079@@ -9,26 +9,33 @@
86080 #include <linux/inet_diag.h>
86081 #include <linux/sock_diag.h>
86082
86083-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
86084+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
86085 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
86086 static DEFINE_MUTEX(sock_diag_table_mutex);
86087
86088 int sock_diag_check_cookie(void *sk, __u32 *cookie)
86089 {
86090+#ifndef CONFIG_GRKERNSEC_HIDESYM
86091 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
86092 cookie[1] != INET_DIAG_NOCOOKIE) &&
86093 ((u32)(unsigned long)sk != cookie[0] ||
86094 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
86095 return -ESTALE;
86096 else
86097+#endif
86098 return 0;
86099 }
86100 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
86101
86102 void sock_diag_save_cookie(void *sk, __u32 *cookie)
86103 {
86104+#ifdef CONFIG_GRKERNSEC_HIDESYM
86105+ cookie[0] = 0;
86106+ cookie[1] = 0;
86107+#else
86108 cookie[0] = (u32)(unsigned long)sk;
86109 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
86110+#endif
86111 }
86112 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
86113
86114@@ -75,8 +82,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
86115 mutex_lock(&sock_diag_table_mutex);
86116 if (sock_diag_handlers[hndl->family])
86117 err = -EBUSY;
86118- else
86119+ else {
86120+ pax_open_kernel();
86121 sock_diag_handlers[hndl->family] = hndl;
86122+ pax_close_kernel();
86123+ }
86124 mutex_unlock(&sock_diag_table_mutex);
86125
86126 return err;
86127@@ -92,7 +102,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
86128
86129 mutex_lock(&sock_diag_table_mutex);
86130 BUG_ON(sock_diag_handlers[family] != hnld);
86131+ pax_open_kernel();
86132 sock_diag_handlers[family] = NULL;
86133+ pax_close_kernel();
86134 mutex_unlock(&sock_diag_table_mutex);
86135 }
86136 EXPORT_SYMBOL_GPL(sock_diag_unregister);
86137diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
86138index cfdb46a..cef55e1 100644
86139--- a/net/core/sysctl_net_core.c
86140+++ b/net/core/sysctl_net_core.c
86141@@ -28,7 +28,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
86142 {
86143 unsigned int orig_size, size;
86144 int ret, i;
86145- ctl_table tmp = {
86146+ ctl_table_no_const tmp = {
86147 .data = &size,
86148 .maxlen = sizeof(size),
86149 .mode = table->mode
86150@@ -211,13 +211,12 @@ static struct ctl_table netns_core_table[] = {
86151
86152 static __net_init int sysctl_core_net_init(struct net *net)
86153 {
86154- struct ctl_table *tbl;
86155+ ctl_table_no_const *tbl = NULL;
86156
86157 net->core.sysctl_somaxconn = SOMAXCONN;
86158
86159- tbl = netns_core_table;
86160 if (!net_eq(net, &init_net)) {
86161- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
86162+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
86163 if (tbl == NULL)
86164 goto err_dup;
86165
86166@@ -227,17 +226,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
86167 if (net->user_ns != &init_user_ns) {
86168 tbl[0].procname = NULL;
86169 }
86170- }
86171-
86172- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
86173+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
86174+ } else
86175+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
86176 if (net->core.sysctl_hdr == NULL)
86177 goto err_reg;
86178
86179 return 0;
86180
86181 err_reg:
86182- if (tbl != netns_core_table)
86183- kfree(tbl);
86184+ kfree(tbl);
86185 err_dup:
86186 return -ENOMEM;
86187 }
86188@@ -252,7 +250,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
86189 kfree(tbl);
86190 }
86191
86192-static __net_initdata struct pernet_operations sysctl_core_ops = {
86193+static __net_initconst struct pernet_operations sysctl_core_ops = {
86194 .init = sysctl_core_net_init,
86195 .exit = sysctl_core_net_exit,
86196 };
86197diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
86198index c21f200..bc4565b 100644
86199--- a/net/decnet/af_decnet.c
86200+++ b/net/decnet/af_decnet.c
86201@@ -465,6 +465,7 @@ static struct proto dn_proto = {
86202 .sysctl_rmem = sysctl_decnet_rmem,
86203 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
86204 .obj_size = sizeof(struct dn_sock),
86205+ .slab_flags = SLAB_USERCOPY,
86206 };
86207
86208 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
86209diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
86210index a55eecc..dd8428c 100644
86211--- a/net/decnet/sysctl_net_decnet.c
86212+++ b/net/decnet/sysctl_net_decnet.c
86213@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
86214
86215 if (len > *lenp) len = *lenp;
86216
86217- if (copy_to_user(buffer, addr, len))
86218+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
86219 return -EFAULT;
86220
86221 *lenp = len;
86222@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
86223
86224 if (len > *lenp) len = *lenp;
86225
86226- if (copy_to_user(buffer, devname, len))
86227+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
86228 return -EFAULT;
86229
86230 *lenp = len;
86231diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
86232index c929d9c..df10cde 100644
86233--- a/net/ipv4/af_inet.c
86234+++ b/net/ipv4/af_inet.c
86235@@ -115,6 +115,7 @@
86236 #include <net/inet_common.h>
86237 #include <net/xfrm.h>
86238 #include <net/net_namespace.h>
86239+#include <net/secure_seq.h>
86240 #ifdef CONFIG_IP_MROUTE
86241 #include <linux/mroute.h>
86242 #endif
86243@@ -263,8 +264,10 @@ void build_ehash_secret(void)
86244 get_random_bytes(&rnd, sizeof(rnd));
86245 } while (rnd == 0);
86246
86247- if (cmpxchg(&inet_ehash_secret, 0, rnd) == 0)
86248+ if (cmpxchg(&inet_ehash_secret, 0, rnd) == 0) {
86249 get_random_bytes(&ipv6_hash_secret, sizeof(ipv6_hash_secret));
86250+ net_secret_init();
86251+ }
86252 }
86253 EXPORT_SYMBOL(build_ehash_secret);
86254
86255@@ -1699,13 +1702,9 @@ static int __init inet_init(void)
86256
86257 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
86258
86259- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
86260- if (!sysctl_local_reserved_ports)
86261- goto out;
86262-
86263 rc = proto_register(&tcp_prot, 1);
86264 if (rc)
86265- goto out_free_reserved_ports;
86266+ goto out;
86267
86268 rc = proto_register(&udp_prot, 1);
86269 if (rc)
86270@@ -1814,8 +1813,6 @@ out_unregister_udp_proto:
86271 proto_unregister(&udp_prot);
86272 out_unregister_tcp_proto:
86273 proto_unregister(&tcp_prot);
86274-out_free_reserved_ports:
86275- kfree(sysctl_local_reserved_ports);
86276 goto out;
86277 }
86278
86279diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
86280index 2e7f194..0fa4d6d 100644
86281--- a/net/ipv4/ah4.c
86282+++ b/net/ipv4/ah4.c
86283@@ -420,7 +420,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
86284 return;
86285
86286 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
86287- atomic_inc(&flow_cache_genid);
86288+ atomic_inc_unchecked(&flow_cache_genid);
86289 rt_genid_bump(net);
86290
86291 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
86292diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
86293index c6287cd..e9bc96a 100644
86294--- a/net/ipv4/devinet.c
86295+++ b/net/ipv4/devinet.c
86296@@ -1992,7 +1992,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
86297 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
86298 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
86299
86300-static struct devinet_sysctl_table {
86301+static const struct devinet_sysctl_table {
86302 struct ctl_table_header *sysctl_header;
86303 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
86304 } devinet_sysctl = {
86305@@ -2110,7 +2110,7 @@ static __net_init int devinet_init_net(struct net *net)
86306 int err;
86307 struct ipv4_devconf *all, *dflt;
86308 #ifdef CONFIG_SYSCTL
86309- struct ctl_table *tbl = ctl_forward_entry;
86310+ ctl_table_no_const *tbl = NULL;
86311 struct ctl_table_header *forw_hdr;
86312 #endif
86313
86314@@ -2128,7 +2128,7 @@ static __net_init int devinet_init_net(struct net *net)
86315 goto err_alloc_dflt;
86316
86317 #ifdef CONFIG_SYSCTL
86318- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
86319+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
86320 if (tbl == NULL)
86321 goto err_alloc_ctl;
86322
86323@@ -2148,7 +2148,10 @@ static __net_init int devinet_init_net(struct net *net)
86324 goto err_reg_dflt;
86325
86326 err = -ENOMEM;
86327- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
86328+ if (!net_eq(net, &init_net))
86329+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
86330+ else
86331+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
86332 if (forw_hdr == NULL)
86333 goto err_reg_ctl;
86334 net->ipv4.forw_hdr = forw_hdr;
86335@@ -2164,8 +2167,7 @@ err_reg_ctl:
86336 err_reg_dflt:
86337 __devinet_sysctl_unregister(all);
86338 err_reg_all:
86339- if (tbl != ctl_forward_entry)
86340- kfree(tbl);
86341+ kfree(tbl);
86342 err_alloc_ctl:
86343 #endif
86344 if (dflt != &ipv4_devconf_dflt)
86345diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
86346index 4cfe34d..a6ba66e 100644
86347--- a/net/ipv4/esp4.c
86348+++ b/net/ipv4/esp4.c
86349@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
86350 return;
86351
86352 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
86353- atomic_inc(&flow_cache_genid);
86354+ atomic_inc_unchecked(&flow_cache_genid);
86355 rt_genid_bump(net);
86356
86357 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
86358diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
86359index eb4bb12..ee4ec7d 100644
86360--- a/net/ipv4/fib_frontend.c
86361+++ b/net/ipv4/fib_frontend.c
86362@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
86363 #ifdef CONFIG_IP_ROUTE_MULTIPATH
86364 fib_sync_up(dev);
86365 #endif
86366- atomic_inc(&net->ipv4.dev_addr_genid);
86367+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
86368 rt_cache_flush(dev_net(dev));
86369 break;
86370 case NETDEV_DOWN:
86371 fib_del_ifaddr(ifa, NULL);
86372- atomic_inc(&net->ipv4.dev_addr_genid);
86373+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
86374 if (ifa->ifa_dev->ifa_list == NULL) {
86375 /* Last address was deleted from this interface.
86376 * Disable IP.
86377@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
86378 #ifdef CONFIG_IP_ROUTE_MULTIPATH
86379 fib_sync_up(dev);
86380 #endif
86381- atomic_inc(&net->ipv4.dev_addr_genid);
86382+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
86383 rt_cache_flush(net);
86384 break;
86385 case NETDEV_DOWN:
86386diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
86387index 8f6cb7a..34507f9 100644
86388--- a/net/ipv4/fib_semantics.c
86389+++ b/net/ipv4/fib_semantics.c
86390@@ -765,7 +765,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
86391 nh->nh_saddr = inet_select_addr(nh->nh_dev,
86392 nh->nh_gw,
86393 nh->nh_parent->fib_scope);
86394- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
86395+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
86396
86397 return nh->nh_saddr;
86398 }
86399diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
86400index 786d97a..1889c0d 100644
86401--- a/net/ipv4/inet_connection_sock.c
86402+++ b/net/ipv4/inet_connection_sock.c
86403@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
86404 .range = { 32768, 61000 },
86405 };
86406
86407-unsigned long *sysctl_local_reserved_ports;
86408+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
86409 EXPORT_SYMBOL(sysctl_local_reserved_ports);
86410
86411 void inet_get_local_port_range(int *low, int *high)
86412diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
86413index 6af375a..c493c74 100644
86414--- a/net/ipv4/inet_hashtables.c
86415+++ b/net/ipv4/inet_hashtables.c
86416@@ -18,12 +18,15 @@
86417 #include <linux/sched.h>
86418 #include <linux/slab.h>
86419 #include <linux/wait.h>
86420+#include <linux/security.h>
86421
86422 #include <net/inet_connection_sock.h>
86423 #include <net/inet_hashtables.h>
86424 #include <net/secure_seq.h>
86425 #include <net/ip.h>
86426
86427+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
86428+
86429 /*
86430 * Allocate and initialize a new local port bind bucket.
86431 * The bindhash mutex for snum's hash chain must be held here.
86432@@ -554,6 +557,8 @@ ok:
86433 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
86434 spin_unlock(&head->lock);
86435
86436+ gr_update_task_in_ip_table(current, inet_sk(sk));
86437+
86438 if (tw) {
86439 inet_twsk_deschedule(tw, death_row);
86440 while (twrefcnt) {
86441diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
86442index 000e3d2..5472da3 100644
86443--- a/net/ipv4/inetpeer.c
86444+++ b/net/ipv4/inetpeer.c
86445@@ -503,8 +503,8 @@ relookup:
86446 if (p) {
86447 p->daddr = *daddr;
86448 atomic_set(&p->refcnt, 1);
86449- atomic_set(&p->rid, 0);
86450- atomic_set(&p->ip_id_count,
86451+ atomic_set_unchecked(&p->rid, 0);
86452+ atomic_set_unchecked(&p->ip_id_count,
86453 (daddr->family == AF_INET) ?
86454 secure_ip_id(daddr->addr.a4) :
86455 secure_ipv6_id(daddr->addr.a6));
86456diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
86457index 52c273e..579060b 100644
86458--- a/net/ipv4/ip_fragment.c
86459+++ b/net/ipv4/ip_fragment.c
86460@@ -311,7 +311,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
86461 return 0;
86462
86463 start = qp->rid;
86464- end = atomic_inc_return(&peer->rid);
86465+ end = atomic_inc_return_unchecked(&peer->rid);
86466 qp->rid = end;
86467
86468 rc = qp->q.fragments && (end - start) > max;
86469@@ -788,12 +788,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
86470
86471 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
86472 {
86473- struct ctl_table *table;
86474+ ctl_table_no_const *table = NULL;
86475 struct ctl_table_header *hdr;
86476
86477- table = ip4_frags_ns_ctl_table;
86478 if (!net_eq(net, &init_net)) {
86479- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
86480+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
86481 if (table == NULL)
86482 goto err_alloc;
86483
86484@@ -804,9 +803,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
86485 /* Don't export sysctls to unprivileged users */
86486 if (net->user_ns != &init_user_ns)
86487 table[0].procname = NULL;
86488- }
86489+ hdr = register_net_sysctl(net, "net/ipv4", table);
86490+ } else
86491+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
86492
86493- hdr = register_net_sysctl(net, "net/ipv4", table);
86494 if (hdr == NULL)
86495 goto err_reg;
86496
86497@@ -814,8 +814,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
86498 return 0;
86499
86500 err_reg:
86501- if (!net_eq(net, &init_net))
86502- kfree(table);
86503+ kfree(table);
86504 err_alloc:
86505 return -ENOMEM;
86506 }
86507diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
86508index 91d66db..4af7d99 100644
86509--- a/net/ipv4/ip_gre.c
86510+++ b/net/ipv4/ip_gre.c
86511@@ -124,7 +124,7 @@ static bool log_ecn_error = true;
86512 module_param(log_ecn_error, bool, 0644);
86513 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
86514
86515-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
86516+static struct rtnl_link_ops ipgre_link_ops;
86517 static int ipgre_tunnel_init(struct net_device *dev);
86518 static void ipgre_tunnel_setup(struct net_device *dev);
86519 static int ipgre_tunnel_bind_dev(struct net_device *dev);
86520@@ -1823,7 +1823,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
86521 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
86522 };
86523
86524-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
86525+static struct rtnl_link_ops ipgre_link_ops = {
86526 .kind = "gre",
86527 .maxtype = IFLA_GRE_MAX,
86528 .policy = ipgre_policy,
86529@@ -1836,7 +1836,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
86530 .fill_info = ipgre_fill_info,
86531 };
86532
86533-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
86534+static struct rtnl_link_ops ipgre_tap_ops = {
86535 .kind = "gretap",
86536 .maxtype = IFLA_GRE_MAX,
86537 .policy = ipgre_policy,
86538diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
86539index d9c4f11..02b82dbc 100644
86540--- a/net/ipv4/ip_sockglue.c
86541+++ b/net/ipv4/ip_sockglue.c
86542@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
86543 len = min_t(unsigned int, len, opt->optlen);
86544 if (put_user(len, optlen))
86545 return -EFAULT;
86546- if (copy_to_user(optval, opt->__data, len))
86547+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
86548+ copy_to_user(optval, opt->__data, len))
86549 return -EFAULT;
86550 return 0;
86551 }
86552@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
86553 if (sk->sk_type != SOCK_STREAM)
86554 return -ENOPROTOOPT;
86555
86556- msg.msg_control = optval;
86557+ msg.msg_control = (void __force_kernel *)optval;
86558 msg.msg_controllen = len;
86559 msg.msg_flags = flags;
86560
86561diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
86562index c3a4233..1412161 100644
86563--- a/net/ipv4/ip_vti.c
86564+++ b/net/ipv4/ip_vti.c
86565@@ -47,7 +47,7 @@
86566 #define HASH_SIZE 16
86567 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
86568
86569-static struct rtnl_link_ops vti_link_ops __read_mostly;
86570+static struct rtnl_link_ops vti_link_ops;
86571
86572 static int vti_net_id __read_mostly;
86573 struct vti_net {
86574@@ -886,7 +886,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
86575 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
86576 };
86577
86578-static struct rtnl_link_ops vti_link_ops __read_mostly = {
86579+static struct rtnl_link_ops vti_link_ops = {
86580 .kind = "vti",
86581 .maxtype = IFLA_VTI_MAX,
86582 .policy = vti_policy,
86583diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
86584index f01d1b1..8fe03ad 100644
86585--- a/net/ipv4/ipcomp.c
86586+++ b/net/ipv4/ipcomp.c
86587@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
86588 return;
86589
86590 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
86591- atomic_inc(&flow_cache_genid);
86592+ atomic_inc_unchecked(&flow_cache_genid);
86593 rt_genid_bump(net);
86594
86595 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
86596diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
86597index bf6c5cf..ab2e9c6 100644
86598--- a/net/ipv4/ipconfig.c
86599+++ b/net/ipv4/ipconfig.c
86600@@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
86601
86602 mm_segment_t oldfs = get_fs();
86603 set_fs(get_ds());
86604- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
86605+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
86606 set_fs(oldfs);
86607 return res;
86608 }
86609@@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
86610
86611 mm_segment_t oldfs = get_fs();
86612 set_fs(get_ds());
86613- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
86614+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
86615 set_fs(oldfs);
86616 return res;
86617 }
86618@@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
86619
86620 mm_segment_t oldfs = get_fs();
86621 set_fs(get_ds());
86622- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
86623+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
86624 set_fs(oldfs);
86625 return res;
86626 }
86627diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
86628index 8f024d4..8b3500c 100644
86629--- a/net/ipv4/ipip.c
86630+++ b/net/ipv4/ipip.c
86631@@ -138,7 +138,7 @@ struct ipip_net {
86632 static int ipip_tunnel_init(struct net_device *dev);
86633 static void ipip_tunnel_setup(struct net_device *dev);
86634 static void ipip_dev_free(struct net_device *dev);
86635-static struct rtnl_link_ops ipip_link_ops __read_mostly;
86636+static struct rtnl_link_ops ipip_link_ops;
86637
86638 static struct rtnl_link_stats64 *ipip_get_stats64(struct net_device *dev,
86639 struct rtnl_link_stats64 *tot)
86640@@ -974,7 +974,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
86641 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
86642 };
86643
86644-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
86645+static struct rtnl_link_ops ipip_link_ops = {
86646 .kind = "ipip",
86647 .maxtype = IFLA_IPTUN_MAX,
86648 .policy = ipip_policy,
86649diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
86650index 7dc6a97..229c61b 100644
86651--- a/net/ipv4/netfilter/arp_tables.c
86652+++ b/net/ipv4/netfilter/arp_tables.c
86653@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
86654 #endif
86655
86656 static int get_info(struct net *net, void __user *user,
86657- const int *len, int compat)
86658+ int len, int compat)
86659 {
86660 char name[XT_TABLE_MAXNAMELEN];
86661 struct xt_table *t;
86662 int ret;
86663
86664- if (*len != sizeof(struct arpt_getinfo)) {
86665- duprintf("length %u != %Zu\n", *len,
86666+ if (len != sizeof(struct arpt_getinfo)) {
86667+ duprintf("length %u != %Zu\n", len,
86668 sizeof(struct arpt_getinfo));
86669 return -EINVAL;
86670 }
86671@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
86672 info.size = private->size;
86673 strcpy(info.name, name);
86674
86675- if (copy_to_user(user, &info, *len) != 0)
86676+ if (copy_to_user(user, &info, len) != 0)
86677 ret = -EFAULT;
86678 else
86679 ret = 0;
86680@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
86681
86682 switch (cmd) {
86683 case ARPT_SO_GET_INFO:
86684- ret = get_info(sock_net(sk), user, len, 1);
86685+ ret = get_info(sock_net(sk), user, *len, 1);
86686 break;
86687 case ARPT_SO_GET_ENTRIES:
86688 ret = compat_get_entries(sock_net(sk), user, len);
86689@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
86690
86691 switch (cmd) {
86692 case ARPT_SO_GET_INFO:
86693- ret = get_info(sock_net(sk), user, len, 0);
86694+ ret = get_info(sock_net(sk), user, *len, 0);
86695 break;
86696
86697 case ARPT_SO_GET_ENTRIES:
86698diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
86699index 3efcf87..5247916 100644
86700--- a/net/ipv4/netfilter/ip_tables.c
86701+++ b/net/ipv4/netfilter/ip_tables.c
86702@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
86703 #endif
86704
86705 static int get_info(struct net *net, void __user *user,
86706- const int *len, int compat)
86707+ int len, int compat)
86708 {
86709 char name[XT_TABLE_MAXNAMELEN];
86710 struct xt_table *t;
86711 int ret;
86712
86713- if (*len != sizeof(struct ipt_getinfo)) {
86714- duprintf("length %u != %zu\n", *len,
86715+ if (len != sizeof(struct ipt_getinfo)) {
86716+ duprintf("length %u != %zu\n", len,
86717 sizeof(struct ipt_getinfo));
86718 return -EINVAL;
86719 }
86720@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
86721 info.size = private->size;
86722 strcpy(info.name, name);
86723
86724- if (copy_to_user(user, &info, *len) != 0)
86725+ if (copy_to_user(user, &info, len) != 0)
86726 ret = -EFAULT;
86727 else
86728 ret = 0;
86729@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86730
86731 switch (cmd) {
86732 case IPT_SO_GET_INFO:
86733- ret = get_info(sock_net(sk), user, len, 1);
86734+ ret = get_info(sock_net(sk), user, *len, 1);
86735 break;
86736 case IPT_SO_GET_ENTRIES:
86737 ret = compat_get_entries(sock_net(sk), user, len);
86738@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86739
86740 switch (cmd) {
86741 case IPT_SO_GET_INFO:
86742- ret = get_info(sock_net(sk), user, len, 0);
86743+ ret = get_info(sock_net(sk), user, *len, 0);
86744 break;
86745
86746 case IPT_SO_GET_ENTRIES:
86747diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
86748index 2e91006..f084394 100644
86749--- a/net/ipv4/ping.c
86750+++ b/net/ipv4/ping.c
86751@@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
86752 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
86753 0, sock_i_ino(sp),
86754 atomic_read(&sp->sk_refcnt), sp,
86755- atomic_read(&sp->sk_drops), len);
86756+ atomic_read_unchecked(&sp->sk_drops), len);
86757 }
86758
86759 static int ping_seq_show(struct seq_file *seq, void *v)
86760diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
86761index dd44e0a..06dcca4 100644
86762--- a/net/ipv4/raw.c
86763+++ b/net/ipv4/raw.c
86764@@ -309,7 +309,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
86765 int raw_rcv(struct sock *sk, struct sk_buff *skb)
86766 {
86767 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
86768- atomic_inc(&sk->sk_drops);
86769+ atomic_inc_unchecked(&sk->sk_drops);
86770 kfree_skb(skb);
86771 return NET_RX_DROP;
86772 }
86773@@ -745,16 +745,20 @@ static int raw_init(struct sock *sk)
86774
86775 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
86776 {
86777+ struct icmp_filter filter;
86778+
86779 if (optlen > sizeof(struct icmp_filter))
86780 optlen = sizeof(struct icmp_filter);
86781- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
86782+ if (copy_from_user(&filter, optval, optlen))
86783 return -EFAULT;
86784+ raw_sk(sk)->filter = filter;
86785 return 0;
86786 }
86787
86788 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
86789 {
86790 int len, ret = -EFAULT;
86791+ struct icmp_filter filter;
86792
86793 if (get_user(len, optlen))
86794 goto out;
86795@@ -764,8 +768,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
86796 if (len > sizeof(struct icmp_filter))
86797 len = sizeof(struct icmp_filter);
86798 ret = -EFAULT;
86799- if (put_user(len, optlen) ||
86800- copy_to_user(optval, &raw_sk(sk)->filter, len))
86801+ filter = raw_sk(sk)->filter;
86802+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
86803 goto out;
86804 ret = 0;
86805 out: return ret;
86806@@ -994,7 +998,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
86807 0, 0L, 0,
86808 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
86809 0, sock_i_ino(sp),
86810- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
86811+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
86812 }
86813
86814 static int raw_seq_show(struct seq_file *seq, void *v)
86815diff --git a/net/ipv4/route.c b/net/ipv4/route.c
86816index 6e28514..5e1b055 100644
86817--- a/net/ipv4/route.c
86818+++ b/net/ipv4/route.c
86819@@ -2553,34 +2553,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
86820 .maxlen = sizeof(int),
86821 .mode = 0200,
86822 .proc_handler = ipv4_sysctl_rtcache_flush,
86823+ .extra1 = &init_net,
86824 },
86825 { },
86826 };
86827
86828 static __net_init int sysctl_route_net_init(struct net *net)
86829 {
86830- struct ctl_table *tbl;
86831+ ctl_table_no_const *tbl = NULL;
86832
86833- tbl = ipv4_route_flush_table;
86834 if (!net_eq(net, &init_net)) {
86835- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
86836+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
86837 if (tbl == NULL)
86838 goto err_dup;
86839
86840 /* Don't export sysctls to unprivileged users */
86841 if (net->user_ns != &init_user_ns)
86842 tbl[0].procname = NULL;
86843- }
86844- tbl[0].extra1 = net;
86845+ tbl[0].extra1 = net;
86846+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
86847+ } else
86848+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
86849
86850- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
86851 if (net->ipv4.route_hdr == NULL)
86852 goto err_reg;
86853 return 0;
86854
86855 err_reg:
86856- if (tbl != ipv4_route_flush_table)
86857- kfree(tbl);
86858+ kfree(tbl);
86859 err_dup:
86860 return -ENOMEM;
86861 }
86862@@ -2603,7 +2603,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
86863
86864 static __net_init int rt_genid_init(struct net *net)
86865 {
86866- atomic_set(&net->rt_genid, 0);
86867+ atomic_set_unchecked(&net->rt_genid, 0);
86868 get_random_bytes(&net->ipv4.dev_addr_genid,
86869 sizeof(net->ipv4.dev_addr_genid));
86870 return 0;
86871diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
86872index 960fd29..d55bf64 100644
86873--- a/net/ipv4/sysctl_net_ipv4.c
86874+++ b/net/ipv4/sysctl_net_ipv4.c
86875@@ -55,7 +55,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
86876 {
86877 int ret;
86878 int range[2];
86879- ctl_table tmp = {
86880+ ctl_table_no_const tmp = {
86881 .data = &range,
86882 .maxlen = sizeof(range),
86883 .mode = table->mode,
86884@@ -108,7 +108,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
86885 int ret;
86886 gid_t urange[2];
86887 kgid_t low, high;
86888- ctl_table tmp = {
86889+ ctl_table_no_const tmp = {
86890 .data = &urange,
86891 .maxlen = sizeof(urange),
86892 .mode = table->mode,
86893@@ -139,7 +139,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
86894 void __user *buffer, size_t *lenp, loff_t *ppos)
86895 {
86896 char val[TCP_CA_NAME_MAX];
86897- ctl_table tbl = {
86898+ ctl_table_no_const tbl = {
86899 .data = val,
86900 .maxlen = TCP_CA_NAME_MAX,
86901 };
86902@@ -158,7 +158,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
86903 void __user *buffer, size_t *lenp,
86904 loff_t *ppos)
86905 {
86906- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
86907+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
86908 int ret;
86909
86910 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
86911@@ -175,7 +175,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
86912 void __user *buffer, size_t *lenp,
86913 loff_t *ppos)
86914 {
86915- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
86916+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
86917 int ret;
86918
86919 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
86920@@ -201,15 +201,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
86921 struct mem_cgroup *memcg;
86922 #endif
86923
86924- ctl_table tmp = {
86925+ ctl_table_no_const tmp = {
86926 .data = &vec,
86927 .maxlen = sizeof(vec),
86928 .mode = ctl->mode,
86929 };
86930
86931 if (!write) {
86932- ctl->data = &net->ipv4.sysctl_tcp_mem;
86933- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
86934+ ctl_table_no_const tcp_mem = *ctl;
86935+
86936+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
86937+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
86938 }
86939
86940 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
86941@@ -236,7 +238,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
86942 static int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
86943 size_t *lenp, loff_t *ppos)
86944 {
86945- ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
86946+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
86947 struct tcp_fastopen_context *ctxt;
86948 int ret;
86949 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
86950@@ -477,7 +479,7 @@ static struct ctl_table ipv4_table[] = {
86951 },
86952 {
86953 .procname = "ip_local_reserved_ports",
86954- .data = NULL, /* initialized in sysctl_ipv4_init */
86955+ .data = sysctl_local_reserved_ports,
86956 .maxlen = 65536,
86957 .mode = 0644,
86958 .proc_handler = proc_do_large_bitmap,
86959@@ -856,11 +858,10 @@ static struct ctl_table ipv4_net_table[] = {
86960
86961 static __net_init int ipv4_sysctl_init_net(struct net *net)
86962 {
86963- struct ctl_table *table;
86964+ ctl_table_no_const *table = NULL;
86965
86966- table = ipv4_net_table;
86967 if (!net_eq(net, &init_net)) {
86968- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
86969+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
86970 if (table == NULL)
86971 goto err_alloc;
86972
86973@@ -895,15 +896,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
86974
86975 tcp_init_mem(net);
86976
86977- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
86978+ if (!net_eq(net, &init_net))
86979+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
86980+ else
86981+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
86982 if (net->ipv4.ipv4_hdr == NULL)
86983 goto err_reg;
86984
86985 return 0;
86986
86987 err_reg:
86988- if (!net_eq(net, &init_net))
86989- kfree(table);
86990+ kfree(table);
86991 err_alloc:
86992 return -ENOMEM;
86993 }
86994@@ -925,16 +928,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
86995 static __init int sysctl_ipv4_init(void)
86996 {
86997 struct ctl_table_header *hdr;
86998- struct ctl_table *i;
86999-
87000- for (i = ipv4_table; i->procname; i++) {
87001- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
87002- i->data = sysctl_local_reserved_ports;
87003- break;
87004- }
87005- }
87006- if (!i->procname)
87007- return -EINVAL;
87008
87009 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
87010 if (hdr == NULL)
87011diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
87012index e220207..cdeb839 100644
87013--- a/net/ipv4/tcp.c
87014+++ b/net/ipv4/tcp.c
87015@@ -3383,8 +3383,11 @@ int tcp_md5_hash_skb_data(struct tcp_md5sig_pool *hp,
87016
87017 for (i = 0; i < shi->nr_frags; ++i) {
87018 const struct skb_frag_struct *f = &shi->frags[i];
87019- struct page *page = skb_frag_page(f);
87020- sg_set_page(&sg, page, skb_frag_size(f), f->page_offset);
87021+ unsigned int offset = f->page_offset;
87022+ struct page *page = skb_frag_page(f) + (offset >> PAGE_SHIFT);
87023+
87024+ sg_set_page(&sg, page, skb_frag_size(f),
87025+ offset_in_page(offset));
87026 if (crypto_hash_update(desc, &sg, skb_frag_size(f)))
87027 return 1;
87028 }
87029diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
87030index 13b9c08..d33a8d0 100644
87031--- a/net/ipv4/tcp_input.c
87032+++ b/net/ipv4/tcp_input.c
87033@@ -4724,7 +4724,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
87034 * simplifies code)
87035 */
87036 static void
87037-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
87038+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
87039 struct sk_buff *head, struct sk_buff *tail,
87040 u32 start, u32 end)
87041 {
87042@@ -5838,6 +5838,7 @@ discard:
87043 tcp_paws_reject(&tp->rx_opt, 0))
87044 goto discard_and_undo;
87045
87046+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
87047 if (th->syn) {
87048 /* We see SYN without ACK. It is attempt of
87049 * simultaneous connect with crossed SYNs.
87050@@ -5888,6 +5889,7 @@ discard:
87051 goto discard;
87052 #endif
87053 }
87054+#endif
87055 /* "fifth, if neither of the SYN or RST bits is set then
87056 * drop the segment and return."
87057 */
87058@@ -5932,7 +5934,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
87059 goto discard;
87060
87061 if (th->syn) {
87062- if (th->fin)
87063+ if (th->fin || th->urg || th->psh)
87064 goto discard;
87065 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
87066 return 1;
87067diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
87068index d09203c..fd5cc91 100644
87069--- a/net/ipv4/tcp_ipv4.c
87070+++ b/net/ipv4/tcp_ipv4.c
87071@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
87072 EXPORT_SYMBOL(sysctl_tcp_low_latency);
87073
87074
87075+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87076+extern int grsec_enable_blackhole;
87077+#endif
87078+
87079 #ifdef CONFIG_TCP_MD5SIG
87080 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
87081 __be32 daddr, __be32 saddr, const struct tcphdr *th);
87082@@ -1897,6 +1901,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
87083 return 0;
87084
87085 reset:
87086+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87087+ if (!grsec_enable_blackhole)
87088+#endif
87089 tcp_v4_send_reset(rsk, skb);
87090 discard:
87091 kfree_skb(skb);
87092@@ -1996,12 +2003,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
87093 TCP_SKB_CB(skb)->sacked = 0;
87094
87095 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
87096- if (!sk)
87097+ if (!sk) {
87098+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87099+ ret = 1;
87100+#endif
87101 goto no_tcp_socket;
87102-
87103+ }
87104 process:
87105- if (sk->sk_state == TCP_TIME_WAIT)
87106+ if (sk->sk_state == TCP_TIME_WAIT) {
87107+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87108+ ret = 2;
87109+#endif
87110 goto do_time_wait;
87111+ }
87112
87113 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
87114 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
87115@@ -2052,6 +2066,10 @@ no_tcp_socket:
87116 bad_packet:
87117 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
87118 } else {
87119+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87120+ if (!grsec_enable_blackhole || (ret == 1 &&
87121+ (skb->dev->flags & IFF_LOOPBACK)))
87122+#endif
87123 tcp_v4_send_reset(NULL, skb);
87124 }
87125
87126diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
87127index 2f672e7..b8895e9 100644
87128--- a/net/ipv4/tcp_minisocks.c
87129+++ b/net/ipv4/tcp_minisocks.c
87130@@ -27,6 +27,10 @@
87131 #include <net/inet_common.h>
87132 #include <net/xfrm.h>
87133
87134+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87135+extern int grsec_enable_blackhole;
87136+#endif
87137+
87138 int sysctl_tcp_syncookies __read_mostly = 1;
87139 EXPORT_SYMBOL(sysctl_tcp_syncookies);
87140
87141@@ -749,7 +753,10 @@ embryonic_reset:
87142 * avoid becoming vulnerable to outside attack aiming at
87143 * resetting legit local connections.
87144 */
87145- req->rsk_ops->send_reset(sk, skb);
87146+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87147+ if (!grsec_enable_blackhole)
87148+#endif
87149+ req->rsk_ops->send_reset(sk, skb);
87150 } else if (fastopen) { /* received a valid RST pkt */
87151 reqsk_fastopen_remove(sk, req, true);
87152 tcp_reset(sk);
87153diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
87154index d4943f6..e7a74a5 100644
87155--- a/net/ipv4/tcp_probe.c
87156+++ b/net/ipv4/tcp_probe.c
87157@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
87158 if (cnt + width >= len)
87159 break;
87160
87161- if (copy_to_user(buf + cnt, tbuf, width))
87162+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
87163 return -EFAULT;
87164 cnt += width;
87165 }
87166diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
87167index b78aac3..e18230b 100644
87168--- a/net/ipv4/tcp_timer.c
87169+++ b/net/ipv4/tcp_timer.c
87170@@ -22,6 +22,10 @@
87171 #include <linux/gfp.h>
87172 #include <net/tcp.h>
87173
87174+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87175+extern int grsec_lastack_retries;
87176+#endif
87177+
87178 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
87179 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
87180 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
87181@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
87182 }
87183 }
87184
87185+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87186+ if ((sk->sk_state == TCP_LAST_ACK) &&
87187+ (grsec_lastack_retries > 0) &&
87188+ (grsec_lastack_retries < retry_until))
87189+ retry_until = grsec_lastack_retries;
87190+#endif
87191+
87192 if (retransmits_timed_out(sk, retry_until,
87193 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
87194 /* Has it gone just too far? */
87195diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
87196index 0a073a2..ddf6279 100644
87197--- a/net/ipv4/udp.c
87198+++ b/net/ipv4/udp.c
87199@@ -87,6 +87,7 @@
87200 #include <linux/types.h>
87201 #include <linux/fcntl.h>
87202 #include <linux/module.h>
87203+#include <linux/security.h>
87204 #include <linux/socket.h>
87205 #include <linux/sockios.h>
87206 #include <linux/igmp.h>
87207@@ -111,6 +112,10 @@
87208 #include <trace/events/skb.h>
87209 #include "udp_impl.h"
87210
87211+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87212+extern int grsec_enable_blackhole;
87213+#endif
87214+
87215 struct udp_table udp_table __read_mostly;
87216 EXPORT_SYMBOL(udp_table);
87217
87218@@ -594,6 +599,9 @@ found:
87219 return s;
87220 }
87221
87222+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
87223+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
87224+
87225 /*
87226 * This routine is called by the ICMP module when it gets some
87227 * sort of error condition. If err < 0 then the socket should
87228@@ -889,9 +897,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
87229 dport = usin->sin_port;
87230 if (dport == 0)
87231 return -EINVAL;
87232+
87233+ err = gr_search_udp_sendmsg(sk, usin);
87234+ if (err)
87235+ return err;
87236 } else {
87237 if (sk->sk_state != TCP_ESTABLISHED)
87238 return -EDESTADDRREQ;
87239+
87240+ err = gr_search_udp_sendmsg(sk, NULL);
87241+ if (err)
87242+ return err;
87243+
87244 daddr = inet->inet_daddr;
87245 dport = inet->inet_dport;
87246 /* Open fast path for connected socket.
87247@@ -1133,7 +1150,7 @@ static unsigned int first_packet_length(struct sock *sk)
87248 udp_lib_checksum_complete(skb)) {
87249 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
87250 IS_UDPLITE(sk));
87251- atomic_inc(&sk->sk_drops);
87252+ atomic_inc_unchecked(&sk->sk_drops);
87253 __skb_unlink(skb, rcvq);
87254 __skb_queue_tail(&list_kill, skb);
87255 }
87256@@ -1219,6 +1236,10 @@ try_again:
87257 if (!skb)
87258 goto out;
87259
87260+ err = gr_search_udp_recvmsg(sk, skb);
87261+ if (err)
87262+ goto out_free;
87263+
87264 ulen = skb->len - sizeof(struct udphdr);
87265 copied = len;
87266 if (copied > ulen)
87267@@ -1252,7 +1273,7 @@ try_again:
87268 if (unlikely(err)) {
87269 trace_kfree_skb(skb, udp_recvmsg);
87270 if (!peeked) {
87271- atomic_inc(&sk->sk_drops);
87272+ atomic_inc_unchecked(&sk->sk_drops);
87273 UDP_INC_STATS_USER(sock_net(sk),
87274 UDP_MIB_INERRORS, is_udplite);
87275 }
87276@@ -1535,7 +1556,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
87277
87278 drop:
87279 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
87280- atomic_inc(&sk->sk_drops);
87281+ atomic_inc_unchecked(&sk->sk_drops);
87282 kfree_skb(skb);
87283 return -1;
87284 }
87285@@ -1554,7 +1575,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
87286 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
87287
87288 if (!skb1) {
87289- atomic_inc(&sk->sk_drops);
87290+ atomic_inc_unchecked(&sk->sk_drops);
87291 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
87292 IS_UDPLITE(sk));
87293 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
87294@@ -1723,6 +1744,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
87295 goto csum_error;
87296
87297 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
87298+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87299+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
87300+#endif
87301 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
87302
87303 /*
87304@@ -2152,7 +2176,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
87305 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
87306 0, sock_i_ino(sp),
87307 atomic_read(&sp->sk_refcnt), sp,
87308- atomic_read(&sp->sk_drops), len);
87309+ atomic_read_unchecked(&sp->sk_drops), len);
87310 }
87311
87312 int udp4_seq_show(struct seq_file *seq, void *v)
87313diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
87314index 9a459be..086b866 100644
87315--- a/net/ipv4/xfrm4_policy.c
87316+++ b/net/ipv4/xfrm4_policy.c
87317@@ -264,19 +264,18 @@ static struct ctl_table xfrm4_policy_table[] = {
87318
87319 static int __net_init xfrm4_net_init(struct net *net)
87320 {
87321- struct ctl_table *table;
87322+ ctl_table_no_const *table = NULL;
87323 struct ctl_table_header *hdr;
87324
87325- table = xfrm4_policy_table;
87326 if (!net_eq(net, &init_net)) {
87327- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
87328+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
87329 if (!table)
87330 goto err_alloc;
87331
87332 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
87333- }
87334-
87335- hdr = register_net_sysctl(net, "net/ipv4", table);
87336+ hdr = register_net_sysctl(net, "net/ipv4", table);
87337+ } else
87338+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
87339 if (!hdr)
87340 goto err_reg;
87341
87342@@ -284,8 +283,7 @@ static int __net_init xfrm4_net_init(struct net *net)
87343 return 0;
87344
87345 err_reg:
87346- if (!net_eq(net, &init_net))
87347- kfree(table);
87348+ kfree(table);
87349 err_alloc:
87350 return -ENOMEM;
87351 }
87352diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
87353index dae802c..bfa4baa 100644
87354--- a/net/ipv6/addrconf.c
87355+++ b/net/ipv6/addrconf.c
87356@@ -2274,7 +2274,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
87357 p.iph.ihl = 5;
87358 p.iph.protocol = IPPROTO_IPV6;
87359 p.iph.ttl = 64;
87360- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
87361+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
87362
87363 if (ops->ndo_do_ioctl) {
87364 mm_segment_t oldfs = get_fs();
87365@@ -4410,7 +4410,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
87366 int *valp = ctl->data;
87367 int val = *valp;
87368 loff_t pos = *ppos;
87369- ctl_table lctl;
87370+ ctl_table_no_const lctl;
87371 int ret;
87372
87373 /*
87374@@ -4492,7 +4492,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
87375 int *valp = ctl->data;
87376 int val = *valp;
87377 loff_t pos = *ppos;
87378- ctl_table lctl;
87379+ ctl_table_no_const lctl;
87380 int ret;
87381
87382 /*
87383diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
87384index fff5bdd..15194fb 100644
87385--- a/net/ipv6/icmp.c
87386+++ b/net/ipv6/icmp.c
87387@@ -973,7 +973,7 @@ ctl_table ipv6_icmp_table_template[] = {
87388
87389 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
87390 {
87391- struct ctl_table *table;
87392+ ctl_table_no_const *table;
87393
87394 table = kmemdup(ipv6_icmp_table_template,
87395 sizeof(ipv6_icmp_table_template),
87396diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
87397index 95d13c7..791fe2f 100644
87398--- a/net/ipv6/ip6_gre.c
87399+++ b/net/ipv6/ip6_gre.c
87400@@ -73,7 +73,7 @@ struct ip6gre_net {
87401 struct net_device *fb_tunnel_dev;
87402 };
87403
87404-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
87405+static struct rtnl_link_ops ip6gre_link_ops;
87406 static int ip6gre_tunnel_init(struct net_device *dev);
87407 static void ip6gre_tunnel_setup(struct net_device *dev);
87408 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
87409@@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
87410 }
87411
87412
87413-static struct inet6_protocol ip6gre_protocol __read_mostly = {
87414+static struct inet6_protocol ip6gre_protocol = {
87415 .handler = ip6gre_rcv,
87416 .err_handler = ip6gre_err,
87417 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
87418@@ -1671,7 +1671,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
87419 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
87420 };
87421
87422-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
87423+static struct rtnl_link_ops ip6gre_link_ops = {
87424 .kind = "ip6gre",
87425 .maxtype = IFLA_GRE_MAX,
87426 .policy = ip6gre_policy,
87427@@ -1684,7 +1684,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
87428 .fill_info = ip6gre_fill_info,
87429 };
87430
87431-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
87432+static struct rtnl_link_ops ip6gre_tap_ops = {
87433 .kind = "ip6gretap",
87434 .maxtype = IFLA_GRE_MAX,
87435 .policy = ip6gre_policy,
87436diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
87437index 155eccf..851fdae 100644
87438--- a/net/ipv6/ip6_output.c
87439+++ b/net/ipv6/ip6_output.c
87440@@ -1147,7 +1147,7 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to,
87441 if (WARN_ON(np->cork.opt))
87442 return -EINVAL;
87443
87444- np->cork.opt = kmalloc(opt->tot_len, sk->sk_allocation);
87445+ np->cork.opt = kzalloc(opt->tot_len, sk->sk_allocation);
87446 if (unlikely(np->cork.opt == NULL))
87447 return -ENOBUFS;
87448
87449diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
87450index fff83cb..82d49dd 100644
87451--- a/net/ipv6/ip6_tunnel.c
87452+++ b/net/ipv6/ip6_tunnel.c
87453@@ -87,7 +87,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
87454
87455 static int ip6_tnl_dev_init(struct net_device *dev);
87456 static void ip6_tnl_dev_setup(struct net_device *dev);
87457-static struct rtnl_link_ops ip6_link_ops __read_mostly;
87458+static struct rtnl_link_ops ip6_link_ops;
87459
87460 static int ip6_tnl_net_id __read_mostly;
87461 struct ip6_tnl_net {
87462@@ -1684,7 +1684,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
87463 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
87464 };
87465
87466-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
87467+static struct rtnl_link_ops ip6_link_ops = {
87468 .kind = "ip6tnl",
87469 .maxtype = IFLA_IPTUN_MAX,
87470 .policy = ip6_tnl_policy,
87471diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
87472index d1e2e8e..51c19ae 100644
87473--- a/net/ipv6/ipv6_sockglue.c
87474+++ b/net/ipv6/ipv6_sockglue.c
87475@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
87476 if (sk->sk_type != SOCK_STREAM)
87477 return -ENOPROTOOPT;
87478
87479- msg.msg_control = optval;
87480+ msg.msg_control = (void __force_kernel *)optval;
87481 msg.msg_controllen = len;
87482 msg.msg_flags = flags;
87483
87484diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
87485index 341b54a..591e8ed 100644
87486--- a/net/ipv6/netfilter/ip6_tables.c
87487+++ b/net/ipv6/netfilter/ip6_tables.c
87488@@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
87489 #endif
87490
87491 static int get_info(struct net *net, void __user *user,
87492- const int *len, int compat)
87493+ int len, int compat)
87494 {
87495 char name[XT_TABLE_MAXNAMELEN];
87496 struct xt_table *t;
87497 int ret;
87498
87499- if (*len != sizeof(struct ip6t_getinfo)) {
87500- duprintf("length %u != %zu\n", *len,
87501+ if (len != sizeof(struct ip6t_getinfo)) {
87502+ duprintf("length %u != %zu\n", len,
87503 sizeof(struct ip6t_getinfo));
87504 return -EINVAL;
87505 }
87506@@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
87507 info.size = private->size;
87508 strcpy(info.name, name);
87509
87510- if (copy_to_user(user, &info, *len) != 0)
87511+ if (copy_to_user(user, &info, len) != 0)
87512 ret = -EFAULT;
87513 else
87514 ret = 0;
87515@@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87516
87517 switch (cmd) {
87518 case IP6T_SO_GET_INFO:
87519- ret = get_info(sock_net(sk), user, len, 1);
87520+ ret = get_info(sock_net(sk), user, *len, 1);
87521 break;
87522 case IP6T_SO_GET_ENTRIES:
87523 ret = compat_get_entries(sock_net(sk), user, len);
87524@@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87525
87526 switch (cmd) {
87527 case IP6T_SO_GET_INFO:
87528- ret = get_info(sock_net(sk), user, len, 0);
87529+ ret = get_info(sock_net(sk), user, *len, 0);
87530 break;
87531
87532 case IP6T_SO_GET_ENTRIES:
87533diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
87534index 6700069..1e50f42 100644
87535--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
87536+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
87537@@ -89,12 +89,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
87538
87539 static int nf_ct_frag6_sysctl_register(struct net *net)
87540 {
87541- struct ctl_table *table;
87542+ ctl_table_no_const *table = NULL;
87543 struct ctl_table_header *hdr;
87544
87545- table = nf_ct_frag6_sysctl_table;
87546 if (!net_eq(net, &init_net)) {
87547- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
87548+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
87549 GFP_KERNEL);
87550 if (table == NULL)
87551 goto err_alloc;
87552@@ -102,9 +101,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
87553 table[0].data = &net->nf_frag.frags.timeout;
87554 table[1].data = &net->nf_frag.frags.low_thresh;
87555 table[2].data = &net->nf_frag.frags.high_thresh;
87556- }
87557-
87558- hdr = register_net_sysctl(net, "net/netfilter", table);
87559+ hdr = register_net_sysctl(net, "net/netfilter", table);
87560+ } else
87561+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
87562 if (hdr == NULL)
87563 goto err_reg;
87564
87565@@ -112,8 +111,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
87566 return 0;
87567
87568 err_reg:
87569- if (!net_eq(net, &init_net))
87570- kfree(table);
87571+ kfree(table);
87572 err_alloc:
87573 return -ENOMEM;
87574 }
87575diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
87576index 330b5e7..796fbf1 100644
87577--- a/net/ipv6/raw.c
87578+++ b/net/ipv6/raw.c
87579@@ -378,7 +378,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
87580 {
87581 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
87582 skb_checksum_complete(skb)) {
87583- atomic_inc(&sk->sk_drops);
87584+ atomic_inc_unchecked(&sk->sk_drops);
87585 kfree_skb(skb);
87586 return NET_RX_DROP;
87587 }
87588@@ -406,7 +406,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
87589 struct raw6_sock *rp = raw6_sk(sk);
87590
87591 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
87592- atomic_inc(&sk->sk_drops);
87593+ atomic_inc_unchecked(&sk->sk_drops);
87594 kfree_skb(skb);
87595 return NET_RX_DROP;
87596 }
87597@@ -430,7 +430,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
87598
87599 if (inet->hdrincl) {
87600 if (skb_checksum_complete(skb)) {
87601- atomic_inc(&sk->sk_drops);
87602+ atomic_inc_unchecked(&sk->sk_drops);
87603 kfree_skb(skb);
87604 return NET_RX_DROP;
87605 }
87606@@ -603,7 +603,7 @@ out:
87607 return err;
87608 }
87609
87610-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
87611+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
87612 struct flowi6 *fl6, struct dst_entry **dstp,
87613 unsigned int flags)
87614 {
87615@@ -915,12 +915,15 @@ do_confirm:
87616 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
87617 char __user *optval, int optlen)
87618 {
87619+ struct icmp6_filter filter;
87620+
87621 switch (optname) {
87622 case ICMPV6_FILTER:
87623 if (optlen > sizeof(struct icmp6_filter))
87624 optlen = sizeof(struct icmp6_filter);
87625- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
87626+ if (copy_from_user(&filter, optval, optlen))
87627 return -EFAULT;
87628+ raw6_sk(sk)->filter = filter;
87629 return 0;
87630 default:
87631 return -ENOPROTOOPT;
87632@@ -933,6 +936,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
87633 char __user *optval, int __user *optlen)
87634 {
87635 int len;
87636+ struct icmp6_filter filter;
87637
87638 switch (optname) {
87639 case ICMPV6_FILTER:
87640@@ -944,7 +948,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
87641 len = sizeof(struct icmp6_filter);
87642 if (put_user(len, optlen))
87643 return -EFAULT;
87644- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
87645+ filter = raw6_sk(sk)->filter;
87646+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
87647 return -EFAULT;
87648 return 0;
87649 default:
87650@@ -1252,7 +1257,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
87651 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
87652 0,
87653 sock_i_ino(sp),
87654- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
87655+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
87656 }
87657
87658 static int raw6_seq_show(struct seq_file *seq, void *v)
87659diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
87660index 0ba10e5..c14a4f6 100644
87661--- a/net/ipv6/reassembly.c
87662+++ b/net/ipv6/reassembly.c
87663@@ -602,12 +602,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
87664
87665 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
87666 {
87667- struct ctl_table *table;
87668+ ctl_table_no_const *table = NULL;
87669 struct ctl_table_header *hdr;
87670
87671- table = ip6_frags_ns_ctl_table;
87672 if (!net_eq(net, &init_net)) {
87673- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
87674+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
87675 if (table == NULL)
87676 goto err_alloc;
87677
87678@@ -618,9 +617,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
87679 /* Don't export sysctls to unprivileged users */
87680 if (net->user_ns != &init_user_ns)
87681 table[0].procname = NULL;
87682- }
87683+ hdr = register_net_sysctl(net, "net/ipv6", table);
87684+ } else
87685+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
87686
87687- hdr = register_net_sysctl(net, "net/ipv6", table);
87688 if (hdr == NULL)
87689 goto err_reg;
87690
87691@@ -628,8 +628,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
87692 return 0;
87693
87694 err_reg:
87695- if (!net_eq(net, &init_net))
87696- kfree(table);
87697+ kfree(table);
87698 err_alloc:
87699 return -ENOMEM;
87700 }
87701diff --git a/net/ipv6/route.c b/net/ipv6/route.c
87702index e5fe004..9fe3e8e 100644
87703--- a/net/ipv6/route.c
87704+++ b/net/ipv6/route.c
87705@@ -2881,7 +2881,7 @@ ctl_table ipv6_route_table_template[] = {
87706
87707 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
87708 {
87709- struct ctl_table *table;
87710+ ctl_table_no_const *table;
87711
87712 table = kmemdup(ipv6_route_table_template,
87713 sizeof(ipv6_route_table_template),
87714diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
87715index 02f96dc..4a5a6e5 100644
87716--- a/net/ipv6/sit.c
87717+++ b/net/ipv6/sit.c
87718@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
87719 static void ipip6_dev_free(struct net_device *dev);
87720 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
87721 __be32 *v4dst);
87722-static struct rtnl_link_ops sit_link_ops __read_mostly;
87723+static struct rtnl_link_ops sit_link_ops;
87724
87725 static int sit_net_id __read_mostly;
87726 struct sit_net {
87727@@ -1486,7 +1486,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
87728 #endif
87729 };
87730
87731-static struct rtnl_link_ops sit_link_ops __read_mostly = {
87732+static struct rtnl_link_ops sit_link_ops = {
87733 .kind = "sit",
87734 .maxtype = IFLA_IPTUN_MAX,
87735 .policy = ipip6_policy,
87736diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
87737index e85c48b..b8268d3 100644
87738--- a/net/ipv6/sysctl_net_ipv6.c
87739+++ b/net/ipv6/sysctl_net_ipv6.c
87740@@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
87741
87742 static int __net_init ipv6_sysctl_net_init(struct net *net)
87743 {
87744- struct ctl_table *ipv6_table;
87745+ ctl_table_no_const *ipv6_table;
87746 struct ctl_table *ipv6_route_table;
87747 struct ctl_table *ipv6_icmp_table;
87748 int err;
87749diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
87750index 0fce928..c52a518 100644
87751--- a/net/ipv6/tcp_ipv6.c
87752+++ b/net/ipv6/tcp_ipv6.c
87753@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
87754 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
87755 }
87756
87757+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87758+extern int grsec_enable_blackhole;
87759+#endif
87760+
87761 static void tcp_v6_hash(struct sock *sk)
87762 {
87763 if (sk->sk_state != TCP_CLOSE) {
87764@@ -1446,6 +1450,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
87765 return 0;
87766
87767 reset:
87768+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87769+ if (!grsec_enable_blackhole)
87770+#endif
87771 tcp_v6_send_reset(sk, skb);
87772 discard:
87773 if (opt_skb)
87774@@ -1527,12 +1534,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
87775 TCP_SKB_CB(skb)->sacked = 0;
87776
87777 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
87778- if (!sk)
87779+ if (!sk) {
87780+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87781+ ret = 1;
87782+#endif
87783 goto no_tcp_socket;
87784+ }
87785
87786 process:
87787- if (sk->sk_state == TCP_TIME_WAIT)
87788+ if (sk->sk_state == TCP_TIME_WAIT) {
87789+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87790+ ret = 2;
87791+#endif
87792 goto do_time_wait;
87793+ }
87794
87795 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
87796 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
87797@@ -1581,6 +1596,10 @@ no_tcp_socket:
87798 bad_packet:
87799 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
87800 } else {
87801+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87802+ if (!grsec_enable_blackhole || (ret == 1 &&
87803+ (skb->dev->flags & IFF_LOOPBACK)))
87804+#endif
87805 tcp_v6_send_reset(NULL, skb);
87806 }
87807
87808diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
87809index 27f0f8e..949e7ee 100644
87810--- a/net/ipv6/udp.c
87811+++ b/net/ipv6/udp.c
87812@@ -52,6 +52,10 @@
87813 #include <trace/events/skb.h>
87814 #include "udp_impl.h"
87815
87816+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87817+extern int grsec_enable_blackhole;
87818+#endif
87819+
87820 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
87821 {
87822 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
87823@@ -419,7 +423,7 @@ try_again:
87824 if (unlikely(err)) {
87825 trace_kfree_skb(skb, udpv6_recvmsg);
87826 if (!peeked) {
87827- atomic_inc(&sk->sk_drops);
87828+ atomic_inc_unchecked(&sk->sk_drops);
87829 if (is_udp4)
87830 UDP_INC_STATS_USER(sock_net(sk),
87831 UDP_MIB_INERRORS,
87832@@ -657,7 +661,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
87833 return rc;
87834 drop:
87835 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
87836- atomic_inc(&sk->sk_drops);
87837+ atomic_inc_unchecked(&sk->sk_drops);
87838 kfree_skb(skb);
87839 return -1;
87840 }
87841@@ -715,7 +719,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
87842 if (likely(skb1 == NULL))
87843 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
87844 if (!skb1) {
87845- atomic_inc(&sk->sk_drops);
87846+ atomic_inc_unchecked(&sk->sk_drops);
87847 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
87848 IS_UDPLITE(sk));
87849 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
87850@@ -852,6 +856,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
87851 goto discard;
87852
87853 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
87854+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87855+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
87856+#endif
87857 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
87858
87859 kfree_skb(skb);
87860@@ -1377,7 +1384,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
87861 0,
87862 sock_i_ino(sp),
87863 atomic_read(&sp->sk_refcnt), sp,
87864- atomic_read(&sp->sk_drops));
87865+ atomic_read_unchecked(&sp->sk_drops));
87866 }
87867
87868 int udp6_seq_show(struct seq_file *seq, void *v)
87869diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
87870index 23ed03d..465a71d 100644
87871--- a/net/ipv6/xfrm6_policy.c
87872+++ b/net/ipv6/xfrm6_policy.c
87873@@ -324,19 +324,19 @@ static struct ctl_table xfrm6_policy_table[] = {
87874
87875 static int __net_init xfrm6_net_init(struct net *net)
87876 {
87877- struct ctl_table *table;
87878+ ctl_table_no_const *table = NULL;
87879 struct ctl_table_header *hdr;
87880
87881- table = xfrm6_policy_table;
87882 if (!net_eq(net, &init_net)) {
87883- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
87884+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
87885 if (!table)
87886 goto err_alloc;
87887
87888 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
87889- }
87890+ hdr = register_net_sysctl(net, "net/ipv6", table);
87891+ } else
87892+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
87893
87894- hdr = register_net_sysctl(net, "net/ipv6", table);
87895 if (!hdr)
87896 goto err_reg;
87897
87898@@ -344,8 +344,7 @@ static int __net_init xfrm6_net_init(struct net *net)
87899 return 0;
87900
87901 err_reg:
87902- if (!net_eq(net, &init_net))
87903- kfree(table);
87904+ kfree(table);
87905 err_alloc:
87906 return -ENOMEM;
87907 }
87908diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
87909index 362ba47..66196f4 100644
87910--- a/net/irda/ircomm/ircomm_tty.c
87911+++ b/net/irda/ircomm/ircomm_tty.c
87912@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
87913 add_wait_queue(&port->open_wait, &wait);
87914
87915 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
87916- __FILE__, __LINE__, tty->driver->name, port->count);
87917+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
87918
87919 spin_lock_irqsave(&port->lock, flags);
87920 if (!tty_hung_up_p(filp))
87921- port->count--;
87922+ atomic_dec(&port->count);
87923 port->blocked_open++;
87924 spin_unlock_irqrestore(&port->lock, flags);
87925
87926@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
87927 }
87928
87929 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
87930- __FILE__, __LINE__, tty->driver->name, port->count);
87931+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
87932
87933 schedule();
87934 }
87935@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
87936
87937 spin_lock_irqsave(&port->lock, flags);
87938 if (!tty_hung_up_p(filp))
87939- port->count++;
87940+ atomic_inc(&port->count);
87941 port->blocked_open--;
87942 spin_unlock_irqrestore(&port->lock, flags);
87943
87944 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
87945- __FILE__, __LINE__, tty->driver->name, port->count);
87946+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
87947
87948 if (!retval)
87949 port->flags |= ASYNC_NORMAL_ACTIVE;
87950@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
87951
87952 /* ++ is not atomic, so this should be protected - Jean II */
87953 spin_lock_irqsave(&self->port.lock, flags);
87954- self->port.count++;
87955+ atomic_inc(&self->port.count);
87956 spin_unlock_irqrestore(&self->port.lock, flags);
87957 tty_port_tty_set(&self->port, tty);
87958
87959 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
87960- self->line, self->port.count);
87961+ self->line, atomic_read(&self->port.count));
87962
87963 /* Not really used by us, but lets do it anyway */
87964 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
87965@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
87966 tty_kref_put(port->tty);
87967 }
87968 port->tty = NULL;
87969- port->count = 0;
87970+ atomic_set(&port->count, 0);
87971 spin_unlock_irqrestore(&port->lock, flags);
87972
87973 wake_up_interruptible(&port->open_wait);
87974@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
87975 seq_putc(m, '\n');
87976
87977 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
87978- seq_printf(m, "Open count: %d\n", self->port.count);
87979+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
87980 seq_printf(m, "Max data size: %d\n", self->max_data_size);
87981 seq_printf(m, "Max header size: %d\n", self->max_header_size);
87982
87983diff --git a/net/irda/irlap_frame.c b/net/irda/irlap_frame.c
87984index 8c00416..9ea0c93 100644
87985--- a/net/irda/irlap_frame.c
87986+++ b/net/irda/irlap_frame.c
87987@@ -544,7 +544,7 @@ static void irlap_recv_discovery_xid_cmd(struct irlap_cb *self,
87988 /*
87989 * We now have some discovery info to deliver!
87990 */
87991- discovery = kmalloc(sizeof(discovery_t), GFP_ATOMIC);
87992+ discovery = kzalloc(sizeof(discovery_t), GFP_ATOMIC);
87993 if (!discovery) {
87994 IRDA_WARNING("%s: unable to malloc!\n", __func__);
87995 return;
87996diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
87997index 206ce6d..cfb27cd 100644
87998--- a/net/iucv/af_iucv.c
87999+++ b/net/iucv/af_iucv.c
88000@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
88001
88002 write_lock_bh(&iucv_sk_list.lock);
88003
88004- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
88005+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
88006 while (__iucv_get_sock_by_name(name)) {
88007 sprintf(name, "%08x",
88008- atomic_inc_return(&iucv_sk_list.autobind_name));
88009+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
88010 }
88011
88012 write_unlock_bh(&iucv_sk_list.lock);
88013diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
88014index 4fe76ff..426a904 100644
88015--- a/net/iucv/iucv.c
88016+++ b/net/iucv/iucv.c
88017@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
88018 return NOTIFY_OK;
88019 }
88020
88021-static struct notifier_block __refdata iucv_cpu_notifier = {
88022+static struct notifier_block iucv_cpu_notifier = {
88023 .notifier_call = iucv_cpu_notify,
88024 };
88025
88026diff --git a/net/key/af_key.c b/net/key/af_key.c
88027index 5b1e5af..2358147 100644
88028--- a/net/key/af_key.c
88029+++ b/net/key/af_key.c
88030@@ -3041,10 +3041,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
88031 static u32 get_acqseq(void)
88032 {
88033 u32 res;
88034- static atomic_t acqseq;
88035+ static atomic_unchecked_t acqseq;
88036
88037 do {
88038- res = atomic_inc_return(&acqseq);
88039+ res = atomic_inc_return_unchecked(&acqseq);
88040 } while (!res);
88041 return res;
88042 }
88043diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
88044index 843d8c4..cb04fa1 100644
88045--- a/net/mac80211/cfg.c
88046+++ b/net/mac80211/cfg.c
88047@@ -799,7 +799,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
88048 ret = ieee80211_vif_use_channel(sdata, chandef,
88049 IEEE80211_CHANCTX_EXCLUSIVE);
88050 }
88051- } else if (local->open_count == local->monitors) {
88052+ } else if (local_read(&local->open_count) == local->monitors) {
88053 local->_oper_channel = chandef->chan;
88054 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
88055 ieee80211_hw_config(local, 0);
88056@@ -2834,7 +2834,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
88057 else
88058 local->probe_req_reg--;
88059
88060- if (!local->open_count)
88061+ if (!local_read(&local->open_count))
88062 break;
88063
88064 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
88065@@ -3297,8 +3297,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
88066 if (chanctx_conf) {
88067 *chandef = chanctx_conf->def;
88068 ret = 0;
88069- } else if (local->open_count > 0 &&
88070- local->open_count == local->monitors &&
88071+ } else if (local_read(&local->open_count) > 0 &&
88072+ local_read(&local->open_count) == local->monitors &&
88073 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
88074 if (local->use_chanctx)
88075 *chandef = local->monitor_chandef;
88076diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
88077index 5672533..6738c93 100644
88078--- a/net/mac80211/ieee80211_i.h
88079+++ b/net/mac80211/ieee80211_i.h
88080@@ -28,6 +28,7 @@
88081 #include <net/ieee80211_radiotap.h>
88082 #include <net/cfg80211.h>
88083 #include <net/mac80211.h>
88084+#include <asm/local.h>
88085 #include "key.h"
88086 #include "sta_info.h"
88087 #include "debug.h"
88088@@ -897,7 +898,7 @@ struct ieee80211_local {
88089 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
88090 spinlock_t queue_stop_reason_lock;
88091
88092- int open_count;
88093+ local_t open_count;
88094 int monitors, cooked_mntrs;
88095 /* number of interfaces with corresponding FIF_ flags */
88096 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
88097diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
88098index 9cbebc2..14879bb 100644
88099--- a/net/mac80211/iface.c
88100+++ b/net/mac80211/iface.c
88101@@ -495,7 +495,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88102 break;
88103 }
88104
88105- if (local->open_count == 0) {
88106+ if (local_read(&local->open_count) == 0) {
88107 res = drv_start(local);
88108 if (res)
88109 goto err_del_bss;
88110@@ -540,7 +540,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88111 break;
88112 }
88113
88114- if (local->monitors == 0 && local->open_count == 0) {
88115+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
88116 res = ieee80211_add_virtual_monitor(local);
88117 if (res)
88118 goto err_stop;
88119@@ -649,7 +649,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88120 atomic_inc(&local->iff_promiscs);
88121
88122 if (coming_up)
88123- local->open_count++;
88124+ local_inc(&local->open_count);
88125
88126 if (hw_reconf_flags)
88127 ieee80211_hw_config(local, hw_reconf_flags);
88128@@ -663,7 +663,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88129 err_del_interface:
88130 drv_remove_interface(local, sdata);
88131 err_stop:
88132- if (!local->open_count)
88133+ if (!local_read(&local->open_count))
88134 drv_stop(local);
88135 err_del_bss:
88136 sdata->bss = NULL;
88137@@ -806,7 +806,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
88138 }
88139
88140 if (going_down)
88141- local->open_count--;
88142+ local_dec(&local->open_count);
88143
88144 switch (sdata->vif.type) {
88145 case NL80211_IFTYPE_AP_VLAN:
88146@@ -871,7 +871,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
88147
88148 ieee80211_recalc_ps(local, -1);
88149
88150- if (local->open_count == 0) {
88151+ if (local_read(&local->open_count) == 0) {
88152 if (local->ops->napi_poll)
88153 napi_disable(&local->napi);
88154 ieee80211_clear_tx_pending(local);
88155@@ -897,7 +897,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
88156 }
88157 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
88158
88159- if (local->monitors == local->open_count && local->monitors > 0)
88160+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
88161 ieee80211_add_virtual_monitor(local);
88162 }
88163
88164diff --git a/net/mac80211/main.c b/net/mac80211/main.c
88165index 1a8591b..ef5db54 100644
88166--- a/net/mac80211/main.c
88167+++ b/net/mac80211/main.c
88168@@ -180,7 +180,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
88169 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
88170 IEEE80211_CONF_CHANGE_POWER);
88171
88172- if (changed && local->open_count) {
88173+ if (changed && local_read(&local->open_count)) {
88174 ret = drv_config(local, changed);
88175 /*
88176 * Goal:
88177diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
88178index 835584c..be46e67 100644
88179--- a/net/mac80211/pm.c
88180+++ b/net/mac80211/pm.c
88181@@ -33,7 +33,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
88182 struct sta_info *sta;
88183 struct ieee80211_chanctx *ctx;
88184
88185- if (!local->open_count)
88186+ if (!local_read(&local->open_count))
88187 goto suspend;
88188
88189 ieee80211_scan_cancel(local);
88190@@ -75,7 +75,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
88191 cancel_work_sync(&local->dynamic_ps_enable_work);
88192 del_timer_sync(&local->dynamic_ps_timer);
88193
88194- local->wowlan = wowlan && local->open_count;
88195+ local->wowlan = wowlan && local_read(&local->open_count);
88196 if (local->wowlan) {
88197 int err = drv_suspend(local, wowlan);
88198 if (err < 0) {
88199@@ -214,7 +214,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
88200 mutex_unlock(&local->chanctx_mtx);
88201
88202 /* stop hardware - this must stop RX */
88203- if (local->open_count)
88204+ if (local_read(&local->open_count))
88205 ieee80211_stop_device(local);
88206
88207 suspend:
88208diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
88209index dd88381..eef4dd6 100644
88210--- a/net/mac80211/rate.c
88211+++ b/net/mac80211/rate.c
88212@@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
88213
88214 ASSERT_RTNL();
88215
88216- if (local->open_count)
88217+ if (local_read(&local->open_count))
88218 return -EBUSY;
88219
88220 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
88221diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
88222index c97a065..ff61928 100644
88223--- a/net/mac80211/rc80211_pid_debugfs.c
88224+++ b/net/mac80211/rc80211_pid_debugfs.c
88225@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
88226
88227 spin_unlock_irqrestore(&events->lock, status);
88228
88229- if (copy_to_user(buf, pb, p))
88230+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
88231 return -EFAULT;
88232
88233 return p;
88234diff --git a/net/mac80211/util.c b/net/mac80211/util.c
88235index 0f38f43..e53d4a8 100644
88236--- a/net/mac80211/util.c
88237+++ b/net/mac80211/util.c
88238@@ -1388,7 +1388,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
88239 }
88240 #endif
88241 /* everything else happens only if HW was up & running */
88242- if (!local->open_count)
88243+ if (!local_read(&local->open_count))
88244 goto wake_up;
88245
88246 /*
88247diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
88248index 56d22ca..87c778f 100644
88249--- a/net/netfilter/Kconfig
88250+++ b/net/netfilter/Kconfig
88251@@ -958,6 +958,16 @@ config NETFILTER_XT_MATCH_ESP
88252
88253 To compile it as a module, choose M here. If unsure, say N.
88254
88255+config NETFILTER_XT_MATCH_GRADM
88256+ tristate '"gradm" match support'
88257+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
88258+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
88259+ ---help---
88260+ The gradm match allows to match on grsecurity RBAC being enabled.
88261+ It is useful when iptables rules are applied early on bootup to
88262+ prevent connections to the machine (except from a trusted host)
88263+ while the RBAC system is disabled.
88264+
88265 config NETFILTER_XT_MATCH_HASHLIMIT
88266 tristate '"hashlimit" match support'
88267 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
88268diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
88269index a1abf87..dbcb7ee 100644
88270--- a/net/netfilter/Makefile
88271+++ b/net/netfilter/Makefile
88272@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
88273 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
88274 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
88275 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
88276+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
88277 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
88278 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
88279 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
88280diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
88281index 1ba9dbc..e39f4ca 100644
88282--- a/net/netfilter/ipset/ip_set_core.c
88283+++ b/net/netfilter/ipset/ip_set_core.c
88284@@ -1801,7 +1801,7 @@ done:
88285 return ret;
88286 }
88287
88288-static struct nf_sockopt_ops so_set __read_mostly = {
88289+static struct nf_sockopt_ops so_set = {
88290 .pf = PF_INET,
88291 .get_optmin = SO_IP_SET,
88292 .get_optmax = SO_IP_SET + 1,
88293diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
88294index 704e514..d644cc2 100644
88295--- a/net/netfilter/ipvs/ip_vs_conn.c
88296+++ b/net/netfilter/ipvs/ip_vs_conn.c
88297@@ -551,7 +551,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
88298 /* Increase the refcnt counter of the dest */
88299 atomic_inc(&dest->refcnt);
88300
88301- conn_flags = atomic_read(&dest->conn_flags);
88302+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
88303 if (cp->protocol != IPPROTO_UDP)
88304 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
88305 flags = cp->flags;
88306@@ -895,7 +895,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
88307 atomic_set(&cp->refcnt, 1);
88308
88309 atomic_set(&cp->n_control, 0);
88310- atomic_set(&cp->in_pkts, 0);
88311+ atomic_set_unchecked(&cp->in_pkts, 0);
88312
88313 atomic_inc(&ipvs->conn_count);
88314 if (flags & IP_VS_CONN_F_NO_CPORT)
88315@@ -1174,7 +1174,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
88316
88317 /* Don't drop the entry if its number of incoming packets is not
88318 located in [0, 8] */
88319- i = atomic_read(&cp->in_pkts);
88320+ i = atomic_read_unchecked(&cp->in_pkts);
88321 if (i > 8 || i < 0) return 0;
88322
88323 if (!todrop_rate[i]) return 0;
88324diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
88325index 61f49d2..6c8c5bc 100644
88326--- a/net/netfilter/ipvs/ip_vs_core.c
88327+++ b/net/netfilter/ipvs/ip_vs_core.c
88328@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
88329 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
88330 /* do not touch skb anymore */
88331
88332- atomic_inc(&cp->in_pkts);
88333+ atomic_inc_unchecked(&cp->in_pkts);
88334 ip_vs_conn_put(cp);
88335 return ret;
88336 }
88337@@ -1689,7 +1689,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
88338 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
88339 pkts = sysctl_sync_threshold(ipvs);
88340 else
88341- pkts = atomic_add_return(1, &cp->in_pkts);
88342+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
88343
88344 if (ipvs->sync_state & IP_VS_STATE_MASTER)
88345 ip_vs_sync_conn(net, cp, pkts);
88346diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
88347index 9e2d1cc..7f8f569 100644
88348--- a/net/netfilter/ipvs/ip_vs_ctl.c
88349+++ b/net/netfilter/ipvs/ip_vs_ctl.c
88350@@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
88351 ip_vs_rs_hash(ipvs, dest);
88352 write_unlock_bh(&ipvs->rs_lock);
88353 }
88354- atomic_set(&dest->conn_flags, conn_flags);
88355+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
88356
88357 /* bind the service */
88358 if (!dest->svc) {
88359@@ -1688,7 +1688,7 @@ proc_do_sync_ports(ctl_table *table, int write,
88360 * align with netns init in ip_vs_control_net_init()
88361 */
88362
88363-static struct ctl_table vs_vars[] = {
88364+static ctl_table_no_const vs_vars[] __read_only = {
88365 {
88366 .procname = "amemthresh",
88367 .maxlen = sizeof(int),
88368@@ -2087,7 +2087,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
88369 " %-7s %-6d %-10d %-10d\n",
88370 &dest->addr.in6,
88371 ntohs(dest->port),
88372- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
88373+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
88374 atomic_read(&dest->weight),
88375 atomic_read(&dest->activeconns),
88376 atomic_read(&dest->inactconns));
88377@@ -2098,7 +2098,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
88378 "%-7s %-6d %-10d %-10d\n",
88379 ntohl(dest->addr.ip),
88380 ntohs(dest->port),
88381- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
88382+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
88383 atomic_read(&dest->weight),
88384 atomic_read(&dest->activeconns),
88385 atomic_read(&dest->inactconns));
88386@@ -2568,7 +2568,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
88387
88388 entry.addr = dest->addr.ip;
88389 entry.port = dest->port;
88390- entry.conn_flags = atomic_read(&dest->conn_flags);
88391+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
88392 entry.weight = atomic_read(&dest->weight);
88393 entry.u_threshold = dest->u_threshold;
88394 entry.l_threshold = dest->l_threshold;
88395@@ -3104,7 +3104,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
88396 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
88397 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
88398 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
88399- (atomic_read(&dest->conn_flags) &
88400+ (atomic_read_unchecked(&dest->conn_flags) &
88401 IP_VS_CONN_F_FWD_MASK)) ||
88402 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
88403 atomic_read(&dest->weight)) ||
88404@@ -3694,7 +3694,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
88405 {
88406 int idx;
88407 struct netns_ipvs *ipvs = net_ipvs(net);
88408- struct ctl_table *tbl;
88409+ ctl_table_no_const *tbl;
88410
88411 atomic_set(&ipvs->dropentry, 0);
88412 spin_lock_init(&ipvs->dropentry_lock);
88413diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
88414index fdd89b9..bd96aa9 100644
88415--- a/net/netfilter/ipvs/ip_vs_lblc.c
88416+++ b/net/netfilter/ipvs/ip_vs_lblc.c
88417@@ -115,7 +115,7 @@ struct ip_vs_lblc_table {
88418 * IPVS LBLC sysctl table
88419 */
88420 #ifdef CONFIG_SYSCTL
88421-static ctl_table vs_vars_table[] = {
88422+static ctl_table_no_const vs_vars_table[] __read_only = {
88423 {
88424 .procname = "lblc_expiration",
88425 .data = NULL,
88426diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
88427index c03b6a3..8ce3681 100644
88428--- a/net/netfilter/ipvs/ip_vs_lblcr.c
88429+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
88430@@ -288,7 +288,7 @@ struct ip_vs_lblcr_table {
88431 * IPVS LBLCR sysctl table
88432 */
88433
88434-static ctl_table vs_vars_table[] = {
88435+static ctl_table_no_const vs_vars_table[] __read_only = {
88436 {
88437 .procname = "lblcr_expiration",
88438 .data = NULL,
88439diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
88440index 44fd10c..2a163b3 100644
88441--- a/net/netfilter/ipvs/ip_vs_sync.c
88442+++ b/net/netfilter/ipvs/ip_vs_sync.c
88443@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
88444 cp = cp->control;
88445 if (cp) {
88446 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
88447- pkts = atomic_add_return(1, &cp->in_pkts);
88448+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
88449 else
88450 pkts = sysctl_sync_threshold(ipvs);
88451 ip_vs_sync_conn(net, cp->control, pkts);
88452@@ -758,7 +758,7 @@ control:
88453 if (!cp)
88454 return;
88455 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
88456- pkts = atomic_add_return(1, &cp->in_pkts);
88457+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
88458 else
88459 pkts = sysctl_sync_threshold(ipvs);
88460 goto sloop;
88461@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
88462
88463 if (opt)
88464 memcpy(&cp->in_seq, opt, sizeof(*opt));
88465- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
88466+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
88467 cp->state = state;
88468 cp->old_state = cp->state;
88469 /*
88470diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
88471index ee6b7a9..f9a89f6 100644
88472--- a/net/netfilter/ipvs/ip_vs_xmit.c
88473+++ b/net/netfilter/ipvs/ip_vs_xmit.c
88474@@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
88475 else
88476 rc = NF_ACCEPT;
88477 /* do not touch skb anymore */
88478- atomic_inc(&cp->in_pkts);
88479+ atomic_inc_unchecked(&cp->in_pkts);
88480 goto out;
88481 }
88482
88483@@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
88484 else
88485 rc = NF_ACCEPT;
88486 /* do not touch skb anymore */
88487- atomic_inc(&cp->in_pkts);
88488+ atomic_inc_unchecked(&cp->in_pkts);
88489 goto out;
88490 }
88491
88492diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
88493index 2d3030a..7ba1c0a 100644
88494--- a/net/netfilter/nf_conntrack_acct.c
88495+++ b/net/netfilter/nf_conntrack_acct.c
88496@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
88497 #ifdef CONFIG_SYSCTL
88498 static int nf_conntrack_acct_init_sysctl(struct net *net)
88499 {
88500- struct ctl_table *table;
88501+ ctl_table_no_const *table;
88502
88503 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
88504 GFP_KERNEL);
88505diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
88506index c8e001a..f842a8b 100644
88507--- a/net/netfilter/nf_conntrack_core.c
88508+++ b/net/netfilter/nf_conntrack_core.c
88509@@ -1594,6 +1594,10 @@ void nf_conntrack_init_end(void)
88510 #define DYING_NULLS_VAL ((1<<30)+1)
88511 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
88512
88513+#ifdef CONFIG_GRKERNSEC_HIDESYM
88514+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
88515+#endif
88516+
88517 int nf_conntrack_init_net(struct net *net)
88518 {
88519 int ret;
88520@@ -1608,7 +1612,11 @@ int nf_conntrack_init_net(struct net *net)
88521 goto err_stat;
88522 }
88523
88524+#ifdef CONFIG_GRKERNSEC_HIDESYM
88525+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
88526+#else
88527 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
88528+#endif
88529 if (!net->ct.slabname) {
88530 ret = -ENOMEM;
88531 goto err_slabname;
88532diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
88533index b5d2eb8..61ef19a 100644
88534--- a/net/netfilter/nf_conntrack_ecache.c
88535+++ b/net/netfilter/nf_conntrack_ecache.c
88536@@ -186,7 +186,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
88537 #ifdef CONFIG_SYSCTL
88538 static int nf_conntrack_event_init_sysctl(struct net *net)
88539 {
88540- struct ctl_table *table;
88541+ ctl_table_no_const *table;
88542
88543 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
88544 GFP_KERNEL);
88545diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
88546index 94b4b98..97cf0ad 100644
88547--- a/net/netfilter/nf_conntrack_helper.c
88548+++ b/net/netfilter/nf_conntrack_helper.c
88549@@ -56,7 +56,7 @@ static struct ctl_table helper_sysctl_table[] = {
88550
88551 static int nf_conntrack_helper_init_sysctl(struct net *net)
88552 {
88553- struct ctl_table *table;
88554+ ctl_table_no_const *table;
88555
88556 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
88557 GFP_KERNEL);
88558diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
88559index 58ab405..50eb8d3 100644
88560--- a/net/netfilter/nf_conntrack_proto.c
88561+++ b/net/netfilter/nf_conntrack_proto.c
88562@@ -51,7 +51,7 @@ nf_ct_register_sysctl(struct net *net,
88563
88564 static void
88565 nf_ct_unregister_sysctl(struct ctl_table_header **header,
88566- struct ctl_table **table,
88567+ ctl_table_no_const **table,
88568 unsigned int users)
88569 {
88570 if (users > 0)
88571diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
88572index fedee39..d62a93d 100644
88573--- a/net/netfilter/nf_conntrack_standalone.c
88574+++ b/net/netfilter/nf_conntrack_standalone.c
88575@@ -470,7 +470,7 @@ static ctl_table nf_ct_netfilter_table[] = {
88576
88577 static int nf_conntrack_standalone_init_sysctl(struct net *net)
88578 {
88579- struct ctl_table *table;
88580+ ctl_table_no_const *table;
88581
88582 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
88583 GFP_KERNEL);
88584diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
88585index 902fb0a..87f7fdb 100644
88586--- a/net/netfilter/nf_conntrack_timestamp.c
88587+++ b/net/netfilter/nf_conntrack_timestamp.c
88588@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
88589 #ifdef CONFIG_SYSCTL
88590 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
88591 {
88592- struct ctl_table *table;
88593+ ctl_table_no_const *table;
88594
88595 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
88596 GFP_KERNEL);
88597diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
88598index 9e31269..bc4c1b7 100644
88599--- a/net/netfilter/nf_log.c
88600+++ b/net/netfilter/nf_log.c
88601@@ -215,7 +215,7 @@ static const struct file_operations nflog_file_ops = {
88602
88603 #ifdef CONFIG_SYSCTL
88604 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
88605-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
88606+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
88607 static struct ctl_table_header *nf_log_dir_header;
88608
88609 static int nf_log_proc_dostring(ctl_table *table, int write,
88610@@ -246,14 +246,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
88611 rcu_assign_pointer(nf_loggers[tindex], logger);
88612 mutex_unlock(&nf_log_mutex);
88613 } else {
88614+ ctl_table_no_const nf_log_table = *table;
88615+
88616 mutex_lock(&nf_log_mutex);
88617 logger = rcu_dereference_protected(nf_loggers[tindex],
88618 lockdep_is_held(&nf_log_mutex));
88619 if (!logger)
88620- table->data = "NONE";
88621+ nf_log_table.data = "NONE";
88622 else
88623- table->data = logger->name;
88624- r = proc_dostring(table, write, buffer, lenp, ppos);
88625+ nf_log_table.data = logger->name;
88626+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
88627 mutex_unlock(&nf_log_mutex);
88628 }
88629
88630diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
88631index f042ae5..30ea486 100644
88632--- a/net/netfilter/nf_sockopt.c
88633+++ b/net/netfilter/nf_sockopt.c
88634@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
88635 }
88636 }
88637
88638- list_add(&reg->list, &nf_sockopts);
88639+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
88640 out:
88641 mutex_unlock(&nf_sockopt_mutex);
88642 return ret;
88643@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
88644 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
88645 {
88646 mutex_lock(&nf_sockopt_mutex);
88647- list_del(&reg->list);
88648+ pax_list_del((struct list_head *)&reg->list);
88649 mutex_unlock(&nf_sockopt_mutex);
88650 }
88651 EXPORT_SYMBOL(nf_unregister_sockopt);
88652diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
88653index f248db5..3778ad9 100644
88654--- a/net/netfilter/nfnetlink_log.c
88655+++ b/net/netfilter/nfnetlink_log.c
88656@@ -72,7 +72,7 @@ struct nfulnl_instance {
88657 };
88658
88659 static DEFINE_SPINLOCK(instances_lock);
88660-static atomic_t global_seq;
88661+static atomic_unchecked_t global_seq;
88662
88663 #define INSTANCE_BUCKETS 16
88664 static struct hlist_head instance_table[INSTANCE_BUCKETS];
88665@@ -536,7 +536,7 @@ __build_packet_message(struct nfulnl_instance *inst,
88666 /* global sequence number */
88667 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
88668 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
88669- htonl(atomic_inc_return(&global_seq))))
88670+ htonl(atomic_inc_return_unchecked(&global_seq))))
88671 goto nla_put_failure;
88672
88673 if (data_len) {
88674diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
88675new file mode 100644
88676index 0000000..c566332
88677--- /dev/null
88678+++ b/net/netfilter/xt_gradm.c
88679@@ -0,0 +1,51 @@
88680+/*
88681+ * gradm match for netfilter
88682