]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.9.6-201306182033.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.9.6-201306182033.patch
CommitLineData
f85fdfd1
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 4a40307..9ac699b 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 9600c36..0c156d7 100644
6686--- a/arch/powerpc/kernel/process.c
6687+++ b/arch/powerpc/kernel/process.c
6688@@ -871,8 +871,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@@ -1331,10 +1331,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@@ -1354,7 +1354,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@@ -1396,58 +1396,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 29857c6..bd31e27 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 96c4e85..284fded 100644
31367--- a/arch/x86/xen/smp.c
31368+++ b/arch/x86/xen/smp.c
31369@@ -230,11 +230,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@@ -304,7 +299,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@@ -314,8 +309,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@@ -360,13 +355,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@@ -642,7 +636,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..04e6d6a2 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 bb5939b..d9accb7 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 2ab65b4..acbd821 100644
35398--- a/drivers/gpu/drm/i915/intel_display.c
35399+++ b/drivers/gpu/drm/i915/intel_display.c
35400@@ -8742,13 +8742,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@@ -8756,18 +8756,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 fad6633..4ff94de 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/brocade/bna/bnad_debugfs.c b/drivers/net/ethernet/brocade/bna/bnad_debugfs.c
39639index 6e8bc9d..94d957d 100644
39640--- a/drivers/net/ethernet/brocade/bna/bnad_debugfs.c
39641+++ b/drivers/net/ethernet/brocade/bna/bnad_debugfs.c
39642@@ -244,7 +244,7 @@ bnad_debugfs_lseek(struct file *file, loff_t offset, int orig)
39643 file->f_pos += offset;
39644 break;
39645 case 2:
39646- file->f_pos = debug->buffer_len - offset;
39647+ file->f_pos = debug->buffer_len + offset;
39648 break;
39649 default:
39650 return -EINVAL;
39651diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39652index 8cffcdf..aadf043 100644
39653--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39654+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39655@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
39656 */
39657 struct l2t_skb_cb {
39658 arp_failure_handler_func arp_failure_handler;
39659-};
39660+} __no_const;
39661
39662 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
39663
39664diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
39665index 4c83003..2a2a5b9 100644
39666--- a/drivers/net/ethernet/dec/tulip/de4x5.c
39667+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
39668@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39669 for (i=0; i<ETH_ALEN; i++) {
39670 tmp.addr[i] = dev->dev_addr[i];
39671 }
39672- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39673+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39674 break;
39675
39676 case DE4X5_SET_HWADDR: /* Set the hardware address */
39677@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39678 spin_lock_irqsave(&lp->lock, flags);
39679 memcpy(&statbuf, &lp->pktStats, ioc->len);
39680 spin_unlock_irqrestore(&lp->lock, flags);
39681- if (copy_to_user(ioc->data, &statbuf, ioc->len))
39682+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
39683 return -EFAULT;
39684 break;
39685 }
39686diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
39687index 2886c9b..db71673 100644
39688--- a/drivers/net/ethernet/emulex/benet/be_main.c
39689+++ b/drivers/net/ethernet/emulex/benet/be_main.c
39690@@ -455,7 +455,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
39691
39692 if (wrapped)
39693 newacc += 65536;
39694- ACCESS_ONCE(*acc) = newacc;
39695+ ACCESS_ONCE_RW(*acc) = newacc;
39696 }
39697
39698 void be_parse_stats(struct be_adapter *adapter)
39699diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
39700index 7c361d1..57e3ff1 100644
39701--- a/drivers/net/ethernet/faraday/ftgmac100.c
39702+++ b/drivers/net/ethernet/faraday/ftgmac100.c
39703@@ -31,6 +31,8 @@
39704 #include <linux/netdevice.h>
39705 #include <linux/phy.h>
39706 #include <linux/platform_device.h>
39707+#include <linux/interrupt.h>
39708+#include <linux/irqreturn.h>
39709 #include <net/ip.h>
39710
39711 #include "ftgmac100.h"
39712diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
39713index b5ea8fb..bd25e9a 100644
39714--- a/drivers/net/ethernet/faraday/ftmac100.c
39715+++ b/drivers/net/ethernet/faraday/ftmac100.c
39716@@ -31,6 +31,8 @@
39717 #include <linux/module.h>
39718 #include <linux/netdevice.h>
39719 #include <linux/platform_device.h>
39720+#include <linux/interrupt.h>
39721+#include <linux/irqreturn.h>
39722
39723 #include "ftmac100.h"
39724
39725diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39726index 331987d..3be1135 100644
39727--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39728+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39729@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
39730 }
39731
39732 /* update the base incval used to calculate frequency adjustment */
39733- ACCESS_ONCE(adapter->base_incval) = incval;
39734+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
39735 smp_mb();
39736
39737 /* need lock to prevent incorrect read while modifying cyclecounter */
39738diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
39739index fbe5363..266b4e3 100644
39740--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
39741+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
39742@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
39743 struct __vxge_hw_fifo *fifo;
39744 struct vxge_hw_fifo_config *config;
39745 u32 txdl_size, txdl_per_memblock;
39746- struct vxge_hw_mempool_cbs fifo_mp_callback;
39747+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
39748+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
39749+ };
39750+
39751 struct __vxge_hw_virtualpath *vpath;
39752
39753 if ((vp == NULL) || (attr == NULL)) {
39754@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
39755 goto exit;
39756 }
39757
39758- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
39759-
39760 fifo->mempool =
39761 __vxge_hw_mempool_create(vpath->hldev,
39762 fifo->config->memblock_size,
39763diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
39764index 5c033f2..7bbb0d8 100644
39765--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
39766+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
39767@@ -1894,7 +1894,9 @@ int qlcnic_83xx_config_default_opmode(struct qlcnic_adapter *adapter)
39768 op_mode = QLCRDX(ahw, QLC_83XX_DRV_OP_MODE);
39769
39770 if (op_mode == QLC_83XX_DEFAULT_OPMODE) {
39771- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
39772+ pax_open_kernel();
39773+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
39774+ pax_close_kernel();
39775 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
39776 } else {
39777 return -EIO;
39778diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
39779index b0c3de9..fc5857e 100644
39780--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
39781+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
39782@@ -200,15 +200,21 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
39783 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
39784 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
39785 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
39786- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
39787+ pax_open_kernel();
39788+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
39789+ pax_close_kernel();
39790 } else if (priv_level == QLCNIC_PRIV_FUNC) {
39791 ahw->op_mode = QLCNIC_PRIV_FUNC;
39792 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
39793- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
39794+ pax_open_kernel();
39795+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
39796+ pax_close_kernel();
39797 } else if (priv_level == QLCNIC_MGMT_FUNC) {
39798 ahw->op_mode = QLCNIC_MGMT_FUNC;
39799 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
39800- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
39801+ pax_open_kernel();
39802+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
39803+ pax_close_kernel();
39804 } else {
39805 return -EIO;
39806 }
39807diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
39808index 15ba8c4..3f56838 100644
39809--- a/drivers/net/ethernet/realtek/r8169.c
39810+++ b/drivers/net/ethernet/realtek/r8169.c
39811@@ -740,22 +740,22 @@ struct rtl8169_private {
39812 struct mdio_ops {
39813 void (*write)(struct rtl8169_private *, int, int);
39814 int (*read)(struct rtl8169_private *, int);
39815- } mdio_ops;
39816+ } __no_const mdio_ops;
39817
39818 struct pll_power_ops {
39819 void (*down)(struct rtl8169_private *);
39820 void (*up)(struct rtl8169_private *);
39821- } pll_power_ops;
39822+ } __no_const pll_power_ops;
39823
39824 struct jumbo_ops {
39825 void (*enable)(struct rtl8169_private *);
39826 void (*disable)(struct rtl8169_private *);
39827- } jumbo_ops;
39828+ } __no_const jumbo_ops;
39829
39830 struct csi_ops {
39831 void (*write)(struct rtl8169_private *, int, int);
39832 u32 (*read)(struct rtl8169_private *, int);
39833- } csi_ops;
39834+ } __no_const csi_ops;
39835
39836 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
39837 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
39838diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
39839index 3f93624..cf01144 100644
39840--- a/drivers/net/ethernet/sfc/ptp.c
39841+++ b/drivers/net/ethernet/sfc/ptp.c
39842@@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
39843 (u32)((u64)ptp->start.dma_addr >> 32));
39844
39845 /* Clear flag that signals MC ready */
39846- ACCESS_ONCE(*start) = 0;
39847+ ACCESS_ONCE_RW(*start) = 0;
39848 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
39849 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
39850
39851diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39852index 50617c5..b13724c 100644
39853--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39854+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39855@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
39856
39857 writel(value, ioaddr + MMC_CNTRL);
39858
39859- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
39860- MMC_CNTRL, value);
39861+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
39862+// MMC_CNTRL, value);
39863 }
39864
39865 /* To mask all all interrupts.*/
39866diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
39867index e6fe0d8..2b7d752 100644
39868--- a/drivers/net/hyperv/hyperv_net.h
39869+++ b/drivers/net/hyperv/hyperv_net.h
39870@@ -101,7 +101,7 @@ struct rndis_device {
39871
39872 enum rndis_device_state state;
39873 bool link_state;
39874- atomic_t new_req_id;
39875+ atomic_unchecked_t new_req_id;
39876
39877 spinlock_t request_lock;
39878 struct list_head req_list;
39879diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
39880index 0775f0a..d4fb316 100644
39881--- a/drivers/net/hyperv/rndis_filter.c
39882+++ b/drivers/net/hyperv/rndis_filter.c
39883@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
39884 * template
39885 */
39886 set = &rndis_msg->msg.set_req;
39887- set->req_id = atomic_inc_return(&dev->new_req_id);
39888+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39889
39890 /* Add to the request list */
39891 spin_lock_irqsave(&dev->request_lock, flags);
39892@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
39893
39894 /* Setup the rndis set */
39895 halt = &request->request_msg.msg.halt_req;
39896- halt->req_id = atomic_inc_return(&dev->new_req_id);
39897+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39898
39899 /* Ignore return since this msg is optional. */
39900 rndis_filter_send_request(dev, request);
39901diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
39902index 8f1c256..a2991d1 100644
39903--- a/drivers/net/ieee802154/fakehard.c
39904+++ b/drivers/net/ieee802154/fakehard.c
39905@@ -385,7 +385,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
39906 phy->transmit_power = 0xbf;
39907
39908 dev->netdev_ops = &fake_ops;
39909- dev->ml_priv = &fake_mlme;
39910+ dev->ml_priv = (void *)&fake_mlme;
39911
39912 priv = netdev_priv(dev);
39913 priv->phy = phy;
39914diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
39915index 011062e..ada88e9 100644
39916--- a/drivers/net/macvlan.c
39917+++ b/drivers/net/macvlan.c
39918@@ -892,13 +892,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
39919 int macvlan_link_register(struct rtnl_link_ops *ops)
39920 {
39921 /* common fields */
39922- ops->priv_size = sizeof(struct macvlan_dev);
39923- ops->validate = macvlan_validate;
39924- ops->maxtype = IFLA_MACVLAN_MAX;
39925- ops->policy = macvlan_policy;
39926- ops->changelink = macvlan_changelink;
39927- ops->get_size = macvlan_get_size;
39928- ops->fill_info = macvlan_fill_info;
39929+ pax_open_kernel();
39930+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
39931+ *(void **)&ops->validate = macvlan_validate;
39932+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
39933+ *(const void **)&ops->policy = macvlan_policy;
39934+ *(void **)&ops->changelink = macvlan_changelink;
39935+ *(void **)&ops->get_size = macvlan_get_size;
39936+ *(void **)&ops->fill_info = macvlan_fill_info;
39937+ pax_close_kernel();
39938
39939 return rtnl_link_register(ops);
39940 };
39941@@ -954,7 +956,7 @@ static int macvlan_device_event(struct notifier_block *unused,
39942 return NOTIFY_DONE;
39943 }
39944
39945-static struct notifier_block macvlan_notifier_block __read_mostly = {
39946+static struct notifier_block macvlan_notifier_block = {
39947 .notifier_call = macvlan_device_event,
39948 };
39949
39950diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
39951index a449439..1e468fe 100644
39952--- a/drivers/net/macvtap.c
39953+++ b/drivers/net/macvtap.c
39954@@ -1090,7 +1090,7 @@ static int macvtap_device_event(struct notifier_block *unused,
39955 return NOTIFY_DONE;
39956 }
39957
39958-static struct notifier_block macvtap_notifier_block __read_mostly = {
39959+static struct notifier_block macvtap_notifier_block = {
39960 .notifier_call = macvtap_device_event,
39961 };
39962
39963diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
39964index daec9b0..6428fcb 100644
39965--- a/drivers/net/phy/mdio-bitbang.c
39966+++ b/drivers/net/phy/mdio-bitbang.c
39967@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
39968 struct mdiobb_ctrl *ctrl = bus->priv;
39969
39970 module_put(ctrl->ops->owner);
39971+ mdiobus_unregister(bus);
39972 mdiobus_free(bus);
39973 }
39974 EXPORT_SYMBOL(free_mdio_bitbang);
39975diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
39976index 72ff14b..11d442d 100644
39977--- a/drivers/net/ppp/ppp_generic.c
39978+++ b/drivers/net/ppp/ppp_generic.c
39979@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39980 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
39981 struct ppp_stats stats;
39982 struct ppp_comp_stats cstats;
39983- char *vers;
39984
39985 switch (cmd) {
39986 case SIOCGPPPSTATS:
39987@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39988 break;
39989
39990 case SIOCGPPPVER:
39991- vers = PPP_VERSION;
39992- if (copy_to_user(addr, vers, strlen(vers) + 1))
39993+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
39994 break;
39995 err = 0;
39996 break;
39997diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
39998index 1252d9c..80e660b 100644
39999--- a/drivers/net/slip/slhc.c
40000+++ b/drivers/net/slip/slhc.c
40001@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
40002 register struct tcphdr *thp;
40003 register struct iphdr *ip;
40004 register struct cstate *cs;
40005- int len, hdrlen;
40006+ long len, hdrlen;
40007 unsigned char *cp = icp;
40008
40009 /* We've got a compressed packet; read the change byte */
40010diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
40011index bf34192..fba3500 100644
40012--- a/drivers/net/team/team.c
40013+++ b/drivers/net/team/team.c
40014@@ -2668,7 +2668,7 @@ static int team_device_event(struct notifier_block *unused,
40015 return NOTIFY_DONE;
40016 }
40017
40018-static struct notifier_block team_notifier_block __read_mostly = {
40019+static struct notifier_block team_notifier_block = {
40020 .notifier_call = team_device_event,
40021 };
40022
40023diff --git a/drivers/net/tun.c b/drivers/net/tun.c
40024index 755fa9e..631fdce 100644
40025--- a/drivers/net/tun.c
40026+++ b/drivers/net/tun.c
40027@@ -1841,7 +1841,7 @@ unlock:
40028 }
40029
40030 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40031- unsigned long arg, int ifreq_len)
40032+ unsigned long arg, size_t ifreq_len)
40033 {
40034 struct tun_file *tfile = file->private_data;
40035 struct tun_struct *tun;
40036@@ -1853,6 +1853,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40037 int vnet_hdr_sz;
40038 int ret;
40039
40040+ if (ifreq_len > sizeof ifr)
40041+ return -EFAULT;
40042+
40043 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
40044 if (copy_from_user(&ifr, argp, ifreq_len))
40045 return -EFAULT;
40046diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
40047index e2dd324..be92fcf 100644
40048--- a/drivers/net/usb/hso.c
40049+++ b/drivers/net/usb/hso.c
40050@@ -71,7 +71,7 @@
40051 #include <asm/byteorder.h>
40052 #include <linux/serial_core.h>
40053 #include <linux/serial.h>
40054-
40055+#include <asm/local.h>
40056
40057 #define MOD_AUTHOR "Option Wireless"
40058 #define MOD_DESCRIPTION "USB High Speed Option driver"
40059@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
40060 struct urb *urb;
40061
40062 urb = serial->rx_urb[0];
40063- if (serial->port.count > 0) {
40064+ if (atomic_read(&serial->port.count) > 0) {
40065 count = put_rxbuf_data(urb, serial);
40066 if (count == -1)
40067 return;
40068@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
40069 DUMP1(urb->transfer_buffer, urb->actual_length);
40070
40071 /* Anyone listening? */
40072- if (serial->port.count == 0)
40073+ if (atomic_read(&serial->port.count) == 0)
40074 return;
40075
40076 if (status == 0) {
40077@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40078 tty_port_tty_set(&serial->port, tty);
40079
40080 /* check for port already opened, if not set the termios */
40081- serial->port.count++;
40082- if (serial->port.count == 1) {
40083+ if (atomic_inc_return(&serial->port.count) == 1) {
40084 serial->rx_state = RX_IDLE;
40085 /* Force default termio settings */
40086 _hso_serial_set_termios(tty, NULL);
40087@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40088 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
40089 if (result) {
40090 hso_stop_serial_device(serial->parent);
40091- serial->port.count--;
40092+ atomic_dec(&serial->port.count);
40093 kref_put(&serial->parent->ref, hso_serial_ref_free);
40094 }
40095 } else {
40096@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
40097
40098 /* reset the rts and dtr */
40099 /* do the actual close */
40100- serial->port.count--;
40101+ atomic_dec(&serial->port.count);
40102
40103- if (serial->port.count <= 0) {
40104- serial->port.count = 0;
40105+ if (atomic_read(&serial->port.count) <= 0) {
40106+ atomic_set(&serial->port.count, 0);
40107 tty_port_tty_set(&serial->port, NULL);
40108 if (!usb_gone)
40109 hso_stop_serial_device(serial->parent);
40110@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
40111
40112 /* the actual setup */
40113 spin_lock_irqsave(&serial->serial_lock, flags);
40114- if (serial->port.count)
40115+ if (atomic_read(&serial->port.count))
40116 _hso_serial_set_termios(tty, old);
40117 else
40118 tty->termios = *old;
40119@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
40120 D1("Pending read interrupt on port %d\n", i);
40121 spin_lock(&serial->serial_lock);
40122 if (serial->rx_state == RX_IDLE &&
40123- serial->port.count > 0) {
40124+ atomic_read(&serial->port.count) > 0) {
40125 /* Setup and send a ctrl req read on
40126 * port i */
40127 if (!serial->rx_urb_filled[0]) {
40128@@ -3066,7 +3065,7 @@ static int hso_resume(struct usb_interface *iface)
40129 /* Start all serial ports */
40130 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
40131 if (serial_table[i] && (serial_table[i]->interface == iface)) {
40132- if (dev2ser(serial_table[i])->port.count) {
40133+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
40134 result =
40135 hso_start_serial_device(serial_table[i], GFP_NOIO);
40136 hso_kick_transmit(dev2ser(serial_table[i]));
40137diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
40138index 7cee7a3..1eb9f3b 100644
40139--- a/drivers/net/vxlan.c
40140+++ b/drivers/net/vxlan.c
40141@@ -1443,7 +1443,7 @@ nla_put_failure:
40142 return -EMSGSIZE;
40143 }
40144
40145-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
40146+static struct rtnl_link_ops vxlan_link_ops = {
40147 .kind = "vxlan",
40148 .maxtype = IFLA_VXLAN_MAX,
40149 .policy = vxlan_policy,
40150diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
40151index 5ac5f7a..5f82012 100644
40152--- a/drivers/net/wireless/at76c50x-usb.c
40153+++ b/drivers/net/wireless/at76c50x-usb.c
40154@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
40155 }
40156
40157 /* Convert timeout from the DFU status to jiffies */
40158-static inline unsigned long at76_get_timeout(struct dfu_status *s)
40159+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
40160 {
40161 return msecs_to_jiffies((s->poll_timeout[2] << 16)
40162 | (s->poll_timeout[1] << 8)
40163diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40164index 8d78253..bebbb68 100644
40165--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40166+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40167@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40168 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
40169 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
40170
40171- ACCESS_ONCE(ads->ds_link) = i->link;
40172- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
40173+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
40174+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
40175
40176 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
40177 ctl6 = SM(i->keytype, AR_EncrType);
40178@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40179
40180 if ((i->is_first || i->is_last) &&
40181 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
40182- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
40183+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
40184 | set11nTries(i->rates, 1)
40185 | set11nTries(i->rates, 2)
40186 | set11nTries(i->rates, 3)
40187 | (i->dur_update ? AR_DurUpdateEna : 0)
40188 | SM(0, AR_BurstDur);
40189
40190- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
40191+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
40192 | set11nRate(i->rates, 1)
40193 | set11nRate(i->rates, 2)
40194 | set11nRate(i->rates, 3);
40195 } else {
40196- ACCESS_ONCE(ads->ds_ctl2) = 0;
40197- ACCESS_ONCE(ads->ds_ctl3) = 0;
40198+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
40199+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
40200 }
40201
40202 if (!i->is_first) {
40203- ACCESS_ONCE(ads->ds_ctl0) = 0;
40204- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
40205- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
40206+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
40207+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
40208+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
40209 return;
40210 }
40211
40212@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40213 break;
40214 }
40215
40216- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
40217+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
40218 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
40219 | SM(i->txpower, AR_XmitPower)
40220 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
40221@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40222 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
40223 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
40224
40225- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
40226- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
40227+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
40228+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
40229
40230 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
40231 return;
40232
40233- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
40234+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
40235 | set11nPktDurRTSCTS(i->rates, 1);
40236
40237- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
40238+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
40239 | set11nPktDurRTSCTS(i->rates, 3);
40240
40241- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
40242+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
40243 | set11nRateFlags(i->rates, 1)
40244 | set11nRateFlags(i->rates, 2)
40245 | set11nRateFlags(i->rates, 3)
40246diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40247index 301bf72..3f5654f 100644
40248--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40249+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40250@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40251 (i->qcu << AR_TxQcuNum_S) | desc_len;
40252
40253 checksum += val;
40254- ACCESS_ONCE(ads->info) = val;
40255+ ACCESS_ONCE_RW(ads->info) = val;
40256
40257 checksum += i->link;
40258- ACCESS_ONCE(ads->link) = i->link;
40259+ ACCESS_ONCE_RW(ads->link) = i->link;
40260
40261 checksum += i->buf_addr[0];
40262- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
40263+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
40264 checksum += i->buf_addr[1];
40265- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
40266+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
40267 checksum += i->buf_addr[2];
40268- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
40269+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
40270 checksum += i->buf_addr[3];
40271- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
40272+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
40273
40274 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
40275- ACCESS_ONCE(ads->ctl3) = val;
40276+ ACCESS_ONCE_RW(ads->ctl3) = val;
40277 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
40278- ACCESS_ONCE(ads->ctl5) = val;
40279+ ACCESS_ONCE_RW(ads->ctl5) = val;
40280 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
40281- ACCESS_ONCE(ads->ctl7) = val;
40282+ ACCESS_ONCE_RW(ads->ctl7) = val;
40283 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
40284- ACCESS_ONCE(ads->ctl9) = val;
40285+ ACCESS_ONCE_RW(ads->ctl9) = val;
40286
40287 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
40288- ACCESS_ONCE(ads->ctl10) = checksum;
40289+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
40290
40291 if (i->is_first || i->is_last) {
40292- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
40293+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
40294 | set11nTries(i->rates, 1)
40295 | set11nTries(i->rates, 2)
40296 | set11nTries(i->rates, 3)
40297 | (i->dur_update ? AR_DurUpdateEna : 0)
40298 | SM(0, AR_BurstDur);
40299
40300- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
40301+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
40302 | set11nRate(i->rates, 1)
40303 | set11nRate(i->rates, 2)
40304 | set11nRate(i->rates, 3);
40305 } else {
40306- ACCESS_ONCE(ads->ctl13) = 0;
40307- ACCESS_ONCE(ads->ctl14) = 0;
40308+ ACCESS_ONCE_RW(ads->ctl13) = 0;
40309+ ACCESS_ONCE_RW(ads->ctl14) = 0;
40310 }
40311
40312 ads->ctl20 = 0;
40313@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40314
40315 ctl17 = SM(i->keytype, AR_EncrType);
40316 if (!i->is_first) {
40317- ACCESS_ONCE(ads->ctl11) = 0;
40318- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
40319- ACCESS_ONCE(ads->ctl15) = 0;
40320- ACCESS_ONCE(ads->ctl16) = 0;
40321- ACCESS_ONCE(ads->ctl17) = ctl17;
40322- ACCESS_ONCE(ads->ctl18) = 0;
40323- ACCESS_ONCE(ads->ctl19) = 0;
40324+ ACCESS_ONCE_RW(ads->ctl11) = 0;
40325+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
40326+ ACCESS_ONCE_RW(ads->ctl15) = 0;
40327+ ACCESS_ONCE_RW(ads->ctl16) = 0;
40328+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
40329+ ACCESS_ONCE_RW(ads->ctl18) = 0;
40330+ ACCESS_ONCE_RW(ads->ctl19) = 0;
40331 return;
40332 }
40333
40334- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
40335+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
40336 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
40337 | SM(i->txpower, AR_XmitPower)
40338 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
40339@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40340 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
40341 ctl12 |= SM(val, AR_PAPRDChainMask);
40342
40343- ACCESS_ONCE(ads->ctl12) = ctl12;
40344- ACCESS_ONCE(ads->ctl17) = ctl17;
40345+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
40346+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
40347
40348- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
40349+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
40350 | set11nPktDurRTSCTS(i->rates, 1);
40351
40352- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
40353+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
40354 | set11nPktDurRTSCTS(i->rates, 3);
40355
40356- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
40357+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
40358 | set11nRateFlags(i->rates, 1)
40359 | set11nRateFlags(i->rates, 2)
40360 | set11nRateFlags(i->rates, 3)
40361 | SM(i->rtscts_rate, AR_RTSCTSRate);
40362
40363- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
40364+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
40365 }
40366
40367 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
40368diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
40369index 784e81c..349e01e 100644
40370--- a/drivers/net/wireless/ath/ath9k/hw.h
40371+++ b/drivers/net/wireless/ath/ath9k/hw.h
40372@@ -653,7 +653,7 @@ struct ath_hw_private_ops {
40373
40374 /* ANI */
40375 void (*ani_cache_ini_regs)(struct ath_hw *ah);
40376-};
40377+} __no_const;
40378
40379 /**
40380 * struct ath_spec_scan - parameters for Atheros spectral scan
40381@@ -722,7 +722,7 @@ struct ath_hw_ops {
40382 struct ath_spec_scan *param);
40383 void (*spectral_scan_trigger)(struct ath_hw *ah);
40384 void (*spectral_scan_wait)(struct ath_hw *ah);
40385-};
40386+} __no_const;
40387
40388 struct ath_nf_limits {
40389 s16 max;
40390diff --git a/drivers/net/wireless/b43/main.c b/drivers/net/wireless/b43/main.c
40391index 64b637a..911c4c0 100644
40392--- a/drivers/net/wireless/b43/main.c
40393+++ b/drivers/net/wireless/b43/main.c
40394@@ -2451,7 +2451,7 @@ static void b43_request_firmware(struct work_struct *work)
40395 for (i = 0; i < B43_NR_FWTYPES; i++) {
40396 errmsg = ctx->errors[i];
40397 if (strlen(errmsg))
40398- b43err(dev->wl, errmsg);
40399+ b43err(dev->wl, "%s", errmsg);
40400 }
40401 b43_print_fw_helptext(dev->wl, 1);
40402 goto out;
40403diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
40404index c353b5f..62aaca2 100644
40405--- a/drivers/net/wireless/iwlegacy/3945-mac.c
40406+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
40407@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
40408 */
40409 if (il3945_mod_params.disable_hw_scan) {
40410 D_INFO("Disabling hw_scan\n");
40411- il3945_mac_ops.hw_scan = NULL;
40412+ pax_open_kernel();
40413+ *(void **)&il3945_mac_ops.hw_scan = NULL;
40414+ pax_close_kernel();
40415 }
40416
40417 D_INFO("*** LOAD DRIVER ***\n");
40418diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40419index 81d4071..f2071ea 100644
40420--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40421+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40422@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
40423 {
40424 struct iwl_priv *priv = file->private_data;
40425 char buf[64];
40426- int buf_size;
40427+ size_t buf_size;
40428 u32 offset, len;
40429
40430 memset(buf, 0, sizeof(buf));
40431@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
40432 struct iwl_priv *priv = file->private_data;
40433
40434 char buf[8];
40435- int buf_size;
40436+ size_t buf_size;
40437 u32 reset_flag;
40438
40439 memset(buf, 0, sizeof(buf));
40440@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
40441 {
40442 struct iwl_priv *priv = file->private_data;
40443 char buf[8];
40444- int buf_size;
40445+ size_t buf_size;
40446 int ht40;
40447
40448 memset(buf, 0, sizeof(buf));
40449@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
40450 {
40451 struct iwl_priv *priv = file->private_data;
40452 char buf[8];
40453- int buf_size;
40454+ size_t buf_size;
40455 int value;
40456
40457 memset(buf, 0, sizeof(buf));
40458@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
40459 {
40460 struct iwl_priv *priv = file->private_data;
40461 char buf[8];
40462- int buf_size;
40463+ size_t buf_size;
40464 int clear;
40465
40466 memset(buf, 0, sizeof(buf));
40467@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
40468 {
40469 struct iwl_priv *priv = file->private_data;
40470 char buf[8];
40471- int buf_size;
40472+ size_t buf_size;
40473 int trace;
40474
40475 memset(buf, 0, sizeof(buf));
40476@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
40477 {
40478 struct iwl_priv *priv = file->private_data;
40479 char buf[8];
40480- int buf_size;
40481+ size_t buf_size;
40482 int missed;
40483
40484 memset(buf, 0, sizeof(buf));
40485@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
40486
40487 struct iwl_priv *priv = file->private_data;
40488 char buf[8];
40489- int buf_size;
40490+ size_t buf_size;
40491 int plcp;
40492
40493 memset(buf, 0, sizeof(buf));
40494@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
40495
40496 struct iwl_priv *priv = file->private_data;
40497 char buf[8];
40498- int buf_size;
40499+ size_t buf_size;
40500 int flush;
40501
40502 memset(buf, 0, sizeof(buf));
40503@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
40504
40505 struct iwl_priv *priv = file->private_data;
40506 char buf[8];
40507- int buf_size;
40508+ size_t buf_size;
40509 int rts;
40510
40511 if (!priv->cfg->ht_params)
40512@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
40513 {
40514 struct iwl_priv *priv = file->private_data;
40515 char buf[8];
40516- int buf_size;
40517+ size_t buf_size;
40518
40519 memset(buf, 0, sizeof(buf));
40520 buf_size = min(count, sizeof(buf) - 1);
40521@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
40522 struct iwl_priv *priv = file->private_data;
40523 u32 event_log_flag;
40524 char buf[8];
40525- int buf_size;
40526+ size_t buf_size;
40527
40528 /* check that the interface is up */
40529 if (!iwl_is_ready(priv))
40530@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
40531 struct iwl_priv *priv = file->private_data;
40532 char buf[8];
40533 u32 calib_disabled;
40534- int buf_size;
40535+ size_t buf_size;
40536
40537 memset(buf, 0, sizeof(buf));
40538 buf_size = min(count, sizeof(buf) - 1);
40539diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
40540index 12c4f31..484d948 100644
40541--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
40542+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
40543@@ -1328,7 +1328,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
40544 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
40545
40546 char buf[8];
40547- int buf_size;
40548+ size_t buf_size;
40549 u32 reset_flag;
40550
40551 memset(buf, 0, sizeof(buf));
40552@@ -1349,7 +1349,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
40553 {
40554 struct iwl_trans *trans = file->private_data;
40555 char buf[8];
40556- int buf_size;
40557+ size_t buf_size;
40558 int csr;
40559
40560 memset(buf, 0, sizeof(buf));
40561diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
40562index 2b49f48..14fc244 100644
40563--- a/drivers/net/wireless/mac80211_hwsim.c
40564+++ b/drivers/net/wireless/mac80211_hwsim.c
40565@@ -2143,25 +2143,19 @@ static int __init init_mac80211_hwsim(void)
40566
40567 if (channels > 1) {
40568 hwsim_if_comb.num_different_channels = channels;
40569- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40570- mac80211_hwsim_ops.cancel_hw_scan =
40571- mac80211_hwsim_cancel_hw_scan;
40572- mac80211_hwsim_ops.sw_scan_start = NULL;
40573- mac80211_hwsim_ops.sw_scan_complete = NULL;
40574- mac80211_hwsim_ops.remain_on_channel =
40575- mac80211_hwsim_roc;
40576- mac80211_hwsim_ops.cancel_remain_on_channel =
40577- mac80211_hwsim_croc;
40578- mac80211_hwsim_ops.add_chanctx =
40579- mac80211_hwsim_add_chanctx;
40580- mac80211_hwsim_ops.remove_chanctx =
40581- mac80211_hwsim_remove_chanctx;
40582- mac80211_hwsim_ops.change_chanctx =
40583- mac80211_hwsim_change_chanctx;
40584- mac80211_hwsim_ops.assign_vif_chanctx =
40585- mac80211_hwsim_assign_vif_chanctx;
40586- mac80211_hwsim_ops.unassign_vif_chanctx =
40587- mac80211_hwsim_unassign_vif_chanctx;
40588+ pax_open_kernel();
40589+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40590+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
40591+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
40592+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
40593+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
40594+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
40595+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
40596+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
40597+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
40598+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
40599+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
40600+ pax_close_kernel();
40601 }
40602
40603 spin_lock_init(&hwsim_radio_lock);
40604diff --git a/drivers/net/wireless/mwifiex/debugfs.c b/drivers/net/wireless/mwifiex/debugfs.c
40605index 753b568..a5f9875 100644
40606--- a/drivers/net/wireless/mwifiex/debugfs.c
40607+++ b/drivers/net/wireless/mwifiex/debugfs.c
40608@@ -26,10 +26,17 @@
40609 static struct dentry *mwifiex_dfs_dir;
40610
40611 static char *bss_modes[] = {
40612- "Unknown",
40613- "Ad-hoc",
40614- "Managed",
40615- "Auto"
40616+ "UNSPECIFIED",
40617+ "ADHOC",
40618+ "STATION",
40619+ "AP",
40620+ "AP_VLAN",
40621+ "WDS",
40622+ "MONITOR",
40623+ "MESH_POINT",
40624+ "P2P_CLIENT",
40625+ "P2P_GO",
40626+ "P2P_DEVICE",
40627 };
40628
40629 /* size/addr for mwifiex_debug_info */
40630@@ -200,7 +207,12 @@ mwifiex_info_read(struct file *file, char __user *ubuf,
40631 p += sprintf(p, "driver_version = %s", fmt);
40632 p += sprintf(p, "\nverext = %s", priv->version_str);
40633 p += sprintf(p, "\ninterface_name=\"%s\"\n", netdev->name);
40634- p += sprintf(p, "bss_mode=\"%s\"\n", bss_modes[info.bss_mode]);
40635+
40636+ if (info.bss_mode >= ARRAY_SIZE(bss_modes))
40637+ p += sprintf(p, "bss_mode=\"%d\"\n", info.bss_mode);
40638+ else
40639+ p += sprintf(p, "bss_mode=\"%s\"\n", bss_modes[info.bss_mode]);
40640+
40641 p += sprintf(p, "media_state=\"%s\"\n",
40642 (!priv->media_connected ? "Disconnected" : "Connected"));
40643 p += sprintf(p, "mac_address=\"%pM\"\n", netdev->dev_addr);
40644diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
40645index 525fd75..6c9f791 100644
40646--- a/drivers/net/wireless/rndis_wlan.c
40647+++ b/drivers/net/wireless/rndis_wlan.c
40648@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
40649
40650 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
40651
40652- if (rts_threshold < 0 || rts_threshold > 2347)
40653+ if (rts_threshold > 2347)
40654 rts_threshold = 2347;
40655
40656 tmp = cpu_to_le32(rts_threshold);
40657diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
40658index 086abb4..8279c30 100644
40659--- a/drivers/net/wireless/rt2x00/rt2x00.h
40660+++ b/drivers/net/wireless/rt2x00/rt2x00.h
40661@@ -396,7 +396,7 @@ struct rt2x00_intf {
40662 * for hardware which doesn't support hardware
40663 * sequence counting.
40664 */
40665- atomic_t seqno;
40666+ atomic_unchecked_t seqno;
40667 };
40668
40669 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
40670diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
40671index 4d91795..62fccff 100644
40672--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
40673+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
40674@@ -251,9 +251,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
40675 * sequence counter given by mac80211.
40676 */
40677 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
40678- seqno = atomic_add_return(0x10, &intf->seqno);
40679+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
40680 else
40681- seqno = atomic_read(&intf->seqno);
40682+ seqno = atomic_read_unchecked(&intf->seqno);
40683
40684 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
40685 hdr->seq_ctrl |= cpu_to_le16(seqno);
40686diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
40687index e57ee48..541cf6c 100644
40688--- a/drivers/net/wireless/ti/wl1251/sdio.c
40689+++ b/drivers/net/wireless/ti/wl1251/sdio.c
40690@@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
40691
40692 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
40693
40694- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
40695- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
40696+ pax_open_kernel();
40697+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
40698+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
40699+ pax_close_kernel();
40700
40701 wl1251_info("using dedicated interrupt line");
40702 } else {
40703- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
40704- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
40705+ pax_open_kernel();
40706+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
40707+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
40708+ pax_close_kernel();
40709
40710 wl1251_info("using SDIO interrupt");
40711 }
40712diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
40713index 09694e3..24ccec7 100644
40714--- a/drivers/net/wireless/ti/wl12xx/main.c
40715+++ b/drivers/net/wireless/ti/wl12xx/main.c
40716@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
40717 sizeof(wl->conf.mem));
40718
40719 /* read data preparation is only needed by wl127x */
40720- wl->ops->prepare_read = wl127x_prepare_read;
40721+ pax_open_kernel();
40722+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
40723+ pax_close_kernel();
40724
40725 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
40726 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
40727@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
40728 sizeof(wl->conf.mem));
40729
40730 /* read data preparation is only needed by wl127x */
40731- wl->ops->prepare_read = wl127x_prepare_read;
40732+ pax_open_kernel();
40733+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
40734+ pax_close_kernel();
40735
40736 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
40737 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
40738diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
40739index da3ef1b..4790b95 100644
40740--- a/drivers/net/wireless/ti/wl18xx/main.c
40741+++ b/drivers/net/wireless/ti/wl18xx/main.c
40742@@ -1664,8 +1664,10 @@ static int wl18xx_setup(struct wl1271 *wl)
40743 }
40744
40745 if (!checksum_param) {
40746- wl18xx_ops.set_rx_csum = NULL;
40747- wl18xx_ops.init_vif = NULL;
40748+ pax_open_kernel();
40749+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
40750+ *(void **)&wl18xx_ops.init_vif = NULL;
40751+ pax_close_kernel();
40752 }
40753
40754 /* Enable 11a Band only if we have 5G antennas */
40755diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
40756index 7ef0b4a..ff65c28 100644
40757--- a/drivers/net/wireless/zd1211rw/zd_usb.c
40758+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
40759@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
40760 {
40761 struct zd_usb *usb = urb->context;
40762 struct zd_usb_interrupt *intr = &usb->intr;
40763- int len;
40764+ unsigned int len;
40765 u16 int_num;
40766
40767 ZD_ASSERT(in_interrupt());
40768diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
40769index d93b2b6..ae50401 100644
40770--- a/drivers/oprofile/buffer_sync.c
40771+++ b/drivers/oprofile/buffer_sync.c
40772@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
40773 if (cookie == NO_COOKIE)
40774 offset = pc;
40775 if (cookie == INVALID_COOKIE) {
40776- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
40777+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
40778 offset = pc;
40779 }
40780 if (cookie != last_cookie) {
40781@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
40782 /* add userspace sample */
40783
40784 if (!mm) {
40785- atomic_inc(&oprofile_stats.sample_lost_no_mm);
40786+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
40787 return 0;
40788 }
40789
40790 cookie = lookup_dcookie(mm, s->eip, &offset);
40791
40792 if (cookie == INVALID_COOKIE) {
40793- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
40794+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
40795 return 0;
40796 }
40797
40798@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
40799 /* ignore backtraces if failed to add a sample */
40800 if (state == sb_bt_start) {
40801 state = sb_bt_ignore;
40802- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
40803+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
40804 }
40805 }
40806 release_mm(mm);
40807diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
40808index c0cc4e7..44d4e54 100644
40809--- a/drivers/oprofile/event_buffer.c
40810+++ b/drivers/oprofile/event_buffer.c
40811@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
40812 }
40813
40814 if (buffer_pos == buffer_size) {
40815- atomic_inc(&oprofile_stats.event_lost_overflow);
40816+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
40817 return;
40818 }
40819
40820diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
40821index ed2c3ec..deda85a 100644
40822--- a/drivers/oprofile/oprof.c
40823+++ b/drivers/oprofile/oprof.c
40824@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
40825 if (oprofile_ops.switch_events())
40826 return;
40827
40828- atomic_inc(&oprofile_stats.multiplex_counter);
40829+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
40830 start_switch_worker();
40831 }
40832
40833diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
40834index 84a208d..d61b0a1 100644
40835--- a/drivers/oprofile/oprofile_files.c
40836+++ b/drivers/oprofile/oprofile_files.c
40837@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
40838
40839 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
40840
40841-static ssize_t timeout_read(struct file *file, char __user *buf,
40842+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
40843 size_t count, loff_t *offset)
40844 {
40845 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
40846diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
40847index 917d28e..d62d981 100644
40848--- a/drivers/oprofile/oprofile_stats.c
40849+++ b/drivers/oprofile/oprofile_stats.c
40850@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
40851 cpu_buf->sample_invalid_eip = 0;
40852 }
40853
40854- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
40855- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
40856- atomic_set(&oprofile_stats.event_lost_overflow, 0);
40857- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
40858- atomic_set(&oprofile_stats.multiplex_counter, 0);
40859+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
40860+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
40861+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
40862+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
40863+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
40864 }
40865
40866
40867diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
40868index 38b6fc0..b5cbfce 100644
40869--- a/drivers/oprofile/oprofile_stats.h
40870+++ b/drivers/oprofile/oprofile_stats.h
40871@@ -13,11 +13,11 @@
40872 #include <linux/atomic.h>
40873
40874 struct oprofile_stat_struct {
40875- atomic_t sample_lost_no_mm;
40876- atomic_t sample_lost_no_mapping;
40877- atomic_t bt_lost_no_mapping;
40878- atomic_t event_lost_overflow;
40879- atomic_t multiplex_counter;
40880+ atomic_unchecked_t sample_lost_no_mm;
40881+ atomic_unchecked_t sample_lost_no_mapping;
40882+ atomic_unchecked_t bt_lost_no_mapping;
40883+ atomic_unchecked_t event_lost_overflow;
40884+ atomic_unchecked_t multiplex_counter;
40885 };
40886
40887 extern struct oprofile_stat_struct oprofile_stats;
40888diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
40889index 7c12d9c..558bf3bb 100644
40890--- a/drivers/oprofile/oprofilefs.c
40891+++ b/drivers/oprofile/oprofilefs.c
40892@@ -190,7 +190,7 @@ static const struct file_operations atomic_ro_fops = {
40893
40894
40895 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
40896- char const *name, atomic_t *val)
40897+ char const *name, atomic_unchecked_t *val)
40898 {
40899 return __oprofilefs_create_file(sb, root, name,
40900 &atomic_ro_fops, 0444, val);
40901diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
40902index 93404f7..4a313d8 100644
40903--- a/drivers/oprofile/timer_int.c
40904+++ b/drivers/oprofile/timer_int.c
40905@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
40906 return NOTIFY_OK;
40907 }
40908
40909-static struct notifier_block __refdata oprofile_cpu_notifier = {
40910+static struct notifier_block oprofile_cpu_notifier = {
40911 .notifier_call = oprofile_cpu_notify,
40912 };
40913
40914diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
40915index 3f56bc0..707d642 100644
40916--- a/drivers/parport/procfs.c
40917+++ b/drivers/parport/procfs.c
40918@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
40919
40920 *ppos += len;
40921
40922- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
40923+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
40924 }
40925
40926 #ifdef CONFIG_PARPORT_1284
40927@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
40928
40929 *ppos += len;
40930
40931- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
40932+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
40933 }
40934 #endif /* IEEE1284.3 support. */
40935
40936diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
40937index c35e8ad..fc33beb 100644
40938--- a/drivers/pci/hotplug/acpiphp_ibm.c
40939+++ b/drivers/pci/hotplug/acpiphp_ibm.c
40940@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
40941 goto init_cleanup;
40942 }
40943
40944- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
40945+ pax_open_kernel();
40946+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
40947+ pax_close_kernel();
40948 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
40949
40950 return retval;
40951diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
40952index a6a71c4..c91097b 100644
40953--- a/drivers/pci/hotplug/cpcihp_generic.c
40954+++ b/drivers/pci/hotplug/cpcihp_generic.c
40955@@ -73,7 +73,6 @@ static u16 port;
40956 static unsigned int enum_bit;
40957 static u8 enum_mask;
40958
40959-static struct cpci_hp_controller_ops generic_hpc_ops;
40960 static struct cpci_hp_controller generic_hpc;
40961
40962 static int __init validate_parameters(void)
40963@@ -139,6 +138,10 @@ static int query_enum(void)
40964 return ((value & enum_mask) == enum_mask);
40965 }
40966
40967+static struct cpci_hp_controller_ops generic_hpc_ops = {
40968+ .query_enum = query_enum,
40969+};
40970+
40971 static int __init cpcihp_generic_init(void)
40972 {
40973 int status;
40974@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
40975 pci_dev_put(dev);
40976
40977 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
40978- generic_hpc_ops.query_enum = query_enum;
40979 generic_hpc.ops = &generic_hpc_ops;
40980
40981 status = cpci_hp_register_controller(&generic_hpc);
40982diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
40983index 449b4bb..257e2e8 100644
40984--- a/drivers/pci/hotplug/cpcihp_zt5550.c
40985+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
40986@@ -59,7 +59,6 @@
40987 /* local variables */
40988 static bool debug;
40989 static bool poll;
40990-static struct cpci_hp_controller_ops zt5550_hpc_ops;
40991 static struct cpci_hp_controller zt5550_hpc;
40992
40993 /* Primary cPCI bus bridge device */
40994@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
40995 return 0;
40996 }
40997
40998+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
40999+ .query_enum = zt5550_hc_query_enum,
41000+};
41001+
41002 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
41003 {
41004 int status;
41005@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
41006 dbg("returned from zt5550_hc_config");
41007
41008 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
41009- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
41010 zt5550_hpc.ops = &zt5550_hpc_ops;
41011 if(!poll) {
41012 zt5550_hpc.irq = hc_dev->irq;
41013 zt5550_hpc.irq_flags = IRQF_SHARED;
41014 zt5550_hpc.dev_id = hc_dev;
41015
41016- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
41017- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
41018- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
41019+ pax_open_kernel();
41020+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
41021+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
41022+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
41023+ pax_open_kernel();
41024 } else {
41025 info("using ENUM# polling mode");
41026 }
41027diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
41028index 76ba8a1..20ca857 100644
41029--- a/drivers/pci/hotplug/cpqphp_nvram.c
41030+++ b/drivers/pci/hotplug/cpqphp_nvram.c
41031@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
41032
41033 void compaq_nvram_init (void __iomem *rom_start)
41034 {
41035+
41036+#ifndef CONFIG_PAX_KERNEXEC
41037 if (rom_start) {
41038 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
41039 }
41040+#endif
41041+
41042 dbg("int15 entry = %p\n", compaq_int15_entry_point);
41043
41044 /* initialize our int15 lock */
41045diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
41046index 202f4a9..8ee47d0 100644
41047--- a/drivers/pci/hotplug/pci_hotplug_core.c
41048+++ b/drivers/pci/hotplug/pci_hotplug_core.c
41049@@ -448,8 +448,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
41050 return -EINVAL;
41051 }
41052
41053- slot->ops->owner = owner;
41054- slot->ops->mod_name = mod_name;
41055+ pax_open_kernel();
41056+ *(struct module **)&slot->ops->owner = owner;
41057+ *(const char **)&slot->ops->mod_name = mod_name;
41058+ pax_close_kernel();
41059
41060 mutex_lock(&pci_hp_mutex);
41061 /*
41062diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
41063index 7d72c5e..edce02c 100644
41064--- a/drivers/pci/hotplug/pciehp_core.c
41065+++ b/drivers/pci/hotplug/pciehp_core.c
41066@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
41067 struct slot *slot = ctrl->slot;
41068 struct hotplug_slot *hotplug = NULL;
41069 struct hotplug_slot_info *info = NULL;
41070- struct hotplug_slot_ops *ops = NULL;
41071+ hotplug_slot_ops_no_const *ops = NULL;
41072 char name[SLOT_NAME_SIZE];
41073 int retval = -ENOMEM;
41074
41075diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
41076index 9c6e9bb..2916736 100644
41077--- a/drivers/pci/pci-sysfs.c
41078+++ b/drivers/pci/pci-sysfs.c
41079@@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
41080 {
41081 /* allocate attribute structure, piggyback attribute name */
41082 int name_len = write_combine ? 13 : 10;
41083- struct bin_attribute *res_attr;
41084+ bin_attribute_no_const *res_attr;
41085 int retval;
41086
41087 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
41088@@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
41089 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
41090 {
41091 int retval;
41092- struct bin_attribute *attr;
41093+ bin_attribute_no_const *attr;
41094
41095 /* If the device has VPD, try to expose it in sysfs. */
41096 if (dev->vpd) {
41097@@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
41098 {
41099 int retval;
41100 int rom_size = 0;
41101- struct bin_attribute *attr;
41102+ bin_attribute_no_const *attr;
41103
41104 if (!sysfs_initialized)
41105 return -EACCES;
41106diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
41107index 7346ee6..41520eb 100644
41108--- a/drivers/pci/pci.h
41109+++ b/drivers/pci/pci.h
41110@@ -93,7 +93,7 @@ struct pci_vpd_ops {
41111 struct pci_vpd {
41112 unsigned int len;
41113 const struct pci_vpd_ops *ops;
41114- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
41115+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
41116 };
41117
41118 extern int pci_vpd_pci22_init(struct pci_dev *dev);
41119diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
41120index d320df6..ca9a8f6 100644
41121--- a/drivers/pci/pcie/aspm.c
41122+++ b/drivers/pci/pcie/aspm.c
41123@@ -27,9 +27,9 @@
41124 #define MODULE_PARAM_PREFIX "pcie_aspm."
41125
41126 /* Note: those are not register definitions */
41127-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
41128-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
41129-#define ASPM_STATE_L1 (4) /* L1 state */
41130+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
41131+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
41132+#define ASPM_STATE_L1 (4U) /* L1 state */
41133 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
41134 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
41135
41136diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
41137index 563771f..4e3c368 100644
41138--- a/drivers/pci/probe.c
41139+++ b/drivers/pci/probe.c
41140@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
41141 struct pci_bus_region region;
41142 bool bar_too_big = false, bar_disabled = false;
41143
41144- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
41145+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
41146
41147 /* No printks while decoding is disabled! */
41148 if (!dev->mmio_always_on) {
41149diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
41150index 0b00947..64f7c0a 100644
41151--- a/drivers/pci/proc.c
41152+++ b/drivers/pci/proc.c
41153@@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
41154 static int __init pci_proc_init(void)
41155 {
41156 struct pci_dev *dev = NULL;
41157+
41158+#ifdef CONFIG_GRKERNSEC_PROC_ADD
41159+#ifdef CONFIG_GRKERNSEC_PROC_USER
41160+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
41161+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
41162+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
41163+#endif
41164+#else
41165 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
41166+#endif
41167 proc_create("devices", 0, proc_bus_pci_dir,
41168 &proc_bus_pci_dev_operations);
41169 proc_initialized = 1;
41170diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
41171index 3e5b4497..dcdfb70 100644
41172--- a/drivers/platform/x86/chromeos_laptop.c
41173+++ b/drivers/platform/x86/chromeos_laptop.c
41174@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
41175 return 0;
41176 }
41177
41178-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
41179+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
41180 {
41181 .ident = "Samsung Series 5 550 - Touchpad",
41182 .matches = {
41183diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
41184index 6b22938..bc9700e 100644
41185--- a/drivers/platform/x86/msi-laptop.c
41186+++ b/drivers/platform/x86/msi-laptop.c
41187@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
41188
41189 if (!quirks->ec_read_only) {
41190 /* allow userland write sysfs file */
41191- dev_attr_bluetooth.store = store_bluetooth;
41192- dev_attr_wlan.store = store_wlan;
41193- dev_attr_threeg.store = store_threeg;
41194- dev_attr_bluetooth.attr.mode |= S_IWUSR;
41195- dev_attr_wlan.attr.mode |= S_IWUSR;
41196- dev_attr_threeg.attr.mode |= S_IWUSR;
41197+ pax_open_kernel();
41198+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
41199+ *(void **)&dev_attr_wlan.store = store_wlan;
41200+ *(void **)&dev_attr_threeg.store = store_threeg;
41201+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
41202+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
41203+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
41204+ pax_close_kernel();
41205 }
41206
41207 /* disable hardware control by fn key */
41208diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
41209index 14d4dce..b129917 100644
41210--- a/drivers/platform/x86/sony-laptop.c
41211+++ b/drivers/platform/x86/sony-laptop.c
41212@@ -2465,7 +2465,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
41213 }
41214
41215 /* High speed charging function */
41216-static struct device_attribute *hsc_handle;
41217+static device_attribute_no_const *hsc_handle;
41218
41219 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
41220 struct device_attribute *attr,
41221diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
41222index edec135..59a24a3 100644
41223--- a/drivers/platform/x86/thinkpad_acpi.c
41224+++ b/drivers/platform/x86/thinkpad_acpi.c
41225@@ -2093,7 +2093,7 @@ static int hotkey_mask_get(void)
41226 return 0;
41227 }
41228
41229-void static hotkey_mask_warn_incomplete_mask(void)
41230+static void hotkey_mask_warn_incomplete_mask(void)
41231 {
41232 /* log only what the user can fix... */
41233 const u32 wantedmask = hotkey_driver_mask &
41234@@ -2324,11 +2324,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
41235 }
41236 }
41237
41238-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41239- struct tp_nvram_state *newn,
41240- const u32 event_mask)
41241-{
41242-
41243 #define TPACPI_COMPARE_KEY(__scancode, __member) \
41244 do { \
41245 if ((event_mask & (1 << __scancode)) && \
41246@@ -2342,36 +2337,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41247 tpacpi_hotkey_send_key(__scancode); \
41248 } while (0)
41249
41250- void issue_volchange(const unsigned int oldvol,
41251- const unsigned int newvol)
41252- {
41253- unsigned int i = oldvol;
41254+static void issue_volchange(const unsigned int oldvol,
41255+ const unsigned int newvol,
41256+ const u32 event_mask)
41257+{
41258+ unsigned int i = oldvol;
41259
41260- while (i > newvol) {
41261- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
41262- i--;
41263- }
41264- while (i < newvol) {
41265- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41266- i++;
41267- }
41268+ while (i > newvol) {
41269+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
41270+ i--;
41271 }
41272+ while (i < newvol) {
41273+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41274+ i++;
41275+ }
41276+}
41277
41278- void issue_brightnesschange(const unsigned int oldbrt,
41279- const unsigned int newbrt)
41280- {
41281- unsigned int i = oldbrt;
41282+static void issue_brightnesschange(const unsigned int oldbrt,
41283+ const unsigned int newbrt,
41284+ const u32 event_mask)
41285+{
41286+ unsigned int i = oldbrt;
41287
41288- while (i > newbrt) {
41289- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
41290- i--;
41291- }
41292- while (i < newbrt) {
41293- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41294- i++;
41295- }
41296+ while (i > newbrt) {
41297+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
41298+ i--;
41299+ }
41300+ while (i < newbrt) {
41301+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41302+ i++;
41303 }
41304+}
41305
41306+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41307+ struct tp_nvram_state *newn,
41308+ const u32 event_mask)
41309+{
41310 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
41311 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
41312 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
41313@@ -2405,7 +2406,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41314 oldn->volume_level != newn->volume_level) {
41315 /* recently muted, or repeated mute keypress, or
41316 * multiple presses ending in mute */
41317- issue_volchange(oldn->volume_level, newn->volume_level);
41318+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
41319 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
41320 }
41321 } else {
41322@@ -2415,7 +2416,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41323 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41324 }
41325 if (oldn->volume_level != newn->volume_level) {
41326- issue_volchange(oldn->volume_level, newn->volume_level);
41327+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
41328 } else if (oldn->volume_toggle != newn->volume_toggle) {
41329 /* repeated vol up/down keypress at end of scale ? */
41330 if (newn->volume_level == 0)
41331@@ -2428,7 +2429,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41332 /* handle brightness */
41333 if (oldn->brightness_level != newn->brightness_level) {
41334 issue_brightnesschange(oldn->brightness_level,
41335- newn->brightness_level);
41336+ newn->brightness_level,
41337+ event_mask);
41338 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
41339 /* repeated key presses that didn't change state */
41340 if (newn->brightness_level == 0)
41341@@ -2437,10 +2439,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41342 && !tp_features.bright_unkfw)
41343 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41344 }
41345+}
41346
41347 #undef TPACPI_COMPARE_KEY
41348 #undef TPACPI_MAY_SEND_KEY
41349-}
41350
41351 /*
41352 * Polling driver
41353diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
41354index 769d265..a3a05ca 100644
41355--- a/drivers/pnp/pnpbios/bioscalls.c
41356+++ b/drivers/pnp/pnpbios/bioscalls.c
41357@@ -58,7 +58,7 @@ do { \
41358 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
41359 } while(0)
41360
41361-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
41362+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
41363 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
41364
41365 /*
41366@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
41367
41368 cpu = get_cpu();
41369 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
41370+
41371+ pax_open_kernel();
41372 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
41373+ pax_close_kernel();
41374
41375 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
41376 spin_lock_irqsave(&pnp_bios_lock, flags);
41377@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
41378 :"memory");
41379 spin_unlock_irqrestore(&pnp_bios_lock, flags);
41380
41381+ pax_open_kernel();
41382 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
41383+ pax_close_kernel();
41384+
41385 put_cpu();
41386
41387 /* If we get here and this is set then the PnP BIOS faulted on us. */
41388@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
41389 return status;
41390 }
41391
41392-void pnpbios_calls_init(union pnp_bios_install_struct *header)
41393+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
41394 {
41395 int i;
41396
41397@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
41398 pnp_bios_callpoint.offset = header->fields.pm16offset;
41399 pnp_bios_callpoint.segment = PNP_CS16;
41400
41401+ pax_open_kernel();
41402+
41403 for_each_possible_cpu(i) {
41404 struct desc_struct *gdt = get_cpu_gdt_table(i);
41405 if (!gdt)
41406@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
41407 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
41408 (unsigned long)__va(header->fields.pm16dseg));
41409 }
41410+
41411+ pax_close_kernel();
41412 }
41413diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
41414index 3e6db1c..1fbbdae 100644
41415--- a/drivers/pnp/resource.c
41416+++ b/drivers/pnp/resource.c
41417@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
41418 return 1;
41419
41420 /* check if the resource is valid */
41421- if (*irq < 0 || *irq > 15)
41422+ if (*irq > 15)
41423 return 0;
41424
41425 /* check if the resource is reserved */
41426@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
41427 return 1;
41428
41429 /* check if the resource is valid */
41430- if (*dma < 0 || *dma == 4 || *dma > 7)
41431+ if (*dma == 4 || *dma > 7)
41432 return 0;
41433
41434 /* check if the resource is reserved */
41435diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
41436index 7df7c5f..bd48c47 100644
41437--- a/drivers/power/pda_power.c
41438+++ b/drivers/power/pda_power.c
41439@@ -37,7 +37,11 @@ static int polling;
41440
41441 #ifdef CONFIG_USB_OTG_UTILS
41442 static struct usb_phy *transceiver;
41443-static struct notifier_block otg_nb;
41444+static int otg_handle_notification(struct notifier_block *nb,
41445+ unsigned long event, void *unused);
41446+static struct notifier_block otg_nb = {
41447+ .notifier_call = otg_handle_notification
41448+};
41449 #endif
41450
41451 static struct regulator *ac_draw;
41452@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
41453
41454 #ifdef CONFIG_USB_OTG_UTILS
41455 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
41456- otg_nb.notifier_call = otg_handle_notification;
41457 ret = usb_register_notifier(transceiver, &otg_nb);
41458 if (ret) {
41459 dev_err(dev, "failure to register otg notifier\n");
41460diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
41461index cc439fd..8fa30df 100644
41462--- a/drivers/power/power_supply.h
41463+++ b/drivers/power/power_supply.h
41464@@ -16,12 +16,12 @@ struct power_supply;
41465
41466 #ifdef CONFIG_SYSFS
41467
41468-extern void power_supply_init_attrs(struct device_type *dev_type);
41469+extern void power_supply_init_attrs(void);
41470 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
41471
41472 #else
41473
41474-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
41475+static inline void power_supply_init_attrs(void) {}
41476 #define power_supply_uevent NULL
41477
41478 #endif /* CONFIG_SYSFS */
41479diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
41480index 5deac43..608c5ff 100644
41481--- a/drivers/power/power_supply_core.c
41482+++ b/drivers/power/power_supply_core.c
41483@@ -24,7 +24,10 @@
41484 struct class *power_supply_class;
41485 EXPORT_SYMBOL_GPL(power_supply_class);
41486
41487-static struct device_type power_supply_dev_type;
41488+extern const struct attribute_group *power_supply_attr_groups[];
41489+static struct device_type power_supply_dev_type = {
41490+ .groups = power_supply_attr_groups,
41491+};
41492
41493 static int __power_supply_changed_work(struct device *dev, void *data)
41494 {
41495@@ -393,7 +396,7 @@ static int __init power_supply_class_init(void)
41496 return PTR_ERR(power_supply_class);
41497
41498 power_supply_class->dev_uevent = power_supply_uevent;
41499- power_supply_init_attrs(&power_supply_dev_type);
41500+ power_supply_init_attrs();
41501
41502 return 0;
41503 }
41504diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
41505index 29178f7..c65f324 100644
41506--- a/drivers/power/power_supply_sysfs.c
41507+++ b/drivers/power/power_supply_sysfs.c
41508@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
41509 .is_visible = power_supply_attr_is_visible,
41510 };
41511
41512-static const struct attribute_group *power_supply_attr_groups[] = {
41513+const struct attribute_group *power_supply_attr_groups[] = {
41514 &power_supply_attr_group,
41515 NULL,
41516 };
41517
41518-void power_supply_init_attrs(struct device_type *dev_type)
41519+void power_supply_init_attrs(void)
41520 {
41521 int i;
41522
41523- dev_type->groups = power_supply_attr_groups;
41524-
41525 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
41526 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
41527 }
41528diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
41529index 4d7c635..9860196 100644
41530--- a/drivers/regulator/max8660.c
41531+++ b/drivers/regulator/max8660.c
41532@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
41533 max8660->shadow_regs[MAX8660_OVER1] = 5;
41534 } else {
41535 /* Otherwise devices can be toggled via software */
41536- max8660_dcdc_ops.enable = max8660_dcdc_enable;
41537- max8660_dcdc_ops.disable = max8660_dcdc_disable;
41538+ pax_open_kernel();
41539+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
41540+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
41541+ pax_close_kernel();
41542 }
41543
41544 /*
41545diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
41546index 9a8ea91..c483dd9 100644
41547--- a/drivers/regulator/max8973-regulator.c
41548+++ b/drivers/regulator/max8973-regulator.c
41549@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
41550 if (!pdata->enable_ext_control) {
41551 max->desc.enable_reg = MAX8973_VOUT;
41552 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
41553- max8973_dcdc_ops.enable = regulator_enable_regmap;
41554- max8973_dcdc_ops.disable = regulator_disable_regmap;
41555- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41556+ pax_open_kernel();
41557+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
41558+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
41559+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41560+ pax_close_kernel();
41561 }
41562
41563 max->enable_external_control = pdata->enable_ext_control;
41564diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
41565index 9891aec..beb3083 100644
41566--- a/drivers/regulator/mc13892-regulator.c
41567+++ b/drivers/regulator/mc13892-regulator.c
41568@@ -583,10 +583,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
41569 }
41570 mc13xxx_unlock(mc13892);
41571
41572- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41573+ pax_open_kernel();
41574+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41575 = mc13892_vcam_set_mode;
41576- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41577+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41578 = mc13892_vcam_get_mode;
41579+ pax_close_kernel();
41580
41581 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
41582 ARRAY_SIZE(mc13892_regulators),
41583diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
41584index cc5bea9..689f7d9 100644
41585--- a/drivers/rtc/rtc-cmos.c
41586+++ b/drivers/rtc/rtc-cmos.c
41587@@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
41588 hpet_rtc_timer_init();
41589
41590 /* export at least the first block of NVRAM */
41591- nvram.size = address_space - NVRAM_OFFSET;
41592+ pax_open_kernel();
41593+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
41594+ pax_close_kernel();
41595 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
41596 if (retval < 0) {
41597 dev_dbg(dev, "can't create nvram file? %d\n", retval);
41598diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
41599index d049393..bb20be0 100644
41600--- a/drivers/rtc/rtc-dev.c
41601+++ b/drivers/rtc/rtc-dev.c
41602@@ -16,6 +16,7 @@
41603 #include <linux/module.h>
41604 #include <linux/rtc.h>
41605 #include <linux/sched.h>
41606+#include <linux/grsecurity.h>
41607 #include "rtc-core.h"
41608
41609 static dev_t rtc_devt;
41610@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
41611 if (copy_from_user(&tm, uarg, sizeof(tm)))
41612 return -EFAULT;
41613
41614+ gr_log_timechange();
41615+
41616 return rtc_set_time(rtc, &tm);
41617
41618 case RTC_PIE_ON:
41619diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
41620index 970a236..3613169 100644
41621--- a/drivers/rtc/rtc-ds1307.c
41622+++ b/drivers/rtc/rtc-ds1307.c
41623@@ -106,7 +106,7 @@ struct ds1307 {
41624 u8 offset; /* register's offset */
41625 u8 regs[11];
41626 u16 nvram_offset;
41627- struct bin_attribute *nvram;
41628+ bin_attribute_no_const *nvram;
41629 enum ds_type type;
41630 unsigned long flags;
41631 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
41632diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
41633index 130f29a..6179d03 100644
41634--- a/drivers/rtc/rtc-m48t59.c
41635+++ b/drivers/rtc/rtc-m48t59.c
41636@@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
41637 goto out;
41638 }
41639
41640- m48t59_nvram_attr.size = pdata->offset;
41641+ pax_open_kernel();
41642+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
41643+ pax_close_kernel();
41644
41645 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
41646 if (ret) {
41647diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
41648index e693af6..2e525b6 100644
41649--- a/drivers/scsi/bfa/bfa_fcpim.h
41650+++ b/drivers/scsi/bfa/bfa_fcpim.h
41651@@ -36,7 +36,7 @@ struct bfa_iotag_s {
41652
41653 struct bfa_itn_s {
41654 bfa_isr_func_t isr;
41655-};
41656+} __no_const;
41657
41658 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
41659 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
41660diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
41661index 23a90e7..9cf04ee 100644
41662--- a/drivers/scsi/bfa/bfa_ioc.h
41663+++ b/drivers/scsi/bfa/bfa_ioc.h
41664@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
41665 bfa_ioc_disable_cbfn_t disable_cbfn;
41666 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
41667 bfa_ioc_reset_cbfn_t reset_cbfn;
41668-};
41669+} __no_const;
41670
41671 /*
41672 * IOC event notification mechanism.
41673@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
41674 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
41675 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
41676 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
41677-};
41678+} __no_const;
41679
41680 /*
41681 * Queue element to wait for room in request queue. FIFO order is
41682diff --git a/drivers/scsi/bfa/bfad_debugfs.c b/drivers/scsi/bfa/bfad_debugfs.c
41683index 439c012..b63d534 100644
41684--- a/drivers/scsi/bfa/bfad_debugfs.c
41685+++ b/drivers/scsi/bfa/bfad_debugfs.c
41686@@ -186,7 +186,7 @@ bfad_debugfs_lseek(struct file *file, loff_t offset, int orig)
41687 file->f_pos += offset;
41688 break;
41689 case 2:
41690- file->f_pos = debug->buffer_len - offset;
41691+ file->f_pos = debug->buffer_len + offset;
41692 break;
41693 default:
41694 return -EINVAL;
41695diff --git a/drivers/scsi/fnic/fnic_debugfs.c b/drivers/scsi/fnic/fnic_debugfs.c
41696index adc1f7f..85e1ffd 100644
41697--- a/drivers/scsi/fnic/fnic_debugfs.c
41698+++ b/drivers/scsi/fnic/fnic_debugfs.c
41699@@ -174,7 +174,7 @@ static loff_t fnic_trace_debugfs_lseek(struct file *file,
41700 pos = file->f_pos + offset;
41701 break;
41702 case 2:
41703- pos = fnic_dbg_prt->buffer_len - offset;
41704+ pos = fnic_dbg_prt->buffer_len + offset;
41705 }
41706 return (pos < 0 || pos > fnic_dbg_prt->buffer_len) ?
41707 -EINVAL : (file->f_pos = pos);
41708diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
41709index df0c3c7..b00e1d0 100644
41710--- a/drivers/scsi/hosts.c
41711+++ b/drivers/scsi/hosts.c
41712@@ -42,7 +42,7 @@
41713 #include "scsi_logging.h"
41714
41715
41716-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
41717+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
41718
41719
41720 static void scsi_host_cls_release(struct device *dev)
41721@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
41722 * subtract one because we increment first then return, but we need to
41723 * know what the next host number was before increment
41724 */
41725- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
41726+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
41727 shost->dma_channel = 0xff;
41728
41729 /* These three are default values which can be overridden */
41730diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
41731index 7f4f790..b75b92a 100644
41732--- a/drivers/scsi/hpsa.c
41733+++ b/drivers/scsi/hpsa.c
41734@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
41735 unsigned long flags;
41736
41737 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
41738- return h->access.command_completed(h, q);
41739+ return h->access->command_completed(h, q);
41740
41741 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
41742 a = rq->head[rq->current_entry];
41743@@ -3422,7 +3422,7 @@ static void start_io(struct ctlr_info *h)
41744 while (!list_empty(&h->reqQ)) {
41745 c = list_entry(h->reqQ.next, struct CommandList, list);
41746 /* can't do anything if fifo is full */
41747- if ((h->access.fifo_full(h))) {
41748+ if ((h->access->fifo_full(h))) {
41749 dev_warn(&h->pdev->dev, "fifo full\n");
41750 break;
41751 }
41752@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
41753
41754 /* Tell the controller execute command */
41755 spin_unlock_irqrestore(&h->lock, flags);
41756- h->access.submit_command(h, c);
41757+ h->access->submit_command(h, c);
41758 spin_lock_irqsave(&h->lock, flags);
41759 }
41760 spin_unlock_irqrestore(&h->lock, flags);
41761@@ -3452,17 +3452,17 @@ static void start_io(struct ctlr_info *h)
41762
41763 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
41764 {
41765- return h->access.command_completed(h, q);
41766+ return h->access->command_completed(h, q);
41767 }
41768
41769 static inline bool interrupt_pending(struct ctlr_info *h)
41770 {
41771- return h->access.intr_pending(h);
41772+ return h->access->intr_pending(h);
41773 }
41774
41775 static inline long interrupt_not_for_us(struct ctlr_info *h)
41776 {
41777- return (h->access.intr_pending(h) == 0) ||
41778+ return (h->access->intr_pending(h) == 0) ||
41779 (h->interrupts_enabled == 0);
41780 }
41781
41782@@ -4364,7 +4364,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
41783 if (prod_index < 0)
41784 return -ENODEV;
41785 h->product_name = products[prod_index].product_name;
41786- h->access = *(products[prod_index].access);
41787+ h->access = products[prod_index].access;
41788
41789 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
41790 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
41791@@ -4646,7 +4646,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
41792
41793 assert_spin_locked(&lockup_detector_lock);
41794 remove_ctlr_from_lockup_detector_list(h);
41795- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41796+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41797 spin_lock_irqsave(&h->lock, flags);
41798 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
41799 spin_unlock_irqrestore(&h->lock, flags);
41800@@ -4823,7 +4823,7 @@ reinit_after_soft_reset:
41801 }
41802
41803 /* make sure the board interrupts are off */
41804- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41805+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41806
41807 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
41808 goto clean2;
41809@@ -4857,7 +4857,7 @@ reinit_after_soft_reset:
41810 * fake ones to scoop up any residual completions.
41811 */
41812 spin_lock_irqsave(&h->lock, flags);
41813- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41814+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41815 spin_unlock_irqrestore(&h->lock, flags);
41816 free_irqs(h);
41817 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
41818@@ -4876,9 +4876,9 @@ reinit_after_soft_reset:
41819 dev_info(&h->pdev->dev, "Board READY.\n");
41820 dev_info(&h->pdev->dev,
41821 "Waiting for stale completions to drain.\n");
41822- h->access.set_intr_mask(h, HPSA_INTR_ON);
41823+ h->access->set_intr_mask(h, HPSA_INTR_ON);
41824 msleep(10000);
41825- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41826+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41827
41828 rc = controller_reset_failed(h->cfgtable);
41829 if (rc)
41830@@ -4899,7 +4899,7 @@ reinit_after_soft_reset:
41831 }
41832
41833 /* Turn the interrupts on so we can service requests */
41834- h->access.set_intr_mask(h, HPSA_INTR_ON);
41835+ h->access->set_intr_mask(h, HPSA_INTR_ON);
41836
41837 hpsa_hba_inquiry(h);
41838 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
41839@@ -4954,7 +4954,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
41840 * To write all data in the battery backed cache to disks
41841 */
41842 hpsa_flush_cache(h);
41843- h->access.set_intr_mask(h, HPSA_INTR_OFF);
41844+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
41845 hpsa_free_irqs_and_disable_msix(h);
41846 }
41847
41848@@ -5122,7 +5122,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
41849 return;
41850 }
41851 /* Change the access methods to the performant access methods */
41852- h->access = SA5_performant_access;
41853+ h->access = &SA5_performant_access;
41854 h->transMethod = CFGTBL_Trans_Performant;
41855 }
41856
41857diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
41858index 9816479..c5d4e97 100644
41859--- a/drivers/scsi/hpsa.h
41860+++ b/drivers/scsi/hpsa.h
41861@@ -79,7 +79,7 @@ struct ctlr_info {
41862 unsigned int msix_vector;
41863 unsigned int msi_vector;
41864 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
41865- struct access_method access;
41866+ struct access_method *access;
41867
41868 /* queue and queue Info */
41869 struct list_head reqQ;
41870diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
41871index c772d8d..35c362c 100644
41872--- a/drivers/scsi/libfc/fc_exch.c
41873+++ b/drivers/scsi/libfc/fc_exch.c
41874@@ -100,12 +100,12 @@ struct fc_exch_mgr {
41875 u16 pool_max_index;
41876
41877 struct {
41878- atomic_t no_free_exch;
41879- atomic_t no_free_exch_xid;
41880- atomic_t xid_not_found;
41881- atomic_t xid_busy;
41882- atomic_t seq_not_found;
41883- atomic_t non_bls_resp;
41884+ atomic_unchecked_t no_free_exch;
41885+ atomic_unchecked_t no_free_exch_xid;
41886+ atomic_unchecked_t xid_not_found;
41887+ atomic_unchecked_t xid_busy;
41888+ atomic_unchecked_t seq_not_found;
41889+ atomic_unchecked_t non_bls_resp;
41890 } stats;
41891 };
41892
41893@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
41894 /* allocate memory for exchange */
41895 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
41896 if (!ep) {
41897- atomic_inc(&mp->stats.no_free_exch);
41898+ atomic_inc_unchecked(&mp->stats.no_free_exch);
41899 goto out;
41900 }
41901 memset(ep, 0, sizeof(*ep));
41902@@ -786,7 +786,7 @@ out:
41903 return ep;
41904 err:
41905 spin_unlock_bh(&pool->lock);
41906- atomic_inc(&mp->stats.no_free_exch_xid);
41907+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
41908 mempool_free(ep, mp->ep_pool);
41909 return NULL;
41910 }
41911@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41912 xid = ntohs(fh->fh_ox_id); /* we originated exch */
41913 ep = fc_exch_find(mp, xid);
41914 if (!ep) {
41915- atomic_inc(&mp->stats.xid_not_found);
41916+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41917 reject = FC_RJT_OX_ID;
41918 goto out;
41919 }
41920@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41921 ep = fc_exch_find(mp, xid);
41922 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
41923 if (ep) {
41924- atomic_inc(&mp->stats.xid_busy);
41925+ atomic_inc_unchecked(&mp->stats.xid_busy);
41926 reject = FC_RJT_RX_ID;
41927 goto rel;
41928 }
41929@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41930 }
41931 xid = ep->xid; /* get our XID */
41932 } else if (!ep) {
41933- atomic_inc(&mp->stats.xid_not_found);
41934+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41935 reject = FC_RJT_RX_ID; /* XID not found */
41936 goto out;
41937 }
41938@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41939 } else {
41940 sp = &ep->seq;
41941 if (sp->id != fh->fh_seq_id) {
41942- atomic_inc(&mp->stats.seq_not_found);
41943+ atomic_inc_unchecked(&mp->stats.seq_not_found);
41944 if (f_ctl & FC_FC_END_SEQ) {
41945 /*
41946 * Update sequence_id based on incoming last
41947@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41948
41949 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
41950 if (!ep) {
41951- atomic_inc(&mp->stats.xid_not_found);
41952+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41953 goto out;
41954 }
41955 if (ep->esb_stat & ESB_ST_COMPLETE) {
41956- atomic_inc(&mp->stats.xid_not_found);
41957+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41958 goto rel;
41959 }
41960 if (ep->rxid == FC_XID_UNKNOWN)
41961 ep->rxid = ntohs(fh->fh_rx_id);
41962 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
41963- atomic_inc(&mp->stats.xid_not_found);
41964+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41965 goto rel;
41966 }
41967 if (ep->did != ntoh24(fh->fh_s_id) &&
41968 ep->did != FC_FID_FLOGI) {
41969- atomic_inc(&mp->stats.xid_not_found);
41970+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41971 goto rel;
41972 }
41973 sof = fr_sof(fp);
41974@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41975 sp->ssb_stat |= SSB_ST_RESP;
41976 sp->id = fh->fh_seq_id;
41977 } else if (sp->id != fh->fh_seq_id) {
41978- atomic_inc(&mp->stats.seq_not_found);
41979+ atomic_inc_unchecked(&mp->stats.seq_not_found);
41980 goto rel;
41981 }
41982
41983@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41984 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
41985
41986 if (!sp)
41987- atomic_inc(&mp->stats.xid_not_found);
41988+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41989 else
41990- atomic_inc(&mp->stats.non_bls_resp);
41991+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
41992
41993 fc_frame_free(fp);
41994 }
41995@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
41996
41997 list_for_each_entry(ema, &lport->ema_list, ema_list) {
41998 mp = ema->mp;
41999- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
42000+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
42001 st->fc_no_free_exch_xid +=
42002- atomic_read(&mp->stats.no_free_exch_xid);
42003- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
42004- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
42005- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
42006- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
42007+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
42008+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
42009+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
42010+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
42011+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
42012 }
42013 }
42014 EXPORT_SYMBOL(fc_exch_update_stats);
42015diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
42016index bdb81cd..d3c7c2c 100644
42017--- a/drivers/scsi/libsas/sas_ata.c
42018+++ b/drivers/scsi/libsas/sas_ata.c
42019@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
42020 .postreset = ata_std_postreset,
42021 .error_handler = ata_std_error_handler,
42022 .post_internal_cmd = sas_ata_post_internal,
42023- .qc_defer = ata_std_qc_defer,
42024+ .qc_defer = ata_std_qc_defer,
42025 .qc_prep = ata_noop_qc_prep,
42026 .qc_issue = sas_ata_qc_issue,
42027 .qc_fill_rtf = sas_ata_qc_fill_rtf,
42028diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
42029index 7706c99..3b4fc0c 100644
42030--- a/drivers/scsi/lpfc/lpfc.h
42031+++ b/drivers/scsi/lpfc/lpfc.h
42032@@ -424,7 +424,7 @@ struct lpfc_vport {
42033 struct dentry *debug_nodelist;
42034 struct dentry *vport_debugfs_root;
42035 struct lpfc_debugfs_trc *disc_trc;
42036- atomic_t disc_trc_cnt;
42037+ atomic_unchecked_t disc_trc_cnt;
42038 #endif
42039 uint8_t stat_data_enabled;
42040 uint8_t stat_data_blocked;
42041@@ -853,8 +853,8 @@ struct lpfc_hba {
42042 struct timer_list fabric_block_timer;
42043 unsigned long bit_flags;
42044 #define FABRIC_COMANDS_BLOCKED 0
42045- atomic_t num_rsrc_err;
42046- atomic_t num_cmd_success;
42047+ atomic_unchecked_t num_rsrc_err;
42048+ atomic_unchecked_t num_cmd_success;
42049 unsigned long last_rsrc_error_time;
42050 unsigned long last_ramp_down_time;
42051 unsigned long last_ramp_up_time;
42052@@ -890,7 +890,7 @@ struct lpfc_hba {
42053
42054 struct dentry *debug_slow_ring_trc;
42055 struct lpfc_debugfs_trc *slow_ring_trc;
42056- atomic_t slow_ring_trc_cnt;
42057+ atomic_unchecked_t slow_ring_trc_cnt;
42058 /* iDiag debugfs sub-directory */
42059 struct dentry *idiag_root;
42060 struct dentry *idiag_pci_cfg;
42061diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
42062index f63f5ff..32549a4 100644
42063--- a/drivers/scsi/lpfc/lpfc_debugfs.c
42064+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
42065@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
42066
42067 #include <linux/debugfs.h>
42068
42069-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
42070+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
42071 static unsigned long lpfc_debugfs_start_time = 0L;
42072
42073 /* iDiag */
42074@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
42075 lpfc_debugfs_enable = 0;
42076
42077 len = 0;
42078- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
42079+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
42080 (lpfc_debugfs_max_disc_trc - 1);
42081 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
42082 dtp = vport->disc_trc + i;
42083@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
42084 lpfc_debugfs_enable = 0;
42085
42086 len = 0;
42087- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
42088+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
42089 (lpfc_debugfs_max_slow_ring_trc - 1);
42090 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
42091 dtp = phba->slow_ring_trc + i;
42092@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
42093 !vport || !vport->disc_trc)
42094 return;
42095
42096- index = atomic_inc_return(&vport->disc_trc_cnt) &
42097+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
42098 (lpfc_debugfs_max_disc_trc - 1);
42099 dtp = vport->disc_trc + index;
42100 dtp->fmt = fmt;
42101 dtp->data1 = data1;
42102 dtp->data2 = data2;
42103 dtp->data3 = data3;
42104- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42105+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42106 dtp->jif = jiffies;
42107 #endif
42108 return;
42109@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
42110 !phba || !phba->slow_ring_trc)
42111 return;
42112
42113- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
42114+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
42115 (lpfc_debugfs_max_slow_ring_trc - 1);
42116 dtp = phba->slow_ring_trc + index;
42117 dtp->fmt = fmt;
42118 dtp->data1 = data1;
42119 dtp->data2 = data2;
42120 dtp->data3 = data3;
42121- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42122+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42123 dtp->jif = jiffies;
42124 #endif
42125 return;
42126@@ -1178,7 +1178,7 @@ lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
42127 pos = file->f_pos + off;
42128 break;
42129 case 2:
42130- pos = debug->len - off;
42131+ pos = debug->len + off;
42132 }
42133 return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
42134 }
42135@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42136 "slow_ring buffer\n");
42137 goto debug_failed;
42138 }
42139- atomic_set(&phba->slow_ring_trc_cnt, 0);
42140+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
42141 memset(phba->slow_ring_trc, 0,
42142 (sizeof(struct lpfc_debugfs_trc) *
42143 lpfc_debugfs_max_slow_ring_trc));
42144@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42145 "buffer\n");
42146 goto debug_failed;
42147 }
42148- atomic_set(&vport->disc_trc_cnt, 0);
42149+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
42150
42151 snprintf(name, sizeof(name), "discovery_trace");
42152 vport->debug_disc_trc =
42153diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
42154index 314b4f6..7005d10 100644
42155--- a/drivers/scsi/lpfc/lpfc_init.c
42156+++ b/drivers/scsi/lpfc/lpfc_init.c
42157@@ -10551,8 +10551,10 @@ lpfc_init(void)
42158 "misc_register returned with status %d", error);
42159
42160 if (lpfc_enable_npiv) {
42161- lpfc_transport_functions.vport_create = lpfc_vport_create;
42162- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42163+ pax_open_kernel();
42164+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
42165+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42166+ pax_close_kernel();
42167 }
42168 lpfc_transport_template =
42169 fc_attach_transport(&lpfc_transport_functions);
42170diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
42171index 98af07c..7625fb5 100644
42172--- a/drivers/scsi/lpfc/lpfc_scsi.c
42173+++ b/drivers/scsi/lpfc/lpfc_scsi.c
42174@@ -325,7 +325,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
42175 uint32_t evt_posted;
42176
42177 spin_lock_irqsave(&phba->hbalock, flags);
42178- atomic_inc(&phba->num_rsrc_err);
42179+ atomic_inc_unchecked(&phba->num_rsrc_err);
42180 phba->last_rsrc_error_time = jiffies;
42181
42182 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
42183@@ -366,7 +366,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
42184 unsigned long flags;
42185 struct lpfc_hba *phba = vport->phba;
42186 uint32_t evt_posted;
42187- atomic_inc(&phba->num_cmd_success);
42188+ atomic_inc_unchecked(&phba->num_cmd_success);
42189
42190 if (vport->cfg_lun_queue_depth <= queue_depth)
42191 return;
42192@@ -410,8 +410,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42193 unsigned long num_rsrc_err, num_cmd_success;
42194 int i;
42195
42196- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
42197- num_cmd_success = atomic_read(&phba->num_cmd_success);
42198+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
42199+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
42200
42201 /*
42202 * The error and success command counters are global per
42203@@ -439,8 +439,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42204 }
42205 }
42206 lpfc_destroy_vport_work_array(phba, vports);
42207- atomic_set(&phba->num_rsrc_err, 0);
42208- atomic_set(&phba->num_cmd_success, 0);
42209+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42210+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42211 }
42212
42213 /**
42214@@ -474,8 +474,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
42215 }
42216 }
42217 lpfc_destroy_vport_work_array(phba, vports);
42218- atomic_set(&phba->num_rsrc_err, 0);
42219- atomic_set(&phba->num_cmd_success, 0);
42220+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42221+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42222 }
42223
42224 /**
42225diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
42226index b46f5e9..c4c4ccb 100644
42227--- a/drivers/scsi/pmcraid.c
42228+++ b/drivers/scsi/pmcraid.c
42229@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
42230 res->scsi_dev = scsi_dev;
42231 scsi_dev->hostdata = res;
42232 res->change_detected = 0;
42233- atomic_set(&res->read_failures, 0);
42234- atomic_set(&res->write_failures, 0);
42235+ atomic_set_unchecked(&res->read_failures, 0);
42236+ atomic_set_unchecked(&res->write_failures, 0);
42237 rc = 0;
42238 }
42239 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
42240@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
42241
42242 /* If this was a SCSI read/write command keep count of errors */
42243 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
42244- atomic_inc(&res->read_failures);
42245+ atomic_inc_unchecked(&res->read_failures);
42246 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
42247- atomic_inc(&res->write_failures);
42248+ atomic_inc_unchecked(&res->write_failures);
42249
42250 if (!RES_IS_GSCSI(res->cfg_entry) &&
42251 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
42252@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
42253 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
42254 * hrrq_id assigned here in queuecommand
42255 */
42256- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
42257+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
42258 pinstance->num_hrrq;
42259 cmd->cmd_done = pmcraid_io_done;
42260
42261@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
42262 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
42263 * hrrq_id assigned here in queuecommand
42264 */
42265- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
42266+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
42267 pinstance->num_hrrq;
42268
42269 if (request_size) {
42270@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
42271
42272 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
42273 /* add resources only after host is added into system */
42274- if (!atomic_read(&pinstance->expose_resources))
42275+ if (!atomic_read_unchecked(&pinstance->expose_resources))
42276 return;
42277
42278 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
42279@@ -5324,8 +5324,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
42280 init_waitqueue_head(&pinstance->reset_wait_q);
42281
42282 atomic_set(&pinstance->outstanding_cmds, 0);
42283- atomic_set(&pinstance->last_message_id, 0);
42284- atomic_set(&pinstance->expose_resources, 0);
42285+ atomic_set_unchecked(&pinstance->last_message_id, 0);
42286+ atomic_set_unchecked(&pinstance->expose_resources, 0);
42287
42288 INIT_LIST_HEAD(&pinstance->free_res_q);
42289 INIT_LIST_HEAD(&pinstance->used_res_q);
42290@@ -6038,7 +6038,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
42291 /* Schedule worker thread to handle CCN and take care of adding and
42292 * removing devices to OS
42293 */
42294- atomic_set(&pinstance->expose_resources, 1);
42295+ atomic_set_unchecked(&pinstance->expose_resources, 1);
42296 schedule_work(&pinstance->worker_q);
42297 return rc;
42298
42299diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
42300index e1d150f..6c6df44 100644
42301--- a/drivers/scsi/pmcraid.h
42302+++ b/drivers/scsi/pmcraid.h
42303@@ -748,7 +748,7 @@ struct pmcraid_instance {
42304 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
42305
42306 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
42307- atomic_t last_message_id;
42308+ atomic_unchecked_t last_message_id;
42309
42310 /* configuration table */
42311 struct pmcraid_config_table *cfg_table;
42312@@ -777,7 +777,7 @@ struct pmcraid_instance {
42313 atomic_t outstanding_cmds;
42314
42315 /* should add/delete resources to mid-layer now ?*/
42316- atomic_t expose_resources;
42317+ atomic_unchecked_t expose_resources;
42318
42319
42320
42321@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
42322 struct pmcraid_config_table_entry_ext cfg_entry_ext;
42323 };
42324 struct scsi_device *scsi_dev; /* Link scsi_device structure */
42325- atomic_t read_failures; /* count of failed READ commands */
42326- atomic_t write_failures; /* count of failed WRITE commands */
42327+ atomic_unchecked_t read_failures; /* count of failed READ commands */
42328+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
42329
42330 /* To indicate add/delete/modify during CCN */
42331 u8 change_detected;
42332diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
42333index b3db9dc..c3b1756 100644
42334--- a/drivers/scsi/qla2xxx/qla_attr.c
42335+++ b/drivers/scsi/qla2xxx/qla_attr.c
42336@@ -1971,7 +1971,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
42337 return 0;
42338 }
42339
42340-struct fc_function_template qla2xxx_transport_functions = {
42341+fc_function_template_no_const qla2xxx_transport_functions = {
42342
42343 .show_host_node_name = 1,
42344 .show_host_port_name = 1,
42345@@ -2018,7 +2018,7 @@ struct fc_function_template qla2xxx_transport_functions = {
42346 .bsg_timeout = qla24xx_bsg_timeout,
42347 };
42348
42349-struct fc_function_template qla2xxx_transport_vport_functions = {
42350+fc_function_template_no_const qla2xxx_transport_vport_functions = {
42351
42352 .show_host_node_name = 1,
42353 .show_host_port_name = 1,
42354diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
42355index b310fa9..b9b3944 100644
42356--- a/drivers/scsi/qla2xxx/qla_gbl.h
42357+++ b/drivers/scsi/qla2xxx/qla_gbl.h
42358@@ -523,8 +523,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
42359 struct device_attribute;
42360 extern struct device_attribute *qla2x00_host_attrs[];
42361 struct fc_function_template;
42362-extern struct fc_function_template qla2xxx_transport_functions;
42363-extern struct fc_function_template qla2xxx_transport_vport_functions;
42364+extern fc_function_template_no_const qla2xxx_transport_functions;
42365+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
42366 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
42367 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
42368 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
42369diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
42370index 2c6dd3d..e5ecd82 100644
42371--- a/drivers/scsi/qla2xxx/qla_os.c
42372+++ b/drivers/scsi/qla2xxx/qla_os.c
42373@@ -1554,8 +1554,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
42374 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
42375 /* Ok, a 64bit DMA mask is applicable. */
42376 ha->flags.enable_64bit_addressing = 1;
42377- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
42378- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
42379+ pax_open_kernel();
42380+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
42381+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
42382+ pax_close_kernel();
42383 return;
42384 }
42385 }
42386diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
42387index 129f5dd..ade53e8 100644
42388--- a/drivers/scsi/qla4xxx/ql4_def.h
42389+++ b/drivers/scsi/qla4xxx/ql4_def.h
42390@@ -275,7 +275,7 @@ struct ddb_entry {
42391 * (4000 only) */
42392 atomic_t relogin_timer; /* Max Time to wait for
42393 * relogin to complete */
42394- atomic_t relogin_retry_count; /* Num of times relogin has been
42395+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
42396 * retried */
42397 uint32_t default_time2wait; /* Default Min time between
42398 * relogins (+aens) */
42399diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
42400index 6142729..b6a85c9 100644
42401--- a/drivers/scsi/qla4xxx/ql4_os.c
42402+++ b/drivers/scsi/qla4xxx/ql4_os.c
42403@@ -2622,12 +2622,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
42404 */
42405 if (!iscsi_is_session_online(cls_sess)) {
42406 /* Reset retry relogin timer */
42407- atomic_inc(&ddb_entry->relogin_retry_count);
42408+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
42409 DEBUG2(ql4_printk(KERN_INFO, ha,
42410 "%s: index[%d] relogin timed out-retrying"
42411 " relogin (%d), retry (%d)\n", __func__,
42412 ddb_entry->fw_ddb_index,
42413- atomic_read(&ddb_entry->relogin_retry_count),
42414+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
42415 ddb_entry->default_time2wait + 4));
42416 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
42417 atomic_set(&ddb_entry->retry_relogin_timer,
42418@@ -4742,7 +4742,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
42419
42420 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
42421 atomic_set(&ddb_entry->relogin_timer, 0);
42422- atomic_set(&ddb_entry->relogin_retry_count, 0);
42423+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
42424 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
42425 ddb_entry->default_relogin_timeout =
42426 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
42427diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
42428index 2c0d0ec..4e8681a 100644
42429--- a/drivers/scsi/scsi.c
42430+++ b/drivers/scsi/scsi.c
42431@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
42432 unsigned long timeout;
42433 int rtn = 0;
42434
42435- atomic_inc(&cmd->device->iorequest_cnt);
42436+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
42437
42438 /* check if the device is still usable */
42439 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
42440diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
42441index c31187d..0ead8c3 100644
42442--- a/drivers/scsi/scsi_lib.c
42443+++ b/drivers/scsi/scsi_lib.c
42444@@ -1459,7 +1459,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
42445 shost = sdev->host;
42446 scsi_init_cmd_errh(cmd);
42447 cmd->result = DID_NO_CONNECT << 16;
42448- atomic_inc(&cmd->device->iorequest_cnt);
42449+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
42450
42451 /*
42452 * SCSI request completion path will do scsi_device_unbusy(),
42453@@ -1485,9 +1485,9 @@ static void scsi_softirq_done(struct request *rq)
42454
42455 INIT_LIST_HEAD(&cmd->eh_entry);
42456
42457- atomic_inc(&cmd->device->iodone_cnt);
42458+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
42459 if (cmd->result)
42460- atomic_inc(&cmd->device->ioerr_cnt);
42461+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
42462
42463 disposition = scsi_decide_disposition(cmd);
42464 if (disposition != SUCCESS &&
42465diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
42466index 931a7d9..0c2a754 100644
42467--- a/drivers/scsi/scsi_sysfs.c
42468+++ b/drivers/scsi/scsi_sysfs.c
42469@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
42470 char *buf) \
42471 { \
42472 struct scsi_device *sdev = to_scsi_device(dev); \
42473- unsigned long long count = atomic_read(&sdev->field); \
42474+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
42475 return snprintf(buf, 20, "0x%llx\n", count); \
42476 } \
42477 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
42478diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
42479index 84a1fdf..693b0d6 100644
42480--- a/drivers/scsi/scsi_tgt_lib.c
42481+++ b/drivers/scsi/scsi_tgt_lib.c
42482@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
42483 int err;
42484
42485 dprintk("%lx %u\n", uaddr, len);
42486- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
42487+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
42488 if (err) {
42489 /*
42490 * TODO: need to fixup sg_tablesize, max_segment_size,
42491diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
42492index e894ca7..de9d7660 100644
42493--- a/drivers/scsi/scsi_transport_fc.c
42494+++ b/drivers/scsi/scsi_transport_fc.c
42495@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
42496 * Netlink Infrastructure
42497 */
42498
42499-static atomic_t fc_event_seq;
42500+static atomic_unchecked_t fc_event_seq;
42501
42502 /**
42503 * fc_get_event_number - Obtain the next sequential FC event number
42504@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
42505 u32
42506 fc_get_event_number(void)
42507 {
42508- return atomic_add_return(1, &fc_event_seq);
42509+ return atomic_add_return_unchecked(1, &fc_event_seq);
42510 }
42511 EXPORT_SYMBOL(fc_get_event_number);
42512
42513@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
42514 {
42515 int error;
42516
42517- atomic_set(&fc_event_seq, 0);
42518+ atomic_set_unchecked(&fc_event_seq, 0);
42519
42520 error = transport_class_register(&fc_host_class);
42521 if (error)
42522@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
42523 char *cp;
42524
42525 *val = simple_strtoul(buf, &cp, 0);
42526- if ((*cp && (*cp != '\n')) || (*val < 0))
42527+ if (*cp && (*cp != '\n'))
42528 return -EINVAL;
42529 /*
42530 * Check for overflow; dev_loss_tmo is u32
42531diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
42532index 0a74b97..fa8d648 100644
42533--- a/drivers/scsi/scsi_transport_iscsi.c
42534+++ b/drivers/scsi/scsi_transport_iscsi.c
42535@@ -79,7 +79,7 @@ struct iscsi_internal {
42536 struct transport_container session_cont;
42537 };
42538
42539-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
42540+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
42541 static struct workqueue_struct *iscsi_eh_timer_workq;
42542
42543 static DEFINE_IDA(iscsi_sess_ida);
42544@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
42545 int err;
42546
42547 ihost = shost->shost_data;
42548- session->sid = atomic_add_return(1, &iscsi_session_nr);
42549+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
42550
42551 if (target_id == ISCSI_MAX_TARGET) {
42552 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
42553@@ -2955,7 +2955,7 @@ static __init int iscsi_transport_init(void)
42554 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
42555 ISCSI_TRANSPORT_VERSION);
42556
42557- atomic_set(&iscsi_session_nr, 0);
42558+ atomic_set_unchecked(&iscsi_session_nr, 0);
42559
42560 err = class_register(&iscsi_transport_class);
42561 if (err)
42562diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
42563index f379c7f..e8fc69c 100644
42564--- a/drivers/scsi/scsi_transport_srp.c
42565+++ b/drivers/scsi/scsi_transport_srp.c
42566@@ -33,7 +33,7 @@
42567 #include "scsi_transport_srp_internal.h"
42568
42569 struct srp_host_attrs {
42570- atomic_t next_port_id;
42571+ atomic_unchecked_t next_port_id;
42572 };
42573 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
42574
42575@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
42576 struct Scsi_Host *shost = dev_to_shost(dev);
42577 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
42578
42579- atomic_set(&srp_host->next_port_id, 0);
42580+ atomic_set_unchecked(&srp_host->next_port_id, 0);
42581 return 0;
42582 }
42583
42584@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
42585 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
42586 rport->roles = ids->roles;
42587
42588- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
42589+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
42590 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
42591
42592 transport_setup_device(&rport->dev);
42593diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
42594index 82910cc..7c350ad 100644
42595--- a/drivers/scsi/sd.c
42596+++ b/drivers/scsi/sd.c
42597@@ -2929,7 +2929,7 @@ static int sd_probe(struct device *dev)
42598 sdkp->disk = gd;
42599 sdkp->index = index;
42600 atomic_set(&sdkp->openers, 0);
42601- atomic_set(&sdkp->device->ioerr_cnt, 0);
42602+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
42603
42604 if (!sdp->request_queue->rq_timeout) {
42605 if (sdp->type != TYPE_MOD)
42606diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
42607index 9f0c465..47194ee 100644
42608--- a/drivers/scsi/sg.c
42609+++ b/drivers/scsi/sg.c
42610@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
42611 sdp->disk->disk_name,
42612 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
42613 NULL,
42614- (char *)arg);
42615+ (char __user *)arg);
42616 case BLKTRACESTART:
42617 return blk_trace_startstop(sdp->device->request_queue, 1);
42618 case BLKTRACESTOP:
42619diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
42620index 004b10f..7c98d51 100644
42621--- a/drivers/spi/spi.c
42622+++ b/drivers/spi/spi.c
42623@@ -1620,7 +1620,7 @@ int spi_bus_unlock(struct spi_master *master)
42624 EXPORT_SYMBOL_GPL(spi_bus_unlock);
42625
42626 /* portable code must never pass more than 32 bytes */
42627-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
42628+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
42629
42630 static u8 *buf;
42631
42632diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c
42633index 93af756..a4bc5bf 100644
42634--- a/drivers/staging/iio/iio_hwmon.c
42635+++ b/drivers/staging/iio/iio_hwmon.c
42636@@ -67,7 +67,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
42637 {
42638 struct device *dev = &pdev->dev;
42639 struct iio_hwmon_state *st;
42640- struct sensor_device_attribute *a;
42641+ sensor_device_attribute_no_const *a;
42642 int ret, i;
42643 int in_i = 1, temp_i = 1, curr_i = 1;
42644 enum iio_chan_type type;
42645diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
42646index 34afc16..ffe44dd 100644
42647--- a/drivers/staging/octeon/ethernet-rx.c
42648+++ b/drivers/staging/octeon/ethernet-rx.c
42649@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
42650 /* Increment RX stats for virtual ports */
42651 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
42652 #ifdef CONFIG_64BIT
42653- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
42654- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
42655+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
42656+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
42657 #else
42658- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
42659- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
42660+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
42661+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
42662 #endif
42663 }
42664 netif_receive_skb(skb);
42665@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
42666 dev->name);
42667 */
42668 #ifdef CONFIG_64BIT
42669- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
42670+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
42671 #else
42672- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
42673+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
42674 #endif
42675 dev_kfree_skb_irq(skb);
42676 }
42677diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
42678index c3a90e7..023619a 100644
42679--- a/drivers/staging/octeon/ethernet.c
42680+++ b/drivers/staging/octeon/ethernet.c
42681@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
42682 * since the RX tasklet also increments it.
42683 */
42684 #ifdef CONFIG_64BIT
42685- atomic64_add(rx_status.dropped_packets,
42686- (atomic64_t *)&priv->stats.rx_dropped);
42687+ atomic64_add_unchecked(rx_status.dropped_packets,
42688+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
42689 #else
42690- atomic_add(rx_status.dropped_packets,
42691- (atomic_t *)&priv->stats.rx_dropped);
42692+ atomic_add_unchecked(rx_status.dropped_packets,
42693+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
42694 #endif
42695 }
42696
42697diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
42698index dc23395..cf7e9b1 100644
42699--- a/drivers/staging/rtl8712/rtl871x_io.h
42700+++ b/drivers/staging/rtl8712/rtl871x_io.h
42701@@ -108,7 +108,7 @@ struct _io_ops {
42702 u8 *pmem);
42703 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
42704 u8 *pmem);
42705-};
42706+} __no_const;
42707
42708 struct io_req {
42709 struct list_head list;
42710diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
42711index 1f5088b..0e59820 100644
42712--- a/drivers/staging/sbe-2t3e3/netdev.c
42713+++ b/drivers/staging/sbe-2t3e3/netdev.c
42714@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
42715 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
42716
42717 if (rlen)
42718- if (copy_to_user(data, &resp, rlen))
42719+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
42720 return -EFAULT;
42721
42722 return 0;
42723diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
42724index 5dddc4d..34fcb2f 100644
42725--- a/drivers/staging/usbip/vhci.h
42726+++ b/drivers/staging/usbip/vhci.h
42727@@ -83,7 +83,7 @@ struct vhci_hcd {
42728 unsigned resuming:1;
42729 unsigned long re_timeout;
42730
42731- atomic_t seqnum;
42732+ atomic_unchecked_t seqnum;
42733
42734 /*
42735 * NOTE:
42736diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
42737index f1ca084..7b5c0c3 100644
42738--- a/drivers/staging/usbip/vhci_hcd.c
42739+++ b/drivers/staging/usbip/vhci_hcd.c
42740@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
42741
42742 spin_lock(&vdev->priv_lock);
42743
42744- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
42745+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42746 if (priv->seqnum == 0xffff)
42747 dev_info(&urb->dev->dev, "seqnum max\n");
42748
42749@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
42750 return -ENOMEM;
42751 }
42752
42753- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
42754+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42755 if (unlink->seqnum == 0xffff)
42756 pr_info("seqnum max\n");
42757
42758@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
42759 vdev->rhport = rhport;
42760 }
42761
42762- atomic_set(&vhci->seqnum, 0);
42763+ atomic_set_unchecked(&vhci->seqnum, 0);
42764 spin_lock_init(&vhci->lock);
42765
42766 hcd->power_budget = 0; /* no limit */
42767diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
42768index faf8e60..c46f8ab 100644
42769--- a/drivers/staging/usbip/vhci_rx.c
42770+++ b/drivers/staging/usbip/vhci_rx.c
42771@@ -76,7 +76,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
42772 if (!urb) {
42773 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
42774 pr_info("max seqnum %d\n",
42775- atomic_read(&the_controller->seqnum));
42776+ atomic_read_unchecked(&the_controller->seqnum));
42777 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
42778 return;
42779 }
42780diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
42781index 5f13890..36a044b 100644
42782--- a/drivers/staging/vt6655/hostap.c
42783+++ b/drivers/staging/vt6655/hostap.c
42784@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
42785 *
42786 */
42787
42788+static net_device_ops_no_const apdev_netdev_ops;
42789+
42790 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42791 {
42792 PSDevice apdev_priv;
42793 struct net_device *dev = pDevice->dev;
42794 int ret;
42795- const struct net_device_ops apdev_netdev_ops = {
42796- .ndo_start_xmit = pDevice->tx_80211,
42797- };
42798
42799 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
42800
42801@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42802 *apdev_priv = *pDevice;
42803 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
42804
42805+ /* only half broken now */
42806+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
42807 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
42808
42809 pDevice->apdev->type = ARPHRD_IEEE80211;
42810diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
42811index a94e66f..31984d0 100644
42812--- a/drivers/staging/vt6656/hostap.c
42813+++ b/drivers/staging/vt6656/hostap.c
42814@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
42815 *
42816 */
42817
42818+static net_device_ops_no_const apdev_netdev_ops;
42819+
42820 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
42821 {
42822 struct vnt_private *apdev_priv;
42823 struct net_device *dev = pDevice->dev;
42824 int ret;
42825- const struct net_device_ops apdev_netdev_ops = {
42826- .ndo_start_xmit = pDevice->tx_80211,
42827- };
42828
42829 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
42830
42831@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
42832 *apdev_priv = *pDevice;
42833 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
42834
42835+ /* only half broken now */
42836+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
42837 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
42838
42839 pDevice->apdev->type = ARPHRD_IEEE80211;
42840diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
42841index a2b7e03..9ff4bbd 100644
42842--- a/drivers/staging/zcache/tmem.c
42843+++ b/drivers/staging/zcache/tmem.c
42844@@ -50,7 +50,7 @@
42845 * A tmem host implementation must use this function to register callbacks
42846 * for memory allocation.
42847 */
42848-static struct tmem_hostops tmem_hostops;
42849+static tmem_hostops_no_const tmem_hostops;
42850
42851 static void tmem_objnode_tree_init(void);
42852
42853@@ -64,7 +64,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
42854 * A tmem host implementation must use this function to register
42855 * callbacks for a page-accessible memory (PAM) implementation.
42856 */
42857-static struct tmem_pamops tmem_pamops;
42858+static tmem_pamops_no_const tmem_pamops;
42859
42860 void tmem_register_pamops(struct tmem_pamops *m)
42861 {
42862diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
42863index adbe5a8..d387359 100644
42864--- a/drivers/staging/zcache/tmem.h
42865+++ b/drivers/staging/zcache/tmem.h
42866@@ -226,6 +226,7 @@ struct tmem_pamops {
42867 int (*replace_in_obj)(void *, struct tmem_obj *);
42868 #endif
42869 };
42870+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
42871 extern void tmem_register_pamops(struct tmem_pamops *m);
42872
42873 /* memory allocation methods provided by the host implementation */
42874@@ -235,6 +236,7 @@ struct tmem_hostops {
42875 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
42876 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
42877 };
42878+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
42879 extern void tmem_register_hostops(struct tmem_hostops *m);
42880
42881 /* core tmem accessor functions */
42882diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
42883index 2e4d655..fd72e68 100644
42884--- a/drivers/target/target_core_device.c
42885+++ b/drivers/target/target_core_device.c
42886@@ -1414,7 +1414,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
42887 spin_lock_init(&dev->se_port_lock);
42888 spin_lock_init(&dev->se_tmr_lock);
42889 spin_lock_init(&dev->qf_cmd_lock);
42890- atomic_set(&dev->dev_ordered_id, 0);
42891+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
42892 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
42893 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
42894 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
42895diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
42896index fc9a5a0..1d5975e 100644
42897--- a/drivers/target/target_core_transport.c
42898+++ b/drivers/target/target_core_transport.c
42899@@ -1081,7 +1081,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
42900 * Used to determine when ORDERED commands should go from
42901 * Dormant to Active status.
42902 */
42903- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
42904+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
42905 smp_mb__after_atomic_inc();
42906 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
42907 cmd->se_ordered_id, cmd->sam_task_attr,
42908diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
42909index 345bd0e..61d5375 100644
42910--- a/drivers/tty/cyclades.c
42911+++ b/drivers/tty/cyclades.c
42912@@ -1576,10 +1576,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
42913 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
42914 info->port.count);
42915 #endif
42916- info->port.count++;
42917+ atomic_inc(&info->port.count);
42918 #ifdef CY_DEBUG_COUNT
42919 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
42920- current->pid, info->port.count);
42921+ current->pid, atomic_read(&info->port.count));
42922 #endif
42923
42924 /*
42925@@ -3978,7 +3978,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
42926 for (j = 0; j < cy_card[i].nports; j++) {
42927 info = &cy_card[i].ports[j];
42928
42929- if (info->port.count) {
42930+ if (atomic_read(&info->port.count)) {
42931 /* XXX is the ldisc num worth this? */
42932 struct tty_struct *tty;
42933 struct tty_ldisc *ld;
42934diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
42935index eb255e8..f637a57 100644
42936--- a/drivers/tty/hvc/hvc_console.c
42937+++ b/drivers/tty/hvc/hvc_console.c
42938@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
42939
42940 spin_lock_irqsave(&hp->port.lock, flags);
42941 /* Check and then increment for fast path open. */
42942- if (hp->port.count++ > 0) {
42943+ if (atomic_inc_return(&hp->port.count) > 1) {
42944 spin_unlock_irqrestore(&hp->port.lock, flags);
42945 hvc_kick();
42946 return 0;
42947@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
42948
42949 spin_lock_irqsave(&hp->port.lock, flags);
42950
42951- if (--hp->port.count == 0) {
42952+ if (atomic_dec_return(&hp->port.count) == 0) {
42953 spin_unlock_irqrestore(&hp->port.lock, flags);
42954 /* We are done with the tty pointer now. */
42955 tty_port_tty_set(&hp->port, NULL);
42956@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
42957 */
42958 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
42959 } else {
42960- if (hp->port.count < 0)
42961+ if (atomic_read(&hp->port.count) < 0)
42962 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
42963- hp->vtermno, hp->port.count);
42964+ hp->vtermno, atomic_read(&hp->port.count));
42965 spin_unlock_irqrestore(&hp->port.lock, flags);
42966 }
42967 }
42968@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
42969 * open->hangup case this can be called after the final close so prevent
42970 * that from happening for now.
42971 */
42972- if (hp->port.count <= 0) {
42973+ if (atomic_read(&hp->port.count) <= 0) {
42974 spin_unlock_irqrestore(&hp->port.lock, flags);
42975 return;
42976 }
42977
42978- hp->port.count = 0;
42979+ atomic_set(&hp->port.count, 0);
42980 spin_unlock_irqrestore(&hp->port.lock, flags);
42981 tty_port_tty_set(&hp->port, NULL);
42982
42983@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
42984 return -EPIPE;
42985
42986 /* FIXME what's this (unprotected) check for? */
42987- if (hp->port.count <= 0)
42988+ if (atomic_read(&hp->port.count) <= 0)
42989 return -EIO;
42990
42991 spin_lock_irqsave(&hp->lock, flags);
42992diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
42993index 81e939e..95ead10 100644
42994--- a/drivers/tty/hvc/hvcs.c
42995+++ b/drivers/tty/hvc/hvcs.c
42996@@ -83,6 +83,7 @@
42997 #include <asm/hvcserver.h>
42998 #include <asm/uaccess.h>
42999 #include <asm/vio.h>
43000+#include <asm/local.h>
43001
43002 /*
43003 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
43004@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
43005
43006 spin_lock_irqsave(&hvcsd->lock, flags);
43007
43008- if (hvcsd->port.count > 0) {
43009+ if (atomic_read(&hvcsd->port.count) > 0) {
43010 spin_unlock_irqrestore(&hvcsd->lock, flags);
43011 printk(KERN_INFO "HVCS: vterm state unchanged. "
43012 "The hvcs device node is still in use.\n");
43013@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
43014 }
43015 }
43016
43017- hvcsd->port.count = 0;
43018+ atomic_set(&hvcsd->port.count, 0);
43019 hvcsd->port.tty = tty;
43020 tty->driver_data = hvcsd;
43021
43022@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
43023 unsigned long flags;
43024
43025 spin_lock_irqsave(&hvcsd->lock, flags);
43026- hvcsd->port.count++;
43027+ atomic_inc(&hvcsd->port.count);
43028 hvcsd->todo_mask |= HVCS_SCHED_READ;
43029 spin_unlock_irqrestore(&hvcsd->lock, flags);
43030
43031@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
43032 hvcsd = tty->driver_data;
43033
43034 spin_lock_irqsave(&hvcsd->lock, flags);
43035- if (--hvcsd->port.count == 0) {
43036+ if (atomic_dec_and_test(&hvcsd->port.count)) {
43037
43038 vio_disable_interrupts(hvcsd->vdev);
43039
43040@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
43041
43042 free_irq(irq, hvcsd);
43043 return;
43044- } else if (hvcsd->port.count < 0) {
43045+ } else if (atomic_read(&hvcsd->port.count) < 0) {
43046 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
43047 " is missmanaged.\n",
43048- hvcsd->vdev->unit_address, hvcsd->port.count);
43049+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
43050 }
43051
43052 spin_unlock_irqrestore(&hvcsd->lock, flags);
43053@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
43054
43055 spin_lock_irqsave(&hvcsd->lock, flags);
43056 /* Preserve this so that we know how many kref refs to put */
43057- temp_open_count = hvcsd->port.count;
43058+ temp_open_count = atomic_read(&hvcsd->port.count);
43059
43060 /*
43061 * Don't kref put inside the spinlock because the destruction
43062@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
43063 tty->driver_data = NULL;
43064 hvcsd->port.tty = NULL;
43065
43066- hvcsd->port.count = 0;
43067+ atomic_set(&hvcsd->port.count, 0);
43068
43069 /* This will drop any buffered data on the floor which is OK in a hangup
43070 * scenario. */
43071@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
43072 * the middle of a write operation? This is a crummy place to do this
43073 * but we want to keep it all in the spinlock.
43074 */
43075- if (hvcsd->port.count <= 0) {
43076+ if (atomic_read(&hvcsd->port.count) <= 0) {
43077 spin_unlock_irqrestore(&hvcsd->lock, flags);
43078 return -ENODEV;
43079 }
43080@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
43081 {
43082 struct hvcs_struct *hvcsd = tty->driver_data;
43083
43084- if (!hvcsd || hvcsd->port.count <= 0)
43085+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
43086 return 0;
43087
43088 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
43089diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
43090index 8fd72ff..34a0bed 100644
43091--- a/drivers/tty/ipwireless/tty.c
43092+++ b/drivers/tty/ipwireless/tty.c
43093@@ -29,6 +29,7 @@
43094 #include <linux/tty_driver.h>
43095 #include <linux/tty_flip.h>
43096 #include <linux/uaccess.h>
43097+#include <asm/local.h>
43098
43099 #include "tty.h"
43100 #include "network.h"
43101@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
43102 mutex_unlock(&tty->ipw_tty_mutex);
43103 return -ENODEV;
43104 }
43105- if (tty->port.count == 0)
43106+ if (atomic_read(&tty->port.count) == 0)
43107 tty->tx_bytes_queued = 0;
43108
43109- tty->port.count++;
43110+ atomic_inc(&tty->port.count);
43111
43112 tty->port.tty = linux_tty;
43113 linux_tty->driver_data = tty;
43114@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
43115
43116 static void do_ipw_close(struct ipw_tty *tty)
43117 {
43118- tty->port.count--;
43119-
43120- if (tty->port.count == 0) {
43121+ if (atomic_dec_return(&tty->port.count) == 0) {
43122 struct tty_struct *linux_tty = tty->port.tty;
43123
43124 if (linux_tty != NULL) {
43125@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
43126 return;
43127
43128 mutex_lock(&tty->ipw_tty_mutex);
43129- if (tty->port.count == 0) {
43130+ if (atomic_read(&tty->port.count) == 0) {
43131 mutex_unlock(&tty->ipw_tty_mutex);
43132 return;
43133 }
43134@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
43135
43136 mutex_lock(&tty->ipw_tty_mutex);
43137
43138- if (!tty->port.count) {
43139+ if (!atomic_read(&tty->port.count)) {
43140 mutex_unlock(&tty->ipw_tty_mutex);
43141 return;
43142 }
43143@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
43144 return -ENODEV;
43145
43146 mutex_lock(&tty->ipw_tty_mutex);
43147- if (!tty->port.count) {
43148+ if (!atomic_read(&tty->port.count)) {
43149 mutex_unlock(&tty->ipw_tty_mutex);
43150 return -EINVAL;
43151 }
43152@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
43153 if (!tty)
43154 return -ENODEV;
43155
43156- if (!tty->port.count)
43157+ if (!atomic_read(&tty->port.count))
43158 return -EINVAL;
43159
43160 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
43161@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
43162 if (!tty)
43163 return 0;
43164
43165- if (!tty->port.count)
43166+ if (!atomic_read(&tty->port.count))
43167 return 0;
43168
43169 return tty->tx_bytes_queued;
43170@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
43171 if (!tty)
43172 return -ENODEV;
43173
43174- if (!tty->port.count)
43175+ if (!atomic_read(&tty->port.count))
43176 return -EINVAL;
43177
43178 return get_control_lines(tty);
43179@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
43180 if (!tty)
43181 return -ENODEV;
43182
43183- if (!tty->port.count)
43184+ if (!atomic_read(&tty->port.count))
43185 return -EINVAL;
43186
43187 return set_control_lines(tty, set, clear);
43188@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
43189 if (!tty)
43190 return -ENODEV;
43191
43192- if (!tty->port.count)
43193+ if (!atomic_read(&tty->port.count))
43194 return -EINVAL;
43195
43196 /* FIXME: Exactly how is the tty object locked here .. */
43197@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
43198 * are gone */
43199 mutex_lock(&ttyj->ipw_tty_mutex);
43200 }
43201- while (ttyj->port.count)
43202+ while (atomic_read(&ttyj->port.count))
43203 do_ipw_close(ttyj);
43204 ipwireless_disassociate_network_ttys(network,
43205 ttyj->channel_idx);
43206diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
43207index adeac25..787a0a1 100644
43208--- a/drivers/tty/moxa.c
43209+++ b/drivers/tty/moxa.c
43210@@ -1193,7 +1193,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
43211 }
43212
43213 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
43214- ch->port.count++;
43215+ atomic_inc(&ch->port.count);
43216 tty->driver_data = ch;
43217 tty_port_tty_set(&ch->port, tty);
43218 mutex_lock(&ch->port.mutex);
43219diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
43220index 4a43ef5d7..aa71f27 100644
43221--- a/drivers/tty/n_gsm.c
43222+++ b/drivers/tty/n_gsm.c
43223@@ -1636,7 +1636,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
43224 spin_lock_init(&dlci->lock);
43225 mutex_init(&dlci->mutex);
43226 dlci->fifo = &dlci->_fifo;
43227- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
43228+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
43229 kfree(dlci);
43230 return NULL;
43231 }
43232@@ -2936,7 +2936,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
43233 struct gsm_dlci *dlci = tty->driver_data;
43234 struct tty_port *port = &dlci->port;
43235
43236- port->count++;
43237+ atomic_inc(&port->count);
43238 dlci_get(dlci);
43239 dlci_get(dlci->gsm->dlci[0]);
43240 mux_get(dlci->gsm);
43241diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
43242index 1f8cba6..47b06c2 100644
43243--- a/drivers/tty/n_tty.c
43244+++ b/drivers/tty/n_tty.c
43245@@ -2205,6 +2205,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
43246 {
43247 *ops = tty_ldisc_N_TTY;
43248 ops->owner = NULL;
43249- ops->refcount = ops->flags = 0;
43250+ atomic_set(&ops->refcount, 0);
43251+ ops->flags = 0;
43252 }
43253 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
43254diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
43255index 125e0fd..8c50690 100644
43256--- a/drivers/tty/pty.c
43257+++ b/drivers/tty/pty.c
43258@@ -800,8 +800,10 @@ static void __init unix98_pty_init(void)
43259 panic("Couldn't register Unix98 pts driver");
43260
43261 /* Now create the /dev/ptmx special device */
43262+ pax_open_kernel();
43263 tty_default_fops(&ptmx_fops);
43264- ptmx_fops.open = ptmx_open;
43265+ *(void **)&ptmx_fops.open = ptmx_open;
43266+ pax_close_kernel();
43267
43268 cdev_init(&ptmx_cdev, &ptmx_fops);
43269 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
43270diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
43271index 1d27003..959f452 100644
43272--- a/drivers/tty/rocket.c
43273+++ b/drivers/tty/rocket.c
43274@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43275 tty->driver_data = info;
43276 tty_port_tty_set(port, tty);
43277
43278- if (port->count++ == 0) {
43279+ if (atomic_inc_return(&port->count) == 1) {
43280 atomic_inc(&rp_num_ports_open);
43281
43282 #ifdef ROCKET_DEBUG_OPEN
43283@@ -932,7 +932,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43284 #endif
43285 }
43286 #ifdef ROCKET_DEBUG_OPEN
43287- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
43288+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
43289 #endif
43290
43291 /*
43292@@ -1527,7 +1527,7 @@ static void rp_hangup(struct tty_struct *tty)
43293 spin_unlock_irqrestore(&info->port.lock, flags);
43294 return;
43295 }
43296- if (info->port.count)
43297+ if (atomic_read(&info->port.count))
43298 atomic_dec(&rp_num_ports_open);
43299 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
43300 spin_unlock_irqrestore(&info->port.lock, flags);
43301diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
43302index 1002054..dd644a8 100644
43303--- a/drivers/tty/serial/kgdboc.c
43304+++ b/drivers/tty/serial/kgdboc.c
43305@@ -24,8 +24,9 @@
43306 #define MAX_CONFIG_LEN 40
43307
43308 static struct kgdb_io kgdboc_io_ops;
43309+static struct kgdb_io kgdboc_io_ops_console;
43310
43311-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
43312+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
43313 static int configured = -1;
43314
43315 static char config[MAX_CONFIG_LEN];
43316@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
43317 kgdboc_unregister_kbd();
43318 if (configured == 1)
43319 kgdb_unregister_io_module(&kgdboc_io_ops);
43320+ else if (configured == 2)
43321+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
43322 }
43323
43324 static int configure_kgdboc(void)
43325@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
43326 int err;
43327 char *cptr = config;
43328 struct console *cons;
43329+ int is_console = 0;
43330
43331 err = kgdboc_option_setup(config);
43332 if (err || !strlen(config) || isspace(config[0]))
43333 goto noconfig;
43334
43335 err = -ENODEV;
43336- kgdboc_io_ops.is_console = 0;
43337 kgdb_tty_driver = NULL;
43338
43339 kgdboc_use_kms = 0;
43340@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
43341 int idx;
43342 if (cons->device && cons->device(cons, &idx) == p &&
43343 idx == tty_line) {
43344- kgdboc_io_ops.is_console = 1;
43345+ is_console = 1;
43346 break;
43347 }
43348 cons = cons->next;
43349@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
43350 kgdb_tty_line = tty_line;
43351
43352 do_register:
43353- err = kgdb_register_io_module(&kgdboc_io_ops);
43354+ if (is_console) {
43355+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
43356+ configured = 2;
43357+ } else {
43358+ err = kgdb_register_io_module(&kgdboc_io_ops);
43359+ configured = 1;
43360+ }
43361 if (err)
43362 goto noconfig;
43363
43364@@ -205,8 +214,6 @@ do_register:
43365 if (err)
43366 goto nmi_con_failed;
43367
43368- configured = 1;
43369-
43370 return 0;
43371
43372 nmi_con_failed:
43373@@ -223,7 +230,7 @@ noconfig:
43374 static int __init init_kgdboc(void)
43375 {
43376 /* Already configured? */
43377- if (configured == 1)
43378+ if (configured >= 1)
43379 return 0;
43380
43381 return configure_kgdboc();
43382@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
43383 if (config[len - 1] == '\n')
43384 config[len - 1] = '\0';
43385
43386- if (configured == 1)
43387+ if (configured >= 1)
43388 cleanup_kgdboc();
43389
43390 /* Go and configure with the new params. */
43391@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
43392 .post_exception = kgdboc_post_exp_handler,
43393 };
43394
43395+static struct kgdb_io kgdboc_io_ops_console = {
43396+ .name = "kgdboc",
43397+ .read_char = kgdboc_get_char,
43398+ .write_char = kgdboc_put_char,
43399+ .pre_exception = kgdboc_pre_exp_handler,
43400+ .post_exception = kgdboc_post_exp_handler,
43401+ .is_console = 1
43402+};
43403+
43404 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
43405 /* This is only available if kgdboc is a built in for early debugging */
43406 static int __init kgdboc_early_init(char *opt)
43407diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
43408index 2769a38..f3dbe48 100644
43409--- a/drivers/tty/serial/samsung.c
43410+++ b/drivers/tty/serial/samsung.c
43411@@ -451,11 +451,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
43412 }
43413 }
43414
43415+static int s3c64xx_serial_startup(struct uart_port *port);
43416 static int s3c24xx_serial_startup(struct uart_port *port)
43417 {
43418 struct s3c24xx_uart_port *ourport = to_ourport(port);
43419 int ret;
43420
43421+ /* Startup sequence is different for s3c64xx and higher SoC's */
43422+ if (s3c24xx_serial_has_interrupt_mask(port))
43423+ return s3c64xx_serial_startup(port);
43424+
43425 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
43426 port->mapbase, port->membase);
43427
43428@@ -1120,10 +1125,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
43429 /* setup info for port */
43430 port->dev = &platdev->dev;
43431
43432- /* Startup sequence is different for s3c64xx and higher SoC's */
43433- if (s3c24xx_serial_has_interrupt_mask(port))
43434- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
43435-
43436 port->uartclk = 1;
43437
43438 if (cfg->uart_flags & UPF_CONS_FLOW) {
43439diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
43440index 8fbb6d2..822a9e6 100644
43441--- a/drivers/tty/serial/serial_core.c
43442+++ b/drivers/tty/serial/serial_core.c
43443@@ -1454,7 +1454,7 @@ static void uart_hangup(struct tty_struct *tty)
43444 uart_flush_buffer(tty);
43445 uart_shutdown(tty, state);
43446 spin_lock_irqsave(&port->lock, flags);
43447- port->count = 0;
43448+ atomic_set(&port->count, 0);
43449 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
43450 spin_unlock_irqrestore(&port->lock, flags);
43451 tty_port_tty_set(port, NULL);
43452@@ -1550,7 +1550,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43453 goto end;
43454 }
43455
43456- port->count++;
43457+ atomic_inc(&port->count);
43458 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
43459 retval = -ENXIO;
43460 goto err_dec_count;
43461@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43462 /*
43463 * Make sure the device is in D0 state.
43464 */
43465- if (port->count == 1)
43466+ if (atomic_read(&port->count) == 1)
43467 uart_change_pm(state, UART_PM_STATE_ON);
43468
43469 /*
43470@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43471 end:
43472 return retval;
43473 err_dec_count:
43474- port->count--;
43475+ atomic_inc(&port->count);
43476 mutex_unlock(&port->mutex);
43477 goto end;
43478 }
43479diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
43480index 8983276..72a4090 100644
43481--- a/drivers/tty/synclink.c
43482+++ b/drivers/tty/synclink.c
43483@@ -3093,7 +3093,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43484
43485 if (debug_level >= DEBUG_LEVEL_INFO)
43486 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
43487- __FILE__,__LINE__, info->device_name, info->port.count);
43488+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43489
43490 if (tty_port_close_start(&info->port, tty, filp) == 0)
43491 goto cleanup;
43492@@ -3111,7 +3111,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43493 cleanup:
43494 if (debug_level >= DEBUG_LEVEL_INFO)
43495 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
43496- tty->driver->name, info->port.count);
43497+ tty->driver->name, atomic_read(&info->port.count));
43498
43499 } /* end of mgsl_close() */
43500
43501@@ -3210,8 +3210,8 @@ static void mgsl_hangup(struct tty_struct *tty)
43502
43503 mgsl_flush_buffer(tty);
43504 shutdown(info);
43505-
43506- info->port.count = 0;
43507+
43508+ atomic_set(&info->port.count, 0);
43509 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43510 info->port.tty = NULL;
43511
43512@@ -3300,12 +3300,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43513
43514 if (debug_level >= DEBUG_LEVEL_INFO)
43515 printk("%s(%d):block_til_ready before block on %s count=%d\n",
43516- __FILE__,__LINE__, tty->driver->name, port->count );
43517+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43518
43519 spin_lock_irqsave(&info->irq_spinlock, flags);
43520 if (!tty_hung_up_p(filp)) {
43521 extra_count = true;
43522- port->count--;
43523+ atomic_dec(&port->count);
43524 }
43525 spin_unlock_irqrestore(&info->irq_spinlock, flags);
43526 port->blocked_open++;
43527@@ -3334,7 +3334,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43528
43529 if (debug_level >= DEBUG_LEVEL_INFO)
43530 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
43531- __FILE__,__LINE__, tty->driver->name, port->count );
43532+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43533
43534 tty_unlock(tty);
43535 schedule();
43536@@ -3346,12 +3346,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43537
43538 /* FIXME: Racy on hangup during close wait */
43539 if (extra_count)
43540- port->count++;
43541+ atomic_inc(&port->count);
43542 port->blocked_open--;
43543
43544 if (debug_level >= DEBUG_LEVEL_INFO)
43545 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
43546- __FILE__,__LINE__, tty->driver->name, port->count );
43547+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43548
43549 if (!retval)
43550 port->flags |= ASYNC_NORMAL_ACTIVE;
43551@@ -3403,7 +3403,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
43552
43553 if (debug_level >= DEBUG_LEVEL_INFO)
43554 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
43555- __FILE__,__LINE__,tty->driver->name, info->port.count);
43556+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
43557
43558 /* If port is closing, signal caller to try again */
43559 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43560@@ -3422,10 +3422,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
43561 spin_unlock_irqrestore(&info->netlock, flags);
43562 goto cleanup;
43563 }
43564- info->port.count++;
43565+ atomic_inc(&info->port.count);
43566 spin_unlock_irqrestore(&info->netlock, flags);
43567
43568- if (info->port.count == 1) {
43569+ if (atomic_read(&info->port.count) == 1) {
43570 /* 1st open on this device, init hardware */
43571 retval = startup(info);
43572 if (retval < 0)
43573@@ -3449,8 +3449,8 @@ cleanup:
43574 if (retval) {
43575 if (tty->count == 1)
43576 info->port.tty = NULL; /* tty layer will release tty struct */
43577- if(info->port.count)
43578- info->port.count--;
43579+ if (atomic_read(&info->port.count))
43580+ atomic_dec(&info->port.count);
43581 }
43582
43583 return retval;
43584@@ -7668,7 +7668,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43585 unsigned short new_crctype;
43586
43587 /* return error if TTY interface open */
43588- if (info->port.count)
43589+ if (atomic_read(&info->port.count))
43590 return -EBUSY;
43591
43592 switch (encoding)
43593@@ -7763,7 +7763,7 @@ static int hdlcdev_open(struct net_device *dev)
43594
43595 /* arbitrate between network and tty opens */
43596 spin_lock_irqsave(&info->netlock, flags);
43597- if (info->port.count != 0 || info->netcount != 0) {
43598+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43599 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
43600 spin_unlock_irqrestore(&info->netlock, flags);
43601 return -EBUSY;
43602@@ -7849,7 +7849,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43603 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
43604
43605 /* return error if TTY interface open */
43606- if (info->port.count)
43607+ if (atomic_read(&info->port.count))
43608 return -EBUSY;
43609
43610 if (cmd != SIOCWANDEV)
43611diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
43612index aa9eece..d8baaec 100644
43613--- a/drivers/tty/synclink_gt.c
43614+++ b/drivers/tty/synclink_gt.c
43615@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
43616 tty->driver_data = info;
43617 info->port.tty = tty;
43618
43619- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
43620+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
43621
43622 /* If port is closing, signal caller to try again */
43623 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43624@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
43625 mutex_unlock(&info->port.mutex);
43626 goto cleanup;
43627 }
43628- info->port.count++;
43629+ atomic_inc(&info->port.count);
43630 spin_unlock_irqrestore(&info->netlock, flags);
43631
43632- if (info->port.count == 1) {
43633+ if (atomic_read(&info->port.count) == 1) {
43634 /* 1st open on this device, init hardware */
43635 retval = startup(info);
43636 if (retval < 0) {
43637@@ -715,8 +715,8 @@ cleanup:
43638 if (retval) {
43639 if (tty->count == 1)
43640 info->port.tty = NULL; /* tty layer will release tty struct */
43641- if(info->port.count)
43642- info->port.count--;
43643+ if(atomic_read(&info->port.count))
43644+ atomic_dec(&info->port.count);
43645 }
43646
43647 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
43648@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43649
43650 if (sanity_check(info, tty->name, "close"))
43651 return;
43652- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
43653+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
43654
43655 if (tty_port_close_start(&info->port, tty, filp) == 0)
43656 goto cleanup;
43657@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43658 tty_port_close_end(&info->port, tty);
43659 info->port.tty = NULL;
43660 cleanup:
43661- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
43662+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
43663 }
43664
43665 static void hangup(struct tty_struct *tty)
43666@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
43667 shutdown(info);
43668
43669 spin_lock_irqsave(&info->port.lock, flags);
43670- info->port.count = 0;
43671+ atomic_set(&info->port.count, 0);
43672 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43673 info->port.tty = NULL;
43674 spin_unlock_irqrestore(&info->port.lock, flags);
43675@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43676 unsigned short new_crctype;
43677
43678 /* return error if TTY interface open */
43679- if (info->port.count)
43680+ if (atomic_read(&info->port.count))
43681 return -EBUSY;
43682
43683 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
43684@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
43685
43686 /* arbitrate between network and tty opens */
43687 spin_lock_irqsave(&info->netlock, flags);
43688- if (info->port.count != 0 || info->netcount != 0) {
43689+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43690 DBGINFO(("%s hdlc_open busy\n", dev->name));
43691 spin_unlock_irqrestore(&info->netlock, flags);
43692 return -EBUSY;
43693@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43694 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
43695
43696 /* return error if TTY interface open */
43697- if (info->port.count)
43698+ if (atomic_read(&info->port.count))
43699 return -EBUSY;
43700
43701 if (cmd != SIOCWANDEV)
43702@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
43703 if (port == NULL)
43704 continue;
43705 spin_lock(&port->lock);
43706- if ((port->port.count || port->netcount) &&
43707+ if ((atomic_read(&port->port.count) || port->netcount) &&
43708 port->pending_bh && !port->bh_running &&
43709 !port->bh_requested) {
43710 DBGISR(("%s bh queued\n", port->device_name));
43711@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43712 spin_lock_irqsave(&info->lock, flags);
43713 if (!tty_hung_up_p(filp)) {
43714 extra_count = true;
43715- port->count--;
43716+ atomic_dec(&port->count);
43717 }
43718 spin_unlock_irqrestore(&info->lock, flags);
43719 port->blocked_open++;
43720@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43721 remove_wait_queue(&port->open_wait, &wait);
43722
43723 if (extra_count)
43724- port->count++;
43725+ atomic_inc(&port->count);
43726 port->blocked_open--;
43727
43728 if (!retval)
43729diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
43730index 6d5780c..aa4d8cd 100644
43731--- a/drivers/tty/synclinkmp.c
43732+++ b/drivers/tty/synclinkmp.c
43733@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
43734
43735 if (debug_level >= DEBUG_LEVEL_INFO)
43736 printk("%s(%d):%s open(), old ref count = %d\n",
43737- __FILE__,__LINE__,tty->driver->name, info->port.count);
43738+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
43739
43740 /* If port is closing, signal caller to try again */
43741 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43742@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
43743 spin_unlock_irqrestore(&info->netlock, flags);
43744 goto cleanup;
43745 }
43746- info->port.count++;
43747+ atomic_inc(&info->port.count);
43748 spin_unlock_irqrestore(&info->netlock, flags);
43749
43750- if (info->port.count == 1) {
43751+ if (atomic_read(&info->port.count) == 1) {
43752 /* 1st open on this device, init hardware */
43753 retval = startup(info);
43754 if (retval < 0)
43755@@ -796,8 +796,8 @@ cleanup:
43756 if (retval) {
43757 if (tty->count == 1)
43758 info->port.tty = NULL; /* tty layer will release tty struct */
43759- if(info->port.count)
43760- info->port.count--;
43761+ if(atomic_read(&info->port.count))
43762+ atomic_dec(&info->port.count);
43763 }
43764
43765 return retval;
43766@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43767
43768 if (debug_level >= DEBUG_LEVEL_INFO)
43769 printk("%s(%d):%s close() entry, count=%d\n",
43770- __FILE__,__LINE__, info->device_name, info->port.count);
43771+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43772
43773 if (tty_port_close_start(&info->port, tty, filp) == 0)
43774 goto cleanup;
43775@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43776 cleanup:
43777 if (debug_level >= DEBUG_LEVEL_INFO)
43778 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
43779- tty->driver->name, info->port.count);
43780+ tty->driver->name, atomic_read(&info->port.count));
43781 }
43782
43783 /* Called by tty_hangup() when a hangup is signaled.
43784@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
43785 shutdown(info);
43786
43787 spin_lock_irqsave(&info->port.lock, flags);
43788- info->port.count = 0;
43789+ atomic_set(&info->port.count, 0);
43790 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43791 info->port.tty = NULL;
43792 spin_unlock_irqrestore(&info->port.lock, flags);
43793@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43794 unsigned short new_crctype;
43795
43796 /* return error if TTY interface open */
43797- if (info->port.count)
43798+ if (atomic_read(&info->port.count))
43799 return -EBUSY;
43800
43801 switch (encoding)
43802@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
43803
43804 /* arbitrate between network and tty opens */
43805 spin_lock_irqsave(&info->netlock, flags);
43806- if (info->port.count != 0 || info->netcount != 0) {
43807+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43808 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
43809 spin_unlock_irqrestore(&info->netlock, flags);
43810 return -EBUSY;
43811@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43812 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
43813
43814 /* return error if TTY interface open */
43815- if (info->port.count)
43816+ if (atomic_read(&info->port.count))
43817 return -EBUSY;
43818
43819 if (cmd != SIOCWANDEV)
43820@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
43821 * do not request bottom half processing if the
43822 * device is not open in a normal mode.
43823 */
43824- if ( port && (port->port.count || port->netcount) &&
43825+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
43826 port->pending_bh && !port->bh_running &&
43827 !port->bh_requested ) {
43828 if ( debug_level >= DEBUG_LEVEL_ISR )
43829@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43830
43831 if (debug_level >= DEBUG_LEVEL_INFO)
43832 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
43833- __FILE__,__LINE__, tty->driver->name, port->count );
43834+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43835
43836 spin_lock_irqsave(&info->lock, flags);
43837 if (!tty_hung_up_p(filp)) {
43838 extra_count = true;
43839- port->count--;
43840+ atomic_dec(&port->count);
43841 }
43842 spin_unlock_irqrestore(&info->lock, flags);
43843 port->blocked_open++;
43844@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43845
43846 if (debug_level >= DEBUG_LEVEL_INFO)
43847 printk("%s(%d):%s block_til_ready() count=%d\n",
43848- __FILE__,__LINE__, tty->driver->name, port->count );
43849+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43850
43851 tty_unlock(tty);
43852 schedule();
43853@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43854 remove_wait_queue(&port->open_wait, &wait);
43855
43856 if (extra_count)
43857- port->count++;
43858+ atomic_inc(&port->count);
43859 port->blocked_open--;
43860
43861 if (debug_level >= DEBUG_LEVEL_INFO)
43862 printk("%s(%d):%s block_til_ready() after, count=%d\n",
43863- __FILE__,__LINE__, tty->driver->name, port->count );
43864+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43865
43866 if (!retval)
43867 port->flags |= ASYNC_NORMAL_ACTIVE;
43868diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
43869index 3687f0c..6b9b808 100644
43870--- a/drivers/tty/sysrq.c
43871+++ b/drivers/tty/sysrq.c
43872@@ -995,7 +995,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
43873 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
43874 size_t count, loff_t *ppos)
43875 {
43876- if (count) {
43877+ if (count && capable(CAP_SYS_ADMIN)) {
43878 char c;
43879
43880 if (get_user(c, buf))
43881diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
43882index a9cd0b9..47b9336 100644
43883--- a/drivers/tty/tty_io.c
43884+++ b/drivers/tty/tty_io.c
43885@@ -3398,7 +3398,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
43886
43887 void tty_default_fops(struct file_operations *fops)
43888 {
43889- *fops = tty_fops;
43890+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
43891 }
43892
43893 /*
43894diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
43895index d794087..e4f49e5 100644
43896--- a/drivers/tty/tty_ldisc.c
43897+++ b/drivers/tty/tty_ldisc.c
43898@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
43899 if (atomic_dec_and_test(&ld->users)) {
43900 struct tty_ldisc_ops *ldo = ld->ops;
43901
43902- ldo->refcount--;
43903+ atomic_dec(&ldo->refcount);
43904 module_put(ldo->owner);
43905 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43906
43907@@ -93,7 +93,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
43908 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43909 tty_ldiscs[disc] = new_ldisc;
43910 new_ldisc->num = disc;
43911- new_ldisc->refcount = 0;
43912+ atomic_set(&new_ldisc->refcount, 0);
43913 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43914
43915 return ret;
43916@@ -121,7 +121,7 @@ int tty_unregister_ldisc(int disc)
43917 return -EINVAL;
43918
43919 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43920- if (tty_ldiscs[disc]->refcount)
43921+ if (atomic_read(&tty_ldiscs[disc]->refcount))
43922 ret = -EBUSY;
43923 else
43924 tty_ldiscs[disc] = NULL;
43925@@ -142,7 +142,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
43926 if (ldops) {
43927 ret = ERR_PTR(-EAGAIN);
43928 if (try_module_get(ldops->owner)) {
43929- ldops->refcount++;
43930+ atomic_inc(&ldops->refcount);
43931 ret = ldops;
43932 }
43933 }
43934@@ -155,7 +155,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
43935 unsigned long flags;
43936
43937 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43938- ldops->refcount--;
43939+ atomic_dec(&ldops->refcount);
43940 module_put(ldops->owner);
43941 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43942 }
43943diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
43944index b7ff59d..7c6105e 100644
43945--- a/drivers/tty/tty_port.c
43946+++ b/drivers/tty/tty_port.c
43947@@ -218,7 +218,7 @@ void tty_port_hangup(struct tty_port *port)
43948 unsigned long flags;
43949
43950 spin_lock_irqsave(&port->lock, flags);
43951- port->count = 0;
43952+ atomic_set(&port->count, 0);
43953 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43954 if (port->tty) {
43955 set_bit(TTY_IO_ERROR, &port->tty->flags);
43956@@ -344,7 +344,7 @@ int tty_port_block_til_ready(struct tty_port *port,
43957 /* The port lock protects the port counts */
43958 spin_lock_irqsave(&port->lock, flags);
43959 if (!tty_hung_up_p(filp))
43960- port->count--;
43961+ atomic_dec(&port->count);
43962 port->blocked_open++;
43963 spin_unlock_irqrestore(&port->lock, flags);
43964
43965@@ -386,7 +386,7 @@ int tty_port_block_til_ready(struct tty_port *port,
43966 we must not mess that up further */
43967 spin_lock_irqsave(&port->lock, flags);
43968 if (!tty_hung_up_p(filp))
43969- port->count++;
43970+ atomic_inc(&port->count);
43971 port->blocked_open--;
43972 if (retval == 0)
43973 port->flags |= ASYNC_NORMAL_ACTIVE;
43974@@ -406,19 +406,19 @@ int tty_port_close_start(struct tty_port *port,
43975 return 0;
43976 }
43977
43978- if (tty->count == 1 && port->count != 1) {
43979+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
43980 printk(KERN_WARNING
43981 "tty_port_close_start: tty->count = 1 port count = %d.\n",
43982- port->count);
43983- port->count = 1;
43984+ atomic_read(&port->count));
43985+ atomic_set(&port->count, 1);
43986 }
43987- if (--port->count < 0) {
43988+ if (atomic_dec_return(&port->count) < 0) {
43989 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
43990- port->count);
43991- port->count = 0;
43992+ atomic_read(&port->count));
43993+ atomic_set(&port->count, 0);
43994 }
43995
43996- if (port->count) {
43997+ if (atomic_read(&port->count)) {
43998 spin_unlock_irqrestore(&port->lock, flags);
43999 if (port->ops->drop)
44000 port->ops->drop(port);
44001@@ -516,7 +516,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
44002 {
44003 spin_lock_irq(&port->lock);
44004 if (!tty_hung_up_p(filp))
44005- ++port->count;
44006+ atomic_inc(&port->count);
44007 spin_unlock_irq(&port->lock);
44008 tty_port_tty_set(port, tty);
44009
44010diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
44011index a9af1b9a..1e08e7f 100644
44012--- a/drivers/tty/vt/keyboard.c
44013+++ b/drivers/tty/vt/keyboard.c
44014@@ -647,6 +647,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
44015 kbd->kbdmode == VC_OFF) &&
44016 value != KVAL(K_SAK))
44017 return; /* SAK is allowed even in raw mode */
44018+
44019+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
44020+ {
44021+ void *func = fn_handler[value];
44022+ if (func == fn_show_state || func == fn_show_ptregs ||
44023+ func == fn_show_mem)
44024+ return;
44025+ }
44026+#endif
44027+
44028 fn_handler[value](vc);
44029 }
44030
44031@@ -1795,9 +1805,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
44032 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
44033 return -EFAULT;
44034
44035- if (!capable(CAP_SYS_TTY_CONFIG))
44036- perm = 0;
44037-
44038 switch (cmd) {
44039 case KDGKBENT:
44040 /* Ensure another thread doesn't free it under us */
44041@@ -1812,6 +1819,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
44042 spin_unlock_irqrestore(&kbd_event_lock, flags);
44043 return put_user(val, &user_kbe->kb_value);
44044 case KDSKBENT:
44045+ if (!capable(CAP_SYS_TTY_CONFIG))
44046+ perm = 0;
44047+
44048 if (!perm)
44049 return -EPERM;
44050 if (!i && v == K_NOSUCHMAP) {
44051@@ -1902,9 +1912,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
44052 int i, j, k;
44053 int ret;
44054
44055- if (!capable(CAP_SYS_TTY_CONFIG))
44056- perm = 0;
44057-
44058 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
44059 if (!kbs) {
44060 ret = -ENOMEM;
44061@@ -1938,6 +1945,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
44062 kfree(kbs);
44063 return ((p && *p) ? -EOVERFLOW : 0);
44064 case KDSKBSENT:
44065+ if (!capable(CAP_SYS_TTY_CONFIG))
44066+ perm = 0;
44067+
44068 if (!perm) {
44069 ret = -EPERM;
44070 goto reterr;
44071diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
44072index c8b9262..7e824e6 100644
44073--- a/drivers/uio/uio.c
44074+++ b/drivers/uio/uio.c
44075@@ -25,6 +25,7 @@
44076 #include <linux/kobject.h>
44077 #include <linux/cdev.h>
44078 #include <linux/uio_driver.h>
44079+#include <asm/local.h>
44080
44081 #define UIO_MAX_DEVICES (1U << MINORBITS)
44082
44083@@ -32,10 +33,10 @@ struct uio_device {
44084 struct module *owner;
44085 struct device *dev;
44086 int minor;
44087- atomic_t event;
44088+ atomic_unchecked_t event;
44089 struct fasync_struct *async_queue;
44090 wait_queue_head_t wait;
44091- int vma_count;
44092+ local_t vma_count;
44093 struct uio_info *info;
44094 struct kobject *map_dir;
44095 struct kobject *portio_dir;
44096@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
44097 struct device_attribute *attr, char *buf)
44098 {
44099 struct uio_device *idev = dev_get_drvdata(dev);
44100- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
44101+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
44102 }
44103
44104 static struct device_attribute uio_class_attributes[] = {
44105@@ -397,7 +398,7 @@ void uio_event_notify(struct uio_info *info)
44106 {
44107 struct uio_device *idev = info->uio_dev;
44108
44109- atomic_inc(&idev->event);
44110+ atomic_inc_unchecked(&idev->event);
44111 wake_up_interruptible(&idev->wait);
44112 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
44113 }
44114@@ -450,7 +451,7 @@ static int uio_open(struct inode *inode, struct file *filep)
44115 }
44116
44117 listener->dev = idev;
44118- listener->event_count = atomic_read(&idev->event);
44119+ listener->event_count = atomic_read_unchecked(&idev->event);
44120 filep->private_data = listener;
44121
44122 if (idev->info->open) {
44123@@ -501,7 +502,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
44124 return -EIO;
44125
44126 poll_wait(filep, &idev->wait, wait);
44127- if (listener->event_count != atomic_read(&idev->event))
44128+ if (listener->event_count != atomic_read_unchecked(&idev->event))
44129 return POLLIN | POLLRDNORM;
44130 return 0;
44131 }
44132@@ -526,7 +527,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
44133 do {
44134 set_current_state(TASK_INTERRUPTIBLE);
44135
44136- event_count = atomic_read(&idev->event);
44137+ event_count = atomic_read_unchecked(&idev->event);
44138 if (event_count != listener->event_count) {
44139 if (copy_to_user(buf, &event_count, count))
44140 retval = -EFAULT;
44141@@ -595,13 +596,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
44142 static void uio_vma_open(struct vm_area_struct *vma)
44143 {
44144 struct uio_device *idev = vma->vm_private_data;
44145- idev->vma_count++;
44146+ local_inc(&idev->vma_count);
44147 }
44148
44149 static void uio_vma_close(struct vm_area_struct *vma)
44150 {
44151 struct uio_device *idev = vma->vm_private_data;
44152- idev->vma_count--;
44153+ local_dec(&idev->vma_count);
44154 }
44155
44156 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
44157@@ -808,7 +809,7 @@ int __uio_register_device(struct module *owner,
44158 idev->owner = owner;
44159 idev->info = info;
44160 init_waitqueue_head(&idev->wait);
44161- atomic_set(&idev->event, 0);
44162+ atomic_set_unchecked(&idev->event, 0);
44163
44164 ret = uio_get_minor(idev);
44165 if (ret)
44166diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
44167index 8a7eb77..c00402f 100644
44168--- a/drivers/usb/atm/cxacru.c
44169+++ b/drivers/usb/atm/cxacru.c
44170@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
44171 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
44172 if (ret < 2)
44173 return -EINVAL;
44174- if (index < 0 || index > 0x7f)
44175+ if (index > 0x7f)
44176 return -EINVAL;
44177 pos += tmp;
44178
44179diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
44180index 35f10bf..6a38a0b 100644
44181--- a/drivers/usb/atm/usbatm.c
44182+++ b/drivers/usb/atm/usbatm.c
44183@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44184 if (printk_ratelimit())
44185 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
44186 __func__, vpi, vci);
44187- atomic_inc(&vcc->stats->rx_err);
44188+ atomic_inc_unchecked(&vcc->stats->rx_err);
44189 return;
44190 }
44191
44192@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44193 if (length > ATM_MAX_AAL5_PDU) {
44194 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
44195 __func__, length, vcc);
44196- atomic_inc(&vcc->stats->rx_err);
44197+ atomic_inc_unchecked(&vcc->stats->rx_err);
44198 goto out;
44199 }
44200
44201@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44202 if (sarb->len < pdu_length) {
44203 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
44204 __func__, pdu_length, sarb->len, vcc);
44205- atomic_inc(&vcc->stats->rx_err);
44206+ atomic_inc_unchecked(&vcc->stats->rx_err);
44207 goto out;
44208 }
44209
44210 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
44211 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
44212 __func__, vcc);
44213- atomic_inc(&vcc->stats->rx_err);
44214+ atomic_inc_unchecked(&vcc->stats->rx_err);
44215 goto out;
44216 }
44217
44218@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44219 if (printk_ratelimit())
44220 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
44221 __func__, length);
44222- atomic_inc(&vcc->stats->rx_drop);
44223+ atomic_inc_unchecked(&vcc->stats->rx_drop);
44224 goto out;
44225 }
44226
44227@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44228
44229 vcc->push(vcc, skb);
44230
44231- atomic_inc(&vcc->stats->rx);
44232+ atomic_inc_unchecked(&vcc->stats->rx);
44233 out:
44234 skb_trim(sarb, 0);
44235 }
44236@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
44237 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
44238
44239 usbatm_pop(vcc, skb);
44240- atomic_inc(&vcc->stats->tx);
44241+ atomic_inc_unchecked(&vcc->stats->tx);
44242
44243 skb = skb_dequeue(&instance->sndqueue);
44244 }
44245@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
44246 if (!left--)
44247 return sprintf(page,
44248 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
44249- atomic_read(&atm_dev->stats.aal5.tx),
44250- atomic_read(&atm_dev->stats.aal5.tx_err),
44251- atomic_read(&atm_dev->stats.aal5.rx),
44252- atomic_read(&atm_dev->stats.aal5.rx_err),
44253- atomic_read(&atm_dev->stats.aal5.rx_drop));
44254+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
44255+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
44256+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
44257+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
44258+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
44259
44260 if (!left--) {
44261 if (instance->disconnected)
44262diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
44263index 2a3bbdf..91d72cf 100644
44264--- a/drivers/usb/core/devices.c
44265+++ b/drivers/usb/core/devices.c
44266@@ -126,7 +126,7 @@ static const char format_endpt[] =
44267 * time it gets called.
44268 */
44269 static struct device_connect_event {
44270- atomic_t count;
44271+ atomic_unchecked_t count;
44272 wait_queue_head_t wait;
44273 } device_event = {
44274 .count = ATOMIC_INIT(1),
44275@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
44276
44277 void usbfs_conn_disc_event(void)
44278 {
44279- atomic_add(2, &device_event.count);
44280+ atomic_add_unchecked(2, &device_event.count);
44281 wake_up(&device_event.wait);
44282 }
44283
44284@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
44285
44286 poll_wait(file, &device_event.wait, wait);
44287
44288- event_count = atomic_read(&device_event.count);
44289+ event_count = atomic_read_unchecked(&device_event.count);
44290 if (file->f_version != event_count) {
44291 file->f_version = event_count;
44292 return POLLIN | POLLRDNORM;
44293diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
44294index f9ec44c..eb5779f 100644
44295--- a/drivers/usb/core/hcd.c
44296+++ b/drivers/usb/core/hcd.c
44297@@ -1526,7 +1526,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44298 */
44299 usb_get_urb(urb);
44300 atomic_inc(&urb->use_count);
44301- atomic_inc(&urb->dev->urbnum);
44302+ atomic_inc_unchecked(&urb->dev->urbnum);
44303 usbmon_urb_submit(&hcd->self, urb);
44304
44305 /* NOTE requirements on root-hub callers (usbfs and the hub
44306@@ -1553,7 +1553,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44307 urb->hcpriv = NULL;
44308 INIT_LIST_HEAD(&urb->urb_list);
44309 atomic_dec(&urb->use_count);
44310- atomic_dec(&urb->dev->urbnum);
44311+ atomic_dec_unchecked(&urb->dev->urbnum);
44312 if (atomic_read(&urb->reject))
44313 wake_up(&usb_kill_urb_queue);
44314 usb_put_urb(urb);
44315diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
44316index 444d30e..f15c850 100644
44317--- a/drivers/usb/core/message.c
44318+++ b/drivers/usb/core/message.c
44319@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
44320 * method can wait for it to complete. Since you don't have a handle on the
44321 * URB used, you can't cancel the request.
44322 */
44323-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44324+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44325 __u8 requesttype, __u16 value, __u16 index, void *data,
44326 __u16 size, int timeout)
44327 {
44328diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
44329index 3f81a3d..a3aa993 100644
44330--- a/drivers/usb/core/sysfs.c
44331+++ b/drivers/usb/core/sysfs.c
44332@@ -239,7 +239,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
44333 struct usb_device *udev;
44334
44335 udev = to_usb_device(dev);
44336- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
44337+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
44338 }
44339 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
44340
44341diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
44342index f81b925..78d22ec 100644
44343--- a/drivers/usb/core/usb.c
44344+++ b/drivers/usb/core/usb.c
44345@@ -388,7 +388,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
44346 set_dev_node(&dev->dev, dev_to_node(bus->controller));
44347 dev->state = USB_STATE_ATTACHED;
44348 dev->lpm_disable_count = 1;
44349- atomic_set(&dev->urbnum, 0);
44350+ atomic_set_unchecked(&dev->urbnum, 0);
44351
44352 INIT_LIST_HEAD(&dev->ep0.urb_list);
44353 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
44354diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
44355index 5e29dde..eca992f 100644
44356--- a/drivers/usb/early/ehci-dbgp.c
44357+++ b/drivers/usb/early/ehci-dbgp.c
44358@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
44359
44360 #ifdef CONFIG_KGDB
44361 static struct kgdb_io kgdbdbgp_io_ops;
44362-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
44363+static struct kgdb_io kgdbdbgp_io_ops_console;
44364+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
44365 #else
44366 #define dbgp_kgdb_mode (0)
44367 #endif
44368@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
44369 .write_char = kgdbdbgp_write_char,
44370 };
44371
44372+static struct kgdb_io kgdbdbgp_io_ops_console = {
44373+ .name = "kgdbdbgp",
44374+ .read_char = kgdbdbgp_read_char,
44375+ .write_char = kgdbdbgp_write_char,
44376+ .is_console = 1
44377+};
44378+
44379 static int kgdbdbgp_wait_time;
44380
44381 static int __init kgdbdbgp_parse_config(char *str)
44382@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
44383 ptr++;
44384 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
44385 }
44386- kgdb_register_io_module(&kgdbdbgp_io_ops);
44387- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
44388+ if (early_dbgp_console.index != -1)
44389+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
44390+ else
44391+ kgdb_register_io_module(&kgdbdbgp_io_ops);
44392
44393 return 0;
44394 }
44395diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
44396index b369292..9f3ba40 100644
44397--- a/drivers/usb/gadget/u_serial.c
44398+++ b/drivers/usb/gadget/u_serial.c
44399@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44400 spin_lock_irq(&port->port_lock);
44401
44402 /* already open? Great. */
44403- if (port->port.count) {
44404+ if (atomic_read(&port->port.count)) {
44405 status = 0;
44406- port->port.count++;
44407+ atomic_inc(&port->port.count);
44408
44409 /* currently opening/closing? wait ... */
44410 } else if (port->openclose) {
44411@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44412 tty->driver_data = port;
44413 port->port.tty = tty;
44414
44415- port->port.count = 1;
44416+ atomic_set(&port->port.count, 1);
44417 port->openclose = false;
44418
44419 /* if connected, start the I/O stream */
44420@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44421
44422 spin_lock_irq(&port->port_lock);
44423
44424- if (port->port.count != 1) {
44425- if (port->port.count == 0)
44426+ if (atomic_read(&port->port.count) != 1) {
44427+ if (atomic_read(&port->port.count) == 0)
44428 WARN_ON(1);
44429 else
44430- --port->port.count;
44431+ atomic_dec(&port->port.count);
44432 goto exit;
44433 }
44434
44435@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44436 * and sleep if necessary
44437 */
44438 port->openclose = true;
44439- port->port.count = 0;
44440+ atomic_set(&port->port.count, 0);
44441
44442 gser = port->port_usb;
44443 if (gser && gser->disconnect)
44444@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
44445 int cond;
44446
44447 spin_lock_irq(&port->port_lock);
44448- cond = (port->port.count == 0) && !port->openclose;
44449+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
44450 spin_unlock_irq(&port->port_lock);
44451 return cond;
44452 }
44453@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
44454 /* if it's already open, start I/O ... and notify the serial
44455 * protocol about open/close status (connect/disconnect).
44456 */
44457- if (port->port.count) {
44458+ if (atomic_read(&port->port.count)) {
44459 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
44460 gs_start_io(port);
44461 if (gser->connect)
44462@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
44463
44464 port->port_usb = NULL;
44465 gser->ioport = NULL;
44466- if (port->port.count > 0 || port->openclose) {
44467+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
44468 wake_up_interruptible(&port->drain_wait);
44469 if (port->port.tty)
44470 tty_hangup(port->port.tty);
44471@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
44472
44473 /* finally, free any unused/unusable I/O buffers */
44474 spin_lock_irqsave(&port->port_lock, flags);
44475- if (port->port.count == 0 && !port->openclose)
44476+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
44477 gs_buf_free(&port->port_write_buf);
44478 gs_free_requests(gser->out, &port->read_pool, NULL);
44479 gs_free_requests(gser->out, &port->read_queue, NULL);
44480diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
44481index 5f3bcd3..bfca43f 100644
44482--- a/drivers/usb/serial/console.c
44483+++ b/drivers/usb/serial/console.c
44484@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
44485
44486 info->port = port;
44487
44488- ++port->port.count;
44489+ atomic_inc(&port->port.count);
44490 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
44491 if (serial->type->set_termios) {
44492 /*
44493@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
44494 }
44495 /* Now that any required fake tty operations are completed restore
44496 * the tty port count */
44497- --port->port.count;
44498+ atomic_dec(&port->port.count);
44499 /* The console is special in terms of closing the device so
44500 * indicate this port is now acting as a system console. */
44501 port->port.console = 1;
44502@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
44503 free_tty:
44504 kfree(tty);
44505 reset_open_count:
44506- port->port.count = 0;
44507+ atomic_set(&port->port.count, 0);
44508 usb_autopm_put_interface(serial->interface);
44509 error_get_interface:
44510 usb_serial_put(serial);
44511diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c
44512index 6c3586a..a94e621 100644
44513--- a/drivers/usb/storage/realtek_cr.c
44514+++ b/drivers/usb/storage/realtek_cr.c
44515@@ -429,7 +429,7 @@ static int rts51x_read_status(struct us_data *us,
44516
44517 buf = kmalloc(len, GFP_NOIO);
44518 if (buf == NULL)
44519- return USB_STOR_TRANSPORT_ERROR;
44520+ return -ENOMEM;
44521
44522 US_DEBUGP("%s, lun = %d\n", __func__, lun);
44523
44524diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
44525index 75f70f0..d467e1a 100644
44526--- a/drivers/usb/storage/usb.h
44527+++ b/drivers/usb/storage/usb.h
44528@@ -63,7 +63,7 @@ struct us_unusual_dev {
44529 __u8 useProtocol;
44530 __u8 useTransport;
44531 int (*initFunction)(struct us_data *);
44532-};
44533+} __do_const;
44534
44535
44536 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
44537diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
44538index d6bea3e..60b250e 100644
44539--- a/drivers/usb/wusbcore/wa-hc.h
44540+++ b/drivers/usb/wusbcore/wa-hc.h
44541@@ -192,7 +192,7 @@ struct wahc {
44542 struct list_head xfer_delayed_list;
44543 spinlock_t xfer_list_lock;
44544 struct work_struct xfer_work;
44545- atomic_t xfer_id_count;
44546+ atomic_unchecked_t xfer_id_count;
44547 };
44548
44549
44550@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
44551 INIT_LIST_HEAD(&wa->xfer_delayed_list);
44552 spin_lock_init(&wa->xfer_list_lock);
44553 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
44554- atomic_set(&wa->xfer_id_count, 1);
44555+ atomic_set_unchecked(&wa->xfer_id_count, 1);
44556 }
44557
44558 /**
44559diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
44560index 6ef94bc..1b41265 100644
44561--- a/drivers/usb/wusbcore/wa-xfer.c
44562+++ b/drivers/usb/wusbcore/wa-xfer.c
44563@@ -296,7 +296,7 @@ out:
44564 */
44565 static void wa_xfer_id_init(struct wa_xfer *xfer)
44566 {
44567- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
44568+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
44569 }
44570
44571 /*
44572diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
44573index 8c55011..eed4ae1a 100644
44574--- a/drivers/video/aty/aty128fb.c
44575+++ b/drivers/video/aty/aty128fb.c
44576@@ -149,7 +149,7 @@ enum {
44577 };
44578
44579 /* Must match above enum */
44580-static char * const r128_family[] = {
44581+static const char * const r128_family[] = {
44582 "AGP",
44583 "PCI",
44584 "PRO AGP",
44585diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
44586index 4f27fdc..d3537e6 100644
44587--- a/drivers/video/aty/atyfb_base.c
44588+++ b/drivers/video/aty/atyfb_base.c
44589@@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
44590 par->accel_flags = var->accel_flags; /* hack */
44591
44592 if (var->accel_flags) {
44593- info->fbops->fb_sync = atyfb_sync;
44594+ pax_open_kernel();
44595+ *(void **)&info->fbops->fb_sync = atyfb_sync;
44596+ pax_close_kernel();
44597 info->flags &= ~FBINFO_HWACCEL_DISABLED;
44598 } else {
44599- info->fbops->fb_sync = NULL;
44600+ pax_open_kernel();
44601+ *(void **)&info->fbops->fb_sync = NULL;
44602+ pax_close_kernel();
44603 info->flags |= FBINFO_HWACCEL_DISABLED;
44604 }
44605
44606diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
44607index 95ec042..e6affdd 100644
44608--- a/drivers/video/aty/mach64_cursor.c
44609+++ b/drivers/video/aty/mach64_cursor.c
44610@@ -7,6 +7,7 @@
44611 #include <linux/string.h>
44612
44613 #include <asm/io.h>
44614+#include <asm/pgtable.h>
44615
44616 #ifdef __sparc__
44617 #include <asm/fbio.h>
44618@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
44619 info->sprite.buf_align = 16; /* and 64 lines tall. */
44620 info->sprite.flags = FB_PIXMAP_IO;
44621
44622- info->fbops->fb_cursor = atyfb_cursor;
44623+ pax_open_kernel();
44624+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
44625+ pax_close_kernel();
44626
44627 return 0;
44628 }
44629diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
44630index 6c5ed6b..b727c88 100644
44631--- a/drivers/video/backlight/kb3886_bl.c
44632+++ b/drivers/video/backlight/kb3886_bl.c
44633@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
44634 static unsigned long kb3886bl_flags;
44635 #define KB3886BL_SUSPENDED 0x01
44636
44637-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
44638+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
44639 {
44640 .ident = "Sahara Touch-iT",
44641 .matches = {
44642diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
44643index 900aa4e..6d49418 100644
44644--- a/drivers/video/fb_defio.c
44645+++ b/drivers/video/fb_defio.c
44646@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
44647
44648 BUG_ON(!fbdefio);
44649 mutex_init(&fbdefio->lock);
44650- info->fbops->fb_mmap = fb_deferred_io_mmap;
44651+ pax_open_kernel();
44652+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
44653+ pax_close_kernel();
44654 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
44655 INIT_LIST_HEAD(&fbdefio->pagelist);
44656 if (fbdefio->delay == 0) /* set a default of 1 s */
44657@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
44658 page->mapping = NULL;
44659 }
44660
44661- info->fbops->fb_mmap = NULL;
44662+ *(void **)&info->fbops->fb_mmap = NULL;
44663 mutex_destroy(&fbdefio->lock);
44664 }
44665 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
44666diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
44667index 5c3960d..15cf8fc 100644
44668--- a/drivers/video/fbcmap.c
44669+++ b/drivers/video/fbcmap.c
44670@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
44671 rc = -ENODEV;
44672 goto out;
44673 }
44674- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
44675- !info->fbops->fb_setcmap)) {
44676+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
44677 rc = -EINVAL;
44678 goto out1;
44679 }
44680diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
44681index 86291dc..7cc5962 100644
44682--- a/drivers/video/fbmem.c
44683+++ b/drivers/video/fbmem.c
44684@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
44685 image->dx += image->width + 8;
44686 }
44687 } else if (rotate == FB_ROTATE_UD) {
44688- for (x = 0; x < num && image->dx >= 0; x++) {
44689+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
44690 info->fbops->fb_imageblit(info, image);
44691 image->dx -= image->width + 8;
44692 }
44693@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
44694 image->dy += image->height + 8;
44695 }
44696 } else if (rotate == FB_ROTATE_CCW) {
44697- for (x = 0; x < num && image->dy >= 0; x++) {
44698+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
44699 info->fbops->fb_imageblit(info, image);
44700 image->dy -= image->height + 8;
44701 }
44702@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
44703 return -EFAULT;
44704 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
44705 return -EINVAL;
44706- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
44707+ if (con2fb.framebuffer >= FB_MAX)
44708 return -EINVAL;
44709 if (!registered_fb[con2fb.framebuffer])
44710 request_module("fb%d", con2fb.framebuffer);
44711diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
44712index 7672d2e..b56437f 100644
44713--- a/drivers/video/i810/i810_accel.c
44714+++ b/drivers/video/i810/i810_accel.c
44715@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
44716 }
44717 }
44718 printk("ringbuffer lockup!!!\n");
44719+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
44720 i810_report_error(mmio);
44721 par->dev_flags |= LOCKUP;
44722 info->pixmap.scan_align = 1;
44723diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
44724index 3c14e43..eafa544 100644
44725--- a/drivers/video/logo/logo_linux_clut224.ppm
44726+++ b/drivers/video/logo/logo_linux_clut224.ppm
44727@@ -1,1604 +1,1123 @@
44728 P3
44729-# Standard 224-color Linux logo
44730 80 80
44731 255
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 0 0 0 0 0 0 0 0 0
44739- 0 0 0 0 0 0 0 0 0 0 0 0
44740- 0 0 0 0 0 0 0 0 0 0 0 0
44741- 6 6 6 6 6 6 10 10 10 10 10 10
44742- 10 10 10 6 6 6 6 6 6 6 6 6
44743- 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0 0 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
44759- 0 0 0 0 0 0 0 0 0 0 0 0
44760- 0 0 0 6 6 6 10 10 10 14 14 14
44761- 22 22 22 26 26 26 30 30 30 34 34 34
44762- 30 30 30 30 30 30 26 26 26 18 18 18
44763- 14 14 14 10 10 10 6 6 6 0 0 0
44764- 0 0 0 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 0 0 0 0 0 0 0 0 0 0
44773- 0 0 0 0 0 1 0 0 1 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- 0 0 0 0 0 0 0 0 0 0 0 0
44779- 0 0 0 0 0 0 0 0 0 0 0 0
44780- 6 6 6 14 14 14 26 26 26 42 42 42
44781- 54 54 54 66 66 66 78 78 78 78 78 78
44782- 78 78 78 74 74 74 66 66 66 54 54 54
44783- 42 42 42 26 26 26 18 18 18 10 10 10
44784- 6 6 6 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 0 0 0 0 0 0 0 0 0 0
44793- 0 0 1 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- 0 0 0 0 0 0 0 0 0 0 0 0
44799- 0 0 0 0 0 0 0 0 0 10 10 10
44800- 22 22 22 42 42 42 66 66 66 86 86 86
44801- 66 66 66 38 38 38 38 38 38 22 22 22
44802- 26 26 26 34 34 34 54 54 54 66 66 66
44803- 86 86 86 70 70 70 46 46 46 26 26 26
44804- 14 14 14 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 1 0 0 1 0 0 1 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 0 0 0
44818- 0 0 0 0 0 0 0 0 0 0 0 0
44819- 0 0 0 0 0 0 10 10 10 26 26 26
44820- 50 50 50 82 82 82 58 58 58 6 6 6
44821- 2 2 6 2 2 6 2 2 6 2 2 6
44822- 2 2 6 2 2 6 2 2 6 2 2 6
44823- 6 6 6 54 54 54 86 86 86 66 66 66
44824- 38 38 38 18 18 18 6 6 6 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 0 0 0 0 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 0 0 0
44838- 0 0 0 0 0 0 0 0 0 0 0 0
44839- 0 0 0 6 6 6 22 22 22 50 50 50
44840- 78 78 78 34 34 34 2 2 6 2 2 6
44841- 2 2 6 2 2 6 2 2 6 2 2 6
44842- 2 2 6 2 2 6 2 2 6 2 2 6
44843- 2 2 6 2 2 6 6 6 6 70 70 70
44844- 78 78 78 46 46 46 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0 0
44853- 0 0 1 0 0 1 0 0 1 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 0 0 0
44858- 0 0 0 0 0 0 0 0 0 0 0 0
44859- 6 6 6 18 18 18 42 42 42 82 82 82
44860- 26 26 26 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 14 14 14
44863- 46 46 46 34 34 34 6 6 6 2 2 6
44864- 42 42 42 78 78 78 42 42 42 18 18 18
44865- 6 6 6 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 0 0 0 0 0 0 0
44873- 0 0 1 0 0 0 0 0 1 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 0 0 0
44878- 0 0 0 0 0 0 0 0 0 0 0 0
44879- 10 10 10 30 30 30 66 66 66 58 58 58
44880- 2 2 6 2 2 6 2 2 6 2 2 6
44881- 2 2 6 2 2 6 2 2 6 2 2 6
44882- 2 2 6 2 2 6 2 2 6 26 26 26
44883- 86 86 86 101 101 101 46 46 46 10 10 10
44884- 2 2 6 58 58 58 70 70 70 34 34 34
44885- 10 10 10 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 0 0 0 0 0 0 0 0 0 0
44893- 0 0 1 0 0 1 0 0 1 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 0 0 0
44898- 0 0 0 0 0 0 0 0 0 0 0 0
44899- 14 14 14 42 42 42 86 86 86 10 10 10
44900- 2 2 6 2 2 6 2 2 6 2 2 6
44901- 2 2 6 2 2 6 2 2 6 2 2 6
44902- 2 2 6 2 2 6 2 2 6 30 30 30
44903- 94 94 94 94 94 94 58 58 58 26 26 26
44904- 2 2 6 6 6 6 78 78 78 54 54 54
44905- 22 22 22 6 6 6 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 0 0 0 0 0 0 0 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 0 0 0
44918- 0 0 0 0 0 0 0 0 0 6 6 6
44919- 22 22 22 62 62 62 62 62 62 2 2 6
44920- 2 2 6 2 2 6 2 2 6 2 2 6
44921- 2 2 6 2 2 6 2 2 6 2 2 6
44922- 2 2 6 2 2 6 2 2 6 26 26 26
44923- 54 54 54 38 38 38 18 18 18 10 10 10
44924- 2 2 6 2 2 6 34 34 34 82 82 82
44925- 38 38 38 14 14 14 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 1 0 0 1 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 0 0 0
44938- 0 0 0 0 0 0 0 0 0 6 6 6
44939- 30 30 30 78 78 78 30 30 30 2 2 6
44940- 2 2 6 2 2 6 2 2 6 2 2 6
44941- 2 2 6 2 2 6 2 2 6 2 2 6
44942- 2 2 6 2 2 6 2 2 6 10 10 10
44943- 10 10 10 2 2 6 2 2 6 2 2 6
44944- 2 2 6 2 2 6 2 2 6 78 78 78
44945- 50 50 50 18 18 18 6 6 6 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 0 0 0 0
44952- 0 0 0 0 0 0 0 0 0 0 0 0
44953- 0 0 1 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 0 0 0
44958- 0 0 0 0 0 0 0 0 0 10 10 10
44959- 38 38 38 86 86 86 14 14 14 2 2 6
44960- 2 2 6 2 2 6 2 2 6 2 2 6
44961- 2 2 6 2 2 6 2 2 6 2 2 6
44962- 2 2 6 2 2 6 2 2 6 2 2 6
44963- 2 2 6 2 2 6 2 2 6 2 2 6
44964- 2 2 6 2 2 6 2 2 6 54 54 54
44965- 66 66 66 26 26 26 6 6 6 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 1 0 0 1 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 0 0 0
44978- 0 0 0 0 0 0 0 0 0 14 14 14
44979- 42 42 42 82 82 82 2 2 6 2 2 6
44980- 2 2 6 6 6 6 10 10 10 2 2 6
44981- 2 2 6 2 2 6 2 2 6 2 2 6
44982- 2 2 6 2 2 6 2 2 6 6 6 6
44983- 14 14 14 10 10 10 2 2 6 2 2 6
44984- 2 2 6 2 2 6 2 2 6 18 18 18
44985- 82 82 82 34 34 34 10 10 10 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 0 0 0 0
44992- 0 0 0 0 0 0 0 0 0 0 0 0
44993- 0 0 1 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 0 0 0
44998- 0 0 0 0 0 0 0 0 0 14 14 14
44999- 46 46 46 86 86 86 2 2 6 2 2 6
45000- 6 6 6 6 6 6 22 22 22 34 34 34
45001- 6 6 6 2 2 6 2 2 6 2 2 6
45002- 2 2 6 2 2 6 18 18 18 34 34 34
45003- 10 10 10 50 50 50 22 22 22 2 2 6
45004- 2 2 6 2 2 6 2 2 6 10 10 10
45005- 86 86 86 42 42 42 14 14 14 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 0 0 0 0
45012- 0 0 0 0 0 0 0 0 0 0 0 0
45013- 0 0 1 0 0 1 0 0 1 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 0 0 0
45018- 0 0 0 0 0 0 0 0 0 14 14 14
45019- 46 46 46 86 86 86 2 2 6 2 2 6
45020- 38 38 38 116 116 116 94 94 94 22 22 22
45021- 22 22 22 2 2 6 2 2 6 2 2 6
45022- 14 14 14 86 86 86 138 138 138 162 162 162
45023-154 154 154 38 38 38 26 26 26 6 6 6
45024- 2 2 6 2 2 6 2 2 6 2 2 6
45025- 86 86 86 46 46 46 14 14 14 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 0 0 0 0
45032- 0 0 0 0 0 0 0 0 0 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 0 0 0
45038- 0 0 0 0 0 0 0 0 0 14 14 14
45039- 46 46 46 86 86 86 2 2 6 14 14 14
45040-134 134 134 198 198 198 195 195 195 116 116 116
45041- 10 10 10 2 2 6 2 2 6 6 6 6
45042-101 98 89 187 187 187 210 210 210 218 218 218
45043-214 214 214 134 134 134 14 14 14 6 6 6
45044- 2 2 6 2 2 6 2 2 6 2 2 6
45045- 86 86 86 50 50 50 18 18 18 6 6 6
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 1 0 0 0
45053- 0 0 1 0 0 1 0 0 1 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 0 0 0
45058- 0 0 0 0 0 0 0 0 0 14 14 14
45059- 46 46 46 86 86 86 2 2 6 54 54 54
45060-218 218 218 195 195 195 226 226 226 246 246 246
45061- 58 58 58 2 2 6 2 2 6 30 30 30
45062-210 210 210 253 253 253 174 174 174 123 123 123
45063-221 221 221 234 234 234 74 74 74 2 2 6
45064- 2 2 6 2 2 6 2 2 6 2 2 6
45065- 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0
45078- 0 0 0 0 0 0 0 0 0 14 14 14
45079- 46 46 46 82 82 82 2 2 6 106 106 106
45080-170 170 170 26 26 26 86 86 86 226 226 226
45081-123 123 123 10 10 10 14 14 14 46 46 46
45082-231 231 231 190 190 190 6 6 6 70 70 70
45083- 90 90 90 238 238 238 158 158 158 2 2 6
45084- 2 2 6 2 2 6 2 2 6 2 2 6
45085- 70 70 70 58 58 58 22 22 22 6 6 6
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 1 0 0 0
45093- 0 0 1 0 0 1 0 0 1 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 0 0 0
45098- 0 0 0 0 0 0 0 0 0 14 14 14
45099- 42 42 42 86 86 86 6 6 6 116 116 116
45100-106 106 106 6 6 6 70 70 70 149 149 149
45101-128 128 128 18 18 18 38 38 38 54 54 54
45102-221 221 221 106 106 106 2 2 6 14 14 14
45103- 46 46 46 190 190 190 198 198 198 2 2 6
45104- 2 2 6 2 2 6 2 2 6 2 2 6
45105- 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 0
45113- 0 0 1 0 0 0 0 0 1 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 0 0 0
45118- 0 0 0 0 0 0 0 0 0 14 14 14
45119- 42 42 42 94 94 94 14 14 14 101 101 101
45120-128 128 128 2 2 6 18 18 18 116 116 116
45121-118 98 46 121 92 8 121 92 8 98 78 10
45122-162 162 162 106 106 106 2 2 6 2 2 6
45123- 2 2 6 195 195 195 195 195 195 6 6 6
45124- 2 2 6 2 2 6 2 2 6 2 2 6
45125- 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 1
45133- 0 0 1 0 0 0 0 0 1 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 0 0 0
45138- 0 0 0 0 0 0 0 0 0 10 10 10
45139- 38 38 38 90 90 90 14 14 14 58 58 58
45140-210 210 210 26 26 26 54 38 6 154 114 10
45141-226 170 11 236 186 11 225 175 15 184 144 12
45142-215 174 15 175 146 61 37 26 9 2 2 6
45143- 70 70 70 246 246 246 138 138 138 2 2 6
45144- 2 2 6 2 2 6 2 2 6 2 2 6
45145- 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0
45158- 0 0 0 0 0 0 0 0 0 10 10 10
45159- 38 38 38 86 86 86 14 14 14 10 10 10
45160-195 195 195 188 164 115 192 133 9 225 175 15
45161-239 182 13 234 190 10 232 195 16 232 200 30
45162-245 207 45 241 208 19 232 195 16 184 144 12
45163-218 194 134 211 206 186 42 42 42 2 2 6
45164- 2 2 6 2 2 6 2 2 6 2 2 6
45165- 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
45178- 0 0 0 0 0 0 0 0 0 10 10 10
45179- 34 34 34 86 86 86 14 14 14 2 2 6
45180-121 87 25 192 133 9 219 162 10 239 182 13
45181-236 186 11 232 195 16 241 208 19 244 214 54
45182-246 218 60 246 218 38 246 215 20 241 208 19
45183-241 208 19 226 184 13 121 87 25 2 2 6
45184- 2 2 6 2 2 6 2 2 6 2 2 6
45185- 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0 0 0 0
45198- 0 0 0 0 0 0 0 0 0 10 10 10
45199- 34 34 34 82 82 82 30 30 30 61 42 6
45200-180 123 7 206 145 10 230 174 11 239 182 13
45201-234 190 10 238 202 15 241 208 19 246 218 74
45202-246 218 38 246 215 20 246 215 20 246 215 20
45203-226 184 13 215 174 15 184 144 12 6 6 6
45204- 2 2 6 2 2 6 2 2 6 2 2 6
45205- 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0 0 0 0
45218- 0 0 0 0 0 0 0 0 0 10 10 10
45219- 30 30 30 78 78 78 50 50 50 104 69 6
45220-192 133 9 216 158 10 236 178 12 236 186 11
45221-232 195 16 241 208 19 244 214 54 245 215 43
45222-246 215 20 246 215 20 241 208 19 198 155 10
45223-200 144 11 216 158 10 156 118 10 2 2 6
45224- 2 2 6 2 2 6 2 2 6 2 2 6
45225- 6 6 6 90 90 90 54 54 54 18 18 18
45226- 6 6 6 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 0 0 0 0 0 0 0 0 0
45238- 0 0 0 0 0 0 0 0 0 10 10 10
45239- 30 30 30 78 78 78 46 46 46 22 22 22
45240-137 92 6 210 162 10 239 182 13 238 190 10
45241-238 202 15 241 208 19 246 215 20 246 215 20
45242-241 208 19 203 166 17 185 133 11 210 150 10
45243-216 158 10 210 150 10 102 78 10 2 2 6
45244- 6 6 6 54 54 54 14 14 14 2 2 6
45245- 2 2 6 62 62 62 74 74 74 30 30 30
45246- 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
45258- 0 0 0 0 0 0 0 0 0 10 10 10
45259- 34 34 34 78 78 78 50 50 50 6 6 6
45260- 94 70 30 139 102 15 190 146 13 226 184 13
45261-232 200 30 232 195 16 215 174 15 190 146 13
45262-168 122 10 192 133 9 210 150 10 213 154 11
45263-202 150 34 182 157 106 101 98 89 2 2 6
45264- 2 2 6 78 78 78 116 116 116 58 58 58
45265- 2 2 6 22 22 22 90 90 90 46 46 46
45266- 18 18 18 6 6 6 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 0 0 0
45277- 0 0 0 0 0 0 0 0 0 0 0 0
45278- 0 0 0 0 0 0 0 0 0 10 10 10
45279- 38 38 38 86 86 86 50 50 50 6 6 6
45280-128 128 128 174 154 114 156 107 11 168 122 10
45281-198 155 10 184 144 12 197 138 11 200 144 11
45282-206 145 10 206 145 10 197 138 11 188 164 115
45283-195 195 195 198 198 198 174 174 174 14 14 14
45284- 2 2 6 22 22 22 116 116 116 116 116 116
45285- 22 22 22 2 2 6 74 74 74 70 70 70
45286- 30 30 30 10 10 10 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 0 0 0
45297- 0 0 0 0 0 0 0 0 0 0 0 0
45298- 0 0 0 0 0 0 6 6 6 18 18 18
45299- 50 50 50 101 101 101 26 26 26 10 10 10
45300-138 138 138 190 190 190 174 154 114 156 107 11
45301-197 138 11 200 144 11 197 138 11 192 133 9
45302-180 123 7 190 142 34 190 178 144 187 187 187
45303-202 202 202 221 221 221 214 214 214 66 66 66
45304- 2 2 6 2 2 6 50 50 50 62 62 62
45305- 6 6 6 2 2 6 10 10 10 90 90 90
45306- 50 50 50 18 18 18 6 6 6 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 0 0 0 0 0 0
45317- 0 0 0 0 0 0 0 0 0 0 0 0
45318- 0 0 0 0 0 0 10 10 10 34 34 34
45319- 74 74 74 74 74 74 2 2 6 6 6 6
45320-144 144 144 198 198 198 190 190 190 178 166 146
45321-154 121 60 156 107 11 156 107 11 168 124 44
45322-174 154 114 187 187 187 190 190 190 210 210 210
45323-246 246 246 253 253 253 253 253 253 182 182 182
45324- 6 6 6 2 2 6 2 2 6 2 2 6
45325- 2 2 6 2 2 6 2 2 6 62 62 62
45326- 74 74 74 34 34 34 14 14 14 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 0 0 0 0 0 0 0 0 0
45337- 0 0 0 0 0 0 0 0 0 0 0 0
45338- 0 0 0 10 10 10 22 22 22 54 54 54
45339- 94 94 94 18 18 18 2 2 6 46 46 46
45340-234 234 234 221 221 221 190 190 190 190 190 190
45341-190 190 190 187 187 187 187 187 187 190 190 190
45342-190 190 190 195 195 195 214 214 214 242 242 242
45343-253 253 253 253 253 253 253 253 253 253 253 253
45344- 82 82 82 2 2 6 2 2 6 2 2 6
45345- 2 2 6 2 2 6 2 2 6 14 14 14
45346- 86 86 86 54 54 54 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- 0 0 0 0 0 0 0 0 0 0 0 0
45357- 0 0 0 0 0 0 0 0 0 0 0 0
45358- 6 6 6 18 18 18 46 46 46 90 90 90
45359- 46 46 46 18 18 18 6 6 6 182 182 182
45360-253 253 253 246 246 246 206 206 206 190 190 190
45361-190 190 190 190 190 190 190 190 190 190 190 190
45362-206 206 206 231 231 231 250 250 250 253 253 253
45363-253 253 253 253 253 253 253 253 253 253 253 253
45364-202 202 202 14 14 14 2 2 6 2 2 6
45365- 2 2 6 2 2 6 2 2 6 2 2 6
45366- 42 42 42 86 86 86 42 42 42 18 18 18
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- 0 0 0 0 0 0 0 0 0 0 0 0
45377- 0 0 0 0 0 0 0 0 0 6 6 6
45378- 14 14 14 38 38 38 74 74 74 66 66 66
45379- 2 2 6 6 6 6 90 90 90 250 250 250
45380-253 253 253 253 253 253 238 238 238 198 198 198
45381-190 190 190 190 190 190 195 195 195 221 221 221
45382-246 246 246 253 253 253 253 253 253 253 253 253
45383-253 253 253 253 253 253 253 253 253 253 253 253
45384-253 253 253 82 82 82 2 2 6 2 2 6
45385- 2 2 6 2 2 6 2 2 6 2 2 6
45386- 2 2 6 78 78 78 70 70 70 34 34 34
45387- 14 14 14 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
45397- 0 0 0 0 0 0 0 0 0 14 14 14
45398- 34 34 34 66 66 66 78 78 78 6 6 6
45399- 2 2 6 18 18 18 218 218 218 253 253 253
45400-253 253 253 253 253 253 253 253 253 246 246 246
45401-226 226 226 231 231 231 246 246 246 253 253 253
45402-253 253 253 253 253 253 253 253 253 253 253 253
45403-253 253 253 253 253 253 253 253 253 253 253 253
45404-253 253 253 178 178 178 2 2 6 2 2 6
45405- 2 2 6 2 2 6 2 2 6 2 2 6
45406- 2 2 6 18 18 18 90 90 90 62 62 62
45407- 30 30 30 10 10 10 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 0 0 0
45416- 0 0 0 0 0 0 0 0 0 0 0 0
45417- 0 0 0 0 0 0 10 10 10 26 26 26
45418- 58 58 58 90 90 90 18 18 18 2 2 6
45419- 2 2 6 110 110 110 253 253 253 253 253 253
45420-253 253 253 253 253 253 253 253 253 253 253 253
45421-250 250 250 253 253 253 253 253 253 253 253 253
45422-253 253 253 253 253 253 253 253 253 253 253 253
45423-253 253 253 253 253 253 253 253 253 253 253 253
45424-253 253 253 231 231 231 18 18 18 2 2 6
45425- 2 2 6 2 2 6 2 2 6 2 2 6
45426- 2 2 6 2 2 6 18 18 18 94 94 94
45427- 54 54 54 26 26 26 10 10 10 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 0 0 0
45436- 0 0 0 0 0 0 0 0 0 0 0 0
45437- 0 0 0 6 6 6 22 22 22 50 50 50
45438- 90 90 90 26 26 26 2 2 6 2 2 6
45439- 14 14 14 195 195 195 250 250 250 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 253 253 253 253 253 253 253 253 253
45444-250 250 250 242 242 242 54 54 54 2 2 6
45445- 2 2 6 2 2 6 2 2 6 2 2 6
45446- 2 2 6 2 2 6 2 2 6 38 38 38
45447- 86 86 86 50 50 50 22 22 22 6 6 6
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 0 0 0
45456- 0 0 0 0 0 0 0 0 0 0 0 0
45457- 6 6 6 14 14 14 38 38 38 82 82 82
45458- 34 34 34 2 2 6 2 2 6 2 2 6
45459- 42 42 42 195 195 195 246 246 246 253 253 253
45460-253 253 253 253 253 253 253 253 253 250 250 250
45461-242 242 242 242 242 242 250 250 250 253 253 253
45462-253 253 253 253 253 253 253 253 253 253 253 253
45463-253 253 253 250 250 250 246 246 246 238 238 238
45464-226 226 226 231 231 231 101 101 101 6 6 6
45465- 2 2 6 2 2 6 2 2 6 2 2 6
45466- 2 2 6 2 2 6 2 2 6 2 2 6
45467- 38 38 38 82 82 82 42 42 42 14 14 14
45468- 6 6 6 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 0 0 0 0 0 0
45476- 0 0 0 0 0 0 0 0 0 0 0 0
45477- 10 10 10 26 26 26 62 62 62 66 66 66
45478- 2 2 6 2 2 6 2 2 6 6 6 6
45479- 70 70 70 170 170 170 206 206 206 234 234 234
45480-246 246 246 250 250 250 250 250 250 238 238 238
45481-226 226 226 231 231 231 238 238 238 250 250 250
45482-250 250 250 250 250 250 246 246 246 231 231 231
45483-214 214 214 206 206 206 202 202 202 202 202 202
45484-198 198 198 202 202 202 182 182 182 18 18 18
45485- 2 2 6 2 2 6 2 2 6 2 2 6
45486- 2 2 6 2 2 6 2 2 6 2 2 6
45487- 2 2 6 62 62 62 66 66 66 30 30 30
45488- 10 10 10 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 0 0 0 0 0 0
45496- 0 0 0 0 0 0 0 0 0 0 0 0
45497- 14 14 14 42 42 42 82 82 82 18 18 18
45498- 2 2 6 2 2 6 2 2 6 10 10 10
45499- 94 94 94 182 182 182 218 218 218 242 242 242
45500-250 250 250 253 253 253 253 253 253 250 250 250
45501-234 234 234 253 253 253 253 253 253 253 253 253
45502-253 253 253 253 253 253 253 253 253 246 246 246
45503-238 238 238 226 226 226 210 210 210 202 202 202
45504-195 195 195 195 195 195 210 210 210 158 158 158
45505- 6 6 6 14 14 14 50 50 50 14 14 14
45506- 2 2 6 2 2 6 2 2 6 2 2 6
45507- 2 2 6 6 6 6 86 86 86 46 46 46
45508- 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0
45516- 0 0 0 0 0 0 0 0 0 6 6 6
45517- 22 22 22 54 54 54 70 70 70 2 2 6
45518- 2 2 6 10 10 10 2 2 6 22 22 22
45519-166 166 166 231 231 231 250 250 250 253 253 253
45520-253 253 253 253 253 253 253 253 253 250 250 250
45521-242 242 242 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 246 246 246
45524-231 231 231 206 206 206 198 198 198 226 226 226
45525- 94 94 94 2 2 6 6 6 6 38 38 38
45526- 30 30 30 2 2 6 2 2 6 2 2 6
45527- 2 2 6 2 2 6 62 62 62 66 66 66
45528- 26 26 26 10 10 10 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 0 0 0 0 0 0 0 0 0
45536- 0 0 0 0 0 0 0 0 0 10 10 10
45537- 30 30 30 74 74 74 50 50 50 2 2 6
45538- 26 26 26 26 26 26 2 2 6 106 106 106
45539-238 238 238 253 253 253 253 253 253 253 253 253
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 246 246 246 218 218 218 202 202 202
45545-210 210 210 14 14 14 2 2 6 2 2 6
45546- 30 30 30 22 22 22 2 2 6 2 2 6
45547- 2 2 6 2 2 6 18 18 18 86 86 86
45548- 42 42 42 14 14 14 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- 0 0 0 0 0 0 0 0 0 0 0 0
45556- 0 0 0 0 0 0 0 0 0 14 14 14
45557- 42 42 42 90 90 90 22 22 22 2 2 6
45558- 42 42 42 2 2 6 18 18 18 218 218 218
45559-253 253 253 253 253 253 253 253 253 253 253 253
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 250 250 250 221 221 221
45565-218 218 218 101 101 101 2 2 6 14 14 14
45566- 18 18 18 38 38 38 10 10 10 2 2 6
45567- 2 2 6 2 2 6 2 2 6 78 78 78
45568- 58 58 58 22 22 22 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
45576- 0 0 0 0 0 0 6 6 6 18 18 18
45577- 54 54 54 82 82 82 2 2 6 26 26 26
45578- 22 22 22 2 2 6 123 123 123 253 253 253
45579-253 253 253 253 253 253 253 253 253 253 253 253
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 253 253 253 250 250 250
45585-238 238 238 198 198 198 6 6 6 38 38 38
45586- 58 58 58 26 26 26 38 38 38 2 2 6
45587- 2 2 6 2 2 6 2 2 6 46 46 46
45588- 78 78 78 30 30 30 10 10 10 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 0 0 0
45595- 0 0 0 0 0 0 0 0 0 0 0 0
45596- 0 0 0 0 0 0 10 10 10 30 30 30
45597- 74 74 74 58 58 58 2 2 6 42 42 42
45598- 2 2 6 22 22 22 231 231 231 253 253 253
45599-253 253 253 253 253 253 253 253 253 253 253 253
45600-253 253 253 253 253 253 253 253 253 250 250 250
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 253 253 253 253 253 253
45605-253 253 253 246 246 246 46 46 46 38 38 38
45606- 42 42 42 14 14 14 38 38 38 14 14 14
45607- 2 2 6 2 2 6 2 2 6 6 6 6
45608- 86 86 86 46 46 46 14 14 14 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 0 0 0
45615- 0 0 0 0 0 0 0 0 0 0 0 0
45616- 0 0 0 6 6 6 14 14 14 42 42 42
45617- 90 90 90 18 18 18 18 18 18 26 26 26
45618- 2 2 6 116 116 116 253 253 253 253 253 253
45619-253 253 253 253 253 253 253 253 253 253 253 253
45620-253 253 253 253 253 253 250 250 250 238 238 238
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 253 253 253 253 253 253
45625-253 253 253 253 253 253 94 94 94 6 6 6
45626- 2 2 6 2 2 6 10 10 10 34 34 34
45627- 2 2 6 2 2 6 2 2 6 2 2 6
45628- 74 74 74 58 58 58 22 22 22 6 6 6
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 0 0 0
45635- 0 0 0 0 0 0 0 0 0 0 0 0
45636- 0 0 0 10 10 10 26 26 26 66 66 66
45637- 82 82 82 2 2 6 38 38 38 6 6 6
45638- 14 14 14 210 210 210 253 253 253 253 253 253
45639-253 253 253 253 253 253 253 253 253 253 253 253
45640-253 253 253 253 253 253 246 246 246 242 242 242
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 253 253 253 253 253 253
45645-253 253 253 253 253 253 144 144 144 2 2 6
45646- 2 2 6 2 2 6 2 2 6 46 46 46
45647- 2 2 6 2 2 6 2 2 6 2 2 6
45648- 42 42 42 74 74 74 30 30 30 10 10 10
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 0 0 0 0 0 0
45655- 0 0 0 0 0 0 0 0 0 0 0 0
45656- 6 6 6 14 14 14 42 42 42 90 90 90
45657- 26 26 26 6 6 6 42 42 42 2 2 6
45658- 74 74 74 250 250 250 253 253 253 253 253 253
45659-253 253 253 253 253 253 253 253 253 253 253 253
45660-253 253 253 253 253 253 242 242 242 242 242 242
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 253 253 253 253 253 253
45665-253 253 253 253 253 253 182 182 182 2 2 6
45666- 2 2 6 2 2 6 2 2 6 46 46 46
45667- 2 2 6 2 2 6 2 2 6 2 2 6
45668- 10 10 10 86 86 86 38 38 38 10 10 10
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 0 0 0 0 0 0
45675- 0 0 0 0 0 0 0 0 0 0 0 0
45676- 10 10 10 26 26 26 66 66 66 82 82 82
45677- 2 2 6 22 22 22 18 18 18 2 2 6
45678-149 149 149 253 253 253 253 253 253 253 253 253
45679-253 253 253 253 253 253 253 253 253 253 253 253
45680-253 253 253 253 253 253 234 234 234 242 242 242
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 253 253 253 253 253 253
45685-253 253 253 253 253 253 206 206 206 2 2 6
45686- 2 2 6 2 2 6 2 2 6 38 38 38
45687- 2 2 6 2 2 6 2 2 6 2 2 6
45688- 6 6 6 86 86 86 46 46 46 14 14 14
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 0 0 0 0 0 0
45695- 0 0 0 0 0 0 0 0 0 6 6 6
45696- 18 18 18 46 46 46 86 86 86 18 18 18
45697- 2 2 6 34 34 34 10 10 10 6 6 6
45698-210 210 210 253 253 253 253 253 253 253 253 253
45699-253 253 253 253 253 253 253 253 253 253 253 253
45700-253 253 253 253 253 253 234 234 234 242 242 242
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 253 253 253 253 253 253
45705-253 253 253 253 253 253 221 221 221 6 6 6
45706- 2 2 6 2 2 6 6 6 6 30 30 30
45707- 2 2 6 2 2 6 2 2 6 2 2 6
45708- 2 2 6 82 82 82 54 54 54 18 18 18
45709- 6 6 6 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 0 0 0 0 0 0
45715- 0 0 0 0 0 0 0 0 0 10 10 10
45716- 26 26 26 66 66 66 62 62 62 2 2 6
45717- 2 2 6 38 38 38 10 10 10 26 26 26
45718-238 238 238 253 253 253 253 253 253 253 253 253
45719-253 253 253 253 253 253 253 253 253 253 253 253
45720-253 253 253 253 253 253 231 231 231 238 238 238
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 253 253 253 253 253 253
45725-253 253 253 253 253 253 231 231 231 6 6 6
45726- 2 2 6 2 2 6 10 10 10 30 30 30
45727- 2 2 6 2 2 6 2 2 6 2 2 6
45728- 2 2 6 66 66 66 58 58 58 22 22 22
45729- 6 6 6 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 0 0 0
45734- 0 0 0 0 0 0 0 0 0 0 0 0
45735- 0 0 0 0 0 0 0 0 0 10 10 10
45736- 38 38 38 78 78 78 6 6 6 2 2 6
45737- 2 2 6 46 46 46 14 14 14 42 42 42
45738-246 246 246 253 253 253 253 253 253 253 253 253
45739-253 253 253 253 253 253 253 253 253 253 253 253
45740-253 253 253 253 253 253 231 231 231 242 242 242
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 253 253 253
45744-253 253 253 253 253 253 253 253 253 253 253 253
45745-253 253 253 253 253 253 234 234 234 10 10 10
45746- 2 2 6 2 2 6 22 22 22 14 14 14
45747- 2 2 6 2 2 6 2 2 6 2 2 6
45748- 2 2 6 66 66 66 62 62 62 22 22 22
45749- 6 6 6 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 0 0 0 0 0 0 0 0 0
45754- 0 0 0 0 0 0 0 0 0 0 0 0
45755- 0 0 0 0 0 0 6 6 6 18 18 18
45756- 50 50 50 74 74 74 2 2 6 2 2 6
45757- 14 14 14 70 70 70 34 34 34 62 62 62
45758-250 250 250 253 253 253 253 253 253 253 253 253
45759-253 253 253 253 253 253 253 253 253 253 253 253
45760-253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253
45764-253 253 253 253 253 253 253 253 253 253 253 253
45765-253 253 253 253 253 253 234 234 234 14 14 14
45766- 2 2 6 2 2 6 30 30 30 2 2 6
45767- 2 2 6 2 2 6 2 2 6 2 2 6
45768- 2 2 6 66 66 66 62 62 62 22 22 22
45769- 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
45774- 0 0 0 0 0 0 0 0 0 0 0 0
45775- 0 0 0 0 0 0 6 6 6 18 18 18
45776- 54 54 54 62 62 62 2 2 6 2 2 6
45777- 2 2 6 30 30 30 46 46 46 70 70 70
45778-250 250 250 253 253 253 253 253 253 253 253 253
45779-253 253 253 253 253 253 253 253 253 253 253 253
45780-253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253
45784-253 253 253 253 253 253 253 253 253 253 253 253
45785-253 253 253 253 253 253 226 226 226 10 10 10
45786- 2 2 6 6 6 6 30 30 30 2 2 6
45787- 2 2 6 2 2 6 2 2 6 2 2 6
45788- 2 2 6 66 66 66 58 58 58 22 22 22
45789- 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
45794- 0 0 0 0 0 0 0 0 0 0 0 0
45795- 0 0 0 0 0 0 6 6 6 22 22 22
45796- 58 58 58 62 62 62 2 2 6 2 2 6
45797- 2 2 6 2 2 6 30 30 30 78 78 78
45798-250 250 250 253 253 253 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 231 231 231 246 246 246
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 253 253 253 253 253 253 253 253 253
45804-253 253 253 253 253 253 253 253 253 253 253 253
45805-253 253 253 253 253 253 206 206 206 2 2 6
45806- 22 22 22 34 34 34 18 14 6 22 22 22
45807- 26 26 26 18 18 18 6 6 6 2 2 6
45808- 2 2 6 82 82 82 54 54 54 18 18 18
45809- 6 6 6 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 0 0 0
45813- 0 0 0 0 0 0 0 0 0 0 0 0
45814- 0 0 0 0 0 0 0 0 0 0 0 0
45815- 0 0 0 0 0 0 6 6 6 26 26 26
45816- 62 62 62 106 106 106 74 54 14 185 133 11
45817-210 162 10 121 92 8 6 6 6 62 62 62
45818-238 238 238 253 253 253 253 253 253 253 253 253
45819-253 253 253 253 253 253 253 253 253 253 253 253
45820-253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253 253 253 253 253 253 253
45824-253 253 253 253 253 253 253 253 253 253 253 253
45825-253 253 253 253 253 253 158 158 158 18 18 18
45826- 14 14 14 2 2 6 2 2 6 2 2 6
45827- 6 6 6 18 18 18 66 66 66 38 38 38
45828- 6 6 6 94 94 94 50 50 50 18 18 18
45829- 6 6 6 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 0 0 0
45833- 0 0 0 0 0 0 0 0 0 0 0 0
45834- 0 0 0 0 0 0 0 0 0 6 6 6
45835- 10 10 10 10 10 10 18 18 18 38 38 38
45836- 78 78 78 142 134 106 216 158 10 242 186 14
45837-246 190 14 246 190 14 156 118 10 10 10 10
45838- 90 90 90 238 238 238 253 253 253 253 253 253
45839-253 253 253 253 253 253 253 253 253 253 253 253
45840-253 253 253 253 253 253 231 231 231 250 250 250
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 253 253 253 253 253 253 253 253 253
45844-253 253 253 253 253 253 253 253 253 246 230 190
45845-238 204 91 238 204 91 181 142 44 37 26 9
45846- 2 2 6 2 2 6 2 2 6 2 2 6
45847- 2 2 6 2 2 6 38 38 38 46 46 46
45848- 26 26 26 106 106 106 54 54 54 18 18 18
45849- 6 6 6 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 0 0 0
45853- 0 0 0 0 0 0 0 0 0 0 0 0
45854- 0 0 0 6 6 6 14 14 14 22 22 22
45855- 30 30 30 38 38 38 50 50 50 70 70 70
45856-106 106 106 190 142 34 226 170 11 242 186 14
45857-246 190 14 246 190 14 246 190 14 154 114 10
45858- 6 6 6 74 74 74 226 226 226 253 253 253
45859-253 253 253 253 253 253 253 253 253 253 253 253
45860-253 253 253 253 253 253 231 231 231 250 250 250
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-253 253 253 253 253 253 253 253 253 253 253 253
45864-253 253 253 253 253 253 253 253 253 228 184 62
45865-241 196 14 241 208 19 232 195 16 38 30 10
45866- 2 2 6 2 2 6 2 2 6 2 2 6
45867- 2 2 6 6 6 6 30 30 30 26 26 26
45868-203 166 17 154 142 90 66 66 66 26 26 26
45869- 6 6 6 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 0 0 0
45873- 0 0 0 0 0 0 0 0 0 0 0 0
45874- 6 6 6 18 18 18 38 38 38 58 58 58
45875- 78 78 78 86 86 86 101 101 101 123 123 123
45876-175 146 61 210 150 10 234 174 13 246 186 14
45877-246 190 14 246 190 14 246 190 14 238 190 10
45878-102 78 10 2 2 6 46 46 46 198 198 198
45879-253 253 253 253 253 253 253 253 253 253 253 253
45880-253 253 253 253 253 253 234 234 234 242 242 242
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-253 253 253 253 253 253 253 253 253 253 253 253
45884-253 253 253 253 253 253 253 253 253 224 178 62
45885-242 186 14 241 196 14 210 166 10 22 18 6
45886- 2 2 6 2 2 6 2 2 6 2 2 6
45887- 2 2 6 2 2 6 6 6 6 121 92 8
45888-238 202 15 232 195 16 82 82 82 34 34 34
45889- 10 10 10 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 0 0 0
45893- 0 0 0 0 0 0 0 0 0 0 0 0
45894- 14 14 14 38 38 38 70 70 70 154 122 46
45895-190 142 34 200 144 11 197 138 11 197 138 11
45896-213 154 11 226 170 11 242 186 14 246 190 14
45897-246 190 14 246 190 14 246 190 14 246 190 14
45898-225 175 15 46 32 6 2 2 6 22 22 22
45899-158 158 158 250 250 250 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 253 253 253 253 253 253 253 253 253
45904-253 253 253 250 250 250 242 242 242 224 178 62
45905-239 182 13 236 186 11 213 154 11 46 32 6
45906- 2 2 6 2 2 6 2 2 6 2 2 6
45907- 2 2 6 2 2 6 61 42 6 225 175 15
45908-238 190 10 236 186 11 112 100 78 42 42 42
45909- 14 14 14 0 0 0 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 0 0 0
45913- 0 0 0 0 0 0 0 0 0 6 6 6
45914- 22 22 22 54 54 54 154 122 46 213 154 11
45915-226 170 11 230 174 11 226 170 11 226 170 11
45916-236 178 12 242 186 14 246 190 14 246 190 14
45917-246 190 14 246 190 14 246 190 14 246 190 14
45918-241 196 14 184 144 12 10 10 10 2 2 6
45919- 6 6 6 116 116 116 242 242 242 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 253 253 253 253 253 253 253 253 253
45924-253 253 253 231 231 231 198 198 198 214 170 54
45925-236 178 12 236 178 12 210 150 10 137 92 6
45926- 18 14 6 2 2 6 2 2 6 2 2 6
45927- 6 6 6 70 47 6 200 144 11 236 178 12
45928-239 182 13 239 182 13 124 112 88 58 58 58
45929- 22 22 22 6 6 6 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 0 0 0
45933- 0 0 0 0 0 0 0 0 0 10 10 10
45934- 30 30 30 70 70 70 180 133 36 226 170 11
45935-239 182 13 242 186 14 242 186 14 246 186 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-246 190 14 232 195 16 98 70 6 2 2 6
45939- 2 2 6 2 2 6 66 66 66 221 221 221
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-253 253 253 253 253 253 253 253 253 253 253 253
45944-253 253 253 206 206 206 198 198 198 214 166 58
45945-230 174 11 230 174 11 216 158 10 192 133 9
45946-163 110 8 116 81 8 102 78 10 116 81 8
45947-167 114 7 197 138 11 226 170 11 239 182 13
45948-242 186 14 242 186 14 162 146 94 78 78 78
45949- 34 34 34 14 14 14 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 0 0 0
45953- 0 0 0 0 0 0 0 0 0 6 6 6
45954- 30 30 30 78 78 78 190 142 34 226 170 11
45955-239 182 13 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-246 190 14 241 196 14 203 166 17 22 18 6
45959- 2 2 6 2 2 6 2 2 6 38 38 38
45960-218 218 218 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 253 253 253
45963-253 253 253 253 253 253 253 253 253 253 253 253
45964-250 250 250 206 206 206 198 198 198 202 162 69
45965-226 170 11 236 178 12 224 166 10 210 150 10
45966-200 144 11 197 138 11 192 133 9 197 138 11
45967-210 150 10 226 170 11 242 186 14 246 190 14
45968-246 190 14 246 186 14 225 175 15 124 112 88
45969- 62 62 62 30 30 30 14 14 14 6 6 6
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 0 0 0
45973- 0 0 0 0 0 0 0 0 0 10 10 10
45974- 30 30 30 78 78 78 174 135 50 224 166 10
45975-239 182 13 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 246 190 14 241 196 14 139 102 15
45979- 2 2 6 2 2 6 2 2 6 2 2 6
45980- 78 78 78 250 250 250 253 253 253 253 253 253
45981-253 253 253 253 253 253 253 253 253 253 253 253
45982-253 253 253 253 253 253 253 253 253 253 253 253
45983-253 253 253 253 253 253 253 253 253 253 253 253
45984-250 250 250 214 214 214 198 198 198 190 150 46
45985-219 162 10 236 178 12 234 174 13 224 166 10
45986-216 158 10 213 154 11 213 154 11 216 158 10
45987-226 170 11 239 182 13 246 190 14 246 190 14
45988-246 190 14 246 190 14 242 186 14 206 162 42
45989-101 101 101 58 58 58 30 30 30 14 14 14
45990- 6 6 6 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 0 0 0 0 0 0
45993- 0 0 0 0 0 0 0 0 0 10 10 10
45994- 30 30 30 74 74 74 174 135 50 216 158 10
45995-236 178 12 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-246 190 14 246 190 14 241 196 14 226 184 13
45999- 61 42 6 2 2 6 2 2 6 2 2 6
46000- 22 22 22 238 238 238 253 253 253 253 253 253
46001-253 253 253 253 253 253 253 253 253 253 253 253
46002-253 253 253 253 253 253 253 253 253 253 253 253
46003-253 253 253 253 253 253 253 253 253 253 253 253
46004-253 253 253 226 226 226 187 187 187 180 133 36
46005-216 158 10 236 178 12 239 182 13 236 178 12
46006-230 174 11 226 170 11 226 170 11 230 174 11
46007-236 178 12 242 186 14 246 190 14 246 190 14
46008-246 190 14 246 190 14 246 186 14 239 182 13
46009-206 162 42 106 106 106 66 66 66 34 34 34
46010- 14 14 14 6 6 6 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 0 0 0 0 0 0
46013- 0 0 0 0 0 0 0 0 0 6 6 6
46014- 26 26 26 70 70 70 163 133 67 213 154 11
46015-236 178 12 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 190 14 246 190 14 246 190 14 241 196 14
46019-190 146 13 18 14 6 2 2 6 2 2 6
46020- 46 46 46 246 246 246 253 253 253 253 253 253
46021-253 253 253 253 253 253 253 253 253 253 253 253
46022-253 253 253 253 253 253 253 253 253 253 253 253
46023-253 253 253 253 253 253 253 253 253 253 253 253
46024-253 253 253 221 221 221 86 86 86 156 107 11
46025-216 158 10 236 178 12 242 186 14 246 186 14
46026-242 186 14 239 182 13 239 182 13 242 186 14
46027-242 186 14 246 186 14 246 190 14 246 190 14
46028-246 190 14 246 190 14 246 190 14 246 190 14
46029-242 186 14 225 175 15 142 122 72 66 66 66
46030- 30 30 30 10 10 10 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 0 0 0 0 0 0
46033- 0 0 0 0 0 0 0 0 0 6 6 6
46034- 26 26 26 70 70 70 163 133 67 210 150 10
46035-236 178 12 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 246 190 14 246 190 14 246 190 14
46039-232 195 16 121 92 8 34 34 34 106 106 106
46040-221 221 221 253 253 253 253 253 253 253 253 253
46041-253 253 253 253 253 253 253 253 253 253 253 253
46042-253 253 253 253 253 253 253 253 253 253 253 253
46043-253 253 253 253 253 253 253 253 253 253 253 253
46044-242 242 242 82 82 82 18 14 6 163 110 8
46045-216 158 10 236 178 12 242 186 14 246 190 14
46046-246 190 14 246 190 14 246 190 14 246 190 14
46047-246 190 14 246 190 14 246 190 14 246 190 14
46048-246 190 14 246 190 14 246 190 14 246 190 14
46049-246 190 14 246 190 14 242 186 14 163 133 67
46050- 46 46 46 18 18 18 6 6 6 0 0 0
46051- 0 0 0 0 0 0 0 0 0 0 0 0
46052- 0 0 0 0 0 0 0 0 0 0 0 0
46053- 0 0 0 0 0 0 0 0 0 10 10 10
46054- 30 30 30 78 78 78 163 133 67 210 150 10
46055-236 178 12 246 186 14 246 190 14 246 190 14
46056-246 190 14 246 190 14 246 190 14 246 190 14
46057-246 190 14 246 190 14 246 190 14 246 190 14
46058-246 190 14 246 190 14 246 190 14 246 190 14
46059-241 196 14 215 174 15 190 178 144 253 253 253
46060-253 253 253 253 253 253 253 253 253 253 253 253
46061-253 253 253 253 253 253 253 253 253 253 253 253
46062-253 253 253 253 253 253 253 253 253 253 253 253
46063-253 253 253 253 253 253 253 253 253 218 218 218
46064- 58 58 58 2 2 6 22 18 6 167 114 7
46065-216 158 10 236 178 12 246 186 14 246 190 14
46066-246 190 14 246 190 14 246 190 14 246 190 14
46067-246 190 14 246 190 14 246 190 14 246 190 14
46068-246 190 14 246 190 14 246 190 14 246 190 14
46069-246 190 14 246 186 14 242 186 14 190 150 46
46070- 54 54 54 22 22 22 6 6 6 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 0 0 0
46073- 0 0 0 0 0 0 0 0 0 14 14 14
46074- 38 38 38 86 86 86 180 133 36 213 154 11
46075-236 178 12 246 186 14 246 190 14 246 190 14
46076-246 190 14 246 190 14 246 190 14 246 190 14
46077-246 190 14 246 190 14 246 190 14 246 190 14
46078-246 190 14 246 190 14 246 190 14 246 190 14
46079-246 190 14 232 195 16 190 146 13 214 214 214
46080-253 253 253 253 253 253 253 253 253 253 253 253
46081-253 253 253 253 253 253 253 253 253 253 253 253
46082-253 253 253 253 253 253 253 253 253 253 253 253
46083-253 253 253 250 250 250 170 170 170 26 26 26
46084- 2 2 6 2 2 6 37 26 9 163 110 8
46085-219 162 10 239 182 13 246 186 14 246 190 14
46086-246 190 14 246 190 14 246 190 14 246 190 14
46087-246 190 14 246 190 14 246 190 14 246 190 14
46088-246 190 14 246 190 14 246 190 14 246 190 14
46089-246 186 14 236 178 12 224 166 10 142 122 72
46090- 46 46 46 18 18 18 6 6 6 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 0 0 0
46093- 0 0 0 0 0 0 6 6 6 18 18 18
46094- 50 50 50 109 106 95 192 133 9 224 166 10
46095-242 186 14 246 190 14 246 190 14 246 190 14
46096-246 190 14 246 190 14 246 190 14 246 190 14
46097-246 190 14 246 190 14 246 190 14 246 190 14
46098-246 190 14 246 190 14 246 190 14 246 190 14
46099-242 186 14 226 184 13 210 162 10 142 110 46
46100-226 226 226 253 253 253 253 253 253 253 253 253
46101-253 253 253 253 253 253 253 253 253 253 253 253
46102-253 253 253 253 253 253 253 253 253 253 253 253
46103-198 198 198 66 66 66 2 2 6 2 2 6
46104- 2 2 6 2 2 6 50 34 6 156 107 11
46105-219 162 10 239 182 13 246 186 14 246 190 14
46106-246 190 14 246 190 14 246 190 14 246 190 14
46107-246 190 14 246 190 14 246 190 14 246 190 14
46108-246 190 14 246 190 14 246 190 14 242 186 14
46109-234 174 13 213 154 11 154 122 46 66 66 66
46110- 30 30 30 10 10 10 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- 0 0 0 0 0 0 6 6 6 22 22 22
46114- 58 58 58 154 121 60 206 145 10 234 174 13
46115-242 186 14 246 186 14 246 190 14 246 190 14
46116-246 190 14 246 190 14 246 190 14 246 190 14
46117-246 190 14 246 190 14 246 190 14 246 190 14
46118-246 190 14 246 190 14 246 190 14 246 190 14
46119-246 186 14 236 178 12 210 162 10 163 110 8
46120- 61 42 6 138 138 138 218 218 218 250 250 250
46121-253 253 253 253 253 253 253 253 253 250 250 250
46122-242 242 242 210 210 210 144 144 144 66 66 66
46123- 6 6 6 2 2 6 2 2 6 2 2 6
46124- 2 2 6 2 2 6 61 42 6 163 110 8
46125-216 158 10 236 178 12 246 190 14 246 190 14
46126-246 190 14 246 190 14 246 190 14 246 190 14
46127-246 190 14 246 190 14 246 190 14 246 190 14
46128-246 190 14 239 182 13 230 174 11 216 158 10
46129-190 142 34 124 112 88 70 70 70 38 38 38
46130- 18 18 18 6 6 6 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 22 22 22
46134- 62 62 62 168 124 44 206 145 10 224 166 10
46135-236 178 12 239 182 13 242 186 14 242 186 14
46136-246 186 14 246 190 14 246 190 14 246 190 14
46137-246 190 14 246 190 14 246 190 14 246 190 14
46138-246 190 14 246 190 14 246 190 14 246 190 14
46139-246 190 14 236 178 12 216 158 10 175 118 6
46140- 80 54 7 2 2 6 6 6 6 30 30 30
46141- 54 54 54 62 62 62 50 50 50 38 38 38
46142- 14 14 14 2 2 6 2 2 6 2 2 6
46143- 2 2 6 2 2 6 2 2 6 2 2 6
46144- 2 2 6 6 6 6 80 54 7 167 114 7
46145-213 154 11 236 178 12 246 190 14 246 190 14
46146-246 190 14 246 190 14 246 190 14 246 190 14
46147-246 190 14 242 186 14 239 182 13 239 182 13
46148-230 174 11 210 150 10 174 135 50 124 112 88
46149- 82 82 82 54 54 54 34 34 34 18 18 18
46150- 6 6 6 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 6 6 6 18 18 18
46154- 50 50 50 158 118 36 192 133 9 200 144 11
46155-216 158 10 219 162 10 224 166 10 226 170 11
46156-230 174 11 236 178 12 239 182 13 239 182 13
46157-242 186 14 246 186 14 246 190 14 246 190 14
46158-246 190 14 246 190 14 246 190 14 246 190 14
46159-246 186 14 230 174 11 210 150 10 163 110 8
46160-104 69 6 10 10 10 2 2 6 2 2 6
46161- 2 2 6 2 2 6 2 2 6 2 2 6
46162- 2 2 6 2 2 6 2 2 6 2 2 6
46163- 2 2 6 2 2 6 2 2 6 2 2 6
46164- 2 2 6 6 6 6 91 60 6 167 114 7
46165-206 145 10 230 174 11 242 186 14 246 190 14
46166-246 190 14 246 190 14 246 186 14 242 186 14
46167-239 182 13 230 174 11 224 166 10 213 154 11
46168-180 133 36 124 112 88 86 86 86 58 58 58
46169- 38 38 38 22 22 22 10 10 10 6 6 6
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 14 14 14
46174- 34 34 34 70 70 70 138 110 50 158 118 36
46175-167 114 7 180 123 7 192 133 9 197 138 11
46176-200 144 11 206 145 10 213 154 11 219 162 10
46177-224 166 10 230 174 11 239 182 13 242 186 14
46178-246 186 14 246 186 14 246 186 14 246 186 14
46179-239 182 13 216 158 10 185 133 11 152 99 6
46180-104 69 6 18 14 6 2 2 6 2 2 6
46181- 2 2 6 2 2 6 2 2 6 2 2 6
46182- 2 2 6 2 2 6 2 2 6 2 2 6
46183- 2 2 6 2 2 6 2 2 6 2 2 6
46184- 2 2 6 6 6 6 80 54 7 152 99 6
46185-192 133 9 219 162 10 236 178 12 239 182 13
46186-246 186 14 242 186 14 239 182 13 236 178 12
46187-224 166 10 206 145 10 192 133 9 154 121 60
46188- 94 94 94 62 62 62 42 42 42 22 22 22
46189- 14 14 14 6 6 6 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 6 6 6
46194- 18 18 18 34 34 34 58 58 58 78 78 78
46195-101 98 89 124 112 88 142 110 46 156 107 11
46196-163 110 8 167 114 7 175 118 6 180 123 7
46197-185 133 11 197 138 11 210 150 10 219 162 10
46198-226 170 11 236 178 12 236 178 12 234 174 13
46199-219 162 10 197 138 11 163 110 8 130 83 6
46200- 91 60 6 10 10 10 2 2 6 2 2 6
46201- 18 18 18 38 38 38 38 38 38 38 38 38
46202- 38 38 38 38 38 38 38 38 38 38 38 38
46203- 38 38 38 38 38 38 26 26 26 2 2 6
46204- 2 2 6 6 6 6 70 47 6 137 92 6
46205-175 118 6 200 144 11 219 162 10 230 174 11
46206-234 174 13 230 174 11 219 162 10 210 150 10
46207-192 133 9 163 110 8 124 112 88 82 82 82
46208- 50 50 50 30 30 30 14 14 14 6 6 6
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- 6 6 6 14 14 14 22 22 22 34 34 34
46215- 42 42 42 58 58 58 74 74 74 86 86 86
46216-101 98 89 122 102 70 130 98 46 121 87 25
46217-137 92 6 152 99 6 163 110 8 180 123 7
46218-185 133 11 197 138 11 206 145 10 200 144 11
46219-180 123 7 156 107 11 130 83 6 104 69 6
46220- 50 34 6 54 54 54 110 110 110 101 98 89
46221- 86 86 86 82 82 82 78 78 78 78 78 78
46222- 78 78 78 78 78 78 78 78 78 78 78 78
46223- 78 78 78 82 82 82 86 86 86 94 94 94
46224-106 106 106 101 101 101 86 66 34 124 80 6
46225-156 107 11 180 123 7 192 133 9 200 144 11
46226-206 145 10 200 144 11 192 133 9 175 118 6
46227-139 102 15 109 106 95 70 70 70 42 42 42
46228- 22 22 22 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
46232- 0 0 0 0 0 0 0 0 0 0 0 0
46233- 0 0 0 0 0 0 0 0 0 0 0 0
46234- 0 0 0 0 0 0 6 6 6 10 10 10
46235- 14 14 14 22 22 22 30 30 30 38 38 38
46236- 50 50 50 62 62 62 74 74 74 90 90 90
46237-101 98 89 112 100 78 121 87 25 124 80 6
46238-137 92 6 152 99 6 152 99 6 152 99 6
46239-138 86 6 124 80 6 98 70 6 86 66 30
46240-101 98 89 82 82 82 58 58 58 46 46 46
46241- 38 38 38 34 34 34 34 34 34 34 34 34
46242- 34 34 34 34 34 34 34 34 34 34 34 34
46243- 34 34 34 34 34 34 38 38 38 42 42 42
46244- 54 54 54 82 82 82 94 86 76 91 60 6
46245-134 86 6 156 107 11 167 114 7 175 118 6
46246-175 118 6 167 114 7 152 99 6 121 87 25
46247-101 98 89 62 62 62 34 34 34 18 18 18
46248- 6 6 6 0 0 0 0 0 0 0 0 0
46249- 0 0 0 0 0 0 0 0 0 0 0 0
46250- 0 0 0 0 0 0 0 0 0 0 0 0
46251- 0 0 0 0 0 0 0 0 0 0 0 0
46252- 0 0 0 0 0 0 0 0 0 0 0 0
46253- 0 0 0 0 0 0 0 0 0 0 0 0
46254- 0 0 0 0 0 0 0 0 0 0 0 0
46255- 0 0 0 6 6 6 6 6 6 10 10 10
46256- 18 18 18 22 22 22 30 30 30 42 42 42
46257- 50 50 50 66 66 66 86 86 86 101 98 89
46258-106 86 58 98 70 6 104 69 6 104 69 6
46259-104 69 6 91 60 6 82 62 34 90 90 90
46260- 62 62 62 38 38 38 22 22 22 14 14 14
46261- 10 10 10 10 10 10 10 10 10 10 10 10
46262- 10 10 10 10 10 10 6 6 6 10 10 10
46263- 10 10 10 10 10 10 10 10 10 14 14 14
46264- 22 22 22 42 42 42 70 70 70 89 81 66
46265- 80 54 7 104 69 6 124 80 6 137 92 6
46266-134 86 6 116 81 8 100 82 52 86 86 86
46267- 58 58 58 30 30 30 14 14 14 6 6 6
46268- 0 0 0 0 0 0 0 0 0 0 0 0
46269- 0 0 0 0 0 0 0 0 0 0 0 0
46270- 0 0 0 0 0 0 0 0 0 0 0 0
46271- 0 0 0 0 0 0 0 0 0 0 0 0
46272- 0 0 0 0 0 0 0 0 0 0 0 0
46273- 0 0 0 0 0 0 0 0 0 0 0 0
46274- 0 0 0 0 0 0 0 0 0 0 0 0
46275- 0 0 0 0 0 0 0 0 0 0 0 0
46276- 0 0 0 6 6 6 10 10 10 14 14 14
46277- 18 18 18 26 26 26 38 38 38 54 54 54
46278- 70 70 70 86 86 86 94 86 76 89 81 66
46279- 89 81 66 86 86 86 74 74 74 50 50 50
46280- 30 30 30 14 14 14 6 6 6 0 0 0
46281- 0 0 0 0 0 0 0 0 0 0 0 0
46282- 0 0 0 0 0 0 0 0 0 0 0 0
46283- 0 0 0 0 0 0 0 0 0 0 0 0
46284- 6 6 6 18 18 18 34 34 34 58 58 58
46285- 82 82 82 89 81 66 89 81 66 89 81 66
46286- 94 86 66 94 86 76 74 74 74 50 50 50
46287- 26 26 26 14 14 14 6 6 6 0 0 0
46288- 0 0 0 0 0 0 0 0 0 0 0 0
46289- 0 0 0 0 0 0 0 0 0 0 0 0
46290- 0 0 0 0 0 0 0 0 0 0 0 0
46291- 0 0 0 0 0 0 0 0 0 0 0 0
46292- 0 0 0 0 0 0 0 0 0 0 0 0
46293- 0 0 0 0 0 0 0 0 0 0 0 0
46294- 0 0 0 0 0 0 0 0 0 0 0 0
46295- 0 0 0 0 0 0 0 0 0 0 0 0
46296- 0 0 0 0 0 0 0 0 0 0 0 0
46297- 6 6 6 6 6 6 14 14 14 18 18 18
46298- 30 30 30 38 38 38 46 46 46 54 54 54
46299- 50 50 50 42 42 42 30 30 30 18 18 18
46300- 10 10 10 0 0 0 0 0 0 0 0 0
46301- 0 0 0 0 0 0 0 0 0 0 0 0
46302- 0 0 0 0 0 0 0 0 0 0 0 0
46303- 0 0 0 0 0 0 0 0 0 0 0 0
46304- 0 0 0 6 6 6 14 14 14 26 26 26
46305- 38 38 38 50 50 50 58 58 58 58 58 58
46306- 54 54 54 42 42 42 30 30 30 18 18 18
46307- 10 10 10 0 0 0 0 0 0 0 0 0
46308- 0 0 0 0 0 0 0 0 0 0 0 0
46309- 0 0 0 0 0 0 0 0 0 0 0 0
46310- 0 0 0 0 0 0 0 0 0 0 0 0
46311- 0 0 0 0 0 0 0 0 0 0 0 0
46312- 0 0 0 0 0 0 0 0 0 0 0 0
46313- 0 0 0 0 0 0 0 0 0 0 0 0
46314- 0 0 0 0 0 0 0 0 0 0 0 0
46315- 0 0 0 0 0 0 0 0 0 0 0 0
46316- 0 0 0 0 0 0 0 0 0 0 0 0
46317- 0 0 0 0 0 0 0 0 0 6 6 6
46318- 6 6 6 10 10 10 14 14 14 18 18 18
46319- 18 18 18 14 14 14 10 10 10 6 6 6
46320- 0 0 0 0 0 0 0 0 0 0 0 0
46321- 0 0 0 0 0 0 0 0 0 0 0 0
46322- 0 0 0 0 0 0 0 0 0 0 0 0
46323- 0 0 0 0 0 0 0 0 0 0 0 0
46324- 0 0 0 0 0 0 0 0 0 6 6 6
46325- 14 14 14 18 18 18 22 22 22 22 22 22
46326- 18 18 18 14 14 14 10 10 10 6 6 6
46327- 0 0 0 0 0 0 0 0 0 0 0 0
46328- 0 0 0 0 0 0 0 0 0 0 0 0
46329- 0 0 0 0 0 0 0 0 0 0 0 0
46330- 0 0 0 0 0 0 0 0 0 0 0 0
46331- 0 0 0 0 0 0 0 0 0 0 0 0
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 4 4 4 4 4 4 4 4 4 4 4 4
46334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46335+4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46339+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46340+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46341+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46342+4 4 4 4 4 4 4 4 4 4 4 4 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
46346+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46349+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46353+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46354+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46355+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46356+4 4 4 4 4 4 4 4 4 4 4 4 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
46360+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46363+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
46366+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46367+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46368+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46369+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46370+4 4 4 4 4 4 4 4 4 4 4 4 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
46374+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46377+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46378+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46379+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46380+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46381+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46382+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46383+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46384+4 4 4 4 4 4 4 4 4 4 4 4 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
46388+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46389+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46390+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46391+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46392+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46393+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46394+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46395+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46396+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46397+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46398+4 4 4 4 4 4 4 4 4 4 4 4 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
46402+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46403+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46404+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46405+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46406+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46407+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46408+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46409+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46410+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46411+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46412+4 4 4 4 4 4 4 4 4 4 4 4 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
46416+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46417+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46418+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46419+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46420+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
46421+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
46422+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46423+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46424+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46425+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
46426+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46427+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
46428+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46429+4 4 4 4 4 4
46430+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46431+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46433+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46434+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
46435+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
46436+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46437+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46438+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46439+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
46440+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
46441+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
46442+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46443+4 4 4 4 4 4
46444+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46445+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46447+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46448+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
46449+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
46450+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46451+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46452+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46453+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
46454+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
46455+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
46456+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
46457+4 4 4 4 4 4
46458+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46459+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46460+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46461+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
46462+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
46463+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
46464+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
46465+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46466+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46467+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
46468+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
46469+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
46470+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
46471+4 4 4 4 4 4
46472+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46473+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46474+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46475+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
46476+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
46477+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
46478+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
46479+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46480+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
46481+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
46482+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
46483+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
46484+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
46485+4 4 4 4 4 4
46486+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46487+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46488+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46489+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
46490+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
46491+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
46492+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
46493+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
46494+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
46495+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
46496+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
46497+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
46498+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
46499+4 4 4 4 4 4
46500+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46501+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46502+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
46503+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
46504+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
46505+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
46506+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
46507+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
46508+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
46509+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
46510+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
46511+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
46512+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
46513+4 4 4 4 4 4
46514+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46515+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46516+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
46517+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
46518+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
46519+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
46520+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
46521+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
46522+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
46523+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
46524+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
46525+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
46526+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
46527+4 4 4 4 4 4
46528+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46529+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46530+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
46531+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
46532+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
46533+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
46534+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
46535+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
46536+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
46537+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
46538+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
46539+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
46540+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46541+4 4 4 4 4 4
46542+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46543+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46544+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
46545+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
46546+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
46547+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
46548+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
46549+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
46550+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
46551+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
46552+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
46553+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
46554+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
46555+4 4 4 4 4 4
46556+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46557+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
46558+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
46559+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
46560+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
46561+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
46562+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
46563+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
46564+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
46565+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
46566+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
46567+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
46568+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
46569+4 4 4 4 4 4
46570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46571+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
46572+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
46573+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
46574+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
46575+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
46576+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
46577+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
46578+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
46579+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
46580+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
46581+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
46582+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
46583+0 0 0 4 4 4
46584+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46585+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
46586+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
46587+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
46588+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
46589+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
46590+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
46591+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
46592+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
46593+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
46594+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
46595+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
46596+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
46597+2 0 0 0 0 0
46598+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
46599+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
46600+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
46601+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
46602+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
46603+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
46604+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
46605+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
46606+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
46607+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
46608+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
46609+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
46610+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
46611+37 38 37 0 0 0
46612+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
46613+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
46614+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
46615+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
46616+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
46617+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
46618+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
46619+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
46620+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
46621+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
46622+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
46623+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
46624+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
46625+85 115 134 4 0 0
46626+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
46627+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
46628+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
46629+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
46630+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
46631+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
46632+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
46633+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
46634+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
46635+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
46636+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
46637+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
46638+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
46639+60 73 81 4 0 0
46640+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
46641+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
46642+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
46643+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
46644+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
46645+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
46646+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
46647+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
46648+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
46649+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
46650+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
46651+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
46652+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
46653+16 19 21 4 0 0
46654+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
46655+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
46656+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
46657+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
46658+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
46659+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
46660+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
46661+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
46662+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
46663+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
46664+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
46665+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
46666+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
46667+4 0 0 4 3 3
46668+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
46669+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
46670+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
46671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
46672+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
46673+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
46674+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
46675+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
46676+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
46677+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
46678+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
46679+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
46680+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
46681+3 2 2 4 4 4
46682+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
46683+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
46684+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
46685+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
46686+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
46687+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
46688+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
46689+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
46690+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
46691+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
46692+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
46693+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
46694+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
46695+4 4 4 4 4 4
46696+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
46697+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
46698+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
46699+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
46700+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
46701+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
46702+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
46703+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
46704+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
46705+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
46706+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
46707+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
46708+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
46709+4 4 4 4 4 4
46710+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
46711+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
46712+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
46713+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
46714+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
46715+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
46716+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
46717+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
46718+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
46719+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
46720+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
46721+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
46722+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
46723+5 5 5 5 5 5
46724+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
46725+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
46726+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
46727+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
46728+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
46729+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46730+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
46731+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
46732+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
46733+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
46734+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
46735+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
46736+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
46737+5 5 5 4 4 4
46738+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
46739+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
46740+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
46741+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
46742+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46743+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
46744+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
46745+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
46746+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
46747+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
46748+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
46749+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
46750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46751+4 4 4 4 4 4
46752+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
46753+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
46754+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
46755+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
46756+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
46757+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46758+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46759+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
46760+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
46761+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
46762+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
46763+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
46764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46765+4 4 4 4 4 4
46766+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
46767+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
46768+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
46769+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
46770+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46771+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
46772+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
46773+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
46774+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
46775+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
46776+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
46777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46779+4 4 4 4 4 4
46780+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
46781+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
46782+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
46783+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
46784+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46785+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46786+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46787+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
46788+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
46789+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
46790+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
46791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46793+4 4 4 4 4 4
46794+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
46795+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
46796+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
46797+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
46798+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46799+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
46800+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
46801+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
46802+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
46803+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
46804+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46807+4 4 4 4 4 4
46808+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
46809+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
46810+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
46811+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
46812+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46813+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
46814+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
46815+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
46816+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
46817+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
46818+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
46819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46821+4 4 4 4 4 4
46822+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
46823+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
46824+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
46825+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
46826+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46827+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
46828+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
46829+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
46830+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
46831+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
46832+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
46833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46835+4 4 4 4 4 4
46836+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
46837+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
46838+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
46839+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
46840+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
46841+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
46842+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
46843+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
46844+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
46845+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
46846+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46849+4 4 4 4 4 4
46850+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
46851+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
46852+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
46853+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
46854+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46855+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
46856+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
46857+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
46858+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
46859+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
46860+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46863+4 4 4 4 4 4
46864+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
46865+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
46866+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
46867+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
46868+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46869+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
46870+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
46871+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
46872+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
46873+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
46874+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46877+4 4 4 4 4 4
46878+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
46879+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
46880+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
46881+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
46882+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46883+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
46884+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
46885+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
46886+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
46887+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46888+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46890+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46891+4 4 4 4 4 4
46892+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
46893+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
46894+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
46895+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
46896+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
46897+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
46898+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
46899+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
46900+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46901+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46902+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46903+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46904+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46905+4 4 4 4 4 4
46906+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
46907+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
46908+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
46909+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
46910+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46911+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
46912+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
46913+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
46914+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46915+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46916+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46917+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46918+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46919+4 4 4 4 4 4
46920+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
46921+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
46922+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
46923+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
46924+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
46925+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
46926+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
46927+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
46928+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46929+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46930+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46931+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46932+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46933+4 4 4 4 4 4
46934+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
46935+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
46936+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46937+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
46938+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
46939+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
46940+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
46941+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
46942+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
46943+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46944+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46945+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46946+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46947+4 4 4 4 4 4
46948+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
46949+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
46950+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
46951+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
46952+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
46953+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
46954+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
46955+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
46956+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46957+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46958+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46959+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46960+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46961+4 4 4 4 4 4
46962+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
46963+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
46964+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46965+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
46966+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
46967+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
46968+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
46969+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
46970+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
46971+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46972+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46973+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46974+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46975+4 4 4 4 4 4
46976+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
46977+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
46978+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
46979+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
46980+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
46981+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
46982+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
46983+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
46984+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46985+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46986+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46987+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46988+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46989+4 4 4 4 4 4
46990+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46991+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
46992+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46993+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
46994+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
46995+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
46996+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
46997+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
46998+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46999+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47000+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47001+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47003+4 4 4 4 4 4
47004+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
47005+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
47006+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
47007+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
47008+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
47009+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
47010+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47011+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
47012+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47013+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47014+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47015+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47017+4 4 4 4 4 4
47018+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47019+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
47020+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
47021+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
47022+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
47023+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
47024+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47025+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
47026+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47027+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47028+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47029+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47031+4 4 4 4 4 4
47032+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
47033+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
47034+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
47035+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
47036+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
47037+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
47038+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
47039+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
47040+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
47041+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47042+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47045+4 4 4 4 4 4
47046+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47047+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
47048+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
47049+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
47050+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
47051+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
47052+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
47053+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
47054+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
47055+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47056+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47057+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47059+4 4 4 4 4 4
47060+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
47061+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
47062+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
47063+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
47064+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
47065+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
47066+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
47067+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
47068+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
47069+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47070+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47071+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47073+4 4 4 4 4 4
47074+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47075+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
47076+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
47077+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
47078+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
47079+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
47080+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
47081+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
47082+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
47083+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47084+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47085+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47086+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47087+4 4 4 4 4 4
47088+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
47089+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
47090+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
47091+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
47092+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
47093+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
47094+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
47095+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
47096+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
47097+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
47098+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47099+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47100+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47101+4 4 4 4 4 4
47102+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
47103+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
47104+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
47105+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
47106+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
47107+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
47108+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
47109+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
47110+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
47111+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
47112+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47113+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47114+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47115+4 4 4 4 4 4
47116+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
47117+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
47118+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
47119+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
47120+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
47121+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
47122+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47123+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
47124+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
47125+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
47126+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47127+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47128+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47129+4 4 4 4 4 4
47130+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
47131+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
47132+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
47133+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
47134+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
47135+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
47136+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
47137+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
47138+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
47139+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
47140+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47141+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47142+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47143+4 4 4 4 4 4
47144+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
47145+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
47146+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
47147+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
47148+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
47149+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
47150+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
47151+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
47152+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
47153+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
47154+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47155+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47156+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47157+4 4 4 4 4 4
47158+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47159+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
47160+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
47161+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
47162+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
47163+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
47164+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
47165+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
47166+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
47167+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
47168+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47169+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47170+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47171+4 4 4 4 4 4
47172+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
47173+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
47174+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
47175+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
47176+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
47177+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
47178+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
47179+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
47180+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
47181+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
47182+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47185+4 4 4 4 4 4
47186+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
47187+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
47188+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
47189+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
47190+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
47191+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
47192+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
47193+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
47194+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
47195+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47196+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
47199+4 4 4 4 4 4
47200+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
47201+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47202+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
47203+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
47204+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
47205+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
47206+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
47207+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
47208+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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 4 4 4 4 4 4 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 4 4 4
47214+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
47215+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
47216+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
47217+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
47218+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
47219+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
47220+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
47221+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
47222+4 0 0 4 0 0 4 0 0 6 6 6 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 4 4 4 4 4 4 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
47228+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47229+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
47230+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
47231+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
47232+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
47233+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
47234+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
47235+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
47236+4 0 0 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 4 4 4 4 4 4 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
47242+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
47243+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
47244+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47245+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
47246+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
47247+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
47248+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
47249+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4 4 4 4 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
47256+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47257+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
47258+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
47259+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
47260+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
47261+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
47262+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
47263+6 6 6 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 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
47270+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47271+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
47272+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47273+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
47274+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
47275+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
47276+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
47277+4 0 0 4 3 3 6 6 6 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 4 4 4 4 4 4 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
47284+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47285+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
47286+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
47287+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
47288+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
47289+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
47290+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
47291+6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 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
47298+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47299+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
47300+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
47301+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47302+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
47303+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
47304+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
47305+5 5 5 5 5 5 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 4 4 4 4 4 4 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
47312+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47313+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47314+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47315+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
47316+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
47317+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
47318+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
47319+4 3 3 5 5 5 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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4
47328+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47329+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47330+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
47331+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
47332+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4
47342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47343+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47344+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47345+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
47346+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 4 4 4 4 4 4
47351+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47352+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47353+4 4 4 4 4 4
47354+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47355+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47357+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47358+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47359+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47360+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
47361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47363+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47364+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47365+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47366+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47367+4 4 4 4 4 4
47368+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47369+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47370+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47371+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
47372+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
47373+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
47374+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
47375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47377+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47378+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47379+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47380+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47381+4 4 4 4 4 4
47382+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47383+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47384+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47385+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47386+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
47387+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47388+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47389+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47390+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47391+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47392+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47393+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47394+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47395+4 4 4 4 4 4
47396+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47397+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47398+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47400+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
47401+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
47402+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
47403+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47404+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47405+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47406+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47407+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47408+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47409+4 4 4 4 4 4
47410+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47411+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47412+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47414+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
47415+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
47416+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47417+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47418+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47419+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47420+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47421+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47422+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47423+4 4 4 4 4 4
47424+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47425+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47426+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47427+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47428+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
47429+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
47430+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47431+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47433+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47434+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47435+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47436+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47437+4 4 4 4 4 4
47438+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47439+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47440+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47441+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47442+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47443+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
47444+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47445+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47447+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47448+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47449+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47450+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47451+4 4 4 4 4 4
47452diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
47453index fe92eed..106e085 100644
47454--- a/drivers/video/mb862xx/mb862xxfb_accel.c
47455+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
47456@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
47457 struct mb862xxfb_par *par = info->par;
47458
47459 if (info->var.bits_per_pixel == 32) {
47460- info->fbops->fb_fillrect = cfb_fillrect;
47461- info->fbops->fb_copyarea = cfb_copyarea;
47462- info->fbops->fb_imageblit = cfb_imageblit;
47463+ pax_open_kernel();
47464+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47465+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47466+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47467+ pax_close_kernel();
47468 } else {
47469 outreg(disp, GC_L0EM, 3);
47470- info->fbops->fb_fillrect = mb86290fb_fillrect;
47471- info->fbops->fb_copyarea = mb86290fb_copyarea;
47472- info->fbops->fb_imageblit = mb86290fb_imageblit;
47473+ pax_open_kernel();
47474+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
47475+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
47476+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
47477+ pax_close_kernel();
47478 }
47479 outreg(draw, GDC_REG_DRAW_BASE, 0);
47480 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
47481diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
47482index ff22871..b129bed 100644
47483--- a/drivers/video/nvidia/nvidia.c
47484+++ b/drivers/video/nvidia/nvidia.c
47485@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
47486 info->fix.line_length = (info->var.xres_virtual *
47487 info->var.bits_per_pixel) >> 3;
47488 if (info->var.accel_flags) {
47489- info->fbops->fb_imageblit = nvidiafb_imageblit;
47490- info->fbops->fb_fillrect = nvidiafb_fillrect;
47491- info->fbops->fb_copyarea = nvidiafb_copyarea;
47492- info->fbops->fb_sync = nvidiafb_sync;
47493+ pax_open_kernel();
47494+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
47495+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
47496+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
47497+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
47498+ pax_close_kernel();
47499 info->pixmap.scan_align = 4;
47500 info->flags &= ~FBINFO_HWACCEL_DISABLED;
47501 info->flags |= FBINFO_READS_FAST;
47502 NVResetGraphics(info);
47503 } else {
47504- info->fbops->fb_imageblit = cfb_imageblit;
47505- info->fbops->fb_fillrect = cfb_fillrect;
47506- info->fbops->fb_copyarea = cfb_copyarea;
47507- info->fbops->fb_sync = NULL;
47508+ pax_open_kernel();
47509+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47510+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47511+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47512+ *(void **)&info->fbops->fb_sync = NULL;
47513+ pax_close_kernel();
47514 info->pixmap.scan_align = 1;
47515 info->flags |= FBINFO_HWACCEL_DISABLED;
47516 info->flags &= ~FBINFO_READS_FAST;
47517@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
47518 info->pixmap.size = 8 * 1024;
47519 info->pixmap.flags = FB_PIXMAP_SYSTEM;
47520
47521- if (!hwcur)
47522- info->fbops->fb_cursor = NULL;
47523+ if (!hwcur) {
47524+ pax_open_kernel();
47525+ *(void **)&info->fbops->fb_cursor = NULL;
47526+ pax_close_kernel();
47527+ }
47528
47529 info->var.accel_flags = (!noaccel);
47530
47531diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
47532index 76d9053..dec2bfd 100644
47533--- a/drivers/video/s1d13xxxfb.c
47534+++ b/drivers/video/s1d13xxxfb.c
47535@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
47536
47537 switch(prod_id) {
47538 case S1D13506_PROD_ID: /* activate acceleration */
47539- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
47540- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
47541+ pax_open_kernel();
47542+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
47543+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
47544+ pax_close_kernel();
47545 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
47546 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
47547 break;
47548diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
47549index 97bd662..39fab85 100644
47550--- a/drivers/video/smscufx.c
47551+++ b/drivers/video/smscufx.c
47552@@ -1171,7 +1171,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
47553 fb_deferred_io_cleanup(info);
47554 kfree(info->fbdefio);
47555 info->fbdefio = NULL;
47556- info->fbops->fb_mmap = ufx_ops_mmap;
47557+ pax_open_kernel();
47558+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
47559+ pax_close_kernel();
47560 }
47561
47562 pr_debug("released /dev/fb%d user=%d count=%d",
47563diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
47564index 86d449e..8e04dc5 100644
47565--- a/drivers/video/udlfb.c
47566+++ b/drivers/video/udlfb.c
47567@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
47568 dlfb_urb_completion(urb);
47569
47570 error:
47571- atomic_add(bytes_sent, &dev->bytes_sent);
47572- atomic_add(bytes_identical, &dev->bytes_identical);
47573- atomic_add(width*height*2, &dev->bytes_rendered);
47574+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
47575+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
47576+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
47577 end_cycles = get_cycles();
47578- atomic_add(((unsigned int) ((end_cycles - start_cycles)
47579+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
47580 >> 10)), /* Kcycles */
47581 &dev->cpu_kcycles_used);
47582
47583@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
47584 dlfb_urb_completion(urb);
47585
47586 error:
47587- atomic_add(bytes_sent, &dev->bytes_sent);
47588- atomic_add(bytes_identical, &dev->bytes_identical);
47589- atomic_add(bytes_rendered, &dev->bytes_rendered);
47590+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
47591+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
47592+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
47593 end_cycles = get_cycles();
47594- atomic_add(((unsigned int) ((end_cycles - start_cycles)
47595+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
47596 >> 10)), /* Kcycles */
47597 &dev->cpu_kcycles_used);
47598 }
47599@@ -989,7 +989,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
47600 fb_deferred_io_cleanup(info);
47601 kfree(info->fbdefio);
47602 info->fbdefio = NULL;
47603- info->fbops->fb_mmap = dlfb_ops_mmap;
47604+ pax_open_kernel();
47605+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
47606+ pax_close_kernel();
47607 }
47608
47609 pr_warn("released /dev/fb%d user=%d count=%d\n",
47610@@ -1372,7 +1374,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
47611 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47612 struct dlfb_data *dev = fb_info->par;
47613 return snprintf(buf, PAGE_SIZE, "%u\n",
47614- atomic_read(&dev->bytes_rendered));
47615+ atomic_read_unchecked(&dev->bytes_rendered));
47616 }
47617
47618 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
47619@@ -1380,7 +1382,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
47620 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47621 struct dlfb_data *dev = fb_info->par;
47622 return snprintf(buf, PAGE_SIZE, "%u\n",
47623- atomic_read(&dev->bytes_identical));
47624+ atomic_read_unchecked(&dev->bytes_identical));
47625 }
47626
47627 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
47628@@ -1388,7 +1390,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
47629 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47630 struct dlfb_data *dev = fb_info->par;
47631 return snprintf(buf, PAGE_SIZE, "%u\n",
47632- atomic_read(&dev->bytes_sent));
47633+ atomic_read_unchecked(&dev->bytes_sent));
47634 }
47635
47636 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
47637@@ -1396,7 +1398,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
47638 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47639 struct dlfb_data *dev = fb_info->par;
47640 return snprintf(buf, PAGE_SIZE, "%u\n",
47641- atomic_read(&dev->cpu_kcycles_used));
47642+ atomic_read_unchecked(&dev->cpu_kcycles_used));
47643 }
47644
47645 static ssize_t edid_show(
47646@@ -1456,10 +1458,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
47647 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47648 struct dlfb_data *dev = fb_info->par;
47649
47650- atomic_set(&dev->bytes_rendered, 0);
47651- atomic_set(&dev->bytes_identical, 0);
47652- atomic_set(&dev->bytes_sent, 0);
47653- atomic_set(&dev->cpu_kcycles_used, 0);
47654+ atomic_set_unchecked(&dev->bytes_rendered, 0);
47655+ atomic_set_unchecked(&dev->bytes_identical, 0);
47656+ atomic_set_unchecked(&dev->bytes_sent, 0);
47657+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
47658
47659 return count;
47660 }
47661diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
47662index d428445..79a78df 100644
47663--- a/drivers/video/uvesafb.c
47664+++ b/drivers/video/uvesafb.c
47665@@ -19,6 +19,7 @@
47666 #include <linux/io.h>
47667 #include <linux/mutex.h>
47668 #include <linux/slab.h>
47669+#include <linux/moduleloader.h>
47670 #include <video/edid.h>
47671 #include <video/uvesafb.h>
47672 #ifdef CONFIG_X86
47673@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
47674 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
47675 par->pmi_setpal = par->ypan = 0;
47676 } else {
47677+
47678+#ifdef CONFIG_PAX_KERNEXEC
47679+#ifdef CONFIG_MODULES
47680+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
47681+#endif
47682+ if (!par->pmi_code) {
47683+ par->pmi_setpal = par->ypan = 0;
47684+ return 0;
47685+ }
47686+#endif
47687+
47688 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
47689 + task->t.regs.edi);
47690+
47691+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47692+ pax_open_kernel();
47693+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
47694+ pax_close_kernel();
47695+
47696+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
47697+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
47698+#else
47699 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
47700 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
47701+#endif
47702+
47703 printk(KERN_INFO "uvesafb: protected mode interface info at "
47704 "%04x:%04x\n",
47705 (u16)task->t.regs.es, (u16)task->t.regs.edi);
47706@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
47707 par->ypan = ypan;
47708
47709 if (par->pmi_setpal || par->ypan) {
47710+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
47711 if (__supported_pte_mask & _PAGE_NX) {
47712 par->pmi_setpal = par->ypan = 0;
47713 printk(KERN_WARNING "uvesafb: NX protection is actively."
47714 "We have better not to use the PMI.\n");
47715- } else {
47716+ } else
47717+#endif
47718 uvesafb_vbe_getpmi(task, par);
47719- }
47720 }
47721 #else
47722 /* The protected mode interface is not available on non-x86. */
47723@@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
47724 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
47725
47726 /* Disable blanking if the user requested so. */
47727- if (!blank)
47728- info->fbops->fb_blank = NULL;
47729+ if (!blank) {
47730+ pax_open_kernel();
47731+ *(void **)&info->fbops->fb_blank = NULL;
47732+ pax_close_kernel();
47733+ }
47734
47735 /*
47736 * Find out how much IO memory is required for the mode with
47737@@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
47738 info->flags = FBINFO_FLAG_DEFAULT |
47739 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
47740
47741- if (!par->ypan)
47742- info->fbops->fb_pan_display = NULL;
47743+ if (!par->ypan) {
47744+ pax_open_kernel();
47745+ *(void **)&info->fbops->fb_pan_display = NULL;
47746+ pax_close_kernel();
47747+ }
47748 }
47749
47750 static void uvesafb_init_mtrr(struct fb_info *info)
47751@@ -1836,6 +1866,11 @@ out:
47752 if (par->vbe_modes)
47753 kfree(par->vbe_modes);
47754
47755+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47756+ if (par->pmi_code)
47757+ module_free_exec(NULL, par->pmi_code);
47758+#endif
47759+
47760 framebuffer_release(info);
47761 return err;
47762 }
47763@@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
47764 kfree(par->vbe_state_orig);
47765 if (par->vbe_state_saved)
47766 kfree(par->vbe_state_saved);
47767+
47768+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47769+ if (par->pmi_code)
47770+ module_free_exec(NULL, par->pmi_code);
47771+#endif
47772+
47773 }
47774
47775 framebuffer_release(info);
47776diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
47777index 501b340..d80aa17 100644
47778--- a/drivers/video/vesafb.c
47779+++ b/drivers/video/vesafb.c
47780@@ -9,6 +9,7 @@
47781 */
47782
47783 #include <linux/module.h>
47784+#include <linux/moduleloader.h>
47785 #include <linux/kernel.h>
47786 #include <linux/errno.h>
47787 #include <linux/string.h>
47788@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
47789 static int vram_total __initdata; /* Set total amount of memory */
47790 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
47791 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
47792-static void (*pmi_start)(void) __read_mostly;
47793-static void (*pmi_pal) (void) __read_mostly;
47794+static void (*pmi_start)(void) __read_only;
47795+static void (*pmi_pal) (void) __read_only;
47796 static int depth __read_mostly;
47797 static int vga_compat __read_mostly;
47798 /* --------------------------------------------------------------------- */
47799@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
47800 unsigned int size_vmode;
47801 unsigned int size_remap;
47802 unsigned int size_total;
47803+ void *pmi_code = NULL;
47804
47805 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
47806 return -ENODEV;
47807@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
47808 size_remap = size_total;
47809 vesafb_fix.smem_len = size_remap;
47810
47811-#ifndef __i386__
47812- screen_info.vesapm_seg = 0;
47813-#endif
47814-
47815 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
47816 printk(KERN_WARNING
47817 "vesafb: cannot reserve video memory at 0x%lx\n",
47818@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
47819 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
47820 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
47821
47822+#ifdef __i386__
47823+
47824+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47825+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
47826+ if (!pmi_code)
47827+#elif !defined(CONFIG_PAX_KERNEXEC)
47828+ if (0)
47829+#endif
47830+
47831+#endif
47832+ screen_info.vesapm_seg = 0;
47833+
47834 if (screen_info.vesapm_seg) {
47835- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
47836- screen_info.vesapm_seg,screen_info.vesapm_off);
47837+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
47838+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
47839 }
47840
47841 if (screen_info.vesapm_seg < 0xc000)
47842@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
47843
47844 if (ypan || pmi_setpal) {
47845 unsigned short *pmi_base;
47846+
47847 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
47848- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
47849- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
47850+
47851+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47852+ pax_open_kernel();
47853+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
47854+#else
47855+ pmi_code = pmi_base;
47856+#endif
47857+
47858+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
47859+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
47860+
47861+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47862+ pmi_start = ktva_ktla(pmi_start);
47863+ pmi_pal = ktva_ktla(pmi_pal);
47864+ pax_close_kernel();
47865+#endif
47866+
47867 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
47868 if (pmi_base[3]) {
47869 printk(KERN_INFO "vesafb: pmi: ports = ");
47870@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
47871 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
47872 (ypan ? FBINFO_HWACCEL_YPAN : 0);
47873
47874- if (!ypan)
47875- info->fbops->fb_pan_display = NULL;
47876+ if (!ypan) {
47877+ pax_open_kernel();
47878+ *(void **)&info->fbops->fb_pan_display = NULL;
47879+ pax_close_kernel();
47880+ }
47881
47882 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
47883 err = -ENOMEM;
47884@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
47885 info->node, info->fix.id);
47886 return 0;
47887 err:
47888+
47889+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47890+ module_free_exec(NULL, pmi_code);
47891+#endif
47892+
47893 if (info->screen_base)
47894 iounmap(info->screen_base);
47895 framebuffer_release(info);
47896diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
47897index 88714ae..16c2e11 100644
47898--- a/drivers/video/via/via_clock.h
47899+++ b/drivers/video/via/via_clock.h
47900@@ -56,7 +56,7 @@ struct via_clock {
47901
47902 void (*set_engine_pll_state)(u8 state);
47903 void (*set_engine_pll)(struct via_pll_config config);
47904-};
47905+} __no_const;
47906
47907
47908 static inline u32 get_pll_internal_frequency(u32 ref_freq,
47909diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
47910index fef20db..d28b1ab 100644
47911--- a/drivers/xen/xenfs/xenstored.c
47912+++ b/drivers/xen/xenfs/xenstored.c
47913@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
47914 static int xsd_kva_open(struct inode *inode, struct file *file)
47915 {
47916 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
47917+#ifdef CONFIG_GRKERNSEC_HIDESYM
47918+ NULL);
47919+#else
47920 xen_store_interface);
47921+#endif
47922+
47923 if (!file->private_data)
47924 return -ENOMEM;
47925 return 0;
47926diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
47927index 0ad61c6..f198bd7 100644
47928--- a/fs/9p/vfs_addr.c
47929+++ b/fs/9p/vfs_addr.c
47930@@ -185,7 +185,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
47931
47932 retval = v9fs_file_write_internal(inode,
47933 v9inode->writeback_fid,
47934- (__force const char __user *)buffer,
47935+ (const char __force_user *)buffer,
47936 len, &offset, 0);
47937 if (retval > 0)
47938 retval = 0;
47939diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
47940index d86edc8..40ff2fb 100644
47941--- a/fs/9p/vfs_inode.c
47942+++ b/fs/9p/vfs_inode.c
47943@@ -1314,7 +1314,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
47944 void
47945 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47946 {
47947- char *s = nd_get_link(nd);
47948+ const char *s = nd_get_link(nd);
47949
47950 p9_debug(P9_DEBUG_VFS, " %s %s\n",
47951 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
47952diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
47953index 0efd152..b5802ad 100644
47954--- a/fs/Kconfig.binfmt
47955+++ b/fs/Kconfig.binfmt
47956@@ -89,7 +89,7 @@ config HAVE_AOUT
47957
47958 config BINFMT_AOUT
47959 tristate "Kernel support for a.out and ECOFF binaries"
47960- depends on HAVE_AOUT
47961+ depends on HAVE_AOUT && BROKEN
47962 ---help---
47963 A.out (Assembler.OUTput) is a set of formats for libraries and
47964 executables used in the earliest versions of UNIX. Linux used
47965diff --git a/fs/aio.c b/fs/aio.c
47966index 1dc8786..d3b29e8 100644
47967--- a/fs/aio.c
47968+++ b/fs/aio.c
47969@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
47970 size += sizeof(struct io_event) * nr_events;
47971 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
47972
47973- if (nr_pages < 0)
47974+ if (nr_pages <= 0)
47975 return -EINVAL;
47976
47977 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
47978@@ -1375,18 +1375,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
47979 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
47980 {
47981 ssize_t ret;
47982+ struct iovec iovstack;
47983
47984 #ifdef CONFIG_COMPAT
47985 if (compat)
47986 ret = compat_rw_copy_check_uvector(type,
47987 (struct compat_iovec __user *)kiocb->ki_buf,
47988- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
47989+ kiocb->ki_nbytes, 1, &iovstack,
47990 &kiocb->ki_iovec);
47991 else
47992 #endif
47993 ret = rw_copy_check_uvector(type,
47994 (struct iovec __user *)kiocb->ki_buf,
47995- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
47996+ kiocb->ki_nbytes, 1, &iovstack,
47997 &kiocb->ki_iovec);
47998 if (ret < 0)
47999 goto out;
48000@@ -1395,6 +1396,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
48001 if (ret < 0)
48002 goto out;
48003
48004+ if (kiocb->ki_iovec == &iovstack) {
48005+ kiocb->ki_inline_vec = iovstack;
48006+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
48007+ }
48008 kiocb->ki_nr_segs = kiocb->ki_nbytes;
48009 kiocb->ki_cur_seg = 0;
48010 /* ki_nbytes/left now reflect bytes instead of segs */
48011diff --git a/fs/attr.c b/fs/attr.c
48012index 1449adb..a2038c2 100644
48013--- a/fs/attr.c
48014+++ b/fs/attr.c
48015@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
48016 unsigned long limit;
48017
48018 limit = rlimit(RLIMIT_FSIZE);
48019+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
48020 if (limit != RLIM_INFINITY && offset > limit)
48021 goto out_sig;
48022 if (offset > inode->i_sb->s_maxbytes)
48023diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
48024index 3db70da..7aeec5b 100644
48025--- a/fs/autofs4/waitq.c
48026+++ b/fs/autofs4/waitq.c
48027@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
48028 {
48029 unsigned long sigpipe, flags;
48030 mm_segment_t fs;
48031- const char *data = (const char *)addr;
48032+ const char __user *data = (const char __force_user *)addr;
48033 ssize_t wr = 0;
48034
48035 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
48036@@ -346,6 +346,10 @@ static int validate_request(struct autofs_wait_queue **wait,
48037 return 1;
48038 }
48039
48040+#ifdef CONFIG_GRKERNSEC_HIDESYM
48041+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
48042+#endif
48043+
48044 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
48045 enum autofs_notify notify)
48046 {
48047@@ -379,7 +383,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
48048
48049 /* If this is a direct mount request create a dummy name */
48050 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
48051+#ifdef CONFIG_GRKERNSEC_HIDESYM
48052+ /* this name does get written to userland via autofs4_write() */
48053+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
48054+#else
48055 qstr.len = sprintf(name, "%p", dentry);
48056+#endif
48057 else {
48058 qstr.len = autofs4_getpath(sbi, dentry, &name);
48059 if (!qstr.len) {
48060diff --git a/fs/befs/endian.h b/fs/befs/endian.h
48061index 2722387..c8dd2a7 100644
48062--- a/fs/befs/endian.h
48063+++ b/fs/befs/endian.h
48064@@ -11,7 +11,7 @@
48065
48066 #include <asm/byteorder.h>
48067
48068-static inline u64
48069+static inline u64 __intentional_overflow(-1)
48070 fs64_to_cpu(const struct super_block *sb, fs64 n)
48071 {
48072 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
48073@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
48074 return (__force fs64)cpu_to_be64(n);
48075 }
48076
48077-static inline u32
48078+static inline u32 __intentional_overflow(-1)
48079 fs32_to_cpu(const struct super_block *sb, fs32 n)
48080 {
48081 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
48082diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
48083index 8615ee8..388ed68 100644
48084--- a/fs/befs/linuxvfs.c
48085+++ b/fs/befs/linuxvfs.c
48086@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48087 {
48088 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
48089 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
48090- char *link = nd_get_link(nd);
48091+ const char *link = nd_get_link(nd);
48092 if (!IS_ERR(link))
48093 kfree(link);
48094 }
48095diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
48096index bbc8f88..7c7ac97 100644
48097--- a/fs/binfmt_aout.c
48098+++ b/fs/binfmt_aout.c
48099@@ -16,6 +16,7 @@
48100 #include <linux/string.h>
48101 #include <linux/fs.h>
48102 #include <linux/file.h>
48103+#include <linux/security.h>
48104 #include <linux/stat.h>
48105 #include <linux/fcntl.h>
48106 #include <linux/ptrace.h>
48107@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
48108 #endif
48109 # define START_STACK(u) ((void __user *)u.start_stack)
48110
48111+ memset(&dump, 0, sizeof(dump));
48112+
48113 fs = get_fs();
48114 set_fs(KERNEL_DS);
48115 has_dumped = 1;
48116@@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
48117
48118 /* If the size of the dump file exceeds the rlimit, then see what would happen
48119 if we wrote the stack, but not the data area. */
48120+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
48121 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
48122 dump.u_dsize = 0;
48123
48124 /* Make sure we have enough room to write the stack and data areas. */
48125+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
48126 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
48127 dump.u_ssize = 0;
48128
48129@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
48130 rlim = rlimit(RLIMIT_DATA);
48131 if (rlim >= RLIM_INFINITY)
48132 rlim = ~0;
48133+
48134+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
48135 if (ex.a_data + ex.a_bss > rlim)
48136 return -ENOMEM;
48137
48138@@ -268,6 +275,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
48139
48140 install_exec_creds(bprm);
48141
48142+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48143+ current->mm->pax_flags = 0UL;
48144+#endif
48145+
48146+#ifdef CONFIG_PAX_PAGEEXEC
48147+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
48148+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
48149+
48150+#ifdef CONFIG_PAX_EMUTRAMP
48151+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
48152+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
48153+#endif
48154+
48155+#ifdef CONFIG_PAX_MPROTECT
48156+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
48157+ current->mm->pax_flags |= MF_PAX_MPROTECT;
48158+#endif
48159+
48160+ }
48161+#endif
48162+
48163 if (N_MAGIC(ex) == OMAGIC) {
48164 unsigned long text_addr, map_size;
48165 loff_t pos;
48166@@ -333,7 +361,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
48167 }
48168
48169 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
48170- PROT_READ | PROT_WRITE | PROT_EXEC,
48171+ PROT_READ | PROT_WRITE,
48172 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
48173 fd_offset + ex.a_text);
48174 if (error != N_DATADDR(ex)) {
48175diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
48176index 86af964..5d53bf6 100644
48177--- a/fs/binfmt_elf.c
48178+++ b/fs/binfmt_elf.c
48179@@ -34,6 +34,7 @@
48180 #include <linux/utsname.h>
48181 #include <linux/coredump.h>
48182 #include <linux/sched.h>
48183+#include <linux/xattr.h>
48184 #include <asm/uaccess.h>
48185 #include <asm/param.h>
48186 #include <asm/page.h>
48187@@ -60,6 +61,10 @@ static int elf_core_dump(struct coredump_params *cprm);
48188 #define elf_core_dump NULL
48189 #endif
48190
48191+#ifdef CONFIG_PAX_MPROTECT
48192+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
48193+#endif
48194+
48195 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
48196 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
48197 #else
48198@@ -79,6 +84,11 @@ static struct linux_binfmt elf_format = {
48199 .load_binary = load_elf_binary,
48200 .load_shlib = load_elf_library,
48201 .core_dump = elf_core_dump,
48202+
48203+#ifdef CONFIG_PAX_MPROTECT
48204+ .handle_mprotect= elf_handle_mprotect,
48205+#endif
48206+
48207 .min_coredump = ELF_EXEC_PAGESIZE,
48208 };
48209
48210@@ -86,6 +96,8 @@ static struct linux_binfmt elf_format = {
48211
48212 static int set_brk(unsigned long start, unsigned long end)
48213 {
48214+ unsigned long e = end;
48215+
48216 start = ELF_PAGEALIGN(start);
48217 end = ELF_PAGEALIGN(end);
48218 if (end > start) {
48219@@ -94,7 +106,7 @@ static int set_brk(unsigned long start, unsigned long end)
48220 if (BAD_ADDR(addr))
48221 return addr;
48222 }
48223- current->mm->start_brk = current->mm->brk = end;
48224+ current->mm->start_brk = current->mm->brk = e;
48225 return 0;
48226 }
48227
48228@@ -155,12 +167,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48229 elf_addr_t __user *u_rand_bytes;
48230 const char *k_platform = ELF_PLATFORM;
48231 const char *k_base_platform = ELF_BASE_PLATFORM;
48232- unsigned char k_rand_bytes[16];
48233+ u32 k_rand_bytes[4];
48234 int items;
48235 elf_addr_t *elf_info;
48236 int ei_index = 0;
48237 const struct cred *cred = current_cred();
48238 struct vm_area_struct *vma;
48239+ unsigned long saved_auxv[AT_VECTOR_SIZE];
48240
48241 /*
48242 * In some cases (e.g. Hyper-Threading), we want to avoid L1
48243@@ -202,8 +215,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48244 * Generate 16 random bytes for userspace PRNG seeding.
48245 */
48246 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
48247- u_rand_bytes = (elf_addr_t __user *)
48248- STACK_ALLOC(p, sizeof(k_rand_bytes));
48249+ srandom32(k_rand_bytes[0] ^ random32());
48250+ srandom32(k_rand_bytes[1] ^ random32());
48251+ srandom32(k_rand_bytes[2] ^ random32());
48252+ srandom32(k_rand_bytes[3] ^ random32());
48253+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
48254+ u_rand_bytes = (elf_addr_t __user *) p;
48255 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
48256 return -EFAULT;
48257
48258@@ -315,9 +332,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48259 return -EFAULT;
48260 current->mm->env_end = p;
48261
48262+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
48263+
48264 /* Put the elf_info on the stack in the right place. */
48265 sp = (elf_addr_t __user *)envp + 1;
48266- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
48267+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
48268 return -EFAULT;
48269 return 0;
48270 }
48271@@ -385,15 +404,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
48272 an ELF header */
48273
48274 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48275- struct file *interpreter, unsigned long *interp_map_addr,
48276- unsigned long no_base)
48277+ struct file *interpreter, unsigned long no_base)
48278 {
48279 struct elf_phdr *elf_phdata;
48280 struct elf_phdr *eppnt;
48281- unsigned long load_addr = 0;
48282+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
48283 int load_addr_set = 0;
48284 unsigned long last_bss = 0, elf_bss = 0;
48285- unsigned long error = ~0UL;
48286+ unsigned long error = -EINVAL;
48287 unsigned long total_size;
48288 int retval, i, size;
48289
48290@@ -439,6 +457,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48291 goto out_close;
48292 }
48293
48294+#ifdef CONFIG_PAX_SEGMEXEC
48295+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
48296+ pax_task_size = SEGMEXEC_TASK_SIZE;
48297+#endif
48298+
48299 eppnt = elf_phdata;
48300 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
48301 if (eppnt->p_type == PT_LOAD) {
48302@@ -462,8 +485,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48303 map_addr = elf_map(interpreter, load_addr + vaddr,
48304 eppnt, elf_prot, elf_type, total_size);
48305 total_size = 0;
48306- if (!*interp_map_addr)
48307- *interp_map_addr = map_addr;
48308 error = map_addr;
48309 if (BAD_ADDR(map_addr))
48310 goto out_close;
48311@@ -482,8 +503,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48312 k = load_addr + eppnt->p_vaddr;
48313 if (BAD_ADDR(k) ||
48314 eppnt->p_filesz > eppnt->p_memsz ||
48315- eppnt->p_memsz > TASK_SIZE ||
48316- TASK_SIZE - eppnt->p_memsz < k) {
48317+ eppnt->p_memsz > pax_task_size ||
48318+ pax_task_size - eppnt->p_memsz < k) {
48319 error = -ENOMEM;
48320 goto out_close;
48321 }
48322@@ -535,6 +556,315 @@ out:
48323 return error;
48324 }
48325
48326+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48327+#ifdef CONFIG_PAX_SOFTMODE
48328+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
48329+{
48330+ unsigned long pax_flags = 0UL;
48331+
48332+#ifdef CONFIG_PAX_PAGEEXEC
48333+ if (elf_phdata->p_flags & PF_PAGEEXEC)
48334+ pax_flags |= MF_PAX_PAGEEXEC;
48335+#endif
48336+
48337+#ifdef CONFIG_PAX_SEGMEXEC
48338+ if (elf_phdata->p_flags & PF_SEGMEXEC)
48339+ pax_flags |= MF_PAX_SEGMEXEC;
48340+#endif
48341+
48342+#ifdef CONFIG_PAX_EMUTRAMP
48343+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
48344+ pax_flags |= MF_PAX_EMUTRAMP;
48345+#endif
48346+
48347+#ifdef CONFIG_PAX_MPROTECT
48348+ if (elf_phdata->p_flags & PF_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 && (elf_phdata->p_flags & PF_RANDMMAP))
48354+ pax_flags |= MF_PAX_RANDMMAP;
48355+#endif
48356+
48357+ return pax_flags;
48358+}
48359+#endif
48360+
48361+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
48362+{
48363+ unsigned long pax_flags = 0UL;
48364+
48365+#ifdef CONFIG_PAX_PAGEEXEC
48366+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
48367+ pax_flags |= MF_PAX_PAGEEXEC;
48368+#endif
48369+
48370+#ifdef CONFIG_PAX_SEGMEXEC
48371+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
48372+ pax_flags |= MF_PAX_SEGMEXEC;
48373+#endif
48374+
48375+#ifdef CONFIG_PAX_EMUTRAMP
48376+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
48377+ pax_flags |= MF_PAX_EMUTRAMP;
48378+#endif
48379+
48380+#ifdef CONFIG_PAX_MPROTECT
48381+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
48382+ pax_flags |= MF_PAX_MPROTECT;
48383+#endif
48384+
48385+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48386+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
48387+ pax_flags |= MF_PAX_RANDMMAP;
48388+#endif
48389+
48390+ return pax_flags;
48391+}
48392+#endif
48393+
48394+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48395+#ifdef CONFIG_PAX_SOFTMODE
48396+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
48397+{
48398+ unsigned long pax_flags = 0UL;
48399+
48400+#ifdef CONFIG_PAX_PAGEEXEC
48401+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
48402+ pax_flags |= MF_PAX_PAGEEXEC;
48403+#endif
48404+
48405+#ifdef CONFIG_PAX_SEGMEXEC
48406+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
48407+ pax_flags |= MF_PAX_SEGMEXEC;
48408+#endif
48409+
48410+#ifdef CONFIG_PAX_EMUTRAMP
48411+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
48412+ pax_flags |= MF_PAX_EMUTRAMP;
48413+#endif
48414+
48415+#ifdef CONFIG_PAX_MPROTECT
48416+ if (pax_flags_softmode & MF_PAX_MPROTECT)
48417+ pax_flags |= MF_PAX_MPROTECT;
48418+#endif
48419+
48420+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48421+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
48422+ pax_flags |= MF_PAX_RANDMMAP;
48423+#endif
48424+
48425+ return pax_flags;
48426+}
48427+#endif
48428+
48429+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
48430+{
48431+ unsigned long pax_flags = 0UL;
48432+
48433+#ifdef CONFIG_PAX_PAGEEXEC
48434+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
48435+ pax_flags |= MF_PAX_PAGEEXEC;
48436+#endif
48437+
48438+#ifdef CONFIG_PAX_SEGMEXEC
48439+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
48440+ pax_flags |= MF_PAX_SEGMEXEC;
48441+#endif
48442+
48443+#ifdef CONFIG_PAX_EMUTRAMP
48444+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
48445+ pax_flags |= MF_PAX_EMUTRAMP;
48446+#endif
48447+
48448+#ifdef CONFIG_PAX_MPROTECT
48449+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
48450+ pax_flags |= MF_PAX_MPROTECT;
48451+#endif
48452+
48453+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48454+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
48455+ pax_flags |= MF_PAX_RANDMMAP;
48456+#endif
48457+
48458+ return pax_flags;
48459+}
48460+#endif
48461+
48462+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48463+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
48464+{
48465+ unsigned long pax_flags = 0UL;
48466+
48467+#ifdef CONFIG_PAX_EI_PAX
48468+
48469+#ifdef CONFIG_PAX_PAGEEXEC
48470+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
48471+ pax_flags |= MF_PAX_PAGEEXEC;
48472+#endif
48473+
48474+#ifdef CONFIG_PAX_SEGMEXEC
48475+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
48476+ pax_flags |= MF_PAX_SEGMEXEC;
48477+#endif
48478+
48479+#ifdef CONFIG_PAX_EMUTRAMP
48480+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
48481+ pax_flags |= MF_PAX_EMUTRAMP;
48482+#endif
48483+
48484+#ifdef CONFIG_PAX_MPROTECT
48485+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
48486+ pax_flags |= MF_PAX_MPROTECT;
48487+#endif
48488+
48489+#ifdef CONFIG_PAX_ASLR
48490+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
48491+ pax_flags |= MF_PAX_RANDMMAP;
48492+#endif
48493+
48494+#else
48495+
48496+#ifdef CONFIG_PAX_PAGEEXEC
48497+ pax_flags |= MF_PAX_PAGEEXEC;
48498+#endif
48499+
48500+#ifdef CONFIG_PAX_SEGMEXEC
48501+ pax_flags |= MF_PAX_SEGMEXEC;
48502+#endif
48503+
48504+#ifdef CONFIG_PAX_MPROTECT
48505+ pax_flags |= MF_PAX_MPROTECT;
48506+#endif
48507+
48508+#ifdef CONFIG_PAX_RANDMMAP
48509+ if (randomize_va_space)
48510+ pax_flags |= MF_PAX_RANDMMAP;
48511+#endif
48512+
48513+#endif
48514+
48515+ return pax_flags;
48516+}
48517+
48518+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
48519+{
48520+
48521+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48522+ unsigned long i;
48523+
48524+ for (i = 0UL; i < elf_ex->e_phnum; i++)
48525+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
48526+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
48527+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
48528+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
48529+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
48530+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
48531+ return ~0UL;
48532+
48533+#ifdef CONFIG_PAX_SOFTMODE
48534+ if (pax_softmode)
48535+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
48536+ else
48537+#endif
48538+
48539+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
48540+ break;
48541+ }
48542+#endif
48543+
48544+ return ~0UL;
48545+}
48546+
48547+static unsigned long pax_parse_xattr_pax(struct file * const file)
48548+{
48549+
48550+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48551+ ssize_t xattr_size, i;
48552+ unsigned char xattr_value[sizeof("pemrs") - 1];
48553+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
48554+
48555+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
48556+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
48557+ return ~0UL;
48558+
48559+ for (i = 0; i < xattr_size; i++)
48560+ switch (xattr_value[i]) {
48561+ default:
48562+ return ~0UL;
48563+
48564+#define parse_flag(option1, option2, flag) \
48565+ case option1: \
48566+ if (pax_flags_hardmode & MF_PAX_##flag) \
48567+ return ~0UL; \
48568+ pax_flags_hardmode |= MF_PAX_##flag; \
48569+ break; \
48570+ case option2: \
48571+ if (pax_flags_softmode & MF_PAX_##flag) \
48572+ return ~0UL; \
48573+ pax_flags_softmode |= MF_PAX_##flag; \
48574+ break;
48575+
48576+ parse_flag('p', 'P', PAGEEXEC);
48577+ parse_flag('e', 'E', EMUTRAMP);
48578+ parse_flag('m', 'M', MPROTECT);
48579+ parse_flag('r', 'R', RANDMMAP);
48580+ parse_flag('s', 'S', SEGMEXEC);
48581+
48582+#undef parse_flag
48583+ }
48584+
48585+ if (pax_flags_hardmode & pax_flags_softmode)
48586+ return ~0UL;
48587+
48588+#ifdef CONFIG_PAX_SOFTMODE
48589+ if (pax_softmode)
48590+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
48591+ else
48592+#endif
48593+
48594+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
48595+#else
48596+ return ~0UL;
48597+#endif
48598+
48599+}
48600+
48601+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
48602+{
48603+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
48604+
48605+ pax_flags = pax_parse_ei_pax(elf_ex);
48606+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
48607+ xattr_pax_flags = pax_parse_xattr_pax(file);
48608+
48609+ if (pt_pax_flags == ~0UL)
48610+ pt_pax_flags = xattr_pax_flags;
48611+ else if (xattr_pax_flags == ~0UL)
48612+ xattr_pax_flags = pt_pax_flags;
48613+ if (pt_pax_flags != xattr_pax_flags)
48614+ return -EINVAL;
48615+ if (pt_pax_flags != ~0UL)
48616+ pax_flags = pt_pax_flags;
48617+
48618+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
48619+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48620+ if ((__supported_pte_mask & _PAGE_NX))
48621+ pax_flags &= ~MF_PAX_SEGMEXEC;
48622+ else
48623+ pax_flags &= ~MF_PAX_PAGEEXEC;
48624+ }
48625+#endif
48626+
48627+ if (0 > pax_check_flags(&pax_flags))
48628+ return -EINVAL;
48629+
48630+ current->mm->pax_flags = pax_flags;
48631+ return 0;
48632+}
48633+#endif
48634+
48635 /*
48636 * These are the functions used to load ELF style executables and shared
48637 * libraries. There is no binary dependent code anywhere else.
48638@@ -551,6 +881,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
48639 {
48640 unsigned int random_variable = 0;
48641
48642+#ifdef CONFIG_PAX_RANDUSTACK
48643+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
48644+ return stack_top - current->mm->delta_stack;
48645+#endif
48646+
48647 if ((current->flags & PF_RANDOMIZE) &&
48648 !(current->personality & ADDR_NO_RANDOMIZE)) {
48649 random_variable = get_random_int() & STACK_RND_MASK;
48650@@ -569,7 +904,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
48651 unsigned long load_addr = 0, load_bias = 0;
48652 int load_addr_set = 0;
48653 char * elf_interpreter = NULL;
48654- unsigned long error;
48655+ unsigned long error = 0;
48656 struct elf_phdr *elf_ppnt, *elf_phdata;
48657 unsigned long elf_bss, elf_brk;
48658 int retval, i;
48659@@ -579,12 +914,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
48660 unsigned long start_code, end_code, start_data, end_data;
48661 unsigned long reloc_func_desc __maybe_unused = 0;
48662 int executable_stack = EXSTACK_DEFAULT;
48663- unsigned long def_flags = 0;
48664 struct pt_regs *regs = current_pt_regs();
48665 struct {
48666 struct elfhdr elf_ex;
48667 struct elfhdr interp_elf_ex;
48668 } *loc;
48669+ unsigned long pax_task_size = TASK_SIZE;
48670
48671 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
48672 if (!loc) {
48673@@ -720,11 +1055,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
48674 goto out_free_dentry;
48675
48676 /* OK, This is the point of no return */
48677- current->mm->def_flags = def_flags;
48678+
48679+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48680+ current->mm->pax_flags = 0UL;
48681+#endif
48682+
48683+#ifdef CONFIG_PAX_DLRESOLVE
48684+ current->mm->call_dl_resolve = 0UL;
48685+#endif
48686+
48687+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
48688+ current->mm->call_syscall = 0UL;
48689+#endif
48690+
48691+#ifdef CONFIG_PAX_ASLR
48692+ current->mm->delta_mmap = 0UL;
48693+ current->mm->delta_stack = 0UL;
48694+#endif
48695+
48696+ current->mm->def_flags = 0;
48697+
48698+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48699+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
48700+ send_sig(SIGKILL, current, 0);
48701+ goto out_free_dentry;
48702+ }
48703+#endif
48704+
48705+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
48706+ pax_set_initial_flags(bprm);
48707+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
48708+ if (pax_set_initial_flags_func)
48709+ (pax_set_initial_flags_func)(bprm);
48710+#endif
48711+
48712+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48713+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
48714+ current->mm->context.user_cs_limit = PAGE_SIZE;
48715+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
48716+ }
48717+#endif
48718+
48719+#ifdef CONFIG_PAX_SEGMEXEC
48720+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
48721+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
48722+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
48723+ pax_task_size = SEGMEXEC_TASK_SIZE;
48724+ current->mm->def_flags |= VM_NOHUGEPAGE;
48725+ }
48726+#endif
48727+
48728+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
48729+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48730+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
48731+ put_cpu();
48732+ }
48733+#endif
48734
48735 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
48736 may depend on the personality. */
48737 SET_PERSONALITY(loc->elf_ex);
48738+
48739+#ifdef CONFIG_PAX_ASLR
48740+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
48741+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
48742+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
48743+ }
48744+#endif
48745+
48746+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
48747+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48748+ executable_stack = EXSTACK_DISABLE_X;
48749+ current->personality &= ~READ_IMPLIES_EXEC;
48750+ } else
48751+#endif
48752+
48753 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
48754 current->personality |= READ_IMPLIES_EXEC;
48755
48756@@ -815,6 +1220,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
48757 #else
48758 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
48759 #endif
48760+
48761+#ifdef CONFIG_PAX_RANDMMAP
48762+ /* PaX: randomize base address at the default exe base if requested */
48763+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
48764+#ifdef CONFIG_SPARC64
48765+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
48766+#else
48767+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
48768+#endif
48769+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
48770+ elf_flags |= MAP_FIXED;
48771+ }
48772+#endif
48773+
48774 }
48775
48776 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
48777@@ -847,9 +1266,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
48778 * allowed task size. Note that p_filesz must always be
48779 * <= p_memsz so it is only necessary to check p_memsz.
48780 */
48781- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
48782- elf_ppnt->p_memsz > TASK_SIZE ||
48783- TASK_SIZE - elf_ppnt->p_memsz < k) {
48784+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
48785+ elf_ppnt->p_memsz > pax_task_size ||
48786+ pax_task_size - elf_ppnt->p_memsz < k) {
48787 /* set_brk can never work. Avoid overflows. */
48788 send_sig(SIGKILL, current, 0);
48789 retval = -EINVAL;
48790@@ -888,17 +1307,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
48791 goto out_free_dentry;
48792 }
48793 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
48794- send_sig(SIGSEGV, current, 0);
48795- retval = -EFAULT; /* Nobody gets to see this, but.. */
48796- goto out_free_dentry;
48797+ /*
48798+ * This bss-zeroing can fail if the ELF
48799+ * file specifies odd protections. So
48800+ * we don't check the return value
48801+ */
48802 }
48803
48804+#ifdef CONFIG_PAX_RANDMMAP
48805+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
48806+ unsigned long start, size, flags;
48807+ vm_flags_t vm_flags;
48808+
48809+ start = ELF_PAGEALIGN(elf_brk);
48810+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
48811+ flags = MAP_FIXED | MAP_PRIVATE;
48812+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
48813+
48814+ down_write(&current->mm->mmap_sem);
48815+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
48816+ retval = -ENOMEM;
48817+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
48818+// if (current->personality & ADDR_NO_RANDOMIZE)
48819+// vm_flags |= VM_READ | VM_MAYREAD;
48820+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
48821+ retval = IS_ERR_VALUE(start) ? start : 0;
48822+ }
48823+ up_write(&current->mm->mmap_sem);
48824+ if (retval == 0)
48825+ retval = set_brk(start + size, start + size + PAGE_SIZE);
48826+ if (retval < 0) {
48827+ send_sig(SIGKILL, current, 0);
48828+ goto out_free_dentry;
48829+ }
48830+ }
48831+#endif
48832+
48833 if (elf_interpreter) {
48834- unsigned long interp_map_addr = 0;
48835-
48836 elf_entry = load_elf_interp(&loc->interp_elf_ex,
48837 interpreter,
48838- &interp_map_addr,
48839 load_bias);
48840 if (!IS_ERR((void *)elf_entry)) {
48841 /*
48842@@ -1120,7 +1567,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
48843 * Decide what to dump of a segment, part, all or none.
48844 */
48845 static unsigned long vma_dump_size(struct vm_area_struct *vma,
48846- unsigned long mm_flags)
48847+ unsigned long mm_flags, long signr)
48848 {
48849 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
48850
48851@@ -1158,7 +1605,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
48852 if (vma->vm_file == NULL)
48853 return 0;
48854
48855- if (FILTER(MAPPED_PRIVATE))
48856+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
48857 goto whole;
48858
48859 /*
48860@@ -1383,9 +1830,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
48861 {
48862 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
48863 int i = 0;
48864- do
48865+ do {
48866 i += 2;
48867- while (auxv[i - 2] != AT_NULL);
48868+ } while (auxv[i - 2] != AT_NULL);
48869 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
48870 }
48871
48872@@ -1394,7 +1841,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
48873 {
48874 mm_segment_t old_fs = get_fs();
48875 set_fs(KERNEL_DS);
48876- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
48877+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
48878 set_fs(old_fs);
48879 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
48880 }
48881@@ -2015,14 +2462,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
48882 }
48883
48884 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
48885- unsigned long mm_flags)
48886+ struct coredump_params *cprm)
48887 {
48888 struct vm_area_struct *vma;
48889 size_t size = 0;
48890
48891 for (vma = first_vma(current, gate_vma); vma != NULL;
48892 vma = next_vma(vma, gate_vma))
48893- size += vma_dump_size(vma, mm_flags);
48894+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48895 return size;
48896 }
48897
48898@@ -2116,7 +2563,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48899
48900 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
48901
48902- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
48903+ offset += elf_core_vma_data_size(gate_vma, cprm);
48904 offset += elf_core_extra_data_size();
48905 e_shoff = offset;
48906
48907@@ -2130,10 +2577,12 @@ static int elf_core_dump(struct coredump_params *cprm)
48908 offset = dataoff;
48909
48910 size += sizeof(*elf);
48911+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48912 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
48913 goto end_coredump;
48914
48915 size += sizeof(*phdr4note);
48916+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48917 if (size > cprm->limit
48918 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
48919 goto end_coredump;
48920@@ -2147,7 +2596,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48921 phdr.p_offset = offset;
48922 phdr.p_vaddr = vma->vm_start;
48923 phdr.p_paddr = 0;
48924- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
48925+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48926 phdr.p_memsz = vma->vm_end - vma->vm_start;
48927 offset += phdr.p_filesz;
48928 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
48929@@ -2158,6 +2607,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48930 phdr.p_align = ELF_EXEC_PAGESIZE;
48931
48932 size += sizeof(phdr);
48933+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48934 if (size > cprm->limit
48935 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
48936 goto end_coredump;
48937@@ -2182,7 +2632,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48938 unsigned long addr;
48939 unsigned long end;
48940
48941- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
48942+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48943
48944 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
48945 struct page *page;
48946@@ -2191,6 +2641,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48947 page = get_dump_page(addr);
48948 if (page) {
48949 void *kaddr = kmap(page);
48950+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
48951 stop = ((size += PAGE_SIZE) > cprm->limit) ||
48952 !dump_write(cprm->file, kaddr,
48953 PAGE_SIZE);
48954@@ -2208,6 +2659,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48955
48956 if (e_phnum == PN_XNUM) {
48957 size += sizeof(*shdr4extnum);
48958+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48959 if (size > cprm->limit
48960 || !dump_write(cprm->file, shdr4extnum,
48961 sizeof(*shdr4extnum)))
48962@@ -2228,6 +2680,97 @@ out:
48963
48964 #endif /* CONFIG_ELF_CORE */
48965
48966+#ifdef CONFIG_PAX_MPROTECT
48967+/* PaX: non-PIC ELF libraries need relocations on their executable segments
48968+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
48969+ * we'll remove VM_MAYWRITE for good on RELRO segments.
48970+ *
48971+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
48972+ * basis because we want to allow the common case and not the special ones.
48973+ */
48974+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
48975+{
48976+ struct elfhdr elf_h;
48977+ struct elf_phdr elf_p;
48978+ unsigned long i;
48979+ unsigned long oldflags;
48980+ bool is_textrel_rw, is_textrel_rx, is_relro;
48981+
48982+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
48983+ return;
48984+
48985+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
48986+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
48987+
48988+#ifdef CONFIG_PAX_ELFRELOCS
48989+ /* possible TEXTREL */
48990+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
48991+ 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);
48992+#else
48993+ is_textrel_rw = false;
48994+ is_textrel_rx = false;
48995+#endif
48996+
48997+ /* possible RELRO */
48998+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
48999+
49000+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
49001+ return;
49002+
49003+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
49004+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
49005+
49006+#ifdef CONFIG_PAX_ETEXECRELOCS
49007+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
49008+#else
49009+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
49010+#endif
49011+
49012+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
49013+ !elf_check_arch(&elf_h) ||
49014+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
49015+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
49016+ return;
49017+
49018+ for (i = 0UL; i < elf_h.e_phnum; i++) {
49019+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
49020+ return;
49021+ switch (elf_p.p_type) {
49022+ case PT_DYNAMIC:
49023+ if (!is_textrel_rw && !is_textrel_rx)
49024+ continue;
49025+ i = 0UL;
49026+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
49027+ elf_dyn dyn;
49028+
49029+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
49030+ return;
49031+ if (dyn.d_tag == DT_NULL)
49032+ return;
49033+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
49034+ gr_log_textrel(vma);
49035+ if (is_textrel_rw)
49036+ vma->vm_flags |= VM_MAYWRITE;
49037+ else
49038+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
49039+ vma->vm_flags &= ~VM_MAYWRITE;
49040+ return;
49041+ }
49042+ i++;
49043+ }
49044+ return;
49045+
49046+ case PT_GNU_RELRO:
49047+ if (!is_relro)
49048+ continue;
49049+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
49050+ vma->vm_flags &= ~VM_MAYWRITE;
49051+ return;
49052+ }
49053+ }
49054+}
49055+#endif
49056+
49057 static int __init init_elf_binfmt(void)
49058 {
49059 register_binfmt(&elf_format);
49060diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
49061index 2036d21..b0430d0 100644
49062--- a/fs/binfmt_flat.c
49063+++ b/fs/binfmt_flat.c
49064@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
49065 realdatastart = (unsigned long) -ENOMEM;
49066 printk("Unable to allocate RAM for process data, errno %d\n",
49067 (int)-realdatastart);
49068+ down_write(&current->mm->mmap_sem);
49069 vm_munmap(textpos, text_len);
49070+ up_write(&current->mm->mmap_sem);
49071 ret = realdatastart;
49072 goto err;
49073 }
49074@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
49075 }
49076 if (IS_ERR_VALUE(result)) {
49077 printk("Unable to read data+bss, errno %d\n", (int)-result);
49078+ down_write(&current->mm->mmap_sem);
49079 vm_munmap(textpos, text_len);
49080 vm_munmap(realdatastart, len);
49081+ up_write(&current->mm->mmap_sem);
49082 ret = result;
49083 goto err;
49084 }
49085@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
49086 }
49087 if (IS_ERR_VALUE(result)) {
49088 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
49089+ down_write(&current->mm->mmap_sem);
49090 vm_munmap(textpos, text_len + data_len + extra +
49091 MAX_SHARED_LIBS * sizeof(unsigned long));
49092+ up_write(&current->mm->mmap_sem);
49093 ret = result;
49094 goto err;
49095 }
49096diff --git a/fs/bio.c b/fs/bio.c
49097index b96fc6c..431d628 100644
49098--- a/fs/bio.c
49099+++ b/fs/bio.c
49100@@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
49101 /*
49102 * Overflow, abort
49103 */
49104- if (end < start)
49105+ if (end < start || end - start > INT_MAX - nr_pages)
49106 return ERR_PTR(-EINVAL);
49107
49108 nr_pages += end - start;
49109@@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
49110 /*
49111 * Overflow, abort
49112 */
49113- if (end < start)
49114+ if (end < start || end - start > INT_MAX - nr_pages)
49115 return ERR_PTR(-EINVAL);
49116
49117 nr_pages += end - start;
49118@@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
49119 const int read = bio_data_dir(bio) == READ;
49120 struct bio_map_data *bmd = bio->bi_private;
49121 int i;
49122- char *p = bmd->sgvecs[0].iov_base;
49123+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
49124
49125 __bio_for_each_segment(bvec, bio, i, 0) {
49126 char *addr = page_address(bvec->bv_page);
49127diff --git a/fs/block_dev.c b/fs/block_dev.c
49128index aae187a..fd790ba 100644
49129--- a/fs/block_dev.c
49130+++ b/fs/block_dev.c
49131@@ -652,7 +652,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
49132 else if (bdev->bd_contains == bdev)
49133 return true; /* is a whole device which isn't held */
49134
49135- else if (whole->bd_holder == bd_may_claim)
49136+ else if (whole->bd_holder == (void *)bd_may_claim)
49137 return true; /* is a partition of a device that is being partitioned */
49138 else if (whole->bd_holder != NULL)
49139 return false; /* is a partition of a held device */
49140diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
49141index ca9d8f1..8c0142d 100644
49142--- a/fs/btrfs/ctree.c
49143+++ b/fs/btrfs/ctree.c
49144@@ -1036,9 +1036,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
49145 free_extent_buffer(buf);
49146 add_root_to_dirty_list(root);
49147 } else {
49148- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
49149- parent_start = parent->start;
49150- else
49151+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
49152+ if (parent)
49153+ parent_start = parent->start;
49154+ else
49155+ parent_start = 0;
49156+ } else
49157 parent_start = 0;
49158
49159 WARN_ON(trans->transid != btrfs_header_generation(parent));
49160diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
49161index f49b62f..07834ab 100644
49162--- a/fs/btrfs/ioctl.c
49163+++ b/fs/btrfs/ioctl.c
49164@@ -3077,9 +3077,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
49165 for (i = 0; i < num_types; i++) {
49166 struct btrfs_space_info *tmp;
49167
49168+ /* Don't copy in more than we allocated */
49169 if (!slot_count)
49170 break;
49171
49172+ slot_count--;
49173+
49174 info = NULL;
49175 rcu_read_lock();
49176 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
49177@@ -3101,10 +3104,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
49178 memcpy(dest, &space, sizeof(space));
49179 dest++;
49180 space_args.total_spaces++;
49181- slot_count--;
49182 }
49183- if (!slot_count)
49184- break;
49185 }
49186 up_read(&info->groups_sem);
49187 }
49188diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
49189index f6b8859..54fe8c5 100644
49190--- a/fs/btrfs/super.c
49191+++ b/fs/btrfs/super.c
49192@@ -266,7 +266,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
49193 function, line, errstr);
49194 return;
49195 }
49196- ACCESS_ONCE(trans->transaction->aborted) = errno;
49197+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
49198 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
49199 }
49200 /*
49201diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
49202index 622f469..e8d2d55 100644
49203--- a/fs/cachefiles/bind.c
49204+++ b/fs/cachefiles/bind.c
49205@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
49206 args);
49207
49208 /* start by checking things over */
49209- ASSERT(cache->fstop_percent >= 0 &&
49210- cache->fstop_percent < cache->fcull_percent &&
49211+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
49212 cache->fcull_percent < cache->frun_percent &&
49213 cache->frun_percent < 100);
49214
49215- ASSERT(cache->bstop_percent >= 0 &&
49216- cache->bstop_percent < cache->bcull_percent &&
49217+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
49218 cache->bcull_percent < cache->brun_percent &&
49219 cache->brun_percent < 100);
49220
49221diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
49222index 0a1467b..6a53245 100644
49223--- a/fs/cachefiles/daemon.c
49224+++ b/fs/cachefiles/daemon.c
49225@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
49226 if (n > buflen)
49227 return -EMSGSIZE;
49228
49229- if (copy_to_user(_buffer, buffer, n) != 0)
49230+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
49231 return -EFAULT;
49232
49233 return n;
49234@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
49235 if (test_bit(CACHEFILES_DEAD, &cache->flags))
49236 return -EIO;
49237
49238- if (datalen < 0 || datalen > PAGE_SIZE - 1)
49239+ if (datalen > PAGE_SIZE - 1)
49240 return -EOPNOTSUPP;
49241
49242 /* drag the command string into the kernel so we can parse it */
49243@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
49244 if (args[0] != '%' || args[1] != '\0')
49245 return -EINVAL;
49246
49247- if (fstop < 0 || fstop >= cache->fcull_percent)
49248+ if (fstop >= cache->fcull_percent)
49249 return cachefiles_daemon_range_error(cache, args);
49250
49251 cache->fstop_percent = fstop;
49252@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
49253 if (args[0] != '%' || args[1] != '\0')
49254 return -EINVAL;
49255
49256- if (bstop < 0 || bstop >= cache->bcull_percent)
49257+ if (bstop >= cache->bcull_percent)
49258 return cachefiles_daemon_range_error(cache, args);
49259
49260 cache->bstop_percent = bstop;
49261diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
49262index 4938251..7e01445 100644
49263--- a/fs/cachefiles/internal.h
49264+++ b/fs/cachefiles/internal.h
49265@@ -59,7 +59,7 @@ struct cachefiles_cache {
49266 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
49267 struct rb_root active_nodes; /* active nodes (can't be culled) */
49268 rwlock_t active_lock; /* lock for active_nodes */
49269- atomic_t gravecounter; /* graveyard uniquifier */
49270+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
49271 unsigned frun_percent; /* when to stop culling (% files) */
49272 unsigned fcull_percent; /* when to start culling (% files) */
49273 unsigned fstop_percent; /* when to stop allocating (% files) */
49274@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
49275 * proc.c
49276 */
49277 #ifdef CONFIG_CACHEFILES_HISTOGRAM
49278-extern atomic_t cachefiles_lookup_histogram[HZ];
49279-extern atomic_t cachefiles_mkdir_histogram[HZ];
49280-extern atomic_t cachefiles_create_histogram[HZ];
49281+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49282+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49283+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
49284
49285 extern int __init cachefiles_proc_init(void);
49286 extern void cachefiles_proc_cleanup(void);
49287 static inline
49288-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
49289+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
49290 {
49291 unsigned long jif = jiffies - start_jif;
49292 if (jif >= HZ)
49293 jif = HZ - 1;
49294- atomic_inc(&histogram[jif]);
49295+ atomic_inc_unchecked(&histogram[jif]);
49296 }
49297
49298 #else
49299diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
49300index 8c01c5fc..15f982e 100644
49301--- a/fs/cachefiles/namei.c
49302+++ b/fs/cachefiles/namei.c
49303@@ -317,7 +317,7 @@ try_again:
49304 /* first step is to make up a grave dentry in the graveyard */
49305 sprintf(nbuffer, "%08x%08x",
49306 (uint32_t) get_seconds(),
49307- (uint32_t) atomic_inc_return(&cache->gravecounter));
49308+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
49309
49310 /* do the multiway lock magic */
49311 trap = lock_rename(cache->graveyard, dir);
49312diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
49313index eccd339..4c1d995 100644
49314--- a/fs/cachefiles/proc.c
49315+++ b/fs/cachefiles/proc.c
49316@@ -14,9 +14,9 @@
49317 #include <linux/seq_file.h>
49318 #include "internal.h"
49319
49320-atomic_t cachefiles_lookup_histogram[HZ];
49321-atomic_t cachefiles_mkdir_histogram[HZ];
49322-atomic_t cachefiles_create_histogram[HZ];
49323+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49324+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49325+atomic_unchecked_t cachefiles_create_histogram[HZ];
49326
49327 /*
49328 * display the latency histogram
49329@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
49330 return 0;
49331 default:
49332 index = (unsigned long) v - 3;
49333- x = atomic_read(&cachefiles_lookup_histogram[index]);
49334- y = atomic_read(&cachefiles_mkdir_histogram[index]);
49335- z = atomic_read(&cachefiles_create_histogram[index]);
49336+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
49337+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
49338+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
49339 if (x == 0 && y == 0 && z == 0)
49340 return 0;
49341
49342diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
49343index 4809922..aab2c39 100644
49344--- a/fs/cachefiles/rdwr.c
49345+++ b/fs/cachefiles/rdwr.c
49346@@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
49347 old_fs = get_fs();
49348 set_fs(KERNEL_DS);
49349 ret = file->f_op->write(
49350- file, (const void __user *) data, len, &pos);
49351+ file, (const void __force_user *) data, len, &pos);
49352 set_fs(old_fs);
49353 kunmap(page);
49354 if (ret != len)
49355diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
49356index 6d797f4..0ace2e5 100644
49357--- a/fs/ceph/dir.c
49358+++ b/fs/ceph/dir.c
49359@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
49360 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
49361 struct ceph_mds_client *mdsc = fsc->mdsc;
49362 unsigned frag = fpos_frag(filp->f_pos);
49363- int off = fpos_off(filp->f_pos);
49364+ unsigned int off = fpos_off(filp->f_pos);
49365 int err;
49366 u32 ftype;
49367 struct ceph_mds_reply_info_parsed *rinfo;
49368diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
49369index d9ea6ed..1e6c8ac 100644
49370--- a/fs/cifs/cifs_debug.c
49371+++ b/fs/cifs/cifs_debug.c
49372@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49373
49374 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
49375 #ifdef CONFIG_CIFS_STATS2
49376- atomic_set(&totBufAllocCount, 0);
49377- atomic_set(&totSmBufAllocCount, 0);
49378+ atomic_set_unchecked(&totBufAllocCount, 0);
49379+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49380 #endif /* CONFIG_CIFS_STATS2 */
49381 spin_lock(&cifs_tcp_ses_lock);
49382 list_for_each(tmp1, &cifs_tcp_ses_list) {
49383@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49384 tcon = list_entry(tmp3,
49385 struct cifs_tcon,
49386 tcon_list);
49387- atomic_set(&tcon->num_smbs_sent, 0);
49388+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
49389 if (server->ops->clear_stats)
49390 server->ops->clear_stats(tcon);
49391 }
49392@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49393 smBufAllocCount.counter, cifs_min_small);
49394 #ifdef CONFIG_CIFS_STATS2
49395 seq_printf(m, "Total Large %d Small %d Allocations\n",
49396- atomic_read(&totBufAllocCount),
49397- atomic_read(&totSmBufAllocCount));
49398+ atomic_read_unchecked(&totBufAllocCount),
49399+ atomic_read_unchecked(&totSmBufAllocCount));
49400 #endif /* CONFIG_CIFS_STATS2 */
49401
49402 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
49403@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49404 if (tcon->need_reconnect)
49405 seq_puts(m, "\tDISCONNECTED ");
49406 seq_printf(m, "\nSMBs: %d",
49407- atomic_read(&tcon->num_smbs_sent));
49408+ atomic_read_unchecked(&tcon->num_smbs_sent));
49409 if (server->ops->print_stats)
49410 server->ops->print_stats(m, tcon);
49411 }
49412diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
49413index 345fc89..b2acae5 100644
49414--- a/fs/cifs/cifsfs.c
49415+++ b/fs/cifs/cifsfs.c
49416@@ -1033,7 +1033,7 @@ cifs_init_request_bufs(void)
49417 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
49418 cifs_req_cachep = kmem_cache_create("cifs_request",
49419 CIFSMaxBufSize + max_hdr_size, 0,
49420- SLAB_HWCACHE_ALIGN, NULL);
49421+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
49422 if (cifs_req_cachep == NULL)
49423 return -ENOMEM;
49424
49425@@ -1060,7 +1060,7 @@ cifs_init_request_bufs(void)
49426 efficient to alloc 1 per page off the slab compared to 17K (5page)
49427 alloc of large cifs buffers even when page debugging is on */
49428 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
49429- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
49430+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
49431 NULL);
49432 if (cifs_sm_req_cachep == NULL) {
49433 mempool_destroy(cifs_req_poolp);
49434@@ -1145,8 +1145,8 @@ init_cifs(void)
49435 atomic_set(&bufAllocCount, 0);
49436 atomic_set(&smBufAllocCount, 0);
49437 #ifdef CONFIG_CIFS_STATS2
49438- atomic_set(&totBufAllocCount, 0);
49439- atomic_set(&totSmBufAllocCount, 0);
49440+ atomic_set_unchecked(&totBufAllocCount, 0);
49441+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49442 #endif /* CONFIG_CIFS_STATS2 */
49443
49444 atomic_set(&midCount, 0);
49445diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
49446index 4f07f6f..55de8ce 100644
49447--- a/fs/cifs/cifsglob.h
49448+++ b/fs/cifs/cifsglob.h
49449@@ -751,35 +751,35 @@ struct cifs_tcon {
49450 __u16 Flags; /* optional support bits */
49451 enum statusEnum tidStatus;
49452 #ifdef CONFIG_CIFS_STATS
49453- atomic_t num_smbs_sent;
49454+ atomic_unchecked_t num_smbs_sent;
49455 union {
49456 struct {
49457- atomic_t num_writes;
49458- atomic_t num_reads;
49459- atomic_t num_flushes;
49460- atomic_t num_oplock_brks;
49461- atomic_t num_opens;
49462- atomic_t num_closes;
49463- atomic_t num_deletes;
49464- atomic_t num_mkdirs;
49465- atomic_t num_posixopens;
49466- atomic_t num_posixmkdirs;
49467- atomic_t num_rmdirs;
49468- atomic_t num_renames;
49469- atomic_t num_t2renames;
49470- atomic_t num_ffirst;
49471- atomic_t num_fnext;
49472- atomic_t num_fclose;
49473- atomic_t num_hardlinks;
49474- atomic_t num_symlinks;
49475- atomic_t num_locks;
49476- atomic_t num_acl_get;
49477- atomic_t num_acl_set;
49478+ atomic_unchecked_t num_writes;
49479+ atomic_unchecked_t num_reads;
49480+ atomic_unchecked_t num_flushes;
49481+ atomic_unchecked_t num_oplock_brks;
49482+ atomic_unchecked_t num_opens;
49483+ atomic_unchecked_t num_closes;
49484+ atomic_unchecked_t num_deletes;
49485+ atomic_unchecked_t num_mkdirs;
49486+ atomic_unchecked_t num_posixopens;
49487+ atomic_unchecked_t num_posixmkdirs;
49488+ atomic_unchecked_t num_rmdirs;
49489+ atomic_unchecked_t num_renames;
49490+ atomic_unchecked_t num_t2renames;
49491+ atomic_unchecked_t num_ffirst;
49492+ atomic_unchecked_t num_fnext;
49493+ atomic_unchecked_t num_fclose;
49494+ atomic_unchecked_t num_hardlinks;
49495+ atomic_unchecked_t num_symlinks;
49496+ atomic_unchecked_t num_locks;
49497+ atomic_unchecked_t num_acl_get;
49498+ atomic_unchecked_t num_acl_set;
49499 } cifs_stats;
49500 #ifdef CONFIG_CIFS_SMB2
49501 struct {
49502- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49503- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49504+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49505+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49506 } smb2_stats;
49507 #endif /* CONFIG_CIFS_SMB2 */
49508 } stats;
49509@@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
49510 }
49511
49512 #ifdef CONFIG_CIFS_STATS
49513-#define cifs_stats_inc atomic_inc
49514+#define cifs_stats_inc atomic_inc_unchecked
49515
49516 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
49517 unsigned int bytes)
49518@@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
49519 /* Various Debug counters */
49520 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
49521 #ifdef CONFIG_CIFS_STATS2
49522-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
49523-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
49524+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
49525+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
49526 #endif
49527 GLOBAL_EXTERN atomic_t smBufAllocCount;
49528 GLOBAL_EXTERN atomic_t midCount;
49529diff --git a/fs/cifs/link.c b/fs/cifs/link.c
49530index 9f6c4c4..8de307a 100644
49531--- a/fs/cifs/link.c
49532+++ b/fs/cifs/link.c
49533@@ -616,7 +616,7 @@ symlink_exit:
49534
49535 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
49536 {
49537- char *p = nd_get_link(nd);
49538+ const char *p = nd_get_link(nd);
49539 if (!IS_ERR(p))
49540 kfree(p);
49541 }
49542diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
49543index 1b15bf8..1ce489e 100644
49544--- a/fs/cifs/misc.c
49545+++ b/fs/cifs/misc.c
49546@@ -169,7 +169,7 @@ cifs_buf_get(void)
49547 memset(ret_buf, 0, buf_size + 3);
49548 atomic_inc(&bufAllocCount);
49549 #ifdef CONFIG_CIFS_STATS2
49550- atomic_inc(&totBufAllocCount);
49551+ atomic_inc_unchecked(&totBufAllocCount);
49552 #endif /* CONFIG_CIFS_STATS2 */
49553 }
49554
49555@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
49556 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
49557 atomic_inc(&smBufAllocCount);
49558 #ifdef CONFIG_CIFS_STATS2
49559- atomic_inc(&totSmBufAllocCount);
49560+ atomic_inc_unchecked(&totSmBufAllocCount);
49561 #endif /* CONFIG_CIFS_STATS2 */
49562
49563 }
49564diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
49565index 47bc5a8..10decbe 100644
49566--- a/fs/cifs/smb1ops.c
49567+++ b/fs/cifs/smb1ops.c
49568@@ -586,27 +586,27 @@ static void
49569 cifs_clear_stats(struct cifs_tcon *tcon)
49570 {
49571 #ifdef CONFIG_CIFS_STATS
49572- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
49573- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
49574- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
49575- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
49576- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
49577- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
49578- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
49579- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
49580- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
49581- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
49582- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
49583- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
49584- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
49585- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
49586- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
49587- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
49588- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
49589- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
49590- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
49591- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
49592- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
49593+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
49594+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
49595+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
49596+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
49597+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
49598+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
49599+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
49600+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
49601+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
49602+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
49603+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
49604+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
49605+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
49606+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
49607+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
49608+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
49609+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
49610+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
49611+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
49612+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
49613+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
49614 #endif
49615 }
49616
49617@@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
49618 {
49619 #ifdef CONFIG_CIFS_STATS
49620 seq_printf(m, " Oplocks breaks: %d",
49621- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
49622+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
49623 seq_printf(m, "\nReads: %d Bytes: %llu",
49624- atomic_read(&tcon->stats.cifs_stats.num_reads),
49625+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
49626 (long long)(tcon->bytes_read));
49627 seq_printf(m, "\nWrites: %d Bytes: %llu",
49628- atomic_read(&tcon->stats.cifs_stats.num_writes),
49629+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
49630 (long long)(tcon->bytes_written));
49631 seq_printf(m, "\nFlushes: %d",
49632- atomic_read(&tcon->stats.cifs_stats.num_flushes));
49633+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
49634 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
49635- atomic_read(&tcon->stats.cifs_stats.num_locks),
49636- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
49637- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
49638+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
49639+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
49640+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
49641 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
49642- atomic_read(&tcon->stats.cifs_stats.num_opens),
49643- atomic_read(&tcon->stats.cifs_stats.num_closes),
49644- atomic_read(&tcon->stats.cifs_stats.num_deletes));
49645+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
49646+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
49647+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
49648 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
49649- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
49650- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
49651+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
49652+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
49653 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
49654- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
49655- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
49656+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
49657+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
49658 seq_printf(m, "\nRenames: %d T2 Renames %d",
49659- atomic_read(&tcon->stats.cifs_stats.num_renames),
49660- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
49661+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
49662+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
49663 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
49664- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
49665- atomic_read(&tcon->stats.cifs_stats.num_fnext),
49666- atomic_read(&tcon->stats.cifs_stats.num_fclose));
49667+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
49668+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
49669+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
49670 #endif
49671 }
49672
49673diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
49674index bceffe7..cd1ae59 100644
49675--- a/fs/cifs/smb2ops.c
49676+++ b/fs/cifs/smb2ops.c
49677@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
49678 #ifdef CONFIG_CIFS_STATS
49679 int i;
49680 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
49681- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
49682- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
49683+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
49684+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
49685 }
49686 #endif
49687 }
49688@@ -284,66 +284,66 @@ static void
49689 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
49690 {
49691 #ifdef CONFIG_CIFS_STATS
49692- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
49693- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
49694+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
49695+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
49696 seq_printf(m, "\nNegotiates: %d sent %d failed",
49697- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
49698- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
49699+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
49700+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
49701 seq_printf(m, "\nSessionSetups: %d sent %d failed",
49702- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
49703- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
49704+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
49705+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
49706 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
49707 seq_printf(m, "\nLogoffs: %d sent %d failed",
49708- atomic_read(&sent[SMB2_LOGOFF_HE]),
49709- atomic_read(&failed[SMB2_LOGOFF_HE]));
49710+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
49711+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
49712 seq_printf(m, "\nTreeConnects: %d sent %d failed",
49713- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
49714- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
49715+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
49716+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
49717 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
49718- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
49719- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
49720+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
49721+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
49722 seq_printf(m, "\nCreates: %d sent %d failed",
49723- atomic_read(&sent[SMB2_CREATE_HE]),
49724- atomic_read(&failed[SMB2_CREATE_HE]));
49725+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
49726+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
49727 seq_printf(m, "\nCloses: %d sent %d failed",
49728- atomic_read(&sent[SMB2_CLOSE_HE]),
49729- atomic_read(&failed[SMB2_CLOSE_HE]));
49730+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
49731+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
49732 seq_printf(m, "\nFlushes: %d sent %d failed",
49733- atomic_read(&sent[SMB2_FLUSH_HE]),
49734- atomic_read(&failed[SMB2_FLUSH_HE]));
49735+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
49736+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
49737 seq_printf(m, "\nReads: %d sent %d failed",
49738- atomic_read(&sent[SMB2_READ_HE]),
49739- atomic_read(&failed[SMB2_READ_HE]));
49740+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
49741+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
49742 seq_printf(m, "\nWrites: %d sent %d failed",
49743- atomic_read(&sent[SMB2_WRITE_HE]),
49744- atomic_read(&failed[SMB2_WRITE_HE]));
49745+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
49746+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
49747 seq_printf(m, "\nLocks: %d sent %d failed",
49748- atomic_read(&sent[SMB2_LOCK_HE]),
49749- atomic_read(&failed[SMB2_LOCK_HE]));
49750+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
49751+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
49752 seq_printf(m, "\nIOCTLs: %d sent %d failed",
49753- atomic_read(&sent[SMB2_IOCTL_HE]),
49754- atomic_read(&failed[SMB2_IOCTL_HE]));
49755+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
49756+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
49757 seq_printf(m, "\nCancels: %d sent %d failed",
49758- atomic_read(&sent[SMB2_CANCEL_HE]),
49759- atomic_read(&failed[SMB2_CANCEL_HE]));
49760+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
49761+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
49762 seq_printf(m, "\nEchos: %d sent %d failed",
49763- atomic_read(&sent[SMB2_ECHO_HE]),
49764- atomic_read(&failed[SMB2_ECHO_HE]));
49765+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
49766+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
49767 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
49768- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
49769- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
49770+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
49771+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
49772 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
49773- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
49774- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
49775+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
49776+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
49777 seq_printf(m, "\nQueryInfos: %d sent %d failed",
49778- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
49779- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
49780+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
49781+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
49782 seq_printf(m, "\nSetInfos: %d sent %d failed",
49783- atomic_read(&sent[SMB2_SET_INFO_HE]),
49784- atomic_read(&failed[SMB2_SET_INFO_HE]));
49785+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
49786+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
49787 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
49788- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
49789- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
49790+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
49791+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
49792 #endif
49793 }
49794
49795diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
49796index 41d9d07..dbb4772 100644
49797--- a/fs/cifs/smb2pdu.c
49798+++ b/fs/cifs/smb2pdu.c
49799@@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
49800 default:
49801 cERROR(1, "info level %u isn't supported",
49802 srch_inf->info_level);
49803- rc = -EINVAL;
49804- goto qdir_exit;
49805+ return -EINVAL;
49806 }
49807
49808 req->FileIndex = cpu_to_le32(index);
49809diff --git a/fs/coda/cache.c b/fs/coda/cache.c
49810index 1da168c..8bc7ff6 100644
49811--- a/fs/coda/cache.c
49812+++ b/fs/coda/cache.c
49813@@ -24,7 +24,7 @@
49814 #include "coda_linux.h"
49815 #include "coda_cache.h"
49816
49817-static atomic_t permission_epoch = ATOMIC_INIT(0);
49818+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
49819
49820 /* replace or extend an acl cache hit */
49821 void coda_cache_enter(struct inode *inode, int mask)
49822@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
49823 struct coda_inode_info *cii = ITOC(inode);
49824
49825 spin_lock(&cii->c_lock);
49826- cii->c_cached_epoch = atomic_read(&permission_epoch);
49827+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
49828 if (!uid_eq(cii->c_uid, current_fsuid())) {
49829 cii->c_uid = current_fsuid();
49830 cii->c_cached_perm = mask;
49831@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
49832 {
49833 struct coda_inode_info *cii = ITOC(inode);
49834 spin_lock(&cii->c_lock);
49835- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
49836+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
49837 spin_unlock(&cii->c_lock);
49838 }
49839
49840 /* remove all acl caches */
49841 void coda_cache_clear_all(struct super_block *sb)
49842 {
49843- atomic_inc(&permission_epoch);
49844+ atomic_inc_unchecked(&permission_epoch);
49845 }
49846
49847
49848@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
49849 spin_lock(&cii->c_lock);
49850 hit = (mask & cii->c_cached_perm) == mask &&
49851 uid_eq(cii->c_uid, current_fsuid()) &&
49852- cii->c_cached_epoch == atomic_read(&permission_epoch);
49853+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
49854 spin_unlock(&cii->c_lock);
49855
49856 return hit;
49857diff --git a/fs/compat.c b/fs/compat.c
49858index d487985..c9e04b1 100644
49859--- a/fs/compat.c
49860+++ b/fs/compat.c
49861@@ -54,7 +54,7 @@
49862 #include <asm/ioctls.h>
49863 #include "internal.h"
49864
49865-int compat_log = 1;
49866+int compat_log = 0;
49867
49868 int compat_printk(const char *fmt, ...)
49869 {
49870@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
49871
49872 set_fs(KERNEL_DS);
49873 /* The __user pointer cast is valid because of the set_fs() */
49874- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
49875+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
49876 set_fs(oldfs);
49877 /* truncating is ok because it's a user address */
49878 if (!ret)
49879@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
49880 goto out;
49881
49882 ret = -EINVAL;
49883- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
49884+ if (nr_segs > UIO_MAXIOV)
49885 goto out;
49886 if (nr_segs > fast_segs) {
49887 ret = -ENOMEM;
49888@@ -835,6 +835,7 @@ struct compat_old_linux_dirent {
49889
49890 struct compat_readdir_callback {
49891 struct compat_old_linux_dirent __user *dirent;
49892+ struct file * file;
49893 int result;
49894 };
49895
49896@@ -852,6 +853,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
49897 buf->result = -EOVERFLOW;
49898 return -EOVERFLOW;
49899 }
49900+
49901+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49902+ return 0;
49903+
49904 buf->result++;
49905 dirent = buf->dirent;
49906 if (!access_ok(VERIFY_WRITE, dirent,
49907@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
49908
49909 buf.result = 0;
49910 buf.dirent = dirent;
49911+ buf.file = f.file;
49912
49913 error = vfs_readdir(f.file, compat_fillonedir, &buf);
49914 if (buf.result)
49915@@ -901,6 +907,7 @@ struct compat_linux_dirent {
49916 struct compat_getdents_callback {
49917 struct compat_linux_dirent __user *current_dir;
49918 struct compat_linux_dirent __user *previous;
49919+ struct file * file;
49920 int count;
49921 int error;
49922 };
49923@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
49924 buf->error = -EOVERFLOW;
49925 return -EOVERFLOW;
49926 }
49927+
49928+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49929+ return 0;
49930+
49931 dirent = buf->previous;
49932 if (dirent) {
49933 if (__put_user(offset, &dirent->d_off))
49934@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
49935 buf.previous = NULL;
49936 buf.count = count;
49937 buf.error = 0;
49938+ buf.file = f.file;
49939
49940 error = vfs_readdir(f.file, compat_filldir, &buf);
49941 if (error >= 0)
49942@@ -987,6 +999,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
49943 struct compat_getdents_callback64 {
49944 struct linux_dirent64 __user *current_dir;
49945 struct linux_dirent64 __user *previous;
49946+ struct file * file;
49947 int count;
49948 int error;
49949 };
49950@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
49951 buf->error = -EINVAL; /* only used if we fail.. */
49952 if (reclen > buf->count)
49953 return -EINVAL;
49954+
49955+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49956+ return 0;
49957+
49958 dirent = buf->previous;
49959
49960 if (dirent) {
49961@@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
49962 buf.previous = NULL;
49963 buf.count = count;
49964 buf.error = 0;
49965+ buf.file = f.file;
49966
49967 error = vfs_readdir(f.file, compat_filldir64, &buf);
49968 if (error >= 0)
49969 error = buf.error;
49970 lastdirent = buf.previous;
49971 if (lastdirent) {
49972- typeof(lastdirent->d_off) d_off = f.file->f_pos;
49973+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
49974 if (__put_user_unaligned(d_off, &lastdirent->d_off))
49975 error = -EFAULT;
49976 else
49977diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
49978index a81147e..20bf2b5 100644
49979--- a/fs/compat_binfmt_elf.c
49980+++ b/fs/compat_binfmt_elf.c
49981@@ -30,11 +30,13 @@
49982 #undef elf_phdr
49983 #undef elf_shdr
49984 #undef elf_note
49985+#undef elf_dyn
49986 #undef elf_addr_t
49987 #define elfhdr elf32_hdr
49988 #define elf_phdr elf32_phdr
49989 #define elf_shdr elf32_shdr
49990 #define elf_note elf32_note
49991+#define elf_dyn Elf32_Dyn
49992 #define elf_addr_t Elf32_Addr
49993
49994 /*
49995diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
49996index 3ced75f..b28d192 100644
49997--- a/fs/compat_ioctl.c
49998+++ b/fs/compat_ioctl.c
49999@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
50000 return -EFAULT;
50001 if (__get_user(udata, &ss32->iomem_base))
50002 return -EFAULT;
50003- ss.iomem_base = compat_ptr(udata);
50004+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
50005 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
50006 __get_user(ss.port_high, &ss32->port_high))
50007 return -EFAULT;
50008@@ -704,8 +704,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
50009 for (i = 0; i < nmsgs; i++) {
50010 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
50011 return -EFAULT;
50012- if (get_user(datap, &umsgs[i].buf) ||
50013- put_user(compat_ptr(datap), &tmsgs[i].buf))
50014+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
50015+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
50016 return -EFAULT;
50017 }
50018 return sys_ioctl(fd, cmd, (unsigned long)tdata);
50019@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
50020 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
50021 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
50022 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
50023- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
50024+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
50025 return -EFAULT;
50026
50027 return ioctl_preallocate(file, p);
50028@@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
50029 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
50030 {
50031 unsigned int a, b;
50032- a = *(unsigned int *)p;
50033- b = *(unsigned int *)q;
50034+ a = *(const unsigned int *)p;
50035+ b = *(const unsigned int *)q;
50036 if (a > b)
50037 return 1;
50038 if (a < b)
50039diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
50040index 7aabc6a..34c1197 100644
50041--- a/fs/configfs/dir.c
50042+++ b/fs/configfs/dir.c
50043@@ -1565,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
50044 }
50045 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
50046 struct configfs_dirent *next;
50047- const char * name;
50048+ const unsigned char * name;
50049+ char d_name[sizeof(next->s_dentry->d_iname)];
50050 int len;
50051 struct inode *inode = NULL;
50052
50053@@ -1575,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
50054 continue;
50055
50056 name = configfs_get_name(next);
50057- len = strlen(name);
50058+ if (next->s_dentry && name == next->s_dentry->d_iname) {
50059+ len = next->s_dentry->d_name.len;
50060+ memcpy(d_name, name, len);
50061+ name = d_name;
50062+ } else
50063+ len = strlen(name);
50064
50065 /*
50066 * We'll have a dentry and an inode for
50067diff --git a/fs/coredump.c b/fs/coredump.c
50068index c647965..a77bff3 100644
50069--- a/fs/coredump.c
50070+++ b/fs/coredump.c
50071@@ -52,7 +52,7 @@ struct core_name {
50072 char *corename;
50073 int used, size;
50074 };
50075-static atomic_t call_count = ATOMIC_INIT(1);
50076+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
50077
50078 /* The maximal length of core_pattern is also specified in sysctl.c */
50079
50080@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
50081 {
50082 char *old_corename = cn->corename;
50083
50084- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
50085+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
50086 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
50087
50088 if (!cn->corename) {
50089@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
50090 int pid_in_pattern = 0;
50091 int err = 0;
50092
50093- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
50094+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
50095 cn->corename = kmalloc(cn->size, GFP_KERNEL);
50096 cn->used = 0;
50097
50098@@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
50099 pipe = file_inode(file)->i_pipe;
50100
50101 pipe_lock(pipe);
50102- pipe->readers++;
50103- pipe->writers--;
50104+ atomic_inc(&pipe->readers);
50105+ atomic_dec(&pipe->writers);
50106
50107- while ((pipe->readers > 1) && (!signal_pending(current))) {
50108+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
50109 wake_up_interruptible_sync(&pipe->wait);
50110 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
50111 pipe_wait(pipe);
50112 }
50113
50114- pipe->readers--;
50115- pipe->writers++;
50116+ atomic_dec(&pipe->readers);
50117+ atomic_inc(&pipe->writers);
50118 pipe_unlock(pipe);
50119
50120 }
50121@@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
50122 int ispipe;
50123 struct files_struct *displaced;
50124 bool need_nonrelative = false;
50125- static atomic_t core_dump_count = ATOMIC_INIT(0);
50126+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
50127+ long signr = siginfo->si_signo;
50128 struct coredump_params cprm = {
50129 .siginfo = siginfo,
50130 .regs = signal_pt_regs(),
50131@@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
50132 .mm_flags = mm->flags,
50133 };
50134
50135- audit_core_dumps(siginfo->si_signo);
50136+ audit_core_dumps(signr);
50137+
50138+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
50139+ gr_handle_brute_attach(cprm.mm_flags);
50140
50141 binfmt = mm->binfmt;
50142 if (!binfmt || !binfmt->core_dump)
50143@@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
50144 need_nonrelative = true;
50145 }
50146
50147- retval = coredump_wait(siginfo->si_signo, &core_state);
50148+ retval = coredump_wait(signr, &core_state);
50149 if (retval < 0)
50150 goto fail_creds;
50151
50152@@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
50153 }
50154 cprm.limit = RLIM_INFINITY;
50155
50156- dump_count = atomic_inc_return(&core_dump_count);
50157+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
50158 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
50159 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
50160 task_tgid_vnr(current), current->comm);
50161@@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
50162 } else {
50163 struct inode *inode;
50164
50165+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
50166+
50167 if (cprm.limit < binfmt->min_coredump)
50168 goto fail_unlock;
50169
50170@@ -640,7 +646,7 @@ close_fail:
50171 filp_close(cprm.file, NULL);
50172 fail_dropcount:
50173 if (ispipe)
50174- atomic_dec(&core_dump_count);
50175+ atomic_dec_unchecked(&core_dump_count);
50176 fail_unlock:
50177 kfree(cn.corename);
50178 fail_corename:
50179@@ -659,7 +665,7 @@ fail:
50180 */
50181 int dump_write(struct file *file, const void *addr, int nr)
50182 {
50183- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
50184+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
50185 }
50186 EXPORT_SYMBOL(dump_write);
50187
50188diff --git a/fs/dcache.c b/fs/dcache.c
50189index e689268..f36956e 100644
50190--- a/fs/dcache.c
50191+++ b/fs/dcache.c
50192@@ -3100,7 +3100,7 @@ void __init vfs_caches_init(unsigned long mempages)
50193 mempages -= reserve;
50194
50195 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
50196- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
50197+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
50198
50199 dcache_init();
50200 inode_init();
50201diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
50202index 4888cb3..e0f7cf8 100644
50203--- a/fs/debugfs/inode.c
50204+++ b/fs/debugfs/inode.c
50205@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
50206 */
50207 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
50208 {
50209+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50210+ return __create_file(name, S_IFDIR | S_IRWXU,
50211+#else
50212 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
50213+#endif
50214 parent, NULL, NULL);
50215 }
50216 EXPORT_SYMBOL_GPL(debugfs_create_dir);
50217diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
50218index 5eab400..810a3f5 100644
50219--- a/fs/ecryptfs/inode.c
50220+++ b/fs/ecryptfs/inode.c
50221@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
50222 old_fs = get_fs();
50223 set_fs(get_ds());
50224 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
50225- (char __user *)lower_buf,
50226+ (char __force_user *)lower_buf,
50227 PATH_MAX);
50228 set_fs(old_fs);
50229 if (rc < 0)
50230@@ -706,7 +706,7 @@ out:
50231 static void
50232 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
50233 {
50234- char *buf = nd_get_link(nd);
50235+ const char *buf = nd_get_link(nd);
50236 if (!IS_ERR(buf)) {
50237 /* Free the char* */
50238 kfree(buf);
50239diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
50240index e4141f2..d8263e8 100644
50241--- a/fs/ecryptfs/miscdev.c
50242+++ b/fs/ecryptfs/miscdev.c
50243@@ -304,7 +304,7 @@ check_list:
50244 goto out_unlock_msg_ctx;
50245 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
50246 if (msg_ctx->msg) {
50247- if (copy_to_user(&buf[i], packet_length, packet_length_size))
50248+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
50249 goto out_unlock_msg_ctx;
50250 i += packet_length_size;
50251 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
50252diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
50253index 6a16053..2155147 100644
50254--- a/fs/ecryptfs/read_write.c
50255+++ b/fs/ecryptfs/read_write.c
50256@@ -240,7 +240,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
50257 return -EIO;
50258 fs_save = get_fs();
50259 set_fs(get_ds());
50260- rc = vfs_read(lower_file, data, size, &offset);
50261+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
50262 set_fs(fs_save);
50263 return rc;
50264 }
50265diff --git a/fs/exec.c b/fs/exec.c
50266index 6d56ff2..3bc6638 100644
50267--- a/fs/exec.c
50268+++ b/fs/exec.c
50269@@ -55,8 +55,20 @@
50270 #include <linux/pipe_fs_i.h>
50271 #include <linux/oom.h>
50272 #include <linux/compat.h>
50273+#include <linux/random.h>
50274+#include <linux/seq_file.h>
50275+#include <linux/coredump.h>
50276+#include <linux/mman.h>
50277+
50278+#ifdef CONFIG_PAX_REFCOUNT
50279+#include <linux/kallsyms.h>
50280+#include <linux/kdebug.h>
50281+#endif
50282+
50283+#include <trace/events/fs.h>
50284
50285 #include <asm/uaccess.h>
50286+#include <asm/sections.h>
50287 #include <asm/mmu_context.h>
50288 #include <asm/tlb.h>
50289
50290@@ -66,6 +78,18 @@
50291
50292 #include <trace/events/sched.h>
50293
50294+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
50295+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
50296+{
50297+ 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");
50298+}
50299+#endif
50300+
50301+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
50302+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
50303+EXPORT_SYMBOL(pax_set_initial_flags_func);
50304+#endif
50305+
50306 int suid_dumpable = 0;
50307
50308 static LIST_HEAD(formats);
50309@@ -75,8 +99,8 @@ void __register_binfmt(struct linux_binfmt * fmt, int insert)
50310 {
50311 BUG_ON(!fmt);
50312 write_lock(&binfmt_lock);
50313- insert ? list_add(&fmt->lh, &formats) :
50314- list_add_tail(&fmt->lh, &formats);
50315+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
50316+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
50317 write_unlock(&binfmt_lock);
50318 }
50319
50320@@ -85,7 +109,7 @@ EXPORT_SYMBOL(__register_binfmt);
50321 void unregister_binfmt(struct linux_binfmt * fmt)
50322 {
50323 write_lock(&binfmt_lock);
50324- list_del(&fmt->lh);
50325+ pax_list_del((struct list_head *)&fmt->lh);
50326 write_unlock(&binfmt_lock);
50327 }
50328
50329@@ -180,18 +204,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50330 int write)
50331 {
50332 struct page *page;
50333- int ret;
50334
50335-#ifdef CONFIG_STACK_GROWSUP
50336- if (write) {
50337- ret = expand_downwards(bprm->vma, pos);
50338- if (ret < 0)
50339- return NULL;
50340- }
50341-#endif
50342- ret = get_user_pages(current, bprm->mm, pos,
50343- 1, write, 1, &page, NULL);
50344- if (ret <= 0)
50345+ if (0 > expand_downwards(bprm->vma, pos))
50346+ return NULL;
50347+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
50348 return NULL;
50349
50350 if (write) {
50351@@ -207,6 +223,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50352 if (size <= ARG_MAX)
50353 return page;
50354
50355+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50356+ // only allow 512KB for argv+env on suid/sgid binaries
50357+ // to prevent easy ASLR exhaustion
50358+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
50359+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
50360+ (size > (512 * 1024))) {
50361+ put_page(page);
50362+ return NULL;
50363+ }
50364+#endif
50365+
50366 /*
50367 * Limit to 1/4-th the stack size for the argv+env strings.
50368 * This ensures that:
50369@@ -266,6 +293,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50370 vma->vm_end = STACK_TOP_MAX;
50371 vma->vm_start = vma->vm_end - PAGE_SIZE;
50372 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
50373+
50374+#ifdef CONFIG_PAX_SEGMEXEC
50375+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
50376+#endif
50377+
50378 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
50379 INIT_LIST_HEAD(&vma->anon_vma_chain);
50380
50381@@ -276,6 +308,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50382 mm->stack_vm = mm->total_vm = 1;
50383 up_write(&mm->mmap_sem);
50384 bprm->p = vma->vm_end - sizeof(void *);
50385+
50386+#ifdef CONFIG_PAX_RANDUSTACK
50387+ if (randomize_va_space)
50388+ bprm->p ^= random32() & ~PAGE_MASK;
50389+#endif
50390+
50391 return 0;
50392 err:
50393 up_write(&mm->mmap_sem);
50394@@ -396,7 +434,7 @@ struct user_arg_ptr {
50395 } ptr;
50396 };
50397
50398-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50399+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50400 {
50401 const char __user *native;
50402
50403@@ -405,14 +443,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50404 compat_uptr_t compat;
50405
50406 if (get_user(compat, argv.ptr.compat + nr))
50407- return ERR_PTR(-EFAULT);
50408+ return (const char __force_user *)ERR_PTR(-EFAULT);
50409
50410 return compat_ptr(compat);
50411 }
50412 #endif
50413
50414 if (get_user(native, argv.ptr.native + nr))
50415- return ERR_PTR(-EFAULT);
50416+ return (const char __force_user *)ERR_PTR(-EFAULT);
50417
50418 return native;
50419 }
50420@@ -431,7 +469,7 @@ static int count(struct user_arg_ptr argv, int max)
50421 if (!p)
50422 break;
50423
50424- if (IS_ERR(p))
50425+ if (IS_ERR((const char __force_kernel *)p))
50426 return -EFAULT;
50427
50428 if (i >= max)
50429@@ -466,7 +504,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
50430
50431 ret = -EFAULT;
50432 str = get_user_arg_ptr(argv, argc);
50433- if (IS_ERR(str))
50434+ if (IS_ERR((const char __force_kernel *)str))
50435 goto out;
50436
50437 len = strnlen_user(str, MAX_ARG_STRLEN);
50438@@ -548,7 +586,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
50439 int r;
50440 mm_segment_t oldfs = get_fs();
50441 struct user_arg_ptr argv = {
50442- .ptr.native = (const char __user *const __user *)__argv,
50443+ .ptr.native = (const char __force_user * const __force_user *)__argv,
50444 };
50445
50446 set_fs(KERNEL_DS);
50447@@ -583,7 +621,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50448 unsigned long new_end = old_end - shift;
50449 struct mmu_gather tlb;
50450
50451- BUG_ON(new_start > new_end);
50452+ if (new_start >= new_end || new_start < mmap_min_addr)
50453+ return -ENOMEM;
50454
50455 /*
50456 * ensure there are no vmas between where we want to go
50457@@ -592,6 +631,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50458 if (vma != find_vma(mm, new_start))
50459 return -EFAULT;
50460
50461+#ifdef CONFIG_PAX_SEGMEXEC
50462+ BUG_ON(pax_find_mirror_vma(vma));
50463+#endif
50464+
50465 /*
50466 * cover the whole range: [new_start, old_end)
50467 */
50468@@ -672,10 +715,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50469 stack_top = arch_align_stack(stack_top);
50470 stack_top = PAGE_ALIGN(stack_top);
50471
50472- if (unlikely(stack_top < mmap_min_addr) ||
50473- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
50474- return -ENOMEM;
50475-
50476 stack_shift = vma->vm_end - stack_top;
50477
50478 bprm->p -= stack_shift;
50479@@ -687,8 +726,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
50480 bprm->exec -= stack_shift;
50481
50482 down_write(&mm->mmap_sem);
50483+
50484+ /* Move stack pages down in memory. */
50485+ if (stack_shift) {
50486+ ret = shift_arg_pages(vma, stack_shift);
50487+ if (ret)
50488+ goto out_unlock;
50489+ }
50490+
50491 vm_flags = VM_STACK_FLAGS;
50492
50493+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
50494+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
50495+ vm_flags &= ~VM_EXEC;
50496+
50497+#ifdef CONFIG_PAX_MPROTECT
50498+ if (mm->pax_flags & MF_PAX_MPROTECT)
50499+ vm_flags &= ~VM_MAYEXEC;
50500+#endif
50501+
50502+ }
50503+#endif
50504+
50505 /*
50506 * Adjust stack execute permissions; explicitly enable for
50507 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
50508@@ -707,13 +766,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50509 goto out_unlock;
50510 BUG_ON(prev != vma);
50511
50512- /* Move stack pages down in memory. */
50513- if (stack_shift) {
50514- ret = shift_arg_pages(vma, stack_shift);
50515- if (ret)
50516- goto out_unlock;
50517- }
50518-
50519 /* mprotect_fixup is overkill to remove the temporary stack flags */
50520 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
50521
50522@@ -737,6 +789,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
50523 #endif
50524 current->mm->start_stack = bprm->p;
50525 ret = expand_stack(vma, stack_base);
50526+
50527+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
50528+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
50529+ unsigned long size;
50530+ vm_flags_t vm_flags;
50531+
50532+ size = STACK_TOP - vma->vm_end;
50533+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
50534+
50535+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
50536+
50537+#ifdef CONFIG_X86
50538+ if (!ret) {
50539+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
50540+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
50541+ }
50542+#endif
50543+
50544+ }
50545+#endif
50546+
50547 if (ret)
50548 ret = -EFAULT;
50549
50550@@ -772,6 +845,8 @@ struct file *open_exec(const char *name)
50551
50552 fsnotify_open(file);
50553
50554+ trace_open_exec(name);
50555+
50556 err = deny_write_access(file);
50557 if (err)
50558 goto exit;
50559@@ -795,7 +870,7 @@ int kernel_read(struct file *file, loff_t offset,
50560 old_fs = get_fs();
50561 set_fs(get_ds());
50562 /* The cast to a user pointer is valid due to the set_fs() */
50563- result = vfs_read(file, (void __user *)addr, count, &pos);
50564+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
50565 set_fs(old_fs);
50566 return result;
50567 }
50568@@ -1250,7 +1325,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
50569 }
50570 rcu_read_unlock();
50571
50572- if (p->fs->users > n_fs) {
50573+ if (atomic_read(&p->fs->users) > n_fs) {
50574 bprm->unsafe |= LSM_UNSAFE_SHARE;
50575 } else {
50576 res = -EAGAIN;
50577@@ -1450,6 +1525,31 @@ int search_binary_handler(struct linux_binprm *bprm)
50578
50579 EXPORT_SYMBOL(search_binary_handler);
50580
50581+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50582+static DEFINE_PER_CPU(u64, exec_counter);
50583+static int __init init_exec_counters(void)
50584+{
50585+ unsigned int cpu;
50586+
50587+ for_each_possible_cpu(cpu) {
50588+ per_cpu(exec_counter, cpu) = (u64)cpu;
50589+ }
50590+
50591+ return 0;
50592+}
50593+early_initcall(init_exec_counters);
50594+static inline void increment_exec_counter(void)
50595+{
50596+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
50597+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
50598+}
50599+#else
50600+static inline void increment_exec_counter(void) {}
50601+#endif
50602+
50603+extern void gr_handle_exec_args(struct linux_binprm *bprm,
50604+ struct user_arg_ptr argv);
50605+
50606 /*
50607 * sys_execve() executes a new program.
50608 */
50609@@ -1457,6 +1557,11 @@ static int do_execve_common(const char *filename,
50610 struct user_arg_ptr argv,
50611 struct user_arg_ptr envp)
50612 {
50613+#ifdef CONFIG_GRKERNSEC
50614+ struct file *old_exec_file;
50615+ struct acl_subject_label *old_acl;
50616+ struct rlimit old_rlim[RLIM_NLIMITS];
50617+#endif
50618 struct linux_binprm *bprm;
50619 struct file *file;
50620 struct files_struct *displaced;
50621@@ -1464,6 +1569,8 @@ static int do_execve_common(const char *filename,
50622 int retval;
50623 const struct cred *cred = current_cred();
50624
50625+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&cred->user->processes), 1);
50626+
50627 /*
50628 * We move the actual failure in case of RLIMIT_NPROC excess from
50629 * set*uid() to execve() because too many poorly written programs
50630@@ -1504,12 +1611,27 @@ static int do_execve_common(const char *filename,
50631 if (IS_ERR(file))
50632 goto out_unmark;
50633
50634+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
50635+ retval = -EPERM;
50636+ goto out_file;
50637+ }
50638+
50639 sched_exec();
50640
50641 bprm->file = file;
50642 bprm->filename = filename;
50643 bprm->interp = filename;
50644
50645+ if (gr_process_user_ban()) {
50646+ retval = -EPERM;
50647+ goto out_file;
50648+ }
50649+
50650+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
50651+ retval = -EACCES;
50652+ goto out_file;
50653+ }
50654+
50655 retval = bprm_mm_init(bprm);
50656 if (retval)
50657 goto out_file;
50658@@ -1526,24 +1648,65 @@ static int do_execve_common(const char *filename,
50659 if (retval < 0)
50660 goto out;
50661
50662+#ifdef CONFIG_GRKERNSEC
50663+ old_acl = current->acl;
50664+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
50665+ old_exec_file = current->exec_file;
50666+ get_file(file);
50667+ current->exec_file = file;
50668+#endif
50669+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50670+ /* limit suid stack to 8MB
50671+ * we saved the old limits above and will restore them if this exec fails
50672+ */
50673+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
50674+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
50675+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
50676+#endif
50677+
50678+ if (!gr_tpe_allow(file)) {
50679+ retval = -EACCES;
50680+ goto out_fail;
50681+ }
50682+
50683+ if (gr_check_crash_exec(file)) {
50684+ retval = -EACCES;
50685+ goto out_fail;
50686+ }
50687+
50688+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
50689+ bprm->unsafe);
50690+ if (retval < 0)
50691+ goto out_fail;
50692+
50693 retval = copy_strings_kernel(1, &bprm->filename, bprm);
50694 if (retval < 0)
50695- goto out;
50696+ goto out_fail;
50697
50698 bprm->exec = bprm->p;
50699 retval = copy_strings(bprm->envc, envp, bprm);
50700 if (retval < 0)
50701- goto out;
50702+ goto out_fail;
50703
50704 retval = copy_strings(bprm->argc, argv, bprm);
50705 if (retval < 0)
50706- goto out;
50707+ goto out_fail;
50708+
50709+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
50710+
50711+ gr_handle_exec_args(bprm, argv);
50712
50713 retval = search_binary_handler(bprm);
50714 if (retval < 0)
50715- goto out;
50716+ goto out_fail;
50717+#ifdef CONFIG_GRKERNSEC
50718+ if (old_exec_file)
50719+ fput(old_exec_file);
50720+#endif
50721
50722 /* execve succeeded */
50723+
50724+ increment_exec_counter();
50725 current->fs->in_exec = 0;
50726 current->in_execve = 0;
50727 acct_update_integrals(current);
50728@@ -1552,6 +1715,14 @@ static int do_execve_common(const char *filename,
50729 put_files_struct(displaced);
50730 return retval;
50731
50732+out_fail:
50733+#ifdef CONFIG_GRKERNSEC
50734+ current->acl = old_acl;
50735+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
50736+ fput(current->exec_file);
50737+ current->exec_file = old_exec_file;
50738+#endif
50739+
50740 out:
50741 if (bprm->mm) {
50742 acct_arg_size(bprm, 0);
50743@@ -1700,3 +1871,283 @@ asmlinkage long compat_sys_execve(const char __user * filename,
50744 return error;
50745 }
50746 #endif
50747+
50748+int pax_check_flags(unsigned long *flags)
50749+{
50750+ int retval = 0;
50751+
50752+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
50753+ if (*flags & MF_PAX_SEGMEXEC)
50754+ {
50755+ *flags &= ~MF_PAX_SEGMEXEC;
50756+ retval = -EINVAL;
50757+ }
50758+#endif
50759+
50760+ if ((*flags & MF_PAX_PAGEEXEC)
50761+
50762+#ifdef CONFIG_PAX_PAGEEXEC
50763+ && (*flags & MF_PAX_SEGMEXEC)
50764+#endif
50765+
50766+ )
50767+ {
50768+ *flags &= ~MF_PAX_PAGEEXEC;
50769+ retval = -EINVAL;
50770+ }
50771+
50772+ if ((*flags & MF_PAX_MPROTECT)
50773+
50774+#ifdef CONFIG_PAX_MPROTECT
50775+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
50776+#endif
50777+
50778+ )
50779+ {
50780+ *flags &= ~MF_PAX_MPROTECT;
50781+ retval = -EINVAL;
50782+ }
50783+
50784+ if ((*flags & MF_PAX_EMUTRAMP)
50785+
50786+#ifdef CONFIG_PAX_EMUTRAMP
50787+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
50788+#endif
50789+
50790+ )
50791+ {
50792+ *flags &= ~MF_PAX_EMUTRAMP;
50793+ retval = -EINVAL;
50794+ }
50795+
50796+ return retval;
50797+}
50798+
50799+EXPORT_SYMBOL(pax_check_flags);
50800+
50801+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
50802+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
50803+{
50804+ struct task_struct *tsk = current;
50805+ struct mm_struct *mm = current->mm;
50806+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
50807+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
50808+ char *path_exec = NULL;
50809+ char *path_fault = NULL;
50810+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
50811+ siginfo_t info = { };
50812+
50813+ if (buffer_exec && buffer_fault) {
50814+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
50815+
50816+ down_read(&mm->mmap_sem);
50817+ vma = mm->mmap;
50818+ while (vma && (!vma_exec || !vma_fault)) {
50819+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
50820+ vma_exec = vma;
50821+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
50822+ vma_fault = vma;
50823+ vma = vma->vm_next;
50824+ }
50825+ if (vma_exec) {
50826+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
50827+ if (IS_ERR(path_exec))
50828+ path_exec = "<path too long>";
50829+ else {
50830+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
50831+ if (path_exec) {
50832+ *path_exec = 0;
50833+ path_exec = buffer_exec;
50834+ } else
50835+ path_exec = "<path too long>";
50836+ }
50837+ }
50838+ if (vma_fault) {
50839+ start = vma_fault->vm_start;
50840+ end = vma_fault->vm_end;
50841+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
50842+ if (vma_fault->vm_file) {
50843+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
50844+ if (IS_ERR(path_fault))
50845+ path_fault = "<path too long>";
50846+ else {
50847+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
50848+ if (path_fault) {
50849+ *path_fault = 0;
50850+ path_fault = buffer_fault;
50851+ } else
50852+ path_fault = "<path too long>";
50853+ }
50854+ } else
50855+ path_fault = "<anonymous mapping>";
50856+ }
50857+ up_read(&mm->mmap_sem);
50858+ }
50859+ if (tsk->signal->curr_ip)
50860+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
50861+ else
50862+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
50863+ 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),
50864+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
50865+ free_page((unsigned long)buffer_exec);
50866+ free_page((unsigned long)buffer_fault);
50867+ pax_report_insns(regs, pc, sp);
50868+ info.si_signo = SIGKILL;
50869+ info.si_errno = 0;
50870+ info.si_code = SI_KERNEL;
50871+ info.si_pid = 0;
50872+ info.si_uid = 0;
50873+ do_coredump(&info);
50874+}
50875+#endif
50876+
50877+#ifdef CONFIG_PAX_REFCOUNT
50878+void pax_report_refcount_overflow(struct pt_regs *regs)
50879+{
50880+ if (current->signal->curr_ip)
50881+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
50882+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
50883+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
50884+ else
50885+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
50886+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
50887+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
50888+ show_regs(regs);
50889+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
50890+}
50891+#endif
50892+
50893+#ifdef CONFIG_PAX_USERCOPY
50894+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
50895+static noinline int check_stack_object(const void *obj, unsigned long len)
50896+{
50897+ const void * const stack = task_stack_page(current);
50898+ const void * const stackend = stack + THREAD_SIZE;
50899+
50900+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
50901+ const void *frame = NULL;
50902+ const void *oldframe;
50903+#endif
50904+
50905+ if (obj + len < obj)
50906+ return -1;
50907+
50908+ if (obj + len <= stack || stackend <= obj)
50909+ return 0;
50910+
50911+ if (obj < stack || stackend < obj + len)
50912+ return -1;
50913+
50914+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
50915+ oldframe = __builtin_frame_address(1);
50916+ if (oldframe)
50917+ frame = __builtin_frame_address(2);
50918+ /*
50919+ low ----------------------------------------------> high
50920+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
50921+ ^----------------^
50922+ allow copies only within here
50923+ */
50924+ while (stack <= frame && frame < stackend) {
50925+ /* if obj + len extends past the last frame, this
50926+ check won't pass and the next frame will be 0,
50927+ causing us to bail out and correctly report
50928+ the copy as invalid
50929+ */
50930+ if (obj + len <= frame)
50931+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
50932+ oldframe = frame;
50933+ frame = *(const void * const *)frame;
50934+ }
50935+ return -1;
50936+#else
50937+ return 1;
50938+#endif
50939+}
50940+
50941+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
50942+{
50943+ if (current->signal->curr_ip)
50944+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
50945+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
50946+ else
50947+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
50948+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
50949+ dump_stack();
50950+ gr_handle_kernel_exploit();
50951+ do_group_exit(SIGKILL);
50952+}
50953+#endif
50954+
50955+#ifdef CONFIG_PAX_USERCOPY
50956+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
50957+{
50958+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
50959+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
50960+#ifdef CONFIG_MODULES
50961+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
50962+#else
50963+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
50964+#endif
50965+
50966+#else
50967+ unsigned long textlow = (unsigned long)_stext;
50968+ unsigned long texthigh = (unsigned long)_etext;
50969+#endif
50970+
50971+ if (high <= textlow || low > texthigh)
50972+ return false;
50973+ else
50974+ return true;
50975+}
50976+#endif
50977+
50978+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
50979+{
50980+
50981+#ifdef CONFIG_PAX_USERCOPY
50982+ const char *type;
50983+
50984+ if (!n)
50985+ return;
50986+
50987+ type = check_heap_object(ptr, n);
50988+ if (!type) {
50989+ int ret = check_stack_object(ptr, n);
50990+ if (ret == 1 || ret == 2)
50991+ return;
50992+ if (ret == 0) {
50993+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
50994+ type = "<kernel text>";
50995+ else
50996+ return;
50997+ } else
50998+ type = "<process stack>";
50999+ }
51000+
51001+ pax_report_usercopy(ptr, n, to_user, type);
51002+#endif
51003+
51004+}
51005+EXPORT_SYMBOL(__check_object_size);
51006+
51007+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
51008+void pax_track_stack(void)
51009+{
51010+ unsigned long sp = (unsigned long)&sp;
51011+ if (sp < current_thread_info()->lowest_stack &&
51012+ sp > (unsigned long)task_stack_page(current))
51013+ current_thread_info()->lowest_stack = sp;
51014+}
51015+EXPORT_SYMBOL(pax_track_stack);
51016+#endif
51017+
51018+#ifdef CONFIG_PAX_SIZE_OVERFLOW
51019+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
51020+{
51021+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
51022+ dump_stack();
51023+ do_group_exit(SIGKILL);
51024+}
51025+EXPORT_SYMBOL(report_size_overflow);
51026+#endif
51027diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
51028index 9f9992b..8b59411 100644
51029--- a/fs/ext2/balloc.c
51030+++ b/fs/ext2/balloc.c
51031@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
51032
51033 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
51034 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
51035- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
51036+ if (free_blocks < root_blocks + 1 &&
51037 !uid_eq(sbi->s_resuid, current_fsuid()) &&
51038 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
51039- !in_group_p (sbi->s_resgid))) {
51040+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
51041 return 0;
51042 }
51043 return 1;
51044diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
51045index 22548f5..41521d8 100644
51046--- a/fs/ext3/balloc.c
51047+++ b/fs/ext3/balloc.c
51048@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
51049
51050 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
51051 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
51052- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
51053+ if (free_blocks < root_blocks + 1 &&
51054 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
51055 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
51056- !in_group_p (sbi->s_resgid))) {
51057+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
51058 return 0;
51059 }
51060 return 1;
51061diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
51062index 92e68b3..115d987 100644
51063--- a/fs/ext4/balloc.c
51064+++ b/fs/ext4/balloc.c
51065@@ -505,8 +505,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
51066 /* Hm, nope. Are (enough) root reserved clusters available? */
51067 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
51068 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
51069- capable(CAP_SYS_RESOURCE) ||
51070- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
51071+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
51072+ capable_nolog(CAP_SYS_RESOURCE)) {
51073
51074 if (free_clusters >= (nclusters + dirty_clusters))
51075 return 1;
51076diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
51077index 3b83cd6..0f34dcd 100644
51078--- a/fs/ext4/ext4.h
51079+++ b/fs/ext4/ext4.h
51080@@ -1254,19 +1254,19 @@ struct ext4_sb_info {
51081 unsigned long s_mb_last_start;
51082
51083 /* stats for buddy allocator */
51084- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
51085- atomic_t s_bal_success; /* we found long enough chunks */
51086- atomic_t s_bal_allocated; /* in blocks */
51087- atomic_t s_bal_ex_scanned; /* total extents scanned */
51088- atomic_t s_bal_goals; /* goal hits */
51089- atomic_t s_bal_breaks; /* too long searches */
51090- atomic_t s_bal_2orders; /* 2^order hits */
51091+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
51092+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
51093+ atomic_unchecked_t s_bal_allocated; /* in blocks */
51094+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
51095+ atomic_unchecked_t s_bal_goals; /* goal hits */
51096+ atomic_unchecked_t s_bal_breaks; /* too long searches */
51097+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
51098 spinlock_t s_bal_lock;
51099 unsigned long s_mb_buddies_generated;
51100 unsigned long long s_mb_generation_time;
51101- atomic_t s_mb_lost_chunks;
51102- atomic_t s_mb_preallocated;
51103- atomic_t s_mb_discarded;
51104+ atomic_unchecked_t s_mb_lost_chunks;
51105+ atomic_unchecked_t s_mb_preallocated;
51106+ atomic_unchecked_t s_mb_discarded;
51107 atomic_t s_lock_busy;
51108
51109 /* locality groups */
51110diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
51111index f3190ab..84ffb21 100644
51112--- a/fs/ext4/mballoc.c
51113+++ b/fs/ext4/mballoc.c
51114@@ -1754,7 +1754,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
51115 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
51116
51117 if (EXT4_SB(sb)->s_mb_stats)
51118- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
51119+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
51120
51121 break;
51122 }
51123@@ -2059,7 +2059,7 @@ repeat:
51124 ac->ac_status = AC_STATUS_CONTINUE;
51125 ac->ac_flags |= EXT4_MB_HINT_FIRST;
51126 cr = 3;
51127- atomic_inc(&sbi->s_mb_lost_chunks);
51128+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
51129 goto repeat;
51130 }
51131 }
51132@@ -2567,25 +2567,25 @@ int ext4_mb_release(struct super_block *sb)
51133 if (sbi->s_mb_stats) {
51134 ext4_msg(sb, KERN_INFO,
51135 "mballoc: %u blocks %u reqs (%u success)",
51136- atomic_read(&sbi->s_bal_allocated),
51137- atomic_read(&sbi->s_bal_reqs),
51138- atomic_read(&sbi->s_bal_success));
51139+ atomic_read_unchecked(&sbi->s_bal_allocated),
51140+ atomic_read_unchecked(&sbi->s_bal_reqs),
51141+ atomic_read_unchecked(&sbi->s_bal_success));
51142 ext4_msg(sb, KERN_INFO,
51143 "mballoc: %u extents scanned, %u goal hits, "
51144 "%u 2^N hits, %u breaks, %u lost",
51145- atomic_read(&sbi->s_bal_ex_scanned),
51146- atomic_read(&sbi->s_bal_goals),
51147- atomic_read(&sbi->s_bal_2orders),
51148- atomic_read(&sbi->s_bal_breaks),
51149- atomic_read(&sbi->s_mb_lost_chunks));
51150+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
51151+ atomic_read_unchecked(&sbi->s_bal_goals),
51152+ atomic_read_unchecked(&sbi->s_bal_2orders),
51153+ atomic_read_unchecked(&sbi->s_bal_breaks),
51154+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
51155 ext4_msg(sb, KERN_INFO,
51156 "mballoc: %lu generated and it took %Lu",
51157 sbi->s_mb_buddies_generated,
51158 sbi->s_mb_generation_time);
51159 ext4_msg(sb, KERN_INFO,
51160 "mballoc: %u preallocated, %u discarded",
51161- atomic_read(&sbi->s_mb_preallocated),
51162- atomic_read(&sbi->s_mb_discarded));
51163+ atomic_read_unchecked(&sbi->s_mb_preallocated),
51164+ atomic_read_unchecked(&sbi->s_mb_discarded));
51165 }
51166
51167 free_percpu(sbi->s_locality_groups);
51168@@ -3039,16 +3039,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
51169 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
51170
51171 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
51172- atomic_inc(&sbi->s_bal_reqs);
51173- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
51174+ atomic_inc_unchecked(&sbi->s_bal_reqs);
51175+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
51176 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
51177- atomic_inc(&sbi->s_bal_success);
51178- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
51179+ atomic_inc_unchecked(&sbi->s_bal_success);
51180+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
51181 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
51182 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
51183- atomic_inc(&sbi->s_bal_goals);
51184+ atomic_inc_unchecked(&sbi->s_bal_goals);
51185 if (ac->ac_found > sbi->s_mb_max_to_scan)
51186- atomic_inc(&sbi->s_bal_breaks);
51187+ atomic_inc_unchecked(&sbi->s_bal_breaks);
51188 }
51189
51190 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
51191@@ -3448,7 +3448,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
51192 trace_ext4_mb_new_inode_pa(ac, pa);
51193
51194 ext4_mb_use_inode_pa(ac, pa);
51195- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
51196+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
51197
51198 ei = EXT4_I(ac->ac_inode);
51199 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51200@@ -3508,7 +3508,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
51201 trace_ext4_mb_new_group_pa(ac, pa);
51202
51203 ext4_mb_use_group_pa(ac, pa);
51204- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51205+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51206
51207 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51208 lg = ac->ac_lg;
51209@@ -3597,7 +3597,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
51210 * from the bitmap and continue.
51211 */
51212 }
51213- atomic_add(free, &sbi->s_mb_discarded);
51214+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
51215
51216 return err;
51217 }
51218@@ -3615,7 +3615,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
51219 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
51220 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
51221 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
51222- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51223+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51224 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
51225
51226 return 0;
51227diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
51228index 3beae6a..8cc5637 100644
51229--- a/fs/ext4/resize.c
51230+++ b/fs/ext4/resize.c
51231@@ -79,12 +79,20 @@ static int verify_group_input(struct super_block *sb,
51232 ext4_fsblk_t end = start + input->blocks_count;
51233 ext4_group_t group = input->group;
51234 ext4_fsblk_t itend = input->inode_table + sbi->s_itb_per_group;
51235- unsigned overhead = ext4_group_overhead_blocks(sb, group);
51236- ext4_fsblk_t metaend = start + overhead;
51237+ unsigned overhead;
51238+ ext4_fsblk_t metaend;
51239 struct buffer_head *bh = NULL;
51240 ext4_grpblk_t free_blocks_count, offset;
51241 int err = -EINVAL;
51242
51243+ if (group != sbi->s_groups_count) {
51244+ ext4_warning(sb, "Cannot add at group %u (only %u groups)",
51245+ input->group, sbi->s_groups_count);
51246+ return -EINVAL;
51247+ }
51248+
51249+ overhead = ext4_group_overhead_blocks(sb, group);
51250+ metaend = start + overhead;
51251 input->free_blocks_count = free_blocks_count =
51252 input->blocks_count - 2 - overhead - sbi->s_itb_per_group;
51253
51254@@ -96,10 +104,7 @@ static int verify_group_input(struct super_block *sb,
51255 free_blocks_count, input->reserved_blocks);
51256
51257 ext4_get_group_no_and_offset(sb, start, NULL, &offset);
51258- if (group != sbi->s_groups_count)
51259- ext4_warning(sb, "Cannot add at group %u (only %u groups)",
51260- input->group, sbi->s_groups_count);
51261- else if (offset != 0)
51262+ if (offset != 0)
51263 ext4_warning(sb, "Last group not full");
51264 else if (input->reserved_blocks > input->blocks_count / 5)
51265 ext4_warning(sb, "Reserved blocks too high (%u)",
51266diff --git a/fs/ext4/super.c b/fs/ext4/super.c
51267index febbe0e..782c4fd 100644
51268--- a/fs/ext4/super.c
51269+++ b/fs/ext4/super.c
51270@@ -2380,7 +2380,7 @@ struct ext4_attr {
51271 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
51272 const char *, size_t);
51273 int offset;
51274-};
51275+} __do_const;
51276
51277 static int parse_strtoul(const char *buf,
51278 unsigned long max, unsigned long *value)
51279diff --git a/fs/fcntl.c b/fs/fcntl.c
51280index 6599222..e7bf0de 100644
51281--- a/fs/fcntl.c
51282+++ b/fs/fcntl.c
51283@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
51284 if (err)
51285 return err;
51286
51287+ if (gr_handle_chroot_fowner(pid, type))
51288+ return -ENOENT;
51289+ if (gr_check_protected_task_fowner(pid, type))
51290+ return -EACCES;
51291+
51292 f_modown(filp, pid, type, force);
51293 return 0;
51294 }
51295diff --git a/fs/fhandle.c b/fs/fhandle.c
51296index 999ff5c..41f4109 100644
51297--- a/fs/fhandle.c
51298+++ b/fs/fhandle.c
51299@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
51300 } else
51301 retval = 0;
51302 /* copy the mount id */
51303- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
51304- sizeof(*mnt_id)) ||
51305+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
51306 copy_to_user(ufh, handle,
51307 sizeof(struct file_handle) + handle_bytes))
51308 retval = -EFAULT;
51309diff --git a/fs/fifo.c b/fs/fifo.c
51310index cf6f434..3d7942c 100644
51311--- a/fs/fifo.c
51312+++ b/fs/fifo.c
51313@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
51314 */
51315 filp->f_op = &read_pipefifo_fops;
51316 pipe->r_counter++;
51317- if (pipe->readers++ == 0)
51318+ if (atomic_inc_return(&pipe->readers) == 1)
51319 wake_up_partner(inode);
51320
51321- if (!pipe->writers) {
51322+ if (!atomic_read(&pipe->writers)) {
51323 if ((filp->f_flags & O_NONBLOCK)) {
51324 /* suppress POLLHUP until we have
51325 * seen a writer */
51326@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
51327 * errno=ENXIO when there is no process reading the FIFO.
51328 */
51329 ret = -ENXIO;
51330- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
51331+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
51332 goto err;
51333
51334 filp->f_op = &write_pipefifo_fops;
51335 pipe->w_counter++;
51336- if (!pipe->writers++)
51337+ if (atomic_inc_return(&pipe->writers) == 1)
51338 wake_up_partner(inode);
51339
51340- if (!pipe->readers) {
51341+ if (!atomic_read(&pipe->readers)) {
51342 if (wait_for_partner(inode, &pipe->r_counter))
51343 goto err_wr;
51344 }
51345@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
51346 */
51347 filp->f_op = &rdwr_pipefifo_fops;
51348
51349- pipe->readers++;
51350- pipe->writers++;
51351+ atomic_inc(&pipe->readers);
51352+ atomic_inc(&pipe->writers);
51353 pipe->r_counter++;
51354 pipe->w_counter++;
51355- if (pipe->readers == 1 || pipe->writers == 1)
51356+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
51357 wake_up_partner(inode);
51358 break;
51359
51360@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
51361 return 0;
51362
51363 err_rd:
51364- if (!--pipe->readers)
51365+ if (atomic_dec_and_test(&pipe->readers))
51366 wake_up_interruptible(&pipe->wait);
51367 ret = -ERESTARTSYS;
51368 goto err;
51369
51370 err_wr:
51371- if (!--pipe->writers)
51372+ if (atomic_dec_and_test(&pipe->writers))
51373 wake_up_interruptible(&pipe->wait);
51374 ret = -ERESTARTSYS;
51375 goto err;
51376
51377 err:
51378- if (!pipe->readers && !pipe->writers)
51379+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
51380 free_pipe_info(inode);
51381
51382 err_nocleanup:
51383diff --git a/fs/file.c b/fs/file.c
51384index 3906d95..5fe379b 100644
51385--- a/fs/file.c
51386+++ b/fs/file.c
51387@@ -16,6 +16,7 @@
51388 #include <linux/slab.h>
51389 #include <linux/vmalloc.h>
51390 #include <linux/file.h>
51391+#include <linux/security.h>
51392 #include <linux/fdtable.h>
51393 #include <linux/bitops.h>
51394 #include <linux/interrupt.h>
51395@@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
51396 if (!file)
51397 return __close_fd(files, fd);
51398
51399+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
51400 if (fd >= rlimit(RLIMIT_NOFILE))
51401 return -EBADF;
51402
51403@@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
51404 if (unlikely(oldfd == newfd))
51405 return -EINVAL;
51406
51407+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
51408 if (newfd >= rlimit(RLIMIT_NOFILE))
51409 return -EBADF;
51410
51411@@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
51412 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
51413 {
51414 int err;
51415+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
51416 if (from >= rlimit(RLIMIT_NOFILE))
51417 return -EINVAL;
51418 err = alloc_fd(from, flags);
51419diff --git a/fs/filesystems.c b/fs/filesystems.c
51420index 92567d9..fcd8cbf 100644
51421--- a/fs/filesystems.c
51422+++ b/fs/filesystems.c
51423@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
51424 int len = dot ? dot - name : strlen(name);
51425
51426 fs = __get_fs_type(name, len);
51427+#ifdef CONFIG_GRKERNSEC_MODHARDEN
51428+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
51429+#else
51430 if (!fs && (request_module("fs-%.*s", len, name) == 0))
51431+#endif
51432 fs = __get_fs_type(name, len);
51433
51434 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
51435diff --git a/fs/fs_struct.c b/fs/fs_struct.c
51436index d8ac61d..79a36f0 100644
51437--- a/fs/fs_struct.c
51438+++ b/fs/fs_struct.c
51439@@ -4,6 +4,7 @@
51440 #include <linux/path.h>
51441 #include <linux/slab.h>
51442 #include <linux/fs_struct.h>
51443+#include <linux/grsecurity.h>
51444 #include "internal.h"
51445
51446 /*
51447@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
51448 write_seqcount_begin(&fs->seq);
51449 old_root = fs->root;
51450 fs->root = *path;
51451+ gr_set_chroot_entries(current, path);
51452 write_seqcount_end(&fs->seq);
51453 spin_unlock(&fs->lock);
51454 if (old_root.dentry)
51455@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
51456 int hits = 0;
51457 spin_lock(&fs->lock);
51458 write_seqcount_begin(&fs->seq);
51459+ /* this root replacement is only done by pivot_root,
51460+ leave grsec's chroot tagging alone for this task
51461+ so that a pivoted root isn't treated as a chroot
51462+ */
51463 hits += replace_path(&fs->root, old_root, new_root);
51464 hits += replace_path(&fs->pwd, old_root, new_root);
51465 write_seqcount_end(&fs->seq);
51466@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
51467 task_lock(tsk);
51468 spin_lock(&fs->lock);
51469 tsk->fs = NULL;
51470- kill = !--fs->users;
51471+ gr_clear_chroot_entries(tsk);
51472+ kill = !atomic_dec_return(&fs->users);
51473 spin_unlock(&fs->lock);
51474 task_unlock(tsk);
51475 if (kill)
51476@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51477 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
51478 /* We don't need to lock fs - think why ;-) */
51479 if (fs) {
51480- fs->users = 1;
51481+ atomic_set(&fs->users, 1);
51482 fs->in_exec = 0;
51483 spin_lock_init(&fs->lock);
51484 seqcount_init(&fs->seq);
51485@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51486 spin_lock(&old->lock);
51487 fs->root = old->root;
51488 path_get(&fs->root);
51489+ /* instead of calling gr_set_chroot_entries here,
51490+ we call it from every caller of this function
51491+ */
51492 fs->pwd = old->pwd;
51493 path_get(&fs->pwd);
51494 spin_unlock(&old->lock);
51495@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
51496
51497 task_lock(current);
51498 spin_lock(&fs->lock);
51499- kill = !--fs->users;
51500+ kill = !atomic_dec_return(&fs->users);
51501 current->fs = new_fs;
51502+ gr_set_chroot_entries(current, &new_fs->root);
51503 spin_unlock(&fs->lock);
51504 task_unlock(current);
51505
51506@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
51507
51508 int current_umask(void)
51509 {
51510- return current->fs->umask;
51511+ return current->fs->umask | gr_acl_umask();
51512 }
51513 EXPORT_SYMBOL(current_umask);
51514
51515 /* to be mentioned only in INIT_TASK */
51516 struct fs_struct init_fs = {
51517- .users = 1,
51518+ .users = ATOMIC_INIT(1),
51519 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
51520 .seq = SEQCNT_ZERO,
51521 .umask = 0022,
51522diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
51523index e2cba1f..17a25bb 100644
51524--- a/fs/fscache/cookie.c
51525+++ b/fs/fscache/cookie.c
51526@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
51527 parent ? (char *) parent->def->name : "<no-parent>",
51528 def->name, netfs_data);
51529
51530- fscache_stat(&fscache_n_acquires);
51531+ fscache_stat_unchecked(&fscache_n_acquires);
51532
51533 /* if there's no parent cookie, then we don't create one here either */
51534 if (!parent) {
51535- fscache_stat(&fscache_n_acquires_null);
51536+ fscache_stat_unchecked(&fscache_n_acquires_null);
51537 _leave(" [no parent]");
51538 return NULL;
51539 }
51540@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
51541 /* allocate and initialise a cookie */
51542 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
51543 if (!cookie) {
51544- fscache_stat(&fscache_n_acquires_oom);
51545+ fscache_stat_unchecked(&fscache_n_acquires_oom);
51546 _leave(" [ENOMEM]");
51547 return NULL;
51548 }
51549@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
51550
51551 switch (cookie->def->type) {
51552 case FSCACHE_COOKIE_TYPE_INDEX:
51553- fscache_stat(&fscache_n_cookie_index);
51554+ fscache_stat_unchecked(&fscache_n_cookie_index);
51555 break;
51556 case FSCACHE_COOKIE_TYPE_DATAFILE:
51557- fscache_stat(&fscache_n_cookie_data);
51558+ fscache_stat_unchecked(&fscache_n_cookie_data);
51559 break;
51560 default:
51561- fscache_stat(&fscache_n_cookie_special);
51562+ fscache_stat_unchecked(&fscache_n_cookie_special);
51563 break;
51564 }
51565
51566@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
51567 if (fscache_acquire_non_index_cookie(cookie) < 0) {
51568 atomic_dec(&parent->n_children);
51569 __fscache_cookie_put(cookie);
51570- fscache_stat(&fscache_n_acquires_nobufs);
51571+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
51572 _leave(" = NULL");
51573 return NULL;
51574 }
51575 }
51576
51577- fscache_stat(&fscache_n_acquires_ok);
51578+ fscache_stat_unchecked(&fscache_n_acquires_ok);
51579 _leave(" = %p", cookie);
51580 return cookie;
51581 }
51582@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
51583 cache = fscache_select_cache_for_object(cookie->parent);
51584 if (!cache) {
51585 up_read(&fscache_addremove_sem);
51586- fscache_stat(&fscache_n_acquires_no_cache);
51587+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
51588 _leave(" = -ENOMEDIUM [no cache]");
51589 return -ENOMEDIUM;
51590 }
51591@@ -255,12 +255,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
51592 object = cache->ops->alloc_object(cache, cookie);
51593 fscache_stat_d(&fscache_n_cop_alloc_object);
51594 if (IS_ERR(object)) {
51595- fscache_stat(&fscache_n_object_no_alloc);
51596+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
51597 ret = PTR_ERR(object);
51598 goto error;
51599 }
51600
51601- fscache_stat(&fscache_n_object_alloc);
51602+ fscache_stat_unchecked(&fscache_n_object_alloc);
51603
51604 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
51605
51606@@ -376,7 +376,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
51607
51608 _enter("{%s}", cookie->def->name);
51609
51610- fscache_stat(&fscache_n_invalidates);
51611+ fscache_stat_unchecked(&fscache_n_invalidates);
51612
51613 /* Only permit invalidation of data files. Invalidating an index will
51614 * require the caller to release all its attachments to the tree rooted
51615@@ -434,10 +434,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
51616 {
51617 struct fscache_object *object;
51618
51619- fscache_stat(&fscache_n_updates);
51620+ fscache_stat_unchecked(&fscache_n_updates);
51621
51622 if (!cookie) {
51623- fscache_stat(&fscache_n_updates_null);
51624+ fscache_stat_unchecked(&fscache_n_updates_null);
51625 _leave(" [no cookie]");
51626 return;
51627 }
51628@@ -471,12 +471,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
51629 struct fscache_object *object;
51630 unsigned long event;
51631
51632- fscache_stat(&fscache_n_relinquishes);
51633+ fscache_stat_unchecked(&fscache_n_relinquishes);
51634 if (retire)
51635- fscache_stat(&fscache_n_relinquishes_retire);
51636+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
51637
51638 if (!cookie) {
51639- fscache_stat(&fscache_n_relinquishes_null);
51640+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
51641 _leave(" [no cookie]");
51642 return;
51643 }
51644@@ -492,7 +492,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
51645
51646 /* wait for the cookie to finish being instantiated (or to fail) */
51647 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
51648- fscache_stat(&fscache_n_relinquishes_waitcrt);
51649+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
51650 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
51651 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
51652 }
51653diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
51654index ee38fef..0a326d4 100644
51655--- a/fs/fscache/internal.h
51656+++ b/fs/fscache/internal.h
51657@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
51658 * stats.c
51659 */
51660 #ifdef CONFIG_FSCACHE_STATS
51661-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
51662-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
51663+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
51664+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
51665
51666-extern atomic_t fscache_n_op_pend;
51667-extern atomic_t fscache_n_op_run;
51668-extern atomic_t fscache_n_op_enqueue;
51669-extern atomic_t fscache_n_op_deferred_release;
51670-extern atomic_t fscache_n_op_release;
51671-extern atomic_t fscache_n_op_gc;
51672-extern atomic_t fscache_n_op_cancelled;
51673-extern atomic_t fscache_n_op_rejected;
51674+extern atomic_unchecked_t fscache_n_op_pend;
51675+extern atomic_unchecked_t fscache_n_op_run;
51676+extern atomic_unchecked_t fscache_n_op_enqueue;
51677+extern atomic_unchecked_t fscache_n_op_deferred_release;
51678+extern atomic_unchecked_t fscache_n_op_release;
51679+extern atomic_unchecked_t fscache_n_op_gc;
51680+extern atomic_unchecked_t fscache_n_op_cancelled;
51681+extern atomic_unchecked_t fscache_n_op_rejected;
51682
51683-extern atomic_t fscache_n_attr_changed;
51684-extern atomic_t fscache_n_attr_changed_ok;
51685-extern atomic_t fscache_n_attr_changed_nobufs;
51686-extern atomic_t fscache_n_attr_changed_nomem;
51687-extern atomic_t fscache_n_attr_changed_calls;
51688+extern atomic_unchecked_t fscache_n_attr_changed;
51689+extern atomic_unchecked_t fscache_n_attr_changed_ok;
51690+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
51691+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
51692+extern atomic_unchecked_t fscache_n_attr_changed_calls;
51693
51694-extern atomic_t fscache_n_allocs;
51695-extern atomic_t fscache_n_allocs_ok;
51696-extern atomic_t fscache_n_allocs_wait;
51697-extern atomic_t fscache_n_allocs_nobufs;
51698-extern atomic_t fscache_n_allocs_intr;
51699-extern atomic_t fscache_n_allocs_object_dead;
51700-extern atomic_t fscache_n_alloc_ops;
51701-extern atomic_t fscache_n_alloc_op_waits;
51702+extern atomic_unchecked_t fscache_n_allocs;
51703+extern atomic_unchecked_t fscache_n_allocs_ok;
51704+extern atomic_unchecked_t fscache_n_allocs_wait;
51705+extern atomic_unchecked_t fscache_n_allocs_nobufs;
51706+extern atomic_unchecked_t fscache_n_allocs_intr;
51707+extern atomic_unchecked_t fscache_n_allocs_object_dead;
51708+extern atomic_unchecked_t fscache_n_alloc_ops;
51709+extern atomic_unchecked_t fscache_n_alloc_op_waits;
51710
51711-extern atomic_t fscache_n_retrievals;
51712-extern atomic_t fscache_n_retrievals_ok;
51713-extern atomic_t fscache_n_retrievals_wait;
51714-extern atomic_t fscache_n_retrievals_nodata;
51715-extern atomic_t fscache_n_retrievals_nobufs;
51716-extern atomic_t fscache_n_retrievals_intr;
51717-extern atomic_t fscache_n_retrievals_nomem;
51718-extern atomic_t fscache_n_retrievals_object_dead;
51719-extern atomic_t fscache_n_retrieval_ops;
51720-extern atomic_t fscache_n_retrieval_op_waits;
51721+extern atomic_unchecked_t fscache_n_retrievals;
51722+extern atomic_unchecked_t fscache_n_retrievals_ok;
51723+extern atomic_unchecked_t fscache_n_retrievals_wait;
51724+extern atomic_unchecked_t fscache_n_retrievals_nodata;
51725+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
51726+extern atomic_unchecked_t fscache_n_retrievals_intr;
51727+extern atomic_unchecked_t fscache_n_retrievals_nomem;
51728+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
51729+extern atomic_unchecked_t fscache_n_retrieval_ops;
51730+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
51731
51732-extern atomic_t fscache_n_stores;
51733-extern atomic_t fscache_n_stores_ok;
51734-extern atomic_t fscache_n_stores_again;
51735-extern atomic_t fscache_n_stores_nobufs;
51736-extern atomic_t fscache_n_stores_oom;
51737-extern atomic_t fscache_n_store_ops;
51738-extern atomic_t fscache_n_store_calls;
51739-extern atomic_t fscache_n_store_pages;
51740-extern atomic_t fscache_n_store_radix_deletes;
51741-extern atomic_t fscache_n_store_pages_over_limit;
51742+extern atomic_unchecked_t fscache_n_stores;
51743+extern atomic_unchecked_t fscache_n_stores_ok;
51744+extern atomic_unchecked_t fscache_n_stores_again;
51745+extern atomic_unchecked_t fscache_n_stores_nobufs;
51746+extern atomic_unchecked_t fscache_n_stores_oom;
51747+extern atomic_unchecked_t fscache_n_store_ops;
51748+extern atomic_unchecked_t fscache_n_store_calls;
51749+extern atomic_unchecked_t fscache_n_store_pages;
51750+extern atomic_unchecked_t fscache_n_store_radix_deletes;
51751+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
51752
51753-extern atomic_t fscache_n_store_vmscan_not_storing;
51754-extern atomic_t fscache_n_store_vmscan_gone;
51755-extern atomic_t fscache_n_store_vmscan_busy;
51756-extern atomic_t fscache_n_store_vmscan_cancelled;
51757-extern atomic_t fscache_n_store_vmscan_wait;
51758+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
51759+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
51760+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
51761+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
51762+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
51763
51764-extern atomic_t fscache_n_marks;
51765-extern atomic_t fscache_n_uncaches;
51766+extern atomic_unchecked_t fscache_n_marks;
51767+extern atomic_unchecked_t fscache_n_uncaches;
51768
51769-extern atomic_t fscache_n_acquires;
51770-extern atomic_t fscache_n_acquires_null;
51771-extern atomic_t fscache_n_acquires_no_cache;
51772-extern atomic_t fscache_n_acquires_ok;
51773-extern atomic_t fscache_n_acquires_nobufs;
51774-extern atomic_t fscache_n_acquires_oom;
51775+extern atomic_unchecked_t fscache_n_acquires;
51776+extern atomic_unchecked_t fscache_n_acquires_null;
51777+extern atomic_unchecked_t fscache_n_acquires_no_cache;
51778+extern atomic_unchecked_t fscache_n_acquires_ok;
51779+extern atomic_unchecked_t fscache_n_acquires_nobufs;
51780+extern atomic_unchecked_t fscache_n_acquires_oom;
51781
51782-extern atomic_t fscache_n_invalidates;
51783-extern atomic_t fscache_n_invalidates_run;
51784+extern atomic_unchecked_t fscache_n_invalidates;
51785+extern atomic_unchecked_t fscache_n_invalidates_run;
51786
51787-extern atomic_t fscache_n_updates;
51788-extern atomic_t fscache_n_updates_null;
51789-extern atomic_t fscache_n_updates_run;
51790+extern atomic_unchecked_t fscache_n_updates;
51791+extern atomic_unchecked_t fscache_n_updates_null;
51792+extern atomic_unchecked_t fscache_n_updates_run;
51793
51794-extern atomic_t fscache_n_relinquishes;
51795-extern atomic_t fscache_n_relinquishes_null;
51796-extern atomic_t fscache_n_relinquishes_waitcrt;
51797-extern atomic_t fscache_n_relinquishes_retire;
51798+extern atomic_unchecked_t fscache_n_relinquishes;
51799+extern atomic_unchecked_t fscache_n_relinquishes_null;
51800+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
51801+extern atomic_unchecked_t fscache_n_relinquishes_retire;
51802
51803-extern atomic_t fscache_n_cookie_index;
51804-extern atomic_t fscache_n_cookie_data;
51805-extern atomic_t fscache_n_cookie_special;
51806+extern atomic_unchecked_t fscache_n_cookie_index;
51807+extern atomic_unchecked_t fscache_n_cookie_data;
51808+extern atomic_unchecked_t fscache_n_cookie_special;
51809
51810-extern atomic_t fscache_n_object_alloc;
51811-extern atomic_t fscache_n_object_no_alloc;
51812-extern atomic_t fscache_n_object_lookups;
51813-extern atomic_t fscache_n_object_lookups_negative;
51814-extern atomic_t fscache_n_object_lookups_positive;
51815-extern atomic_t fscache_n_object_lookups_timed_out;
51816-extern atomic_t fscache_n_object_created;
51817-extern atomic_t fscache_n_object_avail;
51818-extern atomic_t fscache_n_object_dead;
51819+extern atomic_unchecked_t fscache_n_object_alloc;
51820+extern atomic_unchecked_t fscache_n_object_no_alloc;
51821+extern atomic_unchecked_t fscache_n_object_lookups;
51822+extern atomic_unchecked_t fscache_n_object_lookups_negative;
51823+extern atomic_unchecked_t fscache_n_object_lookups_positive;
51824+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
51825+extern atomic_unchecked_t fscache_n_object_created;
51826+extern atomic_unchecked_t fscache_n_object_avail;
51827+extern atomic_unchecked_t fscache_n_object_dead;
51828
51829-extern atomic_t fscache_n_checkaux_none;
51830-extern atomic_t fscache_n_checkaux_okay;
51831-extern atomic_t fscache_n_checkaux_update;
51832-extern atomic_t fscache_n_checkaux_obsolete;
51833+extern atomic_unchecked_t fscache_n_checkaux_none;
51834+extern atomic_unchecked_t fscache_n_checkaux_okay;
51835+extern atomic_unchecked_t fscache_n_checkaux_update;
51836+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
51837
51838 extern atomic_t fscache_n_cop_alloc_object;
51839 extern atomic_t fscache_n_cop_lookup_object;
51840@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
51841 atomic_inc(stat);
51842 }
51843
51844+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
51845+{
51846+ atomic_inc_unchecked(stat);
51847+}
51848+
51849 static inline void fscache_stat_d(atomic_t *stat)
51850 {
51851 atomic_dec(stat);
51852@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
51853
51854 #define __fscache_stat(stat) (NULL)
51855 #define fscache_stat(stat) do {} while (0)
51856+#define fscache_stat_unchecked(stat) do {} while (0)
51857 #define fscache_stat_d(stat) do {} while (0)
51858 #endif
51859
51860diff --git a/fs/fscache/object.c b/fs/fscache/object.c
51861index 50d41c1..10ee117 100644
51862--- a/fs/fscache/object.c
51863+++ b/fs/fscache/object.c
51864@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51865 /* Invalidate an object on disk */
51866 case FSCACHE_OBJECT_INVALIDATING:
51867 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
51868- fscache_stat(&fscache_n_invalidates_run);
51869+ fscache_stat_unchecked(&fscache_n_invalidates_run);
51870 fscache_stat(&fscache_n_cop_invalidate_object);
51871 fscache_invalidate_object(object);
51872 fscache_stat_d(&fscache_n_cop_invalidate_object);
51873@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51874 /* update the object metadata on disk */
51875 case FSCACHE_OBJECT_UPDATING:
51876 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
51877- fscache_stat(&fscache_n_updates_run);
51878+ fscache_stat_unchecked(&fscache_n_updates_run);
51879 fscache_stat(&fscache_n_cop_update_object);
51880 object->cache->ops->update_object(object);
51881 fscache_stat_d(&fscache_n_cop_update_object);
51882@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51883 spin_lock(&object->lock);
51884 object->state = FSCACHE_OBJECT_DEAD;
51885 spin_unlock(&object->lock);
51886- fscache_stat(&fscache_n_object_dead);
51887+ fscache_stat_unchecked(&fscache_n_object_dead);
51888 goto terminal_transit;
51889
51890 /* handle the parent cache of this object being withdrawn from
51891@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51892 spin_lock(&object->lock);
51893 object->state = FSCACHE_OBJECT_DEAD;
51894 spin_unlock(&object->lock);
51895- fscache_stat(&fscache_n_object_dead);
51896+ fscache_stat_unchecked(&fscache_n_object_dead);
51897 goto terminal_transit;
51898
51899 /* complain about the object being woken up once it is
51900@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
51901 parent->cookie->def->name, cookie->def->name,
51902 object->cache->tag->name);
51903
51904- fscache_stat(&fscache_n_object_lookups);
51905+ fscache_stat_unchecked(&fscache_n_object_lookups);
51906 fscache_stat(&fscache_n_cop_lookup_object);
51907 ret = object->cache->ops->lookup_object(object);
51908 fscache_stat_d(&fscache_n_cop_lookup_object);
51909@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
51910 if (ret == -ETIMEDOUT) {
51911 /* probably stuck behind another object, so move this one to
51912 * the back of the queue */
51913- fscache_stat(&fscache_n_object_lookups_timed_out);
51914+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
51915 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
51916 }
51917
51918@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
51919
51920 spin_lock(&object->lock);
51921 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
51922- fscache_stat(&fscache_n_object_lookups_negative);
51923+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
51924
51925 /* transit here to allow write requests to begin stacking up
51926 * and read requests to begin returning ENODATA */
51927@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
51928 * result, in which case there may be data available */
51929 spin_lock(&object->lock);
51930 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
51931- fscache_stat(&fscache_n_object_lookups_positive);
51932+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
51933
51934 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
51935
51936@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
51937 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
51938 } else {
51939 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
51940- fscache_stat(&fscache_n_object_created);
51941+ fscache_stat_unchecked(&fscache_n_object_created);
51942
51943 object->state = FSCACHE_OBJECT_AVAILABLE;
51944 spin_unlock(&object->lock);
51945@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
51946 fscache_enqueue_dependents(object);
51947
51948 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
51949- fscache_stat(&fscache_n_object_avail);
51950+ fscache_stat_unchecked(&fscache_n_object_avail);
51951
51952 _leave("");
51953 }
51954@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
51955 enum fscache_checkaux result;
51956
51957 if (!object->cookie->def->check_aux) {
51958- fscache_stat(&fscache_n_checkaux_none);
51959+ fscache_stat_unchecked(&fscache_n_checkaux_none);
51960 return FSCACHE_CHECKAUX_OKAY;
51961 }
51962
51963@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
51964 switch (result) {
51965 /* entry okay as is */
51966 case FSCACHE_CHECKAUX_OKAY:
51967- fscache_stat(&fscache_n_checkaux_okay);
51968+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
51969 break;
51970
51971 /* entry requires update */
51972 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
51973- fscache_stat(&fscache_n_checkaux_update);
51974+ fscache_stat_unchecked(&fscache_n_checkaux_update);
51975 break;
51976
51977 /* entry requires deletion */
51978 case FSCACHE_CHECKAUX_OBSOLETE:
51979- fscache_stat(&fscache_n_checkaux_obsolete);
51980+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
51981 break;
51982
51983 default:
51984diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
51985index 762a9ec..2023284 100644
51986--- a/fs/fscache/operation.c
51987+++ b/fs/fscache/operation.c
51988@@ -17,7 +17,7 @@
51989 #include <linux/slab.h>
51990 #include "internal.h"
51991
51992-atomic_t fscache_op_debug_id;
51993+atomic_unchecked_t fscache_op_debug_id;
51994 EXPORT_SYMBOL(fscache_op_debug_id);
51995
51996 /**
51997@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
51998 ASSERTCMP(atomic_read(&op->usage), >, 0);
51999 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
52000
52001- fscache_stat(&fscache_n_op_enqueue);
52002+ fscache_stat_unchecked(&fscache_n_op_enqueue);
52003 switch (op->flags & FSCACHE_OP_TYPE) {
52004 case FSCACHE_OP_ASYNC:
52005 _debug("queue async");
52006@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
52007 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
52008 if (op->processor)
52009 fscache_enqueue_operation(op);
52010- fscache_stat(&fscache_n_op_run);
52011+ fscache_stat_unchecked(&fscache_n_op_run);
52012 }
52013
52014 /*
52015@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
52016 if (object->n_in_progress > 0) {
52017 atomic_inc(&op->usage);
52018 list_add_tail(&op->pend_link, &object->pending_ops);
52019- fscache_stat(&fscache_n_op_pend);
52020+ fscache_stat_unchecked(&fscache_n_op_pend);
52021 } else if (!list_empty(&object->pending_ops)) {
52022 atomic_inc(&op->usage);
52023 list_add_tail(&op->pend_link, &object->pending_ops);
52024- fscache_stat(&fscache_n_op_pend);
52025+ fscache_stat_unchecked(&fscache_n_op_pend);
52026 fscache_start_operations(object);
52027 } else {
52028 ASSERTCMP(object->n_in_progress, ==, 0);
52029@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
52030 object->n_exclusive++; /* reads and writes must wait */
52031 atomic_inc(&op->usage);
52032 list_add_tail(&op->pend_link, &object->pending_ops);
52033- fscache_stat(&fscache_n_op_pend);
52034+ fscache_stat_unchecked(&fscache_n_op_pend);
52035 ret = 0;
52036 } else {
52037 /* If we're in any other state, there must have been an I/O
52038@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
52039 if (object->n_exclusive > 0) {
52040 atomic_inc(&op->usage);
52041 list_add_tail(&op->pend_link, &object->pending_ops);
52042- fscache_stat(&fscache_n_op_pend);
52043+ fscache_stat_unchecked(&fscache_n_op_pend);
52044 } else if (!list_empty(&object->pending_ops)) {
52045 atomic_inc(&op->usage);
52046 list_add_tail(&op->pend_link, &object->pending_ops);
52047- fscache_stat(&fscache_n_op_pend);
52048+ fscache_stat_unchecked(&fscache_n_op_pend);
52049 fscache_start_operations(object);
52050 } else {
52051 ASSERTCMP(object->n_exclusive, ==, 0);
52052@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
52053 object->n_ops++;
52054 atomic_inc(&op->usage);
52055 list_add_tail(&op->pend_link, &object->pending_ops);
52056- fscache_stat(&fscache_n_op_pend);
52057+ fscache_stat_unchecked(&fscache_n_op_pend);
52058 ret = 0;
52059 } else if (object->state == FSCACHE_OBJECT_DYING ||
52060 object->state == FSCACHE_OBJECT_LC_DYING ||
52061 object->state == FSCACHE_OBJECT_WITHDRAWING) {
52062- fscache_stat(&fscache_n_op_rejected);
52063+ fscache_stat_unchecked(&fscache_n_op_rejected);
52064 op->state = FSCACHE_OP_ST_CANCELLED;
52065 ret = -ENOBUFS;
52066 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
52067@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
52068 ret = -EBUSY;
52069 if (op->state == FSCACHE_OP_ST_PENDING) {
52070 ASSERT(!list_empty(&op->pend_link));
52071- fscache_stat(&fscache_n_op_cancelled);
52072+ fscache_stat_unchecked(&fscache_n_op_cancelled);
52073 list_del_init(&op->pend_link);
52074 if (do_cancel)
52075 do_cancel(op);
52076@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
52077 while (!list_empty(&object->pending_ops)) {
52078 op = list_entry(object->pending_ops.next,
52079 struct fscache_operation, pend_link);
52080- fscache_stat(&fscache_n_op_cancelled);
52081+ fscache_stat_unchecked(&fscache_n_op_cancelled);
52082 list_del_init(&op->pend_link);
52083
52084 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
52085@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
52086 op->state, ==, FSCACHE_OP_ST_CANCELLED);
52087 op->state = FSCACHE_OP_ST_DEAD;
52088
52089- fscache_stat(&fscache_n_op_release);
52090+ fscache_stat_unchecked(&fscache_n_op_release);
52091
52092 if (op->release) {
52093 op->release(op);
52094@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
52095 * lock, and defer it otherwise */
52096 if (!spin_trylock(&object->lock)) {
52097 _debug("defer put");
52098- fscache_stat(&fscache_n_op_deferred_release);
52099+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
52100
52101 cache = object->cache;
52102 spin_lock(&cache->op_gc_list_lock);
52103@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
52104
52105 _debug("GC DEFERRED REL OBJ%x OP%x",
52106 object->debug_id, op->debug_id);
52107- fscache_stat(&fscache_n_op_gc);
52108+ fscache_stat_unchecked(&fscache_n_op_gc);
52109
52110 ASSERTCMP(atomic_read(&op->usage), ==, 0);
52111 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
52112diff --git a/fs/fscache/page.c b/fs/fscache/page.c
52113index ff000e5..c44ec6d 100644
52114--- a/fs/fscache/page.c
52115+++ b/fs/fscache/page.c
52116@@ -61,7 +61,7 @@ try_again:
52117 val = radix_tree_lookup(&cookie->stores, page->index);
52118 if (!val) {
52119 rcu_read_unlock();
52120- fscache_stat(&fscache_n_store_vmscan_not_storing);
52121+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
52122 __fscache_uncache_page(cookie, page);
52123 return true;
52124 }
52125@@ -91,11 +91,11 @@ try_again:
52126 spin_unlock(&cookie->stores_lock);
52127
52128 if (xpage) {
52129- fscache_stat(&fscache_n_store_vmscan_cancelled);
52130- fscache_stat(&fscache_n_store_radix_deletes);
52131+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
52132+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
52133 ASSERTCMP(xpage, ==, page);
52134 } else {
52135- fscache_stat(&fscache_n_store_vmscan_gone);
52136+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
52137 }
52138
52139 wake_up_bit(&cookie->flags, 0);
52140@@ -110,11 +110,11 @@ page_busy:
52141 * sleeping on memory allocation, so we may need to impose a timeout
52142 * too. */
52143 if (!(gfp & __GFP_WAIT)) {
52144- fscache_stat(&fscache_n_store_vmscan_busy);
52145+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
52146 return false;
52147 }
52148
52149- fscache_stat(&fscache_n_store_vmscan_wait);
52150+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
52151 __fscache_wait_on_page_write(cookie, page);
52152 gfp &= ~__GFP_WAIT;
52153 goto try_again;
52154@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
52155 FSCACHE_COOKIE_STORING_TAG);
52156 if (!radix_tree_tag_get(&cookie->stores, page->index,
52157 FSCACHE_COOKIE_PENDING_TAG)) {
52158- fscache_stat(&fscache_n_store_radix_deletes);
52159+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
52160 xpage = radix_tree_delete(&cookie->stores, page->index);
52161 }
52162 spin_unlock(&cookie->stores_lock);
52163@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
52164
52165 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
52166
52167- fscache_stat(&fscache_n_attr_changed_calls);
52168+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
52169
52170 if (fscache_object_is_active(object)) {
52171 fscache_stat(&fscache_n_cop_attr_changed);
52172@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52173
52174 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52175
52176- fscache_stat(&fscache_n_attr_changed);
52177+ fscache_stat_unchecked(&fscache_n_attr_changed);
52178
52179 op = kzalloc(sizeof(*op), GFP_KERNEL);
52180 if (!op) {
52181- fscache_stat(&fscache_n_attr_changed_nomem);
52182+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
52183 _leave(" = -ENOMEM");
52184 return -ENOMEM;
52185 }
52186@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52187 if (fscache_submit_exclusive_op(object, op) < 0)
52188 goto nobufs;
52189 spin_unlock(&cookie->lock);
52190- fscache_stat(&fscache_n_attr_changed_ok);
52191+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
52192 fscache_put_operation(op);
52193 _leave(" = 0");
52194 return 0;
52195@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52196 nobufs:
52197 spin_unlock(&cookie->lock);
52198 kfree(op);
52199- fscache_stat(&fscache_n_attr_changed_nobufs);
52200+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
52201 _leave(" = %d", -ENOBUFS);
52202 return -ENOBUFS;
52203 }
52204@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
52205 /* allocate a retrieval operation and attempt to submit it */
52206 op = kzalloc(sizeof(*op), GFP_NOIO);
52207 if (!op) {
52208- fscache_stat(&fscache_n_retrievals_nomem);
52209+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52210 return NULL;
52211 }
52212
52213@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
52214 return 0;
52215 }
52216
52217- fscache_stat(&fscache_n_retrievals_wait);
52218+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
52219
52220 jif = jiffies;
52221 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
52222 fscache_wait_bit_interruptible,
52223 TASK_INTERRUPTIBLE) != 0) {
52224- fscache_stat(&fscache_n_retrievals_intr);
52225+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52226 _leave(" = -ERESTARTSYS");
52227 return -ERESTARTSYS;
52228 }
52229@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
52230 */
52231 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52232 struct fscache_retrieval *op,
52233- atomic_t *stat_op_waits,
52234- atomic_t *stat_object_dead)
52235+ atomic_unchecked_t *stat_op_waits,
52236+ atomic_unchecked_t *stat_object_dead)
52237 {
52238 int ret;
52239
52240@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52241 goto check_if_dead;
52242
52243 _debug(">>> WT");
52244- fscache_stat(stat_op_waits);
52245+ fscache_stat_unchecked(stat_op_waits);
52246 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
52247 fscache_wait_bit_interruptible,
52248 TASK_INTERRUPTIBLE) != 0) {
52249@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52250
52251 check_if_dead:
52252 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
52253- fscache_stat(stat_object_dead);
52254+ fscache_stat_unchecked(stat_object_dead);
52255 _leave(" = -ENOBUFS [cancelled]");
52256 return -ENOBUFS;
52257 }
52258 if (unlikely(fscache_object_is_dead(object))) {
52259 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
52260 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
52261- fscache_stat(stat_object_dead);
52262+ fscache_stat_unchecked(stat_object_dead);
52263 return -ENOBUFS;
52264 }
52265 return 0;
52266@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52267
52268 _enter("%p,%p,,,", cookie, page);
52269
52270- fscache_stat(&fscache_n_retrievals);
52271+ fscache_stat_unchecked(&fscache_n_retrievals);
52272
52273 if (hlist_empty(&cookie->backing_objects))
52274 goto nobufs;
52275@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52276 goto nobufs_unlock_dec;
52277 spin_unlock(&cookie->lock);
52278
52279- fscache_stat(&fscache_n_retrieval_ops);
52280+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52281
52282 /* pin the netfs read context in case we need to do the actual netfs
52283 * read because we've encountered a cache read failure */
52284@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52285
52286 error:
52287 if (ret == -ENOMEM)
52288- fscache_stat(&fscache_n_retrievals_nomem);
52289+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52290 else if (ret == -ERESTARTSYS)
52291- fscache_stat(&fscache_n_retrievals_intr);
52292+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52293 else if (ret == -ENODATA)
52294- fscache_stat(&fscache_n_retrievals_nodata);
52295+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52296 else if (ret < 0)
52297- fscache_stat(&fscache_n_retrievals_nobufs);
52298+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52299 else
52300- fscache_stat(&fscache_n_retrievals_ok);
52301+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52302
52303 fscache_put_retrieval(op);
52304 _leave(" = %d", ret);
52305@@ -467,7 +467,7 @@ nobufs_unlock:
52306 spin_unlock(&cookie->lock);
52307 kfree(op);
52308 nobufs:
52309- fscache_stat(&fscache_n_retrievals_nobufs);
52310+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52311 _leave(" = -ENOBUFS");
52312 return -ENOBUFS;
52313 }
52314@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52315
52316 _enter("%p,,%d,,,", cookie, *nr_pages);
52317
52318- fscache_stat(&fscache_n_retrievals);
52319+ fscache_stat_unchecked(&fscache_n_retrievals);
52320
52321 if (hlist_empty(&cookie->backing_objects))
52322 goto nobufs;
52323@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52324 goto nobufs_unlock_dec;
52325 spin_unlock(&cookie->lock);
52326
52327- fscache_stat(&fscache_n_retrieval_ops);
52328+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52329
52330 /* pin the netfs read context in case we need to do the actual netfs
52331 * read because we've encountered a cache read failure */
52332@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52333
52334 error:
52335 if (ret == -ENOMEM)
52336- fscache_stat(&fscache_n_retrievals_nomem);
52337+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52338 else if (ret == -ERESTARTSYS)
52339- fscache_stat(&fscache_n_retrievals_intr);
52340+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52341 else if (ret == -ENODATA)
52342- fscache_stat(&fscache_n_retrievals_nodata);
52343+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52344 else if (ret < 0)
52345- fscache_stat(&fscache_n_retrievals_nobufs);
52346+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52347 else
52348- fscache_stat(&fscache_n_retrievals_ok);
52349+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52350
52351 fscache_put_retrieval(op);
52352 _leave(" = %d", ret);
52353@@ -591,7 +591,7 @@ nobufs_unlock:
52354 spin_unlock(&cookie->lock);
52355 kfree(op);
52356 nobufs:
52357- fscache_stat(&fscache_n_retrievals_nobufs);
52358+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52359 _leave(" = -ENOBUFS");
52360 return -ENOBUFS;
52361 }
52362@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52363
52364 _enter("%p,%p,,,", cookie, page);
52365
52366- fscache_stat(&fscache_n_allocs);
52367+ fscache_stat_unchecked(&fscache_n_allocs);
52368
52369 if (hlist_empty(&cookie->backing_objects))
52370 goto nobufs;
52371@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52372 goto nobufs_unlock;
52373 spin_unlock(&cookie->lock);
52374
52375- fscache_stat(&fscache_n_alloc_ops);
52376+ fscache_stat_unchecked(&fscache_n_alloc_ops);
52377
52378 ret = fscache_wait_for_retrieval_activation(
52379 object, op,
52380@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52381
52382 error:
52383 if (ret == -ERESTARTSYS)
52384- fscache_stat(&fscache_n_allocs_intr);
52385+ fscache_stat_unchecked(&fscache_n_allocs_intr);
52386 else if (ret < 0)
52387- fscache_stat(&fscache_n_allocs_nobufs);
52388+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52389 else
52390- fscache_stat(&fscache_n_allocs_ok);
52391+ fscache_stat_unchecked(&fscache_n_allocs_ok);
52392
52393 fscache_put_retrieval(op);
52394 _leave(" = %d", ret);
52395@@ -677,7 +677,7 @@ nobufs_unlock:
52396 spin_unlock(&cookie->lock);
52397 kfree(op);
52398 nobufs:
52399- fscache_stat(&fscache_n_allocs_nobufs);
52400+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52401 _leave(" = -ENOBUFS");
52402 return -ENOBUFS;
52403 }
52404@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52405
52406 spin_lock(&cookie->stores_lock);
52407
52408- fscache_stat(&fscache_n_store_calls);
52409+ fscache_stat_unchecked(&fscache_n_store_calls);
52410
52411 /* find a page to store */
52412 page = NULL;
52413@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52414 page = results[0];
52415 _debug("gang %d [%lx]", n, page->index);
52416 if (page->index > op->store_limit) {
52417- fscache_stat(&fscache_n_store_pages_over_limit);
52418+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
52419 goto superseded;
52420 }
52421
52422@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52423 spin_unlock(&cookie->stores_lock);
52424 spin_unlock(&object->lock);
52425
52426- fscache_stat(&fscache_n_store_pages);
52427+ fscache_stat_unchecked(&fscache_n_store_pages);
52428 fscache_stat(&fscache_n_cop_write_page);
52429 ret = object->cache->ops->write_page(op, page);
52430 fscache_stat_d(&fscache_n_cop_write_page);
52431@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52432 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52433 ASSERT(PageFsCache(page));
52434
52435- fscache_stat(&fscache_n_stores);
52436+ fscache_stat_unchecked(&fscache_n_stores);
52437
52438 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
52439 _leave(" = -ENOBUFS [invalidating]");
52440@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52441 spin_unlock(&cookie->stores_lock);
52442 spin_unlock(&object->lock);
52443
52444- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
52445+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
52446 op->store_limit = object->store_limit;
52447
52448 if (fscache_submit_op(object, &op->op) < 0)
52449@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52450
52451 spin_unlock(&cookie->lock);
52452 radix_tree_preload_end();
52453- fscache_stat(&fscache_n_store_ops);
52454- fscache_stat(&fscache_n_stores_ok);
52455+ fscache_stat_unchecked(&fscache_n_store_ops);
52456+ fscache_stat_unchecked(&fscache_n_stores_ok);
52457
52458 /* the work queue now carries its own ref on the object */
52459 fscache_put_operation(&op->op);
52460@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52461 return 0;
52462
52463 already_queued:
52464- fscache_stat(&fscache_n_stores_again);
52465+ fscache_stat_unchecked(&fscache_n_stores_again);
52466 already_pending:
52467 spin_unlock(&cookie->stores_lock);
52468 spin_unlock(&object->lock);
52469 spin_unlock(&cookie->lock);
52470 radix_tree_preload_end();
52471 kfree(op);
52472- fscache_stat(&fscache_n_stores_ok);
52473+ fscache_stat_unchecked(&fscache_n_stores_ok);
52474 _leave(" = 0");
52475 return 0;
52476
52477@@ -959,14 +959,14 @@ nobufs:
52478 spin_unlock(&cookie->lock);
52479 radix_tree_preload_end();
52480 kfree(op);
52481- fscache_stat(&fscache_n_stores_nobufs);
52482+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
52483 _leave(" = -ENOBUFS");
52484 return -ENOBUFS;
52485
52486 nomem_free:
52487 kfree(op);
52488 nomem:
52489- fscache_stat(&fscache_n_stores_oom);
52490+ fscache_stat_unchecked(&fscache_n_stores_oom);
52491 _leave(" = -ENOMEM");
52492 return -ENOMEM;
52493 }
52494@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
52495 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52496 ASSERTCMP(page, !=, NULL);
52497
52498- fscache_stat(&fscache_n_uncaches);
52499+ fscache_stat_unchecked(&fscache_n_uncaches);
52500
52501 /* cache withdrawal may beat us to it */
52502 if (!PageFsCache(page))
52503@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
52504 struct fscache_cookie *cookie = op->op.object->cookie;
52505
52506 #ifdef CONFIG_FSCACHE_STATS
52507- atomic_inc(&fscache_n_marks);
52508+ atomic_inc_unchecked(&fscache_n_marks);
52509 #endif
52510
52511 _debug("- mark %p{%lx}", page, page->index);
52512diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
52513index 40d13c7..ddf52b9 100644
52514--- a/fs/fscache/stats.c
52515+++ b/fs/fscache/stats.c
52516@@ -18,99 +18,99 @@
52517 /*
52518 * operation counters
52519 */
52520-atomic_t fscache_n_op_pend;
52521-atomic_t fscache_n_op_run;
52522-atomic_t fscache_n_op_enqueue;
52523-atomic_t fscache_n_op_requeue;
52524-atomic_t fscache_n_op_deferred_release;
52525-atomic_t fscache_n_op_release;
52526-atomic_t fscache_n_op_gc;
52527-atomic_t fscache_n_op_cancelled;
52528-atomic_t fscache_n_op_rejected;
52529+atomic_unchecked_t fscache_n_op_pend;
52530+atomic_unchecked_t fscache_n_op_run;
52531+atomic_unchecked_t fscache_n_op_enqueue;
52532+atomic_unchecked_t fscache_n_op_requeue;
52533+atomic_unchecked_t fscache_n_op_deferred_release;
52534+atomic_unchecked_t fscache_n_op_release;
52535+atomic_unchecked_t fscache_n_op_gc;
52536+atomic_unchecked_t fscache_n_op_cancelled;
52537+atomic_unchecked_t fscache_n_op_rejected;
52538
52539-atomic_t fscache_n_attr_changed;
52540-atomic_t fscache_n_attr_changed_ok;
52541-atomic_t fscache_n_attr_changed_nobufs;
52542-atomic_t fscache_n_attr_changed_nomem;
52543-atomic_t fscache_n_attr_changed_calls;
52544+atomic_unchecked_t fscache_n_attr_changed;
52545+atomic_unchecked_t fscache_n_attr_changed_ok;
52546+atomic_unchecked_t fscache_n_attr_changed_nobufs;
52547+atomic_unchecked_t fscache_n_attr_changed_nomem;
52548+atomic_unchecked_t fscache_n_attr_changed_calls;
52549
52550-atomic_t fscache_n_allocs;
52551-atomic_t fscache_n_allocs_ok;
52552-atomic_t fscache_n_allocs_wait;
52553-atomic_t fscache_n_allocs_nobufs;
52554-atomic_t fscache_n_allocs_intr;
52555-atomic_t fscache_n_allocs_object_dead;
52556-atomic_t fscache_n_alloc_ops;
52557-atomic_t fscache_n_alloc_op_waits;
52558+atomic_unchecked_t fscache_n_allocs;
52559+atomic_unchecked_t fscache_n_allocs_ok;
52560+atomic_unchecked_t fscache_n_allocs_wait;
52561+atomic_unchecked_t fscache_n_allocs_nobufs;
52562+atomic_unchecked_t fscache_n_allocs_intr;
52563+atomic_unchecked_t fscache_n_allocs_object_dead;
52564+atomic_unchecked_t fscache_n_alloc_ops;
52565+atomic_unchecked_t fscache_n_alloc_op_waits;
52566
52567-atomic_t fscache_n_retrievals;
52568-atomic_t fscache_n_retrievals_ok;
52569-atomic_t fscache_n_retrievals_wait;
52570-atomic_t fscache_n_retrievals_nodata;
52571-atomic_t fscache_n_retrievals_nobufs;
52572-atomic_t fscache_n_retrievals_intr;
52573-atomic_t fscache_n_retrievals_nomem;
52574-atomic_t fscache_n_retrievals_object_dead;
52575-atomic_t fscache_n_retrieval_ops;
52576-atomic_t fscache_n_retrieval_op_waits;
52577+atomic_unchecked_t fscache_n_retrievals;
52578+atomic_unchecked_t fscache_n_retrievals_ok;
52579+atomic_unchecked_t fscache_n_retrievals_wait;
52580+atomic_unchecked_t fscache_n_retrievals_nodata;
52581+atomic_unchecked_t fscache_n_retrievals_nobufs;
52582+atomic_unchecked_t fscache_n_retrievals_intr;
52583+atomic_unchecked_t fscache_n_retrievals_nomem;
52584+atomic_unchecked_t fscache_n_retrievals_object_dead;
52585+atomic_unchecked_t fscache_n_retrieval_ops;
52586+atomic_unchecked_t fscache_n_retrieval_op_waits;
52587
52588-atomic_t fscache_n_stores;
52589-atomic_t fscache_n_stores_ok;
52590-atomic_t fscache_n_stores_again;
52591-atomic_t fscache_n_stores_nobufs;
52592-atomic_t fscache_n_stores_oom;
52593-atomic_t fscache_n_store_ops;
52594-atomic_t fscache_n_store_calls;
52595-atomic_t fscache_n_store_pages;
52596-atomic_t fscache_n_store_radix_deletes;
52597-atomic_t fscache_n_store_pages_over_limit;
52598+atomic_unchecked_t fscache_n_stores;
52599+atomic_unchecked_t fscache_n_stores_ok;
52600+atomic_unchecked_t fscache_n_stores_again;
52601+atomic_unchecked_t fscache_n_stores_nobufs;
52602+atomic_unchecked_t fscache_n_stores_oom;
52603+atomic_unchecked_t fscache_n_store_ops;
52604+atomic_unchecked_t fscache_n_store_calls;
52605+atomic_unchecked_t fscache_n_store_pages;
52606+atomic_unchecked_t fscache_n_store_radix_deletes;
52607+atomic_unchecked_t fscache_n_store_pages_over_limit;
52608
52609-atomic_t fscache_n_store_vmscan_not_storing;
52610-atomic_t fscache_n_store_vmscan_gone;
52611-atomic_t fscache_n_store_vmscan_busy;
52612-atomic_t fscache_n_store_vmscan_cancelled;
52613-atomic_t fscache_n_store_vmscan_wait;
52614+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
52615+atomic_unchecked_t fscache_n_store_vmscan_gone;
52616+atomic_unchecked_t fscache_n_store_vmscan_busy;
52617+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
52618+atomic_unchecked_t fscache_n_store_vmscan_wait;
52619
52620-atomic_t fscache_n_marks;
52621-atomic_t fscache_n_uncaches;
52622+atomic_unchecked_t fscache_n_marks;
52623+atomic_unchecked_t fscache_n_uncaches;
52624
52625-atomic_t fscache_n_acquires;
52626-atomic_t fscache_n_acquires_null;
52627-atomic_t fscache_n_acquires_no_cache;
52628-atomic_t fscache_n_acquires_ok;
52629-atomic_t fscache_n_acquires_nobufs;
52630-atomic_t fscache_n_acquires_oom;
52631+atomic_unchecked_t fscache_n_acquires;
52632+atomic_unchecked_t fscache_n_acquires_null;
52633+atomic_unchecked_t fscache_n_acquires_no_cache;
52634+atomic_unchecked_t fscache_n_acquires_ok;
52635+atomic_unchecked_t fscache_n_acquires_nobufs;
52636+atomic_unchecked_t fscache_n_acquires_oom;
52637
52638-atomic_t fscache_n_invalidates;
52639-atomic_t fscache_n_invalidates_run;
52640+atomic_unchecked_t fscache_n_invalidates;
52641+atomic_unchecked_t fscache_n_invalidates_run;
52642
52643-atomic_t fscache_n_updates;
52644-atomic_t fscache_n_updates_null;
52645-atomic_t fscache_n_updates_run;
52646+atomic_unchecked_t fscache_n_updates;
52647+atomic_unchecked_t fscache_n_updates_null;
52648+atomic_unchecked_t fscache_n_updates_run;
52649
52650-atomic_t fscache_n_relinquishes;
52651-atomic_t fscache_n_relinquishes_null;
52652-atomic_t fscache_n_relinquishes_waitcrt;
52653-atomic_t fscache_n_relinquishes_retire;
52654+atomic_unchecked_t fscache_n_relinquishes;
52655+atomic_unchecked_t fscache_n_relinquishes_null;
52656+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
52657+atomic_unchecked_t fscache_n_relinquishes_retire;
52658
52659-atomic_t fscache_n_cookie_index;
52660-atomic_t fscache_n_cookie_data;
52661-atomic_t fscache_n_cookie_special;
52662+atomic_unchecked_t fscache_n_cookie_index;
52663+atomic_unchecked_t fscache_n_cookie_data;
52664+atomic_unchecked_t fscache_n_cookie_special;
52665
52666-atomic_t fscache_n_object_alloc;
52667-atomic_t fscache_n_object_no_alloc;
52668-atomic_t fscache_n_object_lookups;
52669-atomic_t fscache_n_object_lookups_negative;
52670-atomic_t fscache_n_object_lookups_positive;
52671-atomic_t fscache_n_object_lookups_timed_out;
52672-atomic_t fscache_n_object_created;
52673-atomic_t fscache_n_object_avail;
52674-atomic_t fscache_n_object_dead;
52675+atomic_unchecked_t fscache_n_object_alloc;
52676+atomic_unchecked_t fscache_n_object_no_alloc;
52677+atomic_unchecked_t fscache_n_object_lookups;
52678+atomic_unchecked_t fscache_n_object_lookups_negative;
52679+atomic_unchecked_t fscache_n_object_lookups_positive;
52680+atomic_unchecked_t fscache_n_object_lookups_timed_out;
52681+atomic_unchecked_t fscache_n_object_created;
52682+atomic_unchecked_t fscache_n_object_avail;
52683+atomic_unchecked_t fscache_n_object_dead;
52684
52685-atomic_t fscache_n_checkaux_none;
52686-atomic_t fscache_n_checkaux_okay;
52687-atomic_t fscache_n_checkaux_update;
52688-atomic_t fscache_n_checkaux_obsolete;
52689+atomic_unchecked_t fscache_n_checkaux_none;
52690+atomic_unchecked_t fscache_n_checkaux_okay;
52691+atomic_unchecked_t fscache_n_checkaux_update;
52692+atomic_unchecked_t fscache_n_checkaux_obsolete;
52693
52694 atomic_t fscache_n_cop_alloc_object;
52695 atomic_t fscache_n_cop_lookup_object;
52696@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
52697 seq_puts(m, "FS-Cache statistics\n");
52698
52699 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
52700- atomic_read(&fscache_n_cookie_index),
52701- atomic_read(&fscache_n_cookie_data),
52702- atomic_read(&fscache_n_cookie_special));
52703+ atomic_read_unchecked(&fscache_n_cookie_index),
52704+ atomic_read_unchecked(&fscache_n_cookie_data),
52705+ atomic_read_unchecked(&fscache_n_cookie_special));
52706
52707 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
52708- atomic_read(&fscache_n_object_alloc),
52709- atomic_read(&fscache_n_object_no_alloc),
52710- atomic_read(&fscache_n_object_avail),
52711- atomic_read(&fscache_n_object_dead));
52712+ atomic_read_unchecked(&fscache_n_object_alloc),
52713+ atomic_read_unchecked(&fscache_n_object_no_alloc),
52714+ atomic_read_unchecked(&fscache_n_object_avail),
52715+ atomic_read_unchecked(&fscache_n_object_dead));
52716 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
52717- atomic_read(&fscache_n_checkaux_none),
52718- atomic_read(&fscache_n_checkaux_okay),
52719- atomic_read(&fscache_n_checkaux_update),
52720- atomic_read(&fscache_n_checkaux_obsolete));
52721+ atomic_read_unchecked(&fscache_n_checkaux_none),
52722+ atomic_read_unchecked(&fscache_n_checkaux_okay),
52723+ atomic_read_unchecked(&fscache_n_checkaux_update),
52724+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
52725
52726 seq_printf(m, "Pages : mrk=%u unc=%u\n",
52727- atomic_read(&fscache_n_marks),
52728- atomic_read(&fscache_n_uncaches));
52729+ atomic_read_unchecked(&fscache_n_marks),
52730+ atomic_read_unchecked(&fscache_n_uncaches));
52731
52732 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
52733 " oom=%u\n",
52734- atomic_read(&fscache_n_acquires),
52735- atomic_read(&fscache_n_acquires_null),
52736- atomic_read(&fscache_n_acquires_no_cache),
52737- atomic_read(&fscache_n_acquires_ok),
52738- atomic_read(&fscache_n_acquires_nobufs),
52739- atomic_read(&fscache_n_acquires_oom));
52740+ atomic_read_unchecked(&fscache_n_acquires),
52741+ atomic_read_unchecked(&fscache_n_acquires_null),
52742+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
52743+ atomic_read_unchecked(&fscache_n_acquires_ok),
52744+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
52745+ atomic_read_unchecked(&fscache_n_acquires_oom));
52746
52747 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
52748- atomic_read(&fscache_n_object_lookups),
52749- atomic_read(&fscache_n_object_lookups_negative),
52750- atomic_read(&fscache_n_object_lookups_positive),
52751- atomic_read(&fscache_n_object_created),
52752- atomic_read(&fscache_n_object_lookups_timed_out));
52753+ atomic_read_unchecked(&fscache_n_object_lookups),
52754+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
52755+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
52756+ atomic_read_unchecked(&fscache_n_object_created),
52757+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
52758
52759 seq_printf(m, "Invals : n=%u run=%u\n",
52760- atomic_read(&fscache_n_invalidates),
52761- atomic_read(&fscache_n_invalidates_run));
52762+ atomic_read_unchecked(&fscache_n_invalidates),
52763+ atomic_read_unchecked(&fscache_n_invalidates_run));
52764
52765 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
52766- atomic_read(&fscache_n_updates),
52767- atomic_read(&fscache_n_updates_null),
52768- atomic_read(&fscache_n_updates_run));
52769+ atomic_read_unchecked(&fscache_n_updates),
52770+ atomic_read_unchecked(&fscache_n_updates_null),
52771+ atomic_read_unchecked(&fscache_n_updates_run));
52772
52773 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
52774- atomic_read(&fscache_n_relinquishes),
52775- atomic_read(&fscache_n_relinquishes_null),
52776- atomic_read(&fscache_n_relinquishes_waitcrt),
52777- atomic_read(&fscache_n_relinquishes_retire));
52778+ atomic_read_unchecked(&fscache_n_relinquishes),
52779+ atomic_read_unchecked(&fscache_n_relinquishes_null),
52780+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
52781+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
52782
52783 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
52784- atomic_read(&fscache_n_attr_changed),
52785- atomic_read(&fscache_n_attr_changed_ok),
52786- atomic_read(&fscache_n_attr_changed_nobufs),
52787- atomic_read(&fscache_n_attr_changed_nomem),
52788- atomic_read(&fscache_n_attr_changed_calls));
52789+ atomic_read_unchecked(&fscache_n_attr_changed),
52790+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
52791+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
52792+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
52793+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
52794
52795 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
52796- atomic_read(&fscache_n_allocs),
52797- atomic_read(&fscache_n_allocs_ok),
52798- atomic_read(&fscache_n_allocs_wait),
52799- atomic_read(&fscache_n_allocs_nobufs),
52800- atomic_read(&fscache_n_allocs_intr));
52801+ atomic_read_unchecked(&fscache_n_allocs),
52802+ atomic_read_unchecked(&fscache_n_allocs_ok),
52803+ atomic_read_unchecked(&fscache_n_allocs_wait),
52804+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
52805+ atomic_read_unchecked(&fscache_n_allocs_intr));
52806 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
52807- atomic_read(&fscache_n_alloc_ops),
52808- atomic_read(&fscache_n_alloc_op_waits),
52809- atomic_read(&fscache_n_allocs_object_dead));
52810+ atomic_read_unchecked(&fscache_n_alloc_ops),
52811+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
52812+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
52813
52814 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
52815 " int=%u oom=%u\n",
52816- atomic_read(&fscache_n_retrievals),
52817- atomic_read(&fscache_n_retrievals_ok),
52818- atomic_read(&fscache_n_retrievals_wait),
52819- atomic_read(&fscache_n_retrievals_nodata),
52820- atomic_read(&fscache_n_retrievals_nobufs),
52821- atomic_read(&fscache_n_retrievals_intr),
52822- atomic_read(&fscache_n_retrievals_nomem));
52823+ atomic_read_unchecked(&fscache_n_retrievals),
52824+ atomic_read_unchecked(&fscache_n_retrievals_ok),
52825+ atomic_read_unchecked(&fscache_n_retrievals_wait),
52826+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
52827+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
52828+ atomic_read_unchecked(&fscache_n_retrievals_intr),
52829+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
52830 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
52831- atomic_read(&fscache_n_retrieval_ops),
52832- atomic_read(&fscache_n_retrieval_op_waits),
52833- atomic_read(&fscache_n_retrievals_object_dead));
52834+ atomic_read_unchecked(&fscache_n_retrieval_ops),
52835+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
52836+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
52837
52838 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
52839- atomic_read(&fscache_n_stores),
52840- atomic_read(&fscache_n_stores_ok),
52841- atomic_read(&fscache_n_stores_again),
52842- atomic_read(&fscache_n_stores_nobufs),
52843- atomic_read(&fscache_n_stores_oom));
52844+ atomic_read_unchecked(&fscache_n_stores),
52845+ atomic_read_unchecked(&fscache_n_stores_ok),
52846+ atomic_read_unchecked(&fscache_n_stores_again),
52847+ atomic_read_unchecked(&fscache_n_stores_nobufs),
52848+ atomic_read_unchecked(&fscache_n_stores_oom));
52849 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
52850- atomic_read(&fscache_n_store_ops),
52851- atomic_read(&fscache_n_store_calls),
52852- atomic_read(&fscache_n_store_pages),
52853- atomic_read(&fscache_n_store_radix_deletes),
52854- atomic_read(&fscache_n_store_pages_over_limit));
52855+ atomic_read_unchecked(&fscache_n_store_ops),
52856+ atomic_read_unchecked(&fscache_n_store_calls),
52857+ atomic_read_unchecked(&fscache_n_store_pages),
52858+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
52859+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
52860
52861 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
52862- atomic_read(&fscache_n_store_vmscan_not_storing),
52863- atomic_read(&fscache_n_store_vmscan_gone),
52864- atomic_read(&fscache_n_store_vmscan_busy),
52865- atomic_read(&fscache_n_store_vmscan_cancelled),
52866- atomic_read(&fscache_n_store_vmscan_wait));
52867+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
52868+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
52869+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
52870+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
52871+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
52872
52873 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
52874- atomic_read(&fscache_n_op_pend),
52875- atomic_read(&fscache_n_op_run),
52876- atomic_read(&fscache_n_op_enqueue),
52877- atomic_read(&fscache_n_op_cancelled),
52878- atomic_read(&fscache_n_op_rejected));
52879+ atomic_read_unchecked(&fscache_n_op_pend),
52880+ atomic_read_unchecked(&fscache_n_op_run),
52881+ atomic_read_unchecked(&fscache_n_op_enqueue),
52882+ atomic_read_unchecked(&fscache_n_op_cancelled),
52883+ atomic_read_unchecked(&fscache_n_op_rejected));
52884 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
52885- atomic_read(&fscache_n_op_deferred_release),
52886- atomic_read(&fscache_n_op_release),
52887- atomic_read(&fscache_n_op_gc));
52888+ atomic_read_unchecked(&fscache_n_op_deferred_release),
52889+ atomic_read_unchecked(&fscache_n_op_release),
52890+ atomic_read_unchecked(&fscache_n_op_gc));
52891
52892 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
52893 atomic_read(&fscache_n_cop_alloc_object),
52894diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
52895index 6f96a8d..6019bb9 100644
52896--- a/fs/fuse/cuse.c
52897+++ b/fs/fuse/cuse.c
52898@@ -597,10 +597,12 @@ static int __init cuse_init(void)
52899 INIT_LIST_HEAD(&cuse_conntbl[i]);
52900
52901 /* inherit and extend fuse_dev_operations */
52902- cuse_channel_fops = fuse_dev_operations;
52903- cuse_channel_fops.owner = THIS_MODULE;
52904- cuse_channel_fops.open = cuse_channel_open;
52905- cuse_channel_fops.release = cuse_channel_release;
52906+ pax_open_kernel();
52907+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
52908+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
52909+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
52910+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
52911+ pax_close_kernel();
52912
52913 cuse_class = class_create(THIS_MODULE, "cuse");
52914 if (IS_ERR(cuse_class))
52915diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
52916index 11dfa0c..6f64416 100644
52917--- a/fs/fuse/dev.c
52918+++ b/fs/fuse/dev.c
52919@@ -1294,7 +1294,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
52920 ret = 0;
52921 pipe_lock(pipe);
52922
52923- if (!pipe->readers) {
52924+ if (!atomic_read(&pipe->readers)) {
52925 send_sig(SIGPIPE, current, 0);
52926 if (!ret)
52927 ret = -EPIPE;
52928diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
52929index 185c479..51b9986 100644
52930--- a/fs/fuse/dir.c
52931+++ b/fs/fuse/dir.c
52932@@ -1415,7 +1415,7 @@ static char *read_link(struct dentry *dentry)
52933 return link;
52934 }
52935
52936-static void free_link(char *link)
52937+static void free_link(const char *link)
52938 {
52939 if (!IS_ERR(link))
52940 free_page((unsigned long) link);
52941diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
52942index cc00bd1..3edb692 100644
52943--- a/fs/gfs2/inode.c
52944+++ b/fs/gfs2/inode.c
52945@@ -1500,7 +1500,7 @@ out:
52946
52947 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52948 {
52949- char *s = nd_get_link(nd);
52950+ const char *s = nd_get_link(nd);
52951 if (!IS_ERR(s))
52952 kfree(s);
52953 }
52954diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
52955index a3f868a..bb308ae 100644
52956--- a/fs/hugetlbfs/inode.c
52957+++ b/fs/hugetlbfs/inode.c
52958@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
52959 struct mm_struct *mm = current->mm;
52960 struct vm_area_struct *vma;
52961 struct hstate *h = hstate_file(file);
52962+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
52963 struct vm_unmapped_area_info info;
52964
52965 if (len & ~huge_page_mask(h))
52966@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
52967 return addr;
52968 }
52969
52970+#ifdef CONFIG_PAX_RANDMMAP
52971+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
52972+#endif
52973+
52974 if (addr) {
52975 addr = ALIGN(addr, huge_page_size(h));
52976 vma = find_vma(mm, addr);
52977- if (TASK_SIZE - len >= addr &&
52978- (!vma || addr + len <= vma->vm_start))
52979+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
52980 return addr;
52981 }
52982
52983 info.flags = 0;
52984 info.length = len;
52985 info.low_limit = TASK_UNMAPPED_BASE;
52986+
52987+#ifdef CONFIG_PAX_RANDMMAP
52988+ if (mm->pax_flags & MF_PAX_RANDMMAP)
52989+ info.low_limit += mm->delta_mmap;
52990+#endif
52991+
52992 info.high_limit = TASK_SIZE;
52993 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
52994 info.align_offset = 0;
52995@@ -898,7 +908,7 @@ static struct file_system_type hugetlbfs_fs_type = {
52996 };
52997 MODULE_ALIAS_FS("hugetlbfs");
52998
52999-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
53000+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
53001
53002 static int can_do_hugetlb_shm(void)
53003 {
53004diff --git a/fs/inode.c b/fs/inode.c
53005index a898b3d..9b5a214 100644
53006--- a/fs/inode.c
53007+++ b/fs/inode.c
53008@@ -878,8 +878,8 @@ unsigned int get_next_ino(void)
53009
53010 #ifdef CONFIG_SMP
53011 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
53012- static atomic_t shared_last_ino;
53013- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
53014+ static atomic_unchecked_t shared_last_ino;
53015+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
53016
53017 res = next - LAST_INO_BATCH;
53018 }
53019diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
53020index 4a6cf28..d3a29d3 100644
53021--- a/fs/jffs2/erase.c
53022+++ b/fs/jffs2/erase.c
53023@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
53024 struct jffs2_unknown_node marker = {
53025 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
53026 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
53027- .totlen = cpu_to_je32(c->cleanmarker_size)
53028+ .totlen = cpu_to_je32(c->cleanmarker_size),
53029+ .hdr_crc = cpu_to_je32(0)
53030 };
53031
53032 jffs2_prealloc_raw_node_refs(c, jeb, 1);
53033diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
53034index a6597d6..41b30ec 100644
53035--- a/fs/jffs2/wbuf.c
53036+++ b/fs/jffs2/wbuf.c
53037@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
53038 {
53039 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
53040 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
53041- .totlen = constant_cpu_to_je32(8)
53042+ .totlen = constant_cpu_to_je32(8),
53043+ .hdr_crc = constant_cpu_to_je32(0)
53044 };
53045
53046 /*
53047diff --git a/fs/jfs/super.c b/fs/jfs/super.c
53048index 2003e83..40db287 100644
53049--- a/fs/jfs/super.c
53050+++ b/fs/jfs/super.c
53051@@ -856,7 +856,7 @@ static int __init init_jfs_fs(void)
53052
53053 jfs_inode_cachep =
53054 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
53055- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
53056+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
53057 init_once);
53058 if (jfs_inode_cachep == NULL)
53059 return -ENOMEM;
53060diff --git a/fs/libfs.c b/fs/libfs.c
53061index 916da8c..1588998 100644
53062--- a/fs/libfs.c
53063+++ b/fs/libfs.c
53064@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
53065
53066 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
53067 struct dentry *next;
53068+ char d_name[sizeof(next->d_iname)];
53069+ const unsigned char *name;
53070+
53071 next = list_entry(p, struct dentry, d_u.d_child);
53072 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
53073 if (!simple_positive(next)) {
53074@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
53075
53076 spin_unlock(&next->d_lock);
53077 spin_unlock(&dentry->d_lock);
53078- if (filldir(dirent, next->d_name.name,
53079+ name = next->d_name.name;
53080+ if (name == next->d_iname) {
53081+ memcpy(d_name, name, next->d_name.len);
53082+ name = d_name;
53083+ }
53084+ if (filldir(dirent, name,
53085 next->d_name.len, filp->f_pos,
53086 next->d_inode->i_ino,
53087 dt_type(next->d_inode)) < 0)
53088diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
53089index 9760ecb..9b838ef 100644
53090--- a/fs/lockd/clntproc.c
53091+++ b/fs/lockd/clntproc.c
53092@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
53093 /*
53094 * Cookie counter for NLM requests
53095 */
53096-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
53097+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
53098
53099 void nlmclnt_next_cookie(struct nlm_cookie *c)
53100 {
53101- u32 cookie = atomic_inc_return(&nlm_cookie);
53102+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
53103
53104 memcpy(c->data, &cookie, 4);
53105 c->len=4;
53106diff --git a/fs/locks.c b/fs/locks.c
53107index cb424a4..850e4dd 100644
53108--- a/fs/locks.c
53109+++ b/fs/locks.c
53110@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
53111 return;
53112
53113 if (filp->f_op && filp->f_op->flock) {
53114- struct file_lock fl = {
53115+ struct file_lock flock = {
53116 .fl_pid = current->tgid,
53117 .fl_file = filp,
53118 .fl_flags = FL_FLOCK,
53119 .fl_type = F_UNLCK,
53120 .fl_end = OFFSET_MAX,
53121 };
53122- filp->f_op->flock(filp, F_SETLKW, &fl);
53123- if (fl.fl_ops && fl.fl_ops->fl_release_private)
53124- fl.fl_ops->fl_release_private(&fl);
53125+ filp->f_op->flock(filp, F_SETLKW, &flock);
53126+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
53127+ flock.fl_ops->fl_release_private(&flock);
53128 }
53129
53130 lock_flocks();
53131diff --git a/fs/namei.c b/fs/namei.c
53132index 85e40d1..b66744e 100644
53133--- a/fs/namei.c
53134+++ b/fs/namei.c
53135@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
53136 if (ret != -EACCES)
53137 return ret;
53138
53139+#ifdef CONFIG_GRKERNSEC
53140+ /* we'll block if we have to log due to a denied capability use */
53141+ if (mask & MAY_NOT_BLOCK)
53142+ return -ECHILD;
53143+#endif
53144+
53145 if (S_ISDIR(inode->i_mode)) {
53146 /* DACs are overridable for directories */
53147- if (inode_capable(inode, CAP_DAC_OVERRIDE))
53148- return 0;
53149 if (!(mask & MAY_WRITE))
53150- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
53151+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
53152+ inode_capable(inode, CAP_DAC_READ_SEARCH))
53153 return 0;
53154+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
53155+ return 0;
53156 return -EACCES;
53157 }
53158 /*
53159+ * Searching includes executable on directories, else just read.
53160+ */
53161+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
53162+ if (mask == MAY_READ)
53163+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
53164+ inode_capable(inode, CAP_DAC_READ_SEARCH))
53165+ return 0;
53166+
53167+ /*
53168 * Read/write DACs are always overridable.
53169 * Executable DACs are overridable when there is
53170 * at least one exec bit set.
53171@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
53172 if (inode_capable(inode, CAP_DAC_OVERRIDE))
53173 return 0;
53174
53175- /*
53176- * Searching includes executable on directories, else just read.
53177- */
53178- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
53179- if (mask == MAY_READ)
53180- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
53181- return 0;
53182-
53183 return -EACCES;
53184 }
53185
53186@@ -820,7 +828,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53187 {
53188 struct dentry *dentry = link->dentry;
53189 int error;
53190- char *s;
53191+ const char *s;
53192
53193 BUG_ON(nd->flags & LOOKUP_RCU);
53194
53195@@ -841,6 +849,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53196 if (error)
53197 goto out_put_nd_path;
53198
53199+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
53200+ dentry->d_inode, dentry, nd->path.mnt)) {
53201+ error = -EACCES;
53202+ goto out_put_nd_path;
53203+ }
53204+
53205 nd->last_type = LAST_BIND;
53206 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
53207 error = PTR_ERR(*p);
53208@@ -1588,6 +1602,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
53209 if (res)
53210 break;
53211 res = walk_component(nd, path, LOOKUP_FOLLOW);
53212+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
53213+ res = -EACCES;
53214 put_link(nd, &link, cookie);
53215 } while (res > 0);
53216
53217@@ -1686,7 +1702,7 @@ EXPORT_SYMBOL(full_name_hash);
53218 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
53219 {
53220 unsigned long a, b, adata, bdata, mask, hash, len;
53221- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53222+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53223
53224 hash = a = 0;
53225 len = -sizeof(unsigned long);
53226@@ -1968,6 +1984,8 @@ static int path_lookupat(int dfd, const char *name,
53227 if (err)
53228 break;
53229 err = lookup_last(nd, &path);
53230+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
53231+ err = -EACCES;
53232 put_link(nd, &link, cookie);
53233 }
53234 }
53235@@ -1975,6 +1993,13 @@ static int path_lookupat(int dfd, const char *name,
53236 if (!err)
53237 err = complete_walk(nd);
53238
53239+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
53240+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53241+ path_put(&nd->path);
53242+ err = -ENOENT;
53243+ }
53244+ }
53245+
53246 if (!err && nd->flags & LOOKUP_DIRECTORY) {
53247 if (!nd->inode->i_op->lookup) {
53248 path_put(&nd->path);
53249@@ -2002,8 +2027,15 @@ static int filename_lookup(int dfd, struct filename *name,
53250 retval = path_lookupat(dfd, name->name,
53251 flags | LOOKUP_REVAL, nd);
53252
53253- if (likely(!retval))
53254+ if (likely(!retval)) {
53255 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
53256+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
53257+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
53258+ path_put(&nd->path);
53259+ return -ENOENT;
53260+ }
53261+ }
53262+ }
53263 return retval;
53264 }
53265
53266@@ -2381,6 +2413,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
53267 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
53268 return -EPERM;
53269
53270+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
53271+ return -EPERM;
53272+ if (gr_handle_rawio(inode))
53273+ return -EPERM;
53274+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
53275+ return -EACCES;
53276+
53277 return 0;
53278 }
53279
53280@@ -2602,7 +2641,7 @@ looked_up:
53281 * cleared otherwise prior to returning.
53282 */
53283 static int lookup_open(struct nameidata *nd, struct path *path,
53284- struct file *file,
53285+ struct path *link, struct file *file,
53286 const struct open_flags *op,
53287 bool got_write, int *opened)
53288 {
53289@@ -2637,6 +2676,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53290 /* Negative dentry, just create the file */
53291 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
53292 umode_t mode = op->mode;
53293+
53294+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
53295+ error = -EACCES;
53296+ goto out_dput;
53297+ }
53298+
53299+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
53300+ error = -EACCES;
53301+ goto out_dput;
53302+ }
53303+
53304 if (!IS_POSIXACL(dir->d_inode))
53305 mode &= ~current_umask();
53306 /*
53307@@ -2658,6 +2708,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53308 nd->flags & LOOKUP_EXCL);
53309 if (error)
53310 goto out_dput;
53311+ else
53312+ gr_handle_create(dentry, nd->path.mnt);
53313 }
53314 out_no_open:
53315 path->dentry = dentry;
53316@@ -2672,7 +2724,7 @@ out_dput:
53317 /*
53318 * Handle the last step of open()
53319 */
53320-static int do_last(struct nameidata *nd, struct path *path,
53321+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
53322 struct file *file, const struct open_flags *op,
53323 int *opened, struct filename *name)
53324 {
53325@@ -2701,16 +2753,32 @@ static int do_last(struct nameidata *nd, struct path *path,
53326 error = complete_walk(nd);
53327 if (error)
53328 return error;
53329+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53330+ error = -ENOENT;
53331+ goto out;
53332+ }
53333 audit_inode(name, nd->path.dentry, 0);
53334 if (open_flag & O_CREAT) {
53335 error = -EISDIR;
53336 goto out;
53337 }
53338+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53339+ error = -EACCES;
53340+ goto out;
53341+ }
53342 goto finish_open;
53343 case LAST_BIND:
53344 error = complete_walk(nd);
53345 if (error)
53346 return error;
53347+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
53348+ error = -ENOENT;
53349+ goto out;
53350+ }
53351+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53352+ error = -EACCES;
53353+ goto out;
53354+ }
53355 audit_inode(name, dir, 0);
53356 goto finish_open;
53357 }
53358@@ -2759,7 +2827,7 @@ retry_lookup:
53359 */
53360 }
53361 mutex_lock(&dir->d_inode->i_mutex);
53362- error = lookup_open(nd, path, file, op, got_write, opened);
53363+ error = lookup_open(nd, path, link, file, op, got_write, opened);
53364 mutex_unlock(&dir->d_inode->i_mutex);
53365
53366 if (error <= 0) {
53367@@ -2783,11 +2851,28 @@ retry_lookup:
53368 goto finish_open_created;
53369 }
53370
53371+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
53372+ error = -ENOENT;
53373+ goto exit_dput;
53374+ }
53375+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
53376+ error = -EACCES;
53377+ goto exit_dput;
53378+ }
53379+
53380 /*
53381 * create/update audit record if it already exists.
53382 */
53383- if (path->dentry->d_inode)
53384+ if (path->dentry->d_inode) {
53385+ /* only check if O_CREAT is specified, all other checks need to go
53386+ into may_open */
53387+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
53388+ error = -EACCES;
53389+ goto exit_dput;
53390+ }
53391+
53392 audit_inode(name, path->dentry, 0);
53393+ }
53394
53395 /*
53396 * If atomic_open() acquired write access it is dropped now due to
53397@@ -2828,6 +2913,11 @@ finish_lookup:
53398 }
53399 }
53400 BUG_ON(inode != path->dentry->d_inode);
53401+ /* if we're resolving a symlink to another symlink */
53402+ if (link && gr_handle_symlink_owner(link, inode)) {
53403+ error = -EACCES;
53404+ goto out;
53405+ }
53406 return 1;
53407 }
53408
53409@@ -2837,7 +2927,6 @@ finish_lookup:
53410 save_parent.dentry = nd->path.dentry;
53411 save_parent.mnt = mntget(path->mnt);
53412 nd->path.dentry = path->dentry;
53413-
53414 }
53415 nd->inode = inode;
53416 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
53417@@ -2846,6 +2935,16 @@ finish_lookup:
53418 path_put(&save_parent);
53419 return error;
53420 }
53421+
53422+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53423+ error = -ENOENT;
53424+ goto out;
53425+ }
53426+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53427+ error = -EACCES;
53428+ goto out;
53429+ }
53430+
53431 error = -EISDIR;
53432 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
53433 goto out;
53434@@ -2944,7 +3043,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53435 if (unlikely(error))
53436 goto out;
53437
53438- error = do_last(nd, &path, file, op, &opened, pathname);
53439+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
53440 while (unlikely(error > 0)) { /* trailing symlink */
53441 struct path link = path;
53442 void *cookie;
53443@@ -2962,7 +3061,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53444 error = follow_link(&link, nd, &cookie);
53445 if (unlikely(error))
53446 break;
53447- error = do_last(nd, &path, file, op, &opened, pathname);
53448+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
53449 put_link(nd, &link, cookie);
53450 }
53451 out:
53452@@ -3062,8 +3161,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
53453 goto unlock;
53454
53455 error = -EEXIST;
53456- if (dentry->d_inode)
53457+ if (dentry->d_inode) {
53458+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
53459+ error = -ENOENT;
53460+ }
53461 goto fail;
53462+ }
53463 /*
53464 * Special case - lookup gave negative, but... we had foo/bar/
53465 * From the vfs_mknod() POV we just have a negative dentry -
53466@@ -3115,6 +3218,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
53467 }
53468 EXPORT_SYMBOL(user_path_create);
53469
53470+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
53471+{
53472+ struct filename *tmp = getname(pathname);
53473+ struct dentry *res;
53474+ if (IS_ERR(tmp))
53475+ return ERR_CAST(tmp);
53476+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
53477+ if (IS_ERR(res))
53478+ putname(tmp);
53479+ else
53480+ *to = tmp;
53481+ return res;
53482+}
53483+
53484 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
53485 {
53486 int error = may_create(dir, dentry);
53487@@ -3177,6 +3294,17 @@ retry:
53488
53489 if (!IS_POSIXACL(path.dentry->d_inode))
53490 mode &= ~current_umask();
53491+
53492+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
53493+ error = -EPERM;
53494+ goto out;
53495+ }
53496+
53497+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
53498+ error = -EACCES;
53499+ goto out;
53500+ }
53501+
53502 error = security_path_mknod(&path, dentry, mode, dev);
53503 if (error)
53504 goto out;
53505@@ -3193,6 +3321,8 @@ retry:
53506 break;
53507 }
53508 out:
53509+ if (!error)
53510+ gr_handle_create(dentry, path.mnt);
53511 done_path_create(&path, dentry);
53512 if (retry_estale(error, lookup_flags)) {
53513 lookup_flags |= LOOKUP_REVAL;
53514@@ -3245,9 +3375,16 @@ retry:
53515
53516 if (!IS_POSIXACL(path.dentry->d_inode))
53517 mode &= ~current_umask();
53518+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
53519+ error = -EACCES;
53520+ goto out;
53521+ }
53522 error = security_path_mkdir(&path, dentry, mode);
53523 if (!error)
53524 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
53525+ if (!error)
53526+ gr_handle_create(dentry, path.mnt);
53527+out:
53528 done_path_create(&path, dentry);
53529 if (retry_estale(error, lookup_flags)) {
53530 lookup_flags |= LOOKUP_REVAL;
53531@@ -3328,6 +3465,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
53532 struct filename *name;
53533 struct dentry *dentry;
53534 struct nameidata nd;
53535+ ino_t saved_ino = 0;
53536+ dev_t saved_dev = 0;
53537 unsigned int lookup_flags = 0;
53538 retry:
53539 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
53540@@ -3360,10 +3499,21 @@ retry:
53541 error = -ENOENT;
53542 goto exit3;
53543 }
53544+
53545+ saved_ino = dentry->d_inode->i_ino;
53546+ saved_dev = gr_get_dev_from_dentry(dentry);
53547+
53548+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
53549+ error = -EACCES;
53550+ goto exit3;
53551+ }
53552+
53553 error = security_path_rmdir(&nd.path, dentry);
53554 if (error)
53555 goto exit3;
53556 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
53557+ if (!error && (saved_dev || saved_ino))
53558+ gr_handle_delete(saved_ino, saved_dev);
53559 exit3:
53560 dput(dentry);
53561 exit2:
53562@@ -3429,6 +3579,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
53563 struct dentry *dentry;
53564 struct nameidata nd;
53565 struct inode *inode = NULL;
53566+ ino_t saved_ino = 0;
53567+ dev_t saved_dev = 0;
53568 unsigned int lookup_flags = 0;
53569 retry:
53570 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
53571@@ -3455,10 +3607,22 @@ retry:
53572 if (!inode)
53573 goto slashes;
53574 ihold(inode);
53575+
53576+ if (inode->i_nlink <= 1) {
53577+ saved_ino = inode->i_ino;
53578+ saved_dev = gr_get_dev_from_dentry(dentry);
53579+ }
53580+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
53581+ error = -EACCES;
53582+ goto exit2;
53583+ }
53584+
53585 error = security_path_unlink(&nd.path, dentry);
53586 if (error)
53587 goto exit2;
53588 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
53589+ if (!error && (saved_ino || saved_dev))
53590+ gr_handle_delete(saved_ino, saved_dev);
53591 exit2:
53592 dput(dentry);
53593 }
53594@@ -3536,9 +3700,17 @@ retry:
53595 if (IS_ERR(dentry))
53596 goto out_putname;
53597
53598+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
53599+ error = -EACCES;
53600+ goto out;
53601+ }
53602+
53603 error = security_path_symlink(&path, dentry, from->name);
53604 if (!error)
53605 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
53606+ if (!error)
53607+ gr_handle_create(dentry, path.mnt);
53608+out:
53609 done_path_create(&path, dentry);
53610 if (retry_estale(error, lookup_flags)) {
53611 lookup_flags |= LOOKUP_REVAL;
53612@@ -3612,6 +3784,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
53613 {
53614 struct dentry *new_dentry;
53615 struct path old_path, new_path;
53616+ struct filename *to = NULL;
53617 int how = 0;
53618 int error;
53619
53620@@ -3635,7 +3808,7 @@ retry:
53621 if (error)
53622 return error;
53623
53624- new_dentry = user_path_create(newdfd, newname, &new_path,
53625+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
53626 (how & LOOKUP_REVAL));
53627 error = PTR_ERR(new_dentry);
53628 if (IS_ERR(new_dentry))
53629@@ -3647,11 +3820,28 @@ retry:
53630 error = may_linkat(&old_path);
53631 if (unlikely(error))
53632 goto out_dput;
53633+
53634+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
53635+ old_path.dentry->d_inode,
53636+ old_path.dentry->d_inode->i_mode, to)) {
53637+ error = -EACCES;
53638+ goto out_dput;
53639+ }
53640+
53641+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
53642+ old_path.dentry, old_path.mnt, to)) {
53643+ error = -EACCES;
53644+ goto out_dput;
53645+ }
53646+
53647 error = security_path_link(old_path.dentry, &new_path, new_dentry);
53648 if (error)
53649 goto out_dput;
53650 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
53651+ if (!error)
53652+ gr_handle_create(new_dentry, new_path.mnt);
53653 out_dput:
53654+ putname(to);
53655 done_path_create(&new_path, new_dentry);
53656 if (retry_estale(error, how)) {
53657 how |= LOOKUP_REVAL;
53658@@ -3897,12 +4087,21 @@ retry:
53659 if (new_dentry == trap)
53660 goto exit5;
53661
53662+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
53663+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
53664+ to);
53665+ if (error)
53666+ goto exit5;
53667+
53668 error = security_path_rename(&oldnd.path, old_dentry,
53669 &newnd.path, new_dentry);
53670 if (error)
53671 goto exit5;
53672 error = vfs_rename(old_dir->d_inode, old_dentry,
53673 new_dir->d_inode, new_dentry);
53674+ if (!error)
53675+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
53676+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
53677 exit5:
53678 dput(new_dentry);
53679 exit4:
53680@@ -3934,6 +4133,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
53681
53682 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
53683 {
53684+ char tmpbuf[64];
53685+ const char *newlink;
53686 int len;
53687
53688 len = PTR_ERR(link);
53689@@ -3943,7 +4144,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
53690 len = strlen(link);
53691 if (len > (unsigned) buflen)
53692 len = buflen;
53693- if (copy_to_user(buffer, link, len))
53694+
53695+ if (len < sizeof(tmpbuf)) {
53696+ memcpy(tmpbuf, link, len);
53697+ newlink = tmpbuf;
53698+ } else
53699+ newlink = link;
53700+
53701+ if (copy_to_user(buffer, newlink, len))
53702 len = -EFAULT;
53703 out:
53704 return len;
53705diff --git a/fs/namespace.c b/fs/namespace.c
53706index e945b81..fc018e2 100644
53707--- a/fs/namespace.c
53708+++ b/fs/namespace.c
53709@@ -1219,6 +1219,9 @@ static int do_umount(struct mount *mnt, int flags)
53710 if (!(sb->s_flags & MS_RDONLY))
53711 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
53712 up_write(&sb->s_umount);
53713+
53714+ gr_log_remount(mnt->mnt_devname, retval);
53715+
53716 return retval;
53717 }
53718
53719@@ -1238,6 +1241,9 @@ static int do_umount(struct mount *mnt, int flags)
53720 br_write_unlock(&vfsmount_lock);
53721 up_write(&namespace_sem);
53722 release_mounts(&umount_list);
53723+
53724+ gr_log_unmount(mnt->mnt_devname, retval);
53725+
53726 return retval;
53727 }
53728
53729@@ -1257,7 +1263,7 @@ static inline bool may_mount(void)
53730 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
53731 */
53732
53733-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
53734+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
53735 {
53736 struct path path;
53737 struct mount *mnt;
53738@@ -1297,7 +1303,7 @@ out:
53739 /*
53740 * The 2.0 compatible umount. No flags.
53741 */
53742-SYSCALL_DEFINE1(oldumount, char __user *, name)
53743+SYSCALL_DEFINE1(oldumount, const char __user *, name)
53744 {
53745 return sys_umount(name, 0);
53746 }
53747@@ -2267,6 +2273,16 @@ long do_mount(const char *dev_name, const char *dir_name,
53748 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
53749 MS_STRICTATIME);
53750
53751+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
53752+ retval = -EPERM;
53753+ goto dput_out;
53754+ }
53755+
53756+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
53757+ retval = -EPERM;
53758+ goto dput_out;
53759+ }
53760+
53761 if (flags & MS_REMOUNT)
53762 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
53763 data_page);
53764@@ -2281,6 +2297,9 @@ long do_mount(const char *dev_name, const char *dir_name,
53765 dev_name, data_page);
53766 dput_out:
53767 path_put(&path);
53768+
53769+ gr_log_mount(dev_name, dir_name, retval);
53770+
53771 return retval;
53772 }
53773
53774@@ -2454,8 +2473,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
53775 }
53776 EXPORT_SYMBOL(mount_subtree);
53777
53778-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
53779- char __user *, type, unsigned long, flags, void __user *, data)
53780+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
53781+ const char __user *, type, unsigned long, flags, void __user *, data)
53782 {
53783 int ret;
53784 char *kernel_type;
53785@@ -2567,6 +2586,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
53786 if (error)
53787 goto out2;
53788
53789+ if (gr_handle_chroot_pivot()) {
53790+ error = -EPERM;
53791+ goto out2;
53792+ }
53793+
53794 get_fs_root(current->fs, &root);
53795 error = lock_mount(&old);
53796 if (error)
53797@@ -2815,7 +2839,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
53798 !nsown_capable(CAP_SYS_ADMIN))
53799 return -EPERM;
53800
53801- if (fs->users != 1)
53802+ if (atomic_read(&fs->users) != 1)
53803 return -EINVAL;
53804
53805 get_mnt_ns(mnt_ns);
53806diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
53807index 59461c9..b17c57e 100644
53808--- a/fs/nfs/callback_xdr.c
53809+++ b/fs/nfs/callback_xdr.c
53810@@ -51,7 +51,7 @@ struct callback_op {
53811 callback_decode_arg_t decode_args;
53812 callback_encode_res_t encode_res;
53813 long res_maxsize;
53814-};
53815+} __do_const;
53816
53817 static struct callback_op callback_ops[];
53818
53819diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
53820index 1f94167..79c4ce4 100644
53821--- a/fs/nfs/inode.c
53822+++ b/fs/nfs/inode.c
53823@@ -1041,16 +1041,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
53824 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
53825 }
53826
53827-static atomic_long_t nfs_attr_generation_counter;
53828+static atomic_long_unchecked_t nfs_attr_generation_counter;
53829
53830 static unsigned long nfs_read_attr_generation_counter(void)
53831 {
53832- return atomic_long_read(&nfs_attr_generation_counter);
53833+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
53834 }
53835
53836 unsigned long nfs_inc_attr_generation_counter(void)
53837 {
53838- return atomic_long_inc_return(&nfs_attr_generation_counter);
53839+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
53840 }
53841
53842 void nfs_fattr_init(struct nfs_fattr *fattr)
53843diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
53844index d401d01..10b3e62 100644
53845--- a/fs/nfsd/nfs4proc.c
53846+++ b/fs/nfsd/nfs4proc.c
53847@@ -1109,7 +1109,7 @@ struct nfsd4_operation {
53848 nfsd4op_rsize op_rsize_bop;
53849 stateid_getter op_get_currentstateid;
53850 stateid_setter op_set_currentstateid;
53851-};
53852+} __do_const;
53853
53854 static struct nfsd4_operation nfsd4_ops[];
53855
53856diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
53857index 6eb0dc5..29067a9 100644
53858--- a/fs/nfsd/nfs4xdr.c
53859+++ b/fs/nfsd/nfs4xdr.c
53860@@ -1457,7 +1457,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
53861
53862 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
53863
53864-static nfsd4_dec nfsd4_dec_ops[] = {
53865+static const nfsd4_dec nfsd4_dec_ops[] = {
53866 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
53867 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
53868 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
53869@@ -1497,7 +1497,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
53870 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
53871 };
53872
53873-static nfsd4_dec nfsd41_dec_ops[] = {
53874+static const nfsd4_dec nfsd41_dec_ops[] = {
53875 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
53876 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
53877 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
53878@@ -1559,7 +1559,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
53879 };
53880
53881 struct nfsd4_minorversion_ops {
53882- nfsd4_dec *decoders;
53883+ const nfsd4_dec *decoders;
53884 int nops;
53885 };
53886
53887diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
53888index ca05f6d..411a576 100644
53889--- a/fs/nfsd/nfscache.c
53890+++ b/fs/nfsd/nfscache.c
53891@@ -461,13 +461,15 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
53892 {
53893 struct svc_cacherep *rp = rqstp->rq_cacherep;
53894 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
53895- int len;
53896+ long len;
53897
53898 if (!rp)
53899 return;
53900
53901- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
53902- len >>= 2;
53903+ if (statp) {
53904+ len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
53905+ len >>= 2;
53906+ }
53907
53908 /* Don't cache excessive amounts of data and XDR failures */
53909 if (!statp || len > (256 >> 2)) {
53910diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
53911index 2b2e239..c915b48 100644
53912--- a/fs/nfsd/vfs.c
53913+++ b/fs/nfsd/vfs.c
53914@@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
53915 } else {
53916 oldfs = get_fs();
53917 set_fs(KERNEL_DS);
53918- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
53919+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
53920 set_fs(oldfs);
53921 }
53922
53923@@ -1026,7 +1026,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
53924
53925 /* Write the data. */
53926 oldfs = get_fs(); set_fs(KERNEL_DS);
53927- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
53928+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
53929 set_fs(oldfs);
53930 if (host_err < 0)
53931 goto out_nfserr;
53932@@ -1572,7 +1572,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
53933 */
53934
53935 oldfs = get_fs(); set_fs(KERNEL_DS);
53936- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
53937+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
53938 set_fs(oldfs);
53939
53940 if (host_err < 0)
53941diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
53942index fea6bd5..8ee9d81 100644
53943--- a/fs/nls/nls_base.c
53944+++ b/fs/nls/nls_base.c
53945@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
53946
53947 int register_nls(struct nls_table * nls)
53948 {
53949- struct nls_table ** tmp = &tables;
53950+ struct nls_table *tmp = tables;
53951
53952 if (nls->next)
53953 return -EBUSY;
53954
53955 spin_lock(&nls_lock);
53956- while (*tmp) {
53957- if (nls == *tmp) {
53958+ while (tmp) {
53959+ if (nls == tmp) {
53960 spin_unlock(&nls_lock);
53961 return -EBUSY;
53962 }
53963- tmp = &(*tmp)->next;
53964+ tmp = tmp->next;
53965 }
53966- nls->next = tables;
53967+ pax_open_kernel();
53968+ *(struct nls_table **)&nls->next = tables;
53969+ pax_close_kernel();
53970 tables = nls;
53971 spin_unlock(&nls_lock);
53972 return 0;
53973@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
53974
53975 int unregister_nls(struct nls_table * nls)
53976 {
53977- struct nls_table ** tmp = &tables;
53978+ struct nls_table * const * tmp = &tables;
53979
53980 spin_lock(&nls_lock);
53981 while (*tmp) {
53982 if (nls == *tmp) {
53983- *tmp = nls->next;
53984+ pax_open_kernel();
53985+ *(struct nls_table **)tmp = nls->next;
53986+ pax_close_kernel();
53987 spin_unlock(&nls_lock);
53988 return 0;
53989 }
53990diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
53991index 7424929..35f6be5 100644
53992--- a/fs/nls/nls_euc-jp.c
53993+++ b/fs/nls/nls_euc-jp.c
53994@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
53995 p_nls = load_nls("cp932");
53996
53997 if (p_nls) {
53998- table.charset2upper = p_nls->charset2upper;
53999- table.charset2lower = p_nls->charset2lower;
54000+ pax_open_kernel();
54001+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
54002+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
54003+ pax_close_kernel();
54004 return register_nls(&table);
54005 }
54006
54007diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
54008index e7bc1d7..06bd4bb 100644
54009--- a/fs/nls/nls_koi8-ru.c
54010+++ b/fs/nls/nls_koi8-ru.c
54011@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
54012 p_nls = load_nls("koi8-u");
54013
54014 if (p_nls) {
54015- table.charset2upper = p_nls->charset2upper;
54016- table.charset2lower = p_nls->charset2lower;
54017+ pax_open_kernel();
54018+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
54019+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
54020+ pax_close_kernel();
54021 return register_nls(&table);
54022 }
54023
54024diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
54025index 5d84442..2c034ba 100644
54026--- a/fs/notify/fanotify/fanotify_user.c
54027+++ b/fs/notify/fanotify/fanotify_user.c
54028@@ -121,6 +121,7 @@ static int fill_event_metadata(struct fsnotify_group *group,
54029 metadata->event_len = FAN_EVENT_METADATA_LEN;
54030 metadata->metadata_len = FAN_EVENT_METADATA_LEN;
54031 metadata->vers = FANOTIFY_METADATA_VERSION;
54032+ metadata->reserved = 0;
54033 metadata->mask = event->mask & FAN_ALL_OUTGOING_EVENTS;
54034 metadata->pid = pid_vnr(event->tgid);
54035 if (unlikely(event->mask & FAN_Q_OVERFLOW))
54036@@ -251,8 +252,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
54037
54038 fd = fanotify_event_metadata.fd;
54039 ret = -EFAULT;
54040- if (copy_to_user(buf, &fanotify_event_metadata,
54041- fanotify_event_metadata.event_len))
54042+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
54043+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
54044 goto out_close_fd;
54045
54046 ret = prepare_for_access_response(group, event, fd);
54047diff --git a/fs/notify/notification.c b/fs/notify/notification.c
54048index 7b51b05..5ea5ef6 100644
54049--- a/fs/notify/notification.c
54050+++ b/fs/notify/notification.c
54051@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
54052 * get set to 0 so it will never get 'freed'
54053 */
54054 static struct fsnotify_event *q_overflow_event;
54055-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54056+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54057
54058 /**
54059 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
54060@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54061 */
54062 u32 fsnotify_get_cookie(void)
54063 {
54064- return atomic_inc_return(&fsnotify_sync_cookie);
54065+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
54066 }
54067 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
54068
54069diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
54070index aa411c3..c260a84 100644
54071--- a/fs/ntfs/dir.c
54072+++ b/fs/ntfs/dir.c
54073@@ -1329,7 +1329,7 @@ find_next_index_buffer:
54074 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
54075 ~(s64)(ndir->itype.index.block_size - 1)));
54076 /* Bounds checks. */
54077- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
54078+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
54079 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
54080 "inode 0x%lx or driver bug.", vdir->i_ino);
54081 goto err_out;
54082diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
54083index 5b2d4f0..c6de396 100644
54084--- a/fs/ntfs/file.c
54085+++ b/fs/ntfs/file.c
54086@@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
54087 #endif /* NTFS_RW */
54088 };
54089
54090-const struct file_operations ntfs_empty_file_ops = {};
54091+const struct file_operations ntfs_empty_file_ops __read_only;
54092
54093-const struct inode_operations ntfs_empty_inode_ops = {};
54094+const struct inode_operations ntfs_empty_inode_ops __read_only;
54095diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
54096index aebeacd..0dcdd26 100644
54097--- a/fs/ocfs2/localalloc.c
54098+++ b/fs/ocfs2/localalloc.c
54099@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
54100 goto bail;
54101 }
54102
54103- atomic_inc(&osb->alloc_stats.moves);
54104+ atomic_inc_unchecked(&osb->alloc_stats.moves);
54105
54106 bail:
54107 if (handle)
54108diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
54109index d355e6e..578d905 100644
54110--- a/fs/ocfs2/ocfs2.h
54111+++ b/fs/ocfs2/ocfs2.h
54112@@ -235,11 +235,11 @@ enum ocfs2_vol_state
54113
54114 struct ocfs2_alloc_stats
54115 {
54116- atomic_t moves;
54117- atomic_t local_data;
54118- atomic_t bitmap_data;
54119- atomic_t bg_allocs;
54120- atomic_t bg_extends;
54121+ atomic_unchecked_t moves;
54122+ atomic_unchecked_t local_data;
54123+ atomic_unchecked_t bitmap_data;
54124+ atomic_unchecked_t bg_allocs;
54125+ atomic_unchecked_t bg_extends;
54126 };
54127
54128 enum ocfs2_local_alloc_state
54129diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
54130index b7e74b5..19c6536 100644
54131--- a/fs/ocfs2/suballoc.c
54132+++ b/fs/ocfs2/suballoc.c
54133@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
54134 mlog_errno(status);
54135 goto bail;
54136 }
54137- atomic_inc(&osb->alloc_stats.bg_extends);
54138+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
54139
54140 /* You should never ask for this much metadata */
54141 BUG_ON(bits_wanted >
54142@@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
54143 mlog_errno(status);
54144 goto bail;
54145 }
54146- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54147+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54148
54149 *suballoc_loc = res.sr_bg_blkno;
54150 *suballoc_bit_start = res.sr_bit_offset;
54151@@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
54152 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
54153 res->sr_bits);
54154
54155- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54156+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54157
54158 BUG_ON(res->sr_bits != 1);
54159
54160@@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
54161 mlog_errno(status);
54162 goto bail;
54163 }
54164- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54165+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54166
54167 BUG_ON(res.sr_bits != 1);
54168
54169@@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
54170 cluster_start,
54171 num_clusters);
54172 if (!status)
54173- atomic_inc(&osb->alloc_stats.local_data);
54174+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
54175 } else {
54176 if (min_clusters > (osb->bitmap_cpg - 1)) {
54177 /* The only paths asking for contiguousness
54178@@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
54179 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
54180 res.sr_bg_blkno,
54181 res.sr_bit_offset);
54182- atomic_inc(&osb->alloc_stats.bitmap_data);
54183+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
54184 *num_clusters = res.sr_bits;
54185 }
54186 }
54187diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
54188index 01b8516..579c4df 100644
54189--- a/fs/ocfs2/super.c
54190+++ b/fs/ocfs2/super.c
54191@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
54192 "%10s => GlobalAllocs: %d LocalAllocs: %d "
54193 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
54194 "Stats",
54195- atomic_read(&osb->alloc_stats.bitmap_data),
54196- atomic_read(&osb->alloc_stats.local_data),
54197- atomic_read(&osb->alloc_stats.bg_allocs),
54198- atomic_read(&osb->alloc_stats.moves),
54199- atomic_read(&osb->alloc_stats.bg_extends));
54200+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
54201+ atomic_read_unchecked(&osb->alloc_stats.local_data),
54202+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
54203+ atomic_read_unchecked(&osb->alloc_stats.moves),
54204+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
54205
54206 out += snprintf(buf + out, len - out,
54207 "%10s => State: %u Descriptor: %llu Size: %u bits "
54208@@ -2122,11 +2122,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
54209 spin_lock_init(&osb->osb_xattr_lock);
54210 ocfs2_init_steal_slots(osb);
54211
54212- atomic_set(&osb->alloc_stats.moves, 0);
54213- atomic_set(&osb->alloc_stats.local_data, 0);
54214- atomic_set(&osb->alloc_stats.bitmap_data, 0);
54215- atomic_set(&osb->alloc_stats.bg_allocs, 0);
54216- atomic_set(&osb->alloc_stats.bg_extends, 0);
54217+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
54218+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
54219+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
54220+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
54221+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
54222
54223 /* Copy the blockcheck stats from the superblock probe */
54224 osb->osb_ecc_stats = *stats;
54225diff --git a/fs/open.c b/fs/open.c
54226index 6835446..eadf09f 100644
54227--- a/fs/open.c
54228+++ b/fs/open.c
54229@@ -32,6 +32,8 @@
54230 #include <linux/dnotify.h>
54231 #include <linux/compat.h>
54232
54233+#define CREATE_TRACE_POINTS
54234+#include <trace/events/fs.h>
54235 #include "internal.h"
54236
54237 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
54238@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
54239 error = locks_verify_truncate(inode, NULL, length);
54240 if (!error)
54241 error = security_path_truncate(path);
54242+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
54243+ error = -EACCES;
54244 if (!error)
54245 error = do_truncate(path->dentry, length, 0, NULL);
54246
54247@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
54248 error = locks_verify_truncate(inode, f.file, length);
54249 if (!error)
54250 error = security_path_truncate(&f.file->f_path);
54251+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
54252+ error = -EACCES;
54253 if (!error)
54254 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
54255 sb_end_write(inode->i_sb);
54256@@ -388,6 +394,9 @@ retry:
54257 if (__mnt_is_readonly(path.mnt))
54258 res = -EROFS;
54259
54260+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
54261+ res = -EACCES;
54262+
54263 out_path_release:
54264 path_put(&path);
54265 if (retry_estale(res, lookup_flags)) {
54266@@ -419,6 +428,8 @@ retry:
54267 if (error)
54268 goto dput_and_out;
54269
54270+ gr_log_chdir(path.dentry, path.mnt);
54271+
54272 set_fs_pwd(current->fs, &path);
54273
54274 dput_and_out:
54275@@ -448,6 +459,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
54276 goto out_putf;
54277
54278 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
54279+
54280+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
54281+ error = -EPERM;
54282+
54283+ if (!error)
54284+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
54285+
54286 if (!error)
54287 set_fs_pwd(current->fs, &f.file->f_path);
54288 out_putf:
54289@@ -477,7 +495,13 @@ retry:
54290 if (error)
54291 goto dput_and_out;
54292
54293+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
54294+ goto dput_and_out;
54295+
54296 set_fs_root(current->fs, &path);
54297+
54298+ gr_handle_chroot_chdir(&path);
54299+
54300 error = 0;
54301 dput_and_out:
54302 path_put(&path);
54303@@ -499,6 +523,16 @@ static int chmod_common(struct path *path, umode_t mode)
54304 if (error)
54305 return error;
54306 mutex_lock(&inode->i_mutex);
54307+
54308+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
54309+ error = -EACCES;
54310+ goto out_unlock;
54311+ }
54312+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
54313+ error = -EACCES;
54314+ goto out_unlock;
54315+ }
54316+
54317 error = security_path_chmod(path, mode);
54318 if (error)
54319 goto out_unlock;
54320@@ -559,6 +593,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
54321 uid = make_kuid(current_user_ns(), user);
54322 gid = make_kgid(current_user_ns(), group);
54323
54324+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
54325+ return -EACCES;
54326+
54327 newattrs.ia_valid = ATTR_CTIME;
54328 if (user != (uid_t) -1) {
54329 if (!uid_valid(uid))
54330@@ -974,6 +1011,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
54331 } else {
54332 fsnotify_open(f);
54333 fd_install(fd, f);
54334+ trace_do_sys_open(tmp->name, flags, mode);
54335 }
54336 }
54337 putname(tmp);
54338diff --git a/fs/pipe.c b/fs/pipe.c
54339index 2234f3f..f9083a1 100644
54340--- a/fs/pipe.c
54341+++ b/fs/pipe.c
54342@@ -438,9 +438,9 @@ redo:
54343 }
54344 if (bufs) /* More to do? */
54345 continue;
54346- if (!pipe->writers)
54347+ if (!atomic_read(&pipe->writers))
54348 break;
54349- if (!pipe->waiting_writers) {
54350+ if (!atomic_read(&pipe->waiting_writers)) {
54351 /* syscall merging: Usually we must not sleep
54352 * if O_NONBLOCK is set, or if we got some data.
54353 * But if a writer sleeps in kernel space, then
54354@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
54355 mutex_lock(&inode->i_mutex);
54356 pipe = inode->i_pipe;
54357
54358- if (!pipe->readers) {
54359+ if (!atomic_read(&pipe->readers)) {
54360 send_sig(SIGPIPE, current, 0);
54361 ret = -EPIPE;
54362 goto out;
54363@@ -553,7 +553,7 @@ redo1:
54364 for (;;) {
54365 int bufs;
54366
54367- if (!pipe->readers) {
54368+ if (!atomic_read(&pipe->readers)) {
54369 send_sig(SIGPIPE, current, 0);
54370 if (!ret)
54371 ret = -EPIPE;
54372@@ -644,9 +644,9 @@ redo2:
54373 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54374 do_wakeup = 0;
54375 }
54376- pipe->waiting_writers++;
54377+ atomic_inc(&pipe->waiting_writers);
54378 pipe_wait(pipe);
54379- pipe->waiting_writers--;
54380+ atomic_dec(&pipe->waiting_writers);
54381 }
54382 out:
54383 mutex_unlock(&inode->i_mutex);
54384@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54385 mask = 0;
54386 if (filp->f_mode & FMODE_READ) {
54387 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
54388- if (!pipe->writers && filp->f_version != pipe->w_counter)
54389+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
54390 mask |= POLLHUP;
54391 }
54392
54393@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54394 * Most Unices do not set POLLERR for FIFOs but on Linux they
54395 * behave exactly like pipes for poll().
54396 */
54397- if (!pipe->readers)
54398+ if (!atomic_read(&pipe->readers))
54399 mask |= POLLERR;
54400 }
54401
54402@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
54403
54404 mutex_lock(&inode->i_mutex);
54405 pipe = inode->i_pipe;
54406- pipe->readers -= decr;
54407- pipe->writers -= decw;
54408+ atomic_sub(decr, &pipe->readers);
54409+ atomic_sub(decw, &pipe->writers);
54410
54411- if (!pipe->readers && !pipe->writers) {
54412+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
54413 free_pipe_info(inode);
54414 } else {
54415 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
54416@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
54417
54418 if (inode->i_pipe) {
54419 ret = 0;
54420- inode->i_pipe->readers++;
54421+ atomic_inc(&inode->i_pipe->readers);
54422 }
54423
54424 mutex_unlock(&inode->i_mutex);
54425@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
54426
54427 if (inode->i_pipe) {
54428 ret = 0;
54429- inode->i_pipe->writers++;
54430+ atomic_inc(&inode->i_pipe->writers);
54431 }
54432
54433 mutex_unlock(&inode->i_mutex);
54434@@ -871,9 +871,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
54435 if (inode->i_pipe) {
54436 ret = 0;
54437 if (filp->f_mode & FMODE_READ)
54438- inode->i_pipe->readers++;
54439+ atomic_inc(&inode->i_pipe->readers);
54440 if (filp->f_mode & FMODE_WRITE)
54441- inode->i_pipe->writers++;
54442+ atomic_inc(&inode->i_pipe->writers);
54443 }
54444
54445 mutex_unlock(&inode->i_mutex);
54446@@ -965,7 +965,7 @@ void free_pipe_info(struct inode *inode)
54447 inode->i_pipe = NULL;
54448 }
54449
54450-static struct vfsmount *pipe_mnt __read_mostly;
54451+struct vfsmount *pipe_mnt __read_mostly;
54452
54453 /*
54454 * pipefs_dname() is called from d_path().
54455@@ -995,7 +995,8 @@ static struct inode * get_pipe_inode(void)
54456 goto fail_iput;
54457 inode->i_pipe = pipe;
54458
54459- pipe->readers = pipe->writers = 1;
54460+ atomic_set(&pipe->readers, 1);
54461+ atomic_set(&pipe->writers, 1);
54462 inode->i_fop = &rdwr_pipefifo_fops;
54463
54464 /*
54465diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
54466index 15af622..0e9f4467 100644
54467--- a/fs/proc/Kconfig
54468+++ b/fs/proc/Kconfig
54469@@ -30,12 +30,12 @@ config PROC_FS
54470
54471 config PROC_KCORE
54472 bool "/proc/kcore support" if !ARM
54473- depends on PROC_FS && MMU
54474+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
54475
54476 config PROC_VMCORE
54477 bool "/proc/vmcore support"
54478- depends on PROC_FS && CRASH_DUMP
54479- default y
54480+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
54481+ default n
54482 help
54483 Exports the dump image of crashed kernel in ELF format.
54484
54485@@ -59,8 +59,8 @@ config PROC_SYSCTL
54486 limited in memory.
54487
54488 config PROC_PAGE_MONITOR
54489- default y
54490- depends on PROC_FS && MMU
54491+ default n
54492+ depends on PROC_FS && MMU && !GRKERNSEC
54493 bool "Enable /proc page monitoring" if EXPERT
54494 help
54495 Various /proc files exist to monitor process memory utilization:
54496diff --git a/fs/proc/array.c b/fs/proc/array.c
54497index cbd0f1b..adec3f0 100644
54498--- a/fs/proc/array.c
54499+++ b/fs/proc/array.c
54500@@ -60,6 +60,7 @@
54501 #include <linux/tty.h>
54502 #include <linux/string.h>
54503 #include <linux/mman.h>
54504+#include <linux/grsecurity.h>
54505 #include <linux/proc_fs.h>
54506 #include <linux/ioport.h>
54507 #include <linux/uaccess.h>
54508@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
54509 seq_putc(m, '\n');
54510 }
54511
54512+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54513+static inline void task_pax(struct seq_file *m, struct task_struct *p)
54514+{
54515+ if (p->mm)
54516+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
54517+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
54518+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
54519+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
54520+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
54521+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
54522+ else
54523+ seq_printf(m, "PaX:\t-----\n");
54524+}
54525+#endif
54526+
54527 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54528 struct pid *pid, struct task_struct *task)
54529 {
54530@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54531 task_cpus_allowed(m, task);
54532 cpuset_task_status_allowed(m, task);
54533 task_context_switch_counts(m, task);
54534+
54535+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54536+ task_pax(m, task);
54537+#endif
54538+
54539+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
54540+ task_grsec_rbac(m, task);
54541+#endif
54542+
54543 return 0;
54544 }
54545
54546+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54547+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
54548+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
54549+ _mm->pax_flags & MF_PAX_SEGMEXEC))
54550+#endif
54551+
54552 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54553 struct pid *pid, struct task_struct *task, int whole)
54554 {
54555@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54556 char tcomm[sizeof(task->comm)];
54557 unsigned long flags;
54558
54559+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54560+ if (current->exec_id != m->exec_id) {
54561+ gr_log_badprocpid("stat");
54562+ return 0;
54563+ }
54564+#endif
54565+
54566 state = *get_task_state(task);
54567 vsize = eip = esp = 0;
54568 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
54569@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54570 gtime = task_gtime(task);
54571 }
54572
54573+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54574+ if (PAX_RAND_FLAGS(mm)) {
54575+ eip = 0;
54576+ esp = 0;
54577+ wchan = 0;
54578+ }
54579+#endif
54580+#ifdef CONFIG_GRKERNSEC_HIDESYM
54581+ wchan = 0;
54582+ eip =0;
54583+ esp =0;
54584+#endif
54585+
54586 /* scale priority and nice values from timeslices to -20..20 */
54587 /* to make it look like a "normal" Unix priority/nice value */
54588 priority = task_prio(task);
54589@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54590 seq_put_decimal_ull(m, ' ', vsize);
54591 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
54592 seq_put_decimal_ull(m, ' ', rsslim);
54593+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54594+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
54595+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
54596+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
54597+#else
54598 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
54599 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
54600 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
54601+#endif
54602 seq_put_decimal_ull(m, ' ', esp);
54603 seq_put_decimal_ull(m, ' ', eip);
54604 /* The signal information here is obsolete.
54605@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54606 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
54607 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
54608
54609- if (mm && permitted) {
54610+ if (mm && permitted
54611+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54612+ && !PAX_RAND_FLAGS(mm)
54613+#endif
54614+ ) {
54615 seq_put_decimal_ull(m, ' ', mm->start_data);
54616 seq_put_decimal_ull(m, ' ', mm->end_data);
54617 seq_put_decimal_ull(m, ' ', mm->start_brk);
54618@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
54619 struct pid *pid, struct task_struct *task)
54620 {
54621 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
54622- struct mm_struct *mm = get_task_mm(task);
54623+ struct mm_struct *mm;
54624
54625+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54626+ if (current->exec_id != m->exec_id) {
54627+ gr_log_badprocpid("statm");
54628+ return 0;
54629+ }
54630+#endif
54631+ mm = get_task_mm(task);
54632 if (mm) {
54633 size = task_statm(mm, &shared, &text, &data, &resident);
54634 mmput(mm);
54635@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
54636 return 0;
54637 }
54638
54639+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54640+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
54641+{
54642+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
54643+}
54644+#endif
54645+
54646 #ifdef CONFIG_CHECKPOINT_RESTORE
54647 static struct pid *
54648 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
54649diff --git a/fs/proc/base.c b/fs/proc/base.c
54650index 69078c7..3e12a75 100644
54651--- a/fs/proc/base.c
54652+++ b/fs/proc/base.c
54653@@ -112,6 +112,14 @@ struct pid_entry {
54654 union proc_op op;
54655 };
54656
54657+struct getdents_callback {
54658+ struct linux_dirent __user * current_dir;
54659+ struct linux_dirent __user * previous;
54660+ struct file * file;
54661+ int count;
54662+ int error;
54663+};
54664+
54665 #define NOD(NAME, MODE, IOP, FOP, OP) { \
54666 .name = (NAME), \
54667 .len = sizeof(NAME) - 1, \
54668@@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
54669 if (!mm->arg_end)
54670 goto out_mm; /* Shh! No looking before we're done */
54671
54672+ if (gr_acl_handle_procpidmem(task))
54673+ goto out_mm;
54674+
54675 len = mm->arg_end - mm->arg_start;
54676
54677 if (len > PAGE_SIZE)
54678@@ -236,12 +247,28 @@ out:
54679 return res;
54680 }
54681
54682+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54683+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
54684+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
54685+ _mm->pax_flags & MF_PAX_SEGMEXEC))
54686+#endif
54687+
54688 static int proc_pid_auxv(struct task_struct *task, char *buffer)
54689 {
54690 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
54691 int res = PTR_ERR(mm);
54692 if (mm && !IS_ERR(mm)) {
54693 unsigned int nwords = 0;
54694+
54695+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54696+ /* allow if we're currently ptracing this task */
54697+ if (PAX_RAND_FLAGS(mm) &&
54698+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
54699+ mmput(mm);
54700+ return 0;
54701+ }
54702+#endif
54703+
54704 do {
54705 nwords += 2;
54706 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
54707@@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
54708 }
54709
54710
54711-#ifdef CONFIG_KALLSYMS
54712+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54713 /*
54714 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
54715 * Returns the resolved symbol. If that fails, simply return the address.
54716@@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
54717 mutex_unlock(&task->signal->cred_guard_mutex);
54718 }
54719
54720-#ifdef CONFIG_STACKTRACE
54721+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54722
54723 #define MAX_STACK_TRACE_DEPTH 64
54724
54725@@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
54726 return count;
54727 }
54728
54729-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54730+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54731 static int proc_pid_syscall(struct task_struct *task, char *buffer)
54732 {
54733 long nr;
54734@@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
54735 /************************************************************************/
54736
54737 /* permission checks */
54738-static int proc_fd_access_allowed(struct inode *inode)
54739+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
54740 {
54741 struct task_struct *task;
54742 int allowed = 0;
54743@@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
54744 */
54745 task = get_proc_task(inode);
54746 if (task) {
54747- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
54748+ if (log)
54749+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
54750+ else
54751+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
54752 put_task_struct(task);
54753 }
54754 return allowed;
54755@@ -556,10 +586,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
54756 struct task_struct *task,
54757 int hide_pid_min)
54758 {
54759+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54760+ return false;
54761+
54762+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54763+ rcu_read_lock();
54764+ {
54765+ const struct cred *tmpcred = current_cred();
54766+ const struct cred *cred = __task_cred(task);
54767+
54768+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
54769+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54770+ || in_group_p(grsec_proc_gid)
54771+#endif
54772+ ) {
54773+ rcu_read_unlock();
54774+ return true;
54775+ }
54776+ }
54777+ rcu_read_unlock();
54778+
54779+ if (!pid->hide_pid)
54780+ return false;
54781+#endif
54782+
54783 if (pid->hide_pid < hide_pid_min)
54784 return true;
54785 if (in_group_p(pid->pid_gid))
54786 return true;
54787+
54788 return ptrace_may_access(task, PTRACE_MODE_READ);
54789 }
54790
54791@@ -577,7 +632,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
54792 put_task_struct(task);
54793
54794 if (!has_perms) {
54795+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54796+ {
54797+#else
54798 if (pid->hide_pid == 2) {
54799+#endif
54800 /*
54801 * Let's make getdents(), stat(), and open()
54802 * consistent with each other. If a process
54803@@ -675,6 +734,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
54804 if (!task)
54805 return -ESRCH;
54806
54807+ if (gr_acl_handle_procpidmem(task)) {
54808+ put_task_struct(task);
54809+ return -EPERM;
54810+ }
54811+
54812 mm = mm_access(task, mode);
54813 put_task_struct(task);
54814
54815@@ -690,6 +754,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
54816
54817 file->private_data = mm;
54818
54819+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54820+ file->f_version = current->exec_id;
54821+#endif
54822+
54823 return 0;
54824 }
54825
54826@@ -711,6 +779,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
54827 ssize_t copied;
54828 char *page;
54829
54830+#ifdef CONFIG_GRKERNSEC
54831+ if (write)
54832+ return -EPERM;
54833+#endif
54834+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54835+ if (file->f_version != current->exec_id) {
54836+ gr_log_badprocpid("mem");
54837+ return 0;
54838+ }
54839+#endif
54840+
54841 if (!mm)
54842 return 0;
54843
54844@@ -723,7 +802,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
54845 goto free;
54846
54847 while (count > 0) {
54848- int this_len = min_t(int, count, PAGE_SIZE);
54849+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
54850
54851 if (write && copy_from_user(page, buf, this_len)) {
54852 copied = -EFAULT;
54853@@ -815,6 +894,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
54854 if (!mm)
54855 return 0;
54856
54857+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54858+ if (file->f_version != current->exec_id) {
54859+ gr_log_badprocpid("environ");
54860+ return 0;
54861+ }
54862+#endif
54863+
54864 page = (char *)__get_free_page(GFP_TEMPORARY);
54865 if (!page)
54866 return -ENOMEM;
54867@@ -824,7 +910,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
54868 goto free;
54869 while (count > 0) {
54870 size_t this_len, max_len;
54871- int retval;
54872+ ssize_t retval;
54873
54874 if (src >= (mm->env_end - mm->env_start))
54875 break;
54876@@ -1430,7 +1516,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
54877 int error = -EACCES;
54878
54879 /* Are we allowed to snoop on the tasks file descriptors? */
54880- if (!proc_fd_access_allowed(inode))
54881+ if (!proc_fd_access_allowed(inode, 0))
54882 goto out;
54883
54884 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
54885@@ -1474,8 +1560,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
54886 struct path path;
54887
54888 /* Are we allowed to snoop on the tasks file descriptors? */
54889- if (!proc_fd_access_allowed(inode))
54890- goto out;
54891+ /* logging this is needed for learning on chromium to work properly,
54892+ but we don't want to flood the logs from 'ps' which does a readlink
54893+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
54894+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
54895+ */
54896+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
54897+ if (!proc_fd_access_allowed(inode,0))
54898+ goto out;
54899+ } else {
54900+ if (!proc_fd_access_allowed(inode,1))
54901+ goto out;
54902+ }
54903
54904 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
54905 if (error)
54906@@ -1525,7 +1621,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
54907 rcu_read_lock();
54908 cred = __task_cred(task);
54909 inode->i_uid = cred->euid;
54910+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54911+ inode->i_gid = grsec_proc_gid;
54912+#else
54913 inode->i_gid = cred->egid;
54914+#endif
54915 rcu_read_unlock();
54916 }
54917 security_task_to_inode(task, inode);
54918@@ -1561,10 +1661,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
54919 return -ENOENT;
54920 }
54921 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
54922+#ifdef CONFIG_GRKERNSEC_PROC_USER
54923+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
54924+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54925+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
54926+#endif
54927 task_dumpable(task)) {
54928 cred = __task_cred(task);
54929 stat->uid = cred->euid;
54930+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54931+ stat->gid = grsec_proc_gid;
54932+#else
54933 stat->gid = cred->egid;
54934+#endif
54935 }
54936 }
54937 rcu_read_unlock();
54938@@ -1602,11 +1711,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
54939
54940 if (task) {
54941 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
54942+#ifdef CONFIG_GRKERNSEC_PROC_USER
54943+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
54944+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54945+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
54946+#endif
54947 task_dumpable(task)) {
54948 rcu_read_lock();
54949 cred = __task_cred(task);
54950 inode->i_uid = cred->euid;
54951+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54952+ inode->i_gid = grsec_proc_gid;
54953+#else
54954 inode->i_gid = cred->egid;
54955+#endif
54956 rcu_read_unlock();
54957 } else {
54958 inode->i_uid = GLOBAL_ROOT_UID;
54959@@ -2059,6 +2177,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
54960 if (!task)
54961 goto out_no_task;
54962
54963+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54964+ goto out;
54965+
54966 /*
54967 * Yes, it does not scale. And it should not. Don't add
54968 * new entries into /proc/<tgid>/ without very good reasons.
54969@@ -2103,6 +2224,9 @@ static int proc_pident_readdir(struct file *filp,
54970 if (!task)
54971 goto out_no_task;
54972
54973+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54974+ goto out;
54975+
54976 ret = 0;
54977 i = filp->f_pos;
54978 switch (i) {
54979@@ -2516,7 +2640,7 @@ static const struct pid_entry tgid_base_stuff[] = {
54980 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
54981 #endif
54982 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
54983-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54984+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54985 INF("syscall", S_IRUGO, proc_pid_syscall),
54986 #endif
54987 INF("cmdline", S_IRUGO, proc_pid_cmdline),
54988@@ -2541,10 +2665,10 @@ static const struct pid_entry tgid_base_stuff[] = {
54989 #ifdef CONFIG_SECURITY
54990 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
54991 #endif
54992-#ifdef CONFIG_KALLSYMS
54993+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54994 INF("wchan", S_IRUGO, proc_pid_wchan),
54995 #endif
54996-#ifdef CONFIG_STACKTRACE
54997+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54998 ONE("stack", S_IRUGO, proc_pid_stack),
54999 #endif
55000 #ifdef CONFIG_SCHEDSTATS
55001@@ -2578,6 +2702,9 @@ static const struct pid_entry tgid_base_stuff[] = {
55002 #ifdef CONFIG_HARDWALL
55003 INF("hardwall", S_IRUGO, proc_pid_hardwall),
55004 #endif
55005+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55006+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
55007+#endif
55008 #ifdef CONFIG_USER_NS
55009 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
55010 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
55011@@ -2707,7 +2834,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
55012 if (!inode)
55013 goto out;
55014
55015+#ifdef CONFIG_GRKERNSEC_PROC_USER
55016+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
55017+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55018+ inode->i_gid = grsec_proc_gid;
55019+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
55020+#else
55021 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
55022+#endif
55023 inode->i_op = &proc_tgid_base_inode_operations;
55024 inode->i_fop = &proc_tgid_base_operations;
55025 inode->i_flags|=S_IMMUTABLE;
55026@@ -2745,7 +2879,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
55027 if (!task)
55028 goto out;
55029
55030+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55031+ goto out_put_task;
55032+
55033 result = proc_pid_instantiate(dir, dentry, task, NULL);
55034+out_put_task:
55035 put_task_struct(task);
55036 out:
55037 return result;
55038@@ -2808,6 +2946,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
55039 static int fake_filldir(void *buf, const char *name, int namelen,
55040 loff_t offset, u64 ino, unsigned d_type)
55041 {
55042+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
55043+ __buf->error = -EINVAL;
55044 return 0;
55045 }
55046
55047@@ -2859,7 +2999,7 @@ static const struct pid_entry tid_base_stuff[] = {
55048 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
55049 #endif
55050 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
55051-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55052+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55053 INF("syscall", S_IRUGO, proc_pid_syscall),
55054 #endif
55055 INF("cmdline", S_IRUGO, proc_pid_cmdline),
55056@@ -2886,10 +3026,10 @@ static const struct pid_entry tid_base_stuff[] = {
55057 #ifdef CONFIG_SECURITY
55058 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
55059 #endif
55060-#ifdef CONFIG_KALLSYMS
55061+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55062 INF("wchan", S_IRUGO, proc_pid_wchan),
55063 #endif
55064-#ifdef CONFIG_STACKTRACE
55065+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55066 ONE("stack", S_IRUGO, proc_pid_stack),
55067 #endif
55068 #ifdef CONFIG_SCHEDSTATS
55069diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
55070index 82676e3..5f8518a 100644
55071--- a/fs/proc/cmdline.c
55072+++ b/fs/proc/cmdline.c
55073@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
55074
55075 static int __init proc_cmdline_init(void)
55076 {
55077+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55078+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
55079+#else
55080 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
55081+#endif
55082 return 0;
55083 }
55084 module_init(proc_cmdline_init);
55085diff --git a/fs/proc/devices.c b/fs/proc/devices.c
55086index b143471..bb105e5 100644
55087--- a/fs/proc/devices.c
55088+++ b/fs/proc/devices.c
55089@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
55090
55091 static int __init proc_devices_init(void)
55092 {
55093+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55094+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
55095+#else
55096 proc_create("devices", 0, NULL, &proc_devinfo_operations);
55097+#endif
55098 return 0;
55099 }
55100 module_init(proc_devices_init);
55101diff --git a/fs/proc/fd.c b/fs/proc/fd.c
55102index d7a4a28..0201742 100644
55103--- a/fs/proc/fd.c
55104+++ b/fs/proc/fd.c
55105@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
55106 if (!task)
55107 return -ENOENT;
55108
55109- files = get_files_struct(task);
55110+ if (!gr_acl_handle_procpidmem(task))
55111+ files = get_files_struct(task);
55112 put_task_struct(task);
55113
55114 if (files) {
55115@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
55116 */
55117 int proc_fd_permission(struct inode *inode, int mask)
55118 {
55119+ struct task_struct *task;
55120 int rv = generic_permission(inode, mask);
55121- if (rv == 0)
55122- return 0;
55123+
55124 if (task_pid(current) == proc_pid(inode))
55125 rv = 0;
55126+
55127+ task = get_proc_task(inode);
55128+ if (task == NULL)
55129+ return rv;
55130+
55131+ if (gr_acl_handle_procpidmem(task))
55132+ rv = -EACCES;
55133+
55134+ put_task_struct(task);
55135+
55136 return rv;
55137 }
55138
55139diff --git a/fs/proc/inode.c b/fs/proc/inode.c
55140index 869116c..820cb27 100644
55141--- a/fs/proc/inode.c
55142+++ b/fs/proc/inode.c
55143@@ -22,11 +22,17 @@
55144 #include <linux/seq_file.h>
55145 #include <linux/slab.h>
55146 #include <linux/mount.h>
55147+#include <linux/grsecurity.h>
55148
55149 #include <asm/uaccess.h>
55150
55151 #include "internal.h"
55152
55153+#ifdef CONFIG_PROC_SYSCTL
55154+extern const struct inode_operations proc_sys_inode_operations;
55155+extern const struct inode_operations proc_sys_dir_operations;
55156+#endif
55157+
55158 static void proc_evict_inode(struct inode *inode)
55159 {
55160 struct proc_dir_entry *de;
55161@@ -54,6 +60,13 @@ static void proc_evict_inode(struct inode *inode)
55162 ns = PROC_I(inode)->ns;
55163 if (ns_ops && ns)
55164 ns_ops->put(ns);
55165+
55166+#ifdef CONFIG_PROC_SYSCTL
55167+ if (inode->i_op == &proc_sys_inode_operations ||
55168+ inode->i_op == &proc_sys_dir_operations)
55169+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
55170+#endif
55171+
55172 }
55173
55174 static struct kmem_cache * proc_inode_cachep;
55175@@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
55176 if (de->mode) {
55177 inode->i_mode = de->mode;
55178 inode->i_uid = de->uid;
55179+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55180+ inode->i_gid = grsec_proc_gid;
55181+#else
55182 inode->i_gid = de->gid;
55183+#endif
55184 }
55185 if (de->size)
55186 inode->i_size = de->size;
55187diff --git a/fs/proc/internal.h b/fs/proc/internal.h
55188index 85ff3a4..a512bd8 100644
55189--- a/fs/proc/internal.h
55190+++ b/fs/proc/internal.h
55191@@ -56,6 +56,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55192 struct pid *pid, struct task_struct *task);
55193 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55194 struct pid *pid, struct task_struct *task);
55195+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55196+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
55197+#endif
55198 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
55199
55200 extern const struct file_operations proc_tid_children_operations;
55201diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
55202index eda6f01..006ae24 100644
55203--- a/fs/proc/kcore.c
55204+++ b/fs/proc/kcore.c
55205@@ -481,9 +481,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55206 * the addresses in the elf_phdr on our list.
55207 */
55208 start = kc_offset_to_vaddr(*fpos - elf_buflen);
55209- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
55210+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
55211+ if (tsz > buflen)
55212 tsz = buflen;
55213-
55214+
55215 while (buflen) {
55216 struct kcore_list *m;
55217
55218@@ -512,20 +513,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55219 kfree(elf_buf);
55220 } else {
55221 if (kern_addr_valid(start)) {
55222- unsigned long n;
55223+ char *elf_buf;
55224+ mm_segment_t oldfs;
55225
55226- n = copy_to_user(buffer, (char *)start, tsz);
55227- /*
55228- * We cannot distinguish between fault on source
55229- * and fault on destination. When this happens
55230- * we clear too and hope it will trigger the
55231- * EFAULT again.
55232- */
55233- if (n) {
55234- if (clear_user(buffer + tsz - n,
55235- n))
55236+ elf_buf = kmalloc(tsz, GFP_KERNEL);
55237+ if (!elf_buf)
55238+ return -ENOMEM;
55239+ oldfs = get_fs();
55240+ set_fs(KERNEL_DS);
55241+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
55242+ set_fs(oldfs);
55243+ if (copy_to_user(buffer, elf_buf, tsz)) {
55244+ kfree(elf_buf);
55245 return -EFAULT;
55246+ }
55247 }
55248+ set_fs(oldfs);
55249+ kfree(elf_buf);
55250 } else {
55251 if (clear_user(buffer, tsz))
55252 return -EFAULT;
55253@@ -545,6 +549,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55254
55255 static int open_kcore(struct inode *inode, struct file *filp)
55256 {
55257+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
55258+ return -EPERM;
55259+#endif
55260 if (!capable(CAP_SYS_RAWIO))
55261 return -EPERM;
55262 if (kcore_need_update)
55263diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
55264index 1efaaa1..834e49a 100644
55265--- a/fs/proc/meminfo.c
55266+++ b/fs/proc/meminfo.c
55267@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
55268 vmi.used >> 10,
55269 vmi.largest_chunk >> 10
55270 #ifdef CONFIG_MEMORY_FAILURE
55271- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
55272+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
55273 #endif
55274 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
55275 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
55276diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
55277index ccfd99b..1b7e255 100644
55278--- a/fs/proc/nommu.c
55279+++ b/fs/proc/nommu.c
55280@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
55281 if (len < 1)
55282 len = 1;
55283 seq_printf(m, "%*c", len, ' ');
55284- seq_path(m, &file->f_path, "");
55285+ seq_path(m, &file->f_path, "\n\\");
55286 }
55287
55288 seq_putc(m, '\n');
55289diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
55290index b4ac657..0842bd2 100644
55291--- a/fs/proc/proc_net.c
55292+++ b/fs/proc/proc_net.c
55293@@ -23,6 +23,7 @@
55294 #include <linux/nsproxy.h>
55295 #include <net/net_namespace.h>
55296 #include <linux/seq_file.h>
55297+#include <linux/grsecurity.h>
55298
55299 #include "internal.h"
55300
55301@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
55302 struct task_struct *task;
55303 struct nsproxy *ns;
55304 struct net *net = NULL;
55305+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55306+ const struct cred *cred = current_cred();
55307+#endif
55308+
55309+#ifdef CONFIG_GRKERNSEC_PROC_USER
55310+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
55311+ return net;
55312+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55313+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
55314+ return net;
55315+#endif
55316
55317 rcu_read_lock();
55318 task = pid_task(proc_pid(dir), PIDTYPE_PID);
55319diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
55320index ac05f33..1e6dc7e 100644
55321--- a/fs/proc/proc_sysctl.c
55322+++ b/fs/proc/proc_sysctl.c
55323@@ -13,11 +13,15 @@
55324 #include <linux/module.h>
55325 #include "internal.h"
55326
55327+extern int gr_handle_chroot_sysctl(const int op);
55328+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
55329+ const int op);
55330+
55331 static const struct dentry_operations proc_sys_dentry_operations;
55332 static const struct file_operations proc_sys_file_operations;
55333-static const struct inode_operations proc_sys_inode_operations;
55334+const struct inode_operations proc_sys_inode_operations;
55335 static const struct file_operations proc_sys_dir_file_operations;
55336-static const struct inode_operations proc_sys_dir_operations;
55337+const struct inode_operations proc_sys_dir_operations;
55338
55339 void proc_sys_poll_notify(struct ctl_table_poll *poll)
55340 {
55341@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
55342
55343 err = NULL;
55344 d_set_d_op(dentry, &proc_sys_dentry_operations);
55345+
55346+ gr_handle_proc_create(dentry, inode);
55347+
55348 d_add(dentry, inode);
55349
55350 out:
55351@@ -482,6 +489,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55352 struct inode *inode = file_inode(filp);
55353 struct ctl_table_header *head = grab_header(inode);
55354 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
55355+ int op = write ? MAY_WRITE : MAY_READ;
55356 ssize_t error;
55357 size_t res;
55358
55359@@ -493,7 +501,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55360 * and won't be until we finish.
55361 */
55362 error = -EPERM;
55363- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
55364+ if (sysctl_perm(head, table, op))
55365 goto out;
55366
55367 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
55368@@ -501,6 +509,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55369 if (!table->proc_handler)
55370 goto out;
55371
55372+#ifdef CONFIG_GRKERNSEC
55373+ error = -EPERM;
55374+ if (gr_handle_chroot_sysctl(op))
55375+ goto out;
55376+ dget(filp->f_path.dentry);
55377+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
55378+ dput(filp->f_path.dentry);
55379+ goto out;
55380+ }
55381+ dput(filp->f_path.dentry);
55382+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
55383+ goto out;
55384+ if (write && !capable(CAP_SYS_ADMIN))
55385+ goto out;
55386+#endif
55387+
55388 /* careful: calling conventions are nasty here */
55389 res = count;
55390 error = table->proc_handler(table, write, buf, &res, ppos);
55391@@ -598,6 +622,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
55392 return -ENOMEM;
55393 } else {
55394 d_set_d_op(child, &proc_sys_dentry_operations);
55395+
55396+ gr_handle_proc_create(child, inode);
55397+
55398 d_add(child, inode);
55399 }
55400 } else {
55401@@ -641,6 +668,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
55402 if ((*pos)++ < file->f_pos)
55403 return 0;
55404
55405+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
55406+ return 0;
55407+
55408 if (unlikely(S_ISLNK(table->mode)))
55409 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
55410 else
55411@@ -751,6 +781,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
55412 if (IS_ERR(head))
55413 return PTR_ERR(head);
55414
55415+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
55416+ return -ENOENT;
55417+
55418 generic_fillattr(inode, stat);
55419 if (table)
55420 stat->mode = (stat->mode & S_IFMT) | table->mode;
55421@@ -773,13 +806,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
55422 .llseek = generic_file_llseek,
55423 };
55424
55425-static const struct inode_operations proc_sys_inode_operations = {
55426+const struct inode_operations proc_sys_inode_operations = {
55427 .permission = proc_sys_permission,
55428 .setattr = proc_sys_setattr,
55429 .getattr = proc_sys_getattr,
55430 };
55431
55432-static const struct inode_operations proc_sys_dir_operations = {
55433+const struct inode_operations proc_sys_dir_operations = {
55434 .lookup = proc_sys_lookup,
55435 .permission = proc_sys_permission,
55436 .setattr = proc_sys_setattr,
55437@@ -855,7 +888,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
55438 static struct ctl_dir *new_dir(struct ctl_table_set *set,
55439 const char *name, int namelen)
55440 {
55441- struct ctl_table *table;
55442+ ctl_table_no_const *table;
55443 struct ctl_dir *new;
55444 struct ctl_node *node;
55445 char *new_name;
55446@@ -867,7 +900,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
55447 return NULL;
55448
55449 node = (struct ctl_node *)(new + 1);
55450- table = (struct ctl_table *)(node + 1);
55451+ table = (ctl_table_no_const *)(node + 1);
55452 new_name = (char *)(table + 2);
55453 memcpy(new_name, name, namelen);
55454 new_name[namelen] = '\0';
55455@@ -1036,7 +1069,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
55456 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
55457 struct ctl_table_root *link_root)
55458 {
55459- struct ctl_table *link_table, *entry, *link;
55460+ ctl_table_no_const *link_table, *link;
55461+ struct ctl_table *entry;
55462 struct ctl_table_header *links;
55463 struct ctl_node *node;
55464 char *link_name;
55465@@ -1059,7 +1093,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
55466 return NULL;
55467
55468 node = (struct ctl_node *)(links + 1);
55469- link_table = (struct ctl_table *)(node + nr_entries);
55470+ link_table = (ctl_table_no_const *)(node + nr_entries);
55471 link_name = (char *)&link_table[nr_entries + 1];
55472
55473 for (link = link_table, entry = table; entry->procname; link++, entry++) {
55474@@ -1307,8 +1341,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55475 struct ctl_table_header ***subheader, struct ctl_table_set *set,
55476 struct ctl_table *table)
55477 {
55478- struct ctl_table *ctl_table_arg = NULL;
55479- struct ctl_table *entry, *files;
55480+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
55481+ struct ctl_table *entry;
55482 int nr_files = 0;
55483 int nr_dirs = 0;
55484 int err = -ENOMEM;
55485@@ -1320,10 +1354,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55486 nr_files++;
55487 }
55488
55489- files = table;
55490 /* If there are mixed files and directories we need a new table */
55491 if (nr_dirs && nr_files) {
55492- struct ctl_table *new;
55493+ ctl_table_no_const *new;
55494 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
55495 GFP_KERNEL);
55496 if (!files)
55497@@ -1341,7 +1374,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55498 /* Register everything except a directory full of subdirectories */
55499 if (nr_files || !nr_dirs) {
55500 struct ctl_table_header *header;
55501- header = __register_sysctl_table(set, path, files);
55502+ header = __register_sysctl_table(set, path, files ? files : table);
55503 if (!header) {
55504 kfree(ctl_table_arg);
55505 goto out;
55506diff --git a/fs/proc/root.c b/fs/proc/root.c
55507index 9c7fab1..ed1c8e0 100644
55508--- a/fs/proc/root.c
55509+++ b/fs/proc/root.c
55510@@ -180,7 +180,15 @@ void __init proc_root_init(void)
55511 #ifdef CONFIG_PROC_DEVICETREE
55512 proc_device_tree_init();
55513 #endif
55514+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55515+#ifdef CONFIG_GRKERNSEC_PROC_USER
55516+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
55517+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55518+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
55519+#endif
55520+#else
55521 proc_mkdir("bus", NULL);
55522+#endif
55523 proc_sys_init();
55524 }
55525
55526diff --git a/fs/proc/self.c b/fs/proc/self.c
55527index aa5cc3b..c91a5d0 100644
55528--- a/fs/proc/self.c
55529+++ b/fs/proc/self.c
55530@@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
55531 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
55532 void *cookie)
55533 {
55534- char *s = nd_get_link(nd);
55535+ const char *s = nd_get_link(nd);
55536 if (!IS_ERR(s))
55537 kfree(s);
55538 }
55539diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
55540index 3e636d8..83e3b71 100644
55541--- a/fs/proc/task_mmu.c
55542+++ b/fs/proc/task_mmu.c
55543@@ -11,12 +11,19 @@
55544 #include <linux/rmap.h>
55545 #include <linux/swap.h>
55546 #include <linux/swapops.h>
55547+#include <linux/grsecurity.h>
55548
55549 #include <asm/elf.h>
55550 #include <asm/uaccess.h>
55551 #include <asm/tlbflush.h>
55552 #include "internal.h"
55553
55554+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55555+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55556+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55557+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55558+#endif
55559+
55560 void task_mem(struct seq_file *m, struct mm_struct *mm)
55561 {
55562 unsigned long data, text, lib, swap;
55563@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
55564 "VmExe:\t%8lu kB\n"
55565 "VmLib:\t%8lu kB\n"
55566 "VmPTE:\t%8lu kB\n"
55567- "VmSwap:\t%8lu kB\n",
55568- hiwater_vm << (PAGE_SHIFT-10),
55569+ "VmSwap:\t%8lu kB\n"
55570+
55571+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
55572+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
55573+#endif
55574+
55575+ ,hiwater_vm << (PAGE_SHIFT-10),
55576 total_vm << (PAGE_SHIFT-10),
55577 mm->locked_vm << (PAGE_SHIFT-10),
55578 mm->pinned_vm << (PAGE_SHIFT-10),
55579@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
55580 data << (PAGE_SHIFT-10),
55581 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
55582 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
55583- swap << (PAGE_SHIFT-10));
55584+ swap << (PAGE_SHIFT-10)
55585+
55586+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
55587+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55588+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
55589+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
55590+#else
55591+ , mm->context.user_cs_base
55592+ , mm->context.user_cs_limit
55593+#endif
55594+#endif
55595+
55596+ );
55597 }
55598
55599 unsigned long task_vsize(struct mm_struct *mm)
55600@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55601 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
55602 }
55603
55604- /* We don't show the stack guard page in /proc/maps */
55605+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55606+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
55607+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
55608+#else
55609 start = vma->vm_start;
55610- if (stack_guard_page_start(vma, start))
55611- start += PAGE_SIZE;
55612 end = vma->vm_end;
55613- if (stack_guard_page_end(vma, end))
55614- end -= PAGE_SIZE;
55615+#endif
55616
55617 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
55618 start,
55619@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55620 flags & VM_WRITE ? 'w' : '-',
55621 flags & VM_EXEC ? 'x' : '-',
55622 flags & VM_MAYSHARE ? 's' : 'p',
55623+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55624+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
55625+#else
55626 pgoff,
55627+#endif
55628 MAJOR(dev), MINOR(dev), ino, &len);
55629
55630 /*
55631@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55632 */
55633 if (file) {
55634 pad_len_spaces(m, len);
55635- seq_path(m, &file->f_path, "\n");
55636+ seq_path(m, &file->f_path, "\n\\");
55637 goto done;
55638 }
55639
55640@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
55641 * Thread stack in /proc/PID/task/TID/maps or
55642 * the main process stack.
55643 */
55644- if (!is_pid || (vma->vm_start <= mm->start_stack &&
55645- vma->vm_end >= mm->start_stack)) {
55646+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
55647+ (vma->vm_start <= mm->start_stack &&
55648+ vma->vm_end >= mm->start_stack)) {
55649 name = "[stack]";
55650 } else {
55651 /* Thread stack in /proc/PID/maps */
55652@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
55653 struct proc_maps_private *priv = m->private;
55654 struct task_struct *task = priv->task;
55655
55656+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55657+ if (current->exec_id != m->exec_id) {
55658+ gr_log_badprocpid("maps");
55659+ return 0;
55660+ }
55661+#endif
55662+
55663 show_map_vma(m, vma, is_pid);
55664
55665 if (m->count < m->size) /* vma is copied successfully */
55666@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
55667 .private = &mss,
55668 };
55669
55670+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55671+ if (current->exec_id != m->exec_id) {
55672+ gr_log_badprocpid("smaps");
55673+ return 0;
55674+ }
55675+#endif
55676 memset(&mss, 0, sizeof mss);
55677- mss.vma = vma;
55678- /* mmap_sem is held in m_start */
55679- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
55680- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
55681-
55682+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55683+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
55684+#endif
55685+ mss.vma = vma;
55686+ /* mmap_sem is held in m_start */
55687+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
55688+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
55689+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55690+ }
55691+#endif
55692 show_map_vma(m, vma, is_pid);
55693
55694 seq_printf(m,
55695@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
55696 "KernelPageSize: %8lu kB\n"
55697 "MMUPageSize: %8lu kB\n"
55698 "Locked: %8lu kB\n",
55699+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55700+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
55701+#else
55702 (vma->vm_end - vma->vm_start) >> 10,
55703+#endif
55704 mss.resident >> 10,
55705 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
55706 mss.shared_clean >> 10,
55707@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
55708 int n;
55709 char buffer[50];
55710
55711+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55712+ if (current->exec_id != m->exec_id) {
55713+ gr_log_badprocpid("numa_maps");
55714+ return 0;
55715+ }
55716+#endif
55717+
55718 if (!mm)
55719 return 0;
55720
55721@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
55722 mpol_to_str(buffer, sizeof(buffer), pol);
55723 mpol_cond_put(pol);
55724
55725+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55726+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
55727+#else
55728 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
55729+#endif
55730
55731 if (file) {
55732 seq_printf(m, " file=");
55733- seq_path(m, &file->f_path, "\n\t= ");
55734+ seq_path(m, &file->f_path, "\n\t\\= ");
55735 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
55736 seq_printf(m, " heap");
55737 } else {
55738diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
55739index 56123a6..5a2f6ec 100644
55740--- a/fs/proc/task_nommu.c
55741+++ b/fs/proc/task_nommu.c
55742@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
55743 else
55744 bytes += kobjsize(mm);
55745
55746- if (current->fs && current->fs->users > 1)
55747+ if (current->fs && atomic_read(&current->fs->users) > 1)
55748 sbytes += kobjsize(current->fs);
55749 else
55750 bytes += kobjsize(current->fs);
55751@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
55752
55753 if (file) {
55754 pad_len_spaces(m, len);
55755- seq_path(m, &file->f_path, "");
55756+ seq_path(m, &file->f_path, "\n\\");
55757 } else if (mm) {
55758 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
55759
55760diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
55761index b870f74..e9048df 100644
55762--- a/fs/proc/vmcore.c
55763+++ b/fs/proc/vmcore.c
55764@@ -98,9 +98,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
55765 nr_bytes = count;
55766
55767 /* If pfn is not ram, return zeros for sparse dump files */
55768- if (pfn_is_ram(pfn) == 0)
55769- memset(buf, 0, nr_bytes);
55770- else {
55771+ if (pfn_is_ram(pfn) == 0) {
55772+ if (userbuf) {
55773+ if (clear_user((char __force_user *)buf, nr_bytes))
55774+ return -EFAULT;
55775+ } else
55776+ memset(buf, 0, nr_bytes);
55777+ } else {
55778 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
55779 offset, userbuf);
55780 if (tmp < 0)
55781@@ -185,7 +189,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
55782 if (tsz > nr_bytes)
55783 tsz = nr_bytes;
55784
55785- tmp = read_from_oldmem(buffer, tsz, &start, 1);
55786+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, 1);
55787 if (tmp < 0)
55788 return tmp;
55789 buflen -= tsz;
55790diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
55791index b00fcc9..e0c6381 100644
55792--- a/fs/qnx6/qnx6.h
55793+++ b/fs/qnx6/qnx6.h
55794@@ -74,7 +74,7 @@ enum {
55795 BYTESEX_BE,
55796 };
55797
55798-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
55799+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
55800 {
55801 if (sbi->s_bytesex == BYTESEX_LE)
55802 return le64_to_cpu((__force __le64)n);
55803@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
55804 return (__force __fs64)cpu_to_be64(n);
55805 }
55806
55807-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
55808+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
55809 {
55810 if (sbi->s_bytesex == BYTESEX_LE)
55811 return le32_to_cpu((__force __le32)n);
55812diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
55813index 16e8abb..2dcf914 100644
55814--- a/fs/quota/netlink.c
55815+++ b/fs/quota/netlink.c
55816@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
55817 void quota_send_warning(struct kqid qid, dev_t dev,
55818 const char warntype)
55819 {
55820- static atomic_t seq;
55821+ static atomic_unchecked_t seq;
55822 struct sk_buff *skb;
55823 void *msg_head;
55824 int ret;
55825@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
55826 "VFS: Not enough memory to send quota warning.\n");
55827 return;
55828 }
55829- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
55830+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
55831 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
55832 if (!msg_head) {
55833 printk(KERN_ERR
55834diff --git a/fs/read_write.c b/fs/read_write.c
55835index e6ddc8d..9155227 100644
55836--- a/fs/read_write.c
55837+++ b/fs/read_write.c
55838@@ -429,7 +429,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
55839
55840 old_fs = get_fs();
55841 set_fs(get_ds());
55842- p = (__force const char __user *)buf;
55843+ p = (const char __force_user *)buf;
55844 if (count > MAX_RW_COUNT)
55845 count = MAX_RW_COUNT;
55846 if (file->f_op->write)
55847diff --git a/fs/readdir.c b/fs/readdir.c
55848index fee38e0..12fdf47 100644
55849--- a/fs/readdir.c
55850+++ b/fs/readdir.c
55851@@ -17,6 +17,7 @@
55852 #include <linux/security.h>
55853 #include <linux/syscalls.h>
55854 #include <linux/unistd.h>
55855+#include <linux/namei.h>
55856
55857 #include <asm/uaccess.h>
55858
55859@@ -67,6 +68,7 @@ struct old_linux_dirent {
55860
55861 struct readdir_callback {
55862 struct old_linux_dirent __user * dirent;
55863+ struct file * file;
55864 int result;
55865 };
55866
55867@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
55868 buf->result = -EOVERFLOW;
55869 return -EOVERFLOW;
55870 }
55871+
55872+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55873+ return 0;
55874+
55875 buf->result++;
55876 dirent = buf->dirent;
55877 if (!access_ok(VERIFY_WRITE, dirent,
55878@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
55879
55880 buf.result = 0;
55881 buf.dirent = dirent;
55882+ buf.file = f.file;
55883
55884 error = vfs_readdir(f.file, fillonedir, &buf);
55885 if (buf.result)
55886@@ -139,6 +146,7 @@ struct linux_dirent {
55887 struct getdents_callback {
55888 struct linux_dirent __user * current_dir;
55889 struct linux_dirent __user * previous;
55890+ struct file * file;
55891 int count;
55892 int error;
55893 };
55894@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
55895 buf->error = -EOVERFLOW;
55896 return -EOVERFLOW;
55897 }
55898+
55899+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55900+ return 0;
55901+
55902 dirent = buf->previous;
55903 if (dirent) {
55904 if (__put_user(offset, &dirent->d_off))
55905@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
55906 buf.previous = NULL;
55907 buf.count = count;
55908 buf.error = 0;
55909+ buf.file = f.file;
55910
55911 error = vfs_readdir(f.file, filldir, &buf);
55912 if (error >= 0)
55913@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
55914 struct getdents_callback64 {
55915 struct linux_dirent64 __user * current_dir;
55916 struct linux_dirent64 __user * previous;
55917+ struct file *file;
55918 int count;
55919 int error;
55920 };
55921@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
55922 buf->error = -EINVAL; /* only used if we fail.. */
55923 if (reclen > buf->count)
55924 return -EINVAL;
55925+
55926+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55927+ return 0;
55928+
55929 dirent = buf->previous;
55930 if (dirent) {
55931 if (__put_user(offset, &dirent->d_off))
55932@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
55933
55934 buf.current_dir = dirent;
55935 buf.previous = NULL;
55936+ buf.file = f.file;
55937 buf.count = count;
55938 buf.error = 0;
55939
55940@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
55941 error = buf.error;
55942 lastdirent = buf.previous;
55943 if (lastdirent) {
55944- typeof(lastdirent->d_off) d_off = f.file->f_pos;
55945+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
55946 if (__put_user(d_off, &lastdirent->d_off))
55947 error = -EFAULT;
55948 else
55949diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
55950index 2b7882b..1c5ef48 100644
55951--- a/fs/reiserfs/do_balan.c
55952+++ b/fs/reiserfs/do_balan.c
55953@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
55954 return;
55955 }
55956
55957- atomic_inc(&(fs_generation(tb->tb_sb)));
55958+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
55959 do_balance_starts(tb);
55960
55961 /* balance leaf returns 0 except if combining L R and S into
55962diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
55963index 9cc0740a..46bf953 100644
55964--- a/fs/reiserfs/procfs.c
55965+++ b/fs/reiserfs/procfs.c
55966@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
55967 "SMALL_TAILS " : "NO_TAILS ",
55968 replay_only(sb) ? "REPLAY_ONLY " : "",
55969 convert_reiserfs(sb) ? "CONV " : "",
55970- atomic_read(&r->s_generation_counter),
55971+ atomic_read_unchecked(&r->s_generation_counter),
55972 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
55973 SF(s_do_balance), SF(s_unneeded_left_neighbor),
55974 SF(s_good_search_by_key_reada), SF(s_bmaps),
55975diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
55976index 157e474..65a6114 100644
55977--- a/fs/reiserfs/reiserfs.h
55978+++ b/fs/reiserfs/reiserfs.h
55979@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
55980 /* Comment? -Hans */
55981 wait_queue_head_t s_wait;
55982 /* To be obsoleted soon by per buffer seals.. -Hans */
55983- atomic_t s_generation_counter; // increased by one every time the
55984+ atomic_unchecked_t s_generation_counter; // increased by one every time the
55985 // tree gets re-balanced
55986 unsigned long s_properties; /* File system properties. Currently holds
55987 on-disk FS format */
55988@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
55989 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
55990
55991 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
55992-#define get_generation(s) atomic_read (&fs_generation(s))
55993+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
55994 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
55995 #define __fs_changed(gen,s) (gen != get_generation (s))
55996 #define fs_changed(gen,s) \
55997diff --git a/fs/select.c b/fs/select.c
55998index 8c1c96c..a0f9b6d 100644
55999--- a/fs/select.c
56000+++ b/fs/select.c
56001@@ -20,6 +20,7 @@
56002 #include <linux/export.h>
56003 #include <linux/slab.h>
56004 #include <linux/poll.h>
56005+#include <linux/security.h>
56006 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
56007 #include <linux/file.h>
56008 #include <linux/fdtable.h>
56009@@ -827,6 +828,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
56010 struct poll_list *walk = head;
56011 unsigned long todo = nfds;
56012
56013+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
56014 if (nfds > rlimit(RLIMIT_NOFILE))
56015 return -EINVAL;
56016
56017diff --git a/fs/seq_file.c b/fs/seq_file.c
56018index 38bb59f..a304f9d 100644
56019--- a/fs/seq_file.c
56020+++ b/fs/seq_file.c
56021@@ -10,6 +10,7 @@
56022 #include <linux/seq_file.h>
56023 #include <linux/slab.h>
56024 #include <linux/cred.h>
56025+#include <linux/sched.h>
56026
56027 #include <asm/uaccess.h>
56028 #include <asm/page.h>
56029@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
56030 #ifdef CONFIG_USER_NS
56031 p->user_ns = file->f_cred->user_ns;
56032 #endif
56033+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56034+ p->exec_id = current->exec_id;
56035+#endif
56036
56037 /*
56038 * Wrappers around seq_open(e.g. swaps_open) need to be
56039@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
56040 return 0;
56041 }
56042 if (!m->buf) {
56043- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
56044+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
56045 if (!m->buf)
56046 return -ENOMEM;
56047 }
56048@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
56049 Eoverflow:
56050 m->op->stop(m, p);
56051 kfree(m->buf);
56052- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
56053+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
56054 return !m->buf ? -ENOMEM : -EAGAIN;
56055 }
56056
56057@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
56058
56059 /* grab buffer if we didn't have one */
56060 if (!m->buf) {
56061- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
56062+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
56063 if (!m->buf)
56064 goto Enomem;
56065 }
56066@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
56067 goto Fill;
56068 m->op->stop(m, p);
56069 kfree(m->buf);
56070- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
56071+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
56072 if (!m->buf)
56073 goto Enomem;
56074 m->count = 0;
56075@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
56076 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
56077 void *data)
56078 {
56079- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
56080+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
56081 int res = -ENOMEM;
56082
56083 if (op) {
56084diff --git a/fs/splice.c b/fs/splice.c
56085index 29e394e..b13c247 100644
56086--- a/fs/splice.c
56087+++ b/fs/splice.c
56088@@ -195,7 +195,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56089 pipe_lock(pipe);
56090
56091 for (;;) {
56092- if (!pipe->readers) {
56093+ if (!atomic_read(&pipe->readers)) {
56094 send_sig(SIGPIPE, current, 0);
56095 if (!ret)
56096 ret = -EPIPE;
56097@@ -249,9 +249,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56098 do_wakeup = 0;
56099 }
56100
56101- pipe->waiting_writers++;
56102+ atomic_inc(&pipe->waiting_writers);
56103 pipe_wait(pipe);
56104- pipe->waiting_writers--;
56105+ atomic_dec(&pipe->waiting_writers);
56106 }
56107
56108 pipe_unlock(pipe);
56109@@ -564,7 +564,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
56110 old_fs = get_fs();
56111 set_fs(get_ds());
56112 /* The cast to a user pointer is valid due to the set_fs() */
56113- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
56114+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
56115 set_fs(old_fs);
56116
56117 return res;
56118@@ -579,7 +579,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
56119 old_fs = get_fs();
56120 set_fs(get_ds());
56121 /* The cast to a user pointer is valid due to the set_fs() */
56122- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
56123+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
56124 set_fs(old_fs);
56125
56126 return res;
56127@@ -632,7 +632,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
56128 goto err;
56129
56130 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
56131- vec[i].iov_base = (void __user *) page_address(page);
56132+ vec[i].iov_base = (void __force_user *) page_address(page);
56133 vec[i].iov_len = this_len;
56134 spd.pages[i] = page;
56135 spd.nr_pages++;
56136@@ -853,10 +853,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
56137 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
56138 {
56139 while (!pipe->nrbufs) {
56140- if (!pipe->writers)
56141+ if (!atomic_read(&pipe->writers))
56142 return 0;
56143
56144- if (!pipe->waiting_writers && sd->num_spliced)
56145+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
56146 return 0;
56147
56148 if (sd->flags & SPLICE_F_NONBLOCK)
56149@@ -1192,7 +1192,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
56150 * out of the pipe right after the splice_to_pipe(). So set
56151 * PIPE_READERS appropriately.
56152 */
56153- pipe->readers = 1;
56154+ atomic_set(&pipe->readers, 1);
56155
56156 current->splice_pipe = pipe;
56157 }
56158@@ -1741,9 +1741,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56159 ret = -ERESTARTSYS;
56160 break;
56161 }
56162- if (!pipe->writers)
56163+ if (!atomic_read(&pipe->writers))
56164 break;
56165- if (!pipe->waiting_writers) {
56166+ if (!atomic_read(&pipe->waiting_writers)) {
56167 if (flags & SPLICE_F_NONBLOCK) {
56168 ret = -EAGAIN;
56169 break;
56170@@ -1775,7 +1775,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56171 pipe_lock(pipe);
56172
56173 while (pipe->nrbufs >= pipe->buffers) {
56174- if (!pipe->readers) {
56175+ if (!atomic_read(&pipe->readers)) {
56176 send_sig(SIGPIPE, current, 0);
56177 ret = -EPIPE;
56178 break;
56179@@ -1788,9 +1788,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56180 ret = -ERESTARTSYS;
56181 break;
56182 }
56183- pipe->waiting_writers++;
56184+ atomic_inc(&pipe->waiting_writers);
56185 pipe_wait(pipe);
56186- pipe->waiting_writers--;
56187+ atomic_dec(&pipe->waiting_writers);
56188 }
56189
56190 pipe_unlock(pipe);
56191@@ -1826,14 +1826,14 @@ retry:
56192 pipe_double_lock(ipipe, opipe);
56193
56194 do {
56195- if (!opipe->readers) {
56196+ if (!atomic_read(&opipe->readers)) {
56197 send_sig(SIGPIPE, current, 0);
56198 if (!ret)
56199 ret = -EPIPE;
56200 break;
56201 }
56202
56203- if (!ipipe->nrbufs && !ipipe->writers)
56204+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
56205 break;
56206
56207 /*
56208@@ -1930,7 +1930,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
56209 pipe_double_lock(ipipe, opipe);
56210
56211 do {
56212- if (!opipe->readers) {
56213+ if (!atomic_read(&opipe->readers)) {
56214 send_sig(SIGPIPE, current, 0);
56215 if (!ret)
56216 ret = -EPIPE;
56217@@ -1975,7 +1975,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
56218 * return EAGAIN if we have the potential of some data in the
56219 * future, otherwise just return 0
56220 */
56221- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
56222+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
56223 ret = -EAGAIN;
56224
56225 pipe_unlock(ipipe);
56226diff --git a/fs/stat.c b/fs/stat.c
56227index 04ce1ac..a13dd1e 100644
56228--- a/fs/stat.c
56229+++ b/fs/stat.c
56230@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
56231 stat->gid = inode->i_gid;
56232 stat->rdev = inode->i_rdev;
56233 stat->size = i_size_read(inode);
56234- stat->atime = inode->i_atime;
56235- stat->mtime = inode->i_mtime;
56236+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
56237+ stat->atime = inode->i_ctime;
56238+ stat->mtime = inode->i_ctime;
56239+ } else {
56240+ stat->atime = inode->i_atime;
56241+ stat->mtime = inode->i_mtime;
56242+ }
56243 stat->ctime = inode->i_ctime;
56244 stat->blksize = (1 << inode->i_blkbits);
56245 stat->blocks = inode->i_blocks;
56246@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
56247 if (retval)
56248 return retval;
56249
56250- if (inode->i_op->getattr)
56251- return inode->i_op->getattr(path->mnt, path->dentry, stat);
56252+ if (inode->i_op->getattr) {
56253+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
56254+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
56255+ stat->atime = stat->ctime;
56256+ stat->mtime = stat->ctime;
56257+ }
56258+ return retval;
56259+ }
56260
56261 generic_fillattr(inode, stat);
56262 return 0;
56263diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
56264index 15c68f9..36a8b3e 100644
56265--- a/fs/sysfs/bin.c
56266+++ b/fs/sysfs/bin.c
56267@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
56268 return ret;
56269 }
56270
56271-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
56272- void *buf, int len, int write)
56273+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
56274+ void *buf, size_t len, int write)
56275 {
56276 struct file *file = vma->vm_file;
56277 struct bin_buffer *bb = file->private_data;
56278 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
56279- int ret;
56280+ ssize_t ret;
56281
56282 if (!bb->vm_ops)
56283 return -EINVAL;
56284diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
56285index 6f31590..3c87c8a 100644
56286--- a/fs/sysfs/dir.c
56287+++ b/fs/sysfs/dir.c
56288@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
56289 *
56290 * Returns 31 bit hash of ns + name (so it fits in an off_t )
56291 */
56292-static unsigned int sysfs_name_hash(const void *ns, const char *name)
56293+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
56294 {
56295 unsigned long hash = init_name_hash();
56296 unsigned int len = strlen(name);
56297@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
56298 struct sysfs_dirent *sd;
56299 int rc;
56300
56301+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
56302+ const char *parent_name = parent_sd->s_name;
56303+
56304+ mode = S_IFDIR | S_IRWXU;
56305+
56306+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
56307+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
56308+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
56309+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
56310+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
56311+#endif
56312+
56313 /* allocate */
56314 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
56315 if (!sd)
56316diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
56317index 602f56d..6853db8 100644
56318--- a/fs/sysfs/file.c
56319+++ b/fs/sysfs/file.c
56320@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
56321
56322 struct sysfs_open_dirent {
56323 atomic_t refcnt;
56324- atomic_t event;
56325+ atomic_unchecked_t event;
56326 wait_queue_head_t poll;
56327 struct list_head buffers; /* goes through sysfs_buffer.list */
56328 };
56329@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
56330 if (!sysfs_get_active(attr_sd))
56331 return -ENODEV;
56332
56333- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
56334+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
56335 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
56336
56337 sysfs_put_active(attr_sd);
56338@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
56339 return -ENOMEM;
56340
56341 atomic_set(&new_od->refcnt, 0);
56342- atomic_set(&new_od->event, 1);
56343+ atomic_set_unchecked(&new_od->event, 1);
56344 init_waitqueue_head(&new_od->poll);
56345 INIT_LIST_HEAD(&new_od->buffers);
56346 goto retry;
56347@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
56348
56349 sysfs_put_active(attr_sd);
56350
56351- if (buffer->event != atomic_read(&od->event))
56352+ if (buffer->event != atomic_read_unchecked(&od->event))
56353 goto trigger;
56354
56355 return DEFAULT_POLLMASK;
56356@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
56357
56358 od = sd->s_attr.open;
56359 if (od) {
56360- atomic_inc(&od->event);
56361+ atomic_inc_unchecked(&od->event);
56362 wake_up_interruptible(&od->poll);
56363 }
56364
56365diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
56366index 8c940df..25b733e 100644
56367--- a/fs/sysfs/symlink.c
56368+++ b/fs/sysfs/symlink.c
56369@@ -305,7 +305,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
56370
56371 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
56372 {
56373- char *page = nd_get_link(nd);
56374+ const char *page = nd_get_link(nd);
56375 if (!IS_ERR(page))
56376 free_page((unsigned long)page);
56377 }
56378diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
56379index 69d4889..a810bd4 100644
56380--- a/fs/sysv/sysv.h
56381+++ b/fs/sysv/sysv.h
56382@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
56383 #endif
56384 }
56385
56386-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
56387+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
56388 {
56389 if (sbi->s_bytesex == BYTESEX_PDP)
56390 return PDP_swab((__force __u32)n);
56391diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
56392index e18b988..f1d4ad0f 100644
56393--- a/fs/ubifs/io.c
56394+++ b/fs/ubifs/io.c
56395@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
56396 return err;
56397 }
56398
56399-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
56400+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
56401 {
56402 int err;
56403
56404diff --git a/fs/udf/misc.c b/fs/udf/misc.c
56405index c175b4d..8f36a16 100644
56406--- a/fs/udf/misc.c
56407+++ b/fs/udf/misc.c
56408@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
56409
56410 u8 udf_tag_checksum(const struct tag *t)
56411 {
56412- u8 *data = (u8 *)t;
56413+ const u8 *data = (const u8 *)t;
56414 u8 checksum = 0;
56415 int i;
56416 for (i = 0; i < sizeof(struct tag); ++i)
56417diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
56418index 8d974c4..b82f6ec 100644
56419--- a/fs/ufs/swab.h
56420+++ b/fs/ufs/swab.h
56421@@ -22,7 +22,7 @@ enum {
56422 BYTESEX_BE
56423 };
56424
56425-static inline u64
56426+static inline u64 __intentional_overflow(-1)
56427 fs64_to_cpu(struct super_block *sbp, __fs64 n)
56428 {
56429 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
56430@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
56431 return (__force __fs64)cpu_to_be64(n);
56432 }
56433
56434-static inline u32
56435+static inline u32 __intentional_overflow(-1)
56436 fs32_to_cpu(struct super_block *sbp, __fs32 n)
56437 {
56438 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
56439diff --git a/fs/utimes.c b/fs/utimes.c
56440index f4fb7ec..3fe03c0 100644
56441--- a/fs/utimes.c
56442+++ b/fs/utimes.c
56443@@ -1,6 +1,7 @@
56444 #include <linux/compiler.h>
56445 #include <linux/file.h>
56446 #include <linux/fs.h>
56447+#include <linux/security.h>
56448 #include <linux/linkage.h>
56449 #include <linux/mount.h>
56450 #include <linux/namei.h>
56451@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
56452 goto mnt_drop_write_and_out;
56453 }
56454 }
56455+
56456+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
56457+ error = -EACCES;
56458+ goto mnt_drop_write_and_out;
56459+ }
56460+
56461 mutex_lock(&inode->i_mutex);
56462 error = notify_change(path->dentry, &newattrs);
56463 mutex_unlock(&inode->i_mutex);
56464diff --git a/fs/xattr.c b/fs/xattr.c
56465index 3377dff..4d074d9 100644
56466--- a/fs/xattr.c
56467+++ b/fs/xattr.c
56468@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
56469 return rc;
56470 }
56471
56472+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56473+ssize_t
56474+pax_getxattr(struct dentry *dentry, void *value, size_t size)
56475+{
56476+ struct inode *inode = dentry->d_inode;
56477+ ssize_t error;
56478+
56479+ error = inode_permission(inode, MAY_EXEC);
56480+ if (error)
56481+ return error;
56482+
56483+ if (inode->i_op->getxattr)
56484+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
56485+ else
56486+ error = -EOPNOTSUPP;
56487+
56488+ return error;
56489+}
56490+EXPORT_SYMBOL(pax_getxattr);
56491+#endif
56492+
56493 ssize_t
56494 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
56495 {
56496@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
56497 * Extended attribute SET operations
56498 */
56499 static long
56500-setxattr(struct dentry *d, const char __user *name, const void __user *value,
56501+setxattr(struct path *path, const char __user *name, const void __user *value,
56502 size_t size, int flags)
56503 {
56504 int error;
56505@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
56506 posix_acl_fix_xattr_from_user(kvalue, size);
56507 }
56508
56509- error = vfs_setxattr(d, kname, kvalue, size, flags);
56510+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
56511+ error = -EACCES;
56512+ goto out;
56513+ }
56514+
56515+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
56516 out:
56517 if (vvalue)
56518 vfree(vvalue);
56519@@ -377,7 +403,7 @@ retry:
56520 return error;
56521 error = mnt_want_write(path.mnt);
56522 if (!error) {
56523- error = setxattr(path.dentry, name, value, size, flags);
56524+ error = setxattr(&path, name, value, size, flags);
56525 mnt_drop_write(path.mnt);
56526 }
56527 path_put(&path);
56528@@ -401,7 +427,7 @@ retry:
56529 return error;
56530 error = mnt_want_write(path.mnt);
56531 if (!error) {
56532- error = setxattr(path.dentry, name, value, size, flags);
56533+ error = setxattr(&path, name, value, size, flags);
56534 mnt_drop_write(path.mnt);
56535 }
56536 path_put(&path);
56537@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
56538 const void __user *,value, size_t, size, int, flags)
56539 {
56540 struct fd f = fdget(fd);
56541- struct dentry *dentry;
56542 int error = -EBADF;
56543
56544 if (!f.file)
56545 return error;
56546- dentry = f.file->f_path.dentry;
56547- audit_inode(NULL, dentry, 0);
56548+ audit_inode(NULL, f.file->f_path.dentry, 0);
56549 error = mnt_want_write_file(f.file);
56550 if (!error) {
56551- error = setxattr(dentry, name, value, size, flags);
56552+ error = setxattr(&f.file->f_path, name, value, size, flags);
56553 mnt_drop_write_file(f.file);
56554 }
56555 fdput(f);
56556diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
56557index 9fbea87..6b19972 100644
56558--- a/fs/xattr_acl.c
56559+++ b/fs/xattr_acl.c
56560@@ -76,8 +76,8 @@ struct posix_acl *
56561 posix_acl_from_xattr(struct user_namespace *user_ns,
56562 const void *value, size_t size)
56563 {
56564- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
56565- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
56566+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
56567+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
56568 int count;
56569 struct posix_acl *acl;
56570 struct posix_acl_entry *acl_e;
56571diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
56572index b44af92..06073da 100644
56573--- a/fs/xfs/xfs_bmap.c
56574+++ b/fs/xfs/xfs_bmap.c
56575@@ -192,7 +192,7 @@ xfs_bmap_validate_ret(
56576 int nmap,
56577 int ret_nmap);
56578 #else
56579-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
56580+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
56581 #endif /* DEBUG */
56582
56583 STATIC int
56584diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
56585index 1b9fc3e..e1bdde0 100644
56586--- a/fs/xfs/xfs_dir2_sf.c
56587+++ b/fs/xfs/xfs_dir2_sf.c
56588@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
56589 }
56590
56591 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
56592- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
56593+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
56594+ char name[sfep->namelen];
56595+ memcpy(name, sfep->name, sfep->namelen);
56596+ if (filldir(dirent, name, sfep->namelen,
56597+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
56598+ *offset = off & 0x7fffffff;
56599+ return 0;
56600+ }
56601+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
56602 off & 0x7fffffff, ino, DT_UNKNOWN)) {
56603 *offset = off & 0x7fffffff;
56604 return 0;
56605diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
56606index d681e34..2a3f5ab 100644
56607--- a/fs/xfs/xfs_ioctl.c
56608+++ b/fs/xfs/xfs_ioctl.c
56609@@ -127,7 +127,7 @@ xfs_find_handle(
56610 }
56611
56612 error = -EFAULT;
56613- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
56614+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
56615 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
56616 goto out_put;
56617
56618diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
56619index ca9ecaa..60100c7 100644
56620--- a/fs/xfs/xfs_iops.c
56621+++ b/fs/xfs/xfs_iops.c
56622@@ -395,7 +395,7 @@ xfs_vn_put_link(
56623 struct nameidata *nd,
56624 void *p)
56625 {
56626- char *s = nd_get_link(nd);
56627+ const char *s = nd_get_link(nd);
56628
56629 if (!IS_ERR(s))
56630 kfree(s);
56631diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
56632new file mode 100644
56633index 0000000..ba9c5e3
56634--- /dev/null
56635+++ b/grsecurity/Kconfig
56636@@ -0,0 +1,1053 @@
56637+#
56638+# grecurity configuration
56639+#
56640+menu "Memory Protections"
56641+depends on GRKERNSEC
56642+
56643+config GRKERNSEC_KMEM
56644+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
56645+ default y if GRKERNSEC_CONFIG_AUTO
56646+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
56647+ help
56648+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
56649+ be written to or read from to modify or leak the contents of the running
56650+ kernel. /dev/port will also not be allowed to be opened and support
56651+ for /dev/cpu/*/msr will be removed. If you have module
56652+ support disabled, enabling this will close up five ways that are
56653+ currently used to insert malicious code into the running kernel.
56654+
56655+ Even with all these features enabled, we still highly recommend that
56656+ you use the RBAC system, as it is still possible for an attacker to
56657+ modify the running kernel through privileged I/O granted by ioperm/iopl.
56658+
56659+ If you are not using XFree86, you may be able to stop this additional
56660+ case by enabling the 'Disable privileged I/O' option. Though nothing
56661+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
56662+ but only to video memory, which is the only writing we allow in this
56663+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
56664+ not be allowed to mprotect it with PROT_WRITE later.
56665+ Enabling this feature will prevent the "cpupower" and "powertop" tools
56666+ from working.
56667+
56668+ It is highly recommended that you say Y here if you meet all the
56669+ conditions above.
56670+
56671+config GRKERNSEC_VM86
56672+ bool "Restrict VM86 mode"
56673+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
56674+ depends on X86_32
56675+
56676+ help
56677+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
56678+ make use of a special execution mode on 32bit x86 processors called
56679+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
56680+ video cards and will still work with this option enabled. The purpose
56681+ of the option is to prevent exploitation of emulation errors in
56682+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
56683+ Nearly all users should be able to enable this option.
56684+
56685+config GRKERNSEC_IO
56686+ bool "Disable privileged I/O"
56687+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
56688+ depends on X86
56689+ select RTC_CLASS
56690+ select RTC_INTF_DEV
56691+ select RTC_DRV_CMOS
56692+
56693+ help
56694+ If you say Y here, all ioperm and iopl calls will return an error.
56695+ Ioperm and iopl can be used to modify the running kernel.
56696+ Unfortunately, some programs need this access to operate properly,
56697+ the most notable of which are XFree86 and hwclock. hwclock can be
56698+ remedied by having RTC support in the kernel, so real-time
56699+ clock support is enabled if this option is enabled, to ensure
56700+ that hwclock operates correctly. XFree86 still will not
56701+ operate correctly with this option enabled, so DO NOT CHOOSE Y
56702+ IF YOU USE XFree86. If you use XFree86 and you still want to
56703+ protect your kernel against modification, use the RBAC system.
56704+
56705+config GRKERNSEC_JIT_HARDEN
56706+ bool "Harden BPF JIT against spray attacks"
56707+ default y if GRKERNSEC_CONFIG_AUTO
56708+ depends on BPF_JIT
56709+ help
56710+ If you say Y here, the native code generated by the kernel's Berkeley
56711+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
56712+ attacks that attempt to fit attacker-beneficial instructions in
56713+ 32bit immediate fields of JIT-generated native instructions. The
56714+ attacker will generally aim to cause an unintended instruction sequence
56715+ of JIT-generated native code to execute by jumping into the middle of
56716+ a generated instruction. This feature effectively randomizes the 32bit
56717+ immediate constants present in the generated code to thwart such attacks.
56718+
56719+ If you're using KERNEXEC, it's recommended that you enable this option
56720+ to supplement the hardening of the kernel.
56721+
56722+config GRKERNSEC_PERF_HARDEN
56723+ bool "Disable unprivileged PERF_EVENTS usage by default"
56724+ default y if GRKERNSEC_CONFIG_AUTO
56725+ depends on PERF_EVENTS
56726+ help
56727+ If you say Y here, the range of acceptable values for the
56728+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
56729+ default to a new value: 3. When the sysctl is set to this value, no
56730+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
56731+
56732+ Though PERF_EVENTS can be used legitimately for performance monitoring
56733+ and low-level application profiling, it is forced on regardless of
56734+ configuration, has been at fault for several vulnerabilities, and
56735+ creates new opportunities for side channels and other information leaks.
56736+
56737+ This feature puts PERF_EVENTS into a secure default state and permits
56738+ the administrator to change out of it temporarily if unprivileged
56739+ application profiling is needed.
56740+
56741+config GRKERNSEC_RAND_THREADSTACK
56742+ bool "Insert random gaps between thread stacks"
56743+ default y if GRKERNSEC_CONFIG_AUTO
56744+ depends on PAX_RANDMMAP && !PPC && BROKEN
56745+ help
56746+ If you say Y here, a random-sized gap will be enforced between allocated
56747+ thread stacks. Glibc's NPTL and other threading libraries that
56748+ pass MAP_STACK to the kernel for thread stack allocation are supported.
56749+ The implementation currently provides 8 bits of entropy for the gap.
56750+
56751+ Many distributions do not compile threaded remote services with the
56752+ -fstack-check argument to GCC, causing the variable-sized stack-based
56753+ allocator, alloca(), to not probe the stack on allocation. This
56754+ permits an unbounded alloca() to skip over any guard page and potentially
56755+ modify another thread's stack reliably. An enforced random gap
56756+ reduces the reliability of such an attack and increases the chance
56757+ that such a read/write to another thread's stack instead lands in
56758+ an unmapped area, causing a crash and triggering grsecurity's
56759+ anti-bruteforcing logic.
56760+
56761+config GRKERNSEC_PROC_MEMMAP
56762+ bool "Harden ASLR against information leaks and entropy reduction"
56763+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
56764+ depends on PAX_NOEXEC || PAX_ASLR
56765+ help
56766+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
56767+ give no information about the addresses of its mappings if
56768+ PaX features that rely on random addresses are enabled on the task.
56769+ In addition to sanitizing this information and disabling other
56770+ dangerous sources of information, this option causes reads of sensitive
56771+ /proc/<pid> entries where the file descriptor was opened in a different
56772+ task than the one performing the read. Such attempts are logged.
56773+ This option also limits argv/env strings for suid/sgid binaries
56774+ to 512KB to prevent a complete exhaustion of the stack entropy provided
56775+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
56776+ binaries to prevent alternative mmap layouts from being abused.
56777+
56778+ If you use PaX it is essential that you say Y here as it closes up
56779+ several holes that make full ASLR useless locally.
56780+
56781+config GRKERNSEC_BRUTE
56782+ bool "Deter exploit bruteforcing"
56783+ default y if GRKERNSEC_CONFIG_AUTO
56784+ help
56785+ If you say Y here, attempts to bruteforce exploits against forking
56786+ daemons such as apache or sshd, as well as against suid/sgid binaries
56787+ will be deterred. When a child of a forking daemon is killed by PaX
56788+ or crashes due to an illegal instruction or other suspicious signal,
56789+ the parent process will be delayed 30 seconds upon every subsequent
56790+ fork until the administrator is able to assess the situation and
56791+ restart the daemon.
56792+ In the suid/sgid case, the attempt is logged, the user has all their
56793+ processes terminated, and they are prevented from executing any further
56794+ processes for 15 minutes.
56795+ It is recommended that you also enable signal logging in the auditing
56796+ section so that logs are generated when a process triggers a suspicious
56797+ signal.
56798+ If the sysctl option is enabled, a sysctl option with name
56799+ "deter_bruteforce" is created.
56800+
56801+
56802+config GRKERNSEC_MODHARDEN
56803+ bool "Harden module auto-loading"
56804+ default y if GRKERNSEC_CONFIG_AUTO
56805+ depends on MODULES
56806+ help
56807+ If you say Y here, module auto-loading in response to use of some
56808+ feature implemented by an unloaded module will be restricted to
56809+ root users. Enabling this option helps defend against attacks
56810+ by unprivileged users who abuse the auto-loading behavior to
56811+ cause a vulnerable module to load that is then exploited.
56812+
56813+ If this option prevents a legitimate use of auto-loading for a
56814+ non-root user, the administrator can execute modprobe manually
56815+ with the exact name of the module mentioned in the alert log.
56816+ Alternatively, the administrator can add the module to the list
56817+ of modules loaded at boot by modifying init scripts.
56818+
56819+ Modification of init scripts will most likely be needed on
56820+ Ubuntu servers with encrypted home directory support enabled,
56821+ as the first non-root user logging in will cause the ecb(aes),
56822+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
56823+
56824+config GRKERNSEC_HIDESYM
56825+ bool "Hide kernel symbols"
56826+ default y if GRKERNSEC_CONFIG_AUTO
56827+ select PAX_USERCOPY_SLABS
56828+ help
56829+ If you say Y here, getting information on loaded modules, and
56830+ displaying all kernel symbols through a syscall will be restricted
56831+ to users with CAP_SYS_MODULE. For software compatibility reasons,
56832+ /proc/kallsyms will be restricted to the root user. The RBAC
56833+ system can hide that entry even from root.
56834+
56835+ This option also prevents leaking of kernel addresses through
56836+ several /proc entries.
56837+
56838+ Note that this option is only effective provided the following
56839+ conditions are met:
56840+ 1) The kernel using grsecurity is not precompiled by some distribution
56841+ 2) You have also enabled GRKERNSEC_DMESG
56842+ 3) You are using the RBAC system and hiding other files such as your
56843+ kernel image and System.map. Alternatively, enabling this option
56844+ causes the permissions on /boot, /lib/modules, and the kernel
56845+ source directory to change at compile time to prevent
56846+ reading by non-root users.
56847+ If the above conditions are met, this option will aid in providing a
56848+ useful protection against local kernel exploitation of overflows
56849+ and arbitrary read/write vulnerabilities.
56850+
56851+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
56852+ in addition to this feature.
56853+
56854+config GRKERNSEC_KERN_LOCKOUT
56855+ bool "Active kernel exploit response"
56856+ default y if GRKERNSEC_CONFIG_AUTO
56857+ depends on X86 || ARM || PPC || SPARC
56858+ help
56859+ If you say Y here, when a PaX alert is triggered due to suspicious
56860+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
56861+ or an OOPS occurs due to bad memory accesses, instead of just
56862+ terminating the offending process (and potentially allowing
56863+ a subsequent exploit from the same user), we will take one of two
56864+ actions:
56865+ If the user was root, we will panic the system
56866+ If the user was non-root, we will log the attempt, terminate
56867+ all processes owned by the user, then prevent them from creating
56868+ any new processes until the system is restarted
56869+ This deters repeated kernel exploitation/bruteforcing attempts
56870+ and is useful for later forensics.
56871+
56872+endmenu
56873+menu "Role Based Access Control Options"
56874+depends on GRKERNSEC
56875+
56876+config GRKERNSEC_RBAC_DEBUG
56877+ bool
56878+
56879+config GRKERNSEC_NO_RBAC
56880+ bool "Disable RBAC system"
56881+ help
56882+ If you say Y here, the /dev/grsec device will be removed from the kernel,
56883+ preventing the RBAC system from being enabled. You should only say Y
56884+ here if you have no intention of using the RBAC system, so as to prevent
56885+ an attacker with root access from misusing the RBAC system to hide files
56886+ and processes when loadable module support and /dev/[k]mem have been
56887+ locked down.
56888+
56889+config GRKERNSEC_ACL_HIDEKERN
56890+ bool "Hide kernel processes"
56891+ help
56892+ If you say Y here, all kernel threads will be hidden to all
56893+ processes but those whose subject has the "view hidden processes"
56894+ flag.
56895+
56896+config GRKERNSEC_ACL_MAXTRIES
56897+ int "Maximum tries before password lockout"
56898+ default 3
56899+ help
56900+ This option enforces the maximum number of times a user can attempt
56901+ to authorize themselves with the grsecurity RBAC system before being
56902+ denied the ability to attempt authorization again for a specified time.
56903+ The lower the number, the harder it will be to brute-force a password.
56904+
56905+config GRKERNSEC_ACL_TIMEOUT
56906+ int "Time to wait after max password tries, in seconds"
56907+ default 30
56908+ help
56909+ This option specifies the time the user must wait after attempting to
56910+ authorize to the RBAC system with the maximum number of invalid
56911+ passwords. The higher the number, the harder it will be to brute-force
56912+ a password.
56913+
56914+endmenu
56915+menu "Filesystem Protections"
56916+depends on GRKERNSEC
56917+
56918+config GRKERNSEC_PROC
56919+ bool "Proc restrictions"
56920+ default y if GRKERNSEC_CONFIG_AUTO
56921+ help
56922+ If you say Y here, the permissions of the /proc filesystem
56923+ will be altered to enhance system security and privacy. You MUST
56924+ choose either a user only restriction or a user and group restriction.
56925+ Depending upon the option you choose, you can either restrict users to
56926+ see only the processes they themselves run, or choose a group that can
56927+ view all processes and files normally restricted to root if you choose
56928+ the "restrict to user only" option. NOTE: If you're running identd or
56929+ ntpd as a non-root user, you will have to run it as the group you
56930+ specify here.
56931+
56932+config GRKERNSEC_PROC_USER
56933+ bool "Restrict /proc to user only"
56934+ depends on GRKERNSEC_PROC
56935+ help
56936+ If you say Y here, non-root users will only be able to view their own
56937+ processes, and restricts them from viewing network-related information,
56938+ and viewing kernel symbol and module information.
56939+
56940+config GRKERNSEC_PROC_USERGROUP
56941+ bool "Allow special group"
56942+ default y if GRKERNSEC_CONFIG_AUTO
56943+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
56944+ help
56945+ If you say Y here, you will be able to select a group that will be
56946+ able to view all processes and network-related information. If you've
56947+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
56948+ remain hidden. This option is useful if you want to run identd as
56949+ a non-root user. The group you select may also be chosen at boot time
56950+ via "grsec_proc_gid=" on the kernel commandline.
56951+
56952+config GRKERNSEC_PROC_GID
56953+ int "GID for special group"
56954+ depends on GRKERNSEC_PROC_USERGROUP
56955+ default 1001
56956+
56957+config GRKERNSEC_PROC_ADD
56958+ bool "Additional restrictions"
56959+ default y if GRKERNSEC_CONFIG_AUTO
56960+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
56961+ help
56962+ If you say Y here, additional restrictions will be placed on
56963+ /proc that keep normal users from viewing device information and
56964+ slabinfo information that could be useful for exploits.
56965+
56966+config GRKERNSEC_LINK
56967+ bool "Linking restrictions"
56968+ default y if GRKERNSEC_CONFIG_AUTO
56969+ help
56970+ If you say Y here, /tmp race exploits will be prevented, since users
56971+ will no longer be able to follow symlinks owned by other users in
56972+ world-writable +t directories (e.g. /tmp), unless the owner of the
56973+ symlink is the owner of the directory. users will also not be
56974+ able to hardlink to files they do not own. If the sysctl option is
56975+ enabled, a sysctl option with name "linking_restrictions" is created.
56976+
56977+config GRKERNSEC_SYMLINKOWN
56978+ bool "Kernel-enforced SymlinksIfOwnerMatch"
56979+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
56980+ help
56981+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
56982+ that prevents it from being used as a security feature. As Apache
56983+ verifies the symlink by performing a stat() against the target of
56984+ the symlink before it is followed, an attacker can setup a symlink
56985+ to point to a same-owned file, then replace the symlink with one
56986+ that targets another user's file just after Apache "validates" the
56987+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
56988+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
56989+ will be in place for the group you specify. If the sysctl option
56990+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
56991+ created.
56992+
56993+config GRKERNSEC_SYMLINKOWN_GID
56994+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
56995+ depends on GRKERNSEC_SYMLINKOWN
56996+ default 1006
56997+ help
56998+ Setting this GID determines what group kernel-enforced
56999+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
57000+ is enabled, a sysctl option with name "symlinkown_gid" is created.
57001+
57002+config GRKERNSEC_FIFO
57003+ bool "FIFO restrictions"
57004+ default y if GRKERNSEC_CONFIG_AUTO
57005+ help
57006+ If you say Y here, users will not be able to write to FIFOs they don't
57007+ own in world-writable +t directories (e.g. /tmp), unless the owner of
57008+ the FIFO is the same owner of the directory it's held in. If the sysctl
57009+ option is enabled, a sysctl option with name "fifo_restrictions" is
57010+ created.
57011+
57012+config GRKERNSEC_SYSFS_RESTRICT
57013+ bool "Sysfs/debugfs restriction"
57014+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57015+ depends on SYSFS
57016+ help
57017+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
57018+ any filesystem normally mounted under it (e.g. debugfs) will be
57019+ mostly accessible only by root. These filesystems generally provide access
57020+ to hardware and debug information that isn't appropriate for unprivileged
57021+ users of the system. Sysfs and debugfs have also become a large source
57022+ of new vulnerabilities, ranging from infoleaks to local compromise.
57023+ There has been very little oversight with an eye toward security involved
57024+ in adding new exporters of information to these filesystems, so their
57025+ use is discouraged.
57026+ For reasons of compatibility, a few directories have been whitelisted
57027+ for access by non-root users:
57028+ /sys/fs/selinux
57029+ /sys/fs/fuse
57030+ /sys/devices/system/cpu
57031+
57032+config GRKERNSEC_ROFS
57033+ bool "Runtime read-only mount protection"
57034+ help
57035+ If you say Y here, a sysctl option with name "romount_protect" will
57036+ be created. By setting this option to 1 at runtime, filesystems
57037+ will be protected in the following ways:
57038+ * No new writable mounts will be allowed
57039+ * Existing read-only mounts won't be able to be remounted read/write
57040+ * Write operations will be denied on all block devices
57041+ This option acts independently of grsec_lock: once it is set to 1,
57042+ it cannot be turned off. Therefore, please be mindful of the resulting
57043+ behavior if this option is enabled in an init script on a read-only
57044+ filesystem. This feature is mainly intended for secure embedded systems.
57045+
57046+config GRKERNSEC_DEVICE_SIDECHANNEL
57047+ bool "Eliminate stat/notify-based device sidechannels"
57048+ default y if GRKERNSEC_CONFIG_AUTO
57049+ help
57050+ If you say Y here, timing analyses on block or character
57051+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
57052+ will be thwarted for unprivileged users. If a process without
57053+ CAP_MKNOD stats such a device, the last access and last modify times
57054+ will match the device's create time. No access or modify events
57055+ will be triggered through inotify/dnotify/fanotify for such devices.
57056+ This feature will prevent attacks that may at a minimum
57057+ allow an attacker to determine the administrator's password length.
57058+
57059+config GRKERNSEC_CHROOT
57060+ bool "Chroot jail restrictions"
57061+ default y if GRKERNSEC_CONFIG_AUTO
57062+ help
57063+ If you say Y here, you will be able to choose several options that will
57064+ make breaking out of a chrooted jail much more difficult. If you
57065+ encounter no software incompatibilities with the following options, it
57066+ is recommended that you enable each one.
57067+
57068+config GRKERNSEC_CHROOT_MOUNT
57069+ bool "Deny mounts"
57070+ default y if GRKERNSEC_CONFIG_AUTO
57071+ depends on GRKERNSEC_CHROOT
57072+ help
57073+ If you say Y here, processes inside a chroot will not be able to
57074+ mount or remount filesystems. If the sysctl option is enabled, a
57075+ sysctl option with name "chroot_deny_mount" is created.
57076+
57077+config GRKERNSEC_CHROOT_DOUBLE
57078+ bool "Deny double-chroots"
57079+ default y if GRKERNSEC_CONFIG_AUTO
57080+ depends on GRKERNSEC_CHROOT
57081+ help
57082+ If you say Y here, processes inside a chroot will not be able to chroot
57083+ again outside the chroot. This is a widely used method of breaking
57084+ out of a chroot jail and should not be allowed. If the sysctl
57085+ option is enabled, a sysctl option with name
57086+ "chroot_deny_chroot" is created.
57087+
57088+config GRKERNSEC_CHROOT_PIVOT
57089+ bool "Deny pivot_root in chroot"
57090+ default y if GRKERNSEC_CONFIG_AUTO
57091+ depends on GRKERNSEC_CHROOT
57092+ help
57093+ If you say Y here, processes inside a chroot will not be able to use
57094+ a function called pivot_root() that was introduced in Linux 2.3.41. It
57095+ works similar to chroot in that it changes the root filesystem. This
57096+ function could be misused in a chrooted process to attempt to break out
57097+ of the chroot, and therefore should not be allowed. If the sysctl
57098+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
57099+ created.
57100+
57101+config GRKERNSEC_CHROOT_CHDIR
57102+ bool "Enforce chdir(\"/\") on all chroots"
57103+ default y if GRKERNSEC_CONFIG_AUTO
57104+ depends on GRKERNSEC_CHROOT
57105+ help
57106+ If you say Y here, the current working directory of all newly-chrooted
57107+ applications will be set to the the root directory of the chroot.
57108+ The man page on chroot(2) states:
57109+ Note that this call does not change the current working
57110+ directory, so that `.' can be outside the tree rooted at
57111+ `/'. In particular, the super-user can escape from a
57112+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
57113+
57114+ It is recommended that you say Y here, since it's not known to break
57115+ any software. If the sysctl option is enabled, a sysctl option with
57116+ name "chroot_enforce_chdir" is created.
57117+
57118+config GRKERNSEC_CHROOT_CHMOD
57119+ bool "Deny (f)chmod +s"
57120+ default y if GRKERNSEC_CONFIG_AUTO
57121+ depends on GRKERNSEC_CHROOT
57122+ help
57123+ If you say Y here, processes inside a chroot will not be able to chmod
57124+ or fchmod files to make them have suid or sgid bits. This protects
57125+ against another published method of breaking a chroot. If the sysctl
57126+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
57127+ created.
57128+
57129+config GRKERNSEC_CHROOT_FCHDIR
57130+ bool "Deny fchdir out of chroot"
57131+ default y if GRKERNSEC_CONFIG_AUTO
57132+ depends on GRKERNSEC_CHROOT
57133+ help
57134+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
57135+ to a file descriptor of the chrooting process that points to a directory
57136+ outside the filesystem will be stopped. If the sysctl option
57137+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
57138+
57139+config GRKERNSEC_CHROOT_MKNOD
57140+ bool "Deny mknod"
57141+ default y if GRKERNSEC_CONFIG_AUTO
57142+ depends on GRKERNSEC_CHROOT
57143+ help
57144+ If you say Y here, processes inside a chroot will not be allowed to
57145+ mknod. The problem with using mknod inside a chroot is that it
57146+ would allow an attacker to create a device entry that is the same
57147+ as one on the physical root of your system, which could range from
57148+ anything from the console device to a device for your harddrive (which
57149+ they could then use to wipe the drive or steal data). It is recommended
57150+ that you say Y here, unless you run into software incompatibilities.
57151+ If the sysctl option is enabled, a sysctl option with name
57152+ "chroot_deny_mknod" is created.
57153+
57154+config GRKERNSEC_CHROOT_SHMAT
57155+ bool "Deny shmat() out of chroot"
57156+ default y if GRKERNSEC_CONFIG_AUTO
57157+ depends on GRKERNSEC_CHROOT
57158+ help
57159+ If you say Y here, processes inside a chroot will not be able to attach
57160+ to shared memory segments that were created outside of the chroot jail.
57161+ It is recommended that you say Y here. If the sysctl option is enabled,
57162+ a sysctl option with name "chroot_deny_shmat" is created.
57163+
57164+config GRKERNSEC_CHROOT_UNIX
57165+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
57166+ default y if GRKERNSEC_CONFIG_AUTO
57167+ depends on GRKERNSEC_CHROOT
57168+ help
57169+ If you say Y here, processes inside a chroot will not be able to
57170+ connect to abstract (meaning not belonging to a filesystem) Unix
57171+ domain sockets that were bound outside of a chroot. It is recommended
57172+ that you say Y here. If the sysctl option is enabled, a sysctl option
57173+ with name "chroot_deny_unix" is created.
57174+
57175+config GRKERNSEC_CHROOT_FINDTASK
57176+ bool "Protect outside processes"
57177+ default y if GRKERNSEC_CONFIG_AUTO
57178+ depends on GRKERNSEC_CHROOT
57179+ help
57180+ If you say Y here, processes inside a chroot will not be able to
57181+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
57182+ getsid, or view any process outside of the chroot. If the sysctl
57183+ option is enabled, a sysctl option with name "chroot_findtask" is
57184+ created.
57185+
57186+config GRKERNSEC_CHROOT_NICE
57187+ bool "Restrict priority changes"
57188+ default y if GRKERNSEC_CONFIG_AUTO
57189+ depends on GRKERNSEC_CHROOT
57190+ help
57191+ If you say Y here, processes inside a chroot will not be able to raise
57192+ the priority of processes in the chroot, or alter the priority of
57193+ processes outside the chroot. This provides more security than simply
57194+ removing CAP_SYS_NICE from the process' capability set. If the
57195+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
57196+ is created.
57197+
57198+config GRKERNSEC_CHROOT_SYSCTL
57199+ bool "Deny sysctl writes"
57200+ default y if GRKERNSEC_CONFIG_AUTO
57201+ depends on GRKERNSEC_CHROOT
57202+ help
57203+ If you say Y here, an attacker in a chroot will not be able to
57204+ write to sysctl entries, either by sysctl(2) or through a /proc
57205+ interface. It is strongly recommended that you say Y here. If the
57206+ sysctl option is enabled, a sysctl option with name
57207+ "chroot_deny_sysctl" is created.
57208+
57209+config GRKERNSEC_CHROOT_CAPS
57210+ bool "Capability restrictions"
57211+ default y if GRKERNSEC_CONFIG_AUTO
57212+ depends on GRKERNSEC_CHROOT
57213+ help
57214+ If you say Y here, the capabilities on all processes within a
57215+ chroot jail will be lowered to stop module insertion, raw i/o,
57216+ system and net admin tasks, rebooting the system, modifying immutable
57217+ files, modifying IPC owned by another, and changing the system time.
57218+ This is left an option because it can break some apps. Disable this
57219+ if your chrooted apps are having problems performing those kinds of
57220+ tasks. If the sysctl option is enabled, a sysctl option with
57221+ name "chroot_caps" is created.
57222+
57223+config GRKERNSEC_CHROOT_INITRD
57224+ bool "Exempt initrd tasks from restrictions"
57225+ default y if GRKERNSEC_CONFIG_AUTO
57226+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
57227+ help
57228+ If you say Y here, tasks started prior to init will be exempted from
57229+ grsecurity's chroot restrictions. This option is mainly meant to
57230+ resolve Plymouth's performing privileged operations unnecessarily
57231+ in a chroot.
57232+
57233+endmenu
57234+menu "Kernel Auditing"
57235+depends on GRKERNSEC
57236+
57237+config GRKERNSEC_AUDIT_GROUP
57238+ bool "Single group for auditing"
57239+ help
57240+ If you say Y here, the exec and chdir logging features will only operate
57241+ on a group you specify. This option is recommended if you only want to
57242+ watch certain users instead of having a large amount of logs from the
57243+ entire system. If the sysctl option is enabled, a sysctl option with
57244+ name "audit_group" is created.
57245+
57246+config GRKERNSEC_AUDIT_GID
57247+ int "GID for auditing"
57248+ depends on GRKERNSEC_AUDIT_GROUP
57249+ default 1007
57250+
57251+config GRKERNSEC_EXECLOG
57252+ bool "Exec logging"
57253+ help
57254+ If you say Y here, all execve() calls will be logged (since the
57255+ other exec*() calls are frontends to execve(), all execution
57256+ will be logged). Useful for shell-servers that like to keep track
57257+ of their users. If the sysctl option is enabled, a sysctl option with
57258+ name "exec_logging" is created.
57259+ WARNING: This option when enabled will produce a LOT of logs, especially
57260+ on an active system.
57261+
57262+config GRKERNSEC_RESLOG
57263+ bool "Resource logging"
57264+ default y if GRKERNSEC_CONFIG_AUTO
57265+ help
57266+ If you say Y here, all attempts to overstep resource limits will
57267+ be logged with the resource name, the requested size, and the current
57268+ limit. It is highly recommended that you say Y here. If the sysctl
57269+ option is enabled, a sysctl option with name "resource_logging" is
57270+ created. If the RBAC system is enabled, the sysctl value is ignored.
57271+
57272+config GRKERNSEC_CHROOT_EXECLOG
57273+ bool "Log execs within chroot"
57274+ help
57275+ If you say Y here, all executions inside a chroot jail will be logged
57276+ to syslog. This can cause a large amount of logs if certain
57277+ applications (eg. djb's daemontools) are installed on the system, and
57278+ is therefore left as an option. If the sysctl option is enabled, a
57279+ sysctl option with name "chroot_execlog" is created.
57280+
57281+config GRKERNSEC_AUDIT_PTRACE
57282+ bool "Ptrace logging"
57283+ help
57284+ If you say Y here, all attempts to attach to a process via ptrace
57285+ will be logged. If the sysctl option is enabled, a sysctl option
57286+ with name "audit_ptrace" is created.
57287+
57288+config GRKERNSEC_AUDIT_CHDIR
57289+ bool "Chdir logging"
57290+ help
57291+ If you say Y here, all chdir() calls will be logged. If the sysctl
57292+ option is enabled, a sysctl option with name "audit_chdir" is created.
57293+
57294+config GRKERNSEC_AUDIT_MOUNT
57295+ bool "(Un)Mount logging"
57296+ help
57297+ If you say Y here, all mounts and unmounts will be logged. If the
57298+ sysctl option is enabled, a sysctl option with name "audit_mount" is
57299+ created.
57300+
57301+config GRKERNSEC_SIGNAL
57302+ bool "Signal logging"
57303+ default y if GRKERNSEC_CONFIG_AUTO
57304+ help
57305+ If you say Y here, certain important signals will be logged, such as
57306+ SIGSEGV, which will as a result inform you of when a error in a program
57307+ occurred, which in some cases could mean a possible exploit attempt.
57308+ If the sysctl option is enabled, a sysctl option with name
57309+ "signal_logging" is created.
57310+
57311+config GRKERNSEC_FORKFAIL
57312+ bool "Fork failure logging"
57313+ help
57314+ If you say Y here, all failed fork() attempts will be logged.
57315+ This could suggest a fork bomb, or someone attempting to overstep
57316+ their process limit. If the sysctl option is enabled, a sysctl option
57317+ with name "forkfail_logging" is created.
57318+
57319+config GRKERNSEC_TIME
57320+ bool "Time change logging"
57321+ default y if GRKERNSEC_CONFIG_AUTO
57322+ help
57323+ If you say Y here, any changes of the system clock will be logged.
57324+ If the sysctl option is enabled, a sysctl option with name
57325+ "timechange_logging" is created.
57326+
57327+config GRKERNSEC_PROC_IPADDR
57328+ bool "/proc/<pid>/ipaddr support"
57329+ default y if GRKERNSEC_CONFIG_AUTO
57330+ help
57331+ If you say Y here, a new entry will be added to each /proc/<pid>
57332+ directory that contains the IP address of the person using the task.
57333+ The IP is carried across local TCP and AF_UNIX stream sockets.
57334+ This information can be useful for IDS/IPSes to perform remote response
57335+ to a local attack. The entry is readable by only the owner of the
57336+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
57337+ the RBAC system), and thus does not create privacy concerns.
57338+
57339+config GRKERNSEC_RWXMAP_LOG
57340+ bool 'Denied RWX mmap/mprotect logging'
57341+ default y if GRKERNSEC_CONFIG_AUTO
57342+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
57343+ help
57344+ If you say Y here, calls to mmap() and mprotect() with explicit
57345+ usage of PROT_WRITE and PROT_EXEC together will be logged when
57346+ denied by the PAX_MPROTECT feature. If the sysctl option is
57347+ enabled, a sysctl option with name "rwxmap_logging" is created.
57348+
57349+config GRKERNSEC_AUDIT_TEXTREL
57350+ bool 'ELF text relocations logging (READ HELP)'
57351+ depends on PAX_MPROTECT
57352+ help
57353+ If you say Y here, text relocations will be logged with the filename
57354+ of the offending library or binary. The purpose of the feature is
57355+ to help Linux distribution developers get rid of libraries and
57356+ binaries that need text relocations which hinder the future progress
57357+ of PaX. Only Linux distribution developers should say Y here, and
57358+ never on a production machine, as this option creates an information
57359+ leak that could aid an attacker in defeating the randomization of
57360+ a single memory region. If the sysctl option is enabled, a sysctl
57361+ option with name "audit_textrel" is created.
57362+
57363+endmenu
57364+
57365+menu "Executable Protections"
57366+depends on GRKERNSEC
57367+
57368+config GRKERNSEC_DMESG
57369+ bool "Dmesg(8) restriction"
57370+ default y if GRKERNSEC_CONFIG_AUTO
57371+ help
57372+ If you say Y here, non-root users will not be able to use dmesg(8)
57373+ to view the contents of the kernel's circular log buffer.
57374+ The kernel's log buffer often contains kernel addresses and other
57375+ identifying information useful to an attacker in fingerprinting a
57376+ system for a targeted exploit.
57377+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
57378+ created.
57379+
57380+config GRKERNSEC_HARDEN_PTRACE
57381+ bool "Deter ptrace-based process snooping"
57382+ default y if GRKERNSEC_CONFIG_AUTO
57383+ help
57384+ If you say Y here, TTY sniffers and other malicious monitoring
57385+ programs implemented through ptrace will be defeated. If you
57386+ have been using the RBAC system, this option has already been
57387+ enabled for several years for all users, with the ability to make
57388+ fine-grained exceptions.
57389+
57390+ This option only affects the ability of non-root users to ptrace
57391+ processes that are not a descendent of the ptracing process.
57392+ This means that strace ./binary and gdb ./binary will still work,
57393+ but attaching to arbitrary processes will not. If the sysctl
57394+ option is enabled, a sysctl option with name "harden_ptrace" is
57395+ created.
57396+
57397+config GRKERNSEC_PTRACE_READEXEC
57398+ bool "Require read access to ptrace sensitive binaries"
57399+ default y if GRKERNSEC_CONFIG_AUTO
57400+ help
57401+ If you say Y here, unprivileged users will not be able to ptrace unreadable
57402+ binaries. This option is useful in environments that
57403+ remove the read bits (e.g. file mode 4711) from suid binaries to
57404+ prevent infoleaking of their contents. This option adds
57405+ consistency to the use of that file mode, as the binary could normally
57406+ be read out when run without privileges while ptracing.
57407+
57408+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
57409+ is created.
57410+
57411+config GRKERNSEC_SETXID
57412+ bool "Enforce consistent multithreaded privileges"
57413+ default y if GRKERNSEC_CONFIG_AUTO
57414+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
57415+ help
57416+ If you say Y here, a change from a root uid to a non-root uid
57417+ in a multithreaded application will cause the resulting uids,
57418+ gids, supplementary groups, and capabilities in that thread
57419+ to be propagated to the other threads of the process. In most
57420+ cases this is unnecessary, as glibc will emulate this behavior
57421+ on behalf of the application. Other libcs do not act in the
57422+ same way, allowing the other threads of the process to continue
57423+ running with root privileges. If the sysctl option is enabled,
57424+ a sysctl option with name "consistent_setxid" is created.
57425+
57426+config GRKERNSEC_TPE
57427+ bool "Trusted Path Execution (TPE)"
57428+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
57429+ help
57430+ If you say Y here, you will be able to choose a gid to add to the
57431+ supplementary groups of users you want to mark as "untrusted."
57432+ These users will not be able to execute any files that are not in
57433+ root-owned directories writable only by root. If the sysctl option
57434+ is enabled, a sysctl option with name "tpe" is created.
57435+
57436+config GRKERNSEC_TPE_ALL
57437+ bool "Partially restrict all non-root users"
57438+ depends on GRKERNSEC_TPE
57439+ help
57440+ If you say Y here, all non-root users will be covered under
57441+ a weaker TPE restriction. This is separate from, and in addition to,
57442+ the main TPE options that you have selected elsewhere. Thus, if a
57443+ "trusted" GID is chosen, this restriction applies to even that GID.
57444+ Under this restriction, all non-root users will only be allowed to
57445+ execute files in directories they own that are not group or
57446+ world-writable, or in directories owned by root and writable only by
57447+ root. If the sysctl option is enabled, a sysctl option with name
57448+ "tpe_restrict_all" is created.
57449+
57450+config GRKERNSEC_TPE_INVERT
57451+ bool "Invert GID option"
57452+ depends on GRKERNSEC_TPE
57453+ help
57454+ If you say Y here, the group you specify in the TPE configuration will
57455+ decide what group TPE restrictions will be *disabled* for. This
57456+ option is useful if you want TPE restrictions to be applied to most
57457+ users on the system. If the sysctl option is enabled, a sysctl option
57458+ with name "tpe_invert" is created. Unlike other sysctl options, this
57459+ entry will default to on for backward-compatibility.
57460+
57461+config GRKERNSEC_TPE_GID
57462+ int
57463+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
57464+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
57465+
57466+config GRKERNSEC_TPE_UNTRUSTED_GID
57467+ int "GID for TPE-untrusted users"
57468+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
57469+ default 1005
57470+ help
57471+ Setting this GID determines what group TPE restrictions will be
57472+ *enabled* for. If the sysctl option is enabled, a sysctl option
57473+ with name "tpe_gid" is created.
57474+
57475+config GRKERNSEC_TPE_TRUSTED_GID
57476+ int "GID for TPE-trusted users"
57477+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
57478+ default 1005
57479+ help
57480+ Setting this GID determines what group TPE restrictions will be
57481+ *disabled* for. If the sysctl option is enabled, a sysctl option
57482+ with name "tpe_gid" is created.
57483+
57484+endmenu
57485+menu "Network Protections"
57486+depends on GRKERNSEC
57487+
57488+config GRKERNSEC_RANDNET
57489+ bool "Larger entropy pools"
57490+ default y if GRKERNSEC_CONFIG_AUTO
57491+ help
57492+ If you say Y here, the entropy pools used for many features of Linux
57493+ and grsecurity will be doubled in size. Since several grsecurity
57494+ features use additional randomness, it is recommended that you say Y
57495+ here. Saying Y here has a similar effect as modifying
57496+ /proc/sys/kernel/random/poolsize.
57497+
57498+config GRKERNSEC_BLACKHOLE
57499+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
57500+ default y if GRKERNSEC_CONFIG_AUTO
57501+ depends on NET
57502+ help
57503+ If you say Y here, neither TCP resets nor ICMP
57504+ destination-unreachable packets will be sent in response to packets
57505+ sent to ports for which no associated listening process exists.
57506+ This feature supports both IPV4 and IPV6 and exempts the
57507+ loopback interface from blackholing. Enabling this feature
57508+ makes a host more resilient to DoS attacks and reduces network
57509+ visibility against scanners.
57510+
57511+ The blackhole feature as-implemented is equivalent to the FreeBSD
57512+ blackhole feature, as it prevents RST responses to all packets, not
57513+ just SYNs. Under most application behavior this causes no
57514+ problems, but applications (like haproxy) may not close certain
57515+ connections in a way that cleanly terminates them on the remote
57516+ end, leaving the remote host in LAST_ACK state. Because of this
57517+ side-effect and to prevent intentional LAST_ACK DoSes, this
57518+ feature also adds automatic mitigation against such attacks.
57519+ The mitigation drastically reduces the amount of time a socket
57520+ can spend in LAST_ACK state. If you're using haproxy and not
57521+ all servers it connects to have this option enabled, consider
57522+ disabling this feature on the haproxy host.
57523+
57524+ If the sysctl option is enabled, two sysctl options with names
57525+ "ip_blackhole" and "lastack_retries" will be created.
57526+ While "ip_blackhole" takes the standard zero/non-zero on/off
57527+ toggle, "lastack_retries" uses the same kinds of values as
57528+ "tcp_retries1" and "tcp_retries2". The default value of 4
57529+ prevents a socket from lasting more than 45 seconds in LAST_ACK
57530+ state.
57531+
57532+config GRKERNSEC_NO_SIMULT_CONNECT
57533+ bool "Disable TCP Simultaneous Connect"
57534+ default y if GRKERNSEC_CONFIG_AUTO
57535+ depends on NET
57536+ help
57537+ If you say Y here, a feature by Willy Tarreau will be enabled that
57538+ removes a weakness in Linux's strict implementation of TCP that
57539+ allows two clients to connect to each other without either entering
57540+ a listening state. The weakness allows an attacker to easily prevent
57541+ a client from connecting to a known server provided the source port
57542+ for the connection is guessed correctly.
57543+
57544+ As the weakness could be used to prevent an antivirus or IPS from
57545+ fetching updates, or prevent an SSL gateway from fetching a CRL,
57546+ it should be eliminated by enabling this option. Though Linux is
57547+ one of few operating systems supporting simultaneous connect, it
57548+ has no legitimate use in practice and is rarely supported by firewalls.
57549+
57550+config GRKERNSEC_SOCKET
57551+ bool "Socket restrictions"
57552+ depends on NET
57553+ help
57554+ If you say Y here, you will be able to choose from several options.
57555+ If you assign a GID on your system and add it to the supplementary
57556+ groups of users you want to restrict socket access to, this patch
57557+ will perform up to three things, based on the option(s) you choose.
57558+
57559+config GRKERNSEC_SOCKET_ALL
57560+ bool "Deny any sockets to group"
57561+ depends on GRKERNSEC_SOCKET
57562+ help
57563+ If you say Y here, you will be able to choose a GID of whose users will
57564+ be unable to connect to other hosts from your machine or run server
57565+ applications from your machine. If the sysctl option is enabled, a
57566+ sysctl option with name "socket_all" is created.
57567+
57568+config GRKERNSEC_SOCKET_ALL_GID
57569+ int "GID to deny all sockets for"
57570+ depends on GRKERNSEC_SOCKET_ALL
57571+ default 1004
57572+ help
57573+ Here you can choose the GID to disable socket access for. Remember to
57574+ add the users you want socket access disabled for to the GID
57575+ specified here. If the sysctl option is enabled, a sysctl option
57576+ with name "socket_all_gid" is created.
57577+
57578+config GRKERNSEC_SOCKET_CLIENT
57579+ bool "Deny client sockets to group"
57580+ depends on GRKERNSEC_SOCKET
57581+ help
57582+ If you say Y here, you will be able to choose a GID of whose users will
57583+ be unable to connect to other hosts from your machine, but will be
57584+ able to run servers. If this option is enabled, all users in the group
57585+ you specify will have to use passive mode when initiating ftp transfers
57586+ from the shell on your machine. If the sysctl option is enabled, a
57587+ sysctl option with name "socket_client" is created.
57588+
57589+config GRKERNSEC_SOCKET_CLIENT_GID
57590+ int "GID to deny client sockets for"
57591+ depends on GRKERNSEC_SOCKET_CLIENT
57592+ default 1003
57593+ help
57594+ Here you can choose the GID to disable client socket access for.
57595+ Remember to add the users you want client socket access disabled for to
57596+ the GID specified here. If the sysctl option is enabled, a sysctl
57597+ option with name "socket_client_gid" is created.
57598+
57599+config GRKERNSEC_SOCKET_SERVER
57600+ bool "Deny server sockets to group"
57601+ depends on GRKERNSEC_SOCKET
57602+ help
57603+ If you say Y here, you will be able to choose a GID of whose users will
57604+ be unable to run server applications from your machine. If the sysctl
57605+ option is enabled, a sysctl option with name "socket_server" is created.
57606+
57607+config GRKERNSEC_SOCKET_SERVER_GID
57608+ int "GID to deny server sockets for"
57609+ depends on GRKERNSEC_SOCKET_SERVER
57610+ default 1002
57611+ help
57612+ Here you can choose the GID to disable server socket access for.
57613+ Remember to add the users you want server socket access disabled for to
57614+ the GID specified here. If the sysctl option is enabled, a sysctl
57615+ option with name "socket_server_gid" is created.
57616+
57617+endmenu
57618+menu "Sysctl Support"
57619+depends on GRKERNSEC && SYSCTL
57620+
57621+config GRKERNSEC_SYSCTL
57622+ bool "Sysctl support"
57623+ default y if GRKERNSEC_CONFIG_AUTO
57624+ help
57625+ If you say Y here, you will be able to change the options that
57626+ grsecurity runs with at bootup, without having to recompile your
57627+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
57628+ to enable (1) or disable (0) various features. All the sysctl entries
57629+ are mutable until the "grsec_lock" entry is set to a non-zero value.
57630+ All features enabled in the kernel configuration are disabled at boot
57631+ if you do not say Y to the "Turn on features by default" option.
57632+ All options should be set at startup, and the grsec_lock entry should
57633+ be set to a non-zero value after all the options are set.
57634+ *THIS IS EXTREMELY IMPORTANT*
57635+
57636+config GRKERNSEC_SYSCTL_DISTRO
57637+ bool "Extra sysctl support for distro makers (READ HELP)"
57638+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
57639+ help
57640+ If you say Y here, additional sysctl options will be created
57641+ for features that affect processes running as root. Therefore,
57642+ it is critical when using this option that the grsec_lock entry be
57643+ enabled after boot. Only distros with prebuilt kernel packages
57644+ with this option enabled that can ensure grsec_lock is enabled
57645+ after boot should use this option.
57646+ *Failure to set grsec_lock after boot makes all grsec features
57647+ this option covers useless*
57648+
57649+ Currently this option creates the following sysctl entries:
57650+ "Disable Privileged I/O": "disable_priv_io"
57651+
57652+config GRKERNSEC_SYSCTL_ON
57653+ bool "Turn on features by default"
57654+ default y if GRKERNSEC_CONFIG_AUTO
57655+ depends on GRKERNSEC_SYSCTL
57656+ help
57657+ If you say Y here, instead of having all features enabled in the
57658+ kernel configuration disabled at boot time, the features will be
57659+ enabled at boot time. It is recommended you say Y here unless
57660+ there is some reason you would want all sysctl-tunable features to
57661+ be disabled by default. As mentioned elsewhere, it is important
57662+ to enable the grsec_lock entry once you have finished modifying
57663+ the sysctl entries.
57664+
57665+endmenu
57666+menu "Logging Options"
57667+depends on GRKERNSEC
57668+
57669+config GRKERNSEC_FLOODTIME
57670+ int "Seconds in between log messages (minimum)"
57671+ default 10
57672+ help
57673+ This option allows you to enforce the number of seconds between
57674+ grsecurity log messages. The default should be suitable for most
57675+ people, however, if you choose to change it, choose a value small enough
57676+ to allow informative logs to be produced, but large enough to
57677+ prevent flooding.
57678+
57679+config GRKERNSEC_FLOODBURST
57680+ int "Number of messages in a burst (maximum)"
57681+ default 6
57682+ help
57683+ This option allows you to choose the maximum number of messages allowed
57684+ within the flood time interval you chose in a separate option. The
57685+ default should be suitable for most people, however if you find that
57686+ many of your logs are being interpreted as flooding, you may want to
57687+ raise this value.
57688+
57689+endmenu
57690diff --git a/grsecurity/Makefile b/grsecurity/Makefile
57691new file mode 100644
57692index 0000000..1b9afa9
57693--- /dev/null
57694+++ b/grsecurity/Makefile
57695@@ -0,0 +1,38 @@
57696+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
57697+# during 2001-2009 it has been completely redesigned by Brad Spengler
57698+# into an RBAC system
57699+#
57700+# All code in this directory and various hooks inserted throughout the kernel
57701+# are copyright Brad Spengler - Open Source Security, Inc., and released
57702+# under the GPL v2 or higher
57703+
57704+KBUILD_CFLAGS += -Werror
57705+
57706+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
57707+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
57708+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
57709+
57710+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
57711+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
57712+ gracl_learn.o grsec_log.o
57713+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
57714+
57715+ifdef CONFIG_NET
57716+obj-y += grsec_sock.o
57717+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
57718+endif
57719+
57720+ifndef CONFIG_GRKERNSEC
57721+obj-y += grsec_disabled.o
57722+endif
57723+
57724+ifdef CONFIG_GRKERNSEC_HIDESYM
57725+extra-y := grsec_hidesym.o
57726+$(obj)/grsec_hidesym.o:
57727+ @-chmod -f 500 /boot
57728+ @-chmod -f 500 /lib/modules
57729+ @-chmod -f 500 /lib64/modules
57730+ @-chmod -f 500 /lib32/modules
57731+ @-chmod -f 700 .
57732+ @echo ' grsec: protected kernel image paths'
57733+endif
57734diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
57735new file mode 100644
57736index 0000000..1248ee0
57737--- /dev/null
57738+++ b/grsecurity/gracl.c
57739@@ -0,0 +1,4073 @@
57740+#include <linux/kernel.h>
57741+#include <linux/module.h>
57742+#include <linux/sched.h>
57743+#include <linux/mm.h>
57744+#include <linux/file.h>
57745+#include <linux/fs.h>
57746+#include <linux/namei.h>
57747+#include <linux/mount.h>
57748+#include <linux/tty.h>
57749+#include <linux/proc_fs.h>
57750+#include <linux/lglock.h>
57751+#include <linux/slab.h>
57752+#include <linux/vmalloc.h>
57753+#include <linux/types.h>
57754+#include <linux/sysctl.h>
57755+#include <linux/netdevice.h>
57756+#include <linux/ptrace.h>
57757+#include <linux/gracl.h>
57758+#include <linux/gralloc.h>
57759+#include <linux/security.h>
57760+#include <linux/grinternal.h>
57761+#include <linux/pid_namespace.h>
57762+#include <linux/stop_machine.h>
57763+#include <linux/fdtable.h>
57764+#include <linux/percpu.h>
57765+#include <linux/lglock.h>
57766+#include <linux/hugetlb.h>
57767+#include <linux/posix-timers.h>
57768+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
57769+#include <linux/magic.h>
57770+#include <linux/pagemap.h>
57771+#include "../fs/btrfs/async-thread.h"
57772+#include "../fs/btrfs/ctree.h"
57773+#include "../fs/btrfs/btrfs_inode.h"
57774+#endif
57775+#include "../fs/mount.h"
57776+
57777+#include <asm/uaccess.h>
57778+#include <asm/errno.h>
57779+#include <asm/mman.h>
57780+
57781+extern struct lglock vfsmount_lock;
57782+
57783+static struct acl_role_db acl_role_set;
57784+static struct name_db name_set;
57785+static struct inodev_db inodev_set;
57786+
57787+/* for keeping track of userspace pointers used for subjects, so we
57788+ can share references in the kernel as well
57789+*/
57790+
57791+static struct path real_root;
57792+
57793+static struct acl_subj_map_db subj_map_set;
57794+
57795+static struct acl_role_label *default_role;
57796+
57797+static struct acl_role_label *role_list;
57798+
57799+static u16 acl_sp_role_value;
57800+
57801+extern char *gr_shared_page[4];
57802+static DEFINE_MUTEX(gr_dev_mutex);
57803+DEFINE_RWLOCK(gr_inode_lock);
57804+
57805+struct gr_arg *gr_usermode;
57806+
57807+static unsigned int gr_status __read_only = GR_STATUS_INIT;
57808+
57809+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
57810+extern void gr_clear_learn_entries(void);
57811+
57812+unsigned char *gr_system_salt;
57813+unsigned char *gr_system_sum;
57814+
57815+static struct sprole_pw **acl_special_roles = NULL;
57816+static __u16 num_sprole_pws = 0;
57817+
57818+static struct acl_role_label *kernel_role = NULL;
57819+
57820+static unsigned int gr_auth_attempts = 0;
57821+static unsigned long gr_auth_expires = 0UL;
57822+
57823+#ifdef CONFIG_NET
57824+extern struct vfsmount *sock_mnt;
57825+#endif
57826+
57827+extern struct vfsmount *pipe_mnt;
57828+extern struct vfsmount *shm_mnt;
57829+
57830+#ifdef CONFIG_HUGETLBFS
57831+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57832+#endif
57833+
57834+static struct acl_object_label *fakefs_obj_rw;
57835+static struct acl_object_label *fakefs_obj_rwx;
57836+
57837+extern int gr_init_uidset(void);
57838+extern void gr_free_uidset(void);
57839+extern void gr_remove_uid(uid_t uid);
57840+extern int gr_find_uid(uid_t uid);
57841+
57842+__inline__ int
57843+gr_acl_is_enabled(void)
57844+{
57845+ return (gr_status & GR_READY);
57846+}
57847+
57848+static inline dev_t __get_dev(const struct dentry *dentry)
57849+{
57850+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
57851+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
57852+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
57853+ else
57854+#endif
57855+ return dentry->d_sb->s_dev;
57856+}
57857+
57858+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57859+{
57860+ return __get_dev(dentry);
57861+}
57862+
57863+static char gr_task_roletype_to_char(struct task_struct *task)
57864+{
57865+ switch (task->role->roletype &
57866+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
57867+ GR_ROLE_SPECIAL)) {
57868+ case GR_ROLE_DEFAULT:
57869+ return 'D';
57870+ case GR_ROLE_USER:
57871+ return 'U';
57872+ case GR_ROLE_GROUP:
57873+ return 'G';
57874+ case GR_ROLE_SPECIAL:
57875+ return 'S';
57876+ }
57877+
57878+ return 'X';
57879+}
57880+
57881+char gr_roletype_to_char(void)
57882+{
57883+ return gr_task_roletype_to_char(current);
57884+}
57885+
57886+__inline__ int
57887+gr_acl_tpe_check(void)
57888+{
57889+ if (unlikely(!(gr_status & GR_READY)))
57890+ return 0;
57891+ if (current->role->roletype & GR_ROLE_TPE)
57892+ return 1;
57893+ else
57894+ return 0;
57895+}
57896+
57897+int
57898+gr_handle_rawio(const struct inode *inode)
57899+{
57900+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57901+ if (inode && S_ISBLK(inode->i_mode) &&
57902+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57903+ !capable(CAP_SYS_RAWIO))
57904+ return 1;
57905+#endif
57906+ return 0;
57907+}
57908+
57909+static int
57910+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
57911+{
57912+ if (likely(lena != lenb))
57913+ return 0;
57914+
57915+ return !memcmp(a, b, lena);
57916+}
57917+
57918+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
57919+{
57920+ *buflen -= namelen;
57921+ if (*buflen < 0)
57922+ return -ENAMETOOLONG;
57923+ *buffer -= namelen;
57924+ memcpy(*buffer, str, namelen);
57925+ return 0;
57926+}
57927+
57928+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
57929+{
57930+ return prepend(buffer, buflen, name->name, name->len);
57931+}
57932+
57933+static int prepend_path(const struct path *path, struct path *root,
57934+ char **buffer, int *buflen)
57935+{
57936+ struct dentry *dentry = path->dentry;
57937+ struct vfsmount *vfsmnt = path->mnt;
57938+ struct mount *mnt = real_mount(vfsmnt);
57939+ bool slash = false;
57940+ int error = 0;
57941+
57942+ while (dentry != root->dentry || vfsmnt != root->mnt) {
57943+ struct dentry * parent;
57944+
57945+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
57946+ /* Global root? */
57947+ if (!mnt_has_parent(mnt)) {
57948+ goto out;
57949+ }
57950+ dentry = mnt->mnt_mountpoint;
57951+ mnt = mnt->mnt_parent;
57952+ vfsmnt = &mnt->mnt;
57953+ continue;
57954+ }
57955+ parent = dentry->d_parent;
57956+ prefetch(parent);
57957+ spin_lock(&dentry->d_lock);
57958+ error = prepend_name(buffer, buflen, &dentry->d_name);
57959+ spin_unlock(&dentry->d_lock);
57960+ if (!error)
57961+ error = prepend(buffer, buflen, "/", 1);
57962+ if (error)
57963+ break;
57964+
57965+ slash = true;
57966+ dentry = parent;
57967+ }
57968+
57969+out:
57970+ if (!error && !slash)
57971+ error = prepend(buffer, buflen, "/", 1);
57972+
57973+ return error;
57974+}
57975+
57976+/* this must be called with vfsmount_lock and rename_lock held */
57977+
57978+static char *__our_d_path(const struct path *path, struct path *root,
57979+ char *buf, int buflen)
57980+{
57981+ char *res = buf + buflen;
57982+ int error;
57983+
57984+ prepend(&res, &buflen, "\0", 1);
57985+ error = prepend_path(path, root, &res, &buflen);
57986+ if (error)
57987+ return ERR_PTR(error);
57988+
57989+ return res;
57990+}
57991+
57992+static char *
57993+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
57994+{
57995+ char *retval;
57996+
57997+ retval = __our_d_path(path, root, buf, buflen);
57998+ if (unlikely(IS_ERR(retval)))
57999+ retval = strcpy(buf, "<path too long>");
58000+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
58001+ retval[1] = '\0';
58002+
58003+ return retval;
58004+}
58005+
58006+static char *
58007+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
58008+ char *buf, int buflen)
58009+{
58010+ struct path path;
58011+ char *res;
58012+
58013+ path.dentry = (struct dentry *)dentry;
58014+ path.mnt = (struct vfsmount *)vfsmnt;
58015+
58016+ /* we can use real_root.dentry, real_root.mnt, because this is only called
58017+ by the RBAC system */
58018+ res = gen_full_path(&path, &real_root, buf, buflen);
58019+
58020+ return res;
58021+}
58022+
58023+static char *
58024+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
58025+ char *buf, int buflen)
58026+{
58027+ char *res;
58028+ struct path path;
58029+ struct path root;
58030+ struct task_struct *reaper = init_pid_ns.child_reaper;
58031+
58032+ path.dentry = (struct dentry *)dentry;
58033+ path.mnt = (struct vfsmount *)vfsmnt;
58034+
58035+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
58036+ get_fs_root(reaper->fs, &root);
58037+
58038+ br_read_lock(&vfsmount_lock);
58039+ write_seqlock(&rename_lock);
58040+ res = gen_full_path(&path, &root, buf, buflen);
58041+ write_sequnlock(&rename_lock);
58042+ br_read_unlock(&vfsmount_lock);
58043+
58044+ path_put(&root);
58045+ return res;
58046+}
58047+
58048+static char *
58049+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
58050+{
58051+ char *ret;
58052+ br_read_lock(&vfsmount_lock);
58053+ write_seqlock(&rename_lock);
58054+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
58055+ PAGE_SIZE);
58056+ write_sequnlock(&rename_lock);
58057+ br_read_unlock(&vfsmount_lock);
58058+ return ret;
58059+}
58060+
58061+static char *
58062+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
58063+{
58064+ char *ret;
58065+ char *buf;
58066+ int buflen;
58067+
58068+ br_read_lock(&vfsmount_lock);
58069+ write_seqlock(&rename_lock);
58070+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
58071+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
58072+ buflen = (int)(ret - buf);
58073+ if (buflen >= 5)
58074+ prepend(&ret, &buflen, "/proc", 5);
58075+ else
58076+ ret = strcpy(buf, "<path too long>");
58077+ write_sequnlock(&rename_lock);
58078+ br_read_unlock(&vfsmount_lock);
58079+ return ret;
58080+}
58081+
58082+char *
58083+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
58084+{
58085+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
58086+ PAGE_SIZE);
58087+}
58088+
58089+char *
58090+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
58091+{
58092+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
58093+ PAGE_SIZE);
58094+}
58095+
58096+char *
58097+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
58098+{
58099+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
58100+ PAGE_SIZE);
58101+}
58102+
58103+char *
58104+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
58105+{
58106+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
58107+ PAGE_SIZE);
58108+}
58109+
58110+char *
58111+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
58112+{
58113+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
58114+ PAGE_SIZE);
58115+}
58116+
58117+__inline__ __u32
58118+to_gr_audit(const __u32 reqmode)
58119+{
58120+ /* masks off auditable permission flags, then shifts them to create
58121+ auditing flags, and adds the special case of append auditing if
58122+ we're requesting write */
58123+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
58124+}
58125+
58126+struct acl_subject_label *
58127+lookup_subject_map(const struct acl_subject_label *userp)
58128+{
58129+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
58130+ struct subject_map *match;
58131+
58132+ match = subj_map_set.s_hash[index];
58133+
58134+ while (match && match->user != userp)
58135+ match = match->next;
58136+
58137+ if (match != NULL)
58138+ return match->kernel;
58139+ else
58140+ return NULL;
58141+}
58142+
58143+static void
58144+insert_subj_map_entry(struct subject_map *subjmap)
58145+{
58146+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
58147+ struct subject_map **curr;
58148+
58149+ subjmap->prev = NULL;
58150+
58151+ curr = &subj_map_set.s_hash[index];
58152+ if (*curr != NULL)
58153+ (*curr)->prev = subjmap;
58154+
58155+ subjmap->next = *curr;
58156+ *curr = subjmap;
58157+
58158+ return;
58159+}
58160+
58161+static struct acl_role_label *
58162+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
58163+ const gid_t gid)
58164+{
58165+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
58166+ struct acl_role_label *match;
58167+ struct role_allowed_ip *ipp;
58168+ unsigned int x;
58169+ u32 curr_ip = task->signal->curr_ip;
58170+
58171+ task->signal->saved_ip = curr_ip;
58172+
58173+ match = acl_role_set.r_hash[index];
58174+
58175+ while (match) {
58176+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
58177+ for (x = 0; x < match->domain_child_num; x++) {
58178+ if (match->domain_children[x] == uid)
58179+ goto found;
58180+ }
58181+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
58182+ break;
58183+ match = match->next;
58184+ }
58185+found:
58186+ if (match == NULL) {
58187+ try_group:
58188+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
58189+ match = acl_role_set.r_hash[index];
58190+
58191+ while (match) {
58192+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
58193+ for (x = 0; x < match->domain_child_num; x++) {
58194+ if (match->domain_children[x] == gid)
58195+ goto found2;
58196+ }
58197+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
58198+ break;
58199+ match = match->next;
58200+ }
58201+found2:
58202+ if (match == NULL)
58203+ match = default_role;
58204+ if (match->allowed_ips == NULL)
58205+ return match;
58206+ else {
58207+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
58208+ if (likely
58209+ ((ntohl(curr_ip) & ipp->netmask) ==
58210+ (ntohl(ipp->addr) & ipp->netmask)))
58211+ return match;
58212+ }
58213+ match = default_role;
58214+ }
58215+ } else if (match->allowed_ips == NULL) {
58216+ return match;
58217+ } else {
58218+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
58219+ if (likely
58220+ ((ntohl(curr_ip) & ipp->netmask) ==
58221+ (ntohl(ipp->addr) & ipp->netmask)))
58222+ return match;
58223+ }
58224+ goto try_group;
58225+ }
58226+
58227+ return match;
58228+}
58229+
58230+struct acl_subject_label *
58231+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
58232+ const struct acl_role_label *role)
58233+{
58234+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
58235+ struct acl_subject_label *match;
58236+
58237+ match = role->subj_hash[index];
58238+
58239+ while (match && (match->inode != ino || match->device != dev ||
58240+ (match->mode & GR_DELETED))) {
58241+ match = match->next;
58242+ }
58243+
58244+ if (match && !(match->mode & GR_DELETED))
58245+ return match;
58246+ else
58247+ return NULL;
58248+}
58249+
58250+struct acl_subject_label *
58251+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
58252+ const struct acl_role_label *role)
58253+{
58254+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
58255+ struct acl_subject_label *match;
58256+
58257+ match = role->subj_hash[index];
58258+
58259+ while (match && (match->inode != ino || match->device != dev ||
58260+ !(match->mode & GR_DELETED))) {
58261+ match = match->next;
58262+ }
58263+
58264+ if (match && (match->mode & GR_DELETED))
58265+ return match;
58266+ else
58267+ return NULL;
58268+}
58269+
58270+static struct acl_object_label *
58271+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
58272+ const struct acl_subject_label *subj)
58273+{
58274+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
58275+ struct acl_object_label *match;
58276+
58277+ match = subj->obj_hash[index];
58278+
58279+ while (match && (match->inode != ino || match->device != dev ||
58280+ (match->mode & GR_DELETED))) {
58281+ match = match->next;
58282+ }
58283+
58284+ if (match && !(match->mode & GR_DELETED))
58285+ return match;
58286+ else
58287+ return NULL;
58288+}
58289+
58290+static struct acl_object_label *
58291+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
58292+ const struct acl_subject_label *subj)
58293+{
58294+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
58295+ struct acl_object_label *match;
58296+
58297+ match = subj->obj_hash[index];
58298+
58299+ while (match && (match->inode != ino || match->device != dev ||
58300+ !(match->mode & GR_DELETED))) {
58301+ match = match->next;
58302+ }
58303+
58304+ if (match && (match->mode & GR_DELETED))
58305+ return match;
58306+
58307+ match = subj->obj_hash[index];
58308+
58309+ while (match && (match->inode != ino || match->device != dev ||
58310+ (match->mode & GR_DELETED))) {
58311+ match = match->next;
58312+ }
58313+
58314+ if (match && !(match->mode & GR_DELETED))
58315+ return match;
58316+ else
58317+ return NULL;
58318+}
58319+
58320+static struct name_entry *
58321+lookup_name_entry(const char *name)
58322+{
58323+ unsigned int len = strlen(name);
58324+ unsigned int key = full_name_hash(name, len);
58325+ unsigned int index = key % name_set.n_size;
58326+ struct name_entry *match;
58327+
58328+ match = name_set.n_hash[index];
58329+
58330+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
58331+ match = match->next;
58332+
58333+ return match;
58334+}
58335+
58336+static struct name_entry *
58337+lookup_name_entry_create(const char *name)
58338+{
58339+ unsigned int len = strlen(name);
58340+ unsigned int key = full_name_hash(name, len);
58341+ unsigned int index = key % name_set.n_size;
58342+ struct name_entry *match;
58343+
58344+ match = name_set.n_hash[index];
58345+
58346+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
58347+ !match->deleted))
58348+ match = match->next;
58349+
58350+ if (match && match->deleted)
58351+ return match;
58352+
58353+ match = name_set.n_hash[index];
58354+
58355+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
58356+ match->deleted))
58357+ match = match->next;
58358+
58359+ if (match && !match->deleted)
58360+ return match;
58361+ else
58362+ return NULL;
58363+}
58364+
58365+static struct inodev_entry *
58366+lookup_inodev_entry(const ino_t ino, const dev_t dev)
58367+{
58368+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
58369+ struct inodev_entry *match;
58370+
58371+ match = inodev_set.i_hash[index];
58372+
58373+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
58374+ match = match->next;
58375+
58376+ return match;
58377+}
58378+
58379+static void
58380+insert_inodev_entry(struct inodev_entry *entry)
58381+{
58382+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
58383+ inodev_set.i_size);
58384+ struct inodev_entry **curr;
58385+
58386+ entry->prev = NULL;
58387+
58388+ curr = &inodev_set.i_hash[index];
58389+ if (*curr != NULL)
58390+ (*curr)->prev = entry;
58391+
58392+ entry->next = *curr;
58393+ *curr = entry;
58394+
58395+ return;
58396+}
58397+
58398+static void
58399+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
58400+{
58401+ unsigned int index =
58402+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
58403+ struct acl_role_label **curr;
58404+ struct acl_role_label *tmp, *tmp2;
58405+
58406+ curr = &acl_role_set.r_hash[index];
58407+
58408+ /* simple case, slot is empty, just set it to our role */
58409+ if (*curr == NULL) {
58410+ *curr = role;
58411+ } else {
58412+ /* example:
58413+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
58414+ 2 -> 3
58415+ */
58416+ /* first check to see if we can already be reached via this slot */
58417+ tmp = *curr;
58418+ while (tmp && tmp != role)
58419+ tmp = tmp->next;
58420+ if (tmp == role) {
58421+ /* we don't need to add ourselves to this slot's chain */
58422+ return;
58423+ }
58424+ /* we need to add ourselves to this chain, two cases */
58425+ if (role->next == NULL) {
58426+ /* simple case, append the current chain to our role */
58427+ role->next = *curr;
58428+ *curr = role;
58429+ } else {
58430+ /* 1 -> 2 -> 3 -> 4
58431+ 2 -> 3 -> 4
58432+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
58433+ */
58434+ /* trickier case: walk our role's chain until we find
58435+ the role for the start of the current slot's chain */
58436+ tmp = role;
58437+ tmp2 = *curr;
58438+ while (tmp->next && tmp->next != tmp2)
58439+ tmp = tmp->next;
58440+ if (tmp->next == tmp2) {
58441+ /* from example above, we found 3, so just
58442+ replace this slot's chain with ours */
58443+ *curr = role;
58444+ } else {
58445+ /* we didn't find a subset of our role's chain
58446+ in the current slot's chain, so append their
58447+ chain to ours, and set us as the first role in
58448+ the slot's chain
58449+
58450+ we could fold this case with the case above,
58451+ but making it explicit for clarity
58452+ */
58453+ tmp->next = tmp2;
58454+ *curr = role;
58455+ }
58456+ }
58457+ }
58458+
58459+ return;
58460+}
58461+
58462+static void
58463+insert_acl_role_label(struct acl_role_label *role)
58464+{
58465+ int i;
58466+
58467+ if (role_list == NULL) {
58468+ role_list = role;
58469+ role->prev = NULL;
58470+ } else {
58471+ role->prev = role_list;
58472+ role_list = role;
58473+ }
58474+
58475+ /* used for hash chains */
58476+ role->next = NULL;
58477+
58478+ if (role->roletype & GR_ROLE_DOMAIN) {
58479+ for (i = 0; i < role->domain_child_num; i++)
58480+ __insert_acl_role_label(role, role->domain_children[i]);
58481+ } else
58482+ __insert_acl_role_label(role, role->uidgid);
58483+}
58484+
58485+static int
58486+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
58487+{
58488+ struct name_entry **curr, *nentry;
58489+ struct inodev_entry *ientry;
58490+ unsigned int len = strlen(name);
58491+ unsigned int key = full_name_hash(name, len);
58492+ unsigned int index = key % name_set.n_size;
58493+
58494+ curr = &name_set.n_hash[index];
58495+
58496+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
58497+ curr = &((*curr)->next);
58498+
58499+ if (*curr != NULL)
58500+ return 1;
58501+
58502+ nentry = acl_alloc(sizeof (struct name_entry));
58503+ if (nentry == NULL)
58504+ return 0;
58505+ ientry = acl_alloc(sizeof (struct inodev_entry));
58506+ if (ientry == NULL)
58507+ return 0;
58508+ ientry->nentry = nentry;
58509+
58510+ nentry->key = key;
58511+ nentry->name = name;
58512+ nentry->inode = inode;
58513+ nentry->device = device;
58514+ nentry->len = len;
58515+ nentry->deleted = deleted;
58516+
58517+ nentry->prev = NULL;
58518+ curr = &name_set.n_hash[index];
58519+ if (*curr != NULL)
58520+ (*curr)->prev = nentry;
58521+ nentry->next = *curr;
58522+ *curr = nentry;
58523+
58524+ /* insert us into the table searchable by inode/dev */
58525+ insert_inodev_entry(ientry);
58526+
58527+ return 1;
58528+}
58529+
58530+static void
58531+insert_acl_obj_label(struct acl_object_label *obj,
58532+ struct acl_subject_label *subj)
58533+{
58534+ unsigned int index =
58535+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
58536+ struct acl_object_label **curr;
58537+
58538+
58539+ obj->prev = NULL;
58540+
58541+ curr = &subj->obj_hash[index];
58542+ if (*curr != NULL)
58543+ (*curr)->prev = obj;
58544+
58545+ obj->next = *curr;
58546+ *curr = obj;
58547+
58548+ return;
58549+}
58550+
58551+static void
58552+insert_acl_subj_label(struct acl_subject_label *obj,
58553+ struct acl_role_label *role)
58554+{
58555+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
58556+ struct acl_subject_label **curr;
58557+
58558+ obj->prev = NULL;
58559+
58560+ curr = &role->subj_hash[index];
58561+ if (*curr != NULL)
58562+ (*curr)->prev = obj;
58563+
58564+ obj->next = *curr;
58565+ *curr = obj;
58566+
58567+ return;
58568+}
58569+
58570+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
58571+
58572+static void *
58573+create_table(__u32 * len, int elementsize)
58574+{
58575+ unsigned int table_sizes[] = {
58576+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
58577+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
58578+ 4194301, 8388593, 16777213, 33554393, 67108859
58579+ };
58580+ void *newtable = NULL;
58581+ unsigned int pwr = 0;
58582+
58583+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
58584+ table_sizes[pwr] <= *len)
58585+ pwr++;
58586+
58587+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
58588+ return newtable;
58589+
58590+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
58591+ newtable =
58592+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
58593+ else
58594+ newtable = vmalloc(table_sizes[pwr] * elementsize);
58595+
58596+ *len = table_sizes[pwr];
58597+
58598+ return newtable;
58599+}
58600+
58601+static int
58602+init_variables(const struct gr_arg *arg)
58603+{
58604+ struct task_struct *reaper = init_pid_ns.child_reaper;
58605+ unsigned int stacksize;
58606+
58607+ subj_map_set.s_size = arg->role_db.num_subjects;
58608+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
58609+ name_set.n_size = arg->role_db.num_objects;
58610+ inodev_set.i_size = arg->role_db.num_objects;
58611+
58612+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
58613+ !name_set.n_size || !inodev_set.i_size)
58614+ return 1;
58615+
58616+ if (!gr_init_uidset())
58617+ return 1;
58618+
58619+ /* set up the stack that holds allocation info */
58620+
58621+ stacksize = arg->role_db.num_pointers + 5;
58622+
58623+ if (!acl_alloc_stack_init(stacksize))
58624+ return 1;
58625+
58626+ /* grab reference for the real root dentry and vfsmount */
58627+ get_fs_root(reaper->fs, &real_root);
58628+
58629+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58630+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
58631+#endif
58632+
58633+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
58634+ if (fakefs_obj_rw == NULL)
58635+ return 1;
58636+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
58637+
58638+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
58639+ if (fakefs_obj_rwx == NULL)
58640+ return 1;
58641+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
58642+
58643+ subj_map_set.s_hash =
58644+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
58645+ acl_role_set.r_hash =
58646+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
58647+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
58648+ inodev_set.i_hash =
58649+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
58650+
58651+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
58652+ !name_set.n_hash || !inodev_set.i_hash)
58653+ return 1;
58654+
58655+ memset(subj_map_set.s_hash, 0,
58656+ sizeof(struct subject_map *) * subj_map_set.s_size);
58657+ memset(acl_role_set.r_hash, 0,
58658+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
58659+ memset(name_set.n_hash, 0,
58660+ sizeof (struct name_entry *) * name_set.n_size);
58661+ memset(inodev_set.i_hash, 0,
58662+ sizeof (struct inodev_entry *) * inodev_set.i_size);
58663+
58664+ return 0;
58665+}
58666+
58667+/* free information not needed after startup
58668+ currently contains user->kernel pointer mappings for subjects
58669+*/
58670+
58671+static void
58672+free_init_variables(void)
58673+{
58674+ __u32 i;
58675+
58676+ if (subj_map_set.s_hash) {
58677+ for (i = 0; i < subj_map_set.s_size; i++) {
58678+ if (subj_map_set.s_hash[i]) {
58679+ kfree(subj_map_set.s_hash[i]);
58680+ subj_map_set.s_hash[i] = NULL;
58681+ }
58682+ }
58683+
58684+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
58685+ PAGE_SIZE)
58686+ kfree(subj_map_set.s_hash);
58687+ else
58688+ vfree(subj_map_set.s_hash);
58689+ }
58690+
58691+ return;
58692+}
58693+
58694+static void
58695+free_variables(void)
58696+{
58697+ struct acl_subject_label *s;
58698+ struct acl_role_label *r;
58699+ struct task_struct *task, *task2;
58700+ unsigned int x;
58701+
58702+ gr_clear_learn_entries();
58703+
58704+ read_lock(&tasklist_lock);
58705+ do_each_thread(task2, task) {
58706+ task->acl_sp_role = 0;
58707+ task->acl_role_id = 0;
58708+ task->acl = NULL;
58709+ task->role = NULL;
58710+ } while_each_thread(task2, task);
58711+ read_unlock(&tasklist_lock);
58712+
58713+ /* release the reference to the real root dentry and vfsmount */
58714+ path_put(&real_root);
58715+ memset(&real_root, 0, sizeof(real_root));
58716+
58717+ /* free all object hash tables */
58718+
58719+ FOR_EACH_ROLE_START(r)
58720+ if (r->subj_hash == NULL)
58721+ goto next_role;
58722+ FOR_EACH_SUBJECT_START(r, s, x)
58723+ if (s->obj_hash == NULL)
58724+ break;
58725+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
58726+ kfree(s->obj_hash);
58727+ else
58728+ vfree(s->obj_hash);
58729+ FOR_EACH_SUBJECT_END(s, x)
58730+ FOR_EACH_NESTED_SUBJECT_START(r, s)
58731+ if (s->obj_hash == NULL)
58732+ break;
58733+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
58734+ kfree(s->obj_hash);
58735+ else
58736+ vfree(s->obj_hash);
58737+ FOR_EACH_NESTED_SUBJECT_END(s)
58738+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
58739+ kfree(r->subj_hash);
58740+ else
58741+ vfree(r->subj_hash);
58742+ r->subj_hash = NULL;
58743+next_role:
58744+ FOR_EACH_ROLE_END(r)
58745+
58746+ acl_free_all();
58747+
58748+ if (acl_role_set.r_hash) {
58749+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
58750+ PAGE_SIZE)
58751+ kfree(acl_role_set.r_hash);
58752+ else
58753+ vfree(acl_role_set.r_hash);
58754+ }
58755+ if (name_set.n_hash) {
58756+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
58757+ PAGE_SIZE)
58758+ kfree(name_set.n_hash);
58759+ else
58760+ vfree(name_set.n_hash);
58761+ }
58762+
58763+ if (inodev_set.i_hash) {
58764+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
58765+ PAGE_SIZE)
58766+ kfree(inodev_set.i_hash);
58767+ else
58768+ vfree(inodev_set.i_hash);
58769+ }
58770+
58771+ gr_free_uidset();
58772+
58773+ memset(&name_set, 0, sizeof (struct name_db));
58774+ memset(&inodev_set, 0, sizeof (struct inodev_db));
58775+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
58776+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
58777+
58778+ default_role = NULL;
58779+ kernel_role = NULL;
58780+ role_list = NULL;
58781+
58782+ return;
58783+}
58784+
58785+static __u32
58786+count_user_objs(struct acl_object_label *userp)
58787+{
58788+ struct acl_object_label o_tmp;
58789+ __u32 num = 0;
58790+
58791+ while (userp) {
58792+ if (copy_from_user(&o_tmp, userp,
58793+ sizeof (struct acl_object_label)))
58794+ break;
58795+
58796+ userp = o_tmp.prev;
58797+ num++;
58798+ }
58799+
58800+ return num;
58801+}
58802+
58803+static struct acl_subject_label *
58804+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
58805+
58806+static int
58807+copy_user_glob(struct acl_object_label *obj)
58808+{
58809+ struct acl_object_label *g_tmp, **guser;
58810+ unsigned int len;
58811+ char *tmp;
58812+
58813+ if (obj->globbed == NULL)
58814+ return 0;
58815+
58816+ guser = &obj->globbed;
58817+ while (*guser) {
58818+ g_tmp = (struct acl_object_label *)
58819+ acl_alloc(sizeof (struct acl_object_label));
58820+ if (g_tmp == NULL)
58821+ return -ENOMEM;
58822+
58823+ if (copy_from_user(g_tmp, *guser,
58824+ sizeof (struct acl_object_label)))
58825+ return -EFAULT;
58826+
58827+ len = strnlen_user(g_tmp->filename, PATH_MAX);
58828+
58829+ if (!len || len >= PATH_MAX)
58830+ return -EINVAL;
58831+
58832+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58833+ return -ENOMEM;
58834+
58835+ if (copy_from_user(tmp, g_tmp->filename, len))
58836+ return -EFAULT;
58837+ tmp[len-1] = '\0';
58838+ g_tmp->filename = tmp;
58839+
58840+ *guser = g_tmp;
58841+ guser = &(g_tmp->next);
58842+ }
58843+
58844+ return 0;
58845+}
58846+
58847+static int
58848+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
58849+ struct acl_role_label *role)
58850+{
58851+ struct acl_object_label *o_tmp;
58852+ unsigned int len;
58853+ int ret;
58854+ char *tmp;
58855+
58856+ while (userp) {
58857+ if ((o_tmp = (struct acl_object_label *)
58858+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
58859+ return -ENOMEM;
58860+
58861+ if (copy_from_user(o_tmp, userp,
58862+ sizeof (struct acl_object_label)))
58863+ return -EFAULT;
58864+
58865+ userp = o_tmp->prev;
58866+
58867+ len = strnlen_user(o_tmp->filename, PATH_MAX);
58868+
58869+ if (!len || len >= PATH_MAX)
58870+ return -EINVAL;
58871+
58872+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58873+ return -ENOMEM;
58874+
58875+ if (copy_from_user(tmp, o_tmp->filename, len))
58876+ return -EFAULT;
58877+ tmp[len-1] = '\0';
58878+ o_tmp->filename = tmp;
58879+
58880+ insert_acl_obj_label(o_tmp, subj);
58881+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
58882+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
58883+ return -ENOMEM;
58884+
58885+ ret = copy_user_glob(o_tmp);
58886+ if (ret)
58887+ return ret;
58888+
58889+ if (o_tmp->nested) {
58890+ int already_copied;
58891+
58892+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
58893+ if (IS_ERR(o_tmp->nested))
58894+ return PTR_ERR(o_tmp->nested);
58895+
58896+ /* insert into nested subject list if we haven't copied this one yet
58897+ to prevent duplicate entries */
58898+ if (!already_copied) {
58899+ o_tmp->nested->next = role->hash->first;
58900+ role->hash->first = o_tmp->nested;
58901+ }
58902+ }
58903+ }
58904+
58905+ return 0;
58906+}
58907+
58908+static __u32
58909+count_user_subjs(struct acl_subject_label *userp)
58910+{
58911+ struct acl_subject_label s_tmp;
58912+ __u32 num = 0;
58913+
58914+ while (userp) {
58915+ if (copy_from_user(&s_tmp, userp,
58916+ sizeof (struct acl_subject_label)))
58917+ break;
58918+
58919+ userp = s_tmp.prev;
58920+ }
58921+
58922+ return num;
58923+}
58924+
58925+static int
58926+copy_user_allowedips(struct acl_role_label *rolep)
58927+{
58928+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
58929+
58930+ ruserip = rolep->allowed_ips;
58931+
58932+ while (ruserip) {
58933+ rlast = rtmp;
58934+
58935+ if ((rtmp = (struct role_allowed_ip *)
58936+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
58937+ return -ENOMEM;
58938+
58939+ if (copy_from_user(rtmp, ruserip,
58940+ sizeof (struct role_allowed_ip)))
58941+ return -EFAULT;
58942+
58943+ ruserip = rtmp->prev;
58944+
58945+ if (!rlast) {
58946+ rtmp->prev = NULL;
58947+ rolep->allowed_ips = rtmp;
58948+ } else {
58949+ rlast->next = rtmp;
58950+ rtmp->prev = rlast;
58951+ }
58952+
58953+ if (!ruserip)
58954+ rtmp->next = NULL;
58955+ }
58956+
58957+ return 0;
58958+}
58959+
58960+static int
58961+copy_user_transitions(struct acl_role_label *rolep)
58962+{
58963+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
58964+
58965+ unsigned int len;
58966+ char *tmp;
58967+
58968+ rusertp = rolep->transitions;
58969+
58970+ while (rusertp) {
58971+ rlast = rtmp;
58972+
58973+ if ((rtmp = (struct role_transition *)
58974+ acl_alloc(sizeof (struct role_transition))) == NULL)
58975+ return -ENOMEM;
58976+
58977+ if (copy_from_user(rtmp, rusertp,
58978+ sizeof (struct role_transition)))
58979+ return -EFAULT;
58980+
58981+ rusertp = rtmp->prev;
58982+
58983+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
58984+
58985+ if (!len || len >= GR_SPROLE_LEN)
58986+ return -EINVAL;
58987+
58988+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58989+ return -ENOMEM;
58990+
58991+ if (copy_from_user(tmp, rtmp->rolename, len))
58992+ return -EFAULT;
58993+ tmp[len-1] = '\0';
58994+ rtmp->rolename = tmp;
58995+
58996+ if (!rlast) {
58997+ rtmp->prev = NULL;
58998+ rolep->transitions = rtmp;
58999+ } else {
59000+ rlast->next = rtmp;
59001+ rtmp->prev = rlast;
59002+ }
59003+
59004+ if (!rusertp)
59005+ rtmp->next = NULL;
59006+ }
59007+
59008+ return 0;
59009+}
59010+
59011+static struct acl_subject_label *
59012+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
59013+{
59014+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
59015+ unsigned int len;
59016+ char *tmp;
59017+ __u32 num_objs;
59018+ struct acl_ip_label **i_tmp, *i_utmp2;
59019+ struct gr_hash_struct ghash;
59020+ struct subject_map *subjmap;
59021+ unsigned int i_num;
59022+ int err;
59023+
59024+ if (already_copied != NULL)
59025+ *already_copied = 0;
59026+
59027+ s_tmp = lookup_subject_map(userp);
59028+
59029+ /* we've already copied this subject into the kernel, just return
59030+ the reference to it, and don't copy it over again
59031+ */
59032+ if (s_tmp) {
59033+ if (already_copied != NULL)
59034+ *already_copied = 1;
59035+ return(s_tmp);
59036+ }
59037+
59038+ if ((s_tmp = (struct acl_subject_label *)
59039+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
59040+ return ERR_PTR(-ENOMEM);
59041+
59042+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
59043+ if (subjmap == NULL)
59044+ return ERR_PTR(-ENOMEM);
59045+
59046+ subjmap->user = userp;
59047+ subjmap->kernel = s_tmp;
59048+ insert_subj_map_entry(subjmap);
59049+
59050+ if (copy_from_user(s_tmp, userp,
59051+ sizeof (struct acl_subject_label)))
59052+ return ERR_PTR(-EFAULT);
59053+
59054+ len = strnlen_user(s_tmp->filename, PATH_MAX);
59055+
59056+ if (!len || len >= PATH_MAX)
59057+ return ERR_PTR(-EINVAL);
59058+
59059+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59060+ return ERR_PTR(-ENOMEM);
59061+
59062+ if (copy_from_user(tmp, s_tmp->filename, len))
59063+ return ERR_PTR(-EFAULT);
59064+ tmp[len-1] = '\0';
59065+ s_tmp->filename = tmp;
59066+
59067+ if (!strcmp(s_tmp->filename, "/"))
59068+ role->root_label = s_tmp;
59069+
59070+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
59071+ return ERR_PTR(-EFAULT);
59072+
59073+ /* copy user and group transition tables */
59074+
59075+ if (s_tmp->user_trans_num) {
59076+ uid_t *uidlist;
59077+
59078+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
59079+ if (uidlist == NULL)
59080+ return ERR_PTR(-ENOMEM);
59081+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
59082+ return ERR_PTR(-EFAULT);
59083+
59084+ s_tmp->user_transitions = uidlist;
59085+ }
59086+
59087+ if (s_tmp->group_trans_num) {
59088+ gid_t *gidlist;
59089+
59090+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
59091+ if (gidlist == NULL)
59092+ return ERR_PTR(-ENOMEM);
59093+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
59094+ return ERR_PTR(-EFAULT);
59095+
59096+ s_tmp->group_transitions = gidlist;
59097+ }
59098+
59099+ /* set up object hash table */
59100+ num_objs = count_user_objs(ghash.first);
59101+
59102+ s_tmp->obj_hash_size = num_objs;
59103+ s_tmp->obj_hash =
59104+ (struct acl_object_label **)
59105+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
59106+
59107+ if (!s_tmp->obj_hash)
59108+ return ERR_PTR(-ENOMEM);
59109+
59110+ memset(s_tmp->obj_hash, 0,
59111+ s_tmp->obj_hash_size *
59112+ sizeof (struct acl_object_label *));
59113+
59114+ /* add in objects */
59115+ err = copy_user_objs(ghash.first, s_tmp, role);
59116+
59117+ if (err)
59118+ return ERR_PTR(err);
59119+
59120+ /* set pointer for parent subject */
59121+ if (s_tmp->parent_subject) {
59122+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
59123+
59124+ if (IS_ERR(s_tmp2))
59125+ return s_tmp2;
59126+
59127+ s_tmp->parent_subject = s_tmp2;
59128+ }
59129+
59130+ /* add in ip acls */
59131+
59132+ if (!s_tmp->ip_num) {
59133+ s_tmp->ips = NULL;
59134+ goto insert;
59135+ }
59136+
59137+ i_tmp =
59138+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
59139+ sizeof (struct acl_ip_label *));
59140+
59141+ if (!i_tmp)
59142+ return ERR_PTR(-ENOMEM);
59143+
59144+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
59145+ *(i_tmp + i_num) =
59146+ (struct acl_ip_label *)
59147+ acl_alloc(sizeof (struct acl_ip_label));
59148+ if (!*(i_tmp + i_num))
59149+ return ERR_PTR(-ENOMEM);
59150+
59151+ if (copy_from_user
59152+ (&i_utmp2, s_tmp->ips + i_num,
59153+ sizeof (struct acl_ip_label *)))
59154+ return ERR_PTR(-EFAULT);
59155+
59156+ if (copy_from_user
59157+ (*(i_tmp + i_num), i_utmp2,
59158+ sizeof (struct acl_ip_label)))
59159+ return ERR_PTR(-EFAULT);
59160+
59161+ if ((*(i_tmp + i_num))->iface == NULL)
59162+ continue;
59163+
59164+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
59165+ if (!len || len >= IFNAMSIZ)
59166+ return ERR_PTR(-EINVAL);
59167+ tmp = acl_alloc(len);
59168+ if (tmp == NULL)
59169+ return ERR_PTR(-ENOMEM);
59170+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
59171+ return ERR_PTR(-EFAULT);
59172+ (*(i_tmp + i_num))->iface = tmp;
59173+ }
59174+
59175+ s_tmp->ips = i_tmp;
59176+
59177+insert:
59178+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
59179+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
59180+ return ERR_PTR(-ENOMEM);
59181+
59182+ return s_tmp;
59183+}
59184+
59185+static int
59186+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
59187+{
59188+ struct acl_subject_label s_pre;
59189+ struct acl_subject_label * ret;
59190+ int err;
59191+
59192+ while (userp) {
59193+ if (copy_from_user(&s_pre, userp,
59194+ sizeof (struct acl_subject_label)))
59195+ return -EFAULT;
59196+
59197+ ret = do_copy_user_subj(userp, role, NULL);
59198+
59199+ err = PTR_ERR(ret);
59200+ if (IS_ERR(ret))
59201+ return err;
59202+
59203+ insert_acl_subj_label(ret, role);
59204+
59205+ userp = s_pre.prev;
59206+ }
59207+
59208+ return 0;
59209+}
59210+
59211+static int
59212+copy_user_acl(struct gr_arg *arg)
59213+{
59214+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
59215+ struct acl_subject_label *subj_list;
59216+ struct sprole_pw *sptmp;
59217+ struct gr_hash_struct *ghash;
59218+ uid_t *domainlist;
59219+ unsigned int r_num;
59220+ unsigned int len;
59221+ char *tmp;
59222+ int err = 0;
59223+ __u16 i;
59224+ __u32 num_subjs;
59225+
59226+ /* we need a default and kernel role */
59227+ if (arg->role_db.num_roles < 2)
59228+ return -EINVAL;
59229+
59230+ /* copy special role authentication info from userspace */
59231+
59232+ num_sprole_pws = arg->num_sprole_pws;
59233+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
59234+
59235+ if (!acl_special_roles && num_sprole_pws)
59236+ return -ENOMEM;
59237+
59238+ for (i = 0; i < num_sprole_pws; i++) {
59239+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
59240+ if (!sptmp)
59241+ return -ENOMEM;
59242+ if (copy_from_user(sptmp, arg->sprole_pws + i,
59243+ sizeof (struct sprole_pw)))
59244+ return -EFAULT;
59245+
59246+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
59247+
59248+ if (!len || len >= GR_SPROLE_LEN)
59249+ return -EINVAL;
59250+
59251+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59252+ return -ENOMEM;
59253+
59254+ if (copy_from_user(tmp, sptmp->rolename, len))
59255+ return -EFAULT;
59256+
59257+ tmp[len-1] = '\0';
59258+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59259+ printk(KERN_ALERT "Copying special role %s\n", tmp);
59260+#endif
59261+ sptmp->rolename = tmp;
59262+ acl_special_roles[i] = sptmp;
59263+ }
59264+
59265+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
59266+
59267+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
59268+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
59269+
59270+ if (!r_tmp)
59271+ return -ENOMEM;
59272+
59273+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
59274+ sizeof (struct acl_role_label *)))
59275+ return -EFAULT;
59276+
59277+ if (copy_from_user(r_tmp, r_utmp2,
59278+ sizeof (struct acl_role_label)))
59279+ return -EFAULT;
59280+
59281+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
59282+
59283+ if (!len || len >= PATH_MAX)
59284+ return -EINVAL;
59285+
59286+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59287+ return -ENOMEM;
59288+
59289+ if (copy_from_user(tmp, r_tmp->rolename, len))
59290+ return -EFAULT;
59291+
59292+ tmp[len-1] = '\0';
59293+ r_tmp->rolename = tmp;
59294+
59295+ if (!strcmp(r_tmp->rolename, "default")
59296+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
59297+ default_role = r_tmp;
59298+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
59299+ kernel_role = r_tmp;
59300+ }
59301+
59302+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
59303+ return -ENOMEM;
59304+
59305+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
59306+ return -EFAULT;
59307+
59308+ r_tmp->hash = ghash;
59309+
59310+ num_subjs = count_user_subjs(r_tmp->hash->first);
59311+
59312+ r_tmp->subj_hash_size = num_subjs;
59313+ r_tmp->subj_hash =
59314+ (struct acl_subject_label **)
59315+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
59316+
59317+ if (!r_tmp->subj_hash)
59318+ return -ENOMEM;
59319+
59320+ err = copy_user_allowedips(r_tmp);
59321+ if (err)
59322+ return err;
59323+
59324+ /* copy domain info */
59325+ if (r_tmp->domain_children != NULL) {
59326+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
59327+ if (domainlist == NULL)
59328+ return -ENOMEM;
59329+
59330+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
59331+ return -EFAULT;
59332+
59333+ r_tmp->domain_children = domainlist;
59334+ }
59335+
59336+ err = copy_user_transitions(r_tmp);
59337+ if (err)
59338+ return err;
59339+
59340+ memset(r_tmp->subj_hash, 0,
59341+ r_tmp->subj_hash_size *
59342+ sizeof (struct acl_subject_label *));
59343+
59344+ /* acquire the list of subjects, then NULL out
59345+ the list prior to parsing the subjects for this role,
59346+ as during this parsing the list is replaced with a list
59347+ of *nested* subjects for the role
59348+ */
59349+ subj_list = r_tmp->hash->first;
59350+
59351+ /* set nested subject list to null */
59352+ r_tmp->hash->first = NULL;
59353+
59354+ err = copy_user_subjs(subj_list, r_tmp);
59355+
59356+ if (err)
59357+ return err;
59358+
59359+ insert_acl_role_label(r_tmp);
59360+ }
59361+
59362+ if (default_role == NULL || kernel_role == NULL)
59363+ return -EINVAL;
59364+
59365+ return err;
59366+}
59367+
59368+static int
59369+gracl_init(struct gr_arg *args)
59370+{
59371+ int error = 0;
59372+
59373+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
59374+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
59375+
59376+ if (init_variables(args)) {
59377+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
59378+ error = -ENOMEM;
59379+ free_variables();
59380+ goto out;
59381+ }
59382+
59383+ error = copy_user_acl(args);
59384+ free_init_variables();
59385+ if (error) {
59386+ free_variables();
59387+ goto out;
59388+ }
59389+
59390+ if ((error = gr_set_acls(0))) {
59391+ free_variables();
59392+ goto out;
59393+ }
59394+
59395+ pax_open_kernel();
59396+ gr_status |= GR_READY;
59397+ pax_close_kernel();
59398+
59399+ out:
59400+ return error;
59401+}
59402+
59403+/* derived from glibc fnmatch() 0: match, 1: no match*/
59404+
59405+static int
59406+glob_match(const char *p, const char *n)
59407+{
59408+ char c;
59409+
59410+ while ((c = *p++) != '\0') {
59411+ switch (c) {
59412+ case '?':
59413+ if (*n == '\0')
59414+ return 1;
59415+ else if (*n == '/')
59416+ return 1;
59417+ break;
59418+ case '\\':
59419+ if (*n != c)
59420+ return 1;
59421+ break;
59422+ case '*':
59423+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
59424+ if (*n == '/')
59425+ return 1;
59426+ else if (c == '?') {
59427+ if (*n == '\0')
59428+ return 1;
59429+ else
59430+ ++n;
59431+ }
59432+ }
59433+ if (c == '\0') {
59434+ return 0;
59435+ } else {
59436+ const char *endp;
59437+
59438+ if ((endp = strchr(n, '/')) == NULL)
59439+ endp = n + strlen(n);
59440+
59441+ if (c == '[') {
59442+ for (--p; n < endp; ++n)
59443+ if (!glob_match(p, n))
59444+ return 0;
59445+ } else if (c == '/') {
59446+ while (*n != '\0' && *n != '/')
59447+ ++n;
59448+ if (*n == '/' && !glob_match(p, n + 1))
59449+ return 0;
59450+ } else {
59451+ for (--p; n < endp; ++n)
59452+ if (*n == c && !glob_match(p, n))
59453+ return 0;
59454+ }
59455+
59456+ return 1;
59457+ }
59458+ case '[':
59459+ {
59460+ int not;
59461+ char cold;
59462+
59463+ if (*n == '\0' || *n == '/')
59464+ return 1;
59465+
59466+ not = (*p == '!' || *p == '^');
59467+ if (not)
59468+ ++p;
59469+
59470+ c = *p++;
59471+ for (;;) {
59472+ unsigned char fn = (unsigned char)*n;
59473+
59474+ if (c == '\0')
59475+ return 1;
59476+ else {
59477+ if (c == fn)
59478+ goto matched;
59479+ cold = c;
59480+ c = *p++;
59481+
59482+ if (c == '-' && *p != ']') {
59483+ unsigned char cend = *p++;
59484+
59485+ if (cend == '\0')
59486+ return 1;
59487+
59488+ if (cold <= fn && fn <= cend)
59489+ goto matched;
59490+
59491+ c = *p++;
59492+ }
59493+ }
59494+
59495+ if (c == ']')
59496+ break;
59497+ }
59498+ if (!not)
59499+ return 1;
59500+ break;
59501+ matched:
59502+ while (c != ']') {
59503+ if (c == '\0')
59504+ return 1;
59505+
59506+ c = *p++;
59507+ }
59508+ if (not)
59509+ return 1;
59510+ }
59511+ break;
59512+ default:
59513+ if (c != *n)
59514+ return 1;
59515+ }
59516+
59517+ ++n;
59518+ }
59519+
59520+ if (*n == '\0')
59521+ return 0;
59522+
59523+ if (*n == '/')
59524+ return 0;
59525+
59526+ return 1;
59527+}
59528+
59529+static struct acl_object_label *
59530+chk_glob_label(struct acl_object_label *globbed,
59531+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
59532+{
59533+ struct acl_object_label *tmp;
59534+
59535+ if (*path == NULL)
59536+ *path = gr_to_filename_nolock(dentry, mnt);
59537+
59538+ tmp = globbed;
59539+
59540+ while (tmp) {
59541+ if (!glob_match(tmp->filename, *path))
59542+ return tmp;
59543+ tmp = tmp->next;
59544+ }
59545+
59546+ return NULL;
59547+}
59548+
59549+static struct acl_object_label *
59550+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
59551+ const ino_t curr_ino, const dev_t curr_dev,
59552+ const struct acl_subject_label *subj, char **path, const int checkglob)
59553+{
59554+ struct acl_subject_label *tmpsubj;
59555+ struct acl_object_label *retval;
59556+ struct acl_object_label *retval2;
59557+
59558+ tmpsubj = (struct acl_subject_label *) subj;
59559+ read_lock(&gr_inode_lock);
59560+ do {
59561+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
59562+ if (retval) {
59563+ if (checkglob && retval->globbed) {
59564+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
59565+ if (retval2)
59566+ retval = retval2;
59567+ }
59568+ break;
59569+ }
59570+ } while ((tmpsubj = tmpsubj->parent_subject));
59571+ read_unlock(&gr_inode_lock);
59572+
59573+ return retval;
59574+}
59575+
59576+static __inline__ struct acl_object_label *
59577+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
59578+ struct dentry *curr_dentry,
59579+ const struct acl_subject_label *subj, char **path, const int checkglob)
59580+{
59581+ int newglob = checkglob;
59582+ ino_t inode;
59583+ dev_t device;
59584+
59585+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
59586+ as we don't want a / * rule to match instead of the / object
59587+ don't do this for create lookups that call this function though, since they're looking up
59588+ on the parent and thus need globbing checks on all paths
59589+ */
59590+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
59591+ newglob = GR_NO_GLOB;
59592+
59593+ spin_lock(&curr_dentry->d_lock);
59594+ inode = curr_dentry->d_inode->i_ino;
59595+ device = __get_dev(curr_dentry);
59596+ spin_unlock(&curr_dentry->d_lock);
59597+
59598+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
59599+}
59600+
59601+#ifdef CONFIG_HUGETLBFS
59602+static inline bool
59603+is_hugetlbfs_mnt(const struct vfsmount *mnt)
59604+{
59605+ int i;
59606+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
59607+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
59608+ return true;
59609+ }
59610+
59611+ return false;
59612+}
59613+#endif
59614+
59615+static struct acl_object_label *
59616+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59617+ const struct acl_subject_label *subj, char *path, const int checkglob)
59618+{
59619+ struct dentry *dentry = (struct dentry *) l_dentry;
59620+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
59621+ struct mount *real_mnt = real_mount(mnt);
59622+ struct acl_object_label *retval;
59623+ struct dentry *parent;
59624+
59625+ br_read_lock(&vfsmount_lock);
59626+ write_seqlock(&rename_lock);
59627+
59628+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
59629+#ifdef CONFIG_NET
59630+ mnt == sock_mnt ||
59631+#endif
59632+#ifdef CONFIG_HUGETLBFS
59633+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
59634+#endif
59635+ /* ignore Eric Biederman */
59636+ IS_PRIVATE(l_dentry->d_inode))) {
59637+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
59638+ goto out;
59639+ }
59640+
59641+ for (;;) {
59642+ if (dentry == real_root.dentry && mnt == real_root.mnt)
59643+ break;
59644+
59645+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
59646+ if (!mnt_has_parent(real_mnt))
59647+ break;
59648+
59649+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
59650+ if (retval != NULL)
59651+ goto out;
59652+
59653+ dentry = real_mnt->mnt_mountpoint;
59654+ real_mnt = real_mnt->mnt_parent;
59655+ mnt = &real_mnt->mnt;
59656+ continue;
59657+ }
59658+
59659+ parent = dentry->d_parent;
59660+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
59661+ if (retval != NULL)
59662+ goto out;
59663+
59664+ dentry = parent;
59665+ }
59666+
59667+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
59668+
59669+ /* real_root is pinned so we don't have to hold a reference */
59670+ if (retval == NULL)
59671+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
59672+out:
59673+ write_sequnlock(&rename_lock);
59674+ br_read_unlock(&vfsmount_lock);
59675+
59676+ BUG_ON(retval == NULL);
59677+
59678+ return retval;
59679+}
59680+
59681+static __inline__ struct acl_object_label *
59682+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59683+ const struct acl_subject_label *subj)
59684+{
59685+ char *path = NULL;
59686+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
59687+}
59688+
59689+static __inline__ struct acl_object_label *
59690+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59691+ const struct acl_subject_label *subj)
59692+{
59693+ char *path = NULL;
59694+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
59695+}
59696+
59697+static __inline__ struct acl_object_label *
59698+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59699+ const struct acl_subject_label *subj, char *path)
59700+{
59701+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
59702+}
59703+
59704+static struct acl_subject_label *
59705+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
59706+ const struct acl_role_label *role)
59707+{
59708+ struct dentry *dentry = (struct dentry *) l_dentry;
59709+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
59710+ struct mount *real_mnt = real_mount(mnt);
59711+ struct acl_subject_label *retval;
59712+ struct dentry *parent;
59713+
59714+ br_read_lock(&vfsmount_lock);
59715+ write_seqlock(&rename_lock);
59716+
59717+ for (;;) {
59718+ if (dentry == real_root.dentry && mnt == real_root.mnt)
59719+ break;
59720+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
59721+ if (!mnt_has_parent(real_mnt))
59722+ break;
59723+
59724+ spin_lock(&dentry->d_lock);
59725+ read_lock(&gr_inode_lock);
59726+ retval =
59727+ lookup_acl_subj_label(dentry->d_inode->i_ino,
59728+ __get_dev(dentry), role);
59729+ read_unlock(&gr_inode_lock);
59730+ spin_unlock(&dentry->d_lock);
59731+ if (retval != NULL)
59732+ goto out;
59733+
59734+ dentry = real_mnt->mnt_mountpoint;
59735+ real_mnt = real_mnt->mnt_parent;
59736+ mnt = &real_mnt->mnt;
59737+ continue;
59738+ }
59739+
59740+ spin_lock(&dentry->d_lock);
59741+ read_lock(&gr_inode_lock);
59742+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
59743+ __get_dev(dentry), role);
59744+ read_unlock(&gr_inode_lock);
59745+ parent = dentry->d_parent;
59746+ spin_unlock(&dentry->d_lock);
59747+
59748+ if (retval != NULL)
59749+ goto out;
59750+
59751+ dentry = parent;
59752+ }
59753+
59754+ spin_lock(&dentry->d_lock);
59755+ read_lock(&gr_inode_lock);
59756+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
59757+ __get_dev(dentry), role);
59758+ read_unlock(&gr_inode_lock);
59759+ spin_unlock(&dentry->d_lock);
59760+
59761+ if (unlikely(retval == NULL)) {
59762+ /* real_root is pinned, we don't need to hold a reference */
59763+ read_lock(&gr_inode_lock);
59764+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
59765+ __get_dev(real_root.dentry), role);
59766+ read_unlock(&gr_inode_lock);
59767+ }
59768+out:
59769+ write_sequnlock(&rename_lock);
59770+ br_read_unlock(&vfsmount_lock);
59771+
59772+ BUG_ON(retval == NULL);
59773+
59774+ return retval;
59775+}
59776+
59777+static void
59778+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
59779+{
59780+ struct task_struct *task = current;
59781+ const struct cred *cred = current_cred();
59782+
59783+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
59784+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
59785+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
59786+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
59787+
59788+ return;
59789+}
59790+
59791+static void
59792+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
59793+{
59794+ struct task_struct *task = current;
59795+ const struct cred *cred = current_cred();
59796+
59797+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
59798+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
59799+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
59800+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
59801+
59802+ return;
59803+}
59804+
59805+static void
59806+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
59807+{
59808+ struct task_struct *task = current;
59809+ const struct cred *cred = current_cred();
59810+
59811+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
59812+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
59813+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
59814+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
59815+
59816+ return;
59817+}
59818+
59819+__u32
59820+gr_search_file(const struct dentry * dentry, const __u32 mode,
59821+ const struct vfsmount * mnt)
59822+{
59823+ __u32 retval = mode;
59824+ struct acl_subject_label *curracl;
59825+ struct acl_object_label *currobj;
59826+
59827+ if (unlikely(!(gr_status & GR_READY)))
59828+ return (mode & ~GR_AUDITS);
59829+
59830+ curracl = current->acl;
59831+
59832+ currobj = chk_obj_label(dentry, mnt, curracl);
59833+ retval = currobj->mode & mode;
59834+
59835+ /* if we're opening a specified transfer file for writing
59836+ (e.g. /dev/initctl), then transfer our role to init
59837+ */
59838+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
59839+ current->role->roletype & GR_ROLE_PERSIST)) {
59840+ struct task_struct *task = init_pid_ns.child_reaper;
59841+
59842+ if (task->role != current->role) {
59843+ task->acl_sp_role = 0;
59844+ task->acl_role_id = current->acl_role_id;
59845+ task->role = current->role;
59846+ rcu_read_lock();
59847+ read_lock(&grsec_exec_file_lock);
59848+ gr_apply_subject_to_task(task);
59849+ read_unlock(&grsec_exec_file_lock);
59850+ rcu_read_unlock();
59851+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
59852+ }
59853+ }
59854+
59855+ if (unlikely
59856+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
59857+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
59858+ __u32 new_mode = mode;
59859+
59860+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
59861+
59862+ retval = new_mode;
59863+
59864+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
59865+ new_mode |= GR_INHERIT;
59866+
59867+ if (!(mode & GR_NOLEARN))
59868+ gr_log_learn(dentry, mnt, new_mode);
59869+ }
59870+
59871+ return retval;
59872+}
59873+
59874+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
59875+ const struct dentry *parent,
59876+ const struct vfsmount *mnt)
59877+{
59878+ struct name_entry *match;
59879+ struct acl_object_label *matchpo;
59880+ struct acl_subject_label *curracl;
59881+ char *path;
59882+
59883+ if (unlikely(!(gr_status & GR_READY)))
59884+ return NULL;
59885+
59886+ preempt_disable();
59887+ path = gr_to_filename_rbac(new_dentry, mnt);
59888+ match = lookup_name_entry_create(path);
59889+
59890+ curracl = current->acl;
59891+
59892+ if (match) {
59893+ read_lock(&gr_inode_lock);
59894+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
59895+ read_unlock(&gr_inode_lock);
59896+
59897+ if (matchpo) {
59898+ preempt_enable();
59899+ return matchpo;
59900+ }
59901+ }
59902+
59903+ // lookup parent
59904+
59905+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
59906+
59907+ preempt_enable();
59908+ return matchpo;
59909+}
59910+
59911+__u32
59912+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
59913+ const struct vfsmount * mnt, const __u32 mode)
59914+{
59915+ struct acl_object_label *matchpo;
59916+ __u32 retval;
59917+
59918+ if (unlikely(!(gr_status & GR_READY)))
59919+ return (mode & ~GR_AUDITS);
59920+
59921+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
59922+
59923+ retval = matchpo->mode & mode;
59924+
59925+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
59926+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
59927+ __u32 new_mode = mode;
59928+
59929+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
59930+
59931+ gr_log_learn(new_dentry, mnt, new_mode);
59932+ return new_mode;
59933+ }
59934+
59935+ return retval;
59936+}
59937+
59938+__u32
59939+gr_check_link(const struct dentry * new_dentry,
59940+ const struct dentry * parent_dentry,
59941+ const struct vfsmount * parent_mnt,
59942+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
59943+{
59944+ struct acl_object_label *obj;
59945+ __u32 oldmode, newmode;
59946+ __u32 needmode;
59947+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
59948+ GR_DELETE | GR_INHERIT;
59949+
59950+ if (unlikely(!(gr_status & GR_READY)))
59951+ return (GR_CREATE | GR_LINK);
59952+
59953+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
59954+ oldmode = obj->mode;
59955+
59956+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
59957+ newmode = obj->mode;
59958+
59959+ needmode = newmode & checkmodes;
59960+
59961+ // old name for hardlink must have at least the permissions of the new name
59962+ if ((oldmode & needmode) != needmode)
59963+ goto bad;
59964+
59965+ // if old name had restrictions/auditing, make sure the new name does as well
59966+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
59967+
59968+ // don't allow hardlinking of suid/sgid/fcapped files without permission
59969+ if (is_privileged_binary(old_dentry))
59970+ needmode |= GR_SETID;
59971+
59972+ if ((newmode & needmode) != needmode)
59973+ goto bad;
59974+
59975+ // enforce minimum permissions
59976+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
59977+ return newmode;
59978+bad:
59979+ needmode = oldmode;
59980+ if (is_privileged_binary(old_dentry))
59981+ needmode |= GR_SETID;
59982+
59983+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
59984+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
59985+ return (GR_CREATE | GR_LINK);
59986+ } else if (newmode & GR_SUPPRESS)
59987+ return GR_SUPPRESS;
59988+ else
59989+ return 0;
59990+}
59991+
59992+int
59993+gr_check_hidden_task(const struct task_struct *task)
59994+{
59995+ if (unlikely(!(gr_status & GR_READY)))
59996+ return 0;
59997+
59998+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
59999+ return 1;
60000+
60001+ return 0;
60002+}
60003+
60004+int
60005+gr_check_protected_task(const struct task_struct *task)
60006+{
60007+ if (unlikely(!(gr_status & GR_READY) || !task))
60008+ return 0;
60009+
60010+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
60011+ task->acl != current->acl)
60012+ return 1;
60013+
60014+ return 0;
60015+}
60016+
60017+int
60018+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
60019+{
60020+ struct task_struct *p;
60021+ int ret = 0;
60022+
60023+ if (unlikely(!(gr_status & GR_READY) || !pid))
60024+ return ret;
60025+
60026+ read_lock(&tasklist_lock);
60027+ do_each_pid_task(pid, type, p) {
60028+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
60029+ p->acl != current->acl) {
60030+ ret = 1;
60031+ goto out;
60032+ }
60033+ } while_each_pid_task(pid, type, p);
60034+out:
60035+ read_unlock(&tasklist_lock);
60036+
60037+ return ret;
60038+}
60039+
60040+void
60041+gr_copy_label(struct task_struct *tsk)
60042+{
60043+ tsk->signal->used_accept = 0;
60044+ tsk->acl_sp_role = 0;
60045+ tsk->acl_role_id = current->acl_role_id;
60046+ tsk->acl = current->acl;
60047+ tsk->role = current->role;
60048+ tsk->signal->curr_ip = current->signal->curr_ip;
60049+ tsk->signal->saved_ip = current->signal->saved_ip;
60050+ if (current->exec_file)
60051+ get_file(current->exec_file);
60052+ tsk->exec_file = current->exec_file;
60053+ tsk->is_writable = current->is_writable;
60054+ if (unlikely(current->signal->used_accept)) {
60055+ current->signal->curr_ip = 0;
60056+ current->signal->saved_ip = 0;
60057+ }
60058+
60059+ return;
60060+}
60061+
60062+static void
60063+gr_set_proc_res(struct task_struct *task)
60064+{
60065+ struct acl_subject_label *proc;
60066+ unsigned short i;
60067+
60068+ proc = task->acl;
60069+
60070+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
60071+ return;
60072+
60073+ for (i = 0; i < RLIM_NLIMITS; i++) {
60074+ if (!(proc->resmask & (1U << i)))
60075+ continue;
60076+
60077+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
60078+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
60079+
60080+ if (i == RLIMIT_CPU)
60081+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
60082+ }
60083+
60084+ return;
60085+}
60086+
60087+extern int __gr_process_user_ban(struct user_struct *user);
60088+
60089+int
60090+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
60091+{
60092+ unsigned int i;
60093+ __u16 num;
60094+ uid_t *uidlist;
60095+ uid_t curuid;
60096+ int realok = 0;
60097+ int effectiveok = 0;
60098+ int fsok = 0;
60099+ uid_t globalreal, globaleffective, globalfs;
60100+
60101+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
60102+ struct user_struct *user;
60103+
60104+ if (!uid_valid(real))
60105+ goto skipit;
60106+
60107+ /* find user based on global namespace */
60108+
60109+ globalreal = GR_GLOBAL_UID(real);
60110+
60111+ user = find_user(make_kuid(&init_user_ns, globalreal));
60112+ if (user == NULL)
60113+ goto skipit;
60114+
60115+ if (__gr_process_user_ban(user)) {
60116+ /* for find_user */
60117+ free_uid(user);
60118+ return 1;
60119+ }
60120+
60121+ /* for find_user */
60122+ free_uid(user);
60123+
60124+skipit:
60125+#endif
60126+
60127+ if (unlikely(!(gr_status & GR_READY)))
60128+ return 0;
60129+
60130+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60131+ gr_log_learn_uid_change(real, effective, fs);
60132+
60133+ num = current->acl->user_trans_num;
60134+ uidlist = current->acl->user_transitions;
60135+
60136+ if (uidlist == NULL)
60137+ return 0;
60138+
60139+ if (!uid_valid(real)) {
60140+ realok = 1;
60141+ globalreal = (uid_t)-1;
60142+ } else {
60143+ globalreal = GR_GLOBAL_UID(real);
60144+ }
60145+ if (!uid_valid(effective)) {
60146+ effectiveok = 1;
60147+ globaleffective = (uid_t)-1;
60148+ } else {
60149+ globaleffective = GR_GLOBAL_UID(effective);
60150+ }
60151+ if (!uid_valid(fs)) {
60152+ fsok = 1;
60153+ globalfs = (uid_t)-1;
60154+ } else {
60155+ globalfs = GR_GLOBAL_UID(fs);
60156+ }
60157+
60158+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
60159+ for (i = 0; i < num; i++) {
60160+ curuid = uidlist[i];
60161+ if (globalreal == curuid)
60162+ realok = 1;
60163+ if (globaleffective == curuid)
60164+ effectiveok = 1;
60165+ if (globalfs == curuid)
60166+ fsok = 1;
60167+ }
60168+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
60169+ for (i = 0; i < num; i++) {
60170+ curuid = uidlist[i];
60171+ if (globalreal == curuid)
60172+ break;
60173+ if (globaleffective == curuid)
60174+ break;
60175+ if (globalfs == curuid)
60176+ break;
60177+ }
60178+ /* not in deny list */
60179+ if (i == num) {
60180+ realok = 1;
60181+ effectiveok = 1;
60182+ fsok = 1;
60183+ }
60184+ }
60185+
60186+ if (realok && effectiveok && fsok)
60187+ return 0;
60188+ else {
60189+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
60190+ return 1;
60191+ }
60192+}
60193+
60194+int
60195+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
60196+{
60197+ unsigned int i;
60198+ __u16 num;
60199+ gid_t *gidlist;
60200+ gid_t curgid;
60201+ int realok = 0;
60202+ int effectiveok = 0;
60203+ int fsok = 0;
60204+ gid_t globalreal, globaleffective, globalfs;
60205+
60206+ if (unlikely(!(gr_status & GR_READY)))
60207+ return 0;
60208+
60209+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60210+ gr_log_learn_gid_change(real, effective, fs);
60211+
60212+ num = current->acl->group_trans_num;
60213+ gidlist = current->acl->group_transitions;
60214+
60215+ if (gidlist == NULL)
60216+ return 0;
60217+
60218+ if (!gid_valid(real)) {
60219+ realok = 1;
60220+ globalreal = (gid_t)-1;
60221+ } else {
60222+ globalreal = GR_GLOBAL_GID(real);
60223+ }
60224+ if (!gid_valid(effective)) {
60225+ effectiveok = 1;
60226+ globaleffective = (gid_t)-1;
60227+ } else {
60228+ globaleffective = GR_GLOBAL_GID(effective);
60229+ }
60230+ if (!gid_valid(fs)) {
60231+ fsok = 1;
60232+ globalfs = (gid_t)-1;
60233+ } else {
60234+ globalfs = GR_GLOBAL_GID(fs);
60235+ }
60236+
60237+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
60238+ for (i = 0; i < num; i++) {
60239+ curgid = gidlist[i];
60240+ if (globalreal == curgid)
60241+ realok = 1;
60242+ if (globaleffective == curgid)
60243+ effectiveok = 1;
60244+ if (globalfs == curgid)
60245+ fsok = 1;
60246+ }
60247+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
60248+ for (i = 0; i < num; i++) {
60249+ curgid = gidlist[i];
60250+ if (globalreal == curgid)
60251+ break;
60252+ if (globaleffective == curgid)
60253+ break;
60254+ if (globalfs == curgid)
60255+ break;
60256+ }
60257+ /* not in deny list */
60258+ if (i == num) {
60259+ realok = 1;
60260+ effectiveok = 1;
60261+ fsok = 1;
60262+ }
60263+ }
60264+
60265+ if (realok && effectiveok && fsok)
60266+ return 0;
60267+ else {
60268+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
60269+ return 1;
60270+ }
60271+}
60272+
60273+extern int gr_acl_is_capable(const int cap);
60274+
60275+void
60276+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
60277+{
60278+ struct acl_role_label *role = task->role;
60279+ struct acl_subject_label *subj = NULL;
60280+ struct acl_object_label *obj;
60281+ struct file *filp;
60282+ uid_t uid;
60283+ gid_t gid;
60284+
60285+ if (unlikely(!(gr_status & GR_READY)))
60286+ return;
60287+
60288+ uid = GR_GLOBAL_UID(kuid);
60289+ gid = GR_GLOBAL_GID(kgid);
60290+
60291+ filp = task->exec_file;
60292+
60293+ /* kernel process, we'll give them the kernel role */
60294+ if (unlikely(!filp)) {
60295+ task->role = kernel_role;
60296+ task->acl = kernel_role->root_label;
60297+ return;
60298+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
60299+ role = lookup_acl_role_label(task, uid, gid);
60300+
60301+ /* don't change the role if we're not a privileged process */
60302+ if (role && task->role != role &&
60303+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
60304+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
60305+ return;
60306+
60307+ /* perform subject lookup in possibly new role
60308+ we can use this result below in the case where role == task->role
60309+ */
60310+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
60311+
60312+ /* if we changed uid/gid, but result in the same role
60313+ and are using inheritance, don't lose the inherited subject
60314+ if current subject is other than what normal lookup
60315+ would result in, we arrived via inheritance, don't
60316+ lose subject
60317+ */
60318+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
60319+ (subj == task->acl)))
60320+ task->acl = subj;
60321+
60322+ task->role = role;
60323+
60324+ task->is_writable = 0;
60325+
60326+ /* ignore additional mmap checks for processes that are writable
60327+ by the default ACL */
60328+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60329+ if (unlikely(obj->mode & GR_WRITE))
60330+ task->is_writable = 1;
60331+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
60332+ if (unlikely(obj->mode & GR_WRITE))
60333+ task->is_writable = 1;
60334+
60335+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60336+ 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);
60337+#endif
60338+
60339+ gr_set_proc_res(task);
60340+
60341+ return;
60342+}
60343+
60344+int
60345+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
60346+ const int unsafe_flags)
60347+{
60348+ struct task_struct *task = current;
60349+ struct acl_subject_label *newacl;
60350+ struct acl_object_label *obj;
60351+ __u32 retmode;
60352+
60353+ if (unlikely(!(gr_status & GR_READY)))
60354+ return 0;
60355+
60356+ newacl = chk_subj_label(dentry, mnt, task->role);
60357+
60358+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
60359+ did an exec
60360+ */
60361+ rcu_read_lock();
60362+ read_lock(&tasklist_lock);
60363+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
60364+ (task->parent->acl->mode & GR_POVERRIDE))) {
60365+ read_unlock(&tasklist_lock);
60366+ rcu_read_unlock();
60367+ goto skip_check;
60368+ }
60369+ read_unlock(&tasklist_lock);
60370+ rcu_read_unlock();
60371+
60372+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
60373+ !(task->role->roletype & GR_ROLE_GOD) &&
60374+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
60375+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
60376+ if (unsafe_flags & LSM_UNSAFE_SHARE)
60377+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
60378+ else
60379+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
60380+ return -EACCES;
60381+ }
60382+
60383+skip_check:
60384+
60385+ obj = chk_obj_label(dentry, mnt, task->acl);
60386+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
60387+
60388+ if (!(task->acl->mode & GR_INHERITLEARN) &&
60389+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
60390+ if (obj->nested)
60391+ task->acl = obj->nested;
60392+ else
60393+ task->acl = newacl;
60394+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
60395+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
60396+
60397+ task->is_writable = 0;
60398+
60399+ /* ignore additional mmap checks for processes that are writable
60400+ by the default ACL */
60401+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
60402+ if (unlikely(obj->mode & GR_WRITE))
60403+ task->is_writable = 1;
60404+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
60405+ if (unlikely(obj->mode & GR_WRITE))
60406+ task->is_writable = 1;
60407+
60408+ gr_set_proc_res(task);
60409+
60410+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60411+ 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);
60412+#endif
60413+ return 0;
60414+}
60415+
60416+/* always called with valid inodev ptr */
60417+static void
60418+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
60419+{
60420+ struct acl_object_label *matchpo;
60421+ struct acl_subject_label *matchps;
60422+ struct acl_subject_label *subj;
60423+ struct acl_role_label *role;
60424+ unsigned int x;
60425+
60426+ FOR_EACH_ROLE_START(role)
60427+ FOR_EACH_SUBJECT_START(role, subj, x)
60428+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
60429+ matchpo->mode |= GR_DELETED;
60430+ FOR_EACH_SUBJECT_END(subj,x)
60431+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
60432+ /* nested subjects aren't in the role's subj_hash table */
60433+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
60434+ matchpo->mode |= GR_DELETED;
60435+ FOR_EACH_NESTED_SUBJECT_END(subj)
60436+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
60437+ matchps->mode |= GR_DELETED;
60438+ FOR_EACH_ROLE_END(role)
60439+
60440+ inodev->nentry->deleted = 1;
60441+
60442+ return;
60443+}
60444+
60445+void
60446+gr_handle_delete(const ino_t ino, const dev_t dev)
60447+{
60448+ struct inodev_entry *inodev;
60449+
60450+ if (unlikely(!(gr_status & GR_READY)))
60451+ return;
60452+
60453+ write_lock(&gr_inode_lock);
60454+ inodev = lookup_inodev_entry(ino, dev);
60455+ if (inodev != NULL)
60456+ do_handle_delete(inodev, ino, dev);
60457+ write_unlock(&gr_inode_lock);
60458+
60459+ return;
60460+}
60461+
60462+static void
60463+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
60464+ const ino_t newinode, const dev_t newdevice,
60465+ struct acl_subject_label *subj)
60466+{
60467+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
60468+ struct acl_object_label *match;
60469+
60470+ match = subj->obj_hash[index];
60471+
60472+ while (match && (match->inode != oldinode ||
60473+ match->device != olddevice ||
60474+ !(match->mode & GR_DELETED)))
60475+ match = match->next;
60476+
60477+ if (match && (match->inode == oldinode)
60478+ && (match->device == olddevice)
60479+ && (match->mode & GR_DELETED)) {
60480+ if (match->prev == NULL) {
60481+ subj->obj_hash[index] = match->next;
60482+ if (match->next != NULL)
60483+ match->next->prev = NULL;
60484+ } else {
60485+ match->prev->next = match->next;
60486+ if (match->next != NULL)
60487+ match->next->prev = match->prev;
60488+ }
60489+ match->prev = NULL;
60490+ match->next = NULL;
60491+ match->inode = newinode;
60492+ match->device = newdevice;
60493+ match->mode &= ~GR_DELETED;
60494+
60495+ insert_acl_obj_label(match, subj);
60496+ }
60497+
60498+ return;
60499+}
60500+
60501+static void
60502+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
60503+ const ino_t newinode, const dev_t newdevice,
60504+ struct acl_role_label *role)
60505+{
60506+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
60507+ struct acl_subject_label *match;
60508+
60509+ match = role->subj_hash[index];
60510+
60511+ while (match && (match->inode != oldinode ||
60512+ match->device != olddevice ||
60513+ !(match->mode & GR_DELETED)))
60514+ match = match->next;
60515+
60516+ if (match && (match->inode == oldinode)
60517+ && (match->device == olddevice)
60518+ && (match->mode & GR_DELETED)) {
60519+ if (match->prev == NULL) {
60520+ role->subj_hash[index] = match->next;
60521+ if (match->next != NULL)
60522+ match->next->prev = NULL;
60523+ } else {
60524+ match->prev->next = match->next;
60525+ if (match->next != NULL)
60526+ match->next->prev = match->prev;
60527+ }
60528+ match->prev = NULL;
60529+ match->next = NULL;
60530+ match->inode = newinode;
60531+ match->device = newdevice;
60532+ match->mode &= ~GR_DELETED;
60533+
60534+ insert_acl_subj_label(match, role);
60535+ }
60536+
60537+ return;
60538+}
60539+
60540+static void
60541+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
60542+ const ino_t newinode, const dev_t newdevice)
60543+{
60544+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
60545+ struct inodev_entry *match;
60546+
60547+ match = inodev_set.i_hash[index];
60548+
60549+ while (match && (match->nentry->inode != oldinode ||
60550+ match->nentry->device != olddevice || !match->nentry->deleted))
60551+ match = match->next;
60552+
60553+ if (match && (match->nentry->inode == oldinode)
60554+ && (match->nentry->device == olddevice) &&
60555+ match->nentry->deleted) {
60556+ if (match->prev == NULL) {
60557+ inodev_set.i_hash[index] = match->next;
60558+ if (match->next != NULL)
60559+ match->next->prev = NULL;
60560+ } else {
60561+ match->prev->next = match->next;
60562+ if (match->next != NULL)
60563+ match->next->prev = match->prev;
60564+ }
60565+ match->prev = NULL;
60566+ match->next = NULL;
60567+ match->nentry->inode = newinode;
60568+ match->nentry->device = newdevice;
60569+ match->nentry->deleted = 0;
60570+
60571+ insert_inodev_entry(match);
60572+ }
60573+
60574+ return;
60575+}
60576+
60577+static void
60578+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
60579+{
60580+ struct acl_subject_label *subj;
60581+ struct acl_role_label *role;
60582+ unsigned int x;
60583+
60584+ FOR_EACH_ROLE_START(role)
60585+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
60586+
60587+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
60588+ if ((subj->inode == ino) && (subj->device == dev)) {
60589+ subj->inode = ino;
60590+ subj->device = dev;
60591+ }
60592+ /* nested subjects aren't in the role's subj_hash table */
60593+ update_acl_obj_label(matchn->inode, matchn->device,
60594+ ino, dev, subj);
60595+ FOR_EACH_NESTED_SUBJECT_END(subj)
60596+ FOR_EACH_SUBJECT_START(role, subj, x)
60597+ update_acl_obj_label(matchn->inode, matchn->device,
60598+ ino, dev, subj);
60599+ FOR_EACH_SUBJECT_END(subj,x)
60600+ FOR_EACH_ROLE_END(role)
60601+
60602+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
60603+
60604+ return;
60605+}
60606+
60607+static void
60608+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
60609+ const struct vfsmount *mnt)
60610+{
60611+ ino_t ino = dentry->d_inode->i_ino;
60612+ dev_t dev = __get_dev(dentry);
60613+
60614+ __do_handle_create(matchn, ino, dev);
60615+
60616+ return;
60617+}
60618+
60619+void
60620+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
60621+{
60622+ struct name_entry *matchn;
60623+
60624+ if (unlikely(!(gr_status & GR_READY)))
60625+ return;
60626+
60627+ preempt_disable();
60628+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
60629+
60630+ if (unlikely((unsigned long)matchn)) {
60631+ write_lock(&gr_inode_lock);
60632+ do_handle_create(matchn, dentry, mnt);
60633+ write_unlock(&gr_inode_lock);
60634+ }
60635+ preempt_enable();
60636+
60637+ return;
60638+}
60639+
60640+void
60641+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
60642+{
60643+ struct name_entry *matchn;
60644+
60645+ if (unlikely(!(gr_status & GR_READY)))
60646+ return;
60647+
60648+ preempt_disable();
60649+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
60650+
60651+ if (unlikely((unsigned long)matchn)) {
60652+ write_lock(&gr_inode_lock);
60653+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
60654+ write_unlock(&gr_inode_lock);
60655+ }
60656+ preempt_enable();
60657+
60658+ return;
60659+}
60660+
60661+void
60662+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
60663+ struct dentry *old_dentry,
60664+ struct dentry *new_dentry,
60665+ struct vfsmount *mnt, const __u8 replace)
60666+{
60667+ struct name_entry *matchn;
60668+ struct inodev_entry *inodev;
60669+ struct inode *inode = new_dentry->d_inode;
60670+ ino_t old_ino = old_dentry->d_inode->i_ino;
60671+ dev_t old_dev = __get_dev(old_dentry);
60672+
60673+ /* vfs_rename swaps the name and parent link for old_dentry and
60674+ new_dentry
60675+ at this point, old_dentry has the new name, parent link, and inode
60676+ for the renamed file
60677+ if a file is being replaced by a rename, new_dentry has the inode
60678+ and name for the replaced file
60679+ */
60680+
60681+ if (unlikely(!(gr_status & GR_READY)))
60682+ return;
60683+
60684+ preempt_disable();
60685+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
60686+
60687+ /* we wouldn't have to check d_inode if it weren't for
60688+ NFS silly-renaming
60689+ */
60690+
60691+ write_lock(&gr_inode_lock);
60692+ if (unlikely(replace && inode)) {
60693+ ino_t new_ino = inode->i_ino;
60694+ dev_t new_dev = __get_dev(new_dentry);
60695+
60696+ inodev = lookup_inodev_entry(new_ino, new_dev);
60697+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
60698+ do_handle_delete(inodev, new_ino, new_dev);
60699+ }
60700+
60701+ inodev = lookup_inodev_entry(old_ino, old_dev);
60702+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
60703+ do_handle_delete(inodev, old_ino, old_dev);
60704+
60705+ if (unlikely((unsigned long)matchn))
60706+ do_handle_create(matchn, old_dentry, mnt);
60707+
60708+ write_unlock(&gr_inode_lock);
60709+ preempt_enable();
60710+
60711+ return;
60712+}
60713+
60714+static int
60715+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
60716+ unsigned char **sum)
60717+{
60718+ struct acl_role_label *r;
60719+ struct role_allowed_ip *ipp;
60720+ struct role_transition *trans;
60721+ unsigned int i;
60722+ int found = 0;
60723+ u32 curr_ip = current->signal->curr_ip;
60724+
60725+ current->signal->saved_ip = curr_ip;
60726+
60727+ /* check transition table */
60728+
60729+ for (trans = current->role->transitions; trans; trans = trans->next) {
60730+ if (!strcmp(rolename, trans->rolename)) {
60731+ found = 1;
60732+ break;
60733+ }
60734+ }
60735+
60736+ if (!found)
60737+ return 0;
60738+
60739+ /* handle special roles that do not require authentication
60740+ and check ip */
60741+
60742+ FOR_EACH_ROLE_START(r)
60743+ if (!strcmp(rolename, r->rolename) &&
60744+ (r->roletype & GR_ROLE_SPECIAL)) {
60745+ found = 0;
60746+ if (r->allowed_ips != NULL) {
60747+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
60748+ if ((ntohl(curr_ip) & ipp->netmask) ==
60749+ (ntohl(ipp->addr) & ipp->netmask))
60750+ found = 1;
60751+ }
60752+ } else
60753+ found = 2;
60754+ if (!found)
60755+ return 0;
60756+
60757+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
60758+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
60759+ *salt = NULL;
60760+ *sum = NULL;
60761+ return 1;
60762+ }
60763+ }
60764+ FOR_EACH_ROLE_END(r)
60765+
60766+ for (i = 0; i < num_sprole_pws; i++) {
60767+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
60768+ *salt = acl_special_roles[i]->salt;
60769+ *sum = acl_special_roles[i]->sum;
60770+ return 1;
60771+ }
60772+ }
60773+
60774+ return 0;
60775+}
60776+
60777+static void
60778+assign_special_role(char *rolename)
60779+{
60780+ struct acl_object_label *obj;
60781+ struct acl_role_label *r;
60782+ struct acl_role_label *assigned = NULL;
60783+ struct task_struct *tsk;
60784+ struct file *filp;
60785+
60786+ FOR_EACH_ROLE_START(r)
60787+ if (!strcmp(rolename, r->rolename) &&
60788+ (r->roletype & GR_ROLE_SPECIAL)) {
60789+ assigned = r;
60790+ break;
60791+ }
60792+ FOR_EACH_ROLE_END(r)
60793+
60794+ if (!assigned)
60795+ return;
60796+
60797+ read_lock(&tasklist_lock);
60798+ read_lock(&grsec_exec_file_lock);
60799+
60800+ tsk = current->real_parent;
60801+ if (tsk == NULL)
60802+ goto out_unlock;
60803+
60804+ filp = tsk->exec_file;
60805+ if (filp == NULL)
60806+ goto out_unlock;
60807+
60808+ tsk->is_writable = 0;
60809+
60810+ tsk->acl_sp_role = 1;
60811+ tsk->acl_role_id = ++acl_sp_role_value;
60812+ tsk->role = assigned;
60813+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
60814+
60815+ /* ignore additional mmap checks for processes that are writable
60816+ by the default ACL */
60817+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60818+ if (unlikely(obj->mode & GR_WRITE))
60819+ tsk->is_writable = 1;
60820+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
60821+ if (unlikely(obj->mode & GR_WRITE))
60822+ tsk->is_writable = 1;
60823+
60824+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60825+ 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));
60826+#endif
60827+
60828+out_unlock:
60829+ read_unlock(&grsec_exec_file_lock);
60830+ read_unlock(&tasklist_lock);
60831+ return;
60832+}
60833+
60834+int gr_check_secure_terminal(struct task_struct *task)
60835+{
60836+ struct task_struct *p, *p2, *p3;
60837+ struct files_struct *files;
60838+ struct fdtable *fdt;
60839+ struct file *our_file = NULL, *file;
60840+ int i;
60841+
60842+ if (task->signal->tty == NULL)
60843+ return 1;
60844+
60845+ files = get_files_struct(task);
60846+ if (files != NULL) {
60847+ rcu_read_lock();
60848+ fdt = files_fdtable(files);
60849+ for (i=0; i < fdt->max_fds; i++) {
60850+ file = fcheck_files(files, i);
60851+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
60852+ get_file(file);
60853+ our_file = file;
60854+ }
60855+ }
60856+ rcu_read_unlock();
60857+ put_files_struct(files);
60858+ }
60859+
60860+ if (our_file == NULL)
60861+ return 1;
60862+
60863+ read_lock(&tasklist_lock);
60864+ do_each_thread(p2, p) {
60865+ files = get_files_struct(p);
60866+ if (files == NULL ||
60867+ (p->signal && p->signal->tty == task->signal->tty)) {
60868+ if (files != NULL)
60869+ put_files_struct(files);
60870+ continue;
60871+ }
60872+ rcu_read_lock();
60873+ fdt = files_fdtable(files);
60874+ for (i=0; i < fdt->max_fds; i++) {
60875+ file = fcheck_files(files, i);
60876+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
60877+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
60878+ p3 = task;
60879+ while (task_pid_nr(p3) > 0) {
60880+ if (p3 == p)
60881+ break;
60882+ p3 = p3->real_parent;
60883+ }
60884+ if (p3 == p)
60885+ break;
60886+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
60887+ gr_handle_alertkill(p);
60888+ rcu_read_unlock();
60889+ put_files_struct(files);
60890+ read_unlock(&tasklist_lock);
60891+ fput(our_file);
60892+ return 0;
60893+ }
60894+ }
60895+ rcu_read_unlock();
60896+ put_files_struct(files);
60897+ } while_each_thread(p2, p);
60898+ read_unlock(&tasklist_lock);
60899+
60900+ fput(our_file);
60901+ return 1;
60902+}
60903+
60904+static int gr_rbac_disable(void *unused)
60905+{
60906+ pax_open_kernel();
60907+ gr_status &= ~GR_READY;
60908+ pax_close_kernel();
60909+
60910+ return 0;
60911+}
60912+
60913+ssize_t
60914+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
60915+{
60916+ struct gr_arg_wrapper uwrap;
60917+ unsigned char *sprole_salt = NULL;
60918+ unsigned char *sprole_sum = NULL;
60919+ int error = sizeof (struct gr_arg_wrapper);
60920+ int error2 = 0;
60921+
60922+ mutex_lock(&gr_dev_mutex);
60923+
60924+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
60925+ error = -EPERM;
60926+ goto out;
60927+ }
60928+
60929+ if (count != sizeof (struct gr_arg_wrapper)) {
60930+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
60931+ error = -EINVAL;
60932+ goto out;
60933+ }
60934+
60935+
60936+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
60937+ gr_auth_expires = 0;
60938+ gr_auth_attempts = 0;
60939+ }
60940+
60941+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
60942+ error = -EFAULT;
60943+ goto out;
60944+ }
60945+
60946+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
60947+ error = -EINVAL;
60948+ goto out;
60949+ }
60950+
60951+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
60952+ error = -EFAULT;
60953+ goto out;
60954+ }
60955+
60956+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
60957+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
60958+ time_after(gr_auth_expires, get_seconds())) {
60959+ error = -EBUSY;
60960+ goto out;
60961+ }
60962+
60963+ /* if non-root trying to do anything other than use a special role,
60964+ do not attempt authentication, do not count towards authentication
60965+ locking
60966+ */
60967+
60968+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
60969+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
60970+ gr_is_global_nonroot(current_uid())) {
60971+ error = -EPERM;
60972+ goto out;
60973+ }
60974+
60975+ /* ensure pw and special role name are null terminated */
60976+
60977+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
60978+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
60979+
60980+ /* Okay.
60981+ * We have our enough of the argument structure..(we have yet
60982+ * to copy_from_user the tables themselves) . Copy the tables
60983+ * only if we need them, i.e. for loading operations. */
60984+
60985+ switch (gr_usermode->mode) {
60986+ case GR_STATUS:
60987+ if (gr_status & GR_READY) {
60988+ error = 1;
60989+ if (!gr_check_secure_terminal(current))
60990+ error = 3;
60991+ } else
60992+ error = 2;
60993+ goto out;
60994+ case GR_SHUTDOWN:
60995+ if ((gr_status & GR_READY)
60996+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60997+ stop_machine(gr_rbac_disable, NULL, NULL);
60998+ free_variables();
60999+ memset(gr_usermode, 0, sizeof (struct gr_arg));
61000+ memset(gr_system_salt, 0, GR_SALT_LEN);
61001+ memset(gr_system_sum, 0, GR_SHA_LEN);
61002+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
61003+ } else if (gr_status & GR_READY) {
61004+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
61005+ error = -EPERM;
61006+ } else {
61007+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
61008+ error = -EAGAIN;
61009+ }
61010+ break;
61011+ case GR_ENABLE:
61012+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
61013+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
61014+ else {
61015+ if (gr_status & GR_READY)
61016+ error = -EAGAIN;
61017+ else
61018+ error = error2;
61019+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
61020+ }
61021+ break;
61022+ case GR_RELOAD:
61023+ if (!(gr_status & GR_READY)) {
61024+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
61025+ error = -EAGAIN;
61026+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61027+ stop_machine(gr_rbac_disable, NULL, NULL);
61028+ free_variables();
61029+ error2 = gracl_init(gr_usermode);
61030+ if (!error2)
61031+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
61032+ else {
61033+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
61034+ error = error2;
61035+ }
61036+ } else {
61037+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
61038+ error = -EPERM;
61039+ }
61040+ break;
61041+ case GR_SEGVMOD:
61042+ if (unlikely(!(gr_status & GR_READY))) {
61043+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
61044+ error = -EAGAIN;
61045+ break;
61046+ }
61047+
61048+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61049+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
61050+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
61051+ struct acl_subject_label *segvacl;
61052+ segvacl =
61053+ lookup_acl_subj_label(gr_usermode->segv_inode,
61054+ gr_usermode->segv_device,
61055+ current->role);
61056+ if (segvacl) {
61057+ segvacl->crashes = 0;
61058+ segvacl->expires = 0;
61059+ }
61060+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
61061+ gr_remove_uid(gr_usermode->segv_uid);
61062+ }
61063+ } else {
61064+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
61065+ error = -EPERM;
61066+ }
61067+ break;
61068+ case GR_SPROLE:
61069+ case GR_SPROLEPAM:
61070+ if (unlikely(!(gr_status & GR_READY))) {
61071+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
61072+ error = -EAGAIN;
61073+ break;
61074+ }
61075+
61076+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
61077+ current->role->expires = 0;
61078+ current->role->auth_attempts = 0;
61079+ }
61080+
61081+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
61082+ time_after(current->role->expires, get_seconds())) {
61083+ error = -EBUSY;
61084+ goto out;
61085+ }
61086+
61087+ if (lookup_special_role_auth
61088+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
61089+ && ((!sprole_salt && !sprole_sum)
61090+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
61091+ char *p = "";
61092+ assign_special_role(gr_usermode->sp_role);
61093+ read_lock(&tasklist_lock);
61094+ if (current->real_parent)
61095+ p = current->real_parent->role->rolename;
61096+ read_unlock(&tasklist_lock);
61097+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
61098+ p, acl_sp_role_value);
61099+ } else {
61100+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
61101+ error = -EPERM;
61102+ if(!(current->role->auth_attempts++))
61103+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
61104+
61105+ goto out;
61106+ }
61107+ break;
61108+ case GR_UNSPROLE:
61109+ if (unlikely(!(gr_status & GR_READY))) {
61110+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
61111+ error = -EAGAIN;
61112+ break;
61113+ }
61114+
61115+ if (current->role->roletype & GR_ROLE_SPECIAL) {
61116+ char *p = "";
61117+ int i = 0;
61118+
61119+ read_lock(&tasklist_lock);
61120+ if (current->real_parent) {
61121+ p = current->real_parent->role->rolename;
61122+ i = current->real_parent->acl_role_id;
61123+ }
61124+ read_unlock(&tasklist_lock);
61125+
61126+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
61127+ gr_set_acls(1);
61128+ } else {
61129+ error = -EPERM;
61130+ goto out;
61131+ }
61132+ break;
61133+ default:
61134+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
61135+ error = -EINVAL;
61136+ break;
61137+ }
61138+
61139+ if (error != -EPERM)
61140+ goto out;
61141+
61142+ if(!(gr_auth_attempts++))
61143+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
61144+
61145+ out:
61146+ mutex_unlock(&gr_dev_mutex);
61147+ return error;
61148+}
61149+
61150+/* must be called with
61151+ rcu_read_lock();
61152+ read_lock(&tasklist_lock);
61153+ read_lock(&grsec_exec_file_lock);
61154+*/
61155+int gr_apply_subject_to_task(struct task_struct *task)
61156+{
61157+ struct acl_object_label *obj;
61158+ char *tmpname;
61159+ struct acl_subject_label *tmpsubj;
61160+ struct file *filp;
61161+ struct name_entry *nmatch;
61162+
61163+ filp = task->exec_file;
61164+ if (filp == NULL)
61165+ return 0;
61166+
61167+ /* the following is to apply the correct subject
61168+ on binaries running when the RBAC system
61169+ is enabled, when the binaries have been
61170+ replaced or deleted since their execution
61171+ -----
61172+ when the RBAC system starts, the inode/dev
61173+ from exec_file will be one the RBAC system
61174+ is unaware of. It only knows the inode/dev
61175+ of the present file on disk, or the absence
61176+ of it.
61177+ */
61178+ preempt_disable();
61179+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
61180+
61181+ nmatch = lookup_name_entry(tmpname);
61182+ preempt_enable();
61183+ tmpsubj = NULL;
61184+ if (nmatch) {
61185+ if (nmatch->deleted)
61186+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
61187+ else
61188+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
61189+ if (tmpsubj != NULL)
61190+ task->acl = tmpsubj;
61191+ }
61192+ if (tmpsubj == NULL)
61193+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
61194+ task->role);
61195+ if (task->acl) {
61196+ task->is_writable = 0;
61197+ /* ignore additional mmap checks for processes that are writable
61198+ by the default ACL */
61199+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61200+ if (unlikely(obj->mode & GR_WRITE))
61201+ task->is_writable = 1;
61202+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
61203+ if (unlikely(obj->mode & GR_WRITE))
61204+ task->is_writable = 1;
61205+
61206+ gr_set_proc_res(task);
61207+
61208+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61209+ 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);
61210+#endif
61211+ } else {
61212+ return 1;
61213+ }
61214+
61215+ return 0;
61216+}
61217+
61218+int
61219+gr_set_acls(const int type)
61220+{
61221+ struct task_struct *task, *task2;
61222+ struct acl_role_label *role = current->role;
61223+ __u16 acl_role_id = current->acl_role_id;
61224+ const struct cred *cred;
61225+ int ret;
61226+
61227+ rcu_read_lock();
61228+ read_lock(&tasklist_lock);
61229+ read_lock(&grsec_exec_file_lock);
61230+ do_each_thread(task2, task) {
61231+ /* check to see if we're called from the exit handler,
61232+ if so, only replace ACLs that have inherited the admin
61233+ ACL */
61234+
61235+ if (type && (task->role != role ||
61236+ task->acl_role_id != acl_role_id))
61237+ continue;
61238+
61239+ task->acl_role_id = 0;
61240+ task->acl_sp_role = 0;
61241+
61242+ if (task->exec_file) {
61243+ cred = __task_cred(task);
61244+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
61245+ ret = gr_apply_subject_to_task(task);
61246+ if (ret) {
61247+ read_unlock(&grsec_exec_file_lock);
61248+ read_unlock(&tasklist_lock);
61249+ rcu_read_unlock();
61250+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
61251+ return ret;
61252+ }
61253+ } else {
61254+ // it's a kernel process
61255+ task->role = kernel_role;
61256+ task->acl = kernel_role->root_label;
61257+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
61258+ task->acl->mode &= ~GR_PROCFIND;
61259+#endif
61260+ }
61261+ } while_each_thread(task2, task);
61262+ read_unlock(&grsec_exec_file_lock);
61263+ read_unlock(&tasklist_lock);
61264+ rcu_read_unlock();
61265+
61266+ return 0;
61267+}
61268+
61269+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
61270+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
61271+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
61272+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
61273+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
61274+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
61275+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
61276+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
61277+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
61278+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
61279+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
61280+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
61281+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
61282+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
61283+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
61284+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
61285+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
61286+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
61287+};
61288+
61289+void
61290+gr_learn_resource(const struct task_struct *task,
61291+ const int res, const unsigned long wanted, const int gt)
61292+{
61293+ struct acl_subject_label *acl;
61294+ const struct cred *cred;
61295+
61296+ if (unlikely((gr_status & GR_READY) &&
61297+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
61298+ goto skip_reslog;
61299+
61300+ gr_log_resource(task, res, wanted, gt);
61301+skip_reslog:
61302+
61303+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
61304+ return;
61305+
61306+ acl = task->acl;
61307+
61308+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
61309+ !(acl->resmask & (1U << (unsigned short) res))))
61310+ return;
61311+
61312+ if (wanted >= acl->res[res].rlim_cur) {
61313+ unsigned long res_add;
61314+
61315+ res_add = wanted + res_learn_bumps[res];
61316+
61317+ acl->res[res].rlim_cur = res_add;
61318+
61319+ if (wanted > acl->res[res].rlim_max)
61320+ acl->res[res].rlim_max = res_add;
61321+
61322+ /* only log the subject filename, since resource logging is supported for
61323+ single-subject learning only */
61324+ rcu_read_lock();
61325+ cred = __task_cred(task);
61326+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
61327+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
61328+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
61329+ "", (unsigned long) res, &task->signal->saved_ip);
61330+ rcu_read_unlock();
61331+ }
61332+
61333+ return;
61334+}
61335+EXPORT_SYMBOL(gr_learn_resource);
61336+#endif
61337+
61338+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
61339+void
61340+pax_set_initial_flags(struct linux_binprm *bprm)
61341+{
61342+ struct task_struct *task = current;
61343+ struct acl_subject_label *proc;
61344+ unsigned long flags;
61345+
61346+ if (unlikely(!(gr_status & GR_READY)))
61347+ return;
61348+
61349+ flags = pax_get_flags(task);
61350+
61351+ proc = task->acl;
61352+
61353+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
61354+ flags &= ~MF_PAX_PAGEEXEC;
61355+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
61356+ flags &= ~MF_PAX_SEGMEXEC;
61357+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
61358+ flags &= ~MF_PAX_RANDMMAP;
61359+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
61360+ flags &= ~MF_PAX_EMUTRAMP;
61361+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
61362+ flags &= ~MF_PAX_MPROTECT;
61363+
61364+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
61365+ flags |= MF_PAX_PAGEEXEC;
61366+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
61367+ flags |= MF_PAX_SEGMEXEC;
61368+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
61369+ flags |= MF_PAX_RANDMMAP;
61370+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
61371+ flags |= MF_PAX_EMUTRAMP;
61372+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
61373+ flags |= MF_PAX_MPROTECT;
61374+
61375+ pax_set_flags(task, flags);
61376+
61377+ return;
61378+}
61379+#endif
61380+
61381+int
61382+gr_handle_proc_ptrace(struct task_struct *task)
61383+{
61384+ struct file *filp;
61385+ struct task_struct *tmp = task;
61386+ struct task_struct *curtemp = current;
61387+ __u32 retmode;
61388+
61389+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
61390+ if (unlikely(!(gr_status & GR_READY)))
61391+ return 0;
61392+#endif
61393+
61394+ read_lock(&tasklist_lock);
61395+ read_lock(&grsec_exec_file_lock);
61396+ filp = task->exec_file;
61397+
61398+ while (task_pid_nr(tmp) > 0) {
61399+ if (tmp == curtemp)
61400+ break;
61401+ tmp = tmp->real_parent;
61402+ }
61403+
61404+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
61405+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
61406+ read_unlock(&grsec_exec_file_lock);
61407+ read_unlock(&tasklist_lock);
61408+ return 1;
61409+ }
61410+
61411+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61412+ if (!(gr_status & GR_READY)) {
61413+ read_unlock(&grsec_exec_file_lock);
61414+ read_unlock(&tasklist_lock);
61415+ return 0;
61416+ }
61417+#endif
61418+
61419+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
61420+ read_unlock(&grsec_exec_file_lock);
61421+ read_unlock(&tasklist_lock);
61422+
61423+ if (retmode & GR_NOPTRACE)
61424+ return 1;
61425+
61426+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
61427+ && (current->acl != task->acl || (current->acl != current->role->root_label
61428+ && task_pid_nr(current) != task_pid_nr(task))))
61429+ return 1;
61430+
61431+ return 0;
61432+}
61433+
61434+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
61435+{
61436+ if (unlikely(!(gr_status & GR_READY)))
61437+ return;
61438+
61439+ if (!(current->role->roletype & GR_ROLE_GOD))
61440+ return;
61441+
61442+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
61443+ p->role->rolename, gr_task_roletype_to_char(p),
61444+ p->acl->filename);
61445+}
61446+
61447+int
61448+gr_handle_ptrace(struct task_struct *task, const long request)
61449+{
61450+ struct task_struct *tmp = task;
61451+ struct task_struct *curtemp = current;
61452+ __u32 retmode;
61453+
61454+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
61455+ if (unlikely(!(gr_status & GR_READY)))
61456+ return 0;
61457+#endif
61458+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
61459+ read_lock(&tasklist_lock);
61460+ while (task_pid_nr(tmp) > 0) {
61461+ if (tmp == curtemp)
61462+ break;
61463+ tmp = tmp->real_parent;
61464+ }
61465+
61466+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
61467+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
61468+ read_unlock(&tasklist_lock);
61469+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61470+ return 1;
61471+ }
61472+ read_unlock(&tasklist_lock);
61473+ }
61474+
61475+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61476+ if (!(gr_status & GR_READY))
61477+ return 0;
61478+#endif
61479+
61480+ read_lock(&grsec_exec_file_lock);
61481+ if (unlikely(!task->exec_file)) {
61482+ read_unlock(&grsec_exec_file_lock);
61483+ return 0;
61484+ }
61485+
61486+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
61487+ read_unlock(&grsec_exec_file_lock);
61488+
61489+ if (retmode & GR_NOPTRACE) {
61490+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61491+ return 1;
61492+ }
61493+
61494+ if (retmode & GR_PTRACERD) {
61495+ switch (request) {
61496+ case PTRACE_SEIZE:
61497+ case PTRACE_POKETEXT:
61498+ case PTRACE_POKEDATA:
61499+ case PTRACE_POKEUSR:
61500+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
61501+ case PTRACE_SETREGS:
61502+ case PTRACE_SETFPREGS:
61503+#endif
61504+#ifdef CONFIG_X86
61505+ case PTRACE_SETFPXREGS:
61506+#endif
61507+#ifdef CONFIG_ALTIVEC
61508+ case PTRACE_SETVRREGS:
61509+#endif
61510+ return 1;
61511+ default:
61512+ return 0;
61513+ }
61514+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
61515+ !(current->role->roletype & GR_ROLE_GOD) &&
61516+ (current->acl != task->acl)) {
61517+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61518+ return 1;
61519+ }
61520+
61521+ return 0;
61522+}
61523+
61524+static int is_writable_mmap(const struct file *filp)
61525+{
61526+ struct task_struct *task = current;
61527+ struct acl_object_label *obj, *obj2;
61528+
61529+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
61530+ !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))) {
61531+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61532+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
61533+ task->role->root_label);
61534+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
61535+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
61536+ return 1;
61537+ }
61538+ }
61539+ return 0;
61540+}
61541+
61542+int
61543+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
61544+{
61545+ __u32 mode;
61546+
61547+ if (unlikely(!file || !(prot & PROT_EXEC)))
61548+ return 1;
61549+
61550+ if (is_writable_mmap(file))
61551+ return 0;
61552+
61553+ mode =
61554+ gr_search_file(file->f_path.dentry,
61555+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
61556+ file->f_path.mnt);
61557+
61558+ if (!gr_tpe_allow(file))
61559+ return 0;
61560+
61561+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
61562+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61563+ return 0;
61564+ } else if (unlikely(!(mode & GR_EXEC))) {
61565+ return 0;
61566+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
61567+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61568+ return 1;
61569+ }
61570+
61571+ return 1;
61572+}
61573+
61574+int
61575+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
61576+{
61577+ __u32 mode;
61578+
61579+ if (unlikely(!file || !(prot & PROT_EXEC)))
61580+ return 1;
61581+
61582+ if (is_writable_mmap(file))
61583+ return 0;
61584+
61585+ mode =
61586+ gr_search_file(file->f_path.dentry,
61587+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
61588+ file->f_path.mnt);
61589+
61590+ if (!gr_tpe_allow(file))
61591+ return 0;
61592+
61593+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
61594+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61595+ return 0;
61596+ } else if (unlikely(!(mode & GR_EXEC))) {
61597+ return 0;
61598+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
61599+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
61600+ return 1;
61601+ }
61602+
61603+ return 1;
61604+}
61605+
61606+void
61607+gr_acl_handle_psacct(struct task_struct *task, const long code)
61608+{
61609+ unsigned long runtime;
61610+ unsigned long cputime;
61611+ unsigned int wday, cday;
61612+ __u8 whr, chr;
61613+ __u8 wmin, cmin;
61614+ __u8 wsec, csec;
61615+ struct timespec timeval;
61616+
61617+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
61618+ !(task->acl->mode & GR_PROCACCT)))
61619+ return;
61620+
61621+ do_posix_clock_monotonic_gettime(&timeval);
61622+ runtime = timeval.tv_sec - task->start_time.tv_sec;
61623+ wday = runtime / (3600 * 24);
61624+ runtime -= wday * (3600 * 24);
61625+ whr = runtime / 3600;
61626+ runtime -= whr * 3600;
61627+ wmin = runtime / 60;
61628+ runtime -= wmin * 60;
61629+ wsec = runtime;
61630+
61631+ cputime = (task->utime + task->stime) / HZ;
61632+ cday = cputime / (3600 * 24);
61633+ cputime -= cday * (3600 * 24);
61634+ chr = cputime / 3600;
61635+ cputime -= chr * 3600;
61636+ cmin = cputime / 60;
61637+ cputime -= cmin * 60;
61638+ csec = cputime;
61639+
61640+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
61641+
61642+ return;
61643+}
61644+
61645+void gr_set_kernel_label(struct task_struct *task)
61646+{
61647+ if (gr_status & GR_READY) {
61648+ task->role = kernel_role;
61649+ task->acl = kernel_role->root_label;
61650+ }
61651+ return;
61652+}
61653+
61654+#ifdef CONFIG_TASKSTATS
61655+int gr_is_taskstats_denied(int pid)
61656+{
61657+ struct task_struct *task;
61658+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61659+ const struct cred *cred;
61660+#endif
61661+ int ret = 0;
61662+
61663+ /* restrict taskstats viewing to un-chrooted root users
61664+ who have the 'view' subject flag if the RBAC system is enabled
61665+ */
61666+
61667+ rcu_read_lock();
61668+ read_lock(&tasklist_lock);
61669+ task = find_task_by_vpid(pid);
61670+ if (task) {
61671+#ifdef CONFIG_GRKERNSEC_CHROOT
61672+ if (proc_is_chrooted(task))
61673+ ret = -EACCES;
61674+#endif
61675+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61676+ cred = __task_cred(task);
61677+#ifdef CONFIG_GRKERNSEC_PROC_USER
61678+ if (gr_is_global_nonroot(cred->uid))
61679+ ret = -EACCES;
61680+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61681+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
61682+ ret = -EACCES;
61683+#endif
61684+#endif
61685+ if (gr_status & GR_READY) {
61686+ if (!(task->acl->mode & GR_VIEW))
61687+ ret = -EACCES;
61688+ }
61689+ } else
61690+ ret = -ENOENT;
61691+
61692+ read_unlock(&tasklist_lock);
61693+ rcu_read_unlock();
61694+
61695+ return ret;
61696+}
61697+#endif
61698+
61699+/* AUXV entries are filled via a descendant of search_binary_handler
61700+ after we've already applied the subject for the target
61701+*/
61702+int gr_acl_enable_at_secure(void)
61703+{
61704+ if (unlikely(!(gr_status & GR_READY)))
61705+ return 0;
61706+
61707+ if (current->acl->mode & GR_ATSECURE)
61708+ return 1;
61709+
61710+ return 0;
61711+}
61712+
61713+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
61714+{
61715+ struct task_struct *task = current;
61716+ struct dentry *dentry = file->f_path.dentry;
61717+ struct vfsmount *mnt = file->f_path.mnt;
61718+ struct acl_object_label *obj, *tmp;
61719+ struct acl_subject_label *subj;
61720+ unsigned int bufsize;
61721+ int is_not_root;
61722+ char *path;
61723+ dev_t dev = __get_dev(dentry);
61724+
61725+ if (unlikely(!(gr_status & GR_READY)))
61726+ return 1;
61727+
61728+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
61729+ return 1;
61730+
61731+ /* ignore Eric Biederman */
61732+ if (IS_PRIVATE(dentry->d_inode))
61733+ return 1;
61734+
61735+ subj = task->acl;
61736+ read_lock(&gr_inode_lock);
61737+ do {
61738+ obj = lookup_acl_obj_label(ino, dev, subj);
61739+ if (obj != NULL) {
61740+ read_unlock(&gr_inode_lock);
61741+ return (obj->mode & GR_FIND) ? 1 : 0;
61742+ }
61743+ } while ((subj = subj->parent_subject));
61744+ read_unlock(&gr_inode_lock);
61745+
61746+ /* this is purely an optimization since we're looking for an object
61747+ for the directory we're doing a readdir on
61748+ if it's possible for any globbed object to match the entry we're
61749+ filling into the directory, then the object we find here will be
61750+ an anchor point with attached globbed objects
61751+ */
61752+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
61753+ if (obj->globbed == NULL)
61754+ return (obj->mode & GR_FIND) ? 1 : 0;
61755+
61756+ is_not_root = ((obj->filename[0] == '/') &&
61757+ (obj->filename[1] == '\0')) ? 0 : 1;
61758+ bufsize = PAGE_SIZE - namelen - is_not_root;
61759+
61760+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
61761+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
61762+ return 1;
61763+
61764+ preempt_disable();
61765+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
61766+ bufsize);
61767+
61768+ bufsize = strlen(path);
61769+
61770+ /* if base is "/", don't append an additional slash */
61771+ if (is_not_root)
61772+ *(path + bufsize) = '/';
61773+ memcpy(path + bufsize + is_not_root, name, namelen);
61774+ *(path + bufsize + namelen + is_not_root) = '\0';
61775+
61776+ tmp = obj->globbed;
61777+ while (tmp) {
61778+ if (!glob_match(tmp->filename, path)) {
61779+ preempt_enable();
61780+ return (tmp->mode & GR_FIND) ? 1 : 0;
61781+ }
61782+ tmp = tmp->next;
61783+ }
61784+ preempt_enable();
61785+ return (obj->mode & GR_FIND) ? 1 : 0;
61786+}
61787+
61788+void gr_put_exec_file(struct task_struct *task)
61789+{
61790+ struct file *filp;
61791+
61792+ write_lock(&grsec_exec_file_lock);
61793+ filp = task->exec_file;
61794+ task->exec_file = NULL;
61795+ write_unlock(&grsec_exec_file_lock);
61796+
61797+ if (filp)
61798+ fput(filp);
61799+
61800+ return;
61801+}
61802+
61803+
61804+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
61805+EXPORT_SYMBOL(gr_acl_is_enabled);
61806+#endif
61807+EXPORT_SYMBOL(gr_set_kernel_label);
61808+#ifdef CONFIG_SECURITY
61809+EXPORT_SYMBOL(gr_check_user_change);
61810+EXPORT_SYMBOL(gr_check_group_change);
61811+#endif
61812+
61813diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
61814new file mode 100644
61815index 0000000..34fefda
61816--- /dev/null
61817+++ b/grsecurity/gracl_alloc.c
61818@@ -0,0 +1,105 @@
61819+#include <linux/kernel.h>
61820+#include <linux/mm.h>
61821+#include <linux/slab.h>
61822+#include <linux/vmalloc.h>
61823+#include <linux/gracl.h>
61824+#include <linux/grsecurity.h>
61825+
61826+static unsigned long alloc_stack_next = 1;
61827+static unsigned long alloc_stack_size = 1;
61828+static void **alloc_stack;
61829+
61830+static __inline__ int
61831+alloc_pop(void)
61832+{
61833+ if (alloc_stack_next == 1)
61834+ return 0;
61835+
61836+ kfree(alloc_stack[alloc_stack_next - 2]);
61837+
61838+ alloc_stack_next--;
61839+
61840+ return 1;
61841+}
61842+
61843+static __inline__ int
61844+alloc_push(void *buf)
61845+{
61846+ if (alloc_stack_next >= alloc_stack_size)
61847+ return 1;
61848+
61849+ alloc_stack[alloc_stack_next - 1] = buf;
61850+
61851+ alloc_stack_next++;
61852+
61853+ return 0;
61854+}
61855+
61856+void *
61857+acl_alloc(unsigned long len)
61858+{
61859+ void *ret = NULL;
61860+
61861+ if (!len || len > PAGE_SIZE)
61862+ goto out;
61863+
61864+ ret = kmalloc(len, GFP_KERNEL);
61865+
61866+ if (ret) {
61867+ if (alloc_push(ret)) {
61868+ kfree(ret);
61869+ ret = NULL;
61870+ }
61871+ }
61872+
61873+out:
61874+ return ret;
61875+}
61876+
61877+void *
61878+acl_alloc_num(unsigned long num, unsigned long len)
61879+{
61880+ if (!len || (num > (PAGE_SIZE / len)))
61881+ return NULL;
61882+
61883+ return acl_alloc(num * len);
61884+}
61885+
61886+void
61887+acl_free_all(void)
61888+{
61889+ if (gr_acl_is_enabled() || !alloc_stack)
61890+ return;
61891+
61892+ while (alloc_pop()) ;
61893+
61894+ if (alloc_stack) {
61895+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
61896+ kfree(alloc_stack);
61897+ else
61898+ vfree(alloc_stack);
61899+ }
61900+
61901+ alloc_stack = NULL;
61902+ alloc_stack_size = 1;
61903+ alloc_stack_next = 1;
61904+
61905+ return;
61906+}
61907+
61908+int
61909+acl_alloc_stack_init(unsigned long size)
61910+{
61911+ if ((size * sizeof (void *)) <= PAGE_SIZE)
61912+ alloc_stack =
61913+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
61914+ else
61915+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
61916+
61917+ alloc_stack_size = size;
61918+
61919+ if (!alloc_stack)
61920+ return 0;
61921+ else
61922+ return 1;
61923+}
61924diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
61925new file mode 100644
61926index 0000000..bdd51ea
61927--- /dev/null
61928+++ b/grsecurity/gracl_cap.c
61929@@ -0,0 +1,110 @@
61930+#include <linux/kernel.h>
61931+#include <linux/module.h>
61932+#include <linux/sched.h>
61933+#include <linux/gracl.h>
61934+#include <linux/grsecurity.h>
61935+#include <linux/grinternal.h>
61936+
61937+extern const char *captab_log[];
61938+extern int captab_log_entries;
61939+
61940+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
61941+{
61942+ struct acl_subject_label *curracl;
61943+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
61944+ kernel_cap_t cap_audit = __cap_empty_set;
61945+
61946+ if (!gr_acl_is_enabled())
61947+ return 1;
61948+
61949+ curracl = task->acl;
61950+
61951+ cap_drop = curracl->cap_lower;
61952+ cap_mask = curracl->cap_mask;
61953+ cap_audit = curracl->cap_invert_audit;
61954+
61955+ while ((curracl = curracl->parent_subject)) {
61956+ /* if the cap isn't specified in the current computed mask but is specified in the
61957+ current level subject, and is lowered in the current level subject, then add
61958+ it to the set of dropped capabilities
61959+ otherwise, add the current level subject's mask to the current computed mask
61960+ */
61961+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
61962+ cap_raise(cap_mask, cap);
61963+ if (cap_raised(curracl->cap_lower, cap))
61964+ cap_raise(cap_drop, cap);
61965+ if (cap_raised(curracl->cap_invert_audit, cap))
61966+ cap_raise(cap_audit, cap);
61967+ }
61968+ }
61969+
61970+ if (!cap_raised(cap_drop, cap)) {
61971+ if (cap_raised(cap_audit, cap))
61972+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
61973+ return 1;
61974+ }
61975+
61976+ curracl = task->acl;
61977+
61978+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
61979+ && cap_raised(cred->cap_effective, cap)) {
61980+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
61981+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
61982+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
61983+ gr_to_filename(task->exec_file->f_path.dentry,
61984+ task->exec_file->f_path.mnt) : curracl->filename,
61985+ curracl->filename, 0UL,
61986+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
61987+ return 1;
61988+ }
61989+
61990+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
61991+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
61992+
61993+ return 0;
61994+}
61995+
61996+int
61997+gr_acl_is_capable(const int cap)
61998+{
61999+ return gr_task_acl_is_capable(current, current_cred(), cap);
62000+}
62001+
62002+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
62003+{
62004+ struct acl_subject_label *curracl;
62005+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
62006+
62007+ if (!gr_acl_is_enabled())
62008+ return 1;
62009+
62010+ curracl = task->acl;
62011+
62012+ cap_drop = curracl->cap_lower;
62013+ cap_mask = curracl->cap_mask;
62014+
62015+ while ((curracl = curracl->parent_subject)) {
62016+ /* if the cap isn't specified in the current computed mask but is specified in the
62017+ current level subject, and is lowered in the current level subject, then add
62018+ it to the set of dropped capabilities
62019+ otherwise, add the current level subject's mask to the current computed mask
62020+ */
62021+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
62022+ cap_raise(cap_mask, cap);
62023+ if (cap_raised(curracl->cap_lower, cap))
62024+ cap_raise(cap_drop, cap);
62025+ }
62026+ }
62027+
62028+ if (!cap_raised(cap_drop, cap))
62029+ return 1;
62030+
62031+ return 0;
62032+}
62033+
62034+int
62035+gr_acl_is_capable_nolog(const int cap)
62036+{
62037+ return gr_task_acl_is_capable_nolog(current, cap);
62038+}
62039+
62040diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
62041new file mode 100644
62042index 0000000..a340c17
62043--- /dev/null
62044+++ b/grsecurity/gracl_fs.c
62045@@ -0,0 +1,431 @@
62046+#include <linux/kernel.h>
62047+#include <linux/sched.h>
62048+#include <linux/types.h>
62049+#include <linux/fs.h>
62050+#include <linux/file.h>
62051+#include <linux/stat.h>
62052+#include <linux/grsecurity.h>
62053+#include <linux/grinternal.h>
62054+#include <linux/gracl.h>
62055+
62056+umode_t
62057+gr_acl_umask(void)
62058+{
62059+ if (unlikely(!gr_acl_is_enabled()))
62060+ return 0;
62061+
62062+ return current->role->umask;
62063+}
62064+
62065+__u32
62066+gr_acl_handle_hidden_file(const struct dentry * dentry,
62067+ const struct vfsmount * mnt)
62068+{
62069+ __u32 mode;
62070+
62071+ if (unlikely(!dentry->d_inode))
62072+ return GR_FIND;
62073+
62074+ mode =
62075+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
62076+
62077+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
62078+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
62079+ return mode;
62080+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
62081+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
62082+ return 0;
62083+ } else if (unlikely(!(mode & GR_FIND)))
62084+ return 0;
62085+
62086+ return GR_FIND;
62087+}
62088+
62089+__u32
62090+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
62091+ int acc_mode)
62092+{
62093+ __u32 reqmode = GR_FIND;
62094+ __u32 mode;
62095+
62096+ if (unlikely(!dentry->d_inode))
62097+ return reqmode;
62098+
62099+ if (acc_mode & MAY_APPEND)
62100+ reqmode |= GR_APPEND;
62101+ else if (acc_mode & MAY_WRITE)
62102+ reqmode |= GR_WRITE;
62103+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
62104+ reqmode |= GR_READ;
62105+
62106+ mode =
62107+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
62108+ mnt);
62109+
62110+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62111+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
62112+ reqmode & GR_READ ? " reading" : "",
62113+ reqmode & GR_WRITE ? " writing" : reqmode &
62114+ GR_APPEND ? " appending" : "");
62115+ return reqmode;
62116+ } else
62117+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62118+ {
62119+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
62120+ reqmode & GR_READ ? " reading" : "",
62121+ reqmode & GR_WRITE ? " writing" : reqmode &
62122+ GR_APPEND ? " appending" : "");
62123+ return 0;
62124+ } else if (unlikely((mode & reqmode) != reqmode))
62125+ return 0;
62126+
62127+ return reqmode;
62128+}
62129+
62130+__u32
62131+gr_acl_handle_creat(const struct dentry * dentry,
62132+ const struct dentry * p_dentry,
62133+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
62134+ const int imode)
62135+{
62136+ __u32 reqmode = GR_WRITE | GR_CREATE;
62137+ __u32 mode;
62138+
62139+ if (acc_mode & MAY_APPEND)
62140+ reqmode |= GR_APPEND;
62141+ // if a directory was required or the directory already exists, then
62142+ // don't count this open as a read
62143+ if ((acc_mode & MAY_READ) &&
62144+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
62145+ reqmode |= GR_READ;
62146+ if ((open_flags & O_CREAT) &&
62147+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
62148+ reqmode |= GR_SETID;
62149+
62150+ mode =
62151+ gr_check_create(dentry, p_dentry, p_mnt,
62152+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
62153+
62154+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62155+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
62156+ reqmode & GR_READ ? " reading" : "",
62157+ reqmode & GR_WRITE ? " writing" : reqmode &
62158+ GR_APPEND ? " appending" : "");
62159+ return reqmode;
62160+ } else
62161+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62162+ {
62163+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
62164+ reqmode & GR_READ ? " reading" : "",
62165+ reqmode & GR_WRITE ? " writing" : reqmode &
62166+ GR_APPEND ? " appending" : "");
62167+ return 0;
62168+ } else if (unlikely((mode & reqmode) != reqmode))
62169+ return 0;
62170+
62171+ return reqmode;
62172+}
62173+
62174+__u32
62175+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
62176+ const int fmode)
62177+{
62178+ __u32 mode, reqmode = GR_FIND;
62179+
62180+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
62181+ reqmode |= GR_EXEC;
62182+ if (fmode & S_IWOTH)
62183+ reqmode |= GR_WRITE;
62184+ if (fmode & S_IROTH)
62185+ reqmode |= GR_READ;
62186+
62187+ mode =
62188+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
62189+ mnt);
62190+
62191+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62192+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
62193+ reqmode & GR_READ ? " reading" : "",
62194+ reqmode & GR_WRITE ? " writing" : "",
62195+ reqmode & GR_EXEC ? " executing" : "");
62196+ return reqmode;
62197+ } else
62198+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62199+ {
62200+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
62201+ reqmode & GR_READ ? " reading" : "",
62202+ reqmode & GR_WRITE ? " writing" : "",
62203+ reqmode & GR_EXEC ? " executing" : "");
62204+ return 0;
62205+ } else if (unlikely((mode & reqmode) != reqmode))
62206+ return 0;
62207+
62208+ return reqmode;
62209+}
62210+
62211+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
62212+{
62213+ __u32 mode;
62214+
62215+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
62216+
62217+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
62218+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
62219+ return mode;
62220+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
62221+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
62222+ return 0;
62223+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
62224+ return 0;
62225+
62226+ return (reqmode);
62227+}
62228+
62229+__u32
62230+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
62231+{
62232+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
62233+}
62234+
62235+__u32
62236+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
62237+{
62238+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
62239+}
62240+
62241+__u32
62242+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
62243+{
62244+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
62245+}
62246+
62247+__u32
62248+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
62249+{
62250+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
62251+}
62252+
62253+__u32
62254+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
62255+ umode_t *modeptr)
62256+{
62257+ umode_t mode;
62258+
62259+ *modeptr &= ~gr_acl_umask();
62260+ mode = *modeptr;
62261+
62262+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
62263+ return 1;
62264+
62265+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
62266+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
62267+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
62268+ GR_CHMOD_ACL_MSG);
62269+ } else {
62270+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
62271+ }
62272+}
62273+
62274+__u32
62275+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
62276+{
62277+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
62278+}
62279+
62280+__u32
62281+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
62282+{
62283+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
62284+}
62285+
62286+__u32
62287+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
62288+{
62289+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
62290+}
62291+
62292+__u32
62293+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
62294+{
62295+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
62296+ GR_UNIXCONNECT_ACL_MSG);
62297+}
62298+
62299+/* hardlinks require at minimum create and link permission,
62300+ any additional privilege required is based on the
62301+ privilege of the file being linked to
62302+*/
62303+__u32
62304+gr_acl_handle_link(const struct dentry * new_dentry,
62305+ const struct dentry * parent_dentry,
62306+ const struct vfsmount * parent_mnt,
62307+ const struct dentry * old_dentry,
62308+ const struct vfsmount * old_mnt, const struct filename *to)
62309+{
62310+ __u32 mode;
62311+ __u32 needmode = GR_CREATE | GR_LINK;
62312+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
62313+
62314+ mode =
62315+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
62316+ old_mnt);
62317+
62318+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
62319+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
62320+ return mode;
62321+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
62322+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
62323+ return 0;
62324+ } else if (unlikely((mode & needmode) != needmode))
62325+ return 0;
62326+
62327+ return 1;
62328+}
62329+
62330+__u32
62331+gr_acl_handle_symlink(const struct dentry * new_dentry,
62332+ const struct dentry * parent_dentry,
62333+ const struct vfsmount * parent_mnt, const struct filename *from)
62334+{
62335+ __u32 needmode = GR_WRITE | GR_CREATE;
62336+ __u32 mode;
62337+
62338+ mode =
62339+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
62340+ GR_CREATE | GR_AUDIT_CREATE |
62341+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
62342+
62343+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
62344+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
62345+ return mode;
62346+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
62347+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
62348+ return 0;
62349+ } else if (unlikely((mode & needmode) != needmode))
62350+ return 0;
62351+
62352+ return (GR_WRITE | GR_CREATE);
62353+}
62354+
62355+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)
62356+{
62357+ __u32 mode;
62358+
62359+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
62360+
62361+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
62362+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
62363+ return mode;
62364+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
62365+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
62366+ return 0;
62367+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
62368+ return 0;
62369+
62370+ return (reqmode);
62371+}
62372+
62373+__u32
62374+gr_acl_handle_mknod(const struct dentry * new_dentry,
62375+ const struct dentry * parent_dentry,
62376+ const struct vfsmount * parent_mnt,
62377+ const int mode)
62378+{
62379+ __u32 reqmode = GR_WRITE | GR_CREATE;
62380+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
62381+ reqmode |= GR_SETID;
62382+
62383+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
62384+ reqmode, GR_MKNOD_ACL_MSG);
62385+}
62386+
62387+__u32
62388+gr_acl_handle_mkdir(const struct dentry *new_dentry,
62389+ const struct dentry *parent_dentry,
62390+ const struct vfsmount *parent_mnt)
62391+{
62392+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
62393+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
62394+}
62395+
62396+#define RENAME_CHECK_SUCCESS(old, new) \
62397+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
62398+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
62399+
62400+int
62401+gr_acl_handle_rename(struct dentry *new_dentry,
62402+ struct dentry *parent_dentry,
62403+ const struct vfsmount *parent_mnt,
62404+ struct dentry *old_dentry,
62405+ struct inode *old_parent_inode,
62406+ struct vfsmount *old_mnt, const struct filename *newname)
62407+{
62408+ __u32 comp1, comp2;
62409+ int error = 0;
62410+
62411+ if (unlikely(!gr_acl_is_enabled()))
62412+ return 0;
62413+
62414+ if (!new_dentry->d_inode) {
62415+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
62416+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
62417+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
62418+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
62419+ GR_DELETE | GR_AUDIT_DELETE |
62420+ GR_AUDIT_READ | GR_AUDIT_WRITE |
62421+ GR_SUPPRESS, old_mnt);
62422+ } else {
62423+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
62424+ GR_CREATE | GR_DELETE |
62425+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
62426+ GR_AUDIT_READ | GR_AUDIT_WRITE |
62427+ GR_SUPPRESS, parent_mnt);
62428+ comp2 =
62429+ gr_search_file(old_dentry,
62430+ GR_READ | GR_WRITE | GR_AUDIT_READ |
62431+ GR_DELETE | GR_AUDIT_DELETE |
62432+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
62433+ }
62434+
62435+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
62436+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
62437+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
62438+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
62439+ && !(comp2 & GR_SUPPRESS)) {
62440+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
62441+ error = -EACCES;
62442+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
62443+ error = -EACCES;
62444+
62445+ return error;
62446+}
62447+
62448+void
62449+gr_acl_handle_exit(void)
62450+{
62451+ u16 id;
62452+ char *rolename;
62453+
62454+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
62455+ !(current->role->roletype & GR_ROLE_PERSIST))) {
62456+ id = current->acl_role_id;
62457+ rolename = current->role->rolename;
62458+ gr_set_acls(1);
62459+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
62460+ }
62461+
62462+ gr_put_exec_file(current);
62463+ return;
62464+}
62465+
62466+int
62467+gr_acl_handle_procpidmem(const struct task_struct *task)
62468+{
62469+ if (unlikely(!gr_acl_is_enabled()))
62470+ return 0;
62471+
62472+ if (task != current && task->acl->mode & GR_PROTPROCFD)
62473+ return -EACCES;
62474+
62475+ return 0;
62476+}
62477diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
62478new file mode 100644
62479index 0000000..8132048
62480--- /dev/null
62481+++ b/grsecurity/gracl_ip.c
62482@@ -0,0 +1,387 @@
62483+#include <linux/kernel.h>
62484+#include <asm/uaccess.h>
62485+#include <asm/errno.h>
62486+#include <net/sock.h>
62487+#include <linux/file.h>
62488+#include <linux/fs.h>
62489+#include <linux/net.h>
62490+#include <linux/in.h>
62491+#include <linux/skbuff.h>
62492+#include <linux/ip.h>
62493+#include <linux/udp.h>
62494+#include <linux/types.h>
62495+#include <linux/sched.h>
62496+#include <linux/netdevice.h>
62497+#include <linux/inetdevice.h>
62498+#include <linux/gracl.h>
62499+#include <linux/grsecurity.h>
62500+#include <linux/grinternal.h>
62501+
62502+#define GR_BIND 0x01
62503+#define GR_CONNECT 0x02
62504+#define GR_INVERT 0x04
62505+#define GR_BINDOVERRIDE 0x08
62506+#define GR_CONNECTOVERRIDE 0x10
62507+#define GR_SOCK_FAMILY 0x20
62508+
62509+static const char * gr_protocols[IPPROTO_MAX] = {
62510+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
62511+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
62512+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
62513+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
62514+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
62515+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
62516+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
62517+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
62518+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
62519+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
62520+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
62521+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
62522+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
62523+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
62524+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
62525+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
62526+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
62527+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
62528+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
62529+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
62530+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
62531+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
62532+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
62533+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
62534+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
62535+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
62536+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
62537+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
62538+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
62539+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
62540+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
62541+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
62542+ };
62543+
62544+static const char * gr_socktypes[SOCK_MAX] = {
62545+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
62546+ "unknown:7", "unknown:8", "unknown:9", "packet"
62547+ };
62548+
62549+static const char * gr_sockfamilies[AF_MAX+1] = {
62550+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
62551+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
62552+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
62553+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
62554+ };
62555+
62556+const char *
62557+gr_proto_to_name(unsigned char proto)
62558+{
62559+ return gr_protocols[proto];
62560+}
62561+
62562+const char *
62563+gr_socktype_to_name(unsigned char type)
62564+{
62565+ return gr_socktypes[type];
62566+}
62567+
62568+const char *
62569+gr_sockfamily_to_name(unsigned char family)
62570+{
62571+ return gr_sockfamilies[family];
62572+}
62573+
62574+int
62575+gr_search_socket(const int domain, const int type, const int protocol)
62576+{
62577+ struct acl_subject_label *curr;
62578+ const struct cred *cred = current_cred();
62579+
62580+ if (unlikely(!gr_acl_is_enabled()))
62581+ goto exit;
62582+
62583+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
62584+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
62585+ goto exit; // let the kernel handle it
62586+
62587+ curr = current->acl;
62588+
62589+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
62590+ /* the family is allowed, if this is PF_INET allow it only if
62591+ the extra sock type/protocol checks pass */
62592+ if (domain == PF_INET)
62593+ goto inet_check;
62594+ goto exit;
62595+ } else {
62596+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
62597+ __u32 fakeip = 0;
62598+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62599+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62600+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62601+ gr_to_filename(current->exec_file->f_path.dentry,
62602+ current->exec_file->f_path.mnt) :
62603+ curr->filename, curr->filename,
62604+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
62605+ &current->signal->saved_ip);
62606+ goto exit;
62607+ }
62608+ goto exit_fail;
62609+ }
62610+
62611+inet_check:
62612+ /* the rest of this checking is for IPv4 only */
62613+ if (!curr->ips)
62614+ goto exit;
62615+
62616+ if ((curr->ip_type & (1U << type)) &&
62617+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
62618+ goto exit;
62619+
62620+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
62621+ /* we don't place acls on raw sockets , and sometimes
62622+ dgram/ip sockets are opened for ioctl and not
62623+ bind/connect, so we'll fake a bind learn log */
62624+ if (type == SOCK_RAW || type == SOCK_PACKET) {
62625+ __u32 fakeip = 0;
62626+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62627+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62628+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62629+ gr_to_filename(current->exec_file->f_path.dentry,
62630+ current->exec_file->f_path.mnt) :
62631+ curr->filename, curr->filename,
62632+ &fakeip, 0, type,
62633+ protocol, GR_CONNECT, &current->signal->saved_ip);
62634+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
62635+ __u32 fakeip = 0;
62636+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62637+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62638+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62639+ gr_to_filename(current->exec_file->f_path.dentry,
62640+ current->exec_file->f_path.mnt) :
62641+ curr->filename, curr->filename,
62642+ &fakeip, 0, type,
62643+ protocol, GR_BIND, &current->signal->saved_ip);
62644+ }
62645+ /* we'll log when they use connect or bind */
62646+ goto exit;
62647+ }
62648+
62649+exit_fail:
62650+ if (domain == PF_INET)
62651+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
62652+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
62653+ else
62654+#ifndef CONFIG_IPV6
62655+ if (domain != PF_INET6)
62656+#endif
62657+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
62658+ gr_socktype_to_name(type), protocol);
62659+
62660+ return 0;
62661+exit:
62662+ return 1;
62663+}
62664+
62665+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)
62666+{
62667+ if ((ip->mode & mode) &&
62668+ (ip_port >= ip->low) &&
62669+ (ip_port <= ip->high) &&
62670+ ((ntohl(ip_addr) & our_netmask) ==
62671+ (ntohl(our_addr) & our_netmask))
62672+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
62673+ && (ip->type & (1U << type))) {
62674+ if (ip->mode & GR_INVERT)
62675+ return 2; // specifically denied
62676+ else
62677+ return 1; // allowed
62678+ }
62679+
62680+ return 0; // not specifically allowed, may continue parsing
62681+}
62682+
62683+static int
62684+gr_search_connectbind(const int full_mode, struct sock *sk,
62685+ struct sockaddr_in *addr, const int type)
62686+{
62687+ char iface[IFNAMSIZ] = {0};
62688+ struct acl_subject_label *curr;
62689+ struct acl_ip_label *ip;
62690+ struct inet_sock *isk;
62691+ struct net_device *dev;
62692+ struct in_device *idev;
62693+ unsigned long i;
62694+ int ret;
62695+ int mode = full_mode & (GR_BIND | GR_CONNECT);
62696+ __u32 ip_addr = 0;
62697+ __u32 our_addr;
62698+ __u32 our_netmask;
62699+ char *p;
62700+ __u16 ip_port = 0;
62701+ const struct cred *cred = current_cred();
62702+
62703+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
62704+ return 0;
62705+
62706+ curr = current->acl;
62707+ isk = inet_sk(sk);
62708+
62709+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
62710+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
62711+ addr->sin_addr.s_addr = curr->inaddr_any_override;
62712+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
62713+ struct sockaddr_in saddr;
62714+ int err;
62715+
62716+ saddr.sin_family = AF_INET;
62717+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
62718+ saddr.sin_port = isk->inet_sport;
62719+
62720+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
62721+ if (err)
62722+ return err;
62723+
62724+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
62725+ if (err)
62726+ return err;
62727+ }
62728+
62729+ if (!curr->ips)
62730+ return 0;
62731+
62732+ ip_addr = addr->sin_addr.s_addr;
62733+ ip_port = ntohs(addr->sin_port);
62734+
62735+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
62736+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
62737+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
62738+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
62739+ gr_to_filename(current->exec_file->f_path.dentry,
62740+ current->exec_file->f_path.mnt) :
62741+ curr->filename, curr->filename,
62742+ &ip_addr, ip_port, type,
62743+ sk->sk_protocol, mode, &current->signal->saved_ip);
62744+ return 0;
62745+ }
62746+
62747+ for (i = 0; i < curr->ip_num; i++) {
62748+ ip = *(curr->ips + i);
62749+ if (ip->iface != NULL) {
62750+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
62751+ p = strchr(iface, ':');
62752+ if (p != NULL)
62753+ *p = '\0';
62754+ dev = dev_get_by_name(sock_net(sk), iface);
62755+ if (dev == NULL)
62756+ continue;
62757+ idev = in_dev_get(dev);
62758+ if (idev == NULL) {
62759+ dev_put(dev);
62760+ continue;
62761+ }
62762+ rcu_read_lock();
62763+ for_ifa(idev) {
62764+ if (!strcmp(ip->iface, ifa->ifa_label)) {
62765+ our_addr = ifa->ifa_address;
62766+ our_netmask = 0xffffffff;
62767+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
62768+ if (ret == 1) {
62769+ rcu_read_unlock();
62770+ in_dev_put(idev);
62771+ dev_put(dev);
62772+ return 0;
62773+ } else if (ret == 2) {
62774+ rcu_read_unlock();
62775+ in_dev_put(idev);
62776+ dev_put(dev);
62777+ goto denied;
62778+ }
62779+ }
62780+ } endfor_ifa(idev);
62781+ rcu_read_unlock();
62782+ in_dev_put(idev);
62783+ dev_put(dev);
62784+ } else {
62785+ our_addr = ip->addr;
62786+ our_netmask = ip->netmask;
62787+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
62788+ if (ret == 1)
62789+ return 0;
62790+ else if (ret == 2)
62791+ goto denied;
62792+ }
62793+ }
62794+
62795+denied:
62796+ if (mode == GR_BIND)
62797+ 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));
62798+ else if (mode == GR_CONNECT)
62799+ 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));
62800+
62801+ return -EACCES;
62802+}
62803+
62804+int
62805+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
62806+{
62807+ /* always allow disconnection of dgram sockets with connect */
62808+ if (addr->sin_family == AF_UNSPEC)
62809+ return 0;
62810+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
62811+}
62812+
62813+int
62814+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
62815+{
62816+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
62817+}
62818+
62819+int gr_search_listen(struct socket *sock)
62820+{
62821+ struct sock *sk = sock->sk;
62822+ struct sockaddr_in addr;
62823+
62824+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
62825+ addr.sin_port = inet_sk(sk)->inet_sport;
62826+
62827+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
62828+}
62829+
62830+int gr_search_accept(struct socket *sock)
62831+{
62832+ struct sock *sk = sock->sk;
62833+ struct sockaddr_in addr;
62834+
62835+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
62836+ addr.sin_port = inet_sk(sk)->inet_sport;
62837+
62838+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
62839+}
62840+
62841+int
62842+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
62843+{
62844+ if (addr)
62845+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
62846+ else {
62847+ struct sockaddr_in sin;
62848+ const struct inet_sock *inet = inet_sk(sk);
62849+
62850+ sin.sin_addr.s_addr = inet->inet_daddr;
62851+ sin.sin_port = inet->inet_dport;
62852+
62853+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
62854+ }
62855+}
62856+
62857+int
62858+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
62859+{
62860+ struct sockaddr_in sin;
62861+
62862+ if (unlikely(skb->len < sizeof (struct udphdr)))
62863+ return 0; // skip this packet
62864+
62865+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
62866+ sin.sin_port = udp_hdr(skb)->source;
62867+
62868+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
62869+}
62870diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
62871new file mode 100644
62872index 0000000..25f54ef
62873--- /dev/null
62874+++ b/grsecurity/gracl_learn.c
62875@@ -0,0 +1,207 @@
62876+#include <linux/kernel.h>
62877+#include <linux/mm.h>
62878+#include <linux/sched.h>
62879+#include <linux/poll.h>
62880+#include <linux/string.h>
62881+#include <linux/file.h>
62882+#include <linux/types.h>
62883+#include <linux/vmalloc.h>
62884+#include <linux/grinternal.h>
62885+
62886+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
62887+ size_t count, loff_t *ppos);
62888+extern int gr_acl_is_enabled(void);
62889+
62890+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
62891+static int gr_learn_attached;
62892+
62893+/* use a 512k buffer */
62894+#define LEARN_BUFFER_SIZE (512 * 1024)
62895+
62896+static DEFINE_SPINLOCK(gr_learn_lock);
62897+static DEFINE_MUTEX(gr_learn_user_mutex);
62898+
62899+/* we need to maintain two buffers, so that the kernel context of grlearn
62900+ uses a semaphore around the userspace copying, and the other kernel contexts
62901+ use a spinlock when copying into the buffer, since they cannot sleep
62902+*/
62903+static char *learn_buffer;
62904+static char *learn_buffer_user;
62905+static int learn_buffer_len;
62906+static int learn_buffer_user_len;
62907+
62908+static ssize_t
62909+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
62910+{
62911+ DECLARE_WAITQUEUE(wait, current);
62912+ ssize_t retval = 0;
62913+
62914+ add_wait_queue(&learn_wait, &wait);
62915+ set_current_state(TASK_INTERRUPTIBLE);
62916+ do {
62917+ mutex_lock(&gr_learn_user_mutex);
62918+ spin_lock(&gr_learn_lock);
62919+ if (learn_buffer_len)
62920+ break;
62921+ spin_unlock(&gr_learn_lock);
62922+ mutex_unlock(&gr_learn_user_mutex);
62923+ if (file->f_flags & O_NONBLOCK) {
62924+ retval = -EAGAIN;
62925+ goto out;
62926+ }
62927+ if (signal_pending(current)) {
62928+ retval = -ERESTARTSYS;
62929+ goto out;
62930+ }
62931+
62932+ schedule();
62933+ } while (1);
62934+
62935+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
62936+ learn_buffer_user_len = learn_buffer_len;
62937+ retval = learn_buffer_len;
62938+ learn_buffer_len = 0;
62939+
62940+ spin_unlock(&gr_learn_lock);
62941+
62942+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
62943+ retval = -EFAULT;
62944+
62945+ mutex_unlock(&gr_learn_user_mutex);
62946+out:
62947+ set_current_state(TASK_RUNNING);
62948+ remove_wait_queue(&learn_wait, &wait);
62949+ return retval;
62950+}
62951+
62952+static unsigned int
62953+poll_learn(struct file * file, poll_table * wait)
62954+{
62955+ poll_wait(file, &learn_wait, wait);
62956+
62957+ if (learn_buffer_len)
62958+ return (POLLIN | POLLRDNORM);
62959+
62960+ return 0;
62961+}
62962+
62963+void
62964+gr_clear_learn_entries(void)
62965+{
62966+ char *tmp;
62967+
62968+ mutex_lock(&gr_learn_user_mutex);
62969+ spin_lock(&gr_learn_lock);
62970+ tmp = learn_buffer;
62971+ learn_buffer = NULL;
62972+ spin_unlock(&gr_learn_lock);
62973+ if (tmp)
62974+ vfree(tmp);
62975+ if (learn_buffer_user != NULL) {
62976+ vfree(learn_buffer_user);
62977+ learn_buffer_user = NULL;
62978+ }
62979+ learn_buffer_len = 0;
62980+ mutex_unlock(&gr_learn_user_mutex);
62981+
62982+ return;
62983+}
62984+
62985+void
62986+gr_add_learn_entry(const char *fmt, ...)
62987+{
62988+ va_list args;
62989+ unsigned int len;
62990+
62991+ if (!gr_learn_attached)
62992+ return;
62993+
62994+ spin_lock(&gr_learn_lock);
62995+
62996+ /* leave a gap at the end so we know when it's "full" but don't have to
62997+ compute the exact length of the string we're trying to append
62998+ */
62999+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
63000+ spin_unlock(&gr_learn_lock);
63001+ wake_up_interruptible(&learn_wait);
63002+ return;
63003+ }
63004+ if (learn_buffer == NULL) {
63005+ spin_unlock(&gr_learn_lock);
63006+ return;
63007+ }
63008+
63009+ va_start(args, fmt);
63010+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
63011+ va_end(args);
63012+
63013+ learn_buffer_len += len + 1;
63014+
63015+ spin_unlock(&gr_learn_lock);
63016+ wake_up_interruptible(&learn_wait);
63017+
63018+ return;
63019+}
63020+
63021+static int
63022+open_learn(struct inode *inode, struct file *file)
63023+{
63024+ if (file->f_mode & FMODE_READ && gr_learn_attached)
63025+ return -EBUSY;
63026+ if (file->f_mode & FMODE_READ) {
63027+ int retval = 0;
63028+ mutex_lock(&gr_learn_user_mutex);
63029+ if (learn_buffer == NULL)
63030+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
63031+ if (learn_buffer_user == NULL)
63032+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
63033+ if (learn_buffer == NULL) {
63034+ retval = -ENOMEM;
63035+ goto out_error;
63036+ }
63037+ if (learn_buffer_user == NULL) {
63038+ retval = -ENOMEM;
63039+ goto out_error;
63040+ }
63041+ learn_buffer_len = 0;
63042+ learn_buffer_user_len = 0;
63043+ gr_learn_attached = 1;
63044+out_error:
63045+ mutex_unlock(&gr_learn_user_mutex);
63046+ return retval;
63047+ }
63048+ return 0;
63049+}
63050+
63051+static int
63052+close_learn(struct inode *inode, struct file *file)
63053+{
63054+ if (file->f_mode & FMODE_READ) {
63055+ char *tmp = NULL;
63056+ mutex_lock(&gr_learn_user_mutex);
63057+ spin_lock(&gr_learn_lock);
63058+ tmp = learn_buffer;
63059+ learn_buffer = NULL;
63060+ spin_unlock(&gr_learn_lock);
63061+ if (tmp)
63062+ vfree(tmp);
63063+ if (learn_buffer_user != NULL) {
63064+ vfree(learn_buffer_user);
63065+ learn_buffer_user = NULL;
63066+ }
63067+ learn_buffer_len = 0;
63068+ learn_buffer_user_len = 0;
63069+ gr_learn_attached = 0;
63070+ mutex_unlock(&gr_learn_user_mutex);
63071+ }
63072+
63073+ return 0;
63074+}
63075+
63076+const struct file_operations grsec_fops = {
63077+ .read = read_learn,
63078+ .write = write_grsec_handler,
63079+ .open = open_learn,
63080+ .release = close_learn,
63081+ .poll = poll_learn,
63082+};
63083diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
63084new file mode 100644
63085index 0000000..39645c9
63086--- /dev/null
63087+++ b/grsecurity/gracl_res.c
63088@@ -0,0 +1,68 @@
63089+#include <linux/kernel.h>
63090+#include <linux/sched.h>
63091+#include <linux/gracl.h>
63092+#include <linux/grinternal.h>
63093+
63094+static const char *restab_log[] = {
63095+ [RLIMIT_CPU] = "RLIMIT_CPU",
63096+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
63097+ [RLIMIT_DATA] = "RLIMIT_DATA",
63098+ [RLIMIT_STACK] = "RLIMIT_STACK",
63099+ [RLIMIT_CORE] = "RLIMIT_CORE",
63100+ [RLIMIT_RSS] = "RLIMIT_RSS",
63101+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
63102+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
63103+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
63104+ [RLIMIT_AS] = "RLIMIT_AS",
63105+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
63106+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
63107+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
63108+ [RLIMIT_NICE] = "RLIMIT_NICE",
63109+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
63110+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
63111+ [GR_CRASH_RES] = "RLIMIT_CRASH"
63112+};
63113+
63114+void
63115+gr_log_resource(const struct task_struct *task,
63116+ const int res, const unsigned long wanted, const int gt)
63117+{
63118+ const struct cred *cred;
63119+ unsigned long rlim;
63120+
63121+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
63122+ return;
63123+
63124+ // not yet supported resource
63125+ if (unlikely(!restab_log[res]))
63126+ return;
63127+
63128+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
63129+ rlim = task_rlimit_max(task, res);
63130+ else
63131+ rlim = task_rlimit(task, res);
63132+
63133+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
63134+ return;
63135+
63136+ rcu_read_lock();
63137+ cred = __task_cred(task);
63138+
63139+ if (res == RLIMIT_NPROC &&
63140+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
63141+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
63142+ goto out_rcu_unlock;
63143+ else if (res == RLIMIT_MEMLOCK &&
63144+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
63145+ goto out_rcu_unlock;
63146+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
63147+ goto out_rcu_unlock;
63148+ rcu_read_unlock();
63149+
63150+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
63151+
63152+ return;
63153+out_rcu_unlock:
63154+ rcu_read_unlock();
63155+ return;
63156+}
63157diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
63158new file mode 100644
63159index 0000000..4dcc92a
63160--- /dev/null
63161+++ b/grsecurity/gracl_segv.c
63162@@ -0,0 +1,305 @@
63163+#include <linux/kernel.h>
63164+#include <linux/mm.h>
63165+#include <asm/uaccess.h>
63166+#include <asm/errno.h>
63167+#include <asm/mman.h>
63168+#include <net/sock.h>
63169+#include <linux/file.h>
63170+#include <linux/fs.h>
63171+#include <linux/net.h>
63172+#include <linux/in.h>
63173+#include <linux/slab.h>
63174+#include <linux/types.h>
63175+#include <linux/sched.h>
63176+#include <linux/timer.h>
63177+#include <linux/gracl.h>
63178+#include <linux/grsecurity.h>
63179+#include <linux/grinternal.h>
63180+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
63181+#include <linux/magic.h>
63182+#include <linux/pagemap.h>
63183+#include "../fs/btrfs/async-thread.h"
63184+#include "../fs/btrfs/ctree.h"
63185+#include "../fs/btrfs/btrfs_inode.h"
63186+#endif
63187+
63188+static struct crash_uid *uid_set;
63189+static unsigned short uid_used;
63190+static DEFINE_SPINLOCK(gr_uid_lock);
63191+extern rwlock_t gr_inode_lock;
63192+extern struct acl_subject_label *
63193+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
63194+ struct acl_role_label *role);
63195+
63196+static inline dev_t __get_dev(const struct dentry *dentry)
63197+{
63198+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
63199+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
63200+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
63201+ else
63202+#endif
63203+ return dentry->d_sb->s_dev;
63204+}
63205+
63206+int
63207+gr_init_uidset(void)
63208+{
63209+ uid_set =
63210+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
63211+ uid_used = 0;
63212+
63213+ return uid_set ? 1 : 0;
63214+}
63215+
63216+void
63217+gr_free_uidset(void)
63218+{
63219+ if (uid_set)
63220+ kfree(uid_set);
63221+
63222+ return;
63223+}
63224+
63225+int
63226+gr_find_uid(const uid_t uid)
63227+{
63228+ struct crash_uid *tmp = uid_set;
63229+ uid_t buid;
63230+ int low = 0, high = uid_used - 1, mid;
63231+
63232+ while (high >= low) {
63233+ mid = (low + high) >> 1;
63234+ buid = tmp[mid].uid;
63235+ if (buid == uid)
63236+ return mid;
63237+ if (buid > uid)
63238+ high = mid - 1;
63239+ if (buid < uid)
63240+ low = mid + 1;
63241+ }
63242+
63243+ return -1;
63244+}
63245+
63246+static __inline__ void
63247+gr_insertsort(void)
63248+{
63249+ unsigned short i, j;
63250+ struct crash_uid index;
63251+
63252+ for (i = 1; i < uid_used; i++) {
63253+ index = uid_set[i];
63254+ j = i;
63255+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
63256+ uid_set[j] = uid_set[j - 1];
63257+ j--;
63258+ }
63259+ uid_set[j] = index;
63260+ }
63261+
63262+ return;
63263+}
63264+
63265+static __inline__ void
63266+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
63267+{
63268+ int loc;
63269+ uid_t uid = GR_GLOBAL_UID(kuid);
63270+
63271+ if (uid_used == GR_UIDTABLE_MAX)
63272+ return;
63273+
63274+ loc = gr_find_uid(uid);
63275+
63276+ if (loc >= 0) {
63277+ uid_set[loc].expires = expires;
63278+ return;
63279+ }
63280+
63281+ uid_set[uid_used].uid = uid;
63282+ uid_set[uid_used].expires = expires;
63283+ uid_used++;
63284+
63285+ gr_insertsort();
63286+
63287+ return;
63288+}
63289+
63290+void
63291+gr_remove_uid(const unsigned short loc)
63292+{
63293+ unsigned short i;
63294+
63295+ for (i = loc + 1; i < uid_used; i++)
63296+ uid_set[i - 1] = uid_set[i];
63297+
63298+ uid_used--;
63299+
63300+ return;
63301+}
63302+
63303+int
63304+gr_check_crash_uid(const kuid_t kuid)
63305+{
63306+ int loc;
63307+ int ret = 0;
63308+ uid_t uid;
63309+
63310+ if (unlikely(!gr_acl_is_enabled()))
63311+ return 0;
63312+
63313+ uid = GR_GLOBAL_UID(kuid);
63314+
63315+ spin_lock(&gr_uid_lock);
63316+ loc = gr_find_uid(uid);
63317+
63318+ if (loc < 0)
63319+ goto out_unlock;
63320+
63321+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
63322+ gr_remove_uid(loc);
63323+ else
63324+ ret = 1;
63325+
63326+out_unlock:
63327+ spin_unlock(&gr_uid_lock);
63328+ return ret;
63329+}
63330+
63331+static __inline__ int
63332+proc_is_setxid(const struct cred *cred)
63333+{
63334+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
63335+ !uid_eq(cred->uid, cred->fsuid))
63336+ return 1;
63337+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
63338+ !gid_eq(cred->gid, cred->fsgid))
63339+ return 1;
63340+
63341+ return 0;
63342+}
63343+
63344+extern int gr_fake_force_sig(int sig, struct task_struct *t);
63345+
63346+void
63347+gr_handle_crash(struct task_struct *task, const int sig)
63348+{
63349+ struct acl_subject_label *curr;
63350+ struct task_struct *tsk, *tsk2;
63351+ const struct cred *cred;
63352+ const struct cred *cred2;
63353+
63354+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
63355+ return;
63356+
63357+ if (unlikely(!gr_acl_is_enabled()))
63358+ return;
63359+
63360+ curr = task->acl;
63361+
63362+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
63363+ return;
63364+
63365+ if (time_before_eq(curr->expires, get_seconds())) {
63366+ curr->expires = 0;
63367+ curr->crashes = 0;
63368+ }
63369+
63370+ curr->crashes++;
63371+
63372+ if (!curr->expires)
63373+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
63374+
63375+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
63376+ time_after(curr->expires, get_seconds())) {
63377+ rcu_read_lock();
63378+ cred = __task_cred(task);
63379+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
63380+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
63381+ spin_lock(&gr_uid_lock);
63382+ gr_insert_uid(cred->uid, curr->expires);
63383+ spin_unlock(&gr_uid_lock);
63384+ curr->expires = 0;
63385+ curr->crashes = 0;
63386+ read_lock(&tasklist_lock);
63387+ do_each_thread(tsk2, tsk) {
63388+ cred2 = __task_cred(tsk);
63389+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
63390+ gr_fake_force_sig(SIGKILL, tsk);
63391+ } while_each_thread(tsk2, tsk);
63392+ read_unlock(&tasklist_lock);
63393+ } else {
63394+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
63395+ read_lock(&tasklist_lock);
63396+ read_lock(&grsec_exec_file_lock);
63397+ do_each_thread(tsk2, tsk) {
63398+ if (likely(tsk != task)) {
63399+ // if this thread has the same subject as the one that triggered
63400+ // RES_CRASH and it's the same binary, kill it
63401+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
63402+ gr_fake_force_sig(SIGKILL, tsk);
63403+ }
63404+ } while_each_thread(tsk2, tsk);
63405+ read_unlock(&grsec_exec_file_lock);
63406+ read_unlock(&tasklist_lock);
63407+ }
63408+ rcu_read_unlock();
63409+ }
63410+
63411+ return;
63412+}
63413+
63414+int
63415+gr_check_crash_exec(const struct file *filp)
63416+{
63417+ struct acl_subject_label *curr;
63418+
63419+ if (unlikely(!gr_acl_is_enabled()))
63420+ return 0;
63421+
63422+ read_lock(&gr_inode_lock);
63423+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
63424+ __get_dev(filp->f_path.dentry),
63425+ current->role);
63426+ read_unlock(&gr_inode_lock);
63427+
63428+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
63429+ (!curr->crashes && !curr->expires))
63430+ return 0;
63431+
63432+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
63433+ time_after(curr->expires, get_seconds()))
63434+ return 1;
63435+ else if (time_before_eq(curr->expires, get_seconds())) {
63436+ curr->crashes = 0;
63437+ curr->expires = 0;
63438+ }
63439+
63440+ return 0;
63441+}
63442+
63443+void
63444+gr_handle_alertkill(struct task_struct *task)
63445+{
63446+ struct acl_subject_label *curracl;
63447+ __u32 curr_ip;
63448+ struct task_struct *p, *p2;
63449+
63450+ if (unlikely(!gr_acl_is_enabled()))
63451+ return;
63452+
63453+ curracl = task->acl;
63454+ curr_ip = task->signal->curr_ip;
63455+
63456+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
63457+ read_lock(&tasklist_lock);
63458+ do_each_thread(p2, p) {
63459+ if (p->signal->curr_ip == curr_ip)
63460+ gr_fake_force_sig(SIGKILL, p);
63461+ } while_each_thread(p2, p);
63462+ read_unlock(&tasklist_lock);
63463+ } else if (curracl->mode & GR_KILLPROC)
63464+ gr_fake_force_sig(SIGKILL, task);
63465+
63466+ return;
63467+}
63468diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
63469new file mode 100644
63470index 0000000..98011b0
63471--- /dev/null
63472+++ b/grsecurity/gracl_shm.c
63473@@ -0,0 +1,40 @@
63474+#include <linux/kernel.h>
63475+#include <linux/mm.h>
63476+#include <linux/sched.h>
63477+#include <linux/file.h>
63478+#include <linux/ipc.h>
63479+#include <linux/gracl.h>
63480+#include <linux/grsecurity.h>
63481+#include <linux/grinternal.h>
63482+
63483+int
63484+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63485+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
63486+{
63487+ struct task_struct *task;
63488+
63489+ if (!gr_acl_is_enabled())
63490+ return 1;
63491+
63492+ rcu_read_lock();
63493+ read_lock(&tasklist_lock);
63494+
63495+ task = find_task_by_vpid(shm_cprid);
63496+
63497+ if (unlikely(!task))
63498+ task = find_task_by_vpid(shm_lapid);
63499+
63500+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
63501+ (task_pid_nr(task) == shm_lapid)) &&
63502+ (task->acl->mode & GR_PROTSHM) &&
63503+ (task->acl != current->acl))) {
63504+ read_unlock(&tasklist_lock);
63505+ rcu_read_unlock();
63506+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
63507+ return 0;
63508+ }
63509+ read_unlock(&tasklist_lock);
63510+ rcu_read_unlock();
63511+
63512+ return 1;
63513+}
63514diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
63515new file mode 100644
63516index 0000000..bc0be01
63517--- /dev/null
63518+++ b/grsecurity/grsec_chdir.c
63519@@ -0,0 +1,19 @@
63520+#include <linux/kernel.h>
63521+#include <linux/sched.h>
63522+#include <linux/fs.h>
63523+#include <linux/file.h>
63524+#include <linux/grsecurity.h>
63525+#include <linux/grinternal.h>
63526+
63527+void
63528+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
63529+{
63530+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
63531+ if ((grsec_enable_chdir && grsec_enable_group &&
63532+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
63533+ !grsec_enable_group)) {
63534+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
63535+ }
63536+#endif
63537+ return;
63538+}
63539diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
63540new file mode 100644
63541index 0000000..bd6e105
63542--- /dev/null
63543+++ b/grsecurity/grsec_chroot.c
63544@@ -0,0 +1,370 @@
63545+#include <linux/kernel.h>
63546+#include <linux/module.h>
63547+#include <linux/sched.h>
63548+#include <linux/file.h>
63549+#include <linux/fs.h>
63550+#include <linux/mount.h>
63551+#include <linux/types.h>
63552+#include "../fs/mount.h"
63553+#include <linux/grsecurity.h>
63554+#include <linux/grinternal.h>
63555+
63556+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
63557+static int gr_init_ran;
63558+#endif
63559+
63560+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
63561+{
63562+#ifdef CONFIG_GRKERNSEC
63563+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
63564+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
63565+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
63566+ && gr_init_ran
63567+#endif
63568+ )
63569+ task->gr_is_chrooted = 1;
63570+ else {
63571+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
63572+ if (task_pid_nr(task) == 1 && !gr_init_ran)
63573+ gr_init_ran = 1;
63574+#endif
63575+ task->gr_is_chrooted = 0;
63576+ }
63577+
63578+ task->gr_chroot_dentry = path->dentry;
63579+#endif
63580+ return;
63581+}
63582+
63583+void gr_clear_chroot_entries(struct task_struct *task)
63584+{
63585+#ifdef CONFIG_GRKERNSEC
63586+ task->gr_is_chrooted = 0;
63587+ task->gr_chroot_dentry = NULL;
63588+#endif
63589+ return;
63590+}
63591+
63592+int
63593+gr_handle_chroot_unix(const pid_t pid)
63594+{
63595+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
63596+ struct task_struct *p;
63597+
63598+ if (unlikely(!grsec_enable_chroot_unix))
63599+ return 1;
63600+
63601+ if (likely(!proc_is_chrooted(current)))
63602+ return 1;
63603+
63604+ rcu_read_lock();
63605+ read_lock(&tasklist_lock);
63606+ p = find_task_by_vpid_unrestricted(pid);
63607+ if (unlikely(p && !have_same_root(current, p))) {
63608+ read_unlock(&tasklist_lock);
63609+ rcu_read_unlock();
63610+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
63611+ return 0;
63612+ }
63613+ read_unlock(&tasklist_lock);
63614+ rcu_read_unlock();
63615+#endif
63616+ return 1;
63617+}
63618+
63619+int
63620+gr_handle_chroot_nice(void)
63621+{
63622+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
63623+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
63624+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
63625+ return -EPERM;
63626+ }
63627+#endif
63628+ return 0;
63629+}
63630+
63631+int
63632+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
63633+{
63634+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
63635+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
63636+ && proc_is_chrooted(current)) {
63637+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
63638+ return -EACCES;
63639+ }
63640+#endif
63641+ return 0;
63642+}
63643+
63644+int
63645+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
63646+{
63647+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63648+ struct task_struct *p;
63649+ int ret = 0;
63650+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
63651+ return ret;
63652+
63653+ read_lock(&tasklist_lock);
63654+ do_each_pid_task(pid, type, p) {
63655+ if (!have_same_root(current, p)) {
63656+ ret = 1;
63657+ goto out;
63658+ }
63659+ } while_each_pid_task(pid, type, p);
63660+out:
63661+ read_unlock(&tasklist_lock);
63662+ return ret;
63663+#endif
63664+ return 0;
63665+}
63666+
63667+int
63668+gr_pid_is_chrooted(struct task_struct *p)
63669+{
63670+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63671+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
63672+ return 0;
63673+
63674+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
63675+ !have_same_root(current, p)) {
63676+ return 1;
63677+ }
63678+#endif
63679+ return 0;
63680+}
63681+
63682+EXPORT_SYMBOL(gr_pid_is_chrooted);
63683+
63684+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
63685+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
63686+{
63687+ struct path path, currentroot;
63688+ int ret = 0;
63689+
63690+ path.dentry = (struct dentry *)u_dentry;
63691+ path.mnt = (struct vfsmount *)u_mnt;
63692+ get_fs_root(current->fs, &currentroot);
63693+ if (path_is_under(&path, &currentroot))
63694+ ret = 1;
63695+ path_put(&currentroot);
63696+
63697+ return ret;
63698+}
63699+#endif
63700+
63701+int
63702+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
63703+{
63704+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
63705+ if (!grsec_enable_chroot_fchdir)
63706+ return 1;
63707+
63708+ if (!proc_is_chrooted(current))
63709+ return 1;
63710+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
63711+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
63712+ return 0;
63713+ }
63714+#endif
63715+ return 1;
63716+}
63717+
63718+int
63719+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63720+ const time_t shm_createtime)
63721+{
63722+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
63723+ struct task_struct *p;
63724+ time_t starttime;
63725+
63726+ if (unlikely(!grsec_enable_chroot_shmat))
63727+ return 1;
63728+
63729+ if (likely(!proc_is_chrooted(current)))
63730+ return 1;
63731+
63732+ rcu_read_lock();
63733+ read_lock(&tasklist_lock);
63734+
63735+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
63736+ starttime = p->start_time.tv_sec;
63737+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
63738+ if (have_same_root(current, p)) {
63739+ goto allow;
63740+ } else {
63741+ read_unlock(&tasklist_lock);
63742+ rcu_read_unlock();
63743+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
63744+ return 0;
63745+ }
63746+ }
63747+ /* creator exited, pid reuse, fall through to next check */
63748+ }
63749+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
63750+ if (unlikely(!have_same_root(current, p))) {
63751+ read_unlock(&tasklist_lock);
63752+ rcu_read_unlock();
63753+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
63754+ return 0;
63755+ }
63756+ }
63757+
63758+allow:
63759+ read_unlock(&tasklist_lock);
63760+ rcu_read_unlock();
63761+#endif
63762+ return 1;
63763+}
63764+
63765+void
63766+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
63767+{
63768+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
63769+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
63770+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
63771+#endif
63772+ return;
63773+}
63774+
63775+int
63776+gr_handle_chroot_mknod(const struct dentry *dentry,
63777+ const struct vfsmount *mnt, const int mode)
63778+{
63779+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
63780+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
63781+ proc_is_chrooted(current)) {
63782+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
63783+ return -EPERM;
63784+ }
63785+#endif
63786+ return 0;
63787+}
63788+
63789+int
63790+gr_handle_chroot_mount(const struct dentry *dentry,
63791+ const struct vfsmount *mnt, const char *dev_name)
63792+{
63793+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
63794+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
63795+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
63796+ return -EPERM;
63797+ }
63798+#endif
63799+ return 0;
63800+}
63801+
63802+int
63803+gr_handle_chroot_pivot(void)
63804+{
63805+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
63806+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
63807+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
63808+ return -EPERM;
63809+ }
63810+#endif
63811+ return 0;
63812+}
63813+
63814+int
63815+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
63816+{
63817+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
63818+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
63819+ !gr_is_outside_chroot(dentry, mnt)) {
63820+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
63821+ return -EPERM;
63822+ }
63823+#endif
63824+ return 0;
63825+}
63826+
63827+extern const char *captab_log[];
63828+extern int captab_log_entries;
63829+
63830+int
63831+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
63832+{
63833+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63834+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
63835+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
63836+ if (cap_raised(chroot_caps, cap)) {
63837+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
63838+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
63839+ }
63840+ return 0;
63841+ }
63842+ }
63843+#endif
63844+ return 1;
63845+}
63846+
63847+int
63848+gr_chroot_is_capable(const int cap)
63849+{
63850+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63851+ return gr_task_chroot_is_capable(current, current_cred(), cap);
63852+#endif
63853+ return 1;
63854+}
63855+
63856+int
63857+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
63858+{
63859+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63860+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
63861+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
63862+ if (cap_raised(chroot_caps, cap)) {
63863+ return 0;
63864+ }
63865+ }
63866+#endif
63867+ return 1;
63868+}
63869+
63870+int
63871+gr_chroot_is_capable_nolog(const int cap)
63872+{
63873+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63874+ return gr_task_chroot_is_capable_nolog(current, cap);
63875+#endif
63876+ return 1;
63877+}
63878+
63879+int
63880+gr_handle_chroot_sysctl(const int op)
63881+{
63882+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
63883+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
63884+ proc_is_chrooted(current))
63885+ return -EACCES;
63886+#endif
63887+ return 0;
63888+}
63889+
63890+void
63891+gr_handle_chroot_chdir(const struct path *path)
63892+{
63893+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
63894+ if (grsec_enable_chroot_chdir)
63895+ set_fs_pwd(current->fs, path);
63896+#endif
63897+ return;
63898+}
63899+
63900+int
63901+gr_handle_chroot_chmod(const struct dentry *dentry,
63902+ const struct vfsmount *mnt, const int mode)
63903+{
63904+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
63905+ /* allow chmod +s on directories, but not files */
63906+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
63907+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
63908+ proc_is_chrooted(current)) {
63909+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
63910+ return -EPERM;
63911+ }
63912+#endif
63913+ return 0;
63914+}
63915diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
63916new file mode 100644
63917index 0000000..ce65ceb
63918--- /dev/null
63919+++ b/grsecurity/grsec_disabled.c
63920@@ -0,0 +1,434 @@
63921+#include <linux/kernel.h>
63922+#include <linux/module.h>
63923+#include <linux/sched.h>
63924+#include <linux/file.h>
63925+#include <linux/fs.h>
63926+#include <linux/kdev_t.h>
63927+#include <linux/net.h>
63928+#include <linux/in.h>
63929+#include <linux/ip.h>
63930+#include <linux/skbuff.h>
63931+#include <linux/sysctl.h>
63932+
63933+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63934+void
63935+pax_set_initial_flags(struct linux_binprm *bprm)
63936+{
63937+ return;
63938+}
63939+#endif
63940+
63941+#ifdef CONFIG_SYSCTL
63942+__u32
63943+gr_handle_sysctl(const struct ctl_table * table, const int op)
63944+{
63945+ return 0;
63946+}
63947+#endif
63948+
63949+#ifdef CONFIG_TASKSTATS
63950+int gr_is_taskstats_denied(int pid)
63951+{
63952+ return 0;
63953+}
63954+#endif
63955+
63956+int
63957+gr_acl_is_enabled(void)
63958+{
63959+ return 0;
63960+}
63961+
63962+void
63963+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
63964+{
63965+ return;
63966+}
63967+
63968+int
63969+gr_handle_rawio(const struct inode *inode)
63970+{
63971+ return 0;
63972+}
63973+
63974+void
63975+gr_acl_handle_psacct(struct task_struct *task, const long code)
63976+{
63977+ return;
63978+}
63979+
63980+int
63981+gr_handle_ptrace(struct task_struct *task, const long request)
63982+{
63983+ return 0;
63984+}
63985+
63986+int
63987+gr_handle_proc_ptrace(struct task_struct *task)
63988+{
63989+ return 0;
63990+}
63991+
63992+int
63993+gr_set_acls(const int type)
63994+{
63995+ return 0;
63996+}
63997+
63998+int
63999+gr_check_hidden_task(const struct task_struct *tsk)
64000+{
64001+ return 0;
64002+}
64003+
64004+int
64005+gr_check_protected_task(const struct task_struct *task)
64006+{
64007+ return 0;
64008+}
64009+
64010+int
64011+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64012+{
64013+ return 0;
64014+}
64015+
64016+void
64017+gr_copy_label(struct task_struct *tsk)
64018+{
64019+ return;
64020+}
64021+
64022+void
64023+gr_set_pax_flags(struct task_struct *task)
64024+{
64025+ return;
64026+}
64027+
64028+int
64029+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
64030+ const int unsafe_share)
64031+{
64032+ return 0;
64033+}
64034+
64035+void
64036+gr_handle_delete(const ino_t ino, const dev_t dev)
64037+{
64038+ return;
64039+}
64040+
64041+void
64042+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
64043+{
64044+ return;
64045+}
64046+
64047+void
64048+gr_handle_crash(struct task_struct *task, const int sig)
64049+{
64050+ return;
64051+}
64052+
64053+int
64054+gr_check_crash_exec(const struct file *filp)
64055+{
64056+ return 0;
64057+}
64058+
64059+int
64060+gr_check_crash_uid(const kuid_t uid)
64061+{
64062+ return 0;
64063+}
64064+
64065+void
64066+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64067+ struct dentry *old_dentry,
64068+ struct dentry *new_dentry,
64069+ struct vfsmount *mnt, const __u8 replace)
64070+{
64071+ return;
64072+}
64073+
64074+int
64075+gr_search_socket(const int family, const int type, const int protocol)
64076+{
64077+ return 1;
64078+}
64079+
64080+int
64081+gr_search_connectbind(const int mode, const struct socket *sock,
64082+ const struct sockaddr_in *addr)
64083+{
64084+ return 0;
64085+}
64086+
64087+void
64088+gr_handle_alertkill(struct task_struct *task)
64089+{
64090+ return;
64091+}
64092+
64093+__u32
64094+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
64095+{
64096+ return 1;
64097+}
64098+
64099+__u32
64100+gr_acl_handle_hidden_file(const struct dentry * dentry,
64101+ const struct vfsmount * mnt)
64102+{
64103+ return 1;
64104+}
64105+
64106+__u32
64107+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
64108+ int acc_mode)
64109+{
64110+ return 1;
64111+}
64112+
64113+__u32
64114+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
64115+{
64116+ return 1;
64117+}
64118+
64119+__u32
64120+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
64121+{
64122+ return 1;
64123+}
64124+
64125+int
64126+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
64127+ unsigned int *vm_flags)
64128+{
64129+ return 1;
64130+}
64131+
64132+__u32
64133+gr_acl_handle_truncate(const struct dentry * dentry,
64134+ const struct vfsmount * mnt)
64135+{
64136+ return 1;
64137+}
64138+
64139+__u32
64140+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
64141+{
64142+ return 1;
64143+}
64144+
64145+__u32
64146+gr_acl_handle_access(const struct dentry * dentry,
64147+ const struct vfsmount * mnt, const int fmode)
64148+{
64149+ return 1;
64150+}
64151+
64152+__u32
64153+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
64154+ umode_t *mode)
64155+{
64156+ return 1;
64157+}
64158+
64159+__u32
64160+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
64161+{
64162+ return 1;
64163+}
64164+
64165+__u32
64166+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
64167+{
64168+ return 1;
64169+}
64170+
64171+void
64172+grsecurity_init(void)
64173+{
64174+ return;
64175+}
64176+
64177+umode_t gr_acl_umask(void)
64178+{
64179+ return 0;
64180+}
64181+
64182+__u32
64183+gr_acl_handle_mknod(const struct dentry * new_dentry,
64184+ const struct dentry * parent_dentry,
64185+ const struct vfsmount * parent_mnt,
64186+ const int mode)
64187+{
64188+ return 1;
64189+}
64190+
64191+__u32
64192+gr_acl_handle_mkdir(const struct dentry * new_dentry,
64193+ const struct dentry * parent_dentry,
64194+ const struct vfsmount * parent_mnt)
64195+{
64196+ return 1;
64197+}
64198+
64199+__u32
64200+gr_acl_handle_symlink(const struct dentry * new_dentry,
64201+ const struct dentry * parent_dentry,
64202+ const struct vfsmount * parent_mnt, const struct filename *from)
64203+{
64204+ return 1;
64205+}
64206+
64207+__u32
64208+gr_acl_handle_link(const struct dentry * new_dentry,
64209+ const struct dentry * parent_dentry,
64210+ const struct vfsmount * parent_mnt,
64211+ const struct dentry * old_dentry,
64212+ const struct vfsmount * old_mnt, const struct filename *to)
64213+{
64214+ return 1;
64215+}
64216+
64217+int
64218+gr_acl_handle_rename(const struct dentry *new_dentry,
64219+ const struct dentry *parent_dentry,
64220+ const struct vfsmount *parent_mnt,
64221+ const struct dentry *old_dentry,
64222+ const struct inode *old_parent_inode,
64223+ const struct vfsmount *old_mnt, const struct filename *newname)
64224+{
64225+ return 0;
64226+}
64227+
64228+int
64229+gr_acl_handle_filldir(const struct file *file, const char *name,
64230+ const int namelen, const ino_t ino)
64231+{
64232+ return 1;
64233+}
64234+
64235+int
64236+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64237+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
64238+{
64239+ return 1;
64240+}
64241+
64242+int
64243+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
64244+{
64245+ return 0;
64246+}
64247+
64248+int
64249+gr_search_accept(const struct socket *sock)
64250+{
64251+ return 0;
64252+}
64253+
64254+int
64255+gr_search_listen(const struct socket *sock)
64256+{
64257+ return 0;
64258+}
64259+
64260+int
64261+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
64262+{
64263+ return 0;
64264+}
64265+
64266+__u32
64267+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
64268+{
64269+ return 1;
64270+}
64271+
64272+__u32
64273+gr_acl_handle_creat(const struct dentry * dentry,
64274+ const struct dentry * p_dentry,
64275+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
64276+ const int imode)
64277+{
64278+ return 1;
64279+}
64280+
64281+void
64282+gr_acl_handle_exit(void)
64283+{
64284+ return;
64285+}
64286+
64287+int
64288+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
64289+{
64290+ return 1;
64291+}
64292+
64293+void
64294+gr_set_role_label(const kuid_t uid, const kgid_t gid)
64295+{
64296+ return;
64297+}
64298+
64299+int
64300+gr_acl_handle_procpidmem(const struct task_struct *task)
64301+{
64302+ return 0;
64303+}
64304+
64305+int
64306+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
64307+{
64308+ return 0;
64309+}
64310+
64311+int
64312+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
64313+{
64314+ return 0;
64315+}
64316+
64317+void
64318+gr_set_kernel_label(struct task_struct *task)
64319+{
64320+ return;
64321+}
64322+
64323+int
64324+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64325+{
64326+ return 0;
64327+}
64328+
64329+int
64330+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64331+{
64332+ return 0;
64333+}
64334+
64335+int gr_acl_enable_at_secure(void)
64336+{
64337+ return 0;
64338+}
64339+
64340+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
64341+{
64342+ return dentry->d_sb->s_dev;
64343+}
64344+
64345+void gr_put_exec_file(struct task_struct *task)
64346+{
64347+ return;
64348+}
64349+
64350+EXPORT_SYMBOL(gr_set_kernel_label);
64351+#ifdef CONFIG_SECURITY
64352+EXPORT_SYMBOL(gr_check_user_change);
64353+EXPORT_SYMBOL(gr_check_group_change);
64354+#endif
64355diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
64356new file mode 100644
64357index 0000000..387032b
64358--- /dev/null
64359+++ b/grsecurity/grsec_exec.c
64360@@ -0,0 +1,187 @@
64361+#include <linux/kernel.h>
64362+#include <linux/sched.h>
64363+#include <linux/file.h>
64364+#include <linux/binfmts.h>
64365+#include <linux/fs.h>
64366+#include <linux/types.h>
64367+#include <linux/grdefs.h>
64368+#include <linux/grsecurity.h>
64369+#include <linux/grinternal.h>
64370+#include <linux/capability.h>
64371+#include <linux/module.h>
64372+#include <linux/compat.h>
64373+
64374+#include <asm/uaccess.h>
64375+
64376+#ifdef CONFIG_GRKERNSEC_EXECLOG
64377+static char gr_exec_arg_buf[132];
64378+static DEFINE_MUTEX(gr_exec_arg_mutex);
64379+#endif
64380+
64381+struct user_arg_ptr {
64382+#ifdef CONFIG_COMPAT
64383+ bool is_compat;
64384+#endif
64385+ union {
64386+ const char __user *const __user *native;
64387+#ifdef CONFIG_COMPAT
64388+ const compat_uptr_t __user *compat;
64389+#endif
64390+ } ptr;
64391+};
64392+
64393+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
64394+
64395+void
64396+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
64397+{
64398+#ifdef CONFIG_GRKERNSEC_EXECLOG
64399+ char *grarg = gr_exec_arg_buf;
64400+ unsigned int i, x, execlen = 0;
64401+ char c;
64402+
64403+ if (!((grsec_enable_execlog && grsec_enable_group &&
64404+ in_group_p(grsec_audit_gid))
64405+ || (grsec_enable_execlog && !grsec_enable_group)))
64406+ return;
64407+
64408+ mutex_lock(&gr_exec_arg_mutex);
64409+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
64410+
64411+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
64412+ const char __user *p;
64413+ unsigned int len;
64414+
64415+ p = get_user_arg_ptr(argv, i);
64416+ if (IS_ERR(p))
64417+ goto log;
64418+
64419+ len = strnlen_user(p, 128 - execlen);
64420+ if (len > 128 - execlen)
64421+ len = 128 - execlen;
64422+ else if (len > 0)
64423+ len--;
64424+ if (copy_from_user(grarg + execlen, p, len))
64425+ goto log;
64426+
64427+ /* rewrite unprintable characters */
64428+ for (x = 0; x < len; x++) {
64429+ c = *(grarg + execlen + x);
64430+ if (c < 32 || c > 126)
64431+ *(grarg + execlen + x) = ' ';
64432+ }
64433+
64434+ execlen += len;
64435+ *(grarg + execlen) = ' ';
64436+ *(grarg + execlen + 1) = '\0';
64437+ execlen++;
64438+ }
64439+
64440+ log:
64441+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
64442+ bprm->file->f_path.mnt, grarg);
64443+ mutex_unlock(&gr_exec_arg_mutex);
64444+#endif
64445+ return;
64446+}
64447+
64448+#ifdef CONFIG_GRKERNSEC
64449+extern int gr_acl_is_capable(const int cap);
64450+extern int gr_acl_is_capable_nolog(const int cap);
64451+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64452+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
64453+extern int gr_chroot_is_capable(const int cap);
64454+extern int gr_chroot_is_capable_nolog(const int cap);
64455+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64456+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
64457+#endif
64458+
64459+const char *captab_log[] = {
64460+ "CAP_CHOWN",
64461+ "CAP_DAC_OVERRIDE",
64462+ "CAP_DAC_READ_SEARCH",
64463+ "CAP_FOWNER",
64464+ "CAP_FSETID",
64465+ "CAP_KILL",
64466+ "CAP_SETGID",
64467+ "CAP_SETUID",
64468+ "CAP_SETPCAP",
64469+ "CAP_LINUX_IMMUTABLE",
64470+ "CAP_NET_BIND_SERVICE",
64471+ "CAP_NET_BROADCAST",
64472+ "CAP_NET_ADMIN",
64473+ "CAP_NET_RAW",
64474+ "CAP_IPC_LOCK",
64475+ "CAP_IPC_OWNER",
64476+ "CAP_SYS_MODULE",
64477+ "CAP_SYS_RAWIO",
64478+ "CAP_SYS_CHROOT",
64479+ "CAP_SYS_PTRACE",
64480+ "CAP_SYS_PACCT",
64481+ "CAP_SYS_ADMIN",
64482+ "CAP_SYS_BOOT",
64483+ "CAP_SYS_NICE",
64484+ "CAP_SYS_RESOURCE",
64485+ "CAP_SYS_TIME",
64486+ "CAP_SYS_TTY_CONFIG",
64487+ "CAP_MKNOD",
64488+ "CAP_LEASE",
64489+ "CAP_AUDIT_WRITE",
64490+ "CAP_AUDIT_CONTROL",
64491+ "CAP_SETFCAP",
64492+ "CAP_MAC_OVERRIDE",
64493+ "CAP_MAC_ADMIN",
64494+ "CAP_SYSLOG",
64495+ "CAP_WAKE_ALARM"
64496+};
64497+
64498+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
64499+
64500+int gr_is_capable(const int cap)
64501+{
64502+#ifdef CONFIG_GRKERNSEC
64503+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
64504+ return 1;
64505+ return 0;
64506+#else
64507+ return 1;
64508+#endif
64509+}
64510+
64511+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
64512+{
64513+#ifdef CONFIG_GRKERNSEC
64514+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
64515+ return 1;
64516+ return 0;
64517+#else
64518+ return 1;
64519+#endif
64520+}
64521+
64522+int gr_is_capable_nolog(const int cap)
64523+{
64524+#ifdef CONFIG_GRKERNSEC
64525+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
64526+ return 1;
64527+ return 0;
64528+#else
64529+ return 1;
64530+#endif
64531+}
64532+
64533+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
64534+{
64535+#ifdef CONFIG_GRKERNSEC
64536+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
64537+ return 1;
64538+ return 0;
64539+#else
64540+ return 1;
64541+#endif
64542+}
64543+
64544+EXPORT_SYMBOL(gr_is_capable);
64545+EXPORT_SYMBOL(gr_is_capable_nolog);
64546+EXPORT_SYMBOL(gr_task_is_capable);
64547+EXPORT_SYMBOL(gr_task_is_capable_nolog);
64548diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
64549new file mode 100644
64550index 0000000..06cc6ea
64551--- /dev/null
64552+++ b/grsecurity/grsec_fifo.c
64553@@ -0,0 +1,24 @@
64554+#include <linux/kernel.h>
64555+#include <linux/sched.h>
64556+#include <linux/fs.h>
64557+#include <linux/file.h>
64558+#include <linux/grinternal.h>
64559+
64560+int
64561+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
64562+ const struct dentry *dir, const int flag, const int acc_mode)
64563+{
64564+#ifdef CONFIG_GRKERNSEC_FIFO
64565+ const struct cred *cred = current_cred();
64566+
64567+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
64568+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
64569+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
64570+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
64571+ if (!inode_permission(dentry->d_inode, acc_mode))
64572+ 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));
64573+ return -EACCES;
64574+ }
64575+#endif
64576+ return 0;
64577+}
64578diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
64579new file mode 100644
64580index 0000000..8ca18bf
64581--- /dev/null
64582+++ b/grsecurity/grsec_fork.c
64583@@ -0,0 +1,23 @@
64584+#include <linux/kernel.h>
64585+#include <linux/sched.h>
64586+#include <linux/grsecurity.h>
64587+#include <linux/grinternal.h>
64588+#include <linux/errno.h>
64589+
64590+void
64591+gr_log_forkfail(const int retval)
64592+{
64593+#ifdef CONFIG_GRKERNSEC_FORKFAIL
64594+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
64595+ switch (retval) {
64596+ case -EAGAIN:
64597+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
64598+ break;
64599+ case -ENOMEM:
64600+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
64601+ break;
64602+ }
64603+ }
64604+#endif
64605+ return;
64606+}
64607diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
64608new file mode 100644
64609index 0000000..a862e9f
64610--- /dev/null
64611+++ b/grsecurity/grsec_init.c
64612@@ -0,0 +1,283 @@
64613+#include <linux/kernel.h>
64614+#include <linux/sched.h>
64615+#include <linux/mm.h>
64616+#include <linux/gracl.h>
64617+#include <linux/slab.h>
64618+#include <linux/vmalloc.h>
64619+#include <linux/percpu.h>
64620+#include <linux/module.h>
64621+
64622+int grsec_enable_ptrace_readexec;
64623+int grsec_enable_setxid;
64624+int grsec_enable_symlinkown;
64625+kgid_t grsec_symlinkown_gid;
64626+int grsec_enable_brute;
64627+int grsec_enable_link;
64628+int grsec_enable_dmesg;
64629+int grsec_enable_harden_ptrace;
64630+int grsec_enable_fifo;
64631+int grsec_enable_execlog;
64632+int grsec_enable_signal;
64633+int grsec_enable_forkfail;
64634+int grsec_enable_audit_ptrace;
64635+int grsec_enable_time;
64636+int grsec_enable_audit_textrel;
64637+int grsec_enable_group;
64638+kgid_t grsec_audit_gid;
64639+int grsec_enable_chdir;
64640+int grsec_enable_mount;
64641+int grsec_enable_rofs;
64642+int grsec_enable_chroot_findtask;
64643+int grsec_enable_chroot_mount;
64644+int grsec_enable_chroot_shmat;
64645+int grsec_enable_chroot_fchdir;
64646+int grsec_enable_chroot_double;
64647+int grsec_enable_chroot_pivot;
64648+int grsec_enable_chroot_chdir;
64649+int grsec_enable_chroot_chmod;
64650+int grsec_enable_chroot_mknod;
64651+int grsec_enable_chroot_nice;
64652+int grsec_enable_chroot_execlog;
64653+int grsec_enable_chroot_caps;
64654+int grsec_enable_chroot_sysctl;
64655+int grsec_enable_chroot_unix;
64656+int grsec_enable_tpe;
64657+kgid_t grsec_tpe_gid;
64658+int grsec_enable_blackhole;
64659+#ifdef CONFIG_IPV6_MODULE
64660+EXPORT_SYMBOL(grsec_enable_blackhole);
64661+#endif
64662+int grsec_lastack_retries;
64663+int grsec_enable_tpe_all;
64664+int grsec_enable_tpe_invert;
64665+int grsec_enable_socket_all;
64666+kgid_t grsec_socket_all_gid;
64667+int grsec_enable_socket_client;
64668+kgid_t grsec_socket_client_gid;
64669+int grsec_enable_socket_server;
64670+kgid_t grsec_socket_server_gid;
64671+int grsec_resource_logging;
64672+int grsec_disable_privio;
64673+int grsec_enable_log_rwxmaps;
64674+int grsec_lock;
64675+
64676+DEFINE_SPINLOCK(grsec_alert_lock);
64677+unsigned long grsec_alert_wtime = 0;
64678+unsigned long grsec_alert_fyet = 0;
64679+
64680+DEFINE_SPINLOCK(grsec_audit_lock);
64681+
64682+DEFINE_RWLOCK(grsec_exec_file_lock);
64683+
64684+char *gr_shared_page[4];
64685+
64686+char *gr_alert_log_fmt;
64687+char *gr_audit_log_fmt;
64688+char *gr_alert_log_buf;
64689+char *gr_audit_log_buf;
64690+
64691+extern struct gr_arg *gr_usermode;
64692+extern unsigned char *gr_system_salt;
64693+extern unsigned char *gr_system_sum;
64694+
64695+void __init
64696+grsecurity_init(void)
64697+{
64698+ int j;
64699+ /* create the per-cpu shared pages */
64700+
64701+#ifdef CONFIG_X86
64702+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
64703+#endif
64704+
64705+ for (j = 0; j < 4; j++) {
64706+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
64707+ if (gr_shared_page[j] == NULL) {
64708+ panic("Unable to allocate grsecurity shared page");
64709+ return;
64710+ }
64711+ }
64712+
64713+ /* allocate log buffers */
64714+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
64715+ if (!gr_alert_log_fmt) {
64716+ panic("Unable to allocate grsecurity alert log format buffer");
64717+ return;
64718+ }
64719+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
64720+ if (!gr_audit_log_fmt) {
64721+ panic("Unable to allocate grsecurity audit log format buffer");
64722+ return;
64723+ }
64724+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
64725+ if (!gr_alert_log_buf) {
64726+ panic("Unable to allocate grsecurity alert log buffer");
64727+ return;
64728+ }
64729+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
64730+ if (!gr_audit_log_buf) {
64731+ panic("Unable to allocate grsecurity audit log buffer");
64732+ return;
64733+ }
64734+
64735+ /* allocate memory for authentication structure */
64736+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
64737+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
64738+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
64739+
64740+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
64741+ panic("Unable to allocate grsecurity authentication structure");
64742+ return;
64743+ }
64744+
64745+
64746+#ifdef CONFIG_GRKERNSEC_IO
64747+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
64748+ grsec_disable_privio = 1;
64749+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
64750+ grsec_disable_privio = 1;
64751+#else
64752+ grsec_disable_privio = 0;
64753+#endif
64754+#endif
64755+
64756+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
64757+ /* for backward compatibility, tpe_invert always defaults to on if
64758+ enabled in the kernel
64759+ */
64760+ grsec_enable_tpe_invert = 1;
64761+#endif
64762+
64763+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
64764+#ifndef CONFIG_GRKERNSEC_SYSCTL
64765+ grsec_lock = 1;
64766+#endif
64767+
64768+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
64769+ grsec_enable_audit_textrel = 1;
64770+#endif
64771+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64772+ grsec_enable_log_rwxmaps = 1;
64773+#endif
64774+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
64775+ grsec_enable_group = 1;
64776+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
64777+#endif
64778+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
64779+ grsec_enable_ptrace_readexec = 1;
64780+#endif
64781+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
64782+ grsec_enable_chdir = 1;
64783+#endif
64784+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
64785+ grsec_enable_harden_ptrace = 1;
64786+#endif
64787+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64788+ grsec_enable_mount = 1;
64789+#endif
64790+#ifdef CONFIG_GRKERNSEC_LINK
64791+ grsec_enable_link = 1;
64792+#endif
64793+#ifdef CONFIG_GRKERNSEC_BRUTE
64794+ grsec_enable_brute = 1;
64795+#endif
64796+#ifdef CONFIG_GRKERNSEC_DMESG
64797+ grsec_enable_dmesg = 1;
64798+#endif
64799+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
64800+ grsec_enable_blackhole = 1;
64801+ grsec_lastack_retries = 4;
64802+#endif
64803+#ifdef CONFIG_GRKERNSEC_FIFO
64804+ grsec_enable_fifo = 1;
64805+#endif
64806+#ifdef CONFIG_GRKERNSEC_EXECLOG
64807+ grsec_enable_execlog = 1;
64808+#endif
64809+#ifdef CONFIG_GRKERNSEC_SETXID
64810+ grsec_enable_setxid = 1;
64811+#endif
64812+#ifdef CONFIG_GRKERNSEC_SIGNAL
64813+ grsec_enable_signal = 1;
64814+#endif
64815+#ifdef CONFIG_GRKERNSEC_FORKFAIL
64816+ grsec_enable_forkfail = 1;
64817+#endif
64818+#ifdef CONFIG_GRKERNSEC_TIME
64819+ grsec_enable_time = 1;
64820+#endif
64821+#ifdef CONFIG_GRKERNSEC_RESLOG
64822+ grsec_resource_logging = 1;
64823+#endif
64824+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64825+ grsec_enable_chroot_findtask = 1;
64826+#endif
64827+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
64828+ grsec_enable_chroot_unix = 1;
64829+#endif
64830+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
64831+ grsec_enable_chroot_mount = 1;
64832+#endif
64833+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
64834+ grsec_enable_chroot_fchdir = 1;
64835+#endif
64836+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
64837+ grsec_enable_chroot_shmat = 1;
64838+#endif
64839+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
64840+ grsec_enable_audit_ptrace = 1;
64841+#endif
64842+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
64843+ grsec_enable_chroot_double = 1;
64844+#endif
64845+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
64846+ grsec_enable_chroot_pivot = 1;
64847+#endif
64848+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
64849+ grsec_enable_chroot_chdir = 1;
64850+#endif
64851+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
64852+ grsec_enable_chroot_chmod = 1;
64853+#endif
64854+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
64855+ grsec_enable_chroot_mknod = 1;
64856+#endif
64857+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64858+ grsec_enable_chroot_nice = 1;
64859+#endif
64860+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
64861+ grsec_enable_chroot_execlog = 1;
64862+#endif
64863+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64864+ grsec_enable_chroot_caps = 1;
64865+#endif
64866+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
64867+ grsec_enable_chroot_sysctl = 1;
64868+#endif
64869+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
64870+ grsec_enable_symlinkown = 1;
64871+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
64872+#endif
64873+#ifdef CONFIG_GRKERNSEC_TPE
64874+ grsec_enable_tpe = 1;
64875+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
64876+#ifdef CONFIG_GRKERNSEC_TPE_ALL
64877+ grsec_enable_tpe_all = 1;
64878+#endif
64879+#endif
64880+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
64881+ grsec_enable_socket_all = 1;
64882+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
64883+#endif
64884+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
64885+ grsec_enable_socket_client = 1;
64886+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
64887+#endif
64888+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
64889+ grsec_enable_socket_server = 1;
64890+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
64891+#endif
64892+#endif
64893+
64894+ return;
64895+}
64896diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
64897new file mode 100644
64898index 0000000..5e05e20
64899--- /dev/null
64900+++ b/grsecurity/grsec_link.c
64901@@ -0,0 +1,58 @@
64902+#include <linux/kernel.h>
64903+#include <linux/sched.h>
64904+#include <linux/fs.h>
64905+#include <linux/file.h>
64906+#include <linux/grinternal.h>
64907+
64908+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
64909+{
64910+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
64911+ const struct inode *link_inode = link->dentry->d_inode;
64912+
64913+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
64914+ /* ignore root-owned links, e.g. /proc/self */
64915+ gr_is_global_nonroot(link_inode->i_uid) && target &&
64916+ !uid_eq(link_inode->i_uid, target->i_uid)) {
64917+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
64918+ return 1;
64919+ }
64920+#endif
64921+ return 0;
64922+}
64923+
64924+int
64925+gr_handle_follow_link(const struct inode *parent,
64926+ const struct inode *inode,
64927+ const struct dentry *dentry, const struct vfsmount *mnt)
64928+{
64929+#ifdef CONFIG_GRKERNSEC_LINK
64930+ const struct cred *cred = current_cred();
64931+
64932+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
64933+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
64934+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
64935+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
64936+ return -EACCES;
64937+ }
64938+#endif
64939+ return 0;
64940+}
64941+
64942+int
64943+gr_handle_hardlink(const struct dentry *dentry,
64944+ const struct vfsmount *mnt,
64945+ struct inode *inode, const int mode, const struct filename *to)
64946+{
64947+#ifdef CONFIG_GRKERNSEC_LINK
64948+ const struct cred *cred = current_cred();
64949+
64950+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
64951+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
64952+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
64953+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
64954+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
64955+ return -EPERM;
64956+ }
64957+#endif
64958+ return 0;
64959+}
64960diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
64961new file mode 100644
64962index 0000000..7c06085
64963--- /dev/null
64964+++ b/grsecurity/grsec_log.c
64965@@ -0,0 +1,326 @@
64966+#include <linux/kernel.h>
64967+#include <linux/sched.h>
64968+#include <linux/file.h>
64969+#include <linux/tty.h>
64970+#include <linux/fs.h>
64971+#include <linux/grinternal.h>
64972+
64973+#ifdef CONFIG_TREE_PREEMPT_RCU
64974+#define DISABLE_PREEMPT() preempt_disable()
64975+#define ENABLE_PREEMPT() preempt_enable()
64976+#else
64977+#define DISABLE_PREEMPT()
64978+#define ENABLE_PREEMPT()
64979+#endif
64980+
64981+#define BEGIN_LOCKS(x) \
64982+ DISABLE_PREEMPT(); \
64983+ rcu_read_lock(); \
64984+ read_lock(&tasklist_lock); \
64985+ read_lock(&grsec_exec_file_lock); \
64986+ if (x != GR_DO_AUDIT) \
64987+ spin_lock(&grsec_alert_lock); \
64988+ else \
64989+ spin_lock(&grsec_audit_lock)
64990+
64991+#define END_LOCKS(x) \
64992+ if (x != GR_DO_AUDIT) \
64993+ spin_unlock(&grsec_alert_lock); \
64994+ else \
64995+ spin_unlock(&grsec_audit_lock); \
64996+ read_unlock(&grsec_exec_file_lock); \
64997+ read_unlock(&tasklist_lock); \
64998+ rcu_read_unlock(); \
64999+ ENABLE_PREEMPT(); \
65000+ if (x == GR_DONT_AUDIT) \
65001+ gr_handle_alertkill(current)
65002+
65003+enum {
65004+ FLOODING,
65005+ NO_FLOODING
65006+};
65007+
65008+extern char *gr_alert_log_fmt;
65009+extern char *gr_audit_log_fmt;
65010+extern char *gr_alert_log_buf;
65011+extern char *gr_audit_log_buf;
65012+
65013+static int gr_log_start(int audit)
65014+{
65015+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
65016+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
65017+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65018+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
65019+ unsigned long curr_secs = get_seconds();
65020+
65021+ if (audit == GR_DO_AUDIT)
65022+ goto set_fmt;
65023+
65024+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
65025+ grsec_alert_wtime = curr_secs;
65026+ grsec_alert_fyet = 0;
65027+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
65028+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
65029+ grsec_alert_fyet++;
65030+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
65031+ grsec_alert_wtime = curr_secs;
65032+ grsec_alert_fyet++;
65033+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
65034+ return FLOODING;
65035+ }
65036+ else return FLOODING;
65037+
65038+set_fmt:
65039+#endif
65040+ memset(buf, 0, PAGE_SIZE);
65041+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
65042+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
65043+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
65044+ } else if (current->signal->curr_ip) {
65045+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
65046+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
65047+ } else if (gr_acl_is_enabled()) {
65048+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
65049+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
65050+ } else {
65051+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
65052+ strcpy(buf, fmt);
65053+ }
65054+
65055+ return NO_FLOODING;
65056+}
65057+
65058+static void gr_log_middle(int audit, const char *msg, va_list ap)
65059+ __attribute__ ((format (printf, 2, 0)));
65060+
65061+static void gr_log_middle(int audit, const char *msg, va_list ap)
65062+{
65063+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65064+ unsigned int len = strlen(buf);
65065+
65066+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
65067+
65068+ return;
65069+}
65070+
65071+static void gr_log_middle_varargs(int audit, const char *msg, ...)
65072+ __attribute__ ((format (printf, 2, 3)));
65073+
65074+static void gr_log_middle_varargs(int audit, const char *msg, ...)
65075+{
65076+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65077+ unsigned int len = strlen(buf);
65078+ va_list ap;
65079+
65080+ va_start(ap, msg);
65081+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
65082+ va_end(ap);
65083+
65084+ return;
65085+}
65086+
65087+static void gr_log_end(int audit, int append_default)
65088+{
65089+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65090+ if (append_default) {
65091+ struct task_struct *task = current;
65092+ struct task_struct *parent = task->real_parent;
65093+ const struct cred *cred = __task_cred(task);
65094+ const struct cred *pcred = __task_cred(parent);
65095+ unsigned int len = strlen(buf);
65096+
65097+ 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));
65098+ }
65099+
65100+ printk("%s\n", buf);
65101+
65102+ return;
65103+}
65104+
65105+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
65106+{
65107+ int logtype;
65108+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
65109+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
65110+ void *voidptr = NULL;
65111+ int num1 = 0, num2 = 0;
65112+ unsigned long ulong1 = 0, ulong2 = 0;
65113+ struct dentry *dentry = NULL;
65114+ struct vfsmount *mnt = NULL;
65115+ struct file *file = NULL;
65116+ struct task_struct *task = NULL;
65117+ const struct cred *cred, *pcred;
65118+ va_list ap;
65119+
65120+ BEGIN_LOCKS(audit);
65121+ logtype = gr_log_start(audit);
65122+ if (logtype == FLOODING) {
65123+ END_LOCKS(audit);
65124+ return;
65125+ }
65126+ va_start(ap, argtypes);
65127+ switch (argtypes) {
65128+ case GR_TTYSNIFF:
65129+ task = va_arg(ap, struct task_struct *);
65130+ 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));
65131+ break;
65132+ case GR_SYSCTL_HIDDEN:
65133+ str1 = va_arg(ap, char *);
65134+ gr_log_middle_varargs(audit, msg, result, str1);
65135+ break;
65136+ case GR_RBAC:
65137+ dentry = va_arg(ap, struct dentry *);
65138+ mnt = va_arg(ap, struct vfsmount *);
65139+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
65140+ break;
65141+ case GR_RBAC_STR:
65142+ dentry = va_arg(ap, struct dentry *);
65143+ mnt = va_arg(ap, struct vfsmount *);
65144+ str1 = va_arg(ap, char *);
65145+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
65146+ break;
65147+ case GR_STR_RBAC:
65148+ str1 = va_arg(ap, char *);
65149+ dentry = va_arg(ap, struct dentry *);
65150+ mnt = va_arg(ap, struct vfsmount *);
65151+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
65152+ break;
65153+ case GR_RBAC_MODE2:
65154+ dentry = va_arg(ap, struct dentry *);
65155+ mnt = va_arg(ap, struct vfsmount *);
65156+ str1 = va_arg(ap, char *);
65157+ str2 = va_arg(ap, char *);
65158+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
65159+ break;
65160+ case GR_RBAC_MODE3:
65161+ dentry = va_arg(ap, struct dentry *);
65162+ mnt = va_arg(ap, struct vfsmount *);
65163+ str1 = va_arg(ap, char *);
65164+ str2 = va_arg(ap, char *);
65165+ str3 = va_arg(ap, char *);
65166+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
65167+ break;
65168+ case GR_FILENAME:
65169+ dentry = va_arg(ap, struct dentry *);
65170+ mnt = va_arg(ap, struct vfsmount *);
65171+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
65172+ break;
65173+ case GR_STR_FILENAME:
65174+ str1 = va_arg(ap, char *);
65175+ dentry = va_arg(ap, struct dentry *);
65176+ mnt = va_arg(ap, struct vfsmount *);
65177+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
65178+ break;
65179+ case GR_FILENAME_STR:
65180+ dentry = va_arg(ap, struct dentry *);
65181+ mnt = va_arg(ap, struct vfsmount *);
65182+ str1 = va_arg(ap, char *);
65183+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
65184+ break;
65185+ case GR_FILENAME_TWO_INT:
65186+ dentry = va_arg(ap, struct dentry *);
65187+ mnt = va_arg(ap, struct vfsmount *);
65188+ num1 = va_arg(ap, int);
65189+ num2 = va_arg(ap, int);
65190+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
65191+ break;
65192+ case GR_FILENAME_TWO_INT_STR:
65193+ dentry = va_arg(ap, struct dentry *);
65194+ mnt = va_arg(ap, struct vfsmount *);
65195+ num1 = va_arg(ap, int);
65196+ num2 = va_arg(ap, int);
65197+ str1 = va_arg(ap, char *);
65198+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
65199+ break;
65200+ case GR_TEXTREL:
65201+ file = va_arg(ap, struct file *);
65202+ ulong1 = va_arg(ap, unsigned long);
65203+ ulong2 = va_arg(ap, unsigned long);
65204+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
65205+ break;
65206+ case GR_PTRACE:
65207+ task = va_arg(ap, struct task_struct *);
65208+ 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));
65209+ break;
65210+ case GR_RESOURCE:
65211+ task = va_arg(ap, struct task_struct *);
65212+ cred = __task_cred(task);
65213+ pcred = __task_cred(task->real_parent);
65214+ ulong1 = va_arg(ap, unsigned long);
65215+ str1 = va_arg(ap, char *);
65216+ ulong2 = va_arg(ap, unsigned long);
65217+ 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));
65218+ break;
65219+ case GR_CAP:
65220+ task = va_arg(ap, struct task_struct *);
65221+ cred = __task_cred(task);
65222+ pcred = __task_cred(task->real_parent);
65223+ str1 = va_arg(ap, char *);
65224+ 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));
65225+ break;
65226+ case GR_SIG:
65227+ str1 = va_arg(ap, char *);
65228+ voidptr = va_arg(ap, void *);
65229+ gr_log_middle_varargs(audit, msg, str1, voidptr);
65230+ break;
65231+ case GR_SIG2:
65232+ task = va_arg(ap, struct task_struct *);
65233+ cred = __task_cred(task);
65234+ pcred = __task_cred(task->real_parent);
65235+ num1 = va_arg(ap, int);
65236+ 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));
65237+ break;
65238+ case GR_CRASH1:
65239+ task = va_arg(ap, struct task_struct *);
65240+ cred = __task_cred(task);
65241+ pcred = __task_cred(task->real_parent);
65242+ ulong1 = va_arg(ap, unsigned long);
65243+ 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);
65244+ break;
65245+ case GR_CRASH2:
65246+ task = va_arg(ap, struct task_struct *);
65247+ cred = __task_cred(task);
65248+ pcred = __task_cred(task->real_parent);
65249+ ulong1 = va_arg(ap, unsigned long);
65250+ 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);
65251+ break;
65252+ case GR_RWXMAP:
65253+ file = va_arg(ap, struct file *);
65254+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
65255+ break;
65256+ case GR_PSACCT:
65257+ {
65258+ unsigned int wday, cday;
65259+ __u8 whr, chr;
65260+ __u8 wmin, cmin;
65261+ __u8 wsec, csec;
65262+ char cur_tty[64] = { 0 };
65263+ char parent_tty[64] = { 0 };
65264+
65265+ task = va_arg(ap, struct task_struct *);
65266+ wday = va_arg(ap, unsigned int);
65267+ cday = va_arg(ap, unsigned int);
65268+ whr = va_arg(ap, int);
65269+ chr = va_arg(ap, int);
65270+ wmin = va_arg(ap, int);
65271+ cmin = va_arg(ap, int);
65272+ wsec = va_arg(ap, int);
65273+ csec = va_arg(ap, int);
65274+ ulong1 = va_arg(ap, unsigned long);
65275+ cred = __task_cred(task);
65276+ pcred = __task_cred(task->real_parent);
65277+
65278+ 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));
65279+ }
65280+ break;
65281+ default:
65282+ gr_log_middle(audit, msg, ap);
65283+ }
65284+ va_end(ap);
65285+ // these don't need DEFAULTSECARGS printed on the end
65286+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
65287+ gr_log_end(audit, 0);
65288+ else
65289+ gr_log_end(audit, 1);
65290+ END_LOCKS(audit);
65291+}
65292diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
65293new file mode 100644
65294index 0000000..f536303
65295--- /dev/null
65296+++ b/grsecurity/grsec_mem.c
65297@@ -0,0 +1,40 @@
65298+#include <linux/kernel.h>
65299+#include <linux/sched.h>
65300+#include <linux/mm.h>
65301+#include <linux/mman.h>
65302+#include <linux/grinternal.h>
65303+
65304+void
65305+gr_handle_ioperm(void)
65306+{
65307+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
65308+ return;
65309+}
65310+
65311+void
65312+gr_handle_iopl(void)
65313+{
65314+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
65315+ return;
65316+}
65317+
65318+void
65319+gr_handle_mem_readwrite(u64 from, u64 to)
65320+{
65321+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
65322+ return;
65323+}
65324+
65325+void
65326+gr_handle_vm86(void)
65327+{
65328+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
65329+ return;
65330+}
65331+
65332+void
65333+gr_log_badprocpid(const char *entry)
65334+{
65335+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
65336+ return;
65337+}
65338diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
65339new file mode 100644
65340index 0000000..2131422
65341--- /dev/null
65342+++ b/grsecurity/grsec_mount.c
65343@@ -0,0 +1,62 @@
65344+#include <linux/kernel.h>
65345+#include <linux/sched.h>
65346+#include <linux/mount.h>
65347+#include <linux/grsecurity.h>
65348+#include <linux/grinternal.h>
65349+
65350+void
65351+gr_log_remount(const char *devname, const int retval)
65352+{
65353+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65354+ if (grsec_enable_mount && (retval >= 0))
65355+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
65356+#endif
65357+ return;
65358+}
65359+
65360+void
65361+gr_log_unmount(const char *devname, const int retval)
65362+{
65363+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65364+ if (grsec_enable_mount && (retval >= 0))
65365+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
65366+#endif
65367+ return;
65368+}
65369+
65370+void
65371+gr_log_mount(const char *from, const char *to, const int retval)
65372+{
65373+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65374+ if (grsec_enable_mount && (retval >= 0))
65375+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
65376+#endif
65377+ return;
65378+}
65379+
65380+int
65381+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
65382+{
65383+#ifdef CONFIG_GRKERNSEC_ROFS
65384+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
65385+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
65386+ return -EPERM;
65387+ } else
65388+ return 0;
65389+#endif
65390+ return 0;
65391+}
65392+
65393+int
65394+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
65395+{
65396+#ifdef CONFIG_GRKERNSEC_ROFS
65397+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
65398+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
65399+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
65400+ return -EPERM;
65401+ } else
65402+ return 0;
65403+#endif
65404+ return 0;
65405+}
65406diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
65407new file mode 100644
65408index 0000000..a3b12a0
65409--- /dev/null
65410+++ b/grsecurity/grsec_pax.c
65411@@ -0,0 +1,36 @@
65412+#include <linux/kernel.h>
65413+#include <linux/sched.h>
65414+#include <linux/mm.h>
65415+#include <linux/file.h>
65416+#include <linux/grinternal.h>
65417+#include <linux/grsecurity.h>
65418+
65419+void
65420+gr_log_textrel(struct vm_area_struct * vma)
65421+{
65422+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65423+ if (grsec_enable_audit_textrel)
65424+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
65425+#endif
65426+ return;
65427+}
65428+
65429+void
65430+gr_log_rwxmmap(struct file *file)
65431+{
65432+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65433+ if (grsec_enable_log_rwxmaps)
65434+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
65435+#endif
65436+ return;
65437+}
65438+
65439+void
65440+gr_log_rwxmprotect(struct file *file)
65441+{
65442+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65443+ if (grsec_enable_log_rwxmaps)
65444+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
65445+#endif
65446+ return;
65447+}
65448diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
65449new file mode 100644
65450index 0000000..f7f29aa
65451--- /dev/null
65452+++ b/grsecurity/grsec_ptrace.c
65453@@ -0,0 +1,30 @@
65454+#include <linux/kernel.h>
65455+#include <linux/sched.h>
65456+#include <linux/grinternal.h>
65457+#include <linux/security.h>
65458+
65459+void
65460+gr_audit_ptrace(struct task_struct *task)
65461+{
65462+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65463+ if (grsec_enable_audit_ptrace)
65464+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
65465+#endif
65466+ return;
65467+}
65468+
65469+int
65470+gr_ptrace_readexec(struct file *file, int unsafe_flags)
65471+{
65472+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65473+ const struct dentry *dentry = file->f_path.dentry;
65474+ const struct vfsmount *mnt = file->f_path.mnt;
65475+
65476+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
65477+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
65478+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
65479+ return -EACCES;
65480+ }
65481+#endif
65482+ return 0;
65483+}
65484diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
65485new file mode 100644
65486index 0000000..e09715a
65487--- /dev/null
65488+++ b/grsecurity/grsec_sig.c
65489@@ -0,0 +1,222 @@
65490+#include <linux/kernel.h>
65491+#include <linux/sched.h>
65492+#include <linux/delay.h>
65493+#include <linux/grsecurity.h>
65494+#include <linux/grinternal.h>
65495+#include <linux/hardirq.h>
65496+
65497+char *signames[] = {
65498+ [SIGSEGV] = "Segmentation fault",
65499+ [SIGILL] = "Illegal instruction",
65500+ [SIGABRT] = "Abort",
65501+ [SIGBUS] = "Invalid alignment/Bus error"
65502+};
65503+
65504+void
65505+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
65506+{
65507+#ifdef CONFIG_GRKERNSEC_SIGNAL
65508+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
65509+ (sig == SIGABRT) || (sig == SIGBUS))) {
65510+ if (task_pid_nr(t) == task_pid_nr(current)) {
65511+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
65512+ } else {
65513+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
65514+ }
65515+ }
65516+#endif
65517+ return;
65518+}
65519+
65520+int
65521+gr_handle_signal(const struct task_struct *p, const int sig)
65522+{
65523+#ifdef CONFIG_GRKERNSEC
65524+ /* ignore the 0 signal for protected task checks */
65525+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
65526+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
65527+ return -EPERM;
65528+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
65529+ return -EPERM;
65530+ }
65531+#endif
65532+ return 0;
65533+}
65534+
65535+#ifdef CONFIG_GRKERNSEC
65536+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
65537+
65538+int gr_fake_force_sig(int sig, struct task_struct *t)
65539+{
65540+ unsigned long int flags;
65541+ int ret, blocked, ignored;
65542+ struct k_sigaction *action;
65543+
65544+ spin_lock_irqsave(&t->sighand->siglock, flags);
65545+ action = &t->sighand->action[sig-1];
65546+ ignored = action->sa.sa_handler == SIG_IGN;
65547+ blocked = sigismember(&t->blocked, sig);
65548+ if (blocked || ignored) {
65549+ action->sa.sa_handler = SIG_DFL;
65550+ if (blocked) {
65551+ sigdelset(&t->blocked, sig);
65552+ recalc_sigpending_and_wake(t);
65553+ }
65554+ }
65555+ if (action->sa.sa_handler == SIG_DFL)
65556+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
65557+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
65558+
65559+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
65560+
65561+ return ret;
65562+}
65563+#endif
65564+
65565+#ifdef CONFIG_GRKERNSEC_BRUTE
65566+#define GR_USER_BAN_TIME (15 * 60)
65567+#define GR_DAEMON_BRUTE_TIME (30 * 60)
65568+
65569+static int __get_dumpable(unsigned long mm_flags)
65570+{
65571+ int ret;
65572+
65573+ ret = mm_flags & MMF_DUMPABLE_MASK;
65574+ return (ret >= 2) ? 2 : ret;
65575+}
65576+#endif
65577+
65578+void gr_handle_brute_attach(unsigned long mm_flags)
65579+{
65580+#ifdef CONFIG_GRKERNSEC_BRUTE
65581+ struct task_struct *p = current;
65582+ kuid_t uid = GLOBAL_ROOT_UID;
65583+ int daemon = 0;
65584+
65585+ if (!grsec_enable_brute)
65586+ return;
65587+
65588+ rcu_read_lock();
65589+ read_lock(&tasklist_lock);
65590+ read_lock(&grsec_exec_file_lock);
65591+ if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
65592+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
65593+ p->real_parent->brute = 1;
65594+ daemon = 1;
65595+ } else {
65596+ const struct cred *cred = __task_cred(p), *cred2;
65597+ struct task_struct *tsk, *tsk2;
65598+
65599+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
65600+ struct user_struct *user;
65601+
65602+ uid = cred->uid;
65603+
65604+ /* this is put upon execution past expiration */
65605+ user = find_user(uid);
65606+ if (user == NULL)
65607+ goto unlock;
65608+ user->banned = 1;
65609+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
65610+ if (user->ban_expires == ~0UL)
65611+ user->ban_expires--;
65612+
65613+ do_each_thread(tsk2, tsk) {
65614+ cred2 = __task_cred(tsk);
65615+ if (tsk != p && uid_eq(cred2->uid, uid))
65616+ gr_fake_force_sig(SIGKILL, tsk);
65617+ } while_each_thread(tsk2, tsk);
65618+ }
65619+ }
65620+unlock:
65621+ read_unlock(&grsec_exec_file_lock);
65622+ read_unlock(&tasklist_lock);
65623+ rcu_read_unlock();
65624+
65625+ if (gr_is_global_nonroot(uid))
65626+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
65627+ GR_GLOBAL_UID(uid), GR_USER_BAN_TIME / 60);
65628+ else if (daemon)
65629+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
65630+
65631+#endif
65632+ return;
65633+}
65634+
65635+void gr_handle_brute_check(void)
65636+{
65637+#ifdef CONFIG_GRKERNSEC_BRUTE
65638+ struct task_struct *p = current;
65639+
65640+ if (unlikely(p->brute)) {
65641+ if (!grsec_enable_brute)
65642+ p->brute = 0;
65643+ else if (time_before(get_seconds(), p->brute_expires))
65644+ msleep(30 * 1000);
65645+ }
65646+#endif
65647+ return;
65648+}
65649+
65650+void gr_handle_kernel_exploit(void)
65651+{
65652+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
65653+ const struct cred *cred;
65654+ struct task_struct *tsk, *tsk2;
65655+ struct user_struct *user;
65656+ kuid_t uid;
65657+
65658+ if (in_irq() || in_serving_softirq() || in_nmi())
65659+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
65660+
65661+ uid = current_uid();
65662+
65663+ if (gr_is_global_root(uid))
65664+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
65665+ else {
65666+ /* kill all the processes of this user, hold a reference
65667+ to their creds struct, and prevent them from creating
65668+ another process until system reset
65669+ */
65670+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
65671+ GR_GLOBAL_UID(uid));
65672+ /* we intentionally leak this ref */
65673+ user = get_uid(current->cred->user);
65674+ if (user) {
65675+ user->banned = 1;
65676+ user->ban_expires = ~0UL;
65677+ }
65678+
65679+ read_lock(&tasklist_lock);
65680+ do_each_thread(tsk2, tsk) {
65681+ cred = __task_cred(tsk);
65682+ if (uid_eq(cred->uid, uid))
65683+ gr_fake_force_sig(SIGKILL, tsk);
65684+ } while_each_thread(tsk2, tsk);
65685+ read_unlock(&tasklist_lock);
65686+ }
65687+#endif
65688+}
65689+
65690+int __gr_process_user_ban(struct user_struct *user)
65691+{
65692+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
65693+ if (unlikely(user->banned)) {
65694+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
65695+ user->banned = 0;
65696+ user->ban_expires = 0;
65697+ free_uid(user);
65698+ } else
65699+ return -EPERM;
65700+ }
65701+#endif
65702+ return 0;
65703+}
65704+
65705+int gr_process_user_ban(void)
65706+{
65707+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
65708+ return __gr_process_user_ban(current->cred->user);
65709+#endif
65710+ return 0;
65711+}
65712diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
65713new file mode 100644
65714index 0000000..4030d57
65715--- /dev/null
65716+++ b/grsecurity/grsec_sock.c
65717@@ -0,0 +1,244 @@
65718+#include <linux/kernel.h>
65719+#include <linux/module.h>
65720+#include <linux/sched.h>
65721+#include <linux/file.h>
65722+#include <linux/net.h>
65723+#include <linux/in.h>
65724+#include <linux/ip.h>
65725+#include <net/sock.h>
65726+#include <net/inet_sock.h>
65727+#include <linux/grsecurity.h>
65728+#include <linux/grinternal.h>
65729+#include <linux/gracl.h>
65730+
65731+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
65732+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
65733+
65734+EXPORT_SYMBOL(gr_search_udp_recvmsg);
65735+EXPORT_SYMBOL(gr_search_udp_sendmsg);
65736+
65737+#ifdef CONFIG_UNIX_MODULE
65738+EXPORT_SYMBOL(gr_acl_handle_unix);
65739+EXPORT_SYMBOL(gr_acl_handle_mknod);
65740+EXPORT_SYMBOL(gr_handle_chroot_unix);
65741+EXPORT_SYMBOL(gr_handle_create);
65742+#endif
65743+
65744+#ifdef CONFIG_GRKERNSEC
65745+#define gr_conn_table_size 32749
65746+struct conn_table_entry {
65747+ struct conn_table_entry *next;
65748+ struct signal_struct *sig;
65749+};
65750+
65751+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
65752+DEFINE_SPINLOCK(gr_conn_table_lock);
65753+
65754+extern const char * gr_socktype_to_name(unsigned char type);
65755+extern const char * gr_proto_to_name(unsigned char proto);
65756+extern const char * gr_sockfamily_to_name(unsigned char family);
65757+
65758+static __inline__ int
65759+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
65760+{
65761+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
65762+}
65763+
65764+static __inline__ int
65765+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
65766+ __u16 sport, __u16 dport)
65767+{
65768+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
65769+ sig->gr_sport == sport && sig->gr_dport == dport))
65770+ return 1;
65771+ else
65772+ return 0;
65773+}
65774+
65775+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
65776+{
65777+ struct conn_table_entry **match;
65778+ unsigned int index;
65779+
65780+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
65781+ sig->gr_sport, sig->gr_dport,
65782+ gr_conn_table_size);
65783+
65784+ newent->sig = sig;
65785+
65786+ match = &gr_conn_table[index];
65787+ newent->next = *match;
65788+ *match = newent;
65789+
65790+ return;
65791+}
65792+
65793+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
65794+{
65795+ struct conn_table_entry *match, *last = NULL;
65796+ unsigned int index;
65797+
65798+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
65799+ sig->gr_sport, sig->gr_dport,
65800+ gr_conn_table_size);
65801+
65802+ match = gr_conn_table[index];
65803+ while (match && !conn_match(match->sig,
65804+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
65805+ sig->gr_dport)) {
65806+ last = match;
65807+ match = match->next;
65808+ }
65809+
65810+ if (match) {
65811+ if (last)
65812+ last->next = match->next;
65813+ else
65814+ gr_conn_table[index] = NULL;
65815+ kfree(match);
65816+ }
65817+
65818+ return;
65819+}
65820+
65821+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
65822+ __u16 sport, __u16 dport)
65823+{
65824+ struct conn_table_entry *match;
65825+ unsigned int index;
65826+
65827+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
65828+
65829+ match = gr_conn_table[index];
65830+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
65831+ match = match->next;
65832+
65833+ if (match)
65834+ return match->sig;
65835+ else
65836+ return NULL;
65837+}
65838+
65839+#endif
65840+
65841+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
65842+{
65843+#ifdef CONFIG_GRKERNSEC
65844+ struct signal_struct *sig = task->signal;
65845+ struct conn_table_entry *newent;
65846+
65847+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
65848+ if (newent == NULL)
65849+ return;
65850+ /* no bh lock needed since we are called with bh disabled */
65851+ spin_lock(&gr_conn_table_lock);
65852+ gr_del_task_from_ip_table_nolock(sig);
65853+ sig->gr_saddr = inet->inet_rcv_saddr;
65854+ sig->gr_daddr = inet->inet_daddr;
65855+ sig->gr_sport = inet->inet_sport;
65856+ sig->gr_dport = inet->inet_dport;
65857+ gr_add_to_task_ip_table_nolock(sig, newent);
65858+ spin_unlock(&gr_conn_table_lock);
65859+#endif
65860+ return;
65861+}
65862+
65863+void gr_del_task_from_ip_table(struct task_struct *task)
65864+{
65865+#ifdef CONFIG_GRKERNSEC
65866+ spin_lock_bh(&gr_conn_table_lock);
65867+ gr_del_task_from_ip_table_nolock(task->signal);
65868+ spin_unlock_bh(&gr_conn_table_lock);
65869+#endif
65870+ return;
65871+}
65872+
65873+void
65874+gr_attach_curr_ip(const struct sock *sk)
65875+{
65876+#ifdef CONFIG_GRKERNSEC
65877+ struct signal_struct *p, *set;
65878+ const struct inet_sock *inet = inet_sk(sk);
65879+
65880+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
65881+ return;
65882+
65883+ set = current->signal;
65884+
65885+ spin_lock_bh(&gr_conn_table_lock);
65886+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
65887+ inet->inet_dport, inet->inet_sport);
65888+ if (unlikely(p != NULL)) {
65889+ set->curr_ip = p->curr_ip;
65890+ set->used_accept = 1;
65891+ gr_del_task_from_ip_table_nolock(p);
65892+ spin_unlock_bh(&gr_conn_table_lock);
65893+ return;
65894+ }
65895+ spin_unlock_bh(&gr_conn_table_lock);
65896+
65897+ set->curr_ip = inet->inet_daddr;
65898+ set->used_accept = 1;
65899+#endif
65900+ return;
65901+}
65902+
65903+int
65904+gr_handle_sock_all(const int family, const int type, const int protocol)
65905+{
65906+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65907+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
65908+ (family != AF_UNIX)) {
65909+ if (family == AF_INET)
65910+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
65911+ else
65912+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
65913+ return -EACCES;
65914+ }
65915+#endif
65916+ return 0;
65917+}
65918+
65919+int
65920+gr_handle_sock_server(const struct sockaddr *sck)
65921+{
65922+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65923+ if (grsec_enable_socket_server &&
65924+ in_group_p(grsec_socket_server_gid) &&
65925+ sck && (sck->sa_family != AF_UNIX) &&
65926+ (sck->sa_family != AF_LOCAL)) {
65927+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
65928+ return -EACCES;
65929+ }
65930+#endif
65931+ return 0;
65932+}
65933+
65934+int
65935+gr_handle_sock_server_other(const struct sock *sck)
65936+{
65937+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65938+ if (grsec_enable_socket_server &&
65939+ in_group_p(grsec_socket_server_gid) &&
65940+ sck && (sck->sk_family != AF_UNIX) &&
65941+ (sck->sk_family != AF_LOCAL)) {
65942+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
65943+ return -EACCES;
65944+ }
65945+#endif
65946+ return 0;
65947+}
65948+
65949+int
65950+gr_handle_sock_client(const struct sockaddr *sck)
65951+{
65952+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65953+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
65954+ sck && (sck->sa_family != AF_UNIX) &&
65955+ (sck->sa_family != AF_LOCAL)) {
65956+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
65957+ return -EACCES;
65958+ }
65959+#endif
65960+ return 0;
65961+}
65962diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
65963new file mode 100644
65964index 0000000..f55ef0f
65965--- /dev/null
65966+++ b/grsecurity/grsec_sysctl.c
65967@@ -0,0 +1,469 @@
65968+#include <linux/kernel.h>
65969+#include <linux/sched.h>
65970+#include <linux/sysctl.h>
65971+#include <linux/grsecurity.h>
65972+#include <linux/grinternal.h>
65973+
65974+int
65975+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
65976+{
65977+#ifdef CONFIG_GRKERNSEC_SYSCTL
65978+ if (dirname == NULL || name == NULL)
65979+ return 0;
65980+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
65981+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
65982+ return -EACCES;
65983+ }
65984+#endif
65985+ return 0;
65986+}
65987+
65988+#ifdef CONFIG_GRKERNSEC_ROFS
65989+static int __maybe_unused one = 1;
65990+#endif
65991+
65992+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
65993+struct ctl_table grsecurity_table[] = {
65994+#ifdef CONFIG_GRKERNSEC_SYSCTL
65995+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
65996+#ifdef CONFIG_GRKERNSEC_IO
65997+ {
65998+ .procname = "disable_priv_io",
65999+ .data = &grsec_disable_privio,
66000+ .maxlen = sizeof(int),
66001+ .mode = 0600,
66002+ .proc_handler = &proc_dointvec,
66003+ },
66004+#endif
66005+#endif
66006+#ifdef CONFIG_GRKERNSEC_LINK
66007+ {
66008+ .procname = "linking_restrictions",
66009+ .data = &grsec_enable_link,
66010+ .maxlen = sizeof(int),
66011+ .mode = 0600,
66012+ .proc_handler = &proc_dointvec,
66013+ },
66014+#endif
66015+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
66016+ {
66017+ .procname = "enforce_symlinksifowner",
66018+ .data = &grsec_enable_symlinkown,
66019+ .maxlen = sizeof(int),
66020+ .mode = 0600,
66021+ .proc_handler = &proc_dointvec,
66022+ },
66023+ {
66024+ .procname = "symlinkown_gid",
66025+ .data = &grsec_symlinkown_gid,
66026+ .maxlen = sizeof(int),
66027+ .mode = 0600,
66028+ .proc_handler = &proc_dointvec,
66029+ },
66030+#endif
66031+#ifdef CONFIG_GRKERNSEC_BRUTE
66032+ {
66033+ .procname = "deter_bruteforce",
66034+ .data = &grsec_enable_brute,
66035+ .maxlen = sizeof(int),
66036+ .mode = 0600,
66037+ .proc_handler = &proc_dointvec,
66038+ },
66039+#endif
66040+#ifdef CONFIG_GRKERNSEC_FIFO
66041+ {
66042+ .procname = "fifo_restrictions",
66043+ .data = &grsec_enable_fifo,
66044+ .maxlen = sizeof(int),
66045+ .mode = 0600,
66046+ .proc_handler = &proc_dointvec,
66047+ },
66048+#endif
66049+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
66050+ {
66051+ .procname = "ptrace_readexec",
66052+ .data = &grsec_enable_ptrace_readexec,
66053+ .maxlen = sizeof(int),
66054+ .mode = 0600,
66055+ .proc_handler = &proc_dointvec,
66056+ },
66057+#endif
66058+#ifdef CONFIG_GRKERNSEC_SETXID
66059+ {
66060+ .procname = "consistent_setxid",
66061+ .data = &grsec_enable_setxid,
66062+ .maxlen = sizeof(int),
66063+ .mode = 0600,
66064+ .proc_handler = &proc_dointvec,
66065+ },
66066+#endif
66067+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
66068+ {
66069+ .procname = "ip_blackhole",
66070+ .data = &grsec_enable_blackhole,
66071+ .maxlen = sizeof(int),
66072+ .mode = 0600,
66073+ .proc_handler = &proc_dointvec,
66074+ },
66075+ {
66076+ .procname = "lastack_retries",
66077+ .data = &grsec_lastack_retries,
66078+ .maxlen = sizeof(int),
66079+ .mode = 0600,
66080+ .proc_handler = &proc_dointvec,
66081+ },
66082+#endif
66083+#ifdef CONFIG_GRKERNSEC_EXECLOG
66084+ {
66085+ .procname = "exec_logging",
66086+ .data = &grsec_enable_execlog,
66087+ .maxlen = sizeof(int),
66088+ .mode = 0600,
66089+ .proc_handler = &proc_dointvec,
66090+ },
66091+#endif
66092+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
66093+ {
66094+ .procname = "rwxmap_logging",
66095+ .data = &grsec_enable_log_rwxmaps,
66096+ .maxlen = sizeof(int),
66097+ .mode = 0600,
66098+ .proc_handler = &proc_dointvec,
66099+ },
66100+#endif
66101+#ifdef CONFIG_GRKERNSEC_SIGNAL
66102+ {
66103+ .procname = "signal_logging",
66104+ .data = &grsec_enable_signal,
66105+ .maxlen = sizeof(int),
66106+ .mode = 0600,
66107+ .proc_handler = &proc_dointvec,
66108+ },
66109+#endif
66110+#ifdef CONFIG_GRKERNSEC_FORKFAIL
66111+ {
66112+ .procname = "forkfail_logging",
66113+ .data = &grsec_enable_forkfail,
66114+ .maxlen = sizeof(int),
66115+ .mode = 0600,
66116+ .proc_handler = &proc_dointvec,
66117+ },
66118+#endif
66119+#ifdef CONFIG_GRKERNSEC_TIME
66120+ {
66121+ .procname = "timechange_logging",
66122+ .data = &grsec_enable_time,
66123+ .maxlen = sizeof(int),
66124+ .mode = 0600,
66125+ .proc_handler = &proc_dointvec,
66126+ },
66127+#endif
66128+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
66129+ {
66130+ .procname = "chroot_deny_shmat",
66131+ .data = &grsec_enable_chroot_shmat,
66132+ .maxlen = sizeof(int),
66133+ .mode = 0600,
66134+ .proc_handler = &proc_dointvec,
66135+ },
66136+#endif
66137+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
66138+ {
66139+ .procname = "chroot_deny_unix",
66140+ .data = &grsec_enable_chroot_unix,
66141+ .maxlen = sizeof(int),
66142+ .mode = 0600,
66143+ .proc_handler = &proc_dointvec,
66144+ },
66145+#endif
66146+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
66147+ {
66148+ .procname = "chroot_deny_mount",
66149+ .data = &grsec_enable_chroot_mount,
66150+ .maxlen = sizeof(int),
66151+ .mode = 0600,
66152+ .proc_handler = &proc_dointvec,
66153+ },
66154+#endif
66155+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
66156+ {
66157+ .procname = "chroot_deny_fchdir",
66158+ .data = &grsec_enable_chroot_fchdir,
66159+ .maxlen = sizeof(int),
66160+ .mode = 0600,
66161+ .proc_handler = &proc_dointvec,
66162+ },
66163+#endif
66164+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
66165+ {
66166+ .procname = "chroot_deny_chroot",
66167+ .data = &grsec_enable_chroot_double,
66168+ .maxlen = sizeof(int),
66169+ .mode = 0600,
66170+ .proc_handler = &proc_dointvec,
66171+ },
66172+#endif
66173+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
66174+ {
66175+ .procname = "chroot_deny_pivot",
66176+ .data = &grsec_enable_chroot_pivot,
66177+ .maxlen = sizeof(int),
66178+ .mode = 0600,
66179+ .proc_handler = &proc_dointvec,
66180+ },
66181+#endif
66182+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
66183+ {
66184+ .procname = "chroot_enforce_chdir",
66185+ .data = &grsec_enable_chroot_chdir,
66186+ .maxlen = sizeof(int),
66187+ .mode = 0600,
66188+ .proc_handler = &proc_dointvec,
66189+ },
66190+#endif
66191+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
66192+ {
66193+ .procname = "chroot_deny_chmod",
66194+ .data = &grsec_enable_chroot_chmod,
66195+ .maxlen = sizeof(int),
66196+ .mode = 0600,
66197+ .proc_handler = &proc_dointvec,
66198+ },
66199+#endif
66200+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
66201+ {
66202+ .procname = "chroot_deny_mknod",
66203+ .data = &grsec_enable_chroot_mknod,
66204+ .maxlen = sizeof(int),
66205+ .mode = 0600,
66206+ .proc_handler = &proc_dointvec,
66207+ },
66208+#endif
66209+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
66210+ {
66211+ .procname = "chroot_restrict_nice",
66212+ .data = &grsec_enable_chroot_nice,
66213+ .maxlen = sizeof(int),
66214+ .mode = 0600,
66215+ .proc_handler = &proc_dointvec,
66216+ },
66217+#endif
66218+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
66219+ {
66220+ .procname = "chroot_execlog",
66221+ .data = &grsec_enable_chroot_execlog,
66222+ .maxlen = sizeof(int),
66223+ .mode = 0600,
66224+ .proc_handler = &proc_dointvec,
66225+ },
66226+#endif
66227+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66228+ {
66229+ .procname = "chroot_caps",
66230+ .data = &grsec_enable_chroot_caps,
66231+ .maxlen = sizeof(int),
66232+ .mode = 0600,
66233+ .proc_handler = &proc_dointvec,
66234+ },
66235+#endif
66236+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
66237+ {
66238+ .procname = "chroot_deny_sysctl",
66239+ .data = &grsec_enable_chroot_sysctl,
66240+ .maxlen = sizeof(int),
66241+ .mode = 0600,
66242+ .proc_handler = &proc_dointvec,
66243+ },
66244+#endif
66245+#ifdef CONFIG_GRKERNSEC_TPE
66246+ {
66247+ .procname = "tpe",
66248+ .data = &grsec_enable_tpe,
66249+ .maxlen = sizeof(int),
66250+ .mode = 0600,
66251+ .proc_handler = &proc_dointvec,
66252+ },
66253+ {
66254+ .procname = "tpe_gid",
66255+ .data = &grsec_tpe_gid,
66256+ .maxlen = sizeof(int),
66257+ .mode = 0600,
66258+ .proc_handler = &proc_dointvec,
66259+ },
66260+#endif
66261+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
66262+ {
66263+ .procname = "tpe_invert",
66264+ .data = &grsec_enable_tpe_invert,
66265+ .maxlen = sizeof(int),
66266+ .mode = 0600,
66267+ .proc_handler = &proc_dointvec,
66268+ },
66269+#endif
66270+#ifdef CONFIG_GRKERNSEC_TPE_ALL
66271+ {
66272+ .procname = "tpe_restrict_all",
66273+ .data = &grsec_enable_tpe_all,
66274+ .maxlen = sizeof(int),
66275+ .mode = 0600,
66276+ .proc_handler = &proc_dointvec,
66277+ },
66278+#endif
66279+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
66280+ {
66281+ .procname = "socket_all",
66282+ .data = &grsec_enable_socket_all,
66283+ .maxlen = sizeof(int),
66284+ .mode = 0600,
66285+ .proc_handler = &proc_dointvec,
66286+ },
66287+ {
66288+ .procname = "socket_all_gid",
66289+ .data = &grsec_socket_all_gid,
66290+ .maxlen = sizeof(int),
66291+ .mode = 0600,
66292+ .proc_handler = &proc_dointvec,
66293+ },
66294+#endif
66295+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
66296+ {
66297+ .procname = "socket_client",
66298+ .data = &grsec_enable_socket_client,
66299+ .maxlen = sizeof(int),
66300+ .mode = 0600,
66301+ .proc_handler = &proc_dointvec,
66302+ },
66303+ {
66304+ .procname = "socket_client_gid",
66305+ .data = &grsec_socket_client_gid,
66306+ .maxlen = sizeof(int),
66307+ .mode = 0600,
66308+ .proc_handler = &proc_dointvec,
66309+ },
66310+#endif
66311+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66312+ {
66313+ .procname = "socket_server",
66314+ .data = &grsec_enable_socket_server,
66315+ .maxlen = sizeof(int),
66316+ .mode = 0600,
66317+ .proc_handler = &proc_dointvec,
66318+ },
66319+ {
66320+ .procname = "socket_server_gid",
66321+ .data = &grsec_socket_server_gid,
66322+ .maxlen = sizeof(int),
66323+ .mode = 0600,
66324+ .proc_handler = &proc_dointvec,
66325+ },
66326+#endif
66327+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
66328+ {
66329+ .procname = "audit_group",
66330+ .data = &grsec_enable_group,
66331+ .maxlen = sizeof(int),
66332+ .mode = 0600,
66333+ .proc_handler = &proc_dointvec,
66334+ },
66335+ {
66336+ .procname = "audit_gid",
66337+ .data = &grsec_audit_gid,
66338+ .maxlen = sizeof(int),
66339+ .mode = 0600,
66340+ .proc_handler = &proc_dointvec,
66341+ },
66342+#endif
66343+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
66344+ {
66345+ .procname = "audit_chdir",
66346+ .data = &grsec_enable_chdir,
66347+ .maxlen = sizeof(int),
66348+ .mode = 0600,
66349+ .proc_handler = &proc_dointvec,
66350+ },
66351+#endif
66352+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
66353+ {
66354+ .procname = "audit_mount",
66355+ .data = &grsec_enable_mount,
66356+ .maxlen = sizeof(int),
66357+ .mode = 0600,
66358+ .proc_handler = &proc_dointvec,
66359+ },
66360+#endif
66361+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
66362+ {
66363+ .procname = "audit_textrel",
66364+ .data = &grsec_enable_audit_textrel,
66365+ .maxlen = sizeof(int),
66366+ .mode = 0600,
66367+ .proc_handler = &proc_dointvec,
66368+ },
66369+#endif
66370+#ifdef CONFIG_GRKERNSEC_DMESG
66371+ {
66372+ .procname = "dmesg",
66373+ .data = &grsec_enable_dmesg,
66374+ .maxlen = sizeof(int),
66375+ .mode = 0600,
66376+ .proc_handler = &proc_dointvec,
66377+ },
66378+#endif
66379+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
66380+ {
66381+ .procname = "chroot_findtask",
66382+ .data = &grsec_enable_chroot_findtask,
66383+ .maxlen = sizeof(int),
66384+ .mode = 0600,
66385+ .proc_handler = &proc_dointvec,
66386+ },
66387+#endif
66388+#ifdef CONFIG_GRKERNSEC_RESLOG
66389+ {
66390+ .procname = "resource_logging",
66391+ .data = &grsec_resource_logging,
66392+ .maxlen = sizeof(int),
66393+ .mode = 0600,
66394+ .proc_handler = &proc_dointvec,
66395+ },
66396+#endif
66397+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
66398+ {
66399+ .procname = "audit_ptrace",
66400+ .data = &grsec_enable_audit_ptrace,
66401+ .maxlen = sizeof(int),
66402+ .mode = 0600,
66403+ .proc_handler = &proc_dointvec,
66404+ },
66405+#endif
66406+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
66407+ {
66408+ .procname = "harden_ptrace",
66409+ .data = &grsec_enable_harden_ptrace,
66410+ .maxlen = sizeof(int),
66411+ .mode = 0600,
66412+ .proc_handler = &proc_dointvec,
66413+ },
66414+#endif
66415+ {
66416+ .procname = "grsec_lock",
66417+ .data = &grsec_lock,
66418+ .maxlen = sizeof(int),
66419+ .mode = 0600,
66420+ .proc_handler = &proc_dointvec,
66421+ },
66422+#endif
66423+#ifdef CONFIG_GRKERNSEC_ROFS
66424+ {
66425+ .procname = "romount_protect",
66426+ .data = &grsec_enable_rofs,
66427+ .maxlen = sizeof(int),
66428+ .mode = 0600,
66429+ .proc_handler = &proc_dointvec_minmax,
66430+ .extra1 = &one,
66431+ .extra2 = &one,
66432+ },
66433+#endif
66434+ { }
66435+};
66436+#endif
66437diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
66438new file mode 100644
66439index 0000000..0dc13c3
66440--- /dev/null
66441+++ b/grsecurity/grsec_time.c
66442@@ -0,0 +1,16 @@
66443+#include <linux/kernel.h>
66444+#include <linux/sched.h>
66445+#include <linux/grinternal.h>
66446+#include <linux/module.h>
66447+
66448+void
66449+gr_log_timechange(void)
66450+{
66451+#ifdef CONFIG_GRKERNSEC_TIME
66452+ if (grsec_enable_time)
66453+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
66454+#endif
66455+ return;
66456+}
66457+
66458+EXPORT_SYMBOL(gr_log_timechange);
66459diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
66460new file mode 100644
66461index 0000000..ee57dcf
66462--- /dev/null
66463+++ b/grsecurity/grsec_tpe.c
66464@@ -0,0 +1,73 @@
66465+#include <linux/kernel.h>
66466+#include <linux/sched.h>
66467+#include <linux/file.h>
66468+#include <linux/fs.h>
66469+#include <linux/grinternal.h>
66470+
66471+extern int gr_acl_tpe_check(void);
66472+
66473+int
66474+gr_tpe_allow(const struct file *file)
66475+{
66476+#ifdef CONFIG_GRKERNSEC
66477+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
66478+ const struct cred *cred = current_cred();
66479+ char *msg = NULL;
66480+ char *msg2 = NULL;
66481+
66482+ // never restrict root
66483+ if (gr_is_global_root(cred->uid))
66484+ return 1;
66485+
66486+ if (grsec_enable_tpe) {
66487+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
66488+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
66489+ msg = "not being in trusted group";
66490+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
66491+ msg = "being in untrusted group";
66492+#else
66493+ if (in_group_p(grsec_tpe_gid))
66494+ msg = "being in untrusted group";
66495+#endif
66496+ }
66497+ if (!msg && gr_acl_tpe_check())
66498+ msg = "being in untrusted role";
66499+
66500+ // not in any affected group/role
66501+ if (!msg)
66502+ goto next_check;
66503+
66504+ if (gr_is_global_nonroot(inode->i_uid))
66505+ msg2 = "file in non-root-owned directory";
66506+ else if (inode->i_mode & S_IWOTH)
66507+ msg2 = "file in world-writable directory";
66508+ else if (inode->i_mode & S_IWGRP)
66509+ msg2 = "file in group-writable directory";
66510+
66511+ if (msg && msg2) {
66512+ char fullmsg[70] = {0};
66513+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
66514+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
66515+ return 0;
66516+ }
66517+ msg = NULL;
66518+next_check:
66519+#ifdef CONFIG_GRKERNSEC_TPE_ALL
66520+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
66521+ return 1;
66522+
66523+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
66524+ msg = "directory not owned by user";
66525+ else if (inode->i_mode & S_IWOTH)
66526+ msg = "file in world-writable directory";
66527+ else if (inode->i_mode & S_IWGRP)
66528+ msg = "file in group-writable directory";
66529+
66530+ if (msg) {
66531+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
66532+ return 0;
66533+ }
66534+#endif
66535+#endif
66536+ return 1;
66537+}
66538diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
66539new file mode 100644
66540index 0000000..9f7b1ac
66541--- /dev/null
66542+++ b/grsecurity/grsum.c
66543@@ -0,0 +1,61 @@
66544+#include <linux/err.h>
66545+#include <linux/kernel.h>
66546+#include <linux/sched.h>
66547+#include <linux/mm.h>
66548+#include <linux/scatterlist.h>
66549+#include <linux/crypto.h>
66550+#include <linux/gracl.h>
66551+
66552+
66553+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
66554+#error "crypto and sha256 must be built into the kernel"
66555+#endif
66556+
66557+int
66558+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
66559+{
66560+ char *p;
66561+ struct crypto_hash *tfm;
66562+ struct hash_desc desc;
66563+ struct scatterlist sg;
66564+ unsigned char temp_sum[GR_SHA_LEN];
66565+ volatile int retval = 0;
66566+ volatile int dummy = 0;
66567+ unsigned int i;
66568+
66569+ sg_init_table(&sg, 1);
66570+
66571+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
66572+ if (IS_ERR(tfm)) {
66573+ /* should never happen, since sha256 should be built in */
66574+ return 1;
66575+ }
66576+
66577+ desc.tfm = tfm;
66578+ desc.flags = 0;
66579+
66580+ crypto_hash_init(&desc);
66581+
66582+ p = salt;
66583+ sg_set_buf(&sg, p, GR_SALT_LEN);
66584+ crypto_hash_update(&desc, &sg, sg.length);
66585+
66586+ p = entry->pw;
66587+ sg_set_buf(&sg, p, strlen(p));
66588+
66589+ crypto_hash_update(&desc, &sg, sg.length);
66590+
66591+ crypto_hash_final(&desc, temp_sum);
66592+
66593+ memset(entry->pw, 0, GR_PW_LEN);
66594+
66595+ for (i = 0; i < GR_SHA_LEN; i++)
66596+ if (sum[i] != temp_sum[i])
66597+ retval = 1;
66598+ else
66599+ dummy = 1; // waste a cycle
66600+
66601+ crypto_free_hash(tfm);
66602+
66603+ return retval;
66604+}
66605diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
66606index 77ff547..181834f 100644
66607--- a/include/asm-generic/4level-fixup.h
66608+++ b/include/asm-generic/4level-fixup.h
66609@@ -13,8 +13,10 @@
66610 #define pmd_alloc(mm, pud, address) \
66611 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
66612 NULL: pmd_offset(pud, address))
66613+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
66614
66615 #define pud_alloc(mm, pgd, address) (pgd)
66616+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
66617 #define pud_offset(pgd, start) (pgd)
66618 #define pud_none(pud) 0
66619 #define pud_bad(pud) 0
66620diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
66621index b7babf0..04ad282 100644
66622--- a/include/asm-generic/atomic-long.h
66623+++ b/include/asm-generic/atomic-long.h
66624@@ -22,6 +22,12 @@
66625
66626 typedef atomic64_t atomic_long_t;
66627
66628+#ifdef CONFIG_PAX_REFCOUNT
66629+typedef atomic64_unchecked_t atomic_long_unchecked_t;
66630+#else
66631+typedef atomic64_t atomic_long_unchecked_t;
66632+#endif
66633+
66634 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
66635
66636 static inline long atomic_long_read(atomic_long_t *l)
66637@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
66638 return (long)atomic64_read(v);
66639 }
66640
66641+#ifdef CONFIG_PAX_REFCOUNT
66642+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
66643+{
66644+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66645+
66646+ return (long)atomic64_read_unchecked(v);
66647+}
66648+#endif
66649+
66650 static inline void atomic_long_set(atomic_long_t *l, long i)
66651 {
66652 atomic64_t *v = (atomic64_t *)l;
66653@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
66654 atomic64_set(v, i);
66655 }
66656
66657+#ifdef CONFIG_PAX_REFCOUNT
66658+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
66659+{
66660+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66661+
66662+ atomic64_set_unchecked(v, i);
66663+}
66664+#endif
66665+
66666 static inline void atomic_long_inc(atomic_long_t *l)
66667 {
66668 atomic64_t *v = (atomic64_t *)l;
66669@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
66670 atomic64_inc(v);
66671 }
66672
66673+#ifdef CONFIG_PAX_REFCOUNT
66674+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
66675+{
66676+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66677+
66678+ atomic64_inc_unchecked(v);
66679+}
66680+#endif
66681+
66682 static inline void atomic_long_dec(atomic_long_t *l)
66683 {
66684 atomic64_t *v = (atomic64_t *)l;
66685@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
66686 atomic64_dec(v);
66687 }
66688
66689+#ifdef CONFIG_PAX_REFCOUNT
66690+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
66691+{
66692+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66693+
66694+ atomic64_dec_unchecked(v);
66695+}
66696+#endif
66697+
66698 static inline void atomic_long_add(long i, atomic_long_t *l)
66699 {
66700 atomic64_t *v = (atomic64_t *)l;
66701@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
66702 atomic64_add(i, v);
66703 }
66704
66705+#ifdef CONFIG_PAX_REFCOUNT
66706+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
66707+{
66708+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66709+
66710+ atomic64_add_unchecked(i, v);
66711+}
66712+#endif
66713+
66714 static inline void atomic_long_sub(long i, atomic_long_t *l)
66715 {
66716 atomic64_t *v = (atomic64_t *)l;
66717@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
66718 atomic64_sub(i, v);
66719 }
66720
66721+#ifdef CONFIG_PAX_REFCOUNT
66722+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
66723+{
66724+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66725+
66726+ atomic64_sub_unchecked(i, v);
66727+}
66728+#endif
66729+
66730 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
66731 {
66732 atomic64_t *v = (atomic64_t *)l;
66733@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
66734 return (long)atomic64_add_return(i, v);
66735 }
66736
66737+#ifdef CONFIG_PAX_REFCOUNT
66738+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
66739+{
66740+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66741+
66742+ return (long)atomic64_add_return_unchecked(i, v);
66743+}
66744+#endif
66745+
66746 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
66747 {
66748 atomic64_t *v = (atomic64_t *)l;
66749@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
66750 return (long)atomic64_inc_return(v);
66751 }
66752
66753+#ifdef CONFIG_PAX_REFCOUNT
66754+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
66755+{
66756+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
66757+
66758+ return (long)atomic64_inc_return_unchecked(v);
66759+}
66760+#endif
66761+
66762 static inline long atomic_long_dec_return(atomic_long_t *l)
66763 {
66764 atomic64_t *v = (atomic64_t *)l;
66765@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
66766
66767 typedef atomic_t atomic_long_t;
66768
66769+#ifdef CONFIG_PAX_REFCOUNT
66770+typedef atomic_unchecked_t atomic_long_unchecked_t;
66771+#else
66772+typedef atomic_t atomic_long_unchecked_t;
66773+#endif
66774+
66775 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
66776 static inline long atomic_long_read(atomic_long_t *l)
66777 {
66778@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
66779 return (long)atomic_read(v);
66780 }
66781
66782+#ifdef CONFIG_PAX_REFCOUNT
66783+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
66784+{
66785+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66786+
66787+ return (long)atomic_read_unchecked(v);
66788+}
66789+#endif
66790+
66791 static inline void atomic_long_set(atomic_long_t *l, long i)
66792 {
66793 atomic_t *v = (atomic_t *)l;
66794@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
66795 atomic_set(v, i);
66796 }
66797
66798+#ifdef CONFIG_PAX_REFCOUNT
66799+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
66800+{
66801+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66802+
66803+ atomic_set_unchecked(v, i);
66804+}
66805+#endif
66806+
66807 static inline void atomic_long_inc(atomic_long_t *l)
66808 {
66809 atomic_t *v = (atomic_t *)l;
66810@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
66811 atomic_inc(v);
66812 }
66813
66814+#ifdef CONFIG_PAX_REFCOUNT
66815+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
66816+{
66817+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66818+
66819+ atomic_inc_unchecked(v);
66820+}
66821+#endif
66822+
66823 static inline void atomic_long_dec(atomic_long_t *l)
66824 {
66825 atomic_t *v = (atomic_t *)l;
66826@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
66827 atomic_dec(v);
66828 }
66829
66830+#ifdef CONFIG_PAX_REFCOUNT
66831+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
66832+{
66833+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66834+
66835+ atomic_dec_unchecked(v);
66836+}
66837+#endif
66838+
66839 static inline void atomic_long_add(long i, atomic_long_t *l)
66840 {
66841 atomic_t *v = (atomic_t *)l;
66842@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
66843 atomic_add(i, v);
66844 }
66845
66846+#ifdef CONFIG_PAX_REFCOUNT
66847+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
66848+{
66849+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66850+
66851+ atomic_add_unchecked(i, v);
66852+}
66853+#endif
66854+
66855 static inline void atomic_long_sub(long i, atomic_long_t *l)
66856 {
66857 atomic_t *v = (atomic_t *)l;
66858@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
66859 atomic_sub(i, v);
66860 }
66861
66862+#ifdef CONFIG_PAX_REFCOUNT
66863+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
66864+{
66865+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66866+
66867+ atomic_sub_unchecked(i, v);
66868+}
66869+#endif
66870+
66871 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
66872 {
66873 atomic_t *v = (atomic_t *)l;
66874@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
66875 return (long)atomic_add_return(i, v);
66876 }
66877
66878+#ifdef CONFIG_PAX_REFCOUNT
66879+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
66880+{
66881+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66882+
66883+ return (long)atomic_add_return_unchecked(i, v);
66884+}
66885+
66886+#endif
66887+
66888 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
66889 {
66890 atomic_t *v = (atomic_t *)l;
66891@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
66892 return (long)atomic_inc_return(v);
66893 }
66894
66895+#ifdef CONFIG_PAX_REFCOUNT
66896+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
66897+{
66898+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
66899+
66900+ return (long)atomic_inc_return_unchecked(v);
66901+}
66902+#endif
66903+
66904 static inline long atomic_long_dec_return(atomic_long_t *l)
66905 {
66906 atomic_t *v = (atomic_t *)l;
66907@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
66908
66909 #endif /* BITS_PER_LONG == 64 */
66910
66911+#ifdef CONFIG_PAX_REFCOUNT
66912+static inline void pax_refcount_needs_these_functions(void)
66913+{
66914+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
66915+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
66916+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
66917+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
66918+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
66919+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
66920+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
66921+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
66922+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
66923+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
66924+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
66925+#ifdef CONFIG_X86
66926+ atomic_clear_mask_unchecked(0, NULL);
66927+ atomic_set_mask_unchecked(0, NULL);
66928+#endif
66929+
66930+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
66931+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
66932+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
66933+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
66934+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
66935+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
66936+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
66937+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
66938+}
66939+#else
66940+#define atomic_read_unchecked(v) atomic_read(v)
66941+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
66942+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
66943+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
66944+#define atomic_inc_unchecked(v) atomic_inc(v)
66945+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
66946+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
66947+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
66948+#define atomic_dec_unchecked(v) atomic_dec(v)
66949+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
66950+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
66951+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
66952+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
66953+
66954+#define atomic_long_read_unchecked(v) atomic_long_read(v)
66955+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
66956+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
66957+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
66958+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
66959+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
66960+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
66961+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
66962+#endif
66963+
66964 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
66965diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
66966index 33bd2de..f31bff97 100644
66967--- a/include/asm-generic/atomic.h
66968+++ b/include/asm-generic/atomic.h
66969@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
66970 * Atomically clears the bits set in @mask from @v
66971 */
66972 #ifndef atomic_clear_mask
66973-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
66974+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
66975 {
66976 unsigned long flags;
66977
66978diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
66979index b18ce4f..2ee2843 100644
66980--- a/include/asm-generic/atomic64.h
66981+++ b/include/asm-generic/atomic64.h
66982@@ -16,6 +16,8 @@ typedef struct {
66983 long long counter;
66984 } atomic64_t;
66985
66986+typedef atomic64_t atomic64_unchecked_t;
66987+
66988 #define ATOMIC64_INIT(i) { (i) }
66989
66990 extern long long atomic64_read(const atomic64_t *v);
66991@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
66992 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
66993 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
66994
66995+#define atomic64_read_unchecked(v) atomic64_read(v)
66996+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
66997+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
66998+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
66999+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
67000+#define atomic64_inc_unchecked(v) atomic64_inc(v)
67001+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
67002+#define atomic64_dec_unchecked(v) atomic64_dec(v)
67003+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
67004+
67005 #endif /* _ASM_GENERIC_ATOMIC64_H */
67006diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
67007index 1bfcfe5..e04c5c9 100644
67008--- a/include/asm-generic/cache.h
67009+++ b/include/asm-generic/cache.h
67010@@ -6,7 +6,7 @@
67011 * cache lines need to provide their own cache.h.
67012 */
67013
67014-#define L1_CACHE_SHIFT 5
67015-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
67016+#define L1_CACHE_SHIFT 5UL
67017+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
67018
67019 #endif /* __ASM_GENERIC_CACHE_H */
67020diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
67021index 0d68a1e..b74a761 100644
67022--- a/include/asm-generic/emergency-restart.h
67023+++ b/include/asm-generic/emergency-restart.h
67024@@ -1,7 +1,7 @@
67025 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
67026 #define _ASM_GENERIC_EMERGENCY_RESTART_H
67027
67028-static inline void machine_emergency_restart(void)
67029+static inline __noreturn void machine_emergency_restart(void)
67030 {
67031 machine_restart(NULL);
67032 }
67033diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
67034index 90f99c7..00ce236 100644
67035--- a/include/asm-generic/kmap_types.h
67036+++ b/include/asm-generic/kmap_types.h
67037@@ -2,9 +2,9 @@
67038 #define _ASM_GENERIC_KMAP_TYPES_H
67039
67040 #ifdef __WITH_KM_FENCE
67041-# define KM_TYPE_NR 41
67042+# define KM_TYPE_NR 42
67043 #else
67044-# define KM_TYPE_NR 20
67045+# define KM_TYPE_NR 21
67046 #endif
67047
67048 #endif
67049diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
67050index 9ceb03b..62b0b8f 100644
67051--- a/include/asm-generic/local.h
67052+++ b/include/asm-generic/local.h
67053@@ -23,24 +23,37 @@ typedef struct
67054 atomic_long_t a;
67055 } local_t;
67056
67057+typedef struct {
67058+ atomic_long_unchecked_t a;
67059+} local_unchecked_t;
67060+
67061 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
67062
67063 #define local_read(l) atomic_long_read(&(l)->a)
67064+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
67065 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
67066+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
67067 #define local_inc(l) atomic_long_inc(&(l)->a)
67068+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
67069 #define local_dec(l) atomic_long_dec(&(l)->a)
67070+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
67071 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
67072+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
67073 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
67074+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
67075
67076 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
67077 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
67078 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
67079 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
67080 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
67081+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
67082 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
67083 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
67084+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
67085
67086 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
67087+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
67088 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
67089 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
67090 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
67091diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
67092index 725612b..9cc513a 100644
67093--- a/include/asm-generic/pgtable-nopmd.h
67094+++ b/include/asm-generic/pgtable-nopmd.h
67095@@ -1,14 +1,19 @@
67096 #ifndef _PGTABLE_NOPMD_H
67097 #define _PGTABLE_NOPMD_H
67098
67099-#ifndef __ASSEMBLY__
67100-
67101 #include <asm-generic/pgtable-nopud.h>
67102
67103-struct mm_struct;
67104-
67105 #define __PAGETABLE_PMD_FOLDED
67106
67107+#define PMD_SHIFT PUD_SHIFT
67108+#define PTRS_PER_PMD 1
67109+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
67110+#define PMD_MASK (~(PMD_SIZE-1))
67111+
67112+#ifndef __ASSEMBLY__
67113+
67114+struct mm_struct;
67115+
67116 /*
67117 * Having the pmd type consist of a pud gets the size right, and allows
67118 * us to conceptually access the pud entry that this pmd is folded into
67119@@ -16,11 +21,6 @@ struct mm_struct;
67120 */
67121 typedef struct { pud_t pud; } pmd_t;
67122
67123-#define PMD_SHIFT PUD_SHIFT
67124-#define PTRS_PER_PMD 1
67125-#define PMD_SIZE (1UL << PMD_SHIFT)
67126-#define PMD_MASK (~(PMD_SIZE-1))
67127-
67128 /*
67129 * The "pud_xxx()" functions here are trivial for a folded two-level
67130 * setup: the pmd is never bad, and a pmd always exists (as it's folded
67131diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
67132index 810431d..0ec4804f 100644
67133--- a/include/asm-generic/pgtable-nopud.h
67134+++ b/include/asm-generic/pgtable-nopud.h
67135@@ -1,10 +1,15 @@
67136 #ifndef _PGTABLE_NOPUD_H
67137 #define _PGTABLE_NOPUD_H
67138
67139-#ifndef __ASSEMBLY__
67140-
67141 #define __PAGETABLE_PUD_FOLDED
67142
67143+#define PUD_SHIFT PGDIR_SHIFT
67144+#define PTRS_PER_PUD 1
67145+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
67146+#define PUD_MASK (~(PUD_SIZE-1))
67147+
67148+#ifndef __ASSEMBLY__
67149+
67150 /*
67151 * Having the pud type consist of a pgd gets the size right, and allows
67152 * us to conceptually access the pgd entry that this pud is folded into
67153@@ -12,11 +17,6 @@
67154 */
67155 typedef struct { pgd_t pgd; } pud_t;
67156
67157-#define PUD_SHIFT PGDIR_SHIFT
67158-#define PTRS_PER_PUD 1
67159-#define PUD_SIZE (1UL << PUD_SHIFT)
67160-#define PUD_MASK (~(PUD_SIZE-1))
67161-
67162 /*
67163 * The "pgd_xxx()" functions here are trivial for a folded two-level
67164 * setup: the pud is never bad, and a pud always exists (as it's folded
67165@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
67166 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
67167
67168 #define pgd_populate(mm, pgd, pud) do { } while (0)
67169+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
67170 /*
67171 * (puds are folded into pgds so this doesn't get actually called,
67172 * but the define is needed for a generic inline function.)
67173diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
67174index a59ff51..2594a70 100644
67175--- a/include/asm-generic/pgtable.h
67176+++ b/include/asm-generic/pgtable.h
67177@@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
67178 }
67179 #endif /* CONFIG_NUMA_BALANCING */
67180
67181+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
67182+static inline unsigned long pax_open_kernel(void) { return 0; }
67183+#endif
67184+
67185+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
67186+static inline unsigned long pax_close_kernel(void) { return 0; }
67187+#endif
67188+
67189 #endif /* CONFIG_MMU */
67190
67191 #endif /* !__ASSEMBLY__ */
67192diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
67193index afa12c7..99d4da0 100644
67194--- a/include/asm-generic/vmlinux.lds.h
67195+++ b/include/asm-generic/vmlinux.lds.h
67196@@ -245,6 +245,7 @@
67197 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
67198 VMLINUX_SYMBOL(__start_rodata) = .; \
67199 *(.rodata) *(.rodata.*) \
67200+ *(.data..read_only) \
67201 *(__vermagic) /* Kernel version magic */ \
67202 . = ALIGN(8); \
67203 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
67204@@ -755,17 +756,18 @@
67205 * section in the linker script will go there too. @phdr should have
67206 * a leading colon.
67207 *
67208- * Note that this macros defines __per_cpu_load as an absolute symbol.
67209+ * Note that this macros defines per_cpu_load as an absolute symbol.
67210 * If there is no need to put the percpu section at a predetermined
67211 * address, use PERCPU_SECTION.
67212 */
67213 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
67214- VMLINUX_SYMBOL(__per_cpu_load) = .; \
67215- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
67216+ per_cpu_load = .; \
67217+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
67218 - LOAD_OFFSET) { \
67219+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
67220 PERCPU_INPUT(cacheline) \
67221 } phdr \
67222- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
67223+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
67224
67225 /**
67226 * PERCPU_SECTION - define output section for percpu area, simple version
67227diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
67228index 418d270..bfd2794 100644
67229--- a/include/crypto/algapi.h
67230+++ b/include/crypto/algapi.h
67231@@ -34,7 +34,7 @@ struct crypto_type {
67232 unsigned int maskclear;
67233 unsigned int maskset;
67234 unsigned int tfmsize;
67235-};
67236+} __do_const;
67237
67238 struct crypto_instance {
67239 struct crypto_alg alg;
67240diff --git a/include/drm/drmP.h b/include/drm/drmP.h
67241index f1ce786..086a7a5 100644
67242--- a/include/drm/drmP.h
67243+++ b/include/drm/drmP.h
67244@@ -72,6 +72,7 @@
67245 #include <linux/workqueue.h>
67246 #include <linux/poll.h>
67247 #include <asm/pgalloc.h>
67248+#include <asm/local.h>
67249 #include <drm/drm.h>
67250 #include <drm/drm_sarea.h>
67251
67252@@ -296,10 +297,12 @@ do { \
67253 * \param cmd command.
67254 * \param arg argument.
67255 */
67256-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
67257+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
67258+ struct drm_file *file_priv);
67259+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
67260 struct drm_file *file_priv);
67261
67262-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
67263+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
67264 unsigned long arg);
67265
67266 #define DRM_IOCTL_NR(n) _IOC_NR(n)
67267@@ -314,9 +317,9 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
67268 struct drm_ioctl_desc {
67269 unsigned int cmd;
67270 int flags;
67271- drm_ioctl_t *func;
67272+ drm_ioctl_t func;
67273 unsigned int cmd_drv;
67274-};
67275+} __do_const;
67276
67277 /**
67278 * Creates a driver or general drm_ioctl_desc array entry for the given
67279@@ -1014,7 +1017,7 @@ struct drm_info_list {
67280 int (*show)(struct seq_file*, void*); /** show callback */
67281 u32 driver_features; /**< Required driver features for this entry */
67282 void *data;
67283-};
67284+} __do_const;
67285
67286 /**
67287 * debugfs node structure. This structure represents a debugfs file.
67288@@ -1087,7 +1090,7 @@ struct drm_device {
67289
67290 /** \name Usage Counters */
67291 /*@{ */
67292- int open_count; /**< Outstanding files open */
67293+ local_t open_count; /**< Outstanding files open */
67294 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
67295 atomic_t vma_count; /**< Outstanding vma areas open */
67296 int buf_use; /**< Buffers in use -- cannot alloc */
67297@@ -1098,7 +1101,7 @@ struct drm_device {
67298 /*@{ */
67299 unsigned long counters;
67300 enum drm_stat_type types[15];
67301- atomic_t counts[15];
67302+ atomic_unchecked_t counts[15];
67303 /*@} */
67304
67305 struct list_head filelist;
67306diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
67307index f43d556..94d9343 100644
67308--- a/include/drm/drm_crtc_helper.h
67309+++ b/include/drm/drm_crtc_helper.h
67310@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
67311 struct drm_connector *connector);
67312 /* disable encoder when not in use - more explicit than dpms off */
67313 void (*disable)(struct drm_encoder *encoder);
67314-};
67315+} __no_const;
67316
67317 /**
67318 * drm_connector_helper_funcs - helper operations for connectors
67319diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
67320index 72dcbe8..8db58d7 100644
67321--- a/include/drm/ttm/ttm_memory.h
67322+++ b/include/drm/ttm/ttm_memory.h
67323@@ -48,7 +48,7 @@
67324
67325 struct ttm_mem_shrink {
67326 int (*do_shrink) (struct ttm_mem_shrink *);
67327-};
67328+} __no_const;
67329
67330 /**
67331 * struct ttm_mem_global - Global memory accounting structure.
67332diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
67333index 4b840e8..155d235 100644
67334--- a/include/keys/asymmetric-subtype.h
67335+++ b/include/keys/asymmetric-subtype.h
67336@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
67337 /* Verify the signature on a key of this subtype (optional) */
67338 int (*verify_signature)(const struct key *key,
67339 const struct public_key_signature *sig);
67340-};
67341+} __do_const;
67342
67343 /**
67344 * asymmetric_key_subtype - Get the subtype from an asymmetric key
67345diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
67346index c1da539..1dcec55 100644
67347--- a/include/linux/atmdev.h
67348+++ b/include/linux/atmdev.h
67349@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
67350 #endif
67351
67352 struct k_atm_aal_stats {
67353-#define __HANDLE_ITEM(i) atomic_t i
67354+#define __HANDLE_ITEM(i) atomic_unchecked_t i
67355 __AAL_STAT_ITEMS
67356 #undef __HANDLE_ITEM
67357 };
67358@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
67359 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
67360 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
67361 struct module *owner;
67362-};
67363+} __do_const ;
67364
67365 struct atmphy_ops {
67366 int (*start)(struct atm_dev *dev);
67367diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
67368index c3a0914..ec5d48a 100644
67369--- a/include/linux/binfmts.h
67370+++ b/include/linux/binfmts.h
67371@@ -73,8 +73,9 @@ struct linux_binfmt {
67372 int (*load_binary)(struct linux_binprm *);
67373 int (*load_shlib)(struct file *);
67374 int (*core_dump)(struct coredump_params *cprm);
67375+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
67376 unsigned long min_coredump; /* minimal dump size */
67377-};
67378+} __do_const;
67379
67380 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
67381
67382diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
67383index 33f358f..7f2c27f 100644
67384--- a/include/linux/blkdev.h
67385+++ b/include/linux/blkdev.h
67386@@ -1499,7 +1499,7 @@ struct block_device_operations {
67387 /* this callback is with swap_lock and sometimes page table lock held */
67388 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
67389 struct module *owner;
67390-};
67391+} __do_const;
67392
67393 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
67394 unsigned long);
67395diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
67396index 7c2e030..b72475d 100644
67397--- a/include/linux/blktrace_api.h
67398+++ b/include/linux/blktrace_api.h
67399@@ -23,7 +23,7 @@ struct blk_trace {
67400 struct dentry *dir;
67401 struct dentry *dropped_file;
67402 struct dentry *msg_file;
67403- atomic_t dropped;
67404+ atomic_unchecked_t dropped;
67405 };
67406
67407 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
67408diff --git a/include/linux/cache.h b/include/linux/cache.h
67409index 4c57065..4307975 100644
67410--- a/include/linux/cache.h
67411+++ b/include/linux/cache.h
67412@@ -16,6 +16,10 @@
67413 #define __read_mostly
67414 #endif
67415
67416+#ifndef __read_only
67417+#define __read_only __read_mostly
67418+#endif
67419+
67420 #ifndef ____cacheline_aligned
67421 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
67422 #endif
67423diff --git a/include/linux/capability.h b/include/linux/capability.h
67424index d9a4f7f4..19f77d6 100644
67425--- a/include/linux/capability.h
67426+++ b/include/linux/capability.h
67427@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
67428 extern bool nsown_capable(int cap);
67429 extern bool inode_capable(const struct inode *inode, int cap);
67430 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
67431+extern bool capable_nolog(int cap);
67432+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
67433+extern bool inode_capable_nolog(const struct inode *inode, int cap);
67434
67435 /* audit system wants to get cap info from files as well */
67436 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
67437
67438+extern int is_privileged_binary(const struct dentry *dentry);
67439+
67440 #endif /* !_LINUX_CAPABILITY_H */
67441diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
67442index 8609d57..86e4d79 100644
67443--- a/include/linux/cdrom.h
67444+++ b/include/linux/cdrom.h
67445@@ -87,7 +87,6 @@ struct cdrom_device_ops {
67446
67447 /* driver specifications */
67448 const int capability; /* capability flags */
67449- int n_minors; /* number of active minor devices */
67450 /* handle uniform packets for scsi type devices (scsi,atapi) */
67451 int (*generic_packet) (struct cdrom_device_info *,
67452 struct packet_command *);
67453diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
67454index 42e55de..1cd0e66 100644
67455--- a/include/linux/cleancache.h
67456+++ b/include/linux/cleancache.h
67457@@ -31,7 +31,7 @@ struct cleancache_ops {
67458 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
67459 void (*invalidate_inode)(int, struct cleancache_filekey);
67460 void (*invalidate_fs)(int);
67461-};
67462+} __no_const;
67463
67464 extern struct cleancache_ops
67465 cleancache_register_ops(struct cleancache_ops *ops);
67466diff --git a/include/linux/compat.h b/include/linux/compat.h
67467index 377cd8c..2479845 100644
67468--- a/include/linux/compat.h
67469+++ b/include/linux/compat.h
67470@@ -332,14 +332,14 @@ long compat_sys_msgsnd(int first, int second, int third, void __user *uptr);
67471 long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
67472 int version, void __user *uptr);
67473 long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
67474- void __user *uptr);
67475+ void __user *uptr) __intentional_overflow(0);
67476 #else
67477 long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
67478 long compat_sys_msgsnd(int msqid, struct compat_msgbuf __user *msgp,
67479 compat_ssize_t msgsz, int msgflg);
67480 long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp,
67481 compat_ssize_t msgsz, long msgtyp, int msgflg);
67482-long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
67483+long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
67484 #endif
67485 long compat_sys_msgctl(int first, int second, void __user *uptr);
67486 long compat_sys_shmctl(int first, int second, void __user *uptr);
67487@@ -442,7 +442,7 @@ extern int compat_ptrace_request(struct task_struct *child,
67488 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
67489 compat_ulong_t addr, compat_ulong_t data);
67490 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
67491- compat_long_t addr, compat_long_t data);
67492+ compat_ulong_t addr, compat_ulong_t data);
67493
67494 /*
67495 * epoll (fs/eventpoll.c) compat bits follow ...
67496diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
67497index 68b162d..660f5f0 100644
67498--- a/include/linux/compiler-gcc4.h
67499+++ b/include/linux/compiler-gcc4.h
67500@@ -39,9 +39,29 @@
67501 # define __compiletime_warning(message) __attribute__((warning(message)))
67502 # define __compiletime_error(message) __attribute__((error(message)))
67503 #endif /* __CHECKER__ */
67504+
67505+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
67506+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
67507+#define __bos0(ptr) __bos((ptr), 0)
67508+#define __bos1(ptr) __bos((ptr), 1)
67509 #endif /* GCC_VERSION >= 40300 */
67510
67511 #if GCC_VERSION >= 40500
67512+
67513+#ifdef CONSTIFY_PLUGIN
67514+#define __no_const __attribute__((no_const))
67515+#define __do_const __attribute__((do_const))
67516+#endif
67517+
67518+#ifdef SIZE_OVERFLOW_PLUGIN
67519+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
67520+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
67521+#endif
67522+
67523+#ifdef LATENT_ENTROPY_PLUGIN
67524+#define __latent_entropy __attribute__((latent_entropy))
67525+#endif
67526+
67527 /*
67528 * Mark a position in code as unreachable. This can be used to
67529 * suppress control flow warnings after asm blocks that transfer
67530diff --git a/include/linux/compiler.h b/include/linux/compiler.h
67531index 10b8f23..5e0b083 100644
67532--- a/include/linux/compiler.h
67533+++ b/include/linux/compiler.h
67534@@ -5,11 +5,14 @@
67535
67536 #ifdef __CHECKER__
67537 # define __user __attribute__((noderef, address_space(1)))
67538+# define __force_user __force __user
67539 # define __kernel __attribute__((address_space(0)))
67540+# define __force_kernel __force __kernel
67541 # define __safe __attribute__((safe))
67542 # define __force __attribute__((force))
67543 # define __nocast __attribute__((nocast))
67544 # define __iomem __attribute__((noderef, address_space(2)))
67545+# define __force_iomem __force __iomem
67546 # define __must_hold(x) __attribute__((context(x,1,1)))
67547 # define __acquires(x) __attribute__((context(x,0,1)))
67548 # define __releases(x) __attribute__((context(x,1,0)))
67549@@ -17,20 +20,37 @@
67550 # define __release(x) __context__(x,-1)
67551 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
67552 # define __percpu __attribute__((noderef, address_space(3)))
67553+# define __force_percpu __force __percpu
67554 #ifdef CONFIG_SPARSE_RCU_POINTER
67555 # define __rcu __attribute__((noderef, address_space(4)))
67556+# define __force_rcu __force __rcu
67557 #else
67558 # define __rcu
67559+# define __force_rcu
67560 #endif
67561 extern void __chk_user_ptr(const volatile void __user *);
67562 extern void __chk_io_ptr(const volatile void __iomem *);
67563 #else
67564-# define __user
67565-# define __kernel
67566+# ifdef CHECKER_PLUGIN
67567+//# define __user
67568+//# define __force_user
67569+//# define __kernel
67570+//# define __force_kernel
67571+# else
67572+# ifdef STRUCTLEAK_PLUGIN
67573+# define __user __attribute__((user))
67574+# else
67575+# define __user
67576+# endif
67577+# define __force_user
67578+# define __kernel
67579+# define __force_kernel
67580+# endif
67581 # define __safe
67582 # define __force
67583 # define __nocast
67584 # define __iomem
67585+# define __force_iomem
67586 # define __chk_user_ptr(x) (void)0
67587 # define __chk_io_ptr(x) (void)0
67588 # define __builtin_warning(x, y...) (1)
67589@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
67590 # define __release(x) (void)0
67591 # define __cond_lock(x,c) (c)
67592 # define __percpu
67593+# define __force_percpu
67594 # define __rcu
67595+# define __force_rcu
67596 #endif
67597
67598 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
67599@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
67600 # define __attribute_const__ /* unimplemented */
67601 #endif
67602
67603+#ifndef __no_const
67604+# define __no_const
67605+#endif
67606+
67607+#ifndef __do_const
67608+# define __do_const
67609+#endif
67610+
67611+#ifndef __size_overflow
67612+# define __size_overflow(...)
67613+#endif
67614+
67615+#ifndef __intentional_overflow
67616+# define __intentional_overflow(...)
67617+#endif
67618+
67619+#ifndef __latent_entropy
67620+# define __latent_entropy
67621+#endif
67622+
67623 /*
67624 * Tell gcc if a function is cold. The compiler will assume any path
67625 * directly leading to the call is unlikely.
67626@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
67627 #define __cold
67628 #endif
67629
67630+#ifndef __alloc_size
67631+#define __alloc_size(...)
67632+#endif
67633+
67634+#ifndef __bos
67635+#define __bos(ptr, arg)
67636+#endif
67637+
67638+#ifndef __bos0
67639+#define __bos0(ptr)
67640+#endif
67641+
67642+#ifndef __bos1
67643+#define __bos1(ptr)
67644+#endif
67645+
67646 /* Simple shorthand for a section definition */
67647 #ifndef __section
67648 # define __section(S) __attribute__ ((__section__(#S)))
67649@@ -349,6 +407,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
67650 * use is to mediate communication between process-level code and irq/NMI
67651 * handlers, all running on the same CPU.
67652 */
67653-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
67654+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
67655+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
67656
67657 #endif /* __LINUX_COMPILER_H */
67658diff --git a/include/linux/completion.h b/include/linux/completion.h
67659index 33f0280..35c6568 100644
67660--- a/include/linux/completion.h
67661+++ b/include/linux/completion.h
67662@@ -79,15 +79,15 @@ static inline void init_completion(struct completion *x)
67663 extern void wait_for_completion(struct completion *);
67664 extern void wait_for_completion_io(struct completion *);
67665 extern int wait_for_completion_interruptible(struct completion *x);
67666-extern int wait_for_completion_killable(struct completion *x);
67667+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
67668 extern unsigned long wait_for_completion_timeout(struct completion *x,
67669 unsigned long timeout);
67670 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
67671 unsigned long timeout);
67672 extern long wait_for_completion_interruptible_timeout(
67673- struct completion *x, unsigned long timeout);
67674+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
67675 extern long wait_for_completion_killable_timeout(
67676- struct completion *x, unsigned long timeout);
67677+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
67678 extern bool try_wait_for_completion(struct completion *x);
67679 extern bool completion_done(struct completion *x);
67680
67681diff --git a/include/linux/configfs.h b/include/linux/configfs.h
67682index 34025df..d94bbbc 100644
67683--- a/include/linux/configfs.h
67684+++ b/include/linux/configfs.h
67685@@ -125,7 +125,7 @@ struct configfs_attribute {
67686 const char *ca_name;
67687 struct module *ca_owner;
67688 umode_t ca_mode;
67689-};
67690+} __do_const;
67691
67692 /*
67693 * Users often need to create attribute structures for their configurable
67694diff --git a/include/linux/cpu.h b/include/linux/cpu.h
67695index ce7a074..01ab8ac 100644
67696--- a/include/linux/cpu.h
67697+++ b/include/linux/cpu.h
67698@@ -115,7 +115,7 @@ enum {
67699 /* Need to know about CPUs going up/down? */
67700 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
67701 #define cpu_notifier(fn, pri) { \
67702- static struct notifier_block fn##_nb __cpuinitdata = \
67703+ static struct notifier_block fn##_nb = \
67704 { .notifier_call = fn, .priority = pri }; \
67705 register_cpu_notifier(&fn##_nb); \
67706 }
67707diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
67708index a22944c..4e695fe 100644
67709--- a/include/linux/cpufreq.h
67710+++ b/include/linux/cpufreq.h
67711@@ -252,7 +252,7 @@ struct cpufreq_driver {
67712 int (*suspend) (struct cpufreq_policy *policy);
67713 int (*resume) (struct cpufreq_policy *policy);
67714 struct freq_attr **attr;
67715-};
67716+} __do_const;
67717
67718 /* flags */
67719
67720@@ -311,6 +311,7 @@ struct global_attr {
67721 ssize_t (*store)(struct kobject *a, struct attribute *b,
67722 const char *c, size_t count);
67723 };
67724+typedef struct global_attr __no_const global_attr_no_const;
67725
67726 #define define_one_global_ro(_name) \
67727 static struct global_attr _name = \
67728diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
67729index 480c14d..552896f 100644
67730--- a/include/linux/cpuidle.h
67731+++ b/include/linux/cpuidle.h
67732@@ -52,7 +52,8 @@ struct cpuidle_state {
67733 int index);
67734
67735 int (*enter_dead) (struct cpuidle_device *dev, int index);
67736-};
67737+} __do_const;
67738+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
67739
67740 /* Idle State Flags */
67741 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
67742@@ -194,7 +195,7 @@ struct cpuidle_governor {
67743 void (*reflect) (struct cpuidle_device *dev, int index);
67744
67745 struct module *owner;
67746-};
67747+} __do_const;
67748
67749 #ifdef CONFIG_CPU_IDLE
67750
67751diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
67752index 0325602..5e9feff 100644
67753--- a/include/linux/cpumask.h
67754+++ b/include/linux/cpumask.h
67755@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
67756 }
67757
67758 /* Valid inputs for n are -1 and 0. */
67759-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
67760+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
67761 {
67762 return n+1;
67763 }
67764
67765-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
67766+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
67767 {
67768 return n+1;
67769 }
67770
67771-static inline unsigned int cpumask_next_and(int n,
67772+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
67773 const struct cpumask *srcp,
67774 const struct cpumask *andp)
67775 {
67776@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
67777 *
67778 * Returns >= nr_cpu_ids if no further cpus set.
67779 */
67780-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
67781+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
67782 {
67783 /* -1 is a legal arg here. */
67784 if (n != -1)
67785@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
67786 *
67787 * Returns >= nr_cpu_ids if no further cpus unset.
67788 */
67789-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
67790+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
67791 {
67792 /* -1 is a legal arg here. */
67793 if (n != -1)
67794@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
67795 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
67796 }
67797
67798-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
67799+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
67800 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
67801
67802 /**
67803diff --git a/include/linux/cred.h b/include/linux/cred.h
67804index 04421e8..6bce4ef 100644
67805--- a/include/linux/cred.h
67806+++ b/include/linux/cred.h
67807@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
67808 static inline void validate_process_creds(void)
67809 {
67810 }
67811+static inline void validate_task_creds(struct task_struct *task)
67812+{
67813+}
67814 #endif
67815
67816 /**
67817diff --git a/include/linux/crypto.h b/include/linux/crypto.h
67818index b92eadf..b4ecdc1 100644
67819--- a/include/linux/crypto.h
67820+++ b/include/linux/crypto.h
67821@@ -373,7 +373,7 @@ struct cipher_tfm {
67822 const u8 *key, unsigned int keylen);
67823 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
67824 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
67825-};
67826+} __no_const;
67827
67828 struct hash_tfm {
67829 int (*init)(struct hash_desc *desc);
67830@@ -394,13 +394,13 @@ struct compress_tfm {
67831 int (*cot_decompress)(struct crypto_tfm *tfm,
67832 const u8 *src, unsigned int slen,
67833 u8 *dst, unsigned int *dlen);
67834-};
67835+} __no_const;
67836
67837 struct rng_tfm {
67838 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
67839 unsigned int dlen);
67840 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
67841-};
67842+} __no_const;
67843
67844 #define crt_ablkcipher crt_u.ablkcipher
67845 #define crt_aead crt_u.aead
67846diff --git a/include/linux/ctype.h b/include/linux/ctype.h
67847index 8acfe31..6ffccd63 100644
67848--- a/include/linux/ctype.h
67849+++ b/include/linux/ctype.h
67850@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
67851 * Fast implementation of tolower() for internal usage. Do not use in your
67852 * code.
67853 */
67854-static inline char _tolower(const char c)
67855+static inline unsigned char _tolower(const unsigned char c)
67856 {
67857 return c | 0x20;
67858 }
67859diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
67860index 7925bf0..d5143d2 100644
67861--- a/include/linux/decompress/mm.h
67862+++ b/include/linux/decompress/mm.h
67863@@ -77,7 +77,7 @@ static void free(void *where)
67864 * warnings when not needed (indeed large_malloc / large_free are not
67865 * needed by inflate */
67866
67867-#define malloc(a) kmalloc(a, GFP_KERNEL)
67868+#define malloc(a) kmalloc((a), GFP_KERNEL)
67869 #define free(a) kfree(a)
67870
67871 #define large_malloc(a) vmalloc(a)
67872diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
67873index fe8c447..bdc1f33 100644
67874--- a/include/linux/devfreq.h
67875+++ b/include/linux/devfreq.h
67876@@ -114,7 +114,7 @@ struct devfreq_governor {
67877 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
67878 int (*event_handler)(struct devfreq *devfreq,
67879 unsigned int event, void *data);
67880-};
67881+} __do_const;
67882
67883 /**
67884 * struct devfreq - Device devfreq structure
67885diff --git a/include/linux/device.h b/include/linux/device.h
67886index 9d6464e..8a5cc92 100644
67887--- a/include/linux/device.h
67888+++ b/include/linux/device.h
67889@@ -295,7 +295,7 @@ struct subsys_interface {
67890 struct list_head node;
67891 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
67892 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
67893-};
67894+} __do_const;
67895
67896 int subsys_interface_register(struct subsys_interface *sif);
67897 void subsys_interface_unregister(struct subsys_interface *sif);
67898@@ -475,7 +475,7 @@ struct device_type {
67899 void (*release)(struct device *dev);
67900
67901 const struct dev_pm_ops *pm;
67902-};
67903+} __do_const;
67904
67905 /* interface for exporting device attributes */
67906 struct device_attribute {
67907@@ -485,11 +485,12 @@ struct device_attribute {
67908 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
67909 const char *buf, size_t count);
67910 };
67911+typedef struct device_attribute __no_const device_attribute_no_const;
67912
67913 struct dev_ext_attribute {
67914 struct device_attribute attr;
67915 void *var;
67916-};
67917+} __do_const;
67918
67919 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
67920 char *buf);
67921diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
67922index 94af418..b1ca7a2 100644
67923--- a/include/linux/dma-mapping.h
67924+++ b/include/linux/dma-mapping.h
67925@@ -54,7 +54,7 @@ struct dma_map_ops {
67926 u64 (*get_required_mask)(struct device *dev);
67927 #endif
67928 int is_phys;
67929-};
67930+} __do_const;
67931
67932 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
67933
67934diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
67935index 91ac8da..a841318 100644
67936--- a/include/linux/dmaengine.h
67937+++ b/include/linux/dmaengine.h
67938@@ -1034,9 +1034,9 @@ struct dma_pinned_list {
67939 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
67940 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
67941
67942-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
67943+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
67944 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
67945-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
67946+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
67947 struct dma_pinned_list *pinned_list, struct page *page,
67948 unsigned int offset, size_t len);
67949
67950diff --git a/include/linux/efi.h b/include/linux/efi.h
67951index 3d7df3d..301f024 100644
67952--- a/include/linux/efi.h
67953+++ b/include/linux/efi.h
67954@@ -740,6 +740,7 @@ struct efivar_operations {
67955 efi_set_variable_t *set_variable;
67956 efi_query_variable_store_t *query_variable_store;
67957 };
67958+typedef struct efivar_operations __no_const efivar_operations_no_const;
67959
67960 struct efivars {
67961 /*
67962diff --git a/include/linux/elf.h b/include/linux/elf.h
67963index 40a3c0e..4c45a38 100644
67964--- a/include/linux/elf.h
67965+++ b/include/linux/elf.h
67966@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
67967 #define elf_note elf32_note
67968 #define elf_addr_t Elf32_Off
67969 #define Elf_Half Elf32_Half
67970+#define elf_dyn Elf32_Dyn
67971
67972 #else
67973
67974@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
67975 #define elf_note elf64_note
67976 #define elf_addr_t Elf64_Off
67977 #define Elf_Half Elf64_Half
67978+#define elf_dyn Elf64_Dyn
67979
67980 #endif
67981
67982diff --git a/include/linux/err.h b/include/linux/err.h
67983index f2edce2..cc2082c 100644
67984--- a/include/linux/err.h
67985+++ b/include/linux/err.h
67986@@ -19,12 +19,12 @@
67987
67988 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
67989
67990-static inline void * __must_check ERR_PTR(long error)
67991+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
67992 {
67993 return (void *) error;
67994 }
67995
67996-static inline long __must_check PTR_ERR(const void *ptr)
67997+static inline long __must_check __intentional_overflow(-1) PTR_ERR(const void *ptr)
67998 {
67999 return (long) ptr;
68000 }
68001diff --git a/include/linux/extcon.h b/include/linux/extcon.h
68002index fcb51c8..bdafcf6 100644
68003--- a/include/linux/extcon.h
68004+++ b/include/linux/extcon.h
68005@@ -134,7 +134,7 @@ struct extcon_dev {
68006 /* /sys/class/extcon/.../mutually_exclusive/... */
68007 struct attribute_group attr_g_muex;
68008 struct attribute **attrs_muex;
68009- struct device_attribute *d_attrs_muex;
68010+ device_attribute_no_const *d_attrs_muex;
68011 };
68012
68013 /**
68014diff --git a/include/linux/fb.h b/include/linux/fb.h
68015index 58b9860..58e5516 100644
68016--- a/include/linux/fb.h
68017+++ b/include/linux/fb.h
68018@@ -304,7 +304,7 @@ struct fb_ops {
68019 /* called at KDB enter and leave time to prepare the console */
68020 int (*fb_debug_enter)(struct fb_info *info);
68021 int (*fb_debug_leave)(struct fb_info *info);
68022-};
68023+} __do_const;
68024
68025 #ifdef CONFIG_FB_TILEBLITTING
68026 #define FB_TILE_CURSOR_NONE 0
68027diff --git a/include/linux/filter.h b/include/linux/filter.h
68028index c45eabc..baa0be5 100644
68029--- a/include/linux/filter.h
68030+++ b/include/linux/filter.h
68031@@ -20,6 +20,7 @@ struct compat_sock_fprog {
68032
68033 struct sk_buff;
68034 struct sock;
68035+struct bpf_jit_work;
68036
68037 struct sk_filter
68038 {
68039@@ -27,6 +28,9 @@ struct sk_filter
68040 unsigned int len; /* Number of filter blocks */
68041 unsigned int (*bpf_func)(const struct sk_buff *skb,
68042 const struct sock_filter *filter);
68043+#ifdef CONFIG_BPF_JIT
68044+ struct bpf_jit_work *work;
68045+#endif
68046 struct rcu_head rcu;
68047 struct sock_filter insns[0];
68048 };
68049diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
68050index 3044254..9767f41 100644
68051--- a/include/linux/frontswap.h
68052+++ b/include/linux/frontswap.h
68053@@ -11,7 +11,7 @@ struct frontswap_ops {
68054 int (*load)(unsigned, pgoff_t, struct page *);
68055 void (*invalidate_page)(unsigned, pgoff_t);
68056 void (*invalidate_area)(unsigned);
68057-};
68058+} __no_const;
68059
68060 extern bool frontswap_enabled;
68061 extern struct frontswap_ops
68062diff --git a/include/linux/fs.h b/include/linux/fs.h
68063index 2c28271..8d3d74c 100644
68064--- a/include/linux/fs.h
68065+++ b/include/linux/fs.h
68066@@ -1541,7 +1541,8 @@ struct file_operations {
68067 long (*fallocate)(struct file *file, int mode, loff_t offset,
68068 loff_t len);
68069 int (*show_fdinfo)(struct seq_file *m, struct file *f);
68070-};
68071+} __do_const;
68072+typedef struct file_operations __no_const file_operations_no_const;
68073
68074 struct inode_operations {
68075 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
68076@@ -2672,4 +2673,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
68077 inode->i_flags |= S_NOSEC;
68078 }
68079
68080+static inline bool is_sidechannel_device(const struct inode *inode)
68081+{
68082+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
68083+ umode_t mode = inode->i_mode;
68084+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
68085+#else
68086+ return false;
68087+#endif
68088+}
68089+
68090 #endif /* _LINUX_FS_H */
68091diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
68092index 2b93a9a..855d94a 100644
68093--- a/include/linux/fs_struct.h
68094+++ b/include/linux/fs_struct.h
68095@@ -6,7 +6,7 @@
68096 #include <linux/seqlock.h>
68097
68098 struct fs_struct {
68099- int users;
68100+ atomic_t users;
68101 spinlock_t lock;
68102 seqcount_t seq;
68103 int umask;
68104diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
68105index 5dfa0aa..6acf322 100644
68106--- a/include/linux/fscache-cache.h
68107+++ b/include/linux/fscache-cache.h
68108@@ -112,7 +112,7 @@ struct fscache_operation {
68109 fscache_operation_release_t release;
68110 };
68111
68112-extern atomic_t fscache_op_debug_id;
68113+extern atomic_unchecked_t fscache_op_debug_id;
68114 extern void fscache_op_work_func(struct work_struct *work);
68115
68116 extern void fscache_enqueue_operation(struct fscache_operation *);
68117@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
68118 INIT_WORK(&op->work, fscache_op_work_func);
68119 atomic_set(&op->usage, 1);
68120 op->state = FSCACHE_OP_ST_INITIALISED;
68121- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
68122+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
68123 op->processor = processor;
68124 op->release = release;
68125 INIT_LIST_HEAD(&op->pend_link);
68126diff --git a/include/linux/fscache.h b/include/linux/fscache.h
68127index 7a08623..4c07b0f 100644
68128--- a/include/linux/fscache.h
68129+++ b/include/linux/fscache.h
68130@@ -152,7 +152,7 @@ struct fscache_cookie_def {
68131 * - this is mandatory for any object that may have data
68132 */
68133 void (*now_uncached)(void *cookie_netfs_data);
68134-};
68135+} __do_const;
68136
68137 /*
68138 * fscache cached network filesystem type
68139diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
68140index a78680a..87bd73e 100644
68141--- a/include/linux/fsnotify.h
68142+++ b/include/linux/fsnotify.h
68143@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
68144 struct inode *inode = path->dentry->d_inode;
68145 __u32 mask = FS_ACCESS;
68146
68147+ if (is_sidechannel_device(inode))
68148+ return;
68149+
68150 if (S_ISDIR(inode->i_mode))
68151 mask |= FS_ISDIR;
68152
68153@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
68154 struct inode *inode = path->dentry->d_inode;
68155 __u32 mask = FS_MODIFY;
68156
68157+ if (is_sidechannel_device(inode))
68158+ return;
68159+
68160 if (S_ISDIR(inode->i_mode))
68161 mask |= FS_ISDIR;
68162
68163@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
68164 */
68165 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
68166 {
68167- return kstrdup(name, GFP_KERNEL);
68168+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
68169 }
68170
68171 /*
68172diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
68173index 13a54d0..c6ce2a7 100644
68174--- a/include/linux/ftrace_event.h
68175+++ b/include/linux/ftrace_event.h
68176@@ -274,7 +274,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
68177 extern int trace_add_event_call(struct ftrace_event_call *call);
68178 extern void trace_remove_event_call(struct ftrace_event_call *call);
68179
68180-#define is_signed_type(type) (((type)(-1)) < (type)0)
68181+#define is_signed_type(type) (((type)(-1)) < (type)1)
68182
68183 int trace_set_clr_event(const char *system, const char *event, int set);
68184
68185diff --git a/include/linux/genhd.h b/include/linux/genhd.h
68186index 9f3c275..911b591 100644
68187--- a/include/linux/genhd.h
68188+++ b/include/linux/genhd.h
68189@@ -194,7 +194,7 @@ struct gendisk {
68190 struct kobject *slave_dir;
68191
68192 struct timer_rand_state *random;
68193- atomic_t sync_io; /* RAID */
68194+ atomic_unchecked_t sync_io; /* RAID */
68195 struct disk_events *ev;
68196 #ifdef CONFIG_BLK_DEV_INTEGRITY
68197 struct blk_integrity *integrity;
68198diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
68199index 023bc34..b02b46a 100644
68200--- a/include/linux/genl_magic_func.h
68201+++ b/include/linux/genl_magic_func.h
68202@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
68203 },
68204
68205 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
68206-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
68207+static struct genl_ops ZZZ_genl_ops[] = {
68208 #include GENL_MAGIC_INCLUDE_FILE
68209 };
68210
68211diff --git a/include/linux/gfp.h b/include/linux/gfp.h
68212index 0f615eb..5c3832f 100644
68213--- a/include/linux/gfp.h
68214+++ b/include/linux/gfp.h
68215@@ -35,6 +35,13 @@ struct vm_area_struct;
68216 #define ___GFP_NO_KSWAPD 0x400000u
68217 #define ___GFP_OTHER_NODE 0x800000u
68218 #define ___GFP_WRITE 0x1000000u
68219+
68220+#ifdef CONFIG_PAX_USERCOPY_SLABS
68221+#define ___GFP_USERCOPY 0x2000000u
68222+#else
68223+#define ___GFP_USERCOPY 0
68224+#endif
68225+
68226 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
68227
68228 /*
68229@@ -92,6 +99,7 @@ struct vm_area_struct;
68230 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
68231 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
68232 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
68233+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
68234
68235 /*
68236 * This may seem redundant, but it's a way of annotating false positives vs.
68237@@ -99,7 +107,7 @@ struct vm_area_struct;
68238 */
68239 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
68240
68241-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
68242+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
68243 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
68244
68245 /* This equals 0, but use constants in case they ever change */
68246@@ -153,6 +161,8 @@ struct vm_area_struct;
68247 /* 4GB DMA on some platforms */
68248 #define GFP_DMA32 __GFP_DMA32
68249
68250+#define GFP_USERCOPY __GFP_USERCOPY
68251+
68252 /* Convert GFP flags to their corresponding migrate type */
68253 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
68254 {
68255diff --git a/include/linux/gracl.h b/include/linux/gracl.h
68256new file mode 100644
68257index 0000000..ebe6d72
68258--- /dev/null
68259+++ b/include/linux/gracl.h
68260@@ -0,0 +1,319 @@
68261+#ifndef GR_ACL_H
68262+#define GR_ACL_H
68263+
68264+#include <linux/grdefs.h>
68265+#include <linux/resource.h>
68266+#include <linux/capability.h>
68267+#include <linux/dcache.h>
68268+#include <asm/resource.h>
68269+
68270+/* Major status information */
68271+
68272+#define GR_VERSION "grsecurity 2.9.1"
68273+#define GRSECURITY_VERSION 0x2901
68274+
68275+enum {
68276+ GR_SHUTDOWN = 0,
68277+ GR_ENABLE = 1,
68278+ GR_SPROLE = 2,
68279+ GR_RELOAD = 3,
68280+ GR_SEGVMOD = 4,
68281+ GR_STATUS = 5,
68282+ GR_UNSPROLE = 6,
68283+ GR_PASSSET = 7,
68284+ GR_SPROLEPAM = 8,
68285+};
68286+
68287+/* Password setup definitions
68288+ * kernel/grhash.c */
68289+enum {
68290+ GR_PW_LEN = 128,
68291+ GR_SALT_LEN = 16,
68292+ GR_SHA_LEN = 32,
68293+};
68294+
68295+enum {
68296+ GR_SPROLE_LEN = 64,
68297+};
68298+
68299+enum {
68300+ GR_NO_GLOB = 0,
68301+ GR_REG_GLOB,
68302+ GR_CREATE_GLOB
68303+};
68304+
68305+#define GR_NLIMITS 32
68306+
68307+/* Begin Data Structures */
68308+
68309+struct sprole_pw {
68310+ unsigned char *rolename;
68311+ unsigned char salt[GR_SALT_LEN];
68312+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
68313+};
68314+
68315+struct name_entry {
68316+ __u32 key;
68317+ ino_t inode;
68318+ dev_t device;
68319+ char *name;
68320+ __u16 len;
68321+ __u8 deleted;
68322+ struct name_entry *prev;
68323+ struct name_entry *next;
68324+};
68325+
68326+struct inodev_entry {
68327+ struct name_entry *nentry;
68328+ struct inodev_entry *prev;
68329+ struct inodev_entry *next;
68330+};
68331+
68332+struct acl_role_db {
68333+ struct acl_role_label **r_hash;
68334+ __u32 r_size;
68335+};
68336+
68337+struct inodev_db {
68338+ struct inodev_entry **i_hash;
68339+ __u32 i_size;
68340+};
68341+
68342+struct name_db {
68343+ struct name_entry **n_hash;
68344+ __u32 n_size;
68345+};
68346+
68347+struct crash_uid {
68348+ uid_t uid;
68349+ unsigned long expires;
68350+};
68351+
68352+struct gr_hash_struct {
68353+ void **table;
68354+ void **nametable;
68355+ void *first;
68356+ __u32 table_size;
68357+ __u32 used_size;
68358+ int type;
68359+};
68360+
68361+/* Userspace Grsecurity ACL data structures */
68362+
68363+struct acl_subject_label {
68364+ char *filename;
68365+ ino_t inode;
68366+ dev_t device;
68367+ __u32 mode;
68368+ kernel_cap_t cap_mask;
68369+ kernel_cap_t cap_lower;
68370+ kernel_cap_t cap_invert_audit;
68371+
68372+ struct rlimit res[GR_NLIMITS];
68373+ __u32 resmask;
68374+
68375+ __u8 user_trans_type;
68376+ __u8 group_trans_type;
68377+ uid_t *user_transitions;
68378+ gid_t *group_transitions;
68379+ __u16 user_trans_num;
68380+ __u16 group_trans_num;
68381+
68382+ __u32 sock_families[2];
68383+ __u32 ip_proto[8];
68384+ __u32 ip_type;
68385+ struct acl_ip_label **ips;
68386+ __u32 ip_num;
68387+ __u32 inaddr_any_override;
68388+
68389+ __u32 crashes;
68390+ unsigned long expires;
68391+
68392+ struct acl_subject_label *parent_subject;
68393+ struct gr_hash_struct *hash;
68394+ struct acl_subject_label *prev;
68395+ struct acl_subject_label *next;
68396+
68397+ struct acl_object_label **obj_hash;
68398+ __u32 obj_hash_size;
68399+ __u16 pax_flags;
68400+};
68401+
68402+struct role_allowed_ip {
68403+ __u32 addr;
68404+ __u32 netmask;
68405+
68406+ struct role_allowed_ip *prev;
68407+ struct role_allowed_ip *next;
68408+};
68409+
68410+struct role_transition {
68411+ char *rolename;
68412+
68413+ struct role_transition *prev;
68414+ struct role_transition *next;
68415+};
68416+
68417+struct acl_role_label {
68418+ char *rolename;
68419+ uid_t uidgid;
68420+ __u16 roletype;
68421+
68422+ __u16 auth_attempts;
68423+ unsigned long expires;
68424+
68425+ struct acl_subject_label *root_label;
68426+ struct gr_hash_struct *hash;
68427+
68428+ struct acl_role_label *prev;
68429+ struct acl_role_label *next;
68430+
68431+ struct role_transition *transitions;
68432+ struct role_allowed_ip *allowed_ips;
68433+ uid_t *domain_children;
68434+ __u16 domain_child_num;
68435+
68436+ umode_t umask;
68437+
68438+ struct acl_subject_label **subj_hash;
68439+ __u32 subj_hash_size;
68440+};
68441+
68442+struct user_acl_role_db {
68443+ struct acl_role_label **r_table;
68444+ __u32 num_pointers; /* Number of allocations to track */
68445+ __u32 num_roles; /* Number of roles */
68446+ __u32 num_domain_children; /* Number of domain children */
68447+ __u32 num_subjects; /* Number of subjects */
68448+ __u32 num_objects; /* Number of objects */
68449+};
68450+
68451+struct acl_object_label {
68452+ char *filename;
68453+ ino_t inode;
68454+ dev_t device;
68455+ __u32 mode;
68456+
68457+ struct acl_subject_label *nested;
68458+ struct acl_object_label *globbed;
68459+
68460+ /* next two structures not used */
68461+
68462+ struct acl_object_label *prev;
68463+ struct acl_object_label *next;
68464+};
68465+
68466+struct acl_ip_label {
68467+ char *iface;
68468+ __u32 addr;
68469+ __u32 netmask;
68470+ __u16 low, high;
68471+ __u8 mode;
68472+ __u32 type;
68473+ __u32 proto[8];
68474+
68475+ /* next two structures not used */
68476+
68477+ struct acl_ip_label *prev;
68478+ struct acl_ip_label *next;
68479+};
68480+
68481+struct gr_arg {
68482+ struct user_acl_role_db role_db;
68483+ unsigned char pw[GR_PW_LEN];
68484+ unsigned char salt[GR_SALT_LEN];
68485+ unsigned char sum[GR_SHA_LEN];
68486+ unsigned char sp_role[GR_SPROLE_LEN];
68487+ struct sprole_pw *sprole_pws;
68488+ dev_t segv_device;
68489+ ino_t segv_inode;
68490+ uid_t segv_uid;
68491+ __u16 num_sprole_pws;
68492+ __u16 mode;
68493+};
68494+
68495+struct gr_arg_wrapper {
68496+ struct gr_arg *arg;
68497+ __u32 version;
68498+ __u32 size;
68499+};
68500+
68501+struct subject_map {
68502+ struct acl_subject_label *user;
68503+ struct acl_subject_label *kernel;
68504+ struct subject_map *prev;
68505+ struct subject_map *next;
68506+};
68507+
68508+struct acl_subj_map_db {
68509+ struct subject_map **s_hash;
68510+ __u32 s_size;
68511+};
68512+
68513+/* End Data Structures Section */
68514+
68515+/* Hash functions generated by empirical testing by Brad Spengler
68516+ Makes good use of the low bits of the inode. Generally 0-1 times
68517+ in loop for successful match. 0-3 for unsuccessful match.
68518+ Shift/add algorithm with modulus of table size and an XOR*/
68519+
68520+static __inline__ unsigned int
68521+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
68522+{
68523+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
68524+}
68525+
68526+ static __inline__ unsigned int
68527+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
68528+{
68529+ return ((const unsigned long)userp % sz);
68530+}
68531+
68532+static __inline__ unsigned int
68533+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
68534+{
68535+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
68536+}
68537+
68538+static __inline__ unsigned int
68539+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
68540+{
68541+ return full_name_hash((const unsigned char *)name, len) % sz;
68542+}
68543+
68544+#define FOR_EACH_ROLE_START(role) \
68545+ role = role_list; \
68546+ while (role) {
68547+
68548+#define FOR_EACH_ROLE_END(role) \
68549+ role = role->prev; \
68550+ }
68551+
68552+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
68553+ subj = NULL; \
68554+ iter = 0; \
68555+ while (iter < role->subj_hash_size) { \
68556+ if (subj == NULL) \
68557+ subj = role->subj_hash[iter]; \
68558+ if (subj == NULL) { \
68559+ iter++; \
68560+ continue; \
68561+ }
68562+
68563+#define FOR_EACH_SUBJECT_END(subj,iter) \
68564+ subj = subj->next; \
68565+ if (subj == NULL) \
68566+ iter++; \
68567+ }
68568+
68569+
68570+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
68571+ subj = role->hash->first; \
68572+ while (subj != NULL) {
68573+
68574+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
68575+ subj = subj->next; \
68576+ }
68577+
68578+#endif
68579+
68580diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
68581new file mode 100644
68582index 0000000..323ecf2
68583--- /dev/null
68584+++ b/include/linux/gralloc.h
68585@@ -0,0 +1,9 @@
68586+#ifndef __GRALLOC_H
68587+#define __GRALLOC_H
68588+
68589+void acl_free_all(void);
68590+int acl_alloc_stack_init(unsigned long size);
68591+void *acl_alloc(unsigned long len);
68592+void *acl_alloc_num(unsigned long num, unsigned long len);
68593+
68594+#endif
68595diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
68596new file mode 100644
68597index 0000000..be66033
68598--- /dev/null
68599+++ b/include/linux/grdefs.h
68600@@ -0,0 +1,140 @@
68601+#ifndef GRDEFS_H
68602+#define GRDEFS_H
68603+
68604+/* Begin grsecurity status declarations */
68605+
68606+enum {
68607+ GR_READY = 0x01,
68608+ GR_STATUS_INIT = 0x00 // disabled state
68609+};
68610+
68611+/* Begin ACL declarations */
68612+
68613+/* Role flags */
68614+
68615+enum {
68616+ GR_ROLE_USER = 0x0001,
68617+ GR_ROLE_GROUP = 0x0002,
68618+ GR_ROLE_DEFAULT = 0x0004,
68619+ GR_ROLE_SPECIAL = 0x0008,
68620+ GR_ROLE_AUTH = 0x0010,
68621+ GR_ROLE_NOPW = 0x0020,
68622+ GR_ROLE_GOD = 0x0040,
68623+ GR_ROLE_LEARN = 0x0080,
68624+ GR_ROLE_TPE = 0x0100,
68625+ GR_ROLE_DOMAIN = 0x0200,
68626+ GR_ROLE_PAM = 0x0400,
68627+ GR_ROLE_PERSIST = 0x0800
68628+};
68629+
68630+/* ACL Subject and Object mode flags */
68631+enum {
68632+ GR_DELETED = 0x80000000
68633+};
68634+
68635+/* ACL Object-only mode flags */
68636+enum {
68637+ GR_READ = 0x00000001,
68638+ GR_APPEND = 0x00000002,
68639+ GR_WRITE = 0x00000004,
68640+ GR_EXEC = 0x00000008,
68641+ GR_FIND = 0x00000010,
68642+ GR_INHERIT = 0x00000020,
68643+ GR_SETID = 0x00000040,
68644+ GR_CREATE = 0x00000080,
68645+ GR_DELETE = 0x00000100,
68646+ GR_LINK = 0x00000200,
68647+ GR_AUDIT_READ = 0x00000400,
68648+ GR_AUDIT_APPEND = 0x00000800,
68649+ GR_AUDIT_WRITE = 0x00001000,
68650+ GR_AUDIT_EXEC = 0x00002000,
68651+ GR_AUDIT_FIND = 0x00004000,
68652+ GR_AUDIT_INHERIT= 0x00008000,
68653+ GR_AUDIT_SETID = 0x00010000,
68654+ GR_AUDIT_CREATE = 0x00020000,
68655+ GR_AUDIT_DELETE = 0x00040000,
68656+ GR_AUDIT_LINK = 0x00080000,
68657+ GR_PTRACERD = 0x00100000,
68658+ GR_NOPTRACE = 0x00200000,
68659+ GR_SUPPRESS = 0x00400000,
68660+ GR_NOLEARN = 0x00800000,
68661+ GR_INIT_TRANSFER= 0x01000000
68662+};
68663+
68664+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
68665+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
68666+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
68667+
68668+/* ACL subject-only mode flags */
68669+enum {
68670+ GR_KILL = 0x00000001,
68671+ GR_VIEW = 0x00000002,
68672+ GR_PROTECTED = 0x00000004,
68673+ GR_LEARN = 0x00000008,
68674+ GR_OVERRIDE = 0x00000010,
68675+ /* just a placeholder, this mode is only used in userspace */
68676+ GR_DUMMY = 0x00000020,
68677+ GR_PROTSHM = 0x00000040,
68678+ GR_KILLPROC = 0x00000080,
68679+ GR_KILLIPPROC = 0x00000100,
68680+ /* just a placeholder, this mode is only used in userspace */
68681+ GR_NOTROJAN = 0x00000200,
68682+ GR_PROTPROCFD = 0x00000400,
68683+ GR_PROCACCT = 0x00000800,
68684+ GR_RELAXPTRACE = 0x00001000,
68685+ //GR_NESTED = 0x00002000,
68686+ GR_INHERITLEARN = 0x00004000,
68687+ GR_PROCFIND = 0x00008000,
68688+ GR_POVERRIDE = 0x00010000,
68689+ GR_KERNELAUTH = 0x00020000,
68690+ GR_ATSECURE = 0x00040000,
68691+ GR_SHMEXEC = 0x00080000
68692+};
68693+
68694+enum {
68695+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
68696+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
68697+ GR_PAX_ENABLE_MPROTECT = 0x0004,
68698+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
68699+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
68700+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
68701+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
68702+ GR_PAX_DISABLE_MPROTECT = 0x0400,
68703+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
68704+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
68705+};
68706+
68707+enum {
68708+ GR_ID_USER = 0x01,
68709+ GR_ID_GROUP = 0x02,
68710+};
68711+
68712+enum {
68713+ GR_ID_ALLOW = 0x01,
68714+ GR_ID_DENY = 0x02,
68715+};
68716+
68717+#define GR_CRASH_RES 31
68718+#define GR_UIDTABLE_MAX 500
68719+
68720+/* begin resource learning section */
68721+enum {
68722+ GR_RLIM_CPU_BUMP = 60,
68723+ GR_RLIM_FSIZE_BUMP = 50000,
68724+ GR_RLIM_DATA_BUMP = 10000,
68725+ GR_RLIM_STACK_BUMP = 1000,
68726+ GR_RLIM_CORE_BUMP = 10000,
68727+ GR_RLIM_RSS_BUMP = 500000,
68728+ GR_RLIM_NPROC_BUMP = 1,
68729+ GR_RLIM_NOFILE_BUMP = 5,
68730+ GR_RLIM_MEMLOCK_BUMP = 50000,
68731+ GR_RLIM_AS_BUMP = 500000,
68732+ GR_RLIM_LOCKS_BUMP = 2,
68733+ GR_RLIM_SIGPENDING_BUMP = 5,
68734+ GR_RLIM_MSGQUEUE_BUMP = 10000,
68735+ GR_RLIM_NICE_BUMP = 1,
68736+ GR_RLIM_RTPRIO_BUMP = 1,
68737+ GR_RLIM_RTTIME_BUMP = 1000000
68738+};
68739+
68740+#endif
68741diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
68742new file mode 100644
68743index 0000000..5402bce
68744--- /dev/null
68745+++ b/include/linux/grinternal.h
68746@@ -0,0 +1,215 @@
68747+#ifndef __GRINTERNAL_H
68748+#define __GRINTERNAL_H
68749+
68750+#ifdef CONFIG_GRKERNSEC
68751+
68752+#include <linux/fs.h>
68753+#include <linux/mnt_namespace.h>
68754+#include <linux/nsproxy.h>
68755+#include <linux/gracl.h>
68756+#include <linux/grdefs.h>
68757+#include <linux/grmsg.h>
68758+
68759+void gr_add_learn_entry(const char *fmt, ...)
68760+ __attribute__ ((format (printf, 1, 2)));
68761+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
68762+ const struct vfsmount *mnt);
68763+__u32 gr_check_create(const struct dentry *new_dentry,
68764+ const struct dentry *parent,
68765+ const struct vfsmount *mnt, const __u32 mode);
68766+int gr_check_protected_task(const struct task_struct *task);
68767+__u32 to_gr_audit(const __u32 reqmode);
68768+int gr_set_acls(const int type);
68769+int gr_apply_subject_to_task(struct task_struct *task);
68770+int gr_acl_is_enabled(void);
68771+char gr_roletype_to_char(void);
68772+
68773+void gr_handle_alertkill(struct task_struct *task);
68774+char *gr_to_filename(const struct dentry *dentry,
68775+ const struct vfsmount *mnt);
68776+char *gr_to_filename1(const struct dentry *dentry,
68777+ const struct vfsmount *mnt);
68778+char *gr_to_filename2(const struct dentry *dentry,
68779+ const struct vfsmount *mnt);
68780+char *gr_to_filename3(const struct dentry *dentry,
68781+ const struct vfsmount *mnt);
68782+
68783+extern int grsec_enable_ptrace_readexec;
68784+extern int grsec_enable_harden_ptrace;
68785+extern int grsec_enable_link;
68786+extern int grsec_enable_fifo;
68787+extern int grsec_enable_execve;
68788+extern int grsec_enable_shm;
68789+extern int grsec_enable_execlog;
68790+extern int grsec_enable_signal;
68791+extern int grsec_enable_audit_ptrace;
68792+extern int grsec_enable_forkfail;
68793+extern int grsec_enable_time;
68794+extern int grsec_enable_rofs;
68795+extern int grsec_enable_chroot_shmat;
68796+extern int grsec_enable_chroot_mount;
68797+extern int grsec_enable_chroot_double;
68798+extern int grsec_enable_chroot_pivot;
68799+extern int grsec_enable_chroot_chdir;
68800+extern int grsec_enable_chroot_chmod;
68801+extern int grsec_enable_chroot_mknod;
68802+extern int grsec_enable_chroot_fchdir;
68803+extern int grsec_enable_chroot_nice;
68804+extern int grsec_enable_chroot_execlog;
68805+extern int grsec_enable_chroot_caps;
68806+extern int grsec_enable_chroot_sysctl;
68807+extern int grsec_enable_chroot_unix;
68808+extern int grsec_enable_symlinkown;
68809+extern kgid_t grsec_symlinkown_gid;
68810+extern int grsec_enable_tpe;
68811+extern kgid_t grsec_tpe_gid;
68812+extern int grsec_enable_tpe_all;
68813+extern int grsec_enable_tpe_invert;
68814+extern int grsec_enable_socket_all;
68815+extern kgid_t grsec_socket_all_gid;
68816+extern int grsec_enable_socket_client;
68817+extern kgid_t grsec_socket_client_gid;
68818+extern int grsec_enable_socket_server;
68819+extern kgid_t grsec_socket_server_gid;
68820+extern kgid_t grsec_audit_gid;
68821+extern int grsec_enable_group;
68822+extern int grsec_enable_audit_textrel;
68823+extern int grsec_enable_log_rwxmaps;
68824+extern int grsec_enable_mount;
68825+extern int grsec_enable_chdir;
68826+extern int grsec_resource_logging;
68827+extern int grsec_enable_blackhole;
68828+extern int grsec_lastack_retries;
68829+extern int grsec_enable_brute;
68830+extern int grsec_lock;
68831+
68832+extern spinlock_t grsec_alert_lock;
68833+extern unsigned long grsec_alert_wtime;
68834+extern unsigned long grsec_alert_fyet;
68835+
68836+extern spinlock_t grsec_audit_lock;
68837+
68838+extern rwlock_t grsec_exec_file_lock;
68839+
68840+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
68841+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
68842+ (tsk)->exec_file->f_path.mnt) : "/")
68843+
68844+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
68845+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
68846+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
68847+
68848+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
68849+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
68850+ (tsk)->exec_file->f_path.mnt) : "/")
68851+
68852+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
68853+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
68854+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
68855+
68856+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
68857+
68858+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
68859+
68860+#define GR_CHROOT_CAPS {{ \
68861+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
68862+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
68863+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
68864+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
68865+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
68866+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
68867+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
68868+
68869+#define security_learn(normal_msg,args...) \
68870+({ \
68871+ read_lock(&grsec_exec_file_lock); \
68872+ gr_add_learn_entry(normal_msg "\n", ## args); \
68873+ read_unlock(&grsec_exec_file_lock); \
68874+})
68875+
68876+enum {
68877+ GR_DO_AUDIT,
68878+ GR_DONT_AUDIT,
68879+ /* used for non-audit messages that we shouldn't kill the task on */
68880+ GR_DONT_AUDIT_GOOD
68881+};
68882+
68883+enum {
68884+ GR_TTYSNIFF,
68885+ GR_RBAC,
68886+ GR_RBAC_STR,
68887+ GR_STR_RBAC,
68888+ GR_RBAC_MODE2,
68889+ GR_RBAC_MODE3,
68890+ GR_FILENAME,
68891+ GR_SYSCTL_HIDDEN,
68892+ GR_NOARGS,
68893+ GR_ONE_INT,
68894+ GR_ONE_INT_TWO_STR,
68895+ GR_ONE_STR,
68896+ GR_STR_INT,
68897+ GR_TWO_STR_INT,
68898+ GR_TWO_INT,
68899+ GR_TWO_U64,
68900+ GR_THREE_INT,
68901+ GR_FIVE_INT_TWO_STR,
68902+ GR_TWO_STR,
68903+ GR_THREE_STR,
68904+ GR_FOUR_STR,
68905+ GR_STR_FILENAME,
68906+ GR_FILENAME_STR,
68907+ GR_FILENAME_TWO_INT,
68908+ GR_FILENAME_TWO_INT_STR,
68909+ GR_TEXTREL,
68910+ GR_PTRACE,
68911+ GR_RESOURCE,
68912+ GR_CAP,
68913+ GR_SIG,
68914+ GR_SIG2,
68915+ GR_CRASH1,
68916+ GR_CRASH2,
68917+ GR_PSACCT,
68918+ GR_RWXMAP
68919+};
68920+
68921+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
68922+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
68923+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
68924+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
68925+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
68926+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
68927+#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)
68928+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
68929+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
68930+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
68931+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
68932+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
68933+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
68934+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
68935+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
68936+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
68937+#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)
68938+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
68939+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
68940+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
68941+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
68942+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
68943+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
68944+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
68945+#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)
68946+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
68947+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
68948+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
68949+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
68950+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
68951+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
68952+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
68953+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
68954+#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)
68955+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
68956+
68957+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
68958+
68959+#endif
68960+
68961+#endif
68962diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
68963new file mode 100644
68964index 0000000..2bd4c8d
68965--- /dev/null
68966+++ b/include/linux/grmsg.h
68967@@ -0,0 +1,111 @@
68968+#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"
68969+#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"
68970+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
68971+#define GR_STOPMOD_MSG "denied modification of module state by "
68972+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
68973+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
68974+#define GR_IOPERM_MSG "denied use of ioperm() by "
68975+#define GR_IOPL_MSG "denied use of iopl() by "
68976+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
68977+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
68978+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
68979+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
68980+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
68981+#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"
68982+#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"
68983+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
68984+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
68985+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
68986+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
68987+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
68988+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
68989+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
68990+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
68991+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
68992+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
68993+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
68994+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
68995+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
68996+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
68997+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
68998+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
68999+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
69000+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
69001+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
69002+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
69003+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
69004+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
69005+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
69006+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
69007+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
69008+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
69009+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
69010+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
69011+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
69012+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
69013+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
69014+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
69015+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
69016+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
69017+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
69018+#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"
69019+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
69020+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
69021+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
69022+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
69023+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
69024+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
69025+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
69026+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
69027+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
69028+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
69029+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
69030+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
69031+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
69032+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
69033+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
69034+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
69035+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
69036+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
69037+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
69038+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
69039+#define GR_FAILFORK_MSG "failed fork with errno %s by "
69040+#define GR_NICE_CHROOT_MSG "denied priority change by "
69041+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
69042+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
69043+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
69044+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
69045+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
69046+#define GR_TIME_MSG "time set by "
69047+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
69048+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
69049+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
69050+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
69051+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
69052+#define GR_BIND_MSG "denied bind() by "
69053+#define GR_CONNECT_MSG "denied connect() by "
69054+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
69055+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
69056+#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"
69057+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
69058+#define GR_CAP_ACL_MSG "use of %s denied for "
69059+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
69060+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
69061+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
69062+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
69063+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
69064+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
69065+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
69066+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
69067+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
69068+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
69069+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
69070+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
69071+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
69072+#define GR_VM86_MSG "denied use of vm86 by "
69073+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
69074+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
69075+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
69076+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
69077+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
69078+#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 "
69079diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
69080new file mode 100644
69081index 0000000..d7ef0ac
69082--- /dev/null
69083+++ b/include/linux/grsecurity.h
69084@@ -0,0 +1,242 @@
69085+#ifndef GR_SECURITY_H
69086+#define GR_SECURITY_H
69087+#include <linux/fs.h>
69088+#include <linux/fs_struct.h>
69089+#include <linux/binfmts.h>
69090+#include <linux/gracl.h>
69091+
69092+/* notify of brain-dead configs */
69093+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69094+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
69095+#endif
69096+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
69097+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
69098+#endif
69099+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
69100+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
69101+#endif
69102+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
69103+#error "CONFIG_PAX enabled, but no PaX options are enabled."
69104+#endif
69105+
69106+void gr_handle_brute_attach(unsigned long mm_flags);
69107+void gr_handle_brute_check(void);
69108+void gr_handle_kernel_exploit(void);
69109+int gr_process_user_ban(void);
69110+
69111+char gr_roletype_to_char(void);
69112+
69113+int gr_acl_enable_at_secure(void);
69114+
69115+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
69116+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
69117+
69118+void gr_del_task_from_ip_table(struct task_struct *p);
69119+
69120+int gr_pid_is_chrooted(struct task_struct *p);
69121+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
69122+int gr_handle_chroot_nice(void);
69123+int gr_handle_chroot_sysctl(const int op);
69124+int gr_handle_chroot_setpriority(struct task_struct *p,
69125+ const int niceval);
69126+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
69127+int gr_handle_chroot_chroot(const struct dentry *dentry,
69128+ const struct vfsmount *mnt);
69129+void gr_handle_chroot_chdir(const struct path *path);
69130+int gr_handle_chroot_chmod(const struct dentry *dentry,
69131+ const struct vfsmount *mnt, const int mode);
69132+int gr_handle_chroot_mknod(const struct dentry *dentry,
69133+ const struct vfsmount *mnt, const int mode);
69134+int gr_handle_chroot_mount(const struct dentry *dentry,
69135+ const struct vfsmount *mnt,
69136+ const char *dev_name);
69137+int gr_handle_chroot_pivot(void);
69138+int gr_handle_chroot_unix(const pid_t pid);
69139+
69140+int gr_handle_rawio(const struct inode *inode);
69141+
69142+void gr_handle_ioperm(void);
69143+void gr_handle_iopl(void);
69144+
69145+umode_t gr_acl_umask(void);
69146+
69147+int gr_tpe_allow(const struct file *file);
69148+
69149+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
69150+void gr_clear_chroot_entries(struct task_struct *task);
69151+
69152+void gr_log_forkfail(const int retval);
69153+void gr_log_timechange(void);
69154+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
69155+void gr_log_chdir(const struct dentry *dentry,
69156+ const struct vfsmount *mnt);
69157+void gr_log_chroot_exec(const struct dentry *dentry,
69158+ const struct vfsmount *mnt);
69159+void gr_log_remount(const char *devname, const int retval);
69160+void gr_log_unmount(const char *devname, const int retval);
69161+void gr_log_mount(const char *from, const char *to, const int retval);
69162+void gr_log_textrel(struct vm_area_struct *vma);
69163+void gr_log_rwxmmap(struct file *file);
69164+void gr_log_rwxmprotect(struct file *file);
69165+
69166+int gr_handle_follow_link(const struct inode *parent,
69167+ const struct inode *inode,
69168+ const struct dentry *dentry,
69169+ const struct vfsmount *mnt);
69170+int gr_handle_fifo(const struct dentry *dentry,
69171+ const struct vfsmount *mnt,
69172+ const struct dentry *dir, const int flag,
69173+ const int acc_mode);
69174+int gr_handle_hardlink(const struct dentry *dentry,
69175+ const struct vfsmount *mnt,
69176+ struct inode *inode,
69177+ const int mode, const struct filename *to);
69178+
69179+int gr_is_capable(const int cap);
69180+int gr_is_capable_nolog(const int cap);
69181+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69182+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
69183+
69184+void gr_copy_label(struct task_struct *tsk);
69185+void gr_handle_crash(struct task_struct *task, const int sig);
69186+int gr_handle_signal(const struct task_struct *p, const int sig);
69187+int gr_check_crash_uid(const kuid_t uid);
69188+int gr_check_protected_task(const struct task_struct *task);
69189+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
69190+int gr_acl_handle_mmap(const struct file *file,
69191+ const unsigned long prot);
69192+int gr_acl_handle_mprotect(const struct file *file,
69193+ const unsigned long prot);
69194+int gr_check_hidden_task(const struct task_struct *tsk);
69195+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
69196+ const struct vfsmount *mnt);
69197+__u32 gr_acl_handle_utime(const struct dentry *dentry,
69198+ const struct vfsmount *mnt);
69199+__u32 gr_acl_handle_access(const struct dentry *dentry,
69200+ const struct vfsmount *mnt, const int fmode);
69201+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
69202+ const struct vfsmount *mnt, umode_t *mode);
69203+__u32 gr_acl_handle_chown(const struct dentry *dentry,
69204+ const struct vfsmount *mnt);
69205+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
69206+ const struct vfsmount *mnt);
69207+int gr_handle_ptrace(struct task_struct *task, const long request);
69208+int gr_handle_proc_ptrace(struct task_struct *task);
69209+__u32 gr_acl_handle_execve(const struct dentry *dentry,
69210+ const struct vfsmount *mnt);
69211+int gr_check_crash_exec(const struct file *filp);
69212+int gr_acl_is_enabled(void);
69213+void gr_set_kernel_label(struct task_struct *task);
69214+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
69215+ const kgid_t gid);
69216+int gr_set_proc_label(const struct dentry *dentry,
69217+ const struct vfsmount *mnt,
69218+ const int unsafe_flags);
69219+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
69220+ const struct vfsmount *mnt);
69221+__u32 gr_acl_handle_open(const struct dentry *dentry,
69222+ const struct vfsmount *mnt, int acc_mode);
69223+__u32 gr_acl_handle_creat(const struct dentry *dentry,
69224+ const struct dentry *p_dentry,
69225+ const struct vfsmount *p_mnt,
69226+ int open_flags, int acc_mode, const int imode);
69227+void gr_handle_create(const struct dentry *dentry,
69228+ const struct vfsmount *mnt);
69229+void gr_handle_proc_create(const struct dentry *dentry,
69230+ const struct inode *inode);
69231+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
69232+ const struct dentry *parent_dentry,
69233+ const struct vfsmount *parent_mnt,
69234+ const int mode);
69235+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
69236+ const struct dentry *parent_dentry,
69237+ const struct vfsmount *parent_mnt);
69238+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
69239+ const struct vfsmount *mnt);
69240+void gr_handle_delete(const ino_t ino, const dev_t dev);
69241+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
69242+ const struct vfsmount *mnt);
69243+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
69244+ const struct dentry *parent_dentry,
69245+ const struct vfsmount *parent_mnt,
69246+ const struct filename *from);
69247+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
69248+ const struct dentry *parent_dentry,
69249+ const struct vfsmount *parent_mnt,
69250+ const struct dentry *old_dentry,
69251+ const struct vfsmount *old_mnt, const struct filename *to);
69252+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
69253+int gr_acl_handle_rename(struct dentry *new_dentry,
69254+ struct dentry *parent_dentry,
69255+ const struct vfsmount *parent_mnt,
69256+ struct dentry *old_dentry,
69257+ struct inode *old_parent_inode,
69258+ struct vfsmount *old_mnt, const struct filename *newname);
69259+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69260+ struct dentry *old_dentry,
69261+ struct dentry *new_dentry,
69262+ struct vfsmount *mnt, const __u8 replace);
69263+__u32 gr_check_link(const struct dentry *new_dentry,
69264+ const struct dentry *parent_dentry,
69265+ const struct vfsmount *parent_mnt,
69266+ const struct dentry *old_dentry,
69267+ const struct vfsmount *old_mnt);
69268+int gr_acl_handle_filldir(const struct file *file, const char *name,
69269+ const unsigned int namelen, const ino_t ino);
69270+
69271+__u32 gr_acl_handle_unix(const struct dentry *dentry,
69272+ const struct vfsmount *mnt);
69273+void gr_acl_handle_exit(void);
69274+void gr_acl_handle_psacct(struct task_struct *task, const long code);
69275+int gr_acl_handle_procpidmem(const struct task_struct *task);
69276+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
69277+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
69278+void gr_audit_ptrace(struct task_struct *task);
69279+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
69280+void gr_put_exec_file(struct task_struct *task);
69281+
69282+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
69283+
69284+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
69285+extern void gr_learn_resource(const struct task_struct *task, const int res,
69286+ const unsigned long wanted, const int gt);
69287+#else
69288+static inline void gr_learn_resource(const struct task_struct *task, const int res,
69289+ const unsigned long wanted, const int gt)
69290+{
69291+}
69292+#endif
69293+
69294+#ifdef CONFIG_GRKERNSEC_RESLOG
69295+extern void gr_log_resource(const struct task_struct *task, const int res,
69296+ const unsigned long wanted, const int gt);
69297+#else
69298+static inline void gr_log_resource(const struct task_struct *task, const int res,
69299+ const unsigned long wanted, const int gt)
69300+{
69301+}
69302+#endif
69303+
69304+#ifdef CONFIG_GRKERNSEC
69305+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
69306+void gr_handle_vm86(void);
69307+void gr_handle_mem_readwrite(u64 from, u64 to);
69308+
69309+void gr_log_badprocpid(const char *entry);
69310+
69311+extern int grsec_enable_dmesg;
69312+extern int grsec_disable_privio;
69313+
69314+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
69315+extern kgid_t grsec_proc_gid;
69316+#endif
69317+
69318+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69319+extern int grsec_enable_chroot_findtask;
69320+#endif
69321+#ifdef CONFIG_GRKERNSEC_SETXID
69322+extern int grsec_enable_setxid;
69323+#endif
69324+#endif
69325+
69326+#endif
69327diff --git a/include/linux/grsock.h b/include/linux/grsock.h
69328new file mode 100644
69329index 0000000..e7ffaaf
69330--- /dev/null
69331+++ b/include/linux/grsock.h
69332@@ -0,0 +1,19 @@
69333+#ifndef __GRSOCK_H
69334+#define __GRSOCK_H
69335+
69336+extern void gr_attach_curr_ip(const struct sock *sk);
69337+extern int gr_handle_sock_all(const int family, const int type,
69338+ const int protocol);
69339+extern int gr_handle_sock_server(const struct sockaddr *sck);
69340+extern int gr_handle_sock_server_other(const struct sock *sck);
69341+extern int gr_handle_sock_client(const struct sockaddr *sck);
69342+extern int gr_search_connect(struct socket * sock,
69343+ struct sockaddr_in * addr);
69344+extern int gr_search_bind(struct socket * sock,
69345+ struct sockaddr_in * addr);
69346+extern int gr_search_listen(struct socket * sock);
69347+extern int gr_search_accept(struct socket * sock);
69348+extern int gr_search_socket(const int domain, const int type,
69349+ const int protocol);
69350+
69351+#endif
69352diff --git a/include/linux/highmem.h b/include/linux/highmem.h
69353index 7fb31da..08b5114 100644
69354--- a/include/linux/highmem.h
69355+++ b/include/linux/highmem.h
69356@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
69357 kunmap_atomic(kaddr);
69358 }
69359
69360+static inline void sanitize_highpage(struct page *page)
69361+{
69362+ void *kaddr;
69363+ unsigned long flags;
69364+
69365+ local_irq_save(flags);
69366+ kaddr = kmap_atomic(page);
69367+ clear_page(kaddr);
69368+ kunmap_atomic(kaddr);
69369+ local_irq_restore(flags);
69370+}
69371+
69372 static inline void zero_user_segments(struct page *page,
69373 unsigned start1, unsigned end1,
69374 unsigned start2, unsigned end2)
69375diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
69376index 1c7b89a..7f52502 100644
69377--- a/include/linux/hwmon-sysfs.h
69378+++ b/include/linux/hwmon-sysfs.h
69379@@ -25,7 +25,8 @@
69380 struct sensor_device_attribute{
69381 struct device_attribute dev_attr;
69382 int index;
69383-};
69384+} __do_const;
69385+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
69386 #define to_sensor_dev_attr(_dev_attr) \
69387 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
69388
69389@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
69390 struct device_attribute dev_attr;
69391 u8 index;
69392 u8 nr;
69393-};
69394+} __do_const;
69395 #define to_sensor_dev_attr_2(_dev_attr) \
69396 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
69397
69398diff --git a/include/linux/i2c.h b/include/linux/i2c.h
69399index d0c4db7..61b3577 100644
69400--- a/include/linux/i2c.h
69401+++ b/include/linux/i2c.h
69402@@ -369,6 +369,7 @@ struct i2c_algorithm {
69403 /* To determine what the adapter supports */
69404 u32 (*functionality) (struct i2c_adapter *);
69405 };
69406+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
69407
69408 /*
69409 * i2c_adapter is the structure used to identify a physical i2c bus along
69410diff --git a/include/linux/i2o.h b/include/linux/i2o.h
69411index d23c3c2..eb63c81 100644
69412--- a/include/linux/i2o.h
69413+++ b/include/linux/i2o.h
69414@@ -565,7 +565,7 @@ struct i2o_controller {
69415 struct i2o_device *exec; /* Executive */
69416 #if BITS_PER_LONG == 64
69417 spinlock_t context_list_lock; /* lock for context_list */
69418- atomic_t context_list_counter; /* needed for unique contexts */
69419+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
69420 struct list_head context_list; /* list of context id's
69421 and pointers */
69422 #endif
69423diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
69424index aff7ad8..3942bbd 100644
69425--- a/include/linux/if_pppox.h
69426+++ b/include/linux/if_pppox.h
69427@@ -76,7 +76,7 @@ struct pppox_proto {
69428 int (*ioctl)(struct socket *sock, unsigned int cmd,
69429 unsigned long arg);
69430 struct module *owner;
69431-};
69432+} __do_const;
69433
69434 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
69435 extern void unregister_pppox_proto(int proto_num);
69436diff --git a/include/linux/init.h b/include/linux/init.h
69437index 8618147..0821126 100644
69438--- a/include/linux/init.h
69439+++ b/include/linux/init.h
69440@@ -39,9 +39,36 @@
69441 * Also note, that this data cannot be "const".
69442 */
69443
69444+#ifdef MODULE
69445+#define add_init_latent_entropy
69446+#define add_devinit_latent_entropy
69447+#define add_cpuinit_latent_entropy
69448+#define add_meminit_latent_entropy
69449+#else
69450+#define add_init_latent_entropy __latent_entropy
69451+
69452+#ifdef CONFIG_HOTPLUG
69453+#define add_devinit_latent_entropy
69454+#else
69455+#define add_devinit_latent_entropy __latent_entropy
69456+#endif
69457+
69458+#ifdef CONFIG_HOTPLUG_CPU
69459+#define add_cpuinit_latent_entropy
69460+#else
69461+#define add_cpuinit_latent_entropy __latent_entropy
69462+#endif
69463+
69464+#ifdef CONFIG_MEMORY_HOTPLUG
69465+#define add_meminit_latent_entropy
69466+#else
69467+#define add_meminit_latent_entropy __latent_entropy
69468+#endif
69469+#endif
69470+
69471 /* These are for everybody (although not all archs will actually
69472 discard it in modules) */
69473-#define __init __section(.init.text) __cold notrace
69474+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
69475 #define __initdata __section(.init.data)
69476 #define __initconst __constsection(.init.rodata)
69477 #define __exitdata __section(.exit.data)
69478@@ -94,7 +121,7 @@
69479 #define __exit __section(.exit.text) __exitused __cold notrace
69480
69481 /* Used for HOTPLUG_CPU */
69482-#define __cpuinit __section(.cpuinit.text) __cold notrace
69483+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
69484 #define __cpuinitdata __section(.cpuinit.data)
69485 #define __cpuinitconst __constsection(.cpuinit.rodata)
69486 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
69487@@ -102,7 +129,7 @@
69488 #define __cpuexitconst __constsection(.cpuexit.rodata)
69489
69490 /* Used for MEMORY_HOTPLUG */
69491-#define __meminit __section(.meminit.text) __cold notrace
69492+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
69493 #define __meminitdata __section(.meminit.data)
69494 #define __meminitconst __constsection(.meminit.rodata)
69495 #define __memexit __section(.memexit.text) __exitused __cold notrace
69496diff --git a/include/linux/init_task.h b/include/linux/init_task.h
69497index 5cd0f09..c9f67cc 100644
69498--- a/include/linux/init_task.h
69499+++ b/include/linux/init_task.h
69500@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
69501
69502 #define INIT_TASK_COMM "swapper"
69503
69504+#ifdef CONFIG_X86
69505+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
69506+#else
69507+#define INIT_TASK_THREAD_INFO
69508+#endif
69509+
69510 /*
69511 * INIT_TASK is used to set up the first task table, touch at
69512 * your own risk!. Base=0, limit=0x1fffff (=2MB)
69513@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
69514 RCU_POINTER_INITIALIZER(cred, &init_cred), \
69515 .comm = INIT_TASK_COMM, \
69516 .thread = INIT_THREAD, \
69517+ INIT_TASK_THREAD_INFO \
69518 .fs = &init_fs, \
69519 .files = &init_files, \
69520 .signal = &init_signals, \
69521diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
69522index 5fa5afe..ac55b25 100644
69523--- a/include/linux/interrupt.h
69524+++ b/include/linux/interrupt.h
69525@@ -430,7 +430,7 @@ enum
69526 /* map softirq index to softirq name. update 'softirq_to_name' in
69527 * kernel/softirq.c when adding a new softirq.
69528 */
69529-extern char *softirq_to_name[NR_SOFTIRQS];
69530+extern const char * const softirq_to_name[NR_SOFTIRQS];
69531
69532 /* softirq mask and active fields moved to irq_cpustat_t in
69533 * asm/hardirq.h to get better cache usage. KAO
69534@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
69535
69536 struct softirq_action
69537 {
69538- void (*action)(struct softirq_action *);
69539-};
69540+ void (*action)(void);
69541+} __no_const;
69542
69543 asmlinkage void do_softirq(void);
69544 asmlinkage void __do_softirq(void);
69545-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
69546+extern void open_softirq(int nr, void (*action)(void));
69547 extern void softirq_init(void);
69548 extern void __raise_softirq_irqoff(unsigned int nr);
69549
69550diff --git a/include/linux/iommu.h b/include/linux/iommu.h
69551index ba3b8a9..7e14ed8 100644
69552--- a/include/linux/iommu.h
69553+++ b/include/linux/iommu.h
69554@@ -113,7 +113,7 @@ struct iommu_ops {
69555 u32 (*domain_get_windows)(struct iommu_domain *domain);
69556
69557 unsigned long pgsize_bitmap;
69558-};
69559+} __do_const;
69560
69561 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
69562 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
69563diff --git a/include/linux/ioport.h b/include/linux/ioport.h
69564index 85ac9b9b..e5759ab 100644
69565--- a/include/linux/ioport.h
69566+++ b/include/linux/ioport.h
69567@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
69568 int adjust_resource(struct resource *res, resource_size_t start,
69569 resource_size_t size);
69570 resource_size_t resource_alignment(struct resource *res);
69571-static inline resource_size_t resource_size(const struct resource *res)
69572+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
69573 {
69574 return res->end - res->start + 1;
69575 }
69576diff --git a/include/linux/irq.h b/include/linux/irq.h
69577index bc4e066..50468a9 100644
69578--- a/include/linux/irq.h
69579+++ b/include/linux/irq.h
69580@@ -328,7 +328,8 @@ struct irq_chip {
69581 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
69582
69583 unsigned long flags;
69584-};
69585+} __do_const;
69586+typedef struct irq_chip __no_const irq_chip_no_const;
69587
69588 /*
69589 * irq_chip specific flags
69590diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
69591index 3fd8e42..a73e966 100644
69592--- a/include/linux/irqchip/arm-gic.h
69593+++ b/include/linux/irqchip/arm-gic.h
69594@@ -59,9 +59,11 @@
69595
69596 #ifndef __ASSEMBLY__
69597
69598+#include <linux/irq.h>
69599+
69600 struct device_node;
69601
69602-extern struct irq_chip gic_arch_extn;
69603+extern irq_chip_no_const gic_arch_extn;
69604
69605 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
69606 u32 offset, struct device_node *);
69607diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
69608index 6883e19..06992b1 100644
69609--- a/include/linux/kallsyms.h
69610+++ b/include/linux/kallsyms.h
69611@@ -15,7 +15,8 @@
69612
69613 struct module;
69614
69615-#ifdef CONFIG_KALLSYMS
69616+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
69617+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
69618 /* Lookup the address for a symbol. Returns 0 if not found. */
69619 unsigned long kallsyms_lookup_name(const char *name);
69620
69621@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
69622 /* Stupid that this does nothing, but I didn't create this mess. */
69623 #define __print_symbol(fmt, addr)
69624 #endif /*CONFIG_KALLSYMS*/
69625+#else /* when included by kallsyms.c, vsnprintf.c, or
69626+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
69627+extern void __print_symbol(const char *fmt, unsigned long address);
69628+extern int sprint_backtrace(char *buffer, unsigned long address);
69629+extern int sprint_symbol(char *buffer, unsigned long address);
69630+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
69631+const char *kallsyms_lookup(unsigned long addr,
69632+ unsigned long *symbolsize,
69633+ unsigned long *offset,
69634+ char **modname, char *namebuf);
69635+#endif
69636
69637 /* This macro allows us to keep printk typechecking */
69638 static __printf(1, 2)
69639diff --git a/include/linux/key-type.h b/include/linux/key-type.h
69640index 518a53a..5e28358 100644
69641--- a/include/linux/key-type.h
69642+++ b/include/linux/key-type.h
69643@@ -125,7 +125,7 @@ struct key_type {
69644 /* internal fields */
69645 struct list_head link; /* link in types list */
69646 struct lock_class_key lock_class; /* key->sem lock class */
69647-};
69648+} __do_const;
69649
69650 extern struct key_type key_type_keyring;
69651
69652diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
69653index c6e091b..a940adf 100644
69654--- a/include/linux/kgdb.h
69655+++ b/include/linux/kgdb.h
69656@@ -52,7 +52,7 @@ extern int kgdb_connected;
69657 extern int kgdb_io_module_registered;
69658
69659 extern atomic_t kgdb_setting_breakpoint;
69660-extern atomic_t kgdb_cpu_doing_single_step;
69661+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
69662
69663 extern struct task_struct *kgdb_usethread;
69664 extern struct task_struct *kgdb_contthread;
69665@@ -254,7 +254,7 @@ struct kgdb_arch {
69666 void (*correct_hw_break)(void);
69667
69668 void (*enable_nmi)(bool on);
69669-};
69670+} __do_const;
69671
69672 /**
69673 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
69674@@ -279,7 +279,7 @@ struct kgdb_io {
69675 void (*pre_exception) (void);
69676 void (*post_exception) (void);
69677 int is_console;
69678-};
69679+} __do_const;
69680
69681 extern struct kgdb_arch arch_kgdb_ops;
69682
69683diff --git a/include/linux/kmod.h b/include/linux/kmod.h
69684index 5398d58..5883a34 100644
69685--- a/include/linux/kmod.h
69686+++ b/include/linux/kmod.h
69687@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
69688 * usually useless though. */
69689 extern __printf(2, 3)
69690 int __request_module(bool wait, const char *name, ...);
69691+extern __printf(3, 4)
69692+int ___request_module(bool wait, char *param_name, const char *name, ...);
69693 #define request_module(mod...) __request_module(true, mod)
69694 #define request_module_nowait(mod...) __request_module(false, mod)
69695 #define try_then_request_module(x, mod...) \
69696diff --git a/include/linux/kobject.h b/include/linux/kobject.h
69697index 939b112..ed6ed51 100644
69698--- a/include/linux/kobject.h
69699+++ b/include/linux/kobject.h
69700@@ -111,7 +111,7 @@ struct kobj_type {
69701 struct attribute **default_attrs;
69702 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
69703 const void *(*namespace)(struct kobject *kobj);
69704-};
69705+} __do_const;
69706
69707 struct kobj_uevent_env {
69708 char *envp[UEVENT_NUM_ENVP];
69709@@ -134,6 +134,7 @@ struct kobj_attribute {
69710 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
69711 const char *buf, size_t count);
69712 };
69713+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
69714
69715 extern const struct sysfs_ops kobj_sysfs_ops;
69716
69717diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
69718index f66b065..c2c29b4 100644
69719--- a/include/linux/kobject_ns.h
69720+++ b/include/linux/kobject_ns.h
69721@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
69722 const void *(*netlink_ns)(struct sock *sk);
69723 const void *(*initial_ns)(void);
69724 void (*drop_ns)(void *);
69725-};
69726+} __do_const;
69727
69728 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
69729 int kobj_ns_type_registered(enum kobj_ns_type type);
69730diff --git a/include/linux/kref.h b/include/linux/kref.h
69731index 7419c02..aa2f02d 100644
69732--- a/include/linux/kref.h
69733+++ b/include/linux/kref.h
69734@@ -65,7 +65,7 @@ static inline void kref_get(struct kref *kref)
69735 static inline int kref_sub(struct kref *kref, unsigned int count,
69736 void (*release)(struct kref *kref))
69737 {
69738- WARN_ON(release == NULL);
69739+ BUG_ON(release == NULL);
69740
69741 if (atomic_sub_and_test((int) count, &kref->refcount)) {
69742 release(kref);
69743diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
69744index c139582..0b5b102 100644
69745--- a/include/linux/kvm_host.h
69746+++ b/include/linux/kvm_host.h
69747@@ -424,7 +424,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
69748 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
69749 void vcpu_put(struct kvm_vcpu *vcpu);
69750
69751-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
69752+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
69753 struct module *module);
69754 void kvm_exit(void);
69755
69756@@ -582,7 +582,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
69757 struct kvm_guest_debug *dbg);
69758 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
69759
69760-int kvm_arch_init(void *opaque);
69761+int kvm_arch_init(const void *opaque);
69762 void kvm_arch_exit(void);
69763
69764 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
69765diff --git a/include/linux/libata.h b/include/linux/libata.h
69766index eae7a05..2cdd875 100644
69767--- a/include/linux/libata.h
69768+++ b/include/linux/libata.h
69769@@ -919,7 +919,7 @@ struct ata_port_operations {
69770 * fields must be pointers.
69771 */
69772 const struct ata_port_operations *inherits;
69773-};
69774+} __do_const;
69775
69776 struct ata_port_info {
69777 unsigned long flags;
69778diff --git a/include/linux/list.h b/include/linux/list.h
69779index 6a1f8df..eaec1ff 100644
69780--- a/include/linux/list.h
69781+++ b/include/linux/list.h
69782@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
69783 extern void list_del(struct list_head *entry);
69784 #endif
69785
69786+extern void __pax_list_add(struct list_head *new,
69787+ struct list_head *prev,
69788+ struct list_head *next);
69789+static inline void pax_list_add(struct list_head *new, struct list_head *head)
69790+{
69791+ __pax_list_add(new, head, head->next);
69792+}
69793+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
69794+{
69795+ __pax_list_add(new, head->prev, head);
69796+}
69797+extern void pax_list_del(struct list_head *entry);
69798+
69799 /**
69800 * list_replace - replace old entry by new one
69801 * @old : the element to be replaced
69802@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
69803 INIT_LIST_HEAD(entry);
69804 }
69805
69806+extern void pax_list_del_init(struct list_head *entry);
69807+
69808 /**
69809 * list_move - delete from one list and add as another's head
69810 * @list: the entry to move
69811diff --git a/include/linux/math64.h b/include/linux/math64.h
69812index b8ba855..0148090 100644
69813--- a/include/linux/math64.h
69814+++ b/include/linux/math64.h
69815@@ -14,7 +14,7 @@
69816 * This is commonly provided by 32bit archs to provide an optimized 64bit
69817 * divide.
69818 */
69819-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69820+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69821 {
69822 *remainder = dividend % divisor;
69823 return dividend / divisor;
69824@@ -50,7 +50,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
69825 #define div64_long(x,y) div_s64((x),(y))
69826
69827 #ifndef div_u64_rem
69828-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69829+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
69830 {
69831 *remainder = do_div(dividend, divisor);
69832 return dividend;
69833@@ -79,7 +79,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
69834 * divide.
69835 */
69836 #ifndef div_u64
69837-static inline u64 div_u64(u64 dividend, u32 divisor)
69838+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
69839 {
69840 u32 remainder;
69841 return div_u64_rem(dividend, divisor, &remainder);
69842diff --git a/include/linux/mm.h b/include/linux/mm.h
69843index e2091b8..821db54 100644
69844--- a/include/linux/mm.h
69845+++ b/include/linux/mm.h
69846@@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
69847 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
69848 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
69849 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
69850+
69851+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
69852+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
69853+#endif
69854+
69855 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
69856
69857 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
69858@@ -202,8 +207,8 @@ struct vm_operations_struct {
69859 /* called by access_process_vm when get_user_pages() fails, typically
69860 * for use by special VMAs that can switch between memory and hardware
69861 */
69862- int (*access)(struct vm_area_struct *vma, unsigned long addr,
69863- void *buf, int len, int write);
69864+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
69865+ void *buf, size_t len, int write);
69866 #ifdef CONFIG_NUMA
69867 /*
69868 * set_policy() op must add a reference to any non-NULL @new mempolicy
69869@@ -233,6 +238,7 @@ struct vm_operations_struct {
69870 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
69871 unsigned long size, pgoff_t pgoff);
69872 };
69873+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
69874
69875 struct mmu_gather;
69876 struct inode;
69877@@ -970,8 +976,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
69878 unsigned long *pfn);
69879 int follow_phys(struct vm_area_struct *vma, unsigned long address,
69880 unsigned int flags, unsigned long *prot, resource_size_t *phys);
69881-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
69882- void *buf, int len, int write);
69883+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
69884+ void *buf, size_t len, int write);
69885
69886 static inline void unmap_shared_mapping_range(struct address_space *mapping,
69887 loff_t const holebegin, loff_t const holelen)
69888@@ -1010,9 +1016,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
69889 }
69890 #endif
69891
69892-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
69893-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
69894- void *buf, int len, int write);
69895+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
69896+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
69897+ void *buf, size_t len, int write);
69898
69899 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69900 unsigned long start, unsigned long nr_pages,
69901@@ -1043,34 +1049,6 @@ int set_page_dirty(struct page *page);
69902 int set_page_dirty_lock(struct page *page);
69903 int clear_page_dirty_for_io(struct page *page);
69904
69905-/* Is the vma a continuation of the stack vma above it? */
69906-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
69907-{
69908- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
69909-}
69910-
69911-static inline int stack_guard_page_start(struct vm_area_struct *vma,
69912- unsigned long addr)
69913-{
69914- return (vma->vm_flags & VM_GROWSDOWN) &&
69915- (vma->vm_start == addr) &&
69916- !vma_growsdown(vma->vm_prev, addr);
69917-}
69918-
69919-/* Is the vma a continuation of the stack vma below it? */
69920-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
69921-{
69922- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
69923-}
69924-
69925-static inline int stack_guard_page_end(struct vm_area_struct *vma,
69926- unsigned long addr)
69927-{
69928- return (vma->vm_flags & VM_GROWSUP) &&
69929- (vma->vm_end == addr) &&
69930- !vma_growsup(vma->vm_next, addr);
69931-}
69932-
69933 extern pid_t
69934 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
69935
69936@@ -1173,6 +1151,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
69937 }
69938 #endif
69939
69940+#ifdef CONFIG_MMU
69941+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
69942+#else
69943+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
69944+{
69945+ return __pgprot(0);
69946+}
69947+#endif
69948+
69949 int vma_wants_writenotify(struct vm_area_struct *vma);
69950
69951 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
69952@@ -1191,8 +1178,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
69953 {
69954 return 0;
69955 }
69956+
69957+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
69958+ unsigned long address)
69959+{
69960+ return 0;
69961+}
69962 #else
69963 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
69964+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
69965 #endif
69966
69967 #ifdef __PAGETABLE_PMD_FOLDED
69968@@ -1201,8 +1195,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
69969 {
69970 return 0;
69971 }
69972+
69973+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
69974+ unsigned long address)
69975+{
69976+ return 0;
69977+}
69978 #else
69979 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
69980+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
69981 #endif
69982
69983 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
69984@@ -1220,11 +1221,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
69985 NULL: pud_offset(pgd, address);
69986 }
69987
69988+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
69989+{
69990+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
69991+ NULL: pud_offset(pgd, address);
69992+}
69993+
69994 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
69995 {
69996 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
69997 NULL: pmd_offset(pud, address);
69998 }
69999+
70000+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
70001+{
70002+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
70003+ NULL: pmd_offset(pud, address);
70004+}
70005 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
70006
70007 #if USE_SPLIT_PTLOCKS
70008@@ -1455,6 +1468,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70009 unsigned long len, unsigned long prot, unsigned long flags,
70010 unsigned long pgoff, unsigned long *populate);
70011 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
70012+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
70013
70014 #ifdef CONFIG_MMU
70015 extern int __mm_populate(unsigned long addr, unsigned long len,
70016@@ -1483,6 +1497,7 @@ struct vm_unmapped_area_info {
70017 unsigned long high_limit;
70018 unsigned long align_mask;
70019 unsigned long align_offset;
70020+ unsigned long threadstack_offset;
70021 };
70022
70023 extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
70024@@ -1561,6 +1576,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
70025 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
70026 struct vm_area_struct **pprev);
70027
70028+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
70029+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
70030+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
70031+
70032 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
70033 NULL if none. Assume start_addr < end_addr. */
70034 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
70035@@ -1589,15 +1608,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
70036 return vma;
70037 }
70038
70039-#ifdef CONFIG_MMU
70040-pgprot_t vm_get_page_prot(unsigned long vm_flags);
70041-#else
70042-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
70043-{
70044- return __pgprot(0);
70045-}
70046-#endif
70047-
70048 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
70049 unsigned long change_prot_numa(struct vm_area_struct *vma,
70050 unsigned long start, unsigned long end);
70051@@ -1649,6 +1659,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
70052 static inline void vm_stat_account(struct mm_struct *mm,
70053 unsigned long flags, struct file *file, long pages)
70054 {
70055+
70056+#ifdef CONFIG_PAX_RANDMMAP
70057+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
70058+#endif
70059+
70060 mm->total_vm += pages;
70061 }
70062 #endif /* CONFIG_PROC_FS */
70063@@ -1725,7 +1740,7 @@ extern int unpoison_memory(unsigned long pfn);
70064 extern int sysctl_memory_failure_early_kill;
70065 extern int sysctl_memory_failure_recovery;
70066 extern void shake_page(struct page *p, int access);
70067-extern atomic_long_t num_poisoned_pages;
70068+extern atomic_long_unchecked_t num_poisoned_pages;
70069 extern int soft_offline_page(struct page *page, int flags);
70070
70071 extern void dump_page(struct page *page);
70072@@ -1756,5 +1771,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
70073 static inline bool page_is_guard(struct page *page) { return false; }
70074 #endif /* CONFIG_DEBUG_PAGEALLOC */
70075
70076+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
70077+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
70078+#else
70079+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
70080+#endif
70081+
70082 #endif /* __KERNEL__ */
70083 #endif /* _LINUX_MM_H */
70084diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
70085index ace9a5f..81bdb59 100644
70086--- a/include/linux/mm_types.h
70087+++ b/include/linux/mm_types.h
70088@@ -289,6 +289,8 @@ struct vm_area_struct {
70089 #ifdef CONFIG_NUMA
70090 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
70091 #endif
70092+
70093+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
70094 };
70095
70096 struct core_thread {
70097@@ -437,6 +439,24 @@ struct mm_struct {
70098 int first_nid;
70099 #endif
70100 struct uprobes_state uprobes_state;
70101+
70102+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
70103+ unsigned long pax_flags;
70104+#endif
70105+
70106+#ifdef CONFIG_PAX_DLRESOLVE
70107+ unsigned long call_dl_resolve;
70108+#endif
70109+
70110+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
70111+ unsigned long call_syscall;
70112+#endif
70113+
70114+#ifdef CONFIG_PAX_ASLR
70115+ unsigned long delta_mmap; /* randomized offset */
70116+ unsigned long delta_stack; /* randomized offset */
70117+#endif
70118+
70119 };
70120
70121 /* first nid will either be a valid NID or one of these values */
70122diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
70123index c5d5278..f0b68c8 100644
70124--- a/include/linux/mmiotrace.h
70125+++ b/include/linux/mmiotrace.h
70126@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
70127 /* Called from ioremap.c */
70128 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
70129 void __iomem *addr);
70130-extern void mmiotrace_iounmap(volatile void __iomem *addr);
70131+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
70132
70133 /* For anyone to insert markers. Remember trailing newline. */
70134 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
70135@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
70136 {
70137 }
70138
70139-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
70140+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
70141 {
70142 }
70143
70144diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
70145index c74092e..b663967 100644
70146--- a/include/linux/mmzone.h
70147+++ b/include/linux/mmzone.h
70148@@ -396,7 +396,7 @@ struct zone {
70149 unsigned long flags; /* zone flags, see below */
70150
70151 /* Zone statistics */
70152- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70153+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70154
70155 /*
70156 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
70157diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
70158index 779cf7c..e6768240 100644
70159--- a/include/linux/mod_devicetable.h
70160+++ b/include/linux/mod_devicetable.h
70161@@ -12,7 +12,7 @@
70162 typedef unsigned long kernel_ulong_t;
70163 #endif
70164
70165-#define PCI_ANY_ID (~0)
70166+#define PCI_ANY_ID ((__u16)~0)
70167
70168 struct pci_device_id {
70169 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
70170@@ -138,7 +138,7 @@ struct usb_device_id {
70171 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
70172 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
70173
70174-#define HID_ANY_ID (~0)
70175+#define HID_ANY_ID (~0U)
70176 #define HID_BUS_ANY 0xffff
70177 #define HID_GROUP_ANY 0x0000
70178
70179@@ -464,7 +464,7 @@ struct dmi_system_id {
70180 const char *ident;
70181 struct dmi_strmatch matches[4];
70182 void *driver_data;
70183-};
70184+} __do_const;
70185 /*
70186 * struct dmi_device_id appears during expansion of
70187 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
70188diff --git a/include/linux/module.h b/include/linux/module.h
70189index ead1b57..81a3b6c 100644
70190--- a/include/linux/module.h
70191+++ b/include/linux/module.h
70192@@ -17,9 +17,11 @@
70193 #include <linux/moduleparam.h>
70194 #include <linux/tracepoint.h>
70195 #include <linux/export.h>
70196+#include <linux/fs.h>
70197
70198 #include <linux/percpu.h>
70199 #include <asm/module.h>
70200+#include <asm/pgtable.h>
70201
70202 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
70203 #define MODULE_SIG_STRING "~Module signature appended~\n"
70204@@ -54,12 +56,13 @@ struct module_attribute {
70205 int (*test)(struct module *);
70206 void (*free)(struct module *);
70207 };
70208+typedef struct module_attribute __no_const module_attribute_no_const;
70209
70210 struct module_version_attribute {
70211 struct module_attribute mattr;
70212 const char *module_name;
70213 const char *version;
70214-} __attribute__ ((__aligned__(sizeof(void *))));
70215+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
70216
70217 extern ssize_t __modver_version_show(struct module_attribute *,
70218 struct module_kobject *, char *);
70219@@ -232,7 +235,7 @@ struct module
70220
70221 /* Sysfs stuff. */
70222 struct module_kobject mkobj;
70223- struct module_attribute *modinfo_attrs;
70224+ module_attribute_no_const *modinfo_attrs;
70225 const char *version;
70226 const char *srcversion;
70227 struct kobject *holders_dir;
70228@@ -281,19 +284,16 @@ struct module
70229 int (*init)(void);
70230
70231 /* If this is non-NULL, vfree after init() returns */
70232- void *module_init;
70233+ void *module_init_rx, *module_init_rw;
70234
70235 /* Here is the actual code + data, vfree'd on unload. */
70236- void *module_core;
70237+ void *module_core_rx, *module_core_rw;
70238
70239 /* Here are the sizes of the init and core sections */
70240- unsigned int init_size, core_size;
70241+ unsigned int init_size_rw, core_size_rw;
70242
70243 /* The size of the executable code in each section. */
70244- unsigned int init_text_size, core_text_size;
70245-
70246- /* Size of RO sections of the module (text+rodata) */
70247- unsigned int init_ro_size, core_ro_size;
70248+ unsigned int init_size_rx, core_size_rx;
70249
70250 /* Arch-specific module values */
70251 struct mod_arch_specific arch;
70252@@ -349,6 +349,10 @@ struct module
70253 #ifdef CONFIG_EVENT_TRACING
70254 struct ftrace_event_call **trace_events;
70255 unsigned int num_trace_events;
70256+ struct file_operations trace_id;
70257+ struct file_operations trace_enable;
70258+ struct file_operations trace_format;
70259+ struct file_operations trace_filter;
70260 #endif
70261 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
70262 unsigned int num_ftrace_callsites;
70263@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
70264 bool is_module_percpu_address(unsigned long addr);
70265 bool is_module_text_address(unsigned long addr);
70266
70267+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
70268+{
70269+
70270+#ifdef CONFIG_PAX_KERNEXEC
70271+ if (ktla_ktva(addr) >= (unsigned long)start &&
70272+ ktla_ktva(addr) < (unsigned long)start + size)
70273+ return 1;
70274+#endif
70275+
70276+ return ((void *)addr >= start && (void *)addr < start + size);
70277+}
70278+
70279+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
70280+{
70281+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
70282+}
70283+
70284+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
70285+{
70286+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
70287+}
70288+
70289+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
70290+{
70291+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
70292+}
70293+
70294+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
70295+{
70296+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
70297+}
70298+
70299 static inline int within_module_core(unsigned long addr, const struct module *mod)
70300 {
70301- return (unsigned long)mod->module_core <= addr &&
70302- addr < (unsigned long)mod->module_core + mod->core_size;
70303+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
70304 }
70305
70306 static inline int within_module_init(unsigned long addr, const struct module *mod)
70307 {
70308- return (unsigned long)mod->module_init <= addr &&
70309- addr < (unsigned long)mod->module_init + mod->init_size;
70310+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
70311 }
70312
70313 /* Search for module by name: must hold module_mutex. */
70314diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
70315index 560ca53..ef621ef 100644
70316--- a/include/linux/moduleloader.h
70317+++ b/include/linux/moduleloader.h
70318@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
70319 sections. Returns NULL on failure. */
70320 void *module_alloc(unsigned long size);
70321
70322+#ifdef CONFIG_PAX_KERNEXEC
70323+void *module_alloc_exec(unsigned long size);
70324+#else
70325+#define module_alloc_exec(x) module_alloc(x)
70326+#endif
70327+
70328 /* Free memory returned from module_alloc. */
70329 void module_free(struct module *mod, void *module_region);
70330
70331+#ifdef CONFIG_PAX_KERNEXEC
70332+void module_free_exec(struct module *mod, void *module_region);
70333+#else
70334+#define module_free_exec(x, y) module_free((x), (y))
70335+#endif
70336+
70337 /*
70338 * Apply the given relocation to the (simplified) ELF. Return -error
70339 * or 0.
70340@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
70341 unsigned int relsec,
70342 struct module *me)
70343 {
70344+#ifdef CONFIG_MODULES
70345 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
70346+#endif
70347 return -ENOEXEC;
70348 }
70349 #endif
70350@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
70351 unsigned int relsec,
70352 struct module *me)
70353 {
70354+#ifdef CONFIG_MODULES
70355 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
70356+#endif
70357 return -ENOEXEC;
70358 }
70359 #endif
70360diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
70361index 137b419..fe663ec 100644
70362--- a/include/linux/moduleparam.h
70363+++ b/include/linux/moduleparam.h
70364@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
70365 * @len is usually just sizeof(string).
70366 */
70367 #define module_param_string(name, string, len, perm) \
70368- static const struct kparam_string __param_string_##name \
70369+ static const struct kparam_string __param_string_##name __used \
70370 = { len, string }; \
70371 __module_param_call(MODULE_PARAM_PREFIX, name, \
70372 &param_ops_string, \
70373@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
70374 */
70375 #define module_param_array_named(name, array, type, nump, perm) \
70376 param_check_##type(name, &(array)[0]); \
70377- static const struct kparam_array __param_arr_##name \
70378+ static const struct kparam_array __param_arr_##name __used \
70379 = { .max = ARRAY_SIZE(array), .num = nump, \
70380 .ops = &param_ops_##type, \
70381 .elemsize = sizeof(array[0]), .elem = array }; \
70382diff --git a/include/linux/namei.h b/include/linux/namei.h
70383index 5a5ff57..5ae5070 100644
70384--- a/include/linux/namei.h
70385+++ b/include/linux/namei.h
70386@@ -19,7 +19,7 @@ struct nameidata {
70387 unsigned seq;
70388 int last_type;
70389 unsigned depth;
70390- char *saved_names[MAX_NESTED_LINKS + 1];
70391+ const char *saved_names[MAX_NESTED_LINKS + 1];
70392 };
70393
70394 /*
70395@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
70396
70397 extern void nd_jump_link(struct nameidata *nd, struct path *path);
70398
70399-static inline void nd_set_link(struct nameidata *nd, char *path)
70400+static inline void nd_set_link(struct nameidata *nd, const char *path)
70401 {
70402 nd->saved_names[nd->depth] = path;
70403 }
70404
70405-static inline char *nd_get_link(struct nameidata *nd)
70406+static inline const char *nd_get_link(const struct nameidata *nd)
70407 {
70408 return nd->saved_names[nd->depth];
70409 }
70410diff --git a/include/linux/net.h b/include/linux/net.h
70411index aa16731..514b875 100644
70412--- a/include/linux/net.h
70413+++ b/include/linux/net.h
70414@@ -183,7 +183,7 @@ struct net_proto_family {
70415 int (*create)(struct net *net, struct socket *sock,
70416 int protocol, int kern);
70417 struct module *owner;
70418-};
70419+} __do_const;
70420
70421 struct iovec;
70422 struct kvec;
70423diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
70424index 6151e90..2e0afb0 100644
70425--- a/include/linux/netdevice.h
70426+++ b/include/linux/netdevice.h
70427@@ -1028,6 +1028,7 @@ struct net_device_ops {
70428 int (*ndo_change_carrier)(struct net_device *dev,
70429 bool new_carrier);
70430 };
70431+typedef struct net_device_ops __no_const net_device_ops_no_const;
70432
70433 /*
70434 * The DEVICE structure.
70435@@ -1094,7 +1095,7 @@ struct net_device {
70436 int iflink;
70437
70438 struct net_device_stats stats;
70439- atomic_long_t rx_dropped; /* dropped packets by core network
70440+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
70441 * Do not use this in drivers.
70442 */
70443
70444diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
70445index ee14284..bc65d63 100644
70446--- a/include/linux/netfilter.h
70447+++ b/include/linux/netfilter.h
70448@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
70449 #endif
70450 /* Use the module struct to lock set/get code in place */
70451 struct module *owner;
70452-};
70453+} __do_const;
70454
70455 /* Function to register/unregister hook points. */
70456 int nf_register_hook(struct nf_hook_ops *reg);
70457diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
70458index 7958e84..ed74d7a 100644
70459--- a/include/linux/netfilter/ipset/ip_set.h
70460+++ b/include/linux/netfilter/ipset/ip_set.h
70461@@ -98,7 +98,7 @@ struct ip_set_type_variant {
70462 /* Return true if "b" set is the same as "a"
70463 * according to the create set parameters */
70464 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
70465-};
70466+} __do_const;
70467
70468 /* The core set type structure */
70469 struct ip_set_type {
70470diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
70471index ecbb8e4..8a1c4e1 100644
70472--- a/include/linux/netfilter/nfnetlink.h
70473+++ b/include/linux/netfilter/nfnetlink.h
70474@@ -16,7 +16,7 @@ struct nfnl_callback {
70475 const struct nlattr * const cda[]);
70476 const struct nla_policy *policy; /* netlink attribute policy */
70477 const u_int16_t attr_count; /* number of nlattr's */
70478-};
70479+} __do_const;
70480
70481 struct nfnetlink_subsystem {
70482 const char *name;
70483diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
70484new file mode 100644
70485index 0000000..33f4af8
70486--- /dev/null
70487+++ b/include/linux/netfilter/xt_gradm.h
70488@@ -0,0 +1,9 @@
70489+#ifndef _LINUX_NETFILTER_XT_GRADM_H
70490+#define _LINUX_NETFILTER_XT_GRADM_H 1
70491+
70492+struct xt_gradm_mtinfo {
70493+ __u16 flags;
70494+ __u16 invflags;
70495+};
70496+
70497+#endif
70498diff --git a/include/linux/nls.h b/include/linux/nls.h
70499index 5dc635f..35f5e11 100644
70500--- a/include/linux/nls.h
70501+++ b/include/linux/nls.h
70502@@ -31,7 +31,7 @@ struct nls_table {
70503 const unsigned char *charset2upper;
70504 struct module *owner;
70505 struct nls_table *next;
70506-};
70507+} __do_const;
70508
70509 /* this value hold the maximum octet of charset */
70510 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
70511diff --git a/include/linux/notifier.h b/include/linux/notifier.h
70512index d65746e..62e72c2 100644
70513--- a/include/linux/notifier.h
70514+++ b/include/linux/notifier.h
70515@@ -51,7 +51,8 @@ struct notifier_block {
70516 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
70517 struct notifier_block __rcu *next;
70518 int priority;
70519-};
70520+} __do_const;
70521+typedef struct notifier_block __no_const notifier_block_no_const;
70522
70523 struct atomic_notifier_head {
70524 spinlock_t lock;
70525diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
70526index a4c5624..79d6d88 100644
70527--- a/include/linux/oprofile.h
70528+++ b/include/linux/oprofile.h
70529@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
70530 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
70531 char const * name, ulong * val);
70532
70533-/** Create a file for read-only access to an atomic_t. */
70534+/** Create a file for read-only access to an atomic_unchecked_t. */
70535 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
70536- char const * name, atomic_t * val);
70537+ char const * name, atomic_unchecked_t * val);
70538
70539 /** create a directory */
70540 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
70541diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
70542index 45fc162..01a4068 100644
70543--- a/include/linux/pci_hotplug.h
70544+++ b/include/linux/pci_hotplug.h
70545@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
70546 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
70547 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
70548 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
70549-};
70550+} __do_const;
70551+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
70552
70553 /**
70554 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
70555diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
70556index 1d795df..b0a6449 100644
70557--- a/include/linux/perf_event.h
70558+++ b/include/linux/perf_event.h
70559@@ -333,8 +333,8 @@ struct perf_event {
70560
70561 enum perf_event_active_state state;
70562 unsigned int attach_state;
70563- local64_t count;
70564- atomic64_t child_count;
70565+ local64_t count; /* PaX: fix it one day */
70566+ atomic64_unchecked_t child_count;
70567
70568 /*
70569 * These are the total time in nanoseconds that the event
70570@@ -385,8 +385,8 @@ struct perf_event {
70571 * These accumulate total time (in nanoseconds) that children
70572 * events have been enabled and running, respectively.
70573 */
70574- atomic64_t child_total_time_enabled;
70575- atomic64_t child_total_time_running;
70576+ atomic64_unchecked_t child_total_time_enabled;
70577+ atomic64_unchecked_t child_total_time_running;
70578
70579 /*
70580 * Protect attach/detach and child_list:
70581@@ -704,7 +704,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
70582 entry->ip[entry->nr++] = ip;
70583 }
70584
70585-extern int sysctl_perf_event_paranoid;
70586+extern int sysctl_perf_event_legitimately_concerned;
70587 extern int sysctl_perf_event_mlock;
70588 extern int sysctl_perf_event_sample_rate;
70589
70590@@ -712,19 +712,24 @@ extern int perf_proc_update_handler(struct ctl_table *table, int write,
70591 void __user *buffer, size_t *lenp,
70592 loff_t *ppos);
70593
70594+static inline bool perf_paranoid_any(void)
70595+{
70596+ return sysctl_perf_event_legitimately_concerned > 2;
70597+}
70598+
70599 static inline bool perf_paranoid_tracepoint_raw(void)
70600 {
70601- return sysctl_perf_event_paranoid > -1;
70602+ return sysctl_perf_event_legitimately_concerned > -1;
70603 }
70604
70605 static inline bool perf_paranoid_cpu(void)
70606 {
70607- return sysctl_perf_event_paranoid > 0;
70608+ return sysctl_perf_event_legitimately_concerned > 0;
70609 }
70610
70611 static inline bool perf_paranoid_kernel(void)
70612 {
70613- return sysctl_perf_event_paranoid > 1;
70614+ return sysctl_perf_event_legitimately_concerned > 1;
70615 }
70616
70617 extern void perf_event_init(void);
70618@@ -812,7 +817,7 @@ static inline void perf_restore_debug_store(void) { }
70619 */
70620 #define perf_cpu_notifier(fn) \
70621 do { \
70622- static struct notifier_block fn##_nb __cpuinitdata = \
70623+ static struct notifier_block fn##_nb = \
70624 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
70625 unsigned long cpu = smp_processor_id(); \
70626 unsigned long flags; \
70627@@ -831,7 +836,7 @@ do { \
70628 struct perf_pmu_events_attr {
70629 struct device_attribute attr;
70630 u64 id;
70631-};
70632+} __do_const;
70633
70634 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
70635 static struct perf_pmu_events_attr _var = { \
70636diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
70637index ad1a427..6419649 100644
70638--- a/include/linux/pipe_fs_i.h
70639+++ b/include/linux/pipe_fs_i.h
70640@@ -45,9 +45,9 @@ struct pipe_buffer {
70641 struct pipe_inode_info {
70642 wait_queue_head_t wait;
70643 unsigned int nrbufs, curbuf, buffers;
70644- unsigned int readers;
70645- unsigned int writers;
70646- unsigned int waiting_writers;
70647+ atomic_t readers;
70648+ atomic_t writers;
70649+ atomic_t waiting_writers;
70650 unsigned int r_counter;
70651 unsigned int w_counter;
70652 struct page *tmp_page;
70653diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
70654index 5f28cae..3d23723 100644
70655--- a/include/linux/platform_data/usb-ehci-s5p.h
70656+++ b/include/linux/platform_data/usb-ehci-s5p.h
70657@@ -14,7 +14,7 @@
70658 struct s5p_ehci_platdata {
70659 int (*phy_init)(struct platform_device *pdev, int type);
70660 int (*phy_exit)(struct platform_device *pdev, int type);
70661-};
70662+} __no_const;
70663
70664 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
70665
70666diff --git a/include/linux/platform_data/usb-exynos.h b/include/linux/platform_data/usb-exynos.h
70667index c256c59..8ea94c7 100644
70668--- a/include/linux/platform_data/usb-exynos.h
70669+++ b/include/linux/platform_data/usb-exynos.h
70670@@ -14,7 +14,7 @@
70671 struct exynos4_ohci_platdata {
70672 int (*phy_init)(struct platform_device *pdev, int type);
70673 int (*phy_exit)(struct platform_device *pdev, int type);
70674-};
70675+} __no_const;
70676
70677 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
70678
70679diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
70680index 7c1d252..c5c773e 100644
70681--- a/include/linux/pm_domain.h
70682+++ b/include/linux/pm_domain.h
70683@@ -48,7 +48,7 @@ struct gpd_dev_ops {
70684
70685 struct gpd_cpu_data {
70686 unsigned int saved_exit_latency;
70687- struct cpuidle_state *idle_state;
70688+ cpuidle_state_no_const *idle_state;
70689 };
70690
70691 struct generic_pm_domain {
70692diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
70693index 7d7e09e..8671ef8 100644
70694--- a/include/linux/pm_runtime.h
70695+++ b/include/linux/pm_runtime.h
70696@@ -104,7 +104,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
70697
70698 static inline void pm_runtime_mark_last_busy(struct device *dev)
70699 {
70700- ACCESS_ONCE(dev->power.last_busy) = jiffies;
70701+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
70702 }
70703
70704 #else /* !CONFIG_PM_RUNTIME */
70705diff --git a/include/linux/pnp.h b/include/linux/pnp.h
70706index 195aafc..49a7bc2 100644
70707--- a/include/linux/pnp.h
70708+++ b/include/linux/pnp.h
70709@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
70710 struct pnp_fixup {
70711 char id[7];
70712 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
70713-};
70714+} __do_const;
70715
70716 /* config parameters */
70717 #define PNP_CONFIG_NORMAL 0x0001
70718diff --git a/include/linux/poison.h b/include/linux/poison.h
70719index 2110a81..13a11bb 100644
70720--- a/include/linux/poison.h
70721+++ b/include/linux/poison.h
70722@@ -19,8 +19,8 @@
70723 * under normal circumstances, used to verify that nobody uses
70724 * non-initialized list entries.
70725 */
70726-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
70727-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
70728+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
70729+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
70730
70731 /********** include/linux/timer.h **********/
70732 /*
70733diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
70734index c0f44c2..1572583 100644
70735--- a/include/linux/power/smartreflex.h
70736+++ b/include/linux/power/smartreflex.h
70737@@ -238,7 +238,7 @@ struct omap_sr_class_data {
70738 int (*notify)(struct omap_sr *sr, u32 status);
70739 u8 notify_flags;
70740 u8 class_type;
70741-};
70742+} __do_const;
70743
70744 /**
70745 * struct omap_sr_nvalue_table - Smartreflex n-target value info
70746diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
70747index 4ea1d37..80f4b33 100644
70748--- a/include/linux/ppp-comp.h
70749+++ b/include/linux/ppp-comp.h
70750@@ -84,7 +84,7 @@ struct compressor {
70751 struct module *owner;
70752 /* Extra skb space needed by the compressor algorithm */
70753 unsigned int comp_extra;
70754-};
70755+} __do_const;
70756
70757 /*
70758 * The return value from decompress routine is the length of the
70759diff --git a/include/linux/printk.h b/include/linux/printk.h
70760index 822171f..12b30e8 100644
70761--- a/include/linux/printk.h
70762+++ b/include/linux/printk.h
70763@@ -98,6 +98,8 @@ int no_printk(const char *fmt, ...)
70764 extern asmlinkage __printf(1, 2)
70765 void early_printk(const char *fmt, ...);
70766
70767+extern int kptr_restrict;
70768+
70769 #ifdef CONFIG_PRINTK
70770 asmlinkage __printf(5, 0)
70771 int vprintk_emit(int facility, int level,
70772@@ -132,7 +134,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
70773
70774 extern int printk_delay_msec;
70775 extern int dmesg_restrict;
70776-extern int kptr_restrict;
70777
70778 extern void wake_up_klogd(void);
70779
70780diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
70781index 94dfb2a..88b9d3b 100644
70782--- a/include/linux/proc_fs.h
70783+++ b/include/linux/proc_fs.h
70784@@ -165,6 +165,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
70785 return proc_create_data(name, mode, parent, proc_fops, NULL);
70786 }
70787
70788+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
70789+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
70790+{
70791+#ifdef CONFIG_GRKERNSEC_PROC_USER
70792+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
70793+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70794+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
70795+#else
70796+ return proc_create_data(name, mode, parent, proc_fops, NULL);
70797+#endif
70798+}
70799+
70800 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
70801 umode_t mode, struct proc_dir_entry *base,
70802 read_proc_t *read_proc, void * data)
70803@@ -266,7 +278,7 @@ struct proc_ns_operations {
70804 void (*put)(void *ns);
70805 int (*install)(struct nsproxy *nsproxy, void *ns);
70806 unsigned int (*inum)(void *ns);
70807-};
70808+} __do_const;
70809 extern const struct proc_ns_operations netns_operations;
70810 extern const struct proc_ns_operations utsns_operations;
70811 extern const struct proc_ns_operations ipcns_operations;
70812diff --git a/include/linux/random.h b/include/linux/random.h
70813index 347ce55..880f97c 100644
70814--- a/include/linux/random.h
70815+++ b/include/linux/random.h
70816@@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
70817 u32 prandom_u32_state(struct rnd_state *);
70818 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
70819
70820+static inline unsigned long pax_get_random_long(void)
70821+{
70822+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
70823+}
70824+
70825 /*
70826 * Handle minimum values for seeds
70827 */
70828diff --git a/include/linux/rculist.h b/include/linux/rculist.h
70829index 8089e35..3a0d59a 100644
70830--- a/include/linux/rculist.h
70831+++ b/include/linux/rculist.h
70832@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
70833 struct list_head *prev, struct list_head *next);
70834 #endif
70835
70836+extern void __pax_list_add_rcu(struct list_head *new,
70837+ struct list_head *prev, struct list_head *next);
70838+
70839 /**
70840 * list_add_rcu - add a new entry to rcu-protected list
70841 * @new: new entry to be added
70842@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
70843 __list_add_rcu(new, head, head->next);
70844 }
70845
70846+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
70847+{
70848+ __pax_list_add_rcu(new, head, head->next);
70849+}
70850+
70851 /**
70852 * list_add_tail_rcu - add a new entry to rcu-protected list
70853 * @new: new entry to be added
70854@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
70855 __list_add_rcu(new, head->prev, head);
70856 }
70857
70858+static inline void pax_list_add_tail_rcu(struct list_head *new,
70859+ struct list_head *head)
70860+{
70861+ __pax_list_add_rcu(new, head->prev, head);
70862+}
70863+
70864 /**
70865 * list_del_rcu - deletes entry from list without re-initialization
70866 * @entry: the element to delete from the list.
70867@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
70868 entry->prev = LIST_POISON2;
70869 }
70870
70871+extern void pax_list_del_rcu(struct list_head *entry);
70872+
70873 /**
70874 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
70875 * @n: the element to delete from the hash list.
70876diff --git a/include/linux/reboot.h b/include/linux/reboot.h
70877index 23b3630..e1bc12b 100644
70878--- a/include/linux/reboot.h
70879+++ b/include/linux/reboot.h
70880@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
70881 * Architecture-specific implementations of sys_reboot commands.
70882 */
70883
70884-extern void machine_restart(char *cmd);
70885-extern void machine_halt(void);
70886-extern void machine_power_off(void);
70887+extern void machine_restart(char *cmd) __noreturn;
70888+extern void machine_halt(void) __noreturn;
70889+extern void machine_power_off(void) __noreturn;
70890
70891 extern void machine_shutdown(void);
70892 struct pt_regs;
70893@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
70894 */
70895
70896 extern void kernel_restart_prepare(char *cmd);
70897-extern void kernel_restart(char *cmd);
70898-extern void kernel_halt(void);
70899-extern void kernel_power_off(void);
70900+extern void kernel_restart(char *cmd) __noreturn;
70901+extern void kernel_halt(void) __noreturn;
70902+extern void kernel_power_off(void) __noreturn;
70903
70904 extern int C_A_D; /* for sysctl */
70905 void ctrl_alt_del(void);
70906@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
70907 * Emergency restart, callable from an interrupt handler.
70908 */
70909
70910-extern void emergency_restart(void);
70911+extern void emergency_restart(void) __noreturn;
70912 #include <asm/emergency-restart.h>
70913
70914 #endif /* _LINUX_REBOOT_H */
70915diff --git a/include/linux/regset.h b/include/linux/regset.h
70916index 8e0c9fe..ac4d221 100644
70917--- a/include/linux/regset.h
70918+++ b/include/linux/regset.h
70919@@ -161,7 +161,8 @@ struct user_regset {
70920 unsigned int align;
70921 unsigned int bias;
70922 unsigned int core_note_type;
70923-};
70924+} __do_const;
70925+typedef struct user_regset __no_const user_regset_no_const;
70926
70927 /**
70928 * struct user_regset_view - available regsets
70929diff --git a/include/linux/relay.h b/include/linux/relay.h
70930index 91cacc3..b55ff74 100644
70931--- a/include/linux/relay.h
70932+++ b/include/linux/relay.h
70933@@ -160,7 +160,7 @@ struct rchan_callbacks
70934 * The callback should return 0 if successful, negative if not.
70935 */
70936 int (*remove_buf_file)(struct dentry *dentry);
70937-};
70938+} __no_const;
70939
70940 /*
70941 * CONFIG_RELAY kernel API, kernel/relay.c
70942diff --git a/include/linux/rio.h b/include/linux/rio.h
70943index a3e7842..d973ca6 100644
70944--- a/include/linux/rio.h
70945+++ b/include/linux/rio.h
70946@@ -339,7 +339,7 @@ struct rio_ops {
70947 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
70948 u64 rstart, u32 size, u32 flags);
70949 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
70950-};
70951+} __no_const;
70952
70953 #define RIO_RESOURCE_MEM 0x00000100
70954 #define RIO_RESOURCE_DOORBELL 0x00000200
70955diff --git a/include/linux/rmap.h b/include/linux/rmap.h
70956index 6dacb93..6174423 100644
70957--- a/include/linux/rmap.h
70958+++ b/include/linux/rmap.h
70959@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
70960 void anon_vma_init(void); /* create anon_vma_cachep */
70961 int anon_vma_prepare(struct vm_area_struct *);
70962 void unlink_anon_vmas(struct vm_area_struct *);
70963-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
70964-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
70965+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
70966+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
70967
70968 static inline void anon_vma_merge(struct vm_area_struct *vma,
70969 struct vm_area_struct *next)
70970diff --git a/include/linux/sched.h b/include/linux/sched.h
70971index be4e742..7f9d593 100644
70972--- a/include/linux/sched.h
70973+++ b/include/linux/sched.h
70974@@ -62,6 +62,7 @@ struct bio_list;
70975 struct fs_struct;
70976 struct perf_event_context;
70977 struct blk_plug;
70978+struct linux_binprm;
70979
70980 /*
70981 * List of flags we want to share for kernel threads,
70982@@ -315,7 +316,7 @@ extern char __sched_text_start[], __sched_text_end[];
70983 extern int in_sched_functions(unsigned long addr);
70984
70985 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
70986-extern signed long schedule_timeout(signed long timeout);
70987+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
70988 extern signed long schedule_timeout_interruptible(signed long timeout);
70989 extern signed long schedule_timeout_killable(signed long timeout);
70990 extern signed long schedule_timeout_uninterruptible(signed long timeout);
70991@@ -329,6 +330,18 @@ struct user_namespace;
70992 #include <linux/aio.h>
70993
70994 #ifdef CONFIG_MMU
70995+
70996+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
70997+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
70998+#else
70999+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
71000+{
71001+ return 0;
71002+}
71003+#endif
71004+
71005+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
71006+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
71007 extern void arch_pick_mmap_layout(struct mm_struct *mm);
71008 extern unsigned long
71009 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
71010@@ -605,6 +618,17 @@ struct signal_struct {
71011 #ifdef CONFIG_TASKSTATS
71012 struct taskstats *stats;
71013 #endif
71014+
71015+#ifdef CONFIG_GRKERNSEC
71016+ u32 curr_ip;
71017+ u32 saved_ip;
71018+ u32 gr_saddr;
71019+ u32 gr_daddr;
71020+ u16 gr_sport;
71021+ u16 gr_dport;
71022+ u8 used_accept:1;
71023+#endif
71024+
71025 #ifdef CONFIG_AUDIT
71026 unsigned audit_tty;
71027 struct tty_audit_buf *tty_audit_buf;
71028@@ -683,6 +707,11 @@ struct user_struct {
71029 struct key *session_keyring; /* UID's default session keyring */
71030 #endif
71031
71032+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
71033+ unsigned int banned;
71034+ unsigned long ban_expires;
71035+#endif
71036+
71037 /* Hash table maintenance information */
71038 struct hlist_node uidhash_node;
71039 kuid_t uid;
71040@@ -1082,7 +1111,7 @@ struct sched_class {
71041 #ifdef CONFIG_FAIR_GROUP_SCHED
71042 void (*task_move_group) (struct task_struct *p, int on_rq);
71043 #endif
71044-};
71045+} __do_const;
71046
71047 struct load_weight {
71048 unsigned long weight, inv_weight;
71049@@ -1323,8 +1352,8 @@ struct task_struct {
71050 struct list_head thread_group;
71051
71052 struct completion *vfork_done; /* for vfork() */
71053- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
71054- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
71055+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
71056+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
71057
71058 cputime_t utime, stime, utimescaled, stimescaled;
71059 cputime_t gtime;
71060@@ -1349,11 +1378,6 @@ struct task_struct {
71061 struct task_cputime cputime_expires;
71062 struct list_head cpu_timers[3];
71063
71064-/* process credentials */
71065- const struct cred __rcu *real_cred; /* objective and real subjective task
71066- * credentials (COW) */
71067- const struct cred __rcu *cred; /* effective (overridable) subjective task
71068- * credentials (COW) */
71069 char comm[TASK_COMM_LEN]; /* executable name excluding path
71070 - access with [gs]et_task_comm (which lock
71071 it with task_lock())
71072@@ -1370,6 +1394,10 @@ struct task_struct {
71073 #endif
71074 /* CPU-specific state of this task */
71075 struct thread_struct thread;
71076+/* thread_info moved to task_struct */
71077+#ifdef CONFIG_X86
71078+ struct thread_info tinfo;
71079+#endif
71080 /* filesystem information */
71081 struct fs_struct *fs;
71082 /* open file information */
71083@@ -1443,6 +1471,10 @@ struct task_struct {
71084 gfp_t lockdep_reclaim_gfp;
71085 #endif
71086
71087+/* process credentials */
71088+ const struct cred __rcu *real_cred; /* objective and real subjective task
71089+ * credentials (COW) */
71090+
71091 /* journalling filesystem info */
71092 void *journal_info;
71093
71094@@ -1481,6 +1513,10 @@ struct task_struct {
71095 /* cg_list protected by css_set_lock and tsk->alloc_lock */
71096 struct list_head cg_list;
71097 #endif
71098+
71099+ const struct cred __rcu *cred; /* effective (overridable) subjective task
71100+ * credentials (COW) */
71101+
71102 #ifdef CONFIG_FUTEX
71103 struct robust_list_head __user *robust_list;
71104 #ifdef CONFIG_COMPAT
71105@@ -1577,8 +1613,74 @@ struct task_struct {
71106 #ifdef CONFIG_UPROBES
71107 struct uprobe_task *utask;
71108 #endif
71109+
71110+#ifdef CONFIG_GRKERNSEC
71111+ /* grsecurity */
71112+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71113+ u64 exec_id;
71114+#endif
71115+#ifdef CONFIG_GRKERNSEC_SETXID
71116+ const struct cred *delayed_cred;
71117+#endif
71118+ struct dentry *gr_chroot_dentry;
71119+ struct acl_subject_label *acl;
71120+ struct acl_role_label *role;
71121+ struct file *exec_file;
71122+ unsigned long brute_expires;
71123+ u16 acl_role_id;
71124+ /* is this the task that authenticated to the special role */
71125+ u8 acl_sp_role;
71126+ u8 is_writable;
71127+ u8 brute;
71128+ u8 gr_is_chrooted;
71129+#endif
71130+
71131 };
71132
71133+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
71134+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
71135+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
71136+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
71137+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
71138+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
71139+
71140+#ifdef CONFIG_PAX_SOFTMODE
71141+extern int pax_softmode;
71142+#endif
71143+
71144+extern int pax_check_flags(unsigned long *);
71145+
71146+/* if tsk != current then task_lock must be held on it */
71147+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
71148+static inline unsigned long pax_get_flags(struct task_struct *tsk)
71149+{
71150+ if (likely(tsk->mm))
71151+ return tsk->mm->pax_flags;
71152+ else
71153+ return 0UL;
71154+}
71155+
71156+/* if tsk != current then task_lock must be held on it */
71157+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
71158+{
71159+ if (likely(tsk->mm)) {
71160+ tsk->mm->pax_flags = flags;
71161+ return 0;
71162+ }
71163+ return -EINVAL;
71164+}
71165+#endif
71166+
71167+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
71168+extern void pax_set_initial_flags(struct linux_binprm *bprm);
71169+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
71170+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
71171+#endif
71172+
71173+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
71174+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
71175+extern void pax_report_refcount_overflow(struct pt_regs *regs);
71176+
71177 /* Future-safe accessor for struct task_struct's cpus_allowed. */
71178 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
71179
71180@@ -1637,7 +1739,7 @@ struct pid_namespace;
71181 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
71182 struct pid_namespace *ns);
71183
71184-static inline pid_t task_pid_nr(struct task_struct *tsk)
71185+static inline pid_t task_pid_nr(const struct task_struct *tsk)
71186 {
71187 return tsk->pid;
71188 }
71189@@ -2073,7 +2175,9 @@ void yield(void);
71190 extern struct exec_domain default_exec_domain;
71191
71192 union thread_union {
71193+#ifndef CONFIG_X86
71194 struct thread_info thread_info;
71195+#endif
71196 unsigned long stack[THREAD_SIZE/sizeof(long)];
71197 };
71198
71199@@ -2106,6 +2210,7 @@ extern struct pid_namespace init_pid_ns;
71200 */
71201
71202 extern struct task_struct *find_task_by_vpid(pid_t nr);
71203+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
71204 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
71205 struct pid_namespace *ns);
71206
71207@@ -2272,7 +2377,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
71208 extern void exit_itimers(struct signal_struct *);
71209 extern void flush_itimer_signals(void);
71210
71211-extern void do_group_exit(int);
71212+extern __noreturn void do_group_exit(int);
71213
71214 extern int allow_signal(int);
71215 extern int disallow_signal(int);
71216@@ -2463,9 +2568,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
71217
71218 #endif
71219
71220-static inline int object_is_on_stack(void *obj)
71221+static inline int object_starts_on_stack(void *obj)
71222 {
71223- void *stack = task_stack_page(current);
71224+ const void *stack = task_stack_page(current);
71225
71226 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
71227 }
71228diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
71229index bf8086b..962b035 100644
71230--- a/include/linux/sched/sysctl.h
71231+++ b/include/linux/sched/sysctl.h
71232@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
71233 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
71234
71235 extern int sysctl_max_map_count;
71236+extern unsigned long sysctl_heap_stack_gap;
71237
71238 extern unsigned int sysctl_sched_latency;
71239 extern unsigned int sysctl_sched_min_granularity;
71240diff --git a/include/linux/security.h b/include/linux/security.h
71241index 032c366..2c1c2dc2 100644
71242--- a/include/linux/security.h
71243+++ b/include/linux/security.h
71244@@ -26,6 +26,7 @@
71245 #include <linux/capability.h>
71246 #include <linux/slab.h>
71247 #include <linux/err.h>
71248+#include <linux/grsecurity.h>
71249
71250 struct linux_binprm;
71251 struct cred;
71252diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
71253index 68a04a3..866e6a1 100644
71254--- a/include/linux/seq_file.h
71255+++ b/include/linux/seq_file.h
71256@@ -26,6 +26,9 @@ struct seq_file {
71257 struct mutex lock;
71258 const struct seq_operations *op;
71259 int poll_event;
71260+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71261+ u64 exec_id;
71262+#endif
71263 #ifdef CONFIG_USER_NS
71264 struct user_namespace *user_ns;
71265 #endif
71266@@ -38,6 +41,7 @@ struct seq_operations {
71267 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
71268 int (*show) (struct seq_file *m, void *v);
71269 };
71270+typedef struct seq_operations __no_const seq_operations_no_const;
71271
71272 #define SEQ_SKIP 1
71273
71274diff --git a/include/linux/shm.h b/include/linux/shm.h
71275index 429c199..4d42e38 100644
71276--- a/include/linux/shm.h
71277+++ b/include/linux/shm.h
71278@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
71279
71280 /* The task created the shm object. NULL if the task is dead. */
71281 struct task_struct *shm_creator;
71282+#ifdef CONFIG_GRKERNSEC
71283+ time_t shm_createtime;
71284+ pid_t shm_lapid;
71285+#endif
71286 };
71287
71288 /* shm_mode upper byte flags */
71289diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
71290index b8292d8..96db310 100644
71291--- a/include/linux/skbuff.h
71292+++ b/include/linux/skbuff.h
71293@@ -599,7 +599,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
71294 extern struct sk_buff *__alloc_skb(unsigned int size,
71295 gfp_t priority, int flags, int node);
71296 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
71297-static inline struct sk_buff *alloc_skb(unsigned int size,
71298+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
71299 gfp_t priority)
71300 {
71301 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
71302@@ -709,7 +709,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
71303 */
71304 static inline int skb_queue_empty(const struct sk_buff_head *list)
71305 {
71306- return list->next == (struct sk_buff *)list;
71307+ return list->next == (const struct sk_buff *)list;
71308 }
71309
71310 /**
71311@@ -722,7 +722,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
71312 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
71313 const struct sk_buff *skb)
71314 {
71315- return skb->next == (struct sk_buff *)list;
71316+ return skb->next == (const struct sk_buff *)list;
71317 }
71318
71319 /**
71320@@ -735,7 +735,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
71321 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
71322 const struct sk_buff *skb)
71323 {
71324- return skb->prev == (struct sk_buff *)list;
71325+ return skb->prev == (const struct sk_buff *)list;
71326 }
71327
71328 /**
71329@@ -1756,7 +1756,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
71330 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
71331 */
71332 #ifndef NET_SKB_PAD
71333-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
71334+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
71335 #endif
71336
71337 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
71338@@ -2351,7 +2351,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
71339 int noblock, int *err);
71340 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
71341 struct poll_table_struct *wait);
71342-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
71343+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
71344 int offset, struct iovec *to,
71345 int size);
71346 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
71347@@ -2641,6 +2641,9 @@ static inline void nf_reset(struct sk_buff *skb)
71348 nf_bridge_put(skb->nf_bridge);
71349 skb->nf_bridge = NULL;
71350 #endif
71351+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
71352+ skb->nf_trace = 0;
71353+#endif
71354 }
71355
71356 static inline void nf_reset_trace(struct sk_buff *skb)
71357diff --git a/include/linux/slab.h b/include/linux/slab.h
71358index 5d168d7..720bff3 100644
71359--- a/include/linux/slab.h
71360+++ b/include/linux/slab.h
71361@@ -12,13 +12,20 @@
71362 #include <linux/gfp.h>
71363 #include <linux/types.h>
71364 #include <linux/workqueue.h>
71365-
71366+#include <linux/err.h>
71367
71368 /*
71369 * Flags to pass to kmem_cache_create().
71370 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
71371 */
71372 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
71373+
71374+#ifdef CONFIG_PAX_USERCOPY_SLABS
71375+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
71376+#else
71377+#define SLAB_USERCOPY 0x00000000UL
71378+#endif
71379+
71380 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
71381 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
71382 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
71383@@ -89,10 +96,13 @@
71384 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
71385 * Both make kfree a no-op.
71386 */
71387-#define ZERO_SIZE_PTR ((void *)16)
71388+#define ZERO_SIZE_PTR \
71389+({ \
71390+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
71391+ (void *)(-MAX_ERRNO-1L); \
71392+})
71393
71394-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
71395- (unsigned long)ZERO_SIZE_PTR)
71396+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
71397
71398 /*
71399 * Common fields provided in kmem_cache by all slab allocators
71400@@ -112,7 +122,7 @@ struct kmem_cache {
71401 unsigned int align; /* Alignment as calculated */
71402 unsigned long flags; /* Active flags on the slab */
71403 const char *name; /* Slab name for sysfs */
71404- int refcount; /* Use counter */
71405+ atomic_t refcount; /* Use counter */
71406 void (*ctor)(void *); /* Called on object slot creation */
71407 struct list_head list; /* List of all slab caches on the system */
71408 };
71409@@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
71410 void kfree(const void *);
71411 void kzfree(const void *);
71412 size_t ksize(const void *);
71413+const char *check_heap_object(const void *ptr, unsigned long n);
71414+bool is_usercopy_object(const void *ptr);
71415
71416 /*
71417 * Allocator specific definitions. These are mainly used to establish optimized
71418@@ -311,6 +323,7 @@ size_t ksize(const void *);
71419 * for general use, and so are not documented here. For a full list of
71420 * potential flags, always refer to linux/gfp.h.
71421 */
71422+
71423 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
71424 {
71425 if (size != 0 && n > SIZE_MAX / size)
71426@@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
71427 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
71428 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
71429 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
71430-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
71431+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
71432 #define kmalloc_track_caller(size, flags) \
71433 __kmalloc_track_caller(size, flags, _RET_IP_)
71434 #else
71435@@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
71436 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
71437 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
71438 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
71439-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
71440+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
71441 #define kmalloc_node_track_caller(size, flags, node) \
71442 __kmalloc_node_track_caller(size, flags, node, \
71443 _RET_IP_)
71444diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
71445index 8bb6e0e..8eb0dbe 100644
71446--- a/include/linux/slab_def.h
71447+++ b/include/linux/slab_def.h
71448@@ -52,7 +52,7 @@ struct kmem_cache {
71449 /* 4) cache creation/removal */
71450 const char *name;
71451 struct list_head list;
71452- int refcount;
71453+ atomic_t refcount;
71454 int object_size;
71455 int align;
71456
71457@@ -68,10 +68,10 @@ struct kmem_cache {
71458 unsigned long node_allocs;
71459 unsigned long node_frees;
71460 unsigned long node_overflow;
71461- atomic_t allochit;
71462- atomic_t allocmiss;
71463- atomic_t freehit;
71464- atomic_t freemiss;
71465+ atomic_unchecked_t allochit;
71466+ atomic_unchecked_t allocmiss;
71467+ atomic_unchecked_t freehit;
71468+ atomic_unchecked_t freemiss;
71469
71470 /*
71471 * If debugging is enabled, then the allocator can add additional
71472@@ -111,11 +111,16 @@ struct cache_sizes {
71473 #ifdef CONFIG_ZONE_DMA
71474 struct kmem_cache *cs_dmacachep;
71475 #endif
71476+
71477+#ifdef CONFIG_PAX_USERCOPY_SLABS
71478+ struct kmem_cache *cs_usercopycachep;
71479+#endif
71480+
71481 };
71482 extern struct cache_sizes malloc_sizes[];
71483
71484 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
71485-void *__kmalloc(size_t size, gfp_t flags);
71486+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
71487
71488 #ifdef CONFIG_TRACING
71489 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
71490@@ -152,6 +157,13 @@ found:
71491 cachep = malloc_sizes[i].cs_dmacachep;
71492 else
71493 #endif
71494+
71495+#ifdef CONFIG_PAX_USERCOPY_SLABS
71496+ if (flags & GFP_USERCOPY)
71497+ cachep = malloc_sizes[i].cs_usercopycachep;
71498+ else
71499+#endif
71500+
71501 cachep = malloc_sizes[i].cs_cachep;
71502
71503 ret = kmem_cache_alloc_trace(cachep, flags, size);
71504@@ -162,7 +174,7 @@ found:
71505 }
71506
71507 #ifdef CONFIG_NUMA
71508-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
71509+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
71510 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
71511
71512 #ifdef CONFIG_TRACING
71513@@ -205,6 +217,13 @@ found:
71514 cachep = malloc_sizes[i].cs_dmacachep;
71515 else
71516 #endif
71517+
71518+#ifdef CONFIG_PAX_USERCOPY_SLABS
71519+ if (flags & GFP_USERCOPY)
71520+ cachep = malloc_sizes[i].cs_usercopycachep;
71521+ else
71522+#endif
71523+
71524 cachep = malloc_sizes[i].cs_cachep;
71525
71526 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
71527diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
71528index f28e14a..7831211 100644
71529--- a/include/linux/slob_def.h
71530+++ b/include/linux/slob_def.h
71531@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
71532 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
71533 }
71534
71535-void *__kmalloc_node(size_t size, gfp_t flags, int node);
71536+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
71537
71538 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
71539 {
71540@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
71541 return __kmalloc_node(size, flags, NUMA_NO_NODE);
71542 }
71543
71544-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
71545+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
71546 {
71547 return kmalloc(size, flags);
71548 }
71549diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
71550index 9db4825..ed42fb5 100644
71551--- a/include/linux/slub_def.h
71552+++ b/include/linux/slub_def.h
71553@@ -91,7 +91,7 @@ struct kmem_cache {
71554 struct kmem_cache_order_objects max;
71555 struct kmem_cache_order_objects min;
71556 gfp_t allocflags; /* gfp flags to use on each alloc */
71557- int refcount; /* Refcount for slab cache destroy */
71558+ atomic_t refcount; /* Refcount for slab cache destroy */
71559 void (*ctor)(void *);
71560 int inuse; /* Offset to metadata */
71561 int align; /* Alignment */
71562@@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
71563 * Sorry that the following has to be that ugly but some versions of GCC
71564 * have trouble with constant propagation and loops.
71565 */
71566-static __always_inline int kmalloc_index(size_t size)
71567+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
71568 {
71569 if (!size)
71570 return 0;
71571@@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
71572 }
71573
71574 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
71575-void *__kmalloc(size_t size, gfp_t flags);
71576+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
71577
71578 static __always_inline void *
71579 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
71580@@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
71581 }
71582 #endif
71583
71584-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
71585+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
71586 {
71587 unsigned int order = get_order(size);
71588 return kmalloc_order_trace(size, flags, order);
71589@@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
71590 }
71591
71592 #ifdef CONFIG_NUMA
71593-void *__kmalloc_node(size_t size, gfp_t flags, int node);
71594+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
71595 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
71596
71597 #ifdef CONFIG_TRACING
71598diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
71599index e8d702e..0a56eb4 100644
71600--- a/include/linux/sock_diag.h
71601+++ b/include/linux/sock_diag.h
71602@@ -10,7 +10,7 @@ struct sock;
71603 struct sock_diag_handler {
71604 __u8 family;
71605 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
71606-};
71607+} __do_const;
71608
71609 int sock_diag_register(const struct sock_diag_handler *h);
71610 void sock_diag_unregister(const struct sock_diag_handler *h);
71611diff --git a/include/linux/socket.h b/include/linux/socket.h
71612index 2b9f74b..e897bdc 100644
71613--- a/include/linux/socket.h
71614+++ b/include/linux/socket.h
71615@@ -321,6 +321,9 @@ extern int put_cmsg(struct msghdr*, int level, int type, int len, void *data);
71616
71617 struct timespec;
71618
71619+/* The __sys_...msg variants allow MSG_CMSG_COMPAT */
71620+extern long __sys_recvmsg(int fd, struct msghdr __user *msg, unsigned flags);
71621+extern long __sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
71622 extern int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen,
71623 unsigned int flags, struct timespec *timeout);
71624 extern int __sys_sendmmsg(int fd, struct mmsghdr __user *mmsg,
71625diff --git a/include/linux/sonet.h b/include/linux/sonet.h
71626index 680f9a3..f13aeb0 100644
71627--- a/include/linux/sonet.h
71628+++ b/include/linux/sonet.h
71629@@ -7,7 +7,7 @@
71630 #include <uapi/linux/sonet.h>
71631
71632 struct k_sonet_stats {
71633-#define __HANDLE_ITEM(i) atomic_t i
71634+#define __HANDLE_ITEM(i) atomic_unchecked_t i
71635 __SONET_ITEMS
71636 #undef __HANDLE_ITEM
71637 };
71638diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
71639index 07d8e53..dc934c9 100644
71640--- a/include/linux/sunrpc/addr.h
71641+++ b/include/linux/sunrpc/addr.h
71642@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
71643 {
71644 switch (sap->sa_family) {
71645 case AF_INET:
71646- return ntohs(((struct sockaddr_in *)sap)->sin_port);
71647+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
71648 case AF_INET6:
71649- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
71650+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
71651 }
71652 return 0;
71653 }
71654@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
71655 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
71656 const struct sockaddr *src)
71657 {
71658- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
71659+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
71660 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
71661
71662 dsin->sin_family = ssin->sin_family;
71663@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
71664 if (sa->sa_family != AF_INET6)
71665 return 0;
71666
71667- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
71668+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
71669 }
71670
71671 #endif /* _LINUX_SUNRPC_ADDR_H */
71672diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
71673index 2cf4ffa..470d140 100644
71674--- a/include/linux/sunrpc/clnt.h
71675+++ b/include/linux/sunrpc/clnt.h
71676@@ -96,7 +96,7 @@ struct rpc_procinfo {
71677 unsigned int p_timer; /* Which RTT timer to use */
71678 u32 p_statidx; /* Which procedure to account */
71679 const char * p_name; /* name of procedure */
71680-};
71681+} __do_const;
71682
71683 #ifdef __KERNEL__
71684
71685diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
71686index 1f0216b..6a4fa50 100644
71687--- a/include/linux/sunrpc/svc.h
71688+++ b/include/linux/sunrpc/svc.h
71689@@ -411,7 +411,7 @@ struct svc_procedure {
71690 unsigned int pc_count; /* call count */
71691 unsigned int pc_cachetype; /* cache info (NFS) */
71692 unsigned int pc_xdrressize; /* maximum size of XDR reply */
71693-};
71694+} __do_const;
71695
71696 /*
71697 * Function prototypes.
71698diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
71699index 0b8e3e6..33e0a01 100644
71700--- a/include/linux/sunrpc/svc_rdma.h
71701+++ b/include/linux/sunrpc/svc_rdma.h
71702@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
71703 extern unsigned int svcrdma_max_requests;
71704 extern unsigned int svcrdma_max_req_size;
71705
71706-extern atomic_t rdma_stat_recv;
71707-extern atomic_t rdma_stat_read;
71708-extern atomic_t rdma_stat_write;
71709-extern atomic_t rdma_stat_sq_starve;
71710-extern atomic_t rdma_stat_rq_starve;
71711-extern atomic_t rdma_stat_rq_poll;
71712-extern atomic_t rdma_stat_rq_prod;
71713-extern atomic_t rdma_stat_sq_poll;
71714-extern atomic_t rdma_stat_sq_prod;
71715+extern atomic_unchecked_t rdma_stat_recv;
71716+extern atomic_unchecked_t rdma_stat_read;
71717+extern atomic_unchecked_t rdma_stat_write;
71718+extern atomic_unchecked_t rdma_stat_sq_starve;
71719+extern atomic_unchecked_t rdma_stat_rq_starve;
71720+extern atomic_unchecked_t rdma_stat_rq_poll;
71721+extern atomic_unchecked_t rdma_stat_rq_prod;
71722+extern atomic_unchecked_t rdma_stat_sq_poll;
71723+extern atomic_unchecked_t rdma_stat_sq_prod;
71724
71725 #define RPCRDMA_VERSION 1
71726
71727diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
71728index ff374ab..7fd2ecb 100644
71729--- a/include/linux/sunrpc/svcauth.h
71730+++ b/include/linux/sunrpc/svcauth.h
71731@@ -109,7 +109,7 @@ struct auth_ops {
71732 int (*release)(struct svc_rqst *rq);
71733 void (*domain_release)(struct auth_domain *);
71734 int (*set_client)(struct svc_rqst *rq);
71735-};
71736+} __do_const;
71737
71738 #define SVC_GARBAGE 1
71739 #define SVC_SYSERR 2
71740diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
71741index a5ffd32..0935dea 100644
71742--- a/include/linux/swiotlb.h
71743+++ b/include/linux/swiotlb.h
71744@@ -60,7 +60,8 @@ extern void
71745
71746 extern void
71747 swiotlb_free_coherent(struct device *hwdev, size_t size,
71748- void *vaddr, dma_addr_t dma_handle);
71749+ void *vaddr, dma_addr_t dma_handle,
71750+ struct dma_attrs *attrs);
71751
71752 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
71753 unsigned long offset, size_t size,
71754diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
71755index 313a8e0..6b273a9 100644
71756--- a/include/linux/syscalls.h
71757+++ b/include/linux/syscalls.h
71758@@ -418,11 +418,11 @@ asmlinkage long sys_sync(void);
71759 asmlinkage long sys_fsync(unsigned int fd);
71760 asmlinkage long sys_fdatasync(unsigned int fd);
71761 asmlinkage long sys_bdflush(int func, long data);
71762-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
71763- char __user *type, unsigned long flags,
71764+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
71765+ const char __user *type, unsigned long flags,
71766 void __user *data);
71767-asmlinkage long sys_umount(char __user *name, int flags);
71768-asmlinkage long sys_oldumount(char __user *name);
71769+asmlinkage long sys_umount(const char __user *name, int flags);
71770+asmlinkage long sys_oldumount(const char __user *name);
71771 asmlinkage long sys_truncate(const char __user *path, long length);
71772 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
71773 asmlinkage long sys_stat(const char __user *filename,
71774@@ -634,7 +634,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
71775 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
71776 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
71777 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
71778- struct sockaddr __user *, int);
71779+ struct sockaddr __user *, int) __intentional_overflow(0);
71780 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
71781 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
71782 unsigned int vlen, unsigned flags);
71783diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
71784index 27b3b0b..e093dd9 100644
71785--- a/include/linux/syscore_ops.h
71786+++ b/include/linux/syscore_ops.h
71787@@ -16,7 +16,7 @@ struct syscore_ops {
71788 int (*suspend)(void);
71789 void (*resume)(void);
71790 void (*shutdown)(void);
71791-};
71792+} __do_const;
71793
71794 extern void register_syscore_ops(struct syscore_ops *ops);
71795 extern void unregister_syscore_ops(struct syscore_ops *ops);
71796diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
71797index 14a8ff2..af52bad 100644
71798--- a/include/linux/sysctl.h
71799+++ b/include/linux/sysctl.h
71800@@ -34,13 +34,13 @@ struct ctl_table_root;
71801 struct ctl_table_header;
71802 struct ctl_dir;
71803
71804-typedef struct ctl_table ctl_table;
71805-
71806 typedef int proc_handler (struct ctl_table *ctl, int write,
71807 void __user *buffer, size_t *lenp, loff_t *ppos);
71808
71809 extern int proc_dostring(struct ctl_table *, int,
71810 void __user *, size_t *, loff_t *);
71811+extern int proc_dostring_modpriv(struct ctl_table *, int,
71812+ void __user *, size_t *, loff_t *);
71813 extern int proc_dointvec(struct ctl_table *, int,
71814 void __user *, size_t *, loff_t *);
71815 extern int proc_dointvec_minmax(struct ctl_table *, int,
71816@@ -115,7 +115,9 @@ struct ctl_table
71817 struct ctl_table_poll *poll;
71818 void *extra1;
71819 void *extra2;
71820-};
71821+} __do_const;
71822+typedef struct ctl_table __no_const ctl_table_no_const;
71823+typedef struct ctl_table ctl_table;
71824
71825 struct ctl_node {
71826 struct rb_node node;
71827diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
71828index e2cee22..3ddb921 100644
71829--- a/include/linux/sysfs.h
71830+++ b/include/linux/sysfs.h
71831@@ -31,7 +31,8 @@ struct attribute {
71832 struct lock_class_key *key;
71833 struct lock_class_key skey;
71834 #endif
71835-};
71836+} __do_const;
71837+typedef struct attribute __no_const attribute_no_const;
71838
71839 /**
71840 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
71841@@ -59,8 +60,8 @@ struct attribute_group {
71842 umode_t (*is_visible)(struct kobject *,
71843 struct attribute *, int);
71844 struct attribute **attrs;
71845-};
71846-
71847+} __do_const;
71848+typedef struct attribute_group __no_const attribute_group_no_const;
71849
71850
71851 /**
71852@@ -107,7 +108,8 @@ struct bin_attribute {
71853 char *, loff_t, size_t);
71854 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
71855 struct vm_area_struct *vma);
71856-};
71857+} __do_const;
71858+typedef struct bin_attribute __no_const bin_attribute_no_const;
71859
71860 /**
71861 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
71862diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
71863index 7faf933..9b85a0c 100644
71864--- a/include/linux/sysrq.h
71865+++ b/include/linux/sysrq.h
71866@@ -16,6 +16,7 @@
71867
71868 #include <linux/errno.h>
71869 #include <linux/types.h>
71870+#include <linux/compiler.h>
71871
71872 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
71873 #define SYSRQ_DEFAULT_ENABLE 1
71874@@ -36,7 +37,7 @@ struct sysrq_key_op {
71875 char *help_msg;
71876 char *action_msg;
71877 int enable_mask;
71878-};
71879+} __do_const;
71880
71881 #ifdef CONFIG_MAGIC_SYSRQ
71882
71883diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
71884index e7e0473..7989295 100644
71885--- a/include/linux/thread_info.h
71886+++ b/include/linux/thread_info.h
71887@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
71888 #error "no set_restore_sigmask() provided and default one won't work"
71889 #endif
71890
71891+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
71892+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
71893+{
71894+#ifndef CONFIG_PAX_USERCOPY_DEBUG
71895+ if (!__builtin_constant_p(n))
71896+#endif
71897+ __check_object_size(ptr, n, to_user);
71898+}
71899+
71900 #endif /* __KERNEL__ */
71901
71902 #endif /* _LINUX_THREAD_INFO_H */
71903diff --git a/include/linux/tty.h b/include/linux/tty.h
71904index c75d886..04cb148 100644
71905--- a/include/linux/tty.h
71906+++ b/include/linux/tty.h
71907@@ -194,7 +194,7 @@ struct tty_port {
71908 const struct tty_port_operations *ops; /* Port operations */
71909 spinlock_t lock; /* Lock protecting tty field */
71910 int blocked_open; /* Waiting to open */
71911- int count; /* Usage count */
71912+ atomic_t count; /* Usage count */
71913 wait_queue_head_t open_wait; /* Open waiters */
71914 wait_queue_head_t close_wait; /* Close waiters */
71915 wait_queue_head_t delta_msr_wait; /* Modem status change */
71916@@ -515,7 +515,7 @@ extern int tty_port_open(struct tty_port *port,
71917 struct tty_struct *tty, struct file *filp);
71918 static inline int tty_port_users(struct tty_port *port)
71919 {
71920- return port->count + port->blocked_open;
71921+ return atomic_read(&port->count) + port->blocked_open;
71922 }
71923
71924 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
71925diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
71926index 756a609..b302dd6 100644
71927--- a/include/linux/tty_driver.h
71928+++ b/include/linux/tty_driver.h
71929@@ -285,7 +285,7 @@ struct tty_operations {
71930 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
71931 #endif
71932 const struct file_operations *proc_fops;
71933-};
71934+} __do_const;
71935
71936 struct tty_driver {
71937 int magic; /* magic number for this structure */
71938diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
71939index 455a0d7..bf97ff5 100644
71940--- a/include/linux/tty_ldisc.h
71941+++ b/include/linux/tty_ldisc.h
71942@@ -146,7 +146,7 @@ struct tty_ldisc_ops {
71943
71944 struct module *owner;
71945
71946- int refcount;
71947+ atomic_t refcount;
71948 };
71949
71950 struct tty_ldisc {
71951diff --git a/include/linux/types.h b/include/linux/types.h
71952index 4d118ba..c3ee9bf 100644
71953--- a/include/linux/types.h
71954+++ b/include/linux/types.h
71955@@ -176,10 +176,26 @@ typedef struct {
71956 int counter;
71957 } atomic_t;
71958
71959+#ifdef CONFIG_PAX_REFCOUNT
71960+typedef struct {
71961+ int counter;
71962+} atomic_unchecked_t;
71963+#else
71964+typedef atomic_t atomic_unchecked_t;
71965+#endif
71966+
71967 #ifdef CONFIG_64BIT
71968 typedef struct {
71969 long counter;
71970 } atomic64_t;
71971+
71972+#ifdef CONFIG_PAX_REFCOUNT
71973+typedef struct {
71974+ long counter;
71975+} atomic64_unchecked_t;
71976+#else
71977+typedef atomic64_t atomic64_unchecked_t;
71978+#endif
71979 #endif
71980
71981 struct list_head {
71982diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
71983index 5ca0951..ab496a5 100644
71984--- a/include/linux/uaccess.h
71985+++ b/include/linux/uaccess.h
71986@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
71987 long ret; \
71988 mm_segment_t old_fs = get_fs(); \
71989 \
71990- set_fs(KERNEL_DS); \
71991 pagefault_disable(); \
71992- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
71993- pagefault_enable(); \
71994+ set_fs(KERNEL_DS); \
71995+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
71996 set_fs(old_fs); \
71997+ pagefault_enable(); \
71998 ret; \
71999 })
72000
72001diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
72002index 8e522cbc..aa8572d 100644
72003--- a/include/linux/uidgid.h
72004+++ b/include/linux/uidgid.h
72005@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
72006
72007 #endif /* CONFIG_USER_NS */
72008
72009+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
72010+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
72011+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
72012+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
72013+
72014 #endif /* _LINUX_UIDGID_H */
72015diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
72016index 99c1b4d..562e6f3 100644
72017--- a/include/linux/unaligned/access_ok.h
72018+++ b/include/linux/unaligned/access_ok.h
72019@@ -4,34 +4,34 @@
72020 #include <linux/kernel.h>
72021 #include <asm/byteorder.h>
72022
72023-static inline u16 get_unaligned_le16(const void *p)
72024+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
72025 {
72026- return le16_to_cpup((__le16 *)p);
72027+ return le16_to_cpup((const __le16 *)p);
72028 }
72029
72030-static inline u32 get_unaligned_le32(const void *p)
72031+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
72032 {
72033- return le32_to_cpup((__le32 *)p);
72034+ return le32_to_cpup((const __le32 *)p);
72035 }
72036
72037-static inline u64 get_unaligned_le64(const void *p)
72038+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
72039 {
72040- return le64_to_cpup((__le64 *)p);
72041+ return le64_to_cpup((const __le64 *)p);
72042 }
72043
72044-static inline u16 get_unaligned_be16(const void *p)
72045+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
72046 {
72047- return be16_to_cpup((__be16 *)p);
72048+ return be16_to_cpup((const __be16 *)p);
72049 }
72050
72051-static inline u32 get_unaligned_be32(const void *p)
72052+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
72053 {
72054- return be32_to_cpup((__be32 *)p);
72055+ return be32_to_cpup((const __be32 *)p);
72056 }
72057
72058-static inline u64 get_unaligned_be64(const void *p)
72059+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
72060 {
72061- return be64_to_cpup((__be64 *)p);
72062+ return be64_to_cpup((const __be64 *)p);
72063 }
72064
72065 static inline void put_unaligned_le16(u16 val, void *p)
72066diff --git a/include/linux/usb.h b/include/linux/usb.h
72067index 4d22d0f..8d0e8f8 100644
72068--- a/include/linux/usb.h
72069+++ b/include/linux/usb.h
72070@@ -554,7 +554,7 @@ struct usb_device {
72071 int maxchild;
72072
72073 u32 quirks;
72074- atomic_t urbnum;
72075+ atomic_unchecked_t urbnum;
72076
72077 unsigned long active_duration;
72078
72079@@ -1604,7 +1604,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
72080
72081 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
72082 __u8 request, __u8 requesttype, __u16 value, __u16 index,
72083- void *data, __u16 size, int timeout);
72084+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
72085 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
72086 void *data, int len, int *actual_length, int timeout);
72087 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
72088diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
72089index c5d36c6..108f4f9 100644
72090--- a/include/linux/usb/renesas_usbhs.h
72091+++ b/include/linux/usb/renesas_usbhs.h
72092@@ -39,7 +39,7 @@ enum {
72093 */
72094 struct renesas_usbhs_driver_callback {
72095 int (*notify_hotplug)(struct platform_device *pdev);
72096-};
72097+} __no_const;
72098
72099 /*
72100 * callback functions for platform
72101diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
72102index 6f8fbcf..8259001 100644
72103--- a/include/linux/vermagic.h
72104+++ b/include/linux/vermagic.h
72105@@ -25,9 +25,35 @@
72106 #define MODULE_ARCH_VERMAGIC ""
72107 #endif
72108
72109+#ifdef CONFIG_PAX_REFCOUNT
72110+#define MODULE_PAX_REFCOUNT "REFCOUNT "
72111+#else
72112+#define MODULE_PAX_REFCOUNT ""
72113+#endif
72114+
72115+#ifdef CONSTIFY_PLUGIN
72116+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
72117+#else
72118+#define MODULE_CONSTIFY_PLUGIN ""
72119+#endif
72120+
72121+#ifdef STACKLEAK_PLUGIN
72122+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
72123+#else
72124+#define MODULE_STACKLEAK_PLUGIN ""
72125+#endif
72126+
72127+#ifdef CONFIG_GRKERNSEC
72128+#define MODULE_GRSEC "GRSEC "
72129+#else
72130+#define MODULE_GRSEC ""
72131+#endif
72132+
72133 #define VERMAGIC_STRING \
72134 UTS_RELEASE " " \
72135 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
72136 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
72137- MODULE_ARCH_VERMAGIC
72138+ MODULE_ARCH_VERMAGIC \
72139+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
72140+ MODULE_GRSEC
72141
72142diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
72143index 6071e91..ca6a489 100644
72144--- a/include/linux/vmalloc.h
72145+++ b/include/linux/vmalloc.h
72146@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
72147 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
72148 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
72149 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
72150+
72151+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
72152+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
72153+#endif
72154+
72155 /* bits [20..32] reserved for arch specific ioremap internals */
72156
72157 /*
72158@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
72159 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
72160 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
72161 unsigned long start, unsigned long end, gfp_t gfp_mask,
72162- pgprot_t prot, int node, const void *caller);
72163+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
72164 extern void vfree(const void *addr);
72165
72166 extern void *vmap(struct page **pages, unsigned int count,
72167@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
72168 extern void free_vm_area(struct vm_struct *area);
72169
72170 /* for /dev/kmem */
72171-extern long vread(char *buf, char *addr, unsigned long count);
72172-extern long vwrite(char *buf, char *addr, unsigned long count);
72173+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
72174+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
72175
72176 /*
72177 * Internals. Dont't use..
72178diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
72179index 5fd71a7..e5ef9a9 100644
72180--- a/include/linux/vmstat.h
72181+++ b/include/linux/vmstat.h
72182@@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
72183 /*
72184 * Zone based page accounting with per cpu differentials.
72185 */
72186-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
72187+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
72188
72189 static inline void zone_page_state_add(long x, struct zone *zone,
72190 enum zone_stat_item item)
72191 {
72192- atomic_long_add(x, &zone->vm_stat[item]);
72193- atomic_long_add(x, &vm_stat[item]);
72194+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
72195+ atomic_long_add_unchecked(x, &vm_stat[item]);
72196 }
72197
72198 static inline unsigned long global_page_state(enum zone_stat_item item)
72199 {
72200- long x = atomic_long_read(&vm_stat[item]);
72201+ long x = atomic_long_read_unchecked(&vm_stat[item]);
72202 #ifdef CONFIG_SMP
72203 if (x < 0)
72204 x = 0;
72205@@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
72206 static inline unsigned long zone_page_state(struct zone *zone,
72207 enum zone_stat_item item)
72208 {
72209- long x = atomic_long_read(&zone->vm_stat[item]);
72210+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
72211 #ifdef CONFIG_SMP
72212 if (x < 0)
72213 x = 0;
72214@@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
72215 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
72216 enum zone_stat_item item)
72217 {
72218- long x = atomic_long_read(&zone->vm_stat[item]);
72219+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
72220
72221 #ifdef CONFIG_SMP
72222 int cpu;
72223@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
72224
72225 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
72226 {
72227- atomic_long_inc(&zone->vm_stat[item]);
72228- atomic_long_inc(&vm_stat[item]);
72229+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
72230+ atomic_long_inc_unchecked(&vm_stat[item]);
72231 }
72232
72233 static inline void __inc_zone_page_state(struct page *page,
72234@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
72235
72236 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
72237 {
72238- atomic_long_dec(&zone->vm_stat[item]);
72239- atomic_long_dec(&vm_stat[item]);
72240+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
72241+ atomic_long_dec_unchecked(&vm_stat[item]);
72242 }
72243
72244 static inline void __dec_zone_page_state(struct page *page,
72245diff --git a/include/linux/xattr.h b/include/linux/xattr.h
72246index fdbafc6..49dfe4f 100644
72247--- a/include/linux/xattr.h
72248+++ b/include/linux/xattr.h
72249@@ -28,7 +28,7 @@ struct xattr_handler {
72250 size_t size, int handler_flags);
72251 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
72252 size_t size, int flags, int handler_flags);
72253-};
72254+} __do_const;
72255
72256 struct xattr {
72257 char *name;
72258@@ -37,6 +37,9 @@ struct xattr {
72259 };
72260
72261 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
72262+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
72263+ssize_t pax_getxattr(struct dentry *, void *, size_t);
72264+#endif
72265 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
72266 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
72267 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
72268diff --git a/include/linux/zlib.h b/include/linux/zlib.h
72269index 9c5a6b4..09c9438 100644
72270--- a/include/linux/zlib.h
72271+++ b/include/linux/zlib.h
72272@@ -31,6 +31,7 @@
72273 #define _ZLIB_H
72274
72275 #include <linux/zconf.h>
72276+#include <linux/compiler.h>
72277
72278 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
72279 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
72280@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
72281
72282 /* basic functions */
72283
72284-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
72285+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
72286 /*
72287 Returns the number of bytes that needs to be allocated for a per-
72288 stream workspace with the specified parameters. A pointer to this
72289diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
72290index 95d1c91..6798cca 100644
72291--- a/include/media/v4l2-dev.h
72292+++ b/include/media/v4l2-dev.h
72293@@ -76,7 +76,7 @@ struct v4l2_file_operations {
72294 int (*mmap) (struct file *, struct vm_area_struct *);
72295 int (*open) (struct file *);
72296 int (*release) (struct file *);
72297-};
72298+} __do_const;
72299
72300 /*
72301 * Newer version of video_device, handled by videodev2.c
72302diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
72303index 4118ad1..cb7e25f 100644
72304--- a/include/media/v4l2-ioctl.h
72305+++ b/include/media/v4l2-ioctl.h
72306@@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
72307 bool valid_prio, int cmd, void *arg);
72308 };
72309
72310-
72311 /* v4l debugging and diagnostics */
72312
72313 /* Debug bitmask flags to be used on V4L2 */
72314diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
72315index adcbb20..62c2559 100644
72316--- a/include/net/9p/transport.h
72317+++ b/include/net/9p/transport.h
72318@@ -57,7 +57,7 @@ struct p9_trans_module {
72319 int (*cancel) (struct p9_client *, struct p9_req_t *req);
72320 int (*zc_request)(struct p9_client *, struct p9_req_t *,
72321 char *, char *, int , int, int, int);
72322-};
72323+} __do_const;
72324
72325 void v9fs_register_trans(struct p9_trans_module *m);
72326 void v9fs_unregister_trans(struct p9_trans_module *m);
72327diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
72328index cdd3302..76f8ede 100644
72329--- a/include/net/bluetooth/l2cap.h
72330+++ b/include/net/bluetooth/l2cap.h
72331@@ -551,7 +551,7 @@ struct l2cap_ops {
72332 void (*defer) (struct l2cap_chan *chan);
72333 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
72334 unsigned long len, int nb);
72335-};
72336+} __do_const;
72337
72338 struct l2cap_conn {
72339 struct hci_conn *hcon;
72340diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
72341index 9e5425b..8136ffc 100644
72342--- a/include/net/caif/cfctrl.h
72343+++ b/include/net/caif/cfctrl.h
72344@@ -52,7 +52,7 @@ struct cfctrl_rsp {
72345 void (*radioset_rsp)(void);
72346 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
72347 struct cflayer *client_layer);
72348-};
72349+} __no_const;
72350
72351 /* Link Setup Parameters for CAIF-Links. */
72352 struct cfctrl_link_param {
72353@@ -101,8 +101,8 @@ struct cfctrl_request_info {
72354 struct cfctrl {
72355 struct cfsrvl serv;
72356 struct cfctrl_rsp res;
72357- atomic_t req_seq_no;
72358- atomic_t rsp_seq_no;
72359+ atomic_unchecked_t req_seq_no;
72360+ atomic_unchecked_t rsp_seq_no;
72361 struct list_head list;
72362 /* Protects from simultaneous access to first_req list */
72363 spinlock_t info_list_lock;
72364diff --git a/include/net/flow.h b/include/net/flow.h
72365index 628e11b..4c475df 100644
72366--- a/include/net/flow.h
72367+++ b/include/net/flow.h
72368@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
72369
72370 extern void flow_cache_flush(void);
72371 extern void flow_cache_flush_deferred(void);
72372-extern atomic_t flow_cache_genid;
72373+extern atomic_unchecked_t flow_cache_genid;
72374
72375 #endif
72376diff --git a/include/net/genetlink.h b/include/net/genetlink.h
72377index bdfbe68..4402ebe 100644
72378--- a/include/net/genetlink.h
72379+++ b/include/net/genetlink.h
72380@@ -118,7 +118,7 @@ struct genl_ops {
72381 struct netlink_callback *cb);
72382 int (*done)(struct netlink_callback *cb);
72383 struct list_head ops_list;
72384-};
72385+} __do_const;
72386
72387 extern int genl_register_family(struct genl_family *family);
72388 extern int genl_register_family_with_ops(struct genl_family *family,
72389diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
72390index 734d9b5..48a9a4b 100644
72391--- a/include/net/gro_cells.h
72392+++ b/include/net/gro_cells.h
72393@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
72394 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
72395
72396 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
72397- atomic_long_inc(&dev->rx_dropped);
72398+ atomic_long_inc_unchecked(&dev->rx_dropped);
72399 kfree_skb(skb);
72400 return;
72401 }
72402diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
72403index 1832927..ce39aea 100644
72404--- a/include/net/inet_connection_sock.h
72405+++ b/include/net/inet_connection_sock.h
72406@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
72407 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
72408 int (*bind_conflict)(const struct sock *sk,
72409 const struct inet_bind_bucket *tb, bool relax);
72410-};
72411+} __do_const;
72412
72413 /** inet_connection_sock - INET connection oriented sock
72414 *
72415diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
72416index 53f464d..ba76aaa 100644
72417--- a/include/net/inetpeer.h
72418+++ b/include/net/inetpeer.h
72419@@ -47,8 +47,8 @@ struct inet_peer {
72420 */
72421 union {
72422 struct {
72423- atomic_t rid; /* Frag reception counter */
72424- atomic_t ip_id_count; /* IP ID for the next packet */
72425+ atomic_unchecked_t rid; /* Frag reception counter */
72426+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
72427 };
72428 struct rcu_head rcu;
72429 struct inet_peer *gc_next;
72430@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
72431 more++;
72432 inet_peer_refcheck(p);
72433 do {
72434- old = atomic_read(&p->ip_id_count);
72435+ old = atomic_read_unchecked(&p->ip_id_count);
72436 new = old + more;
72437 if (!new)
72438 new = 1;
72439- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
72440+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
72441 return new;
72442 }
72443
72444diff --git a/include/net/ip.h b/include/net/ip.h
72445index a68f838..74518ab 100644
72446--- a/include/net/ip.h
72447+++ b/include/net/ip.h
72448@@ -202,7 +202,7 @@ extern struct local_ports {
72449 } sysctl_local_ports;
72450 extern void inet_get_local_port_range(int *low, int *high);
72451
72452-extern unsigned long *sysctl_local_reserved_ports;
72453+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
72454 static inline int inet_is_reserved_local_port(int port)
72455 {
72456 return test_bit(port, sysctl_local_reserved_ports);
72457diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
72458index e49db91..76a81de 100644
72459--- a/include/net/ip_fib.h
72460+++ b/include/net/ip_fib.h
72461@@ -167,7 +167,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
72462
72463 #define FIB_RES_SADDR(net, res) \
72464 ((FIB_RES_NH(res).nh_saddr_genid == \
72465- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
72466+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
72467 FIB_RES_NH(res).nh_saddr : \
72468 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
72469 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
72470diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
72471index fce8e6b..3ca4916 100644
72472--- a/include/net/ip_vs.h
72473+++ b/include/net/ip_vs.h
72474@@ -599,7 +599,7 @@ struct ip_vs_conn {
72475 struct ip_vs_conn *control; /* Master control connection */
72476 atomic_t n_control; /* Number of controlled ones */
72477 struct ip_vs_dest *dest; /* real server */
72478- atomic_t in_pkts; /* incoming packet counter */
72479+ atomic_unchecked_t in_pkts; /* incoming packet counter */
72480
72481 /* packet transmitter for different forwarding methods. If it
72482 mangles the packet, it must return NF_DROP or better NF_STOLEN,
72483@@ -737,7 +737,7 @@ struct ip_vs_dest {
72484 __be16 port; /* port number of the server */
72485 union nf_inet_addr addr; /* IP address of the server */
72486 volatile unsigned int flags; /* dest status flags */
72487- atomic_t conn_flags; /* flags to copy to conn */
72488+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
72489 atomic_t weight; /* server weight */
72490
72491 atomic_t refcnt; /* reference counter */
72492@@ -981,11 +981,11 @@ struct netns_ipvs {
72493 /* ip_vs_lblc */
72494 int sysctl_lblc_expiration;
72495 struct ctl_table_header *lblc_ctl_header;
72496- struct ctl_table *lblc_ctl_table;
72497+ ctl_table_no_const *lblc_ctl_table;
72498 /* ip_vs_lblcr */
72499 int sysctl_lblcr_expiration;
72500 struct ctl_table_header *lblcr_ctl_header;
72501- struct ctl_table *lblcr_ctl_table;
72502+ ctl_table_no_const *lblcr_ctl_table;
72503 /* ip_vs_est */
72504 struct list_head est_list; /* estimator list */
72505 spinlock_t est_lock;
72506diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
72507index 80ffde3..968b0f4 100644
72508--- a/include/net/irda/ircomm_tty.h
72509+++ b/include/net/irda/ircomm_tty.h
72510@@ -35,6 +35,7 @@
72511 #include <linux/termios.h>
72512 #include <linux/timer.h>
72513 #include <linux/tty.h> /* struct tty_struct */
72514+#include <asm/local.h>
72515
72516 #include <net/irda/irias_object.h>
72517 #include <net/irda/ircomm_core.h>
72518diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
72519index 714cc9a..ea05f3e 100644
72520--- a/include/net/iucv/af_iucv.h
72521+++ b/include/net/iucv/af_iucv.h
72522@@ -149,7 +149,7 @@ struct iucv_skb_cb {
72523 struct iucv_sock_list {
72524 struct hlist_head head;
72525 rwlock_t lock;
72526- atomic_t autobind_name;
72527+ atomic_unchecked_t autobind_name;
72528 };
72529
72530 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
72531diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
72532index df83f69..9b640b8 100644
72533--- a/include/net/llc_c_ac.h
72534+++ b/include/net/llc_c_ac.h
72535@@ -87,7 +87,7 @@
72536 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
72537 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
72538
72539-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
72540+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
72541
72542 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
72543 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
72544diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
72545index 6ca3113..f8026dd 100644
72546--- a/include/net/llc_c_ev.h
72547+++ b/include/net/llc_c_ev.h
72548@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
72549 return (struct llc_conn_state_ev *)skb->cb;
72550 }
72551
72552-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
72553-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
72554+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
72555+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
72556
72557 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
72558 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
72559diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
72560index 0e79cfb..f46db31 100644
72561--- a/include/net/llc_c_st.h
72562+++ b/include/net/llc_c_st.h
72563@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
72564 u8 next_state;
72565 llc_conn_ev_qfyr_t *ev_qualifiers;
72566 llc_conn_action_t *ev_actions;
72567-};
72568+} __do_const;
72569
72570 struct llc_conn_state {
72571 u8 current_state;
72572diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
72573index 37a3bbd..55a4241 100644
72574--- a/include/net/llc_s_ac.h
72575+++ b/include/net/llc_s_ac.h
72576@@ -23,7 +23,7 @@
72577 #define SAP_ACT_TEST_IND 9
72578
72579 /* All action functions must look like this */
72580-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
72581+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
72582
72583 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
72584 struct sk_buff *skb);
72585diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
72586index 567c681..cd73ac0 100644
72587--- a/include/net/llc_s_st.h
72588+++ b/include/net/llc_s_st.h
72589@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
72590 llc_sap_ev_t ev;
72591 u8 next_state;
72592 llc_sap_action_t *ev_actions;
72593-};
72594+} __do_const;
72595
72596 struct llc_sap_state {
72597 u8 curr_state;
72598diff --git a/include/net/mac80211.h b/include/net/mac80211.h
72599index f7eba13..91ed983 100644
72600--- a/include/net/mac80211.h
72601+++ b/include/net/mac80211.h
72602@@ -4119,7 +4119,7 @@ struct rate_control_ops {
72603 void (*add_sta_debugfs)(void *priv, void *priv_sta,
72604 struct dentry *dir);
72605 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
72606-};
72607+} __do_const;
72608
72609 static inline int rate_supported(struct ieee80211_sta *sta,
72610 enum ieee80211_band band,
72611diff --git a/include/net/neighbour.h b/include/net/neighbour.h
72612index 7e748ad..5c6229b 100644
72613--- a/include/net/neighbour.h
72614+++ b/include/net/neighbour.h
72615@@ -123,7 +123,7 @@ struct neigh_ops {
72616 void (*error_report)(struct neighbour *, struct sk_buff *);
72617 int (*output)(struct neighbour *, struct sk_buff *);
72618 int (*connected_output)(struct neighbour *, struct sk_buff *);
72619-};
72620+} __do_const;
72621
72622 struct pneigh_entry {
72623 struct pneigh_entry *next;
72624diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
72625index de644bc..dfbcc4c 100644
72626--- a/include/net/net_namespace.h
72627+++ b/include/net/net_namespace.h
72628@@ -115,7 +115,7 @@ struct net {
72629 #endif
72630 struct netns_ipvs *ipvs;
72631 struct sock *diag_nlsk;
72632- atomic_t rt_genid;
72633+ atomic_unchecked_t rt_genid;
72634 };
72635
72636 /*
72637@@ -272,7 +272,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
72638 #define __net_init __init
72639 #define __net_exit __exit_refok
72640 #define __net_initdata __initdata
72641+#ifdef CONSTIFY_PLUGIN
72642 #define __net_initconst __initconst
72643+#else
72644+#define __net_initconst __initdata
72645+#endif
72646 #endif
72647
72648 struct pernet_operations {
72649@@ -282,7 +286,7 @@ struct pernet_operations {
72650 void (*exit_batch)(struct list_head *net_exit_list);
72651 int *id;
72652 size_t size;
72653-};
72654+} __do_const;
72655
72656 /*
72657 * Use these carefully. If you implement a network device and it
72658@@ -330,12 +334,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
72659
72660 static inline int rt_genid(struct net *net)
72661 {
72662- return atomic_read(&net->rt_genid);
72663+ return atomic_read_unchecked(&net->rt_genid);
72664 }
72665
72666 static inline void rt_genid_bump(struct net *net)
72667 {
72668- atomic_inc(&net->rt_genid);
72669+ atomic_inc_unchecked(&net->rt_genid);
72670 }
72671
72672 #endif /* __NET_NET_NAMESPACE_H */
72673diff --git a/include/net/netdma.h b/include/net/netdma.h
72674index 8ba8ce2..99b7fff 100644
72675--- a/include/net/netdma.h
72676+++ b/include/net/netdma.h
72677@@ -24,7 +24,7 @@
72678 #include <linux/dmaengine.h>
72679 #include <linux/skbuff.h>
72680
72681-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
72682+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
72683 struct sk_buff *skb, int offset, struct iovec *to,
72684 size_t len, struct dma_pinned_list *pinned_list);
72685
72686diff --git a/include/net/netlink.h b/include/net/netlink.h
72687index 9690b0f..87aded7 100644
72688--- a/include/net/netlink.h
72689+++ b/include/net/netlink.h
72690@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
72691 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
72692 {
72693 if (mark)
72694- skb_trim(skb, (unsigned char *) mark - skb->data);
72695+ skb_trim(skb, (const unsigned char *) mark - skb->data);
72696 }
72697
72698 /**
72699diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
72700index c9c0c53..53f24c3 100644
72701--- a/include/net/netns/conntrack.h
72702+++ b/include/net/netns/conntrack.h
72703@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
72704 struct nf_proto_net {
72705 #ifdef CONFIG_SYSCTL
72706 struct ctl_table_header *ctl_table_header;
72707- struct ctl_table *ctl_table;
72708+ ctl_table_no_const *ctl_table;
72709 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
72710 struct ctl_table_header *ctl_compat_header;
72711- struct ctl_table *ctl_compat_table;
72712+ ctl_table_no_const *ctl_compat_table;
72713 #endif
72714 #endif
72715 unsigned int users;
72716@@ -58,7 +58,7 @@ struct nf_ip_net {
72717 struct nf_icmp_net icmpv6;
72718 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
72719 struct ctl_table_header *ctl_table_header;
72720- struct ctl_table *ctl_table;
72721+ ctl_table_no_const *ctl_table;
72722 #endif
72723 };
72724
72725diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
72726index 2ba9de8..47bd6c7 100644
72727--- a/include/net/netns/ipv4.h
72728+++ b/include/net/netns/ipv4.h
72729@@ -67,7 +67,7 @@ struct netns_ipv4 {
72730 kgid_t sysctl_ping_group_range[2];
72731 long sysctl_tcp_mem[3];
72732
72733- atomic_t dev_addr_genid;
72734+ atomic_unchecked_t dev_addr_genid;
72735
72736 #ifdef CONFIG_IP_MROUTE
72737 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
72738diff --git a/include/net/protocol.h b/include/net/protocol.h
72739index 047c047..b9dad15 100644
72740--- a/include/net/protocol.h
72741+++ b/include/net/protocol.h
72742@@ -44,7 +44,7 @@ struct net_protocol {
72743 void (*err_handler)(struct sk_buff *skb, u32 info);
72744 unsigned int no_policy:1,
72745 netns_ok:1;
72746-};
72747+} __do_const;
72748
72749 #if IS_ENABLED(CONFIG_IPV6)
72750 struct inet6_protocol {
72751@@ -57,7 +57,7 @@ struct inet6_protocol {
72752 u8 type, u8 code, int offset,
72753 __be32 info);
72754 unsigned int flags; /* INET6_PROTO_xxx */
72755-};
72756+} __do_const;
72757
72758 #define INET6_PROTO_NOPOLICY 0x1
72759 #define INET6_PROTO_FINAL 0x2
72760diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
72761index 5a15fab..d799ea7 100644
72762--- a/include/net/rtnetlink.h
72763+++ b/include/net/rtnetlink.h
72764@@ -81,7 +81,7 @@ struct rtnl_link_ops {
72765 const struct net_device *dev);
72766 unsigned int (*get_num_tx_queues)(void);
72767 unsigned int (*get_num_rx_queues)(void);
72768-};
72769+} __do_const;
72770
72771 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
72772 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
72773diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
72774index df85a0c..19ac300 100644
72775--- a/include/net/sctp/sctp.h
72776+++ b/include/net/sctp/sctp.h
72777@@ -330,9 +330,9 @@ do { \
72778
72779 #else /* SCTP_DEBUG */
72780
72781-#define SCTP_DEBUG_PRINTK(whatever...)
72782-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
72783-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
72784+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
72785+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
72786+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
72787 #define SCTP_ENABLE_DEBUG
72788 #define SCTP_DISABLE_DEBUG
72789 #define SCTP_ASSERT(expr, str, func)
72790diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
72791index 2a82d13..62a31c2 100644
72792--- a/include/net/sctp/sm.h
72793+++ b/include/net/sctp/sm.h
72794@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
72795 typedef struct {
72796 sctp_state_fn_t *fn;
72797 const char *name;
72798-} sctp_sm_table_entry_t;
72799+} __do_const sctp_sm_table_entry_t;
72800
72801 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
72802 * currently in use.
72803@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
72804 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
72805
72806 /* Extern declarations for major data structures. */
72807-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
72808+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
72809
72810
72811 /* Get the size of a DATA chunk payload. */
72812diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
72813index 0e0f9d2..cd05ebb 100644
72814--- a/include/net/sctp/structs.h
72815+++ b/include/net/sctp/structs.h
72816@@ -517,7 +517,7 @@ struct sctp_pf {
72817 struct sctp_association *asoc);
72818 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
72819 struct sctp_af *af;
72820-};
72821+} __do_const;
72822
72823
72824 /* Structure to track chunk fragments that have been acked, but peer
72825diff --git a/include/net/secure_seq.h b/include/net/secure_seq.h
72826index c2e542b..6ca975b 100644
72827--- a/include/net/secure_seq.h
72828+++ b/include/net/secure_seq.h
72829@@ -3,6 +3,7 @@
72830
72831 #include <linux/types.h>
72832
72833+extern void net_secret_init(void);
72834 extern __u32 secure_ip_id(__be32 daddr);
72835 extern __u32 secure_ipv6_id(const __be32 daddr[4]);
72836 extern u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport);
72837diff --git a/include/net/sock.h b/include/net/sock.h
72838index 0be480a..586232f 100644
72839--- a/include/net/sock.h
72840+++ b/include/net/sock.h
72841@@ -325,7 +325,7 @@ struct sock {
72842 #ifdef CONFIG_RPS
72843 __u32 sk_rxhash;
72844 #endif
72845- atomic_t sk_drops;
72846+ atomic_unchecked_t sk_drops;
72847 int sk_rcvbuf;
72848
72849 struct sk_filter __rcu *sk_filter;
72850@@ -1796,7 +1796,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
72851 }
72852
72853 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
72854- char __user *from, char *to,
72855+ char __user *from, unsigned char *to,
72856 int copy, int offset)
72857 {
72858 if (skb->ip_summed == CHECKSUM_NONE) {
72859@@ -2055,7 +2055,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
72860 }
72861 }
72862
72863-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
72864+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
72865
72866 /**
72867 * sk_page_frag - return an appropriate page_frag
72868diff --git a/include/net/tcp.h b/include/net/tcp.h
72869index a345480..3c65cf4 100644
72870--- a/include/net/tcp.h
72871+++ b/include/net/tcp.h
72872@@ -529,7 +529,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
72873 extern void tcp_xmit_retransmit_queue(struct sock *);
72874 extern void tcp_simple_retransmit(struct sock *);
72875 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
72876-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
72877+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
72878
72879 extern void tcp_send_probe0(struct sock *);
72880 extern void tcp_send_partial(struct sock *);
72881@@ -700,8 +700,8 @@ struct tcp_skb_cb {
72882 struct inet6_skb_parm h6;
72883 #endif
72884 } header; /* For incoming frames */
72885- __u32 seq; /* Starting sequence number */
72886- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
72887+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
72888+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
72889 __u32 when; /* used to compute rtt's */
72890 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
72891
72892@@ -715,7 +715,7 @@ struct tcp_skb_cb {
72893
72894 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
72895 /* 1 byte hole */
72896- __u32 ack_seq; /* Sequence number ACK'd */
72897+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
72898 };
72899
72900 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
72901diff --git a/include/net/xfrm.h b/include/net/xfrm.h
72902index 24c8886..e6fb816 100644
72903--- a/include/net/xfrm.h
72904+++ b/include/net/xfrm.h
72905@@ -304,7 +304,7 @@ struct xfrm_policy_afinfo {
72906 struct net_device *dev,
72907 const struct flowi *fl);
72908 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
72909-};
72910+} __do_const;
72911
72912 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
72913 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
72914@@ -340,7 +340,7 @@ struct xfrm_state_afinfo {
72915 struct sk_buff *skb);
72916 int (*transport_finish)(struct sk_buff *skb,
72917 int async);
72918-};
72919+} __do_const;
72920
72921 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
72922 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
72923@@ -423,7 +423,7 @@ struct xfrm_mode {
72924 struct module *owner;
72925 unsigned int encap;
72926 int flags;
72927-};
72928+} __do_const;
72929
72930 /* Flags for xfrm_mode. */
72931 enum {
72932@@ -520,7 +520,7 @@ struct xfrm_policy {
72933 struct timer_list timer;
72934
72935 struct flow_cache_object flo;
72936- atomic_t genid;
72937+ atomic_unchecked_t genid;
72938 u32 priority;
72939 u32 index;
72940 struct xfrm_mark mark;
72941diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
72942index 1a046b1..ee0bef0 100644
72943--- a/include/rdma/iw_cm.h
72944+++ b/include/rdma/iw_cm.h
72945@@ -122,7 +122,7 @@ struct iw_cm_verbs {
72946 int backlog);
72947
72948 int (*destroy_listen)(struct iw_cm_id *cm_id);
72949-};
72950+} __no_const;
72951
72952 /**
72953 * iw_create_cm_id - Create an IW CM identifier.
72954diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
72955index e1379b4..67eafbe 100644
72956--- a/include/scsi/libfc.h
72957+++ b/include/scsi/libfc.h
72958@@ -762,6 +762,7 @@ struct libfc_function_template {
72959 */
72960 void (*disc_stop_final) (struct fc_lport *);
72961 };
72962+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
72963
72964 /**
72965 * struct fc_disc - Discovery context
72966@@ -866,7 +867,7 @@ struct fc_lport {
72967 struct fc_vport *vport;
72968
72969 /* Operational Information */
72970- struct libfc_function_template tt;
72971+ libfc_function_template_no_const tt;
72972 u8 link_up;
72973 u8 qfull;
72974 enum fc_lport_state state;
72975diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
72976index a7f9cba..b1f44d0 100644
72977--- a/include/scsi/scsi_device.h
72978+++ b/include/scsi/scsi_device.h
72979@@ -171,9 +171,9 @@ struct scsi_device {
72980 unsigned int max_device_blocked; /* what device_blocked counts down from */
72981 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
72982
72983- atomic_t iorequest_cnt;
72984- atomic_t iodone_cnt;
72985- atomic_t ioerr_cnt;
72986+ atomic_unchecked_t iorequest_cnt;
72987+ atomic_unchecked_t iodone_cnt;
72988+ atomic_unchecked_t ioerr_cnt;
72989
72990 struct device sdev_gendev,
72991 sdev_dev;
72992diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
72993index b797e8f..8e2c3aa 100644
72994--- a/include/scsi/scsi_transport_fc.h
72995+++ b/include/scsi/scsi_transport_fc.h
72996@@ -751,7 +751,8 @@ struct fc_function_template {
72997 unsigned long show_host_system_hostname:1;
72998
72999 unsigned long disable_target_scan:1;
73000-};
73001+} __do_const;
73002+typedef struct fc_function_template __no_const fc_function_template_no_const;
73003
73004
73005 /**
73006diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
73007index ff6c741..393815f 100644
73008--- a/include/sound/compress_driver.h
73009+++ b/include/sound/compress_driver.h
73010@@ -130,7 +130,7 @@ struct snd_compr_ops {
73011 struct snd_compr_caps *caps);
73012 int (*get_codec_caps) (struct snd_compr_stream *stream,
73013 struct snd_compr_codec_caps *codec);
73014-};
73015+} __no_const;
73016
73017 /**
73018 * struct snd_compr: Compressed device
73019diff --git a/include/sound/soc.h b/include/sound/soc.h
73020index a6a059c..2243336 100644
73021--- a/include/sound/soc.h
73022+++ b/include/sound/soc.h
73023@@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
73024 /* probe ordering - for components with runtime dependencies */
73025 int probe_order;
73026 int remove_order;
73027-};
73028+} __do_const;
73029
73030 /* SoC platform interface */
73031 struct snd_soc_platform_driver {
73032@@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
73033 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
73034 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
73035 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
73036-};
73037+} __do_const;
73038
73039 struct snd_soc_platform {
73040 const char *name;
73041diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
73042index f8640f3..b72d113 100644
73043--- a/include/target/target_core_base.h
73044+++ b/include/target/target_core_base.h
73045@@ -658,7 +658,7 @@ struct se_device {
73046 spinlock_t stats_lock;
73047 /* Active commands on this virtual SE device */
73048 atomic_t simple_cmds;
73049- atomic_t dev_ordered_id;
73050+ atomic_unchecked_t dev_ordered_id;
73051 atomic_t dev_ordered_sync;
73052 atomic_t dev_qf_count;
73053 int export_count;
73054diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
73055new file mode 100644
73056index 0000000..fb634b7
73057--- /dev/null
73058+++ b/include/trace/events/fs.h
73059@@ -0,0 +1,53 @@
73060+#undef TRACE_SYSTEM
73061+#define TRACE_SYSTEM fs
73062+
73063+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
73064+#define _TRACE_FS_H
73065+
73066+#include <linux/fs.h>
73067+#include <linux/tracepoint.h>
73068+
73069+TRACE_EVENT(do_sys_open,
73070+
73071+ TP_PROTO(const char *filename, int flags, int mode),
73072+
73073+ TP_ARGS(filename, flags, mode),
73074+
73075+ TP_STRUCT__entry(
73076+ __string( filename, filename )
73077+ __field( int, flags )
73078+ __field( int, mode )
73079+ ),
73080+
73081+ TP_fast_assign(
73082+ __assign_str(filename, filename);
73083+ __entry->flags = flags;
73084+ __entry->mode = mode;
73085+ ),
73086+
73087+ TP_printk("\"%s\" %x %o",
73088+ __get_str(filename), __entry->flags, __entry->mode)
73089+);
73090+
73091+TRACE_EVENT(open_exec,
73092+
73093+ TP_PROTO(const char *filename),
73094+
73095+ TP_ARGS(filename),
73096+
73097+ TP_STRUCT__entry(
73098+ __string( filename, filename )
73099+ ),
73100+
73101+ TP_fast_assign(
73102+ __assign_str(filename, filename);
73103+ ),
73104+
73105+ TP_printk("\"%s\"",
73106+ __get_str(filename))
73107+);
73108+
73109+#endif /* _TRACE_FS_H */
73110+
73111+/* This part must be outside protection */
73112+#include <trace/define_trace.h>
73113diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
73114index 1c09820..7f5ec79 100644
73115--- a/include/trace/events/irq.h
73116+++ b/include/trace/events/irq.h
73117@@ -36,7 +36,7 @@ struct softirq_action;
73118 */
73119 TRACE_EVENT(irq_handler_entry,
73120
73121- TP_PROTO(int irq, struct irqaction *action),
73122+ TP_PROTO(int irq, const struct irqaction *action),
73123
73124 TP_ARGS(irq, action),
73125
73126@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
73127 */
73128 TRACE_EVENT(irq_handler_exit,
73129
73130- TP_PROTO(int irq, struct irqaction *action, int ret),
73131+ TP_PROTO(int irq, const struct irqaction *action, int ret),
73132
73133 TP_ARGS(irq, action, ret),
73134
73135diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
73136index 7caf44c..23c6f27 100644
73137--- a/include/uapi/linux/a.out.h
73138+++ b/include/uapi/linux/a.out.h
73139@@ -39,6 +39,14 @@ enum machine_type {
73140 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
73141 };
73142
73143+/* Constants for the N_FLAGS field */
73144+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
73145+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
73146+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
73147+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
73148+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
73149+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
73150+
73151 #if !defined (N_MAGIC)
73152 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
73153 #endif
73154diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
73155index d876736..ccce5c0 100644
73156--- a/include/uapi/linux/byteorder/little_endian.h
73157+++ b/include/uapi/linux/byteorder/little_endian.h
73158@@ -42,51 +42,51 @@
73159
73160 static inline __le64 __cpu_to_le64p(const __u64 *p)
73161 {
73162- return (__force __le64)*p;
73163+ return (__force const __le64)*p;
73164 }
73165-static inline __u64 __le64_to_cpup(const __le64 *p)
73166+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
73167 {
73168- return (__force __u64)*p;
73169+ return (__force const __u64)*p;
73170 }
73171 static inline __le32 __cpu_to_le32p(const __u32 *p)
73172 {
73173- return (__force __le32)*p;
73174+ return (__force const __le32)*p;
73175 }
73176 static inline __u32 __le32_to_cpup(const __le32 *p)
73177 {
73178- return (__force __u32)*p;
73179+ return (__force const __u32)*p;
73180 }
73181 static inline __le16 __cpu_to_le16p(const __u16 *p)
73182 {
73183- return (__force __le16)*p;
73184+ return (__force const __le16)*p;
73185 }
73186 static inline __u16 __le16_to_cpup(const __le16 *p)
73187 {
73188- return (__force __u16)*p;
73189+ return (__force const __u16)*p;
73190 }
73191 static inline __be64 __cpu_to_be64p(const __u64 *p)
73192 {
73193- return (__force __be64)__swab64p(p);
73194+ return (__force const __be64)__swab64p(p);
73195 }
73196 static inline __u64 __be64_to_cpup(const __be64 *p)
73197 {
73198- return __swab64p((__u64 *)p);
73199+ return __swab64p((const __u64 *)p);
73200 }
73201 static inline __be32 __cpu_to_be32p(const __u32 *p)
73202 {
73203- return (__force __be32)__swab32p(p);
73204+ return (__force const __be32)__swab32p(p);
73205 }
73206-static inline __u32 __be32_to_cpup(const __be32 *p)
73207+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
73208 {
73209- return __swab32p((__u32 *)p);
73210+ return __swab32p((const __u32 *)p);
73211 }
73212 static inline __be16 __cpu_to_be16p(const __u16 *p)
73213 {
73214- return (__force __be16)__swab16p(p);
73215+ return (__force const __be16)__swab16p(p);
73216 }
73217 static inline __u16 __be16_to_cpup(const __be16 *p)
73218 {
73219- return __swab16p((__u16 *)p);
73220+ return __swab16p((const __u16 *)p);
73221 }
73222 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
73223 #define __le64_to_cpus(x) do { (void)(x); } while (0)
73224diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
73225index 8072d35..e77aeb8 100644
73226--- a/include/uapi/linux/elf.h
73227+++ b/include/uapi/linux/elf.h
73228@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
73229 #define PT_GNU_EH_FRAME 0x6474e550
73230
73231 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
73232+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
73233+
73234+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
73235+
73236+/* Constants for the e_flags field */
73237+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
73238+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
73239+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
73240+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
73241+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
73242+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
73243
73244 /*
73245 * Extended Numbering
73246@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
73247 #define DT_DEBUG 21
73248 #define DT_TEXTREL 22
73249 #define DT_JMPREL 23
73250+#define DT_FLAGS 30
73251+ #define DF_TEXTREL 0x00000004
73252 #define DT_ENCODING 32
73253 #define OLD_DT_LOOS 0x60000000
73254 #define DT_LOOS 0x6000000d
73255@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
73256 #define PF_W 0x2
73257 #define PF_X 0x1
73258
73259+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
73260+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
73261+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
73262+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
73263+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
73264+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
73265+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
73266+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
73267+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
73268+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
73269+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
73270+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
73271+
73272 typedef struct elf32_phdr{
73273 Elf32_Word p_type;
73274 Elf32_Off p_offset;
73275@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
73276 #define EI_OSABI 7
73277 #define EI_PAD 8
73278
73279+#define EI_PAX 14
73280+
73281 #define ELFMAG0 0x7f /* EI_MAG */
73282 #define ELFMAG1 'E'
73283 #define ELFMAG2 'L'
73284diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
73285index aa169c4..6a2771d 100644
73286--- a/include/uapi/linux/personality.h
73287+++ b/include/uapi/linux/personality.h
73288@@ -30,6 +30,7 @@ enum {
73289 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
73290 ADDR_NO_RANDOMIZE | \
73291 ADDR_COMPAT_LAYOUT | \
73292+ ADDR_LIMIT_3GB | \
73293 MMAP_PAGE_ZERO)
73294
73295 /*
73296diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
73297index 7530e74..e714828 100644
73298--- a/include/uapi/linux/screen_info.h
73299+++ b/include/uapi/linux/screen_info.h
73300@@ -43,7 +43,8 @@ struct screen_info {
73301 __u16 pages; /* 0x32 */
73302 __u16 vesa_attributes; /* 0x34 */
73303 __u32 capabilities; /* 0x36 */
73304- __u8 _reserved[6]; /* 0x3a */
73305+ __u16 vesapm_size; /* 0x3a */
73306+ __u8 _reserved[4]; /* 0x3c */
73307 } __attribute__((packed));
73308
73309 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
73310diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
73311index 0e011eb..82681b1 100644
73312--- a/include/uapi/linux/swab.h
73313+++ b/include/uapi/linux/swab.h
73314@@ -43,7 +43,7 @@
73315 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
73316 */
73317
73318-static inline __attribute_const__ __u16 __fswab16(__u16 val)
73319+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
73320 {
73321 #ifdef __HAVE_BUILTIN_BSWAP16__
73322 return __builtin_bswap16(val);
73323@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
73324 #endif
73325 }
73326
73327-static inline __attribute_const__ __u32 __fswab32(__u32 val)
73328+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
73329 {
73330 #ifdef __HAVE_BUILTIN_BSWAP32__
73331 return __builtin_bswap32(val);
73332@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
73333 #endif
73334 }
73335
73336-static inline __attribute_const__ __u64 __fswab64(__u64 val)
73337+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
73338 {
73339 #ifdef __HAVE_BUILTIN_BSWAP64__
73340 return __builtin_bswap64(val);
73341diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
73342index 6d67213..8dab561 100644
73343--- a/include/uapi/linux/sysctl.h
73344+++ b/include/uapi/linux/sysctl.h
73345@@ -155,7 +155,11 @@ enum
73346 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
73347 };
73348
73349-
73350+#ifdef CONFIG_PAX_SOFTMODE
73351+enum {
73352+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
73353+};
73354+#endif
73355
73356 /* CTL_VM names: */
73357 enum
73358diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
73359index e4629b9..6958086 100644
73360--- a/include/uapi/linux/xattr.h
73361+++ b/include/uapi/linux/xattr.h
73362@@ -63,5 +63,9 @@
73363 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
73364 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
73365
73366+/* User namespace */
73367+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
73368+#define XATTR_PAX_FLAGS_SUFFIX "flags"
73369+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
73370
73371 #endif /* _UAPI_LINUX_XATTR_H */
73372diff --git a/include/video/udlfb.h b/include/video/udlfb.h
73373index f9466fa..f4e2b81 100644
73374--- a/include/video/udlfb.h
73375+++ b/include/video/udlfb.h
73376@@ -53,10 +53,10 @@ struct dlfb_data {
73377 u32 pseudo_palette[256];
73378 int blank_mode; /*one of FB_BLANK_ */
73379 /* blit-only rendering path metrics, exposed through sysfs */
73380- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
73381- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
73382- atomic_t bytes_sent; /* to usb, after compression including overhead */
73383- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
73384+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
73385+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
73386+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
73387+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
73388 };
73389
73390 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
73391diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
73392index 1a91850..28573f8 100644
73393--- a/include/video/uvesafb.h
73394+++ b/include/video/uvesafb.h
73395@@ -122,6 +122,7 @@ struct uvesafb_par {
73396 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
73397 u8 pmi_setpal; /* PMI for palette changes */
73398 u16 *pmi_base; /* protected mode interface location */
73399+ u8 *pmi_code; /* protected mode code location */
73400 void *pmi_start;
73401 void *pmi_pal;
73402 u8 *vbe_state_orig; /*
73403diff --git a/init/Kconfig b/init/Kconfig
73404index 5341d72..153f24f 100644
73405--- a/init/Kconfig
73406+++ b/init/Kconfig
73407@@ -984,6 +984,7 @@ endif # CGROUPS
73408
73409 config CHECKPOINT_RESTORE
73410 bool "Checkpoint/restore support" if EXPERT
73411+ depends on !GRKERNSEC
73412 default n
73413 help
73414 Enables additional kernel features in a sake of checkpoint/restore.
73415@@ -1471,7 +1472,7 @@ config SLUB_DEBUG
73416
73417 config COMPAT_BRK
73418 bool "Disable heap randomization"
73419- default y
73420+ default n
73421 help
73422 Randomizing heap placement makes heap exploits harder, but it
73423 also breaks ancient binaries (including anything libc5 based).
73424@@ -1734,7 +1735,7 @@ config INIT_ALL_POSSIBLE
73425 config STOP_MACHINE
73426 bool
73427 default y
73428- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
73429+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
73430 help
73431 Need stop_machine() primitive.
73432
73433diff --git a/init/Makefile b/init/Makefile
73434index 7bc47ee..6da2dc7 100644
73435--- a/init/Makefile
73436+++ b/init/Makefile
73437@@ -2,6 +2,9 @@
73438 # Makefile for the linux kernel.
73439 #
73440
73441+ccflags-y := $(GCC_PLUGINS_CFLAGS)
73442+asflags-y := $(GCC_PLUGINS_AFLAGS)
73443+
73444 obj-y := main.o version.o mounts.o
73445 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
73446 obj-y += noinitramfs.o
73447diff --git a/init/do_mounts.c b/init/do_mounts.c
73448index a2b49f2..03a0e17c 100644
73449--- a/init/do_mounts.c
73450+++ b/init/do_mounts.c
73451@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
73452 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
73453 {
73454 struct super_block *s;
73455- int err = sys_mount(name, "/root", fs, flags, data);
73456+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
73457 if (err)
73458 return err;
73459
73460- sys_chdir("/root");
73461+ sys_chdir((const char __force_user *)"/root");
73462 s = current->fs->pwd.dentry->d_sb;
73463 ROOT_DEV = s->s_dev;
73464 printk(KERN_INFO
73465@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
73466 va_start(args, fmt);
73467 vsprintf(buf, fmt, args);
73468 va_end(args);
73469- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
73470+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
73471 if (fd >= 0) {
73472 sys_ioctl(fd, FDEJECT, 0);
73473 sys_close(fd);
73474 }
73475 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
73476- fd = sys_open("/dev/console", O_RDWR, 0);
73477+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
73478 if (fd >= 0) {
73479 sys_ioctl(fd, TCGETS, (long)&termios);
73480 termios.c_lflag &= ~ICANON;
73481 sys_ioctl(fd, TCSETSF, (long)&termios);
73482- sys_read(fd, &c, 1);
73483+ sys_read(fd, (char __user *)&c, 1);
73484 termios.c_lflag |= ICANON;
73485 sys_ioctl(fd, TCSETSF, (long)&termios);
73486 sys_close(fd);
73487@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
73488 mount_root();
73489 out:
73490 devtmpfs_mount("dev");
73491- sys_mount(".", "/", NULL, MS_MOVE, NULL);
73492- sys_chroot(".");
73493+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
73494+ sys_chroot((const char __force_user *)".");
73495 }
73496diff --git a/init/do_mounts.h b/init/do_mounts.h
73497index f5b978a..69dbfe8 100644
73498--- a/init/do_mounts.h
73499+++ b/init/do_mounts.h
73500@@ -15,15 +15,15 @@ extern int root_mountflags;
73501
73502 static inline int create_dev(char *name, dev_t dev)
73503 {
73504- sys_unlink(name);
73505- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
73506+ sys_unlink((char __force_user *)name);
73507+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
73508 }
73509
73510 #if BITS_PER_LONG == 32
73511 static inline u32 bstat(char *name)
73512 {
73513 struct stat64 stat;
73514- if (sys_stat64(name, &stat) != 0)
73515+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
73516 return 0;
73517 if (!S_ISBLK(stat.st_mode))
73518 return 0;
73519@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
73520 static inline u32 bstat(char *name)
73521 {
73522 struct stat stat;
73523- if (sys_newstat(name, &stat) != 0)
73524+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
73525 return 0;
73526 if (!S_ISBLK(stat.st_mode))
73527 return 0;
73528diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
73529index a32ec1c..60a6659 100644
73530--- a/init/do_mounts_initrd.c
73531+++ b/init/do_mounts_initrd.c
73532@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
73533 {
73534 sys_unshare(CLONE_FS | CLONE_FILES);
73535 /* stdin/stdout/stderr for /linuxrc */
73536- sys_open("/dev/console", O_RDWR, 0);
73537+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
73538 sys_dup(0);
73539 sys_dup(0);
73540 /* move initrd over / and chdir/chroot in initrd root */
73541- sys_chdir("/root");
73542- sys_mount(".", "/", NULL, MS_MOVE, NULL);
73543- sys_chroot(".");
73544+ sys_chdir((const char __force_user *)"/root");
73545+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
73546+ sys_chroot((const char __force_user *)".");
73547 sys_setsid();
73548 return 0;
73549 }
73550@@ -58,8 +58,8 @@ static void __init handle_initrd(void)
73551 create_dev("/dev/root.old", Root_RAM0);
73552 /* mount initrd on rootfs' /root */
73553 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
73554- sys_mkdir("/old", 0700);
73555- sys_chdir("/old");
73556+ sys_mkdir((const char __force_user *)"/old", 0700);
73557+ sys_chdir((const char __force_user *)"/old");
73558
73559 /* try loading default modules from initrd */
73560 load_default_modules();
73561@@ -76,31 +76,31 @@ static void __init handle_initrd(void)
73562 current->flags &= ~PF_FREEZER_SKIP;
73563
73564 /* move initrd to rootfs' /old */
73565- sys_mount("..", ".", NULL, MS_MOVE, NULL);
73566+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
73567 /* switch root and cwd back to / of rootfs */
73568- sys_chroot("..");
73569+ sys_chroot((const char __force_user *)"..");
73570
73571 if (new_decode_dev(real_root_dev) == Root_RAM0) {
73572- sys_chdir("/old");
73573+ sys_chdir((const char __force_user *)"/old");
73574 return;
73575 }
73576
73577- sys_chdir("/");
73578+ sys_chdir((const char __force_user *)"/");
73579 ROOT_DEV = new_decode_dev(real_root_dev);
73580 mount_root();
73581
73582 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
73583- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
73584+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
73585 if (!error)
73586 printk("okay\n");
73587 else {
73588- int fd = sys_open("/dev/root.old", O_RDWR, 0);
73589+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
73590 if (error == -ENOENT)
73591 printk("/initrd does not exist. Ignored.\n");
73592 else
73593 printk("failed\n");
73594 printk(KERN_NOTICE "Unmounting old root\n");
73595- sys_umount("/old", MNT_DETACH);
73596+ sys_umount((char __force_user *)"/old", MNT_DETACH);
73597 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
73598 if (fd < 0) {
73599 error = fd;
73600@@ -123,11 +123,11 @@ int __init initrd_load(void)
73601 * mounted in the normal path.
73602 */
73603 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
73604- sys_unlink("/initrd.image");
73605+ sys_unlink((const char __force_user *)"/initrd.image");
73606 handle_initrd();
73607 return 1;
73608 }
73609 }
73610- sys_unlink("/initrd.image");
73611+ sys_unlink((const char __force_user *)"/initrd.image");
73612 return 0;
73613 }
73614diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
73615index 8cb6db5..d729f50 100644
73616--- a/init/do_mounts_md.c
73617+++ b/init/do_mounts_md.c
73618@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
73619 partitioned ? "_d" : "", minor,
73620 md_setup_args[ent].device_names);
73621
73622- fd = sys_open(name, 0, 0);
73623+ fd = sys_open((char __force_user *)name, 0, 0);
73624 if (fd < 0) {
73625 printk(KERN_ERR "md: open failed - cannot start "
73626 "array %s\n", name);
73627@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
73628 * array without it
73629 */
73630 sys_close(fd);
73631- fd = sys_open(name, 0, 0);
73632+ fd = sys_open((char __force_user *)name, 0, 0);
73633 sys_ioctl(fd, BLKRRPART, 0);
73634 }
73635 sys_close(fd);
73636@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
73637
73638 wait_for_device_probe();
73639
73640- fd = sys_open("/dev/md0", 0, 0);
73641+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
73642 if (fd >= 0) {
73643 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
73644 sys_close(fd);
73645diff --git a/init/init_task.c b/init/init_task.c
73646index ba0a7f36..2bcf1d5 100644
73647--- a/init/init_task.c
73648+++ b/init/init_task.c
73649@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
73650 * Initial thread structure. Alignment of this is handled by a special
73651 * linker map entry.
73652 */
73653+#ifdef CONFIG_X86
73654+union thread_union init_thread_union __init_task_data;
73655+#else
73656 union thread_union init_thread_union __init_task_data =
73657 { INIT_THREAD_INFO(init_task) };
73658+#endif
73659diff --git a/init/initramfs.c b/init/initramfs.c
73660index a67ef9d..3d88592 100644
73661--- a/init/initramfs.c
73662+++ b/init/initramfs.c
73663@@ -84,7 +84,7 @@ static void __init free_hash(void)
73664 }
73665 }
73666
73667-static long __init do_utime(char *filename, time_t mtime)
73668+static long __init do_utime(char __force_user *filename, time_t mtime)
73669 {
73670 struct timespec t[2];
73671
73672@@ -119,7 +119,7 @@ static void __init dir_utime(void)
73673 struct dir_entry *de, *tmp;
73674 list_for_each_entry_safe(de, tmp, &dir_list, list) {
73675 list_del(&de->list);
73676- do_utime(de->name, de->mtime);
73677+ do_utime((char __force_user *)de->name, de->mtime);
73678 kfree(de->name);
73679 kfree(de);
73680 }
73681@@ -281,7 +281,7 @@ static int __init maybe_link(void)
73682 if (nlink >= 2) {
73683 char *old = find_link(major, minor, ino, mode, collected);
73684 if (old)
73685- return (sys_link(old, collected) < 0) ? -1 : 1;
73686+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
73687 }
73688 return 0;
73689 }
73690@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
73691 {
73692 struct stat st;
73693
73694- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
73695+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
73696 if (S_ISDIR(st.st_mode))
73697- sys_rmdir(path);
73698+ sys_rmdir((char __force_user *)path);
73699 else
73700- sys_unlink(path);
73701+ sys_unlink((char __force_user *)path);
73702 }
73703 }
73704
73705@@ -315,7 +315,7 @@ static int __init do_name(void)
73706 int openflags = O_WRONLY|O_CREAT;
73707 if (ml != 1)
73708 openflags |= O_TRUNC;
73709- wfd = sys_open(collected, openflags, mode);
73710+ wfd = sys_open((char __force_user *)collected, openflags, mode);
73711
73712 if (wfd >= 0) {
73713 sys_fchown(wfd, uid, gid);
73714@@ -327,17 +327,17 @@ static int __init do_name(void)
73715 }
73716 }
73717 } else if (S_ISDIR(mode)) {
73718- sys_mkdir(collected, mode);
73719- sys_chown(collected, uid, gid);
73720- sys_chmod(collected, mode);
73721+ sys_mkdir((char __force_user *)collected, mode);
73722+ sys_chown((char __force_user *)collected, uid, gid);
73723+ sys_chmod((char __force_user *)collected, mode);
73724 dir_add(collected, mtime);
73725 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
73726 S_ISFIFO(mode) || S_ISSOCK(mode)) {
73727 if (maybe_link() == 0) {
73728- sys_mknod(collected, mode, rdev);
73729- sys_chown(collected, uid, gid);
73730- sys_chmod(collected, mode);
73731- do_utime(collected, mtime);
73732+ sys_mknod((char __force_user *)collected, mode, rdev);
73733+ sys_chown((char __force_user *)collected, uid, gid);
73734+ sys_chmod((char __force_user *)collected, mode);
73735+ do_utime((char __force_user *)collected, mtime);
73736 }
73737 }
73738 return 0;
73739@@ -346,15 +346,15 @@ static int __init do_name(void)
73740 static int __init do_copy(void)
73741 {
73742 if (count >= body_len) {
73743- sys_write(wfd, victim, body_len);
73744+ sys_write(wfd, (char __force_user *)victim, body_len);
73745 sys_close(wfd);
73746- do_utime(vcollected, mtime);
73747+ do_utime((char __force_user *)vcollected, mtime);
73748 kfree(vcollected);
73749 eat(body_len);
73750 state = SkipIt;
73751 return 0;
73752 } else {
73753- sys_write(wfd, victim, count);
73754+ sys_write(wfd, (char __force_user *)victim, count);
73755 body_len -= count;
73756 eat(count);
73757 return 1;
73758@@ -365,9 +365,9 @@ static int __init do_symlink(void)
73759 {
73760 collected[N_ALIGN(name_len) + body_len] = '\0';
73761 clean_path(collected, 0);
73762- sys_symlink(collected + N_ALIGN(name_len), collected);
73763- sys_lchown(collected, uid, gid);
73764- do_utime(collected, mtime);
73765+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
73766+ sys_lchown((char __force_user *)collected, uid, gid);
73767+ do_utime((char __force_user *)collected, mtime);
73768 state = SkipIt;
73769 next_state = Reset;
73770 return 0;
73771diff --git a/init/main.c b/init/main.c
73772index 63534a1..85feae2 100644
73773--- a/init/main.c
73774+++ b/init/main.c
73775@@ -98,6 +98,8 @@ static inline void mark_rodata_ro(void) { }
73776 extern void tc_init(void);
73777 #endif
73778
73779+extern void grsecurity_init(void);
73780+
73781 /*
73782 * Debug helper: via this flag we know that we are in 'early bootup code'
73783 * where only the boot processor is running with IRQ disabled. This means
73784@@ -151,6 +153,64 @@ static int __init set_reset_devices(char *str)
73785
73786 __setup("reset_devices", set_reset_devices);
73787
73788+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
73789+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
73790+static int __init setup_grsec_proc_gid(char *str)
73791+{
73792+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
73793+ return 1;
73794+}
73795+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
73796+#endif
73797+
73798+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
73799+unsigned long pax_user_shadow_base __read_only = 1UL << TASK_SIZE_MAX_SHIFT;
73800+EXPORT_SYMBOL(pax_user_shadow_base);
73801+extern char pax_enter_kernel_user[];
73802+extern char pax_exit_kernel_user[];
73803+extern pgdval_t clone_pgd_mask;
73804+#endif
73805+
73806+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
73807+static int __init setup_pax_nouderef(char *str)
73808+{
73809+#ifdef CONFIG_X86_32
73810+ unsigned int cpu;
73811+ struct desc_struct *gdt;
73812+
73813+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
73814+ gdt = get_cpu_gdt_table(cpu);
73815+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
73816+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
73817+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
73818+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
73819+ }
73820+ loadsegment(ds, __KERNEL_DS);
73821+ loadsegment(es, __KERNEL_DS);
73822+ loadsegment(ss, __KERNEL_DS);
73823+#else
73824+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
73825+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
73826+ clone_pgd_mask = ~(pgdval_t)0UL;
73827+ pax_user_shadow_base = 0UL;
73828+#endif
73829+
73830+ return 0;
73831+}
73832+early_param("pax_nouderef", setup_pax_nouderef);
73833+#endif
73834+
73835+#ifdef CONFIG_PAX_SOFTMODE
73836+int pax_softmode;
73837+
73838+static int __init setup_pax_softmode(char *str)
73839+{
73840+ get_option(&str, &pax_softmode);
73841+ return 1;
73842+}
73843+__setup("pax_softmode=", setup_pax_softmode);
73844+#endif
73845+
73846 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
73847 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
73848 static const char *panic_later, *panic_param;
73849@@ -683,6 +743,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
73850 {
73851 int count = preempt_count();
73852 int ret;
73853+ const char *msg1 = "", *msg2 = "";
73854
73855 if (initcall_debug)
73856 ret = do_one_initcall_debug(fn);
73857@@ -695,15 +756,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
73858 sprintf(msgbuf, "error code %d ", ret);
73859
73860 if (preempt_count() != count) {
73861- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
73862+ msg1 = " preemption imbalance";
73863 preempt_count() = count;
73864 }
73865 if (irqs_disabled()) {
73866- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
73867+ msg2 = " disabled interrupts";
73868 local_irq_enable();
73869 }
73870- if (msgbuf[0]) {
73871- printk("initcall %pF returned with %s\n", fn, msgbuf);
73872+ if (msgbuf[0] || *msg1 || *msg2) {
73873+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
73874 }
73875
73876 return ret;
73877@@ -757,8 +818,14 @@ static void __init do_initcall_level(int level)
73878 level, level,
73879 &repair_env_string);
73880
73881- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
73882+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
73883 do_one_initcall(*fn);
73884+
73885+#ifdef LATENT_ENTROPY_PLUGIN
73886+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
73887+#endif
73888+
73889+ }
73890 }
73891
73892 static void __init do_initcalls(void)
73893@@ -792,8 +859,14 @@ static void __init do_pre_smp_initcalls(void)
73894 {
73895 initcall_t *fn;
73896
73897- for (fn = __initcall_start; fn < __initcall0_start; fn++)
73898+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
73899 do_one_initcall(*fn);
73900+
73901+#ifdef LATENT_ENTROPY_PLUGIN
73902+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
73903+#endif
73904+
73905+ }
73906 }
73907
73908 /*
73909@@ -811,8 +884,8 @@ static int run_init_process(const char *init_filename)
73910 {
73911 argv_init[0] = init_filename;
73912 return do_execve(init_filename,
73913- (const char __user *const __user *)argv_init,
73914- (const char __user *const __user *)envp_init);
73915+ (const char __user *const __force_user *)argv_init,
73916+ (const char __user *const __force_user *)envp_init);
73917 }
73918
73919 static noinline void __init kernel_init_freeable(void);
73920@@ -890,7 +963,7 @@ static noinline void __init kernel_init_freeable(void)
73921 do_basic_setup();
73922
73923 /* Open the /dev/console on the rootfs, this should never fail */
73924- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
73925+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
73926 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
73927
73928 (void) sys_dup(0);
73929@@ -903,11 +976,13 @@ static noinline void __init kernel_init_freeable(void)
73930 if (!ramdisk_execute_command)
73931 ramdisk_execute_command = "/init";
73932
73933- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
73934+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
73935 ramdisk_execute_command = NULL;
73936 prepare_namespace();
73937 }
73938
73939+ grsecurity_init();
73940+
73941 /*
73942 * Ok, we have completed the initial bootup, and
73943 * we're essentially up and running. Get rid of the
73944diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
73945index 130dfec..cc88451 100644
73946--- a/ipc/ipc_sysctl.c
73947+++ b/ipc/ipc_sysctl.c
73948@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
73949 static int proc_ipc_dointvec(ctl_table *table, int write,
73950 void __user *buffer, size_t *lenp, loff_t *ppos)
73951 {
73952- struct ctl_table ipc_table;
73953+ ctl_table_no_const ipc_table;
73954
73955 memcpy(&ipc_table, table, sizeof(ipc_table));
73956 ipc_table.data = get_ipc(table);
73957@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
73958 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
73959 void __user *buffer, size_t *lenp, loff_t *ppos)
73960 {
73961- struct ctl_table ipc_table;
73962+ ctl_table_no_const ipc_table;
73963
73964 memcpy(&ipc_table, table, sizeof(ipc_table));
73965 ipc_table.data = get_ipc(table);
73966@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
73967 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
73968 void __user *buffer, size_t *lenp, loff_t *ppos)
73969 {
73970- struct ctl_table ipc_table;
73971+ ctl_table_no_const ipc_table;
73972 size_t lenp_bef = *lenp;
73973 int rc;
73974
73975@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
73976 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
73977 void __user *buffer, size_t *lenp, loff_t *ppos)
73978 {
73979- struct ctl_table ipc_table;
73980+ ctl_table_no_const ipc_table;
73981 memcpy(&ipc_table, table, sizeof(ipc_table));
73982 ipc_table.data = get_ipc(table);
73983
73984@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
73985 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
73986 void __user *buffer, size_t *lenp, loff_t *ppos)
73987 {
73988- struct ctl_table ipc_table;
73989+ ctl_table_no_const ipc_table;
73990 size_t lenp_bef = *lenp;
73991 int oldval;
73992 int rc;
73993diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
73994index 383d638..943fdbb 100644
73995--- a/ipc/mq_sysctl.c
73996+++ b/ipc/mq_sysctl.c
73997@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
73998 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
73999 void __user *buffer, size_t *lenp, loff_t *ppos)
74000 {
74001- struct ctl_table mq_table;
74002+ ctl_table_no_const mq_table;
74003 memcpy(&mq_table, table, sizeof(mq_table));
74004 mq_table.data = get_mq(table);
74005
74006diff --git a/ipc/mqueue.c b/ipc/mqueue.c
74007index e4e47f6..a85e0ad 100644
74008--- a/ipc/mqueue.c
74009+++ b/ipc/mqueue.c
74010@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
74011 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
74012 info->attr.mq_msgsize);
74013
74014+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
74015 spin_lock(&mq_lock);
74016 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
74017 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
74018diff --git a/ipc/msg.c b/ipc/msg.c
74019index fede1d0..9778e0f8 100644
74020--- a/ipc/msg.c
74021+++ b/ipc/msg.c
74022@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
74023 return security_msg_queue_associate(msq, msgflg);
74024 }
74025
74026+static struct ipc_ops msg_ops = {
74027+ .getnew = newque,
74028+ .associate = msg_security,
74029+ .more_checks = NULL
74030+};
74031+
74032 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
74033 {
74034 struct ipc_namespace *ns;
74035- struct ipc_ops msg_ops;
74036 struct ipc_params msg_params;
74037
74038 ns = current->nsproxy->ipc_ns;
74039
74040- msg_ops.getnew = newque;
74041- msg_ops.associate = msg_security;
74042- msg_ops.more_checks = NULL;
74043-
74044 msg_params.key = key;
74045 msg_params.flg = msgflg;
74046
74047diff --git a/ipc/sem.c b/ipc/sem.c
74048index 58d31f1..cce7a55 100644
74049--- a/ipc/sem.c
74050+++ b/ipc/sem.c
74051@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
74052 return 0;
74053 }
74054
74055+static struct ipc_ops sem_ops = {
74056+ .getnew = newary,
74057+ .associate = sem_security,
74058+ .more_checks = sem_more_checks
74059+};
74060+
74061 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
74062 {
74063 struct ipc_namespace *ns;
74064- struct ipc_ops sem_ops;
74065 struct ipc_params sem_params;
74066
74067 ns = current->nsproxy->ipc_ns;
74068@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
74069 if (nsems < 0 || nsems > ns->sc_semmsl)
74070 return -EINVAL;
74071
74072- sem_ops.getnew = newary;
74073- sem_ops.associate = sem_security;
74074- sem_ops.more_checks = sem_more_checks;
74075-
74076 sem_params.key = key;
74077 sem_params.flg = semflg;
74078 sem_params.u.nsems = nsems;
74079diff --git a/ipc/shm.c b/ipc/shm.c
74080index 7e199fa..180a1ca 100644
74081--- a/ipc/shm.c
74082+++ b/ipc/shm.c
74083@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
74084 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
74085 #endif
74086
74087+#ifdef CONFIG_GRKERNSEC
74088+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74089+ const time_t shm_createtime, const kuid_t cuid,
74090+ const int shmid);
74091+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74092+ const time_t shm_createtime);
74093+#endif
74094+
74095 void shm_init_ns(struct ipc_namespace *ns)
74096 {
74097 ns->shm_ctlmax = SHMMAX;
74098@@ -531,6 +539,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
74099 shp->shm_lprid = 0;
74100 shp->shm_atim = shp->shm_dtim = 0;
74101 shp->shm_ctim = get_seconds();
74102+#ifdef CONFIG_GRKERNSEC
74103+ {
74104+ struct timespec timeval;
74105+ do_posix_clock_monotonic_gettime(&timeval);
74106+
74107+ shp->shm_createtime = timeval.tv_sec;
74108+ }
74109+#endif
74110 shp->shm_segsz = size;
74111 shp->shm_nattch = 0;
74112 shp->shm_file = file;
74113@@ -582,18 +598,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
74114 return 0;
74115 }
74116
74117+static struct ipc_ops shm_ops = {
74118+ .getnew = newseg,
74119+ .associate = shm_security,
74120+ .more_checks = shm_more_checks
74121+};
74122+
74123 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
74124 {
74125 struct ipc_namespace *ns;
74126- struct ipc_ops shm_ops;
74127 struct ipc_params shm_params;
74128
74129 ns = current->nsproxy->ipc_ns;
74130
74131- shm_ops.getnew = newseg;
74132- shm_ops.associate = shm_security;
74133- shm_ops.more_checks = shm_more_checks;
74134-
74135 shm_params.key = key;
74136 shm_params.flg = shmflg;
74137 shm_params.u.size = size;
74138@@ -1014,6 +1031,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
74139 f_mode = FMODE_READ | FMODE_WRITE;
74140 }
74141 if (shmflg & SHM_EXEC) {
74142+
74143+#ifdef CONFIG_PAX_MPROTECT
74144+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
74145+ goto out;
74146+#endif
74147+
74148 prot |= PROT_EXEC;
74149 acc_mode |= S_IXUGO;
74150 }
74151@@ -1037,9 +1060,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
74152 if (err)
74153 goto out_unlock;
74154
74155+#ifdef CONFIG_GRKERNSEC
74156+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
74157+ shp->shm_perm.cuid, shmid) ||
74158+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
74159+ err = -EACCES;
74160+ goto out_unlock;
74161+ }
74162+#endif
74163+
74164 path = shp->shm_file->f_path;
74165 path_get(&path);
74166 shp->shm_nattch++;
74167+#ifdef CONFIG_GRKERNSEC
74168+ shp->shm_lapid = current->pid;
74169+#endif
74170 size = i_size_read(path.dentry->d_inode);
74171 shm_unlock(shp);
74172
74173diff --git a/kernel/acct.c b/kernel/acct.c
74174index b9bd7f0..1762b4a 100644
74175--- a/kernel/acct.c
74176+++ b/kernel/acct.c
74177@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
74178 */
74179 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
74180 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
74181- file->f_op->write(file, (char *)&ac,
74182+ file->f_op->write(file, (char __force_user *)&ac,
74183 sizeof(acct_t), &file->f_pos);
74184 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
74185 set_fs(fs);
74186diff --git a/kernel/audit.c b/kernel/audit.c
74187index d596e53..dbef3c3 100644
74188--- a/kernel/audit.c
74189+++ b/kernel/audit.c
74190@@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
74191 3) suppressed due to audit_rate_limit
74192 4) suppressed due to audit_backlog_limit
74193 */
74194-static atomic_t audit_lost = ATOMIC_INIT(0);
74195+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
74196
74197 /* The netlink socket. */
74198 static struct sock *audit_sock;
74199@@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
74200 unsigned long now;
74201 int print;
74202
74203- atomic_inc(&audit_lost);
74204+ atomic_inc_unchecked(&audit_lost);
74205
74206 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
74207
74208@@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
74209 printk(KERN_WARNING
74210 "audit: audit_lost=%d audit_rate_limit=%d "
74211 "audit_backlog_limit=%d\n",
74212- atomic_read(&audit_lost),
74213+ atomic_read_unchecked(&audit_lost),
74214 audit_rate_limit,
74215 audit_backlog_limit);
74216 audit_panic(message);
74217@@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
74218 status_set.pid = audit_pid;
74219 status_set.rate_limit = audit_rate_limit;
74220 status_set.backlog_limit = audit_backlog_limit;
74221- status_set.lost = atomic_read(&audit_lost);
74222+ status_set.lost = atomic_read_unchecked(&audit_lost);
74223 status_set.backlog = skb_queue_len(&audit_skb_queue);
74224 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
74225 &status_set, sizeof(status_set));
74226diff --git a/kernel/auditsc.c b/kernel/auditsc.c
74227index c4b72b0..8654c4e 100644
74228--- a/kernel/auditsc.c
74229+++ b/kernel/auditsc.c
74230@@ -2295,7 +2295,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
74231 }
74232
74233 /* global counter which is incremented every time something logs in */
74234-static atomic_t session_id = ATOMIC_INIT(0);
74235+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
74236
74237 /**
74238 * audit_set_loginuid - set current task's audit_context loginuid
74239@@ -2319,7 +2319,7 @@ int audit_set_loginuid(kuid_t loginuid)
74240 return -EPERM;
74241 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
74242
74243- sessionid = atomic_inc_return(&session_id);
74244+ sessionid = atomic_inc_return_unchecked(&session_id);
74245 if (context && context->in_syscall) {
74246 struct audit_buffer *ab;
74247
74248diff --git a/kernel/capability.c b/kernel/capability.c
74249index f6c2ce5..982c0f9 100644
74250--- a/kernel/capability.c
74251+++ b/kernel/capability.c
74252@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
74253 * before modification is attempted and the application
74254 * fails.
74255 */
74256+ if (tocopy > ARRAY_SIZE(kdata))
74257+ return -EFAULT;
74258+
74259 if (copy_to_user(dataptr, kdata, tocopy
74260 * sizeof(struct __user_cap_data_struct))) {
74261 return -EFAULT;
74262@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
74263 int ret;
74264
74265 rcu_read_lock();
74266- ret = security_capable(__task_cred(t), ns, cap);
74267+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
74268+ gr_task_is_capable(t, __task_cred(t), cap);
74269 rcu_read_unlock();
74270
74271- return (ret == 0);
74272+ return ret;
74273 }
74274
74275 /**
74276@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
74277 int ret;
74278
74279 rcu_read_lock();
74280- ret = security_capable_noaudit(__task_cred(t), ns, cap);
74281+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
74282 rcu_read_unlock();
74283
74284- return (ret == 0);
74285+ return ret;
74286 }
74287
74288 /**
74289@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
74290 BUG();
74291 }
74292
74293- if (security_capable(current_cred(), ns, cap) == 0) {
74294+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
74295 current->flags |= PF_SUPERPRIV;
74296 return true;
74297 }
74298@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
74299 }
74300 EXPORT_SYMBOL(ns_capable);
74301
74302+bool ns_capable_nolog(struct user_namespace *ns, int cap)
74303+{
74304+ if (unlikely(!cap_valid(cap))) {
74305+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
74306+ BUG();
74307+ }
74308+
74309+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
74310+ current->flags |= PF_SUPERPRIV;
74311+ return true;
74312+ }
74313+ return false;
74314+}
74315+EXPORT_SYMBOL(ns_capable_nolog);
74316+
74317 /**
74318 * file_ns_capable - Determine if the file's opener had a capability in effect
74319 * @file: The file we want to check
74320@@ -432,6 +451,12 @@ bool capable(int cap)
74321 }
74322 EXPORT_SYMBOL(capable);
74323
74324+bool capable_nolog(int cap)
74325+{
74326+ return ns_capable_nolog(&init_user_ns, cap);
74327+}
74328+EXPORT_SYMBOL(capable_nolog);
74329+
74330 /**
74331 * nsown_capable - Check superior capability to one's own user_ns
74332 * @cap: The capability in question
74333@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
74334
74335 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
74336 }
74337+
74338+bool inode_capable_nolog(const struct inode *inode, int cap)
74339+{
74340+ struct user_namespace *ns = current_user_ns();
74341+
74342+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
74343+}
74344diff --git a/kernel/cgroup.c b/kernel/cgroup.c
74345index a48de6a..df24bfe 100644
74346--- a/kernel/cgroup.c
74347+++ b/kernel/cgroup.c
74348@@ -5567,7 +5567,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
74349 struct css_set *cg = link->cg;
74350 struct task_struct *task;
74351 int count = 0;
74352- seq_printf(seq, "css_set %p\n", cg);
74353+ seq_printf(seq, "css_set %pK\n", cg);
74354 list_for_each_entry(task, &cg->tasks, cg_list) {
74355 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
74356 seq_puts(seq, " ...\n");
74357diff --git a/kernel/compat.c b/kernel/compat.c
74358index 19971d8..02fe2df 100644
74359--- a/kernel/compat.c
74360+++ b/kernel/compat.c
74361@@ -13,6 +13,7 @@
74362
74363 #include <linux/linkage.h>
74364 #include <linux/compat.h>
74365+#include <linux/module.h>
74366 #include <linux/errno.h>
74367 #include <linux/time.h>
74368 #include <linux/signal.h>
74369@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
74370 mm_segment_t oldfs;
74371 long ret;
74372
74373- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
74374+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
74375 oldfs = get_fs();
74376 set_fs(KERNEL_DS);
74377 ret = hrtimer_nanosleep_restart(restart);
74378@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
74379 oldfs = get_fs();
74380 set_fs(KERNEL_DS);
74381 ret = hrtimer_nanosleep(&tu,
74382- rmtp ? (struct timespec __user *)&rmt : NULL,
74383+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
74384 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
74385 set_fs(oldfs);
74386
74387@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
74388 mm_segment_t old_fs = get_fs();
74389
74390 set_fs(KERNEL_DS);
74391- ret = sys_sigpending((old_sigset_t __user *) &s);
74392+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
74393 set_fs(old_fs);
74394 if (ret == 0)
74395 ret = put_user(s, set);
74396@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
74397 mm_segment_t old_fs = get_fs();
74398
74399 set_fs(KERNEL_DS);
74400- ret = sys_old_getrlimit(resource, &r);
74401+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
74402 set_fs(old_fs);
74403
74404 if (!ret) {
74405@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
74406 mm_segment_t old_fs = get_fs();
74407
74408 set_fs(KERNEL_DS);
74409- ret = sys_getrusage(who, (struct rusage __user *) &r);
74410+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
74411 set_fs(old_fs);
74412
74413 if (ret)
74414@@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
74415 set_fs (KERNEL_DS);
74416 ret = sys_wait4(pid,
74417 (stat_addr ?
74418- (unsigned int __user *) &status : NULL),
74419- options, (struct rusage __user *) &r);
74420+ (unsigned int __force_user *) &status : NULL),
74421+ options, (struct rusage __force_user *) &r);
74422 set_fs (old_fs);
74423
74424 if (ret > 0) {
74425@@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
74426 memset(&info, 0, sizeof(info));
74427
74428 set_fs(KERNEL_DS);
74429- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
74430- uru ? (struct rusage __user *)&ru : NULL);
74431+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
74432+ uru ? (struct rusage __force_user *)&ru : NULL);
74433 set_fs(old_fs);
74434
74435 if ((ret < 0) || (info.si_signo == 0))
74436@@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
74437 oldfs = get_fs();
74438 set_fs(KERNEL_DS);
74439 err = sys_timer_settime(timer_id, flags,
74440- (struct itimerspec __user *) &newts,
74441- (struct itimerspec __user *) &oldts);
74442+ (struct itimerspec __force_user *) &newts,
74443+ (struct itimerspec __force_user *) &oldts);
74444 set_fs(oldfs);
74445 if (!err && old && put_compat_itimerspec(old, &oldts))
74446 return -EFAULT;
74447@@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
74448 oldfs = get_fs();
74449 set_fs(KERNEL_DS);
74450 err = sys_timer_gettime(timer_id,
74451- (struct itimerspec __user *) &ts);
74452+ (struct itimerspec __force_user *) &ts);
74453 set_fs(oldfs);
74454 if (!err && put_compat_itimerspec(setting, &ts))
74455 return -EFAULT;
74456@@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
74457 oldfs = get_fs();
74458 set_fs(KERNEL_DS);
74459 err = sys_clock_settime(which_clock,
74460- (struct timespec __user *) &ts);
74461+ (struct timespec __force_user *) &ts);
74462 set_fs(oldfs);
74463 return err;
74464 }
74465@@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
74466 oldfs = get_fs();
74467 set_fs(KERNEL_DS);
74468 err = sys_clock_gettime(which_clock,
74469- (struct timespec __user *) &ts);
74470+ (struct timespec __force_user *) &ts);
74471 set_fs(oldfs);
74472 if (!err && put_compat_timespec(&ts, tp))
74473 return -EFAULT;
74474@@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
74475
74476 oldfs = get_fs();
74477 set_fs(KERNEL_DS);
74478- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
74479+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
74480 set_fs(oldfs);
74481
74482 err = compat_put_timex(utp, &txc);
74483@@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
74484 oldfs = get_fs();
74485 set_fs(KERNEL_DS);
74486 err = sys_clock_getres(which_clock,
74487- (struct timespec __user *) &ts);
74488+ (struct timespec __force_user *) &ts);
74489 set_fs(oldfs);
74490 if (!err && tp && put_compat_timespec(&ts, tp))
74491 return -EFAULT;
74492@@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
74493 long err;
74494 mm_segment_t oldfs;
74495 struct timespec tu;
74496- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
74497+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
74498
74499- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
74500+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
74501 oldfs = get_fs();
74502 set_fs(KERNEL_DS);
74503 err = clock_nanosleep_restart(restart);
74504@@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
74505 oldfs = get_fs();
74506 set_fs(KERNEL_DS);
74507 err = sys_clock_nanosleep(which_clock, flags,
74508- (struct timespec __user *) &in,
74509- (struct timespec __user *) &out);
74510+ (struct timespec __force_user *) &in,
74511+ (struct timespec __force_user *) &out);
74512 set_fs(oldfs);
74513
74514 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
74515diff --git a/kernel/configs.c b/kernel/configs.c
74516index 42e8fa0..9e7406b 100644
74517--- a/kernel/configs.c
74518+++ b/kernel/configs.c
74519@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
74520 struct proc_dir_entry *entry;
74521
74522 /* create the current config file */
74523+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
74524+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
74525+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
74526+ &ikconfig_file_ops);
74527+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
74528+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
74529+ &ikconfig_file_ops);
74530+#endif
74531+#else
74532 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
74533 &ikconfig_file_ops);
74534+#endif
74535+
74536 if (!entry)
74537 return -ENOMEM;
74538
74539diff --git a/kernel/cred.c b/kernel/cred.c
74540index e0573a4..3874e41 100644
74541--- a/kernel/cred.c
74542+++ b/kernel/cred.c
74543@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
74544 validate_creds(cred);
74545 alter_cred_subscribers(cred, -1);
74546 put_cred(cred);
74547+
74548+#ifdef CONFIG_GRKERNSEC_SETXID
74549+ cred = (struct cred *) tsk->delayed_cred;
74550+ if (cred != NULL) {
74551+ tsk->delayed_cred = NULL;
74552+ validate_creds(cred);
74553+ alter_cred_subscribers(cred, -1);
74554+ put_cred(cred);
74555+ }
74556+#endif
74557 }
74558
74559 /**
74560@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
74561 * Always returns 0 thus allowing this function to be tail-called at the end
74562 * of, say, sys_setgid().
74563 */
74564-int commit_creds(struct cred *new)
74565+static int __commit_creds(struct cred *new)
74566 {
74567 struct task_struct *task = current;
74568 const struct cred *old = task->real_cred;
74569@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
74570
74571 get_cred(new); /* we will require a ref for the subj creds too */
74572
74573+ gr_set_role_label(task, new->uid, new->gid);
74574+
74575 /* dumpability changes */
74576 if (!uid_eq(old->euid, new->euid) ||
74577 !gid_eq(old->egid, new->egid) ||
74578@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
74579 put_cred(old);
74580 return 0;
74581 }
74582+#ifdef CONFIG_GRKERNSEC_SETXID
74583+extern int set_user(struct cred *new);
74584+
74585+void gr_delayed_cred_worker(void)
74586+{
74587+ const struct cred *new = current->delayed_cred;
74588+ struct cred *ncred;
74589+
74590+ current->delayed_cred = NULL;
74591+
74592+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
74593+ // from doing get_cred on it when queueing this
74594+ put_cred(new);
74595+ return;
74596+ } else if (new == NULL)
74597+ return;
74598+
74599+ ncred = prepare_creds();
74600+ if (!ncred)
74601+ goto die;
74602+ // uids
74603+ ncred->uid = new->uid;
74604+ ncred->euid = new->euid;
74605+ ncred->suid = new->suid;
74606+ ncred->fsuid = new->fsuid;
74607+ // gids
74608+ ncred->gid = new->gid;
74609+ ncred->egid = new->egid;
74610+ ncred->sgid = new->sgid;
74611+ ncred->fsgid = new->fsgid;
74612+ // groups
74613+ if (set_groups(ncred, new->group_info) < 0) {
74614+ abort_creds(ncred);
74615+ goto die;
74616+ }
74617+ // caps
74618+ ncred->securebits = new->securebits;
74619+ ncred->cap_inheritable = new->cap_inheritable;
74620+ ncred->cap_permitted = new->cap_permitted;
74621+ ncred->cap_effective = new->cap_effective;
74622+ ncred->cap_bset = new->cap_bset;
74623+
74624+ if (set_user(ncred)) {
74625+ abort_creds(ncred);
74626+ goto die;
74627+ }
74628+
74629+ // from doing get_cred on it when queueing this
74630+ put_cred(new);
74631+
74632+ __commit_creds(ncred);
74633+ return;
74634+die:
74635+ // from doing get_cred on it when queueing this
74636+ put_cred(new);
74637+ do_group_exit(SIGKILL);
74638+}
74639+#endif
74640+
74641+int commit_creds(struct cred *new)
74642+{
74643+#ifdef CONFIG_GRKERNSEC_SETXID
74644+ int ret;
74645+ int schedule_it = 0;
74646+ struct task_struct *t;
74647+
74648+ /* we won't get called with tasklist_lock held for writing
74649+ and interrupts disabled as the cred struct in that case is
74650+ init_cred
74651+ */
74652+ if (grsec_enable_setxid && !current_is_single_threaded() &&
74653+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
74654+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
74655+ schedule_it = 1;
74656+ }
74657+ ret = __commit_creds(new);
74658+ if (schedule_it) {
74659+ rcu_read_lock();
74660+ read_lock(&tasklist_lock);
74661+ for (t = next_thread(current); t != current;
74662+ t = next_thread(t)) {
74663+ if (t->delayed_cred == NULL) {
74664+ t->delayed_cred = get_cred(new);
74665+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
74666+ set_tsk_need_resched(t);
74667+ }
74668+ }
74669+ read_unlock(&tasklist_lock);
74670+ rcu_read_unlock();
74671+ }
74672+ return ret;
74673+#else
74674+ return __commit_creds(new);
74675+#endif
74676+}
74677+
74678 EXPORT_SYMBOL(commit_creds);
74679
74680 /**
74681diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
74682index c26278f..e323fb8 100644
74683--- a/kernel/debug/debug_core.c
74684+++ b/kernel/debug/debug_core.c
74685@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
74686 */
74687 static atomic_t masters_in_kgdb;
74688 static atomic_t slaves_in_kgdb;
74689-static atomic_t kgdb_break_tasklet_var;
74690+static atomic_unchecked_t kgdb_break_tasklet_var;
74691 atomic_t kgdb_setting_breakpoint;
74692
74693 struct task_struct *kgdb_usethread;
74694@@ -133,7 +133,7 @@ int kgdb_single_step;
74695 static pid_t kgdb_sstep_pid;
74696
74697 /* to keep track of the CPU which is doing the single stepping*/
74698-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
74699+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
74700
74701 /*
74702 * If you are debugging a problem where roundup (the collection of
74703@@ -541,7 +541,7 @@ return_normal:
74704 * kernel will only try for the value of sstep_tries before
74705 * giving up and continuing on.
74706 */
74707- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
74708+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
74709 (kgdb_info[cpu].task &&
74710 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
74711 atomic_set(&kgdb_active, -1);
74712@@ -635,8 +635,8 @@ cpu_master_loop:
74713 }
74714
74715 kgdb_restore:
74716- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
74717- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
74718+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
74719+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
74720 if (kgdb_info[sstep_cpu].task)
74721 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
74722 else
74723@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
74724 static void kgdb_tasklet_bpt(unsigned long ing)
74725 {
74726 kgdb_breakpoint();
74727- atomic_set(&kgdb_break_tasklet_var, 0);
74728+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
74729 }
74730
74731 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
74732
74733 void kgdb_schedule_breakpoint(void)
74734 {
74735- if (atomic_read(&kgdb_break_tasklet_var) ||
74736+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
74737 atomic_read(&kgdb_active) != -1 ||
74738 atomic_read(&kgdb_setting_breakpoint))
74739 return;
74740- atomic_inc(&kgdb_break_tasklet_var);
74741+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
74742 tasklet_schedule(&kgdb_tasklet_breakpoint);
74743 }
74744 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
74745diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
74746index 00eb8f7..d7e3244 100644
74747--- a/kernel/debug/kdb/kdb_main.c
74748+++ b/kernel/debug/kdb/kdb_main.c
74749@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
74750 continue;
74751
74752 kdb_printf("%-20s%8u 0x%p ", mod->name,
74753- mod->core_size, (void *)mod);
74754+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
74755 #ifdef CONFIG_MODULE_UNLOAD
74756 kdb_printf("%4ld ", module_refcount(mod));
74757 #endif
74758@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
74759 kdb_printf(" (Loading)");
74760 else
74761 kdb_printf(" (Live)");
74762- kdb_printf(" 0x%p", mod->module_core);
74763+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
74764
74765 #ifdef CONFIG_MODULE_UNLOAD
74766 {
74767diff --git a/kernel/events/core.c b/kernel/events/core.c
74768index 9fcb094..353baaaf 100644
74769--- a/kernel/events/core.c
74770+++ b/kernel/events/core.c
74771@@ -154,8 +154,15 @@ static struct srcu_struct pmus_srcu;
74772 * 0 - disallow raw tracepoint access for unpriv
74773 * 1 - disallow cpu events for unpriv
74774 * 2 - disallow kernel profiling for unpriv
74775+ * 3 - disallow all unpriv perf event use
74776 */
74777-int sysctl_perf_event_paranoid __read_mostly = 1;
74778+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
74779+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
74780+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
74781+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
74782+#else
74783+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
74784+#endif
74785
74786 /* Minimum for 512 kiB + 1 user control page */
74787 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
74788@@ -182,7 +189,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
74789 return 0;
74790 }
74791
74792-static atomic64_t perf_event_id;
74793+static atomic64_unchecked_t perf_event_id;
74794
74795 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
74796 enum event_type_t event_type);
74797@@ -2677,7 +2684,7 @@ static void __perf_event_read(void *info)
74798
74799 static inline u64 perf_event_count(struct perf_event *event)
74800 {
74801- return local64_read(&event->count) + atomic64_read(&event->child_count);
74802+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
74803 }
74804
74805 static u64 perf_event_read(struct perf_event *event)
74806@@ -3007,9 +3014,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
74807 mutex_lock(&event->child_mutex);
74808 total += perf_event_read(event);
74809 *enabled += event->total_time_enabled +
74810- atomic64_read(&event->child_total_time_enabled);
74811+ atomic64_read_unchecked(&event->child_total_time_enabled);
74812 *running += event->total_time_running +
74813- atomic64_read(&event->child_total_time_running);
74814+ atomic64_read_unchecked(&event->child_total_time_running);
74815
74816 list_for_each_entry(child, &event->child_list, child_list) {
74817 total += perf_event_read(child);
74818@@ -3412,10 +3419,10 @@ void perf_event_update_userpage(struct perf_event *event)
74819 userpg->offset -= local64_read(&event->hw.prev_count);
74820
74821 userpg->time_enabled = enabled +
74822- atomic64_read(&event->child_total_time_enabled);
74823+ atomic64_read_unchecked(&event->child_total_time_enabled);
74824
74825 userpg->time_running = running +
74826- atomic64_read(&event->child_total_time_running);
74827+ atomic64_read_unchecked(&event->child_total_time_running);
74828
74829 arch_perf_update_userpage(userpg, now);
74830
74831@@ -3886,7 +3893,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
74832
74833 /* Data. */
74834 sp = perf_user_stack_pointer(regs);
74835- rem = __output_copy_user(handle, (void *) sp, dump_size);
74836+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
74837 dyn_size = dump_size - rem;
74838
74839 perf_output_skip(handle, rem);
74840@@ -3974,11 +3981,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
74841 values[n++] = perf_event_count(event);
74842 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
74843 values[n++] = enabled +
74844- atomic64_read(&event->child_total_time_enabled);
74845+ atomic64_read_unchecked(&event->child_total_time_enabled);
74846 }
74847 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
74848 values[n++] = running +
74849- atomic64_read(&event->child_total_time_running);
74850+ atomic64_read_unchecked(&event->child_total_time_running);
74851 }
74852 if (read_format & PERF_FORMAT_ID)
74853 values[n++] = primary_event_id(event);
74854@@ -4726,12 +4733,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
74855 * need to add enough zero bytes after the string to handle
74856 * the 64bit alignment we do later.
74857 */
74858- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
74859+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
74860 if (!buf) {
74861 name = strncpy(tmp, "//enomem", sizeof(tmp));
74862 goto got_name;
74863 }
74864- name = d_path(&file->f_path, buf, PATH_MAX);
74865+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
74866 if (IS_ERR(name)) {
74867 name = strncpy(tmp, "//toolong", sizeof(tmp));
74868 goto got_name;
74869@@ -6167,7 +6174,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
74870 event->parent = parent_event;
74871
74872 event->ns = get_pid_ns(task_active_pid_ns(current));
74873- event->id = atomic64_inc_return(&perf_event_id);
74874+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
74875
74876 event->state = PERF_EVENT_STATE_INACTIVE;
74877
74878@@ -6463,6 +6470,11 @@ SYSCALL_DEFINE5(perf_event_open,
74879 if (flags & ~PERF_FLAG_ALL)
74880 return -EINVAL;
74881
74882+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
74883+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
74884+ return -EACCES;
74885+#endif
74886+
74887 err = perf_copy_attr(attr_uptr, &attr);
74888 if (err)
74889 return err;
74890@@ -6795,10 +6807,10 @@ static void sync_child_event(struct perf_event *child_event,
74891 /*
74892 * Add back the child's count to the parent's count:
74893 */
74894- atomic64_add(child_val, &parent_event->child_count);
74895- atomic64_add(child_event->total_time_enabled,
74896+ atomic64_add_unchecked(child_val, &parent_event->child_count);
74897+ atomic64_add_unchecked(child_event->total_time_enabled,
74898 &parent_event->child_total_time_enabled);
74899- atomic64_add(child_event->total_time_running,
74900+ atomic64_add_unchecked(child_event->total_time_running,
74901 &parent_event->child_total_time_running);
74902
74903 /*
74904diff --git a/kernel/events/internal.h b/kernel/events/internal.h
74905index eb675c4..54912ff 100644
74906--- a/kernel/events/internal.h
74907+++ b/kernel/events/internal.h
74908@@ -77,10 +77,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
74909 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
74910 }
74911
74912-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
74913+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
74914 static inline unsigned int \
74915 func_name(struct perf_output_handle *handle, \
74916- const void *buf, unsigned int len) \
74917+ const void user *buf, unsigned int len) \
74918 { \
74919 unsigned long size, written; \
74920 \
74921@@ -112,17 +112,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
74922 return n;
74923 }
74924
74925-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
74926+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
74927
74928 #define MEMCPY_SKIP(dst, src, n) (n)
74929
74930-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
74931+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
74932
74933 #ifndef arch_perf_out_copy_user
74934 #define arch_perf_out_copy_user __copy_from_user_inatomic
74935 #endif
74936
74937-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
74938+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
74939
74940 /* Callchain handling */
74941 extern struct perf_callchain_entry *
74942diff --git a/kernel/exit.c b/kernel/exit.c
74943index 60bc027..ca6d727 100644
74944--- a/kernel/exit.c
74945+++ b/kernel/exit.c
74946@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
74947 struct task_struct *leader;
74948 int zap_leader;
74949 repeat:
74950+#ifdef CONFIG_NET
74951+ gr_del_task_from_ip_table(p);
74952+#endif
74953+
74954 /* don't need to get the RCU readlock here - the process is dead and
74955 * can't be modifying its own credentials. But shut RCU-lockdep up */
74956 rcu_read_lock();
74957@@ -340,7 +344,7 @@ int allow_signal(int sig)
74958 * know it'll be handled, so that they don't get converted to
74959 * SIGKILL or just silently dropped.
74960 */
74961- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
74962+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
74963 recalc_sigpending();
74964 spin_unlock_irq(&current->sighand->siglock);
74965 return 0;
74966@@ -710,6 +714,8 @@ void do_exit(long code)
74967 struct task_struct *tsk = current;
74968 int group_dead;
74969
74970+ set_fs(USER_DS);
74971+
74972 profile_task_exit(tsk);
74973
74974 WARN_ON(blk_needs_flush_plug(tsk));
74975@@ -726,7 +732,6 @@ void do_exit(long code)
74976 * mm_release()->clear_child_tid() from writing to a user-controlled
74977 * kernel address.
74978 */
74979- set_fs(USER_DS);
74980
74981 ptrace_event(PTRACE_EVENT_EXIT, code);
74982
74983@@ -785,6 +790,9 @@ void do_exit(long code)
74984 tsk->exit_code = code;
74985 taskstats_exit(tsk, group_dead);
74986
74987+ gr_acl_handle_psacct(tsk, code);
74988+ gr_acl_handle_exit();
74989+
74990 exit_mm(tsk);
74991
74992 if (group_dead)
74993@@ -905,7 +913,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
74994 * Take down every thread in the group. This is called by fatal signals
74995 * as well as by sys_exit_group (below).
74996 */
74997-void
74998+__noreturn void
74999 do_group_exit(int exit_code)
75000 {
75001 struct signal_struct *sig = current->signal;
75002diff --git a/kernel/fork.c b/kernel/fork.c
75003index 1766d32..c0e44e2 100644
75004--- a/kernel/fork.c
75005+++ b/kernel/fork.c
75006@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
75007 *stackend = STACK_END_MAGIC; /* for overflow detection */
75008
75009 #ifdef CONFIG_CC_STACKPROTECTOR
75010- tsk->stack_canary = get_random_int();
75011+ tsk->stack_canary = pax_get_random_long();
75012 #endif
75013
75014 /*
75015@@ -344,13 +344,81 @@ free_tsk:
75016 }
75017
75018 #ifdef CONFIG_MMU
75019+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
75020+{
75021+ struct vm_area_struct *tmp;
75022+ unsigned long charge;
75023+ struct mempolicy *pol;
75024+ struct file *file;
75025+
75026+ charge = 0;
75027+ if (mpnt->vm_flags & VM_ACCOUNT) {
75028+ unsigned long len = vma_pages(mpnt);
75029+
75030+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
75031+ goto fail_nomem;
75032+ charge = len;
75033+ }
75034+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75035+ if (!tmp)
75036+ goto fail_nomem;
75037+ *tmp = *mpnt;
75038+ tmp->vm_mm = mm;
75039+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
75040+ pol = mpol_dup(vma_policy(mpnt));
75041+ if (IS_ERR(pol))
75042+ goto fail_nomem_policy;
75043+ vma_set_policy(tmp, pol);
75044+ if (anon_vma_fork(tmp, mpnt))
75045+ goto fail_nomem_anon_vma_fork;
75046+ tmp->vm_flags &= ~VM_LOCKED;
75047+ tmp->vm_next = tmp->vm_prev = NULL;
75048+ tmp->vm_mirror = NULL;
75049+ file = tmp->vm_file;
75050+ if (file) {
75051+ struct inode *inode = file_inode(file);
75052+ struct address_space *mapping = file->f_mapping;
75053+
75054+ get_file(file);
75055+ if (tmp->vm_flags & VM_DENYWRITE)
75056+ atomic_dec(&inode->i_writecount);
75057+ mutex_lock(&mapping->i_mmap_mutex);
75058+ if (tmp->vm_flags & VM_SHARED)
75059+ mapping->i_mmap_writable++;
75060+ flush_dcache_mmap_lock(mapping);
75061+ /* insert tmp into the share list, just after mpnt */
75062+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
75063+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
75064+ else
75065+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
75066+ flush_dcache_mmap_unlock(mapping);
75067+ mutex_unlock(&mapping->i_mmap_mutex);
75068+ }
75069+
75070+ /*
75071+ * Clear hugetlb-related page reserves for children. This only
75072+ * affects MAP_PRIVATE mappings. Faults generated by the child
75073+ * are not guaranteed to succeed, even if read-only
75074+ */
75075+ if (is_vm_hugetlb_page(tmp))
75076+ reset_vma_resv_huge_pages(tmp);
75077+
75078+ return tmp;
75079+
75080+fail_nomem_anon_vma_fork:
75081+ mpol_put(pol);
75082+fail_nomem_policy:
75083+ kmem_cache_free(vm_area_cachep, tmp);
75084+fail_nomem:
75085+ vm_unacct_memory(charge);
75086+ return NULL;
75087+}
75088+
75089 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75090 {
75091 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
75092 struct rb_node **rb_link, *rb_parent;
75093 int retval;
75094- unsigned long charge;
75095- struct mempolicy *pol;
75096
75097 uprobe_start_dup_mmap();
75098 down_write(&oldmm->mmap_sem);
75099@@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75100 mm->locked_vm = 0;
75101 mm->mmap = NULL;
75102 mm->mmap_cache = NULL;
75103- mm->free_area_cache = oldmm->mmap_base;
75104- mm->cached_hole_size = ~0UL;
75105+ mm->free_area_cache = oldmm->free_area_cache;
75106+ mm->cached_hole_size = oldmm->cached_hole_size;
75107 mm->map_count = 0;
75108 cpumask_clear(mm_cpumask(mm));
75109 mm->mm_rb = RB_ROOT;
75110@@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75111
75112 prev = NULL;
75113 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
75114- struct file *file;
75115-
75116 if (mpnt->vm_flags & VM_DONTCOPY) {
75117 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
75118 -vma_pages(mpnt));
75119 continue;
75120 }
75121- charge = 0;
75122- if (mpnt->vm_flags & VM_ACCOUNT) {
75123- unsigned long len = vma_pages(mpnt);
75124-
75125- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
75126- goto fail_nomem;
75127- charge = len;
75128- }
75129- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75130- if (!tmp)
75131- goto fail_nomem;
75132- *tmp = *mpnt;
75133- INIT_LIST_HEAD(&tmp->anon_vma_chain);
75134- pol = mpol_dup(vma_policy(mpnt));
75135- retval = PTR_ERR(pol);
75136- if (IS_ERR(pol))
75137- goto fail_nomem_policy;
75138- vma_set_policy(tmp, pol);
75139- tmp->vm_mm = mm;
75140- if (anon_vma_fork(tmp, mpnt))
75141- goto fail_nomem_anon_vma_fork;
75142- tmp->vm_flags &= ~VM_LOCKED;
75143- tmp->vm_next = tmp->vm_prev = NULL;
75144- file = tmp->vm_file;
75145- if (file) {
75146- struct inode *inode = file_inode(file);
75147- struct address_space *mapping = file->f_mapping;
75148-
75149- get_file(file);
75150- if (tmp->vm_flags & VM_DENYWRITE)
75151- atomic_dec(&inode->i_writecount);
75152- mutex_lock(&mapping->i_mmap_mutex);
75153- if (tmp->vm_flags & VM_SHARED)
75154- mapping->i_mmap_writable++;
75155- flush_dcache_mmap_lock(mapping);
75156- /* insert tmp into the share list, just after mpnt */
75157- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
75158- vma_nonlinear_insert(tmp,
75159- &mapping->i_mmap_nonlinear);
75160- else
75161- vma_interval_tree_insert_after(tmp, mpnt,
75162- &mapping->i_mmap);
75163- flush_dcache_mmap_unlock(mapping);
75164- mutex_unlock(&mapping->i_mmap_mutex);
75165+ tmp = dup_vma(mm, oldmm, mpnt);
75166+ if (!tmp) {
75167+ retval = -ENOMEM;
75168+ goto out;
75169 }
75170
75171 /*
75172@@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75173 if (retval)
75174 goto out;
75175 }
75176+
75177+#ifdef CONFIG_PAX_SEGMEXEC
75178+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
75179+ struct vm_area_struct *mpnt_m;
75180+
75181+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
75182+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
75183+
75184+ if (!mpnt->vm_mirror)
75185+ continue;
75186+
75187+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
75188+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
75189+ mpnt->vm_mirror = mpnt_m;
75190+ } else {
75191+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
75192+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
75193+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
75194+ mpnt->vm_mirror->vm_mirror = mpnt;
75195+ }
75196+ }
75197+ BUG_ON(mpnt_m);
75198+ }
75199+#endif
75200+
75201 /* a new mm has just been created */
75202 arch_dup_mmap(oldmm, mm);
75203 retval = 0;
75204@@ -472,14 +523,6 @@ out:
75205 up_write(&oldmm->mmap_sem);
75206 uprobe_end_dup_mmap();
75207 return retval;
75208-fail_nomem_anon_vma_fork:
75209- mpol_put(pol);
75210-fail_nomem_policy:
75211- kmem_cache_free(vm_area_cachep, tmp);
75212-fail_nomem:
75213- retval = -ENOMEM;
75214- vm_unacct_memory(charge);
75215- goto out;
75216 }
75217
75218 static inline int mm_alloc_pgd(struct mm_struct *mm)
75219@@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
75220 return ERR_PTR(err);
75221
75222 mm = get_task_mm(task);
75223- if (mm && mm != current->mm &&
75224- !ptrace_may_access(task, mode)) {
75225+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
75226+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
75227 mmput(mm);
75228 mm = ERR_PTR(-EACCES);
75229 }
75230@@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
75231 spin_unlock(&fs->lock);
75232 return -EAGAIN;
75233 }
75234- fs->users++;
75235+ atomic_inc(&fs->users);
75236 spin_unlock(&fs->lock);
75237 return 0;
75238 }
75239 tsk->fs = copy_fs_struct(fs);
75240 if (!tsk->fs)
75241 return -ENOMEM;
75242+ /* Carry through gr_chroot_dentry and is_chrooted instead
75243+ of recomputing it here. Already copied when the task struct
75244+ is duplicated. This allows pivot_root to not be treated as
75245+ a chroot
75246+ */
75247+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
75248+
75249 return 0;
75250 }
75251
75252@@ -1196,6 +1246,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
75253 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
75254 #endif
75255 retval = -EAGAIN;
75256+
75257+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
75258+
75259 if (atomic_read(&p->real_cred->user->processes) >=
75260 task_rlimit(p, RLIMIT_NPROC)) {
75261 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
75262@@ -1441,6 +1494,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
75263 goto bad_fork_free_pid;
75264 }
75265
75266+ /* synchronizes with gr_set_acls()
75267+ we need to call this past the point of no return for fork()
75268+ */
75269+ gr_copy_label(p);
75270+
75271 if (clone_flags & CLONE_THREAD) {
75272 current->signal->nr_threads++;
75273 atomic_inc(&current->signal->live);
75274@@ -1524,6 +1582,8 @@ bad_fork_cleanup_count:
75275 bad_fork_free:
75276 free_task(p);
75277 fork_out:
75278+ gr_log_forkfail(retval);
75279+
75280 return ERR_PTR(retval);
75281 }
75282
75283@@ -1574,6 +1634,23 @@ long do_fork(unsigned long clone_flags,
75284 return -EINVAL;
75285 }
75286
75287+#ifdef CONFIG_GRKERNSEC
75288+ if (clone_flags & CLONE_NEWUSER) {
75289+ /*
75290+ * This doesn't really inspire confidence:
75291+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
75292+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
75293+ * Increases kernel attack surface in areas developers
75294+ * previously cared little about ("low importance due
75295+ * to requiring "root" capability")
75296+ * To be removed when this code receives *proper* review
75297+ */
75298+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
75299+ !capable(CAP_SETGID))
75300+ return -EPERM;
75301+ }
75302+#endif
75303+
75304 /*
75305 * Determine whether and which event to report to ptracer. When
75306 * called from kernel_thread or CLONE_UNTRACED is explicitly
75307@@ -1608,6 +1685,8 @@ long do_fork(unsigned long clone_flags,
75308 if (clone_flags & CLONE_PARENT_SETTID)
75309 put_user(nr, parent_tidptr);
75310
75311+ gr_handle_brute_check();
75312+
75313 if (clone_flags & CLONE_VFORK) {
75314 p->vfork_done = &vfork;
75315 init_completion(&vfork);
75316@@ -1761,7 +1840,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
75317 return 0;
75318
75319 /* don't need lock here; in the worst case we'll do useless copy */
75320- if (fs->users == 1)
75321+ if (atomic_read(&fs->users) == 1)
75322 return 0;
75323
75324 *new_fsp = copy_fs_struct(fs);
75325@@ -1873,7 +1952,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
75326 fs = current->fs;
75327 spin_lock(&fs->lock);
75328 current->fs = new_fs;
75329- if (--fs->users)
75330+ gr_set_chroot_entries(current, &current->fs->root);
75331+ if (atomic_dec_return(&fs->users))
75332 new_fs = NULL;
75333 else
75334 new_fs = fs;
75335diff --git a/kernel/futex.c b/kernel/futex.c
75336index b26dcfc..39e266a 100644
75337--- a/kernel/futex.c
75338+++ b/kernel/futex.c
75339@@ -54,6 +54,7 @@
75340 #include <linux/mount.h>
75341 #include <linux/pagemap.h>
75342 #include <linux/syscalls.h>
75343+#include <linux/ptrace.h>
75344 #include <linux/signal.h>
75345 #include <linux/export.h>
75346 #include <linux/magic.h>
75347@@ -241,6 +242,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
75348 struct page *page, *page_head;
75349 int err, ro = 0;
75350
75351+#ifdef CONFIG_PAX_SEGMEXEC
75352+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
75353+ return -EFAULT;
75354+#endif
75355+
75356 /*
75357 * The futex address must be "naturally" aligned.
75358 */
75359@@ -2732,6 +2738,7 @@ static int __init futex_init(void)
75360 {
75361 u32 curval;
75362 int i;
75363+ mm_segment_t oldfs;
75364
75365 /*
75366 * This will fail and we want it. Some arch implementations do
75367@@ -2743,8 +2750,11 @@ static int __init futex_init(void)
75368 * implementation, the non-functional ones will return
75369 * -ENOSYS.
75370 */
75371+ oldfs = get_fs();
75372+ set_fs(USER_DS);
75373 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
75374 futex_cmpxchg_enabled = 1;
75375+ set_fs(oldfs);
75376
75377 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
75378 plist_head_init(&futex_queues[i].chain);
75379diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
75380index f9f44fd..29885e4 100644
75381--- a/kernel/futex_compat.c
75382+++ b/kernel/futex_compat.c
75383@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
75384 return 0;
75385 }
75386
75387-static void __user *futex_uaddr(struct robust_list __user *entry,
75388+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
75389 compat_long_t futex_offset)
75390 {
75391 compat_uptr_t base = ptr_to_compat(entry);
75392diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
75393index 9b22d03..6295b62 100644
75394--- a/kernel/gcov/base.c
75395+++ b/kernel/gcov/base.c
75396@@ -102,11 +102,6 @@ void gcov_enable_events(void)
75397 }
75398
75399 #ifdef CONFIG_MODULES
75400-static inline int within(void *addr, void *start, unsigned long size)
75401-{
75402- return ((addr >= start) && (addr < start + size));
75403-}
75404-
75405 /* Update list and generate events when modules are unloaded. */
75406 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
75407 void *data)
75408@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
75409 prev = NULL;
75410 /* Remove entries located in module from linked list. */
75411 for (info = gcov_info_head; info; info = info->next) {
75412- if (within(info, mod->module_core, mod->core_size)) {
75413+ if (within_module_core_rw((unsigned long)info, mod)) {
75414 if (prev)
75415 prev->next = info->next;
75416 else
75417diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
75418index 7ef5556..8247f11 100644
75419--- a/kernel/hrtimer.c
75420+++ b/kernel/hrtimer.c
75421@@ -1416,7 +1416,7 @@ void hrtimer_peek_ahead_timers(void)
75422 local_irq_restore(flags);
75423 }
75424
75425-static void run_hrtimer_softirq(struct softirq_action *h)
75426+static void run_hrtimer_softirq(void)
75427 {
75428 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
75429
75430@@ -1758,7 +1758,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
75431 return NOTIFY_OK;
75432 }
75433
75434-static struct notifier_block __cpuinitdata hrtimers_nb = {
75435+static struct notifier_block hrtimers_nb = {
75436 .notifier_call = hrtimer_cpu_notify,
75437 };
75438
75439diff --git a/kernel/irq_work.c b/kernel/irq_work.c
75440index 55fcce6..0e4cf34 100644
75441--- a/kernel/irq_work.c
75442+++ b/kernel/irq_work.c
75443@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
75444 return NOTIFY_OK;
75445 }
75446
75447-static struct notifier_block cpu_notify;
75448+static struct notifier_block cpu_notify = {
75449+ .notifier_call = irq_work_cpu_notify,
75450+ .priority = 0,
75451+};
75452
75453 static __init int irq_work_init_cpu_notifier(void)
75454 {
75455- cpu_notify.notifier_call = irq_work_cpu_notify;
75456- cpu_notify.priority = 0;
75457 register_cpu_notifier(&cpu_notify);
75458 return 0;
75459 }
75460diff --git a/kernel/jump_label.c b/kernel/jump_label.c
75461index 60f48fa..7f3a770 100644
75462--- a/kernel/jump_label.c
75463+++ b/kernel/jump_label.c
75464@@ -13,6 +13,7 @@
75465 #include <linux/sort.h>
75466 #include <linux/err.h>
75467 #include <linux/static_key.h>
75468+#include <linux/mm.h>
75469
75470 #ifdef HAVE_JUMP_LABEL
75471
75472@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
75473
75474 size = (((unsigned long)stop - (unsigned long)start)
75475 / sizeof(struct jump_entry));
75476+ pax_open_kernel();
75477 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
75478+ pax_close_kernel();
75479 }
75480
75481 static void jump_label_update(struct static_key *key, int enable);
75482@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
75483 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
75484 struct jump_entry *iter;
75485
75486+ pax_open_kernel();
75487 for (iter = iter_start; iter < iter_stop; iter++) {
75488 if (within_module_init(iter->code, mod))
75489 iter->code = 0;
75490 }
75491+ pax_close_kernel();
75492 }
75493
75494 static int
75495diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
75496index 2169fee..706ccca 100644
75497--- a/kernel/kallsyms.c
75498+++ b/kernel/kallsyms.c
75499@@ -11,6 +11,9 @@
75500 * Changed the compression method from stem compression to "table lookup"
75501 * compression (see scripts/kallsyms.c for a more complete description)
75502 */
75503+#ifdef CONFIG_GRKERNSEC_HIDESYM
75504+#define __INCLUDED_BY_HIDESYM 1
75505+#endif
75506 #include <linux/kallsyms.h>
75507 #include <linux/module.h>
75508 #include <linux/init.h>
75509@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
75510
75511 static inline int is_kernel_inittext(unsigned long addr)
75512 {
75513+ if (system_state != SYSTEM_BOOTING)
75514+ return 0;
75515+
75516 if (addr >= (unsigned long)_sinittext
75517 && addr <= (unsigned long)_einittext)
75518 return 1;
75519 return 0;
75520 }
75521
75522+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75523+#ifdef CONFIG_MODULES
75524+static inline int is_module_text(unsigned long addr)
75525+{
75526+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
75527+ return 1;
75528+
75529+ addr = ktla_ktva(addr);
75530+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
75531+}
75532+#else
75533+static inline int is_module_text(unsigned long addr)
75534+{
75535+ return 0;
75536+}
75537+#endif
75538+#endif
75539+
75540 static inline int is_kernel_text(unsigned long addr)
75541 {
75542 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
75543@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
75544
75545 static inline int is_kernel(unsigned long addr)
75546 {
75547+
75548+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75549+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
75550+ return 1;
75551+
75552+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
75553+#else
75554 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
75555+#endif
75556+
75557 return 1;
75558 return in_gate_area_no_mm(addr);
75559 }
75560
75561 static int is_ksym_addr(unsigned long addr)
75562 {
75563+
75564+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75565+ if (is_module_text(addr))
75566+ return 0;
75567+#endif
75568+
75569 if (all_var)
75570 return is_kernel(addr);
75571
75572@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
75573
75574 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
75575 {
75576- iter->name[0] = '\0';
75577 iter->nameoff = get_symbol_offset(new_pos);
75578 iter->pos = new_pos;
75579 }
75580@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
75581 {
75582 struct kallsym_iter *iter = m->private;
75583
75584+#ifdef CONFIG_GRKERNSEC_HIDESYM
75585+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
75586+ return 0;
75587+#endif
75588+
75589 /* Some debugging symbols have no name. Ignore them. */
75590 if (!iter->name[0])
75591 return 0;
75592@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
75593 */
75594 type = iter->exported ? toupper(iter->type) :
75595 tolower(iter->type);
75596+
75597 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
75598 type, iter->name, iter->module_name);
75599 } else
75600@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
75601 struct kallsym_iter *iter;
75602 int ret;
75603
75604- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
75605+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
75606 if (!iter)
75607 return -ENOMEM;
75608 reset_iter(iter, 0);
75609diff --git a/kernel/kcmp.c b/kernel/kcmp.c
75610index e30ac0f..3528cac 100644
75611--- a/kernel/kcmp.c
75612+++ b/kernel/kcmp.c
75613@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
75614 struct task_struct *task1, *task2;
75615 int ret;
75616
75617+#ifdef CONFIG_GRKERNSEC
75618+ return -ENOSYS;
75619+#endif
75620+
75621 rcu_read_lock();
75622
75623 /*
75624diff --git a/kernel/kexec.c b/kernel/kexec.c
75625index ffd4e11..c3ff6bf 100644
75626--- a/kernel/kexec.c
75627+++ b/kernel/kexec.c
75628@@ -1048,7 +1048,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
75629 unsigned long flags)
75630 {
75631 struct compat_kexec_segment in;
75632- struct kexec_segment out, __user *ksegments;
75633+ struct kexec_segment out;
75634+ struct kexec_segment __user *ksegments;
75635 unsigned long i, result;
75636
75637 /* Don't allow clients that don't understand the native
75638diff --git a/kernel/kmod.c b/kernel/kmod.c
75639index 8985c87..f539dbe 100644
75640--- a/kernel/kmod.c
75641+++ b/kernel/kmod.c
75642@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
75643 kfree(info->argv);
75644 }
75645
75646-static int call_modprobe(char *module_name, int wait)
75647+static int call_modprobe(char *module_name, char *module_param, int wait)
75648 {
75649 static char *envp[] = {
75650 "HOME=/",
75651@@ -84,7 +84,7 @@ static int call_modprobe(char *module_name, int wait)
75652 NULL
75653 };
75654
75655- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
75656+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
75657 if (!argv)
75658 goto out;
75659
75660@@ -96,7 +96,8 @@ static int call_modprobe(char *module_name, int wait)
75661 argv[1] = "-q";
75662 argv[2] = "--";
75663 argv[3] = module_name; /* check free_modprobe_argv() */
75664- argv[4] = NULL;
75665+ argv[4] = module_param;
75666+ argv[5] = NULL;
75667
75668 return call_usermodehelper_fns(modprobe_path, argv, envp,
75669 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
75670@@ -121,9 +122,8 @@ out:
75671 * If module auto-loading support is disabled then this function
75672 * becomes a no-operation.
75673 */
75674-int __request_module(bool wait, const char *fmt, ...)
75675+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
75676 {
75677- va_list args;
75678 char module_name[MODULE_NAME_LEN];
75679 unsigned int max_modprobes;
75680 int ret;
75681@@ -139,9 +139,7 @@ int __request_module(bool wait, const char *fmt, ...)
75682 */
75683 WARN_ON_ONCE(wait && current_is_async());
75684
75685- va_start(args, fmt);
75686- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
75687- va_end(args);
75688+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
75689 if (ret >= MODULE_NAME_LEN)
75690 return -ENAMETOOLONG;
75691
75692@@ -149,6 +147,20 @@ int __request_module(bool wait, const char *fmt, ...)
75693 if (ret)
75694 return ret;
75695
75696+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75697+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
75698+ /* hack to workaround consolekit/udisks stupidity */
75699+ read_lock(&tasklist_lock);
75700+ if (!strcmp(current->comm, "mount") &&
75701+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
75702+ read_unlock(&tasklist_lock);
75703+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
75704+ return -EPERM;
75705+ }
75706+ read_unlock(&tasklist_lock);
75707+ }
75708+#endif
75709+
75710 /* If modprobe needs a service that is in a module, we get a recursive
75711 * loop. Limit the number of running kmod threads to max_threads/2 or
75712 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
75713@@ -177,11 +189,52 @@ int __request_module(bool wait, const char *fmt, ...)
75714
75715 trace_module_request(module_name, wait, _RET_IP_);
75716
75717- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
75718+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
75719
75720 atomic_dec(&kmod_concurrent);
75721 return ret;
75722 }
75723+
75724+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
75725+{
75726+ va_list args;
75727+ int ret;
75728+
75729+ va_start(args, fmt);
75730+ ret = ____request_module(wait, module_param, fmt, args);
75731+ va_end(args);
75732+
75733+ return ret;
75734+}
75735+
75736+int __request_module(bool wait, const char *fmt, ...)
75737+{
75738+ va_list args;
75739+ int ret;
75740+
75741+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75742+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
75743+ char module_param[MODULE_NAME_LEN];
75744+
75745+ memset(module_param, 0, sizeof(module_param));
75746+
75747+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
75748+
75749+ va_start(args, fmt);
75750+ ret = ____request_module(wait, module_param, fmt, args);
75751+ va_end(args);
75752+
75753+ return ret;
75754+ }
75755+#endif
75756+
75757+ va_start(args, fmt);
75758+ ret = ____request_module(wait, NULL, fmt, args);
75759+ va_end(args);
75760+
75761+ return ret;
75762+}
75763+
75764 EXPORT_SYMBOL(__request_module);
75765 #endif /* CONFIG_MODULES */
75766
75767@@ -292,7 +345,7 @@ static int wait_for_helper(void *data)
75768 *
75769 * Thus the __user pointer cast is valid here.
75770 */
75771- sys_wait4(pid, (int __user *)&ret, 0, NULL);
75772+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
75773
75774 /*
75775 * If ret is 0, either ____call_usermodehelper failed and the
75776@@ -649,7 +702,7 @@ EXPORT_SYMBOL(call_usermodehelper_fns);
75777 static int proc_cap_handler(struct ctl_table *table, int write,
75778 void __user *buffer, size_t *lenp, loff_t *ppos)
75779 {
75780- struct ctl_table t;
75781+ ctl_table_no_const t;
75782 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
75783 kernel_cap_t new_cap;
75784 int err, i;
75785diff --git a/kernel/kprobes.c b/kernel/kprobes.c
75786index 3fed7f0..a3f95ed 100644
75787--- a/kernel/kprobes.c
75788+++ b/kernel/kprobes.c
75789@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
75790 * kernel image and loaded module images reside. This is required
75791 * so x86_64 can correctly handle the %rip-relative fixups.
75792 */
75793- kip->insns = module_alloc(PAGE_SIZE);
75794+ kip->insns = module_alloc_exec(PAGE_SIZE);
75795 if (!kip->insns) {
75796 kfree(kip);
75797 return NULL;
75798@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
75799 */
75800 if (!list_is_singular(&kip->list)) {
75801 list_del(&kip->list);
75802- module_free(NULL, kip->insns);
75803+ module_free_exec(NULL, kip->insns);
75804 kfree(kip);
75805 }
75806 return 1;
75807@@ -2073,7 +2073,7 @@ static int __init init_kprobes(void)
75808 {
75809 int i, err = 0;
75810 unsigned long offset = 0, size = 0;
75811- char *modname, namebuf[128];
75812+ char *modname, namebuf[KSYM_NAME_LEN];
75813 const char *symbol_name;
75814 void *addr;
75815 struct kprobe_blackpoint *kb;
75816@@ -2158,11 +2158,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
75817 kprobe_type = "k";
75818
75819 if (sym)
75820- seq_printf(pi, "%p %s %s+0x%x %s ",
75821+ seq_printf(pi, "%pK %s %s+0x%x %s ",
75822 p->addr, kprobe_type, sym, offset,
75823 (modname ? modname : " "));
75824 else
75825- seq_printf(pi, "%p %s %p ",
75826+ seq_printf(pi, "%pK %s %pK ",
75827 p->addr, kprobe_type, p->addr);
75828
75829 if (!pp)
75830@@ -2199,7 +2199,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
75831 const char *sym = NULL;
75832 unsigned int i = *(loff_t *) v;
75833 unsigned long offset = 0;
75834- char *modname, namebuf[128];
75835+ char *modname, namebuf[KSYM_NAME_LEN];
75836
75837 head = &kprobe_table[i];
75838 preempt_disable();
75839diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
75840index 6ada93c..dce7d5d 100644
75841--- a/kernel/ksysfs.c
75842+++ b/kernel/ksysfs.c
75843@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
75844 {
75845 if (count+1 > UEVENT_HELPER_PATH_LEN)
75846 return -ENOENT;
75847+ if (!capable(CAP_SYS_ADMIN))
75848+ return -EPERM;
75849 memcpy(uevent_helper, buf, count);
75850 uevent_helper[count] = '\0';
75851 if (count && uevent_helper[count-1] == '\n')
75852@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
75853 return count;
75854 }
75855
75856-static struct bin_attribute notes_attr = {
75857+static bin_attribute_no_const notes_attr __read_only = {
75858 .attr = {
75859 .name = "notes",
75860 .mode = S_IRUGO,
75861diff --git a/kernel/lockdep.c b/kernel/lockdep.c
75862index 8a0efac..56f1e2d 100644
75863--- a/kernel/lockdep.c
75864+++ b/kernel/lockdep.c
75865@@ -590,6 +590,10 @@ static int static_obj(void *obj)
75866 end = (unsigned long) &_end,
75867 addr = (unsigned long) obj;
75868
75869+#ifdef CONFIG_PAX_KERNEXEC
75870+ start = ktla_ktva(start);
75871+#endif
75872+
75873 /*
75874 * static variable?
75875 */
75876@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
75877 if (!static_obj(lock->key)) {
75878 debug_locks_off();
75879 printk("INFO: trying to register non-static key.\n");
75880+ printk("lock:%pS key:%pS.\n", lock, lock->key);
75881 printk("the code is fine but needs lockdep annotation.\n");
75882 printk("turning off the locking correctness validator.\n");
75883 dump_stack();
75884@@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
75885 if (!class)
75886 return 0;
75887 }
75888- atomic_inc((atomic_t *)&class->ops);
75889+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
75890 if (very_verbose(class)) {
75891 printk("\nacquire class [%p] %s", class->key, class->name);
75892 if (class->name_version > 1)
75893diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
75894index b2c71c5..7b88d63 100644
75895--- a/kernel/lockdep_proc.c
75896+++ b/kernel/lockdep_proc.c
75897@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
75898 return 0;
75899 }
75900
75901- seq_printf(m, "%p", class->key);
75902+ seq_printf(m, "%pK", class->key);
75903 #ifdef CONFIG_DEBUG_LOCKDEP
75904 seq_printf(m, " OPS:%8ld", class->ops);
75905 #endif
75906@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
75907
75908 list_for_each_entry(entry, &class->locks_after, entry) {
75909 if (entry->distance == 1) {
75910- seq_printf(m, " -> [%p] ", entry->class->key);
75911+ seq_printf(m, " -> [%pK] ", entry->class->key);
75912 print_name(m, entry->class);
75913 seq_puts(m, "\n");
75914 }
75915@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
75916 if (!class->key)
75917 continue;
75918
75919- seq_printf(m, "[%p] ", class->key);
75920+ seq_printf(m, "[%pK] ", class->key);
75921 print_name(m, class);
75922 seq_puts(m, "\n");
75923 }
75924@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
75925 if (!i)
75926 seq_line(m, '-', 40-namelen, namelen);
75927
75928- snprintf(ip, sizeof(ip), "[<%p>]",
75929+ snprintf(ip, sizeof(ip), "[<%pK>]",
75930 (void *)class->contention_point[i]);
75931 seq_printf(m, "%40s %14lu %29s %pS\n",
75932 name, stats->contention_point[i],
75933@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
75934 if (!i)
75935 seq_line(m, '-', 40-namelen, namelen);
75936
75937- snprintf(ip, sizeof(ip), "[<%p>]",
75938+ snprintf(ip, sizeof(ip), "[<%pK>]",
75939 (void *)class->contending_point[i]);
75940 seq_printf(m, "%40s %14lu %29s %pS\n",
75941 name, stats->contending_point[i],
75942diff --git a/kernel/module.c b/kernel/module.c
75943index 97f202c..109575f 100644
75944--- a/kernel/module.c
75945+++ b/kernel/module.c
75946@@ -61,6 +61,7 @@
75947 #include <linux/pfn.h>
75948 #include <linux/bsearch.h>
75949 #include <linux/fips.h>
75950+#include <linux/grsecurity.h>
75951 #include <uapi/linux/module.h>
75952 #include "module-internal.h"
75953
75954@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
75955
75956 /* Bounds of module allocation, for speeding __module_address.
75957 * Protected by module_mutex. */
75958-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
75959+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
75960+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
75961
75962 int register_module_notifier(struct notifier_block * nb)
75963 {
75964@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
75965 return true;
75966
75967 list_for_each_entry_rcu(mod, &modules, list) {
75968- struct symsearch arr[] = {
75969+ struct symsearch modarr[] = {
75970 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
75971 NOT_GPL_ONLY, false },
75972 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
75973@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
75974 if (mod->state == MODULE_STATE_UNFORMED)
75975 continue;
75976
75977- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
75978+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
75979 return true;
75980 }
75981 return false;
75982@@ -485,7 +487,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
75983 static int percpu_modalloc(struct module *mod,
75984 unsigned long size, unsigned long align)
75985 {
75986- if (align > PAGE_SIZE) {
75987+ if (align-1 >= PAGE_SIZE) {
75988 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
75989 mod->name, align, PAGE_SIZE);
75990 align = PAGE_SIZE;
75991@@ -1089,7 +1091,7 @@ struct module_attribute module_uevent =
75992 static ssize_t show_coresize(struct module_attribute *mattr,
75993 struct module_kobject *mk, char *buffer)
75994 {
75995- return sprintf(buffer, "%u\n", mk->mod->core_size);
75996+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
75997 }
75998
75999 static struct module_attribute modinfo_coresize =
76000@@ -1098,7 +1100,7 @@ static struct module_attribute modinfo_coresize =
76001 static ssize_t show_initsize(struct module_attribute *mattr,
76002 struct module_kobject *mk, char *buffer)
76003 {
76004- return sprintf(buffer, "%u\n", mk->mod->init_size);
76005+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
76006 }
76007
76008 static struct module_attribute modinfo_initsize =
76009@@ -1312,7 +1314,7 @@ resolve_symbol_wait(struct module *mod,
76010 */
76011 #ifdef CONFIG_SYSFS
76012
76013-#ifdef CONFIG_KALLSYMS
76014+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
76015 static inline bool sect_empty(const Elf_Shdr *sect)
76016 {
76017 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
76018@@ -1452,7 +1454,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
76019 {
76020 unsigned int notes, loaded, i;
76021 struct module_notes_attrs *notes_attrs;
76022- struct bin_attribute *nattr;
76023+ bin_attribute_no_const *nattr;
76024
76025 /* failed to create section attributes, so can't create notes */
76026 if (!mod->sect_attrs)
76027@@ -1564,7 +1566,7 @@ static void del_usage_links(struct module *mod)
76028 static int module_add_modinfo_attrs(struct module *mod)
76029 {
76030 struct module_attribute *attr;
76031- struct module_attribute *temp_attr;
76032+ module_attribute_no_const *temp_attr;
76033 int error = 0;
76034 int i;
76035
76036@@ -1778,21 +1780,21 @@ static void set_section_ro_nx(void *base,
76037
76038 static void unset_module_core_ro_nx(struct module *mod)
76039 {
76040- set_page_attributes(mod->module_core + mod->core_text_size,
76041- mod->module_core + mod->core_size,
76042+ set_page_attributes(mod->module_core_rw,
76043+ mod->module_core_rw + mod->core_size_rw,
76044 set_memory_x);
76045- set_page_attributes(mod->module_core,
76046- mod->module_core + mod->core_ro_size,
76047+ set_page_attributes(mod->module_core_rx,
76048+ mod->module_core_rx + mod->core_size_rx,
76049 set_memory_rw);
76050 }
76051
76052 static void unset_module_init_ro_nx(struct module *mod)
76053 {
76054- set_page_attributes(mod->module_init + mod->init_text_size,
76055- mod->module_init + mod->init_size,
76056+ set_page_attributes(mod->module_init_rw,
76057+ mod->module_init_rw + mod->init_size_rw,
76058 set_memory_x);
76059- set_page_attributes(mod->module_init,
76060- mod->module_init + mod->init_ro_size,
76061+ set_page_attributes(mod->module_init_rx,
76062+ mod->module_init_rx + mod->init_size_rx,
76063 set_memory_rw);
76064 }
76065
76066@@ -1805,14 +1807,14 @@ void set_all_modules_text_rw(void)
76067 list_for_each_entry_rcu(mod, &modules, list) {
76068 if (mod->state == MODULE_STATE_UNFORMED)
76069 continue;
76070- if ((mod->module_core) && (mod->core_text_size)) {
76071- set_page_attributes(mod->module_core,
76072- mod->module_core + mod->core_text_size,
76073+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
76074+ set_page_attributes(mod->module_core_rx,
76075+ mod->module_core_rx + mod->core_size_rx,
76076 set_memory_rw);
76077 }
76078- if ((mod->module_init) && (mod->init_text_size)) {
76079- set_page_attributes(mod->module_init,
76080- mod->module_init + mod->init_text_size,
76081+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
76082+ set_page_attributes(mod->module_init_rx,
76083+ mod->module_init_rx + mod->init_size_rx,
76084 set_memory_rw);
76085 }
76086 }
76087@@ -1828,14 +1830,14 @@ void set_all_modules_text_ro(void)
76088 list_for_each_entry_rcu(mod, &modules, list) {
76089 if (mod->state == MODULE_STATE_UNFORMED)
76090 continue;
76091- if ((mod->module_core) && (mod->core_text_size)) {
76092- set_page_attributes(mod->module_core,
76093- mod->module_core + mod->core_text_size,
76094+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
76095+ set_page_attributes(mod->module_core_rx,
76096+ mod->module_core_rx + mod->core_size_rx,
76097 set_memory_ro);
76098 }
76099- if ((mod->module_init) && (mod->init_text_size)) {
76100- set_page_attributes(mod->module_init,
76101- mod->module_init + mod->init_text_size,
76102+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
76103+ set_page_attributes(mod->module_init_rx,
76104+ mod->module_init_rx + mod->init_size_rx,
76105 set_memory_ro);
76106 }
76107 }
76108@@ -1886,16 +1888,19 @@ static void free_module(struct module *mod)
76109
76110 /* This may be NULL, but that's OK */
76111 unset_module_init_ro_nx(mod);
76112- module_free(mod, mod->module_init);
76113+ module_free(mod, mod->module_init_rw);
76114+ module_free_exec(mod, mod->module_init_rx);
76115 kfree(mod->args);
76116 percpu_modfree(mod);
76117
76118 /* Free lock-classes: */
76119- lockdep_free_key_range(mod->module_core, mod->core_size);
76120+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
76121+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
76122
76123 /* Finally, free the core (containing the module structure) */
76124 unset_module_core_ro_nx(mod);
76125- module_free(mod, mod->module_core);
76126+ module_free_exec(mod, mod->module_core_rx);
76127+ module_free(mod, mod->module_core_rw);
76128
76129 #ifdef CONFIG_MPU
76130 update_protections(current->mm);
76131@@ -1965,9 +1970,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76132 int ret = 0;
76133 const struct kernel_symbol *ksym;
76134
76135+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76136+ int is_fs_load = 0;
76137+ int register_filesystem_found = 0;
76138+ char *p;
76139+
76140+ p = strstr(mod->args, "grsec_modharden_fs");
76141+ if (p) {
76142+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
76143+ /* copy \0 as well */
76144+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
76145+ is_fs_load = 1;
76146+ }
76147+#endif
76148+
76149 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
76150 const char *name = info->strtab + sym[i].st_name;
76151
76152+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76153+ /* it's a real shame this will never get ripped and copied
76154+ upstream! ;(
76155+ */
76156+ if (is_fs_load && !strcmp(name, "register_filesystem"))
76157+ register_filesystem_found = 1;
76158+#endif
76159+
76160 switch (sym[i].st_shndx) {
76161 case SHN_COMMON:
76162 /* We compiled with -fno-common. These are not
76163@@ -1988,7 +2015,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76164 ksym = resolve_symbol_wait(mod, info, name);
76165 /* Ok if resolved. */
76166 if (ksym && !IS_ERR(ksym)) {
76167+ pax_open_kernel();
76168 sym[i].st_value = ksym->value;
76169+ pax_close_kernel();
76170 break;
76171 }
76172
76173@@ -2007,11 +2036,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76174 secbase = (unsigned long)mod_percpu(mod);
76175 else
76176 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
76177+ pax_open_kernel();
76178 sym[i].st_value += secbase;
76179+ pax_close_kernel();
76180 break;
76181 }
76182 }
76183
76184+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76185+ if (is_fs_load && !register_filesystem_found) {
76186+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
76187+ ret = -EPERM;
76188+ }
76189+#endif
76190+
76191 return ret;
76192 }
76193
76194@@ -2095,22 +2133,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
76195 || s->sh_entsize != ~0UL
76196 || strstarts(sname, ".init"))
76197 continue;
76198- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
76199+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
76200+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
76201+ else
76202+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
76203 pr_debug("\t%s\n", sname);
76204 }
76205- switch (m) {
76206- case 0: /* executable */
76207- mod->core_size = debug_align(mod->core_size);
76208- mod->core_text_size = mod->core_size;
76209- break;
76210- case 1: /* RO: text and ro-data */
76211- mod->core_size = debug_align(mod->core_size);
76212- mod->core_ro_size = mod->core_size;
76213- break;
76214- case 3: /* whole core */
76215- mod->core_size = debug_align(mod->core_size);
76216- break;
76217- }
76218 }
76219
76220 pr_debug("Init section allocation order:\n");
76221@@ -2124,23 +2152,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
76222 || s->sh_entsize != ~0UL
76223 || !strstarts(sname, ".init"))
76224 continue;
76225- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
76226- | INIT_OFFSET_MASK);
76227+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
76228+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
76229+ else
76230+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
76231+ s->sh_entsize |= INIT_OFFSET_MASK;
76232 pr_debug("\t%s\n", sname);
76233 }
76234- switch (m) {
76235- case 0: /* executable */
76236- mod->init_size = debug_align(mod->init_size);
76237- mod->init_text_size = mod->init_size;
76238- break;
76239- case 1: /* RO: text and ro-data */
76240- mod->init_size = debug_align(mod->init_size);
76241- mod->init_ro_size = mod->init_size;
76242- break;
76243- case 3: /* whole init */
76244- mod->init_size = debug_align(mod->init_size);
76245- break;
76246- }
76247 }
76248 }
76249
76250@@ -2313,7 +2331,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
76251
76252 /* Put symbol section at end of init part of module. */
76253 symsect->sh_flags |= SHF_ALLOC;
76254- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
76255+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
76256 info->index.sym) | INIT_OFFSET_MASK;
76257 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
76258
76259@@ -2330,13 +2348,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
76260 }
76261
76262 /* Append room for core symbols at end of core part. */
76263- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
76264- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
76265- mod->core_size += strtab_size;
76266+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
76267+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
76268+ mod->core_size_rx += strtab_size;
76269
76270 /* Put string table section at end of init part of module. */
76271 strsect->sh_flags |= SHF_ALLOC;
76272- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
76273+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
76274 info->index.str) | INIT_OFFSET_MASK;
76275 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
76276 }
76277@@ -2354,12 +2372,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
76278 /* Make sure we get permanent strtab: don't use info->strtab. */
76279 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
76280
76281+ pax_open_kernel();
76282+
76283 /* Set types up while we still have access to sections. */
76284 for (i = 0; i < mod->num_symtab; i++)
76285 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
76286
76287- mod->core_symtab = dst = mod->module_core + info->symoffs;
76288- mod->core_strtab = s = mod->module_core + info->stroffs;
76289+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
76290+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
76291 src = mod->symtab;
76292 for (ndst = i = 0; i < mod->num_symtab; i++) {
76293 if (i == 0 ||
76294@@ -2371,6 +2391,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
76295 }
76296 }
76297 mod->core_num_syms = ndst;
76298+
76299+ pax_close_kernel();
76300 }
76301 #else
76302 static inline void layout_symtab(struct module *mod, struct load_info *info)
76303@@ -2404,17 +2426,33 @@ void * __weak module_alloc(unsigned long size)
76304 return vmalloc_exec(size);
76305 }
76306
76307-static void *module_alloc_update_bounds(unsigned long size)
76308+static void *module_alloc_update_bounds_rw(unsigned long size)
76309 {
76310 void *ret = module_alloc(size);
76311
76312 if (ret) {
76313 mutex_lock(&module_mutex);
76314 /* Update module bounds. */
76315- if ((unsigned long)ret < module_addr_min)
76316- module_addr_min = (unsigned long)ret;
76317- if ((unsigned long)ret + size > module_addr_max)
76318- module_addr_max = (unsigned long)ret + size;
76319+ if ((unsigned long)ret < module_addr_min_rw)
76320+ module_addr_min_rw = (unsigned long)ret;
76321+ if ((unsigned long)ret + size > module_addr_max_rw)
76322+ module_addr_max_rw = (unsigned long)ret + size;
76323+ mutex_unlock(&module_mutex);
76324+ }
76325+ return ret;
76326+}
76327+
76328+static void *module_alloc_update_bounds_rx(unsigned long size)
76329+{
76330+ void *ret = module_alloc_exec(size);
76331+
76332+ if (ret) {
76333+ mutex_lock(&module_mutex);
76334+ /* Update module bounds. */
76335+ if ((unsigned long)ret < module_addr_min_rx)
76336+ module_addr_min_rx = (unsigned long)ret;
76337+ if ((unsigned long)ret + size > module_addr_max_rx)
76338+ module_addr_max_rx = (unsigned long)ret + size;
76339 mutex_unlock(&module_mutex);
76340 }
76341 return ret;
76342@@ -2690,8 +2728,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
76343 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
76344 {
76345 const char *modmagic = get_modinfo(info, "vermagic");
76346+ const char *license = get_modinfo(info, "license");
76347 int err;
76348
76349+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
76350+ if (!license || !license_is_gpl_compatible(license))
76351+ return -ENOEXEC;
76352+#endif
76353+
76354 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
76355 modmagic = NULL;
76356
76357@@ -2717,7 +2761,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
76358 }
76359
76360 /* Set up license info based on the info section */
76361- set_license(mod, get_modinfo(info, "license"));
76362+ set_license(mod, license);
76363
76364 return 0;
76365 }
76366@@ -2811,7 +2855,7 @@ static int move_module(struct module *mod, struct load_info *info)
76367 void *ptr;
76368
76369 /* Do the allocs. */
76370- ptr = module_alloc_update_bounds(mod->core_size);
76371+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
76372 /*
76373 * The pointer to this block is stored in the module structure
76374 * which is inside the block. Just mark it as not being a
76375@@ -2821,11 +2865,11 @@ static int move_module(struct module *mod, struct load_info *info)
76376 if (!ptr)
76377 return -ENOMEM;
76378
76379- memset(ptr, 0, mod->core_size);
76380- mod->module_core = ptr;
76381+ memset(ptr, 0, mod->core_size_rw);
76382+ mod->module_core_rw = ptr;
76383
76384- if (mod->init_size) {
76385- ptr = module_alloc_update_bounds(mod->init_size);
76386+ if (mod->init_size_rw) {
76387+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
76388 /*
76389 * The pointer to this block is stored in the module structure
76390 * which is inside the block. This block doesn't need to be
76391@@ -2834,13 +2878,45 @@ static int move_module(struct module *mod, struct load_info *info)
76392 */
76393 kmemleak_ignore(ptr);
76394 if (!ptr) {
76395- module_free(mod, mod->module_core);
76396+ module_free(mod, mod->module_core_rw);
76397 return -ENOMEM;
76398 }
76399- memset(ptr, 0, mod->init_size);
76400- mod->module_init = ptr;
76401+ memset(ptr, 0, mod->init_size_rw);
76402+ mod->module_init_rw = ptr;
76403 } else
76404- mod->module_init = NULL;
76405+ mod->module_init_rw = NULL;
76406+
76407+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
76408+ kmemleak_not_leak(ptr);
76409+ if (!ptr) {
76410+ if (mod->module_init_rw)
76411+ module_free(mod, mod->module_init_rw);
76412+ module_free(mod, mod->module_core_rw);
76413+ return -ENOMEM;
76414+ }
76415+
76416+ pax_open_kernel();
76417+ memset(ptr, 0, mod->core_size_rx);
76418+ pax_close_kernel();
76419+ mod->module_core_rx = ptr;
76420+
76421+ if (mod->init_size_rx) {
76422+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
76423+ kmemleak_ignore(ptr);
76424+ if (!ptr && mod->init_size_rx) {
76425+ module_free_exec(mod, mod->module_core_rx);
76426+ if (mod->module_init_rw)
76427+ module_free(mod, mod->module_init_rw);
76428+ module_free(mod, mod->module_core_rw);
76429+ return -ENOMEM;
76430+ }
76431+
76432+ pax_open_kernel();
76433+ memset(ptr, 0, mod->init_size_rx);
76434+ pax_close_kernel();
76435+ mod->module_init_rx = ptr;
76436+ } else
76437+ mod->module_init_rx = NULL;
76438
76439 /* Transfer each section which specifies SHF_ALLOC */
76440 pr_debug("final section addresses:\n");
76441@@ -2851,16 +2927,45 @@ static int move_module(struct module *mod, struct load_info *info)
76442 if (!(shdr->sh_flags & SHF_ALLOC))
76443 continue;
76444
76445- if (shdr->sh_entsize & INIT_OFFSET_MASK)
76446- dest = mod->module_init
76447- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
76448- else
76449- dest = mod->module_core + shdr->sh_entsize;
76450+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
76451+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
76452+ dest = mod->module_init_rw
76453+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
76454+ else
76455+ dest = mod->module_init_rx
76456+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
76457+ } else {
76458+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
76459+ dest = mod->module_core_rw + shdr->sh_entsize;
76460+ else
76461+ dest = mod->module_core_rx + shdr->sh_entsize;
76462+ }
76463+
76464+ if (shdr->sh_type != SHT_NOBITS) {
76465+
76466+#ifdef CONFIG_PAX_KERNEXEC
76467+#ifdef CONFIG_X86_64
76468+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
76469+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
76470+#endif
76471+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
76472+ pax_open_kernel();
76473+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
76474+ pax_close_kernel();
76475+ } else
76476+#endif
76477
76478- if (shdr->sh_type != SHT_NOBITS)
76479 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
76480+ }
76481 /* Update sh_addr to point to copy in image. */
76482- shdr->sh_addr = (unsigned long)dest;
76483+
76484+#ifdef CONFIG_PAX_KERNEXEC
76485+ if (shdr->sh_flags & SHF_EXECINSTR)
76486+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
76487+ else
76488+#endif
76489+
76490+ shdr->sh_addr = (unsigned long)dest;
76491 pr_debug("\t0x%lx %s\n",
76492 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
76493 }
76494@@ -2917,12 +3022,12 @@ static void flush_module_icache(const struct module *mod)
76495 * Do it before processing of module parameters, so the module
76496 * can provide parameter accessor functions of its own.
76497 */
76498- if (mod->module_init)
76499- flush_icache_range((unsigned long)mod->module_init,
76500- (unsigned long)mod->module_init
76501- + mod->init_size);
76502- flush_icache_range((unsigned long)mod->module_core,
76503- (unsigned long)mod->module_core + mod->core_size);
76504+ if (mod->module_init_rx)
76505+ flush_icache_range((unsigned long)mod->module_init_rx,
76506+ (unsigned long)mod->module_init_rx
76507+ + mod->init_size_rx);
76508+ flush_icache_range((unsigned long)mod->module_core_rx,
76509+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
76510
76511 set_fs(old_fs);
76512 }
76513@@ -2992,8 +3097,10 @@ out:
76514 static void module_deallocate(struct module *mod, struct load_info *info)
76515 {
76516 percpu_modfree(mod);
76517- module_free(mod, mod->module_init);
76518- module_free(mod, mod->module_core);
76519+ module_free_exec(mod, mod->module_init_rx);
76520+ module_free_exec(mod, mod->module_core_rx);
76521+ module_free(mod, mod->module_init_rw);
76522+ module_free(mod, mod->module_core_rw);
76523 }
76524
76525 int __weak module_finalize(const Elf_Ehdr *hdr,
76526@@ -3006,7 +3113,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
76527 static int post_relocation(struct module *mod, const struct load_info *info)
76528 {
76529 /* Sort exception table now relocations are done. */
76530+ pax_open_kernel();
76531 sort_extable(mod->extable, mod->extable + mod->num_exentries);
76532+ pax_close_kernel();
76533
76534 /* Copy relocated percpu area over. */
76535 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
76536@@ -3060,16 +3169,16 @@ static int do_init_module(struct module *mod)
76537 MODULE_STATE_COMING, mod);
76538
76539 /* Set RO and NX regions for core */
76540- set_section_ro_nx(mod->module_core,
76541- mod->core_text_size,
76542- mod->core_ro_size,
76543- mod->core_size);
76544+ set_section_ro_nx(mod->module_core_rx,
76545+ mod->core_size_rx,
76546+ mod->core_size_rx,
76547+ mod->core_size_rx);
76548
76549 /* Set RO and NX regions for init */
76550- set_section_ro_nx(mod->module_init,
76551- mod->init_text_size,
76552- mod->init_ro_size,
76553- mod->init_size);
76554+ set_section_ro_nx(mod->module_init_rx,
76555+ mod->init_size_rx,
76556+ mod->init_size_rx,
76557+ mod->init_size_rx);
76558
76559 do_mod_ctors(mod);
76560 /* Start the module */
76561@@ -3131,11 +3240,12 @@ static int do_init_module(struct module *mod)
76562 mod->strtab = mod->core_strtab;
76563 #endif
76564 unset_module_init_ro_nx(mod);
76565- module_free(mod, mod->module_init);
76566- mod->module_init = NULL;
76567- mod->init_size = 0;
76568- mod->init_ro_size = 0;
76569- mod->init_text_size = 0;
76570+ module_free(mod, mod->module_init_rw);
76571+ module_free_exec(mod, mod->module_init_rx);
76572+ mod->module_init_rw = NULL;
76573+ mod->module_init_rx = NULL;
76574+ mod->init_size_rw = 0;
76575+ mod->init_size_rx = 0;
76576 mutex_unlock(&module_mutex);
76577 wake_up_all(&module_wq);
76578
76579@@ -3262,9 +3372,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
76580 if (err)
76581 goto free_unload;
76582
76583+ /* Now copy in args */
76584+ mod->args = strndup_user(uargs, ~0UL >> 1);
76585+ if (IS_ERR(mod->args)) {
76586+ err = PTR_ERR(mod->args);
76587+ goto free_unload;
76588+ }
76589+
76590 /* Set up MODINFO_ATTR fields */
76591 setup_modinfo(mod, info);
76592
76593+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76594+ {
76595+ char *p, *p2;
76596+
76597+ if (strstr(mod->args, "grsec_modharden_netdev")) {
76598+ 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);
76599+ err = -EPERM;
76600+ goto free_modinfo;
76601+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
76602+ p += sizeof("grsec_modharden_normal") - 1;
76603+ p2 = strstr(p, "_");
76604+ if (p2) {
76605+ *p2 = '\0';
76606+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
76607+ *p2 = '_';
76608+ }
76609+ err = -EPERM;
76610+ goto free_modinfo;
76611+ }
76612+ }
76613+#endif
76614+
76615 /* Fix up syms, so that st_value is a pointer to location. */
76616 err = simplify_symbols(mod, info);
76617 if (err < 0)
76618@@ -3280,13 +3419,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
76619
76620 flush_module_icache(mod);
76621
76622- /* Now copy in args */
76623- mod->args = strndup_user(uargs, ~0UL >> 1);
76624- if (IS_ERR(mod->args)) {
76625- err = PTR_ERR(mod->args);
76626- goto free_arch_cleanup;
76627- }
76628-
76629 dynamic_debug_setup(info->debug, info->num_debug);
76630
76631 /* Finally it's fully formed, ready to start executing. */
76632@@ -3321,11 +3453,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
76633 ddebug_cleanup:
76634 dynamic_debug_remove(info->debug);
76635 synchronize_sched();
76636- kfree(mod->args);
76637- free_arch_cleanup:
76638 module_arch_cleanup(mod);
76639 free_modinfo:
76640 free_modinfo(mod);
76641+ kfree(mod->args);
76642 free_unload:
76643 module_unload_free(mod);
76644 unlink_mod:
76645@@ -3408,10 +3539,16 @@ static const char *get_ksymbol(struct module *mod,
76646 unsigned long nextval;
76647
76648 /* At worse, next value is at end of module */
76649- if (within_module_init(addr, mod))
76650- nextval = (unsigned long)mod->module_init+mod->init_text_size;
76651+ if (within_module_init_rx(addr, mod))
76652+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
76653+ else if (within_module_init_rw(addr, mod))
76654+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
76655+ else if (within_module_core_rx(addr, mod))
76656+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
76657+ else if (within_module_core_rw(addr, mod))
76658+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
76659 else
76660- nextval = (unsigned long)mod->module_core+mod->core_text_size;
76661+ return NULL;
76662
76663 /* Scan for closest preceding symbol, and next symbol. (ELF
76664 starts real symbols at 1). */
76665@@ -3664,7 +3801,7 @@ static int m_show(struct seq_file *m, void *p)
76666 return 0;
76667
76668 seq_printf(m, "%s %u",
76669- mod->name, mod->init_size + mod->core_size);
76670+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
76671 print_unload_info(m, mod);
76672
76673 /* Informative for users. */
76674@@ -3673,7 +3810,7 @@ static int m_show(struct seq_file *m, void *p)
76675 mod->state == MODULE_STATE_COMING ? "Loading":
76676 "Live");
76677 /* Used by oprofile and other similar tools. */
76678- seq_printf(m, " 0x%pK", mod->module_core);
76679+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
76680
76681 /* Taints info */
76682 if (mod->taints)
76683@@ -3709,7 +3846,17 @@ static const struct file_operations proc_modules_operations = {
76684
76685 static int __init proc_modules_init(void)
76686 {
76687+#ifndef CONFIG_GRKERNSEC_HIDESYM
76688+#ifdef CONFIG_GRKERNSEC_PROC_USER
76689+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
76690+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
76691+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
76692+#else
76693 proc_create("modules", 0, NULL, &proc_modules_operations);
76694+#endif
76695+#else
76696+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
76697+#endif
76698 return 0;
76699 }
76700 module_init(proc_modules_init);
76701@@ -3770,14 +3917,14 @@ struct module *__module_address(unsigned long addr)
76702 {
76703 struct module *mod;
76704
76705- if (addr < module_addr_min || addr > module_addr_max)
76706+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
76707+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
76708 return NULL;
76709
76710 list_for_each_entry_rcu(mod, &modules, list) {
76711 if (mod->state == MODULE_STATE_UNFORMED)
76712 continue;
76713- if (within_module_core(addr, mod)
76714- || within_module_init(addr, mod))
76715+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
76716 return mod;
76717 }
76718 return NULL;
76719@@ -3812,11 +3959,20 @@ bool is_module_text_address(unsigned long addr)
76720 */
76721 struct module *__module_text_address(unsigned long addr)
76722 {
76723- struct module *mod = __module_address(addr);
76724+ struct module *mod;
76725+
76726+#ifdef CONFIG_X86_32
76727+ addr = ktla_ktva(addr);
76728+#endif
76729+
76730+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
76731+ return NULL;
76732+
76733+ mod = __module_address(addr);
76734+
76735 if (mod) {
76736 /* Make sure it's within the text section. */
76737- if (!within(addr, mod->module_init, mod->init_text_size)
76738- && !within(addr, mod->module_core, mod->core_text_size))
76739+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
76740 mod = NULL;
76741 }
76742 return mod;
76743diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
76744index 7e3443f..b2a1e6b 100644
76745--- a/kernel/mutex-debug.c
76746+++ b/kernel/mutex-debug.c
76747@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
76748 }
76749
76750 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
76751- struct thread_info *ti)
76752+ struct task_struct *task)
76753 {
76754 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
76755
76756 /* Mark the current thread as blocked on the lock: */
76757- ti->task->blocked_on = waiter;
76758+ task->blocked_on = waiter;
76759 }
76760
76761 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
76762- struct thread_info *ti)
76763+ struct task_struct *task)
76764 {
76765 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
76766- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
76767- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
76768- ti->task->blocked_on = NULL;
76769+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
76770+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
76771+ task->blocked_on = NULL;
76772
76773 list_del_init(&waiter->list);
76774 waiter->task = NULL;
76775diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
76776index 0799fd3..d06ae3b 100644
76777--- a/kernel/mutex-debug.h
76778+++ b/kernel/mutex-debug.h
76779@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
76780 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
76781 extern void debug_mutex_add_waiter(struct mutex *lock,
76782 struct mutex_waiter *waiter,
76783- struct thread_info *ti);
76784+ struct task_struct *task);
76785 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
76786- struct thread_info *ti);
76787+ struct task_struct *task);
76788 extern void debug_mutex_unlock(struct mutex *lock);
76789 extern void debug_mutex_init(struct mutex *lock, const char *name,
76790 struct lock_class_key *key);
76791diff --git a/kernel/mutex.c b/kernel/mutex.c
76792index 52f2301..73f7528 100644
76793--- a/kernel/mutex.c
76794+++ b/kernel/mutex.c
76795@@ -199,7 +199,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
76796 spin_lock_mutex(&lock->wait_lock, flags);
76797
76798 debug_mutex_lock_common(lock, &waiter);
76799- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
76800+ debug_mutex_add_waiter(lock, &waiter, task);
76801
76802 /* add waiting tasks to the end of the waitqueue (FIFO): */
76803 list_add_tail(&waiter.list, &lock->wait_list);
76804@@ -228,8 +228,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
76805 * TASK_UNINTERRUPTIBLE case.)
76806 */
76807 if (unlikely(signal_pending_state(state, task))) {
76808- mutex_remove_waiter(lock, &waiter,
76809- task_thread_info(task));
76810+ mutex_remove_waiter(lock, &waiter, task);
76811 mutex_release(&lock->dep_map, 1, ip);
76812 spin_unlock_mutex(&lock->wait_lock, flags);
76813
76814@@ -248,7 +247,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
76815 done:
76816 lock_acquired(&lock->dep_map, ip);
76817 /* got the lock - rejoice! */
76818- mutex_remove_waiter(lock, &waiter, current_thread_info());
76819+ mutex_remove_waiter(lock, &waiter, task);
76820 mutex_set_owner(lock);
76821
76822 /* set it to 0 if there are no waiters left: */
76823diff --git a/kernel/notifier.c b/kernel/notifier.c
76824index 2d5cc4c..d9ea600 100644
76825--- a/kernel/notifier.c
76826+++ b/kernel/notifier.c
76827@@ -5,6 +5,7 @@
76828 #include <linux/rcupdate.h>
76829 #include <linux/vmalloc.h>
76830 #include <linux/reboot.h>
76831+#include <linux/mm.h>
76832
76833 /*
76834 * Notifier list for kernel code which wants to be called
76835@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
76836 while ((*nl) != NULL) {
76837 if (n->priority > (*nl)->priority)
76838 break;
76839- nl = &((*nl)->next);
76840+ nl = (struct notifier_block **)&((*nl)->next);
76841 }
76842- n->next = *nl;
76843+ pax_open_kernel();
76844+ *(const void **)&n->next = *nl;
76845 rcu_assign_pointer(*nl, n);
76846+ pax_close_kernel();
76847 return 0;
76848 }
76849
76850@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
76851 return 0;
76852 if (n->priority > (*nl)->priority)
76853 break;
76854- nl = &((*nl)->next);
76855+ nl = (struct notifier_block **)&((*nl)->next);
76856 }
76857- n->next = *nl;
76858+ pax_open_kernel();
76859+ *(const void **)&n->next = *nl;
76860 rcu_assign_pointer(*nl, n);
76861+ pax_close_kernel();
76862 return 0;
76863 }
76864
76865@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
76866 {
76867 while ((*nl) != NULL) {
76868 if ((*nl) == n) {
76869+ pax_open_kernel();
76870 rcu_assign_pointer(*nl, n->next);
76871+ pax_close_kernel();
76872 return 0;
76873 }
76874- nl = &((*nl)->next);
76875+ nl = (struct notifier_block **)&((*nl)->next);
76876 }
76877 return -ENOENT;
76878 }
76879diff --git a/kernel/panic.c b/kernel/panic.c
76880index 7c57cc9..28f1b3f 100644
76881--- a/kernel/panic.c
76882+++ b/kernel/panic.c
76883@@ -403,7 +403,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
76884 const char *board;
76885
76886 printk(KERN_WARNING "------------[ cut here ]------------\n");
76887- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
76888+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
76889 board = dmi_get_system_info(DMI_PRODUCT_NAME);
76890 if (board)
76891 printk(KERN_WARNING "Hardware name: %s\n", board);
76892@@ -459,7 +459,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
76893 */
76894 void __stack_chk_fail(void)
76895 {
76896- panic("stack-protector: Kernel stack is corrupted in: %p\n",
76897+ dump_stack();
76898+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
76899 __builtin_return_address(0));
76900 }
76901 EXPORT_SYMBOL(__stack_chk_fail);
76902diff --git a/kernel/pid.c b/kernel/pid.c
76903index 047dc62..418d74b 100644
76904--- a/kernel/pid.c
76905+++ b/kernel/pid.c
76906@@ -33,6 +33,7 @@
76907 #include <linux/rculist.h>
76908 #include <linux/bootmem.h>
76909 #include <linux/hash.h>
76910+#include <linux/security.h>
76911 #include <linux/pid_namespace.h>
76912 #include <linux/init_task.h>
76913 #include <linux/syscalls.h>
76914@@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
76915
76916 int pid_max = PID_MAX_DEFAULT;
76917
76918-#define RESERVED_PIDS 300
76919+#define RESERVED_PIDS 500
76920
76921 int pid_max_min = RESERVED_PIDS + 1;
76922 int pid_max_max = PID_MAX_LIMIT;
76923@@ -440,10 +441,18 @@ EXPORT_SYMBOL(pid_task);
76924 */
76925 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
76926 {
76927+ struct task_struct *task;
76928+
76929 rcu_lockdep_assert(rcu_read_lock_held(),
76930 "find_task_by_pid_ns() needs rcu_read_lock()"
76931 " protection");
76932- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
76933+
76934+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
76935+
76936+ if (gr_pid_is_chrooted(task))
76937+ return NULL;
76938+
76939+ return task;
76940 }
76941
76942 struct task_struct *find_task_by_vpid(pid_t vnr)
76943@@ -451,6 +460,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
76944 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
76945 }
76946
76947+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
76948+{
76949+ rcu_lockdep_assert(rcu_read_lock_held(),
76950+ "find_task_by_pid_ns() needs rcu_read_lock()"
76951+ " protection");
76952+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
76953+}
76954+
76955 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
76956 {
76957 struct pid *pid;
76958diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
76959index bea15bd..789f3d0 100644
76960--- a/kernel/pid_namespace.c
76961+++ b/kernel/pid_namespace.c
76962@@ -249,7 +249,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
76963 void __user *buffer, size_t *lenp, loff_t *ppos)
76964 {
76965 struct pid_namespace *pid_ns = task_active_pid_ns(current);
76966- struct ctl_table tmp = *table;
76967+ ctl_table_no_const tmp = *table;
76968
76969 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
76970 return -EPERM;
76971diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
76972index 8fd709c..542bf4b 100644
76973--- a/kernel/posix-cpu-timers.c
76974+++ b/kernel/posix-cpu-timers.c
76975@@ -1592,14 +1592,14 @@ struct k_clock clock_posix_cpu = {
76976
76977 static __init int init_posix_cpu_timers(void)
76978 {
76979- struct k_clock process = {
76980+ static struct k_clock process = {
76981 .clock_getres = process_cpu_clock_getres,
76982 .clock_get = process_cpu_clock_get,
76983 .timer_create = process_cpu_timer_create,
76984 .nsleep = process_cpu_nsleep,
76985 .nsleep_restart = process_cpu_nsleep_restart,
76986 };
76987- struct k_clock thread = {
76988+ static struct k_clock thread = {
76989 .clock_getres = thread_cpu_clock_getres,
76990 .clock_get = thread_cpu_clock_get,
76991 .timer_create = thread_cpu_timer_create,
76992diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
76993index 6edbb2c..334f085 100644
76994--- a/kernel/posix-timers.c
76995+++ b/kernel/posix-timers.c
76996@@ -43,6 +43,7 @@
76997 #include <linux/idr.h>
76998 #include <linux/posix-clock.h>
76999 #include <linux/posix-timers.h>
77000+#include <linux/grsecurity.h>
77001 #include <linux/syscalls.h>
77002 #include <linux/wait.h>
77003 #include <linux/workqueue.h>
77004@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
77005 * which we beg off on and pass to do_sys_settimeofday().
77006 */
77007
77008-static struct k_clock posix_clocks[MAX_CLOCKS];
77009+static struct k_clock *posix_clocks[MAX_CLOCKS];
77010
77011 /*
77012 * These ones are defined below.
77013@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
77014 */
77015 static __init int init_posix_timers(void)
77016 {
77017- struct k_clock clock_realtime = {
77018+ static struct k_clock clock_realtime = {
77019 .clock_getres = hrtimer_get_res,
77020 .clock_get = posix_clock_realtime_get,
77021 .clock_set = posix_clock_realtime_set,
77022@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
77023 .timer_get = common_timer_get,
77024 .timer_del = common_timer_del,
77025 };
77026- struct k_clock clock_monotonic = {
77027+ static struct k_clock clock_monotonic = {
77028 .clock_getres = hrtimer_get_res,
77029 .clock_get = posix_ktime_get_ts,
77030 .nsleep = common_nsleep,
77031@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
77032 .timer_get = common_timer_get,
77033 .timer_del = common_timer_del,
77034 };
77035- struct k_clock clock_monotonic_raw = {
77036+ static struct k_clock clock_monotonic_raw = {
77037 .clock_getres = hrtimer_get_res,
77038 .clock_get = posix_get_monotonic_raw,
77039 };
77040- struct k_clock clock_realtime_coarse = {
77041+ static struct k_clock clock_realtime_coarse = {
77042 .clock_getres = posix_get_coarse_res,
77043 .clock_get = posix_get_realtime_coarse,
77044 };
77045- struct k_clock clock_monotonic_coarse = {
77046+ static struct k_clock clock_monotonic_coarse = {
77047 .clock_getres = posix_get_coarse_res,
77048 .clock_get = posix_get_monotonic_coarse,
77049 };
77050- struct k_clock clock_boottime = {
77051+ static struct k_clock clock_boottime = {
77052 .clock_getres = hrtimer_get_res,
77053 .clock_get = posix_get_boottime,
77054 .nsleep = common_nsleep,
77055@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
77056 return;
77057 }
77058
77059- posix_clocks[clock_id] = *new_clock;
77060+ posix_clocks[clock_id] = new_clock;
77061 }
77062 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
77063
77064@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
77065 return (id & CLOCKFD_MASK) == CLOCKFD ?
77066 &clock_posix_dynamic : &clock_posix_cpu;
77067
77068- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
77069+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
77070 return NULL;
77071- return &posix_clocks[id];
77072+ return posix_clocks[id];
77073 }
77074
77075 static int common_timer_create(struct k_itimer *new_timer)
77076@@ -964,6 +965,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
77077 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
77078 return -EFAULT;
77079
77080+ /* only the CLOCK_REALTIME clock can be set, all other clocks
77081+ have their clock_set fptr set to a nosettime dummy function
77082+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
77083+ call common_clock_set, which calls do_sys_settimeofday, which
77084+ we hook
77085+ */
77086+
77087 return kc->clock_set(which_clock, &new_tp);
77088 }
77089
77090diff --git a/kernel/power/process.c b/kernel/power/process.c
77091index 98088e0..aaf95c0 100644
77092--- a/kernel/power/process.c
77093+++ b/kernel/power/process.c
77094@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
77095 u64 elapsed_csecs64;
77096 unsigned int elapsed_csecs;
77097 bool wakeup = false;
77098+ bool timedout = false;
77099
77100 do_gettimeofday(&start);
77101
77102@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
77103
77104 while (true) {
77105 todo = 0;
77106+ if (time_after(jiffies, end_time))
77107+ timedout = true;
77108 read_lock(&tasklist_lock);
77109 do_each_thread(g, p) {
77110 if (p == current || !freeze_task(p))
77111 continue;
77112
77113- if (!freezer_should_skip(p))
77114+ if (!freezer_should_skip(p)) {
77115 todo++;
77116+ if (timedout) {
77117+ printk(KERN_ERR "Task refusing to freeze:\n");
77118+ sched_show_task(p);
77119+ }
77120+ }
77121 } while_each_thread(g, p);
77122 read_unlock(&tasklist_lock);
77123
77124@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
77125 todo += wq_busy;
77126 }
77127
77128- if (!todo || time_after(jiffies, end_time))
77129+ if (!todo || timedout)
77130 break;
77131
77132 if (pm_wakeup_pending()) {
77133diff --git a/kernel/printk.c b/kernel/printk.c
77134index abbdd9e..f294251 100644
77135--- a/kernel/printk.c
77136+++ b/kernel/printk.c
77137@@ -615,11 +615,17 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
77138 return ret;
77139 }
77140
77141+static int check_syslog_permissions(int type, bool from_file);
77142+
77143 static int devkmsg_open(struct inode *inode, struct file *file)
77144 {
77145 struct devkmsg_user *user;
77146 int err;
77147
77148+ err = check_syslog_permissions(SYSLOG_ACTION_OPEN, SYSLOG_FROM_FILE);
77149+ if (err)
77150+ return err;
77151+
77152 /* write-only does not need any file context */
77153 if ((file->f_flags & O_ACCMODE) == O_WRONLY)
77154 return 0;
77155@@ -828,7 +834,7 @@ static int syslog_action_restricted(int type)
77156 if (dmesg_restrict)
77157 return 1;
77158 /* Unless restricted, we allow "read all" and "get buffer size" for everybody */
77159- return type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
77160+ return type != SYSLOG_ACTION_OPEN && type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
77161 }
77162
77163 static int check_syslog_permissions(int type, bool from_file)
77164@@ -840,6 +846,11 @@ static int check_syslog_permissions(int type, bool from_file)
77165 if (from_file && type != SYSLOG_ACTION_OPEN)
77166 return 0;
77167
77168+#ifdef CONFIG_GRKERNSEC_DMESG
77169+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
77170+ return -EPERM;
77171+#endif
77172+
77173 if (syslog_action_restricted(type)) {
77174 if (capable(CAP_SYSLOG))
77175 return 0;
77176diff --git a/kernel/profile.c b/kernel/profile.c
77177index dc3384e..0de5b49 100644
77178--- a/kernel/profile.c
77179+++ b/kernel/profile.c
77180@@ -37,7 +37,7 @@ struct profile_hit {
77181 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
77182 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
77183
77184-static atomic_t *prof_buffer;
77185+static atomic_unchecked_t *prof_buffer;
77186 static unsigned long prof_len, prof_shift;
77187
77188 int prof_on __read_mostly;
77189@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
77190 hits[i].pc = 0;
77191 continue;
77192 }
77193- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
77194+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
77195 hits[i].hits = hits[i].pc = 0;
77196 }
77197 }
77198@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
77199 * Add the current hit(s) and flush the write-queue out
77200 * to the global buffer:
77201 */
77202- atomic_add(nr_hits, &prof_buffer[pc]);
77203+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
77204 for (i = 0; i < NR_PROFILE_HIT; ++i) {
77205- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
77206+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
77207 hits[i].pc = hits[i].hits = 0;
77208 }
77209 out:
77210@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
77211 {
77212 unsigned long pc;
77213 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
77214- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
77215+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
77216 }
77217 #endif /* !CONFIG_SMP */
77218
77219@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
77220 return -EFAULT;
77221 buf++; p++; count--; read++;
77222 }
77223- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
77224+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
77225 if (copy_to_user(buf, (void *)pnt, count))
77226 return -EFAULT;
77227 read += count;
77228@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
77229 }
77230 #endif
77231 profile_discard_flip_buffers();
77232- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
77233+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
77234 return count;
77235 }
77236
77237diff --git a/kernel/ptrace.c b/kernel/ptrace.c
77238index acbd284..00bb0c9 100644
77239--- a/kernel/ptrace.c
77240+++ b/kernel/ptrace.c
77241@@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
77242 if (seize)
77243 flags |= PT_SEIZED;
77244 rcu_read_lock();
77245- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
77246+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
77247 flags |= PT_PTRACE_CAP;
77248 rcu_read_unlock();
77249 task->ptrace = flags;
77250@@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
77251 break;
77252 return -EIO;
77253 }
77254- if (copy_to_user(dst, buf, retval))
77255+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
77256 return -EFAULT;
77257 copied += retval;
77258 src += retval;
77259@@ -726,7 +726,7 @@ int ptrace_request(struct task_struct *child, long request,
77260 bool seized = child->ptrace & PT_SEIZED;
77261 int ret = -EIO;
77262 siginfo_t siginfo, *si;
77263- void __user *datavp = (void __user *) data;
77264+ void __user *datavp = (__force void __user *) data;
77265 unsigned long __user *datalp = datavp;
77266 unsigned long flags;
77267
77268@@ -928,14 +928,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
77269 goto out;
77270 }
77271
77272+ if (gr_handle_ptrace(child, request)) {
77273+ ret = -EPERM;
77274+ goto out_put_task_struct;
77275+ }
77276+
77277 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
77278 ret = ptrace_attach(child, request, addr, data);
77279 /*
77280 * Some architectures need to do book-keeping after
77281 * a ptrace attach.
77282 */
77283- if (!ret)
77284+ if (!ret) {
77285 arch_ptrace_attach(child);
77286+ gr_audit_ptrace(child);
77287+ }
77288 goto out_put_task_struct;
77289 }
77290
77291@@ -963,7 +970,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
77292 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
77293 if (copied != sizeof(tmp))
77294 return -EIO;
77295- return put_user(tmp, (unsigned long __user *)data);
77296+ return put_user(tmp, (__force unsigned long __user *)data);
77297 }
77298
77299 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
77300@@ -1057,7 +1064,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
77301 }
77302
77303 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77304- compat_long_t addr, compat_long_t data)
77305+ compat_ulong_t addr, compat_ulong_t data)
77306 {
77307 struct task_struct *child;
77308 long ret;
77309@@ -1073,14 +1080,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77310 goto out;
77311 }
77312
77313+ if (gr_handle_ptrace(child, request)) {
77314+ ret = -EPERM;
77315+ goto out_put_task_struct;
77316+ }
77317+
77318 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
77319 ret = ptrace_attach(child, request, addr, data);
77320 /*
77321 * Some architectures need to do book-keeping after
77322 * a ptrace attach.
77323 */
77324- if (!ret)
77325+ if (!ret) {
77326 arch_ptrace_attach(child);
77327+ gr_audit_ptrace(child);
77328+ }
77329 goto out_put_task_struct;
77330 }
77331
77332diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
77333index 48ab703..07561d4 100644
77334--- a/kernel/rcupdate.c
77335+++ b/kernel/rcupdate.c
77336@@ -439,10 +439,10 @@ int rcu_jiffies_till_stall_check(void)
77337 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
77338 */
77339 if (till_stall_check < 3) {
77340- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
77341+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
77342 till_stall_check = 3;
77343 } else if (till_stall_check > 300) {
77344- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
77345+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
77346 till_stall_check = 300;
77347 }
77348 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
77349diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
77350index a0714a5..2ab5e34 100644
77351--- a/kernel/rcutiny.c
77352+++ b/kernel/rcutiny.c
77353@@ -46,7 +46,7 @@
77354 struct rcu_ctrlblk;
77355 static void invoke_rcu_callbacks(void);
77356 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
77357-static void rcu_process_callbacks(struct softirq_action *unused);
77358+static void rcu_process_callbacks(void);
77359 static void __call_rcu(struct rcu_head *head,
77360 void (*func)(struct rcu_head *rcu),
77361 struct rcu_ctrlblk *rcp);
77362@@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
77363 rcu_is_callbacks_kthread()));
77364 }
77365
77366-static void rcu_process_callbacks(struct softirq_action *unused)
77367+static void rcu_process_callbacks(void)
77368 {
77369 __rcu_process_callbacks(&rcu_sched_ctrlblk);
77370 __rcu_process_callbacks(&rcu_bh_ctrlblk);
77371diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
77372index 8a23300..4255818 100644
77373--- a/kernel/rcutiny_plugin.h
77374+++ b/kernel/rcutiny_plugin.h
77375@@ -945,7 +945,7 @@ static int rcu_kthread(void *arg)
77376 have_rcu_kthread_work = morework;
77377 local_irq_restore(flags);
77378 if (work)
77379- rcu_process_callbacks(NULL);
77380+ rcu_process_callbacks();
77381 schedule_timeout_interruptible(1); /* Leave CPU for others. */
77382 }
77383
77384diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
77385index e1f3a8c..42c94a2 100644
77386--- a/kernel/rcutorture.c
77387+++ b/kernel/rcutorture.c
77388@@ -164,12 +164,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
77389 { 0 };
77390 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
77391 { 0 };
77392-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
77393-static atomic_t n_rcu_torture_alloc;
77394-static atomic_t n_rcu_torture_alloc_fail;
77395-static atomic_t n_rcu_torture_free;
77396-static atomic_t n_rcu_torture_mberror;
77397-static atomic_t n_rcu_torture_error;
77398+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
77399+static atomic_unchecked_t n_rcu_torture_alloc;
77400+static atomic_unchecked_t n_rcu_torture_alloc_fail;
77401+static atomic_unchecked_t n_rcu_torture_free;
77402+static atomic_unchecked_t n_rcu_torture_mberror;
77403+static atomic_unchecked_t n_rcu_torture_error;
77404 static long n_rcu_torture_barrier_error;
77405 static long n_rcu_torture_boost_ktrerror;
77406 static long n_rcu_torture_boost_rterror;
77407@@ -287,11 +287,11 @@ rcu_torture_alloc(void)
77408
77409 spin_lock_bh(&rcu_torture_lock);
77410 if (list_empty(&rcu_torture_freelist)) {
77411- atomic_inc(&n_rcu_torture_alloc_fail);
77412+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
77413 spin_unlock_bh(&rcu_torture_lock);
77414 return NULL;
77415 }
77416- atomic_inc(&n_rcu_torture_alloc);
77417+ atomic_inc_unchecked(&n_rcu_torture_alloc);
77418 p = rcu_torture_freelist.next;
77419 list_del_init(p);
77420 spin_unlock_bh(&rcu_torture_lock);
77421@@ -304,7 +304,7 @@ rcu_torture_alloc(void)
77422 static void
77423 rcu_torture_free(struct rcu_torture *p)
77424 {
77425- atomic_inc(&n_rcu_torture_free);
77426+ atomic_inc_unchecked(&n_rcu_torture_free);
77427 spin_lock_bh(&rcu_torture_lock);
77428 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
77429 spin_unlock_bh(&rcu_torture_lock);
77430@@ -424,7 +424,7 @@ rcu_torture_cb(struct rcu_head *p)
77431 i = rp->rtort_pipe_count;
77432 if (i > RCU_TORTURE_PIPE_LEN)
77433 i = RCU_TORTURE_PIPE_LEN;
77434- atomic_inc(&rcu_torture_wcount[i]);
77435+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
77436 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
77437 rp->rtort_mbtest = 0;
77438 rcu_torture_free(rp);
77439@@ -472,7 +472,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
77440 i = rp->rtort_pipe_count;
77441 if (i > RCU_TORTURE_PIPE_LEN)
77442 i = RCU_TORTURE_PIPE_LEN;
77443- atomic_inc(&rcu_torture_wcount[i]);
77444+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
77445 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
77446 rp->rtort_mbtest = 0;
77447 list_del(&rp->rtort_free);
77448@@ -990,7 +990,7 @@ rcu_torture_writer(void *arg)
77449 i = old_rp->rtort_pipe_count;
77450 if (i > RCU_TORTURE_PIPE_LEN)
77451 i = RCU_TORTURE_PIPE_LEN;
77452- atomic_inc(&rcu_torture_wcount[i]);
77453+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
77454 old_rp->rtort_pipe_count++;
77455 cur_ops->deferred_free(old_rp);
77456 }
77457@@ -1076,7 +1076,7 @@ static void rcu_torture_timer(unsigned long unused)
77458 return;
77459 }
77460 if (p->rtort_mbtest == 0)
77461- atomic_inc(&n_rcu_torture_mberror);
77462+ atomic_inc_unchecked(&n_rcu_torture_mberror);
77463 spin_lock(&rand_lock);
77464 cur_ops->read_delay(&rand);
77465 n_rcu_torture_timers++;
77466@@ -1146,7 +1146,7 @@ rcu_torture_reader(void *arg)
77467 continue;
77468 }
77469 if (p->rtort_mbtest == 0)
77470- atomic_inc(&n_rcu_torture_mberror);
77471+ atomic_inc_unchecked(&n_rcu_torture_mberror);
77472 cur_ops->read_delay(&rand);
77473 preempt_disable();
77474 pipe_count = p->rtort_pipe_count;
77475@@ -1209,11 +1209,11 @@ rcu_torture_printk(char *page)
77476 rcu_torture_current,
77477 rcu_torture_current_version,
77478 list_empty(&rcu_torture_freelist),
77479- atomic_read(&n_rcu_torture_alloc),
77480- atomic_read(&n_rcu_torture_alloc_fail),
77481- atomic_read(&n_rcu_torture_free));
77482+ atomic_read_unchecked(&n_rcu_torture_alloc),
77483+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
77484+ atomic_read_unchecked(&n_rcu_torture_free));
77485 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
77486- atomic_read(&n_rcu_torture_mberror),
77487+ atomic_read_unchecked(&n_rcu_torture_mberror),
77488 n_rcu_torture_boost_ktrerror,
77489 n_rcu_torture_boost_rterror);
77490 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
77491@@ -1232,14 +1232,14 @@ rcu_torture_printk(char *page)
77492 n_barrier_attempts,
77493 n_rcu_torture_barrier_error);
77494 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
77495- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
77496+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
77497 n_rcu_torture_barrier_error != 0 ||
77498 n_rcu_torture_boost_ktrerror != 0 ||
77499 n_rcu_torture_boost_rterror != 0 ||
77500 n_rcu_torture_boost_failure != 0 ||
77501 i > 1) {
77502 cnt += sprintf(&page[cnt], "!!! ");
77503- atomic_inc(&n_rcu_torture_error);
77504+ atomic_inc_unchecked(&n_rcu_torture_error);
77505 WARN_ON_ONCE(1);
77506 }
77507 cnt += sprintf(&page[cnt], "Reader Pipe: ");
77508@@ -1253,7 +1253,7 @@ rcu_torture_printk(char *page)
77509 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
77510 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
77511 cnt += sprintf(&page[cnt], " %d",
77512- atomic_read(&rcu_torture_wcount[i]));
77513+ atomic_read_unchecked(&rcu_torture_wcount[i]));
77514 }
77515 cnt += sprintf(&page[cnt], "\n");
77516 if (cur_ops->stats)
77517@@ -1962,7 +1962,7 @@ rcu_torture_cleanup(void)
77518
77519 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
77520
77521- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
77522+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
77523 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
77524 else if (n_online_successes != n_online_attempts ||
77525 n_offline_successes != n_offline_attempts)
77526@@ -2031,18 +2031,18 @@ rcu_torture_init(void)
77527
77528 rcu_torture_current = NULL;
77529 rcu_torture_current_version = 0;
77530- atomic_set(&n_rcu_torture_alloc, 0);
77531- atomic_set(&n_rcu_torture_alloc_fail, 0);
77532- atomic_set(&n_rcu_torture_free, 0);
77533- atomic_set(&n_rcu_torture_mberror, 0);
77534- atomic_set(&n_rcu_torture_error, 0);
77535+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
77536+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
77537+ atomic_set_unchecked(&n_rcu_torture_free, 0);
77538+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
77539+ atomic_set_unchecked(&n_rcu_torture_error, 0);
77540 n_rcu_torture_barrier_error = 0;
77541 n_rcu_torture_boost_ktrerror = 0;
77542 n_rcu_torture_boost_rterror = 0;
77543 n_rcu_torture_boost_failure = 0;
77544 n_rcu_torture_boosts = 0;
77545 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
77546- atomic_set(&rcu_torture_wcount[i], 0);
77547+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
77548 for_each_possible_cpu(cpu) {
77549 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
77550 per_cpu(rcu_torture_count, cpu)[i] = 0;
77551diff --git a/kernel/rcutree.c b/kernel/rcutree.c
77552index 5b8ad82..17274d1 100644
77553--- a/kernel/rcutree.c
77554+++ b/kernel/rcutree.c
77555@@ -353,9 +353,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
77556 rcu_prepare_for_idle(smp_processor_id());
77557 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
77558 smp_mb__before_atomic_inc(); /* See above. */
77559- atomic_inc(&rdtp->dynticks);
77560+ atomic_inc_unchecked(&rdtp->dynticks);
77561 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
77562- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
77563+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
77564
77565 /*
77566 * It is illegal to enter an extended quiescent state while
77567@@ -491,10 +491,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
77568 int user)
77569 {
77570 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
77571- atomic_inc(&rdtp->dynticks);
77572+ atomic_inc_unchecked(&rdtp->dynticks);
77573 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
77574 smp_mb__after_atomic_inc(); /* See above. */
77575- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
77576+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
77577 rcu_cleanup_after_idle(smp_processor_id());
77578 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
77579 if (!user && !is_idle_task(current)) {
77580@@ -633,14 +633,14 @@ void rcu_nmi_enter(void)
77581 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
77582
77583 if (rdtp->dynticks_nmi_nesting == 0 &&
77584- (atomic_read(&rdtp->dynticks) & 0x1))
77585+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
77586 return;
77587 rdtp->dynticks_nmi_nesting++;
77588 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
77589- atomic_inc(&rdtp->dynticks);
77590+ atomic_inc_unchecked(&rdtp->dynticks);
77591 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
77592 smp_mb__after_atomic_inc(); /* See above. */
77593- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
77594+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
77595 }
77596
77597 /**
77598@@ -659,9 +659,9 @@ void rcu_nmi_exit(void)
77599 return;
77600 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
77601 smp_mb__before_atomic_inc(); /* See above. */
77602- atomic_inc(&rdtp->dynticks);
77603+ atomic_inc_unchecked(&rdtp->dynticks);
77604 smp_mb__after_atomic_inc(); /* Force delay to next write. */
77605- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
77606+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
77607 }
77608
77609 /**
77610@@ -675,7 +675,7 @@ int rcu_is_cpu_idle(void)
77611 int ret;
77612
77613 preempt_disable();
77614- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
77615+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
77616 preempt_enable();
77617 return ret;
77618 }
77619@@ -743,7 +743,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
77620 */
77621 static int dyntick_save_progress_counter(struct rcu_data *rdp)
77622 {
77623- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
77624+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
77625 return (rdp->dynticks_snap & 0x1) == 0;
77626 }
77627
77628@@ -758,7 +758,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
77629 unsigned int curr;
77630 unsigned int snap;
77631
77632- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
77633+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
77634 snap = (unsigned int)rdp->dynticks_snap;
77635
77636 /*
77637@@ -1698,7 +1698,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
77638 rsp->qlen += rdp->qlen;
77639 rdp->n_cbs_orphaned += rdp->qlen;
77640 rdp->qlen_lazy = 0;
77641- ACCESS_ONCE(rdp->qlen) = 0;
77642+ ACCESS_ONCE_RW(rdp->qlen) = 0;
77643 }
77644
77645 /*
77646@@ -1944,7 +1944,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
77647 }
77648 smp_mb(); /* List handling before counting for rcu_barrier(). */
77649 rdp->qlen_lazy -= count_lazy;
77650- ACCESS_ONCE(rdp->qlen) -= count;
77651+ ACCESS_ONCE_RW(rdp->qlen) -= count;
77652 rdp->n_cbs_invoked += count;
77653
77654 /* Reinstate batch limit if we have worked down the excess. */
77655@@ -2137,7 +2137,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
77656 /*
77657 * Do RCU core processing for the current CPU.
77658 */
77659-static void rcu_process_callbacks(struct softirq_action *unused)
77660+static void rcu_process_callbacks(void)
77661 {
77662 struct rcu_state *rsp;
77663
77664@@ -2260,7 +2260,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
77665 local_irq_restore(flags);
77666 return;
77667 }
77668- ACCESS_ONCE(rdp->qlen)++;
77669+ ACCESS_ONCE_RW(rdp->qlen)++;
77670 if (lazy)
77671 rdp->qlen_lazy++;
77672 else
77673@@ -2469,11 +2469,11 @@ void synchronize_sched_expedited(void)
77674 * counter wrap on a 32-bit system. Quite a few more CPUs would of
77675 * course be required on a 64-bit system.
77676 */
77677- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
77678+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
77679 (ulong)atomic_long_read(&rsp->expedited_done) +
77680 ULONG_MAX / 8)) {
77681 synchronize_sched();
77682- atomic_long_inc(&rsp->expedited_wrap);
77683+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
77684 return;
77685 }
77686
77687@@ -2481,7 +2481,7 @@ void synchronize_sched_expedited(void)
77688 * Take a ticket. Note that atomic_inc_return() implies a
77689 * full memory barrier.
77690 */
77691- snap = atomic_long_inc_return(&rsp->expedited_start);
77692+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
77693 firstsnap = snap;
77694 get_online_cpus();
77695 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
77696@@ -2494,14 +2494,14 @@ void synchronize_sched_expedited(void)
77697 synchronize_sched_expedited_cpu_stop,
77698 NULL) == -EAGAIN) {
77699 put_online_cpus();
77700- atomic_long_inc(&rsp->expedited_tryfail);
77701+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
77702
77703 /* Check to see if someone else did our work for us. */
77704 s = atomic_long_read(&rsp->expedited_done);
77705 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
77706 /* ensure test happens before caller kfree */
77707 smp_mb__before_atomic_inc(); /* ^^^ */
77708- atomic_long_inc(&rsp->expedited_workdone1);
77709+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
77710 return;
77711 }
77712
77713@@ -2510,7 +2510,7 @@ void synchronize_sched_expedited(void)
77714 udelay(trycount * num_online_cpus());
77715 } else {
77716 wait_rcu_gp(call_rcu_sched);
77717- atomic_long_inc(&rsp->expedited_normal);
77718+ atomic_long_inc_unchecked(&rsp->expedited_normal);
77719 return;
77720 }
77721
77722@@ -2519,7 +2519,7 @@ void synchronize_sched_expedited(void)
77723 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
77724 /* ensure test happens before caller kfree */
77725 smp_mb__before_atomic_inc(); /* ^^^ */
77726- atomic_long_inc(&rsp->expedited_workdone2);
77727+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
77728 return;
77729 }
77730
77731@@ -2531,10 +2531,10 @@ void synchronize_sched_expedited(void)
77732 * period works for us.
77733 */
77734 get_online_cpus();
77735- snap = atomic_long_read(&rsp->expedited_start);
77736+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
77737 smp_mb(); /* ensure read is before try_stop_cpus(). */
77738 }
77739- atomic_long_inc(&rsp->expedited_stoppedcpus);
77740+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
77741
77742 /*
77743 * Everyone up to our most recent fetch is covered by our grace
77744@@ -2543,16 +2543,16 @@ void synchronize_sched_expedited(void)
77745 * than we did already did their update.
77746 */
77747 do {
77748- atomic_long_inc(&rsp->expedited_done_tries);
77749+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
77750 s = atomic_long_read(&rsp->expedited_done);
77751 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
77752 /* ensure test happens before caller kfree */
77753 smp_mb__before_atomic_inc(); /* ^^^ */
77754- atomic_long_inc(&rsp->expedited_done_lost);
77755+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
77756 break;
77757 }
77758 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
77759- atomic_long_inc(&rsp->expedited_done_exit);
77760+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
77761
77762 put_online_cpus();
77763 }
77764@@ -2726,7 +2726,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
77765 * ACCESS_ONCE() to prevent the compiler from speculating
77766 * the increment to precede the early-exit check.
77767 */
77768- ACCESS_ONCE(rsp->n_barrier_done)++;
77769+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
77770 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
77771 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
77772 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
77773@@ -2776,7 +2776,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
77774
77775 /* Increment ->n_barrier_done to prevent duplicate work. */
77776 smp_mb(); /* Keep increment after above mechanism. */
77777- ACCESS_ONCE(rsp->n_barrier_done)++;
77778+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
77779 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
77780 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
77781 smp_mb(); /* Keep increment before caller's subsequent code. */
77782@@ -2821,10 +2821,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
77783 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
77784 init_callback_list(rdp);
77785 rdp->qlen_lazy = 0;
77786- ACCESS_ONCE(rdp->qlen) = 0;
77787+ ACCESS_ONCE_RW(rdp->qlen) = 0;
77788 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
77789 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
77790- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
77791+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
77792 rdp->cpu = cpu;
77793 rdp->rsp = rsp;
77794 rcu_boot_init_nocb_percpu_data(rdp);
77795@@ -2857,8 +2857,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
77796 rdp->blimit = blimit;
77797 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
77798 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
77799- atomic_set(&rdp->dynticks->dynticks,
77800- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
77801+ atomic_set_unchecked(&rdp->dynticks->dynticks,
77802+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
77803 rcu_prepare_for_idle_init(cpu);
77804 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
77805
77806diff --git a/kernel/rcutree.h b/kernel/rcutree.h
77807index c896b50..c357252 100644
77808--- a/kernel/rcutree.h
77809+++ b/kernel/rcutree.h
77810@@ -86,7 +86,7 @@ struct rcu_dynticks {
77811 long long dynticks_nesting; /* Track irq/process nesting level. */
77812 /* Process level is worth LLONG_MAX/2. */
77813 int dynticks_nmi_nesting; /* Track NMI nesting level. */
77814- atomic_t dynticks; /* Even value for idle, else odd. */
77815+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
77816 #ifdef CONFIG_RCU_FAST_NO_HZ
77817 int dyntick_drain; /* Prepare-for-idle state variable. */
77818 unsigned long dyntick_holdoff;
77819@@ -416,17 +416,17 @@ struct rcu_state {
77820 /* _rcu_barrier(). */
77821 /* End of fields guarded by barrier_mutex. */
77822
77823- atomic_long_t expedited_start; /* Starting ticket. */
77824- atomic_long_t expedited_done; /* Done ticket. */
77825- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
77826- atomic_long_t expedited_tryfail; /* # acquisition failures. */
77827- atomic_long_t expedited_workdone1; /* # done by others #1. */
77828- atomic_long_t expedited_workdone2; /* # done by others #2. */
77829- atomic_long_t expedited_normal; /* # fallbacks to normal. */
77830- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
77831- atomic_long_t expedited_done_tries; /* # tries to update _done. */
77832- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
77833- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
77834+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
77835+ atomic_long_t expedited_done; /* Done ticket. */
77836+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
77837+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
77838+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
77839+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
77840+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
77841+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
77842+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
77843+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
77844+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
77845
77846 unsigned long jiffies_force_qs; /* Time at which to invoke */
77847 /* force_quiescent_state(). */
77848diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
77849index c1cc7e1..f62e436 100644
77850--- a/kernel/rcutree_plugin.h
77851+++ b/kernel/rcutree_plugin.h
77852@@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
77853
77854 /* Clean up and exit. */
77855 smp_mb(); /* ensure expedited GP seen before counter increment. */
77856- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
77857+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
77858 unlock_mb_ret:
77859 mutex_unlock(&sync_rcu_preempt_exp_mutex);
77860 mb_ret:
77861@@ -1440,7 +1440,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
77862 free_cpumask_var(cm);
77863 }
77864
77865-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
77866+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
77867 .store = &rcu_cpu_kthread_task,
77868 .thread_should_run = rcu_cpu_kthread_should_run,
77869 .thread_fn = rcu_cpu_kthread,
77870@@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
77871 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
77872 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
77873 cpu, ticks_value, ticks_title,
77874- atomic_read(&rdtp->dynticks) & 0xfff,
77875+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
77876 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
77877 fast_no_hz);
77878 }
77879@@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
77880
77881 /* Enqueue the callback on the nocb list and update counts. */
77882 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
77883- ACCESS_ONCE(*old_rhpp) = rhp;
77884+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
77885 atomic_long_add(rhcount, &rdp->nocb_q_count);
77886 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
77887
77888@@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
77889 * Extract queued callbacks, update counts, and wait
77890 * for a grace period to elapse.
77891 */
77892- ACCESS_ONCE(rdp->nocb_head) = NULL;
77893+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
77894 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
77895 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
77896 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
77897- ACCESS_ONCE(rdp->nocb_p_count) += c;
77898- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
77899+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
77900+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
77901 wait_rcu_gp(rdp->rsp->call_remote);
77902
77903 /* Each pass through the following loop invokes a callback. */
77904@@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
77905 list = next;
77906 }
77907 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
77908- ACCESS_ONCE(rdp->nocb_p_count) -= c;
77909- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
77910+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
77911+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
77912 rdp->n_nocbs_invoked += c;
77913 }
77914 return 0;
77915@@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
77916 rdp = per_cpu_ptr(rsp->rda, cpu);
77917 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
77918 BUG_ON(IS_ERR(t));
77919- ACCESS_ONCE(rdp->nocb_kthread) = t;
77920+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
77921 }
77922 }
77923
77924diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
77925index 93f8e8f..cf812ae 100644
77926--- a/kernel/rcutree_trace.c
77927+++ b/kernel/rcutree_trace.c
77928@@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
77929 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
77930 rdp->passed_quiesce, rdp->qs_pending);
77931 seq_printf(m, " dt=%d/%llx/%d df=%lu",
77932- atomic_read(&rdp->dynticks->dynticks),
77933+ atomic_read_unchecked(&rdp->dynticks->dynticks),
77934 rdp->dynticks->dynticks_nesting,
77935 rdp->dynticks->dynticks_nmi_nesting,
77936 rdp->dynticks_fqs);
77937@@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
77938 struct rcu_state *rsp = (struct rcu_state *)m->private;
77939
77940 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",
77941- atomic_long_read(&rsp->expedited_start),
77942+ atomic_long_read_unchecked(&rsp->expedited_start),
77943 atomic_long_read(&rsp->expedited_done),
77944- atomic_long_read(&rsp->expedited_wrap),
77945- atomic_long_read(&rsp->expedited_tryfail),
77946- atomic_long_read(&rsp->expedited_workdone1),
77947- atomic_long_read(&rsp->expedited_workdone2),
77948- atomic_long_read(&rsp->expedited_normal),
77949- atomic_long_read(&rsp->expedited_stoppedcpus),
77950- atomic_long_read(&rsp->expedited_done_tries),
77951- atomic_long_read(&rsp->expedited_done_lost),
77952- atomic_long_read(&rsp->expedited_done_exit));
77953+ atomic_long_read_unchecked(&rsp->expedited_wrap),
77954+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
77955+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
77956+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
77957+ atomic_long_read_unchecked(&rsp->expedited_normal),
77958+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
77959+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
77960+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
77961+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
77962 return 0;
77963 }
77964
77965diff --git a/kernel/resource.c b/kernel/resource.c
77966index 73f35d4..4684fc4 100644
77967--- a/kernel/resource.c
77968+++ b/kernel/resource.c
77969@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
77970
77971 static int __init ioresources_init(void)
77972 {
77973+#ifdef CONFIG_GRKERNSEC_PROC_ADD
77974+#ifdef CONFIG_GRKERNSEC_PROC_USER
77975+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
77976+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
77977+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77978+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
77979+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
77980+#endif
77981+#else
77982 proc_create("ioports", 0, NULL, &proc_ioports_operations);
77983 proc_create("iomem", 0, NULL, &proc_iomem_operations);
77984+#endif
77985 return 0;
77986 }
77987 __initcall(ioresources_init);
77988diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
77989index 7890b10..8b68605f 100644
77990--- a/kernel/rtmutex-tester.c
77991+++ b/kernel/rtmutex-tester.c
77992@@ -21,7 +21,7 @@
77993 #define MAX_RT_TEST_MUTEXES 8
77994
77995 static spinlock_t rttest_lock;
77996-static atomic_t rttest_event;
77997+static atomic_unchecked_t rttest_event;
77998
77999 struct test_thread_data {
78000 int opcode;
78001@@ -62,7 +62,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78002
78003 case RTTEST_LOCKCONT:
78004 td->mutexes[td->opdata] = 1;
78005- td->event = atomic_add_return(1, &rttest_event);
78006+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78007 return 0;
78008
78009 case RTTEST_RESET:
78010@@ -75,7 +75,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78011 return 0;
78012
78013 case RTTEST_RESETEVENT:
78014- atomic_set(&rttest_event, 0);
78015+ atomic_set_unchecked(&rttest_event, 0);
78016 return 0;
78017
78018 default:
78019@@ -92,9 +92,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78020 return ret;
78021
78022 td->mutexes[id] = 1;
78023- td->event = atomic_add_return(1, &rttest_event);
78024+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78025 rt_mutex_lock(&mutexes[id]);
78026- td->event = atomic_add_return(1, &rttest_event);
78027+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78028 td->mutexes[id] = 4;
78029 return 0;
78030
78031@@ -105,9 +105,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78032 return ret;
78033
78034 td->mutexes[id] = 1;
78035- td->event = atomic_add_return(1, &rttest_event);
78036+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78037 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
78038- td->event = atomic_add_return(1, &rttest_event);
78039+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78040 td->mutexes[id] = ret ? 0 : 4;
78041 return ret ? -EINTR : 0;
78042
78043@@ -116,9 +116,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78044 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
78045 return ret;
78046
78047- td->event = atomic_add_return(1, &rttest_event);
78048+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78049 rt_mutex_unlock(&mutexes[id]);
78050- td->event = atomic_add_return(1, &rttest_event);
78051+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78052 td->mutexes[id] = 0;
78053 return 0;
78054
78055@@ -165,7 +165,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78056 break;
78057
78058 td->mutexes[dat] = 2;
78059- td->event = atomic_add_return(1, &rttest_event);
78060+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78061 break;
78062
78063 default:
78064@@ -185,7 +185,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78065 return;
78066
78067 td->mutexes[dat] = 3;
78068- td->event = atomic_add_return(1, &rttest_event);
78069+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78070 break;
78071
78072 case RTTEST_LOCKNOWAIT:
78073@@ -197,7 +197,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78074 return;
78075
78076 td->mutexes[dat] = 1;
78077- td->event = atomic_add_return(1, &rttest_event);
78078+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78079 return;
78080
78081 default:
78082diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
78083index 64de5f8..7735e12 100644
78084--- a/kernel/sched/auto_group.c
78085+++ b/kernel/sched/auto_group.c
78086@@ -11,7 +11,7 @@
78087
78088 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
78089 static struct autogroup autogroup_default;
78090-static atomic_t autogroup_seq_nr;
78091+static atomic_unchecked_t autogroup_seq_nr;
78092
78093 void __init autogroup_init(struct task_struct *init_task)
78094 {
78095@@ -81,7 +81,7 @@ static inline struct autogroup *autogroup_create(void)
78096
78097 kref_init(&ag->kref);
78098 init_rwsem(&ag->lock);
78099- ag->id = atomic_inc_return(&autogroup_seq_nr);
78100+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
78101 ag->tg = tg;
78102 #ifdef CONFIG_RT_GROUP_SCHED
78103 /*
78104diff --git a/kernel/sched/core.c b/kernel/sched/core.c
78105index 67d0465..4cf9361 100644
78106--- a/kernel/sched/core.c
78107+++ b/kernel/sched/core.c
78108@@ -3406,7 +3406,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
78109 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
78110 * positive (at least 1, or number of jiffies left till timeout) if completed.
78111 */
78112-long __sched
78113+long __sched __intentional_overflow(-1)
78114 wait_for_completion_interruptible_timeout(struct completion *x,
78115 unsigned long timeout)
78116 {
78117@@ -3423,7 +3423,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
78118 *
78119 * The return value is -ERESTARTSYS if interrupted, 0 if completed.
78120 */
78121-int __sched wait_for_completion_killable(struct completion *x)
78122+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
78123 {
78124 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
78125 if (t == -ERESTARTSYS)
78126@@ -3444,7 +3444,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
78127 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
78128 * positive (at least 1, or number of jiffies left till timeout) if completed.
78129 */
78130-long __sched
78131+long __sched __intentional_overflow(-1)
78132 wait_for_completion_killable_timeout(struct completion *x,
78133 unsigned long timeout)
78134 {
78135@@ -3670,6 +3670,8 @@ int can_nice(const struct task_struct *p, const int nice)
78136 /* convert nice value [19,-20] to rlimit style value [1,40] */
78137 int nice_rlim = 20 - nice;
78138
78139+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
78140+
78141 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
78142 capable(CAP_SYS_NICE));
78143 }
78144@@ -3703,7 +3705,8 @@ SYSCALL_DEFINE1(nice, int, increment)
78145 if (nice > 19)
78146 nice = 19;
78147
78148- if (increment < 0 && !can_nice(current, nice))
78149+ if (increment < 0 && (!can_nice(current, nice) ||
78150+ gr_handle_chroot_nice()))
78151 return -EPERM;
78152
78153 retval = security_task_setnice(current, nice);
78154@@ -3857,6 +3860,7 @@ recheck:
78155 unsigned long rlim_rtprio =
78156 task_rlimit(p, RLIMIT_RTPRIO);
78157
78158+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
78159 /* can't set/change the rt policy */
78160 if (policy != p->policy && !rlim_rtprio)
78161 return -EPERM;
78162@@ -4954,7 +4958,7 @@ static void migrate_tasks(unsigned int dead_cpu)
78163
78164 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
78165
78166-static struct ctl_table sd_ctl_dir[] = {
78167+static ctl_table_no_const sd_ctl_dir[] __read_only = {
78168 {
78169 .procname = "sched_domain",
78170 .mode = 0555,
78171@@ -4971,17 +4975,17 @@ static struct ctl_table sd_ctl_root[] = {
78172 {}
78173 };
78174
78175-static struct ctl_table *sd_alloc_ctl_entry(int n)
78176+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
78177 {
78178- struct ctl_table *entry =
78179+ ctl_table_no_const *entry =
78180 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
78181
78182 return entry;
78183 }
78184
78185-static void sd_free_ctl_entry(struct ctl_table **tablep)
78186+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
78187 {
78188- struct ctl_table *entry;
78189+ ctl_table_no_const *entry;
78190
78191 /*
78192 * In the intermediate directories, both the child directory and
78193@@ -4989,22 +4993,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
78194 * will always be set. In the lowest directory the names are
78195 * static strings and all have proc handlers.
78196 */
78197- for (entry = *tablep; entry->mode; entry++) {
78198- if (entry->child)
78199- sd_free_ctl_entry(&entry->child);
78200+ for (entry = tablep; entry->mode; entry++) {
78201+ if (entry->child) {
78202+ sd_free_ctl_entry(entry->child);
78203+ pax_open_kernel();
78204+ entry->child = NULL;
78205+ pax_close_kernel();
78206+ }
78207 if (entry->proc_handler == NULL)
78208 kfree(entry->procname);
78209 }
78210
78211- kfree(*tablep);
78212- *tablep = NULL;
78213+ kfree(tablep);
78214 }
78215
78216 static int min_load_idx = 0;
78217 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
78218
78219 static void
78220-set_table_entry(struct ctl_table *entry,
78221+set_table_entry(ctl_table_no_const *entry,
78222 const char *procname, void *data, int maxlen,
78223 umode_t mode, proc_handler *proc_handler,
78224 bool load_idx)
78225@@ -5024,7 +5031,7 @@ set_table_entry(struct ctl_table *entry,
78226 static struct ctl_table *
78227 sd_alloc_ctl_domain_table(struct sched_domain *sd)
78228 {
78229- struct ctl_table *table = sd_alloc_ctl_entry(13);
78230+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
78231
78232 if (table == NULL)
78233 return NULL;
78234@@ -5059,9 +5066,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
78235 return table;
78236 }
78237
78238-static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
78239+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
78240 {
78241- struct ctl_table *entry, *table;
78242+ ctl_table_no_const *entry, *table;
78243 struct sched_domain *sd;
78244 int domain_num = 0, i;
78245 char buf[32];
78246@@ -5088,11 +5095,13 @@ static struct ctl_table_header *sd_sysctl_header;
78247 static void register_sched_domain_sysctl(void)
78248 {
78249 int i, cpu_num = num_possible_cpus();
78250- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
78251+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
78252 char buf[32];
78253
78254 WARN_ON(sd_ctl_dir[0].child);
78255+ pax_open_kernel();
78256 sd_ctl_dir[0].child = entry;
78257+ pax_close_kernel();
78258
78259 if (entry == NULL)
78260 return;
78261@@ -5115,8 +5124,12 @@ static void unregister_sched_domain_sysctl(void)
78262 if (sd_sysctl_header)
78263 unregister_sysctl_table(sd_sysctl_header);
78264 sd_sysctl_header = NULL;
78265- if (sd_ctl_dir[0].child)
78266- sd_free_ctl_entry(&sd_ctl_dir[0].child);
78267+ if (sd_ctl_dir[0].child) {
78268+ sd_free_ctl_entry(sd_ctl_dir[0].child);
78269+ pax_open_kernel();
78270+ sd_ctl_dir[0].child = NULL;
78271+ pax_close_kernel();
78272+ }
78273 }
78274 #else
78275 static void register_sched_domain_sysctl(void)
78276@@ -5215,7 +5228,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
78277 * happens before everything else. This has to be lower priority than
78278 * the notifier in the perf_event subsystem, though.
78279 */
78280-static struct notifier_block __cpuinitdata migration_notifier = {
78281+static struct notifier_block migration_notifier = {
78282 .notifier_call = migration_call,
78283 .priority = CPU_PRI_MIGRATION,
78284 };
78285diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
78286index 7a33e59..2f7730c 100644
78287--- a/kernel/sched/fair.c
78288+++ b/kernel/sched/fair.c
78289@@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
78290
78291 static void reset_ptenuma_scan(struct task_struct *p)
78292 {
78293- ACCESS_ONCE(p->mm->numa_scan_seq)++;
78294+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
78295 p->mm->numa_scan_offset = 0;
78296 }
78297
78298@@ -5654,7 +5654,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
78299 * run_rebalance_domains is triggered when needed from the scheduler tick.
78300 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
78301 */
78302-static void run_rebalance_domains(struct softirq_action *h)
78303+static void run_rebalance_domains(void)
78304 {
78305 int this_cpu = smp_processor_id();
78306 struct rq *this_rq = cpu_rq(this_cpu);
78307diff --git a/kernel/signal.c b/kernel/signal.c
78308index 598dc06..471310a 100644
78309--- a/kernel/signal.c
78310+++ b/kernel/signal.c
78311@@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
78312
78313 int print_fatal_signals __read_mostly;
78314
78315-static void __user *sig_handler(struct task_struct *t, int sig)
78316+static __sighandler_t sig_handler(struct task_struct *t, int sig)
78317 {
78318 return t->sighand->action[sig - 1].sa.sa_handler;
78319 }
78320
78321-static int sig_handler_ignored(void __user *handler, int sig)
78322+static int sig_handler_ignored(__sighandler_t handler, int sig)
78323 {
78324 /* Is it explicitly or implicitly ignored? */
78325 return handler == SIG_IGN ||
78326@@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
78327
78328 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
78329 {
78330- void __user *handler;
78331+ __sighandler_t handler;
78332
78333 handler = sig_handler(t, sig);
78334
78335@@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
78336 atomic_inc(&user->sigpending);
78337 rcu_read_unlock();
78338
78339+ if (!override_rlimit)
78340+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
78341+
78342 if (override_rlimit ||
78343 atomic_read(&user->sigpending) <=
78344 task_rlimit(t, RLIMIT_SIGPENDING)) {
78345@@ -495,7 +498,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
78346
78347 int unhandled_signal(struct task_struct *tsk, int sig)
78348 {
78349- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
78350+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
78351 if (is_global_init(tsk))
78352 return 1;
78353 if (handler != SIG_IGN && handler != SIG_DFL)
78354@@ -815,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
78355 }
78356 }
78357
78358+ /* allow glibc communication via tgkill to other threads in our
78359+ thread group */
78360+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
78361+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
78362+ && gr_handle_signal(t, sig))
78363+ return -EPERM;
78364+
78365 return security_task_kill(t, info, sig, 0);
78366 }
78367
78368@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
78369 return send_signal(sig, info, p, 1);
78370 }
78371
78372-static int
78373+int
78374 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78375 {
78376 return send_signal(sig, info, t, 0);
78377@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78378 unsigned long int flags;
78379 int ret, blocked, ignored;
78380 struct k_sigaction *action;
78381+ int is_unhandled = 0;
78382
78383 spin_lock_irqsave(&t->sighand->siglock, flags);
78384 action = &t->sighand->action[sig-1];
78385@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78386 }
78387 if (action->sa.sa_handler == SIG_DFL)
78388 t->signal->flags &= ~SIGNAL_UNKILLABLE;
78389+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
78390+ is_unhandled = 1;
78391 ret = specific_send_sig_info(sig, info, t);
78392 spin_unlock_irqrestore(&t->sighand->siglock, flags);
78393
78394+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
78395+ normal operation */
78396+ if (is_unhandled) {
78397+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
78398+ gr_handle_crash(t, sig);
78399+ }
78400+
78401 return ret;
78402 }
78403
78404@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
78405 ret = check_kill_permission(sig, info, p);
78406 rcu_read_unlock();
78407
78408- if (!ret && sig)
78409+ if (!ret && sig) {
78410 ret = do_send_sig_info(sig, info, p, true);
78411+ if (!ret)
78412+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
78413+ }
78414
78415 return ret;
78416 }
78417@@ -2923,7 +2946,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
78418 int error = -ESRCH;
78419
78420 rcu_read_lock();
78421- p = find_task_by_vpid(pid);
78422+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
78423+ /* allow glibc communication via tgkill to other threads in our
78424+ thread group */
78425+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
78426+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
78427+ p = find_task_by_vpid_unrestricted(pid);
78428+ else
78429+#endif
78430+ p = find_task_by_vpid(pid);
78431 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
78432 error = check_kill_permission(sig, info, p);
78433 /*
78434@@ -3237,8 +3268,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
78435 }
78436 seg = get_fs();
78437 set_fs(KERNEL_DS);
78438- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
78439- (stack_t __force __user *) &uoss,
78440+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
78441+ (stack_t __force_user *) &uoss,
78442 compat_user_stack_pointer());
78443 set_fs(seg);
78444 if (ret >= 0 && uoss_ptr) {
78445diff --git a/kernel/smp.c b/kernel/smp.c
78446index 8e451f3..8322029 100644
78447--- a/kernel/smp.c
78448+++ b/kernel/smp.c
78449@@ -73,7 +73,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
78450 return NOTIFY_OK;
78451 }
78452
78453-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
78454+static struct notifier_block hotplug_cfd_notifier = {
78455 .notifier_call = hotplug_cfd,
78456 };
78457
78458diff --git a/kernel/smpboot.c b/kernel/smpboot.c
78459index 02fc5c9..e54c335 100644
78460--- a/kernel/smpboot.c
78461+++ b/kernel/smpboot.c
78462@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
78463 }
78464 smpboot_unpark_thread(plug_thread, cpu);
78465 }
78466- list_add(&plug_thread->list, &hotplug_threads);
78467+ pax_list_add(&plug_thread->list, &hotplug_threads);
78468 out:
78469 mutex_unlock(&smpboot_threads_lock);
78470 return ret;
78471@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
78472 {
78473 get_online_cpus();
78474 mutex_lock(&smpboot_threads_lock);
78475- list_del(&plug_thread->list);
78476+ pax_list_del(&plug_thread->list);
78477 smpboot_destroy_threads(plug_thread);
78478 mutex_unlock(&smpboot_threads_lock);
78479 put_online_cpus();
78480diff --git a/kernel/softirq.c b/kernel/softirq.c
78481index d93dcb1..1cd8a71 100644
78482--- a/kernel/softirq.c
78483+++ b/kernel/softirq.c
78484@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
78485 EXPORT_SYMBOL(irq_stat);
78486 #endif
78487
78488-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
78489+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
78490
78491 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
78492
78493-char *softirq_to_name[NR_SOFTIRQS] = {
78494+const char * const softirq_to_name[NR_SOFTIRQS] = {
78495 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
78496 "TASKLET", "SCHED", "HRTIMER", "RCU"
78497 };
78498@@ -250,7 +250,7 @@ restart:
78499 kstat_incr_softirqs_this_cpu(vec_nr);
78500
78501 trace_softirq_entry(vec_nr);
78502- h->action(h);
78503+ h->action();
78504 trace_softirq_exit(vec_nr);
78505 if (unlikely(prev_count != preempt_count())) {
78506 printk(KERN_ERR "huh, entered softirq %u %s %p"
78507@@ -396,7 +396,7 @@ void __raise_softirq_irqoff(unsigned int nr)
78508 or_softirq_pending(1UL << nr);
78509 }
78510
78511-void open_softirq(int nr, void (*action)(struct softirq_action *))
78512+void __init open_softirq(int nr, void (*action)(void))
78513 {
78514 softirq_vec[nr].action = action;
78515 }
78516@@ -452,7 +452,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
78517
78518 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
78519
78520-static void tasklet_action(struct softirq_action *a)
78521+static void tasklet_action(void)
78522 {
78523 struct tasklet_struct *list;
78524
78525@@ -487,7 +487,7 @@ static void tasklet_action(struct softirq_action *a)
78526 }
78527 }
78528
78529-static void tasklet_hi_action(struct softirq_action *a)
78530+static void tasklet_hi_action(void)
78531 {
78532 struct tasklet_struct *list;
78533
78534@@ -723,7 +723,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
78535 return NOTIFY_OK;
78536 }
78537
78538-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
78539+static struct notifier_block remote_softirq_cpu_notifier = {
78540 .notifier_call = remote_softirq_cpu_notify,
78541 };
78542
78543@@ -840,11 +840,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
78544 return NOTIFY_OK;
78545 }
78546
78547-static struct notifier_block __cpuinitdata cpu_nfb = {
78548+static struct notifier_block cpu_nfb = {
78549 .notifier_call = cpu_callback
78550 };
78551
78552-static struct smp_hotplug_thread softirq_threads = {
78553+static struct smp_hotplug_thread softirq_threads __read_only = {
78554 .store = &ksoftirqd,
78555 .thread_should_run = ksoftirqd_should_run,
78556 .thread_fn = run_ksoftirqd,
78557diff --git a/kernel/srcu.c b/kernel/srcu.c
78558index 01d5ccb..cdcbee6 100644
78559--- a/kernel/srcu.c
78560+++ b/kernel/srcu.c
78561@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
78562
78563 idx = ACCESS_ONCE(sp->completed) & 0x1;
78564 preempt_disable();
78565- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
78566+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
78567 smp_mb(); /* B */ /* Avoid leaking the critical section. */
78568- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
78569+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
78570 preempt_enable();
78571 return idx;
78572 }
78573diff --git a/kernel/sys.c b/kernel/sys.c
78574index 0da73cf..5c2af3c 100644
78575--- a/kernel/sys.c
78576+++ b/kernel/sys.c
78577@@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
78578 error = -EACCES;
78579 goto out;
78580 }
78581+
78582+ if (gr_handle_chroot_setpriority(p, niceval)) {
78583+ error = -EACCES;
78584+ goto out;
78585+ }
78586+
78587 no_nice = security_task_setnice(p, niceval);
78588 if (no_nice) {
78589 error = no_nice;
78590@@ -598,6 +604,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
78591 goto error;
78592 }
78593
78594+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
78595+ goto error;
78596+
78597 if (rgid != (gid_t) -1 ||
78598 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
78599 new->sgid = new->egid;
78600@@ -633,6 +642,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
78601 old = current_cred();
78602
78603 retval = -EPERM;
78604+
78605+ if (gr_check_group_change(kgid, kgid, kgid))
78606+ goto error;
78607+
78608 if (nsown_capable(CAP_SETGID))
78609 new->gid = new->egid = new->sgid = new->fsgid = kgid;
78610 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
78611@@ -650,7 +663,7 @@ error:
78612 /*
78613 * change the user struct in a credentials set to match the new UID
78614 */
78615-static int set_user(struct cred *new)
78616+int set_user(struct cred *new)
78617 {
78618 struct user_struct *new_user;
78619
78620@@ -730,6 +743,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
78621 goto error;
78622 }
78623
78624+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
78625+ goto error;
78626+
78627 if (!uid_eq(new->uid, old->uid)) {
78628 retval = set_user(new);
78629 if (retval < 0)
78630@@ -780,6 +796,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
78631 old = current_cred();
78632
78633 retval = -EPERM;
78634+
78635+ if (gr_check_crash_uid(kuid))
78636+ goto error;
78637+ if (gr_check_user_change(kuid, kuid, kuid))
78638+ goto error;
78639+
78640 if (nsown_capable(CAP_SETUID)) {
78641 new->suid = new->uid = kuid;
78642 if (!uid_eq(kuid, old->uid)) {
78643@@ -849,6 +871,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
78644 goto error;
78645 }
78646
78647+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
78648+ goto error;
78649+
78650 if (ruid != (uid_t) -1) {
78651 new->uid = kruid;
78652 if (!uid_eq(kruid, old->uid)) {
78653@@ -931,6 +956,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
78654 goto error;
78655 }
78656
78657+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
78658+ goto error;
78659+
78660 if (rgid != (gid_t) -1)
78661 new->gid = krgid;
78662 if (egid != (gid_t) -1)
78663@@ -992,12 +1020,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
78664 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
78665 nsown_capable(CAP_SETUID)) {
78666 if (!uid_eq(kuid, old->fsuid)) {
78667+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
78668+ goto error;
78669+
78670 new->fsuid = kuid;
78671 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
78672 goto change_okay;
78673 }
78674 }
78675
78676+error:
78677 abort_creds(new);
78678 return old_fsuid;
78679
78680@@ -1030,12 +1062,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
78681 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
78682 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
78683 nsown_capable(CAP_SETGID)) {
78684+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
78685+ goto error;
78686+
78687 if (!gid_eq(kgid, old->fsgid)) {
78688 new->fsgid = kgid;
78689 goto change_okay;
78690 }
78691 }
78692
78693+error:
78694 abort_creds(new);
78695 return old_fsgid;
78696
78697@@ -1343,19 +1379,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
78698 return -EFAULT;
78699
78700 down_read(&uts_sem);
78701- error = __copy_to_user(&name->sysname, &utsname()->sysname,
78702+ error = __copy_to_user(name->sysname, &utsname()->sysname,
78703 __OLD_UTS_LEN);
78704 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
78705- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
78706+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
78707 __OLD_UTS_LEN);
78708 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
78709- error |= __copy_to_user(&name->release, &utsname()->release,
78710+ error |= __copy_to_user(name->release, &utsname()->release,
78711 __OLD_UTS_LEN);
78712 error |= __put_user(0, name->release + __OLD_UTS_LEN);
78713- error |= __copy_to_user(&name->version, &utsname()->version,
78714+ error |= __copy_to_user(name->version, &utsname()->version,
78715 __OLD_UTS_LEN);
78716 error |= __put_user(0, name->version + __OLD_UTS_LEN);
78717- error |= __copy_to_user(&name->machine, &utsname()->machine,
78718+ error |= __copy_to_user(name->machine, &utsname()->machine,
78719 __OLD_UTS_LEN);
78720 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
78721 up_read(&uts_sem);
78722@@ -1557,6 +1593,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
78723 */
78724 new_rlim->rlim_cur = 1;
78725 }
78726+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
78727+ is changed to a lower value. Since tasks can be created by the same
78728+ user in between this limit change and an execve by this task, force
78729+ a recheck only for this task by setting PF_NPROC_EXCEEDED
78730+ */
78731+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
78732+ tsk->flags |= PF_NPROC_EXCEEDED;
78733 }
78734 if (!retval) {
78735 if (old_rlim)
78736diff --git a/kernel/sysctl.c b/kernel/sysctl.c
78737index afc1dc6..f6cf355 100644
78738--- a/kernel/sysctl.c
78739+++ b/kernel/sysctl.c
78740@@ -93,7 +93,6 @@
78741
78742
78743 #if defined(CONFIG_SYSCTL)
78744-
78745 /* External variables not in a header file. */
78746 extern int sysctl_overcommit_memory;
78747 extern int sysctl_overcommit_ratio;
78748@@ -120,18 +119,18 @@ extern int blk_iopoll_enabled;
78749
78750 /* Constants used for minimum and maximum */
78751 #ifdef CONFIG_LOCKUP_DETECTOR
78752-static int sixty = 60;
78753-static int neg_one = -1;
78754+static int sixty __read_only = 60;
78755 #endif
78756
78757-static int zero;
78758-static int __maybe_unused one = 1;
78759-static int __maybe_unused two = 2;
78760-static int __maybe_unused three = 3;
78761-static unsigned long one_ul = 1;
78762-static int one_hundred = 100;
78763+static int neg_one __read_only = -1;
78764+static int zero __read_only = 0;
78765+static int __maybe_unused one __read_only = 1;
78766+static int __maybe_unused two __read_only = 2;
78767+static int __maybe_unused three __read_only = 3;
78768+static unsigned long one_ul __read_only = 1;
78769+static int one_hundred __read_only = 100;
78770 #ifdef CONFIG_PRINTK
78771-static int ten_thousand = 10000;
78772+static int ten_thousand __read_only = 10000;
78773 #endif
78774
78775 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
78776@@ -178,10 +177,8 @@ static int proc_taint(struct ctl_table *table, int write,
78777 void __user *buffer, size_t *lenp, loff_t *ppos);
78778 #endif
78779
78780-#ifdef CONFIG_PRINTK
78781 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
78782 void __user *buffer, size_t *lenp, loff_t *ppos);
78783-#endif
78784
78785 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
78786 void __user *buffer, size_t *lenp, loff_t *ppos);
78787@@ -212,6 +209,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
78788
78789 #endif
78790
78791+extern struct ctl_table grsecurity_table[];
78792+
78793 static struct ctl_table kern_table[];
78794 static struct ctl_table vm_table[];
78795 static struct ctl_table fs_table[];
78796@@ -226,6 +225,20 @@ extern struct ctl_table epoll_table[];
78797 int sysctl_legacy_va_layout;
78798 #endif
78799
78800+#ifdef CONFIG_PAX_SOFTMODE
78801+static ctl_table pax_table[] = {
78802+ {
78803+ .procname = "softmode",
78804+ .data = &pax_softmode,
78805+ .maxlen = sizeof(unsigned int),
78806+ .mode = 0600,
78807+ .proc_handler = &proc_dointvec,
78808+ },
78809+
78810+ { }
78811+};
78812+#endif
78813+
78814 /* The default sysctl tables: */
78815
78816 static struct ctl_table sysctl_base_table[] = {
78817@@ -274,6 +287,22 @@ static int max_extfrag_threshold = 1000;
78818 #endif
78819
78820 static struct ctl_table kern_table[] = {
78821+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
78822+ {
78823+ .procname = "grsecurity",
78824+ .mode = 0500,
78825+ .child = grsecurity_table,
78826+ },
78827+#endif
78828+
78829+#ifdef CONFIG_PAX_SOFTMODE
78830+ {
78831+ .procname = "pax",
78832+ .mode = 0500,
78833+ .child = pax_table,
78834+ },
78835+#endif
78836+
78837 {
78838 .procname = "sched_child_runs_first",
78839 .data = &sysctl_sched_child_runs_first,
78840@@ -608,7 +637,7 @@ static struct ctl_table kern_table[] = {
78841 .data = &modprobe_path,
78842 .maxlen = KMOD_PATH_LEN,
78843 .mode = 0644,
78844- .proc_handler = proc_dostring,
78845+ .proc_handler = proc_dostring_modpriv,
78846 },
78847 {
78848 .procname = "modules_disabled",
78849@@ -775,16 +804,20 @@ static struct ctl_table kern_table[] = {
78850 .extra1 = &zero,
78851 .extra2 = &one,
78852 },
78853+#endif
78854 {
78855 .procname = "kptr_restrict",
78856 .data = &kptr_restrict,
78857 .maxlen = sizeof(int),
78858 .mode = 0644,
78859 .proc_handler = proc_dointvec_minmax_sysadmin,
78860+#ifdef CONFIG_GRKERNSEC_HIDESYM
78861+ .extra1 = &two,
78862+#else
78863 .extra1 = &zero,
78864+#endif
78865 .extra2 = &two,
78866 },
78867-#endif
78868 {
78869 .procname = "ngroups_max",
78870 .data = &ngroups_max,
78871@@ -1026,10 +1059,17 @@ static struct ctl_table kern_table[] = {
78872 */
78873 {
78874 .procname = "perf_event_paranoid",
78875- .data = &sysctl_perf_event_paranoid,
78876- .maxlen = sizeof(sysctl_perf_event_paranoid),
78877+ .data = &sysctl_perf_event_legitimately_concerned,
78878+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
78879 .mode = 0644,
78880- .proc_handler = proc_dointvec,
78881+ /* go ahead, be a hero */
78882+ .proc_handler = proc_dointvec_minmax_sysadmin,
78883+ .extra1 = &neg_one,
78884+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
78885+ .extra2 = &three,
78886+#else
78887+ .extra2 = &two,
78888+#endif
78889 },
78890 {
78891 .procname = "perf_event_mlock_kb",
78892@@ -1283,6 +1323,13 @@ static struct ctl_table vm_table[] = {
78893 .proc_handler = proc_dointvec_minmax,
78894 .extra1 = &zero,
78895 },
78896+ {
78897+ .procname = "heap_stack_gap",
78898+ .data = &sysctl_heap_stack_gap,
78899+ .maxlen = sizeof(sysctl_heap_stack_gap),
78900+ .mode = 0644,
78901+ .proc_handler = proc_doulongvec_minmax,
78902+ },
78903 #else
78904 {
78905 .procname = "nr_trim_pages",
78906@@ -1733,6 +1780,16 @@ int proc_dostring(struct ctl_table *table, int write,
78907 buffer, lenp, ppos);
78908 }
78909
78910+int proc_dostring_modpriv(struct ctl_table *table, int write,
78911+ void __user *buffer, size_t *lenp, loff_t *ppos)
78912+{
78913+ if (write && !capable(CAP_SYS_MODULE))
78914+ return -EPERM;
78915+
78916+ return _proc_do_string(table->data, table->maxlen, write,
78917+ buffer, lenp, ppos);
78918+}
78919+
78920 static size_t proc_skip_spaces(char **buf)
78921 {
78922 size_t ret;
78923@@ -1838,6 +1895,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
78924 len = strlen(tmp);
78925 if (len > *size)
78926 len = *size;
78927+ if (len > sizeof(tmp))
78928+ len = sizeof(tmp);
78929 if (copy_to_user(*buf, tmp, len))
78930 return -EFAULT;
78931 *size -= len;
78932@@ -2002,7 +2061,7 @@ int proc_dointvec(struct ctl_table *table, int write,
78933 static int proc_taint(struct ctl_table *table, int write,
78934 void __user *buffer, size_t *lenp, loff_t *ppos)
78935 {
78936- struct ctl_table t;
78937+ ctl_table_no_const t;
78938 unsigned long tmptaint = get_taint();
78939 int err;
78940
78941@@ -2030,7 +2089,6 @@ static int proc_taint(struct ctl_table *table, int write,
78942 return err;
78943 }
78944
78945-#ifdef CONFIG_PRINTK
78946 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
78947 void __user *buffer, size_t *lenp, loff_t *ppos)
78948 {
78949@@ -2039,7 +2097,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
78950
78951 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
78952 }
78953-#endif
78954
78955 struct do_proc_dointvec_minmax_conv_param {
78956 int *min;
78957@@ -2186,8 +2243,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
78958 *i = val;
78959 } else {
78960 val = convdiv * (*i) / convmul;
78961- if (!first)
78962+ if (!first) {
78963 err = proc_put_char(&buffer, &left, '\t');
78964+ if (err)
78965+ break;
78966+ }
78967 err = proc_put_long(&buffer, &left, val, false);
78968 if (err)
78969 break;
78970@@ -2579,6 +2639,12 @@ int proc_dostring(struct ctl_table *table, int write,
78971 return -ENOSYS;
78972 }
78973
78974+int proc_dostring_modpriv(struct ctl_table *table, int write,
78975+ void __user *buffer, size_t *lenp, loff_t *ppos)
78976+{
78977+ return -ENOSYS;
78978+}
78979+
78980 int proc_dointvec(struct ctl_table *table, int write,
78981 void __user *buffer, size_t *lenp, loff_t *ppos)
78982 {
78983@@ -2635,5 +2701,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
78984 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
78985 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
78986 EXPORT_SYMBOL(proc_dostring);
78987+EXPORT_SYMBOL(proc_dostring_modpriv);
78988 EXPORT_SYMBOL(proc_doulongvec_minmax);
78989 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
78990diff --git a/kernel/taskstats.c b/kernel/taskstats.c
78991index 145bb4d..b2aa969 100644
78992--- a/kernel/taskstats.c
78993+++ b/kernel/taskstats.c
78994@@ -28,9 +28,12 @@
78995 #include <linux/fs.h>
78996 #include <linux/file.h>
78997 #include <linux/pid_namespace.h>
78998+#include <linux/grsecurity.h>
78999 #include <net/genetlink.h>
79000 #include <linux/atomic.h>
79001
79002+extern int gr_is_taskstats_denied(int pid);
79003+
79004 /*
79005 * Maximum length of a cpumask that can be specified in
79006 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
79007@@ -570,6 +573,9 @@ err:
79008
79009 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
79010 {
79011+ if (gr_is_taskstats_denied(current->pid))
79012+ return -EACCES;
79013+
79014 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
79015 return cmd_attr_register_cpumask(info);
79016 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
79017diff --git a/kernel/time.c b/kernel/time.c
79018index f8342a4..288f13b 100644
79019--- a/kernel/time.c
79020+++ b/kernel/time.c
79021@@ -171,6 +171,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
79022 return error;
79023
79024 if (tz) {
79025+ /* we log in do_settimeofday called below, so don't log twice
79026+ */
79027+ if (!tv)
79028+ gr_log_timechange();
79029+
79030 sys_tz = *tz;
79031 update_vsyscall_tz();
79032 if (firsttime) {
79033@@ -501,7 +506,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
79034 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
79035 * value to a scaled second value.
79036 */
79037-unsigned long
79038+unsigned long __intentional_overflow(-1)
79039 timespec_to_jiffies(const struct timespec *value)
79040 {
79041 unsigned long sec = value->tv_sec;
79042diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
79043index f11d83b..d016d91 100644
79044--- a/kernel/time/alarmtimer.c
79045+++ b/kernel/time/alarmtimer.c
79046@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
79047 struct platform_device *pdev;
79048 int error = 0;
79049 int i;
79050- struct k_clock alarm_clock = {
79051+ static struct k_clock alarm_clock = {
79052 .clock_getres = alarm_clock_getres,
79053 .clock_get = alarm_clock_get,
79054 .timer_create = alarm_timer_create,
79055diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
79056index 90ad470..1814e9a 100644
79057--- a/kernel/time/tick-broadcast.c
79058+++ b/kernel/time/tick-broadcast.c
79059@@ -138,7 +138,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
79060 * then clear the broadcast bit.
79061 */
79062 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
79063- int cpu = smp_processor_id();
79064+ cpu = smp_processor_id();
79065 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
79066 tick_broadcast_clear_oneshot(cpu);
79067 } else {
79068diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
79069index 183df62..59b1442 100644
79070--- a/kernel/time/timekeeping.c
79071+++ b/kernel/time/timekeeping.c
79072@@ -15,6 +15,7 @@
79073 #include <linux/init.h>
79074 #include <linux/mm.h>
79075 #include <linux/sched.h>
79076+#include <linux/grsecurity.h>
79077 #include <linux/syscore_ops.h>
79078 #include <linux/clocksource.h>
79079 #include <linux/jiffies.h>
79080@@ -448,6 +449,8 @@ int do_settimeofday(const struct timespec *tv)
79081 if (!timespec_valid_strict(tv))
79082 return -EINVAL;
79083
79084+ gr_log_timechange();
79085+
79086 write_seqlock_irqsave(&tk->lock, flags);
79087
79088 timekeeping_forward_now(tk);
79089diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
79090index af5a7e9..715611a 100644
79091--- a/kernel/time/timer_list.c
79092+++ b/kernel/time/timer_list.c
79093@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
79094
79095 static void print_name_offset(struct seq_file *m, void *sym)
79096 {
79097+#ifdef CONFIG_GRKERNSEC_HIDESYM
79098+ SEQ_printf(m, "<%p>", NULL);
79099+#else
79100 char symname[KSYM_NAME_LEN];
79101
79102 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
79103 SEQ_printf(m, "<%pK>", sym);
79104 else
79105 SEQ_printf(m, "%s", symname);
79106+#endif
79107 }
79108
79109 static void
79110@@ -112,7 +116,11 @@ next_one:
79111 static void
79112 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
79113 {
79114+#ifdef CONFIG_GRKERNSEC_HIDESYM
79115+ SEQ_printf(m, " .base: %p\n", NULL);
79116+#else
79117 SEQ_printf(m, " .base: %pK\n", base);
79118+#endif
79119 SEQ_printf(m, " .index: %d\n",
79120 base->index);
79121 SEQ_printf(m, " .resolution: %Lu nsecs\n",
79122@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
79123 {
79124 struct proc_dir_entry *pe;
79125
79126+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79127+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
79128+#else
79129 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
79130+#endif
79131 if (!pe)
79132 return -ENOMEM;
79133 return 0;
79134diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
79135index 0b537f2..40d6c20 100644
79136--- a/kernel/time/timer_stats.c
79137+++ b/kernel/time/timer_stats.c
79138@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
79139 static unsigned long nr_entries;
79140 static struct entry entries[MAX_ENTRIES];
79141
79142-static atomic_t overflow_count;
79143+static atomic_unchecked_t overflow_count;
79144
79145 /*
79146 * The entries are in a hash-table, for fast lookup:
79147@@ -140,7 +140,7 @@ static void reset_entries(void)
79148 nr_entries = 0;
79149 memset(entries, 0, sizeof(entries));
79150 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
79151- atomic_set(&overflow_count, 0);
79152+ atomic_set_unchecked(&overflow_count, 0);
79153 }
79154
79155 static struct entry *alloc_entry(void)
79156@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
79157 if (likely(entry))
79158 entry->count++;
79159 else
79160- atomic_inc(&overflow_count);
79161+ atomic_inc_unchecked(&overflow_count);
79162
79163 out_unlock:
79164 raw_spin_unlock_irqrestore(lock, flags);
79165@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
79166
79167 static void print_name_offset(struct seq_file *m, unsigned long addr)
79168 {
79169+#ifdef CONFIG_GRKERNSEC_HIDESYM
79170+ seq_printf(m, "<%p>", NULL);
79171+#else
79172 char symname[KSYM_NAME_LEN];
79173
79174 if (lookup_symbol_name(addr, symname) < 0)
79175- seq_printf(m, "<%p>", (void *)addr);
79176+ seq_printf(m, "<%pK>", (void *)addr);
79177 else
79178 seq_printf(m, "%s", symname);
79179+#endif
79180 }
79181
79182 static int tstats_show(struct seq_file *m, void *v)
79183@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
79184
79185 seq_puts(m, "Timer Stats Version: v0.2\n");
79186 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
79187- if (atomic_read(&overflow_count))
79188+ if (atomic_read_unchecked(&overflow_count))
79189 seq_printf(m, "Overflow: %d entries\n",
79190- atomic_read(&overflow_count));
79191+ atomic_read_unchecked(&overflow_count));
79192
79193 for (i = 0; i < nr_entries; i++) {
79194 entry = entries + i;
79195@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
79196 {
79197 struct proc_dir_entry *pe;
79198
79199+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79200+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
79201+#else
79202 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
79203+#endif
79204 if (!pe)
79205 return -ENOMEM;
79206 return 0;
79207diff --git a/kernel/timer.c b/kernel/timer.c
79208index 1b399c8..90e1849 100644
79209--- a/kernel/timer.c
79210+++ b/kernel/timer.c
79211@@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
79212 /*
79213 * This function runs timers and the timer-tq in bottom half context.
79214 */
79215-static void run_timer_softirq(struct softirq_action *h)
79216+static void run_timer_softirq(void)
79217 {
79218 struct tvec_base *base = __this_cpu_read(tvec_bases);
79219
79220@@ -1481,7 +1481,7 @@ static void process_timeout(unsigned long __data)
79221 *
79222 * In all cases the return value is guaranteed to be non-negative.
79223 */
79224-signed long __sched schedule_timeout(signed long timeout)
79225+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
79226 {
79227 struct timer_list timer;
79228 unsigned long expire;
79229@@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
79230 return NOTIFY_OK;
79231 }
79232
79233-static struct notifier_block __cpuinitdata timers_nb = {
79234+static struct notifier_block timers_nb = {
79235 .notifier_call = timer_cpu_notify,
79236 };
79237
79238diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
79239index 5a0f781..1497f95 100644
79240--- a/kernel/trace/blktrace.c
79241+++ b/kernel/trace/blktrace.c
79242@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
79243 struct blk_trace *bt = filp->private_data;
79244 char buf[16];
79245
79246- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
79247+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
79248
79249 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
79250 }
79251@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
79252 return 1;
79253
79254 bt = buf->chan->private_data;
79255- atomic_inc(&bt->dropped);
79256+ atomic_inc_unchecked(&bt->dropped);
79257 return 0;
79258 }
79259
79260@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
79261
79262 bt->dir = dir;
79263 bt->dev = dev;
79264- atomic_set(&bt->dropped, 0);
79265+ atomic_set_unchecked(&bt->dropped, 0);
79266
79267 ret = -EIO;
79268 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
79269diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
79270index 0a0e2a6..943495e 100644
79271--- a/kernel/trace/ftrace.c
79272+++ b/kernel/trace/ftrace.c
79273@@ -1909,12 +1909,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
79274 if (unlikely(ftrace_disabled))
79275 return 0;
79276
79277+ ret = ftrace_arch_code_modify_prepare();
79278+ FTRACE_WARN_ON(ret);
79279+ if (ret)
79280+ return 0;
79281+
79282 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
79283+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
79284 if (ret) {
79285 ftrace_bug(ret, ip);
79286- return 0;
79287 }
79288- return 1;
79289+ return ret ? 0 : 1;
79290 }
79291
79292 /*
79293@@ -2986,7 +2991,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
79294
79295 int
79296 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
79297- void *data)
79298+ void *data)
79299 {
79300 struct ftrace_func_probe *entry;
79301 struct ftrace_page *pg;
79302@@ -3854,8 +3859,10 @@ static int ftrace_process_locs(struct module *mod,
79303 if (!count)
79304 return 0;
79305
79306+ pax_open_kernel();
79307 sort(start, count, sizeof(*start),
79308 ftrace_cmp_ips, ftrace_swap_ips);
79309+ pax_close_kernel();
79310
79311 start_pg = ftrace_allocate_pages(count);
79312 if (!start_pg)
79313@@ -4574,8 +4581,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
79314 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
79315
79316 static int ftrace_graph_active;
79317-static struct notifier_block ftrace_suspend_notifier;
79318-
79319 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
79320 {
79321 return 0;
79322@@ -4719,6 +4724,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
79323 return NOTIFY_DONE;
79324 }
79325
79326+static struct notifier_block ftrace_suspend_notifier = {
79327+ .notifier_call = ftrace_suspend_notifier_call
79328+};
79329+
79330 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
79331 trace_func_graph_ent_t entryfunc)
79332 {
79333@@ -4732,7 +4741,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
79334 goto out;
79335 }
79336
79337- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
79338 register_pm_notifier(&ftrace_suspend_notifier);
79339
79340 ftrace_graph_active++;
79341diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
79342index 6989df2..c2265cf 100644
79343--- a/kernel/trace/ring_buffer.c
79344+++ b/kernel/trace/ring_buffer.c
79345@@ -349,9 +349,9 @@ struct buffer_data_page {
79346 */
79347 struct buffer_page {
79348 struct list_head list; /* list of buffer pages */
79349- local_t write; /* index for next write */
79350+ local_unchecked_t write; /* index for next write */
79351 unsigned read; /* index for next read */
79352- local_t entries; /* entries on this page */
79353+ local_unchecked_t entries; /* entries on this page */
79354 unsigned long real_end; /* real end of data */
79355 struct buffer_data_page *page; /* Actual data page */
79356 };
79357@@ -464,8 +464,8 @@ struct ring_buffer_per_cpu {
79358 unsigned long last_overrun;
79359 local_t entries_bytes;
79360 local_t entries;
79361- local_t overrun;
79362- local_t commit_overrun;
79363+ local_unchecked_t overrun;
79364+ local_unchecked_t commit_overrun;
79365 local_t dropped_events;
79366 local_t committing;
79367 local_t commits;
79368@@ -864,8 +864,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
79369 *
79370 * We add a counter to the write field to denote this.
79371 */
79372- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
79373- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
79374+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
79375+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
79376
79377 /*
79378 * Just make sure we have seen our old_write and synchronize
79379@@ -893,8 +893,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
79380 * cmpxchg to only update if an interrupt did not already
79381 * do it for us. If the cmpxchg fails, we don't care.
79382 */
79383- (void)local_cmpxchg(&next_page->write, old_write, val);
79384- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
79385+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
79386+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
79387
79388 /*
79389 * No need to worry about races with clearing out the commit.
79390@@ -1253,12 +1253,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
79391
79392 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
79393 {
79394- return local_read(&bpage->entries) & RB_WRITE_MASK;
79395+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
79396 }
79397
79398 static inline unsigned long rb_page_write(struct buffer_page *bpage)
79399 {
79400- return local_read(&bpage->write) & RB_WRITE_MASK;
79401+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
79402 }
79403
79404 static int
79405@@ -1353,7 +1353,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
79406 * bytes consumed in ring buffer from here.
79407 * Increment overrun to account for the lost events.
79408 */
79409- local_add(page_entries, &cpu_buffer->overrun);
79410+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
79411 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
79412 }
79413
79414@@ -1909,7 +1909,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
79415 * it is our responsibility to update
79416 * the counters.
79417 */
79418- local_add(entries, &cpu_buffer->overrun);
79419+ local_add_unchecked(entries, &cpu_buffer->overrun);
79420 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
79421
79422 /*
79423@@ -2059,7 +2059,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
79424 if (tail == BUF_PAGE_SIZE)
79425 tail_page->real_end = 0;
79426
79427- local_sub(length, &tail_page->write);
79428+ local_sub_unchecked(length, &tail_page->write);
79429 return;
79430 }
79431
79432@@ -2094,7 +2094,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
79433 rb_event_set_padding(event);
79434
79435 /* Set the write back to the previous setting */
79436- local_sub(length, &tail_page->write);
79437+ local_sub_unchecked(length, &tail_page->write);
79438 return;
79439 }
79440
79441@@ -2106,7 +2106,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
79442
79443 /* Set write to end of buffer */
79444 length = (tail + length) - BUF_PAGE_SIZE;
79445- local_sub(length, &tail_page->write);
79446+ local_sub_unchecked(length, &tail_page->write);
79447 }
79448
79449 /*
79450@@ -2132,7 +2132,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
79451 * about it.
79452 */
79453 if (unlikely(next_page == commit_page)) {
79454- local_inc(&cpu_buffer->commit_overrun);
79455+ local_inc_unchecked(&cpu_buffer->commit_overrun);
79456 goto out_reset;
79457 }
79458
79459@@ -2188,7 +2188,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
79460 cpu_buffer->tail_page) &&
79461 (cpu_buffer->commit_page ==
79462 cpu_buffer->reader_page))) {
79463- local_inc(&cpu_buffer->commit_overrun);
79464+ local_inc_unchecked(&cpu_buffer->commit_overrun);
79465 goto out_reset;
79466 }
79467 }
79468@@ -2236,7 +2236,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
79469 length += RB_LEN_TIME_EXTEND;
79470
79471 tail_page = cpu_buffer->tail_page;
79472- write = local_add_return(length, &tail_page->write);
79473+ write = local_add_return_unchecked(length, &tail_page->write);
79474
79475 /* set write to only the index of the write */
79476 write &= RB_WRITE_MASK;
79477@@ -2253,7 +2253,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
79478 kmemcheck_annotate_bitfield(event, bitfield);
79479 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
79480
79481- local_inc(&tail_page->entries);
79482+ local_inc_unchecked(&tail_page->entries);
79483
79484 /*
79485 * If this is the first commit on the page, then update
79486@@ -2286,7 +2286,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
79487
79488 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
79489 unsigned long write_mask =
79490- local_read(&bpage->write) & ~RB_WRITE_MASK;
79491+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
79492 unsigned long event_length = rb_event_length(event);
79493 /*
79494 * This is on the tail page. It is possible that
79495@@ -2296,7 +2296,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
79496 */
79497 old_index += write_mask;
79498 new_index += write_mask;
79499- index = local_cmpxchg(&bpage->write, old_index, new_index);
79500+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
79501 if (index == old_index) {
79502 /* update counters */
79503 local_sub(event_length, &cpu_buffer->entries_bytes);
79504@@ -2670,7 +2670,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
79505
79506 /* Do the likely case first */
79507 if (likely(bpage->page == (void *)addr)) {
79508- local_dec(&bpage->entries);
79509+ local_dec_unchecked(&bpage->entries);
79510 return;
79511 }
79512
79513@@ -2682,7 +2682,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
79514 start = bpage;
79515 do {
79516 if (bpage->page == (void *)addr) {
79517- local_dec(&bpage->entries);
79518+ local_dec_unchecked(&bpage->entries);
79519 return;
79520 }
79521 rb_inc_page(cpu_buffer, &bpage);
79522@@ -2964,7 +2964,7 @@ static inline unsigned long
79523 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
79524 {
79525 return local_read(&cpu_buffer->entries) -
79526- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
79527+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
79528 }
79529
79530 /**
79531@@ -3053,7 +3053,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
79532 return 0;
79533
79534 cpu_buffer = buffer->buffers[cpu];
79535- ret = local_read(&cpu_buffer->overrun);
79536+ ret = local_read_unchecked(&cpu_buffer->overrun);
79537
79538 return ret;
79539 }
79540@@ -3076,7 +3076,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
79541 return 0;
79542
79543 cpu_buffer = buffer->buffers[cpu];
79544- ret = local_read(&cpu_buffer->commit_overrun);
79545+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
79546
79547 return ret;
79548 }
79549@@ -3161,7 +3161,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
79550 /* if you care about this being correct, lock the buffer */
79551 for_each_buffer_cpu(buffer, cpu) {
79552 cpu_buffer = buffer->buffers[cpu];
79553- overruns += local_read(&cpu_buffer->overrun);
79554+ overruns += local_read_unchecked(&cpu_buffer->overrun);
79555 }
79556
79557 return overruns;
79558@@ -3337,8 +3337,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
79559 /*
79560 * Reset the reader page to size zero.
79561 */
79562- local_set(&cpu_buffer->reader_page->write, 0);
79563- local_set(&cpu_buffer->reader_page->entries, 0);
79564+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
79565+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
79566 local_set(&cpu_buffer->reader_page->page->commit, 0);
79567 cpu_buffer->reader_page->real_end = 0;
79568
79569@@ -3372,7 +3372,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
79570 * want to compare with the last_overrun.
79571 */
79572 smp_mb();
79573- overwrite = local_read(&(cpu_buffer->overrun));
79574+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
79575
79576 /*
79577 * Here's the tricky part.
79578@@ -3942,8 +3942,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
79579
79580 cpu_buffer->head_page
79581 = list_entry(cpu_buffer->pages, struct buffer_page, list);
79582- local_set(&cpu_buffer->head_page->write, 0);
79583- local_set(&cpu_buffer->head_page->entries, 0);
79584+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
79585+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
79586 local_set(&cpu_buffer->head_page->page->commit, 0);
79587
79588 cpu_buffer->head_page->read = 0;
79589@@ -3953,14 +3953,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
79590
79591 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
79592 INIT_LIST_HEAD(&cpu_buffer->new_pages);
79593- local_set(&cpu_buffer->reader_page->write, 0);
79594- local_set(&cpu_buffer->reader_page->entries, 0);
79595+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
79596+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
79597 local_set(&cpu_buffer->reader_page->page->commit, 0);
79598 cpu_buffer->reader_page->read = 0;
79599
79600 local_set(&cpu_buffer->entries_bytes, 0);
79601- local_set(&cpu_buffer->overrun, 0);
79602- local_set(&cpu_buffer->commit_overrun, 0);
79603+ local_set_unchecked(&cpu_buffer->overrun, 0);
79604+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
79605 local_set(&cpu_buffer->dropped_events, 0);
79606 local_set(&cpu_buffer->entries, 0);
79607 local_set(&cpu_buffer->committing, 0);
79608@@ -4364,8 +4364,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
79609 rb_init_page(bpage);
79610 bpage = reader->page;
79611 reader->page = *data_page;
79612- local_set(&reader->write, 0);
79613- local_set(&reader->entries, 0);
79614+ local_set_unchecked(&reader->write, 0);
79615+ local_set_unchecked(&reader->entries, 0);
79616 reader->read = 0;
79617 *data_page = bpage;
79618
79619diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
79620index 3f28192..a29e8b0 100644
79621--- a/kernel/trace/trace.c
79622+++ b/kernel/trace/trace.c
79623@@ -2893,7 +2893,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
79624 return 0;
79625 }
79626
79627-int set_tracer_flag(unsigned int mask, int enabled)
79628+int set_tracer_flag(unsigned long mask, int enabled)
79629 {
79630 /* do nothing if flag is already set */
79631 if (!!(trace_flags & mask) == !!enabled)
79632@@ -4637,10 +4637,9 @@ static const struct file_operations tracing_dyn_info_fops = {
79633 };
79634 #endif
79635
79636-static struct dentry *d_tracer;
79637-
79638 struct dentry *tracing_init_dentry(void)
79639 {
79640+ static struct dentry *d_tracer;
79641 static int once;
79642
79643 if (d_tracer)
79644@@ -4660,10 +4659,9 @@ struct dentry *tracing_init_dentry(void)
79645 return d_tracer;
79646 }
79647
79648-static struct dentry *d_percpu;
79649-
79650 static struct dentry *tracing_dentry_percpu(void)
79651 {
79652+ static struct dentry *d_percpu;
79653 static int once;
79654 struct dentry *d_tracer;
79655
79656diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
79657index 2081971..09f861e 100644
79658--- a/kernel/trace/trace.h
79659+++ b/kernel/trace/trace.h
79660@@ -948,7 +948,7 @@ extern const char *__stop___trace_bprintk_fmt[];
79661 void trace_printk_init_buffers(void);
79662 void trace_printk_start_comm(void);
79663 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
79664-int set_tracer_flag(unsigned int mask, int enabled);
79665+int set_tracer_flag(unsigned long mask, int enabled);
79666
79667 #undef FTRACE_ENTRY
79668 #define FTRACE_ENTRY(call, struct_name, id, tstruct, print, filter) \
79669diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
79670index 57e9b28..eebe41c 100644
79671--- a/kernel/trace/trace_events.c
79672+++ b/kernel/trace/trace_events.c
79673@@ -1329,10 +1329,6 @@ static LIST_HEAD(ftrace_module_file_list);
79674 struct ftrace_module_file_ops {
79675 struct list_head list;
79676 struct module *mod;
79677- struct file_operations id;
79678- struct file_operations enable;
79679- struct file_operations format;
79680- struct file_operations filter;
79681 };
79682
79683 static struct ftrace_module_file_ops *
79684@@ -1353,17 +1349,12 @@ trace_create_file_ops(struct module *mod)
79685
79686 file_ops->mod = mod;
79687
79688- file_ops->id = ftrace_event_id_fops;
79689- file_ops->id.owner = mod;
79690-
79691- file_ops->enable = ftrace_enable_fops;
79692- file_ops->enable.owner = mod;
79693-
79694- file_ops->filter = ftrace_event_filter_fops;
79695- file_ops->filter.owner = mod;
79696-
79697- file_ops->format = ftrace_event_format_fops;
79698- file_ops->format.owner = mod;
79699+ pax_open_kernel();
79700+ mod->trace_id.owner = mod;
79701+ mod->trace_enable.owner = mod;
79702+ mod->trace_filter.owner = mod;
79703+ mod->trace_format.owner = mod;
79704+ pax_close_kernel();
79705
79706 list_add(&file_ops->list, &ftrace_module_file_list);
79707
79708@@ -1387,8 +1378,8 @@ static void trace_module_add_events(struct module *mod)
79709
79710 for_each_event(call, start, end) {
79711 __trace_add_event_call(*call, mod,
79712- &file_ops->id, &file_ops->enable,
79713- &file_ops->filter, &file_ops->format);
79714+ &mod->trace_id, &mod->trace_enable,
79715+ &mod->trace_filter, &mod->trace_format);
79716 }
79717 }
79718
79719diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
79720index fd3c8aa..5f324a6 100644
79721--- a/kernel/trace/trace_mmiotrace.c
79722+++ b/kernel/trace/trace_mmiotrace.c
79723@@ -24,7 +24,7 @@ struct header_iter {
79724 static struct trace_array *mmio_trace_array;
79725 static bool overrun_detected;
79726 static unsigned long prev_overruns;
79727-static atomic_t dropped_count;
79728+static atomic_unchecked_t dropped_count;
79729
79730 static void mmio_reset_data(struct trace_array *tr)
79731 {
79732@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
79733
79734 static unsigned long count_overruns(struct trace_iterator *iter)
79735 {
79736- unsigned long cnt = atomic_xchg(&dropped_count, 0);
79737+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
79738 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
79739
79740 if (over > prev_overruns)
79741@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
79742 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
79743 sizeof(*entry), 0, pc);
79744 if (!event) {
79745- atomic_inc(&dropped_count);
79746+ atomic_inc_unchecked(&dropped_count);
79747 return;
79748 }
79749 entry = ring_buffer_event_data(event);
79750@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
79751 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
79752 sizeof(*entry), 0, pc);
79753 if (!event) {
79754- atomic_inc(&dropped_count);
79755+ atomic_inc_unchecked(&dropped_count);
79756 return;
79757 }
79758 entry = ring_buffer_event_data(event);
79759diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
79760index 697e88d..1a79993 100644
79761--- a/kernel/trace/trace_output.c
79762+++ b/kernel/trace/trace_output.c
79763@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
79764
79765 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
79766 if (!IS_ERR(p)) {
79767- p = mangle_path(s->buffer + s->len, p, "\n");
79768+ p = mangle_path(s->buffer + s->len, p, "\n\\");
79769 if (p) {
79770 s->len = p - s->buffer;
79771 return 1;
79772@@ -851,14 +851,16 @@ int register_ftrace_event(struct trace_event *event)
79773 goto out;
79774 }
79775
79776+ pax_open_kernel();
79777 if (event->funcs->trace == NULL)
79778- event->funcs->trace = trace_nop_print;
79779+ *(void **)&event->funcs->trace = trace_nop_print;
79780 if (event->funcs->raw == NULL)
79781- event->funcs->raw = trace_nop_print;
79782+ *(void **)&event->funcs->raw = trace_nop_print;
79783 if (event->funcs->hex == NULL)
79784- event->funcs->hex = trace_nop_print;
79785+ *(void **)&event->funcs->hex = trace_nop_print;
79786 if (event->funcs->binary == NULL)
79787- event->funcs->binary = trace_nop_print;
79788+ *(void **)&event->funcs->binary = trace_nop_print;
79789+ pax_close_kernel();
79790
79791 key = event->type & (EVENT_HASHSIZE - 1);
79792
79793diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
79794index b20428c..4845a10 100644
79795--- a/kernel/trace/trace_stack.c
79796+++ b/kernel/trace/trace_stack.c
79797@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
79798 return;
79799
79800 /* we do not handle interrupt stacks yet */
79801- if (!object_is_on_stack(stack))
79802+ if (!object_starts_on_stack(stack))
79803 return;
79804
79805 local_irq_save(flags);
79806diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
79807index e134d8f..a018cdd 100644
79808--- a/kernel/user_namespace.c
79809+++ b/kernel/user_namespace.c
79810@@ -853,7 +853,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
79811 if (atomic_read(&current->mm->mm_users) > 1)
79812 return -EINVAL;
79813
79814- if (current->fs->users != 1)
79815+ if (atomic_read(&current->fs->users) != 1)
79816 return -EINVAL;
79817
79818 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
79819diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
79820index 4f69f9a..7c6f8f8 100644
79821--- a/kernel/utsname_sysctl.c
79822+++ b/kernel/utsname_sysctl.c
79823@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
79824 static int proc_do_uts_string(ctl_table *table, int write,
79825 void __user *buffer, size_t *lenp, loff_t *ppos)
79826 {
79827- struct ctl_table uts_table;
79828+ ctl_table_no_const uts_table;
79829 int r;
79830 memcpy(&uts_table, table, sizeof(uts_table));
79831 uts_table.data = get_uts(table, write);
79832diff --git a/kernel/watchdog.c b/kernel/watchdog.c
79833index 4a94467..80a6f9c 100644
79834--- a/kernel/watchdog.c
79835+++ b/kernel/watchdog.c
79836@@ -526,7 +526,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
79837 }
79838 #endif /* CONFIG_SYSCTL */
79839
79840-static struct smp_hotplug_thread watchdog_threads = {
79841+static struct smp_hotplug_thread watchdog_threads __read_only = {
79842 .store = &softlockup_watchdog,
79843 .thread_should_run = watchdog_should_run,
79844 .thread_fn = watchdog,
79845diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
79846index 28be08c..47bab92 100644
79847--- a/lib/Kconfig.debug
79848+++ b/lib/Kconfig.debug
79849@@ -549,7 +549,7 @@ config DEBUG_MUTEXES
79850
79851 config DEBUG_LOCK_ALLOC
79852 bool "Lock debugging: detect incorrect freeing of live locks"
79853- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
79854+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
79855 select DEBUG_SPINLOCK
79856 select DEBUG_MUTEXES
79857 select LOCKDEP
79858@@ -563,7 +563,7 @@ config DEBUG_LOCK_ALLOC
79859
79860 config PROVE_LOCKING
79861 bool "Lock debugging: prove locking correctness"
79862- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
79863+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
79864 select LOCKDEP
79865 select DEBUG_SPINLOCK
79866 select DEBUG_MUTEXES
79867@@ -614,7 +614,7 @@ config LOCKDEP
79868
79869 config LOCK_STAT
79870 bool "Lock usage statistics"
79871- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
79872+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
79873 select LOCKDEP
79874 select DEBUG_SPINLOCK
79875 select DEBUG_MUTEXES
79876@@ -1282,6 +1282,7 @@ config LATENCYTOP
79877 depends on DEBUG_KERNEL
79878 depends on STACKTRACE_SUPPORT
79879 depends on PROC_FS
79880+ depends on !GRKERNSEC_HIDESYM
79881 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
79882 select KALLSYMS
79883 select KALLSYMS_ALL
79884@@ -1310,7 +1311,7 @@ config INTERVAL_TREE_TEST
79885
79886 config PROVIDE_OHCI1394_DMA_INIT
79887 bool "Remote debugging over FireWire early on boot"
79888- depends on PCI && X86
79889+ depends on PCI && X86 && !GRKERNSEC
79890 help
79891 If you want to debug problems which hang or crash the kernel early
79892 on boot and the crashing machine has a FireWire port, you can use
79893@@ -1339,7 +1340,7 @@ config PROVIDE_OHCI1394_DMA_INIT
79894
79895 config FIREWIRE_OHCI_REMOTE_DMA
79896 bool "Remote debugging over FireWire with firewire-ohci"
79897- depends on FIREWIRE_OHCI
79898+ depends on FIREWIRE_OHCI && !GRKERNSEC
79899 help
79900 This option lets you use the FireWire bus for remote debugging
79901 with help of the firewire-ohci driver. It enables unfiltered
79902diff --git a/lib/Makefile b/lib/Makefile
79903index 6e2cc56..9b13738 100644
79904--- a/lib/Makefile
79905+++ b/lib/Makefile
79906@@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
79907
79908 obj-$(CONFIG_BTREE) += btree.o
79909 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
79910-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
79911+obj-y += list_debug.o
79912 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
79913
79914 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
79915diff --git a/lib/bitmap.c b/lib/bitmap.c
79916index 06f7e4f..f3cf2b0 100644
79917--- a/lib/bitmap.c
79918+++ b/lib/bitmap.c
79919@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
79920 {
79921 int c, old_c, totaldigits, ndigits, nchunks, nbits;
79922 u32 chunk;
79923- const char __user __force *ubuf = (const char __user __force *)buf;
79924+ const char __user *ubuf = (const char __force_user *)buf;
79925
79926 bitmap_zero(maskp, nmaskbits);
79927
79928@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
79929 {
79930 if (!access_ok(VERIFY_READ, ubuf, ulen))
79931 return -EFAULT;
79932- return __bitmap_parse((const char __force *)ubuf,
79933+ return __bitmap_parse((const char __force_kernel *)ubuf,
79934 ulen, 1, maskp, nmaskbits);
79935
79936 }
79937@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
79938 {
79939 unsigned a, b;
79940 int c, old_c, totaldigits;
79941- const char __user __force *ubuf = (const char __user __force *)buf;
79942+ const char __user *ubuf = (const char __force_user *)buf;
79943 int exp_digit, in_range;
79944
79945 totaldigits = c = 0;
79946@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
79947 {
79948 if (!access_ok(VERIFY_READ, ubuf, ulen))
79949 return -EFAULT;
79950- return __bitmap_parselist((const char __force *)ubuf,
79951+ return __bitmap_parselist((const char __force_kernel *)ubuf,
79952 ulen, 1, maskp, nmaskbits);
79953 }
79954 EXPORT_SYMBOL(bitmap_parselist_user);
79955diff --git a/lib/bug.c b/lib/bug.c
79956index 1686034..a9c00c8 100644
79957--- a/lib/bug.c
79958+++ b/lib/bug.c
79959@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
79960 return BUG_TRAP_TYPE_NONE;
79961
79962 bug = find_bug(bugaddr);
79963+ if (!bug)
79964+ return BUG_TRAP_TYPE_NONE;
79965
79966 file = NULL;
79967 line = 0;
79968diff --git a/lib/debugobjects.c b/lib/debugobjects.c
79969index 37061ed..da83f48 100644
79970--- a/lib/debugobjects.c
79971+++ b/lib/debugobjects.c
79972@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
79973 if (limit > 4)
79974 return;
79975
79976- is_on_stack = object_is_on_stack(addr);
79977+ is_on_stack = object_starts_on_stack(addr);
79978 if (is_on_stack == onstack)
79979 return;
79980
79981diff --git a/lib/devres.c b/lib/devres.c
79982index 8235331..5881053 100644
79983--- a/lib/devres.c
79984+++ b/lib/devres.c
79985@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
79986 void devm_iounmap(struct device *dev, void __iomem *addr)
79987 {
79988 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
79989- (void *)addr));
79990+ (void __force *)addr));
79991 iounmap(addr);
79992 }
79993 EXPORT_SYMBOL(devm_iounmap);
79994@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
79995 {
79996 ioport_unmap(addr);
79997 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
79998- devm_ioport_map_match, (void *)addr));
79999+ devm_ioport_map_match, (void __force *)addr));
80000 }
80001 EXPORT_SYMBOL(devm_ioport_unmap);
80002 #endif /* CONFIG_HAS_IOPORT */
80003diff --git a/lib/div64.c b/lib/div64.c
80004index a163b6c..9618fa5 100644
80005--- a/lib/div64.c
80006+++ b/lib/div64.c
80007@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
80008 EXPORT_SYMBOL(__div64_32);
80009
80010 #ifndef div_s64_rem
80011-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
80012+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
80013 {
80014 u64 quotient;
80015
80016@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
80017 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
80018 */
80019 #ifndef div64_u64
80020-u64 div64_u64(u64 dividend, u64 divisor)
80021+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80022 {
80023 u32 high = divisor >> 32;
80024 u64 quot;
80025diff --git a/lib/dma-debug.c b/lib/dma-debug.c
80026index d87a17a..ac0d79a 100644
80027--- a/lib/dma-debug.c
80028+++ b/lib/dma-debug.c
80029@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
80030
80031 void dma_debug_add_bus(struct bus_type *bus)
80032 {
80033- struct notifier_block *nb;
80034+ notifier_block_no_const *nb;
80035
80036 if (global_disable)
80037 return;
80038@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
80039
80040 static void check_for_stack(struct device *dev, void *addr)
80041 {
80042- if (object_is_on_stack(addr))
80043+ if (object_starts_on_stack(addr))
80044 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
80045 "stack [addr=%p]\n", addr);
80046 }
80047diff --git a/lib/inflate.c b/lib/inflate.c
80048index 013a761..c28f3fc 100644
80049--- a/lib/inflate.c
80050+++ b/lib/inflate.c
80051@@ -269,7 +269,7 @@ static void free(void *where)
80052 malloc_ptr = free_mem_ptr;
80053 }
80054 #else
80055-#define malloc(a) kmalloc(a, GFP_KERNEL)
80056+#define malloc(a) kmalloc((a), GFP_KERNEL)
80057 #define free(a) kfree(a)
80058 #endif
80059
80060diff --git a/lib/ioremap.c b/lib/ioremap.c
80061index 0c9216c..863bd89 100644
80062--- a/lib/ioremap.c
80063+++ b/lib/ioremap.c
80064@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
80065 unsigned long next;
80066
80067 phys_addr -= addr;
80068- pmd = pmd_alloc(&init_mm, pud, addr);
80069+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
80070 if (!pmd)
80071 return -ENOMEM;
80072 do {
80073@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
80074 unsigned long next;
80075
80076 phys_addr -= addr;
80077- pud = pud_alloc(&init_mm, pgd, addr);
80078+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
80079 if (!pud)
80080 return -ENOMEM;
80081 do {
80082diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
80083index bd2bea9..6b3c95e 100644
80084--- a/lib/is_single_threaded.c
80085+++ b/lib/is_single_threaded.c
80086@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
80087 struct task_struct *p, *t;
80088 bool ret;
80089
80090+ if (!mm)
80091+ return true;
80092+
80093 if (atomic_read(&task->signal->live) != 1)
80094 return false;
80095
80096diff --git a/lib/kobject.c b/lib/kobject.c
80097index a654866..a4fd13d 100644
80098--- a/lib/kobject.c
80099+++ b/lib/kobject.c
80100@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
80101
80102
80103 static DEFINE_SPINLOCK(kobj_ns_type_lock);
80104-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
80105+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
80106
80107-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
80108+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
80109 {
80110 enum kobj_ns_type type = ops->type;
80111 int error;
80112diff --git a/lib/list_debug.c b/lib/list_debug.c
80113index c24c2f7..06e070b 100644
80114--- a/lib/list_debug.c
80115+++ b/lib/list_debug.c
80116@@ -11,7 +11,9 @@
80117 #include <linux/bug.h>
80118 #include <linux/kernel.h>
80119 #include <linux/rculist.h>
80120+#include <linux/mm.h>
80121
80122+#ifdef CONFIG_DEBUG_LIST
80123 /*
80124 * Insert a new entry between two known consecutive entries.
80125 *
80126@@ -19,21 +21,32 @@
80127 * the prev/next entries already!
80128 */
80129
80130-void __list_add(struct list_head *new,
80131- struct list_head *prev,
80132- struct list_head *next)
80133+static bool __list_add_debug(struct list_head *new,
80134+ struct list_head *prev,
80135+ struct list_head *next)
80136 {
80137- WARN(next->prev != prev,
80138+ if (WARN(next->prev != prev,
80139 "list_add corruption. next->prev should be "
80140 "prev (%p), but was %p. (next=%p).\n",
80141- prev, next->prev, next);
80142- WARN(prev->next != next,
80143+ prev, next->prev, next) ||
80144+ WARN(prev->next != next,
80145 "list_add corruption. prev->next should be "
80146 "next (%p), but was %p. (prev=%p).\n",
80147- next, prev->next, prev);
80148- WARN(new == prev || new == next,
80149- "list_add double add: new=%p, prev=%p, next=%p.\n",
80150- new, prev, next);
80151+ next, prev->next, prev) ||
80152+ WARN(new == prev || new == next,
80153+ "list_add double add: new=%p, prev=%p, next=%p.\n",
80154+ new, prev, next))
80155+ return false;
80156+ return true;
80157+}
80158+
80159+void __list_add(struct list_head *new,
80160+ struct list_head *prev,
80161+ struct list_head *next)
80162+{
80163+ if (!__list_add_debug(new, prev, next))
80164+ return;
80165+
80166 next->prev = new;
80167 new->next = next;
80168 new->prev = prev;
80169@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
80170 }
80171 EXPORT_SYMBOL(__list_add);
80172
80173-void __list_del_entry(struct list_head *entry)
80174+static bool __list_del_entry_debug(struct list_head *entry)
80175 {
80176 struct list_head *prev, *next;
80177
80178@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
80179 WARN(next->prev != entry,
80180 "list_del corruption. next->prev should be %p, "
80181 "but was %p\n", entry, next->prev))
80182+ return false;
80183+ return true;
80184+}
80185+
80186+void __list_del_entry(struct list_head *entry)
80187+{
80188+ if (!__list_del_entry_debug(entry))
80189 return;
80190
80191- __list_del(prev, next);
80192+ __list_del(entry->prev, entry->next);
80193 }
80194 EXPORT_SYMBOL(__list_del_entry);
80195
80196@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
80197 void __list_add_rcu(struct list_head *new,
80198 struct list_head *prev, struct list_head *next)
80199 {
80200- WARN(next->prev != prev,
80201- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
80202- prev, next->prev, next);
80203- WARN(prev->next != next,
80204- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
80205- next, prev->next, prev);
80206+ if (!__list_add_debug(new, prev, next))
80207+ return;
80208+
80209 new->next = next;
80210 new->prev = prev;
80211 rcu_assign_pointer(list_next_rcu(prev), new);
80212 next->prev = new;
80213 }
80214 EXPORT_SYMBOL(__list_add_rcu);
80215+#endif
80216+
80217+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
80218+{
80219+#ifdef CONFIG_DEBUG_LIST
80220+ if (!__list_add_debug(new, prev, next))
80221+ return;
80222+#endif
80223+
80224+ pax_open_kernel();
80225+ next->prev = new;
80226+ new->next = next;
80227+ new->prev = prev;
80228+ prev->next = new;
80229+ pax_close_kernel();
80230+}
80231+EXPORT_SYMBOL(__pax_list_add);
80232+
80233+void pax_list_del(struct list_head *entry)
80234+{
80235+#ifdef CONFIG_DEBUG_LIST
80236+ if (!__list_del_entry_debug(entry))
80237+ return;
80238+#endif
80239+
80240+ pax_open_kernel();
80241+ __list_del(entry->prev, entry->next);
80242+ entry->next = LIST_POISON1;
80243+ entry->prev = LIST_POISON2;
80244+ pax_close_kernel();
80245+}
80246+EXPORT_SYMBOL(pax_list_del);
80247+
80248+void pax_list_del_init(struct list_head *entry)
80249+{
80250+ pax_open_kernel();
80251+ __list_del(entry->prev, entry->next);
80252+ INIT_LIST_HEAD(entry);
80253+ pax_close_kernel();
80254+}
80255+EXPORT_SYMBOL(pax_list_del_init);
80256+
80257+void __pax_list_add_rcu(struct list_head *new,
80258+ struct list_head *prev, struct list_head *next)
80259+{
80260+#ifdef CONFIG_DEBUG_LIST
80261+ if (!__list_add_debug(new, prev, next))
80262+ return;
80263+#endif
80264+
80265+ pax_open_kernel();
80266+ new->next = next;
80267+ new->prev = prev;
80268+ rcu_assign_pointer(list_next_rcu(prev), new);
80269+ next->prev = new;
80270+ pax_close_kernel();
80271+}
80272+EXPORT_SYMBOL(__pax_list_add_rcu);
80273+
80274+void pax_list_del_rcu(struct list_head *entry)
80275+{
80276+#ifdef CONFIG_DEBUG_LIST
80277+ if (!__list_del_entry_debug(entry))
80278+ return;
80279+#endif
80280+
80281+ pax_open_kernel();
80282+ __list_del(entry->prev, entry->next);
80283+ entry->next = LIST_POISON1;
80284+ entry->prev = LIST_POISON2;
80285+ pax_close_kernel();
80286+}
80287+EXPORT_SYMBOL(pax_list_del_rcu);
80288diff --git a/lib/radix-tree.c b/lib/radix-tree.c
80289index e796429..6e38f9f 100644
80290--- a/lib/radix-tree.c
80291+++ b/lib/radix-tree.c
80292@@ -92,7 +92,7 @@ struct radix_tree_preload {
80293 int nr;
80294 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
80295 };
80296-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
80297+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
80298
80299 static inline void *ptr_to_indirect(void *ptr)
80300 {
80301diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
80302index bb2b201..46abaf9 100644
80303--- a/lib/strncpy_from_user.c
80304+++ b/lib/strncpy_from_user.c
80305@@ -21,7 +21,7 @@
80306 */
80307 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
80308 {
80309- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80310+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80311 long res = 0;
80312
80313 /*
80314diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
80315index a28df52..3d55877 100644
80316--- a/lib/strnlen_user.c
80317+++ b/lib/strnlen_user.c
80318@@ -26,7 +26,7 @@
80319 */
80320 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
80321 {
80322- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80323+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80324 long align, res = 0;
80325 unsigned long c;
80326
80327diff --git a/lib/swiotlb.c b/lib/swiotlb.c
80328index d23762e..e21eab2 100644
80329--- a/lib/swiotlb.c
80330+++ b/lib/swiotlb.c
80331@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
80332
80333 void
80334 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
80335- dma_addr_t dev_addr)
80336+ dma_addr_t dev_addr, struct dma_attrs *attrs)
80337 {
80338 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
80339
80340diff --git a/lib/vsprintf.c b/lib/vsprintf.c
80341index 0d62fd7..b7bc911 100644
80342--- a/lib/vsprintf.c
80343+++ b/lib/vsprintf.c
80344@@ -16,6 +16,9 @@
80345 * - scnprintf and vscnprintf
80346 */
80347
80348+#ifdef CONFIG_GRKERNSEC_HIDESYM
80349+#define __INCLUDED_BY_HIDESYM 1
80350+#endif
80351 #include <stdarg.h>
80352 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
80353 #include <linux/types.h>
80354@@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
80355 return number(buf, end, *(const netdev_features_t *)addr, spec);
80356 }
80357
80358+#ifdef CONFIG_GRKERNSEC_HIDESYM
80359+int kptr_restrict __read_mostly = 2;
80360+#else
80361 int kptr_restrict __read_mostly;
80362+#endif
80363
80364 /*
80365 * Show a '%p' thing. A kernel extension is that the '%p' is followed
80366@@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
80367 * - 'S' For symbolic direct pointers with offset
80368 * - 's' For symbolic direct pointers without offset
80369 * - 'B' For backtraced symbolic direct pointers with offset
80370+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
80371+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
80372 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
80373 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
80374 * - 'M' For a 6-byte MAC address, it prints the address in the
80375@@ -1044,12 +1053,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80376
80377 if (!ptr && *fmt != 'K') {
80378 /*
80379- * Print (null) with the same width as a pointer so it makes
80380+ * Print (nil) with the same width as a pointer so it makes
80381 * tabular output look nice.
80382 */
80383 if (spec.field_width == -1)
80384 spec.field_width = default_width;
80385- return string(buf, end, "(null)", spec);
80386+ return string(buf, end, "(nil)", spec);
80387 }
80388
80389 switch (*fmt) {
80390@@ -1059,6 +1068,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80391 /* Fallthrough */
80392 case 'S':
80393 case 's':
80394+#ifdef CONFIG_GRKERNSEC_HIDESYM
80395+ break;
80396+#else
80397+ return symbol_string(buf, end, ptr, spec, *fmt);
80398+#endif
80399+ case 'A':
80400 case 'B':
80401 return symbol_string(buf, end, ptr, spec, *fmt);
80402 case 'R':
80403@@ -1099,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80404 va_end(va);
80405 return buf;
80406 }
80407+ case 'P':
80408+ break;
80409 case 'K':
80410 /*
80411 * %pK cannot be used in IRQ context because its test
80412@@ -1128,6 +1145,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80413 return number(buf, end,
80414 (unsigned long long) *((phys_addr_t *)ptr), spec);
80415 }
80416+
80417+#ifdef CONFIG_GRKERNSEC_HIDESYM
80418+ /* 'P' = approved pointers to copy to userland,
80419+ as in the /proc/kallsyms case, as we make it display nothing
80420+ for non-root users, and the real contents for root users
80421+ Also ignore 'K' pointers, since we force their NULLing for non-root users
80422+ above
80423+ */
80424+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
80425+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
80426+ dump_stack();
80427+ ptr = NULL;
80428+ }
80429+#endif
80430+
80431 spec.flags |= SMALL;
80432 if (spec.field_width == -1) {
80433 spec.field_width = default_width;
80434@@ -1849,11 +1881,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
80435 typeof(type) value; \
80436 if (sizeof(type) == 8) { \
80437 args = PTR_ALIGN(args, sizeof(u32)); \
80438- *(u32 *)&value = *(u32 *)args; \
80439- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
80440+ *(u32 *)&value = *(const u32 *)args; \
80441+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
80442 } else { \
80443 args = PTR_ALIGN(args, sizeof(type)); \
80444- value = *(typeof(type) *)args; \
80445+ value = *(const typeof(type) *)args; \
80446 } \
80447 args += sizeof(type); \
80448 value; \
80449@@ -1916,7 +1948,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
80450 case FORMAT_TYPE_STR: {
80451 const char *str_arg = args;
80452 args += strlen(str_arg) + 1;
80453- str = string(str, end, (char *)str_arg, spec);
80454+ str = string(str, end, str_arg, spec);
80455 break;
80456 }
80457
80458diff --git a/localversion-grsec b/localversion-grsec
80459new file mode 100644
80460index 0000000..7cd6065
80461--- /dev/null
80462+++ b/localversion-grsec
80463@@ -0,0 +1 @@
80464+-grsec
80465diff --git a/mm/Kconfig b/mm/Kconfig
80466index 3bea74f..e821c99 100644
80467--- a/mm/Kconfig
80468+++ b/mm/Kconfig
80469@@ -311,10 +311,10 @@ config KSM
80470 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
80471
80472 config DEFAULT_MMAP_MIN_ADDR
80473- int "Low address space to protect from user allocation"
80474+ int "Low address space to protect from user allocation"
80475 depends on MMU
80476- default 4096
80477- help
80478+ default 65536
80479+ help
80480 This is the portion of low virtual memory which should be protected
80481 from userspace allocation. Keeping a user from writing to low pages
80482 can help reduce the impact of kernel NULL pointer bugs.
80483@@ -345,7 +345,7 @@ config MEMORY_FAILURE
80484
80485 config HWPOISON_INJECT
80486 tristate "HWPoison pages injector"
80487- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
80488+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
80489 select PROC_PAGE_MONITOR
80490
80491 config NOMMU_INITIAL_TRIM_EXCESS
80492diff --git a/mm/filemap.c b/mm/filemap.c
80493index e1979fd..dda5120 100644
80494--- a/mm/filemap.c
80495+++ b/mm/filemap.c
80496@@ -1748,7 +1748,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
80497 struct address_space *mapping = file->f_mapping;
80498
80499 if (!mapping->a_ops->readpage)
80500- return -ENOEXEC;
80501+ return -ENODEV;
80502 file_accessed(file);
80503 vma->vm_ops = &generic_file_vm_ops;
80504 return 0;
80505@@ -2088,6 +2088,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
80506 *pos = i_size_read(inode);
80507
80508 if (limit != RLIM_INFINITY) {
80509+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
80510 if (*pos >= limit) {
80511 send_sig(SIGXFSZ, current, 0);
80512 return -EFBIG;
80513diff --git a/mm/fremap.c b/mm/fremap.c
80514index 87da359..3f41cb1 100644
80515--- a/mm/fremap.c
80516+++ b/mm/fremap.c
80517@@ -158,6 +158,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
80518 retry:
80519 vma = find_vma(mm, start);
80520
80521+#ifdef CONFIG_PAX_SEGMEXEC
80522+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
80523+ goto out;
80524+#endif
80525+
80526 /*
80527 * Make sure the vma is shared, that it supports prefaulting,
80528 * and that the remapped range is valid and fully within
80529diff --git a/mm/highmem.c b/mm/highmem.c
80530index b32b70c..e512eb0 100644
80531--- a/mm/highmem.c
80532+++ b/mm/highmem.c
80533@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
80534 * So no dangers, even with speculative execution.
80535 */
80536 page = pte_page(pkmap_page_table[i]);
80537+ pax_open_kernel();
80538 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
80539-
80540+ pax_close_kernel();
80541 set_page_address(page, NULL);
80542 need_flush = 1;
80543 }
80544@@ -198,9 +199,11 @@ start:
80545 }
80546 }
80547 vaddr = PKMAP_ADDR(last_pkmap_nr);
80548+
80549+ pax_open_kernel();
80550 set_pte_at(&init_mm, vaddr,
80551 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
80552-
80553+ pax_close_kernel();
80554 pkmap_count[last_pkmap_nr] = 1;
80555 set_page_address(page, (void *)vaddr);
80556
80557diff --git a/mm/hugetlb.c b/mm/hugetlb.c
80558index 1a12f5b..a85b8fc 100644
80559--- a/mm/hugetlb.c
80560+++ b/mm/hugetlb.c
80561@@ -2005,15 +2005,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
80562 struct hstate *h = &default_hstate;
80563 unsigned long tmp;
80564 int ret;
80565+ ctl_table_no_const hugetlb_table;
80566
80567 tmp = h->max_huge_pages;
80568
80569 if (write && h->order >= MAX_ORDER)
80570 return -EINVAL;
80571
80572- table->data = &tmp;
80573- table->maxlen = sizeof(unsigned long);
80574- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
80575+ hugetlb_table = *table;
80576+ hugetlb_table.data = &tmp;
80577+ hugetlb_table.maxlen = sizeof(unsigned long);
80578+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
80579 if (ret)
80580 goto out;
80581
80582@@ -2070,15 +2072,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
80583 struct hstate *h = &default_hstate;
80584 unsigned long tmp;
80585 int ret;
80586+ ctl_table_no_const hugetlb_table;
80587
80588 tmp = h->nr_overcommit_huge_pages;
80589
80590 if (write && h->order >= MAX_ORDER)
80591 return -EINVAL;
80592
80593- table->data = &tmp;
80594- table->maxlen = sizeof(unsigned long);
80595- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
80596+ hugetlb_table = *table;
80597+ hugetlb_table.data = &tmp;
80598+ hugetlb_table.maxlen = sizeof(unsigned long);
80599+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
80600 if (ret)
80601 goto out;
80602
80603@@ -2512,6 +2516,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
80604 return 1;
80605 }
80606
80607+#ifdef CONFIG_PAX_SEGMEXEC
80608+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
80609+{
80610+ struct mm_struct *mm = vma->vm_mm;
80611+ struct vm_area_struct *vma_m;
80612+ unsigned long address_m;
80613+ pte_t *ptep_m;
80614+
80615+ vma_m = pax_find_mirror_vma(vma);
80616+ if (!vma_m)
80617+ return;
80618+
80619+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
80620+ address_m = address + SEGMEXEC_TASK_SIZE;
80621+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
80622+ get_page(page_m);
80623+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
80624+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
80625+}
80626+#endif
80627+
80628 /*
80629 * Hugetlb_cow() should be called with page lock of the original hugepage held.
80630 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
80631@@ -2630,6 +2655,11 @@ retry_avoidcopy:
80632 make_huge_pte(vma, new_page, 1));
80633 page_remove_rmap(old_page);
80634 hugepage_add_new_anon_rmap(new_page, vma, address);
80635+
80636+#ifdef CONFIG_PAX_SEGMEXEC
80637+ pax_mirror_huge_pte(vma, address, new_page);
80638+#endif
80639+
80640 /* Make the old page be freed below */
80641 new_page = old_page;
80642 }
80643@@ -2788,6 +2818,10 @@ retry:
80644 && (vma->vm_flags & VM_SHARED)));
80645 set_huge_pte_at(mm, address, ptep, new_pte);
80646
80647+#ifdef CONFIG_PAX_SEGMEXEC
80648+ pax_mirror_huge_pte(vma, address, page);
80649+#endif
80650+
80651 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
80652 /* Optimization, do the COW without a second fault */
80653 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
80654@@ -2817,6 +2851,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80655 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
80656 struct hstate *h = hstate_vma(vma);
80657
80658+#ifdef CONFIG_PAX_SEGMEXEC
80659+ struct vm_area_struct *vma_m;
80660+#endif
80661+
80662 address &= huge_page_mask(h);
80663
80664 ptep = huge_pte_offset(mm, address);
80665@@ -2830,6 +2868,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
80666 VM_FAULT_SET_HINDEX(hstate_index(h));
80667 }
80668
80669+#ifdef CONFIG_PAX_SEGMEXEC
80670+ vma_m = pax_find_mirror_vma(vma);
80671+ if (vma_m) {
80672+ unsigned long address_m;
80673+
80674+ if (vma->vm_start > vma_m->vm_start) {
80675+ address_m = address;
80676+ address -= SEGMEXEC_TASK_SIZE;
80677+ vma = vma_m;
80678+ h = hstate_vma(vma);
80679+ } else
80680+ address_m = address + SEGMEXEC_TASK_SIZE;
80681+
80682+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
80683+ return VM_FAULT_OOM;
80684+ address_m &= HPAGE_MASK;
80685+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
80686+ }
80687+#endif
80688+
80689 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
80690 if (!ptep)
80691 return VM_FAULT_OOM;
80692diff --git a/mm/internal.h b/mm/internal.h
80693index 8562de0..7fdfe92 100644
80694--- a/mm/internal.h
80695+++ b/mm/internal.h
80696@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
80697 * in mm/page_alloc.c
80698 */
80699 extern void __free_pages_bootmem(struct page *page, unsigned int order);
80700+extern void free_compound_page(struct page *page);
80701 extern void prep_compound_page(struct page *page, unsigned long order);
80702 #ifdef CONFIG_MEMORY_FAILURE
80703 extern bool is_free_buddy_page(struct page *page);
80704diff --git a/mm/kmemleak.c b/mm/kmemleak.c
80705index c8d7f31..2dbeffd 100644
80706--- a/mm/kmemleak.c
80707+++ b/mm/kmemleak.c
80708@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
80709
80710 for (i = 0; i < object->trace_len; i++) {
80711 void *ptr = (void *)object->trace[i];
80712- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
80713+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
80714 }
80715 }
80716
80717@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
80718 return -ENOMEM;
80719 }
80720
80721- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
80722+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
80723 &kmemleak_fops);
80724 if (!dentry)
80725 pr_warning("Failed to create the debugfs kmemleak file\n");
80726diff --git a/mm/maccess.c b/mm/maccess.c
80727index d53adf9..03a24bf 100644
80728--- a/mm/maccess.c
80729+++ b/mm/maccess.c
80730@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
80731 set_fs(KERNEL_DS);
80732 pagefault_disable();
80733 ret = __copy_from_user_inatomic(dst,
80734- (__force const void __user *)src, size);
80735+ (const void __force_user *)src, size);
80736 pagefault_enable();
80737 set_fs(old_fs);
80738
80739@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
80740
80741 set_fs(KERNEL_DS);
80742 pagefault_disable();
80743- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
80744+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
80745 pagefault_enable();
80746 set_fs(old_fs);
80747
80748diff --git a/mm/madvise.c b/mm/madvise.c
80749index c58c94b..86ec14e 100644
80750--- a/mm/madvise.c
80751+++ b/mm/madvise.c
80752@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
80753 pgoff_t pgoff;
80754 unsigned long new_flags = vma->vm_flags;
80755
80756+#ifdef CONFIG_PAX_SEGMEXEC
80757+ struct vm_area_struct *vma_m;
80758+#endif
80759+
80760 switch (behavior) {
80761 case MADV_NORMAL:
80762 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
80763@@ -126,6 +130,13 @@ success:
80764 /*
80765 * vm_flags is protected by the mmap_sem held in write mode.
80766 */
80767+
80768+#ifdef CONFIG_PAX_SEGMEXEC
80769+ vma_m = pax_find_mirror_vma(vma);
80770+ if (vma_m)
80771+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
80772+#endif
80773+
80774 vma->vm_flags = new_flags;
80775
80776 out:
80777@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
80778 struct vm_area_struct ** prev,
80779 unsigned long start, unsigned long end)
80780 {
80781+
80782+#ifdef CONFIG_PAX_SEGMEXEC
80783+ struct vm_area_struct *vma_m;
80784+#endif
80785+
80786 *prev = vma;
80787 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
80788 return -EINVAL;
80789@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
80790 zap_page_range(vma, start, end - start, &details);
80791 } else
80792 zap_page_range(vma, start, end - start, NULL);
80793+
80794+#ifdef CONFIG_PAX_SEGMEXEC
80795+ vma_m = pax_find_mirror_vma(vma);
80796+ if (vma_m) {
80797+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
80798+ struct zap_details details = {
80799+ .nonlinear_vma = vma_m,
80800+ .last_index = ULONG_MAX,
80801+ };
80802+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
80803+ } else
80804+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
80805+ }
80806+#endif
80807+
80808 return 0;
80809 }
80810
80811@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
80812 if (end < start)
80813 goto out;
80814
80815+#ifdef CONFIG_PAX_SEGMEXEC
80816+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
80817+ if (end > SEGMEXEC_TASK_SIZE)
80818+ goto out;
80819+ } else
80820+#endif
80821+
80822+ if (end > TASK_SIZE)
80823+ goto out;
80824+
80825 error = 0;
80826 if (end == start)
80827 goto out;
80828diff --git a/mm/memory-failure.c b/mm/memory-failure.c
80829index df0694c..bc95539 100644
80830--- a/mm/memory-failure.c
80831+++ b/mm/memory-failure.c
80832@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
80833
80834 int sysctl_memory_failure_recovery __read_mostly = 1;
80835
80836-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
80837+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
80838
80839 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
80840
80841@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
80842 pfn, t->comm, t->pid);
80843 si.si_signo = SIGBUS;
80844 si.si_errno = 0;
80845- si.si_addr = (void *)addr;
80846+ si.si_addr = (void __user *)addr;
80847 #ifdef __ARCH_SI_TRAPNO
80848 si.si_trapno = trapno;
80849 #endif
80850@@ -760,7 +760,7 @@ static struct page_state {
80851 unsigned long res;
80852 char *msg;
80853 int (*action)(struct page *p, unsigned long pfn);
80854-} error_states[] = {
80855+} __do_const error_states[] = {
80856 { reserved, reserved, "reserved kernel", me_kernel },
80857 /*
80858 * free pages are specially detected outside this table:
80859@@ -1051,7 +1051,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
80860 nr_pages = 1 << compound_order(hpage);
80861 else /* normal page or thp */
80862 nr_pages = 1;
80863- atomic_long_add(nr_pages, &num_poisoned_pages);
80864+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
80865
80866 /*
80867 * We need/can do nothing about count=0 pages.
80868@@ -1081,7 +1081,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
80869 if (!PageHWPoison(hpage)
80870 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
80871 || (p != hpage && TestSetPageHWPoison(hpage))) {
80872- atomic_long_sub(nr_pages, &num_poisoned_pages);
80873+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
80874 return 0;
80875 }
80876 set_page_hwpoison_huge_page(hpage);
80877@@ -1148,7 +1148,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
80878 }
80879 if (hwpoison_filter(p)) {
80880 if (TestClearPageHWPoison(p))
80881- atomic_long_sub(nr_pages, &num_poisoned_pages);
80882+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
80883 unlock_page(hpage);
80884 put_page(hpage);
80885 return 0;
80886@@ -1350,7 +1350,7 @@ int unpoison_memory(unsigned long pfn)
80887 return 0;
80888 }
80889 if (TestClearPageHWPoison(p))
80890- atomic_long_sub(nr_pages, &num_poisoned_pages);
80891+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
80892 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
80893 return 0;
80894 }
80895@@ -1364,7 +1364,7 @@ int unpoison_memory(unsigned long pfn)
80896 */
80897 if (TestClearPageHWPoison(page)) {
80898 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
80899- atomic_long_sub(nr_pages, &num_poisoned_pages);
80900+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
80901 freeit = 1;
80902 if (PageHuge(page))
80903 clear_page_hwpoison_huge_page(page);
80904@@ -1491,7 +1491,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
80905 } else {
80906 set_page_hwpoison_huge_page(hpage);
80907 dequeue_hwpoisoned_huge_page(hpage);
80908- atomic_long_add(1 << compound_trans_order(hpage),
80909+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
80910 &num_poisoned_pages);
80911 }
80912 /* keep elevated page count for bad page */
80913@@ -1552,11 +1552,11 @@ int soft_offline_page(struct page *page, int flags)
80914 if (PageHuge(page)) {
80915 set_page_hwpoison_huge_page(hpage);
80916 dequeue_hwpoisoned_huge_page(hpage);
80917- atomic_long_add(1 << compound_trans_order(hpage),
80918+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
80919 &num_poisoned_pages);
80920 } else {
80921 SetPageHWPoison(page);
80922- atomic_long_inc(&num_poisoned_pages);
80923+ atomic_long_inc_unchecked(&num_poisoned_pages);
80924 }
80925 }
80926 /* keep elevated page count for bad page */
80927@@ -1596,7 +1596,7 @@ static int __soft_offline_page(struct page *page, int flags)
80928 put_page(page);
80929 pr_info("soft_offline: %#lx: invalidated\n", pfn);
80930 SetPageHWPoison(page);
80931- atomic_long_inc(&num_poisoned_pages);
80932+ atomic_long_inc_unchecked(&num_poisoned_pages);
80933 return 0;
80934 }
80935
80936@@ -1626,7 +1626,7 @@ static int __soft_offline_page(struct page *page, int flags)
80937 ret = -EIO;
80938 } else {
80939 SetPageHWPoison(page);
80940- atomic_long_inc(&num_poisoned_pages);
80941+ atomic_long_inc_unchecked(&num_poisoned_pages);
80942 }
80943 } else {
80944 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
80945diff --git a/mm/memory.c b/mm/memory.c
80946index ba94dec..08ffe0d 100644
80947--- a/mm/memory.c
80948+++ b/mm/memory.c
80949@@ -438,6 +438,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
80950 free_pte_range(tlb, pmd, addr);
80951 } while (pmd++, addr = next, addr != end);
80952
80953+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
80954 start &= PUD_MASK;
80955 if (start < floor)
80956 return;
80957@@ -452,6 +453,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
80958 pmd = pmd_offset(pud, start);
80959 pud_clear(pud);
80960 pmd_free_tlb(tlb, pmd, start);
80961+#endif
80962+
80963 }
80964
80965 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
80966@@ -471,6 +474,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
80967 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
80968 } while (pud++, addr = next, addr != end);
80969
80970+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
80971 start &= PGDIR_MASK;
80972 if (start < floor)
80973 return;
80974@@ -485,6 +489,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
80975 pud = pud_offset(pgd, start);
80976 pgd_clear(pgd);
80977 pud_free_tlb(tlb, pud, start);
80978+#endif
80979+
80980 }
80981
80982 /*
80983@@ -1644,12 +1650,6 @@ no_page_table:
80984 return page;
80985 }
80986
80987-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
80988-{
80989- return stack_guard_page_start(vma, addr) ||
80990- stack_guard_page_end(vma, addr+PAGE_SIZE);
80991-}
80992-
80993 /**
80994 * __get_user_pages() - pin user pages in memory
80995 * @tsk: task_struct of target task
80996@@ -1736,10 +1736,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80997
80998 i = 0;
80999
81000- do {
81001+ while (nr_pages) {
81002 struct vm_area_struct *vma;
81003
81004- vma = find_extend_vma(mm, start);
81005+ vma = find_vma(mm, start);
81006 if (!vma && in_gate_area(mm, start)) {
81007 unsigned long pg = start & PAGE_MASK;
81008 pgd_t *pgd;
81009@@ -1788,7 +1788,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81010 goto next_page;
81011 }
81012
81013- if (!vma ||
81014+ if (!vma || start < vma->vm_start ||
81015 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
81016 !(vm_flags & vma->vm_flags))
81017 return i ? : -EFAULT;
81018@@ -1817,11 +1817,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81019 int ret;
81020 unsigned int fault_flags = 0;
81021
81022- /* For mlock, just skip the stack guard page. */
81023- if (foll_flags & FOLL_MLOCK) {
81024- if (stack_guard_page(vma, start))
81025- goto next_page;
81026- }
81027 if (foll_flags & FOLL_WRITE)
81028 fault_flags |= FAULT_FLAG_WRITE;
81029 if (nonblocking)
81030@@ -1901,7 +1896,7 @@ next_page:
81031 start += page_increm * PAGE_SIZE;
81032 nr_pages -= page_increm;
81033 } while (nr_pages && start < vma->vm_end);
81034- } while (nr_pages);
81035+ }
81036 return i;
81037 }
81038 EXPORT_SYMBOL(__get_user_pages);
81039@@ -2108,6 +2103,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
81040 page_add_file_rmap(page);
81041 set_pte_at(mm, addr, pte, mk_pte(page, prot));
81042
81043+#ifdef CONFIG_PAX_SEGMEXEC
81044+ pax_mirror_file_pte(vma, addr, page, ptl);
81045+#endif
81046+
81047 retval = 0;
81048 pte_unmap_unlock(pte, ptl);
81049 return retval;
81050@@ -2152,9 +2151,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
81051 if (!page_count(page))
81052 return -EINVAL;
81053 if (!(vma->vm_flags & VM_MIXEDMAP)) {
81054+
81055+#ifdef CONFIG_PAX_SEGMEXEC
81056+ struct vm_area_struct *vma_m;
81057+#endif
81058+
81059 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
81060 BUG_ON(vma->vm_flags & VM_PFNMAP);
81061 vma->vm_flags |= VM_MIXEDMAP;
81062+
81063+#ifdef CONFIG_PAX_SEGMEXEC
81064+ vma_m = pax_find_mirror_vma(vma);
81065+ if (vma_m)
81066+ vma_m->vm_flags |= VM_MIXEDMAP;
81067+#endif
81068+
81069 }
81070 return insert_page(vma, addr, page, vma->vm_page_prot);
81071 }
81072@@ -2237,6 +2248,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
81073 unsigned long pfn)
81074 {
81075 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
81076+ BUG_ON(vma->vm_mirror);
81077
81078 if (addr < vma->vm_start || addr >= vma->vm_end)
81079 return -EFAULT;
81080@@ -2484,7 +2496,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
81081
81082 BUG_ON(pud_huge(*pud));
81083
81084- pmd = pmd_alloc(mm, pud, addr);
81085+ pmd = (mm == &init_mm) ?
81086+ pmd_alloc_kernel(mm, pud, addr) :
81087+ pmd_alloc(mm, pud, addr);
81088 if (!pmd)
81089 return -ENOMEM;
81090 do {
81091@@ -2504,7 +2518,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
81092 unsigned long next;
81093 int err;
81094
81095- pud = pud_alloc(mm, pgd, addr);
81096+ pud = (mm == &init_mm) ?
81097+ pud_alloc_kernel(mm, pgd, addr) :
81098+ pud_alloc(mm, pgd, addr);
81099 if (!pud)
81100 return -ENOMEM;
81101 do {
81102@@ -2592,6 +2608,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
81103 copy_user_highpage(dst, src, va, vma);
81104 }
81105
81106+#ifdef CONFIG_PAX_SEGMEXEC
81107+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
81108+{
81109+ struct mm_struct *mm = vma->vm_mm;
81110+ spinlock_t *ptl;
81111+ pte_t *pte, entry;
81112+
81113+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
81114+ entry = *pte;
81115+ if (!pte_present(entry)) {
81116+ if (!pte_none(entry)) {
81117+ BUG_ON(pte_file(entry));
81118+ free_swap_and_cache(pte_to_swp_entry(entry));
81119+ pte_clear_not_present_full(mm, address, pte, 0);
81120+ }
81121+ } else {
81122+ struct page *page;
81123+
81124+ flush_cache_page(vma, address, pte_pfn(entry));
81125+ entry = ptep_clear_flush(vma, address, pte);
81126+ BUG_ON(pte_dirty(entry));
81127+ page = vm_normal_page(vma, address, entry);
81128+ if (page) {
81129+ update_hiwater_rss(mm);
81130+ if (PageAnon(page))
81131+ dec_mm_counter_fast(mm, MM_ANONPAGES);
81132+ else
81133+ dec_mm_counter_fast(mm, MM_FILEPAGES);
81134+ page_remove_rmap(page);
81135+ page_cache_release(page);
81136+ }
81137+ }
81138+ pte_unmap_unlock(pte, ptl);
81139+}
81140+
81141+/* PaX: if vma is mirrored, synchronize the mirror's PTE
81142+ *
81143+ * the ptl of the lower mapped page is held on entry and is not released on exit
81144+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
81145+ */
81146+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
81147+{
81148+ struct mm_struct *mm = vma->vm_mm;
81149+ unsigned long address_m;
81150+ spinlock_t *ptl_m;
81151+ struct vm_area_struct *vma_m;
81152+ pmd_t *pmd_m;
81153+ pte_t *pte_m, entry_m;
81154+
81155+ BUG_ON(!page_m || !PageAnon(page_m));
81156+
81157+ vma_m = pax_find_mirror_vma(vma);
81158+ if (!vma_m)
81159+ return;
81160+
81161+ BUG_ON(!PageLocked(page_m));
81162+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81163+ address_m = address + SEGMEXEC_TASK_SIZE;
81164+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81165+ pte_m = pte_offset_map(pmd_m, address_m);
81166+ ptl_m = pte_lockptr(mm, pmd_m);
81167+ if (ptl != ptl_m) {
81168+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81169+ if (!pte_none(*pte_m))
81170+ goto out;
81171+ }
81172+
81173+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
81174+ page_cache_get(page_m);
81175+ page_add_anon_rmap(page_m, vma_m, address_m);
81176+ inc_mm_counter_fast(mm, MM_ANONPAGES);
81177+ set_pte_at(mm, address_m, pte_m, entry_m);
81178+ update_mmu_cache(vma_m, address_m, pte_m);
81179+out:
81180+ if (ptl != ptl_m)
81181+ spin_unlock(ptl_m);
81182+ pte_unmap(pte_m);
81183+ unlock_page(page_m);
81184+}
81185+
81186+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
81187+{
81188+ struct mm_struct *mm = vma->vm_mm;
81189+ unsigned long address_m;
81190+ spinlock_t *ptl_m;
81191+ struct vm_area_struct *vma_m;
81192+ pmd_t *pmd_m;
81193+ pte_t *pte_m, entry_m;
81194+
81195+ BUG_ON(!page_m || PageAnon(page_m));
81196+
81197+ vma_m = pax_find_mirror_vma(vma);
81198+ if (!vma_m)
81199+ return;
81200+
81201+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81202+ address_m = address + SEGMEXEC_TASK_SIZE;
81203+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81204+ pte_m = pte_offset_map(pmd_m, address_m);
81205+ ptl_m = pte_lockptr(mm, pmd_m);
81206+ if (ptl != ptl_m) {
81207+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81208+ if (!pte_none(*pte_m))
81209+ goto out;
81210+ }
81211+
81212+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
81213+ page_cache_get(page_m);
81214+ page_add_file_rmap(page_m);
81215+ inc_mm_counter_fast(mm, MM_FILEPAGES);
81216+ set_pte_at(mm, address_m, pte_m, entry_m);
81217+ update_mmu_cache(vma_m, address_m, pte_m);
81218+out:
81219+ if (ptl != ptl_m)
81220+ spin_unlock(ptl_m);
81221+ pte_unmap(pte_m);
81222+}
81223+
81224+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
81225+{
81226+ struct mm_struct *mm = vma->vm_mm;
81227+ unsigned long address_m;
81228+ spinlock_t *ptl_m;
81229+ struct vm_area_struct *vma_m;
81230+ pmd_t *pmd_m;
81231+ pte_t *pte_m, entry_m;
81232+
81233+ vma_m = pax_find_mirror_vma(vma);
81234+ if (!vma_m)
81235+ return;
81236+
81237+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81238+ address_m = address + SEGMEXEC_TASK_SIZE;
81239+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81240+ pte_m = pte_offset_map(pmd_m, address_m);
81241+ ptl_m = pte_lockptr(mm, pmd_m);
81242+ if (ptl != ptl_m) {
81243+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81244+ if (!pte_none(*pte_m))
81245+ goto out;
81246+ }
81247+
81248+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
81249+ set_pte_at(mm, address_m, pte_m, entry_m);
81250+out:
81251+ if (ptl != ptl_m)
81252+ spin_unlock(ptl_m);
81253+ pte_unmap(pte_m);
81254+}
81255+
81256+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
81257+{
81258+ struct page *page_m;
81259+ pte_t entry;
81260+
81261+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
81262+ goto out;
81263+
81264+ entry = *pte;
81265+ page_m = vm_normal_page(vma, address, entry);
81266+ if (!page_m)
81267+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
81268+ else if (PageAnon(page_m)) {
81269+ if (pax_find_mirror_vma(vma)) {
81270+ pte_unmap_unlock(pte, ptl);
81271+ lock_page(page_m);
81272+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
81273+ if (pte_same(entry, *pte))
81274+ pax_mirror_anon_pte(vma, address, page_m, ptl);
81275+ else
81276+ unlock_page(page_m);
81277+ }
81278+ } else
81279+ pax_mirror_file_pte(vma, address, page_m, ptl);
81280+
81281+out:
81282+ pte_unmap_unlock(pte, ptl);
81283+}
81284+#endif
81285+
81286 /*
81287 * This routine handles present pages, when users try to write
81288 * to a shared page. It is done by copying the page to a new address
81289@@ -2808,6 +3004,12 @@ gotten:
81290 */
81291 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
81292 if (likely(pte_same(*page_table, orig_pte))) {
81293+
81294+#ifdef CONFIG_PAX_SEGMEXEC
81295+ if (pax_find_mirror_vma(vma))
81296+ BUG_ON(!trylock_page(new_page));
81297+#endif
81298+
81299 if (old_page) {
81300 if (!PageAnon(old_page)) {
81301 dec_mm_counter_fast(mm, MM_FILEPAGES);
81302@@ -2859,6 +3061,10 @@ gotten:
81303 page_remove_rmap(old_page);
81304 }
81305
81306+#ifdef CONFIG_PAX_SEGMEXEC
81307+ pax_mirror_anon_pte(vma, address, new_page, ptl);
81308+#endif
81309+
81310 /* Free the old page.. */
81311 new_page = old_page;
81312 ret |= VM_FAULT_WRITE;
81313@@ -3134,6 +3340,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
81314 swap_free(entry);
81315 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
81316 try_to_free_swap(page);
81317+
81318+#ifdef CONFIG_PAX_SEGMEXEC
81319+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
81320+#endif
81321+
81322 unlock_page(page);
81323 if (page != swapcache) {
81324 /*
81325@@ -3157,6 +3368,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
81326
81327 /* No need to invalidate - it was non-present before */
81328 update_mmu_cache(vma, address, page_table);
81329+
81330+#ifdef CONFIG_PAX_SEGMEXEC
81331+ pax_mirror_anon_pte(vma, address, page, ptl);
81332+#endif
81333+
81334 unlock:
81335 pte_unmap_unlock(page_table, ptl);
81336 out:
81337@@ -3176,40 +3392,6 @@ out_release:
81338 }
81339
81340 /*
81341- * This is like a special single-page "expand_{down|up}wards()",
81342- * except we must first make sure that 'address{-|+}PAGE_SIZE'
81343- * doesn't hit another vma.
81344- */
81345-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
81346-{
81347- address &= PAGE_MASK;
81348- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
81349- struct vm_area_struct *prev = vma->vm_prev;
81350-
81351- /*
81352- * Is there a mapping abutting this one below?
81353- *
81354- * That's only ok if it's the same stack mapping
81355- * that has gotten split..
81356- */
81357- if (prev && prev->vm_end == address)
81358- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
81359-
81360- expand_downwards(vma, address - PAGE_SIZE);
81361- }
81362- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
81363- struct vm_area_struct *next = vma->vm_next;
81364-
81365- /* As VM_GROWSDOWN but s/below/above/ */
81366- if (next && next->vm_start == address + PAGE_SIZE)
81367- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
81368-
81369- expand_upwards(vma, address + PAGE_SIZE);
81370- }
81371- return 0;
81372-}
81373-
81374-/*
81375 * We enter with non-exclusive mmap_sem (to exclude vma changes,
81376 * but allow concurrent faults), and pte mapped but not yet locked.
81377 * We return with mmap_sem still held, but pte unmapped and unlocked.
81378@@ -3218,27 +3400,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
81379 unsigned long address, pte_t *page_table, pmd_t *pmd,
81380 unsigned int flags)
81381 {
81382- struct page *page;
81383+ struct page *page = NULL;
81384 spinlock_t *ptl;
81385 pte_t entry;
81386
81387- pte_unmap(page_table);
81388-
81389- /* Check if we need to add a guard page to the stack */
81390- if (check_stack_guard_page(vma, address) < 0)
81391- return VM_FAULT_SIGBUS;
81392-
81393- /* Use the zero-page for reads */
81394 if (!(flags & FAULT_FLAG_WRITE)) {
81395 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
81396 vma->vm_page_prot));
81397- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
81398+ ptl = pte_lockptr(mm, pmd);
81399+ spin_lock(ptl);
81400 if (!pte_none(*page_table))
81401 goto unlock;
81402 goto setpte;
81403 }
81404
81405 /* Allocate our own private page. */
81406+ pte_unmap(page_table);
81407+
81408 if (unlikely(anon_vma_prepare(vma)))
81409 goto oom;
81410 page = alloc_zeroed_user_highpage_movable(vma, address);
81411@@ -3257,6 +3435,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
81412 if (!pte_none(*page_table))
81413 goto release;
81414
81415+#ifdef CONFIG_PAX_SEGMEXEC
81416+ if (pax_find_mirror_vma(vma))
81417+ BUG_ON(!trylock_page(page));
81418+#endif
81419+
81420 inc_mm_counter_fast(mm, MM_ANONPAGES);
81421 page_add_new_anon_rmap(page, vma, address);
81422 setpte:
81423@@ -3264,6 +3447,12 @@ setpte:
81424
81425 /* No need to invalidate - it was non-present before */
81426 update_mmu_cache(vma, address, page_table);
81427+
81428+#ifdef CONFIG_PAX_SEGMEXEC
81429+ if (page)
81430+ pax_mirror_anon_pte(vma, address, page, ptl);
81431+#endif
81432+
81433 unlock:
81434 pte_unmap_unlock(page_table, ptl);
81435 return 0;
81436@@ -3407,6 +3596,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81437 */
81438 /* Only go through if we didn't race with anybody else... */
81439 if (likely(pte_same(*page_table, orig_pte))) {
81440+
81441+#ifdef CONFIG_PAX_SEGMEXEC
81442+ if (anon && pax_find_mirror_vma(vma))
81443+ BUG_ON(!trylock_page(page));
81444+#endif
81445+
81446 flush_icache_page(vma, page);
81447 entry = mk_pte(page, vma->vm_page_prot);
81448 if (flags & FAULT_FLAG_WRITE)
81449@@ -3426,6 +3621,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81450
81451 /* no need to invalidate: a not-present page won't be cached */
81452 update_mmu_cache(vma, address, page_table);
81453+
81454+#ifdef CONFIG_PAX_SEGMEXEC
81455+ if (anon)
81456+ pax_mirror_anon_pte(vma, address, page, ptl);
81457+ else
81458+ pax_mirror_file_pte(vma, address, page, ptl);
81459+#endif
81460+
81461 } else {
81462 if (cow_page)
81463 mem_cgroup_uncharge_page(cow_page);
81464@@ -3747,6 +3950,12 @@ int handle_pte_fault(struct mm_struct *mm,
81465 if (flags & FAULT_FLAG_WRITE)
81466 flush_tlb_fix_spurious_fault(vma, address);
81467 }
81468+
81469+#ifdef CONFIG_PAX_SEGMEXEC
81470+ pax_mirror_pte(vma, address, pte, pmd, ptl);
81471+ return 0;
81472+#endif
81473+
81474 unlock:
81475 pte_unmap_unlock(pte, ptl);
81476 return 0;
81477@@ -3763,6 +3972,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81478 pmd_t *pmd;
81479 pte_t *pte;
81480
81481+#ifdef CONFIG_PAX_SEGMEXEC
81482+ struct vm_area_struct *vma_m;
81483+#endif
81484+
81485 __set_current_state(TASK_RUNNING);
81486
81487 count_vm_event(PGFAULT);
81488@@ -3774,6 +3987,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81489 if (unlikely(is_vm_hugetlb_page(vma)))
81490 return hugetlb_fault(mm, vma, address, flags);
81491
81492+#ifdef CONFIG_PAX_SEGMEXEC
81493+ vma_m = pax_find_mirror_vma(vma);
81494+ if (vma_m) {
81495+ unsigned long address_m;
81496+ pgd_t *pgd_m;
81497+ pud_t *pud_m;
81498+ pmd_t *pmd_m;
81499+
81500+ if (vma->vm_start > vma_m->vm_start) {
81501+ address_m = address;
81502+ address -= SEGMEXEC_TASK_SIZE;
81503+ vma = vma_m;
81504+ } else
81505+ address_m = address + SEGMEXEC_TASK_SIZE;
81506+
81507+ pgd_m = pgd_offset(mm, address_m);
81508+ pud_m = pud_alloc(mm, pgd_m, address_m);
81509+ if (!pud_m)
81510+ return VM_FAULT_OOM;
81511+ pmd_m = pmd_alloc(mm, pud_m, address_m);
81512+ if (!pmd_m)
81513+ return VM_FAULT_OOM;
81514+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
81515+ return VM_FAULT_OOM;
81516+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
81517+ }
81518+#endif
81519+
81520 retry:
81521 pgd = pgd_offset(mm, address);
81522 pud = pud_alloc(mm, pgd, address);
81523@@ -3872,6 +4113,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
81524 spin_unlock(&mm->page_table_lock);
81525 return 0;
81526 }
81527+
81528+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
81529+{
81530+ pud_t *new = pud_alloc_one(mm, address);
81531+ if (!new)
81532+ return -ENOMEM;
81533+
81534+ smp_wmb(); /* See comment in __pte_alloc */
81535+
81536+ spin_lock(&mm->page_table_lock);
81537+ if (pgd_present(*pgd)) /* Another has populated it */
81538+ pud_free(mm, new);
81539+ else
81540+ pgd_populate_kernel(mm, pgd, new);
81541+ spin_unlock(&mm->page_table_lock);
81542+ return 0;
81543+}
81544 #endif /* __PAGETABLE_PUD_FOLDED */
81545
81546 #ifndef __PAGETABLE_PMD_FOLDED
81547@@ -3902,6 +4160,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
81548 spin_unlock(&mm->page_table_lock);
81549 return 0;
81550 }
81551+
81552+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
81553+{
81554+ pmd_t *new = pmd_alloc_one(mm, address);
81555+ if (!new)
81556+ return -ENOMEM;
81557+
81558+ smp_wmb(); /* See comment in __pte_alloc */
81559+
81560+ spin_lock(&mm->page_table_lock);
81561+#ifndef __ARCH_HAS_4LEVEL_HACK
81562+ if (pud_present(*pud)) /* Another has populated it */
81563+ pmd_free(mm, new);
81564+ else
81565+ pud_populate_kernel(mm, pud, new);
81566+#else
81567+ if (pgd_present(*pud)) /* Another has populated it */
81568+ pmd_free(mm, new);
81569+ else
81570+ pgd_populate_kernel(mm, pud, new);
81571+#endif /* __ARCH_HAS_4LEVEL_HACK */
81572+ spin_unlock(&mm->page_table_lock);
81573+ return 0;
81574+}
81575 #endif /* __PAGETABLE_PMD_FOLDED */
81576
81577 #if !defined(__HAVE_ARCH_GATE_AREA)
81578@@ -3915,7 +4197,7 @@ static int __init gate_vma_init(void)
81579 gate_vma.vm_start = FIXADDR_USER_START;
81580 gate_vma.vm_end = FIXADDR_USER_END;
81581 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
81582- gate_vma.vm_page_prot = __P101;
81583+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
81584
81585 return 0;
81586 }
81587@@ -4049,8 +4331,8 @@ out:
81588 return ret;
81589 }
81590
81591-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
81592- void *buf, int len, int write)
81593+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
81594+ void *buf, size_t len, int write)
81595 {
81596 resource_size_t phys_addr;
81597 unsigned long prot = 0;
81598@@ -4075,8 +4357,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
81599 * Access another process' address space as given in mm. If non-NULL, use the
81600 * given task for page fault accounting.
81601 */
81602-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
81603- unsigned long addr, void *buf, int len, int write)
81604+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
81605+ unsigned long addr, void *buf, size_t len, int write)
81606 {
81607 struct vm_area_struct *vma;
81608 void *old_buf = buf;
81609@@ -4084,7 +4366,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
81610 down_read(&mm->mmap_sem);
81611 /* ignore errors, just check how much was successfully transferred */
81612 while (len) {
81613- int bytes, ret, offset;
81614+ ssize_t bytes, ret, offset;
81615 void *maddr;
81616 struct page *page = NULL;
81617
81618@@ -4143,8 +4425,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
81619 *
81620 * The caller must hold a reference on @mm.
81621 */
81622-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
81623- void *buf, int len, int write)
81624+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
81625+ void *buf, size_t len, int write)
81626 {
81627 return __access_remote_vm(NULL, mm, addr, buf, len, write);
81628 }
81629@@ -4154,11 +4436,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
81630 * Source/target buffer must be kernel space,
81631 * Do not walk the page table directly, use get_user_pages
81632 */
81633-int access_process_vm(struct task_struct *tsk, unsigned long addr,
81634- void *buf, int len, int write)
81635+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
81636+ void *buf, size_t len, int write)
81637 {
81638 struct mm_struct *mm;
81639- int ret;
81640+ ssize_t ret;
81641
81642 mm = get_task_mm(tsk);
81643 if (!mm)
81644diff --git a/mm/mempolicy.c b/mm/mempolicy.c
81645index 7431001..0f8344e 100644
81646--- a/mm/mempolicy.c
81647+++ b/mm/mempolicy.c
81648@@ -708,6 +708,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
81649 unsigned long vmstart;
81650 unsigned long vmend;
81651
81652+#ifdef CONFIG_PAX_SEGMEXEC
81653+ struct vm_area_struct *vma_m;
81654+#endif
81655+
81656 vma = find_vma(mm, start);
81657 if (!vma || vma->vm_start > start)
81658 return -EFAULT;
81659@@ -744,9 +748,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
81660 if (err)
81661 goto out;
81662 }
81663+
81664 err = vma_replace_policy(vma, new_pol);
81665 if (err)
81666 goto out;
81667+
81668+#ifdef CONFIG_PAX_SEGMEXEC
81669+ vma_m = pax_find_mirror_vma(vma);
81670+ if (vma_m) {
81671+ err = vma_replace_policy(vma_m, new_pol);
81672+ if (err)
81673+ goto out;
81674+ }
81675+#endif
81676+
81677 }
81678
81679 out:
81680@@ -1202,6 +1217,17 @@ static long do_mbind(unsigned long start, unsigned long len,
81681
81682 if (end < start)
81683 return -EINVAL;
81684+
81685+#ifdef CONFIG_PAX_SEGMEXEC
81686+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
81687+ if (end > SEGMEXEC_TASK_SIZE)
81688+ return -EINVAL;
81689+ } else
81690+#endif
81691+
81692+ if (end > TASK_SIZE)
81693+ return -EINVAL;
81694+
81695 if (end == start)
81696 return 0;
81697
81698@@ -1430,8 +1456,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
81699 */
81700 tcred = __task_cred(task);
81701 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
81702- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
81703- !capable(CAP_SYS_NICE)) {
81704+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
81705 rcu_read_unlock();
81706 err = -EPERM;
81707 goto out_put;
81708@@ -1462,6 +1487,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
81709 goto out;
81710 }
81711
81712+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81713+ if (mm != current->mm &&
81714+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
81715+ mmput(mm);
81716+ err = -EPERM;
81717+ goto out;
81718+ }
81719+#endif
81720+
81721 err = do_migrate_pages(mm, old, new,
81722 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
81723
81724diff --git a/mm/migrate.c b/mm/migrate.c
81725index 22ed5c1..87c424c 100644
81726--- a/mm/migrate.c
81727+++ b/mm/migrate.c
81728@@ -1382,8 +1382,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
81729 */
81730 tcred = __task_cred(task);
81731 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
81732- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
81733- !capable(CAP_SYS_NICE)) {
81734+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
81735 rcu_read_unlock();
81736 err = -EPERM;
81737 goto out;
81738diff --git a/mm/mlock.c b/mm/mlock.c
81739index 79b7cf7..9944291 100644
81740--- a/mm/mlock.c
81741+++ b/mm/mlock.c
81742@@ -13,6 +13,7 @@
81743 #include <linux/pagemap.h>
81744 #include <linux/mempolicy.h>
81745 #include <linux/syscalls.h>
81746+#include <linux/security.h>
81747 #include <linux/sched.h>
81748 #include <linux/export.h>
81749 #include <linux/rmap.h>
81750@@ -334,7 +335,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
81751 {
81752 unsigned long nstart, end, tmp;
81753 struct vm_area_struct * vma, * prev;
81754- int error;
81755+ int error = 0;
81756
81757 VM_BUG_ON(start & ~PAGE_MASK);
81758 VM_BUG_ON(len != PAGE_ALIGN(len));
81759@@ -343,6 +344,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
81760 return -EINVAL;
81761 if (end == start)
81762 return 0;
81763+ if (end > TASK_SIZE)
81764+ return -EINVAL;
81765+
81766 vma = find_vma(current->mm, start);
81767 if (!vma || vma->vm_start > start)
81768 return -ENOMEM;
81769@@ -354,6 +358,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
81770 for (nstart = start ; ; ) {
81771 vm_flags_t newflags;
81772
81773+#ifdef CONFIG_PAX_SEGMEXEC
81774+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
81775+ break;
81776+#endif
81777+
81778 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
81779
81780 newflags = vma->vm_flags & ~VM_LOCKED;
81781@@ -466,6 +475,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
81782 lock_limit >>= PAGE_SHIFT;
81783
81784 /* check against resource limits */
81785+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
81786 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
81787 error = do_mlock(start, len, 1);
81788 up_write(&current->mm->mmap_sem);
81789@@ -500,6 +510,11 @@ static int do_mlockall(int flags)
81790 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
81791 vm_flags_t newflags;
81792
81793+#ifdef CONFIG_PAX_SEGMEXEC
81794+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
81795+ break;
81796+#endif
81797+
81798 newflags = vma->vm_flags & ~VM_LOCKED;
81799 if (flags & MCL_CURRENT)
81800 newflags |= VM_LOCKED;
81801@@ -532,6 +547,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
81802 lock_limit >>= PAGE_SHIFT;
81803
81804 ret = -ENOMEM;
81805+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
81806 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
81807 capable(CAP_IPC_LOCK))
81808 ret = do_mlockall(flags);
81809diff --git a/mm/mmap.c b/mm/mmap.c
81810index 0dceed8..e7cfc40 100644
81811--- a/mm/mmap.c
81812+++ b/mm/mmap.c
81813@@ -33,6 +33,7 @@
81814 #include <linux/uprobes.h>
81815 #include <linux/rbtree_augmented.h>
81816 #include <linux/sched/sysctl.h>
81817+#include <linux/random.h>
81818
81819 #include <asm/uaccess.h>
81820 #include <asm/cacheflush.h>
81821@@ -49,6 +50,16 @@
81822 #define arch_rebalance_pgtables(addr, len) (addr)
81823 #endif
81824
81825+static inline void verify_mm_writelocked(struct mm_struct *mm)
81826+{
81827+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
81828+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
81829+ up_read(&mm->mmap_sem);
81830+ BUG();
81831+ }
81832+#endif
81833+}
81834+
81835 static void unmap_region(struct mm_struct *mm,
81836 struct vm_area_struct *vma, struct vm_area_struct *prev,
81837 unsigned long start, unsigned long end);
81838@@ -68,22 +79,32 @@ static void unmap_region(struct mm_struct *mm,
81839 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
81840 *
81841 */
81842-pgprot_t protection_map[16] = {
81843+pgprot_t protection_map[16] __read_only = {
81844 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
81845 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
81846 };
81847
81848-pgprot_t vm_get_page_prot(unsigned long vm_flags)
81849+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
81850 {
81851- return __pgprot(pgprot_val(protection_map[vm_flags &
81852+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
81853 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
81854 pgprot_val(arch_vm_get_page_prot(vm_flags)));
81855+
81856+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
81857+ if (!(__supported_pte_mask & _PAGE_NX) &&
81858+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
81859+ (vm_flags & (VM_READ | VM_WRITE)))
81860+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
81861+#endif
81862+
81863+ return prot;
81864 }
81865 EXPORT_SYMBOL(vm_get_page_prot);
81866
81867 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
81868 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
81869 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
81870+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
81871 /*
81872 * Make sure vm_committed_as in one cacheline and not cacheline shared with
81873 * other variables. It can be updated by several CPUs frequently.
81874@@ -239,6 +260,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
81875 struct vm_area_struct *next = vma->vm_next;
81876
81877 might_sleep();
81878+ BUG_ON(vma->vm_mirror);
81879 if (vma->vm_ops && vma->vm_ops->close)
81880 vma->vm_ops->close(vma);
81881 if (vma->vm_file)
81882@@ -283,6 +305,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
81883 * not page aligned -Ram Gupta
81884 */
81885 rlim = rlimit(RLIMIT_DATA);
81886+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
81887 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
81888 (mm->end_data - mm->start_data) > rlim)
81889 goto out;
81890@@ -897,6 +920,12 @@ static int
81891 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
81892 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
81893 {
81894+
81895+#ifdef CONFIG_PAX_SEGMEXEC
81896+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
81897+ return 0;
81898+#endif
81899+
81900 if (is_mergeable_vma(vma, file, vm_flags) &&
81901 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
81902 if (vma->vm_pgoff == vm_pgoff)
81903@@ -916,6 +945,12 @@ static int
81904 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
81905 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
81906 {
81907+
81908+#ifdef CONFIG_PAX_SEGMEXEC
81909+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
81910+ return 0;
81911+#endif
81912+
81913 if (is_mergeable_vma(vma, file, vm_flags) &&
81914 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
81915 pgoff_t vm_pglen;
81916@@ -958,13 +993,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
81917 struct vm_area_struct *vma_merge(struct mm_struct *mm,
81918 struct vm_area_struct *prev, unsigned long addr,
81919 unsigned long end, unsigned long vm_flags,
81920- struct anon_vma *anon_vma, struct file *file,
81921+ struct anon_vma *anon_vma, struct file *file,
81922 pgoff_t pgoff, struct mempolicy *policy)
81923 {
81924 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
81925 struct vm_area_struct *area, *next;
81926 int err;
81927
81928+#ifdef CONFIG_PAX_SEGMEXEC
81929+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
81930+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
81931+
81932+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
81933+#endif
81934+
81935 /*
81936 * We later require that vma->vm_flags == vm_flags,
81937 * so this tests vma->vm_flags & VM_SPECIAL, too.
81938@@ -980,6 +1022,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
81939 if (next && next->vm_end == end) /* cases 6, 7, 8 */
81940 next = next->vm_next;
81941
81942+#ifdef CONFIG_PAX_SEGMEXEC
81943+ if (prev)
81944+ prev_m = pax_find_mirror_vma(prev);
81945+ if (area)
81946+ area_m = pax_find_mirror_vma(area);
81947+ if (next)
81948+ next_m = pax_find_mirror_vma(next);
81949+#endif
81950+
81951 /*
81952 * Can it merge with the predecessor?
81953 */
81954@@ -999,9 +1050,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
81955 /* cases 1, 6 */
81956 err = vma_adjust(prev, prev->vm_start,
81957 next->vm_end, prev->vm_pgoff, NULL);
81958- } else /* cases 2, 5, 7 */
81959+
81960+#ifdef CONFIG_PAX_SEGMEXEC
81961+ if (!err && prev_m)
81962+ err = vma_adjust(prev_m, prev_m->vm_start,
81963+ next_m->vm_end, prev_m->vm_pgoff, NULL);
81964+#endif
81965+
81966+ } else { /* cases 2, 5, 7 */
81967 err = vma_adjust(prev, prev->vm_start,
81968 end, prev->vm_pgoff, NULL);
81969+
81970+#ifdef CONFIG_PAX_SEGMEXEC
81971+ if (!err && prev_m)
81972+ err = vma_adjust(prev_m, prev_m->vm_start,
81973+ end_m, prev_m->vm_pgoff, NULL);
81974+#endif
81975+
81976+ }
81977 if (err)
81978 return NULL;
81979 khugepaged_enter_vma_merge(prev);
81980@@ -1015,12 +1081,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
81981 mpol_equal(policy, vma_policy(next)) &&
81982 can_vma_merge_before(next, vm_flags,
81983 anon_vma, file, pgoff+pglen)) {
81984- if (prev && addr < prev->vm_end) /* case 4 */
81985+ if (prev && addr < prev->vm_end) { /* case 4 */
81986 err = vma_adjust(prev, prev->vm_start,
81987 addr, prev->vm_pgoff, NULL);
81988- else /* cases 3, 8 */
81989+
81990+#ifdef CONFIG_PAX_SEGMEXEC
81991+ if (!err && prev_m)
81992+ err = vma_adjust(prev_m, prev_m->vm_start,
81993+ addr_m, prev_m->vm_pgoff, NULL);
81994+#endif
81995+
81996+ } else { /* cases 3, 8 */
81997 err = vma_adjust(area, addr, next->vm_end,
81998 next->vm_pgoff - pglen, NULL);
81999+
82000+#ifdef CONFIG_PAX_SEGMEXEC
82001+ if (!err && area_m)
82002+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
82003+ next_m->vm_pgoff - pglen, NULL);
82004+#endif
82005+
82006+ }
82007 if (err)
82008 return NULL;
82009 khugepaged_enter_vma_merge(area);
82010@@ -1129,8 +1210,10 @@ none:
82011 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
82012 struct file *file, long pages)
82013 {
82014- const unsigned long stack_flags
82015- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
82016+
82017+#ifdef CONFIG_PAX_RANDMMAP
82018+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
82019+#endif
82020
82021 mm->total_vm += pages;
82022
82023@@ -1138,7 +1221,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
82024 mm->shared_vm += pages;
82025 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
82026 mm->exec_vm += pages;
82027- } else if (flags & stack_flags)
82028+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
82029 mm->stack_vm += pages;
82030 }
82031 #endif /* CONFIG_PROC_FS */
82032@@ -1177,7 +1260,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82033 * (the exception is when the underlying filesystem is noexec
82034 * mounted, in which case we dont add PROT_EXEC.)
82035 */
82036- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
82037+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
82038 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
82039 prot |= PROT_EXEC;
82040
82041@@ -1203,7 +1286,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82042 /* Obtain the address to map to. we verify (or select) it and ensure
82043 * that it represents a valid section of the address space.
82044 */
82045- addr = get_unmapped_area(file, addr, len, pgoff, flags);
82046+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
82047 if (addr & ~PAGE_MASK)
82048 return addr;
82049
82050@@ -1214,6 +1297,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82051 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
82052 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
82053
82054+#ifdef CONFIG_PAX_MPROTECT
82055+ if (mm->pax_flags & MF_PAX_MPROTECT) {
82056+#ifndef CONFIG_PAX_MPROTECT_COMPAT
82057+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
82058+ gr_log_rwxmmap(file);
82059+
82060+#ifdef CONFIG_PAX_EMUPLT
82061+ vm_flags &= ~VM_EXEC;
82062+#else
82063+ return -EPERM;
82064+#endif
82065+
82066+ }
82067+
82068+ if (!(vm_flags & VM_EXEC))
82069+ vm_flags &= ~VM_MAYEXEC;
82070+#else
82071+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
82072+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
82073+#endif
82074+ else
82075+ vm_flags &= ~VM_MAYWRITE;
82076+ }
82077+#endif
82078+
82079+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82080+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
82081+ vm_flags &= ~VM_PAGEEXEC;
82082+#endif
82083+
82084 if (flags & MAP_LOCKED)
82085 if (!can_do_mlock())
82086 return -EPERM;
82087@@ -1225,6 +1338,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82088 locked += mm->locked_vm;
82089 lock_limit = rlimit(RLIMIT_MEMLOCK);
82090 lock_limit >>= PAGE_SHIFT;
82091+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
82092 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
82093 return -EAGAIN;
82094 }
82095@@ -1305,6 +1419,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82096 vm_flags |= VM_NORESERVE;
82097 }
82098
82099+ if (!gr_acl_handle_mmap(file, prot))
82100+ return -EACCES;
82101+
82102 addr = mmap_region(file, addr, len, vm_flags, pgoff);
82103 if (!IS_ERR_VALUE(addr) &&
82104 ((vm_flags & VM_LOCKED) ||
82105@@ -1396,7 +1513,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
82106 vm_flags_t vm_flags = vma->vm_flags;
82107
82108 /* If it was private or non-writable, the write bit is already clear */
82109- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
82110+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
82111 return 0;
82112
82113 /* The backer wishes to know when pages are first written to? */
82114@@ -1444,16 +1561,30 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
82115 unsigned long charged = 0;
82116 struct inode *inode = file ? file_inode(file) : NULL;
82117
82118+#ifdef CONFIG_PAX_SEGMEXEC
82119+ struct vm_area_struct *vma_m = NULL;
82120+#endif
82121+
82122+ /*
82123+ * mm->mmap_sem is required to protect against another thread
82124+ * changing the mappings in case we sleep.
82125+ */
82126+ verify_mm_writelocked(mm);
82127+
82128 /* Clear old maps */
82129 error = -ENOMEM;
82130-munmap_back:
82131 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
82132 if (do_munmap(mm, addr, len))
82133 return -ENOMEM;
82134- goto munmap_back;
82135+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
82136 }
82137
82138 /* Check against address space limit. */
82139+
82140+#ifdef CONFIG_PAX_RANDMMAP
82141+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
82142+#endif
82143+
82144 if (!may_expand_vm(mm, len >> PAGE_SHIFT))
82145 return -ENOMEM;
82146
82147@@ -1485,6 +1616,16 @@ munmap_back:
82148 goto unacct_error;
82149 }
82150
82151+#ifdef CONFIG_PAX_SEGMEXEC
82152+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
82153+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82154+ if (!vma_m) {
82155+ error = -ENOMEM;
82156+ goto free_vma;
82157+ }
82158+ }
82159+#endif
82160+
82161 vma->vm_mm = mm;
82162 vma->vm_start = addr;
82163 vma->vm_end = addr + len;
82164@@ -1509,6 +1650,13 @@ munmap_back:
82165 if (error)
82166 goto unmap_and_free_vma;
82167
82168+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82169+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
82170+ vma->vm_flags |= VM_PAGEEXEC;
82171+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
82172+ }
82173+#endif
82174+
82175 /* Can addr have changed??
82176 *
82177 * Answer: Yes, several device drivers can do it in their
82178@@ -1547,6 +1695,11 @@ munmap_back:
82179 vma_link(mm, vma, prev, rb_link, rb_parent);
82180 file = vma->vm_file;
82181
82182+#ifdef CONFIG_PAX_SEGMEXEC
82183+ if (vma_m)
82184+ BUG_ON(pax_mirror_vma(vma_m, vma));
82185+#endif
82186+
82187 /* Once vma denies write, undo our temporary denial count */
82188 if (correct_wcount)
82189 atomic_inc(&inode->i_writecount);
82190@@ -1554,6 +1707,7 @@ out:
82191 perf_event_mmap(vma);
82192
82193 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
82194+ track_exec_limit(mm, addr, addr + len, vm_flags);
82195 if (vm_flags & VM_LOCKED) {
82196 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
82197 vma == get_gate_vma(current->mm)))
82198@@ -1577,6 +1731,12 @@ unmap_and_free_vma:
82199 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
82200 charged = 0;
82201 free_vma:
82202+
82203+#ifdef CONFIG_PAX_SEGMEXEC
82204+ if (vma_m)
82205+ kmem_cache_free(vm_area_cachep, vma_m);
82206+#endif
82207+
82208 kmem_cache_free(vm_area_cachep, vma);
82209 unacct_error:
82210 if (charged)
82211@@ -1584,6 +1744,62 @@ unacct_error:
82212 return error;
82213 }
82214
82215+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
82216+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
82217+{
82218+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
82219+ return (random32() & 0xFF) << PAGE_SHIFT;
82220+
82221+ return 0;
82222+}
82223+#endif
82224+
82225+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
82226+{
82227+ if (!vma) {
82228+#ifdef CONFIG_STACK_GROWSUP
82229+ if (addr > sysctl_heap_stack_gap)
82230+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
82231+ else
82232+ vma = find_vma(current->mm, 0);
82233+ if (vma && (vma->vm_flags & VM_GROWSUP))
82234+ return false;
82235+#endif
82236+ return true;
82237+ }
82238+
82239+ if (addr + len > vma->vm_start)
82240+ return false;
82241+
82242+ if (vma->vm_flags & VM_GROWSDOWN)
82243+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
82244+#ifdef CONFIG_STACK_GROWSUP
82245+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
82246+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
82247+#endif
82248+ else if (offset)
82249+ return offset <= vma->vm_start - addr - len;
82250+
82251+ return true;
82252+}
82253+
82254+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
82255+{
82256+ if (vma->vm_start < len)
82257+ return -ENOMEM;
82258+
82259+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
82260+ if (offset <= vma->vm_start - len)
82261+ return vma->vm_start - len - offset;
82262+ else
82263+ return -ENOMEM;
82264+ }
82265+
82266+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
82267+ return vma->vm_start - len - sysctl_heap_stack_gap;
82268+ return -ENOMEM;
82269+}
82270+
82271 unsigned long unmapped_area(struct vm_unmapped_area_info *info)
82272 {
82273 /*
82274@@ -1803,6 +2019,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
82275 struct mm_struct *mm = current->mm;
82276 struct vm_area_struct *vma;
82277 struct vm_unmapped_area_info info;
82278+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
82279
82280 if (len > TASK_SIZE)
82281 return -ENOMEM;
82282@@ -1810,29 +2027,45 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
82283 if (flags & MAP_FIXED)
82284 return addr;
82285
82286+#ifdef CONFIG_PAX_RANDMMAP
82287+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
82288+#endif
82289+
82290 if (addr) {
82291 addr = PAGE_ALIGN(addr);
82292 vma = find_vma(mm, addr);
82293- if (TASK_SIZE - len >= addr &&
82294- (!vma || addr + len <= vma->vm_start))
82295+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
82296 return addr;
82297 }
82298
82299 info.flags = 0;
82300 info.length = len;
82301 info.low_limit = TASK_UNMAPPED_BASE;
82302+
82303+#ifdef CONFIG_PAX_RANDMMAP
82304+ if (mm->pax_flags & MF_PAX_RANDMMAP)
82305+ info.low_limit += mm->delta_mmap;
82306+#endif
82307+
82308 info.high_limit = TASK_SIZE;
82309 info.align_mask = 0;
82310+ info.threadstack_offset = offset;
82311 return vm_unmapped_area(&info);
82312 }
82313 #endif
82314
82315 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
82316 {
82317+
82318+#ifdef CONFIG_PAX_SEGMEXEC
82319+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
82320+ return;
82321+#endif
82322+
82323 /*
82324 * Is this a new hole at the lowest possible address?
82325 */
82326- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
82327+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
82328 mm->free_area_cache = addr;
82329 }
82330
82331@@ -1850,6 +2083,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82332 struct mm_struct *mm = current->mm;
82333 unsigned long addr = addr0;
82334 struct vm_unmapped_area_info info;
82335+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
82336
82337 /* requested length too big for entire address space */
82338 if (len > TASK_SIZE)
82339@@ -1858,12 +2092,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82340 if (flags & MAP_FIXED)
82341 return addr;
82342
82343+#ifdef CONFIG_PAX_RANDMMAP
82344+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
82345+#endif
82346+
82347 /* requesting a specific address */
82348 if (addr) {
82349 addr = PAGE_ALIGN(addr);
82350 vma = find_vma(mm, addr);
82351- if (TASK_SIZE - len >= addr &&
82352- (!vma || addr + len <= vma->vm_start))
82353+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
82354 return addr;
82355 }
82356
82357@@ -1872,6 +2109,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82358 info.low_limit = PAGE_SIZE;
82359 info.high_limit = mm->mmap_base;
82360 info.align_mask = 0;
82361+ info.threadstack_offset = offset;
82362 addr = vm_unmapped_area(&info);
82363
82364 /*
82365@@ -1884,6 +2122,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82366 VM_BUG_ON(addr != -ENOMEM);
82367 info.flags = 0;
82368 info.low_limit = TASK_UNMAPPED_BASE;
82369+
82370+#ifdef CONFIG_PAX_RANDMMAP
82371+ if (mm->pax_flags & MF_PAX_RANDMMAP)
82372+ info.low_limit += mm->delta_mmap;
82373+#endif
82374+
82375 info.high_limit = TASK_SIZE;
82376 addr = vm_unmapped_area(&info);
82377 }
82378@@ -1894,6 +2138,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82379
82380 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
82381 {
82382+
82383+#ifdef CONFIG_PAX_SEGMEXEC
82384+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
82385+ return;
82386+#endif
82387+
82388 /*
82389 * Is this a new hole at the highest possible address?
82390 */
82391@@ -1901,8 +2151,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
82392 mm->free_area_cache = addr;
82393
82394 /* dont allow allocations above current base */
82395- if (mm->free_area_cache > mm->mmap_base)
82396+ if (mm->free_area_cache > mm->mmap_base) {
82397 mm->free_area_cache = mm->mmap_base;
82398+ mm->cached_hole_size = ~0UL;
82399+ }
82400 }
82401
82402 unsigned long
82403@@ -2001,6 +2253,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
82404 return vma;
82405 }
82406
82407+#ifdef CONFIG_PAX_SEGMEXEC
82408+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
82409+{
82410+ struct vm_area_struct *vma_m;
82411+
82412+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
82413+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
82414+ BUG_ON(vma->vm_mirror);
82415+ return NULL;
82416+ }
82417+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
82418+ vma_m = vma->vm_mirror;
82419+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
82420+ BUG_ON(vma->vm_file != vma_m->vm_file);
82421+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
82422+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
82423+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
82424+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
82425+ return vma_m;
82426+}
82427+#endif
82428+
82429 /*
82430 * Verify that the stack growth is acceptable and
82431 * update accounting. This is shared with both the
82432@@ -2017,6 +2291,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
82433 return -ENOMEM;
82434
82435 /* Stack limit test */
82436+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
82437 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
82438 return -ENOMEM;
82439
82440@@ -2027,6 +2302,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
82441 locked = mm->locked_vm + grow;
82442 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
82443 limit >>= PAGE_SHIFT;
82444+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
82445 if (locked > limit && !capable(CAP_IPC_LOCK))
82446 return -ENOMEM;
82447 }
82448@@ -2056,37 +2332,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
82449 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
82450 * vma is the last one with address > vma->vm_end. Have to extend vma.
82451 */
82452+#ifndef CONFIG_IA64
82453+static
82454+#endif
82455 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
82456 {
82457 int error;
82458+ bool locknext;
82459
82460 if (!(vma->vm_flags & VM_GROWSUP))
82461 return -EFAULT;
82462
82463+ /* Also guard against wrapping around to address 0. */
82464+ if (address < PAGE_ALIGN(address+1))
82465+ address = PAGE_ALIGN(address+1);
82466+ else
82467+ return -ENOMEM;
82468+
82469 /*
82470 * We must make sure the anon_vma is allocated
82471 * so that the anon_vma locking is not a noop.
82472 */
82473 if (unlikely(anon_vma_prepare(vma)))
82474 return -ENOMEM;
82475+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
82476+ if (locknext && anon_vma_prepare(vma->vm_next))
82477+ return -ENOMEM;
82478 vma_lock_anon_vma(vma);
82479+ if (locknext)
82480+ vma_lock_anon_vma(vma->vm_next);
82481
82482 /*
82483 * vma->vm_start/vm_end cannot change under us because the caller
82484 * is required to hold the mmap_sem in read mode. We need the
82485- * anon_vma lock to serialize against concurrent expand_stacks.
82486- * Also guard against wrapping around to address 0.
82487+ * anon_vma locks to serialize against concurrent expand_stacks
82488+ * and expand_upwards.
82489 */
82490- if (address < PAGE_ALIGN(address+4))
82491- address = PAGE_ALIGN(address+4);
82492- else {
82493- vma_unlock_anon_vma(vma);
82494- return -ENOMEM;
82495- }
82496 error = 0;
82497
82498 /* Somebody else might have raced and expanded it already */
82499- if (address > vma->vm_end) {
82500+ 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)
82501+ error = -ENOMEM;
82502+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
82503 unsigned long size, grow;
82504
82505 size = address - vma->vm_start;
82506@@ -2121,6 +2408,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
82507 }
82508 }
82509 }
82510+ if (locknext)
82511+ vma_unlock_anon_vma(vma->vm_next);
82512 vma_unlock_anon_vma(vma);
82513 khugepaged_enter_vma_merge(vma);
82514 validate_mm(vma->vm_mm);
82515@@ -2135,6 +2424,8 @@ int expand_downwards(struct vm_area_struct *vma,
82516 unsigned long address)
82517 {
82518 int error;
82519+ bool lockprev = false;
82520+ struct vm_area_struct *prev;
82521
82522 /*
82523 * We must make sure the anon_vma is allocated
82524@@ -2148,6 +2439,15 @@ int expand_downwards(struct vm_area_struct *vma,
82525 if (error)
82526 return error;
82527
82528+ prev = vma->vm_prev;
82529+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
82530+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
82531+#endif
82532+ if (lockprev && anon_vma_prepare(prev))
82533+ return -ENOMEM;
82534+ if (lockprev)
82535+ vma_lock_anon_vma(prev);
82536+
82537 vma_lock_anon_vma(vma);
82538
82539 /*
82540@@ -2157,9 +2457,17 @@ int expand_downwards(struct vm_area_struct *vma,
82541 */
82542
82543 /* Somebody else might have raced and expanded it already */
82544- if (address < vma->vm_start) {
82545+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
82546+ error = -ENOMEM;
82547+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
82548 unsigned long size, grow;
82549
82550+#ifdef CONFIG_PAX_SEGMEXEC
82551+ struct vm_area_struct *vma_m;
82552+
82553+ vma_m = pax_find_mirror_vma(vma);
82554+#endif
82555+
82556 size = vma->vm_end - address;
82557 grow = (vma->vm_start - address) >> PAGE_SHIFT;
82558
82559@@ -2184,13 +2492,27 @@ int expand_downwards(struct vm_area_struct *vma,
82560 vma->vm_pgoff -= grow;
82561 anon_vma_interval_tree_post_update_vma(vma);
82562 vma_gap_update(vma);
82563+
82564+#ifdef CONFIG_PAX_SEGMEXEC
82565+ if (vma_m) {
82566+ anon_vma_interval_tree_pre_update_vma(vma_m);
82567+ vma_m->vm_start -= grow << PAGE_SHIFT;
82568+ vma_m->vm_pgoff -= grow;
82569+ anon_vma_interval_tree_post_update_vma(vma_m);
82570+ vma_gap_update(vma_m);
82571+ }
82572+#endif
82573+
82574 spin_unlock(&vma->vm_mm->page_table_lock);
82575
82576+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
82577 perf_event_mmap(vma);
82578 }
82579 }
82580 }
82581 vma_unlock_anon_vma(vma);
82582+ if (lockprev)
82583+ vma_unlock_anon_vma(prev);
82584 khugepaged_enter_vma_merge(vma);
82585 validate_mm(vma->vm_mm);
82586 return error;
82587@@ -2288,6 +2610,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
82588 do {
82589 long nrpages = vma_pages(vma);
82590
82591+#ifdef CONFIG_PAX_SEGMEXEC
82592+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
82593+ vma = remove_vma(vma);
82594+ continue;
82595+ }
82596+#endif
82597+
82598 if (vma->vm_flags & VM_ACCOUNT)
82599 nr_accounted += nrpages;
82600 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
82601@@ -2333,6 +2662,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
82602 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
82603 vma->vm_prev = NULL;
82604 do {
82605+
82606+#ifdef CONFIG_PAX_SEGMEXEC
82607+ if (vma->vm_mirror) {
82608+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
82609+ vma->vm_mirror->vm_mirror = NULL;
82610+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
82611+ vma->vm_mirror = NULL;
82612+ }
82613+#endif
82614+
82615 vma_rb_erase(vma, &mm->mm_rb);
82616 mm->map_count--;
82617 tail_vma = vma;
82618@@ -2364,14 +2703,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
82619 struct vm_area_struct *new;
82620 int err = -ENOMEM;
82621
82622+#ifdef CONFIG_PAX_SEGMEXEC
82623+ struct vm_area_struct *vma_m, *new_m = NULL;
82624+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
82625+#endif
82626+
82627 if (is_vm_hugetlb_page(vma) && (addr &
82628 ~(huge_page_mask(hstate_vma(vma)))))
82629 return -EINVAL;
82630
82631+#ifdef CONFIG_PAX_SEGMEXEC
82632+ vma_m = pax_find_mirror_vma(vma);
82633+#endif
82634+
82635 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
82636 if (!new)
82637 goto out_err;
82638
82639+#ifdef CONFIG_PAX_SEGMEXEC
82640+ if (vma_m) {
82641+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
82642+ if (!new_m) {
82643+ kmem_cache_free(vm_area_cachep, new);
82644+ goto out_err;
82645+ }
82646+ }
82647+#endif
82648+
82649 /* most fields are the same, copy all, and then fixup */
82650 *new = *vma;
82651
82652@@ -2384,6 +2742,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
82653 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
82654 }
82655
82656+#ifdef CONFIG_PAX_SEGMEXEC
82657+ if (vma_m) {
82658+ *new_m = *vma_m;
82659+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
82660+ new_m->vm_mirror = new;
82661+ new->vm_mirror = new_m;
82662+
82663+ if (new_below)
82664+ new_m->vm_end = addr_m;
82665+ else {
82666+ new_m->vm_start = addr_m;
82667+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
82668+ }
82669+ }
82670+#endif
82671+
82672 pol = mpol_dup(vma_policy(vma));
82673 if (IS_ERR(pol)) {
82674 err = PTR_ERR(pol);
82675@@ -2406,6 +2780,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
82676 else
82677 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
82678
82679+#ifdef CONFIG_PAX_SEGMEXEC
82680+ if (!err && vma_m) {
82681+ if (anon_vma_clone(new_m, vma_m))
82682+ goto out_free_mpol;
82683+
82684+ mpol_get(pol);
82685+ vma_set_policy(new_m, pol);
82686+
82687+ if (new_m->vm_file)
82688+ get_file(new_m->vm_file);
82689+
82690+ if (new_m->vm_ops && new_m->vm_ops->open)
82691+ new_m->vm_ops->open(new_m);
82692+
82693+ if (new_below)
82694+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
82695+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
82696+ else
82697+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
82698+
82699+ if (err) {
82700+ if (new_m->vm_ops && new_m->vm_ops->close)
82701+ new_m->vm_ops->close(new_m);
82702+ if (new_m->vm_file)
82703+ fput(new_m->vm_file);
82704+ mpol_put(pol);
82705+ }
82706+ }
82707+#endif
82708+
82709 /* Success. */
82710 if (!err)
82711 return 0;
82712@@ -2415,10 +2819,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
82713 new->vm_ops->close(new);
82714 if (new->vm_file)
82715 fput(new->vm_file);
82716- unlink_anon_vmas(new);
82717 out_free_mpol:
82718 mpol_put(pol);
82719 out_free_vma:
82720+
82721+#ifdef CONFIG_PAX_SEGMEXEC
82722+ if (new_m) {
82723+ unlink_anon_vmas(new_m);
82724+ kmem_cache_free(vm_area_cachep, new_m);
82725+ }
82726+#endif
82727+
82728+ unlink_anon_vmas(new);
82729 kmem_cache_free(vm_area_cachep, new);
82730 out_err:
82731 return err;
82732@@ -2431,6 +2843,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
82733 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
82734 unsigned long addr, int new_below)
82735 {
82736+
82737+#ifdef CONFIG_PAX_SEGMEXEC
82738+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
82739+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
82740+ if (mm->map_count >= sysctl_max_map_count-1)
82741+ return -ENOMEM;
82742+ } else
82743+#endif
82744+
82745 if (mm->map_count >= sysctl_max_map_count)
82746 return -ENOMEM;
82747
82748@@ -2442,11 +2863,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
82749 * work. This now handles partial unmappings.
82750 * Jeremy Fitzhardinge <jeremy@goop.org>
82751 */
82752+#ifdef CONFIG_PAX_SEGMEXEC
82753 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
82754 {
82755+ int ret = __do_munmap(mm, start, len);
82756+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
82757+ return ret;
82758+
82759+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
82760+}
82761+
82762+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
82763+#else
82764+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
82765+#endif
82766+{
82767 unsigned long end;
82768 struct vm_area_struct *vma, *prev, *last;
82769
82770+ /*
82771+ * mm->mmap_sem is required to protect against another thread
82772+ * changing the mappings in case we sleep.
82773+ */
82774+ verify_mm_writelocked(mm);
82775+
82776 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
82777 return -EINVAL;
82778
82779@@ -2521,6 +2961,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
82780 /* Fix up all other VM information */
82781 remove_vma_list(mm, vma);
82782
82783+ track_exec_limit(mm, start, end, 0UL);
82784+
82785 return 0;
82786 }
82787
82788@@ -2529,6 +2971,13 @@ int vm_munmap(unsigned long start, size_t len)
82789 int ret;
82790 struct mm_struct *mm = current->mm;
82791
82792+
82793+#ifdef CONFIG_PAX_SEGMEXEC
82794+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
82795+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
82796+ return -EINVAL;
82797+#endif
82798+
82799 down_write(&mm->mmap_sem);
82800 ret = do_munmap(mm, start, len);
82801 up_write(&mm->mmap_sem);
82802@@ -2542,16 +2991,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
82803 return vm_munmap(addr, len);
82804 }
82805
82806-static inline void verify_mm_writelocked(struct mm_struct *mm)
82807-{
82808-#ifdef CONFIG_DEBUG_VM
82809- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
82810- WARN_ON(1);
82811- up_read(&mm->mmap_sem);
82812- }
82813-#endif
82814-}
82815-
82816 /*
82817 * this is really a simplified "do_mmap". it only handles
82818 * anonymous maps. eventually we may be able to do some
82819@@ -2565,6 +3004,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
82820 struct rb_node ** rb_link, * rb_parent;
82821 pgoff_t pgoff = addr >> PAGE_SHIFT;
82822 int error;
82823+ unsigned long charged;
82824
82825 len = PAGE_ALIGN(len);
82826 if (!len)
82827@@ -2572,16 +3012,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
82828
82829 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
82830
82831+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
82832+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
82833+ flags &= ~VM_EXEC;
82834+
82835+#ifdef CONFIG_PAX_MPROTECT
82836+ if (mm->pax_flags & MF_PAX_MPROTECT)
82837+ flags &= ~VM_MAYEXEC;
82838+#endif
82839+
82840+ }
82841+#endif
82842+
82843 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
82844 if (error & ~PAGE_MASK)
82845 return error;
82846
82847+ charged = len >> PAGE_SHIFT;
82848+
82849 /*
82850 * mlock MCL_FUTURE?
82851 */
82852 if (mm->def_flags & VM_LOCKED) {
82853 unsigned long locked, lock_limit;
82854- locked = len >> PAGE_SHIFT;
82855+ locked = charged;
82856 locked += mm->locked_vm;
82857 lock_limit = rlimit(RLIMIT_MEMLOCK);
82858 lock_limit >>= PAGE_SHIFT;
82859@@ -2598,21 +3052,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
82860 /*
82861 * Clear old maps. this also does some error checking for us
82862 */
82863- munmap_back:
82864 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
82865 if (do_munmap(mm, addr, len))
82866 return -ENOMEM;
82867- goto munmap_back;
82868+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
82869 }
82870
82871 /* Check against address space limits *after* clearing old maps... */
82872- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
82873+ if (!may_expand_vm(mm, charged))
82874 return -ENOMEM;
82875
82876 if (mm->map_count > sysctl_max_map_count)
82877 return -ENOMEM;
82878
82879- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
82880+ if (security_vm_enough_memory_mm(mm, charged))
82881 return -ENOMEM;
82882
82883 /* Can we just expand an old private anonymous mapping? */
82884@@ -2626,7 +3079,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
82885 */
82886 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82887 if (!vma) {
82888- vm_unacct_memory(len >> PAGE_SHIFT);
82889+ vm_unacct_memory(charged);
82890 return -ENOMEM;
82891 }
82892
82893@@ -2640,9 +3093,10 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
82894 vma_link(mm, vma, prev, rb_link, rb_parent);
82895 out:
82896 perf_event_mmap(vma);
82897- mm->total_vm += len >> PAGE_SHIFT;
82898+ mm->total_vm += charged;
82899 if (flags & VM_LOCKED)
82900- mm->locked_vm += (len >> PAGE_SHIFT);
82901+ mm->locked_vm += charged;
82902+ track_exec_limit(mm, addr, addr + len, flags);
82903 return addr;
82904 }
82905
82906@@ -2704,6 +3158,7 @@ void exit_mmap(struct mm_struct *mm)
82907 while (vma) {
82908 if (vma->vm_flags & VM_ACCOUNT)
82909 nr_accounted += vma_pages(vma);
82910+ vma->vm_mirror = NULL;
82911 vma = remove_vma(vma);
82912 }
82913 vm_unacct_memory(nr_accounted);
82914@@ -2720,6 +3175,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
82915 struct vm_area_struct *prev;
82916 struct rb_node **rb_link, *rb_parent;
82917
82918+#ifdef CONFIG_PAX_SEGMEXEC
82919+ struct vm_area_struct *vma_m = NULL;
82920+#endif
82921+
82922+ if (security_mmap_addr(vma->vm_start))
82923+ return -EPERM;
82924+
82925 /*
82926 * The vm_pgoff of a purely anonymous vma should be irrelevant
82927 * until its first write fault, when page's anon_vma and index
82928@@ -2743,7 +3205,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
82929 security_vm_enough_memory_mm(mm, vma_pages(vma)))
82930 return -ENOMEM;
82931
82932+#ifdef CONFIG_PAX_SEGMEXEC
82933+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
82934+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82935+ if (!vma_m)
82936+ return -ENOMEM;
82937+ }
82938+#endif
82939+
82940 vma_link(mm, vma, prev, rb_link, rb_parent);
82941+
82942+#ifdef CONFIG_PAX_SEGMEXEC
82943+ if (vma_m)
82944+ BUG_ON(pax_mirror_vma(vma_m, vma));
82945+#endif
82946+
82947 return 0;
82948 }
82949
82950@@ -2763,6 +3239,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
82951 struct mempolicy *pol;
82952 bool faulted_in_anon_vma = true;
82953
82954+ BUG_ON(vma->vm_mirror);
82955+
82956 /*
82957 * If anonymous vma has not yet been faulted, update new pgoff
82958 * to match new location, to increase its chance of merging.
82959@@ -2829,6 +3307,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
82960 return NULL;
82961 }
82962
82963+#ifdef CONFIG_PAX_SEGMEXEC
82964+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
82965+{
82966+ struct vm_area_struct *prev_m;
82967+ struct rb_node **rb_link_m, *rb_parent_m;
82968+ struct mempolicy *pol_m;
82969+
82970+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
82971+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
82972+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
82973+ *vma_m = *vma;
82974+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
82975+ if (anon_vma_clone(vma_m, vma))
82976+ return -ENOMEM;
82977+ pol_m = vma_policy(vma_m);
82978+ mpol_get(pol_m);
82979+ vma_set_policy(vma_m, pol_m);
82980+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
82981+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
82982+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
82983+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
82984+ if (vma_m->vm_file)
82985+ get_file(vma_m->vm_file);
82986+ if (vma_m->vm_ops && vma_m->vm_ops->open)
82987+ vma_m->vm_ops->open(vma_m);
82988+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
82989+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
82990+ vma_m->vm_mirror = vma;
82991+ vma->vm_mirror = vma_m;
82992+ return 0;
82993+}
82994+#endif
82995+
82996 /*
82997 * Return true if the calling process may expand its vm space by the passed
82998 * number of pages
82999@@ -2840,6 +3351,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
83000
83001 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
83002
83003+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
83004 if (cur + npages > lim)
83005 return 0;
83006 return 1;
83007@@ -2910,6 +3422,22 @@ int install_special_mapping(struct mm_struct *mm,
83008 vma->vm_start = addr;
83009 vma->vm_end = addr + len;
83010
83011+#ifdef CONFIG_PAX_MPROTECT
83012+ if (mm->pax_flags & MF_PAX_MPROTECT) {
83013+#ifndef CONFIG_PAX_MPROTECT_COMPAT
83014+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
83015+ return -EPERM;
83016+ if (!(vm_flags & VM_EXEC))
83017+ vm_flags &= ~VM_MAYEXEC;
83018+#else
83019+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
83020+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
83021+#endif
83022+ else
83023+ vm_flags &= ~VM_MAYWRITE;
83024+ }
83025+#endif
83026+
83027 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
83028 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
83029
83030diff --git a/mm/mprotect.c b/mm/mprotect.c
83031index 94722a4..07d9926 100644
83032--- a/mm/mprotect.c
83033+++ b/mm/mprotect.c
83034@@ -23,10 +23,18 @@
83035 #include <linux/mmu_notifier.h>
83036 #include <linux/migrate.h>
83037 #include <linux/perf_event.h>
83038+#include <linux/sched/sysctl.h>
83039+
83040+#ifdef CONFIG_PAX_MPROTECT
83041+#include <linux/elf.h>
83042+#include <linux/binfmts.h>
83043+#endif
83044+
83045 #include <asm/uaccess.h>
83046 #include <asm/pgtable.h>
83047 #include <asm/cacheflush.h>
83048 #include <asm/tlbflush.h>
83049+#include <asm/mmu_context.h>
83050
83051 #ifndef pgprot_modify
83052 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
83053@@ -233,6 +241,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
83054 return pages;
83055 }
83056
83057+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83058+/* called while holding the mmap semaphor for writing except stack expansion */
83059+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
83060+{
83061+ unsigned long oldlimit, newlimit = 0UL;
83062+
83063+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
83064+ return;
83065+
83066+ spin_lock(&mm->page_table_lock);
83067+ oldlimit = mm->context.user_cs_limit;
83068+ if ((prot & VM_EXEC) && oldlimit < end)
83069+ /* USER_CS limit moved up */
83070+ newlimit = end;
83071+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
83072+ /* USER_CS limit moved down */
83073+ newlimit = start;
83074+
83075+ if (newlimit) {
83076+ mm->context.user_cs_limit = newlimit;
83077+
83078+#ifdef CONFIG_SMP
83079+ wmb();
83080+ cpus_clear(mm->context.cpu_user_cs_mask);
83081+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
83082+#endif
83083+
83084+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
83085+ }
83086+ spin_unlock(&mm->page_table_lock);
83087+ if (newlimit == end) {
83088+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
83089+
83090+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
83091+ if (is_vm_hugetlb_page(vma))
83092+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
83093+ else
83094+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
83095+ }
83096+}
83097+#endif
83098+
83099 int
83100 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83101 unsigned long start, unsigned long end, unsigned long newflags)
83102@@ -245,11 +295,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83103 int error;
83104 int dirty_accountable = 0;
83105
83106+#ifdef CONFIG_PAX_SEGMEXEC
83107+ struct vm_area_struct *vma_m = NULL;
83108+ unsigned long start_m, end_m;
83109+
83110+ start_m = start + SEGMEXEC_TASK_SIZE;
83111+ end_m = end + SEGMEXEC_TASK_SIZE;
83112+#endif
83113+
83114 if (newflags == oldflags) {
83115 *pprev = vma;
83116 return 0;
83117 }
83118
83119+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
83120+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
83121+
83122+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
83123+ return -ENOMEM;
83124+
83125+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
83126+ return -ENOMEM;
83127+ }
83128+
83129 /*
83130 * If we make a private mapping writable we increase our commit;
83131 * but (without finer accounting) cannot reduce our commit if we
83132@@ -266,6 +334,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83133 }
83134 }
83135
83136+#ifdef CONFIG_PAX_SEGMEXEC
83137+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
83138+ if (start != vma->vm_start) {
83139+ error = split_vma(mm, vma, start, 1);
83140+ if (error)
83141+ goto fail;
83142+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
83143+ *pprev = (*pprev)->vm_next;
83144+ }
83145+
83146+ if (end != vma->vm_end) {
83147+ error = split_vma(mm, vma, end, 0);
83148+ if (error)
83149+ goto fail;
83150+ }
83151+
83152+ if (pax_find_mirror_vma(vma)) {
83153+ error = __do_munmap(mm, start_m, end_m - start_m);
83154+ if (error)
83155+ goto fail;
83156+ } else {
83157+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83158+ if (!vma_m) {
83159+ error = -ENOMEM;
83160+ goto fail;
83161+ }
83162+ vma->vm_flags = newflags;
83163+ error = pax_mirror_vma(vma_m, vma);
83164+ if (error) {
83165+ vma->vm_flags = oldflags;
83166+ goto fail;
83167+ }
83168+ }
83169+ }
83170+#endif
83171+
83172 /*
83173 * First try to merge with previous and/or next vma.
83174 */
83175@@ -296,9 +400,21 @@ success:
83176 * vm_flags and vm_page_prot are protected by the mmap_sem
83177 * held in write mode.
83178 */
83179+
83180+#ifdef CONFIG_PAX_SEGMEXEC
83181+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
83182+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
83183+#endif
83184+
83185 vma->vm_flags = newflags;
83186+
83187+#ifdef CONFIG_PAX_MPROTECT
83188+ if (mm->binfmt && mm->binfmt->handle_mprotect)
83189+ mm->binfmt->handle_mprotect(vma, newflags);
83190+#endif
83191+
83192 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
83193- vm_get_page_prot(newflags));
83194+ vm_get_page_prot(vma->vm_flags));
83195
83196 if (vma_wants_writenotify(vma)) {
83197 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
83198@@ -337,6 +453,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83199 end = start + len;
83200 if (end <= start)
83201 return -ENOMEM;
83202+
83203+#ifdef CONFIG_PAX_SEGMEXEC
83204+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
83205+ if (end > SEGMEXEC_TASK_SIZE)
83206+ return -EINVAL;
83207+ } else
83208+#endif
83209+
83210+ if (end > TASK_SIZE)
83211+ return -EINVAL;
83212+
83213 if (!arch_validate_prot(prot))
83214 return -EINVAL;
83215
83216@@ -344,7 +471,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83217 /*
83218 * Does the application expect PROT_READ to imply PROT_EXEC:
83219 */
83220- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
83221+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
83222 prot |= PROT_EXEC;
83223
83224 vm_flags = calc_vm_prot_bits(prot);
83225@@ -376,6 +503,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83226 if (start > vma->vm_start)
83227 prev = vma;
83228
83229+#ifdef CONFIG_PAX_MPROTECT
83230+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
83231+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
83232+#endif
83233+
83234 for (nstart = start ; ; ) {
83235 unsigned long newflags;
83236
83237@@ -386,6 +518,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83238
83239 /* newflags >> 4 shift VM_MAY% in place of VM_% */
83240 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
83241+ if (prot & (PROT_WRITE | PROT_EXEC))
83242+ gr_log_rwxmprotect(vma->vm_file);
83243+
83244+ error = -EACCES;
83245+ goto out;
83246+ }
83247+
83248+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
83249 error = -EACCES;
83250 goto out;
83251 }
83252@@ -400,6 +540,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83253 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
83254 if (error)
83255 goto out;
83256+
83257+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
83258+
83259 nstart = tmp;
83260
83261 if (nstart < prev->vm_end)
83262diff --git a/mm/mremap.c b/mm/mremap.c
83263index 463a257..c0c7a92 100644
83264--- a/mm/mremap.c
83265+++ b/mm/mremap.c
83266@@ -126,6 +126,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
83267 continue;
83268 pte = ptep_get_and_clear(mm, old_addr, old_pte);
83269 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
83270+
83271+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83272+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
83273+ pte = pte_exprotect(pte);
83274+#endif
83275+
83276 set_pte_at(mm, new_addr, new_pte, pte);
83277 }
83278
83279@@ -318,6 +324,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
83280 if (is_vm_hugetlb_page(vma))
83281 goto Einval;
83282
83283+#ifdef CONFIG_PAX_SEGMEXEC
83284+ if (pax_find_mirror_vma(vma))
83285+ goto Einval;
83286+#endif
83287+
83288 /* We can't remap across vm area boundaries */
83289 if (old_len > vma->vm_end - addr)
83290 goto Efault;
83291@@ -373,20 +384,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
83292 unsigned long ret = -EINVAL;
83293 unsigned long charged = 0;
83294 unsigned long map_flags;
83295+ unsigned long pax_task_size = TASK_SIZE;
83296
83297 if (new_addr & ~PAGE_MASK)
83298 goto out;
83299
83300- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
83301+#ifdef CONFIG_PAX_SEGMEXEC
83302+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
83303+ pax_task_size = SEGMEXEC_TASK_SIZE;
83304+#endif
83305+
83306+ pax_task_size -= PAGE_SIZE;
83307+
83308+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
83309 goto out;
83310
83311 /* Check if the location we're moving into overlaps the
83312 * old location at all, and fail if it does.
83313 */
83314- if ((new_addr <= addr) && (new_addr+new_len) > addr)
83315- goto out;
83316-
83317- if ((addr <= new_addr) && (addr+old_len) > new_addr)
83318+ if (addr + old_len > new_addr && new_addr + new_len > addr)
83319 goto out;
83320
83321 ret = do_munmap(mm, new_addr, new_len);
83322@@ -455,6 +471,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83323 unsigned long ret = -EINVAL;
83324 unsigned long charged = 0;
83325 bool locked = false;
83326+ unsigned long pax_task_size = TASK_SIZE;
83327
83328 down_write(&current->mm->mmap_sem);
83329
83330@@ -475,6 +492,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83331 if (!new_len)
83332 goto out;
83333
83334+#ifdef CONFIG_PAX_SEGMEXEC
83335+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
83336+ pax_task_size = SEGMEXEC_TASK_SIZE;
83337+#endif
83338+
83339+ pax_task_size -= PAGE_SIZE;
83340+
83341+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
83342+ old_len > pax_task_size || addr > pax_task_size-old_len)
83343+ goto out;
83344+
83345 if (flags & MREMAP_FIXED) {
83346 if (flags & MREMAP_MAYMOVE)
83347 ret = mremap_to(addr, old_len, new_addr, new_len,
83348@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83349 new_addr = addr;
83350 }
83351 ret = addr;
83352+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
83353 goto out;
83354 }
83355 }
83356@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83357 goto out;
83358 }
83359
83360+ map_flags = vma->vm_flags;
83361 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
83362+ if (!(ret & ~PAGE_MASK)) {
83363+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
83364+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
83365+ }
83366 }
83367 out:
83368 if (ret & ~PAGE_MASK)
83369diff --git a/mm/nommu.c b/mm/nommu.c
83370index e001768..9b52b30 100644
83371--- a/mm/nommu.c
83372+++ b/mm/nommu.c
83373@@ -63,7 +63,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
83374 int sysctl_overcommit_ratio = 50; /* default is 50% */
83375 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
83376 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
83377-int heap_stack_gap = 0;
83378
83379 atomic_long_t mmap_pages_allocated;
83380
83381@@ -841,15 +840,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
83382 EXPORT_SYMBOL(find_vma);
83383
83384 /*
83385- * find a VMA
83386- * - we don't extend stack VMAs under NOMMU conditions
83387- */
83388-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
83389-{
83390- return find_vma(mm, addr);
83391-}
83392-
83393-/*
83394 * expand a stack to a given address
83395 * - not supported under NOMMU conditions
83396 */
83397@@ -1560,6 +1550,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83398
83399 /* most fields are the same, copy all, and then fixup */
83400 *new = *vma;
83401+ INIT_LIST_HEAD(&new->anon_vma_chain);
83402 *region = *vma->vm_region;
83403 new->vm_region = region;
83404
83405@@ -1992,8 +1983,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
83406 }
83407 EXPORT_SYMBOL(generic_file_remap_pages);
83408
83409-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83410- unsigned long addr, void *buf, int len, int write)
83411+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83412+ unsigned long addr, void *buf, size_t len, int write)
83413 {
83414 struct vm_area_struct *vma;
83415
83416@@ -2034,8 +2025,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83417 *
83418 * The caller must hold a reference on @mm.
83419 */
83420-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83421- void *buf, int len, int write)
83422+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
83423+ void *buf, size_t len, int write)
83424 {
83425 return __access_remote_vm(NULL, mm, addr, buf, len, write);
83426 }
83427@@ -2044,7 +2035,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83428 * Access another process' address space.
83429 * - source/target buffer must be kernel space
83430 */
83431-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
83432+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
83433 {
83434 struct mm_struct *mm;
83435
83436diff --git a/mm/page-writeback.c b/mm/page-writeback.c
83437index efe6814..64b4701 100644
83438--- a/mm/page-writeback.c
83439+++ b/mm/page-writeback.c
83440@@ -659,7 +659,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
83441 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
83442 * - the bdi dirty thresh drops quickly due to change of JBOD workload
83443 */
83444-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
83445+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
83446 unsigned long thresh,
83447 unsigned long bg_thresh,
83448 unsigned long dirty,
83449@@ -1634,7 +1634,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
83450 }
83451 }
83452
83453-static struct notifier_block __cpuinitdata ratelimit_nb = {
83454+static struct notifier_block ratelimit_nb = {
83455 .notifier_call = ratelimit_handler,
83456 .next = NULL,
83457 };
83458diff --git a/mm/page_alloc.c b/mm/page_alloc.c
83459index 8fcced7..ebcd481 100644
83460--- a/mm/page_alloc.c
83461+++ b/mm/page_alloc.c
83462@@ -59,6 +59,7 @@
83463 #include <linux/migrate.h>
83464 #include <linux/page-debug-flags.h>
83465 #include <linux/sched/rt.h>
83466+#include <linux/random.h>
83467
83468 #include <asm/tlbflush.h>
83469 #include <asm/div64.h>
83470@@ -344,7 +345,7 @@ out:
83471 * This usage means that zero-order pages may not be compound.
83472 */
83473
83474-static void free_compound_page(struct page *page)
83475+void free_compound_page(struct page *page)
83476 {
83477 __free_pages_ok(page, compound_order(page));
83478 }
83479@@ -701,6 +702,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
83480 int i;
83481 int bad = 0;
83482
83483+#ifdef CONFIG_PAX_MEMORY_SANITIZE
83484+ unsigned long index = 1UL << order;
83485+#endif
83486+
83487 trace_mm_page_free(page, order);
83488 kmemcheck_free_shadow(page, order);
83489
83490@@ -716,6 +721,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
83491 debug_check_no_obj_freed(page_address(page),
83492 PAGE_SIZE << order);
83493 }
83494+
83495+#ifdef CONFIG_PAX_MEMORY_SANITIZE
83496+ for (; index; --index)
83497+ sanitize_highpage(page + index - 1);
83498+#endif
83499+
83500 arch_free_page(page, order);
83501 kernel_map_pages(page, 1 << order, 0);
83502
83503@@ -738,6 +749,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
83504 local_irq_restore(flags);
83505 }
83506
83507+#ifdef CONFIG_PAX_LATENT_ENTROPY
83508+bool __meminitdata extra_latent_entropy;
83509+
83510+static int __init setup_pax_extra_latent_entropy(char *str)
83511+{
83512+ extra_latent_entropy = true;
83513+ return 0;
83514+}
83515+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
83516+
83517+volatile u64 latent_entropy;
83518+#endif
83519+
83520 /*
83521 * Read access to zone->managed_pages is safe because it's unsigned long,
83522 * but we still need to serialize writers. Currently all callers of
83523@@ -760,6 +784,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
83524 set_page_count(p, 0);
83525 }
83526
83527+#ifdef CONFIG_PAX_LATENT_ENTROPY
83528+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
83529+ u64 hash = 0;
83530+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
83531+ const u64 *data = lowmem_page_address(page);
83532+
83533+ for (index = 0; index < end; index++)
83534+ hash ^= hash + data[index];
83535+ latent_entropy ^= hash;
83536+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
83537+ }
83538+#endif
83539+
83540 page_zone(page)->managed_pages += 1 << order;
83541 set_page_refcounted(page);
83542 __free_pages(page, order);
83543@@ -869,8 +906,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
83544 arch_alloc_page(page, order);
83545 kernel_map_pages(page, 1 << order, 1);
83546
83547+#ifndef CONFIG_PAX_MEMORY_SANITIZE
83548 if (gfp_flags & __GFP_ZERO)
83549 prep_zero_page(page, order, gfp_flags);
83550+#endif
83551
83552 if (order && (gfp_flags & __GFP_COMP))
83553 prep_compound_page(page, order);
83554diff --git a/mm/page_io.c b/mm/page_io.c
83555index 6182870..4bba6a2 100644
83556--- a/mm/page_io.c
83557+++ b/mm/page_io.c
83558@@ -205,7 +205,7 @@ int swap_writepage(struct page *page, struct writeback_control *wbc)
83559 struct file *swap_file = sis->swap_file;
83560 struct address_space *mapping = swap_file->f_mapping;
83561 struct iovec iov = {
83562- .iov_base = kmap(page),
83563+ .iov_base = (void __force_user *)kmap(page),
83564 .iov_len = PAGE_SIZE,
83565 };
83566
83567diff --git a/mm/percpu.c b/mm/percpu.c
83568index 8c8e08f..73a5cda 100644
83569--- a/mm/percpu.c
83570+++ b/mm/percpu.c
83571@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
83572 static unsigned int pcpu_high_unit_cpu __read_mostly;
83573
83574 /* the address of the first chunk which starts with the kernel static area */
83575-void *pcpu_base_addr __read_mostly;
83576+void *pcpu_base_addr __read_only;
83577 EXPORT_SYMBOL_GPL(pcpu_base_addr);
83578
83579 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
83580diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
83581index fd26d04..0cea1b0 100644
83582--- a/mm/process_vm_access.c
83583+++ b/mm/process_vm_access.c
83584@@ -13,6 +13,7 @@
83585 #include <linux/uio.h>
83586 #include <linux/sched.h>
83587 #include <linux/highmem.h>
83588+#include <linux/security.h>
83589 #include <linux/ptrace.h>
83590 #include <linux/slab.h>
83591 #include <linux/syscalls.h>
83592@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
83593 size_t iov_l_curr_offset = 0;
83594 ssize_t iov_len;
83595
83596+ return -ENOSYS; // PaX: until properly audited
83597+
83598 /*
83599 * Work out how many pages of struct pages we're going to need
83600 * when eventually calling get_user_pages
83601 */
83602 for (i = 0; i < riovcnt; i++) {
83603 iov_len = rvec[i].iov_len;
83604- if (iov_len > 0) {
83605- nr_pages_iov = ((unsigned long)rvec[i].iov_base
83606- + iov_len)
83607- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
83608- / PAGE_SIZE + 1;
83609- nr_pages = max(nr_pages, nr_pages_iov);
83610- }
83611+ if (iov_len <= 0)
83612+ continue;
83613+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
83614+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
83615+ nr_pages = max(nr_pages, nr_pages_iov);
83616 }
83617
83618 if (nr_pages == 0)
83619@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
83620 goto free_proc_pages;
83621 }
83622
83623+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
83624+ rc = -EPERM;
83625+ goto put_task_struct;
83626+ }
83627+
83628 mm = mm_access(task, PTRACE_MODE_ATTACH);
83629 if (!mm || IS_ERR(mm)) {
83630 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
83631diff --git a/mm/rmap.c b/mm/rmap.c
83632index 807c96b..0e05279 100644
83633--- a/mm/rmap.c
83634+++ b/mm/rmap.c
83635@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
83636 struct anon_vma *anon_vma = vma->anon_vma;
83637 struct anon_vma_chain *avc;
83638
83639+#ifdef CONFIG_PAX_SEGMEXEC
83640+ struct anon_vma_chain *avc_m = NULL;
83641+#endif
83642+
83643 might_sleep();
83644 if (unlikely(!anon_vma)) {
83645 struct mm_struct *mm = vma->vm_mm;
83646@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
83647 if (!avc)
83648 goto out_enomem;
83649
83650+#ifdef CONFIG_PAX_SEGMEXEC
83651+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
83652+ if (!avc_m)
83653+ goto out_enomem_free_avc;
83654+#endif
83655+
83656 anon_vma = find_mergeable_anon_vma(vma);
83657 allocated = NULL;
83658 if (!anon_vma) {
83659@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
83660 /* page_table_lock to protect against threads */
83661 spin_lock(&mm->page_table_lock);
83662 if (likely(!vma->anon_vma)) {
83663+
83664+#ifdef CONFIG_PAX_SEGMEXEC
83665+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
83666+
83667+ if (vma_m) {
83668+ BUG_ON(vma_m->anon_vma);
83669+ vma_m->anon_vma = anon_vma;
83670+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
83671+ avc_m = NULL;
83672+ }
83673+#endif
83674+
83675 vma->anon_vma = anon_vma;
83676 anon_vma_chain_link(vma, avc, anon_vma);
83677 allocated = NULL;
83678@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
83679
83680 if (unlikely(allocated))
83681 put_anon_vma(allocated);
83682+
83683+#ifdef CONFIG_PAX_SEGMEXEC
83684+ if (unlikely(avc_m))
83685+ anon_vma_chain_free(avc_m);
83686+#endif
83687+
83688 if (unlikely(avc))
83689 anon_vma_chain_free(avc);
83690 }
83691 return 0;
83692
83693 out_enomem_free_avc:
83694+
83695+#ifdef CONFIG_PAX_SEGMEXEC
83696+ if (avc_m)
83697+ anon_vma_chain_free(avc_m);
83698+#endif
83699+
83700 anon_vma_chain_free(avc);
83701 out_enomem:
83702 return -ENOMEM;
83703@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
83704 * Attach the anon_vmas from src to dst.
83705 * Returns 0 on success, -ENOMEM on failure.
83706 */
83707-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
83708+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
83709 {
83710 struct anon_vma_chain *avc, *pavc;
83711 struct anon_vma *root = NULL;
83712@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
83713 * the corresponding VMA in the parent process is attached to.
83714 * Returns 0 on success, non-zero on failure.
83715 */
83716-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
83717+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
83718 {
83719 struct anon_vma_chain *avc;
83720 struct anon_vma *anon_vma;
83721diff --git a/mm/shmem.c b/mm/shmem.c
83722index 1c44af7..cefe9a6 100644
83723--- a/mm/shmem.c
83724+++ b/mm/shmem.c
83725@@ -31,7 +31,7 @@
83726 #include <linux/export.h>
83727 #include <linux/swap.h>
83728
83729-static struct vfsmount *shm_mnt;
83730+struct vfsmount *shm_mnt;
83731
83732 #ifdef CONFIG_SHMEM
83733 /*
83734@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
83735 #define BOGO_DIRENT_SIZE 20
83736
83737 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
83738-#define SHORT_SYMLINK_LEN 128
83739+#define SHORT_SYMLINK_LEN 64
83740
83741 /*
83742 * shmem_fallocate and shmem_writepage communicate via inode->i_private
83743@@ -2201,6 +2201,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
83744 static int shmem_xattr_validate(const char *name)
83745 {
83746 struct { const char *prefix; size_t len; } arr[] = {
83747+
83748+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83749+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
83750+#endif
83751+
83752 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
83753 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
83754 };
83755@@ -2256,6 +2261,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
83756 if (err)
83757 return err;
83758
83759+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83760+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
83761+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
83762+ return -EOPNOTSUPP;
83763+ if (size > 8)
83764+ return -EINVAL;
83765+ }
83766+#endif
83767+
83768 return simple_xattr_set(&info->xattrs, name, value, size, flags);
83769 }
83770
83771@@ -2568,8 +2582,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
83772 int err = -ENOMEM;
83773
83774 /* Round up to L1_CACHE_BYTES to resist false sharing */
83775- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
83776- L1_CACHE_BYTES), GFP_KERNEL);
83777+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
83778 if (!sbinfo)
83779 return -ENOMEM;
83780
83781diff --git a/mm/slab.c b/mm/slab.c
83782index 856e4a1..fafb820 100644
83783--- a/mm/slab.c
83784+++ b/mm/slab.c
83785@@ -306,7 +306,7 @@ struct kmem_list3 {
83786 * Need this for bootstrapping a per node allocator.
83787 */
83788 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
83789-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
83790+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
83791 #define CACHE_CACHE 0
83792 #define SIZE_AC MAX_NUMNODES
83793 #define SIZE_L3 (2 * MAX_NUMNODES)
83794@@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
83795 if ((x)->max_freeable < i) \
83796 (x)->max_freeable = i; \
83797 } while (0)
83798-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
83799-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
83800-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
83801-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
83802+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
83803+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
83804+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
83805+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
83806 #else
83807 #define STATS_INC_ACTIVE(x) do { } while (0)
83808 #define STATS_DEC_ACTIVE(x) do { } while (0)
83809@@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
83810 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
83811 */
83812 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
83813- const struct slab *slab, void *obj)
83814+ const struct slab *slab, const void *obj)
83815 {
83816 u32 offset = (obj - slab->s_mem);
83817 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
83818@@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
83819 struct cache_names {
83820 char *name;
83821 char *name_dma;
83822+ char *name_usercopy;
83823 };
83824
83825 static struct cache_names __initdata cache_names[] = {
83826-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
83827+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
83828 #include <linux/kmalloc_sizes.h>
83829- {NULL,}
83830+ {NULL}
83831 #undef CACHE
83832 };
83833
83834@@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
83835 if (unlikely(gfpflags & GFP_DMA))
83836 return csizep->cs_dmacachep;
83837 #endif
83838+
83839+#ifdef CONFIG_PAX_USERCOPY_SLABS
83840+ if (unlikely(gfpflags & GFP_USERCOPY))
83841+ return csizep->cs_usercopycachep;
83842+#endif
83843+
83844 return csizep->cs_cachep;
83845 }
83846
83847@@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
83848 return notifier_from_errno(err);
83849 }
83850
83851-static struct notifier_block __cpuinitdata cpucache_notifier = {
83852+static struct notifier_block cpucache_notifier = {
83853 &cpuup_callback, NULL, 0
83854 };
83855
83856@@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
83857 */
83858
83859 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
83860- sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
83861+ sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
83862
83863 if (INDEX_AC != INDEX_L3)
83864 sizes[INDEX_L3].cs_cachep =
83865 create_kmalloc_cache(names[INDEX_L3].name,
83866- sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
83867+ sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
83868
83869 slab_early_init = 0;
83870
83871@@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
83872 */
83873 if (!sizes->cs_cachep)
83874 sizes->cs_cachep = create_kmalloc_cache(names->name,
83875- sizes->cs_size, ARCH_KMALLOC_FLAGS);
83876+ sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
83877
83878 #ifdef CONFIG_ZONE_DMA
83879 sizes->cs_dmacachep = create_kmalloc_cache(
83880 names->name_dma, sizes->cs_size,
83881 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
83882 #endif
83883+
83884+#ifdef CONFIG_PAX_USERCOPY_SLABS
83885+ sizes->cs_usercopycachep = create_kmalloc_cache(
83886+ names->name_usercopy, sizes->cs_size,
83887+ ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
83888+#endif
83889+
83890 sizes++;
83891 names++;
83892 }
83893@@ -3924,6 +3938,7 @@ void kfree(const void *objp)
83894
83895 if (unlikely(ZERO_OR_NULL_PTR(objp)))
83896 return;
83897+ VM_BUG_ON(!virt_addr_valid(objp));
83898 local_irq_save(flags);
83899 kfree_debugcheck(objp);
83900 c = virt_to_cache(objp);
83901@@ -4365,10 +4380,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
83902 }
83903 /* cpu stats */
83904 {
83905- unsigned long allochit = atomic_read(&cachep->allochit);
83906- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
83907- unsigned long freehit = atomic_read(&cachep->freehit);
83908- unsigned long freemiss = atomic_read(&cachep->freemiss);
83909+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
83910+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
83911+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
83912+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
83913
83914 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
83915 allochit, allocmiss, freehit, freemiss);
83916@@ -4600,13 +4615,71 @@ static const struct file_operations proc_slabstats_operations = {
83917 static int __init slab_proc_init(void)
83918 {
83919 #ifdef CONFIG_DEBUG_SLAB_LEAK
83920- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
83921+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
83922 #endif
83923 return 0;
83924 }
83925 module_init(slab_proc_init);
83926 #endif
83927
83928+bool is_usercopy_object(const void *ptr)
83929+{
83930+ struct page *page;
83931+ struct kmem_cache *cachep;
83932+
83933+ if (ZERO_OR_NULL_PTR(ptr))
83934+ return false;
83935+
83936+ if (!slab_is_available())
83937+ return false;
83938+
83939+ if (!virt_addr_valid(ptr))
83940+ return false;
83941+
83942+ page = virt_to_head_page(ptr);
83943+
83944+ if (!PageSlab(page))
83945+ return false;
83946+
83947+ cachep = page->slab_cache;
83948+ return cachep->flags & SLAB_USERCOPY;
83949+}
83950+
83951+#ifdef CONFIG_PAX_USERCOPY
83952+const char *check_heap_object(const void *ptr, unsigned long n)
83953+{
83954+ struct page *page;
83955+ struct kmem_cache *cachep;
83956+ struct slab *slabp;
83957+ unsigned int objnr;
83958+ unsigned long offset;
83959+
83960+ if (ZERO_OR_NULL_PTR(ptr))
83961+ return "<null>";
83962+
83963+ if (!virt_addr_valid(ptr))
83964+ return NULL;
83965+
83966+ page = virt_to_head_page(ptr);
83967+
83968+ if (!PageSlab(page))
83969+ return NULL;
83970+
83971+ cachep = page->slab_cache;
83972+ if (!(cachep->flags & SLAB_USERCOPY))
83973+ return cachep->name;
83974+
83975+ slabp = page->slab_page;
83976+ objnr = obj_to_index(cachep, slabp, ptr);
83977+ BUG_ON(objnr >= cachep->num);
83978+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
83979+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
83980+ return NULL;
83981+
83982+ return cachep->name;
83983+}
83984+#endif
83985+
83986 /**
83987 * ksize - get the actual amount of memory allocated for a given object
83988 * @objp: Pointer to the object
83989diff --git a/mm/slab.h b/mm/slab.h
83990index 34a98d6..73633d1 100644
83991--- a/mm/slab.h
83992+++ b/mm/slab.h
83993@@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
83994
83995 /* Legal flag mask for kmem_cache_create(), for various configurations */
83996 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
83997- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
83998+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
83999
84000 #if defined(CONFIG_DEBUG_SLAB)
84001 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
84002@@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
84003 return s;
84004
84005 page = virt_to_head_page(x);
84006+
84007+ BUG_ON(!PageSlab(page));
84008+
84009 cachep = page->slab_cache;
84010 if (slab_equal_or_root(cachep, s))
84011 return cachep;
84012diff --git a/mm/slab_common.c b/mm/slab_common.c
84013index 3f3cd97..93b0236 100644
84014--- a/mm/slab_common.c
84015+++ b/mm/slab_common.c
84016@@ -22,7 +22,7 @@
84017
84018 #include "slab.h"
84019
84020-enum slab_state slab_state;
84021+enum slab_state slab_state __read_only;
84022 LIST_HEAD(slab_caches);
84023 DEFINE_MUTEX(slab_mutex);
84024 struct kmem_cache *kmem_cache;
84025@@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
84026
84027 err = __kmem_cache_create(s, flags);
84028 if (!err) {
84029- s->refcount = 1;
84030+ atomic_set(&s->refcount, 1);
84031 list_add(&s->list, &slab_caches);
84032 memcg_cache_list_add(memcg, s);
84033 } else {
84034@@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
84035
84036 get_online_cpus();
84037 mutex_lock(&slab_mutex);
84038- s->refcount--;
84039- if (!s->refcount) {
84040+ if (atomic_dec_and_test(&s->refcount)) {
84041 list_del(&s->list);
84042
84043 if (!__kmem_cache_shutdown(s)) {
84044@@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
84045 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
84046 name, size, err);
84047
84048- s->refcount = -1; /* Exempt from merging for now */
84049+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
84050 }
84051
84052 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
84053@@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
84054
84055 create_boot_cache(s, name, size, flags);
84056 list_add(&s->list, &slab_caches);
84057- s->refcount = 1;
84058+ atomic_set(&s->refcount, 1);
84059 return s;
84060 }
84061
84062diff --git a/mm/slob.c b/mm/slob.c
84063index eeed4a0..6ee34ec 100644
84064--- a/mm/slob.c
84065+++ b/mm/slob.c
84066@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
84067 /*
84068 * Return the size of a slob block.
84069 */
84070-static slobidx_t slob_units(slob_t *s)
84071+static slobidx_t slob_units(const slob_t *s)
84072 {
84073 if (s->units > 0)
84074 return s->units;
84075@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
84076 /*
84077 * Return the next free slob block pointer after this one.
84078 */
84079-static slob_t *slob_next(slob_t *s)
84080+static slob_t *slob_next(const slob_t *s)
84081 {
84082 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
84083 slobidx_t next;
84084@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
84085 /*
84086 * Returns true if s is the last free block in its page.
84087 */
84088-static int slob_last(slob_t *s)
84089+static int slob_last(const slob_t *s)
84090 {
84091 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
84092 }
84093
84094-static void *slob_new_pages(gfp_t gfp, int order, int node)
84095+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
84096 {
84097- void *page;
84098+ struct page *page;
84099
84100 #ifdef CONFIG_NUMA
84101 if (node != NUMA_NO_NODE)
84102@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
84103 if (!page)
84104 return NULL;
84105
84106- return page_address(page);
84107+ __SetPageSlab(page);
84108+ return page;
84109 }
84110
84111-static void slob_free_pages(void *b, int order)
84112+static void slob_free_pages(struct page *sp, int order)
84113 {
84114 if (current->reclaim_state)
84115 current->reclaim_state->reclaimed_slab += 1 << order;
84116- free_pages((unsigned long)b, order);
84117+ __ClearPageSlab(sp);
84118+ reset_page_mapcount(sp);
84119+ sp->private = 0;
84120+ __free_pages(sp, order);
84121 }
84122
84123 /*
84124@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
84125
84126 /* Not enough space: must allocate a new page */
84127 if (!b) {
84128- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
84129- if (!b)
84130+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
84131+ if (!sp)
84132 return NULL;
84133- sp = virt_to_page(b);
84134- __SetPageSlab(sp);
84135+ b = page_address(sp);
84136
84137 spin_lock_irqsave(&slob_lock, flags);
84138 sp->units = SLOB_UNITS(PAGE_SIZE);
84139 sp->freelist = b;
84140+ sp->private = 0;
84141 INIT_LIST_HEAD(&sp->list);
84142 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
84143 set_slob_page_free(sp, slob_list);
84144@@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
84145 if (slob_page_free(sp))
84146 clear_slob_page_free(sp);
84147 spin_unlock_irqrestore(&slob_lock, flags);
84148- __ClearPageSlab(sp);
84149- page_mapcount_reset(sp);
84150- slob_free_pages(b, 0);
84151+ slob_free_pages(sp, 0);
84152 return;
84153 }
84154
84155@@ -424,11 +426,10 @@ out:
84156 */
84157
84158 static __always_inline void *
84159-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84160+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
84161 {
84162- unsigned int *m;
84163- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84164- void *ret;
84165+ slob_t *m;
84166+ void *ret = NULL;
84167
84168 gfp &= gfp_allowed_mask;
84169
84170@@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84171
84172 if (!m)
84173 return NULL;
84174- *m = size;
84175+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
84176+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
84177+ m[0].units = size;
84178+ m[1].units = align;
84179 ret = (void *)m + align;
84180
84181 trace_kmalloc_node(caller, ret,
84182 size, size + align, gfp, node);
84183 } else {
84184 unsigned int order = get_order(size);
84185+ struct page *page;
84186
84187 if (likely(order))
84188 gfp |= __GFP_COMP;
84189- ret = slob_new_pages(gfp, order, node);
84190+ page = slob_new_pages(gfp, order, node);
84191+ if (page) {
84192+ ret = page_address(page);
84193+ page->private = size;
84194+ }
84195
84196 trace_kmalloc_node(caller, ret,
84197 size, PAGE_SIZE << order, gfp, node);
84198 }
84199
84200- kmemleak_alloc(ret, size, 1, gfp);
84201+ return ret;
84202+}
84203+
84204+static __always_inline void *
84205+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84206+{
84207+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84208+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
84209+
84210+ if (!ZERO_OR_NULL_PTR(ret))
84211+ kmemleak_alloc(ret, size, 1, gfp);
84212 return ret;
84213 }
84214
84215@@ -493,34 +512,112 @@ void kfree(const void *block)
84216 return;
84217 kmemleak_free(block);
84218
84219+ VM_BUG_ON(!virt_addr_valid(block));
84220 sp = virt_to_page(block);
84221- if (PageSlab(sp)) {
84222+ VM_BUG_ON(!PageSlab(sp));
84223+ if (!sp->private) {
84224 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84225- unsigned int *m = (unsigned int *)(block - align);
84226- slob_free(m, *m + align);
84227- } else
84228+ slob_t *m = (slob_t *)(block - align);
84229+ slob_free(m, m[0].units + align);
84230+ } else {
84231+ __ClearPageSlab(sp);
84232+ reset_page_mapcount(sp);
84233+ sp->private = 0;
84234 __free_pages(sp, compound_order(sp));
84235+ }
84236 }
84237 EXPORT_SYMBOL(kfree);
84238
84239+bool is_usercopy_object(const void *ptr)
84240+{
84241+ if (!slab_is_available())
84242+ return false;
84243+
84244+ // PAX: TODO
84245+
84246+ return false;
84247+}
84248+
84249+#ifdef CONFIG_PAX_USERCOPY
84250+const char *check_heap_object(const void *ptr, unsigned long n)
84251+{
84252+ struct page *page;
84253+ const slob_t *free;
84254+ const void *base;
84255+ unsigned long flags;
84256+
84257+ if (ZERO_OR_NULL_PTR(ptr))
84258+ return "<null>";
84259+
84260+ if (!virt_addr_valid(ptr))
84261+ return NULL;
84262+
84263+ page = virt_to_head_page(ptr);
84264+ if (!PageSlab(page))
84265+ return NULL;
84266+
84267+ if (page->private) {
84268+ base = page;
84269+ if (base <= ptr && n <= page->private - (ptr - base))
84270+ return NULL;
84271+ return "<slob>";
84272+ }
84273+
84274+ /* some tricky double walking to find the chunk */
84275+ spin_lock_irqsave(&slob_lock, flags);
84276+ base = (void *)((unsigned long)ptr & PAGE_MASK);
84277+ free = page->freelist;
84278+
84279+ while (!slob_last(free) && (void *)free <= ptr) {
84280+ base = free + slob_units(free);
84281+ free = slob_next(free);
84282+ }
84283+
84284+ while (base < (void *)free) {
84285+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
84286+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
84287+ int offset;
84288+
84289+ if (ptr < base + align)
84290+ break;
84291+
84292+ offset = ptr - base - align;
84293+ if (offset >= m) {
84294+ base += size;
84295+ continue;
84296+ }
84297+
84298+ if (n > m - offset)
84299+ break;
84300+
84301+ spin_unlock_irqrestore(&slob_lock, flags);
84302+ return NULL;
84303+ }
84304+
84305+ spin_unlock_irqrestore(&slob_lock, flags);
84306+ return "<slob>";
84307+}
84308+#endif
84309+
84310 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
84311 size_t ksize(const void *block)
84312 {
84313 struct page *sp;
84314 int align;
84315- unsigned int *m;
84316+ slob_t *m;
84317
84318 BUG_ON(!block);
84319 if (unlikely(block == ZERO_SIZE_PTR))
84320 return 0;
84321
84322 sp = virt_to_page(block);
84323- if (unlikely(!PageSlab(sp)))
84324- return PAGE_SIZE << compound_order(sp);
84325+ VM_BUG_ON(!PageSlab(sp));
84326+ if (sp->private)
84327+ return sp->private;
84328
84329 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84330- m = (unsigned int *)(block - align);
84331- return SLOB_UNITS(*m) * SLOB_UNIT;
84332+ m = (slob_t *)(block - align);
84333+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
84334 }
84335 EXPORT_SYMBOL(ksize);
84336
84337@@ -536,23 +633,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
84338
84339 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
84340 {
84341- void *b;
84342+ void *b = NULL;
84343
84344 flags &= gfp_allowed_mask;
84345
84346 lockdep_trace_alloc(flags);
84347
84348+#ifdef CONFIG_PAX_USERCOPY_SLABS
84349+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
84350+#else
84351 if (c->size < PAGE_SIZE) {
84352 b = slob_alloc(c->size, flags, c->align, node);
84353 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
84354 SLOB_UNITS(c->size) * SLOB_UNIT,
84355 flags, node);
84356 } else {
84357- b = slob_new_pages(flags, get_order(c->size), node);
84358+ struct page *sp;
84359+
84360+ sp = slob_new_pages(flags, get_order(c->size), node);
84361+ if (sp) {
84362+ b = page_address(sp);
84363+ sp->private = c->size;
84364+ }
84365 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
84366 PAGE_SIZE << get_order(c->size),
84367 flags, node);
84368 }
84369+#endif
84370
84371 if (c->ctor)
84372 c->ctor(b);
84373@@ -564,10 +671,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
84374
84375 static void __kmem_cache_free(void *b, int size)
84376 {
84377- if (size < PAGE_SIZE)
84378+ struct page *sp;
84379+
84380+ sp = virt_to_page(b);
84381+ BUG_ON(!PageSlab(sp));
84382+ if (!sp->private)
84383 slob_free(b, size);
84384 else
84385- slob_free_pages(b, get_order(size));
84386+ slob_free_pages(sp, get_order(size));
84387 }
84388
84389 static void kmem_rcu_free(struct rcu_head *head)
84390@@ -580,17 +691,31 @@ static void kmem_rcu_free(struct rcu_head *head)
84391
84392 void kmem_cache_free(struct kmem_cache *c, void *b)
84393 {
84394+ int size = c->size;
84395+
84396+#ifdef CONFIG_PAX_USERCOPY_SLABS
84397+ if (size + c->align < PAGE_SIZE) {
84398+ size += c->align;
84399+ b -= c->align;
84400+ }
84401+#endif
84402+
84403 kmemleak_free_recursive(b, c->flags);
84404 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
84405 struct slob_rcu *slob_rcu;
84406- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
84407- slob_rcu->size = c->size;
84408+ slob_rcu = b + (size - sizeof(struct slob_rcu));
84409+ slob_rcu->size = size;
84410 call_rcu(&slob_rcu->head, kmem_rcu_free);
84411 } else {
84412- __kmem_cache_free(b, c->size);
84413+ __kmem_cache_free(b, size);
84414 }
84415
84416+#ifdef CONFIG_PAX_USERCOPY_SLABS
84417+ trace_kfree(_RET_IP_, b);
84418+#else
84419 trace_kmem_cache_free(_RET_IP_, b);
84420+#endif
84421+
84422 }
84423 EXPORT_SYMBOL(kmem_cache_free);
84424
84425diff --git a/mm/slub.c b/mm/slub.c
84426index 4aec537..a64753d 100644
84427--- a/mm/slub.c
84428+++ b/mm/slub.c
84429@@ -197,7 +197,7 @@ struct track {
84430
84431 enum track_item { TRACK_ALLOC, TRACK_FREE };
84432
84433-#ifdef CONFIG_SYSFS
84434+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84435 static int sysfs_slab_add(struct kmem_cache *);
84436 static int sysfs_slab_alias(struct kmem_cache *, const char *);
84437 static void sysfs_slab_remove(struct kmem_cache *);
84438@@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
84439 if (!t->addr)
84440 return;
84441
84442- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
84443+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
84444 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
84445 #ifdef CONFIG_STACKTRACE
84446 {
84447@@ -2653,7 +2653,7 @@ static int slub_min_objects;
84448 * Merge control. If this is set then no merging of slab caches will occur.
84449 * (Could be removed. This was introduced to pacify the merge skeptics.)
84450 */
84451-static int slub_nomerge;
84452+static int slub_nomerge = 1;
84453
84454 /*
84455 * Calculate the order of allocation given an slab object size.
84456@@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
84457 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
84458 #endif
84459
84460+#ifdef CONFIG_PAX_USERCOPY_SLABS
84461+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
84462+#endif
84463+
84464 static int __init setup_slub_min_order(char *str)
84465 {
84466 get_option(&str, &slub_min_order);
84467@@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
84468 return kmalloc_dma_caches[index];
84469
84470 #endif
84471+
84472+#ifdef CONFIG_PAX_USERCOPY_SLABS
84473+ if (flags & SLAB_USERCOPY)
84474+ return kmalloc_usercopy_caches[index];
84475+
84476+#endif
84477+
84478 return kmalloc_caches[index];
84479 }
84480
84481@@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
84482 EXPORT_SYMBOL(__kmalloc_node);
84483 #endif
84484
84485+bool is_usercopy_object(const void *ptr)
84486+{
84487+ struct page *page;
84488+ struct kmem_cache *s;
84489+
84490+ if (ZERO_OR_NULL_PTR(ptr))
84491+ return false;
84492+
84493+ if (!slab_is_available())
84494+ return false;
84495+
84496+ if (!virt_addr_valid(ptr))
84497+ return false;
84498+
84499+ page = virt_to_head_page(ptr);
84500+
84501+ if (!PageSlab(page))
84502+ return false;
84503+
84504+ s = page->slab_cache;
84505+ return s->flags & SLAB_USERCOPY;
84506+}
84507+
84508+#ifdef CONFIG_PAX_USERCOPY
84509+const char *check_heap_object(const void *ptr, unsigned long n)
84510+{
84511+ struct page *page;
84512+ struct kmem_cache *s;
84513+ unsigned long offset;
84514+
84515+ if (ZERO_OR_NULL_PTR(ptr))
84516+ return "<null>";
84517+
84518+ if (!virt_addr_valid(ptr))
84519+ return NULL;
84520+
84521+ page = virt_to_head_page(ptr);
84522+
84523+ if (!PageSlab(page))
84524+ return NULL;
84525+
84526+ s = page->slab_cache;
84527+ if (!(s->flags & SLAB_USERCOPY))
84528+ return s->name;
84529+
84530+ offset = (ptr - page_address(page)) % s->size;
84531+ if (offset <= s->object_size && n <= s->object_size - offset)
84532+ return NULL;
84533+
84534+ return s->name;
84535+}
84536+#endif
84537+
84538 size_t ksize(const void *object)
84539 {
84540 struct page *page;
84541@@ -3404,6 +3468,7 @@ void kfree(const void *x)
84542 if (unlikely(ZERO_OR_NULL_PTR(x)))
84543 return;
84544
84545+ VM_BUG_ON(!virt_addr_valid(x));
84546 page = virt_to_head_page(x);
84547 if (unlikely(!PageSlab(page))) {
84548 BUG_ON(!PageCompound(page));
84549@@ -3712,17 +3777,17 @@ void __init kmem_cache_init(void)
84550
84551 /* Caches that are not of the two-to-the-power-of size */
84552 if (KMALLOC_MIN_SIZE <= 32) {
84553- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
84554+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
84555 caches++;
84556 }
84557
84558 if (KMALLOC_MIN_SIZE <= 64) {
84559- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
84560+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
84561 caches++;
84562 }
84563
84564 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
84565- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
84566+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
84567 caches++;
84568 }
84569
84570@@ -3764,6 +3829,22 @@ void __init kmem_cache_init(void)
84571 }
84572 }
84573 #endif
84574+
84575+#ifdef CONFIG_PAX_USERCOPY_SLABS
84576+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
84577+ struct kmem_cache *s = kmalloc_caches[i];
84578+
84579+ if (s && s->size) {
84580+ char *name = kasprintf(GFP_NOWAIT,
84581+ "usercopy-kmalloc-%d", s->object_size);
84582+
84583+ BUG_ON(!name);
84584+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
84585+ s->object_size, SLAB_USERCOPY);
84586+ }
84587+ }
84588+#endif
84589+
84590 printk(KERN_INFO
84591 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
84592 " CPUs=%d, Nodes=%d\n",
84593@@ -3790,7 +3871,7 @@ static int slab_unmergeable(struct kmem_cache *s)
84594 /*
84595 * We may have set a slab to be unmergeable during bootstrap.
84596 */
84597- if (s->refcount < 0)
84598+ if (atomic_read(&s->refcount) < 0)
84599 return 1;
84600
84601 return 0;
84602@@ -3848,7 +3929,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
84603
84604 s = find_mergeable(memcg, size, align, flags, name, ctor);
84605 if (s) {
84606- s->refcount++;
84607+ atomic_inc(&s->refcount);
84608 /*
84609 * Adjust the object sizes so that we clear
84610 * the complete object on kzalloc.
84611@@ -3857,7 +3938,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
84612 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
84613
84614 if (sysfs_slab_alias(s, name)) {
84615- s->refcount--;
84616+ atomic_dec(&s->refcount);
84617 s = NULL;
84618 }
84619 }
84620@@ -3919,7 +4000,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
84621 return NOTIFY_OK;
84622 }
84623
84624-static struct notifier_block __cpuinitdata slab_notifier = {
84625+static struct notifier_block slab_notifier = {
84626 .notifier_call = slab_cpuup_callback
84627 };
84628
84629@@ -3977,7 +4058,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
84630 }
84631 #endif
84632
84633-#ifdef CONFIG_SYSFS
84634+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84635 static int count_inuse(struct page *page)
84636 {
84637 return page->inuse;
84638@@ -4364,12 +4445,12 @@ static void resiliency_test(void)
84639 validate_slab_cache(kmalloc_caches[9]);
84640 }
84641 #else
84642-#ifdef CONFIG_SYSFS
84643+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84644 static void resiliency_test(void) {};
84645 #endif
84646 #endif
84647
84648-#ifdef CONFIG_SYSFS
84649+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84650 enum slab_stat_type {
84651 SL_ALL, /* All slabs */
84652 SL_PARTIAL, /* Only partially allocated slabs */
84653@@ -4613,7 +4694,7 @@ SLAB_ATTR_RO(ctor);
84654
84655 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
84656 {
84657- return sprintf(buf, "%d\n", s->refcount - 1);
84658+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
84659 }
84660 SLAB_ATTR_RO(aliases);
84661
84662@@ -5266,6 +5347,7 @@ static char *create_unique_id(struct kmem_cache *s)
84663 return name;
84664 }
84665
84666+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84667 static int sysfs_slab_add(struct kmem_cache *s)
84668 {
84669 int err;
84670@@ -5323,6 +5405,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
84671 kobject_del(&s->kobj);
84672 kobject_put(&s->kobj);
84673 }
84674+#endif
84675
84676 /*
84677 * Need to buffer aliases during bootup until sysfs becomes
84678@@ -5336,6 +5419,7 @@ struct saved_alias {
84679
84680 static struct saved_alias *alias_list;
84681
84682+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84683 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
84684 {
84685 struct saved_alias *al;
84686@@ -5358,6 +5442,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
84687 alias_list = al;
84688 return 0;
84689 }
84690+#endif
84691
84692 static int __init slab_sysfs_init(void)
84693 {
84694diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
84695index 1b7e22a..3fcd4f3 100644
84696--- a/mm/sparse-vmemmap.c
84697+++ b/mm/sparse-vmemmap.c
84698@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
84699 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
84700 if (!p)
84701 return NULL;
84702- pud_populate(&init_mm, pud, p);
84703+ pud_populate_kernel(&init_mm, pud, p);
84704 }
84705 return pud;
84706 }
84707@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
84708 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
84709 if (!p)
84710 return NULL;
84711- pgd_populate(&init_mm, pgd, p);
84712+ pgd_populate_kernel(&init_mm, pgd, p);
84713 }
84714 return pgd;
84715 }
84716diff --git a/mm/sparse.c b/mm/sparse.c
84717index 7ca6dc8..6472aa1 100644
84718--- a/mm/sparse.c
84719+++ b/mm/sparse.c
84720@@ -783,7 +783,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
84721
84722 for (i = 0; i < PAGES_PER_SECTION; i++) {
84723 if (PageHWPoison(&memmap[i])) {
84724- atomic_long_sub(1, &num_poisoned_pages);
84725+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
84726 ClearPageHWPoison(&memmap[i]);
84727 }
84728 }
84729diff --git a/mm/swap.c b/mm/swap.c
84730index 8a529a0..154ef26 100644
84731--- a/mm/swap.c
84732+++ b/mm/swap.c
84733@@ -30,6 +30,7 @@
84734 #include <linux/backing-dev.h>
84735 #include <linux/memcontrol.h>
84736 #include <linux/gfp.h>
84737+#include <linux/hugetlb.h>
84738
84739 #include "internal.h"
84740
84741@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
84742
84743 __page_cache_release(page);
84744 dtor = get_compound_page_dtor(page);
84745+ if (!PageHuge(page))
84746+ BUG_ON(dtor != free_compound_page);
84747 (*dtor)(page);
84748 }
84749
84750diff --git a/mm/swapfile.c b/mm/swapfile.c
84751index a1f7772..9e982ac 100644
84752--- a/mm/swapfile.c
84753+++ b/mm/swapfile.c
84754@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
84755
84756 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
84757 /* Activity counter to indicate that a swapon or swapoff has occurred */
84758-static atomic_t proc_poll_event = ATOMIC_INIT(0);
84759+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
84760
84761 static inline unsigned char swap_count(unsigned char ent)
84762 {
84763@@ -1683,7 +1683,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
84764 }
84765 filp_close(swap_file, NULL);
84766 err = 0;
84767- atomic_inc(&proc_poll_event);
84768+ atomic_inc_unchecked(&proc_poll_event);
84769 wake_up_interruptible(&proc_poll_wait);
84770
84771 out_dput:
84772@@ -1700,8 +1700,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
84773
84774 poll_wait(file, &proc_poll_wait, wait);
84775
84776- if (seq->poll_event != atomic_read(&proc_poll_event)) {
84777- seq->poll_event = atomic_read(&proc_poll_event);
84778+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
84779+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
84780 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
84781 }
84782
84783@@ -1799,7 +1799,7 @@ static int swaps_open(struct inode *inode, struct file *file)
84784 return ret;
84785
84786 seq = file->private_data;
84787- seq->poll_event = atomic_read(&proc_poll_event);
84788+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
84789 return 0;
84790 }
84791
84792@@ -2142,7 +2142,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
84793 (frontswap_map) ? "FS" : "");
84794
84795 mutex_unlock(&swapon_mutex);
84796- atomic_inc(&proc_poll_event);
84797+ atomic_inc_unchecked(&proc_poll_event);
84798 wake_up_interruptible(&proc_poll_wait);
84799
84800 if (S_ISREG(inode->i_mode))
84801diff --git a/mm/util.c b/mm/util.c
84802index ab1424d..7c5bd5a 100644
84803--- a/mm/util.c
84804+++ b/mm/util.c
84805@@ -294,6 +294,12 @@ done:
84806 void arch_pick_mmap_layout(struct mm_struct *mm)
84807 {
84808 mm->mmap_base = TASK_UNMAPPED_BASE;
84809+
84810+#ifdef CONFIG_PAX_RANDMMAP
84811+ if (mm->pax_flags & MF_PAX_RANDMMAP)
84812+ mm->mmap_base += mm->delta_mmap;
84813+#endif
84814+
84815 mm->get_unmapped_area = arch_get_unmapped_area;
84816 mm->unmap_area = arch_unmap_area;
84817 }
84818diff --git a/mm/vmalloc.c b/mm/vmalloc.c
84819index 0f751f2..ef398a0 100644
84820--- a/mm/vmalloc.c
84821+++ b/mm/vmalloc.c
84822@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
84823
84824 pte = pte_offset_kernel(pmd, addr);
84825 do {
84826- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
84827- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
84828+
84829+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84830+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
84831+ BUG_ON(!pte_exec(*pte));
84832+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
84833+ continue;
84834+ }
84835+#endif
84836+
84837+ {
84838+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
84839+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
84840+ }
84841 } while (pte++, addr += PAGE_SIZE, addr != end);
84842 }
84843
84844@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
84845 pte = pte_alloc_kernel(pmd, addr);
84846 if (!pte)
84847 return -ENOMEM;
84848+
84849+ pax_open_kernel();
84850 do {
84851 struct page *page = pages[*nr];
84852
84853- if (WARN_ON(!pte_none(*pte)))
84854+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84855+ if (pgprot_val(prot) & _PAGE_NX)
84856+#endif
84857+
84858+ if (!pte_none(*pte)) {
84859+ pax_close_kernel();
84860+ WARN_ON(1);
84861 return -EBUSY;
84862- if (WARN_ON(!page))
84863+ }
84864+ if (!page) {
84865+ pax_close_kernel();
84866+ WARN_ON(1);
84867 return -ENOMEM;
84868+ }
84869 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
84870 (*nr)++;
84871 } while (pte++, addr += PAGE_SIZE, addr != end);
84872+ pax_close_kernel();
84873 return 0;
84874 }
84875
84876@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
84877 pmd_t *pmd;
84878 unsigned long next;
84879
84880- pmd = pmd_alloc(&init_mm, pud, addr);
84881+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
84882 if (!pmd)
84883 return -ENOMEM;
84884 do {
84885@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
84886 pud_t *pud;
84887 unsigned long next;
84888
84889- pud = pud_alloc(&init_mm, pgd, addr);
84890+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
84891 if (!pud)
84892 return -ENOMEM;
84893 do {
84894@@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
84895 * and fall back on vmalloc() if that fails. Others
84896 * just put it in the vmalloc space.
84897 */
84898-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
84899+#ifdef CONFIG_MODULES
84900+#ifdef MODULES_VADDR
84901 unsigned long addr = (unsigned long)x;
84902 if (addr >= MODULES_VADDR && addr < MODULES_END)
84903 return 1;
84904 #endif
84905+
84906+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84907+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
84908+ return 1;
84909+#endif
84910+
84911+#endif
84912+
84913 return is_vmalloc_addr(x);
84914 }
84915
84916@@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
84917
84918 if (!pgd_none(*pgd)) {
84919 pud_t *pud = pud_offset(pgd, addr);
84920+#ifdef CONFIG_X86
84921+ if (!pud_large(*pud))
84922+#endif
84923 if (!pud_none(*pud)) {
84924 pmd_t *pmd = pmd_offset(pud, addr);
84925+#ifdef CONFIG_X86
84926+ if (!pmd_large(*pmd))
84927+#endif
84928 if (!pmd_none(*pmd)) {
84929 pte_t *ptep, pte;
84930
84931@@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
84932 * Allocate a region of KVA of the specified size and alignment, within the
84933 * vstart and vend.
84934 */
84935-static struct vmap_area *alloc_vmap_area(unsigned long size,
84936+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
84937 unsigned long align,
84938 unsigned long vstart, unsigned long vend,
84939 int node, gfp_t gfp_mask)
84940@@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
84941 struct vm_struct *area;
84942
84943 BUG_ON(in_interrupt());
84944+
84945+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
84946+ if (flags & VM_KERNEXEC) {
84947+ if (start != VMALLOC_START || end != VMALLOC_END)
84948+ return NULL;
84949+ start = (unsigned long)MODULES_EXEC_VADDR;
84950+ end = (unsigned long)MODULES_EXEC_END;
84951+ }
84952+#endif
84953+
84954 if (flags & VM_IOREMAP) {
84955 int bit = fls(size);
84956
84957@@ -1569,6 +1618,11 @@ void *vmap(struct page **pages, unsigned int count,
84958 if (count > totalram_pages)
84959 return NULL;
84960
84961+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
84962+ if (!(pgprot_val(prot) & _PAGE_NX))
84963+ flags |= VM_KERNEXEC;
84964+#endif
84965+
84966 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
84967 __builtin_return_address(0));
84968 if (!area)
84969@@ -1670,6 +1724,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
84970 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
84971 goto fail;
84972
84973+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
84974+ if (!(pgprot_val(prot) & _PAGE_NX))
84975+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
84976+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
84977+ else
84978+#endif
84979+
84980 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
84981 start, end, node, gfp_mask, caller);
84982 if (!area)
84983@@ -1845,10 +1906,9 @@ EXPORT_SYMBOL(vzalloc_node);
84984 * For tight control over page level allocator and protection flags
84985 * use __vmalloc() instead.
84986 */
84987-
84988 void *vmalloc_exec(unsigned long size)
84989 {
84990- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
84991+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
84992 NUMA_NO_NODE, __builtin_return_address(0));
84993 }
84994
84995@@ -2139,6 +2199,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
84996 unsigned long uaddr = vma->vm_start;
84997 unsigned long usize = vma->vm_end - vma->vm_start;
84998
84999+ BUG_ON(vma->vm_mirror);
85000+
85001 if ((PAGE_SIZE-1) & (unsigned long)addr)
85002 return -EINVAL;
85003
85004@@ -2578,7 +2640,11 @@ static int s_show(struct seq_file *m, void *p)
85005 v->addr, v->addr + v->size, v->size);
85006
85007 if (v->caller)
85008+#ifdef CONFIG_GRKERNSEC_HIDESYM
85009+ seq_printf(m, " %pK", v->caller);
85010+#else
85011 seq_printf(m, " %pS", v->caller);
85012+#endif
85013
85014 if (v->nr_pages)
85015 seq_printf(m, " pages=%d", v->nr_pages);
85016diff --git a/mm/vmstat.c b/mm/vmstat.c
85017index e1d8ed1..253fa3c 100644
85018--- a/mm/vmstat.c
85019+++ b/mm/vmstat.c
85020@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
85021 *
85022 * vm_stat contains the global counters
85023 */
85024-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
85025+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
85026 EXPORT_SYMBOL(vm_stat);
85027
85028 #ifdef CONFIG_SMP
85029@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
85030 v = p->vm_stat_diff[i];
85031 p->vm_stat_diff[i] = 0;
85032 local_irq_restore(flags);
85033- atomic_long_add(v, &zone->vm_stat[i]);
85034+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
85035 global_diff[i] += v;
85036 #ifdef CONFIG_NUMA
85037 /* 3 seconds idle till flush */
85038@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
85039
85040 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
85041 if (global_diff[i])
85042- atomic_long_add(global_diff[i], &vm_stat[i]);
85043+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
85044 }
85045
85046 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
85047@@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
85048 if (pset->vm_stat_diff[i]) {
85049 int v = pset->vm_stat_diff[i];
85050 pset->vm_stat_diff[i] = 0;
85051- atomic_long_add(v, &zone->vm_stat[i]);
85052- atomic_long_add(v, &vm_stat[i]);
85053+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
85054+ atomic_long_add_unchecked(v, &vm_stat[i]);
85055 }
85056 }
85057 #endif
85058@@ -1224,7 +1224,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
85059 return NOTIFY_OK;
85060 }
85061
85062-static struct notifier_block __cpuinitdata vmstat_notifier =
85063+static struct notifier_block vmstat_notifier =
85064 { &vmstat_cpuup_callback, NULL, 0 };
85065 #endif
85066
85067@@ -1239,10 +1239,20 @@ static int __init setup_vmstat(void)
85068 start_cpu_timer(cpu);
85069 #endif
85070 #ifdef CONFIG_PROC_FS
85071- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
85072- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
85073- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
85074- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
85075+ {
85076+ mode_t gr_mode = S_IRUGO;
85077+#ifdef CONFIG_GRKERNSEC_PROC_ADD
85078+ gr_mode = S_IRUSR;
85079+#endif
85080+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
85081+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
85082+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
85083+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
85084+#else
85085+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
85086+#endif
85087+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
85088+ }
85089 #endif
85090 return 0;
85091 }
85092diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
85093index 85addcd..c429a13 100644
85094--- a/net/8021q/vlan.c
85095+++ b/net/8021q/vlan.c
85096@@ -114,6 +114,13 @@ void unregister_vlan_dev(struct net_device *dev, struct list_head *head)
85097 if (vlan_id)
85098 vlan_vid_del(real_dev, vlan_id);
85099
85100+ /* Take it out of our own structures, but be sure to interlock with
85101+ * HW accelerating devices or SW vlan input packet processing if
85102+ * VLAN is not 0 (leave it there for 802.1p).
85103+ */
85104+ if (vlan_id)
85105+ vlan_vid_del(real_dev, vlan_id);
85106+
85107 /* Get rid of the vlan's reference to real_dev */
85108 dev_put(real_dev);
85109 }
85110@@ -496,7 +503,7 @@ out:
85111 return NOTIFY_DONE;
85112 }
85113
85114-static struct notifier_block vlan_notifier_block __read_mostly = {
85115+static struct notifier_block vlan_notifier_block = {
85116 .notifier_call = vlan_device_event,
85117 };
85118
85119@@ -571,8 +578,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
85120 err = -EPERM;
85121 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
85122 break;
85123- if ((args.u.name_type >= 0) &&
85124- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
85125+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
85126 struct vlan_net *vn;
85127
85128 vn = net_generic(net, vlan_net_id);
85129diff --git a/net/9p/mod.c b/net/9p/mod.c
85130index 6ab36ae..6f1841b 100644
85131--- a/net/9p/mod.c
85132+++ b/net/9p/mod.c
85133@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
85134 void v9fs_register_trans(struct p9_trans_module *m)
85135 {
85136 spin_lock(&v9fs_trans_lock);
85137- list_add_tail(&m->list, &v9fs_trans_list);
85138+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
85139 spin_unlock(&v9fs_trans_lock);
85140 }
85141 EXPORT_SYMBOL(v9fs_register_trans);
85142@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
85143 void v9fs_unregister_trans(struct p9_trans_module *m)
85144 {
85145 spin_lock(&v9fs_trans_lock);
85146- list_del_init(&m->list);
85147+ pax_list_del_init((struct list_head *)&m->list);
85148 spin_unlock(&v9fs_trans_lock);
85149 }
85150 EXPORT_SYMBOL(v9fs_unregister_trans);
85151diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
85152index 02efb25..41541a9 100644
85153--- a/net/9p/trans_fd.c
85154+++ b/net/9p/trans_fd.c
85155@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
85156 oldfs = get_fs();
85157 set_fs(get_ds());
85158 /* The cast to a user pointer is valid due to the set_fs() */
85159- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
85160+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
85161 set_fs(oldfs);
85162
85163 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
85164diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
85165index 876fbe8..8bbea9f 100644
85166--- a/net/atm/atm_misc.c
85167+++ b/net/atm/atm_misc.c
85168@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
85169 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
85170 return 1;
85171 atm_return(vcc, truesize);
85172- atomic_inc(&vcc->stats->rx_drop);
85173+ atomic_inc_unchecked(&vcc->stats->rx_drop);
85174 return 0;
85175 }
85176 EXPORT_SYMBOL(atm_charge);
85177@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
85178 }
85179 }
85180 atm_return(vcc, guess);
85181- atomic_inc(&vcc->stats->rx_drop);
85182+ atomic_inc_unchecked(&vcc->stats->rx_drop);
85183 return NULL;
85184 }
85185 EXPORT_SYMBOL(atm_alloc_charge);
85186@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
85187
85188 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
85189 {
85190-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
85191+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
85192 __SONET_ITEMS
85193 #undef __HANDLE_ITEM
85194 }
85195@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
85196
85197 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
85198 {
85199-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
85200+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
85201 __SONET_ITEMS
85202 #undef __HANDLE_ITEM
85203 }
85204diff --git a/net/atm/lec.h b/net/atm/lec.h
85205index a86aff9..3a0d6f6 100644
85206--- a/net/atm/lec.h
85207+++ b/net/atm/lec.h
85208@@ -48,7 +48,7 @@ struct lane2_ops {
85209 const u8 *tlvs, u32 sizeoftlvs);
85210 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
85211 const u8 *tlvs, u32 sizeoftlvs);
85212-};
85213+} __no_const;
85214
85215 /*
85216 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
85217diff --git a/net/atm/proc.c b/net/atm/proc.c
85218index 6ac35ff..ac0e136 100644
85219--- a/net/atm/proc.c
85220+++ b/net/atm/proc.c
85221@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
85222 const struct k_atm_aal_stats *stats)
85223 {
85224 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
85225- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
85226- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
85227- atomic_read(&stats->rx_drop));
85228+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
85229+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
85230+ atomic_read_unchecked(&stats->rx_drop));
85231 }
85232
85233 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
85234diff --git a/net/atm/resources.c b/net/atm/resources.c
85235index 0447d5d..3cf4728 100644
85236--- a/net/atm/resources.c
85237+++ b/net/atm/resources.c
85238@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
85239 static void copy_aal_stats(struct k_atm_aal_stats *from,
85240 struct atm_aal_stats *to)
85241 {
85242-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
85243+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
85244 __AAL_STAT_ITEMS
85245 #undef __HANDLE_ITEM
85246 }
85247@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
85248 static void subtract_aal_stats(struct k_atm_aal_stats *from,
85249 struct atm_aal_stats *to)
85250 {
85251-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
85252+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
85253 __AAL_STAT_ITEMS
85254 #undef __HANDLE_ITEM
85255 }
85256diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
85257index d5744b7..506bae3 100644
85258--- a/net/ax25/sysctl_net_ax25.c
85259+++ b/net/ax25/sysctl_net_ax25.c
85260@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
85261 {
85262 char path[sizeof("net/ax25/") + IFNAMSIZ];
85263 int k;
85264- struct ctl_table *table;
85265+ ctl_table_no_const *table;
85266
85267 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
85268 if (!table)
85269diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
85270index a5bb0a7..e1d8b97 100644
85271--- a/net/batman-adv/bat_iv_ogm.c
85272+++ b/net/batman-adv/bat_iv_ogm.c
85273@@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
85274
85275 /* randomize initial seqno to avoid collision */
85276 get_random_bytes(&random_seqno, sizeof(random_seqno));
85277- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
85278+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
85279
85280 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
85281 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
85282@@ -611,9 +611,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
85283 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
85284
85285 /* change sequence number to network order */
85286- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
85287+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
85288 batadv_ogm_packet->seqno = htonl(seqno);
85289- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
85290+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
85291
85292 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
85293 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
85294@@ -1013,7 +1013,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
85295 return;
85296
85297 /* could be changed by schedule_own_packet() */
85298- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
85299+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
85300
85301 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
85302 has_directlink_flag = 1;
85303diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
85304index 368219e..53f56f9 100644
85305--- a/net/batman-adv/hard-interface.c
85306+++ b/net/batman-adv/hard-interface.c
85307@@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
85308 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
85309 dev_add_pack(&hard_iface->batman_adv_ptype);
85310
85311- atomic_set(&hard_iface->frag_seqno, 1);
85312+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
85313 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
85314 hard_iface->net_dev->name);
85315
85316@@ -514,7 +514,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
85317 /* This can't be called via a bat_priv callback because
85318 * we have no bat_priv yet.
85319 */
85320- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
85321+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
85322 hard_iface->bat_iv.ogm_buff = NULL;
85323
85324 return hard_iface;
85325diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
85326index 2711e87..4ca48fa 100644
85327--- a/net/batman-adv/soft-interface.c
85328+++ b/net/batman-adv/soft-interface.c
85329@@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
85330 primary_if->net_dev->dev_addr, ETH_ALEN);
85331
85332 /* set broadcast sequence number */
85333- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
85334+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
85335 bcast_packet->seqno = htonl(seqno);
85336
85337 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
85338@@ -527,7 +527,7 @@ struct net_device *batadv_softif_create(const char *name)
85339 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
85340
85341 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
85342- atomic_set(&bat_priv->bcast_seqno, 1);
85343+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
85344 atomic_set(&bat_priv->tt.vn, 0);
85345 atomic_set(&bat_priv->tt.local_changes, 0);
85346 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
85347diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
85348index 4cd87a0..348e705 100644
85349--- a/net/batman-adv/types.h
85350+++ b/net/batman-adv/types.h
85351@@ -51,7 +51,7 @@
85352 struct batadv_hard_iface_bat_iv {
85353 unsigned char *ogm_buff;
85354 int ogm_buff_len;
85355- atomic_t ogm_seqno;
85356+ atomic_unchecked_t ogm_seqno;
85357 };
85358
85359 /**
85360@@ -75,7 +75,7 @@ struct batadv_hard_iface {
85361 int16_t if_num;
85362 char if_status;
85363 struct net_device *net_dev;
85364- atomic_t frag_seqno;
85365+ atomic_unchecked_t frag_seqno;
85366 struct kobject *hardif_obj;
85367 atomic_t refcount;
85368 struct packet_type batman_adv_ptype;
85369@@ -495,7 +495,7 @@ struct batadv_priv {
85370 #ifdef CONFIG_BATMAN_ADV_DEBUG
85371 atomic_t log_level;
85372 #endif
85373- atomic_t bcast_seqno;
85374+ atomic_unchecked_t bcast_seqno;
85375 atomic_t bcast_queue_left;
85376 atomic_t batman_queue_left;
85377 char num_ifaces;
85378diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
85379index 50e079f..49ce2d2 100644
85380--- a/net/batman-adv/unicast.c
85381+++ b/net/batman-adv/unicast.c
85382@@ -270,7 +270,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
85383 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
85384 frag2->flags = large_tail;
85385
85386- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
85387+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
85388 frag1->seqno = htons(seqno - 1);
85389 frag2->seqno = htons(seqno);
85390
85391diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
85392index 6a93614..1415549 100644
85393--- a/net/bluetooth/hci_sock.c
85394+++ b/net/bluetooth/hci_sock.c
85395@@ -929,7 +929,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
85396 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
85397 }
85398
85399- len = min_t(unsigned int, len, sizeof(uf));
85400+ len = min((size_t)len, sizeof(uf));
85401 if (copy_from_user(&uf, optval, len)) {
85402 err = -EFAULT;
85403 break;
85404diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
85405index 7c7e932..8d23158 100644
85406--- a/net/bluetooth/l2cap_core.c
85407+++ b/net/bluetooth/l2cap_core.c
85408@@ -3395,8 +3395,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
85409 break;
85410
85411 case L2CAP_CONF_RFC:
85412- if (olen == sizeof(rfc))
85413- memcpy(&rfc, (void *)val, olen);
85414+ if (olen != sizeof(rfc))
85415+ break;
85416+
85417+ memcpy(&rfc, (void *)val, olen);
85418
85419 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
85420 rfc.mode != chan->mode)
85421@@ -3568,10 +3570,14 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
85422 }
85423
85424 static inline int l2cap_command_rej(struct l2cap_conn *conn,
85425- struct l2cap_cmd_hdr *cmd, u8 *data)
85426+ struct l2cap_cmd_hdr *cmd, u16 cmd_len,
85427+ u8 *data)
85428 {
85429 struct l2cap_cmd_rej_unk *rej = (struct l2cap_cmd_rej_unk *) data;
85430
85431+ if (cmd_len < sizeof(*rej))
85432+ return -EPROTO;
85433+
85434 if (rej->reason != L2CAP_REJ_NOT_UNDERSTOOD)
85435 return 0;
85436
85437@@ -3720,11 +3726,14 @@ sendresp:
85438 }
85439
85440 static int l2cap_connect_req(struct l2cap_conn *conn,
85441- struct l2cap_cmd_hdr *cmd, u8 *data)
85442+ struct l2cap_cmd_hdr *cmd, u16 cmd_len, u8 *data)
85443 {
85444 struct hci_dev *hdev = conn->hcon->hdev;
85445 struct hci_conn *hcon = conn->hcon;
85446
85447+ if (cmd_len < sizeof(struct l2cap_conn_req))
85448+ return -EPROTO;
85449+
85450 hci_dev_lock(hdev);
85451 if (test_bit(HCI_MGMT, &hdev->dev_flags) &&
85452 !test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &hcon->flags))
85453@@ -3738,7 +3747,8 @@ static int l2cap_connect_req(struct l2cap_conn *conn,
85454 }
85455
85456 static int l2cap_connect_create_rsp(struct l2cap_conn *conn,
85457- struct l2cap_cmd_hdr *cmd, u8 *data)
85458+ struct l2cap_cmd_hdr *cmd, u16 cmd_len,
85459+ u8 *data)
85460 {
85461 struct l2cap_conn_rsp *rsp = (struct l2cap_conn_rsp *) data;
85462 u16 scid, dcid, result, status;
85463@@ -3746,6 +3756,9 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn,
85464 u8 req[128];
85465 int err;
85466
85467+ if (cmd_len < sizeof(*rsp))
85468+ return -EPROTO;
85469+
85470 scid = __le16_to_cpu(rsp->scid);
85471 dcid = __le16_to_cpu(rsp->dcid);
85472 result = __le16_to_cpu(rsp->result);
85473@@ -3843,6 +3856,9 @@ static inline int l2cap_config_req(struct l2cap_conn *conn,
85474 struct l2cap_chan *chan;
85475 int len, err = 0;
85476
85477+ if (cmd_len < sizeof(*req))
85478+ return -EPROTO;
85479+
85480 dcid = __le16_to_cpu(req->dcid);
85481 flags = __le16_to_cpu(req->flags);
85482
85483@@ -3866,7 +3882,7 @@ static inline int l2cap_config_req(struct l2cap_conn *conn,
85484
85485 /* Reject if config buffer is too small. */
85486 len = cmd_len - sizeof(*req);
85487- if (len < 0 || chan->conf_len + len > sizeof(chan->conf_req)) {
85488+ if (chan->conf_len + len > sizeof(chan->conf_req)) {
85489 l2cap_send_cmd(conn, cmd->ident, L2CAP_CONF_RSP,
85490 l2cap_build_conf_rsp(chan, rsp,
85491 L2CAP_CONF_REJECT, flags), rsp);
85492@@ -3944,14 +3960,18 @@ unlock:
85493 }
85494
85495 static inline int l2cap_config_rsp(struct l2cap_conn *conn,
85496- struct l2cap_cmd_hdr *cmd, u8 *data)
85497+ struct l2cap_cmd_hdr *cmd, u16 cmd_len,
85498+ u8 *data)
85499 {
85500 struct l2cap_conf_rsp *rsp = (struct l2cap_conf_rsp *)data;
85501 u16 scid, flags, result;
85502 struct l2cap_chan *chan;
85503- int len = le16_to_cpu(cmd->len) - sizeof(*rsp);
85504+ int len = cmd_len - sizeof(*rsp);
85505 int err = 0;
85506
85507+ if (cmd_len < sizeof(*rsp))
85508+ return -EPROTO;
85509+
85510 scid = __le16_to_cpu(rsp->scid);
85511 flags = __le16_to_cpu(rsp->flags);
85512 result = __le16_to_cpu(rsp->result);
85513@@ -4052,7 +4072,8 @@ done:
85514 }
85515
85516 static inline int l2cap_disconnect_req(struct l2cap_conn *conn,
85517- struct l2cap_cmd_hdr *cmd, u8 *data)
85518+ struct l2cap_cmd_hdr *cmd, u16 cmd_len,
85519+ u8 *data)
85520 {
85521 struct l2cap_disconn_req *req = (struct l2cap_disconn_req *) data;
85522 struct l2cap_disconn_rsp rsp;
85523@@ -4060,6 +4081,9 @@ static inline int l2cap_disconnect_req(struct l2cap_conn *conn,
85524 struct l2cap_chan *chan;
85525 struct sock *sk;
85526
85527+ if (cmd_len != sizeof(*req))
85528+ return -EPROTO;
85529+
85530 scid = __le16_to_cpu(req->scid);
85531 dcid = __le16_to_cpu(req->dcid);
85532
85533@@ -4099,12 +4123,16 @@ static inline int l2cap_disconnect_req(struct l2cap_conn *conn,
85534 }
85535
85536 static inline int l2cap_disconnect_rsp(struct l2cap_conn *conn,
85537- struct l2cap_cmd_hdr *cmd, u8 *data)
85538+ struct l2cap_cmd_hdr *cmd, u16 cmd_len,
85539+ u8 *data)
85540 {
85541 struct l2cap_disconn_rsp *rsp = (struct l2cap_disconn_rsp *) data;
85542 u16 dcid, scid;
85543 struct l2cap_chan *chan;
85544
85545+ if (cmd_len != sizeof(*rsp))
85546+ return -EPROTO;
85547+
85548 scid = __le16_to_cpu(rsp->scid);
85549 dcid = __le16_to_cpu(rsp->dcid);
85550
85551@@ -4134,11 +4162,15 @@ static inline int l2cap_disconnect_rsp(struct l2cap_conn *conn,
85552 }
85553
85554 static inline int l2cap_information_req(struct l2cap_conn *conn,
85555- struct l2cap_cmd_hdr *cmd, u8 *data)
85556+ struct l2cap_cmd_hdr *cmd, u16 cmd_len,
85557+ u8 *data)
85558 {
85559 struct l2cap_info_req *req = (struct l2cap_info_req *) data;
85560 u16 type;
85561
85562+ if (cmd_len != sizeof(*req))
85563+ return -EPROTO;
85564+
85565 type = __le16_to_cpu(req->type);
85566
85567 BT_DBG("type 0x%4.4x", type);
85568@@ -4185,11 +4217,15 @@ static inline int l2cap_information_req(struct l2cap_conn *conn,
85569 }
85570
85571 static inline int l2cap_information_rsp(struct l2cap_conn *conn,
85572- struct l2cap_cmd_hdr *cmd, u8 *data)
85573+ struct l2cap_cmd_hdr *cmd, u16 cmd_len,
85574+ u8 *data)
85575 {
85576 struct l2cap_info_rsp *rsp = (struct l2cap_info_rsp *) data;
85577 u16 type, result;
85578
85579+ if (cmd_len != sizeof(*rsp))
85580+ return -EPROTO;
85581+
85582 type = __le16_to_cpu(rsp->type);
85583 result = __le16_to_cpu(rsp->result);
85584
85585@@ -5055,16 +5091,16 @@ static inline int l2cap_bredr_sig_cmd(struct l2cap_conn *conn,
85586
85587 switch (cmd->code) {
85588 case L2CAP_COMMAND_REJ:
85589- l2cap_command_rej(conn, cmd, data);
85590+ l2cap_command_rej(conn, cmd, cmd_len, data);
85591 break;
85592
85593 case L2CAP_CONN_REQ:
85594- err = l2cap_connect_req(conn, cmd, data);
85595+ err = l2cap_connect_req(conn, cmd, cmd_len, data);
85596 break;
85597
85598 case L2CAP_CONN_RSP:
85599 case L2CAP_CREATE_CHAN_RSP:
85600- err = l2cap_connect_create_rsp(conn, cmd, data);
85601+ err = l2cap_connect_create_rsp(conn, cmd, cmd_len, data);
85602 break;
85603
85604 case L2CAP_CONF_REQ:
85605@@ -5072,15 +5108,15 @@ static inline int l2cap_bredr_sig_cmd(struct l2cap_conn *conn,
85606 break;
85607
85608 case L2CAP_CONF_RSP:
85609- err = l2cap_config_rsp(conn, cmd, data);
85610+ err = l2cap_config_rsp(conn, cmd, cmd_len, data);
85611 break;
85612
85613 case L2CAP_DISCONN_REQ:
85614- err = l2cap_disconnect_req(conn, cmd, data);
85615+ err = l2cap_disconnect_req(conn, cmd, cmd_len, data);
85616 break;
85617
85618 case L2CAP_DISCONN_RSP:
85619- err = l2cap_disconnect_rsp(conn, cmd, data);
85620+ err = l2cap_disconnect_rsp(conn, cmd, cmd_len, data);
85621 break;
85622
85623 case L2CAP_ECHO_REQ:
85624@@ -5091,11 +5127,11 @@ static inline int l2cap_bredr_sig_cmd(struct l2cap_conn *conn,
85625 break;
85626
85627 case L2CAP_INFO_REQ:
85628- err = l2cap_information_req(conn, cmd, data);
85629+ err = l2cap_information_req(conn, cmd, cmd_len, data);
85630 break;
85631
85632 case L2CAP_INFO_RSP:
85633- err = l2cap_information_rsp(conn, cmd, data);
85634+ err = l2cap_information_rsp(conn, cmd, cmd_len, data);
85635 break;
85636
85637 case L2CAP_CREATE_CHAN_REQ:
85638diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
85639index 1bcfb84..dad9f98 100644
85640--- a/net/bluetooth/l2cap_sock.c
85641+++ b/net/bluetooth/l2cap_sock.c
85642@@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
85643 struct sock *sk = sock->sk;
85644 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
85645 struct l2cap_options opts;
85646- int len, err = 0;
85647+ int err = 0;
85648+ size_t len = optlen;
85649 u32 opt;
85650
85651 BT_DBG("sk %p", sk);
85652@@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
85653 opts.max_tx = chan->max_tx;
85654 opts.txwin_size = chan->tx_win;
85655
85656- len = min_t(unsigned int, sizeof(opts), optlen);
85657+ len = min(sizeof(opts), len);
85658 if (copy_from_user((char *) &opts, optval, len)) {
85659 err = -EFAULT;
85660 break;
85661@@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
85662 struct bt_security sec;
85663 struct bt_power pwr;
85664 struct l2cap_conn *conn;
85665- int len, err = 0;
85666+ int err = 0;
85667+ size_t len = optlen;
85668 u32 opt;
85669
85670 BT_DBG("sk %p", sk);
85671@@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
85672
85673 sec.level = BT_SECURITY_LOW;
85674
85675- len = min_t(unsigned int, sizeof(sec), optlen);
85676+ len = min(sizeof(sec), len);
85677 if (copy_from_user((char *) &sec, optval, len)) {
85678 err = -EFAULT;
85679 break;
85680@@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
85681
85682 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
85683
85684- len = min_t(unsigned int, sizeof(pwr), optlen);
85685+ len = min(sizeof(pwr), len);
85686 if (copy_from_user((char *) &pwr, optval, len)) {
85687 err = -EFAULT;
85688 break;
85689diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
85690index 7c9224b..381009e 100644
85691--- a/net/bluetooth/rfcomm/sock.c
85692+++ b/net/bluetooth/rfcomm/sock.c
85693@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
85694 struct sock *sk = sock->sk;
85695 struct bt_security sec;
85696 int err = 0;
85697- size_t len;
85698+ size_t len = optlen;
85699 u32 opt;
85700
85701 BT_DBG("sk %p", sk);
85702@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
85703
85704 sec.level = BT_SECURITY_LOW;
85705
85706- len = min_t(unsigned int, sizeof(sec), optlen);
85707+ len = min(sizeof(sec), len);
85708 if (copy_from_user((char *) &sec, optval, len)) {
85709 err = -EFAULT;
85710 break;
85711diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
85712index b6e44ad..5b0d514 100644
85713--- a/net/bluetooth/rfcomm/tty.c
85714+++ b/net/bluetooth/rfcomm/tty.c
85715@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
85716 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
85717
85718 spin_lock_irqsave(&dev->port.lock, flags);
85719- if (dev->port.count > 0) {
85720+ if (atomic_read(&dev->port.count) > 0) {
85721 spin_unlock_irqrestore(&dev->port.lock, flags);
85722 return;
85723 }
85724@@ -659,10 +659,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
85725 return -ENODEV;
85726
85727 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
85728- dev->channel, dev->port.count);
85729+ dev->channel, atomic_read(&dev->port.count));
85730
85731 spin_lock_irqsave(&dev->port.lock, flags);
85732- if (++dev->port.count > 1) {
85733+ if (atomic_inc_return(&dev->port.count) > 1) {
85734 spin_unlock_irqrestore(&dev->port.lock, flags);
85735 return 0;
85736 }
85737@@ -727,10 +727,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
85738 return;
85739
85740 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
85741- dev->port.count);
85742+ atomic_read(&dev->port.count));
85743
85744 spin_lock_irqsave(&dev->port.lock, flags);
85745- if (!--dev->port.count) {
85746+ if (!atomic_dec_return(&dev->port.count)) {
85747 spin_unlock_irqrestore(&dev->port.lock, flags);
85748 if (dev->tty_dev->parent)
85749 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
85750diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
85751index 8d493c9..3849e49 100644
85752--- a/net/bridge/netfilter/ebtables.c
85753+++ b/net/bridge/netfilter/ebtables.c
85754@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85755 tmp.valid_hooks = t->table->valid_hooks;
85756 }
85757 mutex_unlock(&ebt_mutex);
85758- if (copy_to_user(user, &tmp, *len) != 0){
85759+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
85760 BUGPRINT("c2u Didn't work\n");
85761 ret = -EFAULT;
85762 break;
85763@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
85764 goto out;
85765 tmp.valid_hooks = t->valid_hooks;
85766
85767- if (copy_to_user(user, &tmp, *len) != 0) {
85768+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
85769 ret = -EFAULT;
85770 break;
85771 }
85772@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
85773 tmp.entries_size = t->table->entries_size;
85774 tmp.valid_hooks = t->table->valid_hooks;
85775
85776- if (copy_to_user(user, &tmp, *len) != 0) {
85777+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
85778 ret = -EFAULT;
85779 break;
85780 }
85781diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
85782index a376ec1..1fbd6be 100644
85783--- a/net/caif/cfctrl.c
85784+++ b/net/caif/cfctrl.c
85785@@ -10,6 +10,7 @@
85786 #include <linux/spinlock.h>
85787 #include <linux/slab.h>
85788 #include <linux/pkt_sched.h>
85789+#include <linux/sched.h>
85790 #include <net/caif/caif_layer.h>
85791 #include <net/caif/cfpkt.h>
85792 #include <net/caif/cfctrl.h>
85793@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
85794 memset(&dev_info, 0, sizeof(dev_info));
85795 dev_info.id = 0xff;
85796 cfsrvl_init(&this->serv, 0, &dev_info, false);
85797- atomic_set(&this->req_seq_no, 1);
85798- atomic_set(&this->rsp_seq_no, 1);
85799+ atomic_set_unchecked(&this->req_seq_no, 1);
85800+ atomic_set_unchecked(&this->rsp_seq_no, 1);
85801 this->serv.layer.receive = cfctrl_recv;
85802 sprintf(this->serv.layer.name, "ctrl");
85803 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
85804@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
85805 struct cfctrl_request_info *req)
85806 {
85807 spin_lock_bh(&ctrl->info_list_lock);
85808- atomic_inc(&ctrl->req_seq_no);
85809- req->sequence_no = atomic_read(&ctrl->req_seq_no);
85810+ atomic_inc_unchecked(&ctrl->req_seq_no);
85811+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
85812 list_add_tail(&req->list, &ctrl->list);
85813 spin_unlock_bh(&ctrl->info_list_lock);
85814 }
85815@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
85816 if (p != first)
85817 pr_warn("Requests are not received in order\n");
85818
85819- atomic_set(&ctrl->rsp_seq_no,
85820+ atomic_set_unchecked(&ctrl->rsp_seq_no,
85821 p->sequence_no);
85822 list_del(&p->list);
85823 goto out;
85824diff --git a/net/can/af_can.c b/net/can/af_can.c
85825index c48e522..1223690 100644
85826--- a/net/can/af_can.c
85827+++ b/net/can/af_can.c
85828@@ -870,7 +870,7 @@ static const struct net_proto_family can_family_ops = {
85829 };
85830
85831 /* notifier block for netdevice event */
85832-static struct notifier_block can_netdev_notifier __read_mostly = {
85833+static struct notifier_block can_netdev_notifier = {
85834 .notifier_call = can_notifier,
85835 };
85836
85837diff --git a/net/can/gw.c b/net/can/gw.c
85838index 117814a..ad4fb73 100644
85839--- a/net/can/gw.c
85840+++ b/net/can/gw.c
85841@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
85842 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
85843
85844 static HLIST_HEAD(cgw_list);
85845-static struct notifier_block notifier;
85846
85847 static struct kmem_cache *cgw_cache __read_mostly;
85848
85849@@ -928,6 +927,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
85850 return err;
85851 }
85852
85853+static struct notifier_block notifier = {
85854+ .notifier_call = cgw_notifier
85855+};
85856+
85857 static __init int cgw_module_init(void)
85858 {
85859 /* sanitize given module parameter */
85860@@ -943,7 +946,6 @@ static __init int cgw_module_init(void)
85861 return -ENOMEM;
85862
85863 /* set notifier */
85864- notifier.notifier_call = cgw_notifier;
85865 register_netdevice_notifier(&notifier);
85866
85867 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
85868diff --git a/net/compat.c b/net/compat.c
85869index 79ae884..0541331 100644
85870--- a/net/compat.c
85871+++ b/net/compat.c
85872@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
85873 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
85874 __get_user(kmsg->msg_flags, &umsg->msg_flags))
85875 return -EFAULT;
85876- kmsg->msg_name = compat_ptr(tmp1);
85877- kmsg->msg_iov = compat_ptr(tmp2);
85878- kmsg->msg_control = compat_ptr(tmp3);
85879+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
85880+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
85881+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
85882 return 0;
85883 }
85884
85885@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
85886
85887 if (kern_msg->msg_namelen) {
85888 if (mode == VERIFY_READ) {
85889- int err = move_addr_to_kernel(kern_msg->msg_name,
85890+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
85891 kern_msg->msg_namelen,
85892 kern_address);
85893 if (err < 0)
85894@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
85895 kern_msg->msg_name = NULL;
85896
85897 tot_len = iov_from_user_compat_to_kern(kern_iov,
85898- (struct compat_iovec __user *)kern_msg->msg_iov,
85899+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
85900 kern_msg->msg_iovlen);
85901 if (tot_len >= 0)
85902 kern_msg->msg_iov = kern_iov;
85903@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
85904
85905 #define CMSG_COMPAT_FIRSTHDR(msg) \
85906 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
85907- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
85908+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
85909 (struct compat_cmsghdr __user *)NULL)
85910
85911 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
85912 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
85913 (ucmlen) <= (unsigned long) \
85914 ((mhdr)->msg_controllen - \
85915- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
85916+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
85917
85918 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
85919 struct compat_cmsghdr __user *cmsg, int cmsg_len)
85920 {
85921 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
85922- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
85923+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
85924 msg->msg_controllen)
85925 return NULL;
85926 return (struct compat_cmsghdr __user *)ptr;
85927@@ -219,7 +219,7 @@ Efault:
85928
85929 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
85930 {
85931- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
85932+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
85933 struct compat_cmsghdr cmhdr;
85934 struct compat_timeval ctv;
85935 struct compat_timespec cts[3];
85936@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
85937
85938 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
85939 {
85940- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
85941+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
85942 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
85943 int fdnum = scm->fp->count;
85944 struct file **fp = scm->fp->fp;
85945@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
85946 return -EFAULT;
85947 old_fs = get_fs();
85948 set_fs(KERNEL_DS);
85949- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
85950+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
85951 set_fs(old_fs);
85952
85953 return err;
85954@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
85955 len = sizeof(ktime);
85956 old_fs = get_fs();
85957 set_fs(KERNEL_DS);
85958- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
85959+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
85960 set_fs(old_fs);
85961
85962 if (!err) {
85963@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
85964 case MCAST_JOIN_GROUP:
85965 case MCAST_LEAVE_GROUP:
85966 {
85967- struct compat_group_req __user *gr32 = (void *)optval;
85968+ struct compat_group_req __user *gr32 = (void __user *)optval;
85969 struct group_req __user *kgr =
85970 compat_alloc_user_space(sizeof(struct group_req));
85971 u32 interface;
85972@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
85973 case MCAST_BLOCK_SOURCE:
85974 case MCAST_UNBLOCK_SOURCE:
85975 {
85976- struct compat_group_source_req __user *gsr32 = (void *)optval;
85977+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
85978 struct group_source_req __user *kgsr = compat_alloc_user_space(
85979 sizeof(struct group_source_req));
85980 u32 interface;
85981@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
85982 }
85983 case MCAST_MSFILTER:
85984 {
85985- struct compat_group_filter __user *gf32 = (void *)optval;
85986+ struct compat_group_filter __user *gf32 = (void __user *)optval;
85987 struct group_filter __user *kgf;
85988 u32 interface, fmode, numsrc;
85989
85990@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
85991 char __user *optval, int __user *optlen,
85992 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
85993 {
85994- struct compat_group_filter __user *gf32 = (void *)optval;
85995+ struct compat_group_filter __user *gf32 = (void __user *)optval;
85996 struct group_filter __user *kgf;
85997 int __user *koptlen;
85998 u32 interface, fmode, numsrc;
85999@@ -734,19 +734,25 @@ static unsigned char nas[21] = {
86000
86001 asmlinkage long compat_sys_sendmsg(int fd, struct compat_msghdr __user *msg, unsigned int flags)
86002 {
86003- return sys_sendmsg(fd, (struct msghdr __user *)msg, flags | MSG_CMSG_COMPAT);
86004+ if (flags & MSG_CMSG_COMPAT)
86005+ return -EINVAL;
86006+ return __sys_sendmsg(fd, (struct msghdr __user *)msg, flags | MSG_CMSG_COMPAT);
86007 }
86008
86009 asmlinkage long compat_sys_sendmmsg(int fd, struct compat_mmsghdr __user *mmsg,
86010 unsigned int vlen, unsigned int flags)
86011 {
86012+ if (flags & MSG_CMSG_COMPAT)
86013+ return -EINVAL;
86014 return __sys_sendmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
86015 flags | MSG_CMSG_COMPAT);
86016 }
86017
86018 asmlinkage long compat_sys_recvmsg(int fd, struct compat_msghdr __user *msg, unsigned int flags)
86019 {
86020- return sys_recvmsg(fd, (struct msghdr __user *)msg, flags | MSG_CMSG_COMPAT);
86021+ if (flags & MSG_CMSG_COMPAT)
86022+ return -EINVAL;
86023+ return __sys_recvmsg(fd, (struct msghdr __user *)msg, flags | MSG_CMSG_COMPAT);
86024 }
86025
86026 asmlinkage long compat_sys_recv(int fd, void __user *buf, size_t len, unsigned int flags)
86027@@ -768,6 +774,9 @@ asmlinkage long compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg,
86028 int datagrams;
86029 struct timespec ktspec;
86030
86031+ if (flags & MSG_CMSG_COMPAT)
86032+ return -EINVAL;
86033+
86034 if (COMPAT_USE_64BIT_TIME)
86035 return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
86036 flags | MSG_CMSG_COMPAT,
86037@@ -796,7 +805,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
86038
86039 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
86040 return -EINVAL;
86041- if (copy_from_user(a, args, nas[call]))
86042+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
86043 return -EFAULT;
86044 a0 = a[0];
86045 a1 = a[1];
86046diff --git a/net/core/datagram.c b/net/core/datagram.c
86047index 368f9c3..f82d4a3 100644
86048--- a/net/core/datagram.c
86049+++ b/net/core/datagram.c
86050@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
86051 }
86052
86053 kfree_skb(skb);
86054- atomic_inc(&sk->sk_drops);
86055+ atomic_inc_unchecked(&sk->sk_drops);
86056 sk_mem_reclaim_partial(sk);
86057
86058 return err;
86059diff --git a/net/core/dev.c b/net/core/dev.c
86060index 9a278e9..15f2b9e 100644
86061--- a/net/core/dev.c
86062+++ b/net/core/dev.c
86063@@ -1617,7 +1617,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
86064 {
86065 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
86066 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
86067- atomic_long_inc(&dev->rx_dropped);
86068+ atomic_long_inc_unchecked(&dev->rx_dropped);
86069 kfree_skb(skb);
86070 return NET_RX_DROP;
86071 }
86072@@ -1626,7 +1626,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
86073 skb_orphan(skb);
86074
86075 if (unlikely(!is_skb_forwardable(dev, skb))) {
86076- atomic_long_inc(&dev->rx_dropped);
86077+ atomic_long_inc_unchecked(&dev->rx_dropped);
86078 kfree_skb(skb);
86079 return NET_RX_DROP;
86080 }
86081@@ -2351,7 +2351,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
86082
86083 struct dev_gso_cb {
86084 void (*destructor)(struct sk_buff *skb);
86085-};
86086+} __no_const;
86087
86088 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
86089
86090@@ -3093,7 +3093,7 @@ enqueue:
86091
86092 local_irq_restore(flags);
86093
86094- atomic_long_inc(&skb->dev->rx_dropped);
86095+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
86096 kfree_skb(skb);
86097 return NET_RX_DROP;
86098 }
86099@@ -3165,7 +3165,7 @@ int netif_rx_ni(struct sk_buff *skb)
86100 }
86101 EXPORT_SYMBOL(netif_rx_ni);
86102
86103-static void net_tx_action(struct softirq_action *h)
86104+static void net_tx_action(void)
86105 {
86106 struct softnet_data *sd = &__get_cpu_var(softnet_data);
86107
86108@@ -3490,7 +3490,7 @@ ncls:
86109 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
86110 } else {
86111 drop:
86112- atomic_long_inc(&skb->dev->rx_dropped);
86113+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
86114 kfree_skb(skb);
86115 /* Jamal, now you will not able to escape explaining
86116 * me how you were going to use this. :-)
86117@@ -4095,7 +4095,7 @@ void netif_napi_del(struct napi_struct *napi)
86118 }
86119 EXPORT_SYMBOL(netif_napi_del);
86120
86121-static void net_rx_action(struct softirq_action *h)
86122+static void net_rx_action(void)
86123 {
86124 struct softnet_data *sd = &__get_cpu_var(softnet_data);
86125 unsigned long time_limit = jiffies + 2;
86126@@ -5522,7 +5522,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
86127 } else {
86128 netdev_stats_to_stats64(storage, &dev->stats);
86129 }
86130- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
86131+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
86132 return storage;
86133 }
86134 EXPORT_SYMBOL(dev_get_stats);
86135diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
86136index 6cc0481..59cfb00 100644
86137--- a/net/core/dev_ioctl.c
86138+++ b/net/core/dev_ioctl.c
86139@@ -376,9 +376,13 @@ void dev_load(struct net *net, const char *name)
86140 if (no_module && capable(CAP_NET_ADMIN))
86141 no_module = request_module("netdev-%s", name);
86142 if (no_module && capable(CAP_SYS_MODULE)) {
86143+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86144+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
86145+#else
86146 if (!request_module("%s", name))
86147 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
86148 name);
86149+#endif
86150 }
86151 }
86152 EXPORT_SYMBOL(dev_load);
86153diff --git a/net/core/flow.c b/net/core/flow.c
86154index 2bfd081..53c6058 100644
86155--- a/net/core/flow.c
86156+++ b/net/core/flow.c
86157@@ -61,7 +61,7 @@ struct flow_cache {
86158 struct timer_list rnd_timer;
86159 };
86160
86161-atomic_t flow_cache_genid = ATOMIC_INIT(0);
86162+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
86163 EXPORT_SYMBOL(flow_cache_genid);
86164 static struct flow_cache flow_cache_global;
86165 static struct kmem_cache *flow_cachep __read_mostly;
86166@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
86167
86168 static int flow_entry_valid(struct flow_cache_entry *fle)
86169 {
86170- if (atomic_read(&flow_cache_genid) != fle->genid)
86171+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
86172 return 0;
86173 if (fle->object && !fle->object->ops->check(fle->object))
86174 return 0;
86175@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
86176 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
86177 fcp->hash_count++;
86178 }
86179- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
86180+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
86181 flo = fle->object;
86182 if (!flo)
86183 goto ret_object;
86184@@ -279,7 +279,7 @@ nocache:
86185 }
86186 flo = resolver(net, key, family, dir, flo, ctx);
86187 if (fle) {
86188- fle->genid = atomic_read(&flow_cache_genid);
86189+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
86190 if (!IS_ERR(flo))
86191 fle->object = flo;
86192 else
86193diff --git a/net/core/iovec.c b/net/core/iovec.c
86194index 7e7aeb0..2a998cb 100644
86195--- a/net/core/iovec.c
86196+++ b/net/core/iovec.c
86197@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
86198 if (m->msg_namelen) {
86199 if (mode == VERIFY_READ) {
86200 void __user *namep;
86201- namep = (void __user __force *) m->msg_name;
86202+ namep = (void __force_user *) m->msg_name;
86203 err = move_addr_to_kernel(namep, m->msg_namelen,
86204 address);
86205 if (err < 0)
86206@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
86207 }
86208
86209 size = m->msg_iovlen * sizeof(struct iovec);
86210- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
86211+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
86212 return -EFAULT;
86213
86214 m->msg_iov = iov;
86215diff --git a/net/core/neighbour.c b/net/core/neighbour.c
86216index 3863b8f..85c99a6 100644
86217--- a/net/core/neighbour.c
86218+++ b/net/core/neighbour.c
86219@@ -2778,7 +2778,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
86220 size_t *lenp, loff_t *ppos)
86221 {
86222 int size, ret;
86223- ctl_table tmp = *ctl;
86224+ ctl_table_no_const tmp = *ctl;
86225
86226 tmp.extra1 = &zero;
86227 tmp.extra2 = &unres_qlen_max;
86228diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
86229index 3174f19..5810985 100644
86230--- a/net/core/net-procfs.c
86231+++ b/net/core/net-procfs.c
86232@@ -271,8 +271,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
86233 else
86234 seq_printf(seq, "%04x", ntohs(pt->type));
86235
86236+#ifdef CONFIG_GRKERNSEC_HIDESYM
86237+ seq_printf(seq, " %-8s %pF\n",
86238+ pt->dev ? pt->dev->name : "", NULL);
86239+#else
86240 seq_printf(seq, " %-8s %pF\n",
86241 pt->dev ? pt->dev->name : "", pt->func);
86242+#endif
86243 }
86244
86245 return 0;
86246diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
86247index 7427ab5..389f411 100644
86248--- a/net/core/net-sysfs.c
86249+++ b/net/core/net-sysfs.c
86250@@ -1321,7 +1321,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
86251 }
86252 EXPORT_SYMBOL(netdev_class_remove_file);
86253
86254-int netdev_kobject_init(void)
86255+int __init netdev_kobject_init(void)
86256 {
86257 kobj_ns_type_register(&net_ns_type_operations);
86258 return class_register(&net_class);
86259diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
86260index 80e271d..2980cc2 100644
86261--- a/net/core/net_namespace.c
86262+++ b/net/core/net_namespace.c
86263@@ -442,7 +442,7 @@ static int __register_pernet_operations(struct list_head *list,
86264 int error;
86265 LIST_HEAD(net_exit_list);
86266
86267- list_add_tail(&ops->list, list);
86268+ pax_list_add_tail((struct list_head *)&ops->list, list);
86269 if (ops->init || (ops->id && ops->size)) {
86270 for_each_net(net) {
86271 error = ops_init(ops, net);
86272@@ -455,7 +455,7 @@ static int __register_pernet_operations(struct list_head *list,
86273
86274 out_undo:
86275 /* If I have an error cleanup all namespaces I initialized */
86276- list_del(&ops->list);
86277+ pax_list_del((struct list_head *)&ops->list);
86278 ops_exit_list(ops, &net_exit_list);
86279 ops_free_list(ops, &net_exit_list);
86280 return error;
86281@@ -466,7 +466,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
86282 struct net *net;
86283 LIST_HEAD(net_exit_list);
86284
86285- list_del(&ops->list);
86286+ pax_list_del((struct list_head *)&ops->list);
86287 for_each_net(net)
86288 list_add_tail(&net->exit_list, &net_exit_list);
86289 ops_exit_list(ops, &net_exit_list);
86290@@ -600,7 +600,7 @@ int register_pernet_device(struct pernet_operations *ops)
86291 mutex_lock(&net_mutex);
86292 error = register_pernet_operations(&pernet_list, ops);
86293 if (!error && (first_device == &pernet_list))
86294- first_device = &ops->list;
86295+ first_device = (struct list_head *)&ops->list;
86296 mutex_unlock(&net_mutex);
86297 return error;
86298 }
86299diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
86300index 23854b5..ff4fda4 100644
86301--- a/net/core/rtnetlink.c
86302+++ b/net/core/rtnetlink.c
86303@@ -58,7 +58,7 @@ struct rtnl_link {
86304 rtnl_doit_func doit;
86305 rtnl_dumpit_func dumpit;
86306 rtnl_calcit_func calcit;
86307-};
86308+} __no_const;
86309
86310 static DEFINE_MUTEX(rtnl_mutex);
86311
86312@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
86313 if (rtnl_link_ops_get(ops->kind))
86314 return -EEXIST;
86315
86316- if (!ops->dellink)
86317- ops->dellink = unregister_netdevice_queue;
86318+ if (!ops->dellink) {
86319+ pax_open_kernel();
86320+ *(void **)&ops->dellink = unregister_netdevice_queue;
86321+ pax_close_kernel();
86322+ }
86323
86324- list_add_tail(&ops->list, &link_ops);
86325+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
86326 return 0;
86327 }
86328 EXPORT_SYMBOL_GPL(__rtnl_link_register);
86329@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
86330 for_each_net(net) {
86331 __rtnl_kill_links(net, ops);
86332 }
86333- list_del(&ops->list);
86334+ pax_list_del((struct list_head *)&ops->list);
86335 }
86336 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
86337
86338diff --git a/net/core/scm.c b/net/core/scm.c
86339index 2dc6cda..2159524 100644
86340--- a/net/core/scm.c
86341+++ b/net/core/scm.c
86342@@ -226,7 +226,7 @@ EXPORT_SYMBOL(__scm_send);
86343 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
86344 {
86345 struct cmsghdr __user *cm
86346- = (__force struct cmsghdr __user *)msg->msg_control;
86347+ = (struct cmsghdr __force_user *)msg->msg_control;
86348 struct cmsghdr cmhdr;
86349 int cmlen = CMSG_LEN(len);
86350 int err;
86351@@ -249,7 +249,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
86352 err = -EFAULT;
86353 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
86354 goto out;
86355- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
86356+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
86357 goto out;
86358 cmlen = CMSG_SPACE(len);
86359 if (msg->msg_controllen < cmlen)
86360@@ -265,7 +265,7 @@ EXPORT_SYMBOL(put_cmsg);
86361 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
86362 {
86363 struct cmsghdr __user *cm
86364- = (__force struct cmsghdr __user*)msg->msg_control;
86365+ = (struct cmsghdr __force_user *)msg->msg_control;
86366
86367 int fdmax = 0;
86368 int fdnum = scm->fp->count;
86369@@ -285,7 +285,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
86370 if (fdnum < fdmax)
86371 fdmax = fdnum;
86372
86373- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
86374+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
86375 i++, cmfptr++)
86376 {
86377 struct socket *sock;
86378diff --git a/net/core/secure_seq.c b/net/core/secure_seq.c
86379index e61a8bb..6a2f13c 100644
86380--- a/net/core/secure_seq.c
86381+++ b/net/core/secure_seq.c
86382@@ -12,12 +12,10 @@
86383
86384 static u32 net_secret[MD5_MESSAGE_BYTES / 4] ____cacheline_aligned;
86385
86386-static int __init net_secret_init(void)
86387+void net_secret_init(void)
86388 {
86389 get_random_bytes(net_secret, sizeof(net_secret));
86390- return 0;
86391 }
86392-late_initcall(net_secret_init);
86393
86394 #ifdef CONFIG_INET
86395 static u32 seq_scale(u32 seq)
86396diff --git a/net/core/sock.c b/net/core/sock.c
86397index 1432266..1a0d4a1 100644
86398--- a/net/core/sock.c
86399+++ b/net/core/sock.c
86400@@ -390,7 +390,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86401 struct sk_buff_head *list = &sk->sk_receive_queue;
86402
86403 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
86404- atomic_inc(&sk->sk_drops);
86405+ atomic_inc_unchecked(&sk->sk_drops);
86406 trace_sock_rcvqueue_full(sk, skb);
86407 return -ENOMEM;
86408 }
86409@@ -400,7 +400,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86410 return err;
86411
86412 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
86413- atomic_inc(&sk->sk_drops);
86414+ atomic_inc_unchecked(&sk->sk_drops);
86415 return -ENOBUFS;
86416 }
86417
86418@@ -420,7 +420,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86419 skb_dst_force(skb);
86420
86421 spin_lock_irqsave(&list->lock, flags);
86422- skb->dropcount = atomic_read(&sk->sk_drops);
86423+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
86424 __skb_queue_tail(list, skb);
86425 spin_unlock_irqrestore(&list->lock, flags);
86426
86427@@ -440,7 +440,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
86428 skb->dev = NULL;
86429
86430 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
86431- atomic_inc(&sk->sk_drops);
86432+ atomic_inc_unchecked(&sk->sk_drops);
86433 goto discard_and_relse;
86434 }
86435 if (nested)
86436@@ -458,7 +458,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
86437 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
86438 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
86439 bh_unlock_sock(sk);
86440- atomic_inc(&sk->sk_drops);
86441+ atomic_inc_unchecked(&sk->sk_drops);
86442 goto discard_and_relse;
86443 }
86444
86445@@ -942,12 +942,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86446 struct timeval tm;
86447 } v;
86448
86449- int lv = sizeof(int);
86450- int len;
86451+ unsigned int lv = sizeof(int);
86452+ unsigned int len;
86453
86454 if (get_user(len, optlen))
86455 return -EFAULT;
86456- if (len < 0)
86457+ if (len > INT_MAX)
86458 return -EINVAL;
86459
86460 memset(&v, 0, sizeof(v));
86461@@ -1099,11 +1099,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86462
86463 case SO_PEERNAME:
86464 {
86465- char address[128];
86466+ char address[_K_SS_MAXSIZE];
86467
86468 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
86469 return -ENOTCONN;
86470- if (lv < len)
86471+ if (lv < len || sizeof address < len)
86472 return -EINVAL;
86473 if (copy_to_user(optval, address, len))
86474 return -EFAULT;
86475@@ -1166,7 +1166,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86476
86477 if (len > lv)
86478 len = lv;
86479- if (copy_to_user(optval, &v, len))
86480+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
86481 return -EFAULT;
86482 lenout:
86483 if (put_user(len, optlen))
86484@@ -2284,7 +2284,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
86485 */
86486 smp_wmb();
86487 atomic_set(&sk->sk_refcnt, 1);
86488- atomic_set(&sk->sk_drops, 0);
86489+ atomic_set_unchecked(&sk->sk_drops, 0);
86490 }
86491 EXPORT_SYMBOL(sock_init_data);
86492
86493diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
86494index a29e90c..922399c 100644
86495--- a/net/core/sock_diag.c
86496+++ b/net/core/sock_diag.c
86497@@ -9,26 +9,33 @@
86498 #include <linux/inet_diag.h>
86499 #include <linux/sock_diag.h>
86500
86501-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
86502+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
86503 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
86504 static DEFINE_MUTEX(sock_diag_table_mutex);
86505
86506 int sock_diag_check_cookie(void *sk, __u32 *cookie)
86507 {
86508+#ifndef CONFIG_GRKERNSEC_HIDESYM
86509 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
86510 cookie[1] != INET_DIAG_NOCOOKIE) &&
86511 ((u32)(unsigned long)sk != cookie[0] ||
86512 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
86513 return -ESTALE;
86514 else
86515+#endif
86516 return 0;
86517 }
86518 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
86519
86520 void sock_diag_save_cookie(void *sk, __u32 *cookie)
86521 {
86522+#ifdef CONFIG_GRKERNSEC_HIDESYM
86523+ cookie[0] = 0;
86524+ cookie[1] = 0;
86525+#else
86526 cookie[0] = (u32)(unsigned long)sk;
86527 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
86528+#endif
86529 }
86530 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
86531
86532@@ -75,8 +82,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
86533 mutex_lock(&sock_diag_table_mutex);
86534 if (sock_diag_handlers[hndl->family])
86535 err = -EBUSY;
86536- else
86537+ else {
86538+ pax_open_kernel();
86539 sock_diag_handlers[hndl->family] = hndl;
86540+ pax_close_kernel();
86541+ }
86542 mutex_unlock(&sock_diag_table_mutex);
86543
86544 return err;
86545@@ -92,7 +102,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
86546
86547 mutex_lock(&sock_diag_table_mutex);
86548 BUG_ON(sock_diag_handlers[family] != hnld);
86549+ pax_open_kernel();
86550 sock_diag_handlers[family] = NULL;
86551+ pax_close_kernel();
86552 mutex_unlock(&sock_diag_table_mutex);
86553 }
86554 EXPORT_SYMBOL_GPL(sock_diag_unregister);
86555diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
86556index cfdb46a..cef55e1 100644
86557--- a/net/core/sysctl_net_core.c
86558+++ b/net/core/sysctl_net_core.c
86559@@ -28,7 +28,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
86560 {
86561 unsigned int orig_size, size;
86562 int ret, i;
86563- ctl_table tmp = {
86564+ ctl_table_no_const tmp = {
86565 .data = &size,
86566 .maxlen = sizeof(size),
86567 .mode = table->mode
86568@@ -211,13 +211,12 @@ static struct ctl_table netns_core_table[] = {
86569
86570 static __net_init int sysctl_core_net_init(struct net *net)
86571 {
86572- struct ctl_table *tbl;
86573+ ctl_table_no_const *tbl = NULL;
86574
86575 net->core.sysctl_somaxconn = SOMAXCONN;
86576
86577- tbl = netns_core_table;
86578 if (!net_eq(net, &init_net)) {
86579- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
86580+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
86581 if (tbl == NULL)
86582 goto err_dup;
86583
86584@@ -227,17 +226,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
86585 if (net->user_ns != &init_user_ns) {
86586 tbl[0].procname = NULL;
86587 }
86588- }
86589-
86590- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
86591+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
86592+ } else
86593+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
86594 if (net->core.sysctl_hdr == NULL)
86595 goto err_reg;
86596
86597 return 0;
86598
86599 err_reg:
86600- if (tbl != netns_core_table)
86601- kfree(tbl);
86602+ kfree(tbl);
86603 err_dup:
86604 return -ENOMEM;
86605 }
86606@@ -252,7 +250,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
86607 kfree(tbl);
86608 }
86609
86610-static __net_initdata struct pernet_operations sysctl_core_ops = {
86611+static __net_initconst struct pernet_operations sysctl_core_ops = {
86612 .init = sysctl_core_net_init,
86613 .exit = sysctl_core_net_exit,
86614 };
86615diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
86616index c21f200..bc4565b 100644
86617--- a/net/decnet/af_decnet.c
86618+++ b/net/decnet/af_decnet.c
86619@@ -465,6 +465,7 @@ static struct proto dn_proto = {
86620 .sysctl_rmem = sysctl_decnet_rmem,
86621 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
86622 .obj_size = sizeof(struct dn_sock),
86623+ .slab_flags = SLAB_USERCOPY,
86624 };
86625
86626 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
86627diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
86628index a55eecc..dd8428c 100644
86629--- a/net/decnet/sysctl_net_decnet.c
86630+++ b/net/decnet/sysctl_net_decnet.c
86631@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
86632
86633 if (len > *lenp) len = *lenp;
86634
86635- if (copy_to_user(buffer, addr, len))
86636+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
86637 return -EFAULT;
86638
86639 *lenp = len;
86640@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
86641
86642 if (len > *lenp) len = *lenp;
86643
86644- if (copy_to_user(buffer, devname, len))
86645+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
86646 return -EFAULT;
86647
86648 *lenp = len;
86649diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
86650index c929d9c..df10cde 100644
86651--- a/net/ipv4/af_inet.c
86652+++ b/net/ipv4/af_inet.c
86653@@ -115,6 +115,7 @@
86654 #include <net/inet_common.h>
86655 #include <net/xfrm.h>
86656 #include <net/net_namespace.h>
86657+#include <net/secure_seq.h>
86658 #ifdef CONFIG_IP_MROUTE
86659 #include <linux/mroute.h>
86660 #endif
86661@@ -263,8 +264,10 @@ void build_ehash_secret(void)
86662 get_random_bytes(&rnd, sizeof(rnd));
86663 } while (rnd == 0);
86664
86665- if (cmpxchg(&inet_ehash_secret, 0, rnd) == 0)
86666+ if (cmpxchg(&inet_ehash_secret, 0, rnd) == 0) {
86667 get_random_bytes(&ipv6_hash_secret, sizeof(ipv6_hash_secret));
86668+ net_secret_init();
86669+ }
86670 }
86671 EXPORT_SYMBOL(build_ehash_secret);
86672
86673@@ -1699,13 +1702,9 @@ static int __init inet_init(void)
86674
86675 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
86676
86677- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
86678- if (!sysctl_local_reserved_ports)
86679- goto out;
86680-
86681 rc = proto_register(&tcp_prot, 1);
86682 if (rc)
86683- goto out_free_reserved_ports;
86684+ goto out;
86685
86686 rc = proto_register(&udp_prot, 1);
86687 if (rc)
86688@@ -1814,8 +1813,6 @@ out_unregister_udp_proto:
86689 proto_unregister(&udp_prot);
86690 out_unregister_tcp_proto:
86691 proto_unregister(&tcp_prot);
86692-out_free_reserved_ports:
86693- kfree(sysctl_local_reserved_ports);
86694 goto out;
86695 }
86696
86697diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
86698index 2e7f194..0fa4d6d 100644
86699--- a/net/ipv4/ah4.c
86700+++ b/net/ipv4/ah4.c
86701@@ -420,7 +420,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
86702 return;
86703
86704 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
86705- atomic_inc(&flow_cache_genid);
86706+ atomic_inc_unchecked(&flow_cache_genid);
86707 rt_genid_bump(net);
86708
86709 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
86710diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
86711index c6287cd..e9bc96a 100644
86712--- a/net/ipv4/devinet.c
86713+++ b/net/ipv4/devinet.c
86714@@ -1992,7 +1992,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
86715 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
86716 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
86717
86718-static struct devinet_sysctl_table {
86719+static const struct devinet_sysctl_table {
86720 struct ctl_table_header *sysctl_header;
86721 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
86722 } devinet_sysctl = {
86723@@ -2110,7 +2110,7 @@ static __net_init int devinet_init_net(struct net *net)
86724 int err;
86725 struct ipv4_devconf *all, *dflt;
86726 #ifdef CONFIG_SYSCTL
86727- struct ctl_table *tbl = ctl_forward_entry;
86728+ ctl_table_no_const *tbl = NULL;
86729 struct ctl_table_header *forw_hdr;
86730 #endif
86731
86732@@ -2128,7 +2128,7 @@ static __net_init int devinet_init_net(struct net *net)
86733 goto err_alloc_dflt;
86734
86735 #ifdef CONFIG_SYSCTL
86736- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
86737+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
86738 if (tbl == NULL)
86739 goto err_alloc_ctl;
86740
86741@@ -2148,7 +2148,10 @@ static __net_init int devinet_init_net(struct net *net)
86742 goto err_reg_dflt;
86743
86744 err = -ENOMEM;
86745- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
86746+ if (!net_eq(net, &init_net))
86747+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
86748+ else
86749+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
86750 if (forw_hdr == NULL)
86751 goto err_reg_ctl;
86752 net->ipv4.forw_hdr = forw_hdr;
86753@@ -2164,8 +2167,7 @@ err_reg_ctl:
86754 err_reg_dflt:
86755 __devinet_sysctl_unregister(all);
86756 err_reg_all:
86757- if (tbl != ctl_forward_entry)
86758- kfree(tbl);
86759+ kfree(tbl);
86760 err_alloc_ctl:
86761 #endif
86762 if (dflt != &ipv4_devconf_dflt)
86763diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
86764index 4cfe34d..a6ba66e 100644
86765--- a/net/ipv4/esp4.c
86766+++ b/net/ipv4/esp4.c
86767@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
86768 return;
86769
86770 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
86771- atomic_inc(&flow_cache_genid);
86772+ atomic_inc_unchecked(&flow_cache_genid);
86773 rt_genid_bump(net);
86774
86775 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
86776diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
86777index eb4bb12..ee4ec7d 100644
86778--- a/net/ipv4/fib_frontend.c
86779+++ b/net/ipv4/fib_frontend.c
86780@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
86781 #ifdef CONFIG_IP_ROUTE_MULTIPATH
86782 fib_sync_up(dev);
86783 #endif
86784- atomic_inc(&net->ipv4.dev_addr_genid);
86785+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
86786 rt_cache_flush(dev_net(dev));
86787 break;
86788 case NETDEV_DOWN:
86789 fib_del_ifaddr(ifa, NULL);
86790- atomic_inc(&net->ipv4.dev_addr_genid);
86791+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
86792 if (ifa->ifa_dev->ifa_list == NULL) {
86793 /* Last address was deleted from this interface.
86794 * Disable IP.
86795@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
86796 #ifdef CONFIG_IP_ROUTE_MULTIPATH
86797 fib_sync_up(dev);
86798 #endif
86799- atomic_inc(&net->ipv4.dev_addr_genid);
86800+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
86801 rt_cache_flush(net);
86802 break;
86803 case NETDEV_DOWN:
86804diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
86805index 8f6cb7a..34507f9 100644
86806--- a/net/ipv4/fib_semantics.c
86807+++ b/net/ipv4/fib_semantics.c
86808@@ -765,7 +765,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
86809 nh->nh_saddr = inet_select_addr(nh->nh_dev,
86810 nh->nh_gw,
86811 nh->nh_parent->fib_scope);
86812- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
86813+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
86814
86815 return nh->nh_saddr;
86816 }
86817diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
86818index 786d97a..1889c0d 100644
86819--- a/net/ipv4/inet_connection_sock.c
86820+++ b/net/ipv4/inet_connection_sock.c
86821@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
86822 .range = { 32768, 61000 },
86823 };
86824
86825-unsigned long *sysctl_local_reserved_ports;
86826+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
86827 EXPORT_SYMBOL(sysctl_local_reserved_ports);
86828
86829 void inet_get_local_port_range(int *low, int *high)
86830diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
86831index 6af375a..c493c74 100644
86832--- a/net/ipv4/inet_hashtables.c
86833+++ b/net/ipv4/inet_hashtables.c
86834@@ -18,12 +18,15 @@
86835 #include <linux/sched.h>
86836 #include <linux/slab.h>
86837 #include <linux/wait.h>
86838+#include <linux/security.h>
86839
86840 #include <net/inet_connection_sock.h>
86841 #include <net/inet_hashtables.h>
86842 #include <net/secure_seq.h>
86843 #include <net/ip.h>
86844
86845+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
86846+
86847 /*
86848 * Allocate and initialize a new local port bind bucket.
86849 * The bindhash mutex for snum's hash chain must be held here.
86850@@ -554,6 +557,8 @@ ok:
86851 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
86852 spin_unlock(&head->lock);
86853
86854+ gr_update_task_in_ip_table(current, inet_sk(sk));
86855+
86856 if (tw) {
86857 inet_twsk_deschedule(tw, death_row);
86858 while (twrefcnt) {
86859diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
86860index 000e3d2..5472da3 100644
86861--- a/net/ipv4/inetpeer.c
86862+++ b/net/ipv4/inetpeer.c
86863@@ -503,8 +503,8 @@ relookup:
86864 if (p) {
86865 p->daddr = *daddr;
86866 atomic_set(&p->refcnt, 1);
86867- atomic_set(&p->rid, 0);
86868- atomic_set(&p->ip_id_count,
86869+ atomic_set_unchecked(&p->rid, 0);
86870+ atomic_set_unchecked(&p->ip_id_count,
86871 (daddr->family == AF_INET) ?
86872 secure_ip_id(daddr->addr.a4) :
86873 secure_ipv6_id(daddr->addr.a6));
86874diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
86875index 52c273e..579060b 100644
86876--- a/net/ipv4/ip_fragment.c
86877+++ b/net/ipv4/ip_fragment.c
86878@@ -311,7 +311,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
86879 return 0;
86880
86881 start = qp->rid;
86882- end = atomic_inc_return(&peer->rid);
86883+ end = atomic_inc_return_unchecked(&peer->rid);
86884 qp->rid = end;
86885
86886 rc = qp->q.fragments && (end - start) > max;
86887@@ -788,12 +788,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
86888
86889 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
86890 {
86891- struct ctl_table *table;
86892+ ctl_table_no_const *table = NULL;
86893 struct ctl_table_header *hdr;
86894
86895- table = ip4_frags_ns_ctl_table;
86896 if (!net_eq(net, &init_net)) {
86897- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
86898+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
86899 if (table == NULL)
86900 goto err_alloc;
86901
86902@@ -804,9 +803,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
86903 /* Don't export sysctls to unprivileged users */
86904 if (net->user_ns != &init_user_ns)
86905 table[0].procname = NULL;
86906- }
86907+ hdr = register_net_sysctl(net, "net/ipv4", table);
86908+ } else
86909+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
86910
86911- hdr = register_net_sysctl(net, "net/ipv4", table);
86912 if (hdr == NULL)
86913 goto err_reg;
86914
86915@@ -814,8 +814,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
86916 return 0;
86917
86918 err_reg:
86919- if (!net_eq(net, &init_net))
86920- kfree(table);
86921+ kfree(table);
86922 err_alloc:
86923 return -ENOMEM;
86924 }
86925diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
86926index 91d66db..4af7d99 100644
86927--- a/net/ipv4/ip_gre.c
86928+++ b/net/ipv4/ip_gre.c
86929@@ -124,7 +124,7 @@ static bool log_ecn_error = true;
86930 module_param(log_ecn_error, bool, 0644);
86931 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
86932
86933-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
86934+static struct rtnl_link_ops ipgre_link_ops;
86935 static int ipgre_tunnel_init(struct net_device *dev);
86936 static void ipgre_tunnel_setup(struct net_device *dev);
86937 static int ipgre_tunnel_bind_dev(struct net_device *dev);
86938@@ -1823,7 +1823,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
86939 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
86940 };
86941
86942-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
86943+static struct rtnl_link_ops ipgre_link_ops = {
86944 .kind = "gre",
86945 .maxtype = IFLA_GRE_MAX,
86946 .policy = ipgre_policy,
86947@@ -1836,7 +1836,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
86948 .fill_info = ipgre_fill_info,
86949 };
86950
86951-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
86952+static struct rtnl_link_ops ipgre_tap_ops = {
86953 .kind = "gretap",
86954 .maxtype = IFLA_GRE_MAX,
86955 .policy = ipgre_policy,
86956diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
86957index d9c4f11..02b82dbc 100644
86958--- a/net/ipv4/ip_sockglue.c
86959+++ b/net/ipv4/ip_sockglue.c
86960@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
86961 len = min_t(unsigned int, len, opt->optlen);
86962 if (put_user(len, optlen))
86963 return -EFAULT;
86964- if (copy_to_user(optval, opt->__data, len))
86965+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
86966+ copy_to_user(optval, opt->__data, len))
86967 return -EFAULT;
86968 return 0;
86969 }
86970@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
86971 if (sk->sk_type != SOCK_STREAM)
86972 return -ENOPROTOOPT;
86973
86974- msg.msg_control = optval;
86975+ msg.msg_control = (void __force_kernel *)optval;
86976 msg.msg_controllen = len;
86977 msg.msg_flags = flags;
86978
86979diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
86980index c3a4233..7df5626 100644
86981--- a/net/ipv4/ip_vti.c
86982+++ b/net/ipv4/ip_vti.c
86983@@ -47,7 +47,7 @@
86984 #define HASH_SIZE 16
86985 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
86986
86987-static struct rtnl_link_ops vti_link_ops __read_mostly;
86988+static struct rtnl_link_ops vti_link_ops;
86989
86990 static int vti_net_id __read_mostly;
86991 struct vti_net {
86992@@ -399,8 +399,7 @@ static netdev_tx_t vti_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
86993 tunnel->err_count = 0;
86994 }
86995
86996- IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED |
86997- IPSKB_REROUTED);
86998+ memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
86999 skb_dst_drop(skb);
87000 skb_dst_set(skb, &rt->dst);
87001 nf_reset(skb);
87002@@ -886,7 +885,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
87003 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
87004 };
87005
87006-static struct rtnl_link_ops vti_link_ops __read_mostly = {
87007+static struct rtnl_link_ops vti_link_ops = {
87008 .kind = "vti",
87009 .maxtype = IFLA_VTI_MAX,
87010 .policy = vti_policy,
87011diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
87012index f01d1b1..8fe03ad 100644
87013--- a/net/ipv4/ipcomp.c
87014+++ b/net/ipv4/ipcomp.c
87015@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
87016 return;
87017
87018 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
87019- atomic_inc(&flow_cache_genid);
87020+ atomic_inc_unchecked(&flow_cache_genid);
87021 rt_genid_bump(net);
87022
87023 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
87024diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
87025index bf6c5cf..ab2e9c6 100644
87026--- a/net/ipv4/ipconfig.c
87027+++ b/net/ipv4/ipconfig.c
87028@@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
87029
87030 mm_segment_t oldfs = get_fs();
87031 set_fs(get_ds());
87032- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
87033+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
87034 set_fs(oldfs);
87035 return res;
87036 }
87037@@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
87038
87039 mm_segment_t oldfs = get_fs();
87040 set_fs(get_ds());
87041- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
87042+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
87043 set_fs(oldfs);
87044 return res;
87045 }
87046@@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
87047
87048 mm_segment_t oldfs = get_fs();
87049 set_fs(get_ds());
87050- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
87051+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
87052 set_fs(oldfs);
87053 return res;
87054 }
87055diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
87056index 8f024d4..8b3500c 100644
87057--- a/net/ipv4/ipip.c
87058+++ b/net/ipv4/ipip.c
87059@@ -138,7 +138,7 @@ struct ipip_net {
87060 static int ipip_tunnel_init(struct net_device *dev);
87061 static void ipip_tunnel_setup(struct net_device *dev);
87062 static void ipip_dev_free(struct net_device *dev);
87063-static struct rtnl_link_ops ipip_link_ops __read_mostly;
87064+static struct rtnl_link_ops ipip_link_ops;
87065
87066 static struct rtnl_link_stats64 *ipip_get_stats64(struct net_device *dev,
87067 struct rtnl_link_stats64 *tot)
87068@@ -974,7 +974,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
87069 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
87070 };
87071
87072-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
87073+static struct rtnl_link_ops ipip_link_ops = {
87074 .kind = "ipip",
87075 .maxtype = IFLA_IPTUN_MAX,
87076 .policy = ipip_policy,
87077diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
87078index 7dc6a97..229c61b 100644
87079--- a/net/ipv4/netfilter/arp_tables.c
87080+++ b/net/ipv4/netfilter/arp_tables.c
87081@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
87082 #endif
87083
87084 static int get_info(struct net *net, void __user *user,
87085- const int *len, int compat)
87086+ int len, int compat)
87087 {
87088 char name[XT_TABLE_MAXNAMELEN];
87089 struct xt_table *t;
87090 int ret;
87091
87092- if (*len != sizeof(struct arpt_getinfo)) {
87093- duprintf("length %u != %Zu\n", *len,
87094+ if (len != sizeof(struct arpt_getinfo)) {
87095+ duprintf("length %u != %Zu\n", len,
87096 sizeof(struct arpt_getinfo));
87097 return -EINVAL;
87098 }
87099@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
87100 info.size = private->size;
87101 strcpy(info.name, name);
87102
87103- if (copy_to_user(user, &info, *len) != 0)
87104+ if (copy_to_user(user, &info, len) != 0)
87105 ret = -EFAULT;
87106 else
87107 ret = 0;
87108@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
87109
87110 switch (cmd) {
87111 case ARPT_SO_GET_INFO:
87112- ret = get_info(sock_net(sk), user, len, 1);
87113+ ret = get_info(sock_net(sk), user, *len, 1);
87114 break;
87115 case ARPT_SO_GET_ENTRIES:
87116 ret = compat_get_entries(sock_net(sk), user, len);
87117@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
87118
87119 switch (cmd) {
87120 case ARPT_SO_GET_INFO:
87121- ret = get_info(sock_net(sk), user, len, 0);
87122+ ret = get_info(sock_net(sk), user, *len, 0);
87123 break;
87124
87125 case ARPT_SO_GET_ENTRIES:
87126diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
87127index 3efcf87..5247916 100644
87128--- a/net/ipv4/netfilter/ip_tables.c
87129+++ b/net/ipv4/netfilter/ip_tables.c
87130@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
87131 #endif
87132
87133 static int get_info(struct net *net, void __user *user,
87134- const int *len, int compat)
87135+ int len, int compat)
87136 {
87137 char name[XT_TABLE_MAXNAMELEN];
87138 struct xt_table *t;
87139 int ret;
87140
87141- if (*len != sizeof(struct ipt_getinfo)) {
87142- duprintf("length %u != %zu\n", *len,
87143+ if (len != sizeof(struct ipt_getinfo)) {
87144+ duprintf("length %u != %zu\n", len,
87145 sizeof(struct ipt_getinfo));
87146 return -EINVAL;
87147 }
87148@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
87149 info.size = private->size;
87150 strcpy(info.name, name);
87151
87152- if (copy_to_user(user, &info, *len) != 0)
87153+ if (copy_to_user(user, &info, len) != 0)
87154 ret = -EFAULT;
87155 else
87156 ret = 0;
87157@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87158
87159 switch (cmd) {
87160 case IPT_SO_GET_INFO:
87161- ret = get_info(sock_net(sk), user, len, 1);
87162+ ret = get_info(sock_net(sk), user, *len, 1);
87163 break;
87164 case IPT_SO_GET_ENTRIES:
87165 ret = compat_get_entries(sock_net(sk), user, len);
87166@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87167
87168 switch (cmd) {
87169 case IPT_SO_GET_INFO:
87170- ret = get_info(sock_net(sk), user, len, 0);
87171+ ret = get_info(sock_net(sk), user, *len, 0);
87172 break;
87173
87174 case IPT_SO_GET_ENTRIES:
87175diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
87176index 2e91006..f084394 100644
87177--- a/net/ipv4/ping.c
87178+++ b/net/ipv4/ping.c
87179@@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
87180 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
87181 0, sock_i_ino(sp),
87182 atomic_read(&sp->sk_refcnt), sp,
87183- atomic_read(&sp->sk_drops), len);
87184+ atomic_read_unchecked(&sp->sk_drops), len);
87185 }
87186
87187 static int ping_seq_show(struct seq_file *seq, void *v)
87188diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
87189index dd44e0a..06dcca4 100644
87190--- a/net/ipv4/raw.c
87191+++ b/net/ipv4/raw.c
87192@@ -309,7 +309,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
87193 int raw_rcv(struct sock *sk, struct sk_buff *skb)
87194 {
87195 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
87196- atomic_inc(&sk->sk_drops);
87197+ atomic_inc_unchecked(&sk->sk_drops);
87198 kfree_skb(skb);
87199 return NET_RX_DROP;
87200 }
87201@@ -745,16 +745,20 @@ static int raw_init(struct sock *sk)
87202
87203 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
87204 {
87205+ struct icmp_filter filter;
87206+
87207 if (optlen > sizeof(struct icmp_filter))
87208 optlen = sizeof(struct icmp_filter);
87209- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
87210+ if (copy_from_user(&filter, optval, optlen))
87211 return -EFAULT;
87212+ raw_sk(sk)->filter = filter;
87213 return 0;
87214 }
87215
87216 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
87217 {
87218 int len, ret = -EFAULT;
87219+ struct icmp_filter filter;
87220
87221 if (get_user(len, optlen))
87222 goto out;
87223@@ -764,8 +768,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
87224 if (len > sizeof(struct icmp_filter))
87225 len = sizeof(struct icmp_filter);
87226 ret = -EFAULT;
87227- if (put_user(len, optlen) ||
87228- copy_to_user(optval, &raw_sk(sk)->filter, len))
87229+ filter = raw_sk(sk)->filter;
87230+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
87231 goto out;
87232 ret = 0;
87233 out: return ret;
87234@@ -994,7 +998,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
87235 0, 0L, 0,
87236 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
87237 0, sock_i_ino(sp),
87238- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
87239+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
87240 }
87241
87242 static int raw_seq_show(struct seq_file *seq, void *v)
87243diff --git a/net/ipv4/route.c b/net/ipv4/route.c
87244index 6e28514..5e1b055 100644
87245--- a/net/ipv4/route.c
87246+++ b/net/ipv4/route.c
87247@@ -2553,34 +2553,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
87248 .maxlen = sizeof(int),
87249 .mode = 0200,
87250 .proc_handler = ipv4_sysctl_rtcache_flush,
87251+ .extra1 = &init_net,
87252 },
87253 { },
87254 };
87255
87256 static __net_init int sysctl_route_net_init(struct net *net)
87257 {
87258- struct ctl_table *tbl;
87259+ ctl_table_no_const *tbl = NULL;
87260
87261- tbl = ipv4_route_flush_table;
87262 if (!net_eq(net, &init_net)) {
87263- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
87264+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
87265 if (tbl == NULL)
87266 goto err_dup;
87267
87268 /* Don't export sysctls to unprivileged users */
87269 if (net->user_ns != &init_user_ns)
87270 tbl[0].procname = NULL;
87271- }
87272- tbl[0].extra1 = net;
87273+ tbl[0].extra1 = net;
87274+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
87275+ } else
87276+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
87277
87278- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
87279 if (net->ipv4.route_hdr == NULL)
87280 goto err_reg;
87281 return 0;
87282
87283 err_reg:
87284- if (tbl != ipv4_route_flush_table)
87285- kfree(tbl);
87286+ kfree(tbl);
87287 err_dup:
87288 return -ENOMEM;
87289 }
87290@@ -2603,7 +2603,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
87291
87292 static __net_init int rt_genid_init(struct net *net)
87293 {
87294- atomic_set(&net->rt_genid, 0);
87295+ atomic_set_unchecked(&net->rt_genid, 0);
87296 get_random_bytes(&net->ipv4.dev_addr_genid,
87297 sizeof(net->ipv4.dev_addr_genid));
87298 return 0;
87299diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
87300index 960fd29..d55bf64 100644
87301--- a/net/ipv4/sysctl_net_ipv4.c
87302+++ b/net/ipv4/sysctl_net_ipv4.c
87303@@ -55,7 +55,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
87304 {
87305 int ret;
87306 int range[2];
87307- ctl_table tmp = {
87308+ ctl_table_no_const tmp = {
87309 .data = &range,
87310 .maxlen = sizeof(range),
87311 .mode = table->mode,
87312@@ -108,7 +108,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
87313 int ret;
87314 gid_t urange[2];
87315 kgid_t low, high;
87316- ctl_table tmp = {
87317+ ctl_table_no_const tmp = {
87318 .data = &urange,
87319 .maxlen = sizeof(urange),
87320 .mode = table->mode,
87321@@ -139,7 +139,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
87322 void __user *buffer, size_t *lenp, loff_t *ppos)
87323 {
87324 char val[TCP_CA_NAME_MAX];
87325- ctl_table tbl = {
87326+ ctl_table_no_const tbl = {
87327 .data = val,
87328 .maxlen = TCP_CA_NAME_MAX,
87329 };
87330@@ -158,7 +158,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
87331 void __user *buffer, size_t *lenp,
87332 loff_t *ppos)
87333 {
87334- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
87335+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
87336 int ret;
87337
87338 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
87339@@ -175,7 +175,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
87340 void __user *buffer, size_t *lenp,
87341 loff_t *ppos)
87342 {
87343- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
87344+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
87345 int ret;
87346
87347 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
87348@@ -201,15 +201,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
87349 struct mem_cgroup *memcg;
87350 #endif
87351
87352- ctl_table tmp = {
87353+ ctl_table_no_const tmp = {
87354 .data = &vec,
87355 .maxlen = sizeof(vec),
87356 .mode = ctl->mode,
87357 };
87358
87359 if (!write) {
87360- ctl->data = &net->ipv4.sysctl_tcp_mem;
87361- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
87362+ ctl_table_no_const tcp_mem = *ctl;
87363+
87364+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
87365+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
87366 }
87367
87368 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
87369@@ -236,7 +238,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
87370 static int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
87371 size_t *lenp, loff_t *ppos)
87372 {
87373- ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
87374+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
87375 struct tcp_fastopen_context *ctxt;
87376 int ret;
87377 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
87378@@ -477,7 +479,7 @@ static struct ctl_table ipv4_table[] = {
87379 },
87380 {
87381 .procname = "ip_local_reserved_ports",
87382- .data = NULL, /* initialized in sysctl_ipv4_init */
87383+ .data = sysctl_local_reserved_ports,
87384 .maxlen = 65536,
87385 .mode = 0644,
87386 .proc_handler = proc_do_large_bitmap,
87387@@ -856,11 +858,10 @@ static struct ctl_table ipv4_net_table[] = {
87388
87389 static __net_init int ipv4_sysctl_init_net(struct net *net)
87390 {
87391- struct ctl_table *table;
87392+ ctl_table_no_const *table = NULL;
87393
87394- table = ipv4_net_table;
87395 if (!net_eq(net, &init_net)) {
87396- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
87397+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
87398 if (table == NULL)
87399 goto err_alloc;
87400
87401@@ -895,15 +896,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
87402
87403 tcp_init_mem(net);
87404
87405- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
87406+ if (!net_eq(net, &init_net))
87407+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
87408+ else
87409+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
87410 if (net->ipv4.ipv4_hdr == NULL)
87411 goto err_reg;
87412
87413 return 0;
87414
87415 err_reg:
87416- if (!net_eq(net, &init_net))
87417- kfree(table);
87418+ kfree(table);
87419 err_alloc:
87420 return -ENOMEM;
87421 }
87422@@ -925,16 +928,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
87423 static __init int sysctl_ipv4_init(void)
87424 {
87425 struct ctl_table_header *hdr;
87426- struct ctl_table *i;
87427-
87428- for (i = ipv4_table; i->procname; i++) {
87429- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
87430- i->data = sysctl_local_reserved_ports;
87431- break;
87432- }
87433- }
87434- if (!i->procname)
87435- return -EINVAL;
87436
87437 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
87438 if (hdr == NULL)
87439diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
87440index e220207..cdeb839 100644
87441--- a/net/ipv4/tcp.c
87442+++ b/net/ipv4/tcp.c
87443@@ -3383,8 +3383,11 @@ int tcp_md5_hash_skb_data(struct tcp_md5sig_pool *hp,
87444
87445 for (i = 0; i < shi->nr_frags; ++i) {
87446 const struct skb_frag_struct *f = &shi->frags[i];
87447- struct page *page = skb_frag_page(f);
87448- sg_set_page(&sg, page, skb_frag_size(f), f->page_offset);
87449+ unsigned int offset = f->page_offset;
87450+ struct page *page = skb_frag_page(f) + (offset >> PAGE_SHIFT);
87451+
87452+ sg_set_page(&sg, page, skb_frag_size(f),
87453+ offset_in_page(offset));
87454 if (crypto_hash_update(desc, &sg, skb_frag_size(f)))
87455 return 1;
87456 }
87457diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
87458index 13b9c08..d33a8d0 100644
87459--- a/net/ipv4/tcp_input.c
87460+++ b/net/ipv4/tcp_input.c
87461@@ -4724,7 +4724,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
87462 * simplifies code)
87463 */
87464 static void
87465-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
87466+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
87467 struct sk_buff *head, struct sk_buff *tail,
87468 u32 start, u32 end)
87469 {
87470@@ -5838,6 +5838,7 @@ discard:
87471 tcp_paws_reject(&tp->rx_opt, 0))
87472 goto discard_and_undo;
87473
87474+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
87475 if (th->syn) {
87476 /* We see SYN without ACK. It is attempt of
87477 * simultaneous connect with crossed SYNs.
87478@@ -5888,6 +5889,7 @@ discard:
87479 goto discard;
87480 #endif
87481 }
87482+#endif
87483 /* "fifth, if neither of the SYN or RST bits is set then
87484 * drop the segment and return."
87485 */
87486@@ -5932,7 +5934,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
87487 goto discard;
87488
87489 if (th->syn) {
87490- if (th->fin)
87491+ if (th->fin || th->urg || th->psh)
87492 goto discard;
87493 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
87494 return 1;
87495diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
87496index d09203c..fd5cc91 100644
87497--- a/net/ipv4/tcp_ipv4.c
87498+++ b/net/ipv4/tcp_ipv4.c
87499@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
87500 EXPORT_SYMBOL(sysctl_tcp_low_latency);
87501
87502
87503+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87504+extern int grsec_enable_blackhole;
87505+#endif
87506+
87507 #ifdef CONFIG_TCP_MD5SIG
87508 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
87509 __be32 daddr, __be32 saddr, const struct tcphdr *th);
87510@@ -1897,6 +1901,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
87511 return 0;
87512
87513 reset:
87514+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87515+ if (!grsec_enable_blackhole)
87516+#endif
87517 tcp_v4_send_reset(rsk, skb);
87518 discard:
87519 kfree_skb(skb);
87520@@ -1996,12 +2003,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
87521 TCP_SKB_CB(skb)->sacked = 0;
87522
87523 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
87524- if (!sk)
87525+ if (!sk) {
87526+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87527+ ret = 1;
87528+#endif
87529 goto no_tcp_socket;
87530-
87531+ }
87532 process:
87533- if (sk->sk_state == TCP_TIME_WAIT)
87534+ if (sk->sk_state == TCP_TIME_WAIT) {
87535+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87536+ ret = 2;
87537+#endif
87538 goto do_time_wait;
87539+ }
87540
87541 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
87542 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
87543@@ -2052,6 +2066,10 @@ no_tcp_socket:
87544 bad_packet:
87545 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
87546 } else {
87547+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87548+ if (!grsec_enable_blackhole || (ret == 1 &&
87549+ (skb->dev->flags & IFF_LOOPBACK)))
87550+#endif
87551 tcp_v4_send_reset(NULL, skb);
87552 }
87553
87554diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
87555index 2f672e7..b8895e9 100644
87556--- a/net/ipv4/tcp_minisocks.c
87557+++ b/net/ipv4/tcp_minisocks.c
87558@@ -27,6 +27,10 @@
87559 #include <net/inet_common.h>
87560 #include <net/xfrm.h>
87561
87562+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87563+extern int grsec_enable_blackhole;
87564+#endif
87565+
87566 int sysctl_tcp_syncookies __read_mostly = 1;
87567 EXPORT_SYMBOL(sysctl_tcp_syncookies);
87568
87569@@ -749,7 +753,10 @@ embryonic_reset:
87570 * avoid becoming vulnerable to outside attack aiming at
87571 * resetting legit local connections.
87572 */
87573- req->rsk_ops->send_reset(sk, skb);
87574+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87575+ if (!grsec_enable_blackhole)
87576+#endif
87577+ req->rsk_ops->send_reset(sk, skb);
87578 } else if (fastopen) { /* received a valid RST pkt */
87579 reqsk_fastopen_remove(sk, req, true);
87580 tcp_reset(sk);
87581diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
87582index d4943f6..e7a74a5 100644
87583--- a/net/ipv4/tcp_probe.c
87584+++ b/net/ipv4/tcp_probe.c
87585@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
87586 if (cnt + width >= len)
87587 break;
87588
87589- if (copy_to_user(buf + cnt, tbuf, width))
87590+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
87591 return -EFAULT;
87592 cnt += width;
87593 }
87594diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
87595index b78aac3..e18230b 100644
87596--- a/net/ipv4/tcp_timer.c
87597+++ b/net/ipv4/tcp_timer.c
87598@@ -22,6 +22,10 @@
87599 #include <linux/gfp.h>
87600 #include <net/tcp.h>
87601
87602+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87603+extern int grsec_lastack_retries;
87604+#endif
87605+
87606 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
87607 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
87608 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
87609@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
87610 }
87611 }
87612
87613+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87614+ if ((sk->sk_state == TCP_LAST_ACK) &&
87615+ (grsec_lastack_retries > 0) &&
87616+ (grsec_lastack_retries < retry_until))
87617+ retry_until = grsec_lastack_retries;
87618+#endif
87619+
87620 if (retransmits_timed_out(sk, retry_until,
87621 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
87622 /* Has it gone just too far? */
87623diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
87624index 0a073a2..ddf6279 100644
87625--- a/net/ipv4/udp.c
87626+++ b/net/ipv4/udp.c
87627@@ -87,6 +87,7 @@
87628 #include <linux/types.h>
87629 #include <linux/fcntl.h>
87630 #include <linux/module.h>
87631+#include <linux/security.h>
87632 #include <linux/socket.h>
87633 #include <linux/sockios.h>
87634 #include <linux/igmp.h>
87635@@ -111,6 +112,10 @@
87636 #include <trace/events/skb.h>
87637 #include "udp_impl.h"
87638
87639+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87640+extern int grsec_enable_blackhole;
87641+#endif
87642+
87643 struct udp_table udp_table __read_mostly;
87644 EXPORT_SYMBOL(udp_table);
87645
87646@@ -594,6 +599,9 @@ found:
87647 return s;
87648 }
87649
87650+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
87651+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
87652+
87653 /*
87654 * This routine is called by the ICMP module when it gets some
87655 * sort of error condition. If err < 0 then the socket should
87656@@ -889,9 +897,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
87657 dport = usin->sin_port;
87658 if (dport == 0)
87659 return -EINVAL;
87660+
87661+ err = gr_search_udp_sendmsg(sk, usin);
87662+ if (err)
87663+ return err;
87664 } else {
87665 if (sk->sk_state != TCP_ESTABLISHED)
87666 return -EDESTADDRREQ;
87667+
87668+ err = gr_search_udp_sendmsg(sk, NULL);
87669+ if (err)
87670+ return err;
87671+
87672 daddr = inet->inet_daddr;
87673 dport = inet->inet_dport;
87674 /* Open fast path for connected socket.
87675@@ -1133,7 +1150,7 @@ static unsigned int first_packet_length(struct sock *sk)
87676 udp_lib_checksum_complete(skb)) {
87677 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
87678 IS_UDPLITE(sk));
87679- atomic_inc(&sk->sk_drops);
87680+ atomic_inc_unchecked(&sk->sk_drops);
87681 __skb_unlink(skb, rcvq);
87682 __skb_queue_tail(&list_kill, skb);
87683 }
87684@@ -1219,6 +1236,10 @@ try_again:
87685 if (!skb)
87686 goto out;
87687
87688+ err = gr_search_udp_recvmsg(sk, skb);
87689+ if (err)
87690+ goto out_free;
87691+
87692 ulen = skb->len - sizeof(struct udphdr);
87693 copied = len;
87694 if (copied > ulen)
87695@@ -1252,7 +1273,7 @@ try_again:
87696 if (unlikely(err)) {
87697 trace_kfree_skb(skb, udp_recvmsg);
87698 if (!peeked) {
87699- atomic_inc(&sk->sk_drops);
87700+ atomic_inc_unchecked(&sk->sk_drops);
87701 UDP_INC_STATS_USER(sock_net(sk),
87702 UDP_MIB_INERRORS, is_udplite);
87703 }
87704@@ -1535,7 +1556,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
87705
87706 drop:
87707 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
87708- atomic_inc(&sk->sk_drops);
87709+ atomic_inc_unchecked(&sk->sk_drops);
87710 kfree_skb(skb);
87711 return -1;
87712 }
87713@@ -1554,7 +1575,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
87714 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
87715
87716 if (!skb1) {
87717- atomic_inc(&sk->sk_drops);
87718+ atomic_inc_unchecked(&sk->sk_drops);
87719 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
87720 IS_UDPLITE(sk));
87721 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
87722@@ -1723,6 +1744,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
87723 goto csum_error;
87724
87725 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
87726+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87727+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
87728+#endif
87729 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
87730
87731 /*
87732@@ -2152,7 +2176,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
87733 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
87734 0, sock_i_ino(sp),
87735 atomic_read(&sp->sk_refcnt), sp,
87736- atomic_read(&sp->sk_drops), len);
87737+ atomic_read_unchecked(&sp->sk_drops), len);
87738 }
87739
87740 int udp4_seq_show(struct seq_file *seq, void *v)
87741diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
87742index 9a459be..086b866 100644
87743--- a/net/ipv4/xfrm4_policy.c
87744+++ b/net/ipv4/xfrm4_policy.c
87745@@ -264,19 +264,18 @@ static struct ctl_table xfrm4_policy_table[] = {
87746
87747 static int __net_init xfrm4_net_init(struct net *net)
87748 {
87749- struct ctl_table *table;
87750+ ctl_table_no_const *table = NULL;
87751 struct ctl_table_header *hdr;
87752
87753- table = xfrm4_policy_table;
87754 if (!net_eq(net, &init_net)) {
87755- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
87756+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
87757 if (!table)
87758 goto err_alloc;
87759
87760 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
87761- }
87762-
87763- hdr = register_net_sysctl(net, "net/ipv4", table);
87764+ hdr = register_net_sysctl(net, "net/ipv4", table);
87765+ } else
87766+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
87767 if (!hdr)
87768 goto err_reg;
87769
87770@@ -284,8 +283,7 @@ static int __net_init xfrm4_net_init(struct net *net)
87771 return 0;
87772
87773 err_reg:
87774- if (!net_eq(net, &init_net))
87775- kfree(table);
87776+ kfree(table);
87777 err_alloc:
87778 return -ENOMEM;
87779 }
87780diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
87781index dae802c..bfa4baa 100644
87782--- a/net/ipv6/addrconf.c
87783+++ b/net/ipv6/addrconf.c
87784@@ -2274,7 +2274,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
87785 p.iph.ihl = 5;
87786 p.iph.protocol = IPPROTO_IPV6;
87787 p.iph.ttl = 64;
87788- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
87789+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
87790
87791 if (ops->ndo_do_ioctl) {
87792 mm_segment_t oldfs = get_fs();
87793@@ -4410,7 +4410,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
87794 int *valp = ctl->data;
87795 int val = *valp;
87796 loff_t pos = *ppos;
87797- ctl_table lctl;
87798+ ctl_table_no_const lctl;
87799 int ret;
87800
87801 /*
87802@@ -4492,7 +4492,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
87803 int *valp = ctl->data;
87804 int val = *valp;
87805 loff_t pos = *ppos;
87806- ctl_table lctl;
87807+ ctl_table_no_const lctl;
87808 int ret;
87809
87810 /*
87811diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
87812index fff5bdd..15194fb 100644
87813--- a/net/ipv6/icmp.c
87814+++ b/net/ipv6/icmp.c
87815@@ -973,7 +973,7 @@ ctl_table ipv6_icmp_table_template[] = {
87816
87817 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
87818 {
87819- struct ctl_table *table;
87820+ ctl_table_no_const *table;
87821
87822 table = kmemdup(ipv6_icmp_table_template,
87823 sizeof(ipv6_icmp_table_template),
87824diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
87825index 95d13c7..791fe2f 100644
87826--- a/net/ipv6/ip6_gre.c
87827+++ b/net/ipv6/ip6_gre.c
87828@@ -73,7 +73,7 @@ struct ip6gre_net {
87829 struct net_device *fb_tunnel_dev;
87830 };
87831
87832-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
87833+static struct rtnl_link_ops ip6gre_link_ops;
87834 static int ip6gre_tunnel_init(struct net_device *dev);
87835 static void ip6gre_tunnel_setup(struct net_device *dev);
87836 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
87837@@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
87838 }
87839
87840
87841-static struct inet6_protocol ip6gre_protocol __read_mostly = {
87842+static struct inet6_protocol ip6gre_protocol = {
87843 .handler = ip6gre_rcv,
87844 .err_handler = ip6gre_err,
87845 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
87846@@ -1671,7 +1671,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
87847 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
87848 };
87849
87850-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
87851+static struct rtnl_link_ops ip6gre_link_ops = {
87852 .kind = "ip6gre",
87853 .maxtype = IFLA_GRE_MAX,
87854 .policy = ip6gre_policy,
87855@@ -1684,7 +1684,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
87856 .fill_info = ip6gre_fill_info,
87857 };
87858
87859-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
87860+static struct rtnl_link_ops ip6gre_tap_ops = {
87861 .kind = "ip6gretap",
87862 .maxtype = IFLA_GRE_MAX,
87863 .policy = ip6gre_policy,
87864diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
87865index 155eccf..851fdae 100644
87866--- a/net/ipv6/ip6_output.c
87867+++ b/net/ipv6/ip6_output.c
87868@@ -1147,7 +1147,7 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to,
87869 if (WARN_ON(np->cork.opt))
87870 return -EINVAL;
87871
87872- np->cork.opt = kmalloc(opt->tot_len, sk->sk_allocation);
87873+ np->cork.opt = kzalloc(opt->tot_len, sk->sk_allocation);
87874 if (unlikely(np->cork.opt == NULL))
87875 return -ENOBUFS;
87876
87877diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
87878index fff83cb..82d49dd 100644
87879--- a/net/ipv6/ip6_tunnel.c
87880+++ b/net/ipv6/ip6_tunnel.c
87881@@ -87,7 +87,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
87882
87883 static int ip6_tnl_dev_init(struct net_device *dev);
87884 static void ip6_tnl_dev_setup(struct net_device *dev);
87885-static struct rtnl_link_ops ip6_link_ops __read_mostly;
87886+static struct rtnl_link_ops ip6_link_ops;
87887
87888 static int ip6_tnl_net_id __read_mostly;
87889 struct ip6_tnl_net {
87890@@ -1684,7 +1684,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
87891 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
87892 };
87893
87894-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
87895+static struct rtnl_link_ops ip6_link_ops = {
87896 .kind = "ip6tnl",
87897 .maxtype = IFLA_IPTUN_MAX,
87898 .policy = ip6_tnl_policy,
87899diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
87900index d1e2e8e..51c19ae 100644
87901--- a/net/ipv6/ipv6_sockglue.c
87902+++ b/net/ipv6/ipv6_sockglue.c
87903@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
87904 if (sk->sk_type != SOCK_STREAM)
87905 return -ENOPROTOOPT;
87906
87907- msg.msg_control = optval;
87908+ msg.msg_control = (void __force_kernel *)optval;
87909 msg.msg_controllen = len;
87910 msg.msg_flags = flags;
87911
87912diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
87913index 341b54a..591e8ed 100644
87914--- a/net/ipv6/netfilter/ip6_tables.c
87915+++ b/net/ipv6/netfilter/ip6_tables.c
87916@@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
87917 #endif
87918
87919 static int get_info(struct net *net, void __user *user,
87920- const int *len, int compat)
87921+ int len, int compat)
87922 {
87923 char name[XT_TABLE_MAXNAMELEN];
87924 struct xt_table *t;
87925 int ret;
87926
87927- if (*len != sizeof(struct ip6t_getinfo)) {
87928- duprintf("length %u != %zu\n", *len,
87929+ if (len != sizeof(struct ip6t_getinfo)) {
87930+ duprintf("length %u != %zu\n", len,
87931 sizeof(struct ip6t_getinfo));
87932 return -EINVAL;
87933 }
87934@@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
87935 info.size = private->size;
87936 strcpy(info.name, name);
87937
87938- if (copy_to_user(user, &info, *len) != 0)
87939+ if (copy_to_user(user, &info, len) != 0)
87940 ret = -EFAULT;
87941 else
87942 ret = 0;
87943@@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87944
87945 switch (cmd) {
87946 case IP6T_SO_GET_INFO:
87947- ret = get_info(sock_net(sk), user, len, 1);
87948+ ret = get_info(sock_net(sk), user, *len, 1);
87949 break;
87950 case IP6T_SO_GET_ENTRIES:
87951 ret = compat_get_entries(sock_net(sk), user, len);
87952@@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87953
87954 switch (cmd) {
87955 case IP6T_SO_GET_INFO:
87956- ret = get_info(sock_net(sk), user, len, 0);
87957+ ret = get_info(sock_net(sk), user, *len, 0);
87958 break;
87959
87960 case IP6T_SO_GET_ENTRIES:
87961diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
87962index 6700069..1e50f42 100644
87963--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
87964+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
87965@@ -89,12 +89,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
87966
87967 static int nf_ct_frag6_sysctl_register(struct net *net)
87968 {
87969- struct ctl_table *table;
87970+ ctl_table_no_const *table = NULL;
87971 struct ctl_table_header *hdr;
87972
87973- table = nf_ct_frag6_sysctl_table;
87974 if (!net_eq(net, &init_net)) {
87975- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
87976+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
87977 GFP_KERNEL);
87978 if (table == NULL)
87979 goto err_alloc;
87980@@ -102,9 +101,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
87981 table[0].data = &net->nf_frag.frags.timeout;
87982 table[1].data = &net->nf_frag.frags.low_thresh;
87983 table[2].data = &net->nf_frag.frags.high_thresh;
87984- }
87985-
87986- hdr = register_net_sysctl(net, "net/netfilter", table);
87987+ hdr = register_net_sysctl(net, "net/netfilter", table);
87988+ } else
87989+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
87990 if (hdr == NULL)
87991 goto err_reg;
87992
87993@@ -112,8 +111,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
87994 return 0;
87995
87996 err_reg:
87997- if (!net_eq(net, &init_net))
87998- kfree(table);
87999+ kfree(table);
88000 err_alloc:
88001 return -ENOMEM;
88002 }
88003diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
88004index 330b5e7..796fbf1 100644
88005--- a/net/ipv6/raw.c
88006+++ b/net/ipv6/raw.c
88007@@ -378,7 +378,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
88008 {
88009 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
88010 skb_checksum_complete(skb)) {
88011- atomic_inc(&sk->sk_drops);
88012+ atomic_inc_unchecked(&sk->sk_drops);
88013 kfree_skb(skb);
88014 return NET_RX_DROP;
88015 }
88016@@ -406,7 +406,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
88017 struct raw6_sock *rp = raw6_sk(sk);
88018
88019 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
88020- atomic_inc(&sk->sk_drops);
88021+ atomic_inc_unchecked(&sk->sk_drops);
88022 kfree_skb(skb);
88023 return NET_RX_DROP;
88024 }
88025@@ -430,7 +430,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
88026
88027 if (inet->hdrincl) {
88028 if (skb_checksum_complete(skb)) {
88029- atomic_inc(&sk->sk_drops);
88030+ atomic_inc_unchecked(&sk->sk_drops);
88031 kfree_skb(skb);
88032 return NET_RX_DROP;
88033 }
88034@@ -603,7 +603,7 @@ out:
88035 return err;
88036 }
88037
88038-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
88039+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
88040 struct flowi6 *fl6, struct dst_entry **dstp,
88041 unsigned int flags)
88042 {
88043@@ -915,12 +915,15 @@ do_confirm:
88044 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
88045 char __user *optval, int optlen)
88046 {
88047+ struct icmp6_filter filter;
88048+
88049 switch (optname) {
88050 case ICMPV6_FILTER:
88051 if (optlen > sizeof(struct icmp6_filter))
88052 optlen = sizeof(struct icmp6_filter);
88053- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
88054+ if (copy_from_user(&filter, optval, optlen))
88055 return -EFAULT;
88056+ raw6_sk(sk)->filter = filter;
88057 return 0;
88058 default:
88059 return -ENOPROTOOPT;
88060@@ -933,6 +936,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
88061 char __user *optval, int __user *optlen)
88062 {
88063 int len;
88064+ struct icmp6_filter filter;
88065
88066 switch (optname) {
88067 case ICMPV6_FILTER:
88068@@ -944,7 +948,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
88069 len = sizeof(struct icmp6_filter);
88070 if (put_user(len, optlen))
88071 return -EFAULT;
88072- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
88073+ filter = raw6_sk(sk)->filter;
88074+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
88075 return -EFAULT;
88076 return 0;
88077 default:
88078@@ -1252,7 +1257,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
88079 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
88080 0,
88081 sock_i_ino(sp),
88082- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
88083+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
88084 }
88085
88086 static int raw6_seq_show(struct seq_file *seq, void *v)
88087diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
88088index 0ba10e5..c14a4f6 100644
88089--- a/net/ipv6/reassembly.c
88090+++ b/net/ipv6/reassembly.c
88091@@ -602,12 +602,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
88092
88093 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88094 {
88095- struct ctl_table *table;
88096+ ctl_table_no_const *table = NULL;
88097 struct ctl_table_header *hdr;
88098
88099- table = ip6_frags_ns_ctl_table;
88100 if (!net_eq(net, &init_net)) {
88101- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
88102+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
88103 if (table == NULL)
88104 goto err_alloc;
88105
88106@@ -618,9 +617,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88107 /* Don't export sysctls to unprivileged users */
88108 if (net->user_ns != &init_user_ns)
88109 table[0].procname = NULL;
88110- }
88111+ hdr = register_net_sysctl(net, "net/ipv6", table);
88112+ } else
88113+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
88114
88115- hdr = register_net_sysctl(net, "net/ipv6", table);
88116 if (hdr == NULL)
88117 goto err_reg;
88118
88119@@ -628,8 +628,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88120 return 0;
88121
88122 err_reg:
88123- if (!net_eq(net, &init_net))
88124- kfree(table);
88125+ kfree(table);
88126 err_alloc:
88127 return -ENOMEM;
88128 }
88129diff --git a/net/ipv6/route.c b/net/ipv6/route.c
88130index e5fe004..9fe3e8e 100644
88131--- a/net/ipv6/route.c
88132+++ b/net/ipv6/route.c
88133@@ -2881,7 +2881,7 @@ ctl_table ipv6_route_table_template[] = {
88134
88135 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
88136 {
88137- struct ctl_table *table;
88138+ ctl_table_no_const *table;
88139
88140 table = kmemdup(ipv6_route_table_template,
88141 sizeof(ipv6_route_table_template),
88142diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
88143index 02f96dc..4a5a6e5 100644
88144--- a/net/ipv6/sit.c
88145+++ b/net/ipv6/sit.c
88146@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
88147 static void ipip6_dev_free(struct net_device *dev);
88148 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
88149 __be32 *v4dst);
88150-static struct rtnl_link_ops sit_link_ops __read_mostly;
88151+static struct rtnl_link_ops sit_link_ops;
88152
88153 static int sit_net_id __read_mostly;
88154 struct sit_net {
88155@@ -1486,7 +1486,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
88156 #endif
88157 };
88158
88159-static struct rtnl_link_ops sit_link_ops __read_mostly = {
88160+static struct rtnl_link_ops sit_link_ops = {
88161 .kind = "sit",
88162 .maxtype = IFLA_IPTUN_MAX,
88163 .policy = ipip6_policy,
88164diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
88165index e85c48b..b8268d3 100644
88166--- a/net/ipv6/sysctl_net_ipv6.c
88167+++ b/net/ipv6/sysctl_net_ipv6.c
88168@@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
88169
88170 static int __net_init ipv6_sysctl_net_init(struct net *net)
88171 {
88172- struct ctl_table *ipv6_table;
88173+ ctl_table_no_const *ipv6_table;
88174 struct ctl_table *ipv6_route_table;
88175 struct ctl_table *ipv6_icmp_table;
88176 int err;
88177diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
88178index 0fce928..c52a518 100644
88179--- a/net/ipv6/tcp_ipv6.c
88180+++ b/net/ipv6/tcp_ipv6.c
88181@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
88182 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
88183 }
88184
88185+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88186+extern int grsec_enable_blackhole;
88187+#endif
88188+
88189 static void tcp_v6_hash(struct sock *sk)
88190 {
88191 if (sk->sk_state != TCP_CLOSE) {
88192@@ -1446,6 +1450,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
88193 return 0;
88194
88195 reset:
88196+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88197+ if (!grsec_enable_blackhole)
88198+#endif
88199 tcp_v6_send_reset(sk, skb);
88200 discard:
88201 if (opt_skb)
88202@@ -1527,12 +1534,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
88203 TCP_SKB_CB(skb)->sacked = 0;
88204
88205 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
88206- if (!sk)
88207+ if (!sk) {
88208+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88209+ ret = 1;
88210+#endif
88211 goto no_tcp_socket;
88212+ }
88213
88214 process:
88215- if (sk->sk_state == TCP_TIME_WAIT)
88216+ if (sk->sk_state == TCP_TIME_WAIT) {
88217+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88218+ ret = 2;
88219+#endif
88220 goto do_time_wait;
88221+ }
88222
88223 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
88224 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
88225@@ -1581,6 +1596,10 @@ no_tcp_socket:
88226 bad_packet:
88227 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
88228 } else {
88229+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88230+ if (!grsec_enable_blackhole || (ret == 1 &&
88231+ (skb->dev->flags & IFF_LOOPBACK)))
88232+#endif
88233 tcp_v6_send_reset(NULL, skb);
88234 }
88235
88236diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
88237index 27f0f8e..949e7ee 100644
88238--- a/net/ipv6/udp.c
88239+++ b/net/ipv6/udp.c
88240@@ -52,6 +52,10 @@
88241 #include <trace/events/skb.h>
88242 #include "udp_impl.h"
88243
88244+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88245+extern int grsec_enable_blackhole;
88246+#endif
88247+
88248 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
88249 {
88250 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
88251@@ -419,7 +423,7 @@ try_again:
88252 if (unlikely(err)) {
88253 trace_kfree_skb(skb, udpv6_recvmsg);
88254 if (!peeked) {
88255- atomic_inc(&sk->sk_drops);
88256+ atomic_inc_unchecked(&sk->sk_drops);
88257 if (is_udp4)
88258 UDP_INC_STATS_USER(sock_net(sk),
88259 UDP_MIB_INERRORS,
88260@@ -657,7 +661,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
88261 return rc;
88262 drop:
88263 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
88264- atomic_inc(&sk->sk_drops);
88265+ atomic_inc_unchecked(&sk->sk_drops);
88266 kfree_skb(skb);
88267 return -1;
88268 }
88269@@ -715,7 +719,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
88270 if (likely(skb1 == NULL))
88271 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
88272 if (!skb1) {
88273- atomic_inc(&sk->sk_drops);
88274+ atomic_inc_unchecked(&sk->sk_drops);
88275 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
88276 IS_UDPLITE(sk));
88277 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
88278@@ -852,6 +856,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
88279 goto discard;
88280
88281 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
88282+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88283+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
88284+#endif
88285 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
88286
88287 kfree_skb(skb);
88288@@ -1377,7 +1384,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
88289 0,
88290 sock_i_ino(sp),
88291 atomic_read(&sp->sk_refcnt), sp,
88292- atomic_read(&sp->sk_drops));
88293+ atomic_read_unchecked(&sp->sk_drops));
88294 }
88295
88296 int udp6_seq_show(struct seq_file *seq, void *v)
88297diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
88298index 23ed03d..465a71d 100644
88299--- a/net/ipv6/xfrm6_policy.c
88300+++ b/net/ipv6/xfrm6_policy.c
88301@@ -324,19 +324,19 @@ static struct ctl_table xfrm6_policy_table[] = {
88302
88303 static int __net_init xfrm6_net_init(struct net *net)
88304 {
88305- struct ctl_table *table;
88306+ ctl_table_no_const *table = NULL;
88307 struct ctl_table_header *hdr;
88308
88309- table = xfrm6_policy_table;
88310 if (!net_eq(net, &init_net)) {
88311- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
88312+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
88313 if (!table)
88314 goto err_alloc;
88315
88316 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
88317- }
88318+ hdr = register_net_sysctl(net, "net/ipv6", table);
88319+ } else
88320+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
88321
88322- hdr = register_net_sysctl(net, "net/ipv6", table);
88323 if (!hdr)
88324 goto err_reg;
88325
88326@@ -344,8 +344,7 @@ static int __net_init xfrm6_net_init(struct net *net)
88327 return 0;
88328
88329 err_reg:
88330- if (!net_eq(net, &init_net))
88331- kfree(table);
88332+ kfree(table);
88333 err_alloc:
88334 return -ENOMEM;
88335 }
88336diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
88337index 362ba47..66196f4 100644
88338--- a/net/irda/ircomm/ircomm_tty.c
88339+++ b/net/irda/ircomm/ircomm_tty.c
88340@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88341 add_wait_queue(&port->open_wait, &wait);
88342
88343 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
88344- __FILE__, __LINE__, tty->driver->name, port->count);
88345+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88346
88347 spin_lock_irqsave(&port->lock, flags);
88348 if (!tty_hung_up_p(filp))
88349- port->count--;
88350+ atomic_dec(&port->count);
88351 port->blocked_open++;
88352 spin_unlock_irqrestore(&port->lock, flags);
88353
88354@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88355 }
88356
88357 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
88358- __FILE__, __LINE__, tty->driver->name, port->count);
88359+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88360
88361 schedule();
88362 }
88363@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88364
88365 spin_lock_irqsave(&port->lock, flags);
88366 if (!tty_hung_up_p(filp))
88367- port->count++;
88368+ atomic_inc(&port->count);
88369 port->blocked_open--;
88370 spin_unlock_irqrestore(&port->lock, flags);
88371
88372 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
88373- __FILE__, __LINE__, tty->driver->name, port->count);
88374+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88375
88376 if (!retval)
88377 port->flags |= ASYNC_NORMAL_ACTIVE;
88378@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
88379
88380 /* ++ is not atomic, so this should be protected - Jean II */
88381 spin_lock_irqsave(&self->port.lock, flags);
88382- self->port.count++;
88383+ atomic_inc(&self->port.count);
88384 spin_unlock_irqrestore(&self->port.lock, flags);
88385 tty_port_tty_set(&self->port, tty);
88386
88387 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
88388- self->line, self->port.count);
88389+ self->line, atomic_read(&self->port.count));
88390
88391 /* Not really used by us, but lets do it anyway */
88392 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
88393@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
88394 tty_kref_put(port->tty);
88395 }
88396 port->tty = NULL;
88397- port->count = 0;
88398+ atomic_set(&port->count, 0);
88399 spin_unlock_irqrestore(&port->lock, flags);
88400
88401 wake_up_interruptible(&port->open_wait);
88402@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
88403 seq_putc(m, '\n');
88404
88405 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
88406- seq_printf(m, "Open count: %d\n", self->port.count);
88407+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
88408 seq_printf(m, "Max data size: %d\n", self->max_data_size);
88409 seq_printf(m, "Max header size: %d\n", self->max_header_size);
88410
88411diff --git a/net/irda/irlap_frame.c b/net/irda/irlap_frame.c
88412index 8c00416..9ea0c93 100644
88413--- a/net/irda/irlap_frame.c
88414+++ b/net/irda/irlap_frame.c
88415@@ -544,7 +544,7 @@ static void irlap_recv_discovery_xid_cmd(struct irlap_cb *self,
88416 /*
88417 * We now have some discovery info to deliver!
88418 */
88419- discovery = kmalloc(sizeof(discovery_t), GFP_ATOMIC);
88420+ discovery = kzalloc(sizeof(discovery_t), GFP_ATOMIC);
88421 if (!discovery) {
88422 IRDA_WARNING("%s: unable to malloc!\n", __func__);
88423 return;
88424diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
88425index 206ce6d..cfb27cd 100644
88426--- a/net/iucv/af_iucv.c
88427+++ b/net/iucv/af_iucv.c
88428@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
88429
88430 write_lock_bh(&iucv_sk_list.lock);
88431
88432- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
88433+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
88434 while (__iucv_get_sock_by_name(name)) {
88435 sprintf(name, "%08x",
88436- atomic_inc_return(&iucv_sk_list.autobind_name));
88437+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
88438 }
88439
88440 write_unlock_bh(&iucv_sk_list.lock);
88441diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
88442index 4fe76ff..426a904 100644
88443--- a/net/iucv/iucv.c
88444+++ b/net/iucv/iucv.c
88445@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
88446 return NOTIFY_OK;
88447 }
88448
88449-static struct notifier_block __refdata iucv_cpu_notifier = {
88450+static struct notifier_block iucv_cpu_notifier = {
88451 .notifier_call = iucv_cpu_notify,
88452 };
88453
88454diff --git a/net/key/af_key.c b/net/key/af_key.c
88455index 5b1e5af..2358147 100644
88456--- a/net/key/af_key.c
88457+++ b/net/key/af_key.c
88458@@ -3041,10 +3041,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
88459 static u32 get_acqseq(void)
88460 {
88461 u32 res;
88462- static atomic_t acqseq;
88463+ static atomic_unchecked_t acqseq;
88464
88465 do {
88466- res = atomic_inc_return(&acqseq);
88467+ res = atomic_inc_return_unchecked(&acqseq);
88468 } while (!res);
88469 return res;
88470 }
88471diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
88472index 637a341..8dec687 100644
88473--- a/net/l2tp/l2tp_ppp.c
88474+++ b/net/l2tp/l2tp_ppp.c
88475@@ -346,19 +346,19 @@ static int pppol2tp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msgh
88476 skb_put(skb, 2);
88477
88478 /* Copy user data into skb */
88479- error = memcpy_fromiovec(skb->data, m->msg_iov, total_len);
88480+ error = memcpy_fromiovec(skb_put(skb, total_len), m->msg_iov,
88481+ total_len);
88482 if (error < 0) {
88483 kfree_skb(skb);
88484 goto error_put_sess_tun;
88485 }
88486- skb_put(skb, total_len);
88487
88488 l2tp_xmit_skb(session, skb, session->hdr_len);
88489
88490 sock_put(ps->tunnel_sock);
88491 sock_put(sk);
88492
88493- return error;
88494+ return total_len;
88495
88496 error_put_sess_tun:
88497 sock_put(ps->tunnel_sock);
88498diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
88499index 843d8c4..cb04fa1 100644
88500--- a/net/mac80211/cfg.c
88501+++ b/net/mac80211/cfg.c
88502@@ -799,7 +799,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
88503 ret = ieee80211_vif_use_channel(sdata, chandef,
88504 IEEE80211_CHANCTX_EXCLUSIVE);
88505 }
88506- } else if (local->open_count == local->monitors) {
88507+ } else if (local_read(&local->open_count) == local->monitors) {
88508 local->_oper_channel = chandef->chan;
88509 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
88510 ieee80211_hw_config(local, 0);
88511@@ -2834,7 +2834,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
88512 else
88513 local->probe_req_reg--;
88514
88515- if (!local->open_count)
88516+ if (!local_read(&local->open_count))
88517 break;
88518
88519 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
88520@@ -3297,8 +3297,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
88521 if (chanctx_conf) {
88522 *chandef = chanctx_conf->def;
88523 ret = 0;
88524- } else if (local->open_count > 0 &&
88525- local->open_count == local->monitors &&
88526+ } else if (local_read(&local->open_count) > 0 &&
88527+ local_read(&local->open_count) == local->monitors &&
88528 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
88529 if (local->use_chanctx)
88530 *chandef = local->monitor_chandef;
88531diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
88532index 5672533..6738c93 100644
88533--- a/net/mac80211/ieee80211_i.h
88534+++ b/net/mac80211/ieee80211_i.h
88535@@ -28,6 +28,7 @@
88536 #include <net/ieee80211_radiotap.h>
88537 #include <net/cfg80211.h>
88538 #include <net/mac80211.h>
88539+#include <asm/local.h>
88540 #include "key.h"
88541 #include "sta_info.h"
88542 #include "debug.h"
88543@@ -897,7 +898,7 @@ struct ieee80211_local {
88544 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
88545 spinlock_t queue_stop_reason_lock;
88546
88547- int open_count;
88548+ local_t open_count;
88549 int monitors, cooked_mntrs;
88550 /* number of interfaces with corresponding FIF_ flags */
88551 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
88552diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
88553index 9cbebc2..14879bb 100644
88554--- a/net/mac80211/iface.c
88555+++ b/net/mac80211/iface.c
88556@@ -495,7 +495,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88557 break;
88558 }
88559
88560- if (local->open_count == 0) {
88561+ if (local_read(&local->open_count) == 0) {
88562 res = drv_start(local);
88563 if (res)
88564 goto err_del_bss;
88565@@ -540,7 +540,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88566 break;
88567 }
88568
88569- if (local->monitors == 0 && local->open_count == 0) {
88570+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
88571 res = ieee80211_add_virtual_monitor(local);
88572 if (res)
88573 goto err_stop;
88574@@ -649,7 +649,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88575 atomic_inc(&local->iff_promiscs);
88576
88577 if (coming_up)
88578- local->open_count++;
88579+ local_inc(&local->open_count);
88580
88581 if (hw_reconf_flags)
88582 ieee80211_hw_config(local, hw_reconf_flags);
88583@@ -663,7 +663,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88584 err_del_interface:
88585 drv_remove_interface(local, sdata);
88586 err_stop:
88587- if (!local->open_count)
88588+ if (!local_read(&local->open_count))
88589 drv_stop(local);
88590 err_del_bss:
88591 sdata->bss = NULL;
88592@@ -806,7 +806,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
88593 }
88594
88595 if (going_down)
88596- local->open_count--;
88597+ local_dec(&local->open_count);
88598
88599 switch (sdata->vif.type) {
88600 case NL80211_IFTYPE_AP_VLAN:
88601@@ -871,7 +871,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
88602
88603 ieee80211_recalc_ps(local, -1);
88604
88605- if (local->open_count == 0) {
88606+ if (local_read(&local->open_count) == 0) {
88607 if (local->ops->napi_poll)
88608 napi_disable(&local->napi);
88609 ieee80211_clear_tx_pending(local);
88610@@ -897,7 +897,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
88611 }
88612 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
88613
88614- if (local->monitors == local->open_count && local->monitors > 0)
88615+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
88616 ieee80211_add_virtual_monitor(local);
88617 }
88618
88619diff --git a/net/mac80211/main.c b/net/mac80211/main.c
88620index 1a8591b..ef5db54 100644
88621--- a/net/mac80211/main.c
88622+++ b/net/mac80211/main.c
88623@@ -180,7 +180,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
88624 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
88625 IEEE80211_CONF_CHANGE_POWER);
88626
88627- if (changed && local->open_count) {
88628+ if (changed && local_read(&local->open_count)) {
88629 ret = drv_config(local, changed);
88630 /*
88631 * Goal:
88632diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
88633index 835584c..be46e67 100644
88634--- a/net/mac80211/pm.c
88635+++ b/net/mac80211/pm.c
88636@@ -33,7 +33,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
88637 struct sta_info *sta;
88638 struct ieee80211_chanctx *ctx;
88639
88640- if (!local->open_count)
88641+ if (!local_read(&local->open_count))
88642 goto suspend;
88643
88644 ieee80211_scan_cancel(local);
88645@@ -75,7 +75,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
88646 cancel_work_sync(&local->dynamic_ps_enable_work);
88647 del_timer_sync(&local->dynamic_ps_timer);
88648
88649- local->wowlan = wowlan && local->open_count;
88650+ local->wowlan = wowlan && local_read(&local->open_count);
88651 if (local->wowlan) {
88652 int err = drv_suspend(local, wowlan);
88653 if (err < 0) {
88654@@ -214,7 +214,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
88655 mutex_unlock(&local->chanctx_mtx);
88656
88657 /* stop hardware - this must stop RX */
88658- if (local->open_count)
88659+ if (local_read(&local->open_count))
88660 ieee80211_stop_device(local);
88661
88662 suspend:
88663diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
88664index dd88381..eef4dd6 100644
88665--- a/net/mac80211/rate.c
88666+++ b/net/mac80211/rate.c
88667@@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
88668
88669 ASSERT_RTNL();
88670
88671- if (local->open_count)
88672+ if (local_read(&local->open_count))
88673 return -EBUSY;
88674
88675 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
88676diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
88677index c97a065..ff61928 100644
88678--- a/net/mac80211/rc80211_pid_debugfs.c
88679+++ b/net/mac80211/rc80211_pid_debugfs.c
88680@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
88681
88682 spin_unlock_irqrestore(&events->lock, status);
88683
88684- if (copy_to_user(buf, pb, p))
88685+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
88686 return -EFAULT;
88687
88688 return p;
88689diff --git a/net/mac80211/util.c b/net/mac80211/util.c
88690index 0f38f43..e53d4a8 100644
88691--- a/net/mac80211/util.c
88692+++ b/net/mac80211/util.c
88693@@ -1388,7 +1388,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
88694 }
88695 #endif
88696 /* everything else happens only if HW was up & running */
88697- if (!local->open_count)
88698+ if (!local_read(&local->open_count))
88699 goto wake_up;
88700
88701 /*
88702diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
88703index 56d22ca..87c778f 100644
88704--- a/net/netfilter/Kconfig
88705+++ b/net/netfilter/Kconfig
88706@@ -958,6 +958,16 @@ config NETFILTER_XT_MATCH_ESP
88707
88708 To compile it as a module, choose M here. If unsure, say N.
88709
88710+config NETFILTER_XT_MATCH_GRADM
88711+ tristate '"gradm" match support'
88712+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
88713+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
88714+ ---help---
88715+ The gradm match allows to match on grsecurity RBAC being enabled.
88716+ It is useful when iptables rules are applied early on bootup to
88717+ prevent connections to the machine (except from a trusted host)
88718+ while the RBAC system is disabled.
88719+
88720 config NETFILTER_XT_MATCH_HASHLIMIT
88721 tristate '"hashlimit" match support'
88722 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
88723diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
88724index a1abf87..dbcb7ee 100644
88725--- a/net/netfilter/Makefile
88726+++ b/net/netfilter/Makefile
88727@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
88728 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
88729 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
88730 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
88731+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
88732 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
88733 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
88734 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
88735diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
88736index 1ba9dbc..e39f4ca 100644
88737--- a/net/netfilter/ipset/ip_set_core.c
88738+++ b/net/netfilter/ipset/ip_set_core.c
88739@@ -1801,7 +1801,7 @@ done:
88740 return ret;
88741 }
88742
88743-static struct nf_sockopt_ops so_set __read_mostly = {
88744+static struct nf_sockopt_ops so_set = {
88745 .pf = PF_INET,
88746 .get_optmin = SO_IP_SET,
88747 .get_optmax = SO_IP_SET + 1,
88748diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
88749index 704e514..d644cc2 100644
88750--- a/net/netfilter/ipvs/ip_vs_conn.c
88751+++ b/net/netfilter/ipvs/ip_vs_conn.c
88752@@ -551,7 +551,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
88753 /* Increase the refcnt counter of the dest */
88754 atomic_inc(&dest->refcnt);
88755
88756- conn_flags = atomic_read(&dest->conn_flags);
88757+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
88758 if (cp->protocol != IPPROTO_UDP)
88759 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
88760 flags = cp->flags;
88761@@ -895,7 +895,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
88762 atomic_set(&cp->refcnt, 1);
88763
88764 atomic_set(&cp->n_control, 0);
88765- atomic_set(&cp->in_pkts, 0);
88766+ atomic_set_unchecked(&cp->in_pkts, 0);
88767
88768 atomic_inc(&ipvs->conn_count);
88769 if (flags & IP_VS_CONN_F_NO_CPORT)
88770@@ -1174,7 +1174,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
88771
88772 /* Don't drop the entry if its number of incoming packets is not
88773 located in [0, 8] */
88774- i = atomic_read(&cp->in_pkts);
88775+ i = atomic_read_unchecked(&cp->in_pkts);
88776 if (i > 8 || i < 0) return 0;
88777
88778 if (!todrop_rate[i]) return 0;
88779diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
88780index 61f49d2..6c8c5bc 100644
88781--- a/net/netfilter/ipvs/ip_vs_core.c
88782+++ b/net/netfilter/ipvs/ip_vs_core.c
88783@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
88784 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
88785 /* do not touch skb anymore */
88786
88787- atomic_inc(&cp->in_pkts);
88788+ atomic_inc_unchecked(&cp->in_pkts);
88789 ip_vs_conn_put(cp);
88790 return ret;
88791 }
88792@@ -1689,7 +1689,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
88793 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
88794 pkts = sysctl_sync_threshold(ipvs);
88795 else
88796- pkts = atomic_add_return(1, &cp->in_pkts);
88797+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
88798
88799 if (ipvs->sync_state & IP_VS_STATE_MASTER)
88800 ip_vs_sync_conn(net, cp, pkts);
88801diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
88802index 9e2d1cc..6ed0748 100644
88803--- a/net/netfilter/ipvs/ip_vs_ctl.c
88804+++ b/net/netfilter/ipvs/ip_vs_ctl.c
88805@@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
88806 ip_vs_rs_hash(ipvs, dest);
88807 write_unlock_bh(&ipvs->rs_lock);
88808 }
88809- atomic_set(&dest->conn_flags, conn_flags);
88810+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
88811
88812 /* bind the service */
88813 if (!dest->svc) {
88814@@ -1688,7 +1688,7 @@ proc_do_sync_ports(ctl_table *table, int write,
88815 * align with netns init in ip_vs_control_net_init()
88816 */
88817
88818-static struct ctl_table vs_vars[] = {
88819+static ctl_table_no_const vs_vars[] __read_only = {
88820 {
88821 .procname = "amemthresh",
88822 .maxlen = sizeof(int),
88823@@ -2087,7 +2087,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
88824 " %-7s %-6d %-10d %-10d\n",
88825 &dest->addr.in6,
88826 ntohs(dest->port),
88827- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
88828+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
88829 atomic_read(&dest->weight),
88830 atomic_read(&dest->activeconns),
88831 atomic_read(&dest->inactconns));
88832@@ -2098,7 +2098,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
88833 "%-7s %-6d %-10d %-10d\n",
88834 ntohl(dest->addr.ip),
88835 ntohs(dest->port),
88836- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
88837+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
88838 atomic_read(&dest->weight),
88839 atomic_read(&dest->activeconns),
88840 atomic_read(&dest->inactconns));
88841@@ -2562,13 +2562,14 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
88842 struct ip_vs_dest *dest;
88843 struct ip_vs_dest_entry entry;
88844
88845+ memset(&entry, 0, sizeof(entry));
88846 list_for_each_entry(dest, &svc->destinations, n_list) {
88847 if (count >= get->num_dests)
88848 break;
88849
88850 entry.addr = dest->addr.ip;
88851 entry.port = dest->port;
88852- entry.conn_flags = atomic_read(&dest->conn_flags);
88853+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
88854 entry.weight = atomic_read(&dest->weight);
88855 entry.u_threshold = dest->u_threshold;
88856 entry.l_threshold = dest->l_threshold;
88857@@ -3104,7 +3105,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
88858 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
88859 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
88860 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
88861- (atomic_read(&dest->conn_flags) &
88862+ (atomic_read_unchecked(&dest->conn_flags) &
88863 IP_VS_CONN_F_FWD_MASK)) ||
88864 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
88865 atomic_read(&dest->weight)) ||
88866@@ -3694,7 +3695,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
88867 {
88868 int idx;
88869 struct netns_ipvs *ipvs = net_ipvs(net);
88870- struct ctl_table *tbl;
88871+ ctl_table_no_const *tbl;
88872
88873 atomic_set(&ipvs->dropentry, 0);
88874 spin_lock_init(&ipvs->dropentry_lock);
88875diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
88876index fdd89b9..bd96aa9 100644
88877--- a/net/netfilter/ipvs/ip_vs_lblc.c
88878+++ b/net/netfilter/ipvs/ip_vs_lblc.c
88879@@ -115,7 +115,7 @@ struct ip_vs_lblc_table {
88880 * IPVS LBLC sysctl table
88881 */
88882 #ifdef CONFIG_SYSCTL
88883-static ctl_table vs_vars_table[] = {
88884+static ctl_table_no_const vs_vars_table[] __read_only = {
88885 {
88886 .procname = "lblc_expiration",
88887 .data = NULL,
88888diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
88889index c03b6a3..8ce3681 100644
88890--- a/net/netfilter/ipvs/ip_vs_lblcr.c
88891+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
88892@@ -288,7 +288,7 @@ struct ip_vs_lblcr_table {
88893 * IPVS LBLCR sysctl table
88894 */
88895
88896-static ctl_table vs_vars_table[] = {
88897+static ctl_table_no_const vs_vars_table[] __read_only = {
88898 {
88899 .procname = "lblcr_expiration",
88900 .data = NULL,
88901diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
88902index 44fd10c..2a163b3 100644
88903--- a/net/netfilter/ipvs/ip_vs_sync.c
88904+++ b/net/netfilter/ipvs/ip_vs_sync.c
88905@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
88906 cp = cp->control;
88907 if (cp) {
88908 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
88909- pkts = atomic_add_return(1, &cp->in_pkts);
88910+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
88911 else
88912 pkts = sysctl_sync_threshold(ipvs);
88913 ip_vs_sync_conn(net, cp->control, pkts);
88914@@ -758,7 +758,7 @@ control:
88915 if (!cp)
88916 return;
88917 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
88918- pkts = atomic_add_return(1, &cp->in_pkts);
88919+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
88920 else
88921 pkts = sysctl_sync_threshold(ipvs);
88922 goto sloop;
88923@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
88924
88925 if (opt)
88926 memcpy(&cp->in_seq, opt, sizeof(*opt));
88927- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
88928+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
88929 cp->state = state;
88930 cp->old_state = cp->state;
88931 /*
88932diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
88933index ee6b7a9..f9a89f6 100644
88934--- a/net/netfilter/ipvs/ip_vs_xmit.c
88935+++ b/net/netfilter/ipvs/ip_vs_xmit.c
88936@@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
88937 else
88938 rc = NF_ACCEPT;
88939 /* do not touch skb anymore */
88940- atomic_inc(&cp->in_pkts);
88941+ atomic_inc_unchecked(&cp->in_pkts);
88942 goto out;
88943 }
88944
88945@@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
88946 else
88947 rc = NF_ACCEPT;
88948 /* do not touch skb anymore */
88949- atomic_inc(&cp->in_pkts);
88950+ atomic_inc_unchecked(&cp->in_pkts);
88951 goto out;
88952 }
88953
88954diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
88955index 2d3030a..7ba1c0a 100644
88956--- a/net/netfilter/nf_conntrack_acct.c
88957+++ b/net/netfilter/nf_conntrack_acct.c
88958@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
88959 #ifdef CONFIG_SYSCTL
88960 static int nf_conntrack_acct_init_sysctl(struct net *net)
88961 {
88962- struct ctl_table *table;
88963+ ctl_table_no_const *table;
88964
88965 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
88966 GFP_KERNEL);
88967diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
88968index c8e001a..f842a8b 100644
88969--- a/net/netfilter/nf_conntrack_core.c
88970+++ b/net/netfilter/nf_conntrack_core.c
88971@@ -1594,6 +1594,10 @@ void nf_conntrack_init_end(void)
88972 #define DYING_NULLS_VAL ((1<<30)+1)
88973 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
88974
88975+#ifdef CONFIG_GRKERNSEC_HIDESYM
88976+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
88977+#endif
88978+
88979 int nf_conntrack_init_net(struct net *net)
88980 {
88981 int ret;
88982@@ -1608,7 +1612,11 @@ int nf_conntrack_init_net(struct net *net)
88983 goto err_stat;
88984 }
88985
88986+#ifdef CONFIG_GRKERNSEC_HIDESYM
88987+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
88988+#else
88989 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
88990+#endif
88991 if (!net->ct.slabname) {
88992 ret = -ENOMEM;
88993 goto err_slabname;
88994diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
88995index b5d2eb8..61ef19a 100644
88996--- a/net/netfilter/nf_conntrack_ecache.c
88997+++ b/net/netfilter/nf_conntrack_ecache.c
88998@@ -186,7 +186,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
88999 #ifdef CONFIG_SYSCTL
89000 static int nf_conntrack_event_init_sysctl(struct net *net)
89001 {
89002- struct ctl_table *table;
89003+ ctl_table_no_const *table;
89004
89005 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
89006 GFP_KERNEL);
89007diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
89008index 94b4b98..97cf0ad 100644
89009--- a/net/netfilter/nf_conntrack_helper.c
89010+++ b/net/netfilter/nf_conntrack_helper.c
89011@@ -56,7 +56,7 @@ static struct ctl_table helper_sysctl_table[] = {
89012
89013 static int nf_conntrack_helper_init_sysctl(struct net *net)
89014 {
89015- struct ctl_table *table;
89016+ ctl_table_no_const *table;
89017
89018 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
89019 GFP_KERNEL);
89020diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
89021index 58ab405..50eb8d3 100644
89022--- a/net/netfilter/nf_conntrack_proto.c
89023+++ b/net/netfilter/nf_conntrack_proto.c
89024@@ -51,7 +51,7 @@ nf_ct_register_sysctl(struct net *net,
89025
89026 static void
89027 nf_ct_unregister_sysctl(struct ctl_table_header **header,
89028- struct ctl_table **table,
89029+ ctl_table_no_const **table,
89030 unsigned int users)
89031 {
89032 if (users > 0)
89033diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
89034index fedee39..d62a93d 100644
89035--- a/net/netfilter/nf_conntrack_standalone.c
89036+++ b/net/netfilter/nf_conntrack_standalone.c
89037@@ -470,7 +470,7 @@ static ctl_table nf_ct_netfilter_table[] = {
89038
89039 static int nf_conntrack_standalone_init_sysctl(struct net *net)
89040 {
89041- struct ctl_table *table;
89042+ ctl_table_no_const *table;
89043
89044 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
89045 GFP_KERNEL);
89046diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
89047index 902fb0a..87f7fdb 100644
89048--- a/net/netfilter/nf_conntrack_timestamp.c
89049+++ b/net/netfilter/nf_conntrack_timestamp.c
89050@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
89051 #ifdef CONFIG_SYSCTL
89052 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
89053 {
89054- struct ctl_table *table;
89055+ ctl_table_no_const *table;
89056
89057 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
89058 GFP_KERNEL);
89059diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
89060index 9e31269..bc4c1b7 100644
89061--- a/net/netfilter/nf_log.c
89062+++ b/net/netfilter/nf_log.c
89063@@ -215,7 +215,7 @@ static const struct file_operations nflog_file_ops = {
89064
89065 #ifdef CONFIG_SYSCTL
89066 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
89067-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
89068+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
89069 static struct ctl_table_header *nf_log_dir_header;
89070
89071 static int nf_log_proc_dostring(ctl_table *table, int write,
89072@@ -246,14 +246,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
89073 rcu_assign_pointer(nf_loggers[tindex], logger);
89074 mutex_unlock(&nf_log_mutex);
89075 } else {
89076+ ctl_table_no_const nf_log_table = *table;
89077+
89078 mutex_lock(&nf_log_mutex);
89079 logger = rcu_dereference_protected(nf_loggers[tindex],
89080 lockdep_is_held(&nf_log_mutex));
89081 if (!logger)
89082- table->data = "NONE";
89083+ nf_log_table.data = "NONE";
89084 else
89085- table->data = logger->name;
89086- r = proc_dostring(table, write, buffer, lenp, ppos);
89087+ nf_log_table.data = logger->name;
89088+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
89089 mutex_unlock(&nf_log_mutex);
89090 }
89091
89092diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
89093index f042ae5..30ea486 100644
89094--- a/net/netfilter/nf_sockopt.c
89095+++ b/net/netfilter/nf_sockopt.c
89096@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
89097 }
89098 }
89099
89100- list_add(&reg->list, &nf_sockopts);
89101+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
89102 out:
89103 mutex_unlock(&nf_sockopt_mutex);
89104 return ret;
89105@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
89106 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
89107 {
89108 mutex_lock(&nf_sockopt_mutex);
89109- list_del(&reg->list);
89110+ pax_list_del((struct list_head *)&reg->list);
89111 mutex_unlock(&nf_sockopt_mutex);
89112 }
89113 EXPORT_SYMBOL(nf_unregister_sockopt);
89114diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
89115index f248db5..3778ad9 100644
89116--- a/net/netfilter/nfnetlink_log.c
89117+++ b/net/netfilter/nfnetlink_log.c
89118@@ -72,7 +72,7 @@ struct nfulnl_instance {
89119 };
89120
89121 static DEFINE_SPINLOCK(instances_lock);
89122-static atomic_t global_seq;
89123+static atomic_unchecked_t global_seq;
89124
89125 #define INSTANCE_BUCKETS 16
89126 static struct hlist_head instance_table[INSTANCE_BUCKETS];
89127@@ -536,7 +536,7 @@ __build_packet_message(struct nfulnl_instance *inst,
89128 /* global sequence number */
89129 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
89130 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
89131- htonl(atomic_inc_return(&global_seq))))
89132+ htonl(atomic_inc_return_unchecked(&global_seq))))
89133 goto nla_put_failure;
89134
89135 if (data_len) {
89136diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
89137new file mode 100644
89138index 0000000..c566332
89139--- /dev/null
89140+++ b/net/netfilter/xt_gradm.c
89141@@ -0,0 +1,51 @@
89142+/*
89143+ * gradm match for netfilter
89144